Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/foxtools/MFXStaticToolTip.cpp
169678 views
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
FXIMPLEMENT(MFXStaticToolTip, FXToolTip, MFXStaticToolTipMap, ARRAYNUMBER(MFXStaticToolTipMap))
43
44
// ===========================================================================
45
// method definitions
46
// ===========================================================================
47
48
MFXStaticToolTip::MFXStaticToolTip(FXApp* app) :
49
FXToolTip(app) {
50
// set empty test
51
setText("");
52
// start hide
53
hide();
54
}
55
56
57
MFXStaticToolTip::~MFXStaticToolTip() {}
58
59
60
void
61
MFXStaticToolTip::enableStaticToolTip(const bool value) {
62
if (value) {
63
myEnableStaticTooltip = true;
64
} else {
65
myEnableStaticTooltip = false;
66
hideStaticToolTip();
67
}
68
}
69
70
71
bool
72
MFXStaticToolTip::isStaticToolTipEnabled() const {
73
return myEnableStaticTooltip;
74
}
75
76
77
void
78
MFXStaticToolTip::showStaticToolTip(const FXString& toolTipText) {
79
if (!myEnableStaticTooltip || toolTipText.empty()) {
80
hideStaticToolTip();
81
} else {
82
// set tip text
83
setText(toolTipText);
84
// update before show (for position)
85
onUpdate(nullptr, 0, nullptr);
86
// show StaticToolTip
87
show();
88
}
89
}
90
91
92
void
93
MFXStaticToolTip::hideStaticToolTip() {
94
// clear text
95
setText("");
96
// hide staticTooltip
97
hide();
98
}
99
100
101
long
102
MFXStaticToolTip::onPaint(FXObject* sender, FXSelector sel, void* obj) {
103
// draw tooltip using myToolTippedObject
104
if (!label.empty() && myEnableStaticTooltip) {
105
return FXToolTip::onPaint(sender, sel, obj);
106
} else {
107
return 0;
108
}
109
}
110
111
112
long
113
MFXStaticToolTip::onUpdate(FXObject* sender, FXSelector sel, void* ptr) {
114
// Regular GUI update
115
FXWindow::onUpdate(sender, sel, ptr);
116
// Ask the help source for a new status text first
117
if (label.empty()) {
118
popped = FALSE;
119
hide();
120
} else {
121
popped = TRUE;
122
FXint x, y;
123
FXuint state;
124
getRoot()->getCursorPosition(x, y, state);
125
place(x, y);
126
}
127
return 1;
128
}
129
130
131
MFXStaticToolTip::MFXStaticToolTip() :
132
FXToolTip() {
133
}
134
135