LCOV - code coverage report
Current view: top level - src/utils/foxtools - MFXCheckableButton.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 45 59 76.3 %
Date: 2024-04-27 15:34:54 Functions: 10 14 71.4 %

          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     2612966 : FXIMPLEMENT(MFXCheckableButton, FXButton, MFXCheckableButtonMap, ARRAYNUMBER(MFXCheckableButtonMap))
      36             : 
      37       27316 : 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       27316 :                                        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       27316 :     myAmChecked(amChecked), myAmInitialised(false),
      43       27316 :     myStaticToolTip(staticToolTip) {
      44       27316 :     border = 0;
      45       27316 : }
      46             : 
      47             : 
      48       54496 : MFXCheckableButton::~MFXCheckableButton() {}
      49             : 
      50             : 
      51             : bool
      52        6829 : MFXCheckableButton::amChecked() const {
      53        6829 :     return myAmChecked;
      54             : }
      55             : 
      56             : 
      57             : void
      58       13658 : MFXCheckableButton::setChecked(bool val, const bool inform) {
      59       13658 :     myAmChecked = val;
      60       13658 :     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       13658 : }
      68             : 
      69             : 
      70             : long
      71       54210 : MFXCheckableButton::onPaint(FXObject* sender, FXSelector sel, void* ptr) {
      72       54210 :     if (!myAmInitialised) {
      73          28 :         buildColors();
      74             :     }
      75       54210 :     setColors();
      76       54210 :     return FXButton::onPaint(sender, sel, ptr);
      77             : }
      78             : 
      79             : 
      80             : long
      81     2505800 : MFXCheckableButton::onUpdate(FXObject* sender, FXSelector sel, void* ptr) {
      82     2505800 :     if (!myAmInitialised) {
      83       27284 :         buildColors();
      84             :     }
      85     2505800 :     setColors();
      86     2505800 :     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       27312 : MFXCheckableButton::buildColors() {
     116       27312 :     myBackColor = backColor;
     117       27312 :     myDarkColor = makeShadowColor(myBackColor);
     118       27312 :     myHiliteColor = hiliteColor;
     119       27312 :     myShadowColor = shadowColor;
     120       27312 :     myAmInitialised = true;
     121       27312 : }
     122             : 
     123             : 
     124             : void
     125     2560010 : MFXCheckableButton::setColors() {
     126     2560010 :     options &= (0xffffffff - (FRAME_SUNKEN | FRAME_SUNKEN | FRAME_THICK));
     127     2560010 :     if (myAmChecked) {
     128     1279335 :         backColor = myShadowColor;
     129     1279335 :         hiliteColor = myDarkColor;
     130     1279335 :         shadowColor = myHiliteColor;
     131     1279335 :         if (state == STATE_ENGAGED) {
     132           0 :             options |= FRAME_SUNKEN | FRAME_THICK;
     133             :         } else {
     134     1279335 :             options |= FRAME_SUNKEN;
     135             :         }
     136             :     } else {
     137     1280675 :         backColor = myBackColor;
     138     1280675 :         hiliteColor = myHiliteColor;
     139     1280675 :         shadowColor = myShadowColor;
     140     1280675 :         if (state == STATE_ENGAGED) {
     141           0 :             options |= FRAME_RAISED | FRAME_THICK;
     142             :         } else {
     143     1280675 :             options |= FRAME_RAISED;
     144             :         }
     145             :     }
     146     2560010 : }
     147             : 
     148             : 
     149             : /****************************************************************************/

Generated by: LCOV version 1.14