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-2023 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 (2 + 2)
38 #define ICON_SIZE 16
39 #define COMBOBOX_INS_MASK (COMBOBOX_REPLACE | COMBOBOX_INSERT_BEFORE | COMBOBOX_INSERT_AFTER | COMBOBOX_INSERT_FIRST | COMBOBOX_INSERT_LAST)
40 #define COMBOBOX_MASK (COMBOBOX_STATIC | COMBOBOX_INS_MASK)
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  register FXFont *font = myList->getFont();
78  register FXint ih = 0, th = 0;
79  ih = ICON_SIZE;
80  if (!label.empty()) {
81  th = font->getFontHeight();
82  }
83  if (isSelected()) {
84  dc.setForeground(myList->getSelBackColor());
85  } else {
86  dc.setForeground(myBackGroundColor); // FIXME maybe paint background in onPaint?
87  }
88  dc.fillRectangle(xx, yy, ww, hh);
89  if (hasFocus()) {
90  dc.drawFocusRectangle(xx + 1, yy + 1, ww - 2, hh - 2);
91  }
92  xx += SIDE_SPACING/2;
93  if (icon) {
94  dc.drawIcon(icon, xx, yy + (hh - ih) / 2);
95  }
96  xx += ICON_SPACING + ICON_SIZE;
97  if (!label.empty()) {
98  dc.setFont(font);
99  if (!isEnabled()) {
100  dc.setForeground(makeShadowColor(myList->getBackColor()));
101  } else if (isSelected()) {
102  dc.setForeground(myList->getSelTextColor());
103  } else {
104  dc.setForeground(myList->getTextColor());
105  }
106  dc.drawText(xx, yy + (hh - th) / 2 + font->getFontAscent(), label);
107  }
108 }
109 
110 const FXColor&
112  return myBackGroundColor;
113 }
114 
115 
117  FXListItem("", nullptr),
118  myBackGroundColor(FXRGB(0, 0, 0)) {
119 }
120 
121 
122 MFXIconComboBox::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):
123  FXPacker(p, opts, x, y, w, h, 0, 0, 0, 0, 0, 0),
124  myHaveIcons(haveIcons) {
125  flags |= FLAG_ENABLED;
126  target = tgt;
127  message = sel;
128  myIconLabel = new FXLabel(this, "", nullptr, 0, 0, 0, 0, 0, pl, pr, pt, pb);
129  if (!myHaveIcons) {
130  myIconLabel->hide();
131  }
132  myTextFieldIcon = new MFXTextFieldIcon(this, cols, this, MFXIconComboBox::ID_TEXT, 0, 0, 0, 0, 0, pl, pr, pt, pb);
133  if (options & COMBOBOX_STATIC) {
134  myTextFieldIcon->setEditable(FALSE);
135  }
136  myPane = new FXPopup(this, FRAME_LINE);
137  myList = new FXList(myPane, this, MFXIconComboBox::ID_LIST, LIST_BROWSESELECT | LIST_AUTOSELECT | LAYOUT_FILL_X | LAYOUT_FIX_HEIGHT | SCROLLERS_TRACK | HSCROLLER_NEVER);
138  if (options & COMBOBOX_STATIC) {
139  myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF);
140  }
141  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);
142  myButton->setXOffset(border);
143  myButton->setYOffset(border);
144  flags &= ~FLAG_UPDATE; // Never GUI update
145 }
146 
147 
149  delete myPane;
150  myPane = (FXPopup*) - 1L;
151  myIconLabel = (FXLabel*) - 1L;
153  myButton = (FXMenuButton*) - 1L;
154  myList = (FXList*) - 1L;
155 }
156 
157 
158 void
160  FXPacker::create();
161  myPane->create();
162 }
163 
164 
165 void
167  FXPacker::detach();
168  myPane->detach();
169 }
170 
171 
172 void
174  myPane->destroy();
175  FXPacker::destroy();
176 }
177 
178 
179 void
181  if (!isEnabled()) {
182  FXPacker::enable();
183  myIconLabel->enable();
184  myTextFieldIcon->enable();
185  myButton->enable();
186  }
187 }
188 
189 
190 void
192  if (isEnabled()) {
193  FXPacker::disable();
194  myIconLabel->disable();
195  myTextFieldIcon->disable();
196  myButton->disable();
197  }
198 }
199 
200 
201 FXint
203  FXint ww, pw;
204  if (myIconLabel->shown()) {
205  ww = myIconLabel->getDefaultWidth() + myTextFieldIcon->getDefaultWidth() + myButton->getDefaultWidth() + (border << 1);
206  } else {
207  ww = myTextFieldIcon->getDefaultWidth() + myButton->getDefaultWidth() + (border << 1);
208  }
209  pw = myPane->getDefaultWidth();
210  return FXMAX(ww, pw);
211 }
212 
213 
214 FXint
216  FXint th, bh;
217  th = myTextFieldIcon->getDefaultHeight();
218  bh = myButton->getDefaultHeight();
219  return FXMAX(th, bh) + (border << 1);
220 }
221 
222 
223 void
225  const FXint itemHeight = height - (border << 1);
226  const FXint iconSize = myHaveIcons ? itemHeight : 0;
227  const FXint buttonWidth = myButton->getDefaultWidth();
228  const FXint textWidth = width - buttonWidth - iconSize - (border << 1);
229  myIconLabel->position(border, border, iconSize, iconSize);
230  myTextFieldIcon->position(border + iconSize, border, textWidth, itemHeight);
231  myButton->position(border + textWidth + iconSize, border, buttonWidth, itemHeight);
232 
233  int size = -1;
234  for (int i = 0; i < myList->getNumItems(); i++) {
235  if (myList->getItemWidth(i) > size) {
236  size = myList->getItemWidth(i);
237  }
238  }
239  myPane->resize(size + 17, myPane->getDefaultHeight());
240  flags &= ~FLAG_DIRTY;
241 }
242 
243 
244 FXbool
246  return myTextFieldIcon->isEditable();
247 }
248 
249 
250 void
252  myTextFieldIcon->setEditable(edit);
253 }
254 
255 
256 FXString
258  return myTextFieldIcon->getText();
259 }
260 
261 
262 void
264  myTextFieldIcon->setNumColumns(cols);
265 }
266 
267 
268 FXint
270  return myTextFieldIcon->getNumColumns();
271 }
272 
273 
274 FXint
276  return myList->getNumItems();
277 }
278 
279 
280 FXint
282  return myList->getNumVisible();
283 }
284 
285 
286 void
287 MFXIconComboBox::setText(FXString text) {
288  myTextFieldIcon->setText(text);
289 }
290 
291 
292 void
294  myList->setNumVisible(nvis);
295  myList->setHeight(nvis * (ICON_SIZE + ICON_SPACING));
296 }
297 
298 
299 FXbool
300 MFXIconComboBox::isItemCurrent(FXint index) const {
301  return myList->isItemCurrent(index);
302 }
303 
304 
305 void
306 MFXIconComboBox::setCurrentItem(FXint index, FXbool notify) {
307  FXint current = myList->getCurrentItem();
308  if (current != index) {
309  myList->setCurrentItem(index);
310  myList->makeItemVisible(index);
311  if (0 <= index) {
312  // cast MFXListItem
313  const MFXListItem* item = dynamic_cast<MFXListItem*>(myList->getItem(index));
314  // set icon and background color
315  if (item) {
316  myTextFieldIcon->setText(item->getText());
317  myTextFieldIcon->setBackColor(item->getBackGroundColor());
318  myIconLabel->setIcon(item->getIcon());
319  myIconLabel->setBackColor(item->getBackGroundColor());
320  } else {
322  myTextFieldIcon->setBackColor(FXRGB(255, 255, 255));
323  myIconLabel->setIcon(nullptr);
324  myIconLabel->setBackColor(FXRGB(255, 255, 255));
325  }
326  } else {
328  }
329  if (notify && target) {
330  target->tryHandle(this, FXSEL(SEL_COMMAND, message), (void*)getText().text());
331  }
332  }
333 }
334 
335 
336 FXint
338  return myList->getCurrentItem();
339 }
340 
341 
342 FXString
343 MFXIconComboBox::getItem(FXint index) const {
344  return myList->getItem(index)->getText();
345 }
346 
347 
348 FXint
349 MFXIconComboBox::setIconItem(FXint index, const FXString& text, FXIcon* icon, FXColor bgColor, void* ptr) {
350  if (index < 0 || myList->getNumItems() <= index) {
351  fxerror("%s::setItem: index out of range.\n", getClassName());
352  }
353  myList->setItem(index, text, NULL, ptr);
354  if (isItemCurrent(index)) {
355  myTextFieldIcon->setText(text);
356  myTextFieldIcon->setBackColor(bgColor);
357  myIconLabel->setIcon(icon);
358  myIconLabel->setBackColor(bgColor);
359  }
360  recalc();
361  return index;
362 }
363 
364 
365 FXint
366 MFXIconComboBox::insertIconItem(FXint index, const FXString& text, FXIcon* icon, FXColor bgColor, void* ptr) {
367  if (index < 0 || myList->getNumItems() < index) {
368  fxerror("%s::insertItem: index out of range.\n", getClassName());
369  }
370  myList->insertItem(index, text, NULL, ptr);
371  if (isItemCurrent(index)) {
372  myTextFieldIcon->setText(text);
373  myTextFieldIcon->setBackColor(bgColor);
374  myIconLabel->setIcon(icon);
375  myIconLabel->setBackColor(bgColor);
376  }
377  recalc();
378  return index;
379 }
380 
381 
382 FXint
383 MFXIconComboBox::appendIconItem(const FXString& text, FXIcon* icon, FXColor bgColor, void* ptr) {
384  FXint index = myList->appendItem(new MFXListItem(text, icon, bgColor, ptr));
385  if (isItemCurrent(getNumItems() - 1)) {
386  myTextFieldIcon->setText(text);
387  myTextFieldIcon->setBackColor(bgColor);
388  myIconLabel->setIcon(icon);
389  myIconLabel->setBackColor(bgColor);
390  }
391  recalc();
392  return index;
393 }
394 
395 
396 bool
397 MFXIconComboBox::setItem(const FXString& text, FXIcon* icon) {
398  for (int i = 0; i < myList->getNumItems(); i++) {
399  // cast MFXListItem
400  const MFXListItem* item = dynamic_cast<MFXListItem*>(myList->getItem(i));
401  // set icon and background color
402  if (item && (item->getText() == text) && (item->getIcon() == icon)) {
403  myTextFieldIcon->setText(item->getText());
404  myTextFieldIcon->setBackColor(item->getBackGroundColor());
405  myIconLabel->setIcon(item->getIcon());
406  myIconLabel->setBackColor(item->getBackGroundColor());
407  myTextFieldIcon->setTextColor(FXRGB(0, 0, 0));
408  return true;
409  }
410  }
411  return false;
412 }
413 
414 
415 void
416 MFXIconComboBox::setCustomText(const FXString text) {
417  myTextFieldIcon->setText(text);
418  myTextFieldIcon->setTextColor(FXRGB(128, 128, 128));
419 }
420 
421 
422 FXint
423 MFXIconComboBox::prependItem(const FXString& text, void* ptr) {
424  FXint index = myList->prependItem(text, NULL, ptr);
425  if (isItemCurrent(0)) {
426  myTextFieldIcon->setText(text);
427  myTextFieldIcon->setBackColor(FXRGB(255, 255, 255));
428  myIconLabel->setIcon(nullptr);
429  myIconLabel->setBackColor(FXRGB(255, 255, 255));
430  }
431  recalc();
432  return index;
433 }
434 
435 
436 FXint
437 MFXIconComboBox::moveItem(FXint newindex, FXint oldindex) {
438  if (newindex < 0 || myList->getNumItems() <= newindex || oldindex < 0 || myList->getNumItems() <= oldindex) {
439  fxerror("%s::moveItem: index out of range.\n", getClassName());
440  }
441  FXint current = myList->getCurrentItem();
442  myList->moveItem(newindex, oldindex);
443  if (current != myList->getCurrentItem()) {
444  current = myList->getCurrentItem();
445  if (0 <= current) {
446  myTextFieldIcon->setText(myList->getItemText(current));
447  } else {
448  myTextFieldIcon->setText(" ");
449  }
450  myIconLabel->setIcon(nullptr);
451  myIconLabel->setBackColor(FXRGB(255, 255, 255));
452  }
453  recalc();
454  return newindex;
455 }
456 
457 
458 void
460  FXint current = myList->getCurrentItem();
461  myList->removeItem(index);
462  if (index == current) {
463  current = myList->getCurrentItem();
464  if (0 <= current) {
465  myTextFieldIcon->setText(myList->getItemText(current));
466  } else {
467  myTextFieldIcon->setText(FXString::null);
468  }
469  myIconLabel->setIcon(nullptr);
470  myIconLabel->setBackColor(FXRGB(255, 255, 255));
471  }
472  recalc();
473 }
474 
475 
476 void
479  myList->clearItems();
480  recalc();
481 }
482 
483 
484 FXint
485 MFXIconComboBox::findItem(const FXString& text, FXint start, FXuint flgs) const {
486  return myList->findItem(text, start, flgs);
487 }
488 
489 
490 FXint
491 MFXIconComboBox::findItemByData(const void* ptr, FXint start, FXuint flgs) const {
492  return myList->findItemByData(ptr, start, flgs);
493 }
494 
495 
496 FXString
497 MFXIconComboBox::getItemText(FXint index) const {
498  return myList->getItemText(index);
499 }
500 
501 
502 void
503 MFXIconComboBox::setItemData(FXint index, void* ptr) const {
504  myList->setItemData(index, ptr);
505 }
506 
507 
508 void*
509 MFXIconComboBox::getItemData(FXint index) const {
510  return myList->getItemData(index);
511 }
512 
513 
514 FXbool
516  return myPane->shown();
517 }
518 
519 
520 void
522  if (!fnt) {
523  fxerror("%s::setFont: NULL font specified.\n", getClassName());
524  }
525  myTextFieldIcon->setFont(fnt);
526  myList->setFont(fnt);
527  recalc();
528 }
529 
530 
531 FXFont*
533  return myTextFieldIcon->getFont();
534 }
535 
536 
537 void
539  FXuint opts = (options & ~COMBOBOX_MASK) | (mode & COMBOBOX_MASK);
540  if (opts != options) {
541  options = opts;
542  if (options & COMBOBOX_STATIC) {
543  myTextFieldIcon->setEditable(FALSE); // Non-editable
544  myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF); // No scrolling
545  } else {
546  myTextFieldIcon->setEditable(TRUE); // Editable
547  myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLER_NEVER); // Scrollable, but no scrollbar
548  }
549  recalc();
550  }
551 }
552 
553 
554 FXuint
556  return (options & COMBOBOX_MASK);
557 }
558 
559 
560 void
562  myTextFieldIcon->setJustify(style);
563 }
564 
565 
566 FXuint
568  return myTextFieldIcon->getJustify();
569 }
570 
571 
572 void
574  myTextFieldIcon->setBackColor(clr);
575  myIconLabel->setBackColor(clr);
576  myList->setBackColor(clr);
577 }
578 
579 
580 FXColor
582  return myTextFieldIcon->getBackColor();
583 }
584 
585 
586 void
588  myTextFieldIcon->setTextColor(clr);
589  myList->setTextColor(clr);
590 }
591 
592 
593 FXColor
595  return myTextFieldIcon->getTextColor();
596 }
597 
598 
599 void
601  myTextFieldIcon->setSelBackColor(clr);
602  myList->setSelBackColor(clr);
603 }
604 
605 
606 FXColor
608  return myTextFieldIcon->getSelBackColor();
609 }
610 
611 
612 void
614  myTextFieldIcon->setSelTextColor(clr);
615  myList->setSelTextColor(clr);
616 }
617 
618 
619 FXColor
621  return myTextFieldIcon->getSelTextColor();
622 }
623 
624 
625 void
627  myList->sortItems();
628 }
629 
630 
631 FXListSortFunc
633  return myList->getSortFunc();
634 }
635 
636 
637 void
638 MFXIconComboBox::setSortFunc(FXListSortFunc func) {
639  myList->setSortFunc(func);
640 }
641 
642 
643 void
644 MFXIconComboBox::setHelpText(const FXString& txt) {
645  myTextFieldIcon->setHelpText(txt);
646 }
647 
648 
649 const FXString&
651  return myTextFieldIcon->getHelpText();
652 }
653 
654 
655 void
656 MFXIconComboBox::setTipText(const FXString& txt) {
657  myTextFieldIcon->setTipText(txt);
658 }
659 
660 
661 const FXString&
663  return myTextFieldIcon->getTipText();
664 }
665 
666 
667 long
668 MFXIconComboBox::onUpdFmText(FXObject*, FXSelector, void*) {
669  return target && !isPaneShown() && target->tryHandle(this, FXSEL(SEL_UPDATE, message), NULL);
670 }
671 
672 
673 long
674 MFXIconComboBox::onFwdToText(FXObject* sender, FXSelector sel, void* ptr) {
675  return myTextFieldIcon->handle(sender, sel, ptr);
676 }
677 
678 
679 long
680 MFXIconComboBox::onListClicked(FXObject*, FXSelector sel, void* ptr) {
681  myButton->handle(this, FXSEL(SEL_COMMAND, ID_UNPOST), NULL);
682  if (FXSELTYPE(sel) == SEL_COMMAND) {
683  // cast MFXListItem
684  const MFXListItem* item = dynamic_cast<MFXListItem*>(myList->getItem((FXint)(FXival)ptr));
685  // set icon and background color
686  if (item) {
687  myTextFieldIcon->setText(item->getText());
688  myTextFieldIcon->setBackColor(item->getBackGroundColor());
689  myIconLabel->setIcon(item->getIcon());
690  myIconLabel->setBackColor(item->getBackGroundColor());
691  }
692  if (!(options & COMBOBOX_STATIC)) {
693  // Select if editable
694  myTextFieldIcon->selectAll();
695  }
696  if (target) {
697  target->tryHandle(this, FXSEL(SEL_COMMAND, message), (void*)getText().text());
698  }
699  }
700  return 1;
701 }
702 
703 
704 long
705 MFXIconComboBox::onTextButton(FXObject*, FXSelector, void*) {
706  if (options & COMBOBOX_STATIC) {
707  // Post the myList
708  myButton->handle(this, FXSEL(SEL_COMMAND, ID_POST), NULL);
709  return 1;
710  }
711  return 0;
712 }
713 
714 
715 long
716 MFXIconComboBox::onTextChanged(FXObject*, FXSelector, void* ptr) {
717  return target && target->tryHandle(this, FXSEL(SEL_CHANGED, message), ptr);
718 }
719 
720 
721 long
722 MFXIconComboBox::onTextCommand(FXObject*, FXSelector, void* ptr) {
723  FXint index = myList->getCurrentItem();
724  if (!(options & COMBOBOX_STATIC)) {
725  switch (options & COMBOBOX_INS_MASK) {
726  case COMBOBOX_REPLACE:
727  if (0 <= index) {
728  setIconItem(index, (FXchar*)ptr, nullptr, FXRGB(255, 255, 255), getItemData(index));
729  }
730  break;
731  case COMBOBOX_INSERT_BEFORE:
732  if (0 <= index) {
733  insertIconItem(index, (FXchar*)ptr);
734  }
735  break;
736  case COMBOBOX_INSERT_AFTER:
737  if (0 <= index) {
738  insertIconItem(index + 1, (FXchar*)ptr);
739  }
740  break;
741  case COMBOBOX_INSERT_FIRST:
742  insertIconItem(0, (FXchar*)ptr);
743  break;
744  case COMBOBOX_INSERT_LAST:
745  appendIconItem((FXchar*)ptr);
746  break;
747  }
748  }
749  // reset icon and color
750  myTextFieldIcon->setBackColor(FXRGB(255, 255, 255));
751  myIconLabel->setIcon(nullptr);
752  myIconLabel->setBackColor(FXRGB(255, 255, 255));
753  return target && target->tryHandle(this, FXSEL(SEL_COMMAND, message), ptr);
754 }
755 
756 
757 long
758 MFXIconComboBox::onFocusSelf(FXObject* sender, FXSelector, void* ptr) {
759  return myTextFieldIcon->handle(sender, FXSEL(SEL_FOCUS_SELF, 0), ptr);
760 }
761 
762 
763 long
764 MFXIconComboBox::onFocusUp(FXObject*, FXSelector, void*) {
765  if (isEnabled()) {
766  FXint index = getCurrentItem();
767  if (index < 0) {
768  index = getNumItems() - 1;
769  } else if (0 < index) {
770  index--;
771  }
772  if (0 <= index && index < getNumItems()) {
773  setCurrentItem(index, TRUE);
774  }
775  return 1;
776  }
777  return 0;
778 }
779 
780 
781 long
782 MFXIconComboBox::onFocusDown(FXObject*, FXSelector, void*) {
783  if (isEnabled()) {
784  FXint index = getCurrentItem();
785  if (index < 0) {
786  index = 0;
787  } else if (index < getNumItems() - 1) {
788  index++;
789  }
790  if (0 <= index && index < getNumItems()) {
791  setCurrentItem(index, TRUE);
792  }
793  return 1;
794  }
795  return 0;
796 }
797 
798 
799 long MFXIconComboBox::onMouseWheel(FXObject*, FXSelector, void* ptr) {
800  FXEvent* event = (FXEvent*)ptr;
801  if (isEnabled()) {
802  FXint index = getCurrentItem();
803  if (event->code < 0) {
804  if (index < 0) {
805  index = 0;
806  } else if (index < getNumItems() - 1) {
807  index++;
808  }
809  } else if (event->code > 0) {
810  if (index < 0) {
811  index = getNumItems() - 1;
812  } else if (0 < index) {
813  index--;
814  }
815  }
816  if (0 <= index && index < getNumItems()) {
817  setCurrentItem(index, TRUE);
818  }
819  return 1;
820  }
821  return 0;
822 }
823 
824 
826  myHaveIcons(false) {}
#define COMBOBOX_MASK
#define ICON_SPACING
#define COMBOBOX_INS_MASK
#define SIDE_SPACING
FXDEFMAP(MFXIconComboBox) MFXIconComboBoxMap[]
#define ICON_SIZE
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