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