Eclipse SUMO - Simulation of Urban MObility
MFXIconComboBox.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2006-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19//
20/****************************************************************************/
21
22/* =========================================================================
23 * included modules
24 * ======================================================================= */
25#include <config.h>
26
27#ifdef WIN32
28#define NOMINMAX
29#include <windows.h>
30#undef NOMINMAX
31#endif
32
33#include "MFXIconComboBox.h"
34
35
36#define SIDE_SPACING 6 // Left or right spacing between items
37#define ICON_SPACING 4 // Spacing between icon and label
38#define COMBOBOX_INS_MASK (COMBOBOX_REPLACE | COMBOBOX_INSERT_BEFORE | COMBOBOX_INSERT_AFTER | COMBOBOX_INSERT_FIRST | COMBOBOX_INSERT_LAST)
39#define COMBOBOX_MASK (COMBOBOX_STATIC | COMBOBOX_INS_MASK)
40#define ICON_HEIGHT 20
41
42// Map
43FXDEFMAP(MFXIconComboBox) MFXIconComboBoxMap[] = {
44 FXMAPFUNC(SEL_FOCUS_UP, 0, MFXIconComboBox::onFocusUp),
45 FXMAPFUNC(SEL_FOCUS_DOWN, 0, MFXIconComboBox::onFocusDown),
46 FXMAPFUNC(SEL_FOCUS_SELF, 0, MFXIconComboBox::onFocusSelf),
50 FXMAPFUNC(SEL_LEFTBUTTONPRESS, MFXIconComboBox::ID_TEXT, MFXIconComboBox::onTextButton),
54 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETVALUE, MFXIconComboBox::onFwdToText),
55 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETINTVALUE, MFXIconComboBox::onFwdToText),
56 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETREALVALUE, MFXIconComboBox::onFwdToText),
57 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETSTRINGVALUE, MFXIconComboBox::onFwdToText),
58 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETINTVALUE, MFXIconComboBox::onFwdToText),
59 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETREALVALUE, MFXIconComboBox::onFwdToText),
60 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETSTRINGVALUE, MFXIconComboBox::onFwdToText),
61};
62
63
64// Object implementation
65FXIMPLEMENT(MFXIconComboBox, FXPacker, MFXIconComboBoxMap, ARRAYNUMBER(MFXIconComboBoxMap))
66FXIMPLEMENT(MFXListItem, FXListItem, nullptr, 0)
67
68
69MFXListItem::MFXListItem(const FXString& text, FXIcon* ic, FXColor backGroundColor, void* ptr):
70 FXListItem(text, ic, ptr),
71 myBackGroundColor(backGroundColor) {
72}
73
74
75void
76MFXListItem::draw(const FXList* myList, FXDC& dc, FXint xx, FXint yy, FXint ww, FXint hh) {
77 // almost the same code as FXListItem::draw except for using custom background color
78 FXFont* font = myList->getFont();
79 FXint ih = 0, th = 0;
80 if (icon) {
81 ih = icon->getHeight();
82 }
83 if (!label.empty()) {
84 th = font->getFontHeight();
85 }
86 if (isSelected()) {
87 dc.setForeground(myList->getSelBackColor());
88 } else {
89 dc.setForeground(myBackGroundColor);
90 }
91 dc.fillRectangle(xx, yy, ww, hh);
92 if (hasFocus()) {
93 dc.drawFocusRectangle(xx + 1, yy + 1, ww - 2, hh - 2);
94 }
95 xx += SIDE_SPACING / 2;
96 if (icon) {
97 dc.drawIcon(icon, xx, yy + (hh - ih) / 2);
98 xx += ICON_SPACING + icon->getWidth();
99 }
100 if (!label.empty()) {
101 dc.setFont(font);
102 if (!isEnabled()) {
103 dc.setForeground(makeShadowColor(myList->getBackColor()));
104 } else if (isSelected()) {
105 dc.setForeground(myList->getSelTextColor());
106 } else {
107 dc.setForeground(myList->getTextColor());
108 }
109 dc.drawText(xx, yy + (hh - th) / 2 + font->getFontAscent(), label);
110 }
111}
112
113const FXColor&
115 return myBackGroundColor;
116}
117
118
120 FXListItem("", nullptr),
121 myBackGroundColor(FXRGB(0, 0, 0)) {
122}
123
124
125MFXIconComboBox::MFXIconComboBox(FXComposite* p, FXint cols, const bool haveIcons, FXObject* tgt, FXSelector sel, FXuint opts, FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb):
126 FXPacker(p, opts, x, y, w, h, 0, 0, 0, 0, 0, 0),
127 myHaveIcons(haveIcons) {
128 flags |= FLAG_ENABLED;
129 target = tgt;
130 message = sel;
131 myIconLabel = new FXLabel(this, "", nullptr, 0, 0, 0, 0, 0, pl, pr, pt, pb);
132 if (!myHaveIcons) {
133 myIconLabel->hide();
134 }
135 myTextFieldIcon = new MFXTextFieldIcon(this, cols, this, MFXIconComboBox::ID_TEXT, 0, 0, 0, 0, 0, pl, pr, pt, pb);
136 if (options & COMBOBOX_STATIC) {
137 myTextFieldIcon->setEditable(FALSE);
138 }
139 myPane = new FXPopup(this, FRAME_LINE);
140 myList = new FXList(myPane, this, MFXIconComboBox::ID_LIST, LIST_BROWSESELECT | LIST_AUTOSELECT | LAYOUT_FILL_X | LAYOUT_FIX_HEIGHT | SCROLLERS_TRACK | HSCROLLER_NEVER);
141 if (options & COMBOBOX_STATIC) {
142 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF);
143 }
144 myButton = new FXMenuButton(this, FXString::null, NULL, myPane, FRAME_RAISED | FRAME_THICK | MENUBUTTON_DOWN | MENUBUTTON_ATTACH_RIGHT, 0, 0, 0, 0, 0, 0, 0, 0);
145 myButton->setXOffset(border);
146 myButton->setYOffset(border);
147 flags &= ~FLAG_UPDATE; // Never GUI update
148}
149
150
152 delete myPane;
153 myPane = (FXPopup*) - 1L;
154 myIconLabel = (FXLabel*) - 1L;
156 myButton = (FXMenuButton*) - 1L;
157 myList = (FXList*) - 1L;
158}
159
160
161void
163 FXPacker::create();
164 myPane->create();
165}
166
167
168void
170 FXPacker::detach();
171 myPane->detach();
172}
173
174
175void
177 myPane->destroy();
178 FXPacker::destroy();
179}
180
181
182void
184 if (!isEnabled()) {
185 FXPacker::enable();
186 myIconLabel->enable();
187 myTextFieldIcon->enable();
188 myButton->enable();
189 }
190}
191
192
193void
195 if (isEnabled()) {
196 FXPacker::disable();
197 myIconLabel->disable();
198 myTextFieldIcon->disable();
199 myButton->disable();
200 }
201}
202
203
204FXint
206 FXint ww, pw;
207 if (myIconLabel->shown()) {
208 ww = myIconLabel->getDefaultWidth() + myTextFieldIcon->getDefaultWidth() + myButton->getDefaultWidth() + (border << 1);
209 } else {
210 ww = myTextFieldIcon->getDefaultWidth() + myButton->getDefaultWidth() + (border << 1);
211 }
212 pw = myPane->getDefaultWidth();
213 return FXMAX(ww, pw);
214}
215
216
217FXint
219 FXint th, bh;
220 th = myTextFieldIcon->getDefaultHeight();
221 bh = myButton->getDefaultHeight();
222 return FXMAX(th, bh) + (border << 1);
223}
224
225
226void
228 const FXint itemHeight = height - (border << 1);
229 const FXint iconSize = myHaveIcons ? itemHeight : 0;
230 const FXint buttonWidth = myButton->getDefaultWidth();
231 const FXint textWidth = width - buttonWidth - iconSize - (border << 1);
232 myIconLabel->position(border, border, iconSize, iconSize);
233 myTextFieldIcon->position(border + iconSize, border, textWidth, itemHeight);
234 myButton->position(border + textWidth + iconSize, border, buttonWidth, itemHeight);
235
236 int size = -1;
237 for (int i = 0; i < myList->getNumItems(); i++) {
238 if (myList->getItemWidth(i) > size) {
239 size = myList->getItemWidth(i);
240 }
241 }
242 myPane->resize(size + 17, myPane->getDefaultHeight());
243 flags &= ~FLAG_DIRTY;
244}
245
246
247FXbool
249 return myTextFieldIcon->isEditable();
250}
251
252
253void
255 myTextFieldIcon->setEditable(edit);
256}
257
258
259FXString
261 return myTextFieldIcon->getText();
262}
263
264
265void
267 myTextFieldIcon->setNumColumns(cols);
268}
269
270
271FXint
273 return myTextFieldIcon->getNumColumns();
274}
275
276
277FXint
279 return myList->getNumItems();
280}
281
282
283FXint
285 return myList->getNumVisible();
286}
287
288
289void
291 myTextFieldIcon->setText(text);
292}
293
294
295void
297 myList->setNumVisible(nvis);
298 // set height manually (due icons)
299 myList->setHeight((nvis + 1) * ICON_HEIGHT);
300}
301
302
303FXbool
305 return myList->isItemCurrent(index);
306}
307
308
309void
310MFXIconComboBox::setCurrentItem(FXint index, FXbool notify) {
311 FXint current = myList->getCurrentItem();
312 if (current != index) {
313 myList->setCurrentItem(index);
314 myList->makeItemVisible(index);
315 if (0 <= index) {
316 // cast MFXListItem
317 const MFXListItem* item = dynamic_cast<MFXListItem*>(myList->getItem(index));
318 // set icon and background color
319 if (item) {
320 myTextFieldIcon->setText(item->getText());
321 myTextFieldIcon->setBackColor(item->getBackGroundColor());
322 myIconLabel->setIcon(item->getIcon());
323 myIconLabel->setBackColor(item->getBackGroundColor());
324 } else {
326 myTextFieldIcon->setBackColor(FXRGB(255, 255, 255));
327 myIconLabel->setIcon(nullptr);
328 myIconLabel->setBackColor(FXRGB(255, 255, 255));
329 }
330 } else {
332 }
333 if (notify && target) {
334 target->tryHandle(this, FXSEL(SEL_COMMAND, message), (void*)getText().text());
335 }
336 }
337}
338
339
340FXint
342 return myList->getCurrentItem();
343}
344
345
346FXString
347MFXIconComboBox::getItem(FXint index) const {
348 return myList->getItem(index)->getText();
349}
350
351
352FXint
353MFXIconComboBox::setIconItem(FXint index, const FXString& text, FXIcon* icon, FXColor bgColor, void* ptr) {
354 if (index < 0 || myList->getNumItems() <= index) {
355 fxerror("%s::setItem: index out of range.\n", getClassName());
356 }
357 myList->setItem(index, text, NULL, ptr);
358 if (isItemCurrent(index)) {
359 myTextFieldIcon->setText(text);
360 myTextFieldIcon->setBackColor(bgColor);
361 myIconLabel->setIcon(icon);
362 myIconLabel->setBackColor(bgColor);
363 }
364 recalc();
365 return index;
366}
367
368
369FXint
370MFXIconComboBox::insertIconItem(FXint index, const FXString& text, FXIcon* icon, FXColor bgColor, void* ptr) {
371 if (index < 0 || myList->getNumItems() < index) {
372 fxerror("%s::insertItem: index out of range.\n", getClassName());
373 }
374 myList->insertItem(index, text, NULL, ptr);
375 if (isItemCurrent(index)) {
376 myTextFieldIcon->setText(text);
377 myTextFieldIcon->setBackColor(bgColor);
378 myIconLabel->setIcon(icon);
379 myIconLabel->setBackColor(bgColor);
380 }
381 recalc();
382 return index;
383}
384
385
386FXint
387MFXIconComboBox::appendIconItem(const FXString& text, FXIcon* icon, FXColor bgColor, void* ptr) {
388 FXint index = myList->appendItem(new MFXListItem(text, icon, bgColor, ptr));
389 if (isItemCurrent(getNumItems() - 1)) {
390 myTextFieldIcon->setText(text);
391 myTextFieldIcon->setBackColor(bgColor);
392 myIconLabel->setIcon(icon);
393 myIconLabel->setBackColor(bgColor);
394 }
395 recalc();
396 return index;
397}
398
399
400bool
401MFXIconComboBox::setItem(const FXString& text, FXIcon* icon) {
402 for (int i = 0; i < myList->getNumItems(); i++) {
403 // cast MFXListItem
404 const MFXListItem* item = dynamic_cast<MFXListItem*>(myList->getItem(i));
405 // set icon and background color
406 if (item && (item->getText() == text) && (item->getIcon() == icon)) {
407 myTextFieldIcon->setText(item->getText());
408 myTextFieldIcon->setBackColor(item->getBackGroundColor());
409 myIconLabel->setIcon(item->getIcon());
410 myIconLabel->setBackColor(item->getBackGroundColor());
411 myTextFieldIcon->setTextColor(FXRGB(0, 0, 0));
412 return true;
413 }
414 }
415 return false;
416}
417
418
419void
420MFXIconComboBox::setCustomText(const FXString text) {
421 myTextFieldIcon->setText(text);
422 myTextFieldIcon->setTextColor(FXRGB(128, 128, 128));
423}
424
425
426FXint
427MFXIconComboBox::prependItem(const FXString& text, void* ptr) {
428 FXint index = myList->prependItem(text, NULL, ptr);
429 if (isItemCurrent(0)) {
430 myTextFieldIcon->setText(text);
431 myTextFieldIcon->setBackColor(FXRGB(255, 255, 255));
432 myIconLabel->setIcon(nullptr);
433 myIconLabel->setBackColor(FXRGB(255, 255, 255));
434 }
435 recalc();
436 return index;
437}
438
439
440FXint
441MFXIconComboBox::moveItem(FXint newindex, FXint oldindex) {
442 if (newindex < 0 || myList->getNumItems() <= newindex || oldindex < 0 || myList->getNumItems() <= oldindex) {
443 fxerror("%s::moveItem: index out of range.\n", getClassName());
444 }
445 FXint current = myList->getCurrentItem();
446 myList->moveItem(newindex, oldindex);
447 if (current != myList->getCurrentItem()) {
448 current = myList->getCurrentItem();
449 if (0 <= current) {
450 myTextFieldIcon->setText(myList->getItemText(current));
451 } else {
452 myTextFieldIcon->setText(" ");
453 }
454 myIconLabel->setIcon(nullptr);
455 myIconLabel->setBackColor(FXRGB(255, 255, 255));
456 }
457 recalc();
458 return newindex;
459}
460
461
462void
464 FXint current = myList->getCurrentItem();
465 myList->removeItem(index);
466 if (index == current) {
467 current = myList->getCurrentItem();
468 if (0 <= current) {
469 myTextFieldIcon->setText(myList->getItemText(current));
470 } else {
471 myTextFieldIcon->setText(FXString::null);
472 }
473 myIconLabel->setIcon(nullptr);
474 myIconLabel->setBackColor(FXRGB(255, 255, 255));
475 }
476 recalc();
477}
478
479
480void
483 myList->clearItems();
484 recalc();
485}
486
487
488FXint
489MFXIconComboBox::findItem(const FXString& text, FXint start, FXuint flgs) const {
490 return myList->findItem(text, start, flgs);
491}
492
493
494FXint
495MFXIconComboBox::findItemByData(const void* ptr, FXint start, FXuint flgs) const {
496 return myList->findItemByData(ptr, start, flgs);
497}
498
499
500FXString
502 return myList->getItemText(index);
503}
504
505
506void
507MFXIconComboBox::setItemData(FXint index, void* ptr) const {
508 myList->setItemData(index, ptr);
509}
510
511
512void*
514 return myList->getItemData(index);
515}
516
517
518FXbool
520 return myPane->shown();
521}
522
523
524void
526 if (!fnt) {
527 fxerror("%s::setFont: NULL font specified.\n", getClassName());
528 }
529 myTextFieldIcon->setFont(fnt);
530 myList->setFont(fnt);
531 recalc();
532}
533
534
535FXFont*
537 return myTextFieldIcon->getFont();
538}
539
540
541void
543 FXuint opts = (options & ~COMBOBOX_MASK) | (mode & COMBOBOX_MASK);
544 if (opts != options) {
545 options = opts;
546 if (options & COMBOBOX_STATIC) {
547 myTextFieldIcon->setEditable(FALSE); // Non-editable
548 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF); // No scrolling
549 } else {
550 myTextFieldIcon->setEditable(TRUE); // Editable
551 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLER_NEVER); // Scrollable, but no scrollbar
552 }
553 recalc();
554 }
555}
556
557
558FXuint
560 return (options & COMBOBOX_MASK);
561}
562
563
564void
566 myTextFieldIcon->setJustify(style);
567}
568
569
570FXuint
572 return myTextFieldIcon->getJustify();
573}
574
575
576void
578 myTextFieldIcon->setBackColor(clr);
579 myIconLabel->setBackColor(clr);
580 myList->setBackColor(clr);
581}
582
583
584FXColor
586 return myTextFieldIcon->getBackColor();
587}
588
589
590void
592 myTextFieldIcon->setTextColor(clr);
593 myList->setTextColor(clr);
594}
595
596
597FXColor
599 return myTextFieldIcon->getTextColor();
600}
601
602
603void
605 myTextFieldIcon->setSelBackColor(clr);
606 myList->setSelBackColor(clr);
607}
608
609
610FXColor
612 return myTextFieldIcon->getSelBackColor();
613}
614
615
616void
618 myTextFieldIcon->setSelTextColor(clr);
619 myList->setSelTextColor(clr);
620}
621
622
623FXColor
625 return myTextFieldIcon->getSelTextColor();
626}
627
628
629void
631 myList->sortItems();
632}
633
634
635FXListSortFunc
637 return myList->getSortFunc();
638}
639
640
641void
642MFXIconComboBox::setSortFunc(FXListSortFunc func) {
643 myList->setSortFunc(func);
644}
645
646
647void
648MFXIconComboBox::setHelpText(const FXString& txt) {
649 myTextFieldIcon->setHelpText(txt);
650}
651
652
653const FXString&
655 return myTextFieldIcon->getHelpText();
656}
657
658
659void
660MFXIconComboBox::setTipText(const FXString& txt) {
661 myTextFieldIcon->setTipText(txt);
662}
663
664
665const FXString&
667 return myTextFieldIcon->getTipText();
668}
669
670
671long
672MFXIconComboBox::onUpdFmText(FXObject*, FXSelector, void*) {
673 return target && !isPaneShown() && target->tryHandle(this, FXSEL(SEL_UPDATE, message), NULL);
674}
675
676
677long
678MFXIconComboBox::onFwdToText(FXObject* sender, FXSelector sel, void* ptr) {
679 return myTextFieldIcon->handle(sender, sel, ptr);
680}
681
682
683long
684MFXIconComboBox::onListClicked(FXObject*, FXSelector sel, void* ptr) {
685 myButton->handle(this, FXSEL(SEL_COMMAND, ID_UNPOST), NULL);
686 if (FXSELTYPE(sel) == SEL_COMMAND) {
687 // cast MFXListItem
688 const MFXListItem* item = dynamic_cast<MFXListItem*>(myList->getItem((FXint)(FXival)ptr));
689 // set icon and background color
690 if (item) {
691 myTextFieldIcon->setText(item->getText());
692 myTextFieldIcon->setBackColor(item->getBackGroundColor());
693 myIconLabel->setIcon(item->getIcon());
694 myIconLabel->setBackColor(item->getBackGroundColor());
695 }
696 if (!(options & COMBOBOX_STATIC)) {
697 // Select if editable
698 myTextFieldIcon->selectAll();
699 }
700 if (target) {
701 target->tryHandle(this, FXSEL(SEL_COMMAND, message), (void*)getText().text());
702 }
703 }
704 return 1;
705}
706
707
708long
709MFXIconComboBox::onTextButton(FXObject*, FXSelector, void*) {
710 if (options & COMBOBOX_STATIC) {
711 // Post the myList
712 myButton->handle(this, FXSEL(SEL_COMMAND, ID_POST), NULL);
713 return 1;
714 }
715 return 0;
716}
717
718
719long
720MFXIconComboBox::onTextChanged(FXObject*, FXSelector, void* ptr) {
721 return target && target->tryHandle(this, FXSEL(SEL_CHANGED, message), ptr);
722}
723
724
725long
726MFXIconComboBox::onTextCommand(FXObject*, FXSelector, void* ptr) {
727 FXint index = myList->getCurrentItem();
728 if (!(options & COMBOBOX_STATIC)) {
729 switch (options & COMBOBOX_INS_MASK) {
730 case COMBOBOX_REPLACE:
731 if (0 <= index) {
732 setIconItem(index, (FXchar*)ptr, nullptr, FXRGB(255, 255, 255), getItemData(index));
733 }
734 break;
735 case COMBOBOX_INSERT_BEFORE:
736 if (0 <= index) {
737 insertIconItem(index, (FXchar*)ptr);
738 }
739 break;
740 case COMBOBOX_INSERT_AFTER:
741 if (0 <= index) {
742 insertIconItem(index + 1, (FXchar*)ptr);
743 }
744 break;
745 case COMBOBOX_INSERT_FIRST:
746 insertIconItem(0, (FXchar*)ptr);
747 break;
748 case COMBOBOX_INSERT_LAST:
749 appendIconItem((FXchar*)ptr);
750 break;
751 }
752 }
753 // reset icon and color
754 myTextFieldIcon->setBackColor(FXRGB(255, 255, 255));
755 myIconLabel->setIcon(nullptr);
756 myIconLabel->setBackColor(FXRGB(255, 255, 255));
757 return target && target->tryHandle(this, FXSEL(SEL_COMMAND, message), ptr);
758}
759
760
761long
762MFXIconComboBox::onFocusSelf(FXObject* sender, FXSelector, void* ptr) {
763 return myTextFieldIcon->handle(sender, FXSEL(SEL_FOCUS_SELF, 0), ptr);
764}
765
766
767long
768MFXIconComboBox::onFocusUp(FXObject*, FXSelector, void*) {
769 if (isEnabled()) {
770 FXint index = getCurrentItem();
771 if (index < 0) {
772 index = getNumItems() - 1;
773 } else if (0 < index) {
774 index--;
775 }
776 if (0 <= index && index < getNumItems()) {
777 setCurrentItem(index, TRUE);
778 }
779 return 1;
780 }
781 return 0;
782}
783
784
785long
786MFXIconComboBox::onFocusDown(FXObject*, FXSelector, void*) {
787 if (isEnabled()) {
788 FXint index = getCurrentItem();
789 if (index < 0) {
790 index = 0;
791 } else if (index < getNumItems() - 1) {
792 index++;
793 }
794 if (0 <= index && index < getNumItems()) {
795 setCurrentItem(index, TRUE);
796 }
797 return 1;
798 }
799 return 0;
800}
801
802
803long MFXIconComboBox::onMouseWheel(FXObject*, FXSelector, void* ptr) {
804 FXEvent* event = (FXEvent*)ptr;
805 if (isEnabled()) {
806 FXint index = getCurrentItem();
807 if (event->code < 0) {
808 if (index < 0) {
809 index = 0;
810 } else if (index < getNumItems() - 1) {
811 index++;
812 }
813 } else if (event->code > 0) {
814 if (index < 0) {
815 index = getNumItems() - 1;
816 } else if (0 < index) {
817 index--;
818 }
819 }
820 if (0 <= index && index < getNumItems()) {
821 setCurrentItem(index, TRUE);
822 }
823 return 1;
824 }
825 return 0;
826}
827
828
830 myHaveIcons(false) {}
#define COMBOBOX_MASK
#define ICON_SPACING
#define COMBOBOX_INS_MASK
#define SIDE_SPACING
#define ICON_HEIGHT
FXDEFMAP(MFXIconComboBox) MFXIconComboBoxMap[]
ComboBox with icon.
void setSelBackColor(FXColor clr)
Change selected background color.
const FXString & getHelpText() const
Get the combobox help text.
FXColor getSelBackColor() const
Return selected background color.
virtual void create()
Create server-side resources.
const FXString & getTipText() const
Get the tool tip message for this combobox.
FXint findItem(const FXString &text, FXint start=-1, FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const
virtual ~MFXIconComboBox()
Destructor.
FXString getItem(FXint index) const
Return the item at the given index.
long onTextButton(FXObject *, FXSelector, void *)
long onUpdFmText(FXObject *, FXSelector, void *)
FXint getNumColumns() const
Get the number of columns.
virtual void detach()
Detach server-side resources.
MFXTextFieldIcon * myTextFieldIcon
textField with icon
FXbool isEditable() const
Return true if combobox is editable.
void setHelpText(const FXString &txt)
Set the combobox help text.
void setSelTextColor(FXColor clr)
Change selected text color.
FXString getText() const
Get the text.
long onTextCommand(FXObject *, FXSelector, void *)
void setItemData(FXint index, void *ptr) const
Set data pointer for specified item.
FXint getCurrentItem() const
Get the current item's index.
FXMenuButton * myButton
myButton
FXFont * getFont() const
Get text font.
void removeItem(FXint index)
Remove this item from the list.
long onFocusSelf(FXObject *, FXSelector, void *)
void setSortFunc(FXListSortFunc func)
Change sort function.
void setFont(FXFont *fnt)
Set text font.
virtual void enable()
Enable combo box.
long onMouseWheel(FXObject *, FXSelector, void *)
FXLabel * myIconLabel
label for icon
virtual void layout()
Perform layout.
FXint findItemByData(const void *ptr, FXint start=-1, FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const
FXbool isItemCurrent(FXint index) const
Return true if current item.
void setJustify(FXuint mode)
Change text justification mode; default is JUSTIFY_LEFT.
FXuint getComboStyle() const
Get the combobox style.
FXint insertIconItem(FXint index, const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
Insert a new item at index.
FXint moveItem(FXint newindex, FXint oldindex)
Move item from oldindex to newindex.
FXint setIconItem(FXint index, const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
Replace the item at index.
FXColor getSelTextColor() const
Return selected text color.
FXPopup * myPane
popup
void setCurrentItem(FXint index, FXbool notify=FALSE)
Set the current item (index is zero-based)
void * getItemData(FXint index) const
Get data pointer for specified item.
void setTextColor(FXColor clr)
Change text color.
void sortItems()
Sort items using current sort function.
long onTextChanged(FXObject *, FXSelector, void *)
MFXIconComboBox()
FOX need this.
FXint prependItem(const FXString &text, void *ptr=NULL)
Prepend an item to the list.
virtual FXint getDefaultWidth()
Return default width.
FXList * myList
list
const bool myHaveIcons
check if this iconComboBox have icons
long onFocusUp(FXObject *, FXSelector, void *)
Commands.
void clearItems()
Remove all items from the list.
void setComboStyle(FXuint mode)
Set the combobox style.
FXbool isPaneShown() const
Is the pane shown.
void setText(FXString text)
Set text.
FXListSortFunc getSortFunc() const
Return sort function.
FXString getItemText(FXint index) const
Get text for specified item.
long onFwdToText(FXObject *, FXSelector, void *)
FXuint getJustify() const
Return text justification mode.
FXint getNumVisible() const
Return the number of visible items.
virtual void destroy()
Destroy server-side resources.
void setEditable(FXbool edit=TRUE)
Set editable state.
FXint getNumItems() const
Return the number of items in the list.
void setNumVisible(FXint nvis)
Set the number of visible items in the drop down list.
virtual FXint getDefaultHeight()
Return default height.
void setCustomText(const FXString text)
set custom text
long onFocusDown(FXObject *, FXSelector, void *)
FXColor getTextColor() const
Return text color.
long onListClicked(FXObject *, FXSelector, void *)
void setNumColumns(FXint cols)
Set the number of columns.
bool setItem(const FXString &text, FXIcon *icon)
set Item
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon
virtual void disable()
Disable combo box.
FXColor getBackColor() const
Get background color.
void setTipText(const FXString &txt)
Set the tool tip message for this combobox.
virtual void setBackColor(FXColor clr)
Set window background color.
A list item which allows for custom coloring.
void draw(const FXList *list, FXDC &dc, FXint x, FXint y, FXint w, FXint h)
draw MFXListItem
FXColor myBackGroundColor
backGround color
MFXListItem()
fox need this
const FXColor & getBackGroundColor() const
get background color
FXTextFieldIcon (based on FXTextFieldIcon)
void resetTextField()
reset textField