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