home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 110 / EnigmaAmiga110CD.iso / indispensabili / utility / apdf / xpdf-0.80 / ltk / ltkmenu.h < prev    next >
C/C++ Source or Header  |  1998-11-27  |  3KB  |  122 lines

  1. //========================================================================
  2. //
  3. // LTKMenu.h
  4. //
  5. // Menus and menu items.
  6. //
  7. // Copyright 1997 Derek B. Noonburg.
  8. //
  9. //========================================================================
  10.  
  11. #ifndef LTKMENU_H
  12. #define LTKMENU_H
  13.  
  14. #ifdef __GNUC__
  15. #pragma interface
  16. #endif
  17.  
  18. #include <stddef.h>
  19. #include <X11/Xlib.h>
  20. #include "gtypes.h"
  21. #include "GString.h"
  22.  
  23. class LTKWindow;
  24. class LTKMenuItem;
  25.  
  26. //------------------------------------------------------------------------
  27. // callback type
  28. //------------------------------------------------------------------------
  29.  
  30. // Menu item selection.
  31. typedef void (*LTKMenuCbk)(LTKMenuItem *item);
  32.  
  33. //------------------------------------------------------------------------
  34. // LTKMenu
  35. //------------------------------------------------------------------------
  36.  
  37. class LTKMenu {
  38. public:
  39.  
  40.   //---------- constructor and destructor ----------
  41.  
  42.   // Constructor.  The extra args are the list of menu items.
  43.   LTKMenu(char *title1, int numItems1, ...);
  44.  
  45.   // Destructor.
  46.   ~LTKMenu();
  47.  
  48.   //---------- access ----------
  49.  
  50.   Window getXWindow() { return xwin; }
  51.  
  52.   //---------- drawing ----------
  53.  
  54.   // Post the menu.  Put the top left corner as close as possible
  55.   // to <x1>,<y1>.
  56.   void post(LTKWindow *win1, int x1, int y1, LTKMenu *parent1);
  57.  
  58.   //---------- event handlers ----------
  59.  
  60.   void redraw();
  61.   void buttonPress(int mx, int my, int button, GBool dblClick);
  62.   void buttonRelease(int mx, int my, int button, GBool click);
  63.   void mouseMove(int mx, int my, int btn);
  64.  
  65. private:
  66.  
  67.   void repost();
  68.   void unpost();
  69.   void done();
  70.  
  71.   char *title;            // menu title (may be NULL)
  72.   LTKMenuItem **items;        // array of items
  73.   int numItems;            // number of items
  74.  
  75.   LTKWindow *win;        // parent window
  76.   LTKMenu *parent;        // parent menu, or NULL if none
  77.   int x, y;            // current position
  78.   int width, height;        // size of window
  79.   int itemHeight;        // height of menu item
  80.   Display *display;        // X display
  81.   Window xwin;            // X window
  82.   GC fgGC, bgGC;        // foreground/background GCs
  83.   GC brightGC, darkGC;        // shaded border GCs
  84.  
  85.   int currentItem;        // currently selected item or -1 if none
  86.   int currentY;            // y coordinate of current item
  87.   LTKMenu *currentSubmenu;    // currently posted submenu
  88. };
  89.  
  90. //------------------------------------------------------------------------
  91. // LTKMenuItem
  92. //------------------------------------------------------------------------
  93.  
  94. class LTKMenuItem {
  95. public:
  96.  
  97.   //---------- constructor ----------
  98.  
  99.   // Constructor.
  100.   LTKMenuItem(char *text1, char *shortcut1, int itemNum1,
  101.           LTKMenuCbk cbk1, LTKMenu *submenu1);
  102.  
  103.   //---------- access ----------
  104.  
  105.   int getItemNum() { return itemNum; }
  106.  
  107. private:
  108.  
  109.   int getWidth();
  110.   int getHeight();
  111.  
  112.   char *text;            // text of the menu item
  113.   char *shortcut;        // shortcut for menu item
  114.   int itemNum;            // item number
  115.   LTKMenuCbk cbk;        // selection callback
  116.   LTKMenu *submenu;        // pointer to submenu, or NULL if none
  117.  
  118.   friend class LTKMenu;
  119. };
  120.  
  121. #endif
  122.