LCOV - code coverage report
Current view: top level - src/utils/foxtools - MFXCheckableButton.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 74.6 % 59 44
Test Date: 2024-11-22 15:46:21 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-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    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      2363328 : FXIMPLEMENT(MFXCheckableButton, FXButton, MFXCheckableButtonMap, ARRAYNUMBER(MFXCheckableButtonMap))
      36              : 
      37        28424 : 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        28424 :                                        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        28424 :     myAmChecked(amChecked), myAmInitialised(false),
      43        28424 :     myStaticToolTip(staticToolTip) {
      44        28424 :     border = 0;
      45        28424 : }
      46              : 
      47              : 
      48        56744 : MFXCheckableButton::~MFXCheckableButton() {}
      49              : 
      50              : 
      51              : bool
      52         7106 : MFXCheckableButton::amChecked() const {
      53         7106 :     return myAmChecked;
      54              : }
      55              : 
      56              : 
      57              : void
      58        14212 : MFXCheckableButton::setChecked(bool val, const bool inform) {
      59        14212 :     myAmChecked = val;
      60        14212 :     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        14212 : }
      68              : 
      69              : 
      70              : long
      71        56690 : MFXCheckableButton::onPaint(FXObject* sender, FXSelector sel, void* ptr) {
      72        56690 :     if (!myAmInitialised) {
      73            0 :         buildColors();
      74              :     }
      75        56690 :     setColors();
      76        56690 :     return FXButton::onPaint(sender, sel, ptr);
      77              : }
      78              : 
      79              : 
      80              : long
      81      2251063 : MFXCheckableButton::onUpdate(FXObject* sender, FXSelector sel, void* ptr) {
      82      2251063 :     if (!myAmInitialised) {
      83        28424 :         buildColors();
      84              :     }
      85      2251063 :     setColors();
      86      2251063 :     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        28424 : MFXCheckableButton::buildColors() {
     116        28424 :     myBackColor = backColor;
     117        28424 :     myDarkColor = makeShadowColor(myBackColor);
     118        28424 :     myHiliteColor = hiliteColor;
     119        28424 :     myShadowColor = shadowColor;
     120        28424 :     myAmInitialised = true;
     121        28424 : }
     122              : 
     123              : 
     124              : void
     125      2307753 : MFXCheckableButton::setColors() {
     126      2307753 :     options &= (0xffffffff - (FRAME_SUNKEN | FRAME_SUNKEN | FRAME_THICK));
     127      2307753 :     if (myAmChecked) {
     128      1153253 :         backColor = myShadowColor;
     129      1153253 :         hiliteColor = myDarkColor;
     130      1153253 :         shadowColor = myHiliteColor;
     131      1153253 :         if (state == STATE_ENGAGED) {
     132            0 :             options |= FRAME_SUNKEN | FRAME_THICK;
     133              :         } else {
     134      1153253 :             options |= FRAME_SUNKEN;
     135              :         }
     136              :     } else {
     137      1154500 :         backColor = myBackColor;
     138      1154500 :         hiliteColor = myHiliteColor;
     139      1154500 :         shadowColor = myShadowColor;
     140      1154500 :         if (state == STATE_ENGAGED) {
     141            0 :             options |= FRAME_RAISED | FRAME_THICK;
     142              :         } else {
     143      1154500 :             options |= FRAME_RAISED;
     144              :         }
     145              :     }
     146      2307753 : }
     147              : 
     148              : 
     149              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1