summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/Window.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2017-06-04 16:57:49 +0200
committermanuel <manuel@mausz.at>2017-06-04 16:57:49 +0200
commitf44ecaa4f27e7538ddcad66d40e543bffa2d2d86 (patch)
treed8de60fc7e17edeb6f0921726c038ee54b281445 /xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/Window.h
parentae08c8b7221bc965ac40d70e53fc8fcddb050c46 (diff)
downloadkodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.tar.gz
kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.tar.bz2
kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.zip
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/Window.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/Window.h503
1 files changed, 503 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/Window.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/Window.h
new file mode 100644
index 0000000..7069e63
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/Window.h
@@ -0,0 +1,503 @@
1#pragma once
2/*
3 * Copyright (C) 2005-2017 Team Kodi
4 * http://kodi.tv
5 *
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with KODI; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include "../AddonBase.h"
23#include "ListItem.h"
24
25#ifdef BUILD_KODI_ADDON
26#include "../ActionIDs.h"
27#else
28#include "input/ActionIDs.h"
29#endif
30
31namespace kodi
32{
33namespace gui
34{
35
36 class CListItem;
37
38 //============================================================================
39 ///
40 /// \defgroup cpp_kodi_gui_CWindow Window
41 /// \ingroup cpp_kodi_gui
42 /// @brief \cpp_class{ kodi::gui::CWindow }
43 /// **Main window control class**
44 ///
45 /// The with \ref Window.h "#include <kodi/gui/Window.h>"
46 /// included file brings support to create a window or dialog on Kodi.
47 ///
48 /// --------------------------------------------------------------------------
49 ///
50 /// On functions defined input variable <b><tt>controlId</tt> (GUI control identifier)</b>
51 /// is the on window.xml defined value behind type added with <tt><b>id="..."</b></tt> and
52 /// used to identify for changes there and on callbacks.
53 ///
54 /// ~~~~~~~~~~~~~{.xml}
55 /// <control type="label" id="31">
56 /// <description>Title Label</description>
57 /// ...
58 /// </control>
59 /// <control type="progress" id="32">
60 /// <description>progress control</description>
61 /// ...
62 /// </control>
63 /// ~~~~~~~~~~~~~
64 ///
65 ///
66
67 //============================================================================
68 ///
69 /// \defgroup cpp_kodi_gui_CWindow_Defs Definitions, structures and enumerators
70 /// \ingroup cpp_kodi_gui_CWindow
71 /// @brief <b>Library definition values</b>
72 ///
73
74 class CWindow : public CAddonGUIControlBase
75 {
76 public:
77 //==========================================================================
78 ///
79 /// \ingroup cpp_kodi_gui_CWindow
80 /// @brief Class constructor with needed values for window / dialog.
81 ///
82 /// Creates a new Window class.
83 ///
84 /// @param[in] xmlFilename XML file for the skin
85 /// @param[in] defaultSkin default skin to use if needed not available
86 /// @param[in] asDialog Use window as dialog if set
87 /// @param[in] isMedia [opt] bool - if False, create a regular window.
88 /// if True, create a mediawindow.
89 /// (default=false)
90 /// @note only usable for windows not for dialogs.
91 ///
92 ///
93 CWindow(const std::string& xmlFilename, const std::string& defaultSkin, bool asDialog, bool isMedia = false)
94 : CAddonGUIControlBase(nullptr)
95 {
96 m_controlHandle = m_interface->kodi_gui->window->create(m_interface->kodiBase, xmlFilename.c_str(),
97 defaultSkin.c_str(), asDialog, isMedia);
98 if (!m_controlHandle)
99 kodi::Log(ADDON_LOG_FATAL, "kodi::gui::CWindow can't create window class from Kodi !!!");
100 m_interface->kodi_gui->window->set_callbacks(m_interface->kodiBase, m_controlHandle, this,
101 CBOnInit, CBOnFocus, CBOnClick, CBOnAction,
102 CBGetContextButtons, CBOnContextButton);
103 }
104 //--------------------------------------------------------------------------
105
106 //==========================================================================
107 ///
108 /// \ingroup CWindow
109 /// @brief Class destructor
110 ///
111 ///
112 ///
113 virtual ~CWindow()
114 {
115 if (m_controlHandle)
116 m_interface->kodi_gui->window->destroy(m_interface->kodiBase, m_controlHandle);
117 }
118 //--------------------------------------------------------------------------
119
120 //==========================================================================
121 ///
122 /// \ingroup cpp_kodi_gui_CWindow
123 /// @brief Show this window.
124 ///
125 /// Shows this window by activating it, calling close() after it wil activate the
126 /// current window again.
127 ///
128 /// @note If your Add-On ends this window will be closed to. To show it forever,
129 /// make a loop at the end of your Add-On or use doModal() instead.
130 ///
131 /// @return Return true if call and show is successed,
132 /// if false was something failed to get needed
133 /// skin parts.
134 ///
135 bool Show()
136 {
137 return m_interface->kodi_gui->window->show(m_interface->kodiBase, m_controlHandle);
138 }
139 //--------------------------------------------------------------------------
140
141 //==========================================================================
142 ///
143 /// \ingroup cpp_kodi_gui_CWindow
144 /// @brief Closes this window.
145 ///
146 /// Closes this window by activating the old window.
147 /// @note The window is not deleted with this method.
148 ///
149 void Close()
150 {
151 m_interface->kodi_gui->window->close(m_interface->kodiBase, m_controlHandle);
152 }
153 //--------------------------------------------------------------------------
154
155 //==========================================================================
156 ///
157 /// \ingroup cpp_kodi_gui_CWindow
158 /// @brief Display this window until close() is called.
159 ///
160 void DoModal()
161 {
162 m_interface->kodi_gui->window->do_modal(m_interface->kodiBase, m_controlHandle);
163 }
164 //--------------------------------------------------------------------------
165
166 //==========================================================================
167 ///
168 /// \ingroup cpp_kodi_gui_CWindow
169 /// @brief Function delete all entries in integrated list.
170 ///
171 ///
172 ///
173 void ClearList()
174 {
175 m_interface->kodi_gui->window->clear_item_list(m_interface->kodiBase, m_controlHandle);
176 }
177 //--------------------------------------------------------------------------
178
179 //==========================================================================
180 ///
181 /// \ingroup cpp_kodi_gui_CWindow
182 /// @brief To add a list item in the on window integrated list.
183 ///
184 /// @param[in] item List item to add
185 /// @param[in] itemPosition [opt] The position for item, default is on end
186 ///
187 ///
188 void AddListItem(ListItemPtr item, int itemPosition = -1)
189 {
190 m_interface->kodi_gui->window->add_list_item(m_interface->kodiBase, m_controlHandle, item->m_controlHandle, itemPosition);
191 }
192 //--------------------------------------------------------------------------
193
194 //==========================================================================
195 ///
196 /// \ingroup cpp_kodi_gui_CWindow
197 /// @brief To add a list item based upon string in the on window integrated list.
198 ///
199 /// @param[in] item List item to add
200 /// @param[in] itemPosition [opt] The position for item, default is on end
201 ///
202 ///
203 void AddListItem(const std::string item, int itemPosition = -1)
204 {
205 m_interface->kodi_gui->window->add_list_item(m_interface->kodiBase, m_controlHandle, std::make_shared<kodi::gui::CListItem>(item)->m_controlHandle, itemPosition);
206 }
207 //--------------------------------------------------------------------------
208
209 //==========================================================================
210 ///
211 /// \ingroup cpp_kodi_gui_CWindow
212 /// @brief To get list item control class on wanted position.
213 ///
214 /// @param[in] listPos Position from where control is needed
215 /// @return The list item control class or null if not found
216 ///
217 /// @warning Function returns a new generated **CListItem** class!
218 ///
219 ListItemPtr GetListItem(int listPos)
220 {
221 GUIHANDLE handle = m_interface->kodi_gui->window->get_list_item(m_interface->kodiBase, m_controlHandle, listPos);
222 if (!handle)
223 return ListItemPtr();
224
225 return std::make_shared<kodi::gui::CListItem>(handle);
226 }
227 //--------------------------------------------------------------------------
228
229 //==========================================================================
230 //
231 /// @defgroup cpp_kodi_gui_CWindow_callbacks Callback functions from Kodi to add-on
232 /// \ingroup cpp_kodi_gui_CWindow
233 //@{
234 /// @brief <b>GUI window callback functions.</b>
235 ///
236 /// Functions to handle control callbacks from Kodi
237 ///
238 /// ------------------------------------------------------------------------
239 ///
240 /// @link cpp_kodi_gui_CWindow Go back to normal functions from CWindow@endlink
241 //
242
243 //==========================================================================
244 ///
245 /// \ingroup cpp_kodi_gui_CWindow_callbacks
246 /// @brief OnInit method.
247 ///
248 /// @return Return true if initialize was done successful
249 ///
250 ///
251 virtual bool OnInit() { return false; }
252 //--------------------------------------------------------------------------
253
254 //==========================================================================
255 ///
256 /// \ingroup cpp_kodi_gui_CWindow_callbacks
257 /// @brief OnFocus method.
258 ///
259 /// @param[in] controlId GUI control identifier
260 /// @return Return true if focus condition was handled there or false to handle them by Kodi itself
261 ///
262 ///
263 virtual bool OnFocus(int controlId) { return false; }
264 //--------------------------------------------------------------------------
265
266 //==========================================================================
267 ///
268 /// \ingroup cpp_kodi_gui_CWindow_callbacks
269 /// @brief OnClick method.
270 ///
271 /// @param[in] controlId GUI control identifier
272 /// @return Return true if click was handled there
273 /// or false to handle them by Kodi itself
274 ///
275 ///
276 virtual bool OnClick(int controlId) { return false; }
277 //--------------------------------------------------------------------------
278
279 //==========================================================================
280 ///
281 /// \ingroup cpp_kodi_gui_CWindow_callbacks
282 /// @brief OnAction method.
283 ///
284 /// @param[in] actionId The action id to perform, see
285 /// \ref kodi_key_action_ids to get list of
286 /// them
287 /// @return Return true if action was handled there
288 /// or false to handle them by Kodi itself
289 ///
290 ///
291 /// This method will receive all actions that the main program will send
292 /// to this window.
293 ///
294 /// @note
295 /// - By default, only the \c PREVIOUS_MENU and \c NAV_BACK actions are handled.
296 /// - Overwrite this method to let your code handle all actions.
297 /// - Don't forget to capture \c ACTION_PREVIOUS_MENU or \c ACTION_NAV_BACK, else the user can't close this window.
298 ///
299 ///
300 ///--------------------------------------------------------------------------
301 ///
302 /// **Example:**
303 /// ~~~~~~~~~~~~~{.cpp}
304 /// ..
305 /// /* Window used with parent / child way */
306 /// bool cYOUR_CLASS::OnAction(int actionId)
307 /// {
308 /// switch (action)
309 /// {
310 /// case ACTION_PREVIOUS_MENU:
311 /// case ACTION_NAV_BACK:
312 /// printf("action recieved: previous");
313 /// Close();
314 /// return true;
315 /// case ACTION_SHOW_INFO:
316 /// printf("action recieved: show info");
317 /// break;
318 /// case ACTION_STOP:
319 /// printf("action recieved: stop");
320 /// break;
321 /// case ACTION_PAUSE:
322 /// printf("action recieved: pause");
323 /// break;
324 /// default:
325 /// break;
326 /// }
327 /// return false;
328 /// }
329 /// ..
330 /// ~~~~~~~~~~~~~
331 ///
332 virtual bool OnAction(int actionId)
333 {
334 switch (actionId)
335 {
336 case ACTION_PREVIOUS_MENU:
337 case ACTION_NAV_BACK:
338 Close();
339 return true;
340 default:
341 break;
342 }
343 return false;
344 }
345 //--------------------------------------------------------------------------
346
347 //==========================================================================
348 ///
349 /// \ingroup cpp_kodi_gui_CWindow_callbacks
350 /// @brief Get context menu buttons for list entry
351 ///
352 /// @param[in] itemNumber selected list item entry
353 /// @param[in] buttons list where context menus becomes added with his
354 /// identifier and name.
355 ///
356 virtual void GetContextButtons(int itemNumber, std::vector< std::pair<unsigned int, std::string> > &buttons)
357 {
358 }
359 //--------------------------------------------------------------------------
360
361 //==========================================================================
362 ///
363 /// \ingroup cpp_kodi_gui_CWindow_callbacks
364 /// @brief Called after selection in context menu
365 ///
366 /// @param[in] itemNumber selected list item entry
367 /// @param[in] button the pressed button id
368 /// @return true if handled, otherwise false
369 ///
370 virtual bool OnContextButton(int itemNumber, unsigned int button)
371 {
372 return false;
373 }
374 //--------------------------------------------------------------------------
375
376 //==========================================================================
377 ///
378 /// \ingroup cpp_kodi_gui_CWindow_callbacks
379 /// @brief **Set independent callbacks**
380 ///
381 /// If the class is used independent (with "new CWindow") and
382 /// not as parent (with "cCLASS_own : CWindow") from own must be the
383 /// callback from Kodi to add-on overdriven with own functions!
384 ///
385 /// @param[in] cbhdl The pointer to own handle data
386 /// structure / class
387 /// @param[in] CBOnInit Own defined window init function
388 /// @param[in] CBOnFocus Own defined focus function
389 /// @param[in] CBOnClick Own defined click function
390 /// @param[in] CBOnAction Own defined action function
391 /// @param[in] CBGetContextButtons [opt] To get context menu entries for
392 /// lists function
393 /// @param[in] CBOnContextButton [opt] Used context menu entry function
394 ///
395 ///
396 ///--------------------------------------------------------------------------
397 ///
398 /// **Example:**
399 /// ~~~~~~~~~~~~~{.cpp}
400 /// ...
401 ///
402 /// bool OnInit(GUIHANDLE cbhdl)
403 /// {
404 /// ...
405 /// return true;
406 /// }
407 ///
408 /// bool OnFocus(GUIHANDLE cbhdl, int controlId)
409 /// {
410 /// ...
411 /// return true;
412 /// }
413 ///
414 /// bool OnClick(GUIHANDLE cbhdl, int controlId)
415 /// {
416 /// ...
417 /// return true;
418 /// }
419 ///
420 /// bool OnAction(GUIHANDLE cbhdl, int actionId)
421 /// {
422 /// ...
423 /// return true;
424 /// }
425 ///
426 /// ...
427 /// /* Somewhere where you create the window */
428 /// CWindow myWindow = new CWindow;
429 /// myWindow->SetIndependentCallbacks(myWindow, OnInit, OnFocus, OnClick, OnAction);
430 /// ...
431 /// ~~~~~~~~~~~~~
432 ///
433 void SetIndependentCallbacks(
434 GUIHANDLE cbhdl,
435 bool (*CBOnInit) (GUIHANDLE cbhdl),
436 bool (*CBOnFocus) (GUIHANDLE cbhdl, int controlId),
437 bool (*CBOnClick) (GUIHANDLE cbhdl, int controlId),
438 bool (*CBOnAction) (GUIHANDLE cbhdl, int actionId),
439 void (*CBGetContextButtons) (GUIHANDLE cbhdl, int itemNumber, gui_context_menu_pair* buttons, unsigned int* size) = nullptr,
440 bool (*CBOnContextButton) (GUIHANDLE cbhdl, int itemNumber, unsigned int button) = nullptr)
441 {
442 if (!cbhdl ||
443 !CBOnInit || !CBOnFocus || !CBOnClick || !CBOnAction)
444 {
445 kodi::Log(ADDON_LOG_FATAL, "kodi::gui::CWindow::%s called with nullptr !!!", __FUNCTION__);
446 return;
447 }
448
449 m_interface->kodi_gui->window->set_callbacks(m_interface->kodiBase, m_controlHandle, cbhdl,
450 CBOnInit, CBOnFocus, CBOnClick, CBOnAction,
451 CBGetContextButtons, CBOnContextButton);
452 }
453 //--------------------------------------------------------------------------
454 //@}
455
456 private:
457 static bool CBOnInit(GUIHANDLE cbhdl)
458 {
459 return static_cast<CWindow*>(cbhdl)->OnInit();
460 }
461
462 static bool CBOnFocus(GUIHANDLE cbhdl, int controlId)
463 {
464 return static_cast<CWindow*>(cbhdl)->OnFocus(controlId);
465 }
466
467 static bool CBOnClick(GUIHANDLE cbhdl, int controlId)
468 {
469 return static_cast<CWindow*>(cbhdl)->OnClick(controlId);
470 }
471
472 static bool CBOnAction(GUIHANDLE cbhdl, int actionId)
473 {
474 return static_cast<CWindow*>(cbhdl)->OnAction(actionId);
475 }
476
477 static void CBGetContextButtons(GUIHANDLE cbhdl, int itemNumber, gui_context_menu_pair* buttons, unsigned int* size)
478 {
479 std::vector< std::pair<unsigned int, std::string> > buttonList;
480 static_cast<CWindow*>(cbhdl)->GetContextButtons(itemNumber, buttonList);
481 if (!buttonList.empty())
482 {
483 unsigned int presentSize = buttonList.size();
484 if (presentSize > *size)
485 kodi::Log(ADDON_LOG_WARNING, "GetContextButtons: More as allowed '%i' entries present!", *size);
486 else
487 *size = presentSize;
488 for (unsigned int i = 0; i < *size; ++i)
489 {
490 buttons[i].id = buttonList[i].first;
491 strncpy(buttons[i].name, buttonList[i].second.c_str(), ADDON_MAX_CONTEXT_ENTRY_NAME_LENGTH);
492 }
493 }
494 }
495
496 static bool CBOnContextButton(GUIHANDLE cbhdl, int itemNumber, unsigned int button)
497 {
498 return static_cast<CWindow*>(cbhdl)->OnContextButton(itemNumber, button);
499 }
500 };
501
502} /* namespace gui */
503} /* namespace kodi */