LCOV - code coverage report
Current view: top level - src/utils/foxtools - MFXCheckableButton.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 76.3 % 59 45
Test Date: 2025-11-13 15:38:19 Functions: 71.4 % 14 10

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2004-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    MFXCheckableButton.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @date    2004-03-19
      17              : ///
      18              : // missing_desc
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #include "MFXStaticToolTip.h"
      23              : #include "MFXCheckableButton.h"
      24              : 
      25              : // ===========================================================================
      26              : // FOX callback mapping
      27              : // ===========================================================================
      28              : 
      29              : FXDEFMAP(MFXCheckableButton) MFXCheckableButtonMap[] = {
      30              :     FXMAPFUNC(SEL_PAINT,    0,  MFXCheckableButton::onPaint),
      31              :     FXMAPFUNC(SEL_UPDATE,   0,  MFXCheckableButton::onUpdate),
      32              :     FXMAPFUNC(SEL_ENTER,    0,  MFXCheckableButton::onEnter),
      33              :     FXMAPFUNC(SEL_LEAVE,    0,  MFXCheckableButton::onLeave),
      34              :     FXMAPFUNC(SEL_MOTION,   0,  MFXCheckableButton::onMotion),
      35              : };
      36              : 
      37              : // ===========================================================================
      38              : // method definitions
      39              : // ===========================================================================
      40              : 
      41      1299869 : FXIMPLEMENT(MFXCheckableButton, FXButton, MFXCheckableButtonMap, ARRAYNUMBER(MFXCheckableButtonMap))
      42              : 
      43        30192 : MFXCheckableButton::MFXCheckableButton(bool amChecked, FXComposite* p, MFXStaticToolTip* staticToolTip,
      44              :                                        const std::string& text, FXIcon* ic, FXObject* tgt, FXSelector sel,
      45              :                                        FXuint opts, FXint x, FXint y, FXint w, FXint h,
      46        30192 :                                        FXint pl, FXint pr, FXint pt, FXint pb) :
      47              :     FXButton(p, text.c_str(), ic, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb),
      48        30192 :     myAmChecked(amChecked), myAmInitialised(false),
      49        30192 :     myStaticToolTip(staticToolTip) {
      50        30192 :     border = 0;
      51        30192 : }
      52              : 
      53              : 
      54        60248 : MFXCheckableButton::~MFXCheckableButton() {}
      55              : 
      56              : 
      57              : bool
      58         7548 : MFXCheckableButton::amChecked() const {
      59         7548 :     return myAmChecked;
      60              : }
      61              : 
      62              : 
      63              : void
      64        15096 : MFXCheckableButton::setChecked(bool val, const bool inform) {
      65        15096 :     myAmChecked = val;
      66        15096 :     if (inform) {
      67            0 :         if (myAmChecked) {
      68            0 :             FXButton::onCheck(nullptr, 0, nullptr);
      69              :         } else {
      70            0 :             FXButton::onUncheck(nullptr, 0, nullptr);
      71              :         }
      72              :     }
      73        15096 : }
      74              : 
      75              : 
      76              : long
      77        61354 : MFXCheckableButton::onPaint(FXObject* sender, FXSelector sel, void* ptr) {
      78        61354 :     if (!myAmInitialised) {
      79            4 :         buildColors();
      80              :     }
      81        61354 :     setColors();
      82        61354 :     return FXButton::onPaint(sender, sel, ptr);
      83              : }
      84              : 
      85              : 
      86              : long
      87      1178851 : MFXCheckableButton::onUpdate(FXObject* sender, FXSelector sel, void* ptr) {
      88      1178851 :     if (!myAmInitialised) {
      89        30184 :         buildColors();
      90              :     }
      91      1178851 :     setColors();
      92      1178851 :     return FXButton::onUpdate(sender, sel, ptr);
      93              : }
      94              : 
      95              : 
      96              : long
      97            0 : MFXCheckableButton::onEnter(FXObject* sender, FXSelector sel, void* ptr) {
      98              :     // show tip show
      99            0 :     myStaticToolTip->showStaticToolTip(getTipText());
     100            0 :     return FXButton::onEnter(sender, sel, ptr);
     101              : }
     102              : 
     103              : 
     104              : long
     105            0 : MFXCheckableButton::onLeave(FXObject* sender, FXSelector sel, void* ptr) {
     106              :     // hide static toolTip
     107            0 :     myStaticToolTip->hideStaticToolTip();
     108            0 :     return FXButton::onLeave(sender, sel, ptr);
     109              : }
     110              : 
     111              : 
     112              : long
     113            0 : MFXCheckableButton::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
     114              :     // update static toolTip
     115            0 :     myStaticToolTip->onUpdate(sender, sel, ptr);
     116            0 :     return FXButton::onMotion(sender, sel, ptr);
     117              : }
     118              : 
     119              : 
     120              : void
     121        30188 : MFXCheckableButton::buildColors() {
     122        30188 :     myBackColor = backColor;
     123        30188 :     myDarkColor = makeShadowColor(myBackColor);
     124        30188 :     myHiliteColor = hiliteColor;
     125        30188 :     myShadowColor = shadowColor;
     126        30188 :     myAmInitialised = true;
     127        30188 : }
     128              : 
     129              : 
     130              : void
     131      1240205 : MFXCheckableButton::setColors() {
     132      1240205 :     options &= (0xffffffff - (FRAME_SUNKEN | FRAME_SUNKEN | FRAME_THICK));
     133      1240205 :     if (myAmChecked) {
     134       619228 :         backColor = myShadowColor;
     135       619228 :         hiliteColor = myDarkColor;
     136       619228 :         shadowColor = myHiliteColor;
     137       619228 :         if (state == STATE_ENGAGED) {
     138            0 :             options |= FRAME_SUNKEN | FRAME_THICK;
     139              :         } else {
     140       619228 :             options |= FRAME_SUNKEN;
     141              :         }
     142              :     } else {
     143       620977 :         backColor = myBackColor;
     144       620977 :         hiliteColor = myHiliteColor;
     145       620977 :         shadowColor = myShadowColor;
     146       620977 :         if (state == STATE_ENGAGED) {
     147            0 :             options |= FRAME_RAISED | FRAME_THICK;
     148              :         } else {
     149       620977 :             options |= FRAME_RAISED;
     150              :         }
     151              :     }
     152      1240205 : }
     153              : 
     154              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1