Esempio n. 1
0
static WMenu *createWindowMenu(WScreen * scr)
{
	WMenu *menu;
	int i;

	menu = wMenuCreate(scr, NULL, False);

	for (i = 0; i < wlengthof(window_menu_entries); i++) {
		WMenuEntry *entry;

		entry = wMenuAddCallback(menu, _(window_menu_entries[i].label),
		                         (window_menu_entries[i].generate_submenu == NULL)?execMenuCommand:NULL,
		                         NULL);
		if (window_menu_entries[i].generate_submenu != NULL) {
			WMenu *submenu;

			submenu = window_menu_entries[i].generate_submenu(scr);
			wMenuEntrySetCascade(menu, entry, submenu);
		}
	}

	return menu;
}
Esempio n. 2
0
static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int count, int *index)
{
	WMenu *menu;
	int command;
	int code, pos;
	char title[300];
	char rtext[300];

	if (strlen(slist[*index]) > sizeof(title) - 1) {
		wwarning("appmenu: menu command size exceeded in window %lx", win);
		return NULL;
	}
	if (sscanf(slist[*index], "%i %i %n", &command, &code, &pos) < 2 || command != wmBeginMenu) {
		wwarning("appmenu: bad menu entry \"%s\" in window %lx", slist[*index], win);
		return NULL;
	}
	strcpy(title, &slist[*index][pos]);
	menu = wMenuCreateForApp(scr, title, *index == 1);
	if (!menu)
		return NULL;
	*index += 1;
	while (*index < count) {
		int ecode, etag, enab;

		if (sscanf(slist[*index], "%i", &command) != 1) {
			wMenuDestroy(menu, True);
			wwarning("appmenu: bad menu entry \"%s\" in window %lx", slist[*index], win);
			return NULL;
		}

		if (command == wmEndMenu) {
			*index += 1;
			break;

		} else if (command == wmNormalItem || command == wmDoubleItem) {
			WAppMenuData *data;
			WMenuEntry *entry;

			if (command == wmNormalItem) {
				if (sscanf(slist[*index], "%i %i %i %i %n",
					   &command, &ecode, &etag, &enab, &pos) != 4 || ecode != code) {
					wMenuDestroy(menu, True);
					wwarning("appmenu: bad menu entry \"%s\" in window %lx",
						 slist[*index], win);
					return NULL;
				}
				strcpy(title, &slist[*index][pos]);
				rtext[0] = 0;
			} else {
				if (sscanf(slist[*index], "%i %i %i %i %s %n",
					   &command, &ecode, &etag, &enab, rtext, &pos) != 5 || ecode != code) {
					wMenuDestroy(menu, True);
					wwarning("appmenu: bad menu entry \"%s\" in window %lx",
						 slist[*index], win);
					return NULL;
				}
				strcpy(title, &slist[*index][pos]);
			}
			if (!(data = malloc(sizeof(WAppMenuData)))) {
				wwarning("appmenu: out of memory making menu for window %lx", win);
				wMenuDestroy(menu, True);
				return NULL;
			}
			data->code = code;
			data->tag = etag;
			data->window = win;
			entry = wMenuAddCallback(menu, title, notifyClient, data);
			if (!entry) {
				wMenuDestroy(menu, True);
				wwarning("appmenu: out of memory creating menu for window %lx", win);
				free(data);
				return NULL;
			}
			if (rtext[0] != 0)
				entry->rtext = wstrdup(rtext);
			else
				entry->rtext = NULL;
			entry->free_cdata = free;
			*index += 1;

		} else if (command == wmSubmenuItem) {
			int ncode;
			WMenuEntry *entry;
			WMenu *submenu;

			if (sscanf(slist[*index], "%i %i %i %i %i %n",
				   &command, &ecode, &etag, &enab, &ncode, &pos) != 5 || ecode != code) {
				wMenuDestroy(menu, True);
				wwarning("appmenu: bad menu entry \"%s\" in window %lx", slist[*index], win);

				return NULL;
			}
			strcpy(title, &slist[*index][pos]);
			*index += 1;

			submenu = parseMenuCommand(scr, win, slist, count, index);

			entry = wMenuAddCallback(menu, title, NULL, NULL);

			if (!entry) {
				wMenuDestroy(menu, True);
				wMenuDestroy(submenu, True);
				wwarning("appmenu: out of memory creating menu for window %lx", win);
				return NULL;
			}

			wMenuEntrySetCascade(menu, entry, submenu);

		} else {
			wMenuDestroy(menu, True);
			wwarning("appmenu: bad menu entry \"%s\" in window %lx", slist[*index], win);
			return NULL;
		}
	}

	return menu;
}