[gtkmm-documentation] Fix clipboard example programs



commit 9d105a8dc39edebd768311688349e8831e643ddd
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Jun 5 13:29:17 2020 +0200

    Fix clipboard example programs
    
    and some other example programs.
    
    * examples/book/buildapp/step9/exampleappwindow.cc:
    * examples/book/buildapp/step9/window.ui: Show window icon.
    * examples/book/buttons/radiobutton/radiobuttons.cc: Only one pressed
    button when the program starts up.
    * examples/book/clipboard/ideal/examplewindow.[cc|h]:
    * examples/book/clipboard/simple/examplewindow.[cc|h]: Store copied text
    until someone has a chance to paste it.
    * examples/book/treeview/filter_modify/examplewindow.cc: Fix some TODO
    comments.

 examples/book/buildapp/step9/exampleappwindow.cc   |  6 ------
 examples/book/buildapp/step9/window.ui             |  2 +-
 examples/book/buttons/radiobutton/radiobuttons.cc  |  4 +++-
 examples/book/clipboard/ideal/examplewindow.cc     | 23 ++++++++++++----------
 examples/book/clipboard/ideal/examplewindow.h      |  4 +++-
 examples/book/clipboard/simple/examplewindow.cc    | 14 +++++++------
 examples/book/clipboard/simple/examplewindow.h     |  2 ++
 .../book/treeview/filter_modify/examplewindow.cc   | 14 +++----------
 8 files changed, 33 insertions(+), 36 deletions(-)
