kodi
Window.h
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 #include "addons/kodi-dev-kit/include/kodi/c-api/gui/window.h"
12 #include "threads/Event.h"
13 #include "windows/GUIMediaWindow.h"
14 
15 extern "C"
16 {
17 
18  struct AddonGlobalInterface;
19  struct gui_context_menu_pair;
20 
21  namespace ADDON
22  {
23  class CAddonDll;
24 
34  {
35  static void Init(AddonGlobalInterface* addonInterface);
36  static void DeInit(AddonGlobalInterface* addonInterface);
37 
49  /* Window creation functions */
50  static KODI_GUI_WINDOW_HANDLE create(KODI_HANDLE kodiBase,
51  const char* xml_filename,
52  const char* default_skin,
53  bool as_dialog,
54  bool is_media);
55  static void destroy(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
56  static void set_callbacks(KODI_HANDLE kodiBase,
57  KODI_GUI_WINDOW_HANDLE handle,
58  KODI_GUI_CLIENT_HANDLE clienthandle,
59  bool (*CBInit)(KODI_GUI_CLIENT_HANDLE),
60  bool (*CBFocus)(KODI_GUI_CLIENT_HANDLE, int),
61  bool (*CBClick)(KODI_GUI_CLIENT_HANDLE, int),
62  bool (*CBOnAction)(KODI_GUI_CLIENT_HANDLE, ADDON_ACTION),
63  void (*CBGetContextButtons)(KODI_GUI_CLIENT_HANDLE,
64  int,
66  unsigned int*),
67  bool (*CBOnContextButton)(KODI_GUI_CLIENT_HANDLE, int, unsigned int));
68  static bool show(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
69  static bool close(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
70  static bool do_modal(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
71 
72  /* Window control functions */
73  static bool set_focus_id(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle, int control_id);
74  static int get_focus_id(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
75  static void set_control_label(KODI_HANDLE kodiBase,
76  KODI_GUI_WINDOW_HANDLE handle,
77  int control_id,
78  const char* label);
79  static void set_control_visible(KODI_HANDLE kodiBase,
80  KODI_GUI_WINDOW_HANDLE handle,
81  int control_id,
82  bool visible);
83  static void set_control_selected(KODI_HANDLE kodiBase,
84  KODI_GUI_WINDOW_HANDLE handle,
85  int control_id,
86  bool selected);
87 
88  /* Window property functions */
89  static void set_property(KODI_HANDLE kodiBase,
90  KODI_GUI_WINDOW_HANDLE handle,
91  const char* key,
92  const char* value);
93  static void set_property_int(KODI_HANDLE kodiBase,
94  KODI_GUI_WINDOW_HANDLE handle,
95  const char* key,
96  int value);
97  static void set_property_bool(KODI_HANDLE kodiBase,
98  KODI_GUI_WINDOW_HANDLE handle,
99  const char* key,
100  bool value);
101  static void set_property_double(KODI_HANDLE kodiBase,
102  KODI_GUI_WINDOW_HANDLE handle,
103  const char* key,
104  double value);
105  static char* get_property(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle, const char* key);
106  static int get_property_int(KODI_HANDLE kodiBase,
107  KODI_GUI_WINDOW_HANDLE handle,
108  const char* key);
109  static bool get_property_bool(KODI_HANDLE kodiBase,
110  KODI_GUI_WINDOW_HANDLE handle,
111  const char* key);
112  static double get_property_double(KODI_HANDLE kodiBase,
113  KODI_GUI_WINDOW_HANDLE handle,
114  const char* key);
115  static void clear_properties(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
116  static void clear_property(KODI_HANDLE kodiBase,
117  KODI_GUI_WINDOW_HANDLE handle,
118  const char* key);
119 
120  /* List item functions */
121  static void clear_item_list(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
122  static void add_list_item(KODI_HANDLE kodiBase,
123  KODI_GUI_WINDOW_HANDLE handle,
124  KODI_GUI_LISTITEM_HANDLE item,
125  int list_position);
126  static void remove_list_item_from_position(KODI_HANDLE kodiBase,
127  KODI_GUI_WINDOW_HANDLE handle,
128  int list_position);
129  static void remove_list_item(KODI_HANDLE kodiBase,
130  KODI_GUI_WINDOW_HANDLE handle,
131  KODI_GUI_LISTITEM_HANDLE item);
132  static KODI_GUI_LISTITEM_HANDLE get_list_item(KODI_HANDLE kodiBase,
133  KODI_GUI_WINDOW_HANDLE handle,
134  int list_position);
135  static void set_current_list_position(KODI_HANDLE kodiBase,
136  KODI_GUI_WINDOW_HANDLE handle,
137  int list_position);
138  static int get_current_list_position(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
139  static int get_list_size(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
140  static void set_container_property(KODI_HANDLE kodiBase,
141  KODI_GUI_WINDOW_HANDLE handle,
142  const char* key,
143  const char* value);
144  static void set_container_content(KODI_HANDLE kodiBase,
145  KODI_GUI_WINDOW_HANDLE handle,
146  const char* value);
147  static int get_current_container_id(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
148 
149  /* Various functions */
150  static void mark_dirty_region(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
151 
152  /* GUI control access functions */
153  static KODI_GUI_CONTROL_HANDLE get_control_button(KODI_HANDLE kodiBase,
154  KODI_GUI_WINDOW_HANDLE handle,
155  int control_id);
156  static KODI_GUI_CONTROL_HANDLE get_control_edit(KODI_HANDLE kodiBase,
157  KODI_GUI_WINDOW_HANDLE handle,
158  int control_id);
159  static KODI_GUI_CONTROL_HANDLE get_control_fade_label(KODI_HANDLE kodiBase,
160  KODI_GUI_WINDOW_HANDLE handle,
161  int control_id);
162  static KODI_GUI_CONTROL_HANDLE get_control_image(KODI_HANDLE kodiBase,
163  KODI_GUI_WINDOW_HANDLE handle,
164  int control_id);
165  static KODI_GUI_CONTROL_HANDLE get_control_label(KODI_HANDLE kodiBase,
166  KODI_GUI_WINDOW_HANDLE handle,
167  int control_id);
168  static KODI_GUI_CONTROL_HANDLE get_control_radio_button(KODI_HANDLE kodiBase,
169  KODI_GUI_WINDOW_HANDLE handle,
170  int control_id);
171  static KODI_GUI_CONTROL_HANDLE get_control_progress(KODI_HANDLE kodiBase,
172  KODI_GUI_WINDOW_HANDLE handle,
173  int control_id);
174  static KODI_GUI_CONTROL_HANDLE get_control_render_addon(KODI_HANDLE kodiBase,
175  KODI_GUI_WINDOW_HANDLE handle,
176  int control_id);
177  static KODI_GUI_CONTROL_HANDLE get_control_settings_slider(KODI_HANDLE kodiBase,
178  KODI_GUI_WINDOW_HANDLE handle,
179  int control_id);
180  static KODI_GUI_CONTROL_HANDLE get_control_slider(KODI_HANDLE kodiBase,
181  KODI_GUI_WINDOW_HANDLE handle,
182  int control_id);
183  static KODI_GUI_CONTROL_HANDLE get_control_spin(KODI_HANDLE kodiBase,
184  KODI_GUI_WINDOW_HANDLE handle,
185  int control_id);
186  static KODI_GUI_CONTROL_HANDLE get_control_text_box(KODI_HANDLE kodiBase,
187  KODI_GUI_WINDOW_HANDLE handle,
188  int control_id);
190 
191  private:
192  static KODI_GUI_CONTROL_HANDLE GetControl(KODI_HANDLE kodiBase,
193  KODI_GUI_WINDOW_HANDLE handle,
194  int control_id,
195  const char* function,
196  CGUIControl::GUICONTROLTYPES type,
197  const std::string& typeName);
198  static int GetNextAvailableWindowId();
199  };
200 
202  {
203  friend struct Interface_GUIWindow;
204 
205  public:
206  CGUIAddonWindow(int id, const std::string& strXML, ADDON::CAddonDll* addon, bool isMedia);
207  ~CGUIAddonWindow() override = default;
208 
209  bool OnMessage(CGUIMessage& message) override;
210  bool OnAction(const CAction& action) override;
211  void AllocResources(bool forceLoad = false) override;
212  void Render() override;
213  bool IsMediaWindow() const override { return m_isMedia; }
214 
215  /* Addon to Kodi call functions */
216  void PulseActionEvent();
217  void AddItem(CFileItemPtr* fileItem, int itemPosition);
218  void RemoveItem(int itemPosition);
219  void RemoveItem(CFileItemPtr* fileItem);
220  void ClearList();
221  CFileItemPtr* GetListItem(int position);
222  int GetListSize();
223  int GetCurrentListPosition();
224  void SetCurrentListPosition(int item);
225  void SetContainerProperty(const std::string& key, const std::string& value);
226  void SetContainerContent(const std::string& value);
227  int GetCurrentContainerControlId();
228  CGUIControl* GetAddonControl(int controlId,
229  CGUIControl::GUICONTROLTYPES type,
230  const std::string& typeName);
231 
232  protected:
233  void GetContextButtons(int itemNumber, CContextButtons& buttons) override;
234  bool OnContextButton(int itemNumber, CONTEXT_BUTTON button) override;
235  void SetupShares() override;
236 
237  /* kodi to addon callback function addresses */
238  KODI_GUI_CLIENT_HANDLE m_clientHandle = nullptr;
239  bool (*CBOnInit)(KODI_GUI_CLIENT_HANDLE cbhdl) = nullptr;
240  bool (*CBOnFocus)(KODI_GUI_CLIENT_HANDLE cbhdl, int controlId) = nullptr;
241  bool (*CBOnClick)(KODI_GUI_CLIENT_HANDLE cbhdl, int controlId) = nullptr;
242  bool (*CBOnAction)(KODI_GUI_CLIENT_HANDLE cbhdl, ADDON_ACTION actionId) = nullptr;
243  void (*CBGetContextButtons)(KODI_GUI_CLIENT_HANDLE cbhdl,
244  int itemNumber,
245  gui_context_menu_pair* buttons,
246  unsigned int* size) = nullptr;
247  bool (*CBOnContextButton)(KODI_GUI_CLIENT_HANDLE cbhdl,
248  int itemNumber,
249  unsigned int button) = nullptr;
250 
251  const int m_windowId;
252  int m_oldWindowId = 0;
253 
254  private:
255  void WaitForActionEvent(unsigned int timeout);
256 
257  CEvent m_actionEvent;
258  ADDON::CAddonDll* m_addon;
259  std::string m_mediaDir;
260  bool m_isMedia;
261  };
262 
264  {
265  public:
266  CGUIAddonWindowDialog(int id, const std::string& strXML, ADDON::CAddonDll* addon);
267 
268  bool IsDialogRunning() const override { return m_bRunning; }
269  bool IsDialog() const override { return true; }
270  bool IsModalDialog() const override { return true; }
271 
272  void Show(bool show = true, bool modal = true);
273  void Show_Internal(bool show = true);
274 
275  private:
276  bool m_bRunning = false;
277  };
278 
279  } /* namespace ADDON */
280 } /* extern "C" */
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: AddonDll.h:51
static bool set_focus_id(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle, int control_id)
Definition: Window.cpp:366
ADDON_ACTION
Definition: action_ids.h:18
static void clear_item_list(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle)
Definition: Window.cpp:745
Base class for controls.
Definition: GUIControl.h:83
Main structure passed from kodi to addon with basic information needed to create add-on.
Definition: addon_base.h:378
Global gui Add-on to Kodi callback functions.
Definition: Window.h:33
Definition: window.h:25
Class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:21
static KODI_GUI_CONTROL_HANDLE get_control_button(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle, int control_id)
Definition: Window.cpp:1026
Definition: Window.h:263
Definition: Window.h:201
Definition: GUIMessage.h:365
static KODI_GUI_WINDOW_HANDLE create(KODI_HANDLE kodiBase, const char *xml_filename, const char *default_skin, bool as_dialog, bool is_media)
callback functions from add-on to kodi
Definition: Window.cpp:111
static void mark_dirty_region(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle)
Definition: Window.cpp:1003
Definition: GUIMediaWindow.h:28
Definition: Addon.cpp:39
Definition: GUIDialogContextMenu.h:93
static void set_property(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle, const char *key, const char *value)
Definition: Window.cpp:494