[glom] Frame_Glom: Use GtkStack instead of our PlaceHolder widget for data/find modes.



commit 4b79d4db39758a6680cd02347f87381caa1ca952
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Oct 30 10:41:04 2013 +0100

    Frame_Glom: Use GtkStack instead of our PlaceHolder widget for data/find modes.
    
    * glom/frame_glom.[h|cc]: Replace the Glom::PlaceHolder with
      GtkStack, using set/get_visible_child() instead of adding, removing
      and getting the GtkBox child. This is simpler and safer.
    * glom/mode_data/box_data_details.[h|cc]:
      Constructor: Use show_all_children() instead of show(),
      to avoid showing this when the parent widget does not want it.
      Also override show_all_vfunc() to make sure that we never show
      the layout toolbar accidentally.
    
    This simplifies the code, so we don't have to worry about side-effects
    of repeatedly adding and removing widgets from their container.

 data/ui/operator/window_main.glade |    3 +-
 glom/frame_glom.cc                 |   38 +++++++++++------------------------
 glom/frame_glom.h                  |    2 +-
 glom/mode_data/box_data_details.cc |   16 ++++++++++++++-
 glom/mode_data/box_data_details.h  |    4 +++
 5 files changed, 33 insertions(+), 30 deletions(-)
---
diff --git a/data/ui/operator/window_main.glade b/data/ui/operator/window_main.glade
index 41aa818..0305684 100644
--- a/data/ui/operator/window_main.glade
+++ b/data/ui/operator/window_main.glade
@@ -59,8 +59,7 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkBox" id="vbox_mode">
-                        <property name="orientation">vertical</property>
+                      <object class="GtkStack" id="stack_mode">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <child>
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 6bc8e13..72b9049 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -77,7 +77,7 @@ Frame_Glom::Frame_Glom(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>
   m_pLabel_Table_FindMode(0),
   m_Box_RecordsCount(Gtk::ORIENTATION_HORIZONTAL, Utils::DEFAULT_SPACING_SMALL),
   m_Button_FindAll(_("Find All")),
-  m_pBox_Mode(0),
+  m_stack_mode(0),
   m_pBox_Tables(0),
   m_pDialog_Tables(0),
   m_pBox_QuickFind(0),
@@ -145,7 +145,14 @@ Frame_Glom::Frame_Glom(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>
   m_Button_FindAll.signal_clicked().connect(
     sigc::mem_fun(*this, &Frame_Glom::on_button_find_all) );
 
-  builder->get_widget_derived("vbox_mode", m_pBox_Mode);
+  builder->get_widget("stack_mode", m_stack_mode);
+  if(m_stack_mode)
+  {
+    m_stack_mode->add(m_Notebook_Data, "data");
+    m_stack_mode->add(m_Notebook_Find, "find");
+    m_stack_mode->set_visible_child(m_Notebook_Data);
+    m_Notebook_Data.set_enable_layout_drag_and_drop(false);
+  }
 
   m_Mode = MODE_None;
   m_Mode_Previous = MODE_None;
@@ -258,28 +265,7 @@ void Frame_Glom::on_box_tables_selected(const Glib::ustring& strName)
 
 void Frame_Glom::set_mode_widget(Gtk::Widget& widget)
 {
-  //Remove current contents.
-  //I wish that there was a better way to do this:
-  //Trying to remove all of them leads to warnings,
-  //and I don't see a way to get a list of children.
-
-  AppWindow* pApp = dynamic_cast<AppWindow*>(get_app_window());
-  if(!pApp)
-    return;
-
-  Notebook_Glom* notebook_current = dynamic_cast<Notebook_Glom*>(m_pBox_Mode->get_child());
-  if(notebook_current == &widget)
-  {
-    return; //No change necessary.
-  }
-
-  if(notebook_current)
-  {
-    m_pBox_Mode->remove();
-  }
-
-  m_pBox_Mode->add(widget);
-  widget.show();
+  m_stack_mode->set_visible_child(widget);
 }
 
 bool Frame_Glom::set_mode(enumModes mode)
@@ -1019,7 +1005,7 @@ bool Frame_Glom::attempt_toggle_shared(bool shared)
 
 void Frame_Glom::on_menu_file_print()
 {
- Notebook_Glom* notebook_current = dynamic_cast<Notebook_Glom*>(m_pBox_Mode->get_child());
+ Notebook_Glom* notebook_current = dynamic_cast<Notebook_Glom*>(m_stack_mode->get_visible_child());
  if(notebook_current)
    notebook_current->do_menu_file_print();
 }
@@ -1692,7 +1678,7 @@ void Frame_Glom::on_menu_developer_layout()
   if(m_table_name.empty())
     return;
 
-  Notebook_Glom* notebook_current = dynamic_cast<Notebook_Glom*>(m_pBox_Mode->get_child());
+  Notebook_Glom* notebook_current = dynamic_cast<Notebook_Glom*>(m_stack_mode->get_visible_child());
   if(notebook_current)
     notebook_current->do_menu_developer_layout();
 }
diff --git a/glom/frame_glom.h b/glom/frame_glom.h
index e02513a..d862636 100644
--- a/glom/frame_glom.h
+++ b/glom/frame_glom.h
@@ -265,7 +265,7 @@ private:
   Gtk::Label m_Label_FoundCount;
   Gtk::Button m_Button_FindAll;
 
-  PlaceHolder* m_pBox_Mode; //Contains e.g. design mode notebook.
+  Gtk::Stack* m_stack_mode; //Contains e.g. data or find mode notebook.
 
   //Navigation:
   Box_Tables* m_pBox_Tables;
diff --git a/glom/mode_data/box_data_details.cc b/glom/mode_data/box_data_details.cc
index 9a26900..43b2a1e 100644
--- a/glom/mode_data/box_data_details.cc
+++ b/glom/mode_data/box_data_details.cc
@@ -41,6 +41,7 @@ namespace Glom
 
 Box_Data_Details::Box_Data_Details(bool bWithNavButtons /* = true */)
 : m_hbox_content(Gtk::ORIENTATION_HORIZONTAL, Utils::DEFAULT_SPACING_SMALL),
+  m_show_toolbar(false),
   m_hbox_buttons(Gtk::ORIENTATION_HORIZONTAL),
   m_Button_New(_("_Add"), true),
   m_Button_Del(_("_Delete"), true),
@@ -94,7 +95,6 @@ Box_Data_Details::Box_Data_Details(bool bWithNavButtons /* = true */)
   m_FlowTable.signal_field_edited().connect( sigc::mem_fun(*this,  
&Box_Data_Details::on_flowtable_field_edited) );
   m_FlowTable.signal_field_choices_changed().connect( sigc::mem_fun(*this,  
&Box_Data_Details::on_flowtable_field_choices_changed) );
   m_FlowTable.signal_field_open_details_requested().connect( sigc::mem_fun(*this,  
&Box_Data_Details::on_flowtable_field_open_details_requested) );
-  show_all();
 
   m_FlowTable.signal_related_record_changed().connect( sigc::mem_fun(*this, 
&Box_Data_Details::on_flowtable_related_record_changed) );
 
@@ -144,6 +144,8 @@ Box_Data_Details::Box_Data_Details(bool bWithNavButtons /* = true */)
   pack_start(m_hbox_buttons, Gtk::PACK_SHRINK);
 
   m_ignore_signals = false;
+
+  show_all_children();
 }
 
 Box_Data_Details::~Box_Data_Details()
