neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
item_view.hpp
Go to the documentation of this file.
1// item_view.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
31
32namespace neogfx
33{
34 enum class cell_part : uint32_t
35 {
37 Base,
38 Text,
39 Image,
42 Editor
43 };
44
45 class item_view : public drag_drop_target<drag_drop_source<framed_scrollable_widget>>, protected i_header_view_owner
46 {
48 public:
49 define_event(CellEntered, cell_entered, item_presentation_model_index const&)
50 define_event(CellLeft, cell_left, item_presentation_model_index const&)
51 define_event(CellContextMenu, cell_context_menu, item_presentation_model_index const&)
52 define_event(CellAction, cell_action, item_presentation_model_index const&)
53 public:
54 struct no_model : std::logic_error { no_model() : std::logic_error("neogfx::item_view::no_model") {} };
55 struct no_presentation_model : std::logic_error { no_presentation_model() : std::logic_error("neogfx::item_view::no_presentation_model") {} };
56 struct no_selection_model : std::logic_error { no_selection_model() : std::logic_error("neogfx::item_view::no_selection_model") {} };
57 struct no_editor : std::logic_error { no_editor() : std::logic_error("neogfx::item_view::no_editor") {} };
58 struct unknown_editor_type : std::logic_error { unknown_editor_type() : std::logic_error("neogfx::item_view::unknown_editor_type") {} };
59 struct invalid_cell_part : std::logic_error { invalid_cell_part() : std::logic_error("neogfx::item_view::invalid_cell_part") {} };
60 public:
65 public:
66 bool has_model() const;
67 const i_item_model& model() const;
68 i_item_model& model();
69 void set_model(i_item_model& aModel);
72 const i_item_presentation_model& presentation_model() const;
73 i_item_presentation_model& presentation_model();
74 void set_presentation_model(i_item_presentation_model& aPresentationModel);
76 bool has_selection_model() const;
81 public:
82 bool hot_tracking() const;
85 public:
86 bool is_valid(item_presentation_model_index const& aItemIndex) const;
87 bool is_visible(item_presentation_model_index const& aItemIndex, bool aPartiallyVisible = false) const;
88 bool make_visible(item_presentation_model_index const& aItemIndex);
89 const optional_item_presentation_model_index& editing() const;
90 void edit(item_presentation_model_index const& aItemIndex);
91 void begin_edit();
92 void end_edit(bool aCommit);
93 bool beginning_edit() const;
94 bool ending_edit() const;
95 i_widget& editor() const;
97 text_edit& editor_text_edit() const;
98 public:
99 void enable_drag_drop_source(bool aEnable = true) final;
100 protected:
101 bool is_drag_drop_object(point const& aPosition) const override;
102 i_drag_drop_object const* drag_drop_object(point const& aPosition) override;
103 protected:
104 bool updating_models() const override;
105 protected:
106 void header_view_updated(header_view& aHeaderView, header_view_update_reason aUpdateReason) override;
107 protected:
108 virtual void model_changed() = 0;
109 virtual void presentation_model_changed() = 0;
110 virtual void selection_model_changed() = 0;
111 virtual void tree_changed() = 0;
112 protected:
113 virtual rect item_display_rect(bool aIntersectItemArea = false) const = 0;
114 virtual size total_item_area(i_units_context const& aUnitsContext) const = 0;
115 virtual dimension column_width(uint32_t aColumn) const = 0;
118 protected:
119 void layout_items_completed() override;
120 protected:
121 widget_part hit_test(const point& aPosition) const override;
122 protected:
123 neogfx::size_policy size_policy() const override;
124 protected:
125 void paint(i_graphics_context& aGc) const override;
126 public:
127 color palette_color(color_role aColorRole) const override;
128 protected:
129 void capture_released() override;
131 void focus_gained(focus_reason aFocusReason) override;
132 protected:
133 void mouse_button_pressed(mouse_button aButton, const point& aPosition, key_modifiers_e aKeyModifiers) override;
134 void mouse_button_double_clicked(mouse_button aButton, const point& aPosition, key_modifiers_e aKeyModifiers) override;
135 void mouse_button_released(mouse_button aButton, const point& aPosition) override;
136 void mouse_moved(const point& aPosition, key_modifiers_e aKeyModifiers) override;
137 void mouse_entered(const point& aPosition) override;
138 void mouse_left() override;
139 protected:
140 bool key_pressed(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override;
141 bool text_input(i_string const& aText) override;
142 protected:
143 rect scroll_area() const override;
144 size scroll_page() const override;
145 protected:
148 bool use_scrollbar_container_updater() const override;
149 void scroll_page_updated() override;
150 protected:
151 virtual void column_info_changed(item_model_index::value_type aColumnIndex);
152 virtual void item_added(const item_model_index& aItemIndex);
153 virtual void item_changed(const item_model_index& aItemIndex);
154 virtual void item_removed(const item_model_index& aItemIndex);
155 protected:
156 virtual void item_model_changed(const i_item_model& aItemModel);
157 virtual void item_added(item_presentation_model_index const& aItemIndex);
158 virtual void item_changed(item_presentation_model_index const& aItemIndex);
159 virtual void item_removed(item_presentation_model_index const& aItemIndex);
160 virtual void items_updated();
161 virtual void items_sorting();
162 virtual void items_sorted();
163 virtual void items_filtering();
164 virtual void items_filtered();
165 protected:
166 virtual void presentation_model_added(i_item_presentation_model& aNewModel);
167 virtual void presentation_model_changed(i_item_presentation_model& aNewModel, i_item_presentation_model& aOldModel);
168 virtual void presentation_model_removed(i_item_presentation_model& aOldModel);
169 virtual void mode_changed(item_selection_mode aNewMode);
170 virtual void current_index_changed(const optional_item_presentation_model_index& aCurrentIndex, const optional_item_presentation_model_index& aPreviousIndex);
171 virtual void selection_changed(const item_selection& aCurrentSelection, const item_selection& aPreviousSelection);
172 public:
173 rect row_rect(item_presentation_model_index const& aItemIndex) const;
174 rect cell_rect(item_presentation_model_index const& aItemIndex, cell_part aPart = cell_part::Base) const;
175 rect cell_rect(item_presentation_model_index const& aItemIndex, i_graphics_context& aGc, cell_part aPart = cell_part::Base) const;
176 optional_item_presentation_model_index item_at(const point& aPosition, bool aIncludeEntireRow = true) const;
177 private:
178 void init();
179 void invalidate_item(item_presentation_model_index const& aItemIndex);
180 void update_hover(const optional_point& aPosition);
181 item_selection_operation to_selection_operation(key_modifiers_e aKeyModifiers) const;
182 void select(item_presentation_model_index const& aItemIndex, key_modifiers_e aKeyModifiers);
183 void select(item_presentation_model_index const& aItemIndex, item_selection_operation aSelectionOperation = item_selection_operation::ClearAndSelect);
184 private:
185 sink iSink;
186 sink iModelSink;
187 sink iPresentationModelSink;
188 sink iSelectionModelSink;
189 sink iDragDropSink;
190 ref_ptr<i_item_model> iModel;
191 ref_ptr<i_item_presentation_model> iPresentationModel;
192 ref_ptr<i_item_selection_model> iSelectionModel;
193 bool iUpdatingModels;
194 optional_item_presentation_model_index iItemToMakeVisible;
195 bool iHotTracking;
196 bool iIgnoreNextMouseMove;
197 std::optional<widget_timer> iMouseTracker;
198 optional_item_presentation_model_index iEditing;
199 std::shared_ptr<i_item_editor> iEditor;
200 bool iBeginningEdit;
201 bool iEndingEdit;
202 optional_item_presentation_model_index iHoverCell;
203 optional_item_presentation_model_index iClickedItem;
204 optional_item_presentation_model_index iClickedCheckBox;
205 optional_item_model_index iSavedModelIndex;
206 basic_size<i_scrollbar::value_type> iOldPositionForScrollbarVisibility;
207 std::optional<drag_drop_item> iDragDropItem;
208 };
209}
i_item_selection_model & selection_model()
bool updating_models() const override
virtual void tree_changed()=0
bool ending_edit() const
void mouse_button_released(mouse_button aButton, const point &aPosition) override
rect cell_rect(item_presentation_model_index const &aItemIndex, cell_part aPart=cell_part::Base) const
bool has_model() const
bool key_pressed(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override
void mouse_left() override
void edit(item_presentation_model_index const &aItemIndex)
optional_item_presentation_model_index item_at(const point &aPosition, bool aIncludeEntireRow=true) const
item_view(frame_style aFrameStyle=frame_style::SolidFrame, neogfx::scrollbar_style aScrollbarStyle=neogfx::scrollbar_style::Normal)
size scroll_page() const override
i_widget & editor() const
virtual void presentation_model_added(i_item_presentation_model &aNewModel)
virtual void items_filtered()
void set_selection_model(i_item_selection_model &aSelectionModel)
void disable_hot_tracking()
bool is_drag_drop_object(point const &aPosition) const override
virtual void model_changed()=0
const i_item_selection_model & selection_model() const
void set_model(i_item_model &aModel)
rect scroll_area() const override
bool editor_has_text_edit() const
text_edit & editor_text_edit() const
virtual void mode_changed(item_selection_mode aNewMode)
virtual void presentation_model_removed(i_item_presentation_model &aOldModel)
void scroll_page_updated() override
virtual dimension column_width(uint32_t aColumn) const =0
bool text_input(i_string const &aText) override
rect row_rect(item_presentation_model_index const &aItemIndex) const
i_item_presentation_model & presentation_model()
std::pair< item_model_index::value_type, coordinate > first_visible_item(i_graphics_context &aGc) const
const i_item_presentation_model & presentation_model() const
virtual void column_info_changed(item_model_index::value_type aColumnIndex)
neogfx::size_policy size_policy() const override
bool has_presentation_model() const
virtual void selection_model_changed()=0
void enable_hot_tracking()
void paint(i_graphics_context &aGc) const override
void update_scrollbar_visibility() override
virtual void item_removed(const item_model_index &aItemIndex)
void layout_items_completed() override
color palette_color(color_role aColorRole) const override
void capture_released() override
virtual rect item_display_rect(bool aIntersectItemArea=false) const =0
virtual void item_model_changed(const i_item_model &aItemModel)
const i_item_model & model() const
std::pair< item_model_index::value_type, coordinate > last_visible_item(i_graphics_context &aGc) const
i_item_model & model()
item_view(i_widget &aParent, frame_style aFrameStyle=frame_style::SolidFrame, neogfx::scrollbar_style aScrollbarStyle=neogfx::scrollbar_style::Normal)
void set_selection_model(i_ref_ptr< i_item_selection_model > const &aSelectionModel)
void set_presentation_model(i_ref_ptr< i_item_presentation_model > const &aPresentationModel)
void enable_drag_drop_source(bool aEnable=true) final
void mouse_button_double_clicked(mouse_button aButton, const point &aPosition, key_modifiers_e aKeyModifiers) override
virtual void items_updated()
bool hot_tracking() const
item_view(i_layout &aLayout, frame_style aFrameStyle=frame_style::SolidFrame, neogfx::scrollbar_style aScrollbarStyle=neogfx::scrollbar_style::Normal)
virtual void presentation_model_changed()=0
bool has_selection_model() const
virtual size total_item_area(i_units_context const &aUnitsContext) const =0
virtual void item_changed(const item_model_index &aItemIndex)
widget_part hit_test(const point &aPosition) const override
bool is_valid(item_presentation_model_index const &aItemIndex) const
void set_presentation_model(i_item_presentation_model &aPresentationModel)
bool use_scrollbar_container_updater() const override
virtual void selection_changed(const item_selection &aCurrentSelection, const item_selection &aPreviousSelection)
virtual void item_added(const item_model_index &aItemIndex)
void set_model(i_ref_ptr< i_item_model > const &aModel)
virtual void items_sorted()
bool is_visible(item_presentation_model_index const &aItemIndex, bool aPartiallyVisible=false) const
virtual void current_index_changed(const optional_item_presentation_model_index &aCurrentIndex, const optional_item_presentation_model_index &aPreviousIndex)
virtual void items_sorting()
const optional_item_presentation_model_index & editing() const
bool make_visible(item_presentation_model_index const &aItemIndex)
void mouse_button_pressed(mouse_button aButton, const point &aPosition, key_modifiers_e aKeyModifiers) override
void mouse_moved(const point &aPosition, key_modifiers_e aKeyModifiers) override
void end_edit(bool aCommit)
void header_view_updated(header_view &aHeaderView, header_view_update_reason aUpdateReason) override
void focus_gained(focus_reason aFocusReason) override
virtual void items_filtering()
void mouse_entered(const point &aPosition) override
bool beginning_edit() const
header_view_update_reason
default_geometry_value_type dimension
default_geometry_value_type coordinate
mouse_button
Definition i_mouse.hpp:31
std::optional< item_model_index > optional_item_model_index
@ Background
Definition i_palette.hpp:33
Definition plf_hive.h:79
#define meta_object(...)
Definition i_object.hpp:28
#define define_event(name, declName,...)
Definition event.hpp:200