1 #ifndef __DW_FLTKVIEWPORT_HH__ 2 #define __DW_FLTKVIEWPORT_HH__ 3 4 #include <FL/Fl_Group.H> 5 #include <FL/Fl_Scrollbar.H> 6 7 #include "core.hh" 8 #include "fltkcore.hh" 9 #include "fltkviewbase.hh" 10 11 namespace dw { 12 namespace fltk { 13 14 class FltkViewport: public FltkWidgetView 15 { 16 public: 17 enum GadgetOrientation { GADGET_VERTICAL, GADGET_HORIZONTAL }; 18 19 private: 20 enum { SCROLLBAR_THICKNESS = 15 }; 21 22 int scrollX, scrollY; 23 int scrollDX, scrollDY; 24 int hasDragScroll, dragScrolling, dragX, dragY; 25 int horScrolling, verScrolling; 26 27 Fl_Scrollbar *vscrollbar, *hscrollbar; 28 29 GadgetOrientation gadgetOrientation[4]; 30 lout::container::typed::List <lout::object::TypedPointer < Fl_Widget> > 31 *gadgets; 32 33 void adjustScrollbarsAndGadgetsAllocation (); 34 void adjustScrollbarValues (); 35 void hscrollbarChanged (); 36 void vscrollbarChanged (); 37 void positionChanged (); 38 39 static void hscrollbarCallback (Fl_Widget *hscrollbar, void *viewportPtr); 40 static void vscrollbarCallback (Fl_Widget *vscrollbar, void *viewportPtr); 41 42 void selectionScroll(); 43 static void selectionScroll(void *vport); 44 45 void updateCanvasWidgets (int oldScrollX, int oldScrollY); 46 static void draw_area (void *data, int x, int y, int w, int h); 47 48 protected: 49 int translateViewXToCanvasX (int x); 50 int translateViewYToCanvasY (int y); 51 int translateCanvasXToViewX (int x); 52 int translateCanvasYToViewY (int y); 53 54 public: 55 FltkViewport (int x, int y, int w, int h, const char *label = 0); 56 ~FltkViewport (); 57 58 void resize(int x, int y, int w, int h); 59 void draw (); 60 int handle (int event); 61 62 void setCanvasSize (int width, int ascent, int descent); 63 64 bool usesViewport (); 65 int getHScrollbarThickness (); 66 int getVScrollbarThickness (); 67 void scroll(int dx, int dy); 68 void scroll(dw::core::ScrollCommand cmd); 69 void scrollTo (int x, int y); 70 void setViewportSize (int width, int height, 71 int hScrollbarThickness, int vScrollbarThickness); 72 void setScrollStep(int step); 73 74 void setGadgetOrientation (bool hscrollbarVisible, bool vscrollbarVisible, 75 GadgetOrientation gadgetOrientation); setDragScroll(bool enable)76 void setDragScroll (bool enable) { hasDragScroll = enable ? 1 : 0; } 77 void addGadget (Fl_Widget *gadget); 78 }; 79 80 } // namespace fltk 81 } // namespace dw 82 83 #endif // __DW_FLTKVIEWPORT_HH__ 84 85