26#include "../lout/msg.h"
27#include "../lout/misc.hh"
30#include <FL/fl_draw.H>
31#include <FL/Fl_Input.H>
32#include <FL/Fl_Text_Editor.H>
33#include <FL/Fl_Check_Button.H>
34#include <FL/Fl_Round_Button.H>
35#include <FL/Fl_Choice.H>
36#include <FL/Fl_Browser.H>
44 return fl_color_average(c, bg, .33f);
56class CustInput2 :
public Fl_Input {
58 CustInput2 (
int x,
int y,
int w,
int h,
const char* l=0);
59 ~CustInput2 () {
if (placeholder) free(placeholder); };
60 void set_placeholder(
const char *str);
61 int show_placeholder();
62 int show_normal(
const char *str);
63 void textcolor(Fl_Color c);
64 void input_type(
int t);
65 int value(
const char* str);
70 bool showing_placeholder;
75CustInput2::CustInput2 (
int x,
int y,
int w,
int h,
const char* l) :
79 showing_placeholder =
false;
80 usual_color = FL_BLACK;
86int CustInput2::show_normal(
const char *str)
88 showing_placeholder =
false;
89 Fl_Input::textcolor(usual_color);
90 Fl_Input::input_type(usual_type);
91 return Fl_Input::value(str);
97int CustInput2::show_placeholder()
101 showing_placeholder =
true;
103 Fl_Input::input_type(FL_NORMAL_INPUT);
104 ret = Fl_Input::value(placeholder);
112void CustInput2::set_placeholder(
const char *str)
118 if ((Fl::focus() !=
this) && !*value()) {
126void CustInput2::textcolor(Fl_Color c)
129 if (showing_placeholder)
131 Fl_Input::textcolor(c);
137void CustInput2::input_type(
int t)
140 Fl_Input::input_type(t);
148int CustInput2::value(
const char *str)
150 return (placeholder && (!str || !*str) && Fl::focus() !=
this)
151 ? show_placeholder() : show_normal(str);
157const char* CustInput2::value()
159 return showing_placeholder ?
"" : Fl_Input::value();
162int CustInput2::handle(
int e)
164 int rc, k = Fl::event_key();
166 _MSG(
"CustInput2::handle event=%d\n", e);
169 unsigned modifier = Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT);
171 if (e == FL_KEYBOARD) {
172 if (k == FL_Page_Down || k == FL_Page_Up || k == FL_Up || k == FL_Down) {
176 if (modifier == FL_CTRL) {
177 if (k ==
'a' || k ==
'e') {
178 position(k ==
'a' ? 0 : size());
180 }
else if (k ==
'k') {
181 cut(position(), size());
183 }
else if (k ==
'd') {
184 cut(position(), position()+1);
186 }
else if (k ==
'h' || k ==
'i' || k ==
'j' || k ==
'l' || k ==
'm') {
193 }
else if (e == FL_UNFOCUS) {
194 if (placeholder && !value()[0]) {
199 rc = Fl_Input::handle(e);
201 if (rc && e == FL_FOCUS) {
203 if (showing_placeholder)
212class CustTextEditor :
public Fl_Text_Editor {
214 CustTextEditor (
int x,
int y,
int w,
int h,
const char* l=0);
216 void set_placeholder(
const char *str);
217 void show_placeholder();
218 void show_normal(
const char *str);
219 void textcolor(Fl_Color c);
220 void value(
const char* str);
225 bool showing_placeholder;
226 Fl_Color usual_color;
230CustTextEditor::CustTextEditor (
int x,
int y,
int w,
int h,
const char* l) :
231 Fl_Text_Editor(x,y,w,h,l)
234 showing_placeholder =
false;
235 buffer(
new Fl_Text_Buffer());
236 usual_color = FL_BLACK;
240CustTextEditor::~CustTextEditor ()
242 Fl_Text_Buffer *buf = buffer();
256void CustTextEditor::show_normal(
const char *str)
258 showing_placeholder =
false;
259 Fl_Text_Editor::textcolor(usual_color);
266void CustTextEditor::show_placeholder()
268 showing_placeholder =
true;
269 Fl_Text_Editor::textcolor(
fltkui_dimmed(usual_color, color()));
270 buffer()->text(placeholder);
276void CustTextEditor::set_placeholder(
const char *str)
282 if ((Fl::focus() !=
this) && buffer()->length() == 0) {
290void CustTextEditor::textcolor(Fl_Color c)
293 if (showing_placeholder)
295 Fl_Text_Editor::textcolor(c);
301void CustTextEditor::value(
const char *str)
303 if (placeholder && (!str || !*str) && Fl::focus() !=
this)
312char* CustTextEditor::value()
319 text_copy = showing_placeholder ?
dStrdup(
"") : buffer()->text();
323int CustTextEditor::handle(
int e)
327 if (e == FL_UNFOCUS) {
328 if (placeholder && buffer()->length() == 0) {
333 rc = Fl_Text_Editor::handle(e);
335 if (rc && e == FL_FOCUS) {
337 if (showing_placeholder)
348class CustChoice :
public Fl_Choice {
350 CustChoice (
int x,
int y,
int w,
int h,
const char* l=0) :
351 Fl_Choice(x,y,w,h,l) {};
355int CustChoice::handle(
int e)
357 int k = Fl::event_key();
358 unsigned modifier = Fl::event_state() & (FL_SHIFT|FL_CTRL|FL_ALT|FL_META);
360 _MSG(
"CustChoice::handle %p e=%d active=%d focus=%d\n",
361 this, e, active(), (Fl::focus() ==
this));
362 if (Fl::focus() !=
this) {
364 }
else if (e == FL_KEYDOWN && modifier == 0) {
365 if (k == FL_Enter || k == FL_Down) {
366 return Fl_Choice::handle(FL_PUSH);
368 }
else if (isalnum(k)) {
369 int t = value()+1 >= size() ? 0 : value()+1;
370 while (t != value()) {
371 const Fl_Menu_Item *mi = &(menu()[t]);
374 else if (mi->label() && mi->active()) {
375 if (k == tolower(mi->label()[0])) {
386 return Fl_Choice::handle(e);
446 MSG_ERR(
"FltkResource::attachView: multiple views!\n");
462 if (this->view !=
view)
463 MSG_ERR(
"FltkResource::detachView: this->view: %p view: %p\n",
464 (
void *) this->view, (
void *)
view);
470 DBG_OBJ_ENTER (
"resize", 0,
"sizeAllocate",
"%d, %d; %d * (%d + %d)",
492 this->style->
unref ();
514 Fl_Color fg = fl_contrast(style_fg, normal_bg);
517 widget->selection_color(fg);
607class EnterButton :
public Fl_Button {
609 EnterButton (
int x,
int y,
int w,
int h,
const char* label = 0) :
610 Fl_Button (x,y,w,h,label) {};
614int EnterButton::handle(
int e)
616 if (e == FL_KEYBOARD && Fl::focus() ==
this && Fl::event_key() == FL_Enter){
618 simulate_key_action();
622 return Fl_Button::handle(e);
645 button->when (FL_WHEN_RELEASE);
662 requisition->
width = 1;
679 int s1 = Fl::event_state ();
694 event->xCanvas = Fl::event_x();
695 event->yCanvas = Fl::event_y();
697 event->button = Fl::event_button();
698 event->numPressed = Fl::event_clicks() + 1;
704 if (!Fl::event_button3()) {
720 free((
char *)this->label);
723 widget->label (this->label);
731 *widget,
bool relief):
737 ComplexButtonResource::init (
widget);
749 if (Fl::event() == FL_RELEASE && Fl::event_button() != FL_RIGHT_MOUSE) {
766 }
else if (Fl::event() == FL_KEYBOARD) {
776 event.numPressed = 1;
804 "<b>resize</b> (%d %d, <i>%d - 2 * %d =</i> %d, "
805 "<i>%d + %d - 2 * %d =</i> %d)",
845 button->when (FL_WHEN_RELEASE);
847 button->box(FL_NO_BOX);
864 bool password,
const char *label,
865 const char *placeholder):
896 input->input_type(
password ? FL_SECRET_INPUT : FL_NORMAL_INPUT);
898 input->when (FL_WHEN_ENTER_KEY_ALWAYS);
902 input->align(FL_ALIGN_LEFT);
915 CustInput2 *in = (CustInput2 *)
widget;
919 in->textcolor(
widget->labelcolor());
920 in->cursor_color(
widget->labelcolor());
921 in->textsize(in->labelsize());
922 in->textfont(in->labelfont());
954 requisition->
width = 0;
970 "<b>sizeAllocate</b> (%d, %d; %d * (%d + %d))",
991 return ((CustInput2*)
widget)->value ();
1015 ((Fl_Input *)
widget)->maximum_size(maxlen);
1022 int p1, p2 = e->insert_position();
1025 p1 = e->insert_position();
1026 e->buffer()->remove(p1, p2);
1027 e->show_insert_position();
1029 if (e->when() & FL_WHEN_CHANGED)
1036 const char *placeholder):
1070 CustTextEditor *text =
1073 text->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
1074 text->remove_key_binding(FL_BackSpace, FL_TEXT_EDITOR_ANY_STATE);
1075 text->add_key_binding(FL_BackSpace, 0, Fl_Text_Editor::kf_backspace);
1085 CustTextEditor *ed = (CustTextEditor *)
widget;
1089 ed->textcolor(
widget->labelcolor());
1090 ed->cursor_color(
widget->labelcolor());
1091 ed->textsize(ed->labelsize());
1092 ed->textfont(ed->labelfont());
1104 requisition->
width =
1113 requisition->
width = 1;
1125 return ((CustTextEditor*)
widget)->value ();
1130 ((CustTextEditor*)
widget)->value (text);
1164 Fl_Button *button = createNewButton (allocation);
1165 button->value (initActivated);
1175 widget->selection_color(FL_BLACK);
1193 requisition->
width = 1;
1207 return ((Fl_Button*)this->widget)->value ();
1214 initActivated = activated;
1215 ((Fl_Button*)this->widget)->value (initActivated);
1237 Fl_Check_Button *cb =
1247 return it.hasNext ();
1263 *radioButtonResource)
1265 list =
new lout::container::typed::List <FltkRadioButtonResource> (
false);
1266 connect (radioButtonResource);
1275 *radioButtonResource)
1277 list->append (radioButtonResource);
1281 *radioButtonResource)
1283 list->removeRef (radioButtonResource);
1284 if (
list->isEmpty ())
1320 if (
widget->when () & FL_WHEN_CHANGED)
1326 for (Iterator <FltkRadioButtonResource> it =
group->
iterator ();
1351 button->when (FL_WHEN_CHANGED);
1353 button->type (FL_TOGGLE_BUTTON);
1388 free((
char *)
menu[i].text);
1396 Fl_Choice *ch = (Fl_Choice *)
widget;
1400 ch->textcolor(
widget->labelcolor());
1401 ch->textfont(ch->labelfont());
1402 ch->textsize(ch->labelsize());
1427 const char *str =
menu[i].text;
1430 width = fl_width(str);
1448 requisition->
width = maxItemWidth
1452 requisition->
width = 1;
1464 Fl_Choice *ch = (Fl_Choice *)
widget;
1465 int selected = ch->value();
1466 Fl_Menu_Item *newMenu;
1471 memset(newMenu +
itemsUsed, 0, 0x10 *
sizeof(Fl_Menu_Item));
1475 ch->value(selected);
1492 bool enabled,
bool selected)
1494 Fl_Menu_Item *item =
newItem();
1499 item->flags = FL_MENU_INACTIVE;
1502 ((Fl_Choice *)
widget)->value(item);
1515 Fl_Menu_Item *item =
newItem();
1520 item->flags = FL_MENU_INACTIVE;
1522 item->flags |= FL_SUBMENU;
1536 return index == ((Fl_Choice *)
widget)->value();
1541 return ((Fl_Choice*)
widget)->size();
1546class CustBrowser :
public Fl_Browser {
1548 CustBrowser(
int x,
int y,
int w,
int h) : Fl_Browser(x, y, w, h) {};
1549 int full_width()
const;
1550 int full_height()
const {
return Fl_Browser::full_height();}
1551 int avg_height() {
return size() ? Fl_Browser_::incr_height() : 0;}
1557int CustBrowser::full_width()
const
1560 void *item = item_first();
1563 int w = item_width(item);
1568 item = item_next(item);
1575 selectionMode,
int rowCount):
1579 mode = selectionMode;
1595 b->type((
mode == SELECTION_MULTIPLE) ? FL_MULTI_BROWSER : FL_HOLD_BROWSER);
1597 b->when(FL_WHEN_CHANGED);
1599 b->column_char(
'\a');
1607 Fl_Browser *b = (Fl_Browser *)
widget;
1611 b->textfont(
widget->labelfont());
1612 b->textsize(
widget->labelsize());
1613 b->textcolor(
widget->labelcolor());
1623 Fl_Browser *b = (Fl_Browser *)
widget;
1625 if (b->selected(b->value())) {
1629 const char *inactive_code;
1630 if ((inactive_code = strstr(b->text(b->value()),
"@N"))) {
1631 const char *ignore_codes = strstr(b->text(b->value()),
"@.");
1633 if (inactive_code < ignore_codes)
1634 b->select(b->value(), 0);
1641 Fl_Browser *b = (Fl_Browser *)
widget;
1642 int index = b->size() + 1;
1643 char *label = (
char *)malloc(strlen(str) + 1 +
currDepth + 4),
1663 b->select(index, selected);
1664 if (b->type() == FL_HOLD_BROWSER) {
1695 Fl_Browser *b = (Fl_Browser *)
widget;
1697 b->select(index + 1, selected);
1703 bool selected =
false;
1707 if (!name || !*name)
1719 CustBrowser *b = (CustBrowser *)
widget;
1730 return ((CustBrowser *)
widget)->full_width();
1738 CustBrowser *b = (CustBrowser *)
widget;
1739 int height = b->full_height();
1742 if (
showRows * b->avg_height() < height) {
1743 height =
showRows * b->avg_height();
1744 b->has_scrollbar(Fl_Browser_::VERTICAL_ALWAYS);
1745 requisition->
width += Fl::scrollbar_size();
1747 b->has_scrollbar(0);
1753 requisition->
width = 1;
1765 return ((Fl_Browser*)
widget)->size();
1770 Fl_Browser *b = (Fl_Browser *)
widget;
1772 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 implemtation 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.