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);
70 void d_position(
int p);
73 bool showing_placeholder;
78CustInput2::CustInput2 (
int x,
int y,
int w,
int h,
const char* l) :
82 showing_placeholder =
false;
83 usual_color = FL_BLACK;
88int CustInput2::d_position()
90#if FL_API_VERSION < 10400
91 return CustInput2::position();
93 return CustInput2::insert_position();
97void CustInput2::d_position(
int p)
99#if FL_API_VERSION < 10400
100 CustInput2::position(p);
102 CustInput2::insert_position(p);
109int CustInput2::show_normal(
const char *str)
111 showing_placeholder =
false;
112 Fl_Input::textcolor(usual_color);
113 Fl_Input::input_type(usual_type);
114 return Fl_Input::value(str);
120int CustInput2::show_placeholder()
124 showing_placeholder =
true;
126 Fl_Input::input_type(FL_NORMAL_INPUT);
127 ret = Fl_Input::value(placeholder);
135void CustInput2::set_placeholder(
const char *str)
141 if ((Fl::focus() !=
this) && !*value()) {
149void CustInput2::textcolor(Fl_Color c)
152 if (showing_placeholder)
154 Fl_Input::textcolor(c);
160void CustInput2::input_type(
int t)
163 Fl_Input::input_type(t);
171int CustInput2::value(
const char *str)
173 return (placeholder && (!str || !*str) && Fl::focus() !=
this)
174 ? show_placeholder() : show_normal(str);
180const char* CustInput2::value()
182 return showing_placeholder ?
"" : Fl_Input::value();
185int CustInput2::handle(
int e)
187 int rc, k = Fl::event_key();
189 _MSG(
"CustInput2::handle event=%d\n", e);
192 unsigned modifier = Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT);
194 if (e == FL_KEYBOARD) {
195 if (k == FL_Page_Down || k == FL_Page_Up || k == FL_Up || k == FL_Down) {
199 if (modifier == FL_CTRL) {
203 }
else if (k ==
'k') {
204 cut(d_position(), size());
206 }
else if (k ==
'd') {
207 cut(d_position(), d_position()+1);
209 }
else if (k ==
'h' || k ==
'i' || k ==
'j' || k ==
'l' || k ==
'm') {
216 }
else if (e == FL_UNFOCUS) {
217 if (placeholder && !value()[0]) {
222 rc = Fl_Input::handle(e);
224 if (rc && e == FL_FOCUS) {
226 if (showing_placeholder)
235class CustTextEditor :
public Fl_Text_Editor {
237 CustTextEditor (
int x,
int y,
int w,
int h,
const char* l=0);
239 void set_placeholder(
const char *str);
240 void show_placeholder();
241 void show_normal(
const char *str);
242 void textcolor(Fl_Color c);
243 void value(
const char* str);
248 bool showing_placeholder;
249 Fl_Color usual_color;
253CustTextEditor::CustTextEditor (
int x,
int y,
int w,
int h,
const char* l) :
254 Fl_Text_Editor(x,y,w,h,l)
257 showing_placeholder =
false;
258 buffer(
new Fl_Text_Buffer());
259 usual_color = FL_BLACK;
263CustTextEditor::~CustTextEditor ()
265 Fl_Text_Buffer *buf = buffer();
279void CustTextEditor::show_normal(
const char *str)
281 showing_placeholder =
false;
282 Fl_Text_Editor::textcolor(usual_color);
289void CustTextEditor::show_placeholder()
291 showing_placeholder =
true;
292 Fl_Text_Editor::textcolor(
fltkui_dimmed(usual_color, color()));
293 buffer()->text(placeholder);
299void CustTextEditor::set_placeholder(
const char *str)
305 if ((Fl::focus() !=
this) && buffer()->length() == 0) {
313void CustTextEditor::textcolor(Fl_Color c)
316 if (showing_placeholder)
318 Fl_Text_Editor::textcolor(c);
324void CustTextEditor::value(
const char *str)
326 if (placeholder && (!str || !*str) && Fl::focus() !=
this)
335char* CustTextEditor::value()
342 text_copy = showing_placeholder ?
dStrdup(
"") : buffer()->text();
346int CustTextEditor::handle(
int e)
350 if (e == FL_UNFOCUS) {
351 if (placeholder && buffer()->length() == 0) {
356 rc = Fl_Text_Editor::handle(e);
358 if (rc && e == FL_FOCUS) {
360 if (showing_placeholder)
371class CustChoice :
public Fl_Choice {
373 CustChoice (
int x,
int y,
int w,
int h,
const char* l=0) :
374 Fl_Choice(x,y,w,h,l) {};
378int CustChoice::handle(
int e)
380 int k = Fl::event_key();
381 unsigned modifier = Fl::event_state() & (FL_SHIFT|FL_CTRL|FL_ALT|FL_META);
383 _MSG(
"CustChoice::handle %p e=%d active=%d focus=%d\n",
384 this, e, active(), (Fl::focus() ==
this));
385 if (Fl::focus() !=
this) {
387 }
else if (e == FL_KEYDOWN && modifier == 0) {
388 if (k == FL_Enter || k == FL_Down) {
389 return Fl_Choice::handle(FL_PUSH);
392 int t = value()+1 >= size() ? 0 : value()+1;
393 while (t != value()) {
394 const Fl_Menu_Item *mi = &(menu()[t]);
397 else if (mi->label() && mi->active()) {
398 if (k ==
dTolower(mi->label()[0])) {
409 return Fl_Choice::handle(e);
469 MSG_ERR(
"FltkResource::attachView: multiple views!\n");
485 if (this->view !=
view)
486 MSG_ERR(
"FltkResource::detachView: this->view: %p view: %p\n",
487 (
void *) this->view, (
void *)
view);
493 DBG_OBJ_ENTER (
"resize", 0,
"sizeAllocate",
"%d, %d; %d * (%d + %d)",
515 this->style->
unref ();
537 Fl_Color fg = fl_contrast(style_fg, normal_bg);
540 widget->selection_color(fg);
630class EnterButton :
public Fl_Button {
632 EnterButton (
int x,
int y,
int w,
int h,
const char* label = 0) :
633 Fl_Button (x,y,w,h,label) {};
637int EnterButton::handle(
int e)
639 if (e == FL_KEYBOARD && Fl::focus() ==
this && Fl::event_key() == FL_Enter){
641 simulate_key_action();
645 return Fl_Button::handle(e);
668 button->when (FL_WHEN_RELEASE);
685 requisition->
width = 1;
702 int s1 = Fl::event_state ();
717 event->xCanvas = Fl::event_x();
718 event->yCanvas = Fl::event_y();
720 event->button = Fl::event_button();
721 event->numPressed = Fl::event_clicks() + 1;
727 if (!Fl::event_button3()) {
743 free((
char *)this->label);
746 widget->label (this->label);
754 *widget,
bool relief):
760 ComplexButtonResource::init (
widget);
772 if (Fl::event() == FL_RELEASE && Fl::event_button() != FL_RIGHT_MOUSE) {
789 }
else if (Fl::event() == FL_KEYBOARD) {
799 event.numPressed = 1;
827 "<b>resize</b> (%d %d, <i>%d - 2 * %d =</i> %d, "
828 "<i>%d + %d - 2 * %d =</i> %d)",
868 button->when (FL_WHEN_RELEASE);
870 button->box(FL_NO_BOX);
887 bool password,
const char *label,
888 const char *placeholder):
919 input->input_type(
password ? FL_SECRET_INPUT : FL_NORMAL_INPUT);
921 input->when (FL_WHEN_ENTER_KEY_ALWAYS);
925 input->align(FL_ALIGN_LEFT);
938 CustInput2 *in = (CustInput2 *)
widget;
942 in->textcolor(
widget->labelcolor());
943 in->cursor_color(
widget->labelcolor());
944 in->textsize(in->labelsize());
945 in->textfont(in->labelfont());
977 requisition->
width = 0;
993 "<b>sizeAllocate</b> (%d, %d; %d * (%d + %d))",
1014 return ((CustInput2*)
widget)->value ();
1038 ((Fl_Input *)
widget)->maximum_size(maxlen);
1045 int p1, p2 = e->insert_position();
1048 p1 = e->insert_position();
1049 e->buffer()->remove(p1, p2);
1050 e->show_insert_position();
1052 if (e->when() & FL_WHEN_CHANGED)
1059 const char *placeholder):
1093 CustTextEditor *text =
1096 text->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
1097 text->remove_key_binding(FL_BackSpace, FL_TEXT_EDITOR_ANY_STATE);
1098 text->add_key_binding(FL_BackSpace, 0, Fl_Text_Editor::kf_backspace);
1108 CustTextEditor *ed = (CustTextEditor *)
widget;
1112 ed->textcolor(
widget->labelcolor());
1113 ed->cursor_color(
widget->labelcolor());
1114 ed->textsize(ed->labelsize());
1115 ed->textfont(ed->labelfont());
1127 requisition->
width =
1136 requisition->
width = 1;
1148 return ((CustTextEditor*)
widget)->value ();
1153 ((CustTextEditor*)
widget)->value (text);
1187 Fl_Button *button = createNewButton (allocation);
1188 button->value (initActivated);
1198 widget->selection_color(FL_FOREGROUND_COLOR);
1216 requisition->
width = 1;
1230 return ((Fl_Button*)this->widget)->value ();
1237 initActivated = activated;
1238 ((Fl_Button*)this->widget)->value (initActivated);
1260 Fl_Check_Button *cb =
1270 return it.hasNext ();
1286 *radioButtonResource)
1288 list =
new lout::container::typed::List <FltkRadioButtonResource> (
false);
1289 connect (radioButtonResource);
1298 *radioButtonResource)
1300 list->append (radioButtonResource);
1304 *radioButtonResource)
1306 list->removeRef (radioButtonResource);
1307 if (
list->isEmpty ())
1343 if (
widget->when () & FL_WHEN_CHANGED)
1349 for (Iterator <FltkRadioButtonResource> it =
group->
iterator ();
1374 button->when (FL_WHEN_CHANGED);
1376 button->type (FL_TOGGLE_BUTTON);
1411 free((
char *)
menu[i].text);
1419 Fl_Choice *ch = (Fl_Choice *)
widget;
1423 ch->textcolor(
widget->labelcolor());
1424 ch->textfont(ch->labelfont());
1425 ch->textsize(ch->labelsize());
1450 const char *str =
menu[i].text;
1453 width = fl_width(str);
1471 requisition->
width = maxItemWidth
1475 requisition->
width = 1;
1487 Fl_Choice *ch = (Fl_Choice *)
widget;
1488 int selected = ch->value();
1489 Fl_Menu_Item *newMenu;
1494 memset(newMenu +
itemsUsed, 0, 0x10 *
sizeof(Fl_Menu_Item));
1498 ch->value(selected);
1515 bool enabled,
bool selected)
1517 Fl_Menu_Item *item =
newItem();
1522 item->flags = FL_MENU_INACTIVE;
1525 ((Fl_Choice *)
widget)->value(item);
1538 Fl_Menu_Item *item =
newItem();
1543 item->flags = FL_MENU_INACTIVE;
1545 item->flags |= FL_SUBMENU;
1559 return index == ((Fl_Choice *)
widget)->value();
1564 return ((Fl_Choice*)
widget)->size();
1569class CustBrowser :
public Fl_Browser {
1571 CustBrowser(
int x,
int y,
int w,
int h) : Fl_Browser(x, y, w, h) {};
1572 int full_width()
const;
1573 int full_height()
const {
return Fl_Browser::full_height();}
1574 int avg_height() {
return size() ? Fl_Browser_::incr_height() : 0;}
1580int CustBrowser::full_width()
const
1583 void *item = item_first();
1586 int w = item_width(item);
1591 item = item_next(item);
1598 selectionMode,
int rowCount):
1602 mode = selectionMode;
1618 b->type((
mode == SELECTION_MULTIPLE) ? FL_MULTI_BROWSER : FL_HOLD_BROWSER);
1620 b->when(FL_WHEN_CHANGED);
1622 b->column_char(
'\a');
1630 Fl_Browser *b = (Fl_Browser *)
widget;
1634 b->textfont(
widget->labelfont());
1635 b->textsize(
widget->labelsize());
1636 b->textcolor(
widget->labelcolor());
1646 Fl_Browser *b = (Fl_Browser *)
widget;
1648 if (b->selected(b->value())) {
1652 const char *inactive_code;
1653 if ((inactive_code = strstr(b->text(b->value()),
"@N"))) {
1654 const char *ignore_codes = strstr(b->text(b->value()),
"@.");
1656 if (inactive_code < ignore_codes)
1657 b->select(b->value(), 0);
1664 Fl_Browser *b = (Fl_Browser *)
widget;
1665 int index = b->size() + 1;
1666 char *label = (
char *)malloc(strlen(str) + 1 +
currDepth + 4),
1686 b->select(index, selected);
1687 if (b->type() == FL_HOLD_BROWSER) {
1718 Fl_Browser *b = (Fl_Browser *)
widget;
1720 b->select(index + 1, selected);
1726 bool selected =
false;
1730 if (!name || !*name)
1742 CustBrowser *b = (CustBrowser *)
widget;
1753 return ((CustBrowser *)
widget)->full_width();
1761 CustBrowser *b = (CustBrowser *)
widget;
1762 int height = b->full_height();
1765 if (
showRows * b->avg_height() < height) {
1766 height =
showRows * b->avg_height();
1767 b->has_scrollbar(Fl_Browser_::VERTICAL_ALWAYS);
1768 requisition->
width += Fl::scrollbar_size();
1770 b->has_scrollbar(0);
1776 requisition->
width = 1;
1788 return ((Fl_Browser*)
widget)->size();
1793 Fl_Browser *b = (Fl_Browser *)
widget;
1795 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 int dTolower(unsigned char c)
static int dIsalnum(unsigned char c)
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.