[gtkmm-documentation/gtkmm-2-22] Modified the custom_widget example



commit 530f23eb615e18d5ba65f52055c21c224ad7e178
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Wed Jan 12 10:29:07 2011 +0100

    Modified the custom_widget example
    
    * examples/book/custom/custom_widget/mywidget.cc:
    Make on_realize() more similar to gtk+ widgets' realize methods.
    Replace the deprecated Glib::RefPtr::clear() by reset(). Bug 606903.

 ChangeLog                                      |    8 ++++++++
 examples/book/custom/custom_widget/mywidget.cc |   16 +++++++++-------
 2 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 46b7141..6d9ce65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-01-12  Kjell Ahlstedt <kjell ahlstedt bredband net>
+
+	Modified the custom_widget example
+    
+	* examples/book/custom/custom_widget/mywidget.cc:
+	Make on_realize() more similar to gtk+ widgets' realize methods.
+	Replace the deprecated Glib::RefPtr::clear() by reset(). Bug 606903.
+
 2010-11-18  Kjell Ahlstedt <kjell ahlstedt bredband net>
 
 	Modified the clipboard/ideal example
diff --git a/examples/book/custom/custom_widget/mywidget.cc b/examples/book/custom/custom_widget/mywidget.cc
index c08dcaa..4b0e628 100644
--- a/examples/book/custom/custom_widget/mywidget.cc
+++ b/examples/book/custom/custom_widget/mywidget.cc
@@ -30,7 +30,7 @@ MyWidget::MyWidget() :
   Gtk::Widget(),
   m_scale(1000)
 {
-  set_has_window(false);
+  set_has_window(true);
 
   //This shows the GType name, which must be used in the RC file.
   std::cout << "GType name: " << G_OBJECT_TYPE_NAME(gobj()) << std::endl;
@@ -99,9 +99,10 @@ void MyWidget::on_unmap()
 
 void MyWidget::on_realize()
 {
-  //Call base class:
-  Gtk::Widget::on_realize();
+  //Do not call base class Gtk::Widget::on_realize().
+  //It's intended only for widgets that set_has_window(false).
 
+  set_realized();
   ensure_style();
 
   //Get the themed style from the RC file:
@@ -128,12 +129,13 @@ void MyWidget::on_realize()
     attributes.window_type = GDK_WINDOW_CHILD;
     attributes.wclass = GDK_INPUT_OUTPUT;
 
-
-    m_refGdkWindow = Gdk::Window::create(get_window() /* parent */, &attributes,
+    m_refGdkWindow = Gdk::Window::create(get_parent_window(), &attributes,
             GDK_WA_X | GDK_WA_Y);
-    set_has_window();
     set_window(m_refGdkWindow);
 
+    //Attach this widget's style to its Gdk::Window.
+    style_attach();
+
     //set colors
     modify_bg(Gtk::STATE_NORMAL , Gdk::Color("red"));
     modify_fg(Gtk::STATE_NORMAL , Gdk::Color("blue"));
@@ -145,7 +147,7 @@ void MyWidget::on_realize()
 
 void MyWidget::on_unrealize()
 {
-  m_refGdkWindow.clear();
+  m_refGdkWindow.reset();
 
   //Call base class:
   Gtk::Widget::on_unrealize();



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