[guilib] fix labelcontrols with auto width always being marked as dirty if they speci...
[vuplus_xbmc] / xbmc / guilib / GUIMessage.h
1 /*!
2 \file GUIMessage.h
3 \brief
4 */
5
6 #ifndef GUILIB_MESSAGE_H
7 #define GUILIB_MESSAGE_H
8
9 #pragma once
10
11 /*
12  *      Copyright (C) 2005-2013 Team XBMC
13  *      http://xbmc.org
14  *
15  *  This Program is free software; you can redistribute it and/or modify
16  *  it under the terms of the GNU General Public License as published by
17  *  the Free Software Foundation; either version 2, or (at your option)
18  *  any later version.
19  *
20  *  This Program is distributed in the hope that it will be useful,
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  *  GNU General Public License for more details.
24  *
25  *  You should have received a copy of the GNU General Public License
26  *  along with XBMC; see the file COPYING.  If not, see
27  *  <http://www.gnu.org/licenses/>.
28  *
29  */
30
31 #define GUI_MSG_WINDOW_INIT     1   // initialize window
32 #define GUI_MSG_WINDOW_DEINIT   2   // deinit window
33 #define GUI_MSG_WINDOW_RESET    27  // reset window to initial state
34
35 #define GUI_MSG_SETFOCUS        3   // set focus to control param1=up/down/left/right
36 #define GUI_MSG_LOSTFOCUS       4   // control lost focus
37
38 #define GUI_MSG_CLICKED         5   // control has been clicked
39
40 #define GUI_MSG_VISIBLE         6   // set control visible
41 #define GUI_MSG_HIDDEN          7   // set control hidden
42
43 #define GUI_MSG_ENABLED         8   // enable control
44 #define GUI_MSG_DISABLED        9   // disable control
45
46 #define GUI_MSG_SELECTED       10   // control = selected
47 #define GUI_MSG_DESELECTED     11   // control = not selected
48
49 #define GUI_MSG_LABEL_ADD      12   // add label control (for controls supporting more then 1 label)
50
51 #define GUI_MSG_LABEL_SET      13  // set the label of a control
52
53 #define GUI_MSG_LABEL_RESET    14  // clear all labels of a control // add label control (for controls supporting more then 1 label)
54
55 #define GUI_MSG_ITEM_SELECTED  15  // ask control 2 return the selected item
56 #define GUI_MSG_ITEM_SELECT   16  // ask control 2 select a specific item
57 #define GUI_MSG_LABEL2_SET   17
58 #define GUI_MSG_SHOWRANGE      18
59
60 #define GUI_MSG_FULLSCREEN  19  // should go to fullscreen window (vis or video)
61 #define GUI_MSG_EXECUTE    20  // user has clicked on a button with <execute> tag
62
63 #define GUI_MSG_NOTIFY_ALL    21  // message will be send to all active and inactive(!) windows, all active modal and modeless dialogs
64                                   // dwParam1 must contain an additional message the windows should react on
65
66 #define GUI_MSG_REFRESH_THUMBS 22 // message is sent to all windows to refresh all thumbs
67
68 #define GUI_MSG_MOVE          23 // message is sent to the window from the base control class when it's
69                                  // been asked to move.  dwParam1 contains direction.
70
71 #define GUI_MSG_LABEL_BIND     24   // bind label control (for controls supporting more then 1 label)
72
73 #define GUI_MSG_SELCHANGED  25  // selection within the control has changed
74
75 #define GUI_MSG_FOCUSED     26  // a control has become focused
76
77 #define GUI_MSG_PAGE_CHANGE 28  // a page control has changed the page number
78
79 #define GUI_MSG_REFRESH_LIST 29 // message sent to all listing controls telling them to refresh their item layouts
80
81 #define GUI_MSG_PAGE_UP      30 // page up
82 #define GUI_MSG_PAGE_DOWN    31 // page down
83 #define GUI_MSG_MOVE_OFFSET  32 // Instruct the contorl to MoveUp or MoveDown by offset amount
84
85 #define GUI_MSG_SET_TYPE     33 ///< Instruct a control to set it's type appropriately
86
87 /*!
88  \brief Message indicating the window has been resized
89  Any controls that keep stored sizing information based on aspect ratio or window size should
90  recalculate sizing information
91  */
92 #define GUI_MSG_WINDOW_RESIZE  34
93
94 /*!
95  \brief Message indicating loss of renderer, prior to reset
96  Any controls that keep shared resources should free them on receipt of this message, as the renderer
97  is about to be reset.
98  */
99 #define GUI_MSG_RENDERER_LOST  35
100
101 /*!
102  \brief Message indicating regain of renderer, after reset
103  Any controls that keep shared resources may reallocate them now that the renderer is back
104  */
105 #define GUI_MSG_RENDERER_RESET 36
106
107 /*!
108  \brief A control wishes to have (or release) exclusive access to mouse actions
109  */
110 #define GUI_MSG_EXCLUSIVE_MOUSE 37
111
112 /*!
113  \brief A request for supported gestures is made
114  */
115 #define GUI_MSG_GESTURE_NOTIFY  38
116
117 /*!
118  \brief A request to add a control
119  */
120 #define GUI_MSG_ADD_CONTROL     39
121
122 /*!
123  \brief A request to remove a control
124  */
125 #define GUI_MSG_REMOVE_CONTROL  40
126
127 /*!
128  \brief A request to unfocus all currently focused controls
129  */
130 #define GUI_MSG_UNFOCUS_ALL 41
131
132 #define GUI_MSG_SET_TEXT        42
133
134 #define GUI_MSG_WINDOW_LOAD 43
135
136 #define GUI_MSG_VALIDITY_CHANGED  44
137
138 #define GUI_MSG_USER         1000
139
140 /*!
141  \ingroup winmsg
142  \brief
143  */
144 #define CONTROL_SELECT(controlID) \
145 do { \
146  CGUIMessage msg(GUI_MSG_SELECTED, GetID(), controlID); \
147  OnMessage(msg); \
148 } while(0)
149
150 /*!
151  \ingroup winmsg
152  \brief
153  */
154 #define CONTROL_DESELECT(controlID) \
155 do { \
156  CGUIMessage msg(GUI_MSG_DESELECTED, GetID(), controlID); \
157  OnMessage(msg); \
158 } while(0)
159
160
161 /*!
162  \ingroup winmsg
163  \brief
164  */
165 #define CONTROL_ENABLE(controlID) \
166 do { \
167  CGUIMessage msg(GUI_MSG_ENABLED, GetID(), controlID); \
168  OnMessage(msg); \
169 } while(0)
170
171 /*!
172  \ingroup winmsg
173  \brief
174  */
175 #define CONTROL_DISABLE(controlID) \
176 do { \
177  CGUIMessage msg(GUI_MSG_DISABLED, GetID(), controlID); \
178  OnMessage(msg); \
179 } while(0)
180
181
182 /*!
183  \ingroup winmsg
184  \brief
185  */
186 #define CONTROL_ENABLE_ON_CONDITION(controlID, bCondition) \
187 do { \
188  CGUIMessage msg(bCondition ? GUI_MSG_ENABLED:GUI_MSG_DISABLED, GetID(), controlID); \
189  OnMessage(msg); \
190 } while(0)
191
192
193 /*!
194  \ingroup winmsg
195  \brief
196  */
197 #define CONTROL_SELECT_ITEM(controlID,iItem) \
198 do { \
199  CGUIMessage msg(GUI_MSG_ITEM_SELECT, GetID(), controlID,iItem); \
200  OnMessage(msg); \
201 } while(0)
202
203 /*!
204  \ingroup winmsg
205  \brief Set the label of the current control
206  */
207 #define SET_CONTROL_LABEL(controlID,label) \
208 do { \
209  CGUIMessage msg(GUI_MSG_LABEL_SET, GetID(), controlID); \
210  msg.SetLabel(label); \
211  OnMessage(msg); \
212 } while(0)
213
214 /*!
215  \ingroup winmsg
216  \brief Set the label of the current control
217  */
218 #define SET_CONTROL_LABEL_THREAD_SAFE(controlID,label) \
219 { \
220  CGUIMessage msg(GUI_MSG_LABEL_SET, GetID(), controlID); \
221  msg.SetLabel(label); \
222  if(g_application.IsCurrentThread()) \
223    OnMessage(msg); \
224  else \
225    g_windowManager.SendThreadMessage(msg, GetID()); \
226 }
227
228 /*!
229  \ingroup winmsg
230  \brief Set the second label of the current control
231  */
232 #define SET_CONTROL_LABEL2(controlID,label) \
233 do { \
234  CGUIMessage msg(GUI_MSG_LABEL2_SET, GetID(), controlID); \
235  msg.SetLabel(label); \
236  OnMessage(msg); \
237 } while(0)
238
239 /*!
240  \ingroup winmsg
241  \brief
242  */
243 #define SET_CONTROL_HIDDEN(controlID) \
244 do { \
245  CGUIMessage msg(GUI_MSG_HIDDEN, GetID(), controlID); \
246  OnMessage(msg); \
247 } while(0)
248
249 /*!
250  \ingroup winmsg
251  \brief
252  */
253 #define SET_CONTROL_FOCUS(controlID, dwParam) \
254 do { \
255  CGUIMessage msg(GUI_MSG_SETFOCUS, GetID(), controlID, dwParam); \
256  OnMessage(msg); \
257 } while(0)
258
259 /*!
260  \ingroup winmsg
261  \brief
262  */
263 #define SET_CONTROL_VISIBLE(controlID) \
264 do { \
265  CGUIMessage msg(GUI_MSG_VISIBLE, GetID(), controlID); \
266  OnMessage(msg); \
267 } while(0)
268
269 #define SET_CONTROL_SELECTED(dwSenderId, controlID, bSelect) \
270 do { \
271  CGUIMessage msg(bSelect?GUI_MSG_SELECTED:GUI_MSG_DESELECTED, dwSenderId, controlID); \
272  OnMessage(msg); \
273 } while(0)
274
275 #define BIND_CONTROL(i,c,pv) \
276 do { \
277  pv = ((c*)GetControl(i));\
278 } while(0)
279
280 /*!
281 \ingroup winmsg
282 \brief Click message sent from controls to windows.
283  */
284 #define SEND_CLICK_MESSAGE(id, parentID, action) \
285 do { \
286  CGUIMessage msg(GUI_MSG_CLICKED, id, parentID, action); \
287  SendWindowMessage(msg); \
288 } while(0)
289
290 #include <vector>
291 #include <boost/shared_ptr.hpp>
292 #include "utils/StdString.h"
293
294 // forwards
295 class CGUIListItem; typedef boost::shared_ptr<CGUIListItem> CGUIListItemPtr;
296 class CFileItemList;
297
298 /*!
299  \ingroup winmsg
300  \brief
301  */
302 class CGUIMessage
303 {
304 public:
305   CGUIMessage(int dwMsg, int senderID, int controlID, int param1 = 0, int param2 = 0);
306   CGUIMessage(int msg, int senderID, int controlID, int param1, int param2, CFileItemList* item);
307   CGUIMessage(int msg, int senderID, int controlID, int param1, int param2, const CGUIListItemPtr &item);
308   CGUIMessage(const CGUIMessage& msg);
309   virtual ~CGUIMessage(void);
310   CGUIMessage& operator = (const CGUIMessage& msg);
311
312   int GetControlId() const ;
313   int GetMessage() const;
314   void* GetPointer() const;
315   CGUIListItemPtr GetItem() const;
316   int GetParam1() const;
317   int GetParam2() const;
318   int GetSenderId() const;
319   void SetParam1(int param1);
320   void SetParam2(int param2);
321   void SetPointer(void* pointer);
322   void SetLabel(const std::string& strLabel);
323   void SetLabel(int iString);               // for convience - looks up in strings.xml
324   const std::string& GetLabel() const;
325   void SetStringParam(const CStdString &strParam);
326   void SetStringParams(const std::vector<CStdString> &params);
327   const CStdString& GetStringParam(size_t param = 0) const;
328   size_t GetNumStringParams() const;
329
330 private:
331   std::string m_strLabel;
332   std::vector<CStdString> m_params;
333   int m_senderID;
334   int m_controlID;
335   int m_message;
336   void* m_pointer;
337   int m_param1;
338   int m_param2;
339   CGUIListItemPtr m_item;
340
341   static CStdString empty_string;
342 };
343 #endif