| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1. Redistributions of source code must retain the above copyright notice, this | 
					
						
							|  |  |  |  *    list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 2. Redistributions in binary form must reproduce the above copyright notice, | 
					
						
							|  |  |  |  *    this list of conditions and the following disclaimer in the documentation | 
					
						
							|  |  |  |  *    and/or other materials provided with the distribution. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
					
						
							|  |  |  |  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
					
						
							|  |  |  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
					
						
							|  |  |  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
					
						
							|  |  |  |  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
					
						
							|  |  |  |  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
					
						
							|  |  |  |  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-10 15:12:38 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 10:58:03 +01:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-06 15:04:03 +01:00
										 |  |  | #include <LibCore/Object.h>
 | 
					
						
							| 
									
										
										
										
											2020-08-15 11:44:34 +02:00
										 |  |  | #include <LibGUI/Application.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-14 23:53:11 +01:00
										 |  |  | #include <LibGUI/Event.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-16 09:17:49 +01:00
										 |  |  | #include <LibGUI/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2020-04-24 18:55:29 +02:00
										 |  |  | #include <LibGUI/Margins.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-06 12:04:00 +01:00
										 |  |  | #include <LibGfx/Color.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-14 23:53:11 +01:00
										 |  |  | #include <LibGfx/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-06 12:04:00 +01:00
										 |  |  | #include <LibGfx/Orientation.h>
 | 
					
						
							|  |  |  | #include <LibGfx/Rect.h>
 | 
					
						
							| 
									
										
										
										
											2020-09-11 14:17:35 +02:00
										 |  |  | #include <LibGfx/StandardCursor.h>
 | 
					
						
							| 
									
										
										
										
											2018-10-10 15:12:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 09:56:00 +02:00
										 |  |  | #define REGISTER_WIDGET(namespace_, class_name)               \
 | 
					
						
							|  |  |  |     extern GUI::WidgetClassRegistration registration_##class_name; \ | 
					
						
							|  |  |  |     GUI::WidgetClassRegistration registration_##class_name(#namespace_ "::" #class_name, []() { return namespace_::class_name::construct(); }); | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace GUI { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 17:13:23 +02:00
										 |  |  | enum class SizePolicy { | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  |     Fixed, | 
					
						
							|  |  |  |     Fill | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-08-18 20:39:46 +02:00
										 |  |  | inline const char* to_string(SizePolicy policy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     switch (policy) { | 
					
						
							|  |  |  |     case SizePolicy::Fixed: | 
					
						
							|  |  |  |         return "SizePolicy::Fixed"; | 
					
						
							|  |  |  |     case SizePolicy::Fill: | 
					
						
							|  |  |  |         return "SizePolicy::Fill"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return "SizePolicy::(Invalid)"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 17:13:23 +02:00
										 |  |  | enum class HorizontalDirection { | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  |     Left, | 
					
						
							|  |  |  |     Right | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-06-07 17:13:23 +02:00
										 |  |  | enum class VerticalDirection { | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  |     Up, | 
					
						
							|  |  |  |     Down | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-02-10 11:07:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | class WidgetClassRegistration { | 
					
						
							| 
									
										
										
										
											2020-08-26 21:52:24 +02:00
										 |  |  |     AK_MAKE_NONCOPYABLE(WidgetClassRegistration); | 
					
						
							|  |  |  |     AK_MAKE_NONMOVABLE(WidgetClassRegistration); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 10:58:03 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-02-23 12:07:13 +01:00
										 |  |  |     WidgetClassRegistration(const String& class_name, Function<NonnullRefPtr<Widget>()> factory); | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     ~WidgetClassRegistration(); | 
					
						
							| 
									
										
										
										
											2019-11-10 10:58:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     String class_name() const { return m_class_name; } | 
					
						
							| 
									
										
										
										
											2020-02-23 12:07:13 +01:00
										 |  |  |     NonnullRefPtr<Widget> construct() const { return m_factory(); } | 
					
						
							| 
									
										
										
										
											2019-11-10 10:58:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     static void for_each(Function<void(const WidgetClassRegistration&)>); | 
					
						
							|  |  |  |     static const WidgetClassRegistration* find(const String& class_name); | 
					
						
							| 
									
										
										
										
											2019-11-10 10:58:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     String m_class_name; | 
					
						
							| 
									
										
										
										
											2020-02-23 12:07:13 +01:00
										 |  |  |     Function<NonnullRefPtr<Widget>()> m_factory; | 
					
						
							| 
									
										
										
										
											2019-11-10 10:58:03 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | class Widget : public Core::Object { | 
					
						
							|  |  |  |     C_OBJECT(Widget) | 
					
						
							| 
									
										
										
										
											2018-10-10 15:12:38 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     virtual ~Widget() override; | 
					
						
							| 
									
										
										
										
											2019-01-20 04:49:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Layout* layout() { return m_layout.ptr(); } | 
					
						
							|  |  |  |     const Layout* layout() const { return m_layout.ptr(); } | 
					
						
							| 
									
										
										
										
											2020-03-05 09:21:46 +01:00
										 |  |  |     void set_layout(NonnullRefPtr<Layout>); | 
					
						
							| 
									
										
										
										
											2019-02-10 11:07:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 09:21:46 +01:00
										 |  |  |     template<class T, class... Args> | 
					
						
							|  |  |  |     inline T& set_layout(Args&&... args) | 
					
						
							| 
									
										
										
										
											2020-03-03 21:42:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-03-05 09:21:46 +01:00
										 |  |  |         auto layout = T::construct(forward<Args>(args)...); | 
					
						
							|  |  |  |         set_layout(*layout); | 
					
						
							|  |  |  |         return layout; | 
					
						
							| 
									
										
										
										
											2020-03-03 21:42:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-10 11:07:13 +01:00
										 |  |  |     SizePolicy horizontal_size_policy() const { return m_horizontal_size_policy; } | 
					
						
							|  |  |  |     SizePolicy vertical_size_policy() const { return m_vertical_size_policy; } | 
					
						
							|  |  |  |     SizePolicy size_policy(Orientation orientation) { return orientation == Orientation::Horizontal ? m_horizontal_size_policy : m_vertical_size_policy; } | 
					
						
							|  |  |  |     void set_size_policy(SizePolicy horizontal_policy, SizePolicy vertical_policy); | 
					
						
							| 
									
										
										
										
											2019-07-27 09:34:28 +02:00
										 |  |  |     void set_size_policy(Orientation, SizePolicy); | 
					
						
							| 
									
										
										
										
											2019-02-10 11:07:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     Gfx::IntSize preferred_size() const { return m_preferred_size; } | 
					
						
							|  |  |  |     void set_preferred_size(const Gfx::IntSize&); | 
					
						
							| 
									
										
										
										
											2019-07-20 22:39:24 +02:00
										 |  |  |     void set_preferred_size(int width, int height) { set_preferred_size({ width, height }); } | 
					
						
							| 
									
										
										
										
											2019-02-10 11:07:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-08 18:58:44 +02:00
										 |  |  |     bool has_tooltip() const { return !m_tooltip.is_empty(); } | 
					
						
							|  |  |  |     String tooltip() const { return m_tooltip; } | 
					
						
							| 
									
										
										
										
											2020-08-15 11:44:34 +02:00
										 |  |  |     void set_tooltip(const StringView&); | 
					
						
							| 
									
										
										
										
											2019-04-08 18:58:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-12 02:51:16 +02:00
										 |  |  |     bool is_enabled() const { return m_enabled; } | 
					
						
							|  |  |  |     void set_enabled(bool); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-02 03:46:37 +02:00
										 |  |  |     bool updates_enabled() const { return m_updates_enabled; } | 
					
						
							|  |  |  |     void set_updates_enabled(bool); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 12:34:39 +01:00
										 |  |  |     virtual void event(Core::Event&) override; | 
					
						
							| 
									
										
										
										
											2019-01-21 00:46:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 03:34:37 +02:00
										 |  |  |     // This is called after children have been painted.
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     virtual void second_paint_event(PaintEvent&); | 
					
						
							| 
									
										
										
										
											2019-04-11 03:34:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     Gfx::IntRect relative_rect() const { return m_relative_rect; } | 
					
						
							|  |  |  |     Gfx::IntPoint relative_position() const { return m_relative_rect.location(); } | 
					
						
							| 
									
										
										
										
											2019-01-21 00:46:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     Gfx::IntRect window_relative_rect() const; | 
					
						
							|  |  |  |     Gfx::IntRect screen_relative_rect() const; | 
					
						
							| 
									
										
										
										
											2019-02-09 14:30:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-21 00:46:08 +01:00
										 |  |  |     int x() const { return m_relative_rect.x(); } | 
					
						
							|  |  |  |     int y() const { return m_relative_rect.y(); } | 
					
						
							|  |  |  |     int width() const { return m_relative_rect.width(); } | 
					
						
							|  |  |  |     int height() const { return m_relative_rect.height(); } | 
					
						
							| 
									
										
										
										
											2019-07-01 02:46:36 -05:00
										 |  |  |     int length(Orientation orientation) const { return orientation == Orientation::Vertical ? height() : width(); } | 
					
						
							| 
									
										
										
										
											2018-10-12 14:15:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     Gfx::IntRect rect() const { return { 0, 0, width(), height() }; } | 
					
						
							|  |  |  |     Gfx::IntSize size() const { return m_relative_rect.size(); } | 
					
						
							| 
									
										
										
										
											2018-10-10 16:49:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-10 15:12:38 +02:00
										 |  |  |     void update(); | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     void update(const Gfx::IntRect&); | 
					
						
							| 
									
										
										
										
											2018-10-10 15:12:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 11:24:16 +01:00
										 |  |  |     virtual bool accepts_focus() const { return false; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-21 00:46:08 +01:00
										 |  |  |     bool is_focused() const; | 
					
						
							| 
									
										
										
										
											2020-08-14 19:56:40 +02:00
										 |  |  |     void set_focus(bool, FocusSource = FocusSource::Programmatic); | 
					
						
							| 
									
										
										
										
											2018-10-13 17:52:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-25 11:21:49 +02:00
										 |  |  |     Widget* focus_proxy() { return m_focus_proxy; } | 
					
						
							|  |  |  |     const Widget* focus_proxy() const { return m_focus_proxy; } | 
					
						
							|  |  |  |     void set_focus_proxy(Widget*); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-11 19:12:32 +01:00
										 |  |  |     enum class ShouldRespectGreediness { No = 0, | 
					
						
							|  |  |  |         Yes }; | 
					
						
							| 
									
										
										
										
											2018-10-10 16:49:36 +02:00
										 |  |  |     struct HitTestResult { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |         Widget* widget { nullptr }; | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |         Gfx::IntPoint local_position; | 
					
						
							| 
									
										
										
										
											2018-10-10 16:49:36 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     HitTestResult hit_test(const Gfx::IntPoint&, ShouldRespectGreediness = ShouldRespectGreediness::Yes); | 
					
						
							|  |  |  |     Widget* child_at(const Gfx::IntPoint&) const; | 
					
						
							| 
									
										
										
										
											2019-04-16 03:47:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     void set_relative_rect(const Gfx::IntRect&); | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  |     void set_relative_rect(int x, int y, int width, int height) { set_relative_rect({ x, y, width, height }); } | 
					
						
							| 
									
										
										
										
											2019-02-08 00:14:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-14 04:10:43 +02:00
										 |  |  |     void set_x(int x) { set_relative_rect(x, y(), width(), height()); } | 
					
						
							|  |  |  |     void set_y(int y) { set_relative_rect(x(), y, width(), height()); } | 
					
						
							|  |  |  |     void set_width(int width) { set_relative_rect(x(), y(), width, height()); } | 
					
						
							|  |  |  |     void set_height(int height) { set_relative_rect(x(), y(), width(), height); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     void move_to(const Gfx::IntPoint& point) { set_relative_rect({ point, relative_rect().size() }); } | 
					
						
							| 
									
										
										
										
											2019-02-08 00:14:37 +01:00
										 |  |  |     void move_to(int x, int y) { move_to({ x, y }); } | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     void resize(const Gfx::IntSize& size) { set_relative_rect({ relative_rect().location(), size }); } | 
					
						
							| 
									
										
										
										
											2019-02-08 00:14:37 +01:00
										 |  |  |     void resize(int width, int height) { resize({ width, height }); } | 
					
						
							| 
									
										
										
										
											2018-10-10 16:49:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 22:59:27 +02:00
										 |  |  |     void move_by(int x, int y) { move_by({ x, y }); } | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     void move_by(const Gfx::IntPoint& delta) { set_relative_rect({ relative_position().translated(delta), size() }); } | 
					
						
							| 
									
										
										
										
											2019-04-16 22:59:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-14 23:53:11 +01:00
										 |  |  |     Gfx::ColorRole background_role() const { return m_background_role; } | 
					
						
							|  |  |  |     void set_background_role(Gfx::ColorRole); | 
					
						
							| 
									
										
										
										
											2019-12-24 20:57:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-14 23:53:11 +01:00
										 |  |  |     Gfx::ColorRole foreground_role() const { return m_foreground_role; } | 
					
						
							|  |  |  |     void set_foreground_role(Gfx::ColorRole); | 
					
						
							| 
									
										
										
										
											2019-12-24 20:57:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-21 00:46:08 +01:00
										 |  |  |     Color background_color() const { return m_background_color; } | 
					
						
							|  |  |  |     Color foreground_color() const { return m_foreground_color; } | 
					
						
							| 
									
										
										
										
											2018-10-11 01:48:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-21 00:46:08 +01:00
										 |  |  |     void set_background_color(Color color) { m_background_color = color; } | 
					
						
							|  |  |  |     void set_foreground_color(Color color) { m_foreground_color = color; } | 
					
						
							| 
									
										
										
										
											2018-10-11 01:48:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-03 11:35:10 +02:00
										 |  |  |     void set_backcolor(const StringView&); | 
					
						
							|  |  |  |     void set_forecolor(const StringView&); | 
					
						
							| 
									
										
										
										
											2019-07-10 21:00:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-10 21:12:09 +02:00
										 |  |  |     void set_autofill(bool b) { set_fill_with_background_color(b); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Window* window() | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-21 00:46:08 +01:00
										 |  |  |         if (auto* pw = parent_widget()) | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  |             return pw->window(); | 
					
						
							|  |  |  |         return m_window; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     const Window* window() const | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-21 00:46:08 +01:00
										 |  |  |         if (auto* pw = parent_widget()) | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  |             return pw->window(); | 
					
						
							|  |  |  |         return m_window; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-10-11 16:52:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     void set_window(Window*); | 
					
						
							| 
									
										
										
										
											2018-10-12 02:41:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Widget* parent_widget(); | 
					
						
							|  |  |  |     const Widget* parent_widget() const; | 
					
						
							| 
									
										
										
										
											2018-10-11 16:52:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-21 00:46:08 +01:00
										 |  |  |     void set_fill_with_background_color(bool b) { m_fill_with_background_color = b; } | 
					
						
							|  |  |  |     bool fill_with_background_color() const { return m_fill_with_background_color; } | 
					
						
							| 
									
										
										
										
											2018-10-14 00:21:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  |     const Gfx::Font& font() const { return *m_font; } | 
					
						
							|  |  |  |     void set_font(const Gfx::Font*); | 
					
						
							|  |  |  |     void set_font(const Gfx::Font& font) { set_font(&font); } | 
					
						
							| 
									
										
										
										
											2018-10-14 13:06:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-27 08:48:34 +01:00
										 |  |  |     void set_global_cursor_tracking(bool); | 
					
						
							|  |  |  |     bool global_cursor_tracking() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     void notify_layout_changed(Badge<Layout>); | 
					
						
							| 
									
										
										
										
											2019-03-30 13:53:30 +01:00
										 |  |  |     void invalidate_layout(); | 
					
						
							| 
									
										
										
										
											2019-02-10 11:07:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 16:12:06 +01:00
										 |  |  |     bool is_visible() const { return m_visible; } | 
					
						
							|  |  |  |     void set_visible(bool); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-29 02:20:22 +01:00
										 |  |  |     bool spans_entire_window_horizontally() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 03:34:37 +02:00
										 |  |  |     bool is_greedy_for_hits() const { return m_greedy_for_hits; } | 
					
						
							|  |  |  |     void set_greedy_for_hits(bool b) { m_greedy_for_hits = b; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 03:47:55 +02:00
										 |  |  |     void move_to_front(); | 
					
						
							|  |  |  |     void move_to_back(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool is_frontmost() const; | 
					
						
							|  |  |  |     bool is_backmost() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Action* action_for_key_event(const KeyEvent&); | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-27 03:52:33 +02:00
										 |  |  |     template<typename Callback> | 
					
						
							|  |  |  |     void for_each_child_widget(Callback callback) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  |         for_each_child([&](auto& child) { | 
					
						
							| 
									
										
										
										
											2020-07-26 17:16:35 +02:00
										 |  |  |             if (is<Widget>(child)) | 
					
						
							|  |  |  |                 return callback(downcast<Widget>(child)); | 
					
						
							| 
									
										
										
										
											2019-05-27 03:52:33 +02:00
										 |  |  |             return IterationDecision::Continue; | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Vector<Widget*> child_widgets() const; | 
					
						
							| 
									
										
										
										
											2019-11-11 19:12:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-23 22:37:21 +02:00
										 |  |  |     virtual bool is_radio_button() const { return false; } | 
					
						
							| 
									
										
										
										
											2019-06-12 05:57:26 +02:00
										 |  |  |     virtual bool is_abstract_button() const { return false; } | 
					
						
							| 
									
										
										
										
											2019-05-23 22:37:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-18 20:39:46 +02:00
										 |  |  |     virtual void save_to(AK::JsonObject&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-26 12:27:01 +02:00
										 |  |  |     void do_layout(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-14 23:53:11 +01:00
										 |  |  |     Gfx::Palette palette() const; | 
					
						
							|  |  |  |     void set_palette(const Gfx::Palette&); | 
					
						
							| 
									
										
										
										
											2019-12-24 20:57:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-24 18:55:29 +02:00
										 |  |  |     const Margins& content_margins() const { return m_content_margins; } | 
					
						
							|  |  |  |     void set_content_margins(const Margins&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     Gfx::IntRect content_rect() const; | 
					
						
							| 
									
										
										
										
											2020-04-24 18:55:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-17 21:49:54 +02:00
										 |  |  |     void set_accepts_emoji_input(bool b) { m_accepts_emoji_input = b; } | 
					
						
							|  |  |  |     bool accepts_emoji_input() const { return m_accepts_emoji_input; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-25 21:24:45 +02:00
										 |  |  |     virtual Gfx::IntRect children_clip_rect() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-11 14:17:35 +02:00
										 |  |  |     Gfx::StandardCursor override_cursor() const { return m_override_cursor; } | 
					
						
							|  |  |  |     void set_override_cursor(Gfx::StandardCursor); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 12:46:53 +02:00
										 |  |  |     bool load_from_json(const StringView&); | 
					
						
							|  |  |  |     bool load_from_json(const JsonObject&); | 
					
						
							|  |  |  |     Widget* find_child_by_name(const String&); | 
					
						
							|  |  |  |     Widget* find_descendant_by_name(const String&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-01 20:51:20 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2020-02-23 12:07:13 +01:00
										 |  |  |     Widget(); | 
					
						
							| 
									
										
										
										
											2019-09-21 17:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 17:16:35 +02:00
										 |  |  |     virtual void custom_layout() { } | 
					
						
							|  |  |  |     virtual void did_change_font() { } | 
					
						
							|  |  |  |     virtual void did_layout() { } | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     virtual void paint_event(PaintEvent&); | 
					
						
							|  |  |  |     virtual void resize_event(ResizeEvent&); | 
					
						
							|  |  |  |     virtual void show_event(ShowEvent&); | 
					
						
							|  |  |  |     virtual void hide_event(HideEvent&); | 
					
						
							|  |  |  |     virtual void keydown_event(KeyEvent&); | 
					
						
							|  |  |  |     virtual void keyup_event(KeyEvent&); | 
					
						
							|  |  |  |     virtual void mousemove_event(MouseEvent&); | 
					
						
							|  |  |  |     virtual void mousedown_event(MouseEvent&); | 
					
						
							|  |  |  |     virtual void mouseup_event(MouseEvent&); | 
					
						
							|  |  |  |     virtual void mousewheel_event(MouseEvent&); | 
					
						
							|  |  |  |     virtual void doubleclick_event(MouseEvent&); | 
					
						
							|  |  |  |     virtual void context_menu_event(ContextMenuEvent&); | 
					
						
							| 
									
										
										
										
											2020-08-14 19:56:40 +02:00
										 |  |  |     virtual void focusin_event(FocusEvent&); | 
					
						
							|  |  |  |     virtual void focusout_event(FocusEvent&); | 
					
						
							| 
									
										
										
										
											2020-02-02 12:34:39 +01:00
										 |  |  |     virtual void enter_event(Core::Event&); | 
					
						
							|  |  |  |     virtual void leave_event(Core::Event&); | 
					
						
							|  |  |  |     virtual void child_event(Core::ChildEvent&) override; | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     virtual void change_event(Event&); | 
					
						
							| 
									
										
										
										
											2020-02-13 21:43:32 +01:00
										 |  |  |     virtual void drag_move_event(DragEvent&); | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     virtual void drop_event(DropEvent&); | 
					
						
							| 
									
										
										
										
											2020-03-16 13:36:21 +02:00
										 |  |  |     virtual void theme_change_event(ThemeChangeEvent&); | 
					
						
							| 
									
										
										
										
											2019-09-01 12:26:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 14:42:05 +01:00
										 |  |  |     virtual void did_begin_inspection() override; | 
					
						
							|  |  |  |     virtual void did_end_inspection() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 15:46:37 +01:00
										 |  |  |     virtual bool set_property(const StringView& name, const JsonValue& value) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-10 15:12:38 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     void handle_paint_event(PaintEvent&); | 
					
						
							|  |  |  |     void handle_resize_event(ResizeEvent&); | 
					
						
							|  |  |  |     void handle_mousedown_event(MouseEvent&); | 
					
						
							|  |  |  |     void handle_mousedoubleclick_event(MouseEvent&); | 
					
						
							|  |  |  |     void handle_mouseup_event(MouseEvent&); | 
					
						
							| 
									
										
										
										
											2020-02-02 12:34:39 +01:00
										 |  |  |     void handle_enter_event(Core::Event&); | 
					
						
							|  |  |  |     void handle_leave_event(Core::Event&); | 
					
						
							| 
									
										
										
										
											2020-08-14 19:56:40 +02:00
										 |  |  |     void focus_previous_widget(FocusSource); | 
					
						
							|  |  |  |     void focus_next_widget(FocusSource); | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-15 11:44:34 +02:00
										 |  |  |     void show_tooltip(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Window* m_window { nullptr }; | 
					
						
							| 
									
										
										
										
											2020-03-05 09:21:46 +01:00
										 |  |  |     RefPtr<Layout> m_layout; | 
					
						
							| 
									
										
										
										
											2018-10-12 01:03:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     Gfx::IntRect m_relative_rect; | 
					
						
							| 
									
										
										
										
											2020-02-14 23:53:11 +01:00
										 |  |  |     Gfx::ColorRole m_background_role; | 
					
						
							|  |  |  |     Gfx::ColorRole m_foreground_role; | 
					
						
							| 
									
										
										
										
											2019-02-19 01:42:53 +01:00
										 |  |  |     Color m_background_color; | 
					
						
							|  |  |  |     Color m_foreground_color; | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  |     NonnullRefPtr<Gfx::Font> m_font; | 
					
						
							| 
									
										
										
										
											2019-04-08 18:58:44 +02:00
										 |  |  |     String m_tooltip; | 
					
						
							| 
									
										
										
										
											2018-10-11 12:33:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-10 11:07:13 +01:00
										 |  |  |     SizePolicy m_horizontal_size_policy { SizePolicy::Fill }; | 
					
						
							|  |  |  |     SizePolicy m_vertical_size_policy { SizePolicy::Fill }; | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     Gfx::IntSize m_preferred_size; | 
					
						
							| 
									
										
										
										
											2020-04-24 18:55:29 +02:00
										 |  |  |     Margins m_content_margins; | 
					
						
							| 
									
										
										
										
											2019-02-10 11:07:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-10 13:16:36 +01:00
										 |  |  |     bool m_fill_with_background_color { false }; | 
					
						
							| 
									
										
										
										
											2019-03-15 16:12:06 +01:00
										 |  |  |     bool m_visible { true }; | 
					
						
							| 
									
										
										
										
											2019-04-11 03:34:37 +02:00
										 |  |  |     bool m_greedy_for_hits { false }; | 
					
						
							| 
									
										
										
										
											2019-04-12 02:51:16 +02:00
										 |  |  |     bool m_enabled { true }; | 
					
						
							| 
									
										
										
										
											2019-05-02 03:46:37 +02:00
										 |  |  |     bool m_updates_enabled { true }; | 
					
						
							| 
									
										
										
										
											2020-05-17 21:49:54 +02:00
										 |  |  |     bool m_accepts_emoji_input { false }; | 
					
						
							| 
									
										
										
										
											2019-03-25 01:42:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  |     NonnullRefPtr<Gfx::PaletteImpl> m_palette; | 
					
						
							| 
									
										
										
										
											2020-08-25 11:21:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     WeakPtr<Widget> m_focus_proxy; | 
					
						
							| 
									
										
										
										
											2020-09-11 14:17:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Gfx::StandardCursor m_override_cursor { Gfx::StandardCursor::None }; | 
					
						
							| 
									
										
										
										
											2018-10-10 15:12:38 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-05-27 04:06:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | inline Widget* Widget::parent_widget() | 
					
						
							| 
									
										
										
										
											2019-05-27 04:06:01 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-26 17:16:35 +02:00
										 |  |  |     if (parent() && is<Widget>(*parent())) | 
					
						
							|  |  |  |         return &downcast<Widget>(*parent()); | 
					
						
							| 
									
										
										
										
											2019-05-27 04:06:01 +02:00
										 |  |  |     return nullptr; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | inline const Widget* Widget::parent_widget() const | 
					
						
							| 
									
										
										
										
											2019-05-27 04:06:01 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-26 17:16:35 +02:00
										 |  |  |     if (parent() && is<Widget>(*parent())) | 
					
						
							|  |  |  |         return &downcast<const Widget>(*parent()); | 
					
						
							| 
									
										
										
										
											2019-05-27 04:06:01 +02:00
										 |  |  |     return nullptr; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-07-26 17:16:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | AK_BEGIN_TYPE_TRAITS(GUI::Widget) | 
					
						
							|  |  |  | static bool is_type(const Core::Object& object) { return object.is_widget(); } | 
					
						
							|  |  |  | AK_END_TYPE_TRAITS() |