Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2006-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 : /****************************************************************************/ 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 : // =========================================================================== 34 : // FOX callback mapping 35 : // =========================================================================== 36 : 37 : FXDEFMAP(MFXStaticToolTip) MFXStaticToolTipMap[] = { 38 : FXMAPFUNC(SEL_PAINT, 0, MFXStaticToolTip::onPaint), 39 : FXMAPFUNC(SEL_UPDATE, 0, MFXStaticToolTip::onUpdate), 40 : }; 41 : 42 : // Object implementation 43 1291553 : FXIMPLEMENT(MFXStaticToolTip, FXToolTip, MFXStaticToolTipMap, ARRAYNUMBER(MFXStaticToolTipMap)) 44 : 45 : // =========================================================================== 46 : // method definitions 47 : // =========================================================================== 48 : 49 14508 : MFXStaticToolTip::MFXStaticToolTip(FXApp* app) : 50 14508 : FXToolTip(app) { 51 : // set empty test 52 14508 : setText(""); 53 : // start hide 54 14508 : hide(); 55 14508 : } 56 : 57 : 58 28948 : MFXStaticToolTip::~MFXStaticToolTip() {} 59 : 60 : 61 : void 62 20487 : MFXStaticToolTip::enableStaticToolTip(const bool value) { 63 20487 : if (value) { 64 6829 : myEnableStaticTooltip = true; 65 : } else { 66 13658 : myEnableStaticTooltip = false; 67 13658 : hideStaticToolTip(); 68 : } 69 20487 : } 70 : 71 : 72 : bool 73 555087 : MFXStaticToolTip::isStaticToolTipEnabled() const { 74 555087 : return myEnableStaticTooltip; 75 : } 76 : 77 : 78 : void 79 21 : MFXStaticToolTip::showStaticToolTip(const FXString& toolTipText) { 80 21 : if (!myEnableStaticTooltip || toolTipText.empty()) { 81 0 : hideStaticToolTip(); 82 : } else { 83 : // set tip text 84 21 : setText(toolTipText); 85 : // update before show (for position) 86 21 : onUpdate(nullptr, 0, nullptr); 87 : // show StaticToolTip 88 21 : show(); 89 : } 90 21 : } 91 : 92 : 93 : void 94 568763 : MFXStaticToolTip::hideStaticToolTip() { 95 : // clear text 96 568763 : setText(""); 97 : // hide staticTooltip 98 568763 : hide(); 99 568763 : } 100 : 101 : 102 : long 103 21 : MFXStaticToolTip::onPaint(FXObject* sender, FXSelector sel, void* obj) { 104 : // draw tooltip using myToolTippedObject 105 21 : if (!label.empty() && myEnableStaticTooltip) { 106 21 : return FXToolTip::onPaint(sender, sel, obj); 107 : } else { 108 : return 0; 109 : } 110 : } 111 : 112 : 113 : long 114 1262937 : MFXStaticToolTip::onUpdate(FXObject* sender, FXSelector sel, void* ptr) { 115 : // Regular GUI update 116 1262937 : FXWindow::onUpdate(sender, sel, ptr); 117 : // Ask the help source for a new status text first 118 1262937 : if (label.empty()) { 119 1262676 : popped = FALSE; 120 1262676 : hide(); 121 : } else { 122 261 : popped = TRUE; 123 : FXint x, y; 124 : FXuint state; 125 261 : getRoot()->getCursorPosition(x, y, state); 126 261 : place(x, y); 127 : } 128 1262937 : return 1; 129 : } 130 : 131 : 132 0 : MFXStaticToolTip::MFXStaticToolTip() : 133 0 : FXToolTip() { 134 0 : }