27#include "../lout/msg.h"
28#include "../lout/misc.hh"
31#include <FL/fl_draw.H>
32#include <FL/Fl_Input.H>
33#include <FL/Fl_Text_Editor.H>
34#include <FL/Fl_Check_Button.H>
35#include <FL/Fl_Round_Button.H>
36#include <FL/Fl_Choice.H>
37#include <FL/Fl_Browser.H>
45 return fl_color_average(c, bg, .33f);
57class CustInput2 :
public Fl_Input {
59 CustInput2 (
int x,
int y,
int w,
int h,
const char* l=0);
60 ~CustInput2 () {
if (placeholder) free(placeholder); };
61 void set_placeholder(
const char *str);
62 int show_placeholder();
63 int show_normal(
const char *str);
64 void textcolor(Fl_Color c);
65 void input_type(
int t);
66 int value(
const char* str);
71 bool showing_placeholder;
76CustInput2::CustInput2 (
int x,
int y,
int w,
int h,
const char* l) :
80 showing_placeholder =
false;
81 usual_color = FL_BLACK;
87int CustInput2::show_normal(
const char *str)
89 showing_placeholder =
false;
90 Fl_Input::textcolor(usual_color);
91 Fl_Input::input_type(usual_type);
92 return Fl_Input::value(str);
98int CustInput2::show_placeholder()
102 showing_placeholder =
true;
104 Fl_Input::input_type(FL_NORMAL_INPUT);
105 ret = Fl_Input::value(placeholder);
113void CustInput2::set_placeholder(
const char *str)
119 if ((Fl::focus() !=
this) && !*value()) {
127void CustInput2::textcolor(Fl_Color c)
130 if (showing_placeholder)
132 Fl_Input::textcolor(c);
138void CustInput2::input_type(
int t)
141 Fl_Input::input_type(t);
149int CustInput2::value(
const char *str)
151 return (placeholder && (!str || !*str) && Fl::focus() !=
this)
152 ? show_placeholder() : show_normal(str);
158const char* CustInput2::value()
160 return showing_placeholder ?
"" : Fl_Input::value();
163int CustInput2::handle(
int e)
165 int rc, k = Fl::event_key();
167 _MSG(
"CustInput2::handle event=%d\n", e);
170 unsigned modifier = Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT);
172 if (e == FL_KEYBOARD) {
173 if (k == FL_Page_Down || k == FL_Page_Up || k == FL_Up || k == FL_Down) {
177 if (modifier == FL_CTRL) {
181 }
else if (k ==
'k') {
182 cut(position(), size());
184 }
else if (k ==
'd') {
185 cut(position(), position()+1);
187 }
else if (k ==
'h' || k ==
'i' || k ==
'j' || k ==
'l' || k ==
'm') {
194 }
else if (e == FL_UNFOCUS) {
195 if (placeholder && !value()[0]) {
200 rc = Fl_Input::handle(e);
202 if (rc && e == FL_FOCUS) {
204 if (showing_placeholder)
213class CustTextEditor :
public Fl_Text_Editor {
215 CustTextEditor (
int x,
int y,
int w,
int h,
const char* l=0);
217 void set_placeholder(
const char *str);
218 void show_placeholder();
219 void show_normal(
const char *str);
220 void textcolor(Fl_Color c);
221 void value(
const char* str);
226 bool showing_placeholder;
227 Fl_Color usual_color;
231CustTextEditor::CustTextEditor (
int x,
int y,
int w,
int h,
const char* l) :
232 Fl_Text_Editor(x,y,w,h,l)
235 showing_placeholder =
false;
236 buffer(
new Fl_Text_Buffer());
237 usual_color = FL_BLACK;
241CustTextEditor::~CustTextEditor ()
243 Fl_Text_Buffer *buf = buffer();
257void CustTextEditor::show_normal(
const char *str)
259 showing_placeholder =
false;
260 Fl_Text_Editor::textcolor(usual_color);
267void CustTextEditor::show_placeholder()
269 showing_placeholder =
true;
270 Fl_Text_Editor::textcolor(
fltkui_dimmed(usual_color, color()));
271 buffer()->text(placeholder);
277void CustTextEditor::set_placeholder(
const char *str)
283 if ((Fl::focus() !=
this) && buffer()->length() == 0) {
291void CustTextEditor::textcolor(Fl_Color c)
294 if (showing_placeholder)
296 Fl_Text_Editor::textcolor(c);
302void CustTextEditor::value(
const char *str)
304 if (placeholder && (!str || !*str) && Fl::focus() !=
this)
313char* CustTextEditor::value()
320 text_copy = showing_placeholder ?
dStrdup(
"") : buffer()->text();
324int CustTextEditor::handle(
int e)
328 if (e == FL_UNFOCUS) {
329 if (placeholder && buffer()->length() == 0) {
334 rc = Fl_Text_Editor::handle(e);
336 if (rc && e == FL_FOCUS) {
338 if (showing_placeholder)
349class CustChoice :
public Fl_Choice {
351 CustChoice (
int x,
int y,
int w,
int h,
const char* l=0) :
352 Fl_Choice(x,y,w,h,l) {};
356int CustChoice::handle(
int e)
358 int k = Fl::event_key();
359 unsigned modifier = Fl::event_state() & (FL_SHIFT|FL_CTRL|FL_ALT|FL_META);
361 _MSG(
"CustChoice::handle %p e=%d active=%d focus=%d\n",
362 this, e, active(), (Fl::focus() ==
this));
363 if (Fl::focus() !=
this) {
365 }
else if (e == FL_KEYDOWN && modifier == 0) {
366 if (k == FL_Enter || k == FL_Down) {
367 return Fl_Choice::handle(FL_PUSH);
369 }
else if (isalnum(k)) {
370 int t = value()+1 >= size() ? 0 : value()+1;
371 while (t != value()) {
372 const Fl_Menu_Item *mi = &(menu()[t]);
375 else if (mi->label() && mi->active()) {
376 if (k == tolower(mi->label()[0])) {
387 return Fl_Choice::handle(e);
447 MSG_ERR(
"FltkResource::attachView: multiple views!\n");
463 if (this->view !=
view)
464 MSG_ERR(
"FltkResource::detachView: this->view: %p view: %p\n",
465 (
void *) this->view, (
void *)
view);
493 this->style->
unref ();
515 Fl_Color fg = fl_contrast(style_fg, normal_bg);
518 widget->selection_color(fg);
608class EnterButton :
public Fl_Button {
610 EnterButton (
int x,
int y,
int w,
int h,
const char* label = 0) :
611 Fl_Button (x,y,w,h,label) {};
615int EnterButton::handle(
int e)
617 if (e == FL_KEYBOARD && Fl::focus() ==
this && Fl::event_key() == FL_Enter){
619 simulate_key_action();
623 return Fl_Button::handle(e);
646 button->when (FL_WHEN_RELEASE);
663 requisition->
width = 1;
680 int s1 = Fl::event_state ();
695 event->xCanvas = Fl::event_x();
696 event->yCanvas = Fl::event_y();
698 event->button = Fl::event_button();
699 event->numPressed = Fl::event_clicks() + 1;
705 if (!Fl::event_button3()) {
721 free((
char *)this->label);
724 widget->label (this->label);
732 *widget,
bool relief):
738 ComplexButtonResource::init (
widget);
750 if (Fl::event() == FL_RELEASE && Fl::event_button() != FL_RIGHT_MOUSE) {
767 }
else if (Fl::event() == FL_KEYBOARD) {
777 event.numPressed = 1;
805 "<b>resize</b> (%d %d, <i>%d - 2 * %d =</i> %d, "
806 "<i>%d + %d - 2 * %d =</i> %d)",
846 button->when (FL_WHEN_RELEASE);
848 button->box(FL_NO_BOX);
865 bool password,
const char *label,
866 const char *placeholder):
897 input->input_type(
password ? FL_SECRET_INPUT : FL_NORMAL_INPUT);
899 input->when (FL_WHEN_ENTER_KEY_ALWAYS);
903 input->align(FL_ALIGN_LEFT);
916 CustInput2 *in = (CustInput2 *)
widget;
920 in->textcolor(
widget->labelcolor());
921 in->cursor_color(
widget->labelcolor());
922 in->textsize(in->labelsize());
923 in->textfont(in->labelfont());
955 requisition->
width = 0;
971 "<b>sizeAllocate</b> (%d, %d; %d * (%d + %d))",
992 return ((CustInput2*)
widget)->value ();
1016 ((Fl_Input *)
widget)->maximum_size(maxlen);
1023 int p1, p2 = e->insert_position();
1026 p1 = e->insert_position();
1027 e->buffer()->remove(p1, p2);
1028 e->show_insert_position();
1030 if (e->when() & FL_WHEN_CHANGED)
1037 const char *placeholder):
1071 CustTextEditor *text =
1074 text->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
1075 text->remove_key_binding(FL_BackSpace, FL_TEXT_EDITOR_ANY_STATE);
1076 text->add_key_binding(FL_BackSpace, 0, Fl_Text_Editor::kf_backspace);
1086 CustTextEditor *ed = (CustTextEditor *)
widget;
1090 ed->textcolor(
widget->labelcolor());
1091 ed->cursor_color(
widget->labelcolor());
1092 ed->textsize(ed->labelsize());
1093 ed->textfont(ed->labelfont());
1105 requisition->
width =
1114 requisition->
width = 1;
1126 return ((CustTextEditor*)
widget)->value ();
1131 ((CustTextEditor*)
widget)->value (text);
1165 Fl_Button *button = createNewButton (allocation);
1166 button->value (initActivated);
1176 widget->selection_color(FL_BLACK);
1194 requisition->
width = 1;
1208 return ((Fl_Button*)this->widget)->value ();
1215 initActivated = activated;
1216 ((Fl_Button*)this->widget)->value (initActivated);
1238 Fl_Check_Button *cb =
1248 return it.hasNext ();
1264 *radioButtonResource)
1266 list =
new lout::container::typed::List <FltkRadioButtonResource> (
false);
1267 connect (radioButtonResource);
1276 *radioButtonResource)
1278 list->append (radioButtonResource);
1282 *radioButtonResource)
1284 list->removeRef (radioButtonResource);
1285 if (
list->isEmpty ())
1321 if (
widget->when () & FL_WHEN_CHANGED)
1327 for (Iterator <FltkRadioButtonResource> it =
group->
iterator ();
1352 button->when (FL_WHEN_CHANGED);
1354 button->type (FL_TOGGLE_BUTTON);
1389 free((
char *)
menu[i].text);
1397 Fl_Choice *ch = (Fl_Choice *)
widget;
1401 ch->textcolor(
widget->labelcolor());
1402 ch->textfont(ch->labelfont());
1403 ch->textsize(ch->labelsize());
1428 const char *str =
menu[i].text;
1431 width = fl_width(str);
1449 requisition->
width = maxItemWidth
1453 requisition->
width = 1;
1465 Fl_Choice *ch = (Fl_Choice *)
widget;
1466 int selected = ch->value();
1467 Fl_Menu_Item *newMenu;
1472 memset(newMenu +
itemsUsed, 0, 0x10 *
sizeof(Fl_Menu_Item));
1476 ch->value(selected);
1493 bool enabled,
bool selected)
1495 Fl_Menu_Item *item =
newItem();
1500 item->flags = FL_MENU_INACTIVE;
1503 ((Fl_Choice *)
widget)->value(item);
1516 Fl_Menu_Item *item =
newItem();
1521 item->flags = FL_MENU_INACTIVE;
1523 item->flags |= FL_SUBMENU;
1537 return index == ((Fl_Choice *)
widget)->value();
1542 return ((Fl_Choice*)
widget)->size();
1547class CustBrowser :
public Fl_Browser {
1549 CustBrowser(
int x,
int y,
int w,
int h) : Fl_Browser(x, y, w, h) {};
1550 int full_width()
const;
1551 int full_height()
const {
return Fl_Browser::full_height();}
1552 int avg_height() {
return size() ? Fl_Browser_::incr_height() : 0;}
1558int CustBrowser::full_width()
const
1561 void *item = item_first();
1564 int w = item_width(item);
1569 item = item_next(item);
1576 selectionMode,
int rowCount):
1580 mode = selectionMode;
1596 b->type((
mode == SELECTION_MULTIPLE) ? FL_MULTI_BROWSER : FL_HOLD_BROWSER);
1598 b->when(FL_WHEN_CHANGED);
1600 b->column_char(
'\a');
1608 Fl_Browser *b = (Fl_Browser *)
widget;
1612 b->textfont(
widget->labelfont());
1613 b->textsize(
widget->labelsize());
1614 b->textcolor(
widget->labelcolor());
1624 Fl_Browser *b = (Fl_Browser *)
widget;
1626 if (b->selected(b->value())) {
1630 const char *inactive_code;
1631 if ((inactive_code = strstr(b->text(b->value()),
"@N"))) {
1632 const char *ignore_codes = strstr(b->text(b->value()),
"@.");
1634 if (inactive_code < ignore_codes)
1635 b->select(b->value(), 0);
1642 Fl_Browser *b = (Fl_Browser *)
widget;
1643 int index = b->size() + 1;
1644 char *label = (
char *)malloc(strlen(str) + 1 +
currDepth + 4),
1664 b->select(index, selected);
1665 if (b->type() == FL_HOLD_BROWSER) {
1696 Fl_Browser *b = (Fl_Browser *)
widget;
1698 b->select(index + 1, selected);
1704 bool selected =
false;
1708 if (!name || !*name)
1720 CustBrowser *b = (CustBrowser *)
widget;
1731 return ((CustBrowser *)
widget)->full_width();
1739 CustBrowser *b = (CustBrowser *)
widget;
1740 int height = b->full_height();
1743 if (
showRows * b->avg_height() < height) {
1744 height =
showRows * b->avg_height();
1745 b->has_scrollbar(Fl_Browser_::VERTICAL_ALWAYS);
1746 requisition->
width += Fl::scrollbar_size();
1748 b->has_scrollbar(0);
1754 requisition->
width = 1;
1766 return ((Fl_Browser*)
widget)->size();
1771 Fl_Browser *b = (Fl_Browser *)
widget;
1773 return b->selected(index + 1) ? true :
false;
Set at the top when drawing.
This implementation of dw::core::Iterator can be used by widgets with no contents.
Iterators are used to iterate through the contents of a widget.
The central class for managing and drawing a widget tree.
void attachView(View *view)
Attach a view to the layout.
dw::core::Shape implementation for simple rectangles.
An interface to encapsulate platform dependent drawing.
void emitClicked(EventButton *event)
void queueResize(bool extremesChanged)
This interface adds some more methods for all flkt-based views.
virtual void drawFltkWidget(Fl_Widget *widget, core::Rectangle *area)
virtual void removeFltkWidget(Fl_Widget *widget)
virtual void addFltkWidget(Fl_Widget *widget, core::Allocation *allocation)
virtual void allocateFltkWidget(Fl_Widget *widget, core::Allocation *allocation)
virtual bool usesFltkWidgets()=0
void setWidgetStyle(Fl_Widget *widget, core::style::Style *style)
void setMaxLength(int maxlen)
void sizeRequest(core::Requisition *requisition)
void sizeAllocate(core::Allocation *allocation)
void setDisplayed(bool displayed)
void setEditable(bool editable)
static void widgetCallback(Fl_Widget *widget, void *data)
Fl_Widget * createNewWidget(core::Allocation *allocation)
FltkEntryResource(FltkPlatform *platform, int size, bool password, const char *label, const char *placeholder)
void setText(const char *text)
ListResource::SelectionMode mode
void setWidgetStyle(Fl_Widget *widget, core::style::Style *style)
Fl_Widget * createNewWidget(core::Allocation *allocation)
void * newItem(const char *str, bool enabled, bool selected)
bool isSelected(int index)
static void widgetCallback(Fl_Widget *widget, void *data)
void pushGroup(const char *name, bool enabled)
void setItem(int index, bool selected)
void addItem(const char *str, bool enabled, bool selected)
FltkListResource(FltkPlatform *platform, core::ui::ListResource::SelectionMode selectionMode, int rows)
void sizeRequest(core::Requisition *requisition)
void setEditable(bool editable)
void sizeRequest(core::Requisition *requisition)
Fl_Widget * createNewWidget(core::Allocation *allocation)
~FltkMultiLineTextResource()
void setText(const char *text)
void setWidgetStyle(Fl_Widget *widget, core::style::Style *style)
FltkMultiLineTextResource(FltkPlatform *platform, int cols, int rows, const char *placeholder)
virtual void detachView(FltkView *view)
void setDisplayed(bool displayed)
void init(FltkPlatform *platform)
This is not a constructor, since it calls some virtual methods, which should not be done in a C++ bas...
void setEnabled(bool enabled)
void setStyle(core::style::Style *style)
void sizeAllocate(core::Allocation *allocation)
virtual void attachView(FltkView *view)
FltkResource(FltkPlatform *platform)
core::style::Style * style
virtual void setWidgetStyle(Fl_Widget *widget, core::style::Style *style)
void draw(core::View *view, core::Rectangle *area, core::DrawingContext *context)
core::Allocation allocation
virtual Fl_Widget * createNewWidget(core::Allocation *allocation)=0
dw::core::Iterator * iterator(dw::core::Content::Type mask, bool atEnd)
void setStyle(core::style::Style *style)
void draw(core::View *view, core::Rectangle *area, core::DrawingContext *context)
void sizeAllocate(core::Allocation *allocation)
void setEnabled(bool enabled)
FltkSpecificResource(FltkPlatform *platform)
#define DBG_OBJ_ENTER0(aspect, prio, funname)
#define DBG_OBJ_CREATE(klass)
#define DBG_OBJ_MSGF(aspect, prio, fmt,...)
#define DBG_OBJ_SET_NUM(var, val)
#define DBG_OBJ_MSGF_O(aspect, prio, obj, fmt,...)
#define DBG_OBJ_ENTER(aspect, prio, funname, fmt,...)
#define DBG_OBJ_BASECLASS(klass)
char * dStrdup(const char *s)
static FltkPlatform * platform
static Fl_Color fltkui_dimmed(Fl_Color c, Fl_Color bg)
ButtonState
Platform independent representation.
static int kf_backspace_word(int c, Fl_Text_Editor *e)
static void setButtonEvent(dw::core::EventButton *event)
static core::ButtonState getDwButtonState()
Dw is in this namespace, or sub namespaces of this one.
This namespace provides thin wrappers, implemented as C++ templates, to gain type-safety.
Here, some common classes (or interfaces) are defined, to standardize the access to other classes.
Represents the allocation, i.e.