2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-03-29 06:00:07 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-16 11:17:49 +03:00
|
|
|
#include <AK/HashMap.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/AbstractTableView.h>
|
2019-03-29 06:00:07 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
class TreeView : public AbstractTableView {
|
|
|
|
C_OBJECT(TreeView)
|
2019-03-29 06:00:07 +03:00
|
|
|
public:
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual ~TreeView() override;
|
2019-03-29 06:00:07 +03:00
|
|
|
|
2020-09-16 16:28:16 +03:00
|
|
|
virtual void scroll_into_view(const ModelIndex&, bool scroll_horizontally, bool scroll_vertically) override;
|
2019-03-29 06:00:07 +03:00
|
|
|
|
2019-12-14 01:36:36 +03:00
|
|
|
virtual int item_count() const override;
|
2020-03-18 16:50:34 +03:00
|
|
|
virtual void toggle_index(const ModelIndex&) override;
|
2019-12-14 01:36:36 +03:00
|
|
|
|
2020-05-21 14:36:08 +03:00
|
|
|
void expand_tree(const ModelIndex& root = {});
|
|
|
|
void collapse_tree(const ModelIndex& root = {});
|
|
|
|
|
2020-09-18 19:38:27 +03:00
|
|
|
void expand_all_parents_of(const ModelIndex&);
|
|
|
|
|
2020-07-07 14:12:12 +03:00
|
|
|
Function<void(const ModelIndex&, const bool)> on_toggle;
|
|
|
|
|
2020-10-27 22:33:30 +03:00
|
|
|
void set_should_fill_selected_rows(bool fill) { m_should_fill_selected_rows = fill; }
|
|
|
|
bool should_fill_selected_rows() const { return m_should_fill_selected_rows; }
|
|
|
|
|
2021-03-11 18:35:40 +03:00
|
|
|
virtual int vertical_padding() const override { return m_vertical_padding; }
|
|
|
|
|
2021-07-10 18:11:04 +03:00
|
|
|
virtual Gfx::IntRect content_rect(ModelIndex const&) const override;
|
|
|
|
virtual Gfx::IntRect paint_invalidation_rect(ModelIndex const& index) const override { return content_rect(index); }
|
|
|
|
|
2021-08-08 12:52:15 +03:00
|
|
|
virtual int minimum_column_width(int column) override;
|
|
|
|
|
2019-03-29 06:00:07 +03:00
|
|
|
protected:
|
2020-02-23 14:07:13 +03:00
|
|
|
TreeView();
|
2019-09-21 17:06:43 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual void paint_event(PaintEvent&) override;
|
|
|
|
virtual void doubleclick_event(MouseEvent&) override;
|
|
|
|
virtual void keydown_event(KeyEvent&) override;
|
2020-08-27 18:47:19 +03:00
|
|
|
|
2019-03-30 05:27:25 +03:00
|
|
|
virtual void did_update_selection() override;
|
2020-11-26 10:40:14 +03:00
|
|
|
virtual void model_did_update(unsigned flags) override;
|
2020-08-27 19:36:31 +03:00
|
|
|
virtual void move_cursor(CursorMovement, SelectionUpdate) override;
|
2019-03-29 06:00:07 +03:00
|
|
|
|
|
|
|
private:
|
2020-06-10 11:57:59 +03:00
|
|
|
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&, bool& is_toggle) const override;
|
2019-12-14 01:36:36 +03:00
|
|
|
|
2020-08-26 21:34:07 +03:00
|
|
|
int row_height() const { return 16; }
|
2019-03-29 16:46:53 +03:00
|
|
|
int max_item_width() const { return frame_inner_rect().width(); }
|
2019-03-29 20:10:36 +03:00
|
|
|
int indent_width_in_pixels() const { return 16; }
|
2019-03-29 16:46:53 +03:00
|
|
|
int icon_size() const { return 16; }
|
2019-03-30 03:42:16 +03:00
|
|
|
int icon_spacing() const { return 2; }
|
2019-03-29 22:18:15 +03:00
|
|
|
int toggle_size() const { return 9; }
|
2019-03-30 03:42:16 +03:00
|
|
|
int text_padding() const { return 2; }
|
2020-03-02 23:36:01 +03:00
|
|
|
int tree_column_x_offset() const;
|
2019-12-14 01:36:36 +03:00
|
|
|
virtual void update_column_sizes() override;
|
2021-03-19 05:37:52 +03:00
|
|
|
virtual void auto_resize_column(int column) override;
|
2019-03-29 16:46:53 +03:00
|
|
|
|
2019-03-29 19:30:27 +03:00
|
|
|
template<typename Callback>
|
|
|
|
void traverse_in_paint_order(Callback) const;
|
|
|
|
|
2019-03-29 16:46:53 +03:00
|
|
|
struct MetadataForIndex;
|
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
MetadataForIndex& ensure_metadata_for_index(const ModelIndex&) const;
|
2020-05-21 14:36:08 +03:00
|
|
|
void set_open_state_of_all_in_subtree(const ModelIndex& root, bool open);
|
2019-03-29 16:46:53 +03:00
|
|
|
|
2019-07-24 09:42:55 +03:00
|
|
|
mutable HashMap<void*, NonnullOwnPtr<MetadataForIndex>> m_view_metadata;
|
2019-03-29 20:10:36 +03:00
|
|
|
|
2020-02-06 13:56:38 +03:00
|
|
|
RefPtr<Gfx::Bitmap> m_expand_bitmap;
|
|
|
|
RefPtr<Gfx::Bitmap> m_collapse_bitmap;
|
2020-10-27 22:33:30 +03:00
|
|
|
|
|
|
|
bool m_should_fill_selected_rows { false };
|
2021-03-11 18:35:40 +03:00
|
|
|
int m_vertical_padding { 6 };
|
2019-03-29 06:00:07 +03:00
|
|
|
};
|
2020-02-02 17:07:41 +03:00
|
|
|
|
|
|
|
}
|