Path: blob/main/src/utils/foxtools/MFXCheckableButton.cpp
169678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2004-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file MFXCheckableButton.cpp14/// @author Daniel Krajzewicz15/// @date 2004-03-1916///17// missing_desc18/****************************************************************************/19#include <config.h>2021#include "MFXStaticToolTip.h"22#include "MFXCheckableButton.h"2324// ===========================================================================25// FOX callback mapping26// ===========================================================================2728FXDEFMAP(MFXCheckableButton) MFXCheckableButtonMap[] = {29FXMAPFUNC(SEL_PAINT, 0, MFXCheckableButton::onPaint),30FXMAPFUNC(SEL_UPDATE, 0, MFXCheckableButton::onUpdate),31FXMAPFUNC(SEL_ENTER, 0, MFXCheckableButton::onEnter),32FXMAPFUNC(SEL_LEAVE, 0, MFXCheckableButton::onLeave),33FXMAPFUNC(SEL_MOTION, 0, MFXCheckableButton::onMotion),34};3536// ===========================================================================37// method definitions38// ===========================================================================3940FXIMPLEMENT(MFXCheckableButton, FXButton, MFXCheckableButtonMap, ARRAYNUMBER(MFXCheckableButtonMap))4142MFXCheckableButton::MFXCheckableButton(bool amChecked, FXComposite* p, MFXStaticToolTip* staticToolTip,43const std::string& text, FXIcon* ic, FXObject* tgt, FXSelector sel,44FXuint opts, FXint x, FXint y, FXint w, FXint h,45FXint pl, FXint pr, FXint pt, FXint pb) :46FXButton(p, text.c_str(), ic, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb),47myAmChecked(amChecked), myAmInitialised(false),48myStaticToolTip(staticToolTip) {49border = 0;50}515253MFXCheckableButton::~MFXCheckableButton() {}545556bool57MFXCheckableButton::amChecked() const {58return myAmChecked;59}606162void63MFXCheckableButton::setChecked(bool val, const bool inform) {64myAmChecked = val;65if (inform) {66if (myAmChecked) {67FXButton::onCheck(nullptr, 0, nullptr);68} else {69FXButton::onUncheck(nullptr, 0, nullptr);70}71}72}737475long76MFXCheckableButton::onPaint(FXObject* sender, FXSelector sel, void* ptr) {77if (!myAmInitialised) {78buildColors();79}80setColors();81return FXButton::onPaint(sender, sel, ptr);82}838485long86MFXCheckableButton::onUpdate(FXObject* sender, FXSelector sel, void* ptr) {87if (!myAmInitialised) {88buildColors();89}90setColors();91return FXButton::onUpdate(sender, sel, ptr);92}939495long96MFXCheckableButton::onEnter(FXObject* sender, FXSelector sel, void* ptr) {97// show tip show98myStaticToolTip->showStaticToolTip(getTipText());99return FXButton::onEnter(sender, sel, ptr);100}101102103long104MFXCheckableButton::onLeave(FXObject* sender, FXSelector sel, void* ptr) {105// hide static toolTip106myStaticToolTip->hideStaticToolTip();107return FXButton::onLeave(sender, sel, ptr);108}109110111long112MFXCheckableButton::onMotion(FXObject* sender, FXSelector sel, void* ptr) {113// update static toolTip114myStaticToolTip->onUpdate(sender, sel, ptr);115return FXButton::onMotion(sender, sel, ptr);116}117118119void120MFXCheckableButton::buildColors() {121myBackColor = backColor;122myDarkColor = makeShadowColor(myBackColor);123myHiliteColor = hiliteColor;124myShadowColor = shadowColor;125myAmInitialised = true;126}127128129void130MFXCheckableButton::setColors() {131options &= (0xffffffff - (FRAME_SUNKEN | FRAME_SUNKEN | FRAME_THICK));132if (myAmChecked) {133backColor = myShadowColor;134hiliteColor = myDarkColor;135shadowColor = myHiliteColor;136if (state == STATE_ENGAGED) {137options |= FRAME_SUNKEN | FRAME_THICK;138} else {139options |= FRAME_SUNKEN;140}141} else {142backColor = myBackColor;143hiliteColor = myHiliteColor;144shadowColor = myShadowColor;145if (state == STATE_ENGAGED) {146options |= FRAME_RAISED | FRAME_THICK;147} else {148options |= FRAME_RAISED;149}150}151}152153/****************************************************************************/154155156