Cleanup
[carla.git] / source / modules / dgl / src / WindowPrivateData.hpp
blobd5c3cbd8a6b6cd60d314fb58a71f86f9d19fff89
1 /*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
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.
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.
17 #ifndef DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED
18 #define DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED
20 #include "../Window.hpp"
21 #include "../Widget.hpp"
22 #include "ApplicationPrivateData.hpp"
24 #include "pugl.hpp"
26 #include <list>
28 START_NAMESPACE_DGL
30 class TopLevelWidget;
32 // -----------------------------------------------------------------------
34 struct Window::PrivateData : IdleCallback {
35 /** Reference to the DGL Application class this (private data) window associates with. */
36 Application& app;
38 /** Direct access to the DGL Application private data where we registers ourselves in. */
39 Application::PrivateData* const appData;
41 /** Pointer to the the DGL Window class that this private data belongs to. */
42 Window* const self;
44 /** Pugl view instance. */
45 PuglView* view;
47 /** Reserved space for graphics context. */
48 mutable uint8_t graphicsContext[sizeof(void*)];
50 /** The top-level widgets associated with this Window. */
51 std::list<TopLevelWidget*> topLevelWidgets;
53 /** Whether this Window is closed (not visible or counted in the Application it is tied to).
54 Defaults to true unless embed (embed windows are never closed). */
55 bool isClosed;
57 /** Whether this Window is currently visible/mapped. Defaults to false. */
58 bool isVisible;
60 /** Whether this Window is embed into another (usually not DGL-controlled) Window. */
61 const bool isEmbed;
63 /** Whether to ignore resize requests and feed them into the host instead. used for VST3 */
64 const bool usesSizeRequest;
66 /** Scale factor to report to widgets on request, purely informational. */
67 double scaleFactor;
69 /** Automatic scaling to apply on widgets, implemented internally. */
70 bool autoScaling;
71 double autoScaleFactor;
73 /** Pugl geometry constraints access. */
74 uint minWidth, minHeight;
75 bool keepAspectRatio;
77 /** Whether to ignore idle callback requests, useful for temporary windows. */
78 bool ignoreIdleCallbacks;
80 /** Whether we are waiting to receive clipboard data, ignoring some events in the process. */
81 bool waitingForClipboardData;
82 bool waitingForClipboardEvents;
84 /** The type id returned by the last onClipboardDataOffer call. */
85 uint32_t clipboardTypeId;
87 /** Render to a picture file when non-null, automatically free+unset after saving. */
88 char* filenameToRenderInto;
90 #ifndef DGL_FILE_BROWSER_DISABLED
91 /** Handle for file browser dialog operations. */
92 DGL_NAMESPACE::FileBrowserHandle fileBrowserHandle;
93 #endif
95 /** Modal window setup. */
96 struct Modal {
97 PrivateData* parent; // parent of this window (so we can become modal)
98 PrivateData* child; // child window to give focus to when modal mode is enabled
99 bool enabled; // wherever modal mode is enabled (only possible if parent != null)
101 /** Constructor for a non-modal window. */
102 Modal() noexcept
103 : parent(nullptr),
104 child(nullptr),
105 enabled(false) {}
107 /** Constructor for a modal window (with a parent). */
108 Modal(PrivateData* const p) noexcept
109 : parent(p),
110 child(nullptr),
111 enabled(false) {}
113 /** Destructor. */
114 ~Modal() noexcept
116 DISTRHO_SAFE_ASSERT(! enabled);
119 DISTRHO_DECLARE_NON_COPYABLE(Modal)
120 DISTRHO_PREVENT_HEAP_ALLOCATION
121 } modal;
123 /** Constructor for a regular, standalone window. */
124 explicit PrivateData(Application& app, Window* self);
126 /** Constructor for a modal window. */
127 explicit PrivateData(Application& app, Window* self, PrivateData* ppData);
129 /** Constructor for an embed Window, with a few extra hints from the host side. */
130 explicit PrivateData(Application& app, Window* self, uintptr_t parentWindowHandle, double scaling, bool resizable);
132 /** Constructor for an embed Window, with a few extra hints from the host side. */
133 explicit PrivateData(Application& app, Window* self, uintptr_t parentWindowHandle,
134 uint width, uint height, double scaling, bool resizable, bool isVST3);
136 /** Destructor. */
137 ~PrivateData() override;
139 /** Helper initialization function called at the end of all this class constructors. */
140 void initPre(uint width, uint height, bool resizable);
141 /** Helper initialization function called on the Window constructor after we are done. */
142 bool initPost();
144 /** Hide window and notify application of a window close event.
145 * Does nothing if window is embed (that is, not standalone).
146 * The application event-loop will stop when all windows have been closed.
148 * @note It is possible to hide the window while not stopping the event-loop.
149 * A closed window is always hidden, but the reverse is not always true.
151 void close();
153 void show();
154 void hide();
156 void focus();
158 void setResizable(bool resizable);
160 const GraphicsContext& getGraphicsContext() const noexcept;
162 // idle callback stuff
163 void idleCallback() override;
164 bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs);
165 bool removeIdleCallback(IdleCallback* callback);
167 #ifndef DGL_FILE_BROWSER_DISABLED
168 // file handling
169 bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions& options);
170 #endif
172 static void renderToPicture(const char* filename, const GraphicsContext& context, uint width, uint height);
174 // modal handling
175 void startModal();
176 void stopModal();
177 void runAsModal(bool blockWait);
179 // pugl events
180 void onPuglConfigure(double width, double height);
181 void onPuglExpose();
182 void onPuglClose();
183 void onPuglFocus(bool focus, CrossingMode mode);
184 void onPuglKey(const Widget::KeyboardEvent& ev);
185 void onPuglText(const Widget::CharacterInputEvent& ev);
186 void onPuglMouse(const Widget::MouseEvent& ev);
187 void onPuglMotion(const Widget::MotionEvent& ev);
188 void onPuglScroll(const Widget::ScrollEvent& ev);
190 // clipboard related handling
191 const void* getClipboard(size_t& dataSize);
192 uint32_t onClipboardDataOffer();
193 void onClipboardData(uint32_t typeId);
195 // Pugl event handling entry point
196 static PuglStatus puglEventCallback(PuglView* view, const PuglEvent* event);
198 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PrivateData)
201 // -----------------------------------------------------------------------
203 END_NAMESPACE_DGL
205 #endif // DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED