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
43 FXDEFMAP(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),
51  FXMAPFUNC(SEL_MOUSEWHEEL, MFXIconComboBox::ID_TEXT, MFXIconComboBox::onMouseWheel),
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
65 FXIMPLEMENT(MFXIconComboBox, FXPacker, MFXIconComboBoxMap, ARRAYNUMBER(MFXIconComboBoxMap))
66 FXIMPLEMENT(MFXListItem, FXListItem, nullptr, 0)
67 
68 
69 MFXListItem::MFXListItem(const FXString& text, FXIcon* ic, FXColor backGroundColor, void* ptr):
70  FXListItem(text, ic, ptr),
71  myBackGroundColor(backGroundColor) {
72 }
73 
74 
75 void
76 MFXListItem::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 
113 const FXColor&
115  return myBackGroundColor;
116 }
117 
118 
120  FXListItem("", nullptr),
121  myBackGroundColor(FXRGB(0, 0, 0)) {
122 }
123 
124 
125 MFXIconComboBox::MFXIconComboBox(FXComposite* p, FXint cols, 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  flags |= FLAG_ENABLED;
128  target = tgt;
129  message = sel;
130  myIconLabel = new FXLabel(this, "", nullptr, 0, 0, 0, 0, 0, pl, pr, pt, pb);
131  myTextFieldIcon = new MFXTextFieldIcon(this, cols, this, MFXIconComboBox::ID_TEXT, 0, 0, 0, 0, 0, pl, pr, pt, pb);
132  if (options & COMBOBOX_STATIC) {
133  myTextFieldIcon->setEditable(FALSE);
134  }
135  myPane = new FXPopup(this, FRAME_LINE);
136  myList = new FXList(myPane, this, MFXIconComboBox::ID_LIST, LIST_BROWSESELECT | LIST_AUTOSELECT | LAYOUT_FILL_X | LAYOUT_FIX_HEIGHT | SCROLLERS_TRACK | HSCROLLER_NEVER);
137  if (options & COMBOBOX_STATIC) {
138  myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF);
139  }
140  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);
141  myButton->setXOffset(border);
142  myButton->setYOffset(border);
143  flags &= ~FLAG_UPDATE; // Never GUI update
144 }
145 
146 
148  delete myPane;
149  myPane = (FXPopup*) - 1L;
150  myIconLabel = (FXLabel*) - 1L;
152  myButton = (FXMenuButton*) - 1L;
153  myList = (FXList*) - 1L;
154 }
155 
156 
157 void
159  FXPacker::create();
160  myPane->create();
161 }
162 
163 
164 void
166  FXPacker::detach();
167  myPane->detach();
168 }
169 
170 
171 void
173  myPane->destroy();
174  FXPacker::destroy();
175 }
176 
177 
178 void
180  if (!isEnabled()) {
181  FXPacker::enable();
182  myIconLabel->enable();
183  myTextFieldIcon->enable();
184  myButton->enable();
185  }
186 }
187 
188 
189 void
191  if (isEnabled()) {
192  FXPacker::disable();
193  myIconLabel->disable();
194  myTextFieldIcon->disable();
195  myButton->disable();
196  }
197 }
198 
199 
200 FXint
202  FXint ww, pw;
203  ww = myIconLabel->getDefaultWidth() + myTextFieldIcon->getDefaultWidth() + myButton->getDefaultWidth() + (border << 1);
204  pw = myPane->getDefaultWidth();
205  return FXMAX(ww, pw);
206 }
207 
208 
209 FXint
211  FXint th, bh;
212  th = myTextFieldIcon->getDefaultHeight();
213  bh = myButton->getDefaultHeight();
214  return FXMAX(th, bh) + (border << 1);
215 }
216 
217 
218 void
220  FXint buttonWidth, textWidth, itemHeight, iconSize;
221  itemHeight = height - (border << 1);
222  iconSize = itemHeight;
223  buttonWidth = myButton->getDefaultWidth();
224  textWidth = width - buttonWidth - iconSize - (border << 1);
225  myIconLabel->position(border, border, iconSize, iconSize);
226  myTextFieldIcon->position(border + iconSize, border, textWidth, itemHeight);
227  myButton->position(border + textWidth + iconSize, border, buttonWidth, itemHeight);
228  myPane->resize(width, myPane->getDefaultHeight());
229  flags &= ~FLAG_DIRTY;
230 }
231 
232 
233 FXbool
235  return myTextFieldIcon->isEditable();
236 }
237 
238 
239 void
241  myTextFieldIcon->setEditable(edit);
242 }
243 
244 
245 FXString
247  return myTextFieldIcon->getText();
248 }
249 
250 
251 void
253  myTextFieldIcon->setNumColumns(cols);
254 }
255 
256 
257 FXint
259  return myTextFieldIcon->getNumColumns();
260 }
261 
262 
263 FXint
265  return myList->getNumItems();
266 }
267 
268 
269 FXint
271  return myList->getNumVisible();
272 }
273 
274 
275 void
277  myList->setNumVisible(nvis);
278  // set height manually (due icons)
279  myList->setHeight(nvis * ICON_HEIGHT);
280 }
281 
282 
283 FXbool
284 MFXIconComboBox::isItemCurrent(FXint index) const {
285  return myList->isItemCurrent(index);
286 }
287 
288 
289 void
290 MFXIconComboBox::setCurrentItem(FXint index, FXbool notify) {
291  FXint current = myList->getCurrentItem();
292  if (current != index) {
293  myList->setCurrentItem(index);
294  myList->makeItemVisible(index);
295  if (0 <= index) {
296  // cast MFXListItem
297  const MFXListItem* item = dynamic_cast<MFXListItem*>(myList->getItem(index));
298  // set icon and background color
299  if (item) {
300  myTextFieldIcon->setText(item->getText());
301  myTextFieldIcon->setBackColor(item->getBackGroundColor());
302  myIconLabel->setIcon(item->getIcon());
303  myIconLabel->setBackColor(item->getBackGroundColor());
304  } else {
306  myTextFieldIcon->setBackColor(FXRGB(255, 255, 255));
307  myIconLabel->setIcon(nullptr);
308  myIconLabel->setBackColor(FXRGB(255, 255, 255));
309  }
310  } else {
312  }
313  if (notify && target) {
314  target->tryHandle(this, FXSEL(SEL_COMMAND, message), (void*)getText().text());
315  }
316  }
317 }
318 
319 
320 FXint
322  return myList->getCurrentItem();
323 }
324 
325 
326 FXString
327 MFXIconComboBox::getItem(FXint index) const {
328  return myList->getItem(index)->getText();
329 }
330 
331 
332 FXint
333 MFXIconComboBox::setIconItem(FXint index, const FXString& text, FXIcon* icon, FXColor bgColor, void* ptr) {
334  if (index < 0 || myList->getNumItems() <= index) {
335  fxerror("%s::setItem: index out of range.\n", getClassName());
336  }
337  myList->setItem(index, text, NULL, ptr);
338  if (isItemCurrent(index)) {
339  myTextFieldIcon->setText(text);
340  myTextFieldIcon->setBackColor(bgColor);
341  myIconLabel->setIcon(icon);
342  myIconLabel->setBackColor(bgColor);
343  }
344  recalc();
345  return index;
346 }
347 
348 
349 FXint
350 MFXIconComboBox::insertIconItem(FXint index, const FXString& text, FXIcon* icon, FXColor bgColor, void* ptr) {
351  if (index < 0 || myList->getNumItems() < index) {
352  fxerror("%s::insertItem: index out of range.\n", getClassName());
353  }
354  myList->insertItem(index, text, NULL, ptr);
355  if (isItemCurrent(index)) {
356  myTextFieldIcon->setText(text);
357  myTextFieldIcon->setBackColor(bgColor);
358  myIconLabel->setIcon(icon);
359  myIconLabel->setBackColor(bgColor);
360  }
361  recalc();
362  return index;
363 }
364 
365 
366 FXint
367 MFXIconComboBox::appendIconItem(const FXString& text, FXIcon* icon, FXColor bgColor, void* ptr) {
368  FXint index = myList->appendItem(new MFXListItem(text, icon, bgColor, ptr));
369  if (isItemCurrent(getNumItems() - 1)) {
370  myTextFieldIcon->setText(text);
371  myTextFieldIcon->setBackColor(bgColor);
372  myIconLabel->setIcon(icon);
373  myIconLabel->setBackColor(bgColor);
374  }
375  recalc();
376  return index;
377 }
378 
379 
380 bool
381 MFXIconComboBox::setItem(const FXString& text, FXIcon* icon) {
382  for (int i = 0; i < myList->getNumItems(); i++) {
383  // cast MFXListItem
384  const MFXListItem* item = dynamic_cast<MFXListItem*>(myList->getItem(i));
385  // set icon and background color
386  if (item && (item->getText() == text) && (item->getIcon() == icon)) {
387  myList->setCurrentItem(i, FALSE);
388  return true;
389  }
390  }
391  return false;
392 }
393 
394 
395 FXint
396 MFXIconComboBox::prependItem(const FXString& text, void* ptr) {
397  FXint index = myList->prependItem(text, NULL, ptr);
398  if (isItemCurrent(0)) {
399  myTextFieldIcon->setText(text);
400  myTextFieldIcon->setBackColor(FXRGB(255, 255, 255));
401  myIconLabel->setIcon(nullptr);
402  myIconLabel->setBackColor(FXRGB(255, 255, 255));
403  }
404  recalc();
405  return index;
406 }
407 
408 
409 FXint
410 MFXIconComboBox::moveItem(FXint newindex, FXint oldindex) {
411  if (newindex < 0 || myList->getNumItems() <= newindex || oldindex < 0 || myList->getNumItems() <= oldindex) {
412  fxerror("%s::moveItem: index out of range.\n", getClassName());
413  }
414  FXint current = myList->getCurrentItem();
415  myList->moveItem(newindex, oldindex);
416  if (current != myList->getCurrentItem()) {
417  current = myList->getCurrentItem();
418  if (0 <= current) {
419  myTextFieldIcon->setText(myList->getItemText(current));
420  } else {
421  myTextFieldIcon->setText(" ");
422  }
423  myIconLabel->setIcon(nullptr);
424  myIconLabel->setBackColor(FXRGB(255, 255, 255));
425  }
426  recalc();
427  return newindex;
428 }
429 
430 
431 void
433  FXint current = myList->getCurrentItem();
434  myList->removeItem(index);
435  if (index == current) {
436  current = myList->getCurrentItem();
437  if (0 <= current) {
438  myTextFieldIcon->setText(myList->getItemText(current));
439  } else {
440  myTextFieldIcon->setText(FXString::null);
441  }
442  myIconLabel->setIcon(nullptr);
443  myIconLabel->setBackColor(FXRGB(255, 255, 255));
444  }
445  recalc();
446 }
447 
448 
449 void
452  myList->clearItems();
453  recalc();
454 }
455 
456 
457 FXint
458 MFXIconComboBox::findItem(const FXString& text, FXint start, FXuint flgs) const {
459  return myList->findItem(text, start, flgs);
460 }
461 
462 
463 FXint
464 MFXIconComboBox::findItemByData(const void* ptr, FXint start, FXuint flgs) const {
465  return myList->findItemByData(ptr, start, flgs);
466 }
467 
468 
469 FXString
470 MFXIconComboBox::getItemText(FXint index) const {
471  return myList->getItemText(index);
472 }
473 
474 
475 void
476 MFXIconComboBox::setItemData(FXint index, void* ptr) const {
477  myList->setItemData(index, ptr);
478 }
479 
480 
481 void*
482 MFXIconComboBox::getItemData(FXint index) const {
483  return myList->getItemData(index);
484 }
485 
486 
487 FXbool
489  return myPane->shown();
490 }
491 
492 
493 void
495  if (!fnt) {
496  fxerror("%s::setFont: NULL font specified.\n", getClassName());
497  }
498  myTextFieldIcon->setFont(fnt);
499  myList->setFont(fnt);
500  recalc();
501 }
502 
503 
504 FXFont*
506  return myTextFieldIcon->getFont();
507 }
508 
509 
510 void
512  FXuint opts = (options & ~COMBOBOX_MASK) | (mode & COMBOBOX_MASK);
513  if (opts != options) {
514  options = opts;
515  if (options & COMBOBOX_STATIC) {
516  myTextFieldIcon->setEditable(FALSE); // Non-editable
517  myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF); // No scrolling
518  } else {
519  myTextFieldIcon->setEditable(TRUE); // Editable
520  myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLER_NEVER); // Scrollable, but no scrollbar
521  }
522  recalc();
523  }
524 }
525 
526 
527 FXuint
529  return (options & COMBOBOX_MASK);
530 }
531 
532 
533 void
535  myTextFieldIcon->setJustify(style);
536 }
537 
538 
539 FXuint
541  return myTextFieldIcon->getJustify();
542 }
543 
544 
545 void
547  myTextFieldIcon->setBackColor(clr);
548  myIconLabel->setBackColor(clr);
549  myList->setBackColor(clr);
550 }
551 
552 
553 FXColor
555  return myTextFieldIcon->getBackColor();
556 }
557 
558 
559 void
561  myTextFieldIcon->setTextColor(clr);
562  myList->setTextColor(clr);
563 }
564 
565 
566 FXColor
568  return myTextFieldIcon->getTextColor();
569 }
570 
571 
572 void
574  myTextFieldIcon->setSelBackColor(clr);
575  myList->setSelBackColor(clr);
576 }
577 
578 
579 FXColor
581  return myTextFieldIcon->getSelBackColor();
582 }
583 
584 
585 void
587  myTextFieldIcon->setSelTextColor(clr);
588  myList->setSelTextColor(clr);
589 }
590 
591 
592 FXColor
594  return myTextFieldIcon->getSelTextColor();
595 }
596 
597 
598 void
600  myList->sortItems();
601 }
602 
603 
604 FXListSortFunc
606  return myList->getSortFunc();
607 }
608 
609 
610 void
611 MFXIconComboBox::setSortFunc(FXListSortFunc func) {
612  myList->setSortFunc(func);
613 }
614 
615 
616 void
617 MFXIconComboBox::setHelpText(const FXString& txt) {
618  myTextFieldIcon->setHelpText(txt);
619 }
620 
621 
622 const FXString&
624  return myTextFieldIcon->getHelpText();
625 }
626 
627 
628 void
629 MFXIconComboBox::setTipText(const FXString& txt) {
630  myTextFieldIcon->setTipText(txt);
631 }
632 
633 
634 const FXString&
636  return myTextFieldIcon->getTipText();
637 }
638 
639 
640 long
641 MFXIconComboBox::onUpdFmText(FXObject*, FXSelector, void*) {
642  return target && !isPaneShown() && target->tryHandle(this, FXSEL(SEL_UPDATE, message), NULL);
643 }
644 
645 
646 long
647 MFXIconComboBox::onFwdToText(FXObject* sender, FXSelector sel, void* ptr) {
648  return myTextFieldIcon->handle(sender, sel, ptr);
649 }
650 
651 
652 long
653 MFXIconComboBox::onListClicked(FXObject*, FXSelector sel, void* ptr) {
654  myButton->handle(this, FXSEL(SEL_COMMAND, ID_UNPOST), NULL);
655  if (FXSELTYPE(sel) == SEL_COMMAND) {
656  // cast MFXListItem
657  const MFXListItem* item = dynamic_cast<MFXListItem*>(myList->getItem((FXint)(FXival)ptr));
658  // set icon and background color
659  if (item) {
660  myTextFieldIcon->setText(item->getText());
661  myTextFieldIcon->setBackColor(item->getBackGroundColor());
662  myIconLabel->setIcon(item->getIcon());
663  myIconLabel->setBackColor(item->getBackGroundColor());
664  }
665  if (!(options & COMBOBOX_STATIC)) {
666  // Select if editable
667  myTextFieldIcon->selectAll();
668  }
669  if (target) {
670  target->tryHandle(this, FXSEL(SEL_COMMAND, message), (void*)getText().text());
671  }
672  }
673  return 1;
674 }
675 
676 
677 long
678 MFXIconComboBox::onTextButton(FXObject*, FXSelector, void*) {
679  if (options & COMBOBOX_STATIC) {
680  // Post the myList
681  myButton->handle(this, FXSEL(SEL_COMMAND, ID_POST), NULL);
682  return 1;
683  }
684  return 0;
685 }
686 
687 
688 long
689 MFXIconComboBox::onTextChanged(FXObject*, FXSelector, void* ptr) {
690  return target && target->tryHandle(this, FXSEL(SEL_CHANGED, message), ptr);
691 }
692 
693 
694 long
695 MFXIconComboBox::onTextCommand(FXObject*, FXSelector, void* ptr) {
696  FXint index = myList->getCurrentItem();
697  if (!(options & COMBOBOX_STATIC)) {
698  switch (options & COMBOBOX_INS_MASK) {
699  case COMBOBOX_REPLACE:
700  if (0 <= index) {
701  setIconItem(index, (FXchar*)ptr, nullptr, FXRGB(255, 255, 255), getItemData(index));
702  }
703  break;
704  case COMBOBOX_INSERT_BEFORE:
705  if (0 <= index) {
706  insertIconItem(index, (FXchar*)ptr);
707  }
708  break;
709  case COMBOBOX_INSERT_AFTER:
710  if (0 <= index) {
711  insertIconItem(index + 1, (FXchar*)ptr);
712  }
713  break;
714  case COMBOBOX_INSERT_FIRST:
715  insertIconItem(0, (FXchar*)ptr);
716  break;
717  case COMBOBOX_INSERT_LAST:
718  appendIconItem((FXchar*)ptr);
719  break;
720  }
721  }
722  // reset icon and color
723  myTextFieldIcon->setBackColor(FXRGB(255, 255, 255));
724  myIconLabel->setIcon(nullptr);
725  myIconLabel->setBackColor(FXRGB(255, 255, 255));
726  return target && target->tryHandle(this, FXSEL(SEL_COMMAND, message), ptr);
727 }
728 
729 
730 long
731 MFXIconComboBox::onFocusSelf(FXObject* sender, FXSelector, void* ptr) {
732  return myTextFieldIcon->handle(sender, FXSEL(SEL_FOCUS_SELF, 0), ptr);
733 }
734 
735 
736 long
737 MFXIconComboBox::onFocusUp(FXObject*, FXSelector, void*) {
738  if (isEnabled()) {
739  FXint index = getCurrentItem();
740  if (index < 0) {
741  index = getNumItems() - 1;
742  } else if (0 < index) {
743  index--;
744  }
745  if (0 <= index && index < getNumItems()) {
746  setCurrentItem(index, TRUE);
747  }
748  return 1;
749  }
750  return 0;
751 }
752 
753 
754 long
755 MFXIconComboBox::onFocusDown(FXObject*, FXSelector, void*) {
756  if (isEnabled()) {
757  FXint index = getCurrentItem();
758  if (index < 0) {
759  index = 0;
760  } else if (index < getNumItems() - 1) {
761  index++;
762  }
763  if (0 <= index && index < getNumItems()) {
764  setCurrentItem(index, TRUE);
765  }
766  return 1;
767  }
768  return 0;
769 }
770 
771 
772 long MFXIconComboBox::onMouseWheel(FXObject*, FXSelector, void* ptr) {
773  FXEvent* event = (FXEvent*)ptr;
774  if (isEnabled()) {
775  FXint index = getCurrentItem();
776  if (event->code < 0) {
777  if (index < 0) {
778  index = 0;
779  } else if (index < getNumItems() - 1) {
780  index++;
781  }
782  } else if (event->code > 0) {
783  if (index < 0) {
784  index = getNumItems() - 1;
785  } else if (0 < index) {
786  index--;
787  }
788  }
789  if (0 <= index && index < getNumItems()) {
790  setCurrentItem(index, TRUE);
791  }
792  return 1;
793  }
794  return 0;
795 }
796 
797 
#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
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.
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.
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