22 #ifndef GtkCRNSelectionBox_HEADER
23 #define GtkCRNSelectionBox_HEADER
25 #include <libgtkcrnmm_config.h>
54 void set_homogeneous(
bool homogeneous =
true) { box->set_homogeneous(homogeneous); }
61 void pack_start(Gtk::Widget& child, Gtk::PackOptions options = Gtk::PACK_EXPAND_WIDGET, guint padding = 0);
63 void pack_start(Gtk::Widget& child,
bool expand,
bool fill, guint padding = 0);
65 void pack_end(Gtk::Widget& child, Gtk::PackOptions options = Gtk::PACK_EXPAND_WIDGET, guint padding = 0);
67 void pack_end(Gtk::Widget& child,
bool expand,
bool fill, guint padding = 0);
77 void set_policy(Gtk::PolicyType hscrollbar_policy, Gtk::PolicyType vscrollbar_policy) { sw.set_policy(hscrollbar_policy, vscrollbar_policy); }
104 void set_selected(
size_t index,
bool selected =
true,
bool silent =
false);
129 sigc::signal<void, std::vector<size_t>, std::vector<size_t>>
signal_moved() {
return moved; }
140 Gtk::ScrolledWindow sw;
144 class DropZone:
public Gtk::DrawingArea
147 DropZone(
const sigc::slot7<
void,
Element*,
const Glib::RefPtr<Gdk::DragContext>&,
int,
int,
const Gtk::SelectionData&, guint, guint> &dropfun,
SelectionBox *sb,
Element *el);
149 bool drag_motion(
const Glib::RefPtr<Gdk::DragContext>& context,
int x,
int y, guint time);
150 void drag_leave(
const Glib::RefPtr<Gdk::DragContext>& context, guint time);
151 #ifdef CRN_USING_GTKMM3
152 bool expose(
const Cairo::RefPtr<Cairo::Context>&);
154 bool expose(GdkEventExpose *ev);
157 #ifdef CRN_USING_GTKMM3
161 DropZone first_drop_zone;
162 DropZone last_drop_zone;
165 static const int reorderId;
166 static const int dropId;
169 class Element:
public Gtk::Frame
174 void Select() { tb.set_active(
true); }
175 void Deselect() { tb.set_active(
false); }
177 Gtk::Widget& GetWidget() {
return widget; }
178 const Gtk::Widget& GetWidget()
const {
return widget; }
182 void drag_begin(
const Glib::RefPtr<Gdk::DragContext>&) { Select(); }
183 void drag_data_get(
const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& seldata, guint info, guint time) { seldata.set_text(reorderKey.CStr()); }
185 std::shared_ptr<Gtk::Box> box;
187 Gtk::ToggleButton tb;
193 std::vector<std::shared_ptr<Element>> content;
194 std::set<std::shared_ptr<Element>> selection;
195 std::weak_ptr<Element> last_selected;
198 bool keyevents(GdkEventKey *ev);
200 bool cursor_cross(GdkEventCrossing *ev);
206 void drop(
Element *dropon,
const Glib::RefPtr<Gdk::DragContext>& context,
int,
int,
const Gtk::SelectionData& selection_data, guint, guint time);
208 #ifdef CRN_USING_GTKMM3
209 void dodrop(
Element *dropon,
const Gtk::SelectionData *selection_data,
int info);
211 void dodrop(
Element *dropon,
const GtkSelectionData *selection_data,
int info);
215 bool drag_motion(
const Glib::RefPtr<Gdk::DragContext>& context,
int x,
int y, guint time);
219 Gtk::Widget *drag_item;
220 int vscrolldiv, hscrolldiv;
221 sigc::signal<void, std::vector<size_t>, std::vector<size_t>> moved;
222 sigc::signal<void, int, crn::StringUTF8> droppedin;
223 sigc::signal<void, Gtk::Widget*, const std::vector<Gtk::Widget*>> selection_changed;
void set_selection(size_t index)
Sets the selection (one element)
void set_selected(size_t index, bool selected=true, bool silent=false)
Adds or remove an element from the selection.
void select_next()
If selection size is 0, the select the first element, if selection size is 1, then select the next it...
void set_policy(Gtk::PolicyType hscrollbar_policy, Gtk::PolicyType vscrollbar_policy)
Sets the scrolling policy.
Orientation
An enumeration of orientations.
int get_spacing() const
Gets the value set by set_spacing().
void select_even()
Selects odd elements (2nd, 4th…)
Gtk::Widget * get_last_selected() const
Returns the last widget that was selected.
sigc::signal< void, int, crn::StringUTF8 > signal_droppedin()
Signals when something was dropped from another application. Connect to void on_droppedin(int positio...
virtual ~SelectionBox() override
Destructor.
A UTF32 character string class.
A Gtk::Box-like widget with multiple selection, reordering and drag'n drop features.
void select_odd()
Selects even elements (1st, 3rd…)
void pack_end(Gtk::Widget &child, Gtk::PackOptions options=Gtk::PACK_EXPAND_WIDGET, guint padding=0)
Right/bottom side insert a widget to a box.
void select_first()
If selection size is <= 1, then select the first item, else move last_selected to the first selected ...
void pack_start(Gtk::Widget &child, Gtk::PackOptions options=Gtk::PACK_EXPAND_WIDGET, guint padding=0)
Left/top side insert a widget to a box.
sigc::signal< void, std::vector< size_t >, std::vector< size_t > > signal_moved()
Signals when a widget was moved. Connect to void on_moved(moved_to, moved_from).
void clear()
Erase all elements.
void invert_selection()
Inverts the view selection.
std::vector< Gtk::Widget * > get_selection() const
Returns the list of selected widgets.
SelectionBox(crn::Orientation ori)
Constructor.
sigc::signal< void, Gtk::Widget *, const std::vector< Gtk::Widget * > > signal_selection_changed()
Signal when the selection has changed. Connect to void on_selection_changed(Gtk::Widget last_selected...
size_t get_nb_children() const
Returns the number of widgets inside the box.
bool is_selected(size_t index)
Is an element selected?
void select_last()
If selection size is <= 1, then select the last item, else move last_selected to the last selected el...
bool get_can_reorder() const
Returns if the elements can be reordered by the user.
void set_can_reorder(bool reorder=true)
Sets if the elements can be reordered by the user.
void select_previous()
If selection size is 0, the select the first element, if selection size is 1, then select the previou...
void select_all()
Selects all elements.
std::vector< Gtk::Widget * > get_content() const
Returns the list of widgets inside the box.
void set_spacing(int spacing)
Sets the Gtk::Box:spacing property of box, which is the number of pixels to place between children of...
void deselect_all()
Deselects all elements.
void set_homogeneous(bool homogeneous=true)
Sets the Gtk::Box:homogeneous property of box, controlling whether or not all children of box are giv...
bool get_homogeneous() const
Return value: true if the box is homogeneous.
crn::Orientation get_orientation() const
Returns the orientation of the box.