summaryrefslogtreecommitdiffstats
path: root/xbmc/guilib/GUIMessage.h
blob: 2fc670224acfde22aec3d2968201f834bb3a0545 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

/*!
\file GUIMessage.h
\brief
*/

constexpr const int GUI_MSG_WINDOW_INIT    = 1;  // initialize window
constexpr const int GUI_MSG_WINDOW_DEINIT  = 2;  // deinit window
constexpr const int GUI_MSG_WINDOW_RESET   = 27; // reset window to initial state

constexpr const int GUI_MSG_SETFOCUS       = 3;  // set focus to control param1=up/down/left/right
constexpr const int GUI_MSG_LOSTFOCUS      = 4;  // control lost focus

constexpr const int GUI_MSG_CLICKED        = 5;  // control has been clicked

constexpr const int GUI_MSG_VISIBLE        = 6;  // set control visible
constexpr const int GUI_MSG_HIDDEN         = 7;   // set control hidden

constexpr const int GUI_MSG_ENABLED        = 8;   // enable control
constexpr const int GUI_MSG_DISABLED       = 9;   // disable control

constexpr const int GUI_MSG_SET_SELECTED   = 10;   // control = selected
constexpr const int GUI_MSG_SET_DESELECTED = 11;   // control = not selected

constexpr const int GUI_MSG_LABEL_ADD      = 12;   // add label control (for controls supporting more then 1 label)

constexpr const int GUI_MSG_LABEL_SET      = 13;  // set the label of a control

constexpr const int GUI_MSG_LABEL_RESET    = 14;  // clear all labels of a control // add label control (for controls supporting more then 1 label)

constexpr const int GUI_MSG_ITEM_SELECTED  = 15;  // ask control 2 return the selected item
constexpr const int GUI_MSG_ITEM_SELECT    = 16;  // ask control 2 select a specific item
constexpr const int GUI_MSG_LABEL2_SET     = 17;
constexpr const int GUI_MSG_SHOWRANGE      = 18;

constexpr const int GUI_MSG_FULLSCREEN     = 19;  // should go to fullscreen window (vis or video)
constexpr const int GUI_MSG_EXECUTE        = 20;  // user has clicked on a button with <execute> tag

constexpr const int GUI_MSG_NOTIFY_ALL     = 21;  // message will be send to all active and inactive(!) windows, all active modal and modeless dialogs
                                  // dwParam1 must contain an additional message the windows should react on

constexpr const int GUI_MSG_REFRESH_THUMBS = 22; // message is sent to all windows to refresh all thumbs

constexpr const int GUI_MSG_MOVE           = 23; // message is sent to the window from the base control class when it's
                                 // been asked to move.  dwParam1 contains direction.

constexpr const int GUI_MSG_LABEL_BIND     = 24;   // bind label control (for controls supporting more then 1 label)

constexpr const int GUI_MSG_FOCUSED        = 26;  // a control has become focused

constexpr const int GUI_MSG_PAGE_CHANGE    = 28;  // a page control has changed the page number

constexpr const int GUI_MSG_REFRESH_LIST   = 29; // message sent to all listing controls telling them to refresh their item layouts

constexpr const int GUI_MSG_PAGE_UP      = 30; // page up
constexpr const int GUI_MSG_PAGE_DOWN    = 31; // page down
constexpr const int GUI_MSG_MOVE_OFFSET  = 32; // Instruct the control to MoveUp or MoveDown by offset amount

constexpr const int GUI_MSG_SET_TYPE     = 33; ///< Instruct a control to set it's type appropriately

/*!
 \brief Message indicating the window has been resized
 Any controls that keep stored sizing information based on aspect ratio or window size should
 recalculate sizing information
 */
constexpr const int GUI_MSG_WINDOW_RESIZE  = 34;

/*!
 \brief Message indicating loss of renderer, prior to reset
 Any controls that keep shared resources should free them on receipt of this message, as the renderer
 is about to be reset.
 */
constexpr const int GUI_MSG_RENDERER_LOST = 35;

/*!
 \brief Message indicating regain of renderer, after reset
 Any controls that keep shared resources may reallocate them now that the renderer is back
 */
constexpr const int GUI_MSG_RENDERER_RESET = 36;

