25 #include "../lout/msg.h" 26 #include "../lout/misc.hh" 29 #include <FL/fl_draw.H> 30 #include <FL/Fl_Input.H> 31 #include <FL/Fl_Text_Editor.H> 32 #include <FL/Fl_Check_Button.H> 33 #include <FL/Fl_Round_Button.H> 34 #include <FL/Fl_Choice.H> 35 #include <FL/Fl_Browser.H> 43 return fl_color_average(c, bg, .33f);
57 CustInput2 (
int x,
int y,
int w,
int h,
const char* l=0);
64 int value(
const char* str);
90 return Fl_Input::value(str);
102 Fl_Input::input_type(FL_NORMAL_INPUT);
117 if ((Fl::focus() !=
this) && !*
value()) {
130 Fl_Input::textcolor(c);
139 Fl_Input::input_type(t);
149 return (
placeholder && (!str || !*str) && Fl::focus() !=
this)
163 int rc, k = Fl::event_key();
165 _MSG(
"CustInput2::handle event=%d\n", e);
168 unsigned modifier = Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT);
170 if (e == FL_KEYBOARD) {
171 if (k == FL_Page_Down || k == FL_Page_Up || k == FL_Up || k == FL_Down) {
175 if (modifier == FL_CTRL) {
176 if (k ==
'a' || k ==
'e') {
177 position(k ==
'a' ? 0 : size());
179 }
else if (k ==
'k') {
180 cut(position(), size());
182 }
else if (k ==
'd') {
183 cut(position(), position()+1);
185 }
else if (k ==
'h' || k ==
'i' || k ==
'j' || k ==
'l' || k ==
'm') {
192 }
else if (e == FL_UNFOCUS) {
198 rc = Fl_Input::handle(e);
200 if (rc && e == FL_FOCUS) {
219 void value(
const char* str);
230 Fl_Text_Editor(x,y,w,h,l)
234 buffer(
new Fl_Text_Buffer());
241 Fl_Text_Buffer *buf = buffer();
281 if ((Fl::focus() !=
this) && buffer()->length() == 0) {
294 Fl_Text_Editor::textcolor(c);
302 if (
placeholder && (!str || !*str) && Fl::focus() !=
this)
326 if (e == FL_UNFOCUS) {
332 rc = Fl_Text_Editor::handle(e);
334 if (rc && e == FL_FOCUS) {
350 Fl_Choice(x,y,w,h,l) {};
356 int k = Fl::event_key();
357 unsigned modifier = Fl::event_state() & (FL_SHIFT|FL_CTRL|FL_ALT|FL_META);
359 _MSG(
"CustChoice::handle %p e=%d active=%d focus=%d\n",
360 this, e, active(), (Fl::focus() ==
this));
361 if (Fl::focus() !=
this) {
363 }
else if (e == FL_KEYDOWN && modifier == 0) {
364 if (k == FL_Enter || k == FL_Down) {
365 return Fl_Choice::handle(FL_PUSH);
367 }
else if (isalnum(k)) {
368 int t = value()+1 >= size() ? 0 : value()+1;
369 while (t != value()) {
370 const Fl_Menu_Item *mi = &(menu()[t]);
373 else if (mi->label() && mi->active()) {
374 if (k == tolower(mi->label()[0])) {
385 return Fl_Choice::handle(e);
401 this->platform = platform;
405 allocation.width = 1;
406 allocation.ascent = 1;
407 allocation.descent = 0;
427 platform->detachResource (
this);
430 view->removeFltkWidget(widget);
441 MSG_ERR(
"FltkResource::attachView: multiple views!\n");
446 widget = createNewWidget (&allocation);
449 setWidgetStyle (widget, style);
451 widget->deactivate ();
457 if (this->view != view)
458 MSG_ERR(
"FltkResource::detachView: this->view: %p view: %p\n",
465 this->allocation = *allocation;
466 view->allocateFltkWidget (widget, allocation);
480 this->style->
unref ();
485 setWidgetStyle (widget, style);
492 widget->labelsize (font->
size);
493 widget->labelfont (font->
font);
502 Fl_Color fg = fl_contrast(style_fg, normal_bg);
504 widget->labelcolor(fg);
505 widget->selection_color(fg);
508 widget->color(normal_bg);
527 ret = widget->visible();
539 this->enabled = enabled;
544 widget->deactivate ();
582 Fl_Button (x,y,w,h,label) {};
588 if (e == FL_KEYBOARD && Fl::focus() ==
this && Fl::event_key() == FL_Enter){
590 simulate_key_action();
594 return Fl_Button::handle(e);
601 this->label = strdup (
label);
617 button->when (FL_WHEN_RELEASE);
632 requisition->
width = 1;
645 int s1 = Fl::event_state ();
660 event->xCanvas = Fl::event_x();
661 event->yCanvas = Fl::event_y();
663 event->button = Fl::event_button();
664 event->numPressed = Fl::event_clicks() + 1;
670 if (!Fl::event_button3()) {
686 free((
char *)this->label);
687 this->label = strdup (
label);
689 widget->label (this->label);
697 *widget,
bool relief):
715 if (Fl::event() == FL_RELEASE && Fl::event_button() != FL_RIGHT_MOUSE) {
732 }
else if (Fl::event() == FL_KEYBOARD) {
742 event.numPressed = 1;
800 button->when (FL_WHEN_RELEASE);
802 button->box(FL_NO_BOX);
819 bool password,
const char *label,
820 const char *placeholder):
853 input->when (FL_WHEN_ENTER_KEY_ALWAYS);
857 input->align(FL_ALIGN_LEFT);
875 in->cursor_color(
widget->labelcolor());
876 in->textsize(in->labelsize());
877 in->textfont(in->labelfont());
907 requisition->
width = 0;
959 ((Fl_Input *)
widget)->maximum_size(maxlen);
966 int p1, p2 = e->insert_position();
969 p1 = e->insert_position();
970 e->buffer()->remove(p1, p2);
971 e->show_insert_position();
973 if (e->when() & FL_WHEN_CHANGED)
980 const char *placeholder):
1014 text->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
1015 text->remove_key_binding(FL_BackSpace, FL_TEXT_EDITOR_ANY_STATE);
1016 text->add_key_binding(FL_BackSpace, 0, Fl_Text_Editor::kf_backspace);
1031 ed->cursor_color(
widget->labelcolor());
1032 ed->textsize(ed->labelsize());
1033 ed->textfont(ed->labelfont());
1043 requisition->
width =
1052 requisition->
width = 1;
1085 initActivated = activated;
1099 Fl_Button *button = createNewButton (allocation);
1100 button->value (initActivated);
1108 FltkResource::setWidgetStyle(widget, style);
1110 widget->selection_color(FL_BLACK);
1118 (this->FltkResource::style ? this->FltkResource::style->font : NULL);
1126 requisition->
width = 1;
1136 return ((Fl_Button*)this->widget)->value ();
1143 initActivated = activated;
1144 ((Fl_Button*)this->widget)->value (initActivated);
1166 Fl_Check_Button *cb =
1176 return it.hasNext ();
1192 *radioButtonResource)
1195 connect (radioButtonResource);
1204 *radioButtonResource)
1206 list->append (radioButtonResource);
1210 *radioButtonResource)
1212 list->removeRef (radioButtonResource);
1213 if (
list->isEmpty ())
1249 if (
widget->when () & FL_WHEN_CHANGED)
1280 button->when (FL_WHEN_CHANGED);
1282 button->type (FL_TOGGLE_BUTTON);
1317 free((
char *)
menu[i].text);
1325 Fl_Choice *ch = (Fl_Choice *)
widget;
1329 ch->textcolor(
widget->labelcolor());
1330 ch->textfont(ch->labelfont());
1331 ch->textsize(ch->labelsize());
1356 const char *str =
menu[i].text;
1359 width = fl_width(str);
1375 requisition->
width = maxItemWidth
1379 requisition->
width = 1;
1387 Fl_Choice *ch = (Fl_Choice *)
widget;
1388 int selected = ch->value();
1389 Fl_Menu_Item *newMenu;
1394 memset(newMenu +
itemsUsed, 0, 0x10 *
sizeof(Fl_Menu_Item));
1398 ch->value(selected);
1415 bool enabled,
bool selected)
1417 Fl_Menu_Item *item =
newItem();
1419 item->text = strdup(str);
1422 item->flags = FL_MENU_INACTIVE;
1425 ((Fl_Choice *)
widget)->value(item);
1438 Fl_Menu_Item *item =
newItem();
1440 item->text = strdup(name);
1443 item->flags = FL_MENU_INACTIVE;
1445 item->flags |= FL_SUBMENU;
1459 return index == ((Fl_Choice *)
widget)->value();
1464 return ((Fl_Choice*)
widget)->size();
1474 int avg_height() {
return size() ? Fl_Browser_::incr_height() : 0;}
1483 void *item = item_first();
1486 int w = item_width(item);
1491 item = item_next(item);
1498 selectionMode,
int rowCount):
1502 mode = selectionMode;
1520 b->when(FL_WHEN_CHANGED);
1522 b->column_char(
'\a');
1530 Fl_Browser *b = (Fl_Browser *)
widget;
1534 b->textfont(
widget->labelfont());
1535 b->textsize(
widget->labelsize());
1536 b->textcolor(
widget->labelcolor());
1546 Fl_Browser *b = (Fl_Browser *)
widget;
1548 if (b->selected(b->value())) {
1552 const char *inactive_code;
1553 if ((inactive_code = strstr(b->text(b->value()),
"@N"))) {
1554 const char *ignore_codes = strstr(b->text(b->value()),
"@.");
1556 if (inactive_code < ignore_codes)
1557 b->select(b->value(), 0);
1564 Fl_Browser *b = (Fl_Browser *)
widget;
1565 int index = b->size() + 1;
1566 char *label = (
char *)malloc(strlen(str) + 1 +
currDepth + 4),
1586 b->select(index, selected);
1587 if (b->type() == FL_HOLD_BROWSER) {
1618 Fl_Browser *b = (Fl_Browser *)
widget;
1620 b->select(index + 1, selected);
1626 bool selected =
false;
1630 if (!name || !*name)
1665 b->has_scrollbar(Fl_Browser_::VERTICAL_ALWAYS);
1666 requisition->
width += Fl::scrollbar_size();
1668 b->has_scrollbar(0);
1674 requisition->
width = 1;
1682 return ((Fl_Browser*)
widget)->size();
1687 Fl_Browser *b = (Fl_Browser *)
widget;
1689 return b->selected(index + 1) ? true :
false;