[gtkmm-documentation] Modified the custom_widget example



commit 37f8d7ffb1aeac4dfb54cf517e0f9fe2d418b8ed
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, 18 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6e29b09..3dcac07 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.
+
 2011-01-08  Murray Cumming  <murrayc murrayc com>
 
 	Use RefPtr::reset() instead of deprecated RefPtr::clear().
diff --git a/examples/book/custom/custom_widget/mywidget.cc b/examples/book/custom/custom_widget/mywidget.cc
index 4fd4cd8..b5081dd 100644
--- a/examples/book/custom/custom_widget/mywidget.cc
+++ b/examples/book/custom/custom_widget/mywidget.cc
@@ -29,7 +29,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;
@@ -111,8 +111,11 @@ 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:
   get_style_property("example_scale", m_scale);
@@ -138,12 +141,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
     override_background_color(Gdk::RGBA("red"));
     override_color(Gdk::RGBA("blue"));



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