/*!
 \brief A control wishes to have (or release) exclusive access to mouse actions
 */
constexpr const int GUI_MSG_EXCLUSIVE_MOUSE = 37;

/*!
 \brief A request for supported gestures is made
 */
constexpr const int GUI_MSG_GESTURE_NOTIFY = 38;

/*!
 \brief A request to add a control
 */
constexpr const int GUI_MSG_ADD_CONTROL = 39;

/*!
 \brief A request to remove a control
 */
constexpr const int GUI_MSG_REMOVE_CONTROL = 40;

/*!
 \brief A request to unfocus all currently focused controls
 */
constexpr const int GUI_MSG_UNFOCUS_ALL = 41;

constexpr const int GUI_MSG_SET_TEXT    = 42;

constexpr const int GUI_MSG_WINDOW_LOAD = 43;

constexpr const int GUI_MSG_VALIDITY_CHANGED = 44;

/*!
 \brief Check whether a button is selected
 */
constexpr const int GUI_MSG_IS_SELECTED  = 45;

/*!
 \brief Bind a set of labels to a spin (or similar) control
 */
constexpr const int GUI_MSG_SET_LABELS = 46;

/*!
 \brief Set the filename for an image control
 */
constexpr const int GUI_MSG_SET_FILENAME = 47;

/*!
 \brief Get the filename of an image control
 */

constexpr const int GUI_MSG_GET_FILENAME  = 48;

/*!
 \brief The user interface is ready for usage
 */
constexpr const int GUI_MSG_UI_READY = 49;

 /*!
 \brief Called every 500ms to allow time dependent updates
 */
constexpr const int GUI_MSG_REFRESH_TIMER = 50;

 /*!
 \brief Called if state has changed which could lead to GUI changes
 */
constexpr const int GUI_MSG_STATE_CHANGED = 51;

/*!
 \brief Called when a subtitle download has finished
 */
constexpr const int GUI_MSG_SUBTITLE_DOWNLOADED = 52;


constexpr const int GUI_MSG_USER = 1000;

/*!
\brief Complete to get codingtable page
*/
constexpr const int GUI_MSG_CODINGTABLE_LOOKUP_COMPLETED = 65000;

/*!
 \ingroup winmsg
 \brief
 */
#define CONTROL_SELECT(controlID) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_SET_SELECTED, GetID(), controlID); \
    OnMessage(_msg); \
  } while (0)

/*!
 \ingroup winmsg
 \brief
 */
#define CONTROL_DESELECT(controlID) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_SET_DESELECTED, GetID(), controlID); \
    OnMessage(_msg); \
  } while (0)


/*!
 \ingroup winmsg
 \brief
 */
#define CONTROL_ENABLE(controlID) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_ENABLED, GetID(), controlID); \
    OnMessage(_msg); \
  } while (0)

/*!
 \ingroup winmsg
 \brief
 */
#define CONTROL_DISABLE(controlID) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_DISABLED, GetID(), controlID); \
    OnMessage(_msg); \
  } while (0)


/*!
 \ingroup winmsg
 \brief
 */
#define CONTROL_ENABLE_ON_CONDITION(controlID, bCondition) \
  do \
  { \
    CGUIMessage _msg(bCondition ? GUI_MSG_ENABLED : GUI_MSG_DISABLED, GetID(), controlID); \
    OnMessage(_msg); \
  } while (0)


/*!
 \ingroup winmsg
 \brief
 */
#define CONTROL_SELECT_ITEM(controlID, iItem) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_ITEM_SELECT, GetID(), controlID, iItem); \
    OnMessage(_msg); \
  } while (0)

/*!
 \ingroup winmsg
 \brief Set the label of the current control
 */
#define SET_CONTROL_LABEL(controlID, label) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_LABEL_SET, GetID(), controlID); \
    _msg.SetLabel(label); \
    OnMessage(_msg); \
  } while (0)

/*!
 \ingroup winmsg
 \brief Set the label of the current control
 */
#define SET_CONTROL_LABEL_THREAD_SAFE(controlID, label) \
  { \
    CGUIMessage _msg(GUI_MSG_LABEL_SET, GetID(), controlID); \
    _msg.SetLabel(label); \
    if (CServiceBroker::GetAppMessenger()->IsProcessThread()) \
      OnMessage(_msg); \
    else \
      CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(_msg, GetID()); \
  }

