Line data Source code
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 1831430 : FXIMPLEMENT(MFXCheckableButton, FXButton, MFXCheckableButtonMap, ARRAYNUMBER(MFXCheckableButtonMap))
42 :
43 30328 : 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 30328 : 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 30328 : myAmChecked(amChecked), myAmInitialised(false),
49 30328 : myStaticToolTip(staticToolTip) {
50 30328 : border = 0;
51 30328 : }
52 :
53 :
54 60448 : MFXCheckableButton::~MFXCheckableButton() {}
55 :
56 :
57 : bool
58 7582 : MFXCheckableButton::amChecked() const {
59 7582 : return myAmChecked;
60 : }
61 :
62 :
63 : void
64 15164 : MFXCheckableButton::setChecked(bool val, const bool inform) {
65 15164 : myAmChecked = val;
66 15164 : if (inform) {
67 0 : if (myAmChecked) {
68 0 : FXButton::onCheck(nullptr, 0, nullptr);
69 : } else {
70 0 : FXButton::onUncheck(nullptr, 0, nullptr);
71 : }
72 : }
73 15164 : }
74 :
75 :
76 : long
77 60692 : MFXCheckableButton::onPaint(FXObject* sender, FXSelector sel, void* ptr) {
78 60692 : if (!myAmInitialised) {
79 12 : buildColors();
80 : }
81 60692 : setColors();
82 60692 : return FXButton::onPaint(sender, sel, ptr);
83 : }
84 :
85 :
86 : long
87 1710710 : MFXCheckableButton::onUpdate(FXObject* sender, FXSelector sel, void* ptr) {
88 1710710 : if (!myAmInitialised) {
89 30312 : buildColors();
90 : }
91 1710710 : setColors();
92 1710710 : return FXButton::onUpdate(sender, sel, ptr);
93 : }
94 :
95 :
96 : long
97 0 : MFXCheckableButton::onEnter(FXObject* sender, FXSelector sel, void* ptr) {
98 : // show tip show
99 0 : myStaticToolTip->showStaticToolTip(getTipText());
100 0 : return FXButton::onEnter(sender, sel, ptr);
101 : }
102 :
103 :
104 : long
105 0 : MFXCheckableButton::onLeave(FXObject* sender, FXSelector sel, void* ptr) {
106 : // hide static toolTip
107 0 : myStaticToolTip->hideStaticToolTip();
108 0 : return FXButton::onLeave(sender, sel, ptr);
109 : }
110 :
111 :
112 : long
113 0 : MFXCheckableButton::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
114 : // update static toolTip
115 0 : myStaticToolTip->onUpdate(sender, sel, ptr);
116 0 : return FXButton::onMotion(sender, sel, ptr);
117 : }
118 :
119 :
120 : void
121 30324 : MFXCheckableButton::buildColors() {
122 30324 : myBackColor = backColor;
123 30324 : myDarkColor = makeShadowColor(myBackColor);
124 30324 : myHiliteColor = hiliteColor;
125 30324 : myShadowColor = shadowColor;
126 30324 : myAmInitialised = true;
127 30324 : }
128 :
129 :
130 : void
131 1771402 : MFXCheckableButton::setColors() {
132 1771402 : options &= (0xffffffff - (FRAME_SUNKEN | FRAME_SUNKEN | FRAME_THICK));
133 1771402 : if (myAmChecked) {
134 885379 : backColor = myShadowColor;
135 885379 : hiliteColor = myDarkColor;
136 885379 : shadowColor = myHiliteColor;
137 885379 : if (state == STATE_ENGAGED) {
138 0 : options |= FRAME_SUNKEN | FRAME_THICK;
139 : } else {
140 885379 : options |= FRAME_SUNKEN;
141 : }
142 : } else {
143 886023 : backColor = myBackColor;
144 886023 : hiliteColor = myHiliteColor;
145 886023 : shadowColor = myShadowColor;
146 886023 : if (state == STATE_ENGAGED) {
147 0 : options |= FRAME_RAISED | FRAME_THICK;
148 : } else {
149 886023 : options |= FRAME_RAISED;
150 : }
151 : }
152 1771402 : }
153 :
154 : /****************************************************************************/
|