Eclipse SUMO - Simulation of Urban MObility
MFXLabelTooltip.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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 /****************************************************************************/
18 // Label similar to FXLabel but with the possibility of showing tooltips
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include "MFXLabelTooltip.h"
23 
24 
25 FXDEFMAP(MFXLabelTooltip) MFXLabelTooltipMap[] = {
26  FXMAPFUNC(SEL_PAINT, 0, MFXLabelTooltip::onPaint),
27  FXMAPFUNC(SEL_ENTER, 0, MFXLabelTooltip::onEnter),
28  FXMAPFUNC(SEL_LEAVE, 0, MFXLabelTooltip::onLeave),
29  FXMAPFUNC(SEL_MOTION, 0, MFXLabelTooltip::onMotion),
30 };
31 
32 // Object implementation
33 FXIMPLEMENT(MFXLabelTooltip, FXButton, MFXLabelTooltipMap, ARRAYNUMBER(MFXLabelTooltipMap))
34 
35 
36 MFXLabelTooltip::MFXLabelTooltip(FXComposite* p, MFXStaticToolTip* staticToolTip, const FXString& text, FXIcon* ic, FXuint opts,
37  FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb) :
38  FXButton(p, text, ic, nullptr, 0, opts, x, y, w, h, pl, pr, pt, pb),
39  myStaticToolTip(staticToolTip) {
40  // to avoid select button, just disable it (we can improve this in the future)
41  disable();
42 }
43 
44 
46 
47 
48 long
49 MFXLabelTooltip::onPaint(FXObject*, FXSelector, void* ptr) {
50  FXEvent* ev = (FXEvent*)ptr;
51  FXDCWindow dc(this, ev);
52  FXint tw = 0, th = 0, iw = 0, ih = 0, tx, ty, ix, iy;
53  dc.setForeground(backColor);
54  dc.fillRectangle(0, 0, width, height);
55  if (!label.empty()) {
56  tw = labelWidth(label);
57  th = labelHeight(label);
58  }
59  if (icon) {
60  iw = icon->getWidth();
61  ih = icon->getHeight();
62  }
63  just_x(tx, ix, tw, iw);
64  just_y(ty, iy, th, ih);
65  if (icon) {
66  dc.drawIcon(icon, ix, iy);
67  }
68  if (!label.empty()) {
69  dc.setFont(font);
70  dc.setForeground(textColor);
71  drawLabel(dc, label, hotoff, tx, ty, tw, th);
72  }
73  drawFrame(dc, 0, 0, width, height);
74  return 1;
75 }
76 
77 
78 long
79 MFXLabelTooltip::onEnter(FXObject* sender, FXSelector sel, void* ptr) {
80  // show tip show
81  myStaticToolTip->showStaticToolTip(getTipText());
82  return FXButton::onEnter(sender, sel, ptr);
83 }
84 
85 
86 long
87 MFXLabelTooltip::onLeave(FXObject* sender, FXSelector sel, void* ptr) {
88  // hide static toolTip
90  return FXButton::onLeave(sender, sel, ptr);
91 }
92 
93 
94 long
95 MFXLabelTooltip::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
96  // update static tooltip
97  myStaticToolTip->onUpdate(sender, sel, ptr);
98  return FXButton::onMotion(sender, sel, ptr);
99 }
100 
101 /****************************************************************************/
FXDEFMAP(MFXLabelTooltip) MFXLabelTooltipMap[]
long onLeave(FXObject *, FXSelector, void *)
called when mouse leaves in MFXLabelTooltip
long onMotion(FXObject *, FXSelector, void *)
called when mouse motion in MFXLabelTooltip
MFXStaticToolTip * myStaticToolTip
FOX needs this.
long onPaint(FXObject *, FXSelector, void *)
long onEnter(FXObject *, FXSelector, void *)
called when mouse enter in MFXLabelTooltip
~MFXLabelTooltip()
destructor (Called automatically)
MFXStaticToolTip (based on FXToolTip)
long onUpdate(FXObject *sender, FXSelector sel, void *ptr)
called when tooltip is updated
void showStaticToolTip(const FXString &toolTipText)
show static toolTip
void hideStaticToolTip()
hide static toolTip