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"
41 GeoPointEntryDialog(const TCHAR
*caption
, GeoPoint
&value
,
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
;
57 control_style
.TabStop();
59 DigitEntry
latitude_entry(look
);
60 latitude_entry
.CreateLatitude(client_area
, client_area
.GetClientRect(),
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(),
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
);
75 latitude_entry
.SetInvalid();
76 longitude_entry
.SetInvalid();
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();
90 dialog
.AddButton(_("Clear"), clear_listener
, 0);
94 TwoWidgets
widget(new FixedWindowWidget(&latitude_entry
),
95 new FixedWindowWidget(&longitude_entry
),
97 dialog
.FinishPreliminary(&widget
);
99 bool result
= dialog
.ShowModal() == mrOK
;
100 dialog
.StealWidget();
104 value
= GeoPoint(longitude_entry
.GetLongitude(),
105 latitude_entry
.GetLatitude());