[gtkmm-documentation] Dialogs chapter and examples: Finish replacement of FontSelectionDialog.



commit 062755c4f8c912a4084867dbf9788497baac483a
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Mon Sep 19 14:07:15 2011 +0200

    Dialogs chapter and examples: Finish replacement of FontSelectionDialog.
    
    * examples/book/dialogs/colorselectiondialog/examplewindow.[h|cc]:
    Add a plain Button that opens a ColorSelectionDialog.
    * examples/book/dialogs/fontchooserdialog/examplewindow.[h|cc]:
    Add a plain Button that opens a FontChooserDialog.
    * docs/tutorial/C/gtkmm-tutorial-in.xml: Replace get_vbox() by
    get_content_area(). Replace all references to FontSelectionDialog by
    FontChooserDialog. Bug #658265.

 ChangeLog                                          |   12 ++++
 docs/tutorial/C/gtkmm-tutorial-in.xml              |   17 +++---
 .../dialogs/colorselectiondialog/examplewindow.cc  |   63 ++++++++++++++++----
 .../dialogs/colorselectiondialog/examplewindow.h   |    6 +-
 .../dialogs/fontchooserdialog/examplewindow.cc     |   55 +++++++++++++++---
 .../book/dialogs/fontchooserdialog/examplewindow.h |    7 ++-
 6 files changed, 128 insertions(+), 32 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8e5ef22..3a34fe2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2011-09-19  Kjell Ahlstedt <kjell ahlstedt bredband net>
+
+	Dialogs chapter and examples: Finish replacement of FontSelectionDialog.
+
+	* examples/book/dialogs/colorselectiondialog/examplewindow.[h|cc]:
+	Add a plain Button that opens a ColorSelectionDialog.
+	* examples/book/dialogs/fontchooserdialog/examplewindow.[h|cc]:
+	Add a plain Button that opens a FontChooserDialog.
+	* docs/tutorial/C/gtkmm-tutorial-in.xml: Replace get_vbox() by
+	get_content_area(). Replace all references to FontSelectionDialog by
+	FontChooserDialog. Bug #658265.
+
 2011-09-11  Kjell Ahlstedt <kjell ahlstedt bredband net>
 
 	TreeView Popup example: Make sure the menu items are shown.
diff --git a/docs/tutorial/C/gtkmm-tutorial-in.xml b/docs/tutorial/C/gtkmm-tutorial-in.xml
index 04b0168..c4def76 100644
--- a/docs/tutorial/C/gtkmm-tutorial-in.xml
+++ b/docs/tutorial/C/gtkmm-tutorial-in.xml
@@ -4001,10 +4001,9 @@ class to provide more complex functionality.
 </para>
 
 <para>
-<!-- TODO: Mention get_content_area() instead of get_vbox() for gtkmm 3.2 -->
 To pack widgets into a custom dialog, you should pack them into the
 <classname>Gtk::Box</classname>, available via
-<methodname>get_vbox()</methodname>. To just add a <classname>Button</classname>
+<methodname>get_content_area()</methodname>. To just add a <classname>Button</classname>
 to the bottom of the <classname>Dialog</classname>, you could use the
 <methodname>add_button()</methodname> method.
 </para>
@@ -4073,7 +4072,8 @@ Most of the useful member methods for this class are actually in the
 <sect1 id="sec-color-selection-dialog"><title>ColorSelectionDialog</title>
 <para>
 The <classname>ColorSelectionDialog</classname> allows the user to choose a
-color.
+color. The <classname>ColorButton</classname> opens a color selection dialog
+when it is clicked.
 </para>
 
 <para><ulink url="&url_refdocs_base_gtk;ColorSelectionDialog.html">Reference</ulink></para>
@@ -4093,19 +4093,20 @@ color.
 
 </sect1>
 
-<sect1 id="sec-font-selection-dialog"><title>FontSelectionDialog</title>
+<sect1 id="sec-font-chooser-dialog"><title>FontChooserDialog</title>
 <para>
-The <classname>FontSelectionDialog</classname> allows the user to choose a
-font.
+The <classname>FontChooserDialog</classname> allows the user to choose a
+font. The <classname>FontButton</classname> opens a font chooser dialog
+when it is clicked.
 </para>
 
