Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MFXTextFieldTooltip.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// TextField similar to FXTextField but with the possibility of showing tooltips
19/****************************************************************************/
20#include <config.h>
21
22#include "MFXTextFieldTooltip.h"
23
24
25FXDEFMAP(MFXTextFieldTooltip) MFXTextFieldTooltipMap[] = {
26 FXMAPFUNC(SEL_ENTER, 0, MFXTextFieldTooltip::onEnter),
27 FXMAPFUNC(SEL_LEAVE, 0, MFXTextFieldTooltip::onLeave),
28 FXMAPFUNC(SEL_MOTION, 0, MFXTextFieldTooltip::onMotion),
29};
30
31// Object implementation
32FXIMPLEMENT(MFXTextFieldTooltip, FXTextField, MFXTextFieldTooltipMap, ARRAYNUMBER(MFXTextFieldTooltipMap))
33
34
35MFXTextFieldTooltip::MFXTextFieldTooltip(FXComposite* p, MFXStaticToolTip* staticToolTip, FXint ncols, FXObject* tgt, FXSelector sel,
36 FXuint opts, FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb) :
37 FXTextField(p, ncols, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb),
38 myStaticToolTip(staticToolTip) {
39}
40
41
43
44
45void
46MFXTextFieldTooltip::setToolTipText(const FXString& toolTip) {
47 myToolTipText = toolTip;
48}
49
50
51long
52MFXTextFieldTooltip::onEnter(FXObject* sender, FXSelector sel, void* ptr) {
53 // check if show toolTip text
54 if (!myToolTipText.empty()) {
55 // show toolTip text
56 setTipText(myToolTipText);
57 // show tip show
59 } else if (font->getTextWidth(contents.text(), contents.length()) > getWidth()) {
60 // only show tip Text if contents is bigger than textField width
61 setTipText(contents);
62 // show tip show
64 }
65 // always show help text
66 setHelpText(contents);
67 // continue with FXTextField function
68 return FXTextField::onEnter(sender, sel, ptr);
69}
70
71
72long
73MFXTextFieldTooltip::onLeave(FXObject* sender, FXSelector sel, void* ptr) {
74 // hide static toolTip
76 // continue with FXTextField function
77 return FXTextField::onLeave(sender, sel, ptr);
78}
79
80
81long
82MFXTextFieldTooltip::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
83 // update static tooltip
84 myStaticToolTip->onUpdate(sender, sel, ptr);
85 return FXTextField::onMotion(sender, sel, ptr);
86}
87
88/****************************************************************************/
FXDEFMAP(MFXTextFieldTooltip) MFXTextFieldTooltipMap[]
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
long onLeave(FXObject *, FXSelector, void *)
called when mouse leaves in MFXTextFieldTooltip
long onMotion(FXObject *, FXSelector, void *)
called when mouse motion in MFXTextFieldTooltip
MFXStaticToolTip * myStaticToolTip
FOX needs this.
FXString myToolTipText
toolTip text (if set, tooltip will be always show)
long onEnter(FXObject *, FXSelector, void *)
~MFXTextFieldTooltip()
destructor (Called automatically)
void setToolTipText(const FXString &toolTip)
set toolTip