[gtkmm-documentation/gtkmm-2-22] Modified the clipboard/ideal example



commit 8f6a3cb4bd1246a2f57cf476cae99c61f76ad80a
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Thu Oct 14 17:04:26 2010 +0200

    Modified the clipboard/ideal example
    
    * docs/tutorial/C/gtkmm-tutorial-in.xml: Signal owner_change is mentioned
    in the description of clipboard/ideal.
    * examples/book/clipboard/ideal/examplewindow.[h|cc]:
    Added on_clipboard_owner_change(). In on_button_copy(), m_ClipboardStore
    is set after the call to refClipboard->set(). Bug #553179.

 docs/tutorial/C/gtkmm-tutorial-in.xml          |    2 +-
 examples/book/clipboard/ideal/examplewindow.cc |   18 +++++++++++++++---
 examples/book/clipboard/ideal/examplewindow.h  |    1 +
 3 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/docs/tutorial/C/gtkmm-tutorial-in.xml b/docs/tutorial/C/gtkmm-tutorial-in.xml
index 1a25ef0..e7cd8c7 100644
--- a/docs/tutorial/C/gtkmm-tutorial-in.xml
+++ b/docs/tutorial/C/gtkmm-tutorial-in.xml
@@ -5315,7 +5315,7 @@ type.
 <orderedlist>
 <listitem><simpara>Defines a custom clipboard target, though the format of that target is still text.</simpara></listitem>
 <listitem><simpara>It supports pasting of 2 targets - both the custom one and a text one that creates an arbitrary text representation of the custom data.</simpara></listitem>
-<listitem><simpara>It uses <methodname>request_targets()</methodname> and disables the Paste button if it can't use anything on the clipboard</simpara></listitem>
+<listitem><simpara>It uses <methodname>request_targets()</methodname> and the signal <literal>owner_change</literal> and disables the Paste button if it can't use anything on the clipboard</simpara></listitem>
 </orderedlist>
 </para>
 
diff --git a/examples/book/clipboard/ideal/examplewindow.cc b/examples/book/clipboard/ideal/examplewindow.cc
index 4037ed8..254942b 100644
--- a/examples/book/clipboard/ideal/examplewindow.cc
+++ b/examples/book/clipboard/ideal/examplewindow.cc
@@ -64,6 +64,11 @@ ExampleWindow::ExampleWindow()
   m_Button_Paste.signal_clicked().connect(sigc::mem_fun(*this,
               &ExampleWindow::on_button_paste) );
 
+  //Connect a signal handler that will be called when the contents of
+  //the clipboard changes.
+  Gtk::Clipboard::get()->signal_owner_change().connect(sigc::mem_fun(*this,
+              &ExampleWindow::on_clipboard_owner_change) );
+
   show_all_children();
 
   update_paste_status();
@@ -83,9 +88,6 @@ void ExampleWindow::on_button_copy()
   strData += m_ButtonB1.get_active() ? "1" : "0";
   strData += m_ButtonB2.get_active() ? "1" : "0";
 
-  //Store the copied data until it is pasted:
-  m_ClipboardStore = strData;
-
   Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
 
   //Targets:
@@ -98,6 +100,11 @@ void ExampleWindow::on_button_copy()
               &ExampleWindow::on_clipboard_get), sigc::mem_fun(*this,
                   &ExampleWindow::on_clipboard_clear) );
 
+  //Store the copied data until it is pasted:
+  //(Must be done after the call to refClipboard->set, because that call
+  //may trigger a call to on_clipboard_clear.)
+  m_ClipboardStore = strData;
+
   update_paste_status();
 }
 
@@ -112,6 +119,11 @@ void ExampleWindow::on_button_paste()
   update_paste_status();
 }
 
+void ExampleWindow::on_clipboard_owner_change(GdkEventOwnerChange*)
+{
+  update_paste_status();
+}
+
 void ExampleWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint)
 {
   //info is meant to indicate the target, but it seems to be always 0,
diff --git a/examples/book/clipboard/ideal/examplewindow.h b/examples/book/clipboard/ideal/examplewindow.h
index ae3cdb6..5fe3dd3 100644
--- a/examples/book/clipboard/ideal/examplewindow.h
+++ b/examples/book/clipboard/ideal/examplewindow.h
@@ -32,6 +32,7 @@ protected:
   void on_button_copy();
   void on_button_paste();
 
+  void on_clipboard_owner_change(GdkEventOwnerChange* event);
   void on_clipboard_get(Gtk::SelectionData& selection_data, guint info);
   void on_clipboard_clear();
 



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