Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/foxtools/MFXLabelTooltip.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-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 MFXLabelTooltip.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date 2022-08-10
17
///
18
// Label similar to FXLabel but with the possibility of showing tooltips
19
/****************************************************************************/
20
#include <config.h>
21
22
#include "MFXStaticToolTip.h"
23
#include "MFXLabelTooltip.h"
24
25
// ===========================================================================
26
// FOX callback mapping
27
// ===========================================================================
28
29
FXDEFMAP(MFXLabelTooltip) MFXLabelTooltipMap[] = {
30
FXMAPFUNC(SEL_PAINT, 0, MFXLabelTooltip::onPaint),
31
FXMAPFUNC(SEL_ENTER, 0, MFXLabelTooltip::onEnter),
32
FXMAPFUNC(SEL_LEAVE, 0, MFXLabelTooltip::onLeave),
33
FXMAPFUNC(SEL_MOTION, 0, MFXLabelTooltip::onMotion),
34
};
35
36
// Object implementation
37
FXIMPLEMENT(MFXLabelTooltip, FXButton, MFXLabelTooltipMap, ARRAYNUMBER(MFXLabelTooltipMap))
38
39
// ===========================================================================
40
// method definitions
41
// ===========================================================================
42
43
MFXLabelTooltip::MFXLabelTooltip(FXComposite* p, MFXStaticToolTip* staticToolTip, const FXString& text, FXIcon* ic, FXuint opts,
44
FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb) :
45
FXButton(p, text, ic, nullptr, 0, opts, x, y, w, h, pl, pr, pt, pb),
46
myStaticToolTip(staticToolTip) {
47
// to avoid select button, just disable it (we can improve this in the future)
48
disable();
49
}
50
51
52
MFXLabelTooltip::~MFXLabelTooltip() {}
53
54
55
long
56
MFXLabelTooltip::onPaint(FXObject*, FXSelector, void* ptr) {
57
FXEvent* ev = (FXEvent*)ptr;
58
FXDCWindow dc(this, ev);
59
FXint tw = 0, th = 0, iw = 0, ih = 0, tx, ty, ix, iy;
60
dc.setForeground(backColor);
61
dc.fillRectangle(0, 0, width, height);
62
if (!label.empty()) {
63
tw = labelWidth(label);
64
th = labelHeight(label);
65
}
66
if (icon) {
67
iw = icon->getWidth();
68
ih = icon->getHeight();
69
}
70
just_x(tx, ix, tw, iw);
71
just_y(ty, iy, th, ih);
72
if (icon) {
73
dc.drawIcon(icon, ix, iy);
74
}
75
if (!label.empty()) {
76
dc.setFont(font);
77
dc.setForeground(textColor);
78
drawLabel(dc, label, hotoff, tx, ty, tw, th);
79
}
80
drawFrame(dc, 0, 0, width, height);
81
return 1;
82
}
83
84
85
long
86
MFXLabelTooltip::onEnter(FXObject* sender, FXSelector sel, void* ptr) {
87
// show tip show
88
myStaticToolTip->showStaticToolTip(getTipText());
89
return FXButton::onEnter(sender, sel, ptr);
90
}
91
92
93
long
94
MFXLabelTooltip::onLeave(FXObject* sender, FXSelector sel, void* ptr) {
95
// hide static toolTip
96
myStaticToolTip->hideStaticToolTip();
97
return FXButton::onLeave(sender, sel, ptr);
98
}
99
100
101
long
102
MFXLabelTooltip::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
103
// update static tooltip
104
myStaticToolTip->onUpdate(sender, sel, ptr);
105
return FXButton::onMotion(sender, sel, ptr);
106
}
107
108
/****************************************************************************/
109
110