[gtkmm/wip/dboles/Builder-test-derived-properties] tests/builder: Test derived props declared in C++,
- From: Daniel Boles <dboles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm/wip/dboles/Builder-test-derived-properties] tests/builder: Test derived props declared in C++,
- Date: Mon, 25 Nov 2019 06:41:13 +0000 (UTC)
commit ce2d279a50e059226f480a689babf63d5e0ef4fa
Author: Daniel Boles <dboles src gnome org>
Date: Mon Nov 25 06:38:07 2019 +0000
tests/builder: Test derived props declared in C++,
by giving DerivedButton one and then setting it in the Builder .ui file.
tests/builder/main.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/tests/builder/main.cc b/tests/builder/main.cc
index 3c35c952..509d7f8e 100644
--- a/tests/builder/main.cc
+++ b/tests/builder/main.cc
@@ -40,11 +40,12 @@ const char gladefile[] =
"<property name='can_focus'>False</property>"
"<property name='orientation'>vertical</property>"
"<child>"
- "<object class='GtkButton' id='derived_button'>"
+ "<object class='gtkmm__CustomObject_DerivedButton' id='derived_button'>"
"<property name='label' translatable='yes'>DerivedButton</property>"
"<property name='visible'>True</property>"
"<property name='can_focus'>True</property>"
"<property name='receives_default'>True</property>"
+ "<property name='background'>#008080</property>"
"</object>"
"<packing>"
"<property name='expand'>False</property>"
@@ -91,12 +92,27 @@ void* on_orphaned_button_deleted(void* /* data */)
class DerivedButton : public Gtk::Button
{
public:
+ static void ensure_type()
+ {
+ std::cout << "DerivedButton::ensure_type()" << std::endl;
+ static_cast<void>(DerivedButton());
+ }
+
DerivedButton(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& /* refBuilder */,
const Glib::ustring& icon_name = {})
- : Gtk::Button(cobject)
+ : Glib::ObjectBase(s_type_name)
+ , Gtk::Button(cobject)
+ , m_cssProvider_background{ Gtk::CssProvider::create() }
{
std::cout << "DerivedButton::ctor" << std::endl;
+ get_style_context()->add_provider(
+ m_cssProvider_background, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+ on_background_changed();
+ property_background().signal_changed().connect(
+ sigc::mem_fun(*this, &DerivedButton::on_background_changed));
+
if (!icon_name.empty())
{
set_image_from_icon_name(icon_name);
@@ -104,10 +120,35 @@ public:
}
}
+ Glib::PropertyProxy_ReadOnly<Glib::ustring> property_background() const { return
m_property_background.get_proxy(); }
+ Glib::PropertyProxy <Glib::ustring> property_background() { return
m_property_background.get_proxy(); }
+ Glib::ustring get_background() const { return m_property_background.get_value(); }
+ void set_background(const Glib::ustring& background){ m_property_background.set_value(background); }
+
virtual ~DerivedButton()
{
std::cout << "DerivedButton::dtor" << std::endl;
}
+
+private:
+ static auto constexpr s_type_name = "DerivedButton";
+ Glib::Property<Glib::ustring> m_property_background{*this, "background"};
+
+ Glib::RefPtr<Gtk::CssProvider> const m_cssProvider_background;
+
+ DerivedButton()
+ : Glib::ObjectBase(s_type_name)
+ {
+ std::cout << "DerivedButton::ctor to register type" << std::endl;
+ }
+
+ void on_background_changed()
+ {
+ const auto background = get_background();
+ const auto css = background.empty() ? Glib::ustring()
+ : Glib::ustring::compose("button { background: %1; }", get_background());
+ m_cssProvider_background->load_from_data(css);
+ }
};
class MainWindow : public Gtk::Window
@@ -157,6 +198,7 @@ int main(int argc, char* argv[])
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc1, argv);
+ DerivedButton::ensure_type();
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_string(gladefile);
MainWindow* main_win = nullptr;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]