[glom/spread-table] FlowTable: Implement insert_before().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/spread-table] FlowTable: Implement insert_before().
- Date: Tue, 12 Oct 2010 08:44:43 +0000 (UTC)
commit 61ddaf3fc3c2455605c6a439e10544f3b5c9ace0
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Oct 12 10:09:10 2010 +0200
FlowTable: Implement insert_before().
* glom/utility_widgets/flowtable.[h|cc]: Re-added insert_before() which
we will need for drag and drop support.
ChangeLog | 7 +++
glom/utility_widgets/flowtable.cc | 87 +++++++++++++++++++++++++++++--------
glom/utility_widgets/flowtable.h | 3 +
3 files changed, 78 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1aef94f..bae383a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-10-12 Murray Cumming <murrayc murrayc com>
+
+ FlowTable: Implement insert_before().
+
+ * glom/utility_widgets/flowtable.[h|cc]: Re-added insert_before() which
+ we will need for drag and drop support.
+
2010-10-11 Murray Cumming <murrayc murrayc com>
Details: Use of GtkSpreadTable: Remove FlowTable:m_children.
diff --git a/glom/utility_widgets/flowtable.cc b/glom/utility_widgets/flowtable.cc
index 3c64d9c..942f1b3 100644
--- a/glom/utility_widgets/flowtable.cc
+++ b/glom/utility_widgets/flowtable.cc
@@ -46,34 +46,83 @@ void FlowTable::set_design_mode(bool value)
void FlowTable::add(Gtk::Widget& first, Gtk::Widget& second, bool expand_second)
{
- Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox(false, get_horizontal_spacing()));
+ insert(&first, &second, -1, expand_second);
+}
- hbox->pack_start(first, Gtk::PACK_SHRINK);
- hbox->pack_start(second, expand_second ? Gtk::PACK_EXPAND_WIDGET : Gtk::PACK_SHRINK);
- hbox->show();
+void FlowTable::add(Gtk::Widget& first, bool expand)
+{
+ insert(&first, 0 /* second */, -1, expand);
+}
- hbox->set_halign(Gtk::ALIGN_FILL);
- append_child(*hbox);
+void FlowTable::insert(Gtk::Widget* first, Gtk::Widget* second, int index, bool expand)
+{
+ if(first && second)
+ {
+ Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox(false, get_horizontal_spacing()));
+
+ hbox->pack_start(*first, Gtk::PACK_SHRINK);
+ hbox->pack_start(*second, expand ? Gtk::PACK_EXPAND_WIDGET : Gtk::PACK_SHRINK);
+ hbox->show();
+
+ hbox->set_halign(Gtk::ALIGN_FILL);
+ insert_child(*hbox, index);
+ }
+ else if(first)
+ {
+ first->set_halign(expand ? Gtk::ALIGN_FILL : Gtk::ALIGN_START);
+ append_child(*first);
+ }
+ else
+ {
+ std::cerr << G_STRFUNC << ": first was null" << std::endl;
+ }
}
-void FlowTable::add(Gtk::Widget& first, bool expand)
+int FlowTable::get_child_index(const Gtk::Widget& first) const
{
- first.set_halign(expand ? Gtk::ALIGN_FILL : Gtk::ALIGN_START);
- append_child(first);
+ int index = 0;
+
+ typedef std::vector<const Widget*> type_children;
+ const type_children children = get_children();
+ for(type_children::const_iterator iter = children.begin(); iter != children.end(); ++iter)
+ {
+ const Gtk::Widget* widget = *iter;
+ if(!widget)
+ continue;
+
+ if(widget == &first) //It must be a single item.
+ break;
+ else
+ {
+ const Gtk::HBox* hbox = dynamic_cast<const Gtk::HBox*>(widget);
+ if(hbox) //The first and second widgets are inside an HBox
+ {
+ const type_children box_children = hbox->get_children();
+ if(!box_children.empty())
+ {
+ const Gtk::Widget* child_widget = box_children[0]; //TODO: Is this definitely the left-most one?
+ if(child_widget == &first)
+ break;
+ }
+ }
+ }
+
+ ++index;
+ }
+
+ return index;
}
-void FlowTable::insert_before(Gtk::Widget& /* first */, Gtk::Widget& /* before */, bool /* expand */)
+void FlowTable::insert_before(Gtk::Widget& first, Gtk::Widget& before, bool expand)
{
- std::cerr << G_STRFUNC << ": Unimplemented." << std::endl;
- //FlowTableItem item(&first, this);
- //TODO: insert_before(item, before, expand);
+ const int index = get_child_index(before);
+ insert(&first, 0 /* second */, index - 1, expand);
}
-void FlowTable::insert_before(Gtk::Widget& /* first */, Gtk::Widget& /* second */, Gtk::Widget& /* before */, bool /* expand_second */)
+void FlowTable::insert_before(Gtk::Widget& first, Gtk::Widget& second, Gtk::Widget& before, bool expand_second)
{
- std::cerr << G_STRFUNC << ": Unimplemented." << std::endl;
- //FlowTableItem item(&first, &second, this);
- //TODO: insert_before(item, before, expand_second);
+ const int index = get_child_index(before);
+ insert(&first, &second, index - 1, expand_second);
}
void FlowTable::remove_all()
@@ -97,7 +146,7 @@ bool FlowTable::get_column_for_first_widget(const Gtk::Widget& first, guint& col
return false;
typedef std::vector<const Widget*> type_children;
- type_children children = get_children();
+ const type_children children = get_children();
for(type_children::const_iterator iter = children.begin(); iter != children.end(); ++iter)
{
const Gtk::Widget* widget = *iter;
@@ -113,7 +162,7 @@ bool FlowTable::get_column_for_first_widget(const Gtk::Widget& first, guint& col
const Gtk::HBox* hbox = dynamic_cast<const Gtk::HBox*>(widget);
if(hbox) //The first and second widgets are inside an HBox
{
- type_children box_children = hbox->get_children();
+ const type_children box_children = hbox->get_children();
if(!box_children.empty())
child = box_children[0]; //TODO: Is this definitely the left-most one?
}
diff --git a/glom/utility_widgets/flowtable.h b/glom/utility_widgets/flowtable.h
index 14b3ac5..09e85ca 100644
--- a/glom/utility_widgets/flowtable.h
+++ b/glom/utility_widgets/flowtable.h
@@ -54,7 +54,10 @@ protected:
*/
bool get_column_for_first_widget(const Gtk::Widget& first, guint& column) const;
+ void insert(Gtk::Widget* first, Gtk::Widget* second, int index, bool expand);
+
private:
+ int get_child_index(const Gtk::Widget& first) const;
bool m_design_mode;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]