home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Examples / AppKit / ColorTest / RedPicker.m < prev   
Text File  |  1992-06-17  |  2KB  |  91 lines

  1. // You may freely copy, distribute and reuse the code in this example.
  2. // NeXT disclaims any warranty of any kind, expressed or implied,
  3. // as to its fitness for any particular use.
  4.  
  5. // RedPicker.m written by Keith Bernstein.
  6.  
  7. #import <appkit/appkit.h>
  8. #import "RedPicker.h"
  9.  
  10. extern float insertionPoint;  // Set in Controller.m
  11.  
  12. #define MYMASK 0x0100         // Anything you want, just not 'kit supplied.
  13. #define MYMODE     10         // Anything you want, just not 'kit supplied.
  14.  
  15. @implementation RedPicker : NXColorPicker
  16.  
  17. // Normally you would be able to simply use NXColorPicker's implementation
  18. // of this method (which always returns "YES"), as that will cause your custom
  19. // picker to *always* be added.  In this example program, the RedPicker is
  20. // only added if the user has that checkbox selected, so we need to do this so
  21. // it is not always added automatically.
  22. - initFromPickerMask:(int)mask withColorPanel:owningColorPanel
  23. {    
  24.     [super initFromPickerMask:mask withColorPanel:owningColorPanel];
  25.     
  26.     return((mask & MYMASK) ? self : nil);
  27. }
  28.  
  29. // This method is part of the "NXColo)king" protocol, and it will
  30. // provide the ColorPanel with the view we want inserted into the ColorPanel.
  31. - provideNewView:(BOOL)initialRequest
  32. {
  33.     if (initialRequest) {
  34.     char newPathBuffer[MAXPATHLEN+1];
  35.     char resourcePath[MAXPATHLEN+1];
  36.     
  37.         // Then this is our first time here...
  38.     
  39.     strcpy(resourcePath, [[NXBundle mainBundle] directory]);
  40.     strcat(resourcePath, "/ColorPickers/RedPicker.bundle");
  41.     // Load up our .nib file...
  42.     if ([NXBundle getPath:newPathBuffer 
  43.         forResource:[self name]
  44.             ofType:"nib"
  45.         inDirectory:resourcePath
  46.         withVersion:0]) {
  47.         if (![NXApp loadNibFile:newPathBuffer 
  48.                 owner:self withNames:NO 
  49.                 fromZone:[self zone]]) {
  50.         NXLogError("%s error.  Couldn't load %s.nib\n", [self name], [self name]);
  51.         }
  52.     } else {      
  53.         NXLogError("%s error.  Couldn't find %s.nib\n", [self name], [self name]);
  54.     }
  55.     }
  56.     return(button);
  57. }
  58.  
  59. - (float)insertionOrder
  60. {
  61.     return(insertionPoint);
  62. }
  63.  
  64. // Return NO if "mode" not supported.
  65. - (BOOL)supportsMode:(int)mode
  66. {
  67.    if (mode == MYMODE)
  68.        return(YES);
  69.    else
  70.        return(NO);
  71. }
  72.  
  73. - (int)currentMode
  74. {
  75.     return(MYMODE);
  76. }
  77.  
  78. - setColor:(NXColor)newColor
  79. {
  80.     return(self);
  81. }
  82.  
  83. - button:sender
  84. {
  85.     [colorPanel setColor:NX_COLORRED];
  86.     return(self);
  87. }
  88.  
  89.  
  90.  
  91. @end