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-05-17 15:32:44 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 "MFXCheckableButton.h"
      23              : 
      24              : 
      25              : FXDEFMAP(MFXCheckableButton) MFXCheckableButtonMap[] = {
      26              :     FXMAPFUNC(SEL_PAINT,    0,  MFXCheckableButton::onPaint),
      27              :     FXMAPFUNC(SEL_UPDATE,   0,  MFXCheckableButton::onUpdate),
      28              :     FXMAPFUNC(SEL_ENTER,    0,  MFXCheckableButton::onEnter),
      29              :     FXMAPFUNC(SEL_LEAVE,    0,  MFXCheckableButton::onLeave),
      30              :     FXMAPFUNC(SEL_MOTION,   0,  MFXCheckableButton::onMotion),
      31              : };
      32              : 
      33              : 
      34              : // Object implementation
      35      1348118 : FXIMPLEMENT(MFXCheckableButton, FXButton, MFXCheckableButtonMap, ARRAYNUMBER(MFXCheckableButtonMap))
      36              : 
      37        29440 : MFXCheckableButton::MFXCheckableButton(bool amChecked, FXComposite* p, MFXStaticToolTip* staticToolTip,
      38              :                                        const std::string& text, FXIcon* ic, FXObject* tgt, FXSelector sel,
      39              :                                        FXuint opts, FXint x, FXint y, FXint w, FXint h,
      40        29440 :                                        FXint pl, FXint pr, FXint pt, FXint pb) :
      41              :     FXButton(p, text.c_str(), ic, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb),
      42        29440 :     myAmChecked(amChecked), myAmInitialised(false),
      43        29440 :     myStaticToolTip(staticToolTip) {
      44        29440 :     border = 0;
      45        29440 : }
      46              : 
      47              : 
      48        58720 : MFXCheckableButton::~MFXCheckableButton() {}
      49              : 
      50              : 
      51              : bool
      52         7360 : MFXCheckableButton::amChecked() const {
      53         7360 :     return myAmChecked;
      54              : }
      55              : 
      56              : 
      57              : void
      58        14720 : MFXCheckableButton::setChecked(bool val, const bool inform) {
      59        14720 :     myAmChecked = val;
      60        14720 :     if (inform) {
      61            0 :         if (myAmChecked) {
      62            0 :             FXButton::onCheck(nullptr, 0, nullptr);
      63              :         } else {
      64            0 :             FXButton::onUncheck(nullptr, 0, nullptr);
      65              :         }
      66              :     }
      67        14720 : }
      68              : 
      69              : 
      70              : long
      71        59131 : MFXCheckableButton::onPaint(FXObject* sender, FXSelector sel, void* ptr) {
      72        59131 :     if (!myAmInitialised) {
      73           12 :         buildColors();
      74              :     }
      75        59131 :     setColors();
      76        59131 :     return FXButton::onPaint(sender, sel, ptr);
      77              : }
      78              : 
      79              : 
      80              : long
      81      1231074 : MFXCheckableButton::onUpdate(FXObject* sender, FXSelector sel, void* ptr) {
      82      1231074 :     if (!myAmInitialised) {
      83        29420 :         buildColors();
      84              :     }
      85      1231074 :     setColors();
      86      1231074 :     return FXButton::onUpdate(sender, sel, ptr);
      87              : }
      88              : 
      89              : 
      90              : long
      91            0 : MFXCheckableButton::onEnter(FXObject* sender, FXSelector sel, void* ptr) {
      92              :     // show tip show
      93            0 :     myStaticToolTip->showStaticToolTip(getTipText());
      94            0 :     return FXButton::onEnter(sender, sel, ptr);
      95              : }
      96              : 
      97              : 
      98              : long
      99            0 : MFXCheckableButton::onLeave(FXObject* sender, FXSelector sel, void* ptr) {
     100              :     // hide static toolTip
     101            0 :     myStaticToolTip->hideStaticToolTip();
     102            0 :     return FXButton::onLeave(sender, sel, ptr);
     103              : }
     104              : 
     105              : 
     106              : long
     107            0 : MFXCheckableButton::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
     108              :     // update static toolTip
     109            0 :     myStaticToolTip->onUpdate(sender, sel, ptr);
     110            0 :     return FXButton::onMotion(sender, sel, ptr);
     111              : }
     112              : 
     113              : 
     114              : void
     115        29432 : MFXCheckableButton::buildColors() {
     116        29432 :     myBackColor = backColor;
     117        29432 :     myDarkColor = makeShadowColor(myBackColor);
     118        29432 :     myHiliteColor = hiliteColor;
     119        29432 :     myShadowColor = shadowColor;
     120        29432 :     myAmInitialised = true;
     121        29432 : }
     122              : 
     123              : 
     124              : void
     125      1290205 : MFXCheckableButton::setColors() {
     126      1290205 :     options &= (0xffffffff - (FRAME_SUNKEN | FRAME_SUNKEN | FRAME_THICK));
     127      1290205 :     if (myAmChecked) {
     128       644533 :         backColor = myShadowColor;
     129       644533 :         hiliteColor = myDarkColor;
     130       644533 :         shadowColor = myHiliteColor;
     131       644533 :         if (state == STATE_ENGAGED) {
     132            0 :             options |= FRAME_SUNKEN | FRAME_THICK;
     133              :         } else {
     134       644533 :             options |= FRAME_SUNKEN;
     135              :         }
     136              :     } else {
     137       645672 :         backColor = myBackColor;
     138       645672 :         hiliteColor = myHiliteColor;
     139       645672 :         shadowColor = myShadowColor;
     140       645672 :         if (state == STATE_ENGAGED) {
     141            0 :             options |= FRAME_RAISED | FRAME_THICK;
     142              :         } else {
     143       645672 :             options |= FRAME_RAISED;
     144              :         }
     145              :     }
     146      1290205 : }
     147              : 
     148              : 
     149              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1