xbmc
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 "AddonCallback.h"
12 #include "AddonString.h"
13 #include "Control.h"
14 #include "swighelper.h"
15 
16 #include <limits.h>
17 #include <mutex>
18 #include <vector>
19 
20 namespace XBMCAddon
21 {
22  namespace xbmcgui
23  {
24  // Forward declare the interceptor as the AddonWindowInterceptor.h
25  // file needs to include the Window class because of the template
26  class InterceptorBase;
27 
28  //
43  class Action : public AddonClass
44  {
45  public:
46  Action() = default;
47 
48 #ifndef SWIG
49  explicit Action(const CAction& caction) { setFromCAction(caction); }
50 
51  void setFromCAction(const CAction& caction);
52 
53  long id = -1;
54  float fAmount1 = 0.0f;
55  float fAmount2 = 0.0f;
56  float fRepeat = 0.0f;
57  unsigned long buttonCode = 0;
58  std::string strAction;
59 
60  // Not sure if this is correct but it's here for now.
61  AddonClass::Ref<Control> control; // previously pObject
62 #endif
63 
64 #ifdef DOXYGEN_SHOULD_USE_THIS
65  getId();
90 #else
91  long getId() { XBMC_TRACE; return id; }
92 #endif
93 
94 #ifdef DOXYGEN_SHOULD_USE_THIS
95  getButtonCode();
103 #else
104  long getButtonCode() { XBMC_TRACE; return buttonCode; }
105 #endif
106 
107 #ifdef DOXYGEN_SHOULD_USE_THIS
108  getAmount1();
116 #else
117  float getAmount1() { XBMC_TRACE; return fAmount1; }
118 #endif
119 
120 #ifdef DOXYGEN_SHOULD_USE_THIS
121  getAmount2();
129 #else
130  float getAmount2() { XBMC_TRACE; return fAmount2; }
131 #endif
132  };
134 
135  //==========================================================================
136  // This is the main class for the xbmcgui.Window functionality. It is tied
137  // into the main Kodi windowing system via the Interceptor
138  //==========================================================================
139  //
185  //
186  class Window : public AddonCallback
187  {
188  friend class WindowDialogMixin;
189  bool isDisposed = false;
190 
191  void doAddControl(Control* pControl, CCriticalSection* gcontext, bool wait);
192  void doRemoveControl(Control* pControl, CCriticalSection* gcontext, bool wait);
193 
194  protected:
195 #ifndef SWIG
196  InterceptorBase* window;
197  int iWindowId = -1;
198 
199  std::vector<AddonClass::Ref<Control> > vecControls;
200  int iOldWindowId = 0;
201  int iCurrentControlId = 3000;
202  bool bModal = false;
203  CEvent m_actionEvent;
204 
205  bool canPulse = false;
206 
207  // I REALLY hate this ... but it's the simplest fix right now.
208  bool existingWindow = true;
209  bool destroyAfterDeInit = false;
210 
217  explicit Window(bool discrim);
218 
219  void deallocating() override;
220 
225  static int getNextAvailableWindowId();
226 
232  void setWindow(InterceptorBase* _window);
233 
238  void popActiveWindowId();
239 
244  Control* GetControlById(int iControlId, CCriticalSection* gc);
245 
246  SWIGHIDDENVIRTUAL void PulseActionEvent();
247  SWIGHIDDENVIRTUAL bool WaitForActionEvent(unsigned int milliseconds);
248 #endif
249 
250  public:
251  explicit Window(int existingWindowId = -1);
252 
253  ~Window() override;
254 
255 #ifndef SWIG
256  SWIGHIDDENVIRTUAL bool OnMessage(CGUIMessage& message);
257  SWIGHIDDENVIRTUAL bool OnAction(const CAction &action);
258  SWIGHIDDENVIRTUAL bool OnBack(int actionId);
259  SWIGHIDDENVIRTUAL void OnDeinitWindow(int nextWindowID);
260 
261  SWIGHIDDENVIRTUAL bool IsDialogRunning() const
262  {
263  XBMC_TRACE;
264  return false;
265  }
266  SWIGHIDDENVIRTUAL bool IsDialog() const
267  {
268  XBMC_TRACE;
269  return false;
270  }
271  SWIGHIDDENVIRTUAL bool IsModalDialog() const
272  {
273  XBMC_TRACE;
274  return false;
275  }
276  SWIGHIDDENVIRTUAL bool IsMediaWindow() const
277  {
278  XBMC_TRACE;
279  return false;
280  }
281  SWIGHIDDENVIRTUAL void dispose();
282 
287  inline void interceptorClear()
288  {
289  std::unique_lock<CCriticalSection> lock(*this);
290  window = NULL;
291  }
292 #endif
293 
294  //
312  //
313 
314  // callback takes a parameter
315 #ifdef DOXYGEN_SHOULD_USE_THIS
316  onAction(...);
357 #else
358  virtual void onAction(Action* action);
359 #endif
360 
361  // on control is not actually on Window in the api but is called into Python anyway.
362 #ifdef DOXYGEN_SHOULD_USE_THIS
363  void onControl(...);
387 #else
388  virtual void onControl(Control* control);
389 #endif
390 
391 #ifdef DOXYGEN_SHOULD_USE_THIS
392  onClick(...);
418 #else
419  virtual void onClick(int controlId);
420 #endif
421 
422 #ifdef DOXYGEN_SHOULD_USE_THIS
423  onDoubleClick(...);
449 #else
450  virtual void onDoubleClick(int controlId);
451 #endif
452 
453 #ifdef DOXYGEN_SHOULD_USE_THIS
454  onFocus(...);
479 #else
480  virtual void onFocus(int controlId);
481 #endif
482 
483 #ifdef DOXYGEN_SHOULD_USE_THIS
484  onInit(...);
506 #else
507  virtual void onInit();
508 #endif
509 
510 
511 #ifdef DOXYGEN_SHOULD_USE_THIS
512  show();
525 #else
526  SWIGHIDDENVIRTUAL void show();
527 #endif
528 
529 #ifdef DOXYGEN_SHOULD_USE_THIS
530  setFocus(...);
542 #else
543  SWIGHIDDENVIRTUAL void setFocus(Control* pControl);
544 #endif
545 
546 #ifdef DOXYGEN_SHOULD_USE_THIS
547  setFocusId(...);
557 #else
558  SWIGHIDDENVIRTUAL void setFocusId(int iControlId);
559 #endif
560 
561 #ifdef DOXYGEN_SHOULD_USE_THIS
562  getFocus();
572 #else
573  SWIGHIDDENVIRTUAL Control* getFocus();
574 #endif
575 
576 #ifdef DOXYGEN_SHOULD_USE_THIS
577  getFocusId();
587 #else
588  SWIGHIDDENVIRTUAL long getFocusId();
589 #endif
590 
591 #ifdef DOXYGEN_SHOULD_USE_THIS
592  removeControl(...);
605 #else
606  SWIGHIDDENVIRTUAL void removeControl(Control* pControl);
607 #endif
608 
609 #ifdef DOXYGEN_SHOULD_USE_THIS
610  removeControls(...);
624 #else
625  SWIGHIDDENVIRTUAL void removeControls(std::vector<Control*> pControls);
626 #endif
627 
628 #ifdef DOXYGEN_SHOULD_USE_THIS
629  getHeight();
640 #else
641  SWIGHIDDENVIRTUAL long getHeight();
642 #endif
643 
644 #ifdef DOXYGEN_SHOULD_USE_THIS
645  getWidth();
656 #else
657  SWIGHIDDENVIRTUAL long getWidth();
658 #endif
659 
660 #ifdef DOXYGEN_SHOULD_USE_THIS
661  setProperty(...);
688 #else
689  SWIGHIDDENVIRTUAL void setProperty(const char* key, const String& value);
690 #endif
691 
692 #ifdef DOXYGEN_SHOULD_USE_THIS
693  getProperty(...);
718 #else
719  SWIGHIDDENVIRTUAL String getProperty(const char* key);
720 #endif
721 
722 #ifdef DOXYGEN_SHOULD_USE_THIS
723  clearProperty(...);
748 #else
749  SWIGHIDDENVIRTUAL void clearProperty(const char* key);
750 #endif
751 
752 #ifdef DOXYGEN_SHOULD_USE_THIS
753  clearProperties();
770 #else
771  SWIGHIDDENVIRTUAL void clearProperties();
772 #endif
773 
774 #ifdef DOXYGEN_SHOULD_USE_THIS
775  close();
785 #else
786  SWIGHIDDENVIRTUAL void close();
787 #endif
788 
789 #ifdef DOXYGEN_SHOULD_USE_THIS
790  doModal();
796 #else
797 
798  SWIGHIDDENVIRTUAL void doModal();
799 #endif
800 
801 #ifdef DOXYGEN_SHOULD_USE_THIS
802  addControl(...);
833 #else
834  SWIGHIDDENVIRTUAL void addControl(Control* pControl);
835 #endif
836 
837 #ifdef DOXYGEN_SHOULD_USE_THIS
838  addControls(...);
852 #else
853  SWIGHIDDENVIRTUAL void addControls(std::vector<Control*> pControls);
854 #endif
855 
856 #ifdef DOXYGEN_SHOULD_USE_THIS
857  getControl(...);
872 #else
873  SWIGHIDDENVIRTUAL Control* getControl(int iControlId);
874 #endif
875  };
877  }
878 }
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: Window.h:43
Definition: WindowDialogMixin.h:23
This class is a smart pointer for a Referenced class.
Definition: AddonClass.h:154
Definition: Control.h:61
void interceptorClear()
This is called from the InterceptorBase destructor to prevent further use of the interceptor from the...
Definition: Window.h:287
These two classes are closely associated with the Interceptor template below.
Definition: WindowInterceptor.h:27
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
Defining LOG_LIFECYCLE_EVENTS will log all instantiations, deletions and also reference countings (in...
Definition: Addon.cpp:25
virtual void deallocating()
This method is meant to be called from the destructor of the lowest level class.
Definition: AddonClass.h:82
Definition: GUIMessage.h:365
Definition: Window.h:186
This class is the superclass for all reference counted classes in the api.
Definition: AddonClass.h:57
This class is the superclass for all API classes that are expected to be able to handle cross-languag...
Definition: AddonCallback.h:23