2019-03-23 01:04:31 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
#include <AK/Function.h>
|
2019-03-23 01:04:31 +00:00
|
|
|
#include <LibGUI/GModel.h>
|
|
|
|
#include <LibGUI/GScrollableWidget.h>
|
|
|
|
|
2019-06-23 06:18:28 +00:00
|
|
|
class GModelEditingDelegate;
|
2019-04-18 20:27:14 +00:00
|
|
|
|
2019-03-23 01:04:31 +00:00
|
|
|
class GAbstractView : public GScrollableWidget {
|
|
|
|
friend class GModel;
|
2019-05-28 09:53:16 +00:00
|
|
|
|
2019-03-23 01:04:31 +00:00
|
|
|
public:
|
|
|
|
explicit GAbstractView(GWidget* parent);
|
|
|
|
virtual ~GAbstractView() override;
|
|
|
|
|
2019-06-21 16:37:47 +00:00
|
|
|
void set_model(RefPtr<GModel>&&);
|
2019-03-23 01:04:31 +00:00
|
|
|
GModel* model() { return m_model.ptr(); }
|
|
|
|
const GModel* model() const { return m_model.ptr(); }
|
|
|
|
|
2019-04-18 20:27:14 +00:00
|
|
|
bool is_editable() const { return m_editable; }
|
|
|
|
void set_editable(bool editable) { m_editable = editable; }
|
|
|
|
|
2019-03-23 01:04:31 +00:00
|
|
|
virtual bool accepts_focus() const override { return true; }
|
|
|
|
virtual void did_update_model();
|
2019-03-30 02:27:25 +00:00
|
|
|
virtual void did_update_selection();
|
2019-03-23 01:04:31 +00:00
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
virtual Rect content_rect(const GModelIndex&) const { return {}; }
|
2019-04-18 22:07:33 +00:00
|
|
|
void begin_editing(const GModelIndex&);
|
|
|
|
void stop_editing();
|
|
|
|
|
2019-05-09 02:56:52 +00:00
|
|
|
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;
|
2019-06-22 08:40:35 +00:00
|
|
|
Function<void(const GModelIndex&)> on_selection;
|
2019-03-23 02:53:51 +00:00
|
|
|
Function<void(const GModelNotification&)> on_model_notification;
|
|
|
|
|
2019-06-23 06:18:28 +00:00
|
|
|
Function<OwnPtr<GModelEditingDelegate>(const GModelIndex&)> aid_create_editing_delegate;
|
|
|
|
|
2019-03-23 02:53:51 +00:00
|
|
|
virtual const char* class_name() const override { return "GAbstractView"; }
|
|
|
|
|
2019-03-23 01:04:31 +00:00
|
|
|
protected:
|
|
|
|
virtual void model_notification(const GModelNotification&);
|
2019-04-18 21:57:07 +00:00
|
|
|
virtual void did_scroll() override;
|
2019-05-09 02:56:52 +00:00
|
|
|
void activate(const GModelIndex&);
|
2019-04-18 21:57:07 +00:00
|
|
|
void update_edit_widget_position();
|
2019-03-23 01:04:31 +00:00
|
|
|
|
2019-04-18 20:27:14 +00:00
|
|
|
bool m_editable { false };
|
|
|
|
GModelIndex m_edit_index;
|
2019-06-23 06:18:28 +00:00
|
|
|
GWidget* m_edit_widget { nullptr };
|
2019-04-18 21:57:07 +00:00
|
|
|
Rect m_edit_widget_content_rect;
|
2019-04-18 20:27:14 +00:00
|
|
|
|
2019-03-23 01:04:31 +00:00
|
|
|
private:
|
2019-06-21 16:37:47 +00:00
|
|
|
RefPtr<GModel> m_model;
|
2019-06-23 06:18:28 +00:00
|
|
|
OwnPtr<GModelEditingDelegate> m_editing_delegate;
|
2019-05-09 02:56:52 +00:00
|
|
|
bool m_activates_on_selection { false };
|
2019-03-23 01:04:31 +00:00
|
|
|
};
|