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
|
/*
* 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
#include "addons/kodi-dev-kit/include/kodi/c-api/gui/window.h"
#include "threads/Event.h"
#include "windows/GUIMediaWindow.h"
extern "C"
{
struct AddonGlobalInterface;
struct gui_context_menu_pair;
namespace ADDON
{
class CAddonDll;
/*!
* @brief Global gui Add-on to Kodi callback functions
*
* To hold functions not related to a instance type and usable for
* every add-on type.
*
* Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/Window.h"
*/
struct Interface_GUIWindow
{
static void Init(AddonGlobalInterface* addonInterface);
static void DeInit(AddonGlobalInterface* addonInterface);
/*!
* @brief callback functions from add-on to kodi
*
* @note To add a new function use the "_" style to directly identify an
* add-on callback function. Everything with CamelCase is only to be used
* in Kodi.
*
* The parameter `kodiBase` is used to become the pointer for a `CAddonDll`
* class.
*/
//@{
/* Window creation functions */
static KODI_GUI_WINDOW_HANDLE create(KODI_HANDLE kodiBase,
const char* xml_filename,
const char* default_skin,
bool as_dialog,
bool is_media);
static void destroy(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
static void set_callbacks(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
KODI_GUI_CLIENT_HANDLE clienthandle,
bool (*CBInit)(KODI_GUI_CLIENT_HANDLE),
bool (*CBFocus)(KODI_GUI_CLIENT_HANDLE, int),
bool (*CBClick)(KODI_GUI_CLIENT_HANDLE, int),
bool (*CBOnAction)(KODI_GUI_CLIENT_HANDLE, ADDON_ACTION),
void (*CBGetContextButtons)(KODI_GUI_CLIENT_HANDLE,
int,
gui_context_menu_pair*,
unsigned int*),
bool (*CBOnContextButton)(KODI_GUI_CLIENT_HANDLE, int, unsigned int));
static bool show(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
static bool close(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
static bool do_modal(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
/* Window control functions */
static bool set_focus_id(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle, int control_id);
static int get_focus_id(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
static void set_control_label(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id,
const char* label);
static void set_control_visible(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id,
bool visible);
static void set_control_selected(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id,
bool selected);
/* Window property functions */
static void set_property(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
const char* key,
const char* value);
static void set_property_int(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
const char* key,
int value);
static void set_property_bool(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
const char* key,
bool value);
static void set_property_double(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
const char* key,
double value);
static char* get_property(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle, const char* key);
static int get_property_int(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
const char* key);
static bool get_property_bool(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
const char* key);
static double get_property_double(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
const char* key);
static void clear_properties(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
static void clear_property(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
const char* key);
/* List item functions */
static void clear_item_list(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
static void add_list_item(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
KODI_GUI_LISTITEM_HANDLE item,
int list_position);
static void remove_list_item_from_position(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int list_position);
static void remove_list_item(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
KODI_GUI_LISTITEM_HANDLE item);
static KODI_GUI_LISTITEM_HANDLE get_list_item(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int list_position);
static void set_current_list_position(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int list_position);
static int get_current_list_position(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
static int get_list_size(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
static void set_container_property(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
const char* key,
const char* value);
static void set_container_content(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
const char* value);
static int get_current_container_id(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
/* Various functions */
static void mark_dirty_region(KODI_HANDLE kodiBase, KODI_GUI_WINDOW_HANDLE handle);
/* GUI control access functions */
static KODI_GUI_CONTROL_HANDLE get_control_button(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_edit(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_fade_label(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_image(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_label(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_radio_button(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_progress(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_render_addon(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_settings_slider(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_slider(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_spin(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
static KODI_GUI_CONTROL_HANDLE get_control_text_box(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id);
//@}
private:
static KODI_GUI_CONTROL_HANDLE GetControl(KODI_HANDLE kodiBase,
KODI_GUI_WINDOW_HANDLE handle,
int control_id,
const char* function,
CGUIControl::GUICONTROLTYPES type,
const std::string& typeName);
static int GetNextAvailableWindowId();
};
class CGUIAddonWindow : public CGUIMediaWindow
{
friend struct Interface_GUIWindow;
public:
CGUIAddonWindow(int id, const std::string& strXML, ADDON::CAddonDll* addon, bool isMedia);
~CGUIAddonWindow() override = default;
bool OnMessage(CGUIMessage& message) override;
bool OnAction(const CAction& action) override;
void AllocResources(bool forceLoad = false) override;
void Render() override;
bool IsMediaWindow() const override { return m_isMedia; }
/* Addon to Kodi call functions */
void PulseActionEvent();
void AddItem(CFileItemPtr* fileItem, int itemPosition);
void RemoveItem(int itemPosition);
void RemoveItem(CFileItemPtr* fileItem);
void ClearList();
CFileItemPtr* GetListItem(int position);
int GetListSize();
int GetCurrentListPosition();
void SetCurrentListPosition(int item);
void SetContainerProperty(const std::string& key, const std::string& value);
void SetContainerContent(const std::string& value);
int GetCurrentContainerControlId();
CGUIControl* GetAddonControl(int controlId,
CGUIControl::GUICONTROLTYPES type,
const std::string& typeName);
protected:
void GetContextButtons(int itemNumber, CContextButtons& buttons) override;
bool OnContextButton(int itemNumber, CONTEXT_BUTTON button) override;
void SetupShares() override;
/* kodi to addon callback function addresses */
KODI_GUI_CLIENT_HANDLE m_clientHandle;
bool (*CBOnInit)(KODI_GUI_CLIENT_HANDLE cbhdl);
bool (*CBOnFocus)(KODI_GUI_CLIENT_HANDLE cbhdl, int controlId);
bool (*CBOnClick)(KODI_GUI_CLIENT_HANDLE cbhdl, int controlId);
bool (*CBOnAction)(KODI_GUI_CLIENT_HANDLE cbhdl, ADDON_ACTION actionId);
void (*CBGetContextButtons)(KODI_GUI_CLIENT_HANDLE cbhdl,
int itemNumber,
gui_context_menu_pair* buttons,
unsigned int* size);
bool (*CBOnContextButton)(KODI_GUI_CLIENT_HANDLE cbhdl, int itemNumber, unsigned int button);
const int m_windowId;
int m_oldWindowId;
private:
void WaitForActionEvent(unsigned int timeout);
CEvent m_actionEvent;
ADDON::CAddonDll* m_addon;
std::string m_mediaDir;
bool m_isMedia;
};
class CGUIAddonWindowDialog : public CGUIAddonWindow
{
public:
CGUIAddonWindowDialog(int id, const std::string& strXML, ADDON::CAddonDll* addon);
bool IsDialogRunning() const override { return m_bRunning; }
bool IsDialog() const override { return true; }
bool IsModalDialog() const override { return true; }
void Show(bool show = true, bool modal = true);
void Show_Internal(bool show = true);
private:
bool m_bRunning;
};
} /* namespace ADDON */
} /* extern "C" */
|