Exemplo n.º 1
0
static Bool WDMCheckPLGeometry(WMPropList *pl, void *def, void *target)
{
	WMRect *rect_target = (WMRect *)target;

	WDMDebug("WDMCheckPLGeometry(%p, %p, %p)\n", (void*)pl, def, target);

	if(def)
		memcpy(rect_target, def, sizeof(WMRect));

	if(pl != NULL && WMIsPLArray(pl))
	{
		WDMCheckPLUInteger(WMGetFromPLArray(pl, 0),
				(void*)rect_target->size.width,
				&rect_target->size.width);
		WDMCheckPLUInteger(WMGetFromPLArray(pl, 1),
				(void*)rect_target->size.height,
				&rect_target->size.height);
		WDMCheckPLInteger(WMGetFromPLArray(pl, 2),
				(void*)rect_target->pos.x,
				&rect_target->pos.x);
		WDMCheckPLInteger(WMGetFromPLArray(pl, 3),
				(void*)rect_target->pos.y,
				&rect_target->pos.y);
		return True;
	}
	return False;
}
Exemplo n.º 2
0
/*
 * WMArray *array;
 * WDMCheckPLArray(pl, spec, &array);
 */
Bool WDMCheckPLArray(WMPropList * pl, void *def, void *target)
{
	WMArray **array_target = (WMArray **) target;
	WDMArraySpec *spec = (WDMArraySpec *) def;
	void *entry = NULL;
	int i, count;

	WDMDebug("WDMCheckPLArray(%p, %p, %p)\n", (void *)pl, def, target);
	if (!pl || !WMIsPLArray(pl))
		return False;

	count = WMGetPropListItemCount(pl);
	*array_target = WMCreateArrayWithDestructor(count, spec->destructor);

	for (i = 0; i < count; ++i) {
		if (!(*spec->checker) (WMGetFromPLArray(pl, i), spec->data, &entry)) {
			WMFreeArray(*array_target);
			*array_target = NULL;
			return False;
		}
		if (spec->addnull == True || entry != NULL) {
			WMAddToArray(*array_target, entry);
		}
	}

	return True;
}
Exemplo n.º 3
0
void
hackPaths(WMPropList *style, char *prefix)
{
    WMPropList *keys;
    WMPropList *key;
    WMPropList *value;
    int i;


    keys = WMGetPLDictionaryKeys(style);

    for (i = 0; i < WMGetPropListItemCount(keys); i++) {
        key = WMGetFromPLArray(keys, i);

        value = WMGetFromPLDictionary(style, key);
        if (!value)
            continue;

        if (strcasecmp(WMGetFromPLString(key), "WorkspaceSpecificBack")==0) {
            if (WMIsPLArray(value)) {
                int j;
                WMPropList *texture;

                for (j = 0; j < WMGetPropListItemCount(value); j++) {
                    texture = WMGetFromPLArray(value, j);

                    if (texture && WMIsPLArray(texture)
                        && WMGetPropListItemCount(texture) > 2) {

                        hackPathInTexture(texture, prefix);
                    }
                }
            }
        } else {

            if (WMIsPLArray(value) && WMGetPropListItemCount(value) > 2) {

                hackPathInTexture(value, prefix);
            }
        }
    }

}
Exemplo n.º 4
0
static WEditMenu*
buildSubmenu(_Panel *panel, WMPropList *pl)
{
    WMScreen *scr = WMWidgetScreen(panel->parent);
    WEditMenu *menu;
    WEditMenuItem *item;
    char *title;
    WMPropList *tp, *bp;
    int i;

    tp = WMGetFromPLArray(pl, 0);
    title = WMGetFromPLString(tp);

    menu = WCreateEditMenu(scr, title);

    for (i = 1; i < WMGetPropListItemCount(pl); i++) {
        WMPropList *pi;

        pi = WMGetFromPLArray(pl, i);

        tp = WMGetFromPLArray(pi, 0);
        bp = WMGetFromPLArray(pi, 1);

        title = WMGetFromPLString(tp);

        if (!bp || WMIsPLArray(bp)) {	       /* it's a submenu */
            WEditMenu *submenu;

            submenu = buildSubmenu(panel, pi);

            item = WAddMenuItemWithTitle(menu, title);

            WSetEditMenuSubmenu(menu, item, submenu);
        } else {
            ItemData *data;

            item = WAddMenuItemWithTitle(menu, title);

            data = parseCommand(pi);

            if (panel->markerPix[data->type])
                WSetEditMenuItemImage(item, panel->markerPix[data->type]);
            WSetEditMenuItemData(item, data, (WMCallback*)freeItemData);
        }
    }

    WSetEditMenuAcceptsDrop(menu, True);
    WSetEditMenuDelegate(menu, &menuDelegate);

    WMRealizeWidget(menu);

    return menu;
}
Exemplo n.º 5
0
static void
showData(_Panel *panel)
{
    WMPropList *array, *val;
    int i;

    array = GetObjectForKey("IconPath");
    if (!array || !WMIsPLArray(array)) {
        if (array)
            wwarning(_("bad value in option IconPath. Using default path list"));
        addPathToList(panel->icoL, -1, "~/pixmaps");
        addPathToList(panel->icoL, -1, "~/GNUstep/Library/Icons");
        addPathToList(panel->icoL, -1, "/usr/include/X11/pixmaps");
        addPathToList(panel->icoL, -1, "/usr/local/share/WindowMaker/Icons");
        addPathToList(panel->icoL, -1, "/usr/local/share/WindowMaker/Pixmaps");
        addPathToList(panel->icoL, -1, "/usr/share/WindowMaker/Icons");
    } else {
        for (i=0; i<WMGetPropListItemCount(array); i++) {
            val = WMGetFromPLArray(array, i);
            addPathToList(panel->icoL, -1, WMGetFromPLString(val));
        }
    }

    array = GetObjectForKey("PixmapPath");
    if (!array || !WMIsPLArray(array)) {
        if (array)
            wwarning(_("bad value in option PixmapPath. Using default path list"));
        addPathToList(panel->pixL, -1, "~/pixmaps");
        addPathToList(panel->pixL, -1, "~/GNUstep/Library/WindowMaker/Pixmaps");
        addPathToList(panel->pixL, -1, "/usr/local/share/WindowMaker/Pixmaps");
    } else {
        for (i=0; i<WMGetPropListItemCount(array); i++) {
            val = WMGetFromPLArray(array, i);
            addPathToList(panel->pixL, -1, WMGetFromPLString(val));
        }
    }
}
Exemplo n.º 6
0
static void
showData(_Panel *panel)
{
    char *gspath;
    char *menuPath;
    WMPropList *pmenu;

    gspath = wusergnusteppath();

    menuPath = wmalloc(strlen(gspath)+32);
    strcpy(menuPath, gspath);
    strcat(menuPath, "/Defaults/WMRootMenu");

    pmenu = WMReadPropListFromFile(menuPath);

    if (!pmenu || !WMIsPLArray(pmenu)) {
        int res;

        res = WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent,
                              _("Warning"),
                              _("The menu file format currently in use is not supported\n"
                                "by this tool. Do you want to discard the current menu\n"
                                "to use this tool?"),
                              _("Yes, Discard and Update"),
                              _("No, Keep Current Menu"), NULL);

        if (res == WAPRDefault) {
            pmenu = getDefaultMenu(panel);

            if (!pmenu) {
                pmenu = WMCreatePLArray(WMCreatePLString("Applications"),
                                        NULL);
            }
        } else {
            panel->dontSave = True;
            return;
        }
    }

    panel->menuPath = menuPath;

    buildMenuFromPL(panel, pmenu);

    WMReleasePropList(pmenu);
}
Exemplo n.º 7
0
static void showData(_Panel * panel)
{
	const char *gspath;
	char *menuPath, *labelText;
	char buf[1024];
	WMPropList *pmenu;

	gspath = wusergnusteppath();

	menuPath = wmalloc(strlen(gspath) + 32);
	strcpy(menuPath, gspath);
	strcat(menuPath, "/Defaults/WMRootMenu");

	pmenu = WMReadPropListFromFile(menuPath);

	/* check if WMRootMenu references another file, and if so,
	   if that file is in proplist format */
	while (WMIsPLString(pmenu)) {
		char *path = NULL;

		path = wexpandpath(WMGetFromPLString(pmenu));

		if (access(path, F_OK) < 0)
			path = wfindfile(DEF_CONFIG_PATHS, path);

		/* TODO: if needed, concatenate locale suffix to path.
		   See getLocalizedMenuFile() in src/rootmenu.c. */

		if (!path)
			break;

		if (access(path, W_OK) < 0) {
			snprintf(buf, 1024,
				 _("The menu file \"%s\" referenced by "
				   "WMRootMenu is read-only.\n"
				   "You cannot use WPrefs to modify it."),
				 path);
			WMRunAlertPanel(WMWidgetScreen(panel->parent),
					panel->parent,
					_("Warning"), buf,
					_("OK"), NULL, NULL);
			panel->dontSave = True;
			wfree(path);
			return;
		}

		pmenu = WMReadPropListFromFile(path);
		menuPath = path;
	}

	if (!pmenu || !WMIsPLArray(pmenu)) {
		int res;

		res = WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent,
				      _("Warning"),
				      _("The menu file format currently in use is not supported\n"
					"by this tool. Do you want to discard the current menu\n"
					"to use this tool?"),
				      _("Yes, Discard and Update"), _("No, Keep Current Menu"), NULL);

		if (res == WAPRDefault) {
			pmenu = getDefaultMenu(panel);

			if (!pmenu) {
				pmenu = WMCreatePLArray(WMCreatePLString("Applications"), NULL);
			}
		} else {
			panel->dontSave = True;
			return;
		}
	}

	panel->menuPath = menuPath;

	snprintf(buf, 1024,
		 _("\n\nWhen saved, the menu will be written to the file\n\"%s\"."),
		 menuPath);
	labelText = WMGetLabelText(panel->sections[NoInfo][0]);
	labelText = wstrconcat(labelText, buf);
	WMSetLabelText(panel->sections[NoInfo][0], labelText);
	wfree(labelText);

	buildMenuFromPL(panel, pmenu);

	WMReleasePropList(pmenu);
}
Exemplo n.º 8
0
static WEditMenu *buildSubmenu(_Panel * panel, WMPropList * pl)
{
	WMScreen *scr = WMWidgetScreen(panel->parent);
	WEditMenu *menu;
	WEditMenuItem *item;
	char *title;
	WMPropList *tp, *bp;
	int i;

	tp = WMGetFromPLArray(pl, 0);
	title = WMGetFromPLString(tp);

	menu = WCreateEditMenu(scr, title);

	for (i = 1; i < WMGetPropListItemCount(pl); i++) {
		WMPropList *pi;

		pi = WMGetFromPLArray(pl, i);

		tp = WMGetFromPLArray(pi, 0);
		bp = WMGetFromPLArray(pi, 1);

		title = WMGetFromPLString(tp);

		if (!bp || WMIsPLArray(bp)) {	/* it's a submenu */
			WEditMenu *submenu;

			submenu = buildSubmenu(panel, pi);

			item = WAddMenuItemWithTitle(menu, title);

			WSetEditMenuSubmenu(menu, item, submenu);
		} else {
			ItemData *data;

			data = parseCommand(pi);

			if (data != NULL) {
				item = WAddMenuItemWithTitle(menu, title);
				if (panel->markerPix[data->type])
					WSetEditMenuItemImage(item, panel->markerPix[data->type]);
				WSetEditMenuItemData(item, data, (WMCallback *) freeItemData);
			} else {
				char *buf = wmalloc(1024);
				snprintf(buf, 1024, _("Invalid menu command \"%s\" with label \"%s\" cleared"),
					WMGetFromPLString(WMGetFromPLArray(pi, 1)),
					WMGetFromPLString(WMGetFromPLArray(pi, 0)));
				WMRunAlertPanel(scr, panel->parent, _("Warning"), buf, _("OK"), NULL, NULL);
				wfree(buf);
			}

		}
	}

	WSetEditMenuAcceptsDrop(menu, True);
	WSetEditMenuDelegate(menu, &menuDelegate);

	WMRealizeWidget(menu);

	return menu;
}
Exemplo n.º 9
0
static void makeThemePack(WMPropList * style, const char *themeName)
{
	WMPropList *keys;
	WMPropList *key;
	WMPropList *value;
	int i;
	size_t themeNameLen;
	char *themeDir;
	const char *user_base;

	user_base = wusergnusteppath();
	if (user_base == NULL)
		return;
	themeNameLen = strlen(user_base) + sizeof(THEME_SUBPATH) + strlen(themeName) + sizeof(THEME_EXTDIR) + 1;
	themeDir = wmalloc(themeNameLen);
	snprintf(themeDir, themeNameLen,
	         "%s" THEME_SUBPATH "%s" THEME_EXTDIR,
	         user_base, themeName);
	ThemePath = themeDir;

	if (!wmkdirhier(themeDir)) {
		wwarning("Could not make theme dir %s\n", themeDir);
		return;
	}

	keys = WMGetPLDictionaryKeys(style);

	for (i = 0; i < WMGetPropListItemCount(keys); i++) {
		key = WMGetFromPLArray(keys, i);

		value = WMGetFromPLDictionary(style, key);
		if (value && WMIsPLArray(value) && WMGetPropListItemCount(value) > 2) {
			WMPropList *type;
			char *t;

			type = WMGetFromPLArray(value, 0);
			t = WMGetFromPLString(type);
			if (t == NULL)
				continue;

			if (strcasecmp(t, "tpixmap") == 0 ||
			    strcasecmp(t, "spixmap") == 0 ||
			    strcasecmp(t, "cpixmap") == 0 ||
			    strcasecmp(t, "mpixmap") == 0 ||
			    strcasecmp(t, "tdgradient") == 0 ||
			    strcasecmp(t, "tvgradient") == 0 ||
			    strcasecmp(t, "thgradient") == 0) {

				WMPropList *file;
				char *p;
				char *newPath;

				file = WMGetFromPLArray(value, 1);

				p = strrchr(WMGetFromPLString(file), '/');
				if (p) {
					newPath = wstrdup(p + 1);

					wcopy_file(themeDir, WMGetFromPLString(file), newPath);

					WMDeleteFromPLArray(value, 1);
					WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
					free(newPath);
				} else {
					findCopyFile(themeDir, WMGetFromPLString(file));
				}
			} else if (strcasecmp(t, "bitmap") == 0) {

				WMPropList *file;
				char *p;
				char *newPath;

				file = WMGetFromPLArray(value, 1);

				p = strrchr(WMGetFromPLString(file), '/');
				if (p) {
					newPath = wstrdup(p + 1);

					wcopy_file(themeDir, WMGetFromPLString(file), newPath);

					WMDeleteFromPLArray(value, 1);
					WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
					free(newPath);
				} else {
					findCopyFile(themeDir, WMGetFromPLString(file));
				}

				file = WMGetFromPLArray(value, 2);

				p = strrchr(WMGetFromPLString(file), '/');
				if (p) {
					newPath = wstrdup(p + 1);

					wcopy_file(themeDir, WMGetFromPLString(file), newPath);

					WMDeleteFromPLArray(value, 2);
					WMInsertInPLArray(value, 2, WMCreatePLString(newPath));
					free(newPath);
				} else {
					findCopyFile(themeDir, WMGetFromPLString(file));
				}
			}
		}
	}
	WMReleasePropList(keys);
}
Exemplo n.º 10
0
static BackgroundTexture *parseTexture(RContext * rc, char *text)
{
	BackgroundTexture *texture = NULL;
	WMPropList *texarray;
	WMPropList *val;
	int count;
	char *tmp;
	char *type;

#define GETSTRORGOTO(val, str, i, label) \
    val = WMGetFromPLArray(texarray, i);\
    if (!WMIsPLString(val)) {\
    wwarning("could not parse texture %s", text);\
    goto label;\
    }\
    str = WMGetFromPLString(val)

	texarray = WMCreatePropListFromDescription(text);
	if (!texarray || !WMIsPLArray(texarray)
	    || (count = WMGetPropListItemCount(texarray)) < 2) {

		wwarning("could not parse texture %s", text);
		if (texarray)
			WMReleasePropList(texarray);
		return NULL;
	}

	texture = wmalloc(sizeof(BackgroundTexture));

	GETSTRORGOTO(val, type, 0, error);

	if (strcasecmp(type, "solid") == 0) {
		XColor color;
		Pixmap pixmap;

		texture->solid = 1;

		GETSTRORGOTO(val, tmp, 1, error);

		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {
			wwarning("could not parse color %s in texture %s", tmp, text);
			goto error;
		}
		XAllocColor(dpy, DefaultColormap(dpy, scr), &color);

		pixmap = XCreatePixmap(dpy, root, 8, 8, DefaultDepth(dpy, scr));
		XSetForeground(dpy, DefaultGC(dpy, scr), color.pixel);
		XFillRectangle(dpy, pixmap, DefaultGC(dpy, scr), 0, 0, 8, 8);

		texture->pixmap = pixmap;
		texture->color = color;
		texture->width = 8;
		texture->height = 8;
	} else if (strcasecmp(type, "vgradient") == 0
		   || strcasecmp(type, "dgradient") == 0 || strcasecmp(type, "hgradient") == 0) {
		XColor color;
		RColor color1, color2;
		RImage *image;
		Pixmap pixmap;
		RGradientStyle gtype;
		int iwidth, iheight;

		GETSTRORGOTO(val, tmp, 1, error);

		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {
			wwarning("could not parse color %s in texture %s", tmp, text);
			goto error;
		}

		color1.red = color.red >> 8;
		color1.green = color.green >> 8;
		color1.blue = color.blue >> 8;

		GETSTRORGOTO(val, tmp, 2, error);

		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {
			wwarning("could not parse color %s in texture %s", tmp, text);
			goto error;
		}

		color2.red = color.red >> 8;
		color2.green = color.green >> 8;
		color2.blue = color.blue >> 8;

		switch (type[0]) {
		case 'h':
		case 'H':
			gtype = RHorizontalGradient;
			iwidth = scrWidth;
			iheight = 32;
			break;
		case 'V':
		case 'v':
			gtype = RVerticalGradient;
			iwidth = 32;
			iheight = scrHeight;
			break;
		default:
			gtype = RDiagonalGradient;
			iwidth = scrWidth;
			iheight = scrHeight;
			break;
		}

		image = RRenderGradient(iwidth, iheight, &color1, &color2, gtype);

		if (!image) {
			wwarning("could not render gradient texture:%s", RMessageForError(RErrorCode));
			goto error;
		}

		if (!RConvertImage(rc, image, &pixmap)) {
			wwarning("could not convert texture:%s", RMessageForError(RErrorCode));
			RReleaseImage(image);
			goto error;
		}

		texture->width = image->width;
		texture->height = image->height;
		RReleaseImage(image);

		texture->pixmap = pixmap;
	} else if (strcasecmp(type, "mvgradient") == 0