00001 #ifndef __DW_FLTK_UI_HH__
00002 #define __DW_FLTK_UI_HH__
00003
00004 #ifndef __INCLUDED_FROM_DW_FLTK_CORE_HH__
00005 # error Do not include this file directly, use "fltkcore.hh" instead.
00006 #endif
00007
00008 #include <FL/Fl_Button.H>
00009 #include <FL/Fl_Menu.H>
00010 #include <FL/Fl_Text_Buffer.H>
00011
00012 namespace dw {
00013 namespace fltk {
00014
00168 namespace ui {
00169
00173 class FltkResource: public lout::object::Object
00174 {
00175 private:
00176 bool enabled;
00177
00178 protected:
00179 FltkView *view;
00180 Fl_Widget *widget;
00181 core::Allocation allocation;
00182 FltkPlatform *platform;
00183
00184 core::style::Style *style;
00185
00186 FltkResource (FltkPlatform *platform);
00187 void init (FltkPlatform *platform);
00188 virtual Fl_Widget *createNewWidget (core::Allocation *allocation) = 0;
00189
00190 virtual void setWidgetStyle (Fl_Widget *widget, core::style::Style *style);
00191 void setDisplayed (bool displayed);
00192 bool displayed();
00193 public:
00194 ~FltkResource ();
00195
00196 virtual void attachView (FltkView *view);
00197 virtual void detachView (FltkView *view);
00198
00199 void sizeAllocate (core::Allocation *allocation);
00200 void draw (core::View *view, core::Rectangle *area);
00201
00202 void setStyle (core::style::Style *style);
00203
00204 bool isEnabled ();
00205 void setEnabled (bool enabled);
00206 };
00207
00208
00209 template <class I> class FltkSpecificResource: public I, public FltkResource
00210 {
00211 public:
00212 inline FltkSpecificResource (FltkPlatform *platform) :
00213 FltkResource (platform) { }
00214
00215 void sizeAllocate (core::Allocation *allocation);
00216 void draw (core::View *view, core::Rectangle *area);
00217 void setStyle (core::style::Style *style);
00218
00219 bool isEnabled ();
00220 void setEnabled (bool enabled);
00221 };
00222
00223
00224 class FltkLabelButtonResource:
00225 public FltkSpecificResource <dw::core::ui::LabelButtonResource>
00226 {
00227 private:
00228 const char *label;
00229
00230 static void widgetCallback (Fl_Widget *widget, void *data);
00231
00232 protected:
00233 Fl_Widget *createNewWidget (core::Allocation *allocation);
00234
00235 public:
00236 FltkLabelButtonResource (FltkPlatform *platform, const char *label);
00237 ~FltkLabelButtonResource ();
00238
00239 void sizeRequest (core::Requisition *requisition);
00240
00241 const char *getLabel ();
00242 void setLabel (const char *label);
00243 };
00244
00245
00246 class FltkComplexButtonResource:
00247 public FltkSpecificResource <dw::core::ui::ComplexButtonResource>
00248 {
00249 private:
00250 bool relief;
00251
00252 static void widgetCallback (Fl_Widget *widget, void *data);
00253
00254 protected:
00255 FltkView *topView, *flatView;
00256
00257 void attachView (FltkView *view);
00258 void detachView (FltkView *view);
00259
00260 void sizeAllocate (core::Allocation *allocation);
00261
00262 dw::core::Platform *createPlatform ();
00263 void setLayout (dw::core::Layout *layout);
00264
00265 int reliefXThickness ();
00266 int reliefYThickness ();
00267
00268 Fl_Widget *createNewWidget (core::Allocation *allocation);
00269
00270 public:
00271 FltkComplexButtonResource (FltkPlatform *platform, dw::core::Widget *widget,
00272 bool relief);
00273 ~FltkComplexButtonResource ();
00274 };
00275
00276
00281 class FltkEntryResource:
00282 public FltkSpecificResource <dw::core::ui::EntryResource>
00283 {
00284 private:
00285 int maxLength;
00286 bool password;
00287 const char *initText;
00288 char *label;
00289 int label_w;
00290 bool editable;
00291
00292 static void widgetCallback (Fl_Widget *widget, void *data);
00293 void setDisplayed (bool displayed);
00294
00295 protected:
00296 Fl_Widget *createNewWidget (core::Allocation *allocation);
00297 void setWidgetStyle (Fl_Widget *widget, core::style::Style *style);
00298
00299 public:
00300 FltkEntryResource (FltkPlatform *platform, int maxLength, bool password,
00301 const char *label);
00302 ~FltkEntryResource ();
00303
00304 void sizeRequest (core::Requisition *requisition);
00305 void sizeAllocate (core::Allocation *allocation);
00306
00307 const char *getText ();
00308 void setText (const char *text);
00309 bool isEditable ();
00310 void setEditable (bool editable);
00311 };
00312
00313
00314 class FltkMultiLineTextResource:
00315 public FltkSpecificResource <dw::core::ui::MultiLineTextResource>
00316 {
00317 private:
00318 Fl_Text_Buffer *buffer;
00319 char *text_copy;
00320 bool editable;
00321 int numCols, numRows;
00322
00323 protected:
00324 Fl_Widget *createNewWidget (core::Allocation *allocation);
00325 void setWidgetStyle (Fl_Widget *widget, core::style::Style *style);
00326
00327 public:
00328 FltkMultiLineTextResource (FltkPlatform *platform, int cols, int rows);
00329 ~FltkMultiLineTextResource ();
00330
00331 void sizeRequest (core::Requisition *requisition);
00332
00333 const char *getText ();
00334 void setText (const char *text);
00335 bool isEditable ();
00336 void setEditable (bool editable);
00337 };
00338
00339
00340 template <class I> class FltkToggleButtonResource:
00341 public FltkSpecificResource <I>
00342 {
00343 private:
00344 bool initActivated;
00345
00346 protected:
00347 virtual Fl_Button *createNewButton (core::Allocation *allocation) = 0;
00348 Fl_Widget *createNewWidget (core::Allocation *allocation);
00349 void setWidgetStyle (Fl_Widget *widget, core::style::Style *style);
00350
00351 public:
00352 FltkToggleButtonResource (FltkPlatform *platform,
00353 bool activated);
00354 ~FltkToggleButtonResource ();
00355
00356 void sizeRequest (core::Requisition *requisition);
00357
00358 bool isActivated ();
00359 void setActivated (bool activated);
00360 };
00361
00362
00363 class FltkCheckButtonResource:
00364 public FltkToggleButtonResource <dw::core::ui::CheckButtonResource>
00365 {
00366 protected:
00367 Fl_Button *createNewButton (core::Allocation *allocation);
00368
00369 public:
00370 FltkCheckButtonResource (FltkPlatform *platform,
00371 bool activated);
00372 ~FltkCheckButtonResource ();
00373 };
00374
00375
00376 class FltkRadioButtonResource:
00377 public FltkToggleButtonResource <dw::core::ui::RadioButtonResource>
00378 {
00379 private:
00380 class Group
00381 {
00382 private:
00383 class FltkGroupIterator:
00384 public dw::core::ui::RadioButtonResource::GroupIterator
00385 {
00386 private:
00387 lout::container::typed::Iterator <FltkRadioButtonResource> it;
00388
00389 public:
00390 inline FltkGroupIterator (lout::container::typed::List
00391 <FltkRadioButtonResource>
00392 *list)
00393 { it = list->iterator (); }
00394
00395 bool hasNext ();
00396 dw::core::ui::RadioButtonResource *getNext ();
00397 void unref ();
00398 };
00399
00400 lout::container::typed::List <FltkRadioButtonResource> *list;
00401
00402 protected:
00403 ~Group ();
00404
00405 public:
00406 Group (FltkRadioButtonResource *radioButtonResource);
00407
00408 inline lout::container::typed::Iterator <FltkRadioButtonResource>
00409 iterator ()
00410 {
00411 return list->iterator ();
00412 }
00413
00414 inline dw::core::ui::RadioButtonResource::GroupIterator
00415 *groupIterator ()
00416 {
00417 return new FltkGroupIterator (list);
00418 }
00419
00420 void connect (FltkRadioButtonResource *radioButtonResource);
00421 void unconnect (FltkRadioButtonResource *radioButtonResource);
00422 };
00423
00424 Group *group;
00425
00426 static void widgetCallback (Fl_Widget *widget, void *data);
00427 void buttonClicked ();
00428
00429 protected:
00430 Fl_Button *createNewButton (core::Allocation *allocation);
00431
00432 public:
00433 FltkRadioButtonResource (FltkPlatform *platform,
00434 FltkRadioButtonResource *groupedWith,
00435 bool activated);
00436 ~FltkRadioButtonResource ();
00437
00438 GroupIterator *groupIterator ();
00439 };
00440
00441
00442 template <class I> class FltkSelectionResource:
00443 public FltkSpecificResource <I>
00444 {
00445 protected:
00446 virtual bool setSelectedItems() { return false; }
00447 virtual void addItem (const char *str, bool enabled, bool selected) = 0;
00448 virtual void pushGroup (const char *name, bool enabled) = 0;
00449 virtual void popGroup () = 0;
00450 public:
00451 FltkSelectionResource (FltkPlatform *platform) :
00452 FltkSpecificResource<I> (platform) {};
00453 dw::core::Iterator *iterator (dw::core::Content::Type mask, bool atEnd);
00454 };
00455
00456
00457 class FltkOptionMenuResource:
00458 public FltkSelectionResource <dw::core::ui::OptionMenuResource>
00459 {
00460 protected:
00461 Fl_Widget *createNewWidget (core::Allocation *allocation);
00462 virtual bool setSelectedItems() { return true; }
00463 void setWidgetStyle (Fl_Widget *widget, core::style::Style *style);
00464 int getNumberOfItems();
00465 int getMaxItemWidth ();
00466 private:
00467 static void widgetCallback (Fl_Widget *widget, void *data);
00468 void enlargeMenu();
00469 Fl_Menu_Item *newItem();
00470 Fl_Menu_Item *menu;
00471 int itemsAllocated, itemsUsed;
00472 int visibleItems;
00473 public:
00474 FltkOptionMenuResource (FltkPlatform *platform);
00475 ~FltkOptionMenuResource ();
00476
00477 void addItem (const char *str, bool enabled, bool selected);
00478 void pushGroup (const char *name, bool enabled);
00479 void popGroup ();
00480
00481 void sizeRequest (core::Requisition *requisition);
00482 bool isSelected (int index);
00483 };
00484
00485 class FltkListResource:
00486 public FltkSelectionResource <dw::core::ui::ListResource>
00487 {
00488 protected:
00489 Fl_Widget *createNewWidget (core::Allocation *allocation);
00490 void setWidgetStyle (Fl_Widget *widget, core::style::Style *style);
00491
00492 int getNumberOfItems () {return itemsSelected.size();};
00493 int getMaxItemWidth ();
00494
00495 private:
00496 static void widgetCallback (Fl_Widget *widget, void *data);
00497 void *newItem (const char *str, bool enabled, bool selected);
00498 void *currParent;
00499 lout::misc::SimpleVector <bool> itemsSelected;
00500 int showRows;
00501 ListResource::SelectionMode mode;
00502 public:
00503 FltkListResource (FltkPlatform *platform,
00504 core::ui::ListResource::SelectionMode selectionMode,
00505 int rows);
00506 ~FltkListResource ();
00507
00508 void addItem (const char *str, bool enabled, bool selected);
00509 void pushGroup (const char *name, bool enabled);
00510 void popGroup ();
00511
00512 void sizeRequest (core::Requisition *requisition);
00513 bool isSelected (int index);
00514 };
00515
00516
00517 }
00518 }
00519 }
00520
00521
00522 #endif // __DW_FLTK_UI_HH__