Kodi Development 22.0
for Binary and Script based Add-Ons
 
All Classes Functions Variables Typedefs Enumerations Enumerator Modules Pages
Loading...
Searching...
No Matches
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 "../AddonBase.h"
12#include "../c-api/gui/window.h"
13#include "ListItem.h"
14#include "input/ActionIDs.h"
15
16#ifdef __cplusplus
17
18namespace kodi
19{
20namespace gui
21{
22
23//==============================================================================
33
34//==============================================================================
43using ClientHandle = KODI_GUI_CLIENT_HANDLE;
44//------------------------------------------------------------------------------
45
46class CListItem;
47
48//==============================================================================
109class ATTR_DLL_LOCAL CWindow : public CAddonGUIControlBase
110{
111public:
112 //============================================================================
126 CWindow(const std::string& xmlFilename,
127 const std::string& defaultSkin,
128 bool asDialog,
129 bool isMedia = false)
130 : CAddonGUIControlBase(nullptr)
131 {
132 m_controlHandle = m_interface->kodi_gui->window->create(
133 m_interface->kodiBase, xmlFilename.c_str(), defaultSkin.c_str(), asDialog, isMedia);
134 if (!m_controlHandle)
135 kodi::Log(ADDON_LOG_FATAL, "kodi::gui::CWindow can't create window class from Kodi !!!");
136 m_interface->kodi_gui->window->set_callbacks(m_interface->kodiBase, m_controlHandle, this,
137 CBOnInit, CBOnFocus, CBOnClick, CBOnAction,
138 CBGetContextButtons, CBOnContextButton);
139 }
140 //----------------------------------------------------------------------------
141
142 //============================================================================
146 ~CWindow() override
147 {
148 if (m_controlHandle)
149 m_interface->kodi_gui->window->destroy(m_interface->kodiBase, m_controlHandle);
150 }
151 //----------------------------------------------------------------------------
152
153 //============================================================================
169 bool Show()
170 {
171 return m_interface->kodi_gui->window->show(m_interface->kodiBase, m_controlHandle);
172 }
173 //----------------------------------------------------------------------------
174
175 //============================================================================
182 void Close() { m_interface->kodi_gui->window->close(m_interface->kodiBase, m_controlHandle); }
183 //----------------------------------------------------------------------------
184
185 //============================================================================
189 void DoModal()
190 {
191 m_interface->kodi_gui->window->do_modal(m_interface->kodiBase, m_controlHandle);
192 }
193 //----------------------------------------------------------------------------
194
195 //============================================================================
202 bool SetFocusId(int controlId)
203 {
204 return m_interface->kodi_gui->window->set_focus_id(m_interface->kodiBase, m_controlHandle,
205 controlId);
206 }
207 //----------------------------------------------------------------------------
208
209 //============================================================================
216 {
217 return m_interface->kodi_gui->window->get_focus_id(m_interface->kodiBase, m_controlHandle);
218 }
219 //----------------------------------------------------------------------------
220
221 //============================================================================
228 void SetControlLabel(int controlId, const std::string& label)
229 {
230 m_interface->kodi_gui->window->set_control_label(m_interface->kodiBase, m_controlHandle,
231 controlId, label.c_str());
232 }
233 //----------------------------------------------------------------------------
234
235 //============================================================================
242 void SetControlVisible(int controlId, bool visible)
243 {
244 m_interface->kodi_gui->window->set_control_visible(m_interface->kodiBase, m_controlHandle,
245 controlId, visible);
246 }
247 //----------------------------------------------------------------------------
248
249 //============================================================================
256 void SetControlSelected(int controlId, bool selected)
257 {
258 m_interface->kodi_gui->window->set_control_selected(m_interface->kodiBase, m_controlHandle,
259 controlId, selected);
260 }
261 //----------------------------------------------------------------------------
262
263 //============================================================================
276 void SetProperty(const std::string& key, const std::string& value)
277 {
278 m_interface->kodi_gui->window->set_property(m_interface->kodiBase, m_controlHandle, key.c_str(),
279 value.c_str());
280 }
281 //----------------------------------------------------------------------------
282
283 //============================================================================
296 std::string GetProperty(const std::string& key) const
297 {
298 std::string label;
299 char* ret = m_interface->kodi_gui->window->get_property(m_interface->kodiBase, m_controlHandle,
300 key.c_str());
301 if (ret != nullptr)
302 {
303 if (std::strlen(ret))
304 label = ret;
305 m_interface->free_string(m_interface->kodiBase, ret);
306 }
307 return label;
308 }
309 //----------------------------------------------------------------------------
310
311 //============================================================================
318 void SetPropertyInt(const std::string& key, int value)
319 {
320 m_interface->kodi_gui->window->set_property_int(m_interface->kodiBase, m_controlHandle,
321 key.c_str(), value);
322 }
323 //----------------------------------------------------------------------------
324
325 //============================================================================
332 int GetPropertyInt(const std::string& key) const
333 {
334 return m_interface->kodi_gui->window->get_property_int(m_interface->kodiBase, m_controlHandle,
335 key.c_str());
336 }
337 //----------------------------------------------------------------------------
338
339 //============================================================================
346 void SetPropertyBool(const std::string& key, bool value)
347 {
348 m_interface->kodi_gui->window->set_property_bool(m_interface->kodiBase, m_controlHandle,
349 key.c_str(), value);
350 }
351 //----------------------------------------------------------------------------
352
353 //============================================================================
360 bool GetPropertyBool(const std::string& key) const
361 {
362 return m_interface->kodi_gui->window->get_property_bool(m_interface->kodiBase, m_controlHandle,
363 key.c_str());
364 }
365 //----------------------------------------------------------------------------
366
367 //============================================================================
374 void SetPropertyDouble(const std::string& key, double value)
375 {
376 m_interface->kodi_gui->window->set_property_double(m_interface->kodiBase, m_controlHandle,
377 key.c_str(), value);
378 }
379 //----------------------------------------------------------------------------
380
381 //============================================================================
388 double GetPropertyDouble(const std::string& key) const
389 {
390 return m_interface->kodi_gui->window->get_property_double(m_interface->kodiBase,
391 m_controlHandle, key.c_str());
392 }
393 //----------------------------------------------------------------------------
394
395 //============================================================================
400 {
401 m_interface->kodi_gui->window->clear_properties(m_interface->kodiBase, m_controlHandle);
402 }
403 //----------------------------------------------------------------------------
404
405 //============================================================================
427 void ClearProperty(const std::string& key)
428 {
429 m_interface->kodi_gui->window->clear_property(m_interface->kodiBase, m_controlHandle,
430 key.c_str());
431 }
432 //----------------------------------------------------------------------------
433
435 //============================================================================
440 {
441 m_interface->kodi_gui->window->clear_item_list(m_interface->kodiBase, m_controlHandle);
442 }
443 //----------------------------------------------------------------------------
444
445 //============================================================================
452 void AddListItem(const std::shared_ptr<CListItem>& item, int itemPosition = -1)
453 {
454 m_interface->kodi_gui->window->add_list_item(m_interface->kodiBase, m_controlHandle,
455 item->m_controlHandle, itemPosition);
456 }
457 //----------------------------------------------------------------------------
458
459 //============================================================================
466 void AddListItem(const std::string& item, int itemPosition = -1)
467 {
468 m_interface->kodi_gui->window->add_list_item(
469 m_interface->kodiBase, m_controlHandle,
470 std::make_shared<kodi::gui::CListItem>(item)->m_controlHandle, itemPosition);
471 }
472 //----------------------------------------------------------------------------
473
474 //============================================================================
480 void RemoveListItem(int itemPosition)
481 {
482 m_interface->kodi_gui->window->remove_list_item_from_position(m_interface->kodiBase,
483 m_controlHandle, itemPosition);
484 }
485 //----------------------------------------------------------------------------
486
487 //============================================================================
493 void RemoveListItem(const std::shared_ptr<CListItem>& item)
494 {
495 m_interface->kodi_gui->window->remove_list_item(m_interface->kodiBase, m_controlHandle,
496 item->m_controlHandle);
497 }
498 //----------------------------------------------------------------------------
499
500 //============================================================================
509 std::shared_ptr<CListItem> GetListItem(int listPos)
510 {
511 KODI_GUI_LISTITEM_HANDLE handle = m_interface->kodi_gui->window->get_list_item(
512 m_interface->kodiBase, m_controlHandle, listPos);
513 if (!handle)
514 return std::shared_ptr<CListItem>();
515
516 return std::make_shared<kodi::gui::CListItem>(handle);
517 }
518 //----------------------------------------------------------------------------
519
520 //============================================================================
526 void SetCurrentListPosition(int listPos)
527 {
528 m_interface->kodi_gui->window->set_current_list_position(m_interface->kodiBase, m_controlHandle,
529 listPos);
530 }
531 //----------------------------------------------------------------------------
532
533 //============================================================================
540 {
541 return m_interface->kodi_gui->window->get_current_list_position(m_interface->kodiBase,
542 m_controlHandle);
543 }
544 //----------------------------------------------------------------------------
545
546 //============================================================================
553 {
554 return m_interface->kodi_gui->window->get_list_size(m_interface->kodiBase, m_controlHandle);
555 }
556 //----------------------------------------------------------------------------
557
558 //============================================================================
570 void SetContainerProperty(const std::string& key, const std::string& value)
571 {
572 m_interface->kodi_gui->window->set_container_property(m_interface->kodiBase, m_controlHandle,
573 key.c_str(), value.c_str());
574 }
575 //----------------------------------------------------------------------------
576
577 //============================================================================
609 void SetContainerContent(const std::string& value)
610 {
611 m_interface->kodi_gui->window->set_container_content(m_interface->kodiBase, m_controlHandle,
612 value.c_str());
613 }
614 //----------------------------------------------------------------------------
615
616 //============================================================================
623 {
624 return m_interface->kodi_gui->window->get_current_container_id(m_interface->kodiBase,
625 m_controlHandle);
626 }
627 //----------------------------------------------------------------------------
629
630 //============================================================================
635 {
636 return m_interface->kodi_gui->window->mark_dirty_region(m_interface->kodiBase, m_controlHandle);
637 }
638 //----------------------------------------------------------------------------
639
640 //============================================================================
650 //
651
652 //============================================================================
659 virtual bool OnInit() { return false; }
660 //----------------------------------------------------------------------------
661
662 //============================================================================
671 virtual bool OnFocus(int controlId) { return false; }
672 //----------------------------------------------------------------------------
673
674 //============================================================================
683 virtual bool OnClick(int controlId) { return false; }
684 //----------------------------------------------------------------------------
685
686 //============================================================================
738 virtual bool OnAction(ADDON_ACTION actionId)
739 {
740 switch (actionId)
741 {
744 Close();
745 return true;
746 default:
747 break;
748 }
749 return false;
750 }
751 //----------------------------------------------------------------------------
752
753 //============================================================================
761 virtual void GetContextButtons(int itemNumber,
762 std::vector<std::pair<unsigned int, std::string>>& buttons)
763 {
764 }
765 //----------------------------------------------------------------------------
766
767 //============================================================================
775 virtual bool OnContextButton(int itemNumber, unsigned int button) { return false; }
776 //----------------------------------------------------------------------------
777
778 //============================================================================
834 bool (*CBOnInit)(kodi::gui::ClientHandle cbhdl),
835 bool (*CBOnFocus)(kodi::gui::ClientHandle cbhdl, int controlId),
836 bool (*CBOnClick)(kodi::gui::ClientHandle cbhdl, int controlId),
837 bool (*CBOnAction)(kodi::gui::ClientHandle cbhdl,
838 ADDON_ACTION actionId),
839 void (*CBGetContextButtons)(kodi::gui::ClientHandle cbhdl,
840 int itemNumber,
841 gui_context_menu_pair* buttons,
842 unsigned int* size) = nullptr,
843 bool (*CBOnContextButton)(kodi::gui::ClientHandle cbhdl,
844 int itemNumber,
845 unsigned int button) = nullptr)
846 {
847 if (!cbhdl || !CBOnInit || !CBOnFocus || !CBOnClick || !CBOnAction)
848 {
849 kodi::Log(ADDON_LOG_FATAL, "kodi::gui::CWindow::%s called with nullptr !!!", __FUNCTION__);
850 return;
851 }
852
853 m_interface->kodi_gui->window->set_callbacks(m_interface->kodiBase, m_controlHandle, cbhdl,
854 CBOnInit, CBOnFocus, CBOnClick, CBOnAction,
855 CBGetContextButtons, CBOnContextButton);
856 }
857 //----------------------------------------------------------------------------
859
860private:
861 static bool CBOnInit(KODI_GUI_CLIENT_HANDLE cbhdl)
862 {
863 return static_cast<CWindow*>(cbhdl)->OnInit();
864 }
865
866 static bool CBOnFocus(KODI_GUI_CLIENT_HANDLE cbhdl, int controlId)
867 {
868 return static_cast<CWindow*>(cbhdl)->OnFocus(controlId);
869 }
870
871 static bool CBOnClick(KODI_GUI_CLIENT_HANDLE cbhdl, int controlId)
872 {
873 return static_cast<CWindow*>(cbhdl)->OnClick(controlId);
874 }
875
876 static bool CBOnAction(KODI_GUI_CLIENT_HANDLE cbhdl, ADDON_ACTION actionId)
877 {
878 return static_cast<CWindow*>(cbhdl)->OnAction(actionId);
879 }
880
881 static void CBGetContextButtons(KODI_GUI_CLIENT_HANDLE cbhdl,
882 int itemNumber,
883 gui_context_menu_pair* buttons,
884 unsigned int* size)
885 {
886 std::vector<std::pair<unsigned int, std::string>> buttonList;
887 static_cast<CWindow*>(cbhdl)->GetContextButtons(itemNumber, buttonList);
888 if (!buttonList.empty())
889 {
890 unsigned int presentSize = static_cast<unsigned int>(buttonList.size());
891 if (presentSize > *size)
892 kodi::Log(ADDON_LOG_WARNING, "GetContextButtons: More as allowed '%i' entries present!",
893 *size);
894 else
895 *size = presentSize;
896 for (unsigned int i = 0; i < *size; ++i)
897 {
898 buttons[i].id = buttonList[i].first;
899 strncpy(buttons[i].name, buttonList[i].second.c_str(), ADDON_MAX_CONTEXT_ENTRY_NAME_LENGTH);
900 }
901 }
902 }
903
904 static bool CBOnContextButton(KODI_GUI_CLIENT_HANDLE cbhdl, int itemNumber, unsigned int button)
905 {
906 return static_cast<CWindow*>(cbhdl)->OnContextButton(itemNumber, button);
907 }
908};
909
910} /* namespace gui */
911} /* namespace kodi */
912
913#endif /* __cplusplus */
Definition ListItem.h:65
Definition Window.h:110
~CWindow() override
Class destructor.
Definition Window.h:146
@ ADDON_LOG_FATAL
4 : To notify fatal unrecoverable errors, which can may also indicate upcoming crashes.
Definition addon_base.h:197
@ ADDON_LOG_WARNING
2 : To write warnings in the log file.
Definition addon_base.h:190
ADDON_ACTION
Definition action_ids.h:19
@ ADDON_ACTION_PREVIOUS_MENU
10: Previous menu.
Definition action_ids.h:54
@ ADDON_ACTION_NAV_BACK
90: Nav back.
Definition action_ids.h:286
KODI_GUI_CLIENT_HANDLE ClientHandle
Handler for addon-sided processing class If the callback functions used by the window are not used di...
Definition Window.h:43
virtual bool OnContextButton(int itemNumber, unsigned int button)
Called after selection in context menu.
Definition Window.h:775
virtual void GetContextButtons(int itemNumber, std::vector< std::pair< unsigned int, std::string > > &buttons)
Get context menu buttons for list entry.
Definition Window.h:761
virtual bool OnAction(ADDON_ACTION actionId)
OnAction method.
Definition Window.h:738
virtual bool OnInit()
OnInit method.
Definition Window.h:659
virtual bool OnFocus(int controlId)
OnFocus method.
Definition Window.h:671
void SetIndependentCallbacks(kodi::gui::ClientHandle cbhdl, bool(*CBOnInit)(kodi::gui::ClientHandle cbhdl), bool(*CBOnFocus)(kodi::gui::ClientHandle cbhdl, int controlId), bool(*CBOnClick)(kodi::gui::ClientHandle cbhdl, int controlId), bool(*CBOnAction)(kodi::gui::ClientHandle cbhdl, ADDON_ACTION actionId), void(*CBGetContextButtons)(kodi::gui::ClientHandle cbhdl, int itemNumber, gui_context_menu_pair *buttons, unsigned int *size)=nullptr, bool(*CBOnContextButton)(kodi::gui::ClientHandle cbhdl, int itemNumber, unsigned int button)=nullptr)
Set independent callbacks
Definition Window.h:833
virtual bool OnClick(int controlId)
OnClick method.
Definition Window.h:683
bool SetFocusId(int controlId)
Gives the control with the supplied focus.
Definition Window.h:202
void RemoveListItem(const std::shared_ptr< CListItem > &item)
Remove item with given control class from list.
Definition Window.h:493
int GetListSize()
To get the amount of entries in the list.
Definition Window.h:552
CWindow(const std::string &xmlFilename, const std::string &defaultSkin, bool asDialog, bool isMedia=false)
Class constructor with needed values for window / dialog.
Definition Window.h:126
void ClearList()
Function delete all entries in integrated list.
Definition Window.h:439
void SetContainerContent(const std::string &value)
Sets the content type of the container.
Definition Window.h:609
void SetPropertyDouble(const std::string &key, double value)
Sets a window property with double value.
Definition Window.h:374
void SetPropertyInt(const std::string &key, int value)
Sets a window property with integer value.
Definition Window.h:318
std::shared_ptr< CListItem > GetListItem(int listPos)
To get list item control class on wanted position.
Definition Window.h:509
void SetControlLabel(int controlId, const std::string &label)
To set the used label on given control id.
Definition Window.h:228
void MarkDirtyRegion()
To inform Kodi that it need to render region new.
Definition Window.h:634
void SetControlVisible(int controlId, bool visible)
To set the visibility on given control id.
Definition Window.h:242
void SetControlSelected(int controlId, bool selected)
To set the selection on given control id.
Definition Window.h:256
void SetProperty(const std::string &key, const std::string &value)
Sets a window property, similar to an infolabel.
Definition Window.h:276
void Close()
Closes this window.
Definition Window.h:182
int GetCurrentListPosition()
To get current selected position in list.
Definition Window.h:539
void DoModal()
Display this window until close() is called.
Definition Window.h:189
void ClearProperty(const std::string &key)
Clears the specific window property.
Definition Window.h:427
void SetPropertyBool(const std::string &key, bool value)
Sets a window property with boolean value.
Definition Window.h:346
std::string GetProperty(const std::string &key) const
Returns a window property as a string, similar to an infolabel.
Definition Window.h:296
bool GetPropertyBool(const std::string &key) const
Returns a window property with boolean value.
Definition Window.h:360
bool Show()
Show this window.
Definition Window.h:169
void SetContainerProperty(const std::string &key, const std::string &value)
Sets a container property, similar to an infolabel.
Definition Window.h:570
int GetPropertyInt(const std::string &key) const
Returns a window property with integer value.
Definition Window.h:332
void SetCurrentListPosition(int listPos)
To set position of selected part in list.
Definition Window.h:526
void AddListItem(const std::shared_ptr< CListItem > &item, int itemPosition=-1)
To add a list item in the on window integrated list.
Definition Window.h:452
void ClearProperties()
Remove all present properties from window.
Definition Window.h:399
void RemoveListItem(int itemPosition)
Remove list item on position.
Definition Window.h:480
int GetCurrentContainerId()
Get the id of the currently visible container.
Definition Window.h:622
void AddListItem(const std::string &item, int itemPosition=-1)
To add a list item based upon string in the on window integrated list.
Definition Window.h:466
double GetPropertyDouble(const std::string &key) const
Returns a window property with double value.
Definition Window.h:388
int GetFocusId()
Returns the id of the control which is focused.
Definition Window.h:215
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition AddonBase.h:1935
Definition window.h:26