home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / PBL30SAM.ZIP / CBARTEST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-06  |  3.4 KB  |  93 lines

  1. //
  2. // teststat.cpp - zCommandBar class usage example (EXE and SDK modes)
  3. //
  4. // Copyright (c) 1996 by Branislav L. Slantchev
  5. // A Product of Silicon Creations, Inc.
  6. //
  7. // Source is for purely educational purposes only. It is provided as a
  8. // service to all PB-Lib users. It is not supported by Silicon Creations.
  9. //
  10. #include "cmdbar.h"
  11. #include "keyboard.h"
  12. #include "kbcodes.h"
  13.  
  14. int main( void )
  15. {
  16.     zKeyboard    kbd;
  17.     keyDownEvent event;
  18.     short        cmd = cmNoCommand;
  19.     Boolean      focus = True;
  20.  
  21.     // this is the original way of creating the list. Note how each
  22.     // new item is appended by passing the pointer as an argument to
  23.     // the constructor of the previos one. This can be very confusing,
  24.     // especially with all the parenthesis that should be appended!
  25.     // Even though it is still OK to use this, the overloaded operator+
  26.     // is probably a better (and definitely much clearer) choice
  27. #if 0
  28.     zCommandItem *items = new zCommandItem("[~S~elect]", 'S', 1,
  29.         new zCommandItem("[~Q~uit]", 'Q', 2,
  30.         new zCommandItem("[~H~ello!]", 'H', 3,
  31.         new zCommandItem("[Aha! ~N~ot]", 'N', 8,
  32.         new zCommandItem("[No ~5~: Fifth]", '5', 4,
  33.         new zCommandItem(0, 'X', 100,    // hidden entry, only hotkey
  34.         new zCommandItem("[~L~ast Item]", 'L', 5,
  35.         new zCommandItem("[~A~nother]", 'A', 6,
  36.         new zCommandItem("[~V~isible]", 'V', 7)))))))));
  37. #endif
  38.  
  39.     // create a list of items for the status line bar, note that we
  40.     // must allocate them dynamically because of zCommandBar requirements
  41.     // (see the manual). Also note the use of the overloaded operator+
  42.     // for much more readable coding. You can construct the item list as
  43.     // shown stright in the zCommandBar constructor, if you wish to.
  44.     zCommandItem *items =
  45.         new zCommandItem("[~S~elect]", 'S', 1)
  46.         + *new zCommandItem("[~Q~uit]", 'Q', 200)
  47.         + *new zCommandItem("[~H~ello!]", 'H', 3)
  48.         + *new zCommandItem("[Aha! ~N~ot]", 'N', 8)
  49.         + *new zCommandItem("[No ~5~: Fifth]", '5', 4)
  50.         + *new zCommandItem(0, 'X', 100)    // hidden entry, only hotkey
  51.         + *new zCommandItem("[~L~ast Item]", 'L', 5)
  52.         + *new zCommandItem("[~A~nother]", 'A', 6)
  53.         + *new zCommandItem("[~V~isible]", 'V', 7);
  54.  
  55.     // create a status line (the location is usually the best one)
  56.     zCommandBar *status = new zCommandBar(zRect(1,24,80,25), items);
  57.  
  58.     // just to show you how to disable an item on the status line
  59.     // this will cause the 'Hello' item to be non-selectable
  60.     status->enableCommand(3, False);
  61.     status->draw(); // display the line
  62.  
  63.     // note that the loop will terminate when either Escape is pressed
  64.     // or when the user chooses 'X' (the invisible item) or 'Quit'
  65.     while( 200 != cmd && 100 != cmd && cmCancel != cmd ){
  66.  
  67.         kbd.getEvent(event);
  68.  
  69.         // we use the tab to focus and unfocus the status line
  70.         if( kbTab == event.keyCode ){
  71.             focus = Boolean(!focus);
  72.             if( !focus ) status->options &= ~zCommandBar::focus;
  73.             else status->options |= zCommandBar::focus;
  74.             status->draw(); // needed so the line is shown in proper colors
  75.         }
  76.         // we use Alt+H to hide and Alt+U to unhide the status line
  77.         // note that is will be drawn according to the focus state
  78.         else if( kbAltH == event.keyCode ){
  79.             status->options |= zCommandBar::hide;
  80.             status->draw();
  81.         }
  82.         else if( kbAltU == event.keyCode ){
  83.             status->options &= ~zCommandBar::hide;
  84.             status->draw();
  85.         }
  86.         // just process each keystroke
  87.         else cmd = status->handle(event.keyCode);
  88.     }
  89.     delete status;
  90.  
  91.     return 0;
  92. }
  93.