home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Connectivity / GateKeeper-2.1 / ToolBar.m < prev    next >
Encoding:
Text File  |  1997-04-14  |  8.0 KB  |  280 lines

  1. //************************************************************************
  2. //
  3. //    ToolBar.m.  
  4. //
  5. //        ToolBar control object
  6. //
  7. //            by    Felipe A. Rodriguez        
  8. //
  9. //    This code is supplied "as is" the author makes no warranty as to its 
  10. //    suitability for any purpose.  This code is free and may be distributed 
  11. //    in accordance with the terms of the:
  12. //        
  13. //            GNU GENERAL PUBLIC LICENSE
  14. //            Version 2, June 1991
  15. //            copyright (C) 1989, 1991 Free Software Foundation, Inc.
  16. //             675 Mass Ave, Cambridge, MA 02139, USA
  17. //
  18. //************************************************************************
  19.  
  20.  
  21. #import "GKdefs.h"
  22. #import "IconView.h"
  23. #import "ToolBar.h"
  24. #import "ToolBarView.h"
  25. #import "ToolIconView.h"
  26. #import "HLRecord.h"
  27. #import "HLDelegate.h"
  28. #import "Coordinator.h"
  29. #import <appkit/appkit.h>
  30. #import <dbkit/DBImageView.h>
  31.  
  32. #import <sys/types.h>
  33. #import <sys/dir.h>  /* POSIX applications #include <dirent.h> */
  34.  
  35.  
  36. @implementation ToolBar
  37.  
  38. //************************************************************************
  39. //
  40. //        sent to us after nib objects are unarchived and init'd 
  41. //
  42. //************************************************************************
  43.  
  44. - awakeFromNib
  45. {
  46. NXRect    appIconFrame;
  47. NXRect    lineViewRect;
  48. id appIcon;
  49.  
  50.     appTile = [NXImage findImageNamed: "NXAppTile"];
  51.     appIcon = [NXApp appIcon];                    // get appIcon window
  52.     [appIcon getFrame:&appIconFrame];            // get appIcon frame rect
  53.     [Window getContentRect:&lineViewRect         // get content view rect appIco
  54.                         forFrameRect:&appIconFrame style:[appIcon style]];
  55.                 // reduce the size and width/ht by a border of 1
  56.     NX_X(&lineViewRect) = 1;
  57.     NX_Y(&lineViewRect) = 1;
  58.     NX_WIDTH(&lineViewRect) -= 1 ;
  59.     NX_HEIGHT(&lineViewRect) -= 1;
  60.                                                             // create tool view
  61.     theToolView = [[ToolBarView alloc] initFrame:&lineViewRect];    
  62.                                                             // create icon view
  63.     toolIconView = [[ToolIconView alloc] initFrame:&lineViewRect];    
  64.     toolWin = [[Window allocFromZone:[self zone]]            // create tool Win
  65.                        initContent:&appIconFrame
  66.                        style:NX_TOKENSTYLE
  67.                        backing:NX_BUFFERED 
  68. //                    buttonMask:NX_CLOSEBUTTONMASK defer:NO];
  69.                     buttonMask:0 defer:NO];
  70.     [toolWin setFreeWhenClosed:NO];
  71.  
  72.     if(![toolWin setFrameUsingName:"toolBar"])            
  73.         [toolWin moveTo:100.0 :100.0];                    // initial pos of toolB
  74.     [toolWin setFrameUsingName:"toolbar"];                // remember location
  75.     [toolWin setFrameAutosaveName:"toolbar"];            // remember location
  76.     [[toolWin setContentView:theToolView] free];        // replace cont w/toolV
  77.                                     // add IB created backWindow's contentView
  78.     [[toolWin contentView] addSubview:[backWindow contentView]];
  79.     toolView = [toolWin setContentView:toolIconView];        
  80.     [toolWin setBackgroundGray:NX_BLACK];
  81.     [[toolWin contentView] getFrame:&lineViewRect];                        
  82.     [[toolWin contentView] convertRect:&lineViewRect toView:nil];
  83.     [toolWin setTrackingRect:&lineViewRect                    // create mouse 
  84.                     inside:YES                                // tracking rect
  85.                     owner:self
  86.                     tag:1500
  87.                     left:NO
  88.                     right:NO];
  89.  
  90.     nxAppDel = [NXApp delegate];
  91.     hotListDelegate = [nxAppDel hotListDelegate];
  92.     [hotListDelegate setToolBar:toolIconView];
  93.     [toolWin orderFront:self];            
  94.     [toolWin display];
  95.  
  96.     return self;
  97. }
  98. //*****************************************************************************
  99. //
  100. //         user pressed play button in toolbar 
  101. //
  102. //*****************************************************************************
  103.  
  104. - playLink:sender 
  105. {
  106.     [sender setState:0];                                    
  107.     [[NXApp delegate] Link:self];                            
  108.  
  109.     return self;
  110. }
  111. //*****************************************************************************
  112. //
  113. //         user pressed stop button in toolbar 
  114. //
  115. //*****************************************************************************
  116.  
  117. - playUnlink:sender 
  118. {
  119.     [sender setState:0];
  120.     if((strcmp([[[NXApp mainMenu] findCellWithTag:2] title], 
  121.                     [[NXApp delegate] localString:"Disconnect"]) == 0) && 
  122.                             [[[NXApp mainMenu] findCellWithTag:2] isEnabled])
  123.         [[NXApp delegate] UnLink:self];                        // item enabled
  124.     
  125.     return self;
  126. }
  127. //*****************************************************************************
  128. //
  129. //         go to next gate doc in hotList 
  130. //
  131. //*****************************************************************************
  132.  
  133. - nextItem:sender 
  134. {
  135.     return [hotListDelegate nextItem:sender];
  136. }
  137. //*****************************************************************************
  138. //
  139. //         go to previous gate doc in hotList 
  140. //
  141. //*****************************************************************************
  142.  
  143. - prevItem:sender 
  144. {
  145.     return [hotListDelegate prevItem:sender];
  146. }
  147. //*****************************************************************************
  148. //
  149. //         close toolbar 
  150. //
  151. //*****************************************************************************
  152.  
  153. - close:sender 
  154. {
  155.     if(!NXWriteDefault([NXApp appName], DISPLAYT, "NO"))
  156.         [[NXApp delegate] showAlert:"ddbWriteError"];
  157.     [sender setState:0];
  158.     [toolWin close];
  159.  
  160.     return self;
  161. }
  162. //*****************************************************************************
  163. //
  164. //         mouse has entered our tracking rect (window)
  165. //
  166. //*****************************************************************************
  167.  
  168. - mouseEntered:(NXEvent *)theEvent 
  169. {
  170.     wasHidden = [NXApp isHidden];                    // is the app hidden?
  171.     [NXApp unhide:self];
  172.     statusVisible = [[hotListDelegate statusWindow] isVisible];                        
  173.     [toolWin setContentView:toolView];        
  174.     [toolWin display];    
  175.     [hotListDelegate loadBrowser];    // NXBrowser s/load cols from its delegate
  176.     if([nxAppDel mailInQueue])
  177.         iWasSet = 8;
  178.     cursorOverToolBar = YES;
  179.     if(iWasSet > 0)
  180.         {
  181.         [[nxAppDel appIconView] setMailFlag:YES];
  182.         [self perform:@selector(mailInQueueIcon) with:self afterDelay:3000     
  183.                                                         cancelPrevious:YES];
  184.         }
  185.     NXPing();
  186.     
  187.     return self;
  188. }
  189. //*****************************************************************************
  190. //
  191. //         mouse has exited our tracking rect (window)
  192. //
  193. //*****************************************************************************
  194.  
  195. - mouseExited:(NXEvent *)theEvent 
  196. {
  197.     [toolWin setContentView:toolIconView];        
  198.     [toolWin display];        
  199.  
  200.     [[nxAppDel appIconView] setMailFlag:NO];
  201.                         // if status win was hidden prior to cursor in, hide
  202.     if(!statusVisible && cursorOverToolBar)     
  203.         [[hotListDelegate statusWindow] close];
  204.     if(wasHidden)                // if app was hidden prior to cursor in, hide
  205.         [NXApp hide:self];
  206.     cursorOverToolBar = NO;
  207.  
  208.     return self;
  209. }
  210. - (BOOL)acceptsFirstMouse
  211. {
  212.     return YES;
  213. }
  214. //*****************************************************************************
  215. //
  216. //         clear mail in queue icon from app icon if mail has been sent
  217. //
  218. //*****************************************************************************
  219.  
  220. - mailInQueueIcon
  221. {
  222.     if(!((strcmp([[[NXApp mainMenu] findCellWithTag:2] title], 
  223.                     [[NXApp delegate] localString:"Disconnect"]) == 0) && 
  224.                             [[[NXApp mainMenu] findCellWithTag:2] isEnabled]))
  225.         iWasSet = 0;
  226.     if(![nxAppDel mailInQueue])
  227.         {
  228.         iWasSet--;
  229.                         // if user mouseExited while mail icon set, 
  230.                         // mouseEntered may occur during interim period
  231.                         // when mail is not shown in queue, but is
  232.         if(iWasSet > 0 && cursorOverToolBar)
  233.             [[nxAppDel appIconView] setMailFlag:YES];
  234.         else
  235.             [[nxAppDel appIconView] setMailFlag:NO];    
  236.         }
  237.     else
  238.         iWasSet = 8;
  239.     if(iWasSet > 0)
  240.         [self perform:@selector(mailInQueueIcon) with:self 
  241.                                     afterDelay:4000  cancelPrevious:YES];
  242.  
  243.     return self;
  244. }
  245. //*****************************************************************************
  246. //
  247. //         forward anything in Greek to someone who might understand 
  248. //
  249. //*****************************************************************************
  250.  
  251. - forward:(SEL)aSelector :(marg_list)argFrame
  252. {
  253.     if ( [toolWin respondsTo:aSelector] )
  254.         return [toolWin performv:aSelector :argFrame];
  255.  
  256.     [self doesNotRecognize:aSelector];                    // error abort process
  257.  
  258.     return self;
  259. }
  260. //************************************************************************
  261. //
  262. //     free simply gets rid of everything we created
  263. //     This is how nice objects clean up.
  264. //
  265. //************************************************************************
  266.  
  267. - free
  268. {
  269.     if(toolWin)
  270.         [toolWin free];                                    
  271.     if(theToolView)
  272.         [theToolView free];                                    
  273.     if(toolIconView)
  274.         [toolIconView free];                                    
  275.  
  276.     return [super free];
  277. }
  278.  
  279. @end
  280.