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

  1. //========================================================================
  2. //
  3. // LTKWidget.h
  4. //
  5. // Widget base class.
  6. //
  7. // Copyright 1996 Derek B. Noonburg
  8. //
  9. //========================================================================
  10.  
  11. #ifndef LTKWIDGET_H
  12. #define LTKWIDGET_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. #include "LTKWindow.h"
  23.  
  24. //------------------------------------------------------------------------
  25. // callback types
  26. //------------------------------------------------------------------------
  27.  
  28. // Mouse button press/release.
  29. typedef void (*LTKButtonPressCbk)(LTKWidget *widget, int widgetNum,
  30.                   int mx, int my, int button, GBool dblClick);
  31. typedef void (*LTKButtonReleaseCbk)(LTKWidget *widget, int widgetNum,
  32.                     int mx, int my, int button, GBool click);
  33.  
  34. // Mouse move.
  35. typedef void (*LTKMouseMoveCbk)(LTKWidget *widget, int widgetNum,
  36.                 int mx, int my);
  37.  
  38. // Mouse drag.
  39. typedef void (*LTKMouseDragCbk)(LTKWidget *widget, int widgetNum,
  40.                 int mx, int my, int button);
  41.  
  42. // Boolean value change.
  43. typedef void (*LTKBoolValCbk)(LTKWidget *widget, int widgetNum, GBool on);
  44.  
  45. // Integer value change.
  46. typedef void (*LTKIntValCbk)(LTKWidget *widget, int widgetNum, int val);
  47.  
  48. // String value change.
  49. typedef void (*LTKStringValCbk)(LTKWidget *widget, int widgetNum,
  50.                 GString *val);
  51.  
  52. // Redraw widget.
  53. typedef void (*LTKRedrawCbk)(LTKWidget *widget, int widgetNum);
  54.  
  55. //------------------------------------------------------------------------
  56. // LTKWidget
  57. //------------------------------------------------------------------------
  58.  
  59. class LTKWidget {
  60. public:
  61.  
  62.   //---------- constructor and destructor ----------
  63.  
  64.   // Constructor.
  65.   LTKWidget(char *name1, int widgetNum1);
  66.  
  67.   // Destructor.
  68.   virtual ~LTKWidget();
  69.  
  70.   //---------- access ----------
  71.  
  72.   virtual GBool isBox() { return gFalse; }
  73.   char *getName() { return name; }
  74.   virtual void setParent(LTKWindow *parent1);
  75.   LTKWindow *getParent() { return parent; }
  76.   virtual void setCompoundParent(LTKWidget *compParent1);
  77.   LTKWidget *getCompoundParent() { return compParent; }
  78.   int getWidth() { return width; }
  79.   int getHeight() { return height; }
  80.   Window getXWindow() { return xwin; }
  81.   virtual long getEventMask();
  82.   Display *getDisplay() { return parent->getDisplay(); }
  83.   int getScreenNum() { return parent->getScreenNum(); }
  84.   unsigned long getFgColor() { return parent->getFgColor(); }
  85.   unsigned long getBgColor() { return parent->getBgColor(); }
  86.   GC getFgGC() { return parent->getFgGC(); }
  87.   GC getBgGC() { return parent->getBgGC(); }
  88.   GC getBrightGC() { return parent->getBrightGC(); }
  89.   GC getDarkGC() { return parent->getDarkGC(); }
  90.   GC getXorGC() { return parent->getXorGC(); }
  91.   XFontStruct *getXFontStruct() { return parent->getXFontStruct(); }
  92.   LTKWidget *getNext() { return next; }
  93.   LTKWidget *setNext(LTKWidget *next1) { return next = next1; }
  94.  
  95.   //---------- special access ----------
  96.  
  97.   void setButtonPressCbk(LTKButtonPressCbk cbk) { btnPressCbk = cbk; }
  98.   void setButtonReleaseCbk(LTKButtonReleaseCbk cbk) { btnReleaseCbk = cbk; }
  99.   void setMouseMoveCbk(LTKMouseMoveCbk cbk) { mouseMoveCbk = cbk; }
  100.   void setMouseDragCbk(LTKMouseDragCbk cbk) { mouseDragCbk = cbk; }
  101.  
  102.   //---------- layout ----------
  103.  
  104.   // Compute minimum width and height of widget.
  105.   virtual void layout1() = 0;
  106.  
  107.   // Layout widget internals at specified position, with specified size.
  108.   virtual void layout2(int x1, int y1, int width1, int height1);
  109.  
  110.   // Construct the X window(s) for widget and children.  If windows
  111.   // are already constructed, move/resize them as necessary.
  112.   virtual void layout3();
  113.  
  114.   // Map the X window(s) for widget and children.
  115.   virtual void map();
  116.  
  117.   //---------- drawing ----------
  118.  
  119.   // Clear the widget's window to the background color.
  120.   virtual void clear();
  121.  
  122.   // Draw the widget and its children.
  123.   virtual void redraw() = 0;
  124.  
  125.   // Draw the window background (only used by boxes, compound widgets,
  126.   // etc., which draw directly in the window).
  127.   virtual void redrawBackground() {}
  128.  
  129.   //---------- callbacks and event handlers ----------
  130.  
  131.   virtual void buttonPress(int mx, int my, int button, GBool dblClick);
  132.   virtual void buttonRelease(int mx, int my, int button, GBool click);
  133.   virtual void activate(GBool on) {}
  134.   virtual void activateDefault() {}
  135.   virtual void mouseMove(int mx, int my, int btn);
  136.   virtual void keyPress(KeySym key, Guint modifiers, char *s, int n) {}
  137.   virtual void repeatEvent() {}
  138.   virtual void clearSelection() {}
  139.   virtual void paste(GString *str) {}
  140.  
  141. protected:
  142.  
  143.   char *name;            // name (for lookup within window)
  144.   int widgetNum;        // widget number (for callbacks)
  145.   LTKWindow *parent;        // parent window
  146.   LTKWidget *compParent;    // parent compound widget
  147.   int x, y;            // current position (in window)
  148.   int width, height;        // current size
  149.  
  150.   LTKButtonPressCbk btnPressCbk;     // mouse button press callback
  151.   LTKButtonReleaseCbk btnReleaseCbk; // mouse button release callback
  152.   LTKMouseMoveCbk mouseMoveCbk;         // mouse move callback
  153.   LTKMouseDragCbk mouseDragCbk;         // mouse drag callback
  154.  
  155.   Window xwin;            // X window (not used for Boxes)
  156.   GBool mapped;            // set when mapped
  157.  
  158.   LTKWidget *next;        // LTKWindow keeps a list of widgets
  159. };
  160.  
  161. #endif
  162.