summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Bosveld <Joel.Bosveld@gmail.com>2008-06-03 21:58:39 +0800
committerJoel Bosveld <Joel.Bosveld@gmail.com>2008-06-03 21:58:39 +0800
commit83e6505939e3b38332cb68588c00fe786f72fdc6 (patch)
tree3d2221eccbc34b62f032cc85fe1d734cf29c3559
parenta3cf3f0c7e969a70c1ef4124498d1831b44b22aa (diff)
downloadjasper-83e6505939e3b38332cb68588c00fe786f72fdc6.tar.gz
jasper-83e6505939e3b38332cb68588c00fe786f72fdc6.tar.bz2
Update text on propertyChangeNotify
-rw-r--r--plugins/text.c58
1 files changed, 47 insertions, 11 deletions
diff --git a/plugins/text.c b/plugins/text.c
index 4cfb02b..c84862a 100644
--- a/plugins/text.c
+++ b/plugins/text.c
@@ -60,19 +60,20 @@ typedef struct _TextCore
Atom nameAtom;
Atom XA_UTF8_STRING;
- mainLoopInitProc mainLoopInit;
+ mainLoopInitProc mainLoopInit;
+ handleEventProc handleEvent;
} TextCore;
typedef struct _TextWindow
{
int buttonPrivateIndex; //XXX - this is important (it must be here) - see below
+ char *title;
} TextWindow;
typedef struct _TextButton
{
int buttonPrivateIndex; //XXX - this is important (it must be here) - so we can use BW instead of BB when creating the children of frame-button
- char *title;
char *font;
double fontSize;
@@ -80,7 +81,7 @@ typedef struct _TextButton
} TextButton;
static char
-*getName (JasperWindow *w, int width)
+*getName (JasperWindow *w)
{
Atom type;
int format;
@@ -121,6 +122,7 @@ textDrawDecoration (JasperWindow *w, JasperButton *b)
{
BUTTONS_BUTTON (b);
TEXT_BUTTON (b);
+ TEXT_WINDOW (w);
UNWRAP (tb, b, drawDecoration);
b->drawDecoration (w,b);
@@ -138,10 +140,14 @@ textDrawDecoration (JasperWindow *w, JasperButton *b)
decor_compute_quad_box (&bb->quad, w->width, w->height, &x1, &y1, &x2, &y2, &sx, &sy);
/* This is obviously not finished - as with alot of the quad stuff, it is not completely handled */
-
+ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+ cairo_rectangle (cr, bb->quad.m.x0, bb->quad.m.y0, sx*(x2-x1), sy*(y2-y1));
+ cairo_fill (cr);
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
cairo_text_extents_t extents;
- char *s = getName(w, sx*(x2-x1)); //This will return the name of appropriate size
+ char *s = tw->title; //This should return the name of appropriate size - need another function
double x,y;
cairo_select_font_face (cr, tb->font,
@@ -158,8 +164,29 @@ textDrawDecoration (JasperWindow *w, JasperButton *b)
cairo_surface_destroy (surface);
cairo_destroy (cr);
+}
+
+static void
+textHandleEvent (JasperCore *core, XEvent *event)
+{
+ TEXT_CORE (core);
- free(s);
+ UNWRAP (tc, core, handleEvent);
+ core->handleEvent (core, event);
+ WRAP (tc, core, handleEvent, textHandleEvent);
+
+ if(event->type == PropertyNotify)
+ {
+ JasperWindow *w;
+ for(w=(JasperWindow *)core->base.children;w;w=(JasperWindow *)w->base.next) if(w->id == event->xproperty.window) break;
+
+ if(w)
+ {
+ TEXT_WINDOW (w);
+ if(tw->title) free(tw->title);
+ tw->title = getName(w);
+ }
+ }
}
static void
@@ -197,7 +224,6 @@ textInitButton (JasperButton *button)
tb->buttonPrivateIndex = allocatePrivateIndex ((JasperObject *) button);
if(tb->buttonPrivateIndex < 0) return false; //ERROR
- tb->title = NULL;
tb->drawDecoration = NULL;
tb->fontSize = 12;
tb->font = NULL;
@@ -228,7 +254,6 @@ textFiniButton (JasperButton *button)
{
TEXT_BUTTON (button);
- if(tb->title) free(tb->title);
free(tb->font);
if(button->drawDecoration)
@@ -243,10 +268,17 @@ textInitWindow (JasperWindow *window)
{
TEXT_CORE (window->base.parent);
+ JasperCore *c = (JasperCore *) window->base.parent;
+ XWindowAttributes attrib;
+ XGetWindowAttributes (c->display, window->id, &attrib);
+ XSelectInput(c->display, window->id, attrib.your_event_mask | PropertyChangeMask);
+
window->base.privates[tc->windowPrivateIndex].ptr=malloc (sizeof(TextWindow));
TEXT_WINDOW (window);
-
+
+ tw->title = getName (window);
+
tw->buttonPrivateIndex = allocatePrivateIndex ((JasperObject *) window);
if(tw->buttonPrivateIndex < 0) return false; //ERROR
@@ -257,6 +289,8 @@ static void
textFiniWindow (JasperWindow *window)
{
TEXT_WINDOW (window);
+
+ if(tw->title) free(tw->title);
freePrivateIndex ((JasperObject *) window, tw->buttonPrivateIndex);
free(tw);
@@ -273,7 +307,8 @@ textInitCore (JasperCore *core)
if(tc->windowPrivateIndex < 0) return false; //ERROR
WRAP (tc, core, mainLoopInit, coreMainLoopInit);
-
+ WRAP (tc, core, handleEvent, textHandleEvent);
+
return true;
}
@@ -282,7 +317,8 @@ textFiniCore (JasperCore *core)
{
TEXT_CORE (core);
- UNWRAP (tc, core, mainLoopInit);
+ UNWRAP (tc, core, mainLoopInit);
+ UNWRAP (tc, core, handleEvent);
freePrivateIndex ((JasperObject *) core, tc->windowPrivateIndex);
free(tc);