DeviceDescriptor: eliminate obsolete NMEAOut kludge
[xcsoar.git] / src / MainWindow.hpp
blobac63e93ea3f6645b4bd9fe1c6ce96d93149f6ac5
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 #ifndef XCSOAR_MAIN_WINDOW_HXX
25 #define XCSOAR_MAIN_WINDOW_HXX
27 #include "Screen/SingleWindow.hpp"
28 #include "Screen/Timer.hpp"
29 #include "InfoBoxes/InfoBoxLayout.hpp"
30 #include "PopupMessage.hpp"
31 #include "BatteryTimer.hpp"
32 #include "Widget/ManagedWidget.hpp"
33 #include "UIUtil/GestureManager.hpp"
35 #include <stdint.h>
36 #include <assert.h>
38 struct ComputerSettings;
39 struct MapSettings;
40 struct UIState;
41 struct Look;
42 class GlueMapWindow;
43 class Widget;
44 class StatusMessageList;
45 class RasterTerrain;
46 class TopographyStore;
47 class MapWindowProjection;
49 /**
50 * The XCSoar main window.
52 class MainWindow : public SingleWindow {
53 enum class Command: uint8_t {
54 /**
55 * Check the airspace_warning_pending flag and show the airspace
56 * warning dialog.
58 AIRSPACE_WARNING,
60 /**
61 * Called by the #MergeThread when new GPS data is available.
63 GPS_UPDATE,
65 /**
66 * Called by the calculation thread when new calculation results
67 * are available. This updates the map and the info boxes.
69 CALCULATED_UPDATE,
71 /**
72 * @see DeferredRestorePage()
74 RESTORE_PAGE,
77 static constexpr const TCHAR *title = _T("XCSoar");
79 Look *look;
81 GlueMapWindow *map;
83 /**
84 * A #Widget that is shown below the map.
86 Widget *bottom_widget;
88 /**
89 * A #Widget that is shown instead of the map. The #GlueMapWindow
90 * is hidden and the DrawThread is suspended while this attribute is
91 * non-NULL.
93 Widget *widget;
95 ManagedWidget vario;
97 ManagedWidget traffic_gauge;
98 bool suppress_traffic_gauge, force_traffic_gauge;
100 ManagedWidget thermal_assistant;
102 bool dragging;
103 GestureManager gestures;
105 public:
106 PopupMessage popup;
108 private:
109 WindowTimer timer;
111 BatteryTimer battery_timer;
113 PixelRect map_rect;
114 bool FullScreen;
116 #ifndef ENABLE_OPENGL
118 * This variable tracks whether the #DrawThread was suspended
119 * because the map was replaced by a #Widget.
121 bool draw_suspended;
122 #endif
124 bool restore_page_pending;
126 bool airspace_warning_pending;
128 public:
129 MainWindow(const StatusMessageList &status_messages);
130 virtual ~MainWindow();
132 #ifdef USE_GDI
133 static bool Find() {
134 return SingleWindow::Find(title);
136 #endif
138 protected:
140 * Is XCSoar already up and running?
142 bool IsRunning() {
143 /* it is safe enough to say that XCSoar initialization is complete
144 after the MapWindow has been created */
145 return map != NULL;
149 * Destroy the current Widget, but don't reactivate the map. The
150 * caller is responsible for reactivating the map or another Widget.
152 void KillWidget();
155 * Destroy the current "bottom" Widget, but don't resize the main
156 * area. The caller is responsible for doing that or installing a
157 * new bottom Widget.
159 void KillBottomWidget();
161 public:
162 void Create(PixelSize size, TopWindowStyle style=TopWindowStyle());
164 void Destroy();
166 void Initialise();
167 void InitialiseConfigured();
170 * Destroy the components of the main view (map, info boxes,
171 * gauges).
173 void Deinitialise();
175 private:
176 gcc_pure
177 const PixelRect &GetMainRect(const PixelRect &full_rc) const {
178 return FullScreen ? full_rc : map_rect;
181 gcc_pure
182 PixelRect GetMainRect() const {
183 return FullScreen ? GetClientRect() : map_rect;
187 * Adjust the flarm radar position
189 void ReinitialiseLayout_flarm(PixelRect rc, const InfoBoxLayout::Layout ib_layout);
192 * Adjust vario
194 void ReinitialiseLayout_vario(const InfoBoxLayout::Layout &layout);
196 void ReinitialiseLayoutTA(PixelRect rc, const InfoBoxLayout::Layout &layout);
198 public:
200 * Called by XCSoarInterface::Startup() after startup has been
201 * completed.
203 void FinishStartup();
206 * Called by XCSoarInterface::Shutdown() before shutdown begins.
208 void BeginShutdown();
211 * Destroy and re-create all info boxes, and adjust the map
212 * position/size.
214 void ReinitialiseLayout();
217 * Suspend threads that are owned by this object.
219 void SuspendThreads();
222 * Resumt threads that are owned by this object.
224 void ResumeThreads();
227 * Set the keyboard focus on the default element (i.e. the
228 * MapWindow).
230 void SetDefaultFocus();
233 * Trigger a full redraw of the screen.
235 void FullRedraw();
237 bool GetFullScreen() const {
238 return FullScreen;
241 void SetFullScreen(bool _full_screen);
244 * A new airspace warning was found. This method sends the
245 * Command::AIRSPACE_WARNING command to this window, which displays the
246 * airspace warning dialog.
248 void SendAirspaceWarning() {
249 airspace_warning_pending = true;
250 SendUser((unsigned)Command::AIRSPACE_WARNING);
253 void SendGPSUpdate() {
254 SendUser((unsigned)Command::GPS_UPDATE);
257 void SendCalculatedUpdate() {
258 SendUser((unsigned)Command::CALCULATED_UPDATE);
261 void SetTerrain(RasterTerrain *terrain);
262 void SetTopography(TopographyStore *topography);
264 const Look &GetLook() const {
265 assert(look != NULL);
267 return *look;
270 Look &SetLook() {
271 assert(look != NULL);
273 return *look;
276 void SetComputerSettings(const ComputerSettings &settings_computer);
277 void SetMapSettings(const MapSettings &settings_map);
278 void SetUIState(const UIState &ui_state);
281 * Returns the map even if it is not active. May return NULL if
282 * there is no map.
284 gcc_pure
285 GlueMapWindow *GetMap() {
286 return map;
290 * Is the map active, i.e. currently visible?
292 bool IsMapActive() const {
293 return widget == NULL;
297 * Returns the map if it is active, or NULL if the map is not
298 * active.
300 gcc_pure
301 GlueMapWindow *GetMapIfActive();
304 * Activate the map and return a pointer to it. May return NULL if
305 * there is no map.
307 GlueMapWindow *ActivateMap();
310 * Schedule a call to PageActions::Restore(). The function returns
311 * immediately, and there is no guarantee that it succeeds.
313 void DeferredRestorePage();
316 * Show this #Widget below the map. This replaces (deletes) the
317 * previous bottom widget, if any. To disable this feature, call
318 * this method with widget==nullptr.
320 void SetBottomWidget(Widget *widget);
323 * Replace the map with a #Widget. The Widget instance gets deleted
324 * when the map gets reactivated with ActivateMap() or if another
325 * Widget gets set.
327 void SetWidget(Widget *_widget);
330 * Returns the current #Widget, but only if the specified flavour is
331 * active.
333 * @see InputEvents::IsFlavour(), InputEvents::SetFlavour()
335 gcc_pure
336 Widget *GetFlavourWidget(const TCHAR *flavour);
338 void UpdateGaugeVisibility();
340 gcc_pure
341 const MapWindowProjection &GetProjection() const;
343 void ToggleSuppressFLARMRadar();
344 void ToggleForceFLARMRadar();
346 private:
347 void UpdateVarioGaugeVisibility();
348 void UpdateTrafficGaugeVisibility();
350 void StopDragging();
352 protected:
353 /* virtual methods from class Window */
354 virtual void OnDestroy() override;
355 virtual void OnResize(PixelSize new_size) override;
356 virtual void OnSetFocus() override;
357 virtual void OnCancelMode() override;
358 virtual bool OnMouseDown(PixelScalar x, PixelScalar y) override;
359 virtual bool OnMouseUp(PixelScalar x, PixelScalar y) override;
360 virtual bool OnMouseMove(PixelScalar x, PixelScalar y,
361 unsigned keys) override;
362 virtual bool OnMouseDouble(PixelScalar x, PixelScalar y) override;
363 virtual bool OnKeyDown(unsigned key_code) override;
364 virtual bool OnUser(unsigned id) override;
365 virtual bool OnTimer(WindowTimer &timer) override;
367 /* virtual methods from class TopWindow */
368 virtual bool OnClose() override;
369 virtual bool OnActivate() override;
371 #ifdef ANDROID
372 virtual void OnPause() override;
373 #endif
376 #endif