| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 15:34:26 +02:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-03 16:02:49 +01:00
										 |  |  | #include <AK/HashMap.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  | #include <AK/WeakPtr.h>
 | 
					
						
							| 
									
										
										
										
											2019-04-10 17:01:54 +02:00
										 |  |  | #include <LibCore/CObject.h>
 | 
					
						
							| 
									
										
										
										
											2019-07-18 10:15:00 +02:00
										 |  |  | #include <LibDraw/GraphicsBitmap.h>
 | 
					
						
							|  |  |  | #include <LibDraw/Rect.h>
 | 
					
						
							| 
									
										
										
										
											2019-08-27 20:35:37 +02:00
										 |  |  | #include <LibGUI/GWindowType.h>
 | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  | class GWidget; | 
					
						
							| 
									
										
										
										
											2019-04-03 21:03:12 +02:00
										 |  |  | class GWMEvent; | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 17:13:23 +02:00
										 |  |  | enum class GStandardCursor { | 
					
						
							| 
									
										
										
										
											2019-03-31 23:52:02 +02:00
										 |  |  |     None = 0, | 
					
						
							|  |  |  |     Arrow, | 
					
						
							|  |  |  |     IBeam, | 
					
						
							| 
									
										
										
										
											2019-04-02 02:34:09 +02:00
										 |  |  |     ResizeHorizontal, | 
					
						
							|  |  |  |     ResizeVertical, | 
					
						
							| 
									
										
										
										
											2019-05-03 01:38:24 +02:00
										 |  |  |     ResizeDiagonalTLBR, | 
					
						
							|  |  |  |     ResizeDiagonalBLTR, | 
					
						
							| 
									
										
										
										
											2019-10-10 21:35:12 +02:00
										 |  |  |     Hand, | 
					
						
							| 
									
										
										
										
											2019-03-31 23:52:02 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-10 17:01:54 +02:00
										 |  |  | class GWindow : public CObject { | 
					
						
							| 
									
										
										
										
											2019-07-25 19:49:28 +02:00
										 |  |  |     C_OBJECT(GWindow) | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-01-20 04:49:48 +01:00
										 |  |  |     virtual ~GWindow() override; | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  |     static GWindow* from_window_id(int); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-19 00:01:02 +01:00
										 |  |  |     bool is_modal() const { return m_modal; } | 
					
						
							|  |  |  |     void set_modal(bool); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-17 21:33:44 +02:00
										 |  |  |     bool is_fullscreen() const { return m_fullscreen; } | 
					
						
							| 
									
										
										
										
											2019-09-16 18:38:42 +02:00
										 |  |  |     void set_fullscreen(bool); | 
					
						
							| 
									
										
										
										
											2019-05-17 21:33:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 21:24:02 +02:00
										 |  |  |     bool is_resizable() const { return m_resizable; } | 
					
						
							|  |  |  |     void set_resizable(bool resizable) { m_resizable = resizable; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-17 04:23:54 +01:00
										 |  |  |     void set_double_buffering_enabled(bool); | 
					
						
							| 
									
										
										
										
											2019-02-19 01:42:53 +01:00
										 |  |  |     void set_has_alpha_channel(bool); | 
					
						
							|  |  |  |     void set_opacity(float); | 
					
						
							| 
									
										
										
										
											2019-04-03 19:38:44 +02:00
										 |  |  |     void set_window_type(GWindowType); | 
					
						
							| 
									
										
										
										
											2019-02-19 01:42:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-14 14:21:51 +01:00
										 |  |  |     int window_id() const { return m_window_id; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 05:20:32 +01:00
										 |  |  |     String title() const; | 
					
						
							| 
									
										
										
										
											2019-06-02 14:58:02 +02:00
										 |  |  |     void set_title(const StringView&); | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-24 14:37:23 -07:00
										 |  |  |     bool show_titlebar() const { return m_show_titlebar; }; | 
					
						
							|  |  |  |     void set_show_titlebar(bool show) { m_show_titlebar = show; }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-10 14:29:47 +02:00
										 |  |  |     Color background_color() const { return m_background_color; } | 
					
						
							|  |  |  |     void set_background_color(Color color) { m_background_color = color; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 20:35:37 +02:00
										 |  |  |     enum class CloseRequestDecision { | 
					
						
							|  |  |  |         StayOpen, | 
					
						
							|  |  |  |         Close, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Function<CloseRequestDecision()> on_close_request; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 23:40:12 +01:00
										 |  |  |     int x() const { return rect().x(); } | 
					
						
							|  |  |  |     int y() const { return rect().y(); } | 
					
						
							|  |  |  |     int width() const { return rect().width(); } | 
					
						
							|  |  |  |     int height() const { return rect().height(); } | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 23:40:12 +01:00
										 |  |  |     Rect rect() const; | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  |     Size size() const { return rect().size(); } | 
					
						
							| 
									
										
										
										
											2019-01-16 13:49:44 +01:00
										 |  |  |     void set_rect(const Rect&); | 
					
						
							| 
									
										
										
										
											2019-02-08 00:14:37 +01:00
										 |  |  |     void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); } | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 23:40:12 +01:00
										 |  |  |     Point position() const { return rect().location(); } | 
					
						
							| 
									
										
										
										
											2018-10-12 02:24:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-11 06:09:54 +01:00
										 |  |  |     void move_to(int x, int y) { move_to({ x, y }); } | 
					
						
							|  |  |  |     void move_to(const Point& point) { set_rect({ point, size() }); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-26 17:33:20 +02:00
										 |  |  |     void resize(int width, int height) { resize({ width, height }); } | 
					
						
							|  |  |  |     void resize(const Size& size) { set_rect({ position(), size }); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-10 16:56:55 +02:00
										 |  |  |     virtual void event(CEvent&) override; | 
					
						
							| 
									
										
										
										
											2018-10-12 01:26:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 13:49:44 +01:00
										 |  |  |     bool is_visible() const; | 
					
						
							| 
									
										
										
										
											2019-01-26 21:58:43 +01:00
										 |  |  |     bool is_active() const { return m_is_active; } | 
					
						
							| 
									
										
										
										
											2018-10-14 01:23:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-30 20:03:52 +01:00
										 |  |  |     void show(); | 
					
						
							|  |  |  |     void hide(); | 
					
						
							| 
									
										
										
										
											2019-07-26 16:13:59 +02:00
										 |  |  |     virtual void close(); | 
					
						
							| 
									
										
										
										
											2019-06-01 20:10:37 +02:00
										 |  |  |     void move_to_front(); | 
					
						
							| 
									
										
										
										
											2018-10-14 00:21:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-03 01:38:24 +02:00
										 |  |  |     void start_wm_resize(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-20 07:56:48 +01:00
										 |  |  |     GWidget* main_widget() { return m_main_widget; } | 
					
						
							|  |  |  |     const GWidget* main_widget() const { return m_main_widget; } | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  |     void set_main_widget(GWidget*); | 
					
						
							| 
									
										
										
										
											2019-01-26 11:24:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     GWidget* focused_widget() { return m_focused_widget; } | 
					
						
							|  |  |  |     const GWidget* focused_widget() const { return m_focused_widget; } | 
					
						
							| 
									
										
										
										
											2019-01-26 06:39:13 +01:00
										 |  |  |     void set_focused_widget(GWidget*); | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 05:20:32 +01:00
										 |  |  |     void update(const Rect& = Rect()); | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-27 08:48:34 +01:00
										 |  |  |     void set_global_cursor_tracking_widget(GWidget*); | 
					
						
							|  |  |  |     GWidget* global_cursor_tracking_widget() { return m_global_cursor_tracking_widget.ptr(); } | 
					
						
							|  |  |  |     const GWidget* global_cursor_tracking_widget() const { return m_global_cursor_tracking_widget.ptr(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-24 15:01:56 +01:00
										 |  |  |     void set_automatic_cursor_tracking_widget(GWidget*); | 
					
						
							|  |  |  |     GWidget* automatic_cursor_tracking_widget() { return m_automatic_cursor_tracking_widget.ptr(); } | 
					
						
							|  |  |  |     const GWidget* automatic_cursor_tracking_widget() const { return m_automatic_cursor_tracking_widget.ptr(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-20 10:12:19 +01:00
										 |  |  |     GWidget* hovered_widget() { return m_hovered_widget.ptr(); } | 
					
						
							|  |  |  |     const GWidget* hovered_widget() const { return m_hovered_widget.ptr(); } | 
					
						
							|  |  |  |     void set_hovered_widget(GWidget*); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-17 04:23:54 +01:00
										 |  |  |     GraphicsBitmap* front_bitmap() { return m_front_bitmap.ptr(); } | 
					
						
							|  |  |  |     GraphicsBitmap* back_bitmap() { return m_back_bitmap.ptr(); } | 
					
						
							| 
									
										
										
										
											2019-02-20 21:59:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-21 00:21:23 +01:00
										 |  |  |     Size size_increment() const { return m_size_increment; } | 
					
						
							|  |  |  |     void set_size_increment(const Size& increment) { m_size_increment = increment; } | 
					
						
							|  |  |  |     Size base_size() const { return m_base_size; } | 
					
						
							|  |  |  |     void set_base_size(const Size& size) { m_base_size = size; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-31 23:52:02 +02:00
										 |  |  |     void set_override_cursor(GStandardCursor); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-28 10:18:49 +02:00
										 |  |  |     void set_icon(const GraphicsBitmap*); | 
					
						
							| 
									
										
										
										
											2019-08-02 14:02:56 -05:00
										 |  |  |     void apply_icon(); | 
					
						
							| 
									
										
										
										
											2019-07-28 10:18:49 +02:00
										 |  |  |     const GraphicsBitmap* icon() const { return m_icon.ptr(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-15 02:39:58 +02:00
										 |  |  |     Vector<GWidget*> focusable_widgets() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-18 20:39:46 +02:00
										 |  |  |     virtual void save_to(AK::JsonObject&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-03 21:03:12 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2019-09-21 18:34:06 +02:00
										 |  |  |     GWindow(CObject* parent = nullptr); | 
					
						
							| 
									
										
										
										
											2019-04-03 21:03:12 +02:00
										 |  |  |     virtual void wm_event(GWMEvent&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-20 22:31:21 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-03-19 02:20:00 +01:00
										 |  |  |     virtual bool is_window() const override final { return true; } | 
					
						
							| 
									
										
										
										
											2019-02-10 14:28:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 15:13:16 +01:00
										 |  |  |     void paint_keybinds(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 10:09:57 +02:00
										 |  |  |     void collect_keyboard_activation_targets(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 18:37:47 +02:00
										 |  |  |     NonnullRefPtr<GraphicsBitmap> create_backing_bitmap(const Size&); | 
					
						
							| 
									
										
										
										
											2019-07-28 10:18:49 +02:00
										 |  |  |     NonnullRefPtr<GraphicsBitmap> create_shared_bitmap(GraphicsBitmap::Format, const Size&); | 
					
						
							| 
									
										
										
										
											2019-03-17 04:23:54 +01:00
										 |  |  |     void set_current_backing_bitmap(GraphicsBitmap&, bool flush_immediately = false); | 
					
						
							| 
									
										
										
										
											2019-05-21 21:05:10 +02:00
										 |  |  |     void flip(const Vector<Rect, 32>& dirty_rects); | 
					
						
							| 
									
										
										
										
											2019-03-17 04:23:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 18:37:47 +02:00
										 |  |  |     RefPtr<GraphicsBitmap> m_front_bitmap; | 
					
						
							|  |  |  |     RefPtr<GraphicsBitmap> m_back_bitmap; | 
					
						
							| 
									
										
										
										
											2019-07-28 10:18:49 +02:00
										 |  |  |     RefPtr<GraphicsBitmap> m_icon; | 
					
						
							| 
									
										
										
										
											2019-01-30 20:03:52 +01:00
										 |  |  |     int m_window_id { 0 }; | 
					
						
							| 
									
										
										
										
											2019-02-19 01:42:53 +01:00
										 |  |  |     float m_opacity_when_windowless { 1.0f }; | 
					
						
							| 
									
										
										
										
											2019-09-22 00:31:54 +02:00
										 |  |  |     RefPtr<GWidget> m_main_widget; | 
					
						
							| 
									
										
										
										
											2019-04-18 23:16:57 +02:00
										 |  |  |     WeakPtr<GWidget> m_focused_widget; | 
					
						
							| 
									
										
										
										
											2019-01-27 08:48:34 +01:00
										 |  |  |     WeakPtr<GWidget> m_global_cursor_tracking_widget; | 
					
						
							| 
									
										
										
										
											2019-03-24 15:01:56 +01:00
										 |  |  |     WeakPtr<GWidget> m_automatic_cursor_tracking_widget; | 
					
						
							| 
									
										
										
										
											2019-02-20 10:12:19 +01:00
										 |  |  |     WeakPtr<GWidget> m_hovered_widget; | 
					
						
							| 
									
										
										
										
											2019-01-30 20:03:52 +01:00
										 |  |  |     Rect m_rect_when_windowless; | 
					
						
							|  |  |  |     String m_title_when_windowless; | 
					
						
							| 
									
										
										
										
											2019-04-22 01:15:47 +02:00
										 |  |  |     Vector<Rect, 32> m_pending_paint_event_rects; | 
					
						
							| 
									
										
										
										
											2019-02-21 00:21:23 +01:00
										 |  |  |     Size m_size_increment; | 
					
						
							|  |  |  |     Size m_base_size; | 
					
						
							| 
									
										
										
										
											2019-06-30 09:23:16 +02:00
										 |  |  |     Color m_background_color { Color::WarmGray }; | 
					
						
							| 
									
										
										
										
											2019-04-03 19:38:44 +02:00
										 |  |  |     GWindowType m_window_type { GWindowType::Normal }; | 
					
						
							| 
									
										
										
										
											2019-02-19 01:42:53 +01:00
										 |  |  |     bool m_is_active { false }; | 
					
						
							|  |  |  |     bool m_has_alpha_channel { false }; | 
					
						
							| 
									
										
										
										
											2019-03-17 04:23:54 +01:00
										 |  |  |     bool m_double_buffering_enabled { true }; | 
					
						
							| 
									
										
										
										
											2019-03-19 00:01:02 +01:00
										 |  |  |     bool m_modal { false }; | 
					
						
							| 
									
										
										
										
											2019-03-19 00:52:39 +01:00
										 |  |  |     bool m_resizable { true }; | 
					
						
							| 
									
										
										
										
											2019-05-17 21:33:44 +02:00
										 |  |  |     bool m_fullscreen { false }; | 
					
						
							| 
									
										
										
										
											2019-05-24 14:37:23 -07:00
										 |  |  |     bool m_show_titlebar { true }; | 
					
						
							| 
									
										
										
										
											2019-06-03 16:02:49 +01:00
										 |  |  |     bool m_keybind_mode { false }; | 
					
						
							|  |  |  |     String m_entered_keybind; | 
					
						
							| 
									
										
										
										
											2019-06-22 14:41:11 +02:00
										 |  |  |     int m_max_keybind_length { 0 }; | 
					
						
							| 
									
										
										
										
											2019-06-21 10:09:57 +02:00
										 |  |  |     HashMap<String, WeakPtr<GWidget>> m_keyboard_activation_targets; | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  | }; |