comparison DPF-Prymula-audioplugins/dpf/dgl/src/WindowPrivateData.hpp @ 3:84e66ea83026

DPF-Prymula-audioplugins-0.231015-2
author prymula <prymula76@outlook.com>
date Mon, 16 Oct 2023 21:53:34 +0200
parents
children
comparison
equal deleted inserted replaced
2:cf2cb71d31dd 3:84e66ea83026
1 /*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2022 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_PRIVATE_DATA_HPP_INCLUDED
18 #define DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED
19
20 #include "../Window.hpp"
21 #include "../Widget.hpp"
22 #include "ApplicationPrivateData.hpp"
23
24 #include "pugl.hpp"
25
26 #include <list>
27
28 START_NAMESPACE_DGL
29
30 class TopLevelWidget;
31
32 // -----------------------------------------------------------------------
33
34 struct Window::PrivateData : IdleCallback {
35 /** Reference to the DGL Application class this (private data) window associates with. */
36 Application& app;
37
38 /** Direct access to the DGL Application private data where we registers ourselves in. */
39 Application::PrivateData* const appData;
40
41 /** Pointer to the the DGL Window class that this private data belongs to. */
42 Window* const self;
43
44 /** Pugl view instance. */
45 PuglView* view;
46
47 /** Reserved space for graphics context. */
48 mutable uint8_t graphicsContext[sizeof(void*)];
49
50 /** The top-level widgets associated with this Window. */
51 std::list<TopLevelWidget*> topLevelWidgets;
52
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;
56
57 /** Whether this Window is currently visible/mapped. Defaults to false. */
58 bool isVisible;
59
60 /** Whether this Window is embed into another (usually not DGL-controlled) Window. */
61 const bool isEmbed;
62
63 /** Whether to ignore resize requests and feed them into the host instead. used for VST3 */
64 const bool usesSizeRequest;
65
66 /** Scale factor to report to widgets on request, purely informational. */
67 double scaleFactor;
68
69 /** Automatic scaling to apply on widgets, implemented internally. */
70 bool autoScaling;
71 double autoScaleFactor;
72
73 /** Pugl geometry constraints access. */
74 uint minWidth, minHeight;
75 bool keepAspectRatio;
76
77 /** Whether to ignore idle callback requests, useful for temporary windows. */
78 bool ignoreIdleCallbacks;
79
80 /** Whether we are waiting to receive clipboard data, ignoring some events in the process. */
81 bool waitingForClipboardData;
82 bool waitingForClipboardEvents;
83
84 /** The type id returned by the last onClipboardDataOffer call. */
85 uint32_t clipboardTypeId;
86
87 /** Render to a picture file when non-null, automatically free+unset after saving. */
88 char* filenameToRenderInto;
89
90 #ifndef DGL_FILE_BROWSER_DISABLED
91 /** Handle for file browser dialog operations. */
92 DGL_NAMESPACE::FileBrowserHandle fileBrowserHandle;
93 #endif
94
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)
100
101 /** Constructor for a non-modal window. */
102 Modal() noexcept
103 : parent(nullptr),
104 child(nullptr),
105 enabled(false) {}
106
107 /** Constructor for a modal window (with a parent). */
108 Modal(PrivateData* const p) noexcept
109 : parent(p),
110 child(nullptr),
111 enabled(false) {}
112
113 /** Destructor. */
114 ~Modal() noexcept
115 {
116 DISTRHO_SAFE_ASSERT(! enabled);
117 }
118
119 DISTRHO_DECLARE_NON_COPYABLE(Modal)
120 DISTRHO_PREVENT_HEAP_ALLOCATION
121 } modal;
122
123 /** Constructor for a regular, standalone window. */
124 explicit PrivateData(Application& app, Window* self);
125
126 /** Constructor for a modal window. */
127 explicit PrivateData(Application& app, Window* self, PrivateData* ppData);
128
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);
131
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);
135
136 /** Destructor. */
137 ~PrivateData() override;
138
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();
143
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.
147 *
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.
150 */
151 void close();
152
153 void show();
154 void hide();
155
156 void focus();
157
158 void setResizable(bool resizable);
159
160 const GraphicsContext& getGraphicsContext() const noexcept;
161
162 // idle callback stuff
163 void idleCallback() override;
164 bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs);
165 bool removeIdleCallback(IdleCallback* callback);
166
167 #ifndef DGL_FILE_BROWSER_DISABLED
168 // file handling
169 bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions& options);
170 #endif
171
172 static void renderToPicture(const char* filename, const GraphicsContext& context, uint width, uint height);
173
174 // modal handling
175 void startModal();
176 void stopModal();
177 void runAsModal(bool blockWait);
178
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);
189
190 // clipboard related handling
191 const void* getClipboard(size_t& dataSize);
192 uint32_t onClipboardDataOffer();
193 void onClipboardData(uint32_t typeId);
194
195 // Pugl event handling entry point
196 static PuglStatus puglEventCallback(PuglView* view, const PuglEvent* event);
197
198 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PrivateData)
199 };
200
201 // -----------------------------------------------------------------------
202
203 END_NAMESPACE_DGL
204
205 #endif // DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED