/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file MFXLabelTooltip.cpp14/// @author Pablo Alvarez Lopez15/// @date 2022-08-1016///17// Label similar to FXLabel but with the possibility of showing tooltips18/****************************************************************************/19#include <config.h>2021#include "MFXStaticToolTip.h"22#include "MFXLabelTooltip.h"2324// ===========================================================================25// FOX callback mapping26// ===========================================================================2728FXDEFMAP(MFXLabelTooltip) MFXLabelTooltipMap[] = {29FXMAPFUNC(SEL_PAINT, 0, MFXLabelTooltip::onPaint),30FXMAPFUNC(SEL_ENTER, 0, MFXLabelTooltip::onEnter),31FXMAPFUNC(SEL_LEAVE, 0, MFXLabelTooltip::onLeave),32FXMAPFUNC(SEL_MOTION, 0, MFXLabelTooltip::onMotion),33};3435// Object implementation36FXIMPLEMENT(MFXLabelTooltip, FXButton, MFXLabelTooltipMap, ARRAYNUMBER(MFXLabelTooltipMap))3738// ===========================================================================39// method definitions40// ===========================================================================4142MFXLabelTooltip::MFXLabelTooltip(FXComposite* p, MFXStaticToolTip* staticToolTip, const FXString& text, FXIcon* ic, FXuint opts,43FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb) :44FXButton(p, text, ic, nullptr, 0, opts, x, y, w, h, pl, pr, pt, pb),45myStaticToolTip(staticToolTip) {46// to avoid select button, just disable it (we can improve this in the future)47disable();48}495051MFXLabelTooltip::~MFXLabelTooltip() {}525354long55MFXLabelTooltip::onPaint(FXObject*, FXSelector, void* ptr) {56FXEvent* ev = (FXEvent*)ptr;57FXDCWindow dc(this, ev);58FXint tw = 0, th = 0, iw = 0, ih = 0, tx, ty, ix, iy;59dc.setForeground(backColor);60dc.fillRectangle(0, 0, width, height);61if (!label.empty()) {62tw = labelWidth(label);63th = labelHeight(label);64}65if (icon) {66iw = icon->getWidth();67ih = icon->getHeight();68}69just_x(tx, ix, tw, iw);70just_y(ty, iy, th, ih);71if (icon) {72dc.drawIcon(icon, ix, iy);73}74if (!label.empty()) {75dc.setFont(font);76dc.setForeground(textColor);77drawLabel(dc, label, hotoff, tx, ty, tw, th);78}79drawFrame(dc, 0, 0, width, height);80return 1;81}828384long85MFXLabelTooltip::onEnter(FXObject* sender, FXSelector sel, void* ptr) {86// show tip show87myStaticToolTip->showStaticToolTip(getTipText());88return FXButton::onEnter(sender, sel, ptr);89}909192long93MFXLabelTooltip::onLeave(FXObject* sender, FXSelector sel, void* ptr) {94// hide static toolTip95myStaticToolTip->hideStaticToolTip();96return FXButton::onLeave(sender, sel, ptr);97}9899100long101MFXLabelTooltip::onMotion(FXObject* sender, FXSelector sel, void* ptr) {102// update static tooltip103myStaticToolTip->onUpdate(sender, sel, ptr);104return FXButton::onMotion(sender, sel, ptr);105}106107/****************************************************************************/108109110