[gtkmm] Widget, StyleContext: Allow default StyleFlag values.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Widget, StyleContext: Allow default StyleFlag values.
- Date: Tue, 7 Dec 2010 16:16:05 +0000 (UTC)
commit 4d72a35b261f69284e440edc37b97c5bc58819c7
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Dec 7 16:14:03 2010 +0100
Widget, StyleContext: Allow default StyleFlag values.
* gtk/src/stylecontext.[hg|ccg]: get_color(), get_background_color(),
get_border_color(), get_padding(), get_margin().
* gtk/src/widget.[hg|ccg]: override_color(), override_background_color():
Manually implement these methods so we can rearrange the parameters and then
provide a default StateFlags value of 0.
* demos/gtk-demo/example_colorsel.cc:
* demos/gtk-demo/example_textview.cc: Adapted.
ChangeLog | 12 ++++++++++
demos/gtk-demo/example_colorsel.cc | 4 +-
demos/gtk-demo/example_textview.cc | 2 +-
gtk/src/stylecontext.ccg | 43 ++++++++++++++++++++++++++++++++++++
gtk/src/stylecontext.hg | 26 +++++++++++++++------
gtk/src/widget.ccg | 12 ++++++++++
gtk/src/widget.hg | 10 ++++++-
7 files changed, 96 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 640c248..58fc9fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2010-12-07 Murray Cumming <murrayc murrayc com>
+ Widget, StyleContext: Allow default StyleFlag values.
+
+ * gtk/src/stylecontext.[hg|ccg]: get_color(), get_background_color(),
+ get_border_color(), get_padding(), get_margin().
+ * gtk/src/widget.[hg|ccg]: override_color(), override_background_color():
+ Manually implement these methods so we can rearrange the parameters and then
+ provide a default StateFlags value of 0.
+ * demos/gtk-demo/example_colorsel.cc:
+ * demos/gtk-demo/example_textview.cc: Adapted.
+
+2010-12-07 Murray Cumming <murrayc murrayc com>
+
Widget: Added get_style_context().
* gtk/src/widget.hg: Wrap gtk_widget_get_style_context().
diff --git a/demos/gtk-demo/example_colorsel.cc b/demos/gtk-demo/example_colorsel.cc
index a7ddec7..de9bb99 100644
--- a/demos/gtk-demo/example_colorsel.cc
+++ b/demos/gtk-demo/example_colorsel.cc
@@ -61,7 +61,7 @@ Example_ColorSel::Example_ColorSel()
// set the color
m_Color.set_rgba(0, 0, 1, 1);
- m_DrawingArea.override_background_color((Gtk::StateFlags)0, m_Color);
+ m_DrawingArea.override_background_color(m_Color);
m_Frame.add(m_DrawingArea);
@@ -95,7 +95,7 @@ void Example_ColorSel::on_button_clicked()
{
m_Color = pColorSel->get_current_rgba();
- m_DrawingArea.override_background_color((Gtk::StateFlags)0, m_Color);
+ m_DrawingArea.override_background_color(m_Color);
}
}
diff --git a/demos/gtk-demo/example_textview.cc b/demos/gtk-demo/example_textview.cc
index 84b4a67..96c8f60 100644
--- a/demos/gtk-demo/example_textview.cc
+++ b/demos/gtk-demo/example_textview.cc
@@ -458,7 +458,7 @@ void Window_EasterEgg::recursive_attach_view(int depth, Gtk::TextView& view, Gli
/* 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((Gtk::StateFlags)0, color);
+ pEventBox->override_background_color(color);
Gtk::Alignment* pAlign = Gtk::manage( new Gtk::Alignment(0.5, 0.5, 1.0, 1.0));
pAlign->set_border_width(1);
diff --git a/gtk/src/stylecontext.ccg b/gtk/src/stylecontext.ccg
index d67f84a..b6c7b09 100644
--- a/gtk/src/stylecontext.ccg
+++ b/gtk/src/stylecontext.ccg
@@ -25,4 +25,47 @@
namespace Gtk
{
+
+Gdk::RGBA StyleContext::get_color(StateFlags state) const
+{
+ GdkRGBA crgba;
+ gtk_style_context_get_color(const_cast<GtkStyleContext*>(gobj()), ((GtkStateFlags)(state)), &crgba);
+ return Gdk::RGBA(&crgba, false);
+}
+
+Gdk::RGBA StyleContext::get_background_color(StateFlags state) const
+{
+ GdkRGBA crgba;
+ gtk_style_context_get_background_color(const_cast<GtkStyleContext*>(gobj()), ((GtkStateFlags)(state)), &crgba);
+ return Gdk::RGBA(&crgba, false);
+}
+
+Gdk::RGBA StyleContext::get_border_color(StateFlags state) const
+{
+ GdkRGBA crgba;
+ gtk_style_context_get_border_color(const_cast<GtkStyleContext*>(gobj()), ((GtkStateFlags)(state)), &crgba);
+ return Gdk::RGBA(&crgba, false);
+}
+
+Border StyleContext::get_border(StateFlags state) const
+{
+ GtkBorder cborder;
+ gtk_style_context_get_border(const_cast<GtkStyleContext*>(gobj()), ((GtkStateFlags)(state)), &cborder);
+ return Border(&cborder, false);
+}
+
+Border StyleContext::get_padding(StateFlags state) const
+{
+ GtkBorder cborder;
+ gtk_style_context_get_padding(const_cast<GtkStyleContext*>(gobj()), ((GtkStateFlags)(state)), &cborder);
+ return Border(&cborder, false);
+}
+
+Border StyleContext::get_margin(StateFlags state) const
+{
+ GtkBorder cborder;
+ gtk_style_context_get_margin(const_cast<GtkStyleContext*>(gobj()), ((GtkStateFlags)(state)), &cborder);
+ return Border(&cborder, false);
+}
+
} // namespace Gtk
diff --git a/gtk/src/stylecontext.hg b/gtk/src/stylecontext.hg
index 731870c..aa7ac07 100644
--- a/gtk/src/stylecontext.hg
+++ b/gtk/src/stylecontext.hg
@@ -127,14 +127,24 @@ public:
_WRAP_METHOD(void push_animatable_region(gpointer region_id), gtk_style_context_push_animatable_region)
_WRAP_METHOD(void pop_animatable_region(), gtk_style_context_pop_animatable_region)
-/* Some helper functions to retrieve most common properties */
- _WRAP_METHOD(void get_color(StateFlags state, Gdk::RGBA& color) const, gtk_style_context_get_color)
- _WRAP_METHOD(void get_background_color(StateFlags state, Gdk::RGBA& color) const, gtk_style_context_get_background_color)
- _WRAP_METHOD(void get_border_color(StateFlags state, Gdk::RGBA& color) const, gtk_style_context_get_border_color)
-
- _WRAP_METHOD(void get_border(StateFlags state, Border& border) const, gtk_style_context_get_border)
- _WRAP_METHOD(void get_padding(StateFlags state, Border& padding) const, gtk_style_context_get_padding)
- _WRAP_METHOD(void get_margin (StateFlags state, Border& margin) const, gtk_style_context_get_margin)
+ //TODO: Documentation
+ Gdk::RGBA get_color(StateFlags state = (StateFlags)0) const;
+ _IGNORE(gtk_style_context_get_color)
+
+ Gdk::RGBA get_background_color(StateFlags state = (StateFlags)0) const;
+ _IGNORE(gtk_style_context_get_background_color)
+
+ Gdk::RGBA get_border_color(StateFlags state = (StateFlags)0) const;
+ _IGNORE(gtk_style_context_get_border_color)
+
+ Border get_border(StateFlags state = (StateFlags)0) const;
+ _IGNORE(gtk_style_context_get_border)
+
+ Border get_padding(StateFlags state = (StateFlags)0) const;
+ _IGNORE(gtk_style_context_get_padding)
+
+ Border get_margin (StateFlags state = (StateFlags)0) const;
+ _IGNORE(gtk_style_context_get_margin)
_WRAP_METHOD(void invalidate(), gtk_style_context_invalidate)
//TODO: _WRAP_METHOD(void reset_widgets(const Glib::RefPtr<Gdk::Screen>& screen), gtk_style_context_reset_widgets)
diff --git a/gtk/src/widget.ccg b/gtk/src/widget.ccg
index 0a966c4..039d458 100644
--- a/gtk/src/widget.ccg
+++ b/gtk/src/widget.ccg
@@ -415,4 +415,16 @@ Requisition Widget::get_requisition() const
return result;
}
+
+//Implemented manually so we can reorder the parameters, to have a default value:
+void Widget::override_color(const Gdk::RGBA& color, StateFlags state)
+{
+ gtk_widget_override_color(gobj(), ((GtkStateFlags)(state)), (color).gobj());
+}
+
+void Widget::override_background_color(const Gdk::RGBA& color, StateFlags state)
+{
+ gtk_widget_override_background_color(gobj(), ((GtkStateFlags)(state)), (color).gobj());
+}
+
} // namespace Gtk
diff --git a/gtk/src/widget.hg b/gtk/src/widget.hg
index 8c576e4..bad1875 100644
--- a/gtk/src/widget.hg
+++ b/gtk/src/widget.hg
@@ -352,12 +352,18 @@ public:
gtk_widget_reset_rc_styles) //deprecated broadly in favour of StyleContext.;
+//TODO: Use _WRAP_METHOD() when it allows us to reorder parameters.
//TODO: Add unset_*() methods?
- _WRAP_METHOD(void override_color(StateFlags state, const Gdk::RGBA& color), gtk_widget_override_color)
- _WRAP_METHOD(void override_background_color(StateFlags state ,const Gdk::RGBA& color), gtk_widget_override_background_color)
+ void override_color(const Gdk::RGBA& color, StateFlags state = (StateFlags)0);
+ _IGNORE(gtk_widget_override_color)
+
+ void override_background_color(const Gdk::RGBA& color, StateFlags state = (StateFlags)0);
+ _IGNORE(gtk_widget_override_background_color)
+
_WRAP_METHOD(void override_font(const Pango::FontDescription& font_desc), gtk_widget_override_font)
_WRAP_METHOD(void override_symbolic_color(const Glib::ustring& name, const Gdk::RGBA& color), gtk_widget_override_symbolic_color)
_WRAP_METHOD(void override_cursor(const Gdk::RGBA& cursor, const Gdk::RGBA& secondary_cursor), gtk_widget_override_cursor)
+
_IGNORE(gtk_widget_modify_fg, gtk_widget_modify_bg, gtk_widget_modify_font, gtk_widget_modify_text,
gtk_widget_modify_base, gtk_widget_modify_cursor, gtk_widget_modify_symbolic_color) //deprecated
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]