summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GAbstractView.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-04 16:16:50 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-04 16:16:50 +0200
commit04b9dc2d30cfc9b383029f6a4b02e2725108b0ae (patch)
treee117a998173b767f9fd009d49c4f8573d8b85432 /Libraries/LibGUI/GAbstractView.h
parent63814ffebf16291419745cd8ba29a4d2fd888563 (diff)
downloadserenity-04b9dc2d30cfc9b383029f6a4b02e2725108b0ae.zip
Libraries: Create top level directory for libraries.
Things were getting a little crowded in the project root, so this patch moves the Lib*/ directories into Libraries/.
Diffstat (limited to 'Libraries/LibGUI/GAbstractView.h')
-rw-r--r--Libraries/LibGUI/GAbstractView.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/Libraries/LibGUI/GAbstractView.h b/Libraries/LibGUI/GAbstractView.h
new file mode 100644
index 0000000000..348cabfdc3
--- /dev/null
+++ b/Libraries/LibGUI/GAbstractView.h
@@ -0,0 +1,58 @@
+#pragma once
+
+#include <AK/Function.h>
+#include <LibGUI/GModel.h>
+#include <LibGUI/GScrollableWidget.h>
+
+class GModelEditingDelegate;
+
+class GAbstractView : public GScrollableWidget {
+ friend class GModel;
+
+public:
+ explicit GAbstractView(GWidget* parent);
+ virtual ~GAbstractView() override;
+
+ void set_model(RefPtr<GModel>&&);
+ GModel* model() { return m_model.ptr(); }
+ const GModel* model() const { return m_model.ptr(); }
+
+ bool is_editable() const { return m_editable; }
+ void set_editable(bool editable) { m_editable = editable; }
+
+ virtual bool accepts_focus() const override { return true; }
+ virtual void did_update_model();
+ virtual void did_update_selection();
+
+ virtual Rect content_rect(const GModelIndex&) const { return {}; }
+ void begin_editing(const GModelIndex&);
+ void stop_editing();
+
+ void set_activates_on_selection(bool b) { m_activates_on_selection = b; }
+ bool activates_on_selection() const { return m_activates_on_selection; }
+
+ Function<void(const GModelIndex&)> on_activation;
+ Function<void(const GModelIndex&)> on_selection;
+ Function<void(const GModelIndex&, const GContextMenuEvent&)> on_context_menu_request;
+ Function<void(const GModelNotification&)> on_model_notification;
+
+ Function<OwnPtr<GModelEditingDelegate>(const GModelIndex&)> aid_create_editing_delegate;
+
+ virtual const char* class_name() const override { return "GAbstractView"; }
+
+protected:
+ virtual void model_notification(const GModelNotification&);
+ virtual void did_scroll() override;
+ void activate(const GModelIndex&);
+ void update_edit_widget_position();
+
+ bool m_editable { false };
+ GModelIndex m_edit_index;
+ GWidget* m_edit_widget { nullptr };
+ Rect m_edit_widget_content_rect;
+
+private:
+ RefPtr<GModel> m_model;
+ OwnPtr<GModelEditingDelegate> m_editing_delegate;
+ bool m_activates_on_selection { false };
+};