[gtkmm] demos: Replace calls to deprecated API



commit ea7ce0dcff00383d39ffa5091e9daeb4465da66c
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Fri Feb 6 18:43:26 2015 +0100

    demos: Replace calls to deprecated API
    
    * demos/gtk-demo/example_colorsel.cc:
    * demos/gtk-demo/example_flowbox.cc:
    * demos/gtk-demo/example_textview.cc: Don't call
    Widget::override_background_color().
    * demos/gtk-demo/textwidget.cc: Don't call Widget::override_font().

 demos/gtk-demo/example_colorsel.cc |   30 ++++++++++++++----------------
 demos/gtk-demo/example_flowbox.cc  |   14 ++++++++++++--
 demos/gtk-demo/example_textview.cc |   18 ++++++------------
 demos/gtk-demo/textwidget.cc       |   23 ++++++++++-------------
 4 files changed, 42 insertions(+), 43 deletions(-)
---
diff --git a/demos/gtk-demo/example_colorsel.cc b/demos/gtk-demo/example_colorsel.cc
index d12785a..2bf7f7a 100644
--- a/demos/gtk-demo/example_colorsel.cc
+++ b/demos/gtk-demo/example_colorsel.cc
@@ -1,6 +1,6 @@
  /* Color Chooser
  *
- * GtkColorChooserDialog lets the user choose a color.
+ * Gtk::ColorChooserDialog lets the user choose a color.
  *
  */
 
@@ -14,7 +14,8 @@ public:
 
 protected:
   //Signal handlers:
-  virtual void on_button_clicked();
+  void on_button_clicked();
+  bool on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr);
 
   //Member widgets:
   Gtk::Box m_VBox;
@@ -34,31 +35,22 @@ Example_ColorSel::Example_ColorSel()
 : m_VBox(Gtk::ORIENTATION_VERTICAL, 8),
   m_Button("_Change the above color", true)
 {
-  set_title("Color Selection");
+  set_title("Color Chooser");
   set_border_width(8);
 
   m_VBox.set_border_width(8);
   add(m_VBox);
 
-  /*
-   * Create the color swatch area
-   */
-
+  // Create the color swatch area
   m_Frame.set_shadow_type(Gtk::SHADOW_IN);
   m_VBox.pack_start(m_Frame);
 
   // set a fixed size
   m_DrawingArea.set_size_request(200, 200);
 
-  /* TODO: Is this still necessary? It is not in the C version now.
-  // Unset the background pixmap (as used by pixmap themes)
-  // because it takes precedence over the background color.
-  m_DrawingArea.modify_bg_pixmap(Gtk::STATE_NORMAL, "<none>");
-  */
-
   // set the color
   m_Color.set_rgba(0, 0, 1, 1);
-  m_DrawingArea.override_background_color(m_Color);
+  m_DrawingArea.signal_draw().connect(sigc::mem_fun(*this, &Example_ColorSel::on_drawing_area_draw));
 
   m_Frame.add(m_DrawingArea);
 
@@ -87,8 +79,14 @@ void Example_ColorSel::on_button_clicked()
   if(response == Gtk::RESPONSE_OK)
   {
     m_Color = dialog.get_rgba();
-
-    m_DrawingArea.override_background_color(m_Color);
   }
 }
 
+bool Example_ColorSel::on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+{
+  Gdk::Cairo::set_source_rgba(cr, m_Color);
+  cr->paint();
+
+  return true;
+}
+
diff --git a/demos/gtk-demo/example_flowbox.cc b/demos/gtk-demo/example_flowbox.cc
index a033bc3..8b5092f 100644
--- a/demos/gtk-demo/example_flowbox.cc
+++ b/demos/gtk-demo/example_flowbox.cc
@@ -15,6 +15,8 @@ public:
   virtual ~Example_FlowBox();
 
 protected:
+  //Signal handlers:
+  bool on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int swatch_i);
 
   // Containers
   Gtk::ScrolledWindow m_scrolled_window;
@@ -69,18 +71,26 @@ Example_FlowBox::~Example_FlowBox()
 
 Gtk::Button* Example_FlowBox::create_color_swatch(int swatch_i)
 {
-  Gdk::RGBA rgba(m_color_names[swatch_i]);
   Gtk::DrawingArea* drawing_area = Gtk::manage(new Gtk::DrawingArea());
   Gtk::Button* color_swatch = Gtk::manage(new Gtk::Button());
 
   drawing_area->set_size_request(24, 24);
-  drawing_area->override_background_color(rgba);
 
   color_swatch->add(*drawing_area);
+  drawing_area->signal_draw().connect(sigc::bind(sigc::mem_fun(*this, 
&Example_FlowBox::on_drawing_area_draw), swatch_i));
 
   return color_swatch;
 }
 
