[glom/maemo5] Maemo: Use a PickerButton with TouchSelector for combo boxes on details views.



commit 5a5cfbfcb789275612f2a621fd8a9457284ab2df
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Oct 8 15:47:16 2009 +0200

    Maemo: Use a PickerButton with TouchSelector for combo boxes on details views.
    
    * glom/utility_widgets/comboentryglom.[h|cc]:
    * glom/utility_widgets/comboglom.[h|cc]: On Maemo, derive from
    Hildon::PickerButton instead of Gtk::ComboBox*, with a member TouchSelector/
    TouchSelector.
    However, the ID field seems to be shown twice.
    Also remove the unused constructors for use with Gtk::Builder.

 ChangeLog                              |   10 +++++
 glom/utility_widgets/comboentryglom.cc |   59 ++++++++++++++++++++++++++---
 glom/utility_widgets/comboentryglom.h  |   14 +++++--
 glom/utility_widgets/comboglom.cc      |   64 +++++++++++++++++++++++++++----
 glom/utility_widgets/comboglom.h       |   25 ++++++++++--
 5 files changed, 149 insertions(+), 23 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c8cfc3f..ace23f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2009-10-08  Murray Cumming  <murrayc murrayc com>
 
+  Maemo: Use a PickerButton with TouchSelector for combo boxes on details views.
+  
+	* glom/utility_widgets/comboentryglom.[h|cc]:
+	* glom/utility_widgets/comboglom.[h|cc]: On Maemo, derive from 
+	Hildon::PickerButton instead of Gtk::ComboBox*, with a member TouchSelector/
+	TouchSelector.
+	However, the ID field seems to be shown twice.
+
+2009-10-08  Murray Cumming  <murrayc murrayc com>
+
   Maemo: Actually show new list views and related records portals.
   
 	* glom/utility_widgets/db_adddel/db_adddel.cc: construct_specified_columns():
diff --git a/glom/utility_widgets/comboentryglom.cc b/glom/utility_widgets/comboentryglom.cc
index 458551a..ac35233 100644
--- a/glom/utility_widgets/comboentryglom.cc
+++ b/glom/utility_widgets/comboentryglom.cc
@@ -54,17 +54,41 @@ ComboEntryGlom::ComboEntryGlom(const sharedptr<LayoutItem_Field>& field_second)
   init();
 }
 
+Gtk::Entry* ComboEntryGlom::get_entry()
+{
+  #ifndef GLOM_ENABLE_MAEMO
+  return Gtk::ComboBoxEntry::get_entry();
+  #else
+  return m_maemo_selector.get_entry();
+  #endif
+}
+
+const Gtk::Entry* ComboEntryGlom::get_entry() const
+{
+  #ifndef GLOM_ENABLE_MAEMO
+  return Gtk::ComboBoxEntry::get_entry();
+  #else
+  return m_maemo_selector.get_entry();
+  #endif
+}
+
 void ComboEntryGlom::init()
 {
 #ifndef GLOM_ENABLE_MAEMO
   set_model(m_refModel);
-
   set_text_column(m_Columns.m_col_first);
 #else
   //Maemo:
-  set_model(0, m_refModel);
-
-  set_text_column(0);
+  set_selector(m_maemo_selector);
+ 
+  Glib::RefPtr<Hildon::TouchSelectorColumn> column =
+    m_maemo_selector.append_text_column(m_refModel);
+  column->pack_start(m_Columns.m_col_first, false);
+  //column->set_property("text-column", 0); // TODO: Add a TextSelectorEntry::set_text_column() method?
+
+  
+  //m_maemo_selector.set_model(0, m_refModel);
+  //m_maemo_selector.set_text_column(0);
 #endif
 
   //We use connect(slot, false) to connect before the default signal handler, because the default signal handler prevents _further_ handling.
@@ -76,7 +100,11 @@ void ComboEntryGlom::init()
   get_entry()->signal_activate().connect(sigc::mem_fun(*this, &ComboEntryGlom::on_entry_activate));
 
 #ifndef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+  #ifndef GLOM_ENABLE_MAEMO
   signal_changed().connect(sigc::mem_fun(*this, &ComboEntryGlom::on_changed));
+  #else
+  m_maemo_selector.signal_changed().connect(sigc::mem_fun(*this, &ComboEntryGlom::on_changed));
+  #endif
 #endif // GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
 
   if(m_with_second)
@@ -100,7 +128,7 @@ void ComboEntryGlom::init()
     add_attribute(*cell_second, cell_second->_property_renderable(), m_Columns.m_col_second);
     #endif
     #else //GLOM_ENABLE_MAEMO
-    //TODO: Add the second cell renderer.
+    column->pack_start(m_Columns.m_col_second, false);
     #endif //GLOM_ENABLE_MAEMO
   }
 }
