PageRenderTime 43ms CodeModel.GetById 15ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 1ms

/xbmc/guilib/GUIMessage.h

http://github.com/xbmc/xbmc
C Header | 390 lines | 185 code | 71 blank | 134 comment | 2 complexity | 10ecb20097c15eefb5a8d6cf934b5f77 MD5 | raw file
  1/*
  2 *  Copyright (C) 2005-2018 Team Kodi
  3 *  This file is part of Kodi - https://kodi.tv
  4 *
  5 *  SPDX-License-Identifier: GPL-2.0-or-later
  6 *  See LICENSES/README.md for more information.
  7 */
  8
  9#pragma once
 10
 11/*!
 12\file GUIMessage.h
 13\brief
 14*/
 15
 16#define GUI_MSG_WINDOW_INIT     1   // initialize window
 17#define GUI_MSG_WINDOW_DEINIT   2   // deinit window
 18#define GUI_MSG_WINDOW_RESET    27  // reset window to initial state
 19
 20#define GUI_MSG_SETFOCUS        3   // set focus to control param1=up/down/left/right
 21#define GUI_MSG_LOSTFOCUS       4   // control lost focus
 22
 23#define GUI_MSG_CLICKED         5   // control has been clicked
 24
 25#define GUI_MSG_VISIBLE         6   // set control visible
 26#define GUI_MSG_HIDDEN          7   // set control hidden
 27
 28#define GUI_MSG_ENABLED         8   // enable control
 29#define GUI_MSG_DISABLED        9   // disable control
 30
 31#define GUI_MSG_SET_SELECTED   10   // control = selected
 32#define GUI_MSG_SET_DESELECTED 11   // control = not selected
 33
 34#define GUI_MSG_LABEL_ADD      12   // add label control (for controls supporting more then 1 label)
 35
 36#define GUI_MSG_LABEL_SET      13  // set the label of a control
 37
 38#define GUI_MSG_LABEL_RESET    14  // clear all labels of a control // add label control (for controls supporting more then 1 label)
 39
 40#define GUI_MSG_ITEM_SELECTED  15  // ask control 2 return the selected item
 41#define GUI_MSG_ITEM_SELECT   16  // ask control 2 select a specific item
 42#define GUI_MSG_LABEL2_SET   17
 43#define GUI_MSG_SHOWRANGE      18
 44
 45#define GUI_MSG_FULLSCREEN  19  // should go to fullscreen window (vis or video)
 46#define GUI_MSG_EXECUTE    20  // user has clicked on a button with <execute> tag
 47
 48#define GUI_MSG_NOTIFY_ALL    21  // message will be send to all active and inactive(!) windows, all active modal and modeless dialogs
 49                                  // dwParam1 must contain an additional message the windows should react on
 50
 51#define GUI_MSG_REFRESH_THUMBS 22 // message is sent to all windows to refresh all thumbs
 52
 53#define GUI_MSG_MOVE          23 // message is sent to the window from the base control class when it's
 54                                 // been asked to move.  dwParam1 contains direction.
 55
 56#define GUI_MSG_LABEL_BIND     24   // bind label control (for controls supporting more then 1 label)
 57
 58#define GUI_MSG_FOCUSED     26  // a control has become focused
 59
 60#define GUI_MSG_PAGE_CHANGE 28  // a page control has changed the page number
 61
 62#define GUI_MSG_REFRESH_LIST 29 // message sent to all listing controls telling them to refresh their item layouts
 63
 64#define GUI_MSG_PAGE_UP      30 // page up
 65#define GUI_MSG_PAGE_DOWN    31 // page down
 66#define GUI_MSG_MOVE_OFFSET  32 // Instruct the control to MoveUp or MoveDown by offset amount
 67
 68#define GUI_MSG_SET_TYPE     33 ///< Instruct a control to set it's type appropriately
 69
 70/*!
 71 \brief Message indicating the window has been resized
 72 Any controls that keep stored sizing information based on aspect ratio or window size should
 73 recalculate sizing information
 74 */
 75#define GUI_MSG_WINDOW_RESIZE  34
 76
 77/*!
 78 \brief Message indicating loss of renderer, prior to reset
 79 Any controls that keep shared resources should free them on receipt of this message, as the renderer
 80 is about to be reset.
 81 */
 82#define GUI_MSG_RENDERER_LOST  35
 83
 84/*!
 85 \brief Message indicating regain of renderer, after reset
 86 Any controls that keep shared resources may reallocate them now that the renderer is back
 87 */
 88#define GUI_MSG_RENDERER_RESET 36
 89
 90/*!
 91 \brief A control wishes to have (or release) exclusive access to mouse actions
 92 */
 93#define GUI_MSG_EXCLUSIVE_MOUSE 37
 94
 95/*!
 96 \brief A request for supported gestures is made
 97 */
 98#define GUI_MSG_GESTURE_NOTIFY  38
 99