+bool Example_FlowBox::on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int swatch_i)
+{
+  Gdk::RGBA rgba(m_color_names[swatch_i]);
+  Gdk::Cairo::set_source_rgba(cr, rgba);
+  cr->paint();
+
+  return true;
+}
+
 void Example_FlowBox::fill_color_names()
 {
   m_color_names.push_back("AliceBlue");
diff --git a/demos/gtk-demo/example_textview.cc b/demos/gtk-demo/example_textview.cc
index 3b03c80..4b5bbf8 100644
--- a/demos/gtk-demo/example_textview.cc
+++ b/demos/gtk-demo/example_textview.cc
@@ -1,7 +1,7 @@
 /* Text Widget
  *
- * The GtkTextView widget displays a GtkTextBuffer. One GtkTextBuffer
- * can be displayed by multiple GtkTextViews. This demo has two views
+ * The Gtk::TextView widget displays a Gtk::TextBuffer. One Gtk::TextBuffer
+ * can be displayed by multiple Gtk::TextViews. This demo has two views
  * displaying a single buffer, and shows off the widget's text
  * formatting features.
  *
@@ -464,17 +464,11 @@ void Window_EasterEgg::recursive_attach_view(int depth, Gtk::TextView& view, Gli
 
   Gtk::TextView* pChildView = Gtk::manage( new Gtk::TextView(view.get_buffer()));
 
-  /* Event box is to add a black border around each child view */
-  Gtk::EventBox* pEventBox = Gtk::manage( new Gtk::EventBox());
-  Gdk::RGBA color("black");
-  pEventBox->override_background_color(color);
+  /* Frame is to add a black border around each child view */
+  Gtk::Frame* pFrame = Gtk::manage( new Gtk::Frame());
 
-  pChildView->set_halign(Gtk::ALIGN_CENTER);
-  pChildView->set_valign(Gtk::ALIGN_CENTER);
-  pChildView->set_border_width(1);
+  pFrame->add(*pChildView);
 
-  pEventBox->add(*pChildView);
-
-  view.add_child_at_anchor(*pEventBox, refAnchor);
+  view.add_child_at_anchor(*pFrame, refAnchor);
   recursive_attach_view (depth + 1, *pChildView, refAnchor);
 }
diff --git a/demos/gtk-demo/textwidget.cc b/demos/gtk-demo/textwidget.cc
index 6906db8..44627b3 100644
--- a/demos/gtk-demo/textwidget.cc
+++ b/demos/gtk-demo/textwidget.cc
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /* textwidget.cc
  *
  * Copyright (C) 2001-2002 The gtkmm Development Team
@@ -41,13 +39,12 @@ TextWidget::TextWidget(bool is_source)
 
   if (is_source)
   {
-#ifndef G_OS_WIN32
-    Pango::FontDescription fontDesc("Courier 12");
-    m_TextView.override_font(fontDesc);
-#endif /* G_OS_WIN32 */
     m_TextView.set_wrap_mode (Gtk::WRAP_NONE);
 
-    Glib::RefPtr<Gtk::TextBuffer::Tag> refTag  =  m_refTextBuffer->create_tag("comment");
+    Glib::RefPtr<Gtk::TextBuffer::Tag> refTag = m_refTextBuffer->create_tag("source");
+    refTag->property_font() = "Courier 12";
+
+    refTag = m_refTextBuffer->create_tag("comment");
     refTag->property_foreground() = "red";
 
     refTag = m_refTextBuffer->create_tag("type");
@@ -79,7 +76,6 @@ TextWidget::TextWidget(bool is_source)
 
     Glib::RefPtr<Gtk::TextBuffer::Tag> refTag = m_refTextBuffer->create_tag("title");
     refTag->property_font() = "Sans 18";
-
   }
 }
 
@@ -335,7 +331,12 @@ void TextWidget::fontify()
 {
   enumStates state = STATE_NORMAL;
 
-  Gtk::TextBuffer::iterator iterStart = m_refTextBuffer->get_iter_at_offset(0);
+  Gtk::TextBuffer::iterator iterStart;
+  Gtk::TextBuffer::iterator iterEnd;
+  m_refTextBuffer->get_bounds(iterStart, iterEnd);
+  m_refTextBuffer->apply_tag_by_name("source", iterStart, iterEnd);
+
+  iterStart = m_refTextBuffer->get_iter_at_offset(0);
 
   Gtk::TextBuffer::iterator iterNext = iterStart;
   while(iterNext.forward_line())
@@ -374,7 +375,3 @@ void TextWidget::fontify()
     iterStart = iterNext;
   }
 }
-
-
-
-


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