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"
32 // -----------------------------------------------------------------------
34 struct Window::PrivateData
: IdleCallback
{
35 /** Reference to the DGL Application class this (private data) window associates with. */
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. */
44 /** Pugl view instance. */
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). */
57 /** Whether this Window is currently visible/mapped. Defaults to false. */
60 /** Whether this Window is embed into another (usually not DGL-controlled) Window. */
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. */
69 /** Automatic scaling to apply on widgets, implemented internally. */
71 double autoScaleFactor
;
73 /** Pugl geometry constraints access. */
74 uint minWidth
, minHeight
;
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
;
95 /** Modal window setup. */
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. */
107 /** Constructor for a modal window (with a parent). */
108 Modal(PrivateData
* const p
) noexcept
116 DISTRHO_SAFE_ASSERT(! enabled
);
119 DISTRHO_DECLARE_NON_COPYABLE(Modal
)
120 DISTRHO_PREVENT_HEAP_ALLOCATION
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
);
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. */
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.
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
169 bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions
& options
);
172 static void renderToPicture(const char* filename
, const GraphicsContext
& context
, uint width
, uint height
);
177 void runAsModal(bool blockWait
);
180 void onPuglConfigure(double width
, double height
);
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 // -----------------------------------------------------------------------
205 #endif // DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED