summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/Window.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/Window.h
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.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.h909
1 files changed, 0 insertions, 909 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
deleted file mode 100644
index 5011374..0000000
--- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/Window.h
+++ /dev/null
@@ -1,909 +0,0 @@
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 "../AddonBase.h"
12#include "ListItem.h"
13
14#ifdef BUILD_KODI_ADDON
15#include "../ActionIDs.h"
16#else
17#include "input/actions/ActionIDs.h"
18#endif
19
20namespace kodi
21{
22namespace gui
23{
24
25 class CListItem;
26
27 //============================================================================
28 ///
29 /// \defgroup cpp_kodi_gui_CWindow Window
30 /// \ingroup cpp_kodi_gui
31 /// @brief \cpp_class{ kodi::gui::CWindow }
32 /// **Main window control class**
33 ///
34 /// The with \ref Window.h "#include <kodi/gui/Window.h>"
35 /// included file brings support to create a window or dialog on Kodi.
36 ///
37 /// --------------------------------------------------------------------------
38 ///
39 /// On functions defined input variable <b><tt>controlId</tt> (GUI control identifier)</b>
40 /// is the on window.xml defined value behind type added with <tt><b>id="..."</b></tt> and
41 /// used to identify for changes there and on callbacks.
42 ///
43 /// ~~~~~~~~~~~~~{.xml}
44 /// <control type="label" id="31">
45 /// <description>Title Label</description>
46 /// ...
47 /// </control>
48 /// <control type="progress" id="32">
49 /// <description>progress control</description>
50 /// ...
51 /// </control>
52 /// ~~~~~~~~~~~~~
53 ///
54 ///
55
56 //============================================================================
57 ///
58 /// \defgroup cpp_kodi_gui_CWindow_Defs Definitions, structures and enumerators
59 /// \ingroup cpp_kodi_gui_CWindow
60 /// @brief <b>Library definition values</b>
61 ///
62
63 class ATTRIBUTE_HIDDEN CWindow : public CAddonGUIControlBase
64 {
65 public:
66 //==========================================================================
67 ///
68 /// \ingroup cpp_kodi_gui_CWindow
69 /// @brief Class constructor with needed values for window / dialog.
70 ///
71 /// Creates a new Window class.
72 ///
73 /// @param[in] xmlFilename XML file for the skin
74 /// @param[in] defaultSkin default skin to use if needed not available
75 /// @param[in] asDialog Use window as dialog if set
76 /// @param[in] isMedia [opt] bool - if False, create a regular window.
77 /// if True, create a mediawindow.
78 /// (default=false)
79 /// @note only usable for windows not for dialogs.
80 ///
81 ///
82 CWindow(const std::string& xmlFilename, const std::string& defaultSkin, bool asDialog, bool isMedia = false)
83 : CAddonGUIControlBase(nullptr)
84 {
85 m_controlHandle = m_interface->kodi_gui->window->create(m_interface->kodiBase, xmlFilename.c_str(),
86 defaultSkin.c_str(), asDialog, isMedia);
87 if (!m_controlHandle)
88 kodi::Log(ADDON_LOG_FATAL, "kodi::gui::CWindow can't create window class from Kodi !!!");
89 m_interface->kodi_gui->window->set_callbacks(m_interface->kodiBase, m_controlHandle, this,
90 CBOnInit, CBOnFocus, CBOnClick, CBOnAction,
91 CBGetContextButtons, CBOnContextButton);
92 }
93 //--------------------------------------------------------------------------
94
95 //==========================================================================
96 ///
97 /// \ingroup CWindow
98 /// @brief Class destructor
99 ///
100 ///
101 ///
102 ~CWindow() override
103 {
104 if (m_controlHandle)
105 m_interface->kodi_gui->window->destroy(m_interface->kodiBase, m_controlHandle);
106 }
107 //--------------------------------------------------------------------------
108
109 //==========================================================================
110 ///
111 /// \ingroup cpp_kodi_gui_CWindow
112 /// @brief Show this window.
113 ///
114 /// Shows this window by activating it, calling close() after it wil activate the
115 /// current window again.
116 ///
117 /// @note If your Add-On ends this window will be closed to. To show it forever,
118 /// make a loop at the end of your Add-On or use doModal() instead.
119 ///
120 /// @warning If used must be the class be global present until Kodi becomes
121 /// closed. The creation can be done after before "Show" becomes called, but
122 /// not delete class after them.
123 ///
124 /// @return Return true if call and show is successed,
125 /// if false was something failed to get needed
126 /// skin parts.
127 ///
128 bool Show()
129 {
130 return m_interface->kodi_gui->window->show(m_interface->kodiBase, m_controlHandle);
131 }
132 //--------------------------------------------------------------------------
133
134 //==========================================================================
135 ///
136 /// \ingroup cpp_kodi_gui_CWindow
137 /// @brief Closes this window.
138 ///
139 /// Closes this window by activating the old window.
140 /// @note The window is not deleted with this method.
141 ///
142 void Close()
143 {
144 m_interface->kodi_gui->window->close(m_interface->kodiBase, m_controlHandle);
145 }
146 //--------------------------------------------------------------------------
147
148 //==========================================================================
149 ///
150 /// \ingroup cpp_kodi_gui_CWindow
151 /// @brief Display this window until close() is called.
152 ///
153 void DoModal()
154 {
155 m_interface->kodi_gui->window->do_modal(m_interface->kodiBase, m_controlHandle);
156 }
157 //--------------------------------------------------------------------------
158
159 //==========================================================================
160 ///
161 /// \ingroup cpp_kodi_gui_CWindow
162 /// @brief Gives the control with the supplied focus.
163 ///
164 /// @param[in] iControlId On skin defined id of control
165 /// @return Return true if call and focus is successed,
166 /// if false was something failed to get needed
167 /// skin parts.
168 ///
169 ///
170 bool SetFocusId(int iControlId)
171 {
172 return m_interface->kodi_gui->window->set_focus_id(m_interface->kodiBase, m_controlHandle, iControlId);
173 }
174 //--------------------------------------------------------------------------
175
176 //==========================================================================
177 ///
178 /// \ingroup cpp_kodi_gui_CWindow
179 /// @brief Returns the id of the control which is focused.
180 ///
181 /// @return Focused control id
182 ///
183 ///
184 int GetFocusId()
185 {
186 return m_interface->kodi_gui->window->get_focus_id(m_interface->kodiBase, m_controlHandle);
187 }
188 //--------------------------------------------------------------------------
189
190 //==========================================================================
191 ///
192 /// \ingroup cpp_kodi_gui_CWindow
193 /// @brief To set the used label on given control id
194 ///
195 /// @param[in] controlId Control id where label need to set
196 /// @param[in] label Label to use
197 ///
198 ///
199 void SetControlLabel(int controlId, const std::string& label)
200 {
201 m_interface->kodi_gui->window->set_control_label(m_interface->kodiBase, m_controlHandle, controlId, label.c_str());
202 }
203 //--------------------------------------------------------------------------
204
205 //==========================================================================
206 ///
207 /// \ingroup cpp_kodi_gui_CWindow
208 /// @brief To set the visibility on given control id
209 ///
210 /// @param[in] controlId Control id where visibility is changed
211 /// @param[in] visible Boolean value with `true` for visible, `false` for hidden
212 ///
213 ///
214 void SetControlVisible(int controlId, bool visible)
215 {
216 m_interface->kodi_gui->window->set_control_visible(m_interface->kodiBase, m_controlHandle, controlId, visible);
217 }
218 //--------------------------------------------------------------------------
219
220 //==========================================================================
221 ///
222 /// \ingroup cpp_kodi_gui_CWindow
223 /// @brief To set the selection on given control id
224 ///
225 /// @param[in] controlId Control id where selection is changed
226 /// @param[in] selected Boolean value with `true` for selected, `false` for not
227 ///
228 ///
229 void SetControlSelected(int controlId, bool selected)
230 {
231 m_interface->kodi_gui->window->set_control_selected(m_interface->kodiBase, m_controlHandle, controlId, selected);
232 }
233 //--------------------------------------------------------------------------
234
235 //==========================================================================
236 ///
237 /// \ingroup cpp_kodi_gui_CWindow
238 /// @brief Sets a window property, similar to an infolabel.
239 ///
240 /// @param[in] key string - property name.
241 /// @param[in] value string or unicode - value of property.
242 ///
243 /// @note Key is NOT case sensitive. Setting value to an empty string is
244 /// equivalent to clearProperty(key).\n
245 /// You can use the above as keywords for arguments and skip certain
246 /// optional arguments.\n
247 /// Once you use a keyword, all following arguments require the keyword.
248 ///
249 void SetProperty(const std::string& key, const std::string& value)
250 {
251 m_interface->kodi_gui->window->set_property(m_interface->kodiBase, m_controlHandle, key.c_str(), value.c_str());
252 }
253 //--------------------------------------------------------------------------
254
255 //==========================================================================
256 ///
257 /// \ingroup cpp_kodi_gui_CWindow
258 /// @brief Returns a window property as a string, similar to an infolabel.
259 ///
260 /// @param[in] key string - property name.
261 /// @return The property as strin (if present)
262 ///
263 /// @note Key is NOT case sensitive. Setting value to an empty string is
264 /// equivalent to clearProperty(key).\n
265 /// You can use the above as keywords for arguments and skip certain
266 /// optional arguments.\n
267 /// Once you use a keyword, all following arguments require the keyword.
268 ///
269 ///
270 std::string GetProperty(const std::string& key) const
271 {
272 std::string label;
273 char* ret = m_interface->kodi_gui->window->get_property(m_interface->kodiBase, m_controlHandle, key.c_str());
274 if (ret != nullptr)
275 {
276 if (std::strlen(ret))
277 label = ret;
278 m_interface->free_string(m_interface->kodiBase, ret);
279 }
280 return label;
281 }
282 //--------------------------------------------------------------------------
283
284 //==========================================================================
285 ///
286 /// \ingroup cpp_kodi_gui_CWindow
287 /// @brief Sets a window property with integer value
288 ///
289 /// @param[in] key string - property name.
290 /// @param[in] value integer value to set
291 ///
292 ///
293 void SetPropertyInt(const std::string& key, int value)
294 {
295 m_interface->kodi_gui->window->set_property_int(m_interface->kodiBase, m_controlHandle, key.c_str(), value);
296 }
297 //--------------------------------------------------------------------------
298
299 //==========================================================================
300 ///
301 /// \ingroup cpp_kodi_gui_CWindow
302 /// @brief Returns a window property with integer value
303 ///
304 /// @param[in] key string - property name.
305 /// @return integer value of property
306 ///
307 int GetPropertyInt(const std::string& key) const
308 {
309 return m_interface->kodi_gui->window->get_property_int(m_interface->kodiBase, m_controlHandle, key.c_str());
310 }
311 //--------------------------------------------------------------------------
312
313 //==========================================================================
314 ///
315 /// \ingroup cpp_kodi_gui_CWindow
316 /// @brief Sets a window property with boolean value
317 ///
318 /// @param[in] key string - property name.
319 /// @param[in] value boolean value to set
320 ///
321 ///
322 void SetPropertyBool(const std::string& key, bool value)
323 {
324 m_interface->kodi_gui->window->set_property_bool(m_interface->kodiBase, m_controlHandle, key.c_str(), value);
325 }
326 //--------------------------------------------------------------------------
327
328 //==========================================================================
329 ///
330 /// \ingroup cpp_kodi_gui_CWindow
331 /// @brief Returns a window property with boolean value
332 ///
333 /// @param[in] key string - property name.
334 /// @return boolean value of property
335 ///
336 bool GetPropertyBool(const std::string& key) const
337 {
338 return m_interface->kodi_gui->window->get_property_bool(m_interface->kodiBase, m_controlHandle, key.c_str());
339 }
340 //--------------------------------------------------------------------------
341
342 //==========================================================================
343 ///
344 /// \ingroup cpp_kodi_gui_CWindow
345 /// @brief Sets a window property with double value
346 ///
347 /// @param[in] key string - property name.
348 /// @param[in] value double value to set
349 ///
350 ///
351 void SetPropertyDouble(const std::string& key, double value)
352 {
353 m_interface->kodi_gui->window->set_property_double(m_interface->kodiBase, m_controlHandle, key.c_str(), value);
354 }
355 //--------------------------------------------------------------------------
356
357 //==========================================================================
358 ///
359 /// \ingroup cpp_kodi_gui_CWindow
360 /// @brief Returns a window property with double value
361 ///
362 /// @param[in] key string - property name.
363 /// @return double value of property
364 ///
365 ///
366 double GetPropertyDouble(const std::string& key) const
367 {
368 return m_interface->kodi_gui->window->get_property_double(m_interface->kodiBase, m_controlHandle, key.c_str());
369 }
370 //--------------------------------------------------------------------------
371
372 //==========================================================================
373 ///
374 /// \ingroup cpp_kodi_gui_CWindow
375 /// @brief Remove all present properties from window
376 ///
377 ///
378 ///
379 void ClearProperties()
380 {
381 m_interface->kodi_gui->window->clear_properties(m_interface->kodiBase, m_controlHandle);
382 }
383 //--------------------------------------------------------------------------
384
385 //==========================================================================
386 ///
387 /// \ingroup cpp_kodi_gui_CWindow
388 /// @brief Clears the specific window property.
389 ///
390 /// @param[in] key string - property name.
391 ///
392 /// @note Key is NOT case sensitive. Equivalent to SetProperty(key, "")
393 /// You can use the above as keywords for arguments and skip certain
394 /// optional arguments.
395 /// Once you use a keyword, all following arguments require the
396 /// keyword.
397 ///
398 ///
399 ///-----------------------------------------------------------------------
400 ///
401 /// **Example:**
402 /// ~~~~~~~~~~~~~{.cpp}
403 /// ..
404 /// ClearProperty('Category')
405 /// ..
406 /// ~~~~~~~~~~~~~
407 ///
408 void ClearProperty(const std::string& key)
409 {
410 m_interface->kodi_gui->window->clear_property(m_interface->kodiBase, m_controlHandle, key.c_str());
411 }
412 //--------------------------------------------------------------------------
413
414 //@{
415 //==========================================================================
416 ///
417 /// \ingroup cpp_kodi_gui_CWindow
418 /// @brief Function delete all entries in integrated list.
419 ///
420 ///
421 ///
422 void ClearList()
423 {
424 m_interface->kodi_gui->window->clear_item_list(m_interface->kodiBase, m_controlHandle);
425 }
426 //--------------------------------------------------------------------------
427
428 //==========================================================================
429 ///
430 /// \ingroup cpp_kodi_gui_CWindow
431 /// @brief To add a list item in the on window integrated list.
432 ///
433 /// @param[in] item List item to add
434 /// @param[in] itemPosition [opt] The position for item, default is on end
435 ///
436 ///
437 void AddListItem(ListItemPtr item, int itemPosition = -1)
438 {
439 m_interface->kodi_gui->window->add_list_item(m_interface->kodiBase, m_controlHandle, item->m_controlHandle, itemPosition);
440 }
441 //--------------------------------------------------------------------------
442
443 //==========================================================================
444 ///
445 /// \ingroup cpp_kodi_gui_CWindow
446 /// @brief To add a list item based upon string in the on window integrated list.
447 ///
448 /// @param[in] item List item to add
449 /// @param[in] itemPosition [opt] The position for item, default is on end
450 ///
451 ///
452 void AddListItem(const std::string item, int itemPosition = -1)
453 {
454 m_interface->kodi_gui->window->add_list_item(m_interface->kodiBase, m_controlHandle, std::make_shared<kodi::gui::CListItem>(item)->m_controlHandle, itemPosition);
455 }
456 //--------------------------------------------------------------------------
457
458 //==========================================================================
459 ///
460 /// \ingroup cpp_kodi_gui_CWindow
461 /// @brief Remove list item on position.
462 ///
463 /// @param[in] itemPosition List position to remove
464 ///
465 ///
466 void RemoveListItem(int itemPosition)
467 {
468 m_interface->kodi_gui->window->remove_list_item_from_position(m_interface->kodiBase, m_controlHandle, itemPosition);
469 }
470 //--------------------------------------------------------------------------
471
472 //==========================================================================
473 ///
474 /// \ingroup cpp_kodi_gui_CWindow
475 /// @brief Remove item with given control class from list.
476 ///
477 /// @param[in] item List item control class to remove
478 ///
479 ///
480 void RemoveListItem(ListItemPtr item)
481 {
482 m_interface->kodi_gui->window->remove_list_item(m_interface->kodiBase, m_controlHandle, item->m_controlHandle);
483 }
484 //--------------------------------------------------------------------------
485
486 //==========================================================================
487 ///
488 /// \ingroup cpp_kodi_gui_CWindow
489 /// @brief To get list item control class on wanted position.
490 ///
491 /// @param[in] listPos Position from where control is needed
492 /// @return The list item control class or null if not found
493 ///
494 /// @warning Function returns a new generated **CListItem** class!
495 ///
496 ListItemPtr GetListItem(int listPos)
497 {
498 GUIHANDLE handle = m_interface->kodi_gui->window->get_list_item(m_interface->kodiBase, m_controlHandle, listPos);
499 if (!handle)
500 return ListItemPtr();
501
502 return std::make_shared<kodi::gui::CListItem>(handle);
503 }
504 //--------------------------------------------------------------------------
505
506 //==========================================================================
507 ///
508 /// \ingroup cpp_kodi_gui_CWindow
509 /// @brief To set position of selected part in list.
510 ///
511 /// @param[in] listPos Position to use
512 ///
513 ///
514 void SetCurrentListPosition(int listPos)
515 {
516 m_interface->kodi_gui->window->set_current_list_position(m_interface->kodiBase, m_controlHandle, listPos);
517 }
518 //--------------------------------------------------------------------------
519
520 //==========================================================================
521 ///
522 /// \ingroup cpp_kodi_gui_CWindow
523 /// @brief To get current selected position in list
524 ///
525 /// @return Current list position
526 ///
527 ///
528 int GetCurrentListPosition()
529 {
530 return m_interface->kodi_gui->window->get_current_list_position(m_interface->kodiBase, m_controlHandle);
531 }
532 //--------------------------------------------------------------------------
533
534 //==========================================================================
535 ///
536 /// \ingroup cpp_kodi_gui_CWindow
537 /// @brief To get the amount of entries in the list.
538 ///
539 /// @return Size of in window integrated control class
540 ///
541 ///
542 int GetListSize()
543 {
544 return m_interface->kodi_gui->window->get_list_size(m_interface->kodiBase, m_controlHandle);
545 }
546 //--------------------------------------------------------------------------
547
548 //==========================================================================
549 ///
550 /// \ingroup cpp_kodi_gui_CWindow
551 /// @brief Sets a container property, similar to an infolabel.
552 ///
553 /// @param[in] key string - property name.
554 /// @param[in] value string or unicode - value of property.
555 ///
556 /// @note Key is NOT case sensitive.\n
557 /// You can use the above as keywords for arguments and skip certain
558 /// optional arguments.\n
559 /// Once you use a keyword, all following arguments require the keyword.
560 ///
561 ///
562 void SetContainerProperty(const std::string& key, const std::string& value)
563 {
564 m_interface->kodi_gui->window->set_container_property(m_interface->kodiBase, m_controlHandle, key.c_str(), value.c_str());
565 }
566 //--------------------------------------------------------------------------
567
568 //==========================================================================
569 ///
570 /// \ingroup cpp_kodi_gui_CWindow
571 /// @brief Sets the content type of the container.
572 ///
573 /// @param[in] value string or unicode - content value.
574 ///
575 /// __Available content types__
576 /// | Name | Media |
577 /// |:-----------:|:-----------------------------------------|
578 /// | actors | Videos
579 /// | addons | Addons, Music, Pictures, Programs, Videos
580 /// | albums | Music, Videos
581 /// | artists | Music, Videos
582 /// | countries | Music, Videos
583 /// | directors | Videos
584 /// | files | Music, Videos
585 /// | games | Games
586 /// | genres | Music, Videos
587 /// | images | Pictures
588 /// | mixed | Music, Videos
589 /// | movies | Videos
590 /// | Musicvideos | Music, Videos
591 /// | playlists | Music, Videos
592 /// | seasons | Videos
593 /// | sets | Videos
594 /// | songs | Music
595 /// | studios | Music, Videos
596 /// | tags | Music, Videos
597 /// | tvshows | Videos
598 /// | videos | Videos
599 /// | years | Music, Videos
600 ///
601 ///
602 void SetContainerContent(const std::string& value)
603 {
604 m_interface->kodi_gui->window->set_container_content(m_interface->kodiBase, m_controlHandle, value.c_str());
605 }
606 //--------------------------------------------------------------------------
607
608 //==========================================================================
609 ///
610 /// \ingroup cpp_kodi_gui_CWindow
611 /// @brief Get the id of the currently visible container.
612 ///
613 /// @return currently visible container id
614 ///
615 ///
616 int GetCurrentContainerId()
617 {
618 return m_interface->kodi_gui->window->get_current_container_id(m_interface->kodiBase, m_controlHandle);
619 }
620 //--------------------------------------------------------------------------
621 //@}
622
623 //==========================================================================
624 ///
625 /// \ingroup cpp_kodi_gui_CWindow
626 /// @brief To inform Kodi that it need to render region new.
627 ///
628 ///
629 void MarkDirtyRegion()
630 {
631 return m_interface->kodi_gui->window->mark_dirty_region(m_interface->kodiBase, m_controlHandle);
632 }
633 //--------------------------------------------------------------------------
634
635 //==========================================================================
636 //
637 /// @defgroup cpp_kodi_gui_CWindow_callbacks Callback functions from Kodi to add-on
638 /// \ingroup cpp_kodi_gui_CWindow
639 //@{
640 /// @brief <b>GUI window callback functions.</b>
641 ///
642 /// Functions to handle control callbacks from Kodi
643 ///
644 /// ------------------------------------------------------------------------
645 ///
646 /// @link cpp_kodi_gui_CWindow Go back to normal functions from CWindow@endlink
647 //
648
649 //==========================================================================
650 ///
651 /// \ingroup cpp_kodi_gui_CWindow_callbacks
652 /// @brief OnInit method.
653 ///
654 /// @return Return true if initialize was done successful
655 ///
656 ///
657 virtual bool OnInit() { return false; }
658 //--------------------------------------------------------------------------
659
660 //==========================================================================
661 ///
662 /// \ingroup cpp_kodi_gui_CWindow_callbacks
663 /// @brief OnFocus method.
664 ///
665 /// @param[in] controlId GUI control identifier
666 /// @return Return true if focus condition was handled there or false to handle them by Kodi itself
667 ///
668 ///
669 virtual bool OnFocus(int controlId) { return false; }
670 //--------------------------------------------------------------------------
671
672 //==========================================================================
673 ///
674 /// \ingroup cpp_kodi_gui_CWindow_callbacks
675 /// @brief OnClick method.
676 ///
677 /// @param[in] controlId GUI control identifier
678 /// @return Return true if click was handled there
679 /// or false to handle them by Kodi itself
680 ///
681 ///
682 virtual bool OnClick(int controlId) { return false; }
683 //--------------------------------------------------------------------------
684
685 //==========================================================================
686 ///
687 /// \ingroup cpp_kodi_gui_CWindow_callbacks
688 /// @brief OnAction method.
689 ///
690 /// @param[in] actionId The action id to perform, see
691 /// \ref kodi_key_action_ids to get list of
692 /// them
693 /// @return Return true if action was handled there
694 /// or false to handle them by Kodi itself
695 ///
696 ///
697 /// This method will receive all actions that the main program will send
698 /// to this window.
699 ///
700 /// @note
701 /// - By default, only the \c PREVIOUS_MENU and \c NAV_BACK actions are handled.
702 /// - Overwrite this method to let your code handle all actions.
703 /// - Don't forget to capture \c ACTION_PREVIOUS_MENU or \c ACTION_NAV_BACK, else the user can't close this window.
704 ///
705 ///
706 ///--------------------------------------------------------------------------
707 ///
708 /// **Example:**
709 /// ~~~~~~~~~~~~~{.cpp}
710 /// ..
711 /// /* Window used with parent / child way */
712 /// bool cYOUR_CLASS::OnAction(int actionId)
713 /// {
714 /// switch (action)
715 /// {
716 /// case ACTION_PREVIOUS_MENU:
717 /// case ACTION_NAV_BACK:
718 /// printf("action recieved: previous");
719 /// Close();
720 /// return true;
721 /// case ACTION_SHOW_INFO:
722 /// printf("action recieved: show info");
723 /// break;
724 /// case ACTION_STOP:
725 /// printf("action recieved: stop");
726 /// break;
727 /// case ACTION_PAUSE:
728 /// printf("action recieved: pause");
729 /// break;
730 /// default:
731 /// break;
732 /// }
733 /// return false;
734 /// }
735 /// ..
736 /// ~~~~~~~~~~~~~
737 ///
738 virtual bool OnAction(int actionId, uint32_t buttoncode, wchar_t unicode)
739 {
740 switch (actionId)
741 {
742 case ACTION_PREVIOUS_MENU:
743 case ACTION_NAV_BACK:
744 Close();
745 return true;
746 default:
747 break;
748 }
749 return false;
750 }
751 //--------------------------------------------------------------------------
752
753 //==========================================================================
754 ///
755 /// \ingroup cpp_kodi_gui_CWindow_callbacks
756 /// @brief Get context menu buttons for list entry
757 ///
758 /// @param[in] itemNumber selected list item entry
759 /// @param[in] buttons list where context menus becomes added with his
760 /// identifier and name.
761 ///
762 virtual void GetContextButtons(int itemNumber, std::vector< std::pair<unsigned int, std::string> > &buttons)
763 {
764 }
765 //--------------------------------------------------------------------------
766
767 //==========================================================================
768 ///
769 /// \ingroup cpp_kodi_gui_CWindow_callbacks
770 /// @brief Called after selection in context menu
771 ///
772 /// @param[in] itemNumber selected list item entry
773 /// @param[in] button the pressed button id
774 /// @return true if handled, otherwise false
775 ///
776 virtual bool OnContextButton(int itemNumber, unsigned int button)
777 {
778 return false;
779 }
780 //--------------------------------------------------------------------------
781
782 //==========================================================================
783 ///
784 /// \ingroup cpp_kodi_gui_CWindow_callbacks
785 /// @brief **Set independent callbacks**
786 ///
787 /// If the class is used independent (with "new CWindow") and
788 /// not as parent (with "cCLASS_own : CWindow") from own must be the
789 /// callback from Kodi to add-on overdriven with own functions!
790 ///
791 /// @param[in] cbhdl The pointer to own handle data
792 /// structure / class
793 /// @param[in] CBOnInit Own defined window init function
794 /// @param[in] CBOnFocus Own defined focus function
795 /// @param[in] CBOnClick Own defined click function
796 /// @param[in] CBOnAction Own defined action function
797 /// @param[in] CBGetContextButtons [opt] To get context menu entries for
798 /// lists function
799 /// @param[in] CBOnContextButton [opt] Used context menu entry function
800 ///
801 ///
802 ///--------------------------------------------------------------------------
803 ///
804 /// **Example:**
805 /// ~~~~~~~~~~~~~{.cpp}
806 /// ...
807 ///
808 /// bool OnInit(GUIHANDLE cbhdl)
809 /// {
810 /// ...
811 /// return true;
812 /// }
813 ///
814 /// bool OnFocus(GUIHANDLE cbhdl, int controlId)
815 /// {
816 /// ...
817 /// return true;
818 /// }
819 ///
820 /// bool OnClick(GUIHANDLE cbhdl, int controlId)
821 /// {
822 /// ...
823 /// return true;
824 /// }
825 ///
826 /// bool OnAction(GUIHANDLE cbhdl, int actionId)
827 /// {
828 /// ...
829 /// return true;
830 /// }
831 ///
832 /// ...
833 /// /* Somewhere where you create the window */
834 /// CWindow myWindow = new CWindow;
835 /// myWindow->SetIndependentCallbacks(myWindow, OnInit, OnFocus, OnClick, OnAction);
836 /// ...
837 /// ~~~~~~~~~~~~~
838 ///
839 void SetIndependentCallbacks(
840 GUIHANDLE cbhdl,
841 bool (*CBOnInit) (GUIHANDLE cbhdl),
842 bool (*CBOnFocus) (GUIHANDLE cbhdl, int controlId),
843 bool (*CBOnClick) (GUIHANDLE cbhdl, int controlId),
844 bool (*CBOnAction) (GUIHANDLE cbhdl, int actionId, uint32_t buttoncode, wchar_t unicode),
845 void (*CBGetContextButtons) (GUIHANDLE cbhdl, int itemNumber, gui_context_menu_pair* buttons, unsigned int* size) = nullptr,
846 bool (*CBOnContextButton) (GUIHANDLE cbhdl, int itemNumber, unsigned int button) = nullptr)
847 {
848 if (!cbhdl ||
849 !CBOnInit || !CBOnFocus || !CBOnClick || !CBOnAction)
850 {
851 kodi::Log(ADDON_LOG_FATAL, "kodi::gui::CWindow::%s called with nullptr !!!", __FUNCTION__);
852 return;
853 }
854
855 m_interface->kodi_gui->window->set_callbacks(m_interface->kodiBase, m_controlHandle, cbhdl,
856 CBOnInit, CBOnFocus, CBOnClick, CBOnAction,
857 CBGetContextButtons, CBOnContextButton);
858 }
859 //--------------------------------------------------------------------------
860 //@}
861
862 private:
863 static bool CBOnInit(GUIHANDLE cbhdl)
864 {
865 return static_cast<CWindow*>(cbhdl)->OnInit();
866 }
867
868 static bool CBOnFocus(GUIHANDLE cbhdl, int controlId)
869 {
870 return static_cast<CWindow*>(cbhdl)->OnFocus(controlId);
871 }
872
873 static bool CBOnClick(GUIHANDLE cbhdl, int controlId)
874 {
875 return static_cast<CWindow*>(cbhdl)->OnClick(controlId);
876 }
877
878 static bool CBOnAction(GUIHANDLE cbhdl, int actionId, uint32_t buttoncode, wchar_t unicode)
879 {
880 return static_cast<CWindow*>(cbhdl)->OnAction(actionId, buttoncode, unicode);
881 }
882
883 static void CBGetContextButtons(GUIHANDLE cbhdl, int itemNumber, gui_context_menu_pair* buttons, unsigned int* size)
884 {
885 std::vector< std::pair<unsigned int, std::string> > buttonList;
886 static_cast<CWindow*>(cbhdl)->GetContextButtons(itemNumber, buttonList);
887 if (!buttonList.empty())
888 {
889 unsigned int presentSize = static_cast<unsigned int>(buttonList.size());
890 if (presentSize > *size)
891 kodi::Log(ADDON_LOG_WARNING, "GetContextButtons: More as allowed '%i' entries present!", *size);
892 else
893 *size = presentSize;
894 for (unsigned int i = 0; i < *size; ++i)
895 {
896 buttons[i].id = buttonList[i].first;
897 strncpy(buttons[i].name, buttonList[i].second.c_str(), ADDON_MAX_CONTEXT_ENTRY_NAME_LENGTH);
898 }
899 }
900 }
901
902 static bool CBOnContextButton(GUIHANDLE cbhdl, int itemNumber, unsigned int button)
903 {
904 return static_cast<CWindow*>(cbhdl)->OnContextButton(itemNumber, button);
905 }
906 };
907
908} /* namespace gui */
909} /* namespace kodi */