Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/foxtools/MFXCheckableButton.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2004-2025 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
/****************************************************************************/
14
/// @file MFXCheckableButton.cpp
15
/// @author Daniel Krajzewicz
16
/// @date 2004-03-19
17
///
18
// missing_desc
19
/****************************************************************************/
20
#include <config.h>
21
22
#include "MFXStaticToolTip.h"
23
#include "MFXCheckableButton.h"
24
25
// ===========================================================================
26
// FOX callback mapping
27
// ===========================================================================
28
29
FXDEFMAP(MFXCheckableButton) MFXCheckableButtonMap[] = {
30
FXMAPFUNC(SEL_PAINT, 0, MFXCheckableButton::onPaint),
31
FXMAPFUNC(SEL_UPDATE, 0, MFXCheckableButton::onUpdate),
32
FXMAPFUNC(SEL_ENTER, 0, MFXCheckableButton::onEnter),
33
FXMAPFUNC(SEL_LEAVE, 0, MFXCheckableButton::onLeave),
34
FXMAPFUNC(SEL_MOTION, 0, MFXCheckableButton::onMotion),
35
};
36
37
// ===========================================================================
38
// method definitions
39
// ===========================================================================
40
41
FXIMPLEMENT(MFXCheckableButton, FXButton, MFXCheckableButtonMap, ARRAYNUMBER(MFXCheckableButtonMap))
42
43
MFXCheckableButton::MFXCheckableButton(bool amChecked, FXComposite* p, MFXStaticToolTip* staticToolTip,
44
const std::string& text, FXIcon* ic, FXObject* tgt, FXSelector sel,
45
FXuint opts, FXint x, FXint y, FXint w, FXint h,
46
FXint pl, FXint pr, FXint pt, FXint pb) :
47
FXButton(p, text.c_str(), ic, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb),
48
myAmChecked(amChecked), myAmInitialised(false),
49
myStaticToolTip(staticToolTip) {
50
border = 0;
51
}
52
53
54
MFXCheckableButton::~MFXCheckableButton() {}
55
56
57
bool
58
MFXCheckableButton::amChecked() const {
59
return myAmChecked;
60
}
61
62
63
void
64
MFXCheckableButton::setChecked(bool val, const bool inform) {
65
myAmChecked = val;
66
if (inform) {
67
if (myAmChecked) {
68
FXButton::onCheck(nullptr, 0, nullptr);
69
} else {
70
FXButton::onUncheck(nullptr, 0, nullptr);
71
}
72
}
73
}
74
75
76
long
77
MFXCheckableButton::onPaint(FXObject* sender, FXSelector sel, void* ptr) {
78
if (!myAmInitialised) {
79
buildColors();
80
}
81
setColors();
82
return FXButton::onPaint(sender, sel, ptr);
83
}
84
85
86
long
87
MFXCheckableButton::onUpdate(FXObject* sender, FXSelector sel, void* ptr) {
88
if (!myAmInitialised) {
89
buildColors();
90
}
91
setColors();
92
return FXButton::onUpdate(sender, sel, ptr);
93
}
94
95
96
long
97
MFXCheckableButton::onEnter(FXObject* sender, FXSelector sel, void* ptr) {
98
// show tip show
99
myStaticToolTip->showStaticToolTip(getTipText());
100
return FXButton::onEnter(sender, sel, ptr);
101
}
102
103
104
long
105
MFXCheckableButton::onLeave(FXObject* sender, FXSelector sel, void* ptr) {
106
// hide static toolTip
107
myStaticToolTip->hideStaticToolTip();
108
return FXButton::onLeave(sender, sel, ptr);
109
}
110
111
112
long
113
MFXCheckableButton::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
114
// update static toolTip
115
myStaticToolTip->onUpdate(sender, sel, ptr);
116
return FXButton::onMotion(sender, sel, ptr);
117
}
118
119
120
void
121
MFXCheckableButton::buildColors() {
122
myBackColor = backColor;
123
myDarkColor = makeShadowColor(myBackColor);
124
myHiliteColor = hiliteColor;
125
myShadowColor = shadowColor;
126
myAmInitialised = true;
127
}
128
129
130
void
131
MFXCheckableButton::setColors() {
132
options &= (0xffffffff - (FRAME_SUNKEN | FRAME_SUNKEN | FRAME_THICK));
133
if (myAmChecked) {
134
backColor = myShadowColor;
135
hiliteColor = myDarkColor;
136
shadowColor = myHiliteColor;
137
if (state == STATE_ENGAGED) {
138
options |= FRAME_SUNKEN | FRAME_THICK;
139
} else {
140
options |= FRAME_SUNKEN;
141
}
142
} else {
143
backColor = myBackColor;
144
hiliteColor = myHiliteColor;
145
shadowColor = myShadowColor;
146
if (state == STATE_ENGAGED) {
147
options |= FRAME_RAISED | FRAME_THICK;
148
} else {
149
options |= FRAME_RAISED;
150
}
151
}
152
}
153
154
/****************************************************************************/
155
156