2002-04-27 11:18:22 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 2002 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
2002-05-28 13:07:53 +04:00
|
|
|
*
|
2002-04-27 11:18:22 +04:00
|
|
|
*/
|
|
|
|
|
2002-04-27 12:25:30 +04:00
|
|
|
#import <AppKit/AppKit.h>
|
2002-05-28 13:07:53 +04:00
|
|
|
#import "CHAutoCompleteTextField.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCRT.h"
|
2002-04-27 11:18:22 +04:00
|
|
|
|
|
|
|
@implementation CHAutoCompleteDataSource
|
|
|
|
|
2002-04-27 13:09:08 +04:00
|
|
|
-(id)init
|
|
|
|
{
|
|
|
|
if ((self = [super init])) {
|
2002-05-28 13:07:53 +04:00
|
|
|
mResults = nil;
|
|
|
|
mIconImage = [[NSImage imageNamed:@"globe_ico"] autorelease];
|
2002-04-27 13:09:08 +04:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2002-05-28 13:07:53 +04:00
|
|
|
-(void)dealloc
|
2002-04-27 13:09:08 +04:00
|
|
|
{
|
2002-05-28 13:07:53 +04:00
|
|
|
NS_IF_RELEASE(mResults);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setErrorMessage: (NSString*) error
|
|
|
|
{
|
|
|
|
[self setResults:nsnull];
|
|
|
|
mErrorMessage = error;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) errorMessage
|
|
|
|
{
|
|
|
|
return mErrorMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setResults:(nsIAutoCompleteResults*)aResults
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mResults);
|
|
|
|
|
|
|
|
mErrorMessage = nil;
|
|
|
|
mResults = aResults;
|
|
|
|
NS_IF_ADDREF(mResults);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (nsIAutoCompleteResults *) results
|
|
|
|
{
|
|
|
|
return mResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) rowCount
|
|
|
|
{
|
|
|
|
if (!mResults)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsArray> items;
|
|
|
|
mResults->GetItems(getter_AddRefs(items));
|
|
|
|
PRUint32 count;
|
|
|
|
items->Count(&count);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) resultString:(int)aRow column:(NSString *)aColumn
|
|
|
|
{
|
|
|
|
NSString *result = @"";
|
|
|
|
|
|
|
|
if (!mResults)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsArray> items;
|
|
|
|
mResults->GetItems(getter_AddRefs(items));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> itemSupports = dont_AddRef(items->ElementAt(aRow));
|
|
|
|
nsCOMPtr<nsIAutoCompleteItem> item = do_QueryInterface(itemSupports);
|
|
|
|
if (!item)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if ([aColumn isEqualToString:@"icon"]) {
|
|
|
|
return mIconImage;
|
|
|
|
} else if ([aColumn isEqualToString:@"col1"]) {
|
|
|
|
nsAutoString value;
|
|
|
|
item->GetValue(value);
|
|
|
|
result = [NSString stringWithCharacters:value.get() length:value.Length()];
|
|
|
|
} else if ([aColumn isEqualToString:@"col2"]) {
|
|
|
|
PRUnichar *comment;
|
|
|
|
item->GetComment(&comment);
|
|
|
|
result = [NSString stringWithCharacters:comment length:nsCRT::strlen(comment)];
|
2002-04-27 13:09:08 +04:00
|
|
|
}
|
2002-05-28 13:07:53 +04:00
|
|
|
|
|
|
|
return result;
|
2002-04-27 13:09:08 +04:00
|
|
|
}
|
|
|
|
|
2002-05-28 13:07:53 +04:00
|
|
|
-(int) numberOfRowsInTableView:(NSTableView*)aTableView
|
2002-04-27 12:25:30 +04:00
|
|
|
{
|
2002-05-28 13:07:53 +04:00
|
|
|
return [self rowCount];
|
2002-04-27 12:25:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
-(id)tableView:(NSTableView*)aTableView objectValueForTableColumn:(NSTableColumn*)aTableColumn row:(int)aRowIndex
|
|
|
|
{
|
2002-05-28 13:07:53 +04:00
|
|
|
return [self resultString:aRowIndex column:[aTableColumn identifier]];
|
2002-04-27 12:25:30 +04:00
|
|
|
}
|
|
|
|
|
2002-04-27 11:18:22 +04:00
|
|
|
@end
|