michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsAutoCompleteSimpleResult.h" michael@0: michael@0: NS_IMPL_ISUPPORTS(nsAutoCompleteSimpleResult, michael@0: nsIAutoCompleteResult, michael@0: nsIAutoCompleteSimpleResult) michael@0: michael@0: nsAutoCompleteSimpleResult::nsAutoCompleteSimpleResult() : michael@0: mDefaultIndex(-1), michael@0: mSearchResult(RESULT_NOMATCH), michael@0: mTypeAheadResult(false) michael@0: { michael@0: } michael@0: michael@0: // searchString michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetSearchString(nsAString &aSearchString) michael@0: { michael@0: aSearchString = mSearchString; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::SetSearchString(const nsAString &aSearchString) michael@0: { michael@0: mSearchString.Assign(aSearchString); michael@0: return NS_OK; michael@0: } michael@0: michael@0: // searchResult michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetSearchResult(uint16_t *aSearchResult) michael@0: { michael@0: *aSearchResult = mSearchResult; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::SetSearchResult(uint16_t aSearchResult) michael@0: { michael@0: mSearchResult = aSearchResult; michael@0: return NS_OK; michael@0: } michael@0: michael@0: // defaultIndex michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetDefaultIndex(int32_t *aDefaultIndex) michael@0: { michael@0: *aDefaultIndex = mDefaultIndex; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::SetDefaultIndex(int32_t aDefaultIndex) michael@0: { michael@0: mDefaultIndex = aDefaultIndex; michael@0: return NS_OK; michael@0: } michael@0: michael@0: // errorDescription michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetErrorDescription(nsAString & aErrorDescription) michael@0: { michael@0: aErrorDescription = mErrorDescription; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::SetErrorDescription( michael@0: const nsAString &aErrorDescription) michael@0: { michael@0: mErrorDescription.Assign(aErrorDescription); michael@0: return NS_OK; michael@0: } michael@0: michael@0: // typeAheadResult michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetTypeAheadResult(bool *aTypeAheadResult) michael@0: { michael@0: *aTypeAheadResult = mTypeAheadResult; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::SetTypeAheadResult(bool aTypeAheadResult) michael@0: { michael@0: mTypeAheadResult = aTypeAheadResult; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::AppendMatch(const nsAString& aValue, michael@0: const nsAString& aComment, michael@0: const nsAString& aImage, michael@0: const nsAString& aStyle, michael@0: const nsAString& aFinalCompleteValue) michael@0: { michael@0: CheckInvariants(); michael@0: michael@0: if (! mValues.AppendElement(aValue)) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: if (! mComments.AppendElement(aComment)) { michael@0: mValues.RemoveElementAt(mValues.Length() - 1); michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: if (! mImages.AppendElement(aImage)) { michael@0: mValues.RemoveElementAt(mValues.Length() - 1); michael@0: mComments.RemoveElementAt(mComments.Length() - 1); michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: if (! mStyles.AppendElement(aStyle)) { michael@0: mValues.RemoveElementAt(mValues.Length() - 1); michael@0: mComments.RemoveElementAt(mComments.Length() - 1); michael@0: mImages.RemoveElementAt(mImages.Length() - 1); michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: if (!mFinalCompleteValues.AppendElement(aFinalCompleteValue)) { michael@0: mValues.RemoveElementAt(mValues.Length() - 1); michael@0: mComments.RemoveElementAt(mComments.Length() - 1); michael@0: mImages.RemoveElementAt(mImages.Length() - 1); michael@0: mStyles.RemoveElementAt(mStyles.Length() - 1); michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetMatchCount(uint32_t *aMatchCount) michael@0: { michael@0: CheckInvariants(); michael@0: michael@0: *aMatchCount = mValues.Length(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetValueAt(int32_t aIndex, nsAString& _retval) michael@0: { michael@0: NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mValues.Length()), michael@0: NS_ERROR_ILLEGAL_VALUE); michael@0: CheckInvariants(); michael@0: michael@0: _retval = mValues[aIndex]; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetLabelAt(int32_t aIndex, nsAString& _retval) michael@0: { michael@0: return GetValueAt(aIndex, _retval); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetCommentAt(int32_t aIndex, nsAString& _retval) michael@0: { michael@0: NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mComments.Length()), michael@0: NS_ERROR_ILLEGAL_VALUE); michael@0: CheckInvariants(); michael@0: _retval = mComments[aIndex]; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetImageAt(int32_t aIndex, nsAString& _retval) michael@0: { michael@0: NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mImages.Length()), michael@0: NS_ERROR_ILLEGAL_VALUE); michael@0: CheckInvariants(); michael@0: _retval = mImages[aIndex]; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetStyleAt(int32_t aIndex, nsAString& _retval) michael@0: { michael@0: NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mStyles.Length()), michael@0: NS_ERROR_ILLEGAL_VALUE); michael@0: CheckInvariants(); michael@0: _retval = mStyles[aIndex]; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::GetFinalCompleteValueAt(int32_t aIndex, michael@0: nsAString& _retval) michael@0: { michael@0: NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mFinalCompleteValues.Length()), michael@0: NS_ERROR_ILLEGAL_VALUE); michael@0: CheckInvariants(); michael@0: _retval = mFinalCompleteValues[aIndex]; michael@0: if (_retval.Length() == 0) michael@0: _retval = mValues[aIndex]; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::SetListener(nsIAutoCompleteSimpleResultListener* aListener) michael@0: { michael@0: mListener = aListener; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAutoCompleteSimpleResult::RemoveValueAt(int32_t aRowIndex, michael@0: bool aRemoveFromDb) michael@0: { michael@0: NS_ENSURE_TRUE(aRowIndex >= 0 && aRowIndex < int32_t(mValues.Length()), michael@0: NS_ERROR_ILLEGAL_VALUE); michael@0: michael@0: nsAutoString removedValue(mValues[aRowIndex]); michael@0: mValues.RemoveElementAt(aRowIndex); michael@0: mComments.RemoveElementAt(aRowIndex); michael@0: mImages.RemoveElementAt(aRowIndex); michael@0: mStyles.RemoveElementAt(aRowIndex); michael@0: mFinalCompleteValues.RemoveElementAt(aRowIndex); michael@0: michael@0: if (mListener) michael@0: mListener->OnValueRemoved(this, removedValue, aRemoveFromDb); michael@0: michael@0: return NS_OK; michael@0: }