Back to index

lightning-sunbird  0.9+nobinonly
nsAutoComplete.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Original Author: Jean-Francois Ducarroz (ducarroz@netscape.com)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsCOMPtr.h"
00040 #include "prtypes.h"
00041 #include "nsAutoComplete.h"
00042 #include "nsReadableUtils.h"
00043 
00044 /******************************************************************************
00045  * nsAutoCompleteItem
00046  ******************************************************************************/
00047 
00048 NS_IMPL_ISUPPORTS1(nsAutoCompleteItem, nsIAutoCompleteItem)
00049 
00050 nsAutoCompleteItem::nsAutoCompleteItem()
00051 {
00052 }
00053 
00054 nsAutoCompleteItem::~nsAutoCompleteItem()
00055 {
00056 }
00057 
00058 NS_IMETHODIMP nsAutoCompleteItem::GetValue(nsAString& aValue)
00059 {
00060     aValue.Assign(mValue);
00061     return NS_OK;
00062 }
00063 
00064 NS_IMETHODIMP nsAutoCompleteItem::SetValue(const nsAString& aValue)
00065 {
00066     mValue.Assign(aValue);
00067     return NS_OK;
00068 }
00069 
00070 NS_IMETHODIMP nsAutoCompleteItem::GetComment(PRUnichar * *aComment)
00071 {
00072     if (!aComment) return NS_ERROR_NULL_POINTER;
00073     *aComment = ToNewUnicode(mComment);
00074     return NS_OK;
00075 }
00076 NS_IMETHODIMP nsAutoCompleteItem::SetComment(const PRUnichar * aComment)
00077 {
00078     mComment = aComment;
00079     return NS_OK;
00080 }
00081 
00082 /* attribute string className; */
00083 NS_IMETHODIMP nsAutoCompleteItem::GetClassName(char * *aClassName)
00084 {
00085     if (!aClassName) return NS_ERROR_NULL_POINTER;
00086     *aClassName = ToNewCString(mClassName);
00087     return NS_OK;
00088 }
00089 NS_IMETHODIMP nsAutoCompleteItem::SetClassName(const char * aClassName)
00090 {
00091     mClassName.AssignWithConversion(aClassName);
00092     return NS_OK;
00093 }
00094 
00095 /* attribute nsISupports param; */
00096 NS_IMETHODIMP nsAutoCompleteItem::GetParam(nsISupports * *aParam)
00097 {
00098     if (!aParam) return NS_ERROR_NULL_POINTER;
00099     *aParam = mParam;
00100     NS_IF_ADDREF(*aParam);
00101     return NS_OK;
00102 }
00103 NS_IMETHODIMP nsAutoCompleteItem::SetParam(nsISupports * aParam)
00104 {
00105     mParam = aParam;
00106     return NS_OK;
00107 }
00108 
00109 
00110 /******************************************************************************
00111  * nsAutoCompleteResults
00112  ******************************************************************************/
00113 NS_IMPL_ISUPPORTS1(nsAutoCompleteResults, nsIAutoCompleteResults)
00114 
00115 nsAutoCompleteResults::nsAutoCompleteResults() :
00116     mDefaultItemIndex(0)
00117 {
00118     NS_NewISupportsArray(getter_AddRefs(mItems));
00119 }
00120 
00121 nsAutoCompleteResults::~nsAutoCompleteResults()
00122 {
00123 }
00124 
00125 NS_IMETHODIMP nsAutoCompleteResults::GetSearchString(PRUnichar * *aSearchString)
00126 {
00127     if (!aSearchString) return NS_ERROR_NULL_POINTER;
00128     *aSearchString = ToNewUnicode(mSearchString);  
00129     return NS_OK;
00130 }
00131 
00132 NS_IMETHODIMP nsAutoCompleteResults::SetSearchString(const PRUnichar * aSearchString)
00133 {
00134     mSearchString = aSearchString;
00135     return NS_OK;
00136 }
00137 
00138 NS_IMETHODIMP nsAutoCompleteResults::GetParam(nsISupports * *aParam)
00139 {
00140     if (!aParam) return NS_ERROR_NULL_POINTER;
00141     *aParam = mParam;
00142     NS_IF_ADDREF(*aParam);
00143     return NS_OK;
00144 }
00145 
00146 NS_IMETHODIMP nsAutoCompleteResults::SetParam(nsISupports * aParam)
00147 {
00148     mParam = aParam;
00149     return NS_OK;
00150 }
00151 
00152 NS_IMETHODIMP nsAutoCompleteResults::GetItems(nsISupportsArray * *aItems)
00153 {
00154     if (!aItems) return NS_ERROR_NULL_POINTER;
00155     *aItems = mItems;
00156     NS_IF_ADDREF(*aItems);   
00157     return NS_OK;
00158 }
00159 
00160 NS_IMETHODIMP nsAutoCompleteResults::SetItems(nsISupportsArray * aItems)
00161 {
00162     mItems = aItems;
00163     return NS_OK;
00164 }
00165 
00166 NS_IMETHODIMP nsAutoCompleteResults::GetDefaultItemIndex(PRInt32 *aDefaultItemIndex)
00167 {
00168     if (!aDefaultItemIndex) return NS_ERROR_NULL_POINTER;
00169     *aDefaultItemIndex = mDefaultItemIndex;  
00170     return NS_OK;
00171 }
00172 
00173 NS_IMETHODIMP nsAutoCompleteResults::SetDefaultItemIndex(PRInt32 aDefaultItemIndex)
00174 {
00175     mDefaultItemIndex = aDefaultItemIndex;
00176     return NS_OK;
00177 }