SectorZone: add attribute arc_boundary
[xcsoar.git] / src / Dialogs / GeoPointEntry.cpp
blob72c3cfc386fdb68073147cf31c05babe48620c57
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2011 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 "Dialogs/GeoPointEntry.hpp"
25 #include "Dialogs/WidgetDialog.hpp"
26 #include "Widget/FixedWindowWidget.hpp"
27 #include "Widget/TwoWidgets.hpp"
28 #include "Form/Form.hpp"
29 #include "Form/DigitEntry.hpp"
30 #include "Form/LambdaActionListener.hpp"
31 #include "Screen/SingleWindow.hpp"
32 #include "Language/Language.hpp"
33 #include "UIGlobals.hpp"
34 #include "Geo/GeoPoint.hpp"
36 enum {
37 CLEAR = 100,
40 bool
41 GeoPointEntryDialog(const TCHAR *caption, GeoPoint &value,
42 bool nullable)
44 /* create the dialog */
46 const DialogLook &look = UIGlobals::GetDialogLook();
48 WidgetDialog dialog(look);
49 dialog.CreatePreliminary(UIGlobals::GetMainWindow(), caption);
51 ContainerWindow &client_area = dialog.GetClientAreaWindow();
53 /* create the input control */
55 WindowStyle control_style;
56 control_style.Hide();
57 control_style.TabStop();
59 DigitEntry latitude_entry(look);
60 latitude_entry.CreateLatitude(client_area, client_area.GetClientRect(),
61 control_style);
62 latitude_entry.Resize(latitude_entry.GetRecommendedSize());
63 latitude_entry.SetActionListener(dialog, mrOK);
65 DigitEntry longitude_entry(look);
66 longitude_entry.CreateLongitude(client_area, client_area.GetClientRect(),
67 control_style);
68 longitude_entry.Resize(longitude_entry.GetRecommendedSize());
69 longitude_entry.SetActionListener(dialog, mrOK);
71 if (value.IsValid()) {
72 latitude_entry.SetLatitude(value.latitude);
73 longitude_entry.SetLongitude(value.longitude);
74 } else {
75 latitude_entry.SetInvalid();
76 longitude_entry.SetInvalid();
79 /* create buttons */
81 dialog.AddButton(_("OK"), dialog, mrOK);
82 dialog.AddButton(_("Cancel"), dialog, mrCancel);
84 auto clear_listener = MakeLambdaActionListener([&latitude_entry,
85 &longitude_entry](unsigned){
86 latitude_entry.SetInvalid();
87 longitude_entry.SetInvalid();
88 });
89 if (nullable)
90 dialog.AddButton(_("Clear"), clear_listener, 0);
92 /* run it */
94 TwoWidgets widget(new FixedWindowWidget(&latitude_entry),
95 new FixedWindowWidget(&longitude_entry),
96 true);
97 dialog.FinishPreliminary(&widget);
99 bool result = dialog.ShowModal() == mrOK;
100 dialog.StealWidget();
101 if (!result)
102 return false;
104 value = GeoPoint(longitude_entry.GetLongitude(),
105 latitude_entry.GetLatitude());
106 return true;