NEWS: prepare for 6.6.1
[xcsoar.git] / src / Widget / ButtonPanelWidget.cpp
blobb9644452f6304fe794ae5944981e9085f0677954
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "ButtonPanelWidget.hpp"
25 #include "Form/ButtonPanel.hpp"
26 #include "Screen/Layout.hpp"
27 #include "UIGlobals.hpp"
29 #include <assert.h>
31 ButtonPanelWidget::~ButtonPanelWidget()
33 delete buttons;
34 delete widget;
37 PixelRect
38 ButtonPanelWidget::UpdateLayout(const PixelRect &rc)
40 assert(buttons != nullptr);
42 switch (alignment) {
43 case Alignment::AUTO:
44 return buttons->UpdateLayout(rc);
46 case Alignment::LEFT:
47 return buttons->LeftLayout(rc);
49 case Alignment::BOTTOM:
50 return buttons->BottomLayout(rc);
53 gcc_unreachable();
56 PixelSize
57 ButtonPanelWidget::GetMinimumSize() const
59 PixelSize size = widget->GetMinimumSize();
60 if (size.cy > 0)
61 size.cy += Layout::GetMinimumControlHeight();
62 return size;
65 PixelSize
66 ButtonPanelWidget::GetMaximumSize() const
68 PixelSize size = widget->GetMaximumSize();
69 if (size.cy > 0)
70 size.cy += Layout::GetMaximumControlHeight();
71 return size;
74 void
75 ButtonPanelWidget::Initialise(ContainerWindow &parent, const PixelRect &rc)
77 assert(buttons == nullptr);
79 buttons = new ButtonPanel(parent, UIGlobals::GetDialogLook());
80 buttons->SetDefaultHidden();
82 /* initialise with full dimensions for now, buttons will be added
83 later */
84 widget->Initialise(parent, rc);
87 void
88 ButtonPanelWidget::Prepare(ContainerWindow &parent, const PixelRect &rc)
90 assert(buttons != nullptr);
92 /* initialise with full dimensions for now, buttons may be added
93 during this call, and the final layout will be set by Show() */
94 widget->Prepare(parent, rc);
97 void
98 ButtonPanelWidget::Unprepare()
100 assert(buttons != nullptr);
103 bool
104 ButtonPanelWidget::Save(bool &changed)
106 return widget->Save(changed);
109 bool
110 ButtonPanelWidget::Click()
112 return widget->Click();
115 void
116 ButtonPanelWidget::ReClick()
118 assert(buttons != nullptr);
120 widget->ReClick();
123 void
124 ButtonPanelWidget::Show(const PixelRect &rc)
126 assert(buttons != nullptr);
128 widget->Show(UpdateLayout(rc));
129 buttons->ShowAll();
132 bool
133 ButtonPanelWidget::Leave()
135 return widget->Leave();
138 void
139 ButtonPanelWidget::Hide()
141 buttons->HideAll();
142 widget->Hide();
145 void
146 ButtonPanelWidget::Move(const PixelRect &rc)
148 widget->Move(UpdateLayout(rc));
151 bool
152 ButtonPanelWidget::SetFocus()
154 return widget->SetFocus();