mousetrap v0.2.0
Loading...
Searching...
No Matches
window.hpp
1//
2// Copyright 2022 Clemens Cords
3// Created on 8/5/22 by clem (mail@clemens-cords.com)
4//
5
6#pragma once
7
8#include <mousetrap/widget.hpp>
9
10#ifdef DOXYGEN
11 #include "../../docs/doxygen.inl"
12#endif
13
14namespace mousetrap
15{
16 #ifndef DOXYGEN
17 class Application;
18 class Window;
19 class HeaderBar;
20 namespace detail
21 {
22 struct _WindowInternal
23 {
24 GObject parent_instance;
25
26 AdwApplicationWindow* native;
27 AdwHeaderBar* header_bar;
28 GtkBox* vbox;
29 AdwBin* header_bar_area;
30 AdwBin* content_area;
31 };
32 using WindowInternal = _WindowInternal;
33 DEFINE_INTERNAL_MAPPING(Window);
34 }
35 #endif
36
37 /// @brief window, registered to an application
38 /// \signals
39 /// \signal_close_request{Window}
40 /// \signal_activate_default_widget{Window}
41 /// \signal_activate_focused_widget{Window}
42 /// \widget_signals{Window}
43 class Window : public detail::notify_if_gtk_uninitialized,
44 public Widget,
45 HAS_SIGNAL(Window, close_request),
46 HAS_SIGNAL(Window, activate_default_widget),
47 HAS_SIGNAL(Window, activate_focused_widget),
48 HAS_SIGNAL(Window, realize),
49 HAS_SIGNAL(Window, unrealize),
50 HAS_SIGNAL(Window, destroy),
51 HAS_SIGNAL(Window, hide),
52 HAS_SIGNAL(Window, show),
53 HAS_SIGNAL(Window, map),
54 HAS_SIGNAL(Window, unmap)
55 {
56 public:
57 /// @brief construct
58 /// @param application
59 Window(Application& application);
60
61 /// @brief construct from internal
62 Window(detail::WindowInternal*);
63
64 /// @brief destructor
65 ~Window();
66
67 /// @brief expose internal
68 NativeObject get_internal() const override;
69
70 /// @brief override signal emitter
71 operator NativeObject() const override;
72
73 /// @brief link with application
74 /// @param application
75 void set_application(Application& application);
76
77 /// @brief attempt to maximize the window
78 /// @param b true if window should be maximize, false otherwise
79 void set_maximized(bool);
80
81 /// @brief set whether the window should attempt to enter fullscreen mode
82 /// @param b true if window should enter fullscreen mode, false otherwise
83 void set_fullscreen(bool);
84
85 /// @brief attempt to minimize the window
86 /// @param b true if window should be minimized, false otherwise
87 void set_minimized(bool);
88
89 /// @brief present the window to the user
90 void present();
91
92 /// @brief set whether mousetrap::Window::close should hide or destroy the window, true by default
93 /// @param b true if window should only be hidden, false if it should be destroyed
94 void set_hide_on_close(bool);
95
96 /// @brief get whether mousetrap::Window::close should hide or destroy the window, true by default
97 /// @return boolean
98 bool get_hide_on_close() const;
99
100 /// @brief hide the window, it will be inaccesible until mousetrap::Window::present is called again
101 void close();
102
103 /// @brief set the child of the window
104 /// @param widget child
105 void set_child(const Widget&);
106
107 /// @brief remove child
108 void remove_child();
109
110 /// @brief set whether the window should be destroyed if its parent window is destroyed, true by default
111 /// @param b true if it should also be destroyed, false if not
112 void set_destroy_with_parent(bool);
113
114 /// @brief get whether the window should be destroyed if its parent window is destroyed
115 /// @return true if it should also be destroyed, false if not
116 bool get_destroy_with_parent() const;
117
118 /// @brief set the title of the titlebar
119 /// @param title
120 void set_title(const std::string& title);
121
122 /// @brief get the title of the window
123 /// @return title
124 std::string get_title() const;
125
126 /// @brief access the windows header bar widget
127 /// @return header abr
128 [[nodiscard]] HeaderBar get_header_bar() const;
129
130 /// @brief set whether the window should be modal. A modal window prevents users from interacting with any other open application window
131 /// @param b true if window should be modal, false otherwise
132 void set_is_modal(bool);
133
134 /// @brief get whether the window is modal. A modal window prevents users from interacting with any other open application window
135 /// @return true if modal, false otherwise.
136 bool get_is_modal() const;
137
138 /// @brief set whether this window should always be shown on top of the partner window
139 /// @param partner other window, self will be shown above partner
140 void set_transient_for(Window& partner);
141
142 /// @brief set whether the window has a titlebar
143 /// @param b true if window should have a titlebar, false othterwise
144 void set_is_decorated(bool);
145
146 /// @brief get whether the window has a titlebar
147 /// @return true if window has a titlebar, false otherwise
148 bool get_is_decorated() const;
149
150 /// @brief set whether the window should have a close button
151 /// @param b true if window should have a close button, false otherwise
152 void set_has_close_button(bool);
153
154 /// @brief get whether the window has a close button
155 /// @return true if close button should be shown, false otherwise
156 bool get_has_close_button() const;
157
158 /// @brief set the window startup notification identifier, usually results in the users OS sending a notification "<name> is ready"
159 /// @param id
160 void set_startup_notification_identifier(const std::string& id);
161
162 /// @brief set whether the focused widget should be highlighted with a rectangle
163 /// @param b true if it should be highlighted, false otherwise
164 void set_focus_visible(bool);
165
166 /// @brief get whether the focused widget should be highlighted with a rectangle
167 /// @return true if it should be highlighted, false otherwise
168 bool get_focus_visible() const;
169
170 /// @brief set default widget
171 /// @param widget
172 void set_default_widget(const Widget& widget);
173
174 /// @brief free all internal references
175 void destroy();
176
177 private:
178 detail::WindowInternal* _internal = nullptr;
179 };
180}
object representing an entire application, supplies the main render loop, mapping of actions
Definition: application.hpp:54
widget that is usually used in the decoration of a window
Definition: header_bar.hpp:32
Widget, super class of all renderable entities.
Definition: widget.hpp:67
window, registered to an application
Definition: window.hpp:55
void present()
present the window to the user
Definition: window.cpp:112
~Window()
destructor
Definition: window.cpp:92
std::string get_title() const
get the title of the window
Definition: window.cpp:175
void set_child(const Widget &)
set the child of the window
Definition: window.cpp:146
void set_startup_notification_identifier(const std::string &id)
set the window startup notification identifier, usually results in the users OS sending a notificatio...
Definition: window.cpp:231
void set_minimized(bool)
attempt to minimize the window
Definition: window.cpp:138
void remove_child()
remove child
Definition: window.cpp:155
void set_fullscreen(bool)
set whether the window should attempt to enter fullscreen mode
Definition: window.cpp:130
void set_is_decorated(bool)
set whether the window has a titlebar
Definition: window.cpp:211
bool get_is_decorated() const
get whether the window has a titlebar
Definition: window.cpp:216
bool get_destroy_with_parent() const
get whether the window should be destroyed if its parent window is destroyed
Definition: window.cpp:186
void set_transient_for(Window &partner)
set whether this window should always be shown on top of the partner window
Definition: window.cpp:206
bool get_focus_visible() const
get whether the focused widget should be highlighted with a rectangle
Definition: window.cpp:241
void set_maximized(bool)
attempt to maximize the window
Definition: window.cpp:122
void set_hide_on_close(bool)
set whether mousetrap::Window::close should hide or destroy the window, true by default
Definition: window.cpp:160
HeaderBar get_header_bar() const
access the windows header bar widget
Definition: window.cpp:191
bool get_is_modal() const
get whether the window is modal. A modal window prevents users from interacting with any other open a...
Definition: window.cpp:201
void set_has_close_button(bool)
set whether the window should have a close button
Definition: window.cpp:221
void destroy()
free all internal references
Definition: window.cpp:251
bool get_has_close_button() const
get whether the window has a close button
Definition: window.cpp:226
bool get_hide_on_close() const
get whether mousetrap::Window::close should hide or destroy the window, true by default
Definition: window.cpp:165
void close()
hide the window, it will be inaccesible until mousetrap::Window::present is called again
Definition: window.cpp:117
void set_application(Application &application)
link with application
Definition: window.cpp:107
void set_default_widget(const Widget &widget)
set default widget
Definition: window.cpp:246
void set_destroy_with_parent(bool)
set whether the window should be destroyed if its parent window is destroyed, true by default
Definition: window.cpp:181
void set_is_modal(bool)
set whether the window should be modal. A modal window prevents users from interacting with any other...
Definition: window.cpp:196
void set_focus_visible(bool)
set whether the focused widget should be highlighted with a rectangle
Definition: window.cpp:236
void set_title(const std::string &title)
set the title of the titlebar
Definition: window.cpp:170
NativeObject get_internal() const override
expose internal
Definition: window.cpp:97