Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2006-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 MFXStaticToolTip.cpp
15 : /// @author Pablo Alvarez Lopez
16 : /// @date May 2022
17 : ///
18 : //
19 : /****************************************************************************/
20 :
21 : /* =========================================================================
22 : * included modules
23 : * ======================================================================= */
24 : #include <config.h>
25 :
26 : #include <utils/gui/div/GUIDesigns.h>
27 : #include <utils/gui/images/GUIIconSubSys.h>
28 : #include <utils/gui/windows/GUIAppEnum.h>
29 :
30 : #include "MFXStaticToolTip.h"
31 :
32 : // ===========================================================================
33 : // FOX callback mapping
34 : // ===========================================================================
35 :
36 : FXDEFMAP(MFXStaticToolTip) MFXStaticToolTipMap[] = {
37 : FXMAPFUNC(SEL_PAINT, 0, MFXStaticToolTip::onPaint),
38 : FXMAPFUNC(SEL_UPDATE, 0, MFXStaticToolTip::onUpdate),
39 : };
40 :
41 : // Object implementation
42 899411 : FXIMPLEMENT(MFXStaticToolTip, FXToolTip, MFXStaticToolTipMap, ARRAYNUMBER(MFXStaticToolTipMap))
43 :
44 : // ===========================================================================
45 : // method definitions
46 : // ===========================================================================
47 :
48 16060 : MFXStaticToolTip::MFXStaticToolTip(FXApp* app) :
49 16060 : FXToolTip(app) {
50 : // set empty test
51 16060 : setText("");
52 : // start hide
53 16060 : hide();
54 16060 : }
55 :
56 :
57 32016 : MFXStaticToolTip::~MFXStaticToolTip() {}
58 :
59 :
60 : void
61 22746 : MFXStaticToolTip::enableStaticToolTip(const bool value) {
62 22746 : if (value) {
63 7582 : myEnableStaticTooltip = true;
64 : } else {
65 15164 : myEnableStaticTooltip = false;
66 15164 : hideStaticToolTip();
67 : }
68 22746 : }
69 :
70 :
71 : bool
72 768689 : MFXStaticToolTip::isStaticToolTipEnabled() const {
73 768689 : return myEnableStaticTooltip;
74 : }
75 :
76 :
77 : void
78 0 : MFXStaticToolTip::showStaticToolTip(const FXString& toolTipText) {
79 0 : if (!myEnableStaticTooltip || toolTipText.empty()) {
80 0 : hideStaticToolTip();
81 : } else {
82 : // set tip text
83 0 : setText(toolTipText);
84 : // update before show (for position)
85 0 : onUpdate(nullptr, 0, nullptr);
86 : // show StaticToolTip
87 0 : show();
88 : }
89 0 : }
90 :
91 :
92 : void
93 783853 : MFXStaticToolTip::hideStaticToolTip() {
94 : // clear text
95 783853 : setText("");
96 : // hide staticTooltip
97 783853 : hide();
98 783853 : }
99 :
100 :
101 : long
102 0 : MFXStaticToolTip::onPaint(FXObject* sender, FXSelector sel, void* obj) {
103 : // draw tooltip using myToolTippedObject
104 0 : if (!label.empty() && myEnableStaticTooltip) {
105 0 : return FXToolTip::onPaint(sender, sel, obj);
106 : } else {
107 : return 0;
108 : }
109 : }
110 :
111 :
112 : long
113 867545 : MFXStaticToolTip::onUpdate(FXObject* sender, FXSelector sel, void* ptr) {
114 : // Regular GUI update
115 867545 : FXWindow::onUpdate(sender, sel, ptr);
116 : // Ask the help source for a new status text first
117 867545 : if (label.empty()) {
118 867545 : popped = FALSE;
119 867545 : hide();
120 : } else {
121 0 : popped = TRUE;
122 : FXint x, y;
123 : FXuint state;
124 0 : getRoot()->getCursorPosition(x, y, state);
125 0 : place(x, y);
126 : }
127 867545 : return 1;
128 : }
129 :
130 :
131 0 : MFXStaticToolTip::MFXStaticToolTip() :
132 0 : FXToolTip() {
133 0 : }
|