/*!
 \ingroup winmsg
 \brief Set the second label of the current control
 */
#define SET_CONTROL_LABEL2(controlID, label) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_LABEL2_SET, GetID(), controlID); \
    _msg.SetLabel(label); \
    OnMessage(_msg); \
  } while (0)

/*!
 \ingroup winmsg
 \brief Set a bunch of labels on the given control
 */
#define SET_CONTROL_LABELS(controlID, defaultValue, labels) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_SET_LABELS, GetID(), controlID, defaultValue); \
    _msg.SetPointer(labels); \
    OnMessage(_msg); \
  } while (0)

/*!
 \ingroup winmsg
 \brief Set the label of the current control
 */
#define SET_CONTROL_FILENAME(controlID, label) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_SET_FILENAME, GetID(), controlID); \
    _msg.SetLabel(label); \
    OnMessage(_msg); \
  } while (0)

/*!
 \ingroup winmsg
 \brief
 */
#define SET_CONTROL_HIDDEN(controlID) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_HIDDEN, GetID(), controlID); \
    OnMessage(_msg); \
  } while (0)

/*!
 \ingroup winmsg
 \brief
 */
#define SET_CONTROL_FOCUS(controlID, dwParam) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_SETFOCUS, GetID(), controlID, dwParam); \
    OnMessage(_msg); \
  } while (0)

/*!
 \ingroup winmsg
 \brief
 */
#define SET_CONTROL_VISIBLE(controlID) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_VISIBLE, GetID(), controlID); \
    OnMessage(_msg); \
  } while (0)

#define SET_CONTROL_SELECTED(dwSenderId, controlID, bSelect) \
  do \
  { \
    CGUIMessage _msg(bSelect ? GUI_MSG_SET_SELECTED : GUI_MSG_SET_DESELECTED, dwSenderId, \
                     controlID); \
    OnMessage(_msg); \
  } while (0)

/*!
\ingroup winmsg
\brief Click message sent from controls to windows.
 */
#define SEND_CLICK_MESSAGE(id, parentID, action) \
  do \
  { \
    CGUIMessage _msg(GUI_MSG_CLICKED, id, parentID, action); \
    SendWindowMessage(_msg); \
  } while (0)

#include <string>
#include <vector>
#include <memory>

// forwards
class CGUIListItem; typedef std::shared_ptr<CGUIListItem> CGUIListItemPtr;
class CFileItemList;

/*!
 \ingroup winmsg
 \brief
 */
class CGUIMessage final
{
public:
  CGUIMessage(int dwMsg, int senderID, int controlID, int param1 = 0, int param2 = 0);
  CGUIMessage(int msg, int senderID, int controlID, int param1, int param2, CFileItemList* item);
  CGUIMessage(int msg, int senderID, int controlID, int param1, int param2, const CGUIListItemPtr &item);
  CGUIMessage(const CGUIMessage& msg);
  ~CGUIMessage(void);
  CGUIMessage& operator = (const CGUIMessage& msg);

  int GetControlId() const ;
  int GetMessage() const;
  void* GetPointer() const;
  CGUIListItemPtr GetItem() const;
  int GetParam1() const;
  int GetParam2() const;
  int GetSenderId() const;
  void SetParam1(int param1);
  void SetParam2(int param2);
  void SetPointer(void* pointer);
  void SetLabel(const std::string& strLabel);
  void SetLabel(int iString);               // for convenience - looks up in strings.po
  const std::string& GetLabel() const;
  void SetStringParam(const std::string &strParam);
  void SetStringParams(const std::vector<std::string> &params);
  const std::string& GetStringParam(size_t param = 0) const;
  size_t GetNumStringParams() const;
  void SetItem(CGUIListItemPtr item);

private:
  std::string m_strLabel;
  std::vector<std::string> m_params;
  int m_senderID;
  int m_controlID;
  int m_message;
  void* m_pointer;
  int m_param1;
  int m_param2;
  CGUIListItemPtr m_item;

  static std::string empty_string;
};