home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / PBL30SRC.ZIP / CMDBAR.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-28  |  3.4 KB  |  116 lines

  1. /*
  2.  * This file is part of PB-Lib v3.0 C++ Programming Library
  3.  *
  4.  * Copyright (c) 1995, 1997 by Branislav L. Slantchev
  5.  * A fine product of Silicon Creations, Inc. (gargoyle)
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the License which accompanies this
  9.  * software. This library is distributed in the hope that it will
  10.  * be useful, but without any warranty; without even the implied
  11.  * warranty of merchantability or fitness for a particular purpose.
  12.  *
  13.  * You should have received a copy of the License along with this
  14.  * library, in the file LICENSE.DOC; if not, write to the address
  15.  * below to receive a copy via electronic mail.
  16.  *
  17.  * You can reach Branislav L. Slantchev (Silicon Creations, Inc.)
  18.  * at bslantch@cs.angelo.edu. The file SUPPORT.DOC has the current
  19.  * telephone numbers and the postal address for contacts.
  20. */
  21.  
  22. #ifndef INCLUDED_CMDBAR_H
  23. #define INCLUDED_CMDBAR_H
  24. #include "geometry.h"
  25.  
  26. /*
  27.  * c o m m a n d   b a r   c l a s s e s
  28.  * ──────────────────────────────────────────────────────────────────────────
  29.  * these are the declarations of the command bar and command item classes.
  30. */
  31.  
  32. const short
  33.     cmNoCommand = -1, cmCancel = -2; // reserved by the handler
  34.  
  35. class zCommandItem
  36. {
  37.     friend class zCommandBar;
  38.     friend class TLangEntry;
  39.     friend zCommandItem* operator+(zCommandItem *item, zCommandItem &link);
  40.  
  41. public:
  42.     zCommandItem(const char *aText, ushort key, ushort aCmd, zCommandItem *next = 0);
  43.  
  44. protected:
  45.     zCommandItem *next;    //..................................link to next item
  46.     zCommandItem *prev;    //..............................link to previous item
  47.     const char  *text;    //.....text to display (with '~' for highlight chars)
  48.  
  49.     ushort  keyCode;    //........key that activates the item (not sensitive)
  50.     ushort  command;    //...................command generated when activated
  51.     Boolean enabled;    //............................item is enabled if True
  52. };
  53.  
  54. class zCommandBar
  55. {
  56. public:
  57.     enum cbar_options
  58.     {
  59.         hide  = 1,  //.......................hide the command bar (invisible)
  60.         focus = 2,  //.......................focus (receives events and acts)
  61.         delim = 4   //............treat 1st and last chars of items specially
  62.     };
  63.  
  64.     zCommandBar(const zRect &bounds, zCommandItem *items);
  65.     ~zCommandBar();
  66.  
  67.     virtual short handle(ushort aKeyCode);
  68.     virtual void  draw();
  69.  
  70.     void  show(Boolean enable);
  71.     void  setState(Boolean focused);
  72.  
  73.     void  setPalette(const char *aPalette);
  74.     uchar getColor(short aColor);
  75.     void  enableCommand(ushort aCommand, Boolean enable);
  76.  
  77.     ushort options;
  78.  
  79. protected:
  80.     void          drawItem(const zCommandItem *item);
  81.     short         getItemPos(const zCommandItem *item);
  82.     void          focusItem(const zCommandItem *item);
  83.     zCommandItem* lastItem();
  84.     zCommandItem* firstItem();
  85.     zCommandItem* prevItem();
  86.     zCommandItem* nextItem();
  87.  
  88.     zPoint       origin;
  89.     zPoint       size;
  90.     char         palette[15];
  91.     zCommandItem *items;
  92.     zCommandItem *current;
  93. };
  94.  
  95. // Global functions and utilities
  96. zCommandItem* operator+(zCommandItem *item, zCommandItem &link);
  97.  
  98. // inlined functions
  99. inline void
  100. zCommandBar::show(Boolean mustShow)
  101. {
  102.     if( mustShow ) options &= ~hide;
  103.     else options |= hide;
  104.     draw();
  105. }
  106.  
  107. inline void
  108. zCommandBar::setState(Boolean focused)
  109. {
  110.     if( focused ) options |= focus;
  111.     else options &= ~focus;
  112.     draw();
  113. }
  114.  
  115. #endif /* INCLUDED_CMDBAR_H */
  116.