DeviceDescriptor: eliminate obsolete NMEAOut kludge
[xcsoar.git] / src / PopupMessage.hpp
blob17c85efc1eb59e3fce9d87421a194fb65cb15d96
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_POPUP_MESSAGE_H
25 #define XCSOAR_POPUP_MESSAGE_H
27 #include "Thread/Mutex.hpp"
28 #include "Util/StaticString.hpp"
29 #include "Screen/LargeTextWindow.hpp"
31 #include <tchar.h>
33 struct UISettings;
34 class SingleWindow;
35 class StatusMessageList;
37 /**
38 * - Single window, created in GUI thread.
39 * -- hidden when no messages for display
40 * -- shown when messages available
41 * -- disappear when touched
42 * -- disappear when return clicked
43 * -- disappear when timeout
44 * -- disappear when extrn event triggered
45 * - Message properties
46 * -- have a start time (seconds)
47 * -- timeout (start time + delta)
48 * - Messages stay in a circular buffer can be reviewed
49 * - Optional logging of all messages to file
50 * - Thread locking so available from any thread
52 class PopupMessage : public LargeTextWindow
54 public:
55 enum Type {
56 MSG_UNKNOWN = 0,
57 MSG_AIRSPACE = 1,
58 MSG_USERINTERFACE = 2,
59 MSG_GLIDECOMPUTER = 3,
60 MSG_COMMS = 4,
63 private:
64 enum { MAXMESSAGES = 20 };
66 struct Message {
67 Type type;
68 unsigned tstart; // time message was created
69 unsigned texpiry; // time message will expire
70 unsigned tshow; // time message is visible for
72 StaticString<256u> text;
74 Message()
75 :type(MSG_UNKNOWN), tstart(0), texpiry(0)
77 text.clear();
80 bool IsUnknown() const {
81 return type == MSG_UNKNOWN;
84 bool IsNew() const {
85 return texpiry == tstart;
88 /**
89 * Expired for the first time?
91 bool IsNewlyExpired(unsigned now) const {
92 return texpiry <= now && texpiry > tstart;
95 void Set(Type type, unsigned tshow, const TCHAR *text, unsigned now);
97 /**
98 * @return true if something was changed
100 bool Update(unsigned now);
103 * @return true if a message has been appended
105 bool AppendTo(StaticString<2000> &buffer, unsigned now);
108 const StatusMessageList &status_messages;
110 SingleWindow &parent;
111 PixelRect rc; // maximum message size
113 const UISettings &settings;
115 Mutex mutex;
116 struct Message messages[MAXMESSAGES];
117 StaticString<2000> text;
119 unsigned n_visible;
121 bool enable_sound;
123 public:
124 PopupMessage(const StatusMessageList &_status_messages,
125 SingleWindow &_parent, const UISettings &settings);
127 void Create(const PixelRect _rc);
129 /** returns true if messages have changed */
130 bool Render();
132 protected:
133 /** Caller must hold the lock. */
134 void AddMessage(unsigned tshow, Type type, const TCHAR *Text);
136 public:
137 void AddMessage(const TCHAR* text, const TCHAR *data=NULL);
140 * Repeats last non-visible message of specified type
141 * (or any message type=MSG_UNKNOWN).
143 void Repeat(Type type=MSG_UNKNOWN);
145 /** Clears all visible messages (of specified type or if type=0, all). */
146 bool Acknowledge(Type type=MSG_UNKNOWN);
148 private:
149 gcc_pure
150 PixelRect GetRect(UPixelScalar height) const;
152 void UpdateTextAndLayout(const TCHAR *text);
153 int GetEmptySlot();
155 protected:
156 virtual bool OnMouseDown(PixelScalar x, PixelScalar y);
159 #endif