@@ -208,6 +236,18 @@ void ComboEntryGlom::set_value(const Gnome::Gda::Value& value)
 void ComboEntryGlom::set_text(const Glib::ustring& text)
 {
   m_old_text = text;
+  
+  #if GLOM_ENABLE_MAEMO
+  for(Gtk::TreeModel::iterator iter = m_refModel->children().begin(); iter != m_refModel->children().end(); ++iter)
+  {
+    const Glib::ustring& this_text = (*iter)[m_Columns.m_col_first];
+
+    if(this_text == text)
+    {
+      m_maemo_selector.set_active(0, iter);
+    }
+  }
+  #endif //GLOM_ENABLE_MAEMO
 
   //Call base class:
   get_entry()->set_text(text);
@@ -267,7 +307,7 @@ App_Glom* ComboEntryGlom::get_application()
 #ifndef GLOM_ENABLE_MAEMO
 void ComboEntryGlom::on_changed()
 #else
-void ComboEntryGlom::on_changed(int column)
+void ComboEntryGlom::on_changed(int /* column */)
 #endif 
 {
 #ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
@@ -277,7 +317,14 @@ void ComboEntryGlom::on_changed(int column)
 
   //This signal is emitted for every key press, but sometimes it's just to say that the active item has changed to "no active item",
   //if the text is not in the dropdown list:
+  #ifndef GLOM_ENABLE_MAEMO
   Gtk::TreeModel::iterator iter = get_active();
+  #else
+   //TODO: See bug https://bugs.maemo.org/show_bug.cgi?id=4640
+  //about the get_selected()/get_active() confusion.
+  Gtk::TreeModel::iterator iter = m_maemo_selector.get_selected(0);
+  #endif //GLOM_ENABLE_MAEMO
+  
   if(iter)
   {
     //This is either a choice from the dropdown menu, or someone has typed in something that is in the drop-down menu.
diff --git a/glom/utility_widgets/comboentryglom.h b/glom/utility_widgets/comboentryglom.h
index 71c2850..fab447f 100644
--- a/glom/utility_widgets/comboentryglom.h
+++ b/glom/utility_widgets/comboentryglom.h
@@ -26,9 +26,9 @@
 #include <gtkmm.h>
 #include <libglom/data_structure/field.h>
 #include "comboglomchoicesbase.h"
-#include <gtkmm/builder.h>
 
 #ifdef GLOM_ENABLE_MAEMO
+#include <hildonmm/picker-button.h>
 #include <hildonmm/touch-selector-entry.h>
 #endif //GLOM_ENABLE_MAEMO
 
@@ -46,7 +46,7 @@ class ComboEntryGlom
 #ifndef GLOM_ENABLE_MAEMO
   public Gtk::ComboBoxEntry,
 #else
-  public Hildon::TouchSelectorEntry,
+  public Hildon::PickerButton,
 #endif
   public ComboGlomChoicesBase
 {
@@ -90,7 +90,7 @@ private:
   virtual void on_changed(); //From Gtk::ComboBox
   #else
   void on_changed(int column);
-  #endif
+  #endif //GLOM_ENABLE_MAEMO
   
 
   virtual void check_for_change();
@@ -100,10 +100,16 @@ private:
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
   virtual App_Glom* get_application();
-
+  
+  Gtk::Entry* get_entry();
+  const Gtk::Entry* get_entry() const;
 
   Glib::ustring m_old_text;
   //Gnome::Gda::Value m_value; //The last-stored value. We have this because the displayed value might be unparseable.
+   
+  #ifdef GLOM_ENABLE_MAEMO
+  Hildon::TouchSelectorEntry m_maemo_selector;
+  #endif
 };
 
 } //namespace Glom
diff --git a/glom/utility_widgets/comboglom.cc b/glom/utility_widgets/comboglom.cc
index 40a2f8c..bd8b743 100644
--- a/glom/utility_widgets/comboglom.cc
+++ b/glom/utility_widgets/comboglom.cc
@@ -56,16 +56,34 @@ ComboGlom::ComboGlom(const sharedptr<LayoutItem_Field>& field_second)
 
 void ComboGlom::init()
 {
+  #ifndef GLOM_ENABLE_MAEMO
   set_model(m_refModel);
-
   pack_start(m_Columns.m_col_first);
+  #else
+  //Maemo:
+  set_selector(m_maemo_selector);
+  m_maemo_selector.set_model(0, m_refModel);
+  
+  Glib::RefPtr<Hildon::TouchSelectorColumn> column =
+    m_maemo_selector.append_text_column(m_refModel);
+  column->set_property("text-column", 0); // TODO: Add a TextSelectorColumn::set_text_column() method?
+
+  column->pack_start(m_Columns.m_col_first, false);
+  #endif //GLOM_ENABLE_MAEMO
+
 
-#ifndef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+
+  #ifndef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+  #ifndef GLOM_ENABLE_MAEMO
   signal_changed().connect(sigc::mem_fun(*this, &ComboGlom::on_changed));
-#endif // GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+  #else
+  m_maemo_selector.signal_changed().connect(sigc::mem_fun(*this, &ComboGlom::on_changed));
+  #endif // GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+  #endif //GLOM_ENABLE_MAEMO
 
   if(m_with_second)
   {
+    #ifndef GLOM_ENABLE_MAEMO
     //We don't use this convenience method, because we want more control over the renderer.
     //and CellLayout gives no way to get the renderer back afterwards.
     //(well, maybe set_cell_data_func(), but that's a bit awkward.)
@@ -78,11 +96,15 @@ void ComboGlom::init()
     pack_start(*cell_second);
 
     //Make the renderer render the column:
-#ifdef GLIBMM_PROPERTIES_ENABLED
+    #ifdef GLIBMM_PROPERTIES_ENABLED
     add_attribute(cell_second->_property_renderable(), m_Columns.m_col_second);
-#else
+    #else
     add_attribute(*cell_second, cell_second->_property_renderable(), m_Columns.m_col_second);
-#endif
+    #endif
+    #else
+    //Maemo:
+    column->pack_start(m_Columns.m_col_second);
+    #endif //GLOM_ENABLE_MAEMO
   }
 
   //if(m_glom_type == Field::TYPE_NUMERIC)
@@ -149,7 +171,11 @@ void ComboGlom::set_text(const Glib::ustring& text)
   g_warning("ComboGlom::set_text(): no item found for: %s", text.c_str());
 
   //Not found, so mark it as blank:
+  #ifndef GLOM_ENABLE_MAEMO
   unset_active();
+  #else
+  m_maemo_selector.unset_active(0);
+  #endif
 }
 
 Gnome::Gda::Value ComboGlom::get_value() const
@@ -164,10 +190,18 @@ Gnome::Gda::Value ComboGlom::get_value() const
 Glib::ustring ComboGlom::get_text() const
 {
   //Get the active row:
-  Gtk::TreeModel::iterator active_row = get_active();
-  if(active_row)
+  #ifndef GLOM_ENABLE_MAEMO
+  Gtk::TreeModel::iterator iter = get_active();
+  #else
+  //TODO: See bug https://bugs.maemo.org/show_bug.cgi?id=4640
+  //about the get_selected()/get_active() confusion.
+  Hildon::TouchSelector& unconst = const_cast<Hildon::TouchSelector&>(m_maemo_selector);
+  Gtk::TreeModel::iterator iter = unconst.get_selected(0);
+  #endif //GLOM_ENABLE_MAEMO
+  
+  if(iter)
   {
-    Gtk::TreeModel::Row row = *active_row;
+    Gtk::TreeModel::Row row = *iter;
     return row[m_Columns.m_col_first];
   }
 
@@ -219,7 +253,12 @@ App_Glom* ComboGlom::get_application()
   return dynamic_cast<App_Glom*>(pWindow);
 }
 
+
+#ifndef GLOM_ENABLE_MAEMO
 void ComboGlom::on_changed()
+#else
+void ComboGlom::on_changed(int /* column */)
+#endif 
 {
 #ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
   //Call base class:
@@ -228,7 +267,14 @@ void ComboGlom::on_changed()
 
   //This signal is emitted for every key press, but sometimes it's just to say that the active item has changed to "no active item",
   //if the text is not in the dropdown list:
+  #ifndef GLOM_ENABLE_MAEMO
   Gtk::TreeModel::iterator iter = get_active();
+  #else
+   //TODO: See bug https://bugs.maemo.org/show_bug.cgi?id=4640
+  //about the get_selected()/get_active() confusion.
+  Gtk::TreeModel::iterator iter = m_maemo_selector.get_selected(0);
+  #endif //GLOM_ENABLE_MAEMO
+  
   if(iter)
   {
     //This is either a choice from the dropdown menu, or someone has typed in something that is in the drop-down menu.
diff --git a/glom/utility_widgets/comboglom.h b/glom/utility_widgets/comboglom.h
index ff5a2b4..6365615 100644
--- a/glom/utility_widgets/comboglom.h
+++ b/glom/utility_widgets/comboglom.h
@@ -26,7 +26,11 @@
 #include <gtkmm.h>
 #include <libglom/data_structure/field.h>
 #include "comboglomchoicesbase.h"
-#include <gtkmm/builder.h>
+
+#ifdef GLOM_ENABLE_MAEMO
+#include <hildonmm/picker-button.h>
+#include <hildonmm/touch-selector-entry.h>
+#endif //GLOM_ENABLE_MAEMO
 
 namespace Glom
 {
@@ -37,7 +41,12 @@ class App_Glom;
  * Use this when the user should only be allowed to enter values that are in the choices.
  */
 class ComboGlom
-: public Gtk::ComboBox,
+: 
+#ifndef GLOM_ENABLE_MAEMO
+  public Gtk::ComboBox,
+#else
+  public Hildon::PickerButton,
+#endif
   public ComboGlomChoicesBase
 {
 public:
@@ -68,9 +77,13 @@ public:
 private:
   void init();
 
-  // Note this is a normal signal handlers when compiled without default
-  // signal handlers
+  #ifndef GLOM_ENABLE_MAEMO
+  // Note that this is a normal signal handler when glibmm was complied
+  // without default signal handlers
   virtual void on_changed(); //From Gtk::ComboBox
+  #else
+  void on_changed(int column);
+  #endif //GLOM_ENABLE_MAEMO
 
   virtual void check_for_change();
 
@@ -83,6 +96,10 @@ private:
 
   Glib::ustring m_old_text;
   //Gnome::Gda::Value m_value; //The last-stored value. We have this because the displayed value might be unparseable.
+  
+  #ifdef GLOM_ENABLE_MAEMO
+  Hildon::TouchSelector m_maemo_selector;
+  #endif
 };
 
 } //namespace Glom



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