1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 20:38:08 +01:00

changes related to plugin system & drawstring

This commit is contained in:
id
2000-12-11 03:10:26 +00:00
parent 2d063d279e
commit 8ca4a67a24
11 changed files with 282 additions and 96 deletions

View File

@@ -37,8 +37,7 @@ typedef struct __FreeTypeData{
RColor color; RColor color;
WMFreeTypeRImage **glyphs_array; WMFreeTypeRImage **glyphs_array;
WMFreeTypeRImage **glyphs_shadow_array; WMFreeTypeRImage **glyphs_shadow_array;
/* will use this when we have frame window plugin */ void (*strwidth)();
/* char *last_titlestr; */
} WMFreeTypeData; } WMFreeTypeData;
#endif /* USE_FREETYPE */ #endif /* USE_FREETYPE */
@@ -60,14 +59,15 @@ initDrawPlainString(Display *dpy, Colormap *cmap) {
} }
void void
destroyDrawPlainString(proplist_t pl, void **func_data) { destroyDrawPlainString(proplist_t pl, WPluginData *func_data) {
return; return;
} }
/* FIX FIX FIX */
void void
drawPlainString (proplist_t pl, Drawable d, drawPlainString (proplist_t pl, Drawable d,
int x, int y, unsigned width, unsigned height, int x, int y, unsigned width, unsigned height,
char *text, void **func_data) char *text, WPluginData *func_data)
{ {
XColor color1, color2, color3, color4; XColor color1, color2, color3, color4;
char *plcolor; char *plcolor;
@@ -78,8 +78,8 @@ drawPlainString (proplist_t pl, Drawable d,
WMFont *font; WMFont *font;
length = strlen(text); length = strlen(text);
gc = func_data[0]; gc = func_data->array[2];
font = func_data[1]; font = func_data->array[3];
/* /*
@@ -188,15 +188,43 @@ WMFreeTypeRImage *renderChar(FT_Face face, FT_ULong char_index, RColor *color) {
return tmp_data; return tmp_data;
} }
void
widthOfFreeTypeString (unsigned char *text, int length, WPluginData *func_data,
int *width, int *height, int *top) {
WMFreeTypeData *data;
RImage *rimg;
int i;
/* see framewin.c for the order of arguments (look in wPluginPackData) */
data = ((WPluginData*)func_data->array[0])->array[2]; /* initialized data */
if (width) *width = 0;
/* may finish height & top later if they really are neccessary */
/* create temp for drawing */
for (i = 0; i < length; i++) {
if (!data->glyphs_array[text[i]]) {
data->glyphs_array[text[i]] = renderChar(data->face, (FT_ULong)text[i], &data->color);
data->glyphs_shadow_array[text[i]] = renderChar(data->face, (FT_ULong)text[i], &black_color);
}
if (data->glyphs_array[text[i]])
if (data->glyphs_array[text[i]]->image) {
if (width)
*width += data->glyphs_array[text[i]]->advance_x >> 6;
}
}
}
/* drawFreeTypeString */ /* drawFreeTypeString */
void initDrawFreeTypeString(proplist_t pl, void **init_data) { void initDrawFreeTypeString(proplist_t pl, WPluginData *init_data) {
WMFreeTypeData *data; WMFreeTypeData *data;
XColor xcolor; XColor xcolor;
_debug("invoke initDrawFreeTypeString with init_data[3] %s\n", init_data[3]); _debug("invoke initDrawFreeTypeString with init_data[3] %s\n",
init_data->array[2]);
_debug("%x is ds_dpy\n", ds_dpy); _debug("%x is ds_dpy\n", ds_dpy);
initDrawPlainString((Display *)init_data[1], (Colormap *)init_data[2]); initDrawPlainString((Display *)init_data->array[0], (Colormap *)init_data->array[1]);
_debug("then %x is ds_dpy\n", ds_dpy); _debug("then %x is ds_dpy\n", ds_dpy);
/* set init_data[2] to array of RImage */ /* set init_data[2] to array of RImage */
@@ -205,8 +233,8 @@ void initDrawFreeTypeString(proplist_t pl, void **init_data) {
* this would better to have sharable font system but * this would better to have sharable font system but
* I want to see this more in WINGs though -- ]d * I want to see this more in WINGs though -- ]d
*/ */
init_data[3] = malloc(sizeof(WMFreeTypeData)); init_data->array[2] = malloc(sizeof(WMFreeTypeData));
data = init_data[3]; data = init_data->array[2];
getColor(PLGetString(PLGetArrayElement(pl, 3)), ds_cmap, &xcolor); getColor(PLGetString(PLGetArrayElement(pl, 3)), ds_cmap, &xcolor);
data->color.red = xcolor.red >> 8; data->color.red = xcolor.red >> 8;
data->color.green = xcolor.green >> 8; data->color.green = xcolor.green >> 8;
@@ -216,6 +244,7 @@ void initDrawFreeTypeString(proplist_t pl, void **init_data) {
memset(data->glyphs_array, 0, sizeof(WMFreeTypeRImage*) * MAX_GLYPHS); memset(data->glyphs_array, 0, sizeof(WMFreeTypeRImage*) * MAX_GLYPHS);
data->glyphs_shadow_array = malloc(sizeof(WMFreeTypeRImage*) * MAX_GLYPHS); data->glyphs_shadow_array = malloc(sizeof(WMFreeTypeRImage*) * MAX_GLYPHS);
memset(data->glyphs_shadow_array, 0, sizeof(WMFreeTypeRImage*) * MAX_GLYPHS); memset(data->glyphs_shadow_array, 0, sizeof(WMFreeTypeRImage*) * MAX_GLYPHS);
data->strwidth = widthOfFreeTypeString;
if (!rc) { if (!rc) {
RContextAttributes rcattr; RContextAttributes rcattr;
@@ -239,11 +268,11 @@ void initDrawFreeTypeString(proplist_t pl, void **init_data) {
} }
void void
destroyDrawFreeTypeString(proplist_t pl, void **func_data) { destroyDrawFreeTypeString(proplist_t pl, WPluginData *func_data) {
int i; /* error? no no no */ int i; /* error? no no no */
WMFreeTypeData *data; WMFreeTypeData *data;
data = (WMFreeTypeData *) func_data[3]; data = (WMFreeTypeData *) func_data->array[2];
for (i = 0; i < MAX_GLYPHS; i++) { for (i = 0; i < MAX_GLYPHS; i++) {
if (data->glyphs_array[i]) { if (data->glyphs_array[i]) {
if (data->glyphs_array[i]->image) if (data->glyphs_array[i]->image)
@@ -305,10 +334,11 @@ logicalCombineArea(RImage *bg, RImage *image,
} }
} }
void void
drawFreeTypeString (proplist_t pl, Drawable d, drawFreeTypeString (proplist_t pl, Drawable d,
int x, int y, int x, int y,
unsigned char *text, int length, void **func_data) { unsigned char *text, int length, WPluginData *func_data) {
WMFreeTypeData *data; WMFreeTypeData *data;
RImage *rimg; RImage *rimg;
int i, j, width, height; int i, j, width, height;
@@ -318,16 +348,16 @@ drawFreeTypeString (proplist_t pl, Drawable d,
Window wdummy; Window wdummy;
/* see framewin.c for the order of arguments (look in wPluginPackData) */ /* see framewin.c for the order of arguments (look in wPluginPackData) */
data = ((void **)func_data[1])[3]; /* initialized data */ data = ((WPluginData*)func_data->array[0])->array[2]; /* initialized data */
if (func_data[2]) if (func_data->array[1])
pixmap = *(Pixmap *)func_data[2]; pixmap = *(Pixmap *)func_data->array[1];
gc = *(GC *)func_data[3]; gc = *(GC *)func_data->array[2];
width = *(int *)func_data[5]; width = *(int *)func_data->array[4];
height = *(int *)func_data[6]; height = *(int *)func_data->array[5];
/* create temp for drawing */ /* create temp for drawing */
if (!func_data[2]) { if (!func_data->array[1]) {
XGetGeometry(ds_dpy, d, &wdummy, &dummy, &dummy, &xwidth, &xheight, &dummy, &dummy); XGetGeometry(ds_dpy, d, &wdummy, &dummy, &dummy, &xwidth, &xheight, &dummy, &dummy);
pixmap = XCreatePixmap(ds_dpy, d, xwidth, xheight, DefaultDepth(ds_dpy, DefaultScreen(ds_dpy))); pixmap = XCreatePixmap(ds_dpy, d, xwidth, xheight, DefaultDepth(ds_dpy, DefaultScreen(ds_dpy)));
XClearWindow(ds_dpy, d); XClearWindow(ds_dpy, d);
@@ -368,13 +398,6 @@ drawFreeTypeString (proplist_t pl, Drawable d,
XFreePixmap(ds_dpy, pixmap); XFreePixmap(ds_dpy, pixmap);
RDestroyImage(rimg); RDestroyImage(rimg);
/*
_debug("%d\n", height);
i = (height + data->face->size->metrics.y_ppem)/2 - data->face->size->metrics.y_ppem;
XDrawLine(ds_dpy, d, gc, 5, y + i, 100, y + data->face->size->metrics.y_ppem);
XDrawLine(ds_dpy, d, gc, 100, y + i, 5, y + data->face->size->metrics.y_ppem);
*/
} }
} }
@@ -383,18 +406,27 @@ drawFreeTypeString (proplist_t pl, Drawable d,
/* core */ /* core */
void void
destroyDrawString (proplist_t pl, void **init_data) { destroyDrawString (proplist_t pl, WPluginData *init_data) {
if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawPlainString") == 0) if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawPlainString") == 0)
destroyDrawPlainString((Display *)init_data[0], NULL); destroyDrawPlainString((Display *)init_data->array[0], NULL);
else if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawFreeTypeString") == 0) else if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawFreeTypeString") == 0)
destroyDrawFreeTypeString(pl, init_data); destroyDrawFreeTypeString(pl, init_data);
} }
void void
initDrawString (proplist_t pl, void **init_data) { widthOfString (unsigned char *text, int length, WPluginData *func_data,
int *width, int *height, int *top) {
WMFreeTypeData *data;
data = ((WPluginData*)func_data->array[0])->array[2];
data->strwidth(text, length, func_data, width, height, top);
}
void
initDrawString (proplist_t pl, WPluginData *init_data) {
_debug("invoke initDrawString: %s\n", PLGetString(PLGetArrayElement(pl, 2))); _debug("invoke initDrawString: %s\n", PLGetString(PLGetArrayElement(pl, 2)));
if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawPlainString") == 0) if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawPlainString") == 0)
initDrawPlainString((Display *)init_data[1], (Colormap *)init_data[2]); initDrawPlainString((Display *)init_data->array[0], (Colormap *)init_data->array[1]);
#ifdef USE_FREETYPE #ifdef USE_FREETYPE
else if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawFreeTypeString") == 0) else if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawFreeTypeString") == 0)
initDrawFreeTypeString(pl, init_data); initDrawFreeTypeString(pl, init_data);

View File

@@ -22,6 +22,9 @@
* $Id$ * $Id$
* *
* $Log$ * $Log$
* Revision 1.3 2000/12/11 03:10:26 id
* changes related to plugin system & drawstring
*
* Revision 1.2 2000/12/03 22:18:20 id * Revision 1.2 2000/12/03 22:18:20 id
* initiate * initiate
* *
@@ -41,6 +44,11 @@
#include <wraster.h> #include <wraster.h>
typedef struct _WPluginData {
int size;
void **array;
} WPluginData;
extern void initWindowMaker (Display *d, Colormap c); extern void initWindowMaker (Display *d, Colormap c);
extern int start_image (const char *name, int argc, int argc_min, int argc_max, extern int start_image (const char *name, int argc, int argc_min, int argc_max,
int width, int height, RImage **image); int width, int height, RImage **image);

View File

@@ -2213,7 +2213,9 @@ getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
if (!elem || !PLIsString(elem)) return False; if (!elem || !PLIsString(elem)) return False;
func = PLGetString(elem); func = PLGetString(elem);
scr->drawstring_func[changed] = wPluginCreateFunction(W_FUNCTION_DRAWSTRING, scr->drawstring_func[changed] = wPluginCreateFunction(W_FUNCTION_DRAWSTRING,
lib, "initDrawString", func, "destroyDrawString", value, lib, "initDrawString",
wPluginPackData(2, func, "widthOfString"),
"destroyDrawString", value,
wPluginPackData(3, dpy, &scr->w_colormap, "dummy")); wPluginPackData(3, dpy, &scr->w_colormap, "dummy"));
} }

View File

@@ -947,9 +947,11 @@ wFrameWindowPaint(WFrameWindow *fwin)
{ {
WScreen *scr = fwin->screen_ptr; WScreen *scr = fwin->screen_ptr;
#ifdef DRAWSTRING_PLUGIN #ifdef DRAWSTRING_PLUGIN
#define DRAWSTRING_CURRENT_STATE fwin->flags.state + fwin->drawstring_proc_offset
Pixmap *background; Pixmap *background;
Pixmap tmp_bg; Pixmap tmp_bg;
int tb = fwin->top_width; int tb = fwin->top_width;
WPluginData *pd;
#endif #endif
if (fwin->flags.is_client_window_frame) if (fwin->flags.is_client_window_frame)
@@ -1083,11 +1085,28 @@ wFrameWindowPaint(WFrameWindow *fwin)
scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode]; scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
#endif #endif
#ifdef DRAWSTRING_PLUGIN
if(scr->drawstring_func[DRAWSTRING_CURRENT_STATE]) {
title = ShrinkString(*fwin->font, fwin->title,
fwin->titlebar->width - lofs - rofs,
scr->drawstring_func[DRAWSTRING_CURRENT_STATE]);
titlelen = strlen(title);
pd = wPluginPackData(1, scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->data);
scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->proc.widthOfString[W_DSPROC_WIDTHOFSTRING](
title, titlelen, pd, &w, NULL, NULL);
wfree(pd);
} else {
title = ShrinkString(*fwin->font, fwin->title,
fwin->titlebar->width - lofs - rofs, NULL);
titlelen = strlen(title);
w = WMWidthOfString(*fwin->font, title, titlelen);
}
#else
title = ShrinkString(*fwin->font, fwin->title, title = ShrinkString(*fwin->font, fwin->title,
fwin->titlebar->width - lofs - rofs); fwin->titlebar->width - lofs - rofs);
titlelen = strlen(title); titlelen = strlen(title);
w = WMWidthOfString(*fwin->font, title, titlelen); w = WMWidthOfString(*fwin->font, title, titlelen);
#endif
switch (fwin->flags.justification) { switch (fwin->flags.justification) {
case WTJ_LEFT: case WTJ_LEFT:
x = lofs; x = lofs;
@@ -1109,28 +1128,25 @@ wFrameWindowPaint(WFrameWindow *fwin)
fwin->title_pixel[fwin->flags.state]); fwin->title_pixel[fwin->flags.state]);
#ifdef DRAWSTRING_PLUGIN #ifdef DRAWSTRING_PLUGIN
#define DRAWSTRING_CURRENT_STATE fwin->flags.state + fwin->drawstring_proc_offset /* if the plugin want to do shrinking locally, they can trick
* wmaker by returning a very short value (such as 0) to widthOfString -- I think */
if (scr->drawstring_func[DRAWSTRING_CURRENT_STATE]) { if (scr->drawstring_func[DRAWSTRING_CURRENT_STATE]) {
void **p; pd = wPluginPackData(6, /* number of argument, will be passed */
p = wPluginPackData(6,
/* 0 number of argument, will be passed */
scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->data, scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->data,
/* 1 plugin data, as it was initialized */ /* 0 plugin data, as it was initialized */
background, background, /* 1 current background Pixmap */
/* 2 current background Pixmap */ fwin->title_gc, /* 2 gc */
fwin->title_gc, /* 3 gc */ *fwin->font, /* 3 WMFont** */
*fwin->font, /* 4 WMFont** */
&fwin->titlebar->width, &fwin->titlebar->width,
/* 5 suggested width */ /* 4 suggested width */
&tb /* 6 suggested height */ &tb /* 5 suggested height */
); );
scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->proc.drawString( scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->proc.drawString[W_DSPROC_DRAWSTRING](
scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->arg, scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->arg,
fwin->titlebar->window, fwin->titlebar->window,
x, 0, x, 0,
fwin->title, strlen(fwin->title), p); title, strlen(fwin->title), pd);
free(p); wfree(pd);
} else { } else {
WMDrawString(scr->wmscreen, fwin->titlebar->window, WMDrawString(scr->wmscreen, fwin->titlebar->window,
*fwin->title_gc, *fwin->font, *fwin->title_gc, *fwin->font,

View File

@@ -26,6 +26,9 @@
#include <stdio.h> #include <stdio.h>
#include "window.h" #include "window.h"
#ifdef DRAWSTRING_PLUGIN
#include "plugin.h"
#endif
typedef void (WCallBack)(void *cdata); typedef void (WCallBack)(void *cdata);
@@ -116,7 +119,11 @@ WWindow *NextToFocusBefore(WWindow *wwin);
void SlideWindow(Window win, int from_x, int from_y, int to_x, int to_y); void SlideWindow(Window win, int from_x, int from_y, int to_x, int to_y);
#ifdef DRAWSTRING_PLUGIN
char *ShrinkString(WMFont *font, char *string, int width, WFunction *func);
#else
char *ShrinkString(WMFont *font, char *string, int width); char *ShrinkString(WMFont *font, char *string, int width);
#endif
char *FindImage(char *paths, char *file); char *FindImage(char *paths, char *file);

View File

@@ -824,8 +824,13 @@ wIconPaint(WIcon *icon)
int l; int l;
int w; int w;
#ifdef DRAWSTRING_PLUGIN
tmp = ShrinkString(scr->icon_title_font, icon->icon_name,
wPreferences.icon_size-4, NULL);
#else
tmp = ShrinkString(scr->icon_title_font, icon->icon_name, tmp = ShrinkString(scr->icon_title_font, icon->icon_name,
wPreferences.icon_size-4); wPreferences.icon_size-4);
#endif
w = WMWidthOfString(scr->icon_title_font, tmp, l=strlen(tmp)); w = WMWidthOfString(scr->icon_title_font, tmp, l=strlen(tmp));
if (w > icon->core->width - 4) if (w > icon->core->width - 4)

View File

@@ -731,6 +731,14 @@ paintEntry(WMenu *menu, int index, int selected)
WScreen *scr=menu->frame->screen_ptr; WScreen *scr=menu->frame->screen_ptr;
Window win = menu->menu->window; Window win = menu->menu->window;
WMenuEntry *entry=menu->entries[index]; WMenuEntry *entry=menu->entries[index];
#ifdef DRAWSTRING_PLUGIN
Pixmap tmp_bg;
Pixmap *texture_data;
WPluginData *p;
int _y;
int tb = menu->entry_height; /* convert short into int */
#endif
if (!menu->flags.realized) return; if (!menu->flags.realized) return;
h = menu->entry_height; h = menu->entry_height;
@@ -800,12 +808,6 @@ paintEntry(WMenu *menu, int index, int selected)
#ifdef DRAWSTRING_PLUGIN #ifdef DRAWSTRING_PLUGIN
if (scr->drawstring_func[W_STRING_MTEXT]) { if (scr->drawstring_func[W_STRING_MTEXT]) {
Pixmap tmp_bg;
Pixmap *texture_data;
void **p;
int _y;
int tb = menu->entry_height; /* convert short into int */
_y = (wPreferences.menu_style == MS_NORMAL) ? 0 : y; _y = (wPreferences.menu_style == MS_NORMAL) ? 0 : y;
texture_data = menu->flags.brother ? texture_data = menu->flags.brother ?
&menu->brother->menu_texture_data : &menu->menu_texture_data; &menu->brother->menu_texture_data : &menu->menu_texture_data;
@@ -835,10 +837,9 @@ paintEntry(WMenu *menu, int index, int selected)
&textGC, &textGC,
scr->menu_entry_font, scr->menu_entry_font,
&menu->frame->core->width, &menu->frame->core->width,
&tb, &tb, "extendable");
"extendable");
scr->drawstring_func[W_STRING_MTEXT]->proc.drawString( scr->drawstring_func[W_STRING_MTEXT]->proc.drawString[W_DSPROC_DRAWSTRING](
scr->drawstring_func[W_STRING_MTEXT]->arg, scr->drawstring_func[W_STRING_MTEXT]->arg,
win, win,
x, y, x, y,
@@ -908,12 +909,55 @@ paintEntry(WMenu *menu, int index, int selected)
/* draw right text */ /* draw right text */
if (entry->rtext && entry->cascade<0) { if (entry->rtext && entry->cascade<0) {
#ifdef DRAWSTRING_PLUGIN
if (scr->drawstring_func[W_STRING_MTEXT]) {
/*
p = wPluginPackData(1, scr->drawstring_func[W_STRING_MTEXT]->data);
scr->drawstring_func[W_STRING_MTEXT]->proc.widthOfString[W_DSPROC_WIDTHOFSTRING](
entry->rtext, strlen(entry->rtext), p, &tw, NULL, NULL);
wfree(p);
texture_data = menu->flags.brother ?
&menu->brother->menu_texture_data : &menu->menu_texture_data;
tmp_bg = XCreatePixmap(dpy, win, w, menu->entry_height,
DefaultDepth(dpy, DefaultScreen(dpy)));
XCopyArea(dpy, win, tmp_bg, textGC,
0, y, w, menu->entry_height, 0, 0);
p = wPluginPackData(6,
scr->drawstring_func[W_STRING_MTEXT]->data,
&tmp_bg,
&textGC,
scr->menu_entry_font,
&menu->frame->core->width,
&tb, "extendable");
scr->drawstring_func[W_STRING_MTEXT]->proc.drawString[W_DSPROC_DRAWSTRING](
scr->drawstring_func[W_STRING_MTEXT]->arg,
win,
w-0-tw, y,
entry->rtext, strlen(entry->rtext), p);
XFreePixmap(dpy, tmp_bg);
free(p);
*/
} else {
tw = WMWidthOfString(scr->menu_entry_font, entry->rtext, tw = WMWidthOfString(scr->menu_entry_font, entry->rtext,
strlen(entry->rtext)); strlen(entry->rtext));
WMDrawString(scr->wmscreen, win, textGC, scr->menu_entry_font, w-6-tw, WMDrawString(scr->wmscreen, win, textGC, scr->menu_entry_font, w-6-tw,
y + 3 + wPreferences.menu_text_clearance, entry->rtext, strlen(entry->rtext)); y + 3 + wPreferences.menu_text_clearance, entry->rtext, strlen(entry->rtext));
} }
#else
tw = WMWidthOfString(scr->menu_entry_font, entry->rtext,
strlen(entry->rtext));
WMDrawString(scr->wmscreen, win, textGC, scr->menu_entry_font, w-6-tw,
y + 3 + wPreferences.menu_text_clearance, entry->rtext, strlen(entry->rtext));
#endif
}
} }

View File

@@ -48,6 +48,7 @@
#include "dialog.h" #include "dialog.h"
#include "xutil.h" #include "xutil.h"
#include "xmodifier.h" #include "xmodifier.h"
#include "plugin.h"
/**** global variables *****/ /**** global variables *****/
@@ -420,23 +421,45 @@ SlideWindow(Window win, int from_x, int from_y, int to_x, int to_y)
char* char*
#ifdef DRAWSTRING_PLUGIN
ShrinkString(WMFont *font, char *string, int width, WFunction *func)
#else
ShrinkString(WMFont *font, char *string, int width) ShrinkString(WMFont *font, char *string, int width)
#endif
{ {
int w, w1=0; int w, w1=0;
int p; int p;
char *pos; char *pos;
char *text; char *text;
int p1, p2, t; int p1, p2, t;
#ifdef DRAWSTRING_PLUGIN
WPluginData *pd;
#endif
if (wPreferences.multi_byte_text) if (wPreferences.multi_byte_text)
return wstrdup(string); return wstrdup(string);
p = strlen(string); p = strlen(string);
#ifdef DRAWSTRING_PLUGIN
if (func) {
pd = wPluginPackData(1, func->data);
func->proc.widthOfString[W_DSPROC_WIDTHOFSTRING](
string, strlen(string), pd, &w, NULL, NULL);
} else w = WMWidthOfString(font, string, p);
#else
w = WMWidthOfString(font, string, p); w = WMWidthOfString(font, string, p);
#endif
text = wmalloc(strlen(string)+8); text = wmalloc(strlen(string)+8);
strcpy(text, string); strcpy(text, string);
if (w<=width) if (w<=width)
#ifdef DRAWSTRING_PLUGIN
{
if (func) wfree(pd);
return text; return text;
}
#else
return text;
#endif
pos = strchr(text, ' '); pos = strchr(text, ' ');
if (!pos) if (!pos)
@@ -445,7 +468,14 @@ ShrinkString(WMFont *font, char *string, int width)
if (pos) { if (pos) {
*pos = 0; *pos = 0;
p = strlen(text); p = strlen(text);
#ifdef DRAWSTRING_PLUGIN
if (func) {
func->proc.widthOfString[W_DSPROC_WIDTHOFSTRING](
text, strlen(text), pd, &w1, NULL, NULL);
} else w1 = WMWidthOfString(font, text, p);
#else
w1 = WMWidthOfString(font, text, p); w1 = WMWidthOfString(font, text, p);
#endif
if (w1 > width) { if (w1 > width) {
w1 = 0; w1 = 0;
p = 0; p = 0;
@@ -462,14 +492,28 @@ ShrinkString(WMFont *font, char *string, int width)
*text=0; *text=0;
} }
strcat(text, "..."); strcat(text, "...");
#ifdef DRAWSTRING_PLUGIN
if (func) {
func->proc.widthOfString[W_DSPROC_WIDTHOFSTRING](
"...", 3, pd, &w1, NULL, NULL);
} else w1 = WMWidthOfString(font, "...", 3);
width -= w1;
#else
width -= WMWidthOfString(font, "...", 3); width -= WMWidthOfString(font, "...", 3);
#endif
pos = string; pos = string;
p1=0; p1=0;
p2=p; p2=p;
t = (p2-p1)/2; t = (p2-p1)/2;
while (p2>p1 && p1!=t) { while (p2>p1 && p1!=t) {
#ifdef DRAWSTRING_PLUGIN
if (func) {
func->proc.widthOfString[W_DSPROC_WIDTHOFSTRING](
&string[p-t], t, pd, &w, NULL, NULL);
} else w = WMWidthOfString(font, &string[p-t], t);
#else
w = WMWidthOfString(font, &string[p-t], t); w = WMWidthOfString(font, &string[p-t], t);
#endif
if (w>width) { if (w>width) {
p2 = t; p2 = t;
t = p1+(p2-p1)/2; t = p1+(p2-p1)/2;
@@ -479,6 +523,9 @@ ShrinkString(WMFont *font, char *string, int width)
} else } else
p2=p1=t; p2=p1=t;
} }
#ifdef DRAWSTRING_PLUGIN
if (func) wfree(pd);
#endif
strcat(text, &string[p-p1]); strcat(text, &string[p-p1]);
return text; return text;

View File

@@ -45,30 +45,33 @@
#include <proplist.h> #include <proplist.h>
void** WPluginData*
wPluginPackData(int members, ...) wPluginPackData(int members, ...)
{ {
void **p; void **p;
va_list vp; va_list vp;
int i; int i;
p = wmalloc(sizeof(void *) * (members + 1)); WPluginData *data;
memset(p, 0, sizeof(void *) * (members + 1)); data = wmalloc(sizeof(WPluginData));
p[0] = (void *)members; data->size = members;
data->array = wmalloc(sizeof(void *) * (members));
memset(data->array, 0, sizeof(void *) * (members));
va_start(vp, members); va_start(vp, members);
for(i=1;i<members+1;i++) { for(i=0;i<members;i++) {
p[i] = va_arg(vp, void *); data->array[i] = va_arg(vp, void *);
} }
va_end(vp); va_end(vp);
return p; return data;
} }
WFunction * WFunction *
wPluginCreateFunction(int type, char *library_name, wPluginCreateFunction(int type, char *library_name,
char *init_proc_name, char *proc_name, char *free_data_proc_name, char *init_proc_name, WPluginData *proc_name, char *free_data_proc_name,
proplist_t pl_arg, void *init_data) proplist_t pl_arg, WPluginData *init_data)
{ {
WFunction *function; WFunction *function;
_DL_InitDataProc *initProc; _DL_InitDataProc *initProc;
int i;
function = wmalloc(sizeof(WFunction)); function = wmalloc(sizeof(WFunction));
memset(function, 0, sizeof(WFunction)); memset(function, 0, sizeof(WFunction));
@@ -80,13 +83,18 @@ wPluginCreateFunction(int type, char *library_name,
return NULL; return NULL;
} }
function->proc.any = dlsym(function->handle, proc_name); i = proc_name->size;
if (!function->proc.any) { function->proc.any = wmalloc(sizeof(_DL_AnyProc) * i);
for (i = 0; i < proc_name->size; i++) {
function->proc.any[i] = dlsym(function->handle, (char *)proc_name->array[i]);
if (!function->proc.any[i]) {
wwarning(_("function \"%s\" not found in library \"%s\""), proc_name, library_name); wwarning(_("function \"%s\" not found in library \"%s\""), proc_name, library_name);
dlclose(function->handle); dlclose(function->handle);
wfree(function->proc.any);
wfree(function); wfree(function);
return NULL; return NULL;
} }
}
if (free_data_proc_name) { if (free_data_proc_name) {
function->freeData = dlsym(function->handle, free_data_proc_name); function->freeData = dlsym(function->handle, free_data_proc_name);
@@ -129,6 +137,7 @@ wPluginDestroyFunction(WFunction *function)
wfree(function->data); wfree(function->data);
} }
if (function->arg) PLRelease(function->arg); if (function->arg) PLRelease(function->arg);
if (function->proc.any) wfree(function->proc.any);
wfree(function); wfree(function);
return; return;
} }

View File

@@ -39,6 +39,11 @@
#define W_FUNCTION_ANY 0 #define W_FUNCTION_ANY 0
#define W_FUNCTION_DRAWSTRING 1 #define W_FUNCTION_DRAWSTRING 1
typedef struct _WPluginData {
int size;
void **array;
} WPluginData;
typedef void _DL_AnyProc(proplist_t); typedef void _DL_AnyProc(proplist_t);
/* first 3 must == WS_FOCUSED WS_UNFOCUSED WS_PFOCUSED -- ]d */ /* first 3 must == WS_FOCUSED WS_UNFOCUSED WS_PFOCUSED -- ]d */
@@ -50,27 +55,29 @@ typedef void _DL_AnyProc(proplist_t);
#define W_STRING_MTEXT 4 #define W_STRING_MTEXT 4
#define W_STRING_MEMBERS 5 #define W_STRING_MEMBERS 5
typedef void _DL_DrawStringProc(proplist_t, Drawable, int, int, char*, int, void**); typedef void _DL_DrawStringProc(proplist_t, Drawable, int, int, char*, int, WPluginData*);
typedef void _DL_WidthStringProc(char*, int, WPluginData*, int*, int*, int*);
#endif #endif
typedef void _DL_FreeDataProc(proplist_t pl, void *free_data); typedef void _DL_FreeDataProc(proplist_t pl, WPluginData *free_data);
typedef int _DL_InitDataProc(proplist_t pl, void *init_data); /* prototype typedef int _DL_InitDataProc(proplist_t pl, WPluginData *init_data);
for function /* prototype for function initializer */
initializer
*/ #define W_DSPROC_DRAWSTRING 0
#define W_DSPROC_WIDTHOFSTRING 1
#define W_DSPROC_MEMBERS 2
typedef struct _WFunction { typedef struct _WFunction {
int type; int type;
void *handle; void *handle;
proplist_t arg; proplist_t arg;
void *data; WPluginData *data;
_DL_FreeDataProc *freeData; _DL_FreeDataProc *freeData;
union { union {
_DL_AnyProc *any; _DL_AnyProc **any;
#ifdef DRAWSTRING_PLUGIN _DL_DrawStringProc **drawString;
_DL_DrawStringProc *drawString; _DL_WidthStringProc **widthOfString;
#endif
} proc; } proc;
/* /*
char *libraryName; char *libraryName;
@@ -90,11 +97,11 @@ typedef struct _WFunction {
*/ */
WFunction* wPluginCreateFunction(int type, char *library_name, WFunction* wPluginCreateFunction(int type, char *library_name,
char *init_proc_name, char *proc_name, char *free_data_proc_name, char *init_proc_name, WPluginData *funcs, char *free_data_proc_name,
proplist_t pl_arg, void *init_data); proplist_t pl_arg, WPluginData *init_data);
void wPluginDestroyFunction(WFunction *function); void wPluginDestroyFunction(WFunction *function);
void** wPluginPackData(int members, ...); WPluginData* wPluginPackData(int members, ...);
#endif #endif

View File

@@ -195,7 +195,12 @@ UpdateSwitchMenu(WScreen *scr, WWindow *wwin, int action)
sprintf(title, "%s", wwin->frame->title); sprintf(title, "%s", wwin->frame->title);
else else
sprintf(title, "%s", DEF_WINDOW_TITLE); sprintf(title, "%s", DEF_WINDOW_TITLE);
#ifdef DRAWSTRING_PLUGIN
t = ShrinkString(scr->menu_entry_font, title, MAX_WINDOWLIST_WIDTH,
scr->drawstring_func[W_STRING_MTEXT]);
#else
t = ShrinkString(scr->menu_entry_font, title, MAX_WINDOWLIST_WIDTH); t = ShrinkString(scr->menu_entry_font, title, MAX_WINDOWLIST_WIDTH);
#endif
if (IS_OMNIPRESENT(wwin)) if (IS_OMNIPRESENT(wwin))
idx = -1; idx = -1;
@@ -252,8 +257,12 @@ UpdateSwitchMenu(WScreen *scr, WWindow *wwin, int action)
else else
sprintf(title, "%s", DEF_WINDOW_TITLE); sprintf(title, "%s", DEF_WINDOW_TITLE);
t = ShrinkString(scr->menu_entry_font, title, #ifdef DRAWSTRING_PLUGIN
MAX_WINDOWLIST_WIDTH); t = ShrinkString(scr->menu_entry_font, title, MAX_WINDOWLIST_WIDTH,
scr->drawstring_func[W_STRING_MTEXT]);
#else
t = ShrinkString(scr->menu_entry_font, title, MAX_WINDOWLIST_WIDTH);
#endif
entry->text = t; entry->text = t;
wMenuRealize(switchmenu); wMenuRealize(switchmenu);