---
diff --git a/examples/book/buildapp/step9/exampleappwindow.cc 
b/examples/book/buildapp/step9/exampleappwindow.cc
index 23d88d7..61632b8 100644
--- a/examples/book/buildapp/step9/exampleappwindow.cc
+++ b/examples/book/buildapp/step9/exampleappwindow.cc
@@ -106,12 +106,6 @@ ExampleAppWindow::ExampleAppWindow(BaseObjectType* cobject,
   m_binding_lines_visible = Glib::Binding::bind_property(m_lines->property_visible(),
     m_lines_label->property_visible());
 
-  // Display the application menu in the application, not in the desktop environment.
-  auto gtk_settings = Gtk::Settings::get_default();
-  if (gtk_settings)
-    gtk_settings->property_gtk_shell_shows_app_menu() = false;
-  set_show_menubar(true);
-
   // Set the window icon.
   Gtk::IconTheme::get_for_display(get_display())->add_resource_path("/org/gtkmm/exampleapp");
   set_icon_name("exampleapp");
diff --git a/examples/book/buildapp/step9/window.ui b/examples/book/buildapp/step9/window.ui
index 7337c7e..60efd3e 100644
--- a/examples/book/buildapp/step9/window.ui
+++ b/examples/book/buildapp/step9/window.ui
@@ -8,7 +8,7 @@
     <child type="titlebar">
       <object class="GtkHeaderBar" id="header">
         <property name="show-title-buttons">True</property>
-        <property name="decoration-layout">menu:close</property>
+        <property name="decoration-layout">icon:close</property>
         <child>
           <object class="GtkLabel" id="lines_label">
             <property name="visible">False</property>
diff --git a/examples/book/buttons/radiobutton/radiobuttons.cc 
b/examples/book/buttons/radiobutton/radiobuttons.cc
index 0b27750..e5f7d7a 100644
--- a/examples/book/buttons/radiobutton/radiobuttons.cc
+++ b/examples/book/buttons/radiobutton/radiobuttons.cc
@@ -56,7 +56,9 @@ RadioButtons::RadioButtons() :
   m_RadioButton3.set_expand();
 
   // Set the second button active
-  m_RadioButton2.set_active();
+  m_RadioButton1.set_active(false);
+  m_RadioButton2.set_active(true);
+  m_RadioButton3.set_active(false);
 
   // Put Close button in Box2:
   m_Box2.append(m_Button_Close);
diff --git a/examples/book/clipboard/ideal/examplewindow.cc b/examples/book/clipboard/ideal/examplewindow.cc
index 762d066..65726de 100644
--- a/examples/book/clipboard/ideal/examplewindow.cc
+++ b/examples/book/clipboard/ideal/examplewindow.cc
@@ -67,7 +67,7 @@ ExampleWindow::ExampleWindow()
 
   //Connect a signal handler that will be called when the contents of
   //the clipboard change.
-  get_clipboard()->property_content().signal_changed().connect(sigc::mem_fun(*this,
+  get_clipboard()->signal_changed().connect(sigc::mem_fun(*this,
               &ExampleWindow::on_clipboard_content_changed));
 
   update_paste_status();
@@ -81,13 +81,16 @@ void ExampleWindow::on_button_copy()
 {
   //Build a string representation of the stuff to be copied:
   //Ideally you would use XML, with an XML parser here:
-  Glib::ustring strData(example_format_custom);
-  strData += m_ButtonA1.get_active() ? " A1" : "";
-  strData += m_ButtonA2.get_active() ? " A2" : "";
-  strData += m_ButtonB1.get_active() ? " B1" : "";
-  strData += m_ButtonB2.get_active() ? " B2" : "";
-
-  get_clipboard()->set_text(strData);
+  m_strData = example_format_custom;
+  m_strData += m_ButtonA1.get_active() ? " A1" : "";
+  m_strData += m_ButtonA2.get_active() ? " A2" : "";
+  m_strData += m_ButtonB1.get_active() ? " B1" : "";
+  m_strData += m_ButtonB2.get_active() ? " B2" : "";
+
+  // Gdk::Clipboard::set_text() does not take a copy of the text.
+  // The text can only be pasted (in this program or in some other program)
+  // for as long as it exists.
+  get_clipboard()->set_text(m_strData);
 }
 
 void ExampleWindow::on_button_paste()
@@ -137,10 +140,10 @@ void ExampleWindow::update_paste_status()
 {
   // Disable the paste button if there is nothing to paste.
   get_clipboard()->read_text_async(sigc::mem_fun(*this,
-              &ExampleWindow::on_clipboard_received_targets));
+              &ExampleWindow::on_clipboard_received_status));
 }
 
-void ExampleWindow::on_clipboard_received_targets(Glib::RefPtr<Gio::AsyncResult>& result)
+void ExampleWindow::on_clipboard_received_status(Glib::RefPtr<Gio::AsyncResult>& result)
 {
   Glib::ustring text;
   try
diff --git a/examples/book/clipboard/ideal/examplewindow.h b/examples/book/clipboard/ideal/examplewindow.h
index 5c2b90d..534e918 100644
--- a/examples/book/clipboard/ideal/examplewindow.h
+++ b/examples/book/clipboard/ideal/examplewindow.h
@@ -33,10 +33,12 @@ protected:
   void on_clipboard_content_changed();
 
   void on_clipboard_received(Glib::RefPtr<Gio::AsyncResult>& result);
-  void on_clipboard_received_targets(Glib::RefPtr<Gio::AsyncResult>& result);
+  void on_clipboard_received_status(Glib::RefPtr<Gio::AsyncResult>& result);
 
   void update_paste_status(); //Disable the paste button if there is nothing to paste.
 
+  Glib::ustring m_strData;
+
   //Child widgets:
   Gtk::Box m_VBox;
 
diff --git a/examples/book/clipboard/simple/examplewindow.cc b/examples/book/clipboard/simple/examplewindow.cc
index 40ac684..08e4357 100644
--- a/examples/book/clipboard/simple/examplewindow.cc
+++ b/examples/book/clipboard/simple/examplewindow.cc
@@ -64,13 +64,15 @@ void ExampleWindow::on_button_copy()
 {
   //Build a string representation of the stuff to be copied:
   //Ideally you would use XML, with an XML parser here:
-  Glib::ustring strData;
-  strData += m_ButtonA1.get_active() ? "1" : "0";
-  strData += m_ButtonA2.get_active() ? "1" : "0";
-  strData += m_ButtonB1.get_active() ? "1" : "0";
-  strData += m_ButtonB2.get_active() ? "1" : "0";
+  m_strData = m_ButtonA1.get_active() ? "1" : "0";
+  m_strData += m_ButtonA2.get_active() ? "1" : "0";
+  m_strData += m_ButtonB1.get_active() ? "1" : "0";
+  m_strData += m_ButtonB2.get_active() ? "1" : "0";
 
-  get_clipboard()->set_text(strData);
+  // Gdk::Clipboard::set_text() does not take a copy of the text.
+  // The text can only be pasted (in this program or in some other program)
+  // for as long as it exists.
+  get_clipboard()->set_text(m_strData);
 }
 
 void ExampleWindow::on_button_paste()
diff --git a/examples/book/clipboard/simple/examplewindow.h b/examples/book/clipboard/simple/examplewindow.h
index b0584c5..2f6b3a3 100644
--- a/examples/book/clipboard/simple/examplewindow.h
+++ b/examples/book/clipboard/simple/examplewindow.h
@@ -32,6 +32,8 @@ protected:
 
   void on_clipboard_text_received(Glib::RefPtr<Gio::AsyncResult>& result);
 
+  Glib::ustring m_strData;
+
   //Child widgets:
   Gtk::Box m_VBox;
 
diff --git a/examples/book/treeview/filter_modify/examplewindow.cc 
b/examples/book/treeview/filter_modify/examplewindow.cc
index fae5083..bc5e28a 100644
--- a/examples/book/treeview/filter_modify/examplewindow.cc
+++ b/examples/book/treeview/filter_modify/examplewindow.cc
@@ -47,10 +47,7 @@ ExampleWindow::ExampleWindow()
   //Create the Tree model:
   m_refTreeModel = Gtk::ListStore::create(m_Columns);
 
-  m_refTreeModelFilter = Gtk::TreeModelFilter::create( m_refTreeModel,
-          Gtk::TreeModel::Path() );
-  //TODO: Do not specify the empty Path, when we have added a suitable
-  //constructor to gtkmm.
+  m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
   m_refTreeModelFilter->set_modify_func( m_ColumnsDisplay, sigc::mem_fun(*this,
               &ExampleWindow::on_filter_modify) );
 
@@ -113,9 +110,7 @@ void ExampleWindow::on_filter_modify(const Gtk::TreeModel::iterator& iter,
       Glib::ustring name = row_child[m_Columns.m_col_name];
 
       Glib::Value<Glib::ustring> valString;
-      //TODO: Is there any way to avoid this step? Can't it copy the type as
-      //well as the value?
-      valString.init( Glib::Value< Glib::ustring >::value_type() );
+      valString.init(valString.value_type());
 
       valString.set(name);
       value = valString;
@@ -126,9 +121,7 @@ void ExampleWindow::on_filter_modify(const Gtk::TreeModel::iterator& iter,
       bool something = row_child[m_Columns.m_col_something];
 
       Glib::Value<Glib::ustring> valString;
-      //TODO: Is there any way to avoid this step? Can't it copy the type as
-      //well as the value?
-      valString.init( Glib::Value< Glib::ustring >::value_type());
+      valString.init(valString.value_type());
 
       valString.set( (something ? "something" : "notsomething"));
       value = valString;
@@ -145,4 +138,3 @@ void ExampleWindow::on_button_quit()
 {
   hide();
 }
-


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