LCOV - code coverage report
Current view: top level - src/utils/foxtools - MFXLabelTooltip.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 71.4 % 35 25
Test Date: 2025-12-06 15:35:27 Functions: 55.6 % 9 5

            Line data    Source code
       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       458897 : FXIMPLEMENT(MFXLabelTooltip, FXButton, MFXLabelTooltipMap, ARRAYNUMBER(MFXLabelTooltipMap))
      38              : 
      39              : // ===========================================================================
      40              : // method definitions
      41              : // ===========================================================================
      42              : 
      43         8030 : MFXLabelTooltip::MFXLabelTooltip(FXComposite* p, MFXStaticToolTip* staticToolTip, const FXString& text, FXIcon* ic, FXuint opts,
      44         8030 :                                  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         8030 :     myStaticToolTip(staticToolTip) {
      47              :     // to avoid select button, just disable it (we can improve this in the future)
      48         8030 :     disable();
      49         8030 : }
      50              : 
      51              : 
      52        16008 : MFXLabelTooltip::~MFXLabelTooltip() {}
      53              : 
      54              : 
      55              : long
      56         7960 : MFXLabelTooltip::onPaint(FXObject*, FXSelector, void* ptr) {
      57              :     FXEvent* ev = (FXEvent*)ptr;
      58         7960 :     FXDCWindow dc(this, ev);
      59              :     FXint tw = 0, th = 0, iw = 0, ih = 0, tx, ty, ix, iy;
      60         7960 :     dc.setForeground(backColor);
      61         7960 :     dc.fillRectangle(0, 0, width, height);
      62         7960 :     if (!label.empty()) {
      63         7960 :         tw = labelWidth(label);
      64         7960 :         th = labelHeight(label);
      65              :     }
      66         7960 :     if (icon) {
      67              :         iw = icon->getWidth();
      68              :         ih = icon->getHeight();
      69              :     }
      70         7960 :     just_x(tx, ix, tw, iw);
      71         7960 :     just_y(ty, iy, th, ih);
      72         7960 :     if (icon) {
      73            0 :         dc.drawIcon(icon, ix, iy);
      74              :     }
      75         7960 :     if (!label.empty()) {
      76         7960 :         dc.setFont(font);
      77         7960 :         dc.setForeground(textColor);
      78         7960 :         drawLabel(dc, label, hotoff, tx, ty, tw, th);
      79              :     }
      80         7960 :     drawFrame(dc, 0, 0, width, height);
      81         7960 :     return 1;
      82         7960 : }
      83              : 
      84              : 
      85              : long
      86            0 : MFXLabelTooltip::onEnter(FXObject* sender, FXSelector sel, void* ptr) {
      87              :     // show tip show
      88            0 :     myStaticToolTip->showStaticToolTip(getTipText());
      89            0 :     return FXButton::onEnter(sender, sel, ptr);
      90              : }
      91              : 
      92              : 
      93              : long
      94            0 : MFXLabelTooltip::onLeave(FXObject* sender, FXSelector sel, void* ptr) {
      95              :     // hide static toolTip
      96            0 :     myStaticToolTip->hideStaticToolTip();
      97            0 :     return FXButton::onLeave(sender, sel, ptr);
      98              : }
      99              : 
     100              : 
     101              : long
     102            0 : MFXLabelTooltip::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
     103              :     // update static tooltip
     104            0 :     myStaticToolTip->onUpdate(sender, sel, ptr);
     105            0 :     return FXButton::onMotion(sender, sel, ptr);
     106              : }
     107              : 
     108              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1