summaryrefslogtreecommitdiff
path: root/LibGUI/GAbstractView.h
blob: f660e141cefbf5af251e018b4c7e8a1e02375ebf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#include <LibGUI/GModel.h>
#include <LibGUI/GScrollableWidget.h>
#include <AK/Function.h>

class GTextBox;

class GAbstractView : public GScrollableWidget {
    friend class GModel;
public:
    explicit GAbstractView(GWidget* parent);
    virtual ~GAbstractView() override;

    void set_model(RetainPtr<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();

    Function<void(const GModelNotification&)> on_model_notification;

    virtual const char* class_name() const override { return "GAbstractView"; }

protected:
    virtual void model_notification(const GModelNotification&);
    virtual void did_scroll() override;
    void update_edit_widget_position();

    bool m_editable { false };
    GModelIndex m_edit_index;
    GTextBox* m_edit_widget { nullptr };
    Rect m_edit_widget_content_rect;

private:
    RetainPtr<GModel> m_model;
};