/xbmc/guilib/GUIMessage.h

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