Eclipse SUMO - Simulation of Urban MObility
MFXCheckableButton.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2004-2024 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 // missing_desc
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include "MFXCheckableButton.h"
23 
24 
25 FXDEFMAP(MFXCheckableButton) MFXCheckableButtonMap[] = {
26  FXMAPFUNC(SEL_PAINT, 0, MFXCheckableButton::onPaint),
27  FXMAPFUNC(SEL_UPDATE, 0, MFXCheckableButton::onUpdate),
28  FXMAPFUNC(SEL_ENTER, 0, MFXCheckableButton::onEnter),
29  FXMAPFUNC(SEL_LEAVE, 0, MFXCheckableButton::onLeave),
30  FXMAPFUNC(SEL_MOTION, 0, MFXCheckableButton::onMotion),
31 };
32 
33 
34 // Object implementation
35 FXIMPLEMENT(MFXCheckableButton, FXButton, MFXCheckableButtonMap, ARRAYNUMBER(MFXCheckableButtonMap))
36 
37 MFXCheckableButton::MFXCheckableButton(bool amChecked, FXComposite* p, MFXStaticToolTip* staticToolTip,
38  const std::string& text, FXIcon* ic, FXObject* tgt, FXSelector sel,
39  FXuint opts, FXint x, FXint y, FXint w, FXint h,
40  FXint pl, FXint pr, FXint pt, FXint pb) :
41  FXButton(p, text.c_str(), ic, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb),
42  myAmChecked(amChecked), myAmInitialised(false),
43  myStaticToolTip(staticToolTip) {
44  border = 0;
45 }
46 
47 
49 
50 
51 bool
53  return myAmChecked;
54 }
55 
56 
57 void
58 MFXCheckableButton::setChecked(bool val, const bool inform) {
59  myAmChecked = val;
60  if (inform) {
61  if (myAmChecked) {
62  FXButton::onCheck(nullptr, 0, nullptr);
63  } else {
64  FXButton::onUncheck(nullptr, 0, nullptr);
65  }
66  }
67 }
68 
69 
70 long
71 MFXCheckableButton::onPaint(FXObject* sender, FXSelector sel, void* ptr) {
72  if (!myAmInitialised) {
73  buildColors();
74  }
75  setColors();
76  return FXButton::onPaint(sender, sel, ptr);
77 }
78 
79 
80 long
81 MFXCheckableButton::onUpdate(FXObject* sender, FXSelector sel, void* ptr) {
82  if (!myAmInitialised) {
83  buildColors();
84  }
85  setColors();
86  return FXButton::onUpdate(sender, sel, ptr);
87 }
88 
89 
90 long
91 MFXCheckableButton::onEnter(FXObject* sender, FXSelector sel, void* ptr) {
92  // show tip show
93  myStaticToolTip->showStaticToolTip(getTipText());
94  return FXButton::onEnter(sender, sel, ptr);
95 }
96 
97 
98 long
99 MFXCheckableButton::onLeave(FXObject* sender, FXSelector sel, void* ptr) {
100  // hide static toolTip
102  return FXButton::onLeave(sender, sel, ptr);
103 }
104 
105 
106 long
107 MFXCheckableButton::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
108  // update static toolTip
109  myStaticToolTip->onUpdate(sender, sel, ptr);
110  return FXButton::onMotion(sender, sel, ptr);
111 }
112 
113 
114 void
116  myBackColor = backColor;
117  myDarkColor = makeShadowColor(myBackColor);
118  myHiliteColor = hiliteColor;
119  myShadowColor = shadowColor;
120  myAmInitialised = true;
121 }
122 
123 
124 void
126  options &= (0xffffffff - (FRAME_SUNKEN | FRAME_SUNKEN | FRAME_THICK));
127  if (myAmChecked) {
128  backColor = myShadowColor;
129  hiliteColor = myDarkColor;
130  shadowColor = myHiliteColor;
131  if (state == STATE_ENGAGED) {
132  options |= FRAME_SUNKEN | FRAME_THICK;
133  } else {
134  options |= FRAME_SUNKEN;
135  }
136  } else {
137  backColor = myBackColor;
138  hiliteColor = myHiliteColor;
139  shadowColor = myShadowColor;
140  if (state == STATE_ENGAGED) {
141  options |= FRAME_RAISED | FRAME_THICK;
142  } else {
143  options |= FRAME_RAISED;
144  }
145  }
146 }
147 
148 
149 /****************************************************************************/
FXDEFMAP(MFXCheckableButton) MFXCheckableButtonMap[]
void buildColors()
build color of this MFXCheckableButton
long onUpdate(FXObject *, FXSelector, void *)
called when this MFXCheckableButton is updated
FXColor myBackColor
colors of this MFXCheckableButton
void setColors()
set colors of this MFXCheckableButton
long onLeave(FXObject *, FXSelector, void *)
called when mouse leaves in MFXCheckableButton
bool amChecked() const
check if this MFXCheckableButton is checked
~MFXCheckableButton()
destructor (Called automatically)
long onPaint(FXObject *, FXSelector, void *)
bool myAmInitialised
check if this MFXCheckableButton is initialised
bool myAmChecked
FOX need this.
void setChecked(bool val, const bool inform=false)
check or uncheck this MFXCheckableButton
long onMotion(FXObject *, FXSelector, void *)
called when mouse motion in MFXCheckableButton
MFXStaticToolTip * myStaticToolTip
static tool tip
long onEnter(FXObject *, FXSelector, void *)
called when mouse enter in MFXCheckableButton
MFXStaticToolTip (based on FXToolTip)
long onUpdate(FXObject *sender, FXSelector sel, void *ptr)
called when tooltip is updated
void showStaticToolTip(const FXString &toolTipText)
show static toolTip
void hideStaticToolTip()
hide static toolTip
Definition: json.hpp:4471