[gtkmm-documentation] custom_widget example: Use Gtk::WidgetCustomDraw and WidgetCustomSnapshot
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] custom_widget example: Use Gtk::WidgetCustomDraw and WidgetCustomSnapshot
- Date: Wed, 15 Feb 2017 10:06:29 +0000 (UTC)
commit 8bb730aafaf1f45e1b746f62d5e62ebdc6960746
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Wed Feb 15 11:03:37 2017 +0100
custom_widget example: Use Gtk::WidgetCustomDraw and WidgetCustomSnapshot
and add custom class_init and instance_init functions to the example.
Bug 775348
examples/Makefile.am | 6 +-
examples/book/custom/custom_widget/custom_gtk.css | 9 +-
.../book/custom/custom_widget/examplewindow.cc | 20 ++-
examples/book/custom/custom_widget/examplewindow.h | 10 +-
examples/book/custom/custom_widget/myextrainit.cc | 51 +++++
examples/book/custom/custom_widget/myextrainit.h | 33 +++
examples/book/custom/custom_widget/mywidget.cc | 33 ++--
examples/book/custom/custom_widget/mywidget.h | 12 +-
examples/book/custom/custom_widget/mywidget2.cc | 228 ++++++++++++++++++++
examples/book/custom/custom_widget/mywidget2.h | 58 +++++
10 files changed, 428 insertions(+), 32 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index e575bc0..c4ece4b 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -283,8 +283,12 @@ book_custom_custom_widget_example_SOURCES = \
book/custom/custom_widget/examplewindow.cc \
book/custom/custom_widget/examplewindow.h \
book/custom/custom_widget/main.cc \
+ book/custom/custom_widget/myextrainit.cc \
+ book/custom/custom_widget/myextrainit.h \
book/custom/custom_widget/mywidget.cc \
- book/custom/custom_widget/mywidget.h
+ book/custom/custom_widget/mywidget.h \
+ book/custom/custom_widget/mywidget2.cc \
+ book/custom/custom_widget/mywidget2.h
nodist_book_dialogs_aboutdialog_example_SOURCES = book/dialogs/aboutdialog/resources.c
book_dialogs_aboutdialog_example_SOURCES = \
diff --git a/examples/book/custom/custom_widget/custom_gtk.css
b/examples/book/custom/custom_widget/custom_gtk.css
index dbdd7f7..1ecb3dd 100644
--- a/examples/book/custom/custom_widget/custom_gtk.css
+++ b/examples/book/custom/custom_widget/custom_gtk.css
@@ -6,11 +6,16 @@
* {
/* -<widget class name>-<style property canonical name>: <value>; */
- -gtkmm__CustomObject_mywidget-example-scale: 920;
+ -gtkmm__CustomObject_MyWidget-example-scale: 920;
+ -gtkmm__CustomObject_MyWidget2-example-scale: 1000;
}
-#my-widget {
+my-widget {
background-color: rgb(255,0,0);
color: rgb(0,0,255);
}
+my-widget2 {
+ background-color: rgb(255,255,0);
+ color: rgb(255,0,0);
+}
diff --git a/examples/book/custom/custom_widget/examplewindow.cc
b/examples/book/custom/custom_widget/examplewindow.cc
index a632740..da9feb7 100644
--- a/examples/book/custom/custom_widget/examplewindow.cc
+++ b/examples/book/custom/custom_widget/examplewindow.cc
@@ -17,17 +17,23 @@
#include "examplewindow.h"
ExampleWindow::ExampleWindow()
-: m_VBox(Gtk::ORIENTATION_VERTICAL),
- m_Button_Quit("Quit")
+: m_Button_Quit("Quit")
{
set_title("Custom Widget example");
- set_default_size(400, 200);
+ set_default_size(600, 400);
- m_VBox.set_margin(6);
- add(m_VBox);
- m_VBox.pack_start(m_MyWidget, Gtk::PACK_EXPAND_WIDGET);
+ m_Grid.set_margin(6);
+ m_Grid.set_row_spacing(10);
+ m_Grid.set_column_spacing(10);
- m_VBox.pack_start(m_ButtonBox, Gtk::PACK_SHRINK);
+ add(m_Grid);
+
+ m_Grid.attach(m_MyWidgetS1, 0, 0);
+ m_Grid.attach(m_MyWidgetS2, 1, 1);
+ m_Grid.attach(m_MyWidgetD1, 0, 1);
+ m_Grid.attach(m_MyWidgetD2, 1, 0);
+
+ m_Grid.attach(m_ButtonBox, 0, 2, 2, 1);
m_ButtonBox.pack_start(m_Button_Quit, Gtk::PACK_SHRINK);
m_ButtonBox.set_margin(6);
diff --git a/examples/book/custom/custom_widget/examplewindow.h
b/examples/book/custom/custom_widget/examplewindow.h
index fd4fe07..3a6e392 100644
--- a/examples/book/custom/custom_widget/examplewindow.h
+++ b/examples/book/custom/custom_widget/examplewindow.h
@@ -1,5 +1,3 @@
-//$Id: examplewindow.h 705 2006-07-19 02:55:32Z jjongsma $ -*- c++ -*-
-
/* gtkmm example Copyright (C) 2004 gtkmm development team
*
* This program is free software; you can redistribute it and/or modify
@@ -21,6 +19,7 @@
#include <gtkmm.h>
#include "mywidget.h"
+#include "mywidget2.h"
class ExampleWindow : public Gtk::Window
{
@@ -33,8 +32,11 @@ protected:
void on_button_quit();
//Child widgets:
- Gtk::Box m_VBox;
- MyWidget m_MyWidget;
+ Gtk::Grid m_Grid;
+ MyWidget m_MyWidgetS1;
+ MyWidget m_MyWidgetS2;
+ MyWidget2 m_MyWidgetD1;
+ MyWidget2 m_MyWidgetD2;
Gtk::ButtonBox m_ButtonBox;
Gtk::Button m_Button_Quit;
};
diff --git a/examples/book/custom/custom_widget/myextrainit.cc
b/examples/book/custom/custom_widget/myextrainit.cc
new file mode 100644
index 0000000..f2875c4
--- /dev/null
+++ b/examples/book/custom/custom_widget/myextrainit.cc
@@ -0,0 +1,51 @@
+/* gtkmm example Copyright (C) 2017 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "myextrainit.h"
+#include <gtkmm/widget.h>
+#include <gtk/gtk.h>
+
+namespace
+{
+using BaseObjectType = GtkWidget;
+using BaseClassType = GtkWidgetClass;
+
+// Extra class init function.
+void class_init_function(void* g_class, void* class_data)
+{
+ g_return_if_fail(GTK_IS_WIDGET_CLASS(g_class));
+
+ const auto klass = static_cast<BaseClassType*>(g_class);
+ const auto css_name = static_cast<Glib::ustring*>(class_data);
+
+ gtk_widget_class_set_css_name(klass, css_name->c_str());
+}
+
+// Extra instance init function.
+void instance_init_function(GTypeInstance* instance, void* /* g_class */)
+{
+ g_return_if_fail(GTK_IS_WIDGET(instance));
+
+ gtk_widget_set_has_window(GTK_WIDGET(instance), true);
+}
+
+} // anonymous namespace
+
+MyExtraInit::MyExtraInit(const Glib::ustring& css_name)
+:
+Glib::ExtraClassInit(class_init_function, &m_css_name, instance_init_function),
+m_css_name(css_name)
+{
+}
diff --git a/examples/book/custom/custom_widget/myextrainit.h
b/examples/book/custom/custom_widget/myextrainit.h
new file mode 100644
index 0000000..952b091
--- /dev/null
+++ b/examples/book/custom/custom_widget/myextrainit.h
@@ -0,0 +1,33 @@
+/* gtkmm example Copyright (C) 2017 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTKMM_CUSTOM_WIDGET_MYEXTRAINIT_H
+#define GTKMM_CUSTOM_WIDGET_MYEXTRAINIT_H
+
+#include <glibmm/extraclassinit.h>
+#include <glibmm/ustring.h>
+
+// Calls gtk_widget_class_set_css_name() in the class init function
+// and gtk_set_has_window() in the instance init function.
+class MyExtraInit : public Glib::ExtraClassInit
+{
+public:
+ MyExtraInit(const Glib::ustring& css_name);
+
+private:
+ Glib::ustring m_css_name;
+};
+
+#endif //GTKMM_CUSTOM_WIDGET_MYEXTRAINIT_H
diff --git a/examples/book/custom/custom_widget/mywidget.cc b/examples/book/custom/custom_widget/mywidget.cc
index bcdaf25..7e9b659 100644
--- a/examples/book/custom/custom_widget/mywidget.cc
+++ b/examples/book/custom/custom_widget/mywidget.cc
@@ -22,15 +22,19 @@
MyWidget::MyWidget() :
- //The GType name will actually be gtkmm__CustomObject_mywidget
- Glib::ObjectBase("mywidget"),
+ //The GType name will actually be gtkmm__CustomObject_MyWidget
+ Glib::ObjectBase("MyWidget"),
+ Gtk::WidgetCustomSnapshot(),
+ MyExtraInit("my-widget"),
Gtk::Widget(),
//Install a style property so that an aspect of this widget may be themed
//via a CSS style sheet file:
m_scale_prop(*this, "example_scale", 500),
m_scale(1000)
{
- set_has_window(true);
+ // Expand, if there is extra space.
+ set_hexpand(true);
+ set_vexpand(true);
//This shows the GType name, which must be used in the CSS file.
std::cout << "GType name: " << G_OBJECT_TYPE_NAME(gobj()) << std::endl;
@@ -38,15 +42,13 @@ MyWidget::MyWidget() :
//This shows that the GType still derives from GtkWidget:
//std::cout << "Gtype is a GtkWidget?:" << GTK_IS_WIDGET(gobj()) << std::endl;
- // Set the widget name to use in the CSS file.
- set_name("my-widget");
-
- // If you make a custom widget in C code, based on gtk+'s GtkWidget, there is
- // an alternative to gtk_widget_set_name(): Set a CSS name for your custom
- // class (instead of the widget instance) with gtk_widget_class_set_css_name()
- // (new in gtk+ 3.19.1). That's not possible for custom widgets defined in gtkmm.
- // gtk_widget_class_set_css_name() must be called in the class init function,
- // which can't be customized, when the widget is based on gtkmm's Gtk::Widget.
+ // The CSS name can be set either
+ // - for a GType (in this case for your custom class) with gtk_widget_class_set_css_name(), or
+ // - for a widget instance with gtk_widget_set_name() (Gtk::Widget::set_name()).
+ //
+ // gtk_widget_class_set_css_name(), if used, must be called in the class init function.
+ // It has not been wrapped in a C++ function.
+ // Gtk::Widget::set_name() can be called in a C++ constructor.
//
// Another alternative: The custom widget inherits the CSS name "widget" from
// GtkWidget. That name can be used in the CSS file. This is not a very good
@@ -169,7 +171,7 @@ void MyWidget::on_unrealize()
Gtk::Widget::on_unrealize();
}
-bool MyWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void MyWidget::snapshot_vfunc(Gtk::Snapshot& snapshot)
{
const Gtk::Allocation allocation = get_allocation();
Gtk::Allocation clip = get_clip();
@@ -179,6 +181,9 @@ bool MyWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
const double scale_y = (double)clip.get_height() / m_scale;
auto refStyleContext = get_style_context();
+ // Create a cairo context to draw on.
+ auto cr = snapshot.append_cairo(clip, "MyCairoNode");
+
// paint the background
refStyleContext->render_background(cr,
clip.get_x(), clip.get_y(), clip.get_width(), clip.get_height());
@@ -204,8 +209,6 @@ bool MyWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
cr->move_to(633.*scale_x, 564.*scale_y);
cr->line_to(155.*scale_x, 838.*scale_y);
cr->stroke();
-
- return true;
}
void MyWidget::on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section, const Glib::Error& error)
diff --git a/examples/book/custom/custom_widget/mywidget.h b/examples/book/custom/custom_widget/mywidget.h
index 2eac98c..679a8f3 100644
--- a/examples/book/custom/custom_widget/mywidget.h
+++ b/examples/book/custom/custom_widget/mywidget.h
@@ -20,8 +20,14 @@
#include <gtkmm/widget.h>
#include <gtkmm/cssprovider.h>
#include <gtkmm/styleproperty.h>
-
-class MyWidget : public Gtk::Widget
+#include <gtkmm/widgetcustomsnapshot.h>
+#include "myextrainit.h"
+
+class MyWidget
+:
+public Gtk::WidgetCustomSnapshot,
+public MyExtraInit,
+public Gtk::Widget
{
public:
MyWidget();
@@ -38,7 +44,7 @@ protected:
void on_unmap() override;
void on_realize() override;
void on_unrealize() override;
- bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) /* override */;
+ void snapshot_vfunc(Gtk::Snapshot& snapshot) override;
//Signal handler:
void on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section, const Glib::Error& error);
diff --git a/examples/book/custom/custom_widget/mywidget2.cc b/examples/book/custom/custom_widget/mywidget2.cc
new file mode 100644
index 0000000..7f22fd1
--- /dev/null
+++ b/examples/book/custom/custom_widget/mywidget2.cc
@@ -0,0 +1,228 @@
+/* gtkmm example Copyright (C) 2017 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mywidget2.h"
+#include <gdkmm/general.h> // for cairo helper functions
+#include <iostream>
+//#include <gtk/gtkwidget.h> //For GTK_IS_WIDGET()
+#include <cstring>
+
+
+MyWidget2::MyWidget2() :
+ //The GType name will actually be gtkmm__CustomObject_MyWidget2
+ Glib::ObjectBase("MyWidget2"),
+ Gtk::WidgetCustomDraw(),
+ MyExtraInit("my-widget2"),
+ Gtk::Widget(),
+ //Install a style property so that an aspect of this widget may be themed
+ //via a CSS style sheet file:
+ m_scale_prop(*this, "example_scale", 500),
+ m_scale(1000)
+{
+ // Expand, if there is extra space.
+ set_hexpand(true);
+ set_vexpand(true);
+
+ //This shows the GType name, which must be used in the CSS file.
+ std::cout << "GType name: " << G_OBJECT_TYPE_NAME(gobj()) << std::endl;
+
+ //This shows that the GType still derives from GtkWidget:
+ //std::cout << "Gtype is a GtkWidget?:" << GTK_IS_WIDGET(gobj()) << std::endl;
+
+ // The CSS name can be set either
+ // - for a GType (in this case for your custom class) with gtk_widget_class_set_css_name(), or
+ // - for a widget instance with gtk_widget_set_name() (Gtk::Widget::set_name()).
+ //
+ // gtk_widget_class_set_css_name(), if used, must be called in the class init function.
+ // It has not been wrapped in a C++ function.
+ // Gtk::Widget::set_name() can be called in a C++ constructor.
+ //
+ // Another alternative: The custom widget inherits the CSS name "widget" from
+ // GtkWidget. That name can be used in the CSS file. This is not a very good
+ // alternative. GtkWidget's CSS name is not documented. It can probably be
+ // changed or removed in the future.
+
+ m_refCssProvider = Gtk::CssProvider::create();
+ auto refStyleContext = get_style_context();
+ refStyleContext->add_provider(m_refCssProvider,
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ m_refCssProvider->signal_parsing_error().connect(
+ sigc::mem_fun(*this, &MyWidget2::on_parsing_error));
+
+ try
+ {
+ m_refCssProvider->load_from_path("custom_gtk.css");
+ }
+ 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;
+ }
+}
+
+MyWidget2::~MyWidget2()
+{
+}
+
+Gtk::SizeRequestMode MyWidget2::get_request_mode_vfunc() const
+{
+ //Accept the default value supplied by the base class.
+ return Gtk::Widget::get_request_mode_vfunc();
+}
+
+//Discover the total amount of minimum space and natural space needed by
+//this widget.
+//Let's make this simple example widget always need minimum 60 by 50 and
+//natural 100 by 70.
+void MyWidget2::measure_vfunc(Gtk::Orientation orientation, int /* for_size */,
+ int& minimum, int& natural, int& minimum_baseline, int& natural_baseline) const
+{
+ if (orientation == Gtk::ORIENTATION_HORIZONTAL)
+ {
+ minimum = 60;
+ natural = 100;
+ }
+ else
+ {
+ minimum = 50;
+ natural = 70;
+ }
+
+ // Don't use baseline alignment.
+ minimum_baseline = -1;
+ natural_baseline = -1;
+}
+
+void MyWidget2::on_size_allocate(Gtk::Allocation& allocation)
+{
+ //Do something with the space that we have actually been given:
+ //(We will not be given heights or widths less than we have requested, though
+ //we might get more)
+
+ //Use the offered allocation for this container:
+ set_allocation(allocation);
+
+ if(m_refGdkWindow)
+ {
+ m_refGdkWindow->move_resize( allocation.get_x(), allocation.get_y(),
+ allocation.get_width(), allocation.get_height() );
+ }
+}
+
+void MyWidget2::on_map()
+{
+ //Call base class:
+ Gtk::Widget::on_map();
+}
+
+void MyWidget2::on_unmap()
+{
+ //Call base class:
+ Gtk::Widget::on_unmap();
+}
+
+void MyWidget2::on_realize()
+{
+ //Do not call base class Gtk::Widget::on_realize().
+ //It's intended only for widgets that set_has_window(false).
+
+ set_realized();
+
+ //Get the themed style from the CSS file:
+ m_scale = m_scale_prop.get_value();
+ std::cout << "m_scale (example_scale from the theme/css-file) is: "
+ << m_scale << std::endl;
+
+ if(!m_refGdkWindow)
+ {
+ //Create the GdkWindow:
+ m_refGdkWindow = Gdk::Window::create_child(get_parent_window(),
+ get_events () | Gdk::EXPOSURE_MASK, get_allocation());
+ set_window(m_refGdkWindow);
+
+ //make the widget receive expose events
+ m_refGdkWindow->set_user_data(gobj());
+ }
+}
+
+void MyWidget2::on_unrealize()
+{
+ m_refGdkWindow.reset();
+
+ //Call base class:
+ Gtk::Widget::on_unrealize();
+}
+
+bool MyWidget2::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+{
+ const Gtk::Allocation allocation = get_allocation();
+ Gtk::Allocation clip = get_clip();
+ clip.set_x(clip.get_x() - allocation.get_x());
+ clip.set_y(clip.get_y() - allocation.get_y());
+ const double scale_x = (double)clip.get_width() / m_scale;
+ const double scale_y = (double)clip.get_height() / m_scale;
+ auto refStyleContext = get_style_context();
+
+ // paint the background
+ refStyleContext->render_background(cr,
+ clip.get_x(), clip.get_y(), clip.get_width(), clip.get_height());
+
+ // draw the foreground
+ Gdk::Cairo::set_source_rgba(cr, refStyleContext->get_color());
+ cr->move_to(155.*scale_x, 165.*scale_y);
+ cr->line_to(155.*scale_x, 838.*scale_y);
+ cr->line_to(265.*scale_x, 900.*scale_y);
+ cr->line_to(849.*scale_x, 564.*scale_y);
+ cr->line_to(849.*scale_x, 438.*scale_y);
+ cr->line_to(265.*scale_x, 100.*scale_y);
+ cr->line_to(155.*scale_x, 165.*scale_y);
+ cr->move_to(265.*scale_x, 100.*scale_y);
+ cr->line_to(265.*scale_x, 652.*scale_y);
+ cr->line_to(526.*scale_x, 502.*scale_y);
+ cr->move_to(369.*scale_x, 411.*scale_y);
+ cr->line_to(633.*scale_x, 564.*scale_y);
+ cr->move_to(369.*scale_x, 286.*scale_y);
+ cr->line_to(369.*scale_x, 592.*scale_y);
+ cr->move_to(369.*scale_x, 286.*scale_y);
+ cr->line_to(849.*scale_x, 564.*scale_y);
+ cr->move_to(633.*scale_x, 564.*scale_y);
+ cr->line_to(155.*scale_x, 838.*scale_y);
+ cr->stroke();
+
+ return true;
+}
+
+void MyWidget2::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)
+ {
+ const auto file = section->get_file();
+ if (file)
+ {
+ std::cerr << " URI = " << 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;
+ }
+}
diff --git a/examples/book/custom/custom_widget/mywidget2.h b/examples/book/custom/custom_widget/mywidget2.h
new file mode 100644
index 0000000..c80b4d3
--- /dev/null
+++ b/examples/book/custom/custom_widget/mywidget2.h
@@ -0,0 +1,58 @@
+/* gtkmm example Copyright (C) 2017 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTKMM_CUSTOM_WIDGET_MYWIDGET2_H
+#define GTKMM_CUSTOM_WIDGET_MYWIDGET2_H
+
+#include <gtkmm/widget.h>
+#include <gtkmm/cssprovider.h>
+#include <gtkmm/styleproperty.h>
+#include <gtkmm/widgetcustomdraw.h>
+#include "myextrainit.h"
+
+class MyWidget2
+:
+public Gtk::WidgetCustomDraw,
+public MyExtraInit,
+public Gtk::Widget
+{
+public:
+ MyWidget2();
+ virtual ~MyWidget2();
+
+protected:
+
+ //Overrides:
+ Gtk::SizeRequestMode get_request_mode_vfunc() const override;
+ void measure_vfunc(Gtk::Orientation orientation, int for_size, int& minimum, int& natural,
+ int& minimum_baseline, int& natural_baseline) const override;
+ void on_size_allocate(Gtk::Allocation& allocation) override;
+ void on_map() override;
+ void on_unmap() override;
+ void on_realize() override;
+ void on_unrealize() override;
+ bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+
+ //Signal handler:
+ void on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section, const Glib::Error& error);
+
+ Gtk::StyleProperty<int> m_scale_prop;
+ Glib::RefPtr<Gdk::Window> m_refGdkWindow;
+ Glib::RefPtr<Gtk::CssProvider> m_refCssProvider;
+
+ int m_scale;
+};
+
+#endif //GTKMM_CUSTOM_WIDGET_MYWIDGET2_H
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]