TaskStats: move task_started to new struct StartStats
[xcsoar.git] / src / InfoBoxes / InfoBoxWindow.hpp
blob50b178b4260645c1d7a9e1d3b689720687aa22fa
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_INFO_BOX_HPP
25 #define XCSOAR_INFO_BOX_HPP
27 #include "Util/StaticString.hpp"
28 #include "InfoBoxes/Content/Base.hpp"
29 #include "Screen/PaintWindow.hpp"
30 #include "Screen/Timer.hpp"
31 #include "Data.hpp"
33 struct InfoBoxSettings;
34 struct InfoBoxLook;
35 struct UnitsLook;
37 class InfoBoxWindow : public PaintWindow
39 /** timeout of infobox focus [ms] */
40 static constexpr unsigned FOCUS_TIMEOUT_MAX = 20 * 1000;
42 private:
43 InfoBoxContent *content;
45 const InfoBoxSettings &settings;
46 const InfoBoxLook &look;
47 const UnitsLook &units_look;
49 const unsigned border_kind;
51 const unsigned id;
53 InfoBoxData data;
55 bool dragging;
57 /**
58 * Is the mouse currently pressed inside this InfoBox?
60 bool pressed;
62 /**
63 * draw the selector event if the InfoBox window is not the system focus
65 bool force_draw_selector;
67 /** a timer which returns keyboard focus back to the map window after a while */
68 WindowTimer focus_timer;
70 /**
71 * This timer opens the dialog. It is used to check for "long
72 * click" and to delay the dialog a bit (for double click
73 * detection).
75 WindowTimer dialog_timer;
77 PixelRect title_rect;
78 PixelRect value_rect;
79 PixelRect comment_rect;
80 PixelRect value_and_comment_rect;
82 /**
83 * Paints the InfoBox title to the given canvas
84 * @param canvas The canvas to paint on
86 void PaintTitle(Canvas &canvas);
87 /**
88 * Paints the InfoBox value to the given canvas
89 * @param canvas The canvas to paint on
91 void PaintValue(Canvas &canvas);
92 /**
93 * Paints the InfoBox comment on the given canvas
94 * @param canvas The canvas to paint on
96 void PaintComment(Canvas &canvas);
97 /**
98 * Paints the InfoBox with borders, title, comment and value
100 void Paint(Canvas &canvas);
102 public:
103 void PaintInto(Canvas &dest, PixelScalar xoff, PixelScalar yoff,
104 UPixelScalar width, UPixelScalar height);
107 * Sets the InfoBox title to the given Value
108 * @param Value New value of the InfoBox title
110 void SetTitle(const TCHAR *title);
112 const TCHAR* GetTitle() {
113 return data.title;
117 * Constructor of the InfoBoxWindow class
118 * @param Parent The parent ContainerWindow (usually MainWindow)
120 InfoBoxWindow(ContainerWindow &parent, PixelRect rc, unsigned border_flags,
121 const InfoBoxSettings &settings, const InfoBoxLook &_look,
122 const UnitsLook &units_look,
123 unsigned id,
124 WindowStyle style=WindowStyle());
126 ~InfoBoxWindow();
128 const InfoBoxLook &GetLook() const {
129 return look;
132 void SetContentProvider(InfoBoxContent *_content);
133 void UpdateContent();
135 private:
136 void SetPressed(bool _pressed) {
137 if (_pressed == pressed)
138 return;
140 pressed = _pressed;
141 Invalidate();
144 protected:
145 void ShowDialog();
147 bool HandleKey(InfoBoxContent::InfoBoxKeyCodes keycode);
149 public:
150 gcc_pure
151 const InfoBoxPanel *GetDialogContent() const;
153 const PixelRect GetValueRect() const {
154 return value_rect;
156 const PixelRect GetValueAndCommentRect() const {
157 return value_and_comment_rect;
160 protected:
161 virtual void OnDestroy() override;
162 virtual void OnResize(PixelSize new_size) override;
163 virtual void OnSetFocus() override;
164 virtual void OnKillFocus() override;
165 virtual void OnCancelMode() override;
166 virtual bool OnTimer(WindowTimer &timer) override;
168 virtual bool OnKeyDown(unsigned key_code) override;
170 virtual bool OnMouseDown(PixelScalar x, PixelScalar y) override;
171 virtual bool OnMouseUp(PixelScalar x, PixelScalar y) override;
172 virtual bool OnMouseDouble(PixelScalar x, PixelScalar y) override;
173 virtual bool OnMouseMove(PixelScalar x, PixelScalar y,
174 unsigned keys) override;
176 virtual void OnPaint(Canvas &canvas) override;
179 #endif