adding google search bar, from pgauria@uark.edu (bug 158246)

This commit is contained in:
pinkerton%netscape.com 2003-04-10 03:48:41 +00:00
parent 722239b743
commit d9dc9f4ffd
24 changed files with 1722 additions and 232 deletions

View File

@ -386,6 +386,7 @@
F5F190BE02D217C201026D5D,
3F22CC1303DF42A200026DCE,
F56610A1039474CB01A9666E,
3003B8AB044514E300B85BF3,
);
isa = PBXGroup;
name = Resources;
@ -734,6 +735,9 @@
F527C90403BCD43601A80166,
3F2CF8CD042A88B7005FD42F,
3F2CF8D2042A8B30005FD42F,
3003B8960445144100B85BF3,
3003B8970445144100B85BF3,
3003B8980445144100B85BF3,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -817,6 +821,12 @@
F5F415E403B97C6101A80166,
F5F7EF0F03C1F29C01BDD337,
3F22CC1503DF42A200026DCE,
3003B8A1044514B600B85BF3,
3003B8A2044514B600B85BF3,
3003B8A3044514B600B85BF3,
3003B8A4044514B600B85BF3,
3003B8A5044514B600B85BF3,
3003B8AD044514E300B85BF3,
);
isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -890,6 +900,9 @@
F527C90503BCD43601A80166,
3F2CF8CE042A88B7005FD42F,
3F2CF8D5042A8C47005FD42F,
3003B88D0445140000B85BF3,
3003B88E0445140000B85BF3,
3003B88F0445140000B85BF3,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -1012,6 +1025,258 @@
//2E2
//2E3
//2E4
//300
//301
//302
//303
//304
3003B8890445124400B85BF3 = {
children = (
3003B88A044513FF00B85BF3,
3003B88B044513FF00B85BF3,
3003B88C0445140000B85BF3,
);
isa = PBXGroup;
name = SearchTextField;
refType = 4;
};
3003B88A044513FF00B85BF3 = {
fileEncoding = 30;
isa = PBXFileReference;
name = SearchTextField.m;
path = src/browser/SearchTextField.m;
refType = 4;
};
3003B88B044513FF00B85BF3 = {
fileEncoding = 30;
isa = PBXFileReference;
name = SearchTextFieldCell.m;
path = src/browser/SearchTextFieldCell.m;
refType = 4;
};
3003B88C0445140000B85BF3 = {
fileEncoding = 30;
isa = PBXFileReference;
name = STFPopUpButtonCell.m;
path = src/browser/STFPopUpButtonCell.m;
refType = 4;
};
3003B88D0445140000B85BF3 = {
fileRef = 3003B88A044513FF00B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B88E0445140000B85BF3 = {
fileRef = 3003B88B044513FF00B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B88F0445140000B85BF3 = {
fileRef = 3003B88C0445140000B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8900445140000B85BF3 = {
fileRef = 3003B88A044513FF00B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8910445140000B85BF3 = {
fileRef = 3003B88B044513FF00B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8920445140000B85BF3 = {
fileRef = 3003B88C0445140000B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8930445144100B85BF3 = {
fileEncoding = 30;
isa = PBXFileReference;
name = SearchTextField.h;
path = src/browser/SearchTextField.h;
refType = 4;
};
3003B8940445144100B85BF3 = {
fileEncoding = 30;
isa = PBXFileReference;
name = SearchTextFieldCell.h;
path = src/browser/SearchTextFieldCell.h;
refType = 4;
};
3003B8950445144100B85BF3 = {
fileEncoding = 30;
isa = PBXFileReference;
name = STFPopUpButtonCell.h;
path = src/browser/STFPopUpButtonCell.h;
refType = 4;
};
3003B8960445144100B85BF3 = {
fileRef = 3003B8930445144100B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8970445144100B85BF3 = {
fileRef = 3003B8940445144100B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8980445144100B85BF3 = {
fileRef = 3003B8950445144100B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8990445144100B85BF3 = {
fileRef = 3003B8930445144100B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B89A0445144100B85BF3 = {
fileRef = 3003B8940445144100B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B89B0445144100B85BF3 = {
fileRef = 3003B8950445144100B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B89C044514B600B85BF3 = {
isa = PBXFileReference;
name = SearchCancel.tiff;
path = chrome/SearchCancel.tiff;
refType = 4;
};
3003B89D044514B600B85BF3 = {
isa = PBXFileReference;
name = SearchLeft.tiff;
path = chrome/SearchLeft.tiff;
refType = 4;
};
3003B89E044514B600B85BF3 = {
isa = PBXFileReference;
name = SearchMiddle.tiff;
path = chrome/SearchMiddle.tiff;
refType = 4;
};
3003B89F044514B600B85BF3 = {
isa = PBXFileReference;
name = SearchPopUp.tiff;
path = chrome/SearchPopUp.tiff;
refType = 4;
};
3003B8A0044514B600B85BF3 = {
isa = PBXFileReference;
name = SearchRight.tiff;
path = chrome/SearchRight.tiff;
refType = 4;
};
3003B8A1044514B600B85BF3 = {
fileRef = 3003B89C044514B600B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8A2044514B600B85BF3 = {
fileRef = 3003B89D044514B600B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8A3044514B600B85BF3 = {
fileRef = 3003B89E044514B600B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8A4044514B600B85BF3 = {
fileRef = 3003B89F044514B600B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8A5044514B600B85BF3 = {
fileRef = 3003B8A0044514B600B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8A6044514B600B85BF3 = {
fileRef = 3003B89C044514B600B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8A7044514B600B85BF3 = {
fileRef = 3003B89D044514B600B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8A8044514B600B85BF3 = {
fileRef = 3003B89E044514B600B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8A9044514B600B85BF3 = {
fileRef = 3003B89F044514B600B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8AA044514B600B85BF3 = {
fileRef = 3003B8A0044514B600B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8AB044514E300B85BF3 = {
children = (
3003B8AC044514E300B85BF3,
);
isa = PBXVariantGroup;
name = SearchURLList.plist;
path = "";
refType = 4;
};
3003B8AC044514E300B85BF3 = {
fileEncoding = 30;
isa = PBXFileReference;
name = English;
path = resources/localized/English.lproj/SearchURLList.plist;
refType = 4;
};
3003B8AD044514E300B85BF3 = {
fileRef = 3003B8AB044514E300B85BF3;
isa = PBXBuildFile;
settings = {
};
};
3003B8AE044514E300B85BF3 = {
fileRef = 3003B8AB044514E300B85BF3;
isa = PBXBuildFile;
settings = {
};
};
//300
//301
//302
//303
//304
//3F0
//3F1
//3F2
@ -1577,6 +1842,11 @@
F583E3B503B8204901A80166,
F583E3B603B8204901A80166,
F5F415E303B97C6101A80166,
3003B89C044514B600B85BF3,
3003B89D044514B600B85BF3,
3003B89E044514B600B85BF3,
3003B89F044514B600B85BF3,
3003B8A0044514B600B85BF3,
);
isa = PBXGroup;
name = images;
@ -1905,6 +2175,7 @@
F549ACDE0302DE6001026D5D,
F5BF71460231B8BC010001CA,
F5B950BD030C83B601A96654,
3003B8890445124400B85BF3,
F558137B030AEF9B0176F207,
);
isa = PBXGroup;
@ -2584,50 +2855,53 @@
};
F51842F30206168101A966FE = {
children = (
F59236C102C89AC90100012B,
F52D5CD3027A88C601A80166,
F52D5CCF027A887001A80166,
F53E012902AEE91C01A967F3,
F57074B9026BFD0101A80166,
3F2CF8D1042A8B30005FD42F,
F5C8D55203A2A42401A8016F,
F5F94B900332532801026D5D,
F5DE10E60209DC0601A967DF,
F517395A020CE3740189DA0C,
F528E218020FD8400168DE43,
F5DE10E70209DC0601A967DF,
F632AF8302B9AEBB01000103,
F5DE10E80209DC0601A967DF,
F558B1F0030F6E470166970F,
F51B70B6026EC98B01A80166,
F5125A110202064D01FAFD9F,
F5AE04B20206A34801A967DF,
F5AE04B60206A37C01A967DF,
F52D5CD7027D3D5001A80166,
F5A3669302CCFAF601DC3354,
F53D36BD037843C201A80166,
2EEC3E61028138714B000102,
F507BA480213AD5F01D93544,
F57074B5026BA85F01A80166,
F57074B9026BFD0101A80166,
2EEC3E61028138714B000102,
F57074BD026D80DF01A80166,
2E293A00027F33604B000102,
F5607CB5023944AD01A967DF,
F53C1CD6032FF3B301A96654,
F5BF71450231B8BC010001CA,
F5B950BC030C83B601A96654,
F632AF8302B9AEBB01000103,
F5AE04B20206A34801A967DF,
F5125A110202064D01FAFD9F,
F558B1F0030F6E470166970F,
F5DE10E80209DC0601A967DF,
F5DE10E70209DC0601A967DF,
F5C8D55203A2A42401A8016F,
F566BD1202EFA9AD01A967F3,
F59E9F3D0237E28401A967DF,
F5137A1102676B9101026D05,
F52D5CCF027A887001A80166,
F52D5CD3027A88C601A80166,
F52F87CB027D75C301A80165,
F52F87CC027D75C301A80165,
F528E218020FD8400168DE43,
F5607CB5023944AD01A967DF,
F51B70B6026EC98B01A80166,
2E748B72029A448D4B000102,
F53E012902AEE91C01A967F3,
F5A3669302CCFAF601DC3354,
F59236C102C89AC90100012B,
F50D9DE202ECC2C601BB4219,
F55C4DD302D2864D0130B065,
F5D33CBC02EF61A901A967F3,
F566BD1202EFA9AD01A967F3,
F549ACE70302DEF001026D5D,
F5581379030AEF9B0176F207,
F558137A030AEF9B0176F207,
F5B950BC030C83B601A96654,
F5BF71450231B8BC010001CA,
F53C1CD6032FF3B301A96654,
F53D36BD037843C201A80166,
F52F87CB027D75C301A80165,
F58DB2D20381FD3301A9666E,
F5F94B900332532801026D5D,
F57074BD026D80DF01A80166,
F5AE04B60206A37C01A967DF,
2E293A00027F33604B000102,
F52D5CD7027D3D5001A80166,
F517395A020CE3740189DA0C,
F52F87CC027D75C301A80165,
F5581379030AEF9B0176F207,
3003B8950445144100B85BF3,
3003B8930445144100B85BF3,
3003B8940445144100B85BF3,
F5D33CBC02EF61A901A967F3,
F558137A030AEF9B0176F207,
F549ACE70302DEF001026D5D,
F55C4DD302D2864D0130B065,
F5DE10E60209DC0601A967DF,
F50D9DE202ECC2C601BB4219,
F5C8D55503A2A43301A8016F,
);
isa = PBXGroup;
@ -4927,10 +5201,13 @@
};
F56769FB0208F74A010001CA = {
fileEncoding = 30;
indentWidth = 2;
isa = PBXFileReference;
name = BrowserWindowController.mm;
path = src/browser/BrowserWindowController.mm;
refType = 2;
tabWidth = 8;
usesTabs = 0;
};
F56769FC0208F74A010001CA = {
fileRef = F56769FB0208F74A010001CA;
@ -7009,10 +7286,13 @@
};
F5AE04BA0206A4FE01A967DF = {
fileEncoding = 30;
indentWidth = 2;
isa = PBXFileReference;
name = MainController.mm;
path = src/application/MainController.mm;
refType = 2;
tabWidth = 8;
usesTabs = 0;
};
F5AE04BB0206A4FE01A967DF = {
fileRef = F5AE04BA0206A4FE01A967DF;
@ -7471,6 +7751,9 @@
F527C90603BCD43601A80166,
3F2CF8CF042A88B7005FD42F,
3F2CF8D3042A8B30005FD42F,
3003B8990445144100B85BF3,
3003B89A0445144100B85BF3,
3003B89B0445144100B85BF3,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -7554,6 +7837,12 @@
F5F415E503B97C6101A80166,
F5F7EF1003C1F29C01BDD337,
3F22CC1403DF42A200026DCE,
3003B8A6044514B600B85BF3,
3003B8A7044514B600B85BF3,
3003B8A8044514B600B85BF3,
3003B8A9044514B600B85BF3,
3003B8AA044514B600B85BF3,
3003B8AE044514E300B85BF3,
);
isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -7628,6 +7917,9 @@
F527C90703BCD43601A80166,
3F2CF8D0042A88B7005FD42F,
3F2CF8D6042A8C47005FD42F,
3003B8900445140000B85BF3,
3003B8910445140000B85BF3,
3003B8920445140000B85BF3,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;

View File

@ -5,10 +5,10 @@
CLASS = NSPreferencePane;
LANGUAGE = ObjC;
OUTLETS = {
_firstKeyView = NSView;
_initialKeyView = NSView;
_lastKeyView = NSView;
_window = NSWindow;
"_firstKeyView" = NSView;
"_initialKeyView" = NSView;
"_lastKeyView" = NSView;
"_window" = NSWindow;
};
SUPERCLASS = NSObject;
},
@ -28,12 +28,14 @@
checkboxLoadTabsInBackground = NSButton;
checkboxNewTabBlank = NSButton;
checkboxNewWindowBlank = NSButton;
checkboxOpenTabs = NSButton;
checkboxOpenTabsForAEs = NSButton;
checkboxUseSystemHomePage = NSButton;
sliderHistoryDays = NSSlider;
mDownloadFolder = NSTextField;
mEnableHelperApps = NSButton;
radioOpenForAE = id;
radioOpenTabsForCommand = id;
textFieldHistoryDays = NSTextField;
textFieldHomePage = NSTextField;
textFieldSearchPage = NSTextField;
};
SUPERCLASS = PreferencePaneBase;
},

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>1166 344 522 320 1152 -88 1280 1024 </string>
<string>140 56 522 320 0 0 1280 1002 </string>
<key>IBFramework Version</key>
<string>248.0</string>
<string>291.0</string>
<key>IBGroupedObjects</key>
<dict>
<key>5</key>
@ -22,6 +22,6 @@
<integer>5</integer>
</array>
<key>IBSystem Version</key>
<string>5S60</string>
<string>6I32</string>
</dict>
</plist>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -86,6 +86,7 @@
bookmarkPage = id;
cancelAddBookmarkSheet = id;
cancelLocationSheet = id;
cancelSearchSheet = id;
closeCurrentTab = id;
closeOtherTabs = id;
closeSendersTab = id;
@ -94,6 +95,8 @@
copyLinkLocation = id;
endAddBookmarkSheet = id;
endLocationSheet = id;
endSearchSheet = id;
ensureBrowserVisible = id;
forward = id;
frameToNewTab = id;
frameToNewWindow = id;
@ -153,6 +156,9 @@
mPersonalToolbar = BookmarksToolbar;
mProgress = NSProgressIndicator;
mProxyIcon = PageProxyIcon;
mSearchBar = SearchTextField;
mSearchSheetTextField = SearchTextField;
mSearchSheetWindow = NSWindow;
mSidebarBookmarksDataSource = BookmarksDataSource;
mSidebarDrawer = NSDrawer;
mSidebarSourceTabView = NSTabView;
@ -198,6 +204,7 @@
SUPERCLASS = NSObject;
},
{CLASS = RDFOutlineViewItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
{CLASS = SearchTextField; LANGUAGE = ObjC; SUPERCLASS = NSTextField; },
{CLASS = ThrobberHandler; LANGUAGE = ObjC; SUPERCLASS = NSObject; }
);
IBVersion = 1;

View File

@ -23,11 +23,13 @@
<key>463</key>
<string>268 375 213 264 0 0 1280 832 </string>
<key>56</key>
<string>493 520 343 68 0 0 1280 832 </string>
<string>340 478 343 68 0 0 1024 746 </string>
<key>654</key>
<string>159 629 198 144 0 0 1280 832 </string>
<key>731</key>
<string>249 352 654 459 0 0 1152 848 </string>
<string>185 277 654 459 0 0 1024 746 </string>
<key>801</key>
<string>418 480 188 64 0 0 1024 746 </string>
</dict>
<key>IBFramework Version</key>
<string>291.0</string>
@ -43,10 +45,6 @@
<string>8</string>
<key>IBLockedObjects</key>
<array/>
<key>IBOpenObjects</key>
<array>
<integer>731</integer>
</array>
<key>IBSystem Version</key>
<string>6I32</string>
</dict>

View File

@ -9,9 +9,9 @@
<key>266</key>
<string>644 623 277 90 0 0 1600 1002 </string>
<key>29</key>
<string>191 773 433 44 0 0 1280 832 </string>
<string>133 689 433 44 0 0 1024 746 </string>
<key>494</key>
<string>569 607 185 78 0 0 1280 1002 </string>
<string>444 442 116 60 0 0 1024 746 </string>
</dict>
<key>IBFramework Version</key>
<string>291.0</string>
@ -31,6 +31,10 @@
</dict>
<key>IBLastGroupID</key>
<string>2</string>
<key>IBOpenObjects</key>
<array>
<integer>29</integer>
</array>
<key>IBSystem Version</key>
<string>6I32</string>
</dict>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Google</key>
<string>http://www.google.com/search?q=%s</string>
<key>Google Images</key>
<string>http://images.google.com/images?q=%s</string>
<key>PreferredSearchEngine</key>
<string>Google</string>
<key>Search this Site</key>
<string>http://www.google.com/search?q=%s site:%d</string>
</dict>
</plist>

View File

@ -582,17 +582,16 @@ const int kReuseWindowOnAE = 2;
-(IBAction) doSearch:(id)aSender
{
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
if (browserWindow) {
if (![browserWindow isMainWindow])
[browserWindow makeKeyAndOrderFront:self];
[[browserWindow windowController] performSearch: aSender];
}
else {
} else {
[self newWindow:self];
browserWindow = [self getFrontmostBrowserWindow];
[[browserWindow windowController] performSearch: aSender];
}
[[browserWindow windowController] performAppropriateSearchAction];
}
-(IBAction) downloadsWindow:(id)aSender

View File

@ -96,6 +96,7 @@ typedef enum
@class BrowserContentView;
@class BrowserTabViewItem;
@class AutoCompleteTextField;
@class SearchTextField;
@interface BrowserWindowController : NSWindowController<Find>
{
@ -125,6 +126,10 @@ typedef enum
IBOutlet NSPopUpButton* mAddBookmarkFolderField;
IBOutlet NSButton* mAddBookmarkCheckbox;
IBOutlet SearchTextField* mSearchBar;
IBOutlet SearchTextField* mSearchSheetTextField;
IBOutlet NSWindow* mSearchSheetWindow;
// Context menu outlets.
IBOutlet NSMenu* mPageMenu;
IBOutlet NSMenu* mImageMenu;
@ -208,6 +213,13 @@ typedef enum
- (IBAction)endLocationSheet:(id)sender;
- (IBAction)cancelLocationSheet:(id)sender;
- (void)performAppropriateSearchAction;
- (void)focusSearchBar;
- (void)beginSearchSheet;
- (IBAction)endSearchSheet:(id)sender;
- (IBAction)cancelSearchSheet:(id)sender;
- (IBAction)cancelAddBookmarkSheet:(id)sender;
- (IBAction)endAddBookmarkSheet:(id)sender;
- (void)cacheBookmarkDS:(BookmarksDataSource*)aDS;
@ -332,6 +344,9 @@ typedef enum
+ (NSImage*) secureIcon;
+ (NSImage*) brokenIcon;
// cache the search engines and their search strings we parse from a plist
+ (NSDictionary *)searchURLDictionary;
// cache the toolbar defaults we parse from a plist
+ (NSArray*) toolbarDefaults;

View File

@ -49,6 +49,9 @@
#import "PageProxyIcon.h"
#import "AutoCompleteTextField.h"
#import "BookmarksController.h"
#import "SearchTextField.h"
#import "SearchTextFieldCell.h"
#import "STFPopUpButtonCell.h"
#include "nsIWebNavigation.h"
#include "nsIDOMDocument.h"
@ -65,6 +68,7 @@
#include "GeckoUtils.h"
#include "nsIWebProgressListener.h"
#include "nsIWebBrowserChrome.h"
#include "nsNetUtil.h"
#include "nsIClipboardCommands.h"
#include "nsICommandManager.h"
@ -355,7 +359,7 @@ static NSArray* sToolbarDefaults = nil;
// [mSidebarBrowserView windowClosed];
[mProgress release];
[mSearchBar release];
[self stopThrobber];
[mThrobberImages release];
[mURLFieldEditor release];
@ -401,6 +405,24 @@ static NSArray* sToolbarDefaults = nil;
[mStatus setDrawsBackground:YES];
}
// Set up the toolbar's search text field
NSMutableArray *searchTitles =
[NSMutableArray arrayWithArray:[[[BrowserWindowController searchURLDictionary] allKeys] sortedArrayUsingSelector:@selector(compare:)]];
[searchTitles removeObject:@"PreferredSearchEngine"];
[mSearchBar addPopUpMenuItemsWithTitles:searchTitles];
[[[mSearchBar cell] popUpButtonCell] selectItemWithTitle:
[[BrowserWindowController searchURLDictionary] objectForKey:@"PreferredSearchEngine"]];
[mSearchBar retain];
[mSearchBar removeFromSuperview];
// Set the sheet's search text field
[mSearchSheetTextField addPopUpMenuItemsWithTitles:searchTitles];
[[[mSearchSheetTextField cell] popUpButtonCell] selectItemWithTitle:
[[BrowserWindowController searchURLDictionary] objectForKey:@"PreferredSearchEngine"]];
// Get our saved dimensions.
NSRect oldFrame = [[self window] frame];
[[self window] setFrameUsingName: NavigatorWindowFrameSaveName];
@ -659,174 +681,184 @@ static NSArray* sToolbarDefaults = nil;
itemForItemIdentifier:(NSString *)itemIdent
willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
if ( [itemIdent isEqual:BackToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Back", @"Back")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Go Back", @"Go Back")];
[toolbarItem setToolTip:NSLocalizedString(@"BackToolTip", @"Go back one page")];
[toolbarItem setImage:[NSImage imageNamed:@"back"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(back:)];
}
else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Forward", @"Forward")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Go Forward", @"Go Forward")];
[toolbarItem setToolTip:NSLocalizedString(@"ForwardToolTip", @"Go forward one page")];
[toolbarItem setImage:[NSImage imageNamed:@"forward"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(forward:)];
}
else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Reload", @"Reload")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Reload Page", @"Reload Page")];
[toolbarItem setToolTip:NSLocalizedString(@"ReloadToolTip", @"Reload current page")];
[toolbarItem setImage:[NSImage imageNamed:@"reload"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(reload:)];
}
else if ( [itemIdent isEqual:StopToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Stop", @"Stop")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Stop Loading", @"Stop Loading")];
[toolbarItem setToolTip:NSLocalizedString(@"StopToolTip", @"Stop loading this page")];
[toolbarItem setImage:[NSImage imageNamed:@"stop"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(stop:)];
}
else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Home", @"Home")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Go Home", @"Go Home")];
[toolbarItem setToolTip:NSLocalizedString(@"HomeToolTip", @"Go to home page")];
[toolbarItem setImage:[NSImage imageNamed:@"home"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(home:)];
}
else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Sidebar", @"Sidebar")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toggle Sidebar", @"Toggle Sidebar")];
[toolbarItem setToolTip:NSLocalizedString(@"SidebarToolTip", @"Show or hide the Sidebar")];
[toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleSidebar:)];
}
else if ( [itemIdent isEqual:SearchToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Search", @"Search")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Search", @"Search")];
[toolbarItem setToolTip:NSLocalizedString(@"SearchToolTip", @"Search the Internet")];
[toolbarItem setImage:[NSImage imageNamed:@"searchWeb.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(performSearch:)];
}
else if ( [itemIdent isEqual:ThrobberToolbarItemIdentifier] )
{
[toolbarItem setLabel:@""];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Progress", @"Progress")];
[toolbarItem setToolTip:NSLocalizedStringFromTable(@"ThrobberPageDefault", @"WebsiteDefaults", nil)];
[toolbarItem setImage:[NSImage imageNamed:@"throbber-01"]];
[toolbarItem setTarget:self];
[toolbarItem setTag:'Thrb'];
[toolbarItem setAction:@selector(clickThrobber:)];
}
else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] )
{
NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
[toolbarItem setLabel:NSLocalizedString(@"Location", @"Location")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Location", @"Location")];
[toolbarItem setView:mLocationToolbarView];
[toolbarItem setMinSize:NSMakeSize(128,20)];
[toolbarItem setMaxSize:NSMakeSize(2560,32)];
[menuFormRep setTarget:self];
[menuFormRep setAction:@selector(performAppropriateLocationAction)];
[menuFormRep setTitle:[toolbarItem label]];
[toolbarItem setMenuFormRepresentation:menuFormRep];
}
else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Print", @"Print")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Print", @"Print")];
[toolbarItem setToolTip:NSLocalizedString(@"PrintToolTip", @"Print this page")];
[toolbarItem setImage:[NSImage imageNamed:@"print"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(printDocument:)];
}
else if ( [itemIdent isEqual:ViewSourceToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"View Source", @"View Source")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"View Page Source", @"View Page Source")];
[toolbarItem setToolTip:NSLocalizedString(@"ViewSourceToolTip", @"Display the HTML source of this page")];
[toolbarItem setImage:[NSImage imageNamed:@"showsource"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(viewSource:)];
}
else if ( [itemIdent isEqual:BookmarkToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Bookmark", @"Bookmark")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Bookmark Page", @"Bookmark Page")];
[toolbarItem setToolTip:NSLocalizedString(@"BookmarkToolTip", @"Add this page to your bookmarks")];
[toolbarItem setImage:[NSImage imageNamed:@"add_to_bookmark.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(bookmarkPage:)];
}
else if ( [itemIdent isEqual:TextBiggerToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"BigText", @"Enlarge Text")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"BigText", @"Enlarge Text")];
[toolbarItem setToolTip:NSLocalizedString(@"BigTextToolTip", @"Enlarge the text on this page")];
[toolbarItem setImage:[NSImage imageNamed:@"textBigger.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(biggerTextSize:)];
}
else if ( [itemIdent isEqual:TextSmallerToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"SmallText", @"Shrink Text")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"SmallText", @"Shrink Text")];
[toolbarItem setToolTip:NSLocalizedString(@"SmallTextToolTip", @"Shrink the text on this page")];
[toolbarItem setImage:[NSImage imageNamed:@"textSmaller.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(smallerTextSize:)];
}
else if ( [itemIdent isEqual:NewTabToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"NewTab", @"New Tab")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"NewTab", @"New Tab")];
[toolbarItem setToolTip:NSLocalizedString(@"NewTabToolTip", @"Create a new tab")];
[toolbarItem setImage:[NSImage imageNamed:@"newTab.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(newTab:)];
}
else if ( [itemIdent isEqual:CloseTabToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"CloseTab", @"Close Tab")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"CloseTab", @"Close Tab")];
[toolbarItem setToolTip:NSLocalizedString(@"CloseTabToolTip", @"Close the current tab")];
[toolbarItem setImage:[NSImage imageNamed:@"closeTab.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(closeCurrentTab:)];
}
else if ( [itemIdent isEqual:SendURLToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"SendLink", @"Send Link")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"SendLink", @"Send Link")];
[toolbarItem setToolTip:NSLocalizedString(@"SendLinkToolTip", @"Send current URL")];
[toolbarItem setImage:[NSImage imageNamed:@"sendLink.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(sendURL:)];
}
else
{
toolbarItem = nil;
}
return toolbarItem;
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
if ( [itemIdent isEqual:BackToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Back", @"Back")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Go Back", @"Go Back")];
[toolbarItem setToolTip:NSLocalizedString(@"BackToolTip", @"Go back one page")];
[toolbarItem setImage:[NSImage imageNamed:@"back"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(back:)];
}
else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Forward", @"Forward")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Go Forward", @"Go Forward")];
[toolbarItem setToolTip:NSLocalizedString(@"ForwardToolTip", @"Go forward one page")];
[toolbarItem setImage:[NSImage imageNamed:@"forward"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(forward:)];
}
else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Reload", @"Reload")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Reload Page", @"Reload Page")];
[toolbarItem setToolTip:NSLocalizedString(@"ReloadToolTip", @"Reload current page")];
[toolbarItem setImage:[NSImage imageNamed:@"reload"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(reload:)];
}
else if ( [itemIdent isEqual:StopToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Stop", @"Stop")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Stop Loading", @"Stop Loading")];
[toolbarItem setToolTip:NSLocalizedString(@"StopToolTip", @"Stop loading this page")];
[toolbarItem setImage:[NSImage imageNamed:@"stop"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(stop:)];
}
else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Home", @"Home")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Go Home", @"Go Home")];
[toolbarItem setToolTip:NSLocalizedString(@"HomeToolTip", @"Go to home page")];
[toolbarItem setImage:[NSImage imageNamed:@"home"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(home:)];
}
else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Sidebar", @"Sidebar")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toggle Sidebar", @"Toggle Sidebar")];
[toolbarItem setToolTip:NSLocalizedString(@"SidebarToolTip", @"Show or hide the Sidebar")];
[toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleSidebar:)];
}
else if ( [itemIdent isEqual:SearchToolbarItemIdentifier] )
{
NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
[toolbarItem setLabel:NSLocalizedString(@"Search", @"Search")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Search", @"Search")];
[toolbarItem setToolTip:NSLocalizedString(@"SearchToolTip", @"Search the Internet")];
[toolbarItem setView:mSearchBar];
[toolbarItem setMinSize:NSMakeSize(128, NSHeight([mSearchBar frame]))];
[toolbarItem setMaxSize:NSMakeSize(150, NSHeight([mSearchBar frame]))];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(performSearch:)];
[menuFormRep setTarget:self];
[menuFormRep setAction:@selector(beginSearchSheet)];
[menuFormRep setTitle:[toolbarItem label]];
[toolbarItem setMenuFormRepresentation:menuFormRep];
}
else if ( [itemIdent isEqual:ThrobberToolbarItemIdentifier] )
{
[toolbarItem setLabel:@""];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Progress", @"Progress")];
[toolbarItem setToolTip:NSLocalizedStringFromTable(@"ThrobberPageDefault", @"WebsiteDefaults", nil)];
[toolbarItem setImage:[NSImage imageNamed:@"throbber-01"]];
[toolbarItem setTarget:self];
[toolbarItem setTag:'Thrb'];
[toolbarItem setAction:@selector(clickThrobber:)];
}
else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] )
{
NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
[toolbarItem setLabel:NSLocalizedString(@"Location", @"Location")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Location", @"Location")];
[toolbarItem setView:mLocationToolbarView];
[toolbarItem setMinSize:NSMakeSize(128,20)];
[toolbarItem setMaxSize:NSMakeSize(2560,32)];
[menuFormRep setTarget:self];
[menuFormRep setAction:@selector(performAppropriateLocationAction)];
[menuFormRep setTitle:[toolbarItem label]];
[toolbarItem setMenuFormRepresentation:menuFormRep];
}
else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Print", @"Print")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Print", @"Print")];
[toolbarItem setToolTip:NSLocalizedString(@"PrintToolTip", @"Print this page")];
[toolbarItem setImage:[NSImage imageNamed:@"print"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(printDocument:)];
}
else if ( [itemIdent isEqual:ViewSourceToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"View Source", @"View Source")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"View Page Source", @"View Page Source")];
[toolbarItem setToolTip:NSLocalizedString(@"ViewSourceToolTip", @"Display the HTML source of this page")];
[toolbarItem setImage:[NSImage imageNamed:@"showsource"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(viewSource:)];
}
else if ( [itemIdent isEqual:BookmarkToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"Bookmark", @"Bookmark")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Bookmark Page", @"Bookmark Page")];
[toolbarItem setToolTip:NSLocalizedString(@"BookmarkToolTip", @"Add this page to your bookmarks")];
[toolbarItem setImage:[NSImage imageNamed:@"add_to_bookmark.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(bookmarkPage:)];
}
else if ( [itemIdent isEqual:TextBiggerToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"BigText", @"Enlarge Text")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"BigText", @"Enlarge Text")];
[toolbarItem setToolTip:NSLocalizedString(@"BigTextToolTip", @"Enlarge the text on this page")];
[toolbarItem setImage:[NSImage imageNamed:@"textBigger.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(biggerTextSize:)];
}
else if ( [itemIdent isEqual:TextSmallerToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"SmallText", @"Shrink Text")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"SmallText", @"Shrink Text")];
[toolbarItem setToolTip:NSLocalizedString(@"SmallTextToolTip", @"Shrink the text on this page")];
[toolbarItem setImage:[NSImage imageNamed:@"textSmaller.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(smallerTextSize:)];
}
else if ( [itemIdent isEqual:NewTabToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"NewTab", @"New Tab")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"NewTab", @"New Tab")];
[toolbarItem setToolTip:NSLocalizedString(@"NewTabToolTip", @"Create a new tab")];
[toolbarItem setImage:[NSImage imageNamed:@"newTab.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(newTab:)];
}
else if ( [itemIdent isEqual:CloseTabToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"CloseTab", @"Close Tab")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"CloseTab", @"Close Tab")];
[toolbarItem setToolTip:NSLocalizedString(@"CloseTabToolTip", @"Close the current tab")];
[toolbarItem setImage:[NSImage imageNamed:@"closeTab.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(closeCurrentTab:)];
}
else if ( [itemIdent isEqual:SendURLToolbarItemIdentifier] )
{
[toolbarItem setLabel:NSLocalizedString(@"SendLink", @"Send Link")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"SendLink", @"Send Link")];
[toolbarItem setToolTip:NSLocalizedString(@"SendLinkToolTip", @"Send current URL")];
[toolbarItem setImage:[NSImage imageNamed:@"sendLink.tif"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(sendURL:)];
}
else
{
toolbarItem = nil;
}
return toolbarItem;
}
// This method handles the enabling/disabling of the toolbar buttons.
@ -938,6 +970,59 @@ static NSArray* sToolbarDefaults = nil;
[NSApp endSheet:mLocationSheetWindow returnCode:0];
}
- (void)performAppropriateSearchAction
{
NSToolbar *toolbar = [[self window] toolbar];
if ( [toolbar isVisible] )
{
if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) )
{
NSArray *itemsWeCanSee = [toolbar visibleItems];
for (unsigned int i = 0; i < [itemsWeCanSee count]; i++)
{
if ([[[itemsWeCanSee objectAtIndex:i] itemIdentifier] isEqual:SearchToolbarItemIdentifier])
{
[self focusSearchBar];
return;
}
}
}
}
[self beginSearchSheet];
}
- (void)focusSearchBar
{
[[mBrowserView getBrowserView] setActive:NO];
[mSearchBar selectText:self];
}
- (void)beginSearchSheet
{
[NSApp beginSheet: mSearchSheetWindow
modalForWindow: [self window]
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
}
- (IBAction)endSearchSheet:(id)sender
{
[mSearchSheetWindow orderOut:self];
[NSApp endSheet:mSearchSheetWindow returnCode:1];
[self performSearch:mSearchSheetTextField];
}
- (IBAction)cancelSearchSheet:(id)sender
{
[mSearchSheetWindow orderOut:self];
[NSApp endSheet:mSearchSheetWindow returnCode:0];
}
-(IBAction)cancelAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
@ -1072,7 +1157,72 @@ static NSArray* sToolbarDefaults = nil;
- (IBAction)performSearch:(id)aSender
{
[mBrowserView loadURI:[[PreferenceManager sharedInstance] searchPage] referrer: nil flags:NSLoadFlagsNone activate:NO];
// If we have a valid SearchTextField, perform a search using its contents
if ([aSender isKindOfClass:[SearchTextField class]]) {
// Get the search URL from our dictionary of sites and search urls
NSMutableString *searchURL = [NSMutableString stringWithString:
[[BrowserWindowController searchURLDictionary] objectForKey:
[aSender titleOfSelectedPopUpItem]]];
NSString *currentURL = [[self getBrowserWrapper] getCurrentURLSpec];
const char *aURLSpec = [currentURL lossyCString];
NSString *aDomain;
nsIURI *aURI;
// If we have an about: type URL, remove " site:%d" from the search string
// This is a fix to deal with Google's Search this Site feature
// If other sites use %d to search the site, we'll have to have specific rules
// for those sites.
if ([currentURL hasPrefix:@"about:"]) {
NSRange domainStringRange = [searchURL rangeOfString:@" site:%d"
options:NSBackwardsSearch];
if (NSEqualRanges(domainStringRange, NSMakeRange(NSNotFound, 0)) == NO)
[searchURL deleteCharactersInRange:domainStringRange];
}
// If they didn't type anything in the search field, visit the domain of
// the search site, i.e. www.google.com for the Google site
if ([[aSender stringValue] isEqualToString:@""]) {
aURLSpec = [searchURL lossyCString];
if (NS_NewURI(&aURI, aURLSpec, nsnull, nsnull) == NS_OK) {
nsCAutoString spec;
aURI->GetHost(spec);
aDomain = [NSString stringWithUTF8String:spec.get()];
[self loadURL:aDomain referrer:nil activate:NO];
}
} else {
aURLSpec = [[[self getBrowserWrapper] getCurrentURLSpec] lossyCString];
// Get the domain so that we can replace %d in our searchURL
if (NS_NewURI(&aURI, aURLSpec, nsnull, nsnull) == NS_OK) {
nsCAutoString spec;
aURI->GetHost(spec);
aDomain = [NSString stringWithUTF8String:spec.get()];
}
// Replace any occurence of %d in the search URL with the current domain
[searchURL replaceOccurrencesOfString:@"%d"
withString:aDomain
options:NSBackwardsSearch
range:NSMakeRange(0, [searchURL length])];
// Replace any occurence of %s in the search URL with the
// contents of the search text field
[searchURL replaceOccurrencesOfString:@"%s"
withString:[aSender stringValue]
options:NSBackwardsSearch
range:NSMakeRange(0, [searchURL length])];
[self loadURL:searchURL referrer:nil activate:NO];
}
}
}
- (IBAction)sendURL:(id)aSender
@ -2118,6 +2268,20 @@ static NSArray* sToolbarDefaults = nil;
return sBrokenIcon;
}
+ (NSDictionary *)searchURLDictionary
{
static NSDictionary *searchURLDictionary = nil;
if (searchURLDictionary == nil)
searchURLDictionary = [[NSDictionary alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"SearchURLList" ofType:@"plist"]];
return searchURLDictionary;
}
- (void) focusChangedFrom:(NSResponder*) oldResponder to:(NSResponder*) newResponder
{
BOOL oldResponderIsGecko = [self isResponderGeckoView:oldResponder];

View File

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Prachi Gauriar
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Prachi Gauriar (pgauria@uark.edu)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <AppKit/AppKit.h>
@interface STFPopUpButtonCell : NSPopUpButtonCell
{
}
- (void)addItemWithTitle:(NSString *)itemTitle;
- (void)addItemsWithTitles:(NSArray *)itemTitles;
- (void)insertItemWithTitle:(NSString *)itemTitle atIndex:(int)index;
- (void)selectItem:(NSMenuItem *)anItem;
- (void)selectItemAtIndex:(int)index;
- (void)selectItemWithTitle:(NSString *)title;
@end

View File

@ -0,0 +1,135 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 SearchTextField UI code.
*
* The Initial Developer of the Original Code is
* Prachi Gauriar
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Prachi Gauriar (pgauria@uark.edu)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "STFPopUpButtonCell.h"
@interface STFPopUpButtonCell(PrivateMethods)
- (void)_searchTextFieldPopUpCellButtonSelectionChanged:(id)sender;
@end
@implementation STFPopUpButtonCell
- (void)addItemWithTitle:(NSString *)itemTitle
{
NSMenuItem *aMenuItem;
[super addItemWithTitle:itemTitle];
aMenuItem = [self itemWithTitle:itemTitle];
[aMenuItem setTarget:self];
[aMenuItem setAction:@selector(_searchTextFieldPopUpCellButtonSelectionChanged:)];
}
- (void)addItemsWithTitles:(NSArray *)itemTitles
{
NSEnumerator *itemTitleEnumerator = [itemTitles objectEnumerator];
NSString *anItemTitle;
NSMenuItem *aMenuItem;
[super addItemsWithTitles:itemTitles];
while ((anItemTitle = [itemTitleEnumerator nextObject])) {
aMenuItem = [self itemWithTitle:anItemTitle];
[aMenuItem setTarget:self];
[aMenuItem setAction:@selector(_searchTextFieldPopUpCellButtonSelectionChanged:)];
}
}
- (void)insertItemWithTitle:(NSString *)itemTitle atIndex:(int)index
{
NSMenuItem *aMenuItem;
[super insertItemWithTitle:itemTitle atIndex:index];
aMenuItem = [self itemWithTitle:itemTitle];
[aMenuItem setTarget:self];
[aMenuItem setAction:@selector(_searchTextFieldPopUpCellButtonSelectionChanged:)];
}
- (void)selectItem:(NSMenuItem *)anItem
{
NSMenuItem *oldItem = [self selectedItem];
[oldItem setState:NSOffState];
[anItem setState:NSOnState];
[super selectItem:anItem];
}
- (void)selectItemAtIndex:(int)index
{
if (index >= 0 && index < [self numberOfItems]) {
NSMenuItem *oldItem = [self selectedItem];
[oldItem setState:NSOffState];
[[self itemAtIndex:index] setState:NSOnState];
}
[super selectItemAtIndex:index];
}
- (void)selectItemWithTitle:(NSString *)title
{
NSMenuItem *oldItem = [self selectedItem];
NSMenuItem *newItem = [self itemWithTitle:title];
[oldItem setState:NSOffState];
[newItem setState:NSOnState];
[super selectItemWithTitle:title];
}
@end
@implementation STFPopUpButtonCell(PrivateMethods)
- (void)_searchTextFieldPopUpCellButtonSelectionChanged:(id)sender
{
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter postNotificationName:@"STFPopUpButtonCellSelectionChanged"
object:self
userInfo:nil];
}
@end

View File

@ -0,0 +1,66 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 SearchTextField UI code.
*
* The Initial Developer of the Original Code is
* Prachi Gauriar
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Prachi Gauriar (pgauria@uark.edu)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <AppKit/AppKit.h>
@class SearchTextFieldCell;
@interface SearchTextField : NSTextField
{
}
+ (Class)cellClass;
- (void)awakeFromNib;
- (void)mouseDown:(NSEvent *)theEvent;
- (void)resetCursorRects;
- (BOOL)isFirstResponder;
- (BOOL)becomeFirstResponder;
- (void)selectText:(id)sender;
- (NSString *)titleOfSelectedPopUpItem;
// Use this method to add menu items to the list
// If you need to access menu items, message the control's cell
// DO NOT EVER ACCESS THE MENU ITEM AT INDEX 0
// IT IS A BLANK ITEM REQUIRED SO THAT THE MENU
// DISPLAYS CORRECTLY
- (void)addPopUpMenuItemsWithTitles:(NSArray *)itemTitles;
@end

View File

@ -0,0 +1,213 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 SearchTextField UI code.
*
* The Initial Developer of the Original Code is
* Prachi Gauriar
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Prachi Gauriar (pgauria@uark.edu)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "STFPopUpButtonCell.h"
#import "SearchTextFieldCell.h"
#import "SearchTextField.h"
@implementation SearchTextField
+ (Class)cellClass
{
return [SearchTextFieldCell class];
}
- (void)awakeFromNib
{
[self setCell:[[[SearchTextFieldCell alloc] initTextCell:@""] autorelease]];
}
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint pointInField = [self convertPoint:[theEvent locationInWindow] fromView:nil];
NSRect cellFrame = [self convertRect:[self frame] fromView:[self superview]];
if (NSMouseInRect(pointInField, [[self cell] cancelButtonRectFromRect:cellFrame], NO))
[[self cell] cancelButtonClickedWithFrame:cellFrame inView:self];
else if (NSMouseInRect(pointInField, [[self cell] popUpButtonRectFromRect:cellFrame], NO))
[[self cell] popUpButtonClickedWithFrame:cellFrame inView:self];
}
// Do not remove. This method must be empty to setup cursor rects properly
- (void)resetCursorRects
{
}
- (BOOL)isFirstResponder
{
NSResponder *first = ([self window] != nil) ? [[self window] firstResponder] : nil;
while (first != nil && [first isKindOfClass:[NSView class]]) {
first = [first superview];
if (first == self)
return YES;
}
return NO;
}
- (BOOL)becomeFirstResponder
{
if ([[self textColor] isEqualTo:[NSColor disabledControlTextColor]]) {
[self setTextColor:[NSColor controlTextColor]];
[self setStringValue:@""];
}
return [super becomeFirstResponder];
}
- (void)selectText:(id)sender
{
if ([[self textColor] isEqualTo:[NSColor disabledControlTextColor]]) {
[self setTextColor:[NSColor controlTextColor]];
[self setStringValue:@""];
}
return [super selectText:sender];
}
- (void)textDidChange:(NSNotification *)aNotification
{
[[self cell] searchSubmittedFromView:self];
}
- (NSString *)titleOfSelectedPopUpItem
{
return [[[self cell] popUpButtonCell] titleOfSelectedItem];
}
// This method completely overrides NSTextField's textDidEndEditing: method
// No call to the superclass is made. Check NSTextField docs to see requirements
// of this method
// This code is a modified form of the method of same name at:
// http://s.sudre.free.fr/Software/Source/WBSearchTextField.m
- (void)textDidEndEditing:(NSNotification *)aNotification
{
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
id cell = [self cell];
BOOL showGreyText = YES;
NSFormatter *formatter = [cell formatter];
NSString *string = [[[[[self window] fieldEditor:YES forObject:self] string] copy] autorelease];
NSMutableDictionary *userInfo;
NSNumber *textMovement;
if (formatter == nil)
[cell setStringValue:string];
else {
// If we have a special formatter, transform our string based on that method
id newObjectValue;
NSString *error;
SEL controlFailedMethod = @selector(control:didFailToFormatString:errorDescription:);
if ([formatter getObjectValue:&newObjectValue forString:string errorDescription:&error])
[cell setObjectValue:newObjectValue];
else if ([[self delegate] respondsToSelector:controlFailedMethod] &&
[[self delegate] control:self didFailToFormatString:string
errorDescription:error])
[cell setStringValue:string];
}
[cell endEditing:[aNotification object]];
// Get information from the notifcation dictionary so that we can decide
// what to do in response to the user's action
userInfo = [[NSMutableDictionary alloc] initWithDictionary:[aNotification userInfo]];
[userInfo setObject:[aNotification object] forKey:@"NSFieldEditor"];
[defaultCenter postNotificationName:NSControlTextDidEndEditingNotification
object:self
userInfo:userInfo];
textMovement = [[aNotification userInfo] objectForKey:@"NSTextMovement"];
if (textMovement) {
switch ([(NSNumber *)textMovement intValue]) {
// If the user hit enter, send our action to our target
case NSReturnTextMovement:
[[self cell] searchSubmittedFromView:self];
if ([self sendAction:[self action] to:[self target]] == NO) {
NSEvent *event = [[self window] currentEvent];
if ([self performKeyEquivalent:event] == NO &&
[[self window] performKeyEquivalent:event] == NO)
[self selectText:self];
}
break;
// If the user hit tab, go to the next key view
case NSTabTextMovement:
[[self window] selectKeyViewFollowingView:self];
if ([[self window] firstResponder] == [self window])
[self selectText:self];
break;
// If the user hit shift-tab, go to the key view before us
case NSBacktabTextMovement:
[[self window] selectKeyViewPrecedingView:self];
if ([[self window] firstResponder] == [self window])
[self selectText:self];
break;
default:
if ([self isFirstResponder])
showGreyText = NO;
}
}
[cell showSelectedPopUpItem:showGreyText];
}
- (void)addPopUpMenuItemsWithTitles:(NSArray *)itemTitles
{
[[[self cell] popUpButtonCell] addItemsWithTitles:itemTitles];
}
@end

View File

@ -0,0 +1,90 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 SearchTextField UI code.
*
* The Initial Developer of the Original Code is
* Prachi Gauriar
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Prachi Gauriar (pgauria@uark.edu)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// DO NOT EVER ACCESS THE MENU ITEM AT INDEX 0
// IT IS A BLANK ITEM REQUIRED SO THAT THE MENU
// DISPLAYS CORRECTLY
#import <AppKit/AppKit.h>
@class STFPopUpButtonCell;
@interface SearchTextFieldCell : NSTextFieldCell
{
BOOL hasPopUpButton;
STFPopUpButtonCell *popUpButtonCell;
NSImage *_leftImage;
NSImage *_middleImage;
NSImage *_rightImage;
NSImage *_popUpImage;
NSImage *_cancelImage;
BOOL _shouldShowCancelButton;
BOOL _shouldShowSelectedPopUpItem;
}
- (id)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
- (id)initTextCell:(NSString *)aString;
- (void)dealloc;
- (BOOL)hasPopUpButton;
- (void)setHasPopUpButton:(BOOL)aBoolean;
- (STFPopUpButtonCell *)popUpButtonCell;
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj
delegate:(id)anObject event:(NSEvent *)theEvent;
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj
delegate:(id)anObject start:(int)selStart length:(int)selLength;
- (void)cancelButtonClickedWithFrame:(NSRect)aFrame inView:(NSView *)aView;
- (void)popUpButtonClickedWithFrame:(NSRect)aFrame inView:(NSView *)aView;
- (void)searchSubmittedFromView:(NSView *)controlView;
- (void)showSelectedPopUpItem:(BOOL)shouldShow;
- (NSBezierPath *)fieldOutlinePathForRect:(NSRect)aRect;
- (NSRect)cancelButtonRectFromRect:(NSRect)aRect;
- (NSRect)popUpButtonRectFromRect:(NSRect)aRect;
- (NSRect)textFieldRectFromRect:(NSRect)aRect;
@end