100/*!
101 \brief A request to add a control
102 */
103#define GUI_MSG_ADD_CONTROL     39
104
105/*!
106 \brief A request to remove a control
107 */
108#define GUI_MSG_REMOVE_CONTROL  40
109
110/*!
111 \brief A request to unfocus all currently focused controls
112 */
113#define GUI_MSG_UNFOCUS_ALL 41
114
115#define GUI_MSG_SET_TEXT        42
116
117#define GUI_MSG_WINDOW_LOAD 43
118
119#define GUI_MSG_VALIDITY_CHANGED  44
120
121/*!
122 \brief Check whether a button is selected
123 */
124#define GUI_MSG_IS_SELECTED    45
125
126/*!
127 \brief Bind a set of labels to a spin (or similar) control
128 */
129#define GUI_MSG_SET_LABELS     46
130
131/*!
132 \brief Set the filename for an image control
133 */
134#define GUI_MSG_SET_FILENAME   47
135
136/*!
137 \brief Get the filename of an image control
138 */
139
140#define GUI_MSG_GET_FILENAME   48
141
142/*!
143 \brief The user interface is ready for usage
144 */
145#define GUI_MSG_UI_READY       49
146
147 /*!
148 \brief Called every 500ms to allow time dependent updates
149 */
150#define GUI_MSG_REFRESH_TIMER  50
151
152 /*!
153 \brief Called if state has changed wich could lead to GUI changes
154 */
155#define GUI_MSG_STATE_CHANGED  51
156
157/*!
158 \brief Called when a subtitle download has finished
159 */
160#define GUI_MSG_SUBTITLE_DOWNLOADED  52
161
162
163#define GUI_MSG_USER         1000
164
165/*!
166\brief Complete to get codingtable page
167*/
168#define GUI_MSG_CODINGTABLE_LOOKUP_COMPLETED 65000
169
170/*!
171 \ingroup winmsg
172 \brief
173 */
174#define CONTROL_SELECT(controlID) \
175do { \
176 CGUIMessage msg(GUI_MSG_SET_SELECTED, GetID(), controlID); \
177 OnMessage(msg); \
178} while(0)
179
180/*!
181 \ingroup winmsg
182 \brief
183 */
184#define CONTROL_DESELECT(controlID) \
185do { \
186 CGUIMessage msg(GUI_MSG_SET_DESELECTED, GetID(), controlID); \
187 OnMessage(msg); \
188} while(0)
189
190
191/*!
192 \ingroup winmsg
193 \brief
194 */
195#define CONTROL_ENABLE(controlID) \
196do { \
197 CGUIMessage msg(GUI_MSG_ENABLED, GetID(), controlID); \
198 OnMessage(msg); \
199} while(0)
200
201/*!
202 \ingroup winmsg
203 \brief
204 */
205#define CONTROL_DISABLE(controlID) \
206do { \
207 CGUIMessage msg(GUI_MSG_DISABLED, GetID(), controlID); \
208 OnMessage(msg); \
209} while(0)
210
211
212/*!
213 \ingroup winmsg
214 \brief
215 */
216#define CONTROL_ENABLE_ON_CONDITION(controlID, bCondition) \
217do { \
218 CGUIMessage msg(bCondition ? GUI_MSG_ENABLED:GUI_MSG_DISABLED, GetID(), controlID); \
219 OnMessage(msg); \
220} while(0)
221
222
223/*!
224 \ingroup winmsg
225 \brief
226 */
227#define CONTROL_SELECT_ITEM(controlID,iItem) \
228do { \
229 CGUIMessage msg(GUI_MSG_ITEM_SELECT, GetID(), controlID,iItem); \
230 OnMessage(msg); \
231} while(0)
232
233/*!
234 \ingroup winmsg
235 \brief Set the label of the current control
236 */
237#define SET_CONTROL_LABEL(controlID,label) \
238do { \
239 CGUIMessage msg(GUI_MSG_LABEL_SET, GetID(), controlID); \
240 msg.SetLabel(label); \
241 OnMessage(msg); \
242} while(0)
243
244/*!
245 \ingroup winmsg
246 \brief Set the label of the current control
247 */
248#define SET_CONTROL_LABEL_THREAD_SAFE(controlID,label) \
249{ \
250 CGUIMessage msg(GUI_MSG_LABEL_SET, GetID(), controlID); \
251 msg.SetLabel(label); \
252 if(g_application.IsCurrentThread()) \
253   OnMessage(msg); \
254 else \
255   CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg, GetID()); \
256}
257
258/*!
259 \ingroup winmsg
260 \brief Set the second label of the current control
261 */
262#define SET_CONTROL_LABEL2(controlID,label) \
263do { \
264 CGUIMessage msg(GUI_MSG_LABEL2_SET, GetID(), controlID); \
265 msg.SetLabel(label); \
266 OnMessage(msg); \
267} while(0)
268
269/*!
270 \ingroup winmsg
271 \brief Set a bunch of labels on the given control
272 */
273#define SET_CONTROL_LABELS(controlID, defaultValue, labels) \
274do { \
275CGUIMessage msg(GUI_MSG_SET_LABELS, GetID(), controlID, defaultValue); \
276msg.SetPointer(labels); \
277OnMessage(msg); \
278} while(0)
279
280/*!
281 \ingroup winmsg
282 \brief Set the label of the current control
283 */
284#define SET_CONTROL_FILENAME(controlID,label) \
285do { \
286CGUIMessage msg(GUI_MSG_SET_FILENAME, GetID(), controlID); \
287msg.SetLabel(label); \
288OnMessage(msg); \
289} while(0)
290
291/*!
292 \ingroup winmsg
293 \brief
294 */
295#define SET_CONTROL_HIDDEN(controlID) \
296do { \
297 CGUIMessage msg(GUI_MSG_HIDDEN, GetID(), controlID); \
298 OnMessage(msg); \
299} while(0)
300
301/*!
302 \ingroup winmsg
303 \brief
304 */
305#define SET_CONTROL_FOCUS(controlID, dwParam) \
306do { \
307 CGUIMessage msg(GUI_MSG_SETFOCUS, GetID(), controlID, dwParam); \
308 OnMessage(msg); \
309} while(0)
310
311/*!
312 \ingroup winmsg
313 \brief
314 */
315#define SET_CONTROL_VISIBLE(controlID) \
316do { \
317 CGUIMessage msg(GUI_MSG_VISIBLE, GetID(), controlID); \
318 OnMessage(msg); \
319} while(0)
320
321#define SET_CONTROL_SELECTED(dwSenderId, controlID, bSelect) \
322do { \
323 CGUIMessage msg(bSelect?GUI_MSG_SET_SELECTED:GUI_MSG_SET_DESELECTED, dwSenderId, controlID); \
324 OnMessage(msg); \
325} while(0)
326
327/*!
328\ingroup winmsg
329\brief Click message sent from controls to windows.
330 */
331#define SEND_CLICK_MESSAGE(id, parentID, action) \
332do { \
333 CGUIMessage msg(GUI_MSG_CLICKED, id, parentID, action); \
334 SendWindowMessage(msg); \
335} while(0)
336
337#include <string>
338#include <vector>
339#include <memory>
340
341// forwards
342class CGUIListItem; typedef std::shared_ptr<CGUIListItem> CGUIListItemPtr;
343class CFileItemList;
344
345/*!
346 \ingroup winmsg
347 \brief
348 */
349class CGUIMessage final
350{
351public:
352  CGUIMessage(int dwMsg, int senderID, int controlID, int param1 = 0, int param2 = 0);
353  CGUIMessage(int msg, int senderID, int controlID, int param1, int param2, CFileItemList* item);
354  CGUIMessage(int msg, int senderID, int controlID, int param1, int param2, const CGUIListItemPtr &item);
355  CGUIMessage(const CGUIMessage& msg);
356  ~CGUIMessage(void);
357  CGUIMessage& operator = (const CGUIMessage& msg);
358
359  int GetControlId() const ;
360  int GetMessage() const;
361  void* GetPointer() const;
362  CGUIListItemPtr GetItem() const;
363  int GetParam1() const;
364  int GetParam2() const;
365  int GetSenderId() const;
366  void SetParam1(int param1);
367  void SetParam2(int param2);
368  void SetPointer(void* pointer);
369  void SetLabel(const std::string& strLabel);
370  void SetLabel(int iString);               // for convenience - looks up in strings.po
371  const std::string& GetLabel() const;
372  void SetStringParam(const std::string &strParam);
373  void SetStringParams(const std::vector<std::string> &params);
374  const std::string& GetStringParam(size_t param = 0) const;
375  size_t GetNumStringParams() const;
376
377private:
378  std::string m_strLabel;
379  std::vector<std::string> m_params;
380  int m_senderID;
381  int m_controlID;
382  int m_message;
383  void* m_pointer;
384  int m_param1;
385  int m_param2;
386  CGUIListItemPtr m_item;
387
388  static std::string empty_string;
389};
390