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 "Dialogs/Dialogs.h"
25 #include "Dialogs/WidgetDialog.hpp"
26 #include "Dialogs/Waypoint/WaypointDialogs.hpp"
27 #include "Widget/ListWidget.hpp"
28 #include "Screen/Layout.hpp"
29 #include "Screen/Font.hpp"
30 #include "Look/DialogLook.hpp"
31 #include "Task/ProtectedTaskManager.hpp"
32 #include "Components.hpp"
33 #include "Interface.hpp"
34 #include "UIGlobals.hpp"
35 #include "Look/MapLook.hpp"
36 #include "Renderer/WaypointListRenderer.hpp"
37 #include "Language/Language.hpp"
39 class AlternatesListWidget final
40 : public ListWidget
, private ActionListener
{
46 const DialogLook
&dialog_look
;
48 WndButton
*details_button
, *cancel_button
, *goto_button
;
51 AbortTask::AlternateVector alternates
;
54 void CreateButtons(WidgetDialog
&dialog
);
57 AlternatesListWidget(const DialogLook
&_dialog_look
)
58 :dialog_look(_dialog_look
) {}
60 unsigned GetCursorIndex() const {
61 return GetList().GetCursorIndex();
65 ProtectedTaskManager::Lease
lease(*protected_task_manager
);
66 alternates
= lease
->GetAlternates();
70 /* virtual methods from class Widget */
71 virtual void Prepare(ContainerWindow
&parent
, const PixelRect
&rc
) override
;
72 virtual void Unprepare() override
{
76 /* virtual methods from class List::Handler */
77 virtual void OnPaintItem(Canvas
&canvas
, const PixelRect rc
,
78 unsigned index
) override
{
79 assert(index
< alternates
.size());
81 const ComputerSettings
&settings
= CommonInterface::GetComputerSettings();
82 const Waypoint
&waypoint
= alternates
[index
].waypoint
;
83 const GlideResult
& solution
= alternates
[index
].solution
;
85 WaypointListRenderer::Draw(canvas
, rc
, waypoint
, solution
.vector
.distance
,
86 solution
.SelectAltitudeDifference(settings
.task
.glide
),
87 UIGlobals::GetDialogLook(),
88 UIGlobals::GetMapLook().waypoint
,
89 CommonInterface::GetMapSettings().waypoint
);
92 virtual void OnActivateItem(unsigned index
) override
;
94 /* virtual methods from class ActionListener */
95 virtual void OnAction(int id
) override
;
99 AlternatesListWidget::CreateButtons(WidgetDialog
&dialog
)
101 goto_button
= dialog
.AddButton(_("Goto"), *this, GOTO
);
102 details_button
= dialog
.AddButton(_("Details"), mrOK
);
103 cancel_button
= dialog
.AddButton(_("Close"), mrCancel
);
107 AlternatesListWidget::Prepare(ContainerWindow
&parent
, const PixelRect
&rc
)
109 UPixelScalar item_height
= dialog_look
.list
.font_bold
->GetHeight()
110 + Layout::Scale(6) + dialog_look
.small_font
->GetHeight();
111 assert(item_height
> 0);
113 CreateList(parent
, dialog_look
, rc
, item_height
);
115 GetList().SetLength(alternates
.size());
119 AlternatesListWidget::OnActivateItem(unsigned index
)
121 details_button
->OnClicked();
125 AlternatesListWidget::OnAction(int id
)
129 unsigned index
= GetCursorIndex();
131 auto const &item
= alternates
[index
];
132 auto const &waypoint
= item
.waypoint
;
134 protected_task_manager
->DoGoto(waypoint
);
135 cancel_button
->OnClicked();
142 dlgAlternatesListShowModal(SingleWindow
&parent
)
144 if (protected_task_manager
== NULL
)
147 const DialogLook
&dialog_look
= UIGlobals::GetDialogLook();
149 AlternatesListWidget
widget(dialog_look
);
152 WidgetDialog
dialog(dialog_look
);
153 dialog
.CreateFull(parent
, _("Alternates"), &widget
);
154 widget
.CreateButtons(dialog
);
156 int i
= dialog
.ShowModal() == mrOK
157 ? (int)widget
.GetCursorIndex()
159 dialog
.StealWidget();
161 if (i
< 0 || (unsigned)i
>= widget
.alternates
.size())
164 dlgWaypointDetailsShowModal(parent
, widget
.alternates
[i
].waypoint
);