hippo-canvas r7266 - in trunk: common/hippo python tests
- From: marco svn gnome org
- To: svn-commits-list gnome org
- Subject: hippo-canvas r7266 - in trunk: common/hippo python tests
- Date: Wed, 4 Jun 2008 15:37:12 +0000 (UTC)
Author: marco
Date: Wed Jun 4 15:37:11 2008
New Revision: 7266
URL: http://svn.gnome.org/viewvc/hippo-canvas?rev=7266&view=rev
Log:
Add a method to set the theme for a box. Clear the style when chaning the context.
Added:
trunk/tests/box1.css
trunk/tests/box2.css
trunk/tests/test-box-theme.py
Modified:
trunk/common/hippo/hippo-canvas-box.c
trunk/common/hippo/hippo-canvas-box.h
trunk/python/hippo.defs
Modified: trunk/common/hippo/hippo-canvas-box.c
==============================================================================
--- trunk/common/hippo/hippo-canvas-box.c (original)
+++ trunk/common/hippo/hippo-canvas-box.c Wed Jun 4 15:37:11 2008
@@ -779,6 +779,7 @@
hippo_canvas_box_clear(box);
hippo_canvas_box_set_layout(box, NULL);
+ hippo_canvas_box_set_theme(box, NULL);
clear_style(box);
@@ -1334,10 +1335,19 @@
HippoCanvasBox *box = HIPPO_CANVAS_BOX(context);
if (box->style == NULL) {
- box->style = hippo_canvas_style_new(box->context,
- hippo_canvas_context_get_style(box->context),
- NULL, /* Inherit theme from parent */
- G_OBJECT_TYPE(box), box->element_id, box->element_class);
+ if (box->theme == NULL) {
+ box->style = hippo_canvas_style_new(box->context,
+ hippo_canvas_context_get_style(box->context),
+ NULL, /* Inherit theme from parent */
+ G_OBJECT_TYPE(box), box->element_id,
+ box->element_class);
+
+ } else {
+ box->style = hippo_canvas_style_new(box->context, NULL,
+ box->theme, G_OBJECT_TYPE(box),
+ box->element_id, box->element_class);
+
+ }
hippo_canvas_style_set_link_type(box->style, box->link_type);
}
@@ -1388,13 +1398,15 @@
gboolean resize_needed,
HippoCanvasBox *box)
{
- clear_style(box);
-
- /* If our context's style changed, then our own style also
- * changed since we chain up to the outer context.
- */
- hippo_canvas_context_emit_style_changed(HIPPO_CANVAS_CONTEXT(box),
- resize_needed);
+ if (box->theme == NULL) {
+ clear_style(box);
+
+ /* If our context's style changed, then our own style also
+ * changed since we chain up to the outer context.
+ */
+ hippo_canvas_context_emit_style_changed(HIPPO_CANVAS_CONTEXT(box),
+ resize_needed);
+ }
}
static HippoCanvasContext*
@@ -1416,7 +1428,9 @@
/* this shortcut most importantly catches NULL == NULL */
if (box->context == context)
return;
-
+
+ clear_style(box);
+
/* Note that we do not ref the context; the parent is responsible for setting
* it back to NULL before dropping the ref to the item.
*
@@ -4761,3 +4775,31 @@
hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(box));
}
+
+/**
+ * hippo_canvas_box_set_theme:
+ * @box: a #HippoCanvasBox
+ * @theme: the theme to set on the box or %NULL to unset the current one
+ *
+ * Sets the theme to use for the box. It breaks the normal style inheritance
+ * by insulating the box and it's descendant into their own style context. It's
+ * useful to embed components which provides their own application stylesheet.
+ */
+void
+hippo_canvas_box_set_theme (HippoCanvasBox *box,
+ HippoCanvasTheme *theme)
+{
+ g_return_if_fail(HIPPO_IS_CANVAS_BOX(box));
+
+ if (box->theme)
+ g_object_unref(box->theme);
+
+ box->theme = theme;
+
+ if (box->theme)
+ g_object_ref(box->theme);
+
+ clear_style(box);
+
+ hippo_canvas_context_emit_style_changed(HIPPO_CANVAS_CONTEXT(box), TRUE);
+}
Modified: trunk/common/hippo/hippo-canvas-box.h
==============================================================================
--- trunk/common/hippo/hippo-canvas-box.h (original)
+++ trunk/common/hippo/hippo-canvas-box.h Wed Jun 4 15:37:11 2008
@@ -5,6 +5,7 @@
#include <hippo/hippo-canvas-item.h>
#include <hippo/hippo-canvas-container.h>
#include <hippo/hippo-canvas-style.h>
+#include <hippo/hippo-canvas-theme.h>
G_BEGIN_DECLS
@@ -57,6 +58,7 @@
HippoCanvasContainer *parent;
HippoCanvasContext *context;
HippoCanvasStyle *style; /* may be NULL if no relevant props set */
+ HippoCanvasTheme *theme;
GSList *children;
char *element_id;
@@ -215,6 +217,8 @@
void hippo_canvas_box_set_child_packing (HippoCanvasBox *box,
HippoCanvasItem *child,
HippoPackFlags flags);
+void hippo_canvas_box_set_theme (HippoCanvasBox *box,
+ HippoCanvasTheme *theme);
void hippo_canvas_box_set_layout(HippoCanvasBox *box,
HippoCanvasLayout *layout);
Modified: trunk/python/hippo.defs
==============================================================================
--- trunk/python/hippo.defs (original)
+++ trunk/python/hippo.defs Wed Jun 4 15:37:11 2008
@@ -774,6 +774,14 @@
(return-type "GSList*")
)
+(define-method set_theme
+ (of-object "HippoCanvasBox")
+ (c-name "hippo_canvas_box_set_theme")
+ (parameters
+ '("HippoCanvasTheme*" "theme")
+ )
+)
+
;; From hippo-canvas-context.h
(define-function canvas_context_get_type
Added: trunk/tests/box1.css
==============================================================================
--- (empty file)
+++ trunk/tests/box1.css Wed Jun 4 15:37:11 2008
@@ -0,0 +1,5 @@
+.title {
+ color: red;
+ font-size: 2em;
+ border: 10px;
+}
Added: trunk/tests/box2.css
==============================================================================
--- (empty file)
+++ trunk/tests/box2.css Wed Jun 4 15:37:11 2008
@@ -0,0 +1,4 @@
+.title {
+ color: green;
+ border: 20px;
+}
Added: trunk/tests/test-box-theme.py
==============================================================================
--- (empty file)
+++ trunk/tests/test-box-theme.py Wed Jun 4 15:37:11 2008
@@ -0,0 +1,40 @@
+import pygtk
+pygtk.require('2.0')
+import gtk
+import hippo
+
+window = gtk.Window()
+window.connect("destroy", lambda w: gtk.main_quit())
+
+canvas = hippo.Canvas()
+window.add(canvas)
+canvas.show()
+
+root = hippo.CanvasBox()
+canvas.set_root(root)
+canvas.set_size_request(400, 400)
+
+box1 = hippo.CanvasBox()
+
+theme1 = hippo.CanvasTheme(theme_stylesheet="box1.css")
+
+text = hippo.CanvasText(text="Box 1 theme", classes="title")
+box1.append(text)
+
+box1.set_theme(theme1)
+
+root.append(box1)
+
+box2 = hippo.CanvasBox()
+
+theme2 = hippo.CanvasTheme(theme_stylesheet="box2.css")
+box2.set_theme(theme2)
+
+text = hippo.CanvasText(text="Box 2 theme", classes="title")
+box2.append(text)
+
+root.append(box2)
+
+window.show()
+
+gtk.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]