AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AWindow.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include "AUI/Views.h"
15#include "AUI/Common/AString.h"
16
17#include "AUI/Common/AObject.h"
18#include "AUI/Common/ASignal.h"
19
20#include "AUI/Platform/AWindowBase.h"
21#include "AUI/Thread/IEventLoop.h"
22#include "AUI/Util/AMetric.h"
23#include "AWindowNativePtr.h"
24#include <AUI/Enum/WindowStyle.h>
25#include <AUI/Enum/AScreenOrientation.h>
26
27#if AUI_PLATFORM_WIN
28#include <windows.h>
29
30#elif AUI_PLATFORM_ANDROID
31#include <jni.h>
32#elif AUI_PLATFORM_APPLE
33#else
34
35#endif
36
37class ARender;
38class AWindowManager;
39
44class API_AUI_VIEWS AWindow: public AWindowBase
45{
46 friend class OpenGLRenderingContext;
47 friend class CommonRenderingContext;
48 friend class SoftwareRenderingContext;
49 friend class AWindowManager;
50 friend struct painter;
51public:
52 AWindow(const AString& name = "My window", int width = 854_dp, int height = 500_dp, AWindow* parent = nullptr, WindowStyle ws = WindowStyle::DEFAULT) {
53 windowNativePreInit(name, width, height, parent, ws);
54 }
55 virtual ~AWindow();
56
57 [[nodiscard]]
58 unsigned frameMillis() const noexcept override {
59 return mFrameMillis;
60 }
61
62 void redraw();
63
64 void blockUserInput(bool blockUserInput = true) override;
65
73 static bool isRedrawWillBeEfficient();
74
75 void setIcon(const AImage& image);
76
80 void quit();
81
82 void setWindowStyle(WindowStyle ws);
83
87 void minimize();
88
92 bool isMinimized() const;
93
97 void maximize();
98
102 bool isMaximized() const;
103
107 void restore();
108
109 void flagRedraw() override;
110
118 void show();
119 void close();
120 void hide();
121
122 [[nodiscard]]
123 bool isClosed() const noexcept;
124
125#if AUI_PLATFORM_WIN
126 HWND getNativeHandle() { return mHandle; }
127#elif AUI_PLATFORM_ANDROID
128 jobject getNativeHandle() { return mHandle; }
129#elif AUI_PLATFORM_APPLE
130#else
131 AWindowNativePtr getNativeHandle() { return mHandle; }
132#endif
133
134 auto nativeHandle() const {
135 return mHandle;
136 }
137
138 const AString& getWindowTitle() const
139 {
140 return mWindowTitle;
141 }
142
143 glm::ivec2 getWindowPosition() const;
144
145 void setPosition(glm::ivec2 position) override;
146 void setSize(glm::ivec2 size) override;
147 void setGeometry(int x, int y, int width, int height) override;
148
149#if AUI_PLATFORM_LINUX
150 void applyGeometryToChildren() override;
151#endif
152
153 void onFocusAcquired() override;
154 void onFocusLost() override;
155
156 void onKeyDown(AInput::Key key) override;
157 void onKeyRepeat(AInput::Key key) override;
158
159 void setFocusNextViewOnTab(bool value) {
160 mFocusNextViewOnTab = value;
161 }
162
173 static _<AWindow> wrapViewToWindow(const _<AView>& view, const AString& title, int width = 854_dp, int height = 500_dp, AWindow* parent = nullptr, WindowStyle ws = WindowStyle::DEFAULT);
174
178 static AWindowBase* current();
179
186 [[nodiscard]] glm::ivec2 mapPositionTo(const glm::ivec2& position, _<AWindow> other);
187
193 [[nodiscard]] glm::ivec2 unmapPosition(const glm::ivec2& position);
194
200 [[nodiscard]] glm::ivec2 mapPosition(const glm::ivec2& position);
201
202 _<AOverlappingSurface> createOverlappingSurfaceImpl(const glm::ivec2& position, const glm::ivec2& size) override;
203
204 void closeOverlappingSurfaceImpl(AOverlappingSurface* surface) override;
205 virtual void onCloseButtonClicked();
206
207 void forceUpdateCursor() override;
208
209 void showTouchscreenKeyboardImpl() override;
210 void hideTouchscreenKeyboardImpl() override;
211
217 void moveToCenter();
218
224 void setMobileScreenOrientation(AScreenOrientation screenOrientation);
225
226signals:
227 emits<> closed;
228 emits<> shown;
229
235
240
245
250
251 bool consumesClick(const glm::ivec2& pos) override;
252
253 void onPointerMove(glm::vec2 pos, const APointerMoveEvent& event) override;
254
255protected:
256#if AUI_PLATFORM_WIN
257 HICON mIcon = nullptr;
258 virtual LRESULT winProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
259#elif AUI_PLATFORM_ANDROID
260#elif AUI_PLATFORM_APPLE
261#endif
262 AWindowNativePtr mHandle = 0; // on linux AWindowNativePtr is not a pointer type so using zero here
263 WindowStyle mWindowStyle = WindowStyle::DEFAULT;
264
265 virtual void doDrawWindow();
266 virtual void onClosed();
267
268 void windowNativePreInit(const AString& name, int width, int height, AWindow* parent, WindowStyle ws);
269
273 void allowDragNDrop();
274
279 AWindow(std::nullptr_t) {}
280
281 void createDevtoolsWindow() override;
282
283 float fetchDpiFromSystem() const override;
284
289
290private:
291#if AUI_PLATFORM_WIN
292
293#elif AUI_PLATFORM_ANDROID
294#elif AUI_PLATFORM_LINUX
298 struct {
299 uint32_t lo = 0;
300 uint32_t hi = 0;
301 /* XID */ unsigned long counter;
302 } mXsyncRequestCounter;
303 bool mWasMaximized = false;
304
305 void* mIC = nullptr; // input context
306#endif
307#ifdef AUI_PLATFORM_MACOS
308 bool mRedrawFlag = false;
309#else
310 bool mRedrawFlag = true;
311#endif
312 AString mWindowClass;
313 AWindow* mParentWindow;
314
315 unsigned mFrameMillis = 1;
316
320 _<AWindow> mSelfHolder;
321
322 AString mWindowTitle;
323
324#if AUI_PLATFORM_WIN
325 friend LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
326#endif
327#if AUI_PLATFORM_LINUX
328 unsigned long xGetWindowProperty(unsigned long property, unsigned long type, unsigned char** value) const;
329 void xSendEventToWM(unsigned long atom, long a, long b, long c, long d, long e) const;
330#endif
331
332};
Represents a Unicode character string.
Definition AString.h:37
bool consumesClick(const glm::ivec2 &pos) override
Determines whether this AView processes this click or passes it thru.
Definition AViewContainerBase.cpp:371
void redraw()
Request window manager to redraw this AView.
Definition AView.cpp:68
virtual void blockUserInput(bool blockUserInput=true)
Enables or disables user input for this window.
Definition AWindowBase.cpp:518
virtual _< AOverlappingSurface > createOverlappingSurfaceImpl(const glm::ivec2 &position, const glm::ivec2 &size)=0
void onPointerMove(glm::vec2 pos, const APointerMoveEvent &event) override
Handles pointer hover events.
Definition AWindowBase.cpp:353
virtual void forceUpdateCursor()
Updates cursor by triggering onPointerMove on the same position (mMousePos).
Definition AWindowBase.cpp:333
Definition AWindowManager.h:23
Represents a window in the underlying windowing system.
Definition AWindow.h:45
void allowDragNDrop()
Enables drag-n-drop for this window.
Definition AWindowsImpl.cpp:146
bool mFocusNextViewOnTab
defines if the next view must be focused on tab button pressed
Definition AWindow.h:288
emits< glm::vec2 > moving
Window is moving.
Definition AWindow.h:234
emits restored
Window is restored (shown from the taskbar, deiconified).
Definition AWindow.h:249
AWindow(std::nullptr_t)
Constructor for custom initialization logic.
Definition AWindow.h:279
emits maximized
Window is maximized.
Definition AWindow.h:239
unsigned frameMillis() const noexcept override
Returns previous frame's rendering duration in millis.
Definition AWindow.h:58
emits minimized
Window is minimized (hidden to the taskbar, iconified).
Definition AWindow.h:244
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
AScreenOrientation
Controls screen orientation.
Definition AScreenOrientation.h:20
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:348
Pointing method move event.
Definition APointerMoveEvent.h:21