View File

@ -0,0 +1,439 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 SearchTextField UI code.
*
* The Initial Developer of the Original Code is
* Prachi Gauriar
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Prachi Gauriar (pgauria@uark.edu)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "STFPopUpButtonCell.h"
#import "SearchTextFieldCell.h"
const float STFSymbolXOffset = 4.0;
const float STFSymbolYOffset = 4.0;
@interface SearchTextFieldCell(PrivateMethods)
+ (NSImage *)cachedLeftImage;
+ (NSImage *)cachedMiddleImage;
+ (NSImage *)cachedRightImage;
+ (NSImage *)cachedPopUpImage;
+ (NSImage *)cachedCancelImage;
@end
@implementation SearchTextFieldCell
- (id)initWithCoder:(NSCoder *)coder
{
[super initWithCoder:coder];
[coder decodeValueOfObjCType:@encode(BOOL) at:&hasPopUpButton];
popUpButtonCell = [[coder decodeObject] retain];
_leftImage = [[coder decodeObject] retain];
_middleImage = [[coder decodeObject] retain];
_rightImage = [[coder decodeObject] retain];
_popUpImage = [[coder decodeObject] retain];
_cancelImage = [[coder decodeObject] retain];
[coder decodeValueOfObjCType:@encode(BOOL) at:&_shouldShowCancelButton];
[coder decodeValueOfObjCType:@encode(BOOL) at:&_shouldShowSelectedPopUpItem];
[self setStringValue:[coder decodeObject]];
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[super encodeWithCoder:coder];
[coder encodeValueOfObjCType:@encode(BOOL) at:&hasPopUpButton];
[coder encodeObject:popUpButtonCell];
[coder encodeObject:_leftImage];
[coder encodeObject:_middleImage];
[coder encodeObject:_rightImage];
[coder encodeObject:_popUpImage];
[coder encodeObject:_cancelImage];
[coder encodeValueOfObjCType:@encode(BOOL) at:&_shouldShowCancelButton];
[coder encodeValueOfObjCType:@encode(BOOL) at:&_shouldShowSelectedPopUpItem];
[coder encodeObject:[self stringValue]];
}
- (id)initTextCell:(NSString *)aString
{
[super initTextCell:aString];
_leftImage = [[SearchTextFieldCell cachedLeftImage] copy];
_middleImage = [[SearchTextFieldCell cachedMiddleImage] copy];
_rightImage = [[SearchTextFieldCell cachedRightImage] copy];
_popUpImage = [[SearchTextFieldCell cachedPopUpImage] copy];
_cancelImage = [[SearchTextFieldCell cachedCancelImage] copy];
hasPopUpButton = YES;
_shouldShowCancelButton = NO;
_shouldShowSelectedPopUpItem = YES;
popUpButtonCell = [[STFPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES];
[popUpButtonCell addItemWithTitle:@""];
[self setEditable:YES];
[self setScrollable:YES];
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[popUpButtonCell release];
[_leftImage release];
[_rightImage release];
[_middleImage release];
[_popUpImage release];
[_cancelImage release];
[super dealloc];
}
- (BOOL)hasPopUpButton
{
return hasPopUpButton;
}
- (void)setHasPopUpButton:(BOOL)aBoolean
{
hasPopUpButton = aBoolean;
}
- (STFPopUpButtonCell *)popUpButtonCell
{
if (hasPopUpButton)
return popUpButtonCell;
else
return nil;
}
- (void)showSelectedPopUpItem:(BOOL)shouldShow
{
NSString *newTitle = [[self popUpButtonCell] titleOfSelectedItem];
if (shouldShow && _shouldShowSelectedPopUpItem) {
if (hasPopUpButton && newTitle && [[self stringValue] isEqualToString:@""]) {
[self setTextColor:[NSColor disabledControlTextColor]];
[self setStringValue:newTitle];
}
} else
[self setTextColor:[NSColor controlTextColor]];
_shouldShowSelectedPopUpItem = shouldShow;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSPoint _leftImageOrigin, _middleImageOrigin, _rightImageOrigin;
NSPoint _popUpImageOrigin, _cancelImageOrigin;
float _middleImageWidth;
BOOL wasShowingFirstResponder = [self showsFirstResponder];
// Draw the left end of the widget
_leftImageOrigin = cellFrame.origin;
_leftImageOrigin.y += [_leftImage size].height;
[_leftImage compositeToPoint:_leftImageOrigin operation:NSCompositeSourceOver];
// Draw the right end of the widget
_rightImageOrigin = cellFrame.origin;
_rightImageOrigin.x += cellFrame.size.width - [_rightImage size].width;
_rightImageOrigin.y += [_rightImage size].height;
[_rightImage compositeToPoint:_rightImageOrigin operation:NSCompositeSourceOver];
// Draw the middle section
_middleImageOrigin = cellFrame.origin;
_middleImageOrigin.x += [_leftImage size].width;
_middleImageOrigin.y += [_middleImage size].height;
_middleImageWidth = cellFrame.size.width - ([_leftImage size].width + [_rightImage size].width);
[_middleImage setSize:NSMakeSize(_middleImageWidth, [_middleImage size].height)];
[_middleImage compositeToPoint:_middleImageOrigin operation:NSCompositeSourceOver];
// If we have a popUp button, draw it on the widget
if (hasPopUpButton) {
_popUpImageOrigin = cellFrame.origin;
_popUpImageOrigin.x += STFSymbolXOffset;
_popUpImageOrigin.y += [_popUpImage size].height + STFSymbolXOffset;
[_popUpImage compositeToPoint:_popUpImageOrigin operation:NSCompositeSourceOver];
}
// If we should show the cancel button, draw the button in the proper rect
if (_shouldShowCancelButton) {
_cancelImageOrigin = cellFrame.origin;
_cancelImageOrigin.x += cellFrame.size.width - [_cancelImage size].width -
STFSymbolXOffset;
_cancelImageOrigin.y += [_cancelImage size].height + STFSymbolYOffset;
[_cancelImage compositeToPoint:_cancelImageOrigin operation:NSCompositeSourceOver];
}
[self showSelectedPopUpItem:([self controlView] && ![[self controlView] isFirstResponder])];
// Invalidate the focus ring
[controlView setKeyboardFocusRingNeedsDisplayInRect:cellFrame];
// Draw a custom focus ring if necessary
if (wasShowingFirstResponder && [[controlView window] isKeyWindow]) {
[NSGraphicsContext saveGraphicsState];
NSSetFocusRingStyle(NSFocusRingOnly);
[[self fieldOutlinePathForRect:cellFrame] fill];
[NSGraphicsContext restoreGraphicsState];
}
// Draw the text field
[self setShowsFirstResponder:NO];
[super drawWithFrame:[self textFieldRectFromRect:cellFrame] inView:controlView];
[self setShowsFirstResponder:wasShowingFirstResponder];
}
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj
delegate:(id)anObject event:(NSEvent *)theEvent
{
// Make sure that the frame is the text field rect and pass it up to the superclass
[super editWithFrame:[self textFieldRectFromRect:aRect]
inView:controlView
editor:textObj
delegate:anObject
event:theEvent];
}
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj
delegate:(id)anObject start:(int)selStart length:(int)selLength
{
// Make sure that the frame is the text field rect and pass it up to the superclass
[super selectWithFrame:[self textFieldRectFromRect:aRect]
inView:controlView
editor:textObj
delegate:anObject
start:selStart
length:selLength];
}
- (void)cancelButtonClickedWithFrame:(NSRect)aFrame inView:(NSView *)aView
{
[self setStringValue:@""];
_shouldShowCancelButton = NO;
_shouldShowSelectedPopUpItem = YES;
}
- (void)popUpButtonClickedWithFrame:(NSRect)aFrame inView:(NSView *)aView
{
aFrame.origin.y += 4.0;
_shouldShowSelectedPopUpItem = NO;
[popUpButtonCell performClickWithFrame:aFrame inView:aView];
}
- (void)searchSubmittedFromView:(NSView *)controlView
{
_shouldShowCancelButton = [[self stringValue] isEqualToString:@""] ? NO : YES;
[controlView setNeedsDisplay:YES];
}
// Returns a path around the widget
- (NSBezierPath *)fieldOutlinePathForRect:(NSRect)aRect
{
NSBezierPath *fieldOutlinePath = [NSBezierPath bezierPath];
NSPoint aPoint;
// Start at the top left of the middle section
aPoint.x = aRect.origin.x + [_leftImage size].width;
aPoint.y = NSMaxY(aRect) - 1.0;
[fieldOutlinePath moveToPoint:aPoint];
// Trace to the top right of the middle section
aPoint.x = NSMaxX(aRect) - [_rightImage size].width;
[fieldOutlinePath lineToPoint:aPoint];
// Trace around the right curve to the bottom right of the middle section
aPoint.y = aRect.origin.y;
[fieldOutlinePath curveToPoint:aPoint
controlPoint1:NSMakePoint(aPoint.x + 13.0, NSMaxY(aRect))
controlPoint2:NSMakePoint(aPoint.x + 13.0, aPoint.y)];
// Trace to the bottom left of the middle section
aPoint.x = aRect.origin.x + [_leftImage size].width;
[fieldOutlinePath lineToPoint:aPoint];
// Trace around the left curve to the top left of the middle section, i.e. the beginning
aPoint.y = NSMaxY(aRect) - 1.0;
[fieldOutlinePath curveToPoint:aPoint
controlPoint1:NSMakePoint(aPoint.x - 11.0, aRect.origin.y)
controlPoint2:NSMakePoint(aPoint.x - 11.0, aPoint.y)];
[fieldOutlinePath closePath];
return fieldOutlinePath;
}
// Returns a rect for where the cancel button should be
- (NSRect)cancelButtonRectFromRect:(NSRect)aRect
{
// If we have a cancel button ready, return the rect for
// where it should be. Else return an empty rect.
if (_shouldShowCancelButton) {
NSRect cancelButtonRect, remainderRect;
float width = [_cancelImage size].width + STFSymbolXOffset*2;
NSDivideRect(aRect, &cancelButtonRect, &remainderRect, width, NSMaxXEdge);
return cancelButtonRect;
} else
return NSZeroRect;
}
// Returns a rect for where the popUp button should be
- (NSRect)popUpButtonRectFromRect:(NSRect)aRect
{
// If we are supposed to show the popUp button, return the
// rect for where it should be. Else return an empty rect.
if (hasPopUpButton) {
NSRect popUpButtonRect, remainderRect;
float width = 2 * STFSymbolXOffset + [_popUpImage size].width;
NSDivideRect(aRect, &popUpButtonRect, &remainderRect, width, NSMinXEdge);
return popUpButtonRect;
} else
return NSZeroRect;
}
// Returns a rect for where the text field should be
- (NSRect)textFieldRectFromRect:(NSRect)aRect
{
NSRect remainderRect, tempRect;
// If we have a popup, make a little room for its icon, else just make enough
// room for the left end cap
float startWidth = hasPopUpButton ?
[_popUpImage size].width + STFSymbolXOffset : [_leftImage size].width;
// Make room for the cancel image and give it just a little extra padding (1.0)
float endWidth = [_cancelImage size].width + STFSymbolXOffset + 1.0;
// Cut off the cancel button
NSDivideRect(aRect, &tempRect, &remainderRect, endWidth, NSMaxXEdge);
// Cut off the popUp button
NSDivideRect(remainderRect, &tempRect, &remainderRect, startWidth, NSMinXEdge);
// Cut a little off the bottom so that the text is centered well
NSDivideRect(remainderRect, &tempRect, &remainderRect, (float)3, NSMinYEdge);
return remainderRect;
}
@end
@implementation SearchTextFieldCell(PrivateMethods)
+ (NSImage *)cachedLeftImage
{
static NSImage *cachedLeftImage = nil;
if (cachedLeftImage == nil)
cachedLeftImage = [[NSImage imageNamed:@"SearchLeft"] retain];
return cachedLeftImage;
}
+ (NSImage *)cachedMiddleImage
{
static NSImage *cachedMiddleImage = nil;
if (cachedMiddleImage == nil) {
cachedMiddleImage = [[NSImage imageNamed:@"SearchMiddle"] retain];
[cachedMiddleImage setScalesWhenResized:TRUE];
}
return cachedMiddleImage;
}
+ (NSImage *)cachedRightImage
{
static NSImage *cachedRightImage = nil;
if (cachedRightImage == nil)
cachedRightImage = [[NSImage imageNamed:@"SearchRight"] retain];
return cachedRightImage;
}
+ (NSImage *)cachedPopUpImage
{
static NSImage *cachedPopUpImage = nil;
if (cachedPopUpImage == nil)
cachedPopUpImage = [[NSImage imageNamed:@"SearchPopUp"] retain];
return cachedPopUpImage;
}
+ (NSImage *)cachedCancelImage
{
static NSImage *cachedCancelImage = nil;
if (cachedCancelImage == nil)
cachedCancelImage = [[NSImage imageNamed:@"SearchCancel"] retain];
return cachedCancelImage;
}
@end