DISTRHO Plugin Framework
Window.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
6  * or without fee is hereby granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef DGL_WINDOW_HPP_INCLUDED
18 #define DGL_WINDOW_HPP_INCLUDED
19 
20 #include "Geometry.hpp"
21 
22 #ifdef DISTRHO_DEFINES_H_INCLUDED
23 START_NAMESPACE_DISTRHO
24 class UIExporter;
25 END_NAMESPACE_DISTRHO
26 #endif
27 
28 START_NAMESPACE_DGL
29 
30 // -----------------------------------------------------------------------
31 
32 class Application;
33 class Widget;
34 class StandaloneWindow;
35 
36 class Window
37 {
38 public:
39 #ifndef DGL_FILE_BROWSER_DISABLED
40  /**
41  File browser options.
42  */
44  const char* startDir;
45  const char* title;
46  uint width;
47  uint height;
48 
49  /**
50  File browser buttons.
51 
52  0 means hidden.
53  1 means visible and unchecked.
54  2 means visible and checked.
55  */
56  struct Buttons {
57  uint listAllFiles;
58  uint showHidden;
59  uint showPlaces;
60 
61  /** Constuctor for default values */
63  : listAllFiles(2),
64  showHidden(1),
65  showPlaces(1) {}
66  } buttons;
67 
68  /** Constuctor for default values */
70  : startDir(nullptr),
71  title(nullptr),
72  width(0),
73  height(0),
74  buttons() {}
75  };
76 #endif // DGL_FILE_BROWSER_DISABLED
77 
78  explicit Window(Application& app);
79  explicit Window(Application& app, Window& parent);
80  explicit Window(Application& app, intptr_t parentId, bool resizable);
81  virtual ~Window();
82 
83  void show();
84  void hide();
85  void close();
86  void exec(bool lockWait = false);
87 
88  void focus();
89  void repaint() noexcept;
90 
91 #ifndef DGL_FILE_BROWSER_DISABLED
92  bool openFileBrowser(const FileBrowserOptions& options);
93 #endif
94 
95  bool isEmbed() const noexcept;
96 
97  bool isVisible() const noexcept;
98  void setVisible(bool yesNo);
99 
100  bool isResizable() const noexcept;
101  void setResizable(bool yesNo);
102 
103  uint getWidth() const noexcept;
104  uint getHeight() const noexcept;
105  Size<uint> getSize() const noexcept;
106  void setSize(uint width, uint height);
107  void setSize(Size<uint> size);
108 
109  const char* getTitle() const noexcept;
110  void setTitle(const char* title);
111 
112  void setGeometryConstraints(uint width, uint height, bool aspect);
113  void setTransientWinId(uintptr_t winId);
114 
115  double getScaling() const noexcept;
116  void setScaling(double scaling) noexcept;
117 
118  bool getIgnoringKeyRepeat() const noexcept;
119  void setIgnoringKeyRepeat(bool ignore) noexcept;
120 
121  Application& getApp() const noexcept;
122  intptr_t getWindowId() const noexcept;
123 
124  void addIdleCallback(IdleCallback* const callback);
125  void removeIdleCallback(IdleCallback* const callback);
126 
127 protected:
128  virtual void onDisplayBefore();
129  virtual void onDisplayAfter();
130  virtual void onReshape(uint width, uint height);
131  virtual void onClose();
132 
133 #ifndef DGL_FILE_BROWSER_DISABLED
134  virtual void fileBrowserSelected(const char* filename);
135 #endif
136 
137 private:
138  struct PrivateData;
139  PrivateData* const pData;
140  friend class Application;
141  friend class Widget;
142  friend class StandaloneWindow;
143 #ifdef DISTRHO_DEFINES_H_INCLUDED
144  friend class DISTRHO_NAMESPACE::UIExporter;
145 #endif
146 
147  virtual void _addWidget(Widget* const widget);
148  virtual void _removeWidget(Widget* const widget);
149  void _idle();
150 
151  bool handlePluginKeyboard(const bool press, const uint key);
152  bool handlePluginSpecial(const bool press, const Key key);
153 
154  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Window)
155 };
156 
157 // -----------------------------------------------------------------------
158 
159 END_NAMESPACE_DGL
160 
161 #endif // DGL_WINDOW_HPP_INCLUDED
FileBrowserOptions()
Definition: Window.hpp:69
Definition: Window.hpp:36
Buttons()
Definition: Window.hpp:62
Definition: StandaloneWindow.hpp:28
Definition: Window.hpp:43
Definition: Base.hpp:178
Definition: Window.hpp:56
Definition: Application.hpp:41
Definition: Widget.hpp:61