Kodi Development  20.0
for Binary and Script based Add-Ons
Button.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 "../../c-api/gui/controls/button.h"
12 #include "../Window.h"
13 
14 #ifdef __cplusplus
15 
16 namespace kodi
17 {
18 namespace gui
19 {
20 namespace controls
21 {
22 
23 //==============================================================================
41 class ATTRIBUTE_HIDDEN CButton : public CAddonGUIControlBase
42 {
43 public:
44  //============================================================================
51  CButton(CWindow* window, int controlId) : CAddonGUIControlBase(window)
52  {
53  m_controlHandle = m_interface->kodi_gui->window->get_control_button(
54  m_interface->kodiBase, m_Window->GetControlHandle(), controlId);
55  if (!m_controlHandle)
56  kodi::Log(ADDON_LOG_FATAL, "kodi::gui::CButton can't create control class from Kodi !!!");
57  }
58  //----------------------------------------------------------------------------
59 
60  //============================================================================
64  ~CButton() override = default;
65  //----------------------------------------------------------------------------
66 
67  //============================================================================
73  void SetVisible(bool visible)
74  {
75  m_interface->kodi_gui->control_button->set_visible(m_interface->kodiBase, m_controlHandle,
76  visible);
77  }
78  //----------------------------------------------------------------------------
79 
80  //============================================================================
86  void SetEnabled(bool enabled)
87  {
88  m_interface->kodi_gui->control_button->set_enabled(m_interface->kodiBase, m_controlHandle,
89  enabled);
90  }
91  //----------------------------------------------------------------------------
92 
93  //============================================================================
99  void SetLabel(const std::string& label)
100  {
101  m_interface->kodi_gui->control_button->set_label(m_interface->kodiBase, m_controlHandle,
102  label.c_str());
103  }
104  //----------------------------------------------------------------------------
105 
106  //============================================================================
112  std::string GetLabel() const
113  {
114  std::string label;
115  char* ret =
116  m_interface->kodi_gui->control_button->get_label(m_interface->kodiBase, m_controlHandle);
117  if (ret != nullptr)
118  {
119  if (std::strlen(ret))
120  label = ret;
121  m_interface->free_string(m_interface->kodiBase, ret);
122  }
123  return label;
124  }
125  //----------------------------------------------------------------------------
126 
127  //============================================================================
133  void SetLabel2(const std::string& label)
134  {
135  m_interface->kodi_gui->control_button->set_label2(m_interface->kodiBase, m_controlHandle,
136  label.c_str());
137  }
138  //----------------------------------------------------------------------------
139 
140  //============================================================================
146  std::string GetLabel2() const
147  {
148  std::string label;
149  char* ret =
150  m_interface->kodi_gui->control_button->get_label2(m_interface->kodiBase, m_controlHandle);
151  if (ret != nullptr)
152  {
153  if (std::strlen(ret))
154  label = ret;
155  m_interface->free_string(m_interface->kodiBase, ret);
156  }
157  return label;
158  }
159  //----------------------------------------------------------------------------
160 };
161 
162 } /* namespace controls */
163 } /* namespace gui */
164 } /* namespace kodi */
165 
166 #endif /* __cplusplus */
Definition: ListItem.h:26
Definition: Window.h:110
Definition: Button.h:42
@ ADDON_LOG_FATAL
4 : To notify fatal unrecoverable errors, which can may also indicate upcoming crashes.
Definition: addon_base.h:187
CButton(CWindow *window, int controlId)
Construct a new control.
Definition: Button.h:51
std::string GetLabel() const
Get the used text from button.
Definition: Button.h:112
std::string GetLabel2() const
Get the second label if present.
Definition: Button.h:146
void SetVisible(bool visible)
Set the control on window to visible.
Definition: Button.h:73
void SetEnabled(bool enabled)
Set's the control's enabled/disabled state.
Definition: Button.h:86
void SetLabel(const std::string &label)
To set the text string on button.
Definition: Button.h:99
~CButton() override=default
Destructor.
void SetLabel2(const std::string &label)
If two labels are used for button becomes it set with them.
Definition: Button.h:133
void ATTRIBUTE_HIDDEN Log(const AddonLog loglevel, const char *format,...)
Add a message to Kodi's log.
Definition: AddonBase.h:749