@@ -971,6 +973,9 @@ void Box_Data_Details::prepare_layout_dialog(Dialog_Layout* dialog)
 
 void Box_Data_Details::show_layout_toolbar(bool show)
 {
+  //Remember this so we can use it in the show_all() vfunc.
+  m_show_toolbar = show;
+
   if(show)
     m_Dragbar.show();
   else
@@ -989,4 +994,13 @@ void Box_Data_Details::set_enable_drag_and_drop(bool enabled)
   m_FlowTable.set_enable_drag_and_drop(enabled);
 }
 
+void Box_Data_Details::show_all_vfunc()
+{
+  //Call the base class:
+  Box_Data::show_all_vfunc();
+
+  //Hide some stuff:
+  show_layout_toolbar(m_show_toolbar);
+}
+
 } //namespace Glom
diff --git a/glom/mode_data/box_data_details.h b/glom/mode_data/box_data_details.h
index 9ae5082..660c345 100644
--- a/glom/mode_data/box_data_details.h
+++ b/glom/mode_data/box_data_details.h
@@ -136,6 +136,9 @@ protected:
   virtual void prepare_layout_dialog(Dialog_Layout* dialog); // override.
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
+
+ virtual void show_all_vfunc(); //override.
+
   sharedptr<Field> m_field_primary_key;
   Gnome::Gda::Value m_primary_key_value;
 
@@ -146,6 +149,7 @@ protected:
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   LayoutToolbar m_Dragbar;
+  bool m_show_toolbar;
 #endif
 
   Gtk::ButtonBox m_hbox_buttons;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]