1 // This file is part of Desktop App Toolkit,
2 // a set of libraries for developing nice desktop applications.
3 //
4 // For license and copyright information please follow this link:
5 // https://github.com/desktop-app/legal/blob/master/LEGAL
6 //
7 #pragma once
8 
9 #include "ui/platform/ui_platform_window.h"
10 #include "ui/platform/win/ui_window_shadow_win.h"
11 
12 #include <windef.h>
13 
14 namespace Ui {
15 namespace Platform {
16 
17 class TitleWidget;
18 
19 class WindowHelper final : public BasicWindowHelper {
20 public:
21 	explicit WindowHelper(not_null<RpWidget*> window);
22 	~WindowHelper();
23 
24 	not_null<RpWidget*> body() override;
25 	QMargins frameMargins() override;
26 	void setTitle(const QString &title) override;
27 	void setTitleStyle(const style::WindowTitle &st) override;
28 	void setNativeFrame(bool enabled) override;
29 	void setMinimumSize(QSize size) override;
30 	void setFixedSize(QSize size) override;
31 	void setGeometry(QRect rect) override;
32 	void showFullScreen() override;
33 	void showNormal() override;
34 
35 private:
36 	class NativeFilter;
37 	friend class NativeFilter;
38 
39 	void init();
40 	void updateMargins();
41 	void updateWindowFrameColors();
42 	void updateWindowFrameColors(bool active);
43 	void updateSystemMenu();
44 	void updateSystemMenu(Qt::WindowState state);
45 	void initialShadowUpdate();
46 	void fixMaximizedWindow();
47 	[[nodiscard]] bool handleNativeEvent(
48 		UINT msg,
49 		WPARAM wParam,
50 		LPARAM lParam,
51 		LRESULT *result);
52 	[[nodiscard]] bool fixedSize() const;
53 
54 	[[nodiscard]] int titleHeight() const;
55 	static not_null<NativeFilter*> GetNativeFilter();
56 
57 	const HWND _handle = nullptr;
58 	const not_null<TitleWidget*> _title;
59 	const not_null<RpWidget*> _body;
60 	std::optional<WindowShadow> _shadow;
61 	bool _updatingMargins = false;
62 	QMargins _marginsDelta;
63 	HMENU _menu = nullptr;
64 	bool _isFullScreen = false;
65 
66 };
67 
68 [[nodiscard]] HWND GetWindowHandle(not_null<QWidget*> widget);
69 [[nodiscard]] HWND GetWindowHandle(not_null<QWindow*> window);
70 
71 void SendWMPaintForce(not_null<QWidget*> widget);
72 void SendWMPaintForce(not_null<QWindow*> window);
73 
74 } // namespace Platform
75 } // namespace Ui
76