| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  | #include <AK/Function.h>
 | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  | #include <LibGUI/GModel.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-07 19:14:59 +02:00
										 |  |  | #include <LibGUI/GModelSelection.h>
 | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  | #include <LibGUI/GScrollableWidget.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-23 08:18:28 +02:00
										 |  |  | class GModelEditingDelegate; | 
					
						
							| 
									
										
										
										
											2019-04-18 22:27:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  | class GAbstractView : public GScrollableWidget { | 
					
						
							| 
									
										
										
										
											2019-07-25 19:49:28 +02:00
										 |  |  |     C_OBJECT(GAbstractView) | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  |     friend class GModel; | 
					
						
							| 
									
										
										
										
											2019-09-07 19:14:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  | public: | 
					
						
							|  |  |  |     explicit GAbstractView(GWidget* parent); | 
					
						
							|  |  |  |     virtual ~GAbstractView() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 18:37:47 +02:00
										 |  |  |     void set_model(RefPtr<GModel>&&); | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  |     GModel* model() { return m_model.ptr(); } | 
					
						
							|  |  |  |     const GModel* model() const { return m_model.ptr(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-07 19:14:59 +02:00
										 |  |  |     GModelSelection& selection() { return m_selection; } | 
					
						
							|  |  |  |     const GModelSelection& selection() const { return m_selection; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-18 22:27:14 +02:00
										 |  |  |     bool is_editable() const { return m_editable; } | 
					
						
							|  |  |  |     void set_editable(bool editable) { m_editable = editable; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  |     virtual bool accepts_focus() const override { return true; } | 
					
						
							|  |  |  |     virtual void did_update_model(); | 
					
						
							| 
									
										
										
										
											2019-03-30 03:27:25 +01:00
										 |  |  |     virtual void did_update_selection(); | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  |     virtual Rect content_rect(const GModelIndex&) const { return {}; } | 
					
						
							| 
									
										
										
										
											2019-04-19 00:07:33 +02:00
										 |  |  |     void begin_editing(const GModelIndex&); | 
					
						
							|  |  |  |     void stop_editing(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 04:56:52 +02:00
										 |  |  |     void set_activates_on_selection(bool b) { m_activates_on_selection = b; } | 
					
						
							|  |  |  |     bool activates_on_selection() const { return m_activates_on_selection; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-07 21:34:26 +02:00
										 |  |  |     Function<void()> on_selection_change; | 
					
						
							| 
									
										
										
										
											2019-05-09 04:56:52 +02:00
										 |  |  |     Function<void(const GModelIndex&)> on_activation; | 
					
						
							| 
									
										
										
										
											2019-06-22 10:40:35 +02:00
										 |  |  |     Function<void(const GModelIndex&)> on_selection; | 
					
						
							| 
									
										
										
										
											2019-06-30 08:13:41 +02:00
										 |  |  |     Function<void(const GModelIndex&, const GContextMenuEvent&)> on_context_menu_request; | 
					
						
							| 
									
										
										
										
											2019-03-23 03:53:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-23 08:18:28 +02:00
										 |  |  |     Function<OwnPtr<GModelEditingDelegate>(const GModelIndex&)> aid_create_editing_delegate; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-07 19:14:59 +02:00
										 |  |  |     void notify_selection_changed(Badge<GModelSelection>); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2019-04-18 23:57:07 +02:00
										 |  |  |     virtual void did_scroll() override; | 
					
						
							| 
									
										
										
										
											2019-05-09 04:56:52 +02:00
										 |  |  |     void activate(const GModelIndex&); | 
					
						
							| 
									
										
										
										
											2019-04-18 23:57:07 +02:00
										 |  |  |     void update_edit_widget_position(); | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-18 22:27:14 +02:00
										 |  |  |     bool m_editable { false }; | 
					
						
							|  |  |  |     GModelIndex m_edit_index; | 
					
						
							| 
									
										
										
										
											2019-06-23 08:18:28 +02:00
										 |  |  |     GWidget* m_edit_widget { nullptr }; | 
					
						
							| 
									
										
										
										
											2019-04-18 23:57:07 +02:00
										 |  |  |     Rect m_edit_widget_content_rect; | 
					
						
							| 
									
										
										
										
											2019-04-18 22:27:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-06-21 18:37:47 +02:00
										 |  |  |     RefPtr<GModel> m_model; | 
					
						
							| 
									
										
										
										
											2019-06-23 08:18:28 +02:00
										 |  |  |     OwnPtr<GModelEditingDelegate> m_editing_delegate; | 
					
						
							| 
									
										
										
										
											2019-09-07 19:14:59 +02:00
										 |  |  |     GModelSelection m_selection; | 
					
						
							| 
									
										
										
										
											2019-05-09 04:56:52 +02:00
										 |  |  |     bool m_activates_on_selection { false }; | 
					
						
							| 
									
										
										
										
											2019-03-23 02:04:31 +01:00
										 |  |  | }; |