Eclipse SUMO - Simulation of Urban MObility
FXGroupBoxModule.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2006-2022 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 /****************************************************************************/
18 //
19 /****************************************************************************/
20 
21 /* =========================================================================
22  * included modules
23  * ======================================================================= */
24 #include <config.h>
25 
29 
30 #include "FXGroupBoxModule.h"
31 
32 
33 // ===========================================================================
34 // FOX callback mapping
35 // ===========================================================================
36 
37 FXDEFMAP(FXGroupBoxModule) FXGroupBoxModuleMap[] = {
38  FXMAPFUNC(SEL_PAINT, 0, FXGroupBoxModule::onPaint),
42 };
43 
44 // Object implementation
45 FXIMPLEMENT(FXGroupBoxModule, FXVerticalFrame, FXGroupBoxModuleMap, ARRAYNUMBER(FXGroupBoxModuleMap))
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 
51 FXGroupBoxModule::FXGroupBoxModule(FXVerticalFrame* contentFrame, const std::string& text, const int options) :
52  FXVerticalFrame(contentFrame, GUIDesignHorizontalFrame),
53  myOptions(options),
54  myCollapsed(false) {
55  // build button and labels
56  FXHorizontalFrame* headerFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
57  if (myOptions & Options::COLLAPSIBLE) {
58  myCollapseButton = new FXButton(headerFrame, "", GUIIconSubSys::getIcon(GUIIcon::COLLAPSE), this, MID_GROUPBOXMODULE_COLLAPSE, GUIDesignButtonFXGroupBoxModule);
59  }
60  if (myOptions & Options::SAVE) {
61  mySaveButton = new FXButton(headerFrame, "", GUIIconSubSys::getIcon(GUIIcon::SAVE), this, MID_GROUPBOXMODULE_SAVE, GUIDesignButtonFXGroupBoxModule);
62  }
63  if (myOptions & Options::LOAD) {
64  myLoadButton = new FXButton(headerFrame, "", GUIIconSubSys::getIcon(GUIIcon::OPEN_NET), this, MID_GROUPBOXMODULE_LOAD, GUIDesignButtonFXGroupBoxModule);
65  }
66  myLabel = new FXLabel(headerFrame, text.c_str(), nullptr, GUIDesignLabelFXGroupBoxModule);
67  // build collapsable frame
68  myCollapsableFrame = new FXVerticalFrame(this, GUIDesignCollapsableFrame);
69 }
70 
71 
73 
74 
75 void
76 FXGroupBoxModule::setText(const std::string& text) {
77  myLabel->setText(text.c_str());
78 }
79 
80 
81 FXVerticalFrame*
83  return myCollapsableFrame;
84 }
85 
86 
87 long
88 FXGroupBoxModule::onPaint(FXObject*, FXSelector, void* ptr) {
89  FXEvent* event = (FXEvent*)ptr;
90  FXDCWindow dc(this, event);
91  // Paint background
92  dc.setForeground(backColor);
93  dc.fillRectangle(event->rect.x, event->rect.y, event->rect.w, event->rect.h);
94  // draw groove rectangle
95  drawGrooveRectangle(dc, 0, 15, width, height - 15);
96  return 1;
97 }
98 
99 
100 long
101 FXGroupBoxModule::onCmdCollapseButton(FXObject*, FXSelector, void*) {
102  if (myCollapsed) {
103  myCollapsed = false;
105  myCollapsableFrame->show();
106  } else {
107  myCollapsed = true;
109  myCollapsableFrame->hide();
110  }
111  recalc();
112  return 1;
113 }
114 
115 
116 long
117 FXGroupBoxModule::onCmdSaveButton(FXObject*, FXSelector, void*) {
118  return saveContents();
119 }
120 
121 
122 long
123 FXGroupBoxModule::onCmdLoadButton(FXObject*, FXSelector, void*) {
124  return loadContents();
125 }
126 
127 
129  myOptions(Options::NOTHING),
130  myCollapsed(false) {
131 }
132 
133 
134 bool
136  // nothing to do
137  return false;
138 }
139 
140 
141 bool
143  // nothing to do
144  return false;
145 }
146 
147 
148 void
150  if (mySaveButton) {
151  if (value) {
152  mySaveButton->enable();
153  } else {
154  mySaveButton->disable();
155  }
156  }
157 }
FXDEFMAP(FXGroupBoxModule) FXGroupBoxModuleMap[]
@ MID_GROUPBOXMODULE_LOAD
load contents
Definition: GUIAppEnum.h:621
@ MID_GROUPBOXMODULE_SAVE
save contents
Definition: GUIAppEnum.h:619
@ MID_GROUPBOXMODULE_COLLAPSE
Definition: GUIAppEnum.h:617
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:343
#define GUIDesignButtonFXGroupBoxModule
button used in GroupBoxModule
Definition: GUIDesigns.h:89
#define GUIDesignLabelFXGroupBoxModule
label used in GroupBoxModule
Definition: GUIDesigns.h:259
#define GUIDesignCollapsableFrame
design for CollapsableFrame (Used in FXGroupBoxModule)
Definition: GUIDesigns.h:355
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:293
FXGroupBoxModule (based on FXGroupBox)
FXButton * myCollapseButton
button for collapse elements
long onCmdSaveButton(FXObject *, FXSelector, void *)
save contents
long onCmdCollapseButton(FXObject *, FXSelector, void *)
collapse GroupBoxModule
FXLabel * myLabel
label used in non collapsable FXGroupBoxModule
FXButton * mySaveButton
button for save elements
long onCmdLoadButton(FXObject *, FXSelector, void *)
load contents
~FXGroupBoxModule()
destructor
Options
GroupBoxModule options.
FXGroupBoxModule()
FOX need this.
virtual bool loadContents() const
load contents (can be reimplemented in children)
void toogleSaveButton(const bool value)
enable or disable save buttons
FXVerticalFrame * myCollapsableFrame
vertical collapsable frame
long onPaint(FXObject *, FXSelector, void *)
draw FXGroupBoxModule
virtual bool saveContents() const
save contents (can be reimplemented in children)
void setText(const std::string &text)
set text
bool myCollapsed
flag to check if this groupbox is collapsed
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toogled)
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon