[gtkmm-documentation] Range Widgets example: Really show a Position combo.



commit c9d519bacaeb99897707b44868c14e99acf8dd3b
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Apr 17 10:06:47 2012 +0200

    Range Widgets example: Really show a Position combo.
    
    * examples/book/range_widgets/examplewindow.[h|cc]:
    Convert the menu (which was once put in a deprecated OptionMenu)
    to a ComboBox and actually show it and handle it.

 ChangeLog                                    |    8 +++
 examples/book/range_widgets/examplewindow.cc |   64 ++++++++++++++++----------
 examples/book/range_widgets/examplewindow.h  |   22 ++++++++-
 3 files changed, 66 insertions(+), 28 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f2c0729..d3f6778 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-04-17  Murray Cumming  <murrayc murrayc com>
+
+	Range Widgets example: Really show a Position combo.
+
+	* examples/book/range_widgets/examplewindow.[h|cc]:
+	Convert the menu (which was once put in a deprecated OptionMenu)
+	to a ComboBox and actually show it and handle it.
+
 3.4.0:
 
 2012-04-02  Kjell Ahlstedt <kjell ahlstedt bredband net>
diff --git a/examples/book/range_widgets/examplewindow.cc b/examples/book/range_widgets/examplewindow.cc
index 651da1a..a99d64a 100644
--- a/examples/book/range_widgets/examplewindow.cc
+++ b/examples/book/range_widgets/examplewindow.cc
@@ -25,6 +25,7 @@ ExampleWindow::ExampleWindow()
   m_VBox2(Gtk::ORIENTATION_VERTICAL, 20),
   m_VBox_HScale(Gtk::ORIENTATION_VERTICAL, 10),
   m_HBox_Scales(Gtk::ORIENTATION_HORIZONTAL, 10),
+  m_HBox_Combo(Gtk::ORIENTATION_HORIZONTAL, 10),
   m_HBox_Digits(Gtk::ORIENTATION_HORIZONTAL, 10),
   m_HBox_PageSize(Gtk::ORIENTATION_HORIZONTAL, 10),
 
@@ -85,30 +86,33 @@ ExampleWindow::ExampleWindow()
     &ExampleWindow::on_checkbutton_toggled) );
   m_VBox2.pack_start(m_CheckButton, Gtk::PACK_SHRINK);
 
-  //Menus:
-  Gtk::MenuItem* item = Gtk::manage(new Gtk::MenuItem("Top"));
-  item->signal_activate().connect(
-    sigc::bind(sigc::mem_fun(*this,
-      &ExampleWindow::on_menu_position), Gtk::POS_TOP));
-  m_Menu_Position.append(*item);
-
-  item = Gtk::manage(new Gtk::MenuItem("Bottom"));
-  item->signal_activate().connect(
-    sigc::bind(sigc::mem_fun(*this,
-      &ExampleWindow::on_menu_position), Gtk::POS_BOTTOM));
-  m_Menu_Position.append(*item);
-
-  item = Gtk::manage(new Gtk::MenuItem("Left"));
-  item->signal_activate().connect(
-    sigc::bind(sigc::mem_fun(*this,
-      &ExampleWindow::on_menu_position), Gtk::POS_LEFT));
-  m_Menu_Position.append(*item);
-
-  item = Gtk::manage(new Gtk::MenuItem("Right"));
-  item->signal_activate().connect(
-    sigc::bind(sigc::mem_fun(*this,
-      &ExampleWindow::on_menu_position), Gtk::POS_RIGHT));
-  m_Menu_Position.append(*item);
+  //Position ComboBox:
+  //Create the Tree model:
+  m_refTreeModel = Gtk::ListStore::create(m_Columns);
+  m_ComboBox_Position.set_model(m_refTreeModel);
+  m_ComboBox_Position.pack_start(m_Columns.m_col_title);
+
+  //Fill the ComboBox's Tree Model:
+  Gtk::TreeModel::Row row = *(m_refTreeModel->append());
+  row[m_Columns.m_col_position_type] = Gtk::POS_TOP;
+  row[m_Columns.m_col_title] = "Top";
+  row = *(m_refTreeModel->append());
+  row[m_Columns.m_col_position_type] = Gtk::POS_BOTTOM;
+  row[m_Columns.m_col_title] = "Bottom";
+  row = *(m_refTreeModel->append());
+  row[m_Columns.m_col_position_type] = Gtk::POS_LEFT;
+  row[m_Columns.m_col_title] = "Left";
+  row = *(m_refTreeModel->append());
+  row[m_Columns.m_col_position_type] = Gtk::POS_RIGHT;
+  row[m_Columns.m_col_title] = "Right";
+
+
+  m_VBox2.pack_start(m_HBox_Combo, Gtk::PACK_SHRINK);
+  m_HBox_Combo.pack_start(
+    *Gtk::manage(new Gtk::Label("Scale Value Position:", 0)), Gtk::PACK_SHRINK);
+  m_HBox_Combo.pack_start(m_ComboBox_Position);
+  m_ComboBox_Position.signal_changed().connect( sigc::mem_fun(*this, &ExampleWindow::on_menu_position) );
+
 
   //Digits:
   m_HBox_Digits.pack_start(
@@ -151,8 +155,18 @@ void ExampleWindow::on_checkbutton_toggled()
   m_HScale.set_draw_value(m_CheckButton.get_active());
 }
 
-void ExampleWindow::on_menu_position(Gtk::PositionType postype)
+void ExampleWindow::on_menu_position()
 {
+  Gtk::TreeModel::iterator iter = m_ComboBox_Position.get_active();
+  if(!iter)
+    return;
+
+  Gtk::TreeModel::Row row = *iter;
+  if(!row)
+    return;
+
+  const Gtk::PositionType postype = row[m_Columns.m_col_position_type];
+
   m_VScale.set_value_pos(postype);
   m_HScale.set_value_pos(postype);
 }
diff --git a/examples/book/range_widgets/examplewindow.h b/examples/book/range_widgets/examplewindow.h
index 55b254b..35df846 100644
--- a/examples/book/range_widgets/examplewindow.h
+++ b/examples/book/range_widgets/examplewindow.h
@@ -30,14 +30,14 @@ public:
 protected:
   //Signal handlers:
   void on_checkbutton_toggled();
-  void on_menu_position(Gtk::PositionType type);
+  void on_menu_position();
   void on_adjustment1_value_changed();
   void on_adjustment2_value_changed();
   void on_button_quit();
 
   //Child widgets:
   Gtk::Box m_VBox_Top, m_VBox2, m_VBox_HScale;
-  Gtk::Box m_HBox_Scales, m_HBox_Digits, m_HBox_PageSize;
+  Gtk::Box m_HBox_Scales, m_HBox_Combo, m_HBox_Digits, m_HBox_PageSize;
 
   Glib::RefPtr<Gtk::Adjustment> m_adjustment, m_adjustment_digits, m_adjustment_pagesize;
 
@@ -50,7 +50,23 @@ protected:
 
   Gtk::Scrollbar m_Scrollbar;
 
-  Gtk::Menu m_Menu_Position;
+  //Tree model columns:
+  class ModelColumns : public Gtk::TreeModel::ColumnRecord
+  {
+  public:
+
+    ModelColumns()
+    { add(m_col_position_type); add(m_col_title); }
+
+    Gtk::TreeModelColumn<Gtk::PositionType> m_col_position_type;
+    Gtk::TreeModelColumn<Glib::ustring> m_col_title;
+  };
+
+  ModelColumns m_Columns;
+
+  //Child widgets:
+  Gtk::ComboBox m_ComboBox_Position;
+  Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
 
   Gtk::Button m_Button_Quit;
 };



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