-<para><ulink url="&url_refdocs_base_gtk;FontSelectionDialog.html">Reference</ulink></para>
+<para><ulink url="&url_refdocs_base_gtk;FontChooserDialog.html">Reference</ulink></para>
 
 <sect2 id="fontchooserdialog-example">
 <title>Example</title>
 
 <figure id="figure-dialogs-fontchooserdialog">
-  <title>FontSelectionDialog</title>
+  <title>FontChooserDialog</title>
   <screenshot>
     <graphic format="PNG" fileref="&url_figures_base;dialogs_fontchooserdialog.png"/>
   </screenshot>
diff --git a/examples/book/dialogs/colorselectiondialog/examplewindow.cc b/examples/book/dialogs/colorselectiondialog/examplewindow.cc
index ab632e6..3b851b7 100644
--- a/examples/book/dialogs/colorselectiondialog/examplewindow.cc
+++ b/examples/book/dialogs/colorselectiondialog/examplewindow.cc
@@ -19,24 +19,29 @@
 #include "examplewindow.h"
 #include <iostream>
 
-
 ExampleWindow::ExampleWindow()
-: m_VBox(Gtk::ORIENTATION_VERTICAL)
+: m_VBox(Gtk::ORIENTATION_VERTICAL, 5),
+  m_Button_Dialog("Choose Color")
 {
-  set_title("Gtk::ColorButton example");
+  set_title("Gtk::ColorSelectionDialog example");
   set_default_size(200, 200);
 
   add(m_VBox);
 
-  m_VBox.pack_start(m_Button, Gtk::PACK_SHRINK);
-  m_Button.signal_color_set().connect(sigc::mem_fun(*this,
-              &ExampleWindow::on_button_color_set) );
+  m_VBox.pack_start(m_ColorButton, Gtk::PACK_SHRINK);
+  m_ColorButton.signal_color_set().connect(sigc::mem_fun(*this,
+    &ExampleWindow::on_color_button_color_set) );
+
+  m_VBox.pack_start(m_Button_Dialog, Gtk::PACK_SHRINK);
+  m_Button_Dialog.signal_clicked().connect(sigc::mem_fun(*this,
+    &ExampleWindow::on_button_dialog_clicked) );
 
   //Set start color:
-  m_Color.set_red(0);
-  m_Color.set_blue(1);
-  m_Color.set_green(0);
-  m_Button.set_rgba(m_Color);
+  m_Color.set_red(0.0);
+  m_Color.set_green(0.0);
+  m_Color.set_blue(1.0);
+  m_Color.set_alpha(1.0); //opaque
+  m_ColorButton.set_rgba(m_Color);
 
   m_DrawingArea.override_background_color(m_Color);
 
@@ -49,9 +54,43 @@ ExampleWindow::~ExampleWindow()
 {
 }
 
-void ExampleWindow::on_button_color_set()
+void ExampleWindow::on_color_button_color_set()
 {
   //Store the chosen color, and show it:
-  m_Color = m_Button.get_rgba();
+  m_Color = m_ColorButton.get_rgba();
   m_DrawingArea.override_background_color(m_Color);
 }
+
+void ExampleWindow::on_button_dialog_clicked()
+{
+  Gtk::ColorSelectionDialog dialog("Please choose a color");
+  dialog.set_transient_for(*this);
+
+  //Get the previously selected color:
+  dialog.get_color_selection()->set_current_rgba(m_Color);
+
+  int result = dialog.run();
+
+  //Handle the response:
+  switch(result)
+  {
+    case Gtk::RESPONSE_OK:
+    {
+      //Store the chosen color, and show it:
+      m_Color = dialog.get_color_selection()->get_current_rgba();
+      m_ColorButton.set_rgba(m_Color);
+      m_DrawingArea.override_background_color(m_Color);
+      break;
+    }
+    case Gtk::RESPONSE_CANCEL:
+    {
+      std::cout << "Cancel clicked." << std::endl;
+      break;
+    }
+    default:
+    {
+      std::cout << "Unexpected button clicked: " << result << std::endl;
+      break;
+    }
+  }
+}
diff --git a/examples/book/dialogs/colorselectiondialog/examplewindow.h b/examples/book/dialogs/colorselectiondialog/examplewindow.h
index 1dff35d..364acb7 100644
--- a/examples/book/dialogs/colorselectiondialog/examplewindow.h
+++ b/examples/book/dialogs/colorselectiondialog/examplewindow.h
@@ -29,11 +29,13 @@ public:
 
 protected:
   //Signal handlers:
-  void on_button_color_set();
+  void on_color_button_color_set();
+  void on_button_dialog_clicked();
 
   //Child widgets:
   Gtk::Box m_VBox;
-  Gtk::ColorButton m_Button;
+  Gtk::ColorButton m_ColorButton;
+  Gtk::Button m_Button_Dialog;
   Gtk::DrawingArea m_DrawingArea; //To show the color.
 
   Gdk::RGBA m_Color;
diff --git a/examples/book/dialogs/fontchooserdialog/examplewindow.cc b/examples/book/dialogs/fontchooserdialog/examplewindow.cc
index 224e276..3acd136 100644
--- a/examples/book/dialogs/fontchooserdialog/examplewindow.cc
+++ b/examples/book/dialogs/fontchooserdialog/examplewindow.cc
@@ -19,17 +19,24 @@
 #include "examplewindow.h"
 #include <iostream>
 
-
-//TODO: This is not actually a FontChooserDialog example.
 ExampleWindow::ExampleWindow()
-: m_Button("sans")
+: m_ButtonBox(Gtk::ORIENTATION_VERTICAL),
+  m_FontButton("Sans 10"),
+  m_Button_Dialog("Choose Font")
 {
   set_title("Gtk::FontChooserDialog example");
 
-  add(m_Button);
-  m_Button.signal_font_set().connect(sigc::mem_fun(*this,
-              &ExampleWindow::on_button_font_set) );
+  add(m_ButtonBox);
+
+  m_ButtonBox.pack_start(m_FontButton);
+  m_FontButton.set_use_font(true);
+  m_FontButton.set_use_size(true);
+  m_FontButton.signal_font_set().connect(sigc::mem_fun(*this,
+    &ExampleWindow::on_font_button_font_set) );
 
+  m_ButtonBox.pack_start(m_Button_Dialog);
+  m_Button_Dialog.signal_clicked().connect(sigc::mem_fun(*this,
+    &ExampleWindow::on_button_dialog_clicked) );
   show_all_children();
 }
 
@@ -37,8 +44,40 @@ ExampleWindow::~ExampleWindow()
 {
 }
 
-void ExampleWindow::on_button_font_set()
+void ExampleWindow::on_font_button_font_set()
 {
-  Glib::ustring font_name = m_Button.get_font_name();
+  Glib::ustring font_name = m_FontButton.get_font_name();
   std::cout << "Font chosen: " << font_name << std::endl;
 }
+
+void ExampleWindow::on_button_dialog_clicked()
+{
+  Gtk::FontChooserDialog dialog("Please choose a font", *this);
+
+  //Get the previously selected font name from the FontButton:
+  dialog.set_font(m_FontButton.get_font_name());
+
+  int result = dialog.run();
+
+  //Handle the response:
+  switch(result)
+  {
+    case Gtk::RESPONSE_OK:
+    {
+      Glib::ustring font_name = dialog.get_font();
+      std::cout << "Font chosen: " << font_name << std::endl;
+      m_FontButton.set_font_name(font_name);
+      break;
+    }
+    case Gtk::RESPONSE_CANCEL:
+    {
+      std::cout << "Cancel clicked." << std::endl;
+      break;
+    }
+    default:
+    {
+      std::cout << "Unexpected button clicked: " << result << std::endl;
+      break;
+    }
+  }
+}
diff --git a/examples/book/dialogs/fontchooserdialog/examplewindow.h b/examples/book/dialogs/fontchooserdialog/examplewindow.h
index cb4569b..a3de2cd 100644
--- a/examples/book/dialogs/fontchooserdialog/examplewindow.h
+++ b/examples/book/dialogs/fontchooserdialog/examplewindow.h
@@ -29,10 +29,13 @@ public:
 
 protected:
   //Signal handlers:
-  void on_button_font_set();
+  void on_font_button_font_set();
+  void on_button_dialog_clicked();
 
   //Child widgets:
-  Gtk::FontButton m_Button;
+  Gtk::ButtonBox m_ButtonBox;
+  Gtk::FontButton m_FontButton;
+  Gtk::Button m_Button_Dialog;
 };
 
 #endif //GTKMM_EXAMPLEWINDOW_H



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