home *** CD-ROM | disk | FTP | other *** search
- // You may freely copy, distribute and reuse the code in this example.
- // NeXT disclaims any warranty of any kind, expressed or implied,
- // as to its fitness for any particular use.
-
- // RedPicker.m written by Keith Bernstein.
-
- #import <appkit/appkit.h>
- #import "RedPicker.h"
-
- extern float insertionPoint; // Set in Controller.m
-
- #define MYMASK 0x0100 // Anything you want, just not 'kit supplied.
- #define MYMODE 10 // Anything you want, just not 'kit supplied.
-
- @implementation RedPicker : NXColorPicker
-
- // Normally you would be able to simply use NXColorPicker's implementation
- // of this method (which always returns "YES"), as that will cause your custom
- // picker to *always* be added. In this example program, the RedPicker is
- // only added if the user has that checkbox selected, so we need to do this so
- // it is not always added automatically.
- - initFromPickerMask:(int)mask withColorPanel:owningColorPanel
- {
- [super initFromPickerMask:mask withColorPanel:owningColorPanel];
-
- return((mask & MYMASK) ? self : nil);
- }
-
- // This method is part of the "NXColorPicking" protocol, and it will
- // provide the ColorPanel with the view we want inserted into the ColorPanel.
- - provideNewView:(BOOL)initialRequest
- {
- if (initialRequest) {
- char newPathBuffer[MAXPATHLEN+1];
- char resourcePath[MAXPATHLEN+1];
-
- // Then this is our first time here...
-
- strcpy(resourcePath, [[NXBundle mainBundle] directory]);
- strcat(resourcePath, "/ColorPickers/RedPicker.bundle");
- // Load up our .nib file...
- if ([NXBundle getPath:newPathBuffer
- forResource:[self name]
- ofType:"nib"
- inDirectory:resourcePath
- withVersion:0]) {
- if (![NXApp loadNibFile:newPathBuffer
- owner:self withNames:NO
- fromZone:[self zone]]) {
- NXLogError("%s error. Couldn't load %s.nib\n", [self name], [self name]);
- }
- } else {
- NXLogError("%s error. Couldn't find %s.nib\n", [self name], [self name]);
- }
- }
- return(button);
- }
-
- - (float)insertionOrder
- {
- return(insertionPoint);
- }
-
- // Return NO if "mode" not supported.
- - (BOOL)supportsMode:(int)mode
- {
- if (mode == MYMODE)
- return(YES);
- else
- return(NO);
- }
-
- - (int)currentMode
- {
- return(MYMODE);
- }
-
- - setColor:(NXColor)newColor
- {
- return(self);
- }
-
- - button:sender
- {
- [colorPanel setColor:NX_COLORRED];
- return(self);
- }
-
-
-
- @end