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-2020 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 /****************************************************************************/
18 //
19 /****************************************************************************/
20 
21 /* =========================================================================
22  * included modules
23  * ======================================================================= */
24 #include <config.h>
25 
26 #ifdef WIN32
27 #define NOMINMAX
28 #include <windows.h>
29 #undef NOMINMAX
30 #endif
31 
32 #include "MFXIconComboBox.h"
33 
34 
35 #define SIDE_SPACING 6 // Left or right spacing between items
36 #define ICON_SPACING 4 // Spacing between icon and label
37 
38 FXIMPLEMENT(MFXListItem, FXListItem, nullptr, 0)
39 FXIMPLEMENT(MFXIconComboBox, FXComboBox, nullptr, 0)
40 
41 void MFXListItem::draw(const FXList* list, FXDC& dc, FXint xx, FXint yy, FXint ww, FXint hh) {
42  // almost the same code as FXListItem::draw except for using custom background color
43  FXFont* font = list->getFont();
44  FXint ih = 0, th = 0;
45  if (icon) {
46  ih = icon->getHeight();
47  }
48  if (!label.empty()) {
49  th = font->getFontHeight();
50  }
51  if (isSelected()) {
52  dc.setForeground(list->getSelBackColor());
53  } else if (bgColor != FXRGBA(0, 0, 0, 0)) {
54  dc.setForeground(bgColor); // custom code here
55  } else {
56  dc.setForeground(list->getBackColor());
57  }
58  dc.fillRectangle(xx, yy, ww, hh);
59  if (hasFocus()) {
60  dc.drawFocusRectangle(xx + 1, yy + 1, ww - 2, hh - 2);
61  }
62  xx += SIDE_SPACING / 2;
63  if (icon) {
64  dc.drawIcon(icon, xx, yy + (hh - ih) / 2);
65  xx += ICON_SPACING + icon->getWidth();
66  }
67  if (!label.empty()) {
68  dc.setFont(font);
69  if (!isEnabled()) {
70  dc.setForeground(makeShadowColor(list->getBackColor()));
71  } else if (isSelected()) {
72  dc.setForeground(list->getSelTextColor());
73  } else {
74  dc.setForeground(list->getTextColor());
75  }
76  dc.drawText(xx, yy + (hh - th) / 2 + font->getFontAscent(), label);
77  }
78 }
79 
80 
82  FXComposite* p, FXint cols, FXObject* tgt,
83  FXSelector sel, FXuint opts,
84  FXint x, FXint y, FXint w, FXint h,
85  FXint pl, FXint pr, FXint pt, FXint pb):
86  FXComboBox(p, cols, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb)
87 {}
88 
89 FXint
90 MFXIconComboBox::appendIconItem(const FXString& text, FXIcon* icon, FXColor bgColor, void* ptr) {
91  FXint index = list->appendItem(new MFXListItem(text, icon, bgColor, ptr));
92  if (isItemCurrent(getNumItems() - 1)) {
93  field->setText(text);
94  }
95  recalc();
96  return index;
97 }
98 
#define ICON_SPACING
#define SIDE_SPACING
FXint appendIconItem(const FXString &text, FXIcon *icon, FXColor bgColor=FXRGBA(0, 0, 0, 0), void *ptr=NULL)