[gtkmm-documentation] Fix 'make check' after Widget::override_*() have been deprecated
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Fix 'make check' after Widget::override_*() have been deprecated
- Date: Fri, 6 Feb 2015 18:24:37 +0000 (UTC)
commit b295eb16e95fe9d40aa356bef84a9606743b0af9
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Fri Feb 6 19:21:31 2015 +0100
Fix 'make check' after Widget::override_*() have been deprecated
* examples/book/custom/custom_widget/custom_gtk.css: Add color and
background_color.
* examples/book/custom/custom_widget/mywidget.cc: Don't call
Widget::override_color() and override_background_color().
* examples/book/dialogs/colorchooserdialog/examplewindow.[cc|h]:
* examples/book/flowbox/examplewindow.[cc|h]: Don't call
Widget::override_background_color(). Add on_drawing_area_draw().
* examples/others/calendar/calendar.cc: Don't call Widget::override_font().
Add a CssProvider for setting the font.
examples/book/custom/custom_widget/custom_gtk.css | 5 ++
examples/book/custom/custom_widget/mywidget.cc | 14 ++---
.../dialogs/colorchooserdialog/examplewindow.cc | 20 +++++---
.../dialogs/colorchooserdialog/examplewindow.h | 3 +-
examples/book/flowbox/examplewindow.cc | 13 ++++-
examples/book/flowbox/examplewindow.h | 2 +
examples/others/calendar/calendar.cc | 51 ++++++++++++++++---
7 files changed, 80 insertions(+), 28 deletions(-)
---
diff --git a/examples/book/custom/custom_widget/custom_gtk.css
b/examples/book/custom/custom_widget/custom_gtk.css
index 2354d0b..8b8d349 100644
--- a/examples/book/custom/custom_widget/custom_gtk.css
+++ b/examples/book/custom/custom_widget/custom_gtk.css
@@ -9,3 +9,8 @@
-gtkmm__CustomObject_mywidget-example-scale: 920;
}
+gtkmm__CustomObject_mywidget {
+ background-color: rgb(255,0,0);
+ color: rgb(0,0,255);
+}
+
diff --git a/examples/book/custom/custom_widget/mywidget.cc b/examples/book/custom/custom_widget/mywidget.cc
index 01c78d5..51b76cd 100644
--- a/examples/book/custom/custom_widget/mywidget.cc
+++ b/examples/book/custom/custom_widget/mywidget.cc
@@ -167,10 +167,6 @@ void MyWidget::on_realize()
GDK_WA_X | GDK_WA_Y);
set_window(m_refGdkWindow);
- //set colors
- override_background_color(Gdk::RGBA("red"));
- override_color(Gdk::RGBA("blue"));
-
//make the widget receive expose events
m_refGdkWindow->set_user_data(gobj());
}
@@ -186,12 +182,14 @@ void MyWidget::on_unrealize()
bool MyWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
- const double scale_x = (double)get_allocation().get_width() / m_scale;
- const double scale_y = (double)get_allocation().get_height() / m_scale;
+ const Gtk::Allocation allocation = get_allocation();
+ const double scale_x = (double)allocation.get_width() / m_scale;
+ const double scale_y = (double)allocation.get_height() / m_scale;
// paint the background
- Gdk::Cairo::set_source_rgba(cr, get_style_context()->get_background_color());
- cr->paint();
+ get_style_context()->render_background(cr,
+ allocation.get_x(), allocation.get_y(),
+ allocation.get_width(), allocation.get_height());
// draw the foreground
Gdk::Cairo::set_source_rgba(cr, get_style_context()->get_color());
diff --git a/examples/book/dialogs/colorchooserdialog/examplewindow.cc
b/examples/book/dialogs/colorchooserdialog/examplewindow.cc
index 9dd68ae..bdf0f23 100644
--- a/examples/book/dialogs/colorchooserdialog/examplewindow.cc
+++ b/examples/book/dialogs/colorchooserdialog/examplewindow.cc
@@ -1,5 +1,3 @@
-//$Id: examplewindow.cc 836 2007-05-09 03:02:38Z jjongsma $ -*- c++ -*-
-
/* gtkmm example Copyright (C) 2002 gtkmm development team
*
* This program is free software; you can redistribute it and/or modify
@@ -43,9 +41,9 @@ ExampleWindow::ExampleWindow()
m_Color.set_alpha(1.0); //opaque
m_ColorButton.set_rgba(m_Color);
- m_DrawingArea.override_background_color(m_Color);
-
m_VBox.pack_start(m_DrawingArea);
+ m_DrawingArea.signal_draw().connect(sigc::mem_fun(*this,
+ &ExampleWindow::on_drawing_area_draw));
show_all_children();
}
@@ -56,9 +54,8 @@ ExampleWindow::~ExampleWindow()
void ExampleWindow::on_color_button_color_set()
{
- //Store the chosen color, and show it:
+ //Store the chosen color:
m_Color = m_ColorButton.get_rgba();
- m_DrawingArea.override_background_color(m_Color);
}
void ExampleWindow::on_button_dialog_clicked()
@@ -76,10 +73,9 @@ void ExampleWindow::on_button_dialog_clicked()
{
case Gtk::RESPONSE_OK:
{
- //Store the chosen color, and show it:
+ //Store the chosen color:
m_Color = dialog.get_rgba();
m_ColorButton.set_rgba(m_Color);
- m_DrawingArea.override_background_color(m_Color);
break;
}
case Gtk::RESPONSE_CANCEL:
@@ -94,3 +90,11 @@ void ExampleWindow::on_button_dialog_clicked()
}
}
}
+
+bool ExampleWindow::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/examples/book/dialogs/colorchooserdialog/examplewindow.h
b/examples/book/dialogs/colorchooserdialog/examplewindow.h
index 364acb7..d1d848b 100644
--- a/examples/book/dialogs/colorchooserdialog/examplewindow.h
+++ b/examples/book/dialogs/colorchooserdialog/examplewindow.h
@@ -1,5 +1,3 @@
-//$Id: examplewindow.h 705 2006-07-19 02:55:32Z jjongsma $ -*- c++ -*-
-
/* gtkmm example Copyright (C) 2002 gtkmm development team
*
* This program is free software; you can redistribute it and/or modify
@@ -31,6 +29,7 @@ protected:
//Signal handlers:
void on_color_button_color_set();
void on_button_dialog_clicked();
+ bool on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr);
//Child widgets:
Gtk::Box m_VBox;
diff --git a/examples/book/flowbox/examplewindow.cc b/examples/book/flowbox/examplewindow.cc
index 3269a7d..7ec0932 100644
--- a/examples/book/flowbox/examplewindow.cc
+++ b/examples/book/flowbox/examplewindow.cc
@@ -52,18 +52,27 @@ ExampleWindow::~ExampleWindow()
Gtk::Button* ExampleWindow::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,
+ &ExampleWindow::on_drawing_area_draw), swatch_i));
return color_swatch;
}
+bool ExampleWindow::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 ExampleWindow::fill_color_names()
{
m_color_names.push_back("AliceBlue");
diff --git a/examples/book/flowbox/examplewindow.h b/examples/book/flowbox/examplewindow.h
index 1d335d8..14a1008 100644
--- a/examples/book/flowbox/examplewindow.h
+++ b/examples/book/flowbox/examplewindow.h
@@ -28,6 +28,8 @@ public:
virtual ~ExampleWindow();
protected:
+ //Signal handlers:
+ bool on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int swatch_i);
// Containers
Gtk::ScrolledWindow m_scrolled_window;
diff --git a/examples/others/calendar/calendar.cc b/examples/others/calendar/calendar.cc
index cde92a5..f49708a 100644
--- a/examples/others/calendar/calendar.cc
+++ b/examples/others/calendar/calendar.cc
@@ -1,5 +1,3 @@
-//$Id: calendar.cc 829 2007-05-01 17:04:39Z murrayc $ -*- c++ -*-
-
/* gtkmm example Copyright (C) 2002 gtkmm development team
*
* This program is free software; you can redistribute it and/or modify
@@ -34,7 +32,6 @@ public:
virtual ~CalendarExample();
void set_flags();
- void font_selection_ok();
void toggle_flag(Gtk::CheckButton *toggle);
void month_changed();
@@ -44,10 +41,13 @@ public:
protected:
void on_font_button_font_set();
void on_button_close();
+ void on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section, const Glib::Error& error);
Gtk::CheckButton* flag_checkboxes_[5];
bool settings_[5];
+ Glib::RefPtr<Gtk::CssProvider> css_provider_;
+
Gtk::FontButton* font_button_;
Gtk::Calendar* calendar_;
Gtk::Label* label_selected_;
@@ -118,10 +118,23 @@ void CalendarExample::toggle_flag(Gtk::CheckButton *toggle)
void CalendarExample::on_font_button_font_set()
{
- const Glib::ustring font_name = font_button_->get_font_name();
- if(!font_name.empty())
+ try
{
- calendar_->override_font(Pango::FontDescription(font_name));
+ const Glib::ustring font_name = font_button_->get_font_name();
+ if (!font_name.empty())
+ {
+ css_provider_->load_from_data("* { font: " + font_name + "; }");
+ }
+ }
+ catch (const Gtk::CssProviderError& ex)
+ {
+ std::cerr << "CssProviderError, Gtk::CssProvider::load_from_path() failed: "
+ << ex.what() << std::endl;
+ }
+ catch (const Glib::Error& ex)
+ {
+ std::cerr << "Error, Gtk::CssProvider::load_from_path() failed: "
+ << ex.what() << std::endl;
}
}
@@ -130,6 +143,19 @@ void CalendarExample::on_button_close()
hide();
}
+void CalendarExample::on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section, const
Glib::Error& error)
+{
+ std::cerr << "on_parsing_error(): " << error.what() << std::endl;
+ if (section)
+ {
+ std::cerr << " URI = " << section->get_file()->get_uri() << std::endl;
+ std::cerr << " start_line = " << section->get_start_line()+1
+ << ", end_line = " << section->get_end_line()+1 << std::endl;
+ std::cerr << " start_position = " << section->get_start_position()
+ << ", end_position = " << section->get_end_position() << std::endl;
+ }
+}
+
CalendarExample::CalendarExample()
{
for (int i = 0; i < 5; i++) {
@@ -202,10 +228,20 @@ CalendarExample::CalendarExample()
font_button_->signal_font_set().connect(sigc::mem_fun(*this, &CalendarExample::on_font_button_font_set));
vbox2->pack_start(*font_button_, Gtk::PACK_SHRINK);
+ // Add a StyleProvider to the Gtk::Calendar, so we can change the font.
+ // This was easier before Gtk::Widget::override_font() was deprecated.
+ css_provider_ = Gtk::CssProvider::create();
+ Glib::RefPtr<Gtk::StyleContext> refStyleContext = calendar_->get_style_context();
+ refStyleContext->add_provider(css_provider_, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ css_provider_->signal_parsing_error().connect(
+ sigc::mem_fun(*this, &CalendarExample::on_parsing_error));
+
+ // Set initial font.
+ on_font_button_font_set();
+
/*
* Build the Signal-event part.
*/
-
frame = Gtk::manage(new Gtk::Frame("Signal events"));
vbox->pack_start(*frame, Gtk::PACK_EXPAND_WIDGET, DEF_PAD);
vbox2 = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, DEF_PAD_SMALL));
@@ -255,7 +291,6 @@ Glib::Date CalendarExample::get_date() const
return date;
}
-
int main(int argc, char** argv)
{
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]