00001 #ifndef __DW_FLTKVIEWPORT_HH__
00002 #define __DW_FLTKVIEWPORT_HH__
00003
00004 #include <FL/Fl_Group.H>
00005 #include <FL/Fl_Scrollbar.H>
00006
00007 #include "core.hh"
00008 #include "fltkcore.hh"
00009 #include "fltkviewbase.hh"
00010
00011 namespace dw {
00012 namespace fltk {
00013
00014 class FltkViewport: public FltkWidgetView
00015 {
00016 public:
00017 enum GadgetOrientation { GADGET_VERTICAL, GADGET_HORIZONTAL };
00018
00019 private:
00020 enum { SCROLLBAR_THICKNESS = 15 };
00021
00022 int scrollX, scrollY;
00023 int scrollDX, scrollDY;
00024 int hasDragScroll, dragScrolling, dragX, dragY;
00025 int horScrolling, verScrolling;
00026
00027 Fl_Scrollbar *vscrollbar, *hscrollbar;
00028
00029 GadgetOrientation gadgetOrientation[4];
00030 lout::container::typed::List <lout::object::TypedPointer < Fl_Widget> >
00031 *gadgets;
00032
00033 void adjustScrollbarsAndGadgetsAllocation ();
00034 void adjustScrollbarValues ();
00035 void hscrollbarChanged ();
00036 void vscrollbarChanged ();
00037 void positionChanged ();
00038
00039 static void hscrollbarCallback (Fl_Widget *hscrollbar, void *viewportPtr);
00040 static void vscrollbarCallback (Fl_Widget *vscrollbar, void *viewportPtr);
00041
00042 void updateCanvasWidgets (int oldScrollX, int oldScrollY);
00043 static void draw_area (void *data, int x, int y, int w, int h);
00044
00045 protected:
00046 int translateViewXToCanvasX (int x);
00047 int translateViewYToCanvasY (int y);
00048 int translateCanvasXToViewX (int x);
00049 int translateCanvasYToViewY (int y);
00050
00051 public:
00052 FltkViewport (int x, int y, int w, int h, const char *label = 0);
00053 ~FltkViewport ();
00054
00055 void resize(int x, int y, int w, int h);
00056 void draw ();
00057 int handle (int event);
00058
00059 void setCanvasSize (int width, int ascent, int descent);
00060
00061 bool usesViewport ();
00062 int getHScrollbarThickness ();
00063 int getVScrollbarThickness ();
00064 void scroll(int dx, int dy);
00065 void scroll(dw::core::ScrollCommand cmd);
00066 void scrollTo (int x, int y);
00067 void setViewportSize (int width, int height,
00068 int hScrollbarThickness, int vScrollbarThickness);
00069 void setScrollStep(int step);
00070
00071 void setGadgetOrientation (bool hscrollbarVisible, bool vscrollbarVisible,
00072 GadgetOrientation gadgetOrientation);
00073 void setDragScroll (bool enable) { hasDragScroll = enable ? 1 : 0; }
00074 void addGadget (Fl_Widget *gadget);
00075 };
00076
00077 }
00078 }
00079
00080 #endif // __DW_FLTKVIEWPORT_HH__
00081