dlgTextEntry_Keyboard: rename to TouchTextEntry
[xcsoar.git] / src / Widget / OffsetButtonsWidget.cpp
bloba5f72e41b1174d42289898e8d11834181d476da6
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 "OffsetButtonsWidget.hpp"
25 #include "Form/Button.hpp"
26 #include "Util/Macros.hpp"
27 #include "Screen/Layout.hpp"
29 PixelSize
30 OffsetButtonsWidget::GetMinimumSize() const
32 return { 4u * Layout::GetMinimumControlHeight(),
33 Layout::GetMinimumControlHeight() };
36 PixelSize
37 OffsetButtonsWidget::GetMaximumSize() const
39 return { 4u * Layout::GetMaximumControlHeight(),
40 Layout::GetMaximumControlHeight() };
43 static void
44 LayoutOffsetButtons(const PixelRect &total_rc, PixelRect buttons[4])
46 const unsigned total_width = total_rc.right - total_rc.left;
47 PixelRect rc = { 0, total_rc.top, total_rc.left, total_rc.bottom };
49 for (unsigned i = 0; i < 4; ++i) {
50 rc.left = rc.right;
51 rc.right = total_rc.left + (i + 1) * total_width / 4;
52 buttons[i] = rc;
56 void
57 OffsetButtonsWidget::Prepare(ContainerWindow &parent,
58 const PixelRect &total_rc)
60 PixelRect rc[ARRAY_SIZE(buttons)];
61 LayoutOffsetButtons(total_rc, rc);
63 ButtonWindowStyle style;
64 style.TabStop();
65 style.Hide();
67 for (unsigned i = 0; i < ARRAY_SIZE(buttons); ++i) {
68 TCHAR caption[16];
69 _stprintf(caption, format, (double)offsets[i]);
70 buttons[i] = new WndButton(parent, look, caption, rc[i], style,
71 *this, i);
75 void
76 OffsetButtonsWidget::Unprepare()
78 for (unsigned i = 0; i < ARRAY_SIZE(offsets); ++i)
79 delete buttons[i];
82 void
83 OffsetButtonsWidget::Show(const PixelRect &total_rc)
85 PixelRect rc[ARRAY_SIZE(buttons)];
86 LayoutOffsetButtons(total_rc, rc);
88 for (unsigned i = 0; i < ARRAY_SIZE(buttons); ++i)
89 buttons[i]->MoveAndShow(rc[i]);
92 void
93 OffsetButtonsWidget::Hide()
95 for (unsigned i = 0; i < ARRAY_SIZE(buttons); ++i)
96 buttons[i]->Hide();
99 void
100 OffsetButtonsWidget::Move(const PixelRect &total_rc)
102 PixelRect rc[ARRAY_SIZE(buttons)];
103 LayoutOffsetButtons(total_rc, rc);
105 for (unsigned i = 0; i < ARRAY_SIZE(buttons); ++i)
106 buttons[i]->Move(rc[i]);
109 bool
110 OffsetButtonsWidget::SetFocus()
112 buttons[2]->SetFocus();
113 return true;
116 void
117 OffsetButtonsWidget::OnAction(int id)
119 assert(unsigned(id) < ARRAY_SIZE(offsets));
121 OnOffset(offsets[id]);