Back to index

lightning-sunbird  0.9+nobinonly
nsAutoCompleteSimpleResult.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is autocomplete code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Google Inc.
00018  * Portions created by the Initial Developer are Copyright (C) 2005
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Brett Wilson <brettw@gmail.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsAutoCompleteSimpleResult.h"
00039 
00040 NS_IMPL_ISUPPORTS2(nsAutoCompleteSimpleResult,
00041                    nsIAutoCompleteResult,
00042                    nsIAutoCompleteSimpleResult)
00043 
00044 nsAutoCompleteSimpleResult::nsAutoCompleteSimpleResult() :
00045   mDefaultIndex(-1),
00046   mSearchResult(RESULT_NOMATCH)
00047 {
00048 }
00049 
00050 // searchString
00051 NS_IMETHODIMP
00052 nsAutoCompleteSimpleResult::GetSearchString(nsAString &aSearchString)
00053 {
00054   aSearchString = mSearchString;
00055   return NS_OK;
00056 }
00057 NS_IMETHODIMP
00058 nsAutoCompleteSimpleResult::SetSearchString(const nsAString &aSearchString)
00059 {
00060   mSearchString.Assign(aSearchString);
00061   return NS_OK;
00062 }
00063 
00064 // searchResult
00065 NS_IMETHODIMP
00066 nsAutoCompleteSimpleResult::GetSearchResult(PRUint16 *aSearchResult)
00067 {
00068   *aSearchResult = mSearchResult;
00069   return NS_OK;
00070 }
00071 NS_IMETHODIMP
00072 nsAutoCompleteSimpleResult::SetSearchResult(PRUint16 aSearchResult)
00073 {
00074   mSearchResult = aSearchResult;
00075   return NS_OK;
00076 }
00077 
00078 // defaultIndex
00079 NS_IMETHODIMP
00080 nsAutoCompleteSimpleResult::GetDefaultIndex(PRInt32 *aDefaultIndex)
00081 {
00082   *aDefaultIndex = mDefaultIndex;
00083   return NS_OK;
00084 }
00085 NS_IMETHODIMP
00086 nsAutoCompleteSimpleResult::SetDefaultIndex(PRInt32 aDefaultIndex)
00087 {
00088   mDefaultIndex = aDefaultIndex;
00089   return NS_OK;
00090 }
00091 
00092 // errorDescription
00093 NS_IMETHODIMP
00094 nsAutoCompleteSimpleResult::GetErrorDescription(nsAString & aErrorDescription)
00095 {
00096   aErrorDescription = mErrorDescription;
00097   return NS_OK;
00098 }
00099 NS_IMETHODIMP
00100 nsAutoCompleteSimpleResult::SetErrorDescription(
00101                                              const nsAString &aErrorDescription)
00102 {
00103   mErrorDescription.Assign(aErrorDescription);
00104   return NS_OK;
00105 }
00106 
00107 NS_IMETHODIMP
00108 nsAutoCompleteSimpleResult::AppendMatch(const nsAString& aValue,
00109                                         const nsAString& aComment)
00110 {
00111   NS_ASSERTION(mValues.Count() == mComments.Count(), "Arrays out of sync");
00112   if (! mValues.AppendString(aValue))
00113     return NS_ERROR_OUT_OF_MEMORY;
00114   if (! mComments.AppendString(aComment)) {
00115     mValues.RemoveStringAt(mValues.Count() - 1);
00116     return NS_ERROR_OUT_OF_MEMORY;
00117   }
00118   return NS_OK;
00119 }
00120 
00121 NS_IMETHODIMP
00122 nsAutoCompleteSimpleResult::GetMatchCount(PRUint32 *aMatchCount)
00123 {
00124   NS_ASSERTION(mValues.Count() == mComments.Count(), "Arrays out of sync");
00125   *aMatchCount = mValues.Count();
00126   return NS_OK;
00127 }
00128 
00129 NS_IMETHODIMP
00130 nsAutoCompleteSimpleResult::GetValueAt(PRInt32 aIndex, nsAString& _retval)
00131 {
00132   NS_ENSURE_TRUE(aIndex >= 0 && aIndex < mValues.Count(),
00133                  NS_ERROR_ILLEGAL_VALUE);
00134   NS_ASSERTION(mValues.Count() == mComments.Count(), "Arrays out of sync");
00135   mValues.StringAt(aIndex, _retval);
00136   return NS_OK;
00137 }
00138 
00139 NS_IMETHODIMP
00140 nsAutoCompleteSimpleResult::GetCommentAt(PRInt32 aIndex, nsAString& _retval)
00141 {
00142   NS_ENSURE_TRUE(aIndex >= 0 && aIndex < mComments.Count(),
00143                  NS_ERROR_ILLEGAL_VALUE);
00144   NS_ASSERTION(mValues.Count() == mComments.Count(), "Arrays out of sync");
00145   mComments.StringAt(aIndex, _retval);
00146   return NS_OK;
00147 }
00148 
00149 NS_IMETHODIMP
00150 nsAutoCompleteSimpleResult::GetStyleAt(PRInt32 aIndex, nsAString& _retval)
00151 {
00152   return NS_ERROR_NOT_IMPLEMENTED;
00153 }
00154 
00155 NS_IMETHODIMP
00156 nsAutoCompleteSimpleResult::RemoveValueAt(PRInt32 aRowIndex,
00157                                           PRBool aRemoveFromDb)
00158 {
00159   NS_ENSURE_TRUE(aRowIndex >= 0 && aRowIndex < mValues.Count(),
00160                  NS_ERROR_ILLEGAL_VALUE);
00161 
00162   mValues.RemoveStringAt(aRowIndex);
00163   mComments.RemoveStringAt(aRowIndex);
00164   return NS_OK;
00165 }
00166 
00167