mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
new menu editor updates
This commit is contained in:
@@ -99,14 +99,12 @@ static char *keyOptions[] = {
|
|||||||
"WindowShortcut2Key",
|
"WindowShortcut2Key",
|
||||||
"WindowShortcut3Key",
|
"WindowShortcut3Key",
|
||||||
"WindowShortcut4Key",
|
"WindowShortcut4Key",
|
||||||
#ifdef EXTEND_WINDOWSHORTCUT
|
|
||||||
"WindowShortcut5Key",
|
"WindowShortcut5Key",
|
||||||
"WindowShortcut6Key",
|
"WindowShortcut6Key",
|
||||||
"WindowShortcut7Key",
|
"WindowShortcut7Key",
|
||||||
"WindowShortcut8Key",
|
"WindowShortcut8Key",
|
||||||
"WindowShortcut9Key",
|
"WindowShortcut9Key",
|
||||||
"WindowShortcut10Key",
|
"WindowShortcut10Key",
|
||||||
#endif
|
|
||||||
"ClipRaiseKey",
|
"ClipRaiseKey",
|
||||||
"ClipLowerKey",
|
"ClipLowerKey",
|
||||||
#ifndef XKB_MODELOCK
|
#ifndef XKB_MODELOCK
|
||||||
@@ -408,14 +406,12 @@ createPanel(Panel *p)
|
|||||||
WMAddListItem(panel->actLs, _("Shortcut for window 2"));
|
WMAddListItem(panel->actLs, _("Shortcut for window 2"));
|
||||||
WMAddListItem(panel->actLs, _("Shortcut for window 3"));
|
WMAddListItem(panel->actLs, _("Shortcut for window 3"));
|
||||||
WMAddListItem(panel->actLs, _("Shortcut for window 4"));
|
WMAddListItem(panel->actLs, _("Shortcut for window 4"));
|
||||||
#ifdef EXTEND_WINDOWSHORTCUT
|
|
||||||
WMAddListItem(panel->actLs, _("Shortcut for window 5"));
|
WMAddListItem(panel->actLs, _("Shortcut for window 5"));
|
||||||
WMAddListItem(panel->actLs, _("Shortcut for window 6"));
|
WMAddListItem(panel->actLs, _("Shortcut for window 6"));
|
||||||
WMAddListItem(panel->actLs, _("Shortcut for window 7"));
|
WMAddListItem(panel->actLs, _("Shortcut for window 7"));
|
||||||
WMAddListItem(panel->actLs, _("Shortcut for window 8"));
|
WMAddListItem(panel->actLs, _("Shortcut for window 8"));
|
||||||
WMAddListItem(panel->actLs, _("Shortcut for window 9"));
|
WMAddListItem(panel->actLs, _("Shortcut for window 9"));
|
||||||
WMAddListItem(panel->actLs, _("Shortcut for window 10"));
|
WMAddListItem(panel->actLs, _("Shortcut for window 10"));
|
||||||
#endif
|
|
||||||
WMAddListItem(panel->actLs, _("Raise Clip"));
|
WMAddListItem(panel->actLs, _("Raise Clip"));
|
||||||
WMAddListItem(panel->actLs, _("Lower Clip"));
|
WMAddListItem(panel->actLs, _("Lower Clip"));
|
||||||
WMAddListItem(panel->actLs, _("Raise/Lower Clip"));
|
WMAddListItem(panel->actLs, _("Raise/Lower Clip"));
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
*
|
*
|
||||||
* WPrefs - Window Maker Preferences Program
|
* WPrefs - Window Maker Preferences Program
|
||||||
*
|
*
|
||||||
* Copyright (c) 1998 Alfredo K. Kojima
|
* Copyright (c) 1998-2000 Alfredo K. Kojima
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -376,6 +376,9 @@ showPanel(Panel *panel)
|
|||||||
|
|
||||||
WMSetWindowTitle(WPrefs.win, rec->sectionName);
|
WMSetWindowTitle(WPrefs.win, rec->sectionName);
|
||||||
|
|
||||||
|
if (rec->callbacks.showPanel)
|
||||||
|
(*rec->callbacks.showPanel)(panel);
|
||||||
|
|
||||||
WMMapWidget(rec->frame);
|
WMMapWidget(rec->frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,6 +390,9 @@ hidePanel(Panel *panel)
|
|||||||
PanelRec *rec = (PanelRec*)panel;
|
PanelRec *rec = (PanelRec*)panel;
|
||||||
|
|
||||||
WMUnmapWidget(rec->frame);
|
WMUnmapWidget(rec->frame);
|
||||||
|
|
||||||
|
if (rec->callbacks.hidePanel)
|
||||||
|
(*rec->callbacks.hidePanel)(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -689,7 +695,8 @@ Initialize(WMScreen *scr)
|
|||||||
InitWorkspace(scr, WPrefs.win);
|
InitWorkspace(scr, WPrefs.win);
|
||||||
InitConfigurations(scr, WPrefs.win);
|
InitConfigurations(scr, WPrefs.win);
|
||||||
|
|
||||||
InitMenu(scr, WPrefs.win);
|
changeSection(NULL, InitMenu(scr, WPrefs.win));
|
||||||
|
return;
|
||||||
|
|
||||||
#ifdef not_yet_fully_implemented
|
#ifdef not_yet_fully_implemented
|
||||||
InitKeyboardSettings(scr, WPrefs.win);
|
InitKeyboardSettings(scr, WPrefs.win);
|
||||||
@@ -752,9 +759,13 @@ loadConfigurations(WMScreen *scr, WMWindow *mainw)
|
|||||||
path = getenv("WMAKER_BIN_NAME");
|
path = getenv("WMAKER_BIN_NAME");
|
||||||
if (!path)
|
if (!path)
|
||||||
path = "wmaker";
|
path = "wmaker";
|
||||||
path = wstrappend(path, " --version");
|
{
|
||||||
|
char *command;
|
||||||
|
|
||||||
file = popen(path, "r");
|
command = wstrappend(path, " --version");
|
||||||
|
file = popen(command, "r");
|
||||||
|
free(command);
|
||||||
|
}
|
||||||
if (!file || !fgets(buffer, 1023, file)) {
|
if (!file || !fgets(buffer, 1023, file)) {
|
||||||
wsyserror(_("could not extract version information from Window Maker"));
|
wsyserror(_("could not extract version information from Window Maker"));
|
||||||
wfatal(_("Make sure wmaker is in your search path."));
|
wfatal(_("Make sure wmaker is in your search path."));
|
||||||
@@ -789,9 +800,15 @@ loadConfigurations(WMScreen *scr, WMWindow *mainw)
|
|||||||
WMRunAlertPanel(scr, mainw, _("Warning"), mbuf, _("OK"), NULL, NULL);
|
WMRunAlertPanel(scr, mainw, _("Warning"), mbuf, _("OK"), NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
file = popen("wmaker --global_defaults_path", "r");
|
{
|
||||||
|
char *command;
|
||||||
|
|
||||||
|
command = wstrappend(path, " --global_defaults_path");
|
||||||
|
file = popen(command, "r");
|
||||||
|
free(command);
|
||||||
|
}
|
||||||
if (!file || !fgets(buffer, 1023, file)) {
|
if (!file || !fgets(buffer, 1023, file)) {
|
||||||
wsyserror(_("could not run \"wmaker --global_defaults_path\"."));
|
wsyserror(_("could not run \"%s --global_defaults_path\"."), path);
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ typedef struct {
|
|||||||
Bool (*requiresRestart)(Panel*); /* return True if some static option was changed */
|
Bool (*requiresRestart)(Panel*); /* return True if some static option was changed */
|
||||||
void (*undoChanges)(Panel*); /* reset values to those in the dictionary */
|
void (*undoChanges)(Panel*); /* reset values to those in the dictionary */
|
||||||
void (*prepareForClose)(Panel*); /* called when exiting WPrefs */
|
void (*prepareForClose)(Panel*); /* called when exiting WPrefs */
|
||||||
|
void (*showPanel)(Panel*); /* called when entering the panel */
|
||||||
|
void (*hidePanel)(Panel*); /* called when exiting the panel */
|
||||||
} CallbackRec;
|
} CallbackRec;
|
||||||
|
|
||||||
|
|
||||||
@@ -124,8 +126,10 @@ void AddDeadChildHandler(pid_t pid, void (*handler)(void*), void *data);
|
|||||||
#if HAVE_LIBINTL_H && I18N
|
#if HAVE_LIBINTL_H && I18N
|
||||||
# include <libintl.h>
|
# include <libintl.h>
|
||||||
# define _(text) gettext(text)
|
# define _(text) gettext(text)
|
||||||
|
# define N_(text) (text)
|
||||||
#else
|
#else
|
||||||
# define _(text) (text)
|
# define _(text) (text)
|
||||||
|
# define N_(text) (text)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -70,8 +70,6 @@ typedef struct W_EditMenu {
|
|||||||
int draggedItem;
|
int draggedItem;
|
||||||
int dragX, dragY;
|
int dragX, dragY;
|
||||||
|
|
||||||
struct W_EditMenu **dropTargets;
|
|
||||||
|
|
||||||
/* only for non-standalone menu */
|
/* only for non-standalone menu */
|
||||||
WMSize maxSize;
|
WMSize maxSize;
|
||||||
WMSize minSize;
|
WMSize minSize;
|
||||||
@@ -80,6 +78,7 @@ typedef struct W_EditMenu {
|
|||||||
unsigned standalone:1;
|
unsigned standalone:1;
|
||||||
unsigned isTitled:1;
|
unsigned isTitled:1;
|
||||||
|
|
||||||
|
unsigned acceptsDrop:1;
|
||||||
unsigned isFactory:1;
|
unsigned isFactory:1;
|
||||||
unsigned isSelectable:1;
|
unsigned isSelectable:1;
|
||||||
unsigned isEditable:1;
|
unsigned isEditable:1;
|
||||||
@@ -161,6 +160,12 @@ WCreateEditMenuItem(WMWidget *parent, char *title, Bool isTitle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *WGetEditMenuItemTitle(WEditMenuItem *item)
|
||||||
|
{
|
||||||
|
return item->label;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void *WGetEditMenuItemData(WEditMenuItem *item)
|
void *WGetEditMenuItemData(WEditMenuItem *item)
|
||||||
{
|
{
|
||||||
return item->data;
|
return item->data;
|
||||||
@@ -292,12 +297,14 @@ static void destroyEditMenu(WEditMenu *mPtr);
|
|||||||
static void updateMenuContents(WEditMenu *mPtr);
|
static void updateMenuContents(WEditMenu *mPtr);
|
||||||
|
|
||||||
static void handleEvents(XEvent *event, void *data);
|
static void handleEvents(XEvent *event, void *data);
|
||||||
static void handleActionEvents(XEvent *event, void *data);
|
|
||||||
|
|
||||||
static void editItemLabel(WEditMenuItem *item);
|
static void editItemLabel(WEditMenuItem *item);
|
||||||
static void stopEditItem(WEditMenu *menu, Bool apply);
|
static void stopEditItem(WEditMenu *menu, Bool apply);
|
||||||
|
|
||||||
|
|
||||||
|
static void deselectItem(WEditMenu *menu);
|
||||||
|
|
||||||
|
|
||||||
static W_Class EditMenuClass = 0;
|
static W_Class EditMenuClass = 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -368,6 +375,25 @@ realizeObserver(void *self, WMNotification *not)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
itemSelectObserver(void *self, WMNotification *notif)
|
||||||
|
{
|
||||||
|
WEditMenu *menu = (WEditMenu*)self;
|
||||||
|
WEditMenu *rmenu;
|
||||||
|
|
||||||
|
rmenu = (WEditMenu*)WMGetNotificationObject(notif);
|
||||||
|
/* check whether rmenu is from the same hierarchy of menu? */
|
||||||
|
|
||||||
|
if (rmenu == menu) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (menu->selectedItem && !menu->selectedItem->submenu) {
|
||||||
|
deselectItem(menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static WEditMenu*
|
static WEditMenu*
|
||||||
makeEditMenu(WMScreen *scr, WMWidget *parent, char *title)
|
makeEditMenu(WMScreen *scr, WMWidget *parent, char *title)
|
||||||
{
|
{
|
||||||
@@ -404,13 +430,14 @@ makeEditMenu(WMScreen *scr, WMWidget *parent, char *title)
|
|||||||
WMAddNotificationObserver(realizeObserver, mPtr,
|
WMAddNotificationObserver(realizeObserver, mPtr,
|
||||||
WMViewRealizedNotification, mPtr->view);
|
WMViewRealizedNotification, mPtr->view);
|
||||||
|
|
||||||
|
WMAddNotificationObserver(itemSelectObserver, mPtr,
|
||||||
|
"EditMenuItemSelected", NULL);
|
||||||
|
|
||||||
mPtr->items = WMCreateBag(4);
|
mPtr->items = WMCreateBag(4);
|
||||||
|
|
||||||
WMCreateEventHandler(mPtr->view, ExposureMask|StructureNotifyMask,
|
WMCreateEventHandler(mPtr->view, ExposureMask|StructureNotifyMask,
|
||||||
handleEvents, mPtr);
|
handleEvents, mPtr);
|
||||||
|
|
||||||
WMCreateEventHandler(mPtr->view, ButtonPressMask,handleActionEvents, mPtr);
|
|
||||||
|
|
||||||
|
|
||||||
if (title != NULL) {
|
if (title != NULL) {
|
||||||
item = WCreateEditMenuItem(mPtr, title, True);
|
item = WCreateEditMenuItem(mPtr, title, True);
|
||||||
@@ -460,9 +487,9 @@ WInsertMenuItemWithTitle(WEditMenu *mPtr, int index, char *title)
|
|||||||
|
|
||||||
WMMapWidget(item);
|
WMMapWidget(item);
|
||||||
|
|
||||||
if (index >= WMGetBagItemCount(mPtr->items))
|
if (index >= WMGetBagItemCount(mPtr->items)) {
|
||||||
WMPutInBag(mPtr->items, item);
|
WMPutInBag(mPtr->items, item);
|
||||||
else {
|
} else {
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
index = 0;
|
index = 0;
|
||||||
if (mPtr->flags.isTitled)
|
if (mPtr->flags.isTitled)
|
||||||
@@ -485,16 +512,24 @@ WAddMenuItemWithTitle(WEditMenu *mPtr, char *title)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
WSetEditMenuItemDropTargets(WEditMenu *mPtr, WEditMenu **dropTargets,
|
|
||||||
int count)
|
|
||||||
{
|
|
||||||
if (mPtr->dropTargets)
|
|
||||||
free(mPtr->dropTargets);
|
|
||||||
|
|
||||||
mPtr->dropTargets = wmalloc(sizeof(WEditMenu*)*(count+1));
|
void
|
||||||
memcpy(mPtr->dropTargets, dropTargets, sizeof(WEditMenu*)*count);
|
WSetEditMenuTitle(WEditMenu *mPtr, char *title)
|
||||||
mPtr->dropTargets[count] = NULL;
|
{
|
||||||
|
WEditMenuItem *item;
|
||||||
|
|
||||||
|
item = WMGetFromBag(mPtr->items, 0);
|
||||||
|
|
||||||
|
free(item->label);
|
||||||
|
item->label = wstrdup(title);
|
||||||
|
updateMenuContents(mPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
WSetEditMenuAcceptsDrop(WEditMenu *mPtr, Bool flag)
|
||||||
|
{
|
||||||
|
mPtr->flags.acceptsDrop = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -507,6 +542,14 @@ WSetEditMenuSubmenu(WEditMenu *mPtr, WEditMenuItem *item, WEditMenu *submenu)
|
|||||||
paintEditMenuItem(item);
|
paintEditMenuItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WEditMenu*
|
||||||
|
WGetEditMenuSubmenu(WEditMenu *mPtr, WEditMenuItem *item)
|
||||||
|
{
|
||||||
|
return item->submenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int simpleMatch(void *a, void *b)
|
static int simpleMatch(void *a, void *b)
|
||||||
{
|
{
|
||||||
if (a == b)
|
if (a == b)
|
||||||
@@ -577,16 +620,17 @@ WGetEditMenuLocationForSubmenu(WEditMenu *mPtr, WEditMenu *submenu)
|
|||||||
WEditMenuItem *item;
|
WEditMenuItem *item;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
if (mPtr->flags.isTitled) {
|
if (mPtr->flags.isTitled)
|
||||||
y = mPtr->titleHeight;
|
y = -mPtr->titleHeight;
|
||||||
} else {
|
else
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
|
||||||
WM_ITERATE_BAG(mPtr->items, item, iter) {
|
WM_ITERATE_BAG(mPtr->items, item, iter) {
|
||||||
if (item->submenu == submenu) {
|
if (item->submenu == submenu) {
|
||||||
return wmkpoint(mPtr->view->pos.x + mPtr->view->size.width, y);
|
WMPoint pt = WMGetViewScreenPosition(mPtr->view);
|
||||||
|
|
||||||
|
return wmkpoint(pt.x + mPtr->view->size.width, pt.y + y);
|
||||||
}
|
}
|
||||||
y += mPtr->itemHeight;
|
y += W_VIEW_HEIGHT(item->view);
|
||||||
}
|
}
|
||||||
|
|
||||||
puts("invalid submenu passed to WGetEditMenuLocationForSubmenu()");
|
puts("invalid submenu passed to WGetEditMenuLocationForSubmenu()");
|
||||||
@@ -595,10 +639,21 @@ WGetEditMenuLocationForSubmenu(WEditMenu *mPtr, WEditMenu *submenu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
WTearOffEditMenu(WEditMenu *menu, WEditMenu *submenu)
|
||||||
|
{
|
||||||
|
submenu->flags.isTornOff = 1;
|
||||||
|
|
||||||
|
if (menu->selectedItem && menu->selectedItem->submenu == submenu)
|
||||||
|
deselectItem(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Bool
|
Bool
|
||||||
WEditMenuIsTornOff(WEditMenu *mPtr)
|
WEditMenuIsTornOff(WEditMenu *mPtr)
|
||||||
{
|
{
|
||||||
return !mPtr->flags.isTornOff;
|
return mPtr->flags.isTornOff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -661,37 +716,79 @@ updateMenuContents(WEditMenu *mPtr)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
selectItem(WEditMenu *menu, WEditMenuItem *item)
|
unmapMenu(WEditMenu *menu)
|
||||||
{
|
{
|
||||||
if (!menu->flags.isSelectable) {
|
WMUnmapWidget(menu);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (menu->selectedItem) {
|
if (menu->selectedItem) {
|
||||||
highlightItem(menu->selectedItem, False);
|
deselectItem(menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (menu->delegate) {
|
|
||||||
(*menu->delegate->itemDeselected)(menu->delegate, menu,
|
static void
|
||||||
menu->selectedItem);
|
deselectItem(WEditMenu *menu)
|
||||||
}
|
{
|
||||||
|
WEditMenu *submenu;
|
||||||
|
WEditMenuItem *item = menu->selectedItem;
|
||||||
|
|
||||||
|
highlightItem(item, False);
|
||||||
|
|
||||||
|
if (menu->delegate && menu->delegate->itemDeselected) {
|
||||||
|
(*menu->delegate->itemDeselected)(menu->delegate, menu, item);
|
||||||
|
}
|
||||||
|
submenu = item->submenu;
|
||||||
|
|
||||||
|
if (submenu && !WEditMenuIsTornOff(submenu)) {
|
||||||
|
unmapMenu(submenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
menu->selectedItem = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
selectItem(WEditMenu *menu, WEditMenuItem *item)
|
||||||
|
{
|
||||||
|
if (!menu->flags.isSelectable || menu->selectedItem == item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (menu->selectedItem) {
|
||||||
|
deselectItem(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menu->flags.isEditing) {
|
if (menu->flags.isEditing) {
|
||||||
stopEditItem(menu, False);
|
stopEditItem(menu, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item) {
|
if (item && !item->flags.isTitle) {
|
||||||
highlightItem(item, True);
|
highlightItem(item, True);
|
||||||
|
|
||||||
if (item->submenu) {
|
if (item->submenu) {
|
||||||
WMPoint pt;
|
WMPoint pt;
|
||||||
|
XSizeHints *hints;
|
||||||
|
|
||||||
|
hints = XAllocSizeHints();
|
||||||
|
|
||||||
pt = WGetEditMenuLocationForSubmenu(menu, item->submenu);
|
pt = WGetEditMenuLocationForSubmenu(menu, item->submenu);
|
||||||
|
|
||||||
|
hints->flags = USPosition;
|
||||||
|
hints->x = pt.x;
|
||||||
|
hints->y = pt.y;
|
||||||
|
|
||||||
WMMoveWidget(item->submenu, pt.x, pt.y);
|
WMMoveWidget(item->submenu, pt.x, pt.y);
|
||||||
|
XSetWMNormalHints(W_VIEW_DISPLAY(item->submenu->view),
|
||||||
|
W_VIEW_DRAWABLE(item->submenu->view),
|
||||||
|
hints);
|
||||||
|
XFree(hints);
|
||||||
WMMapWidget(item->submenu);
|
WMMapWidget(item->submenu);
|
||||||
|
|
||||||
|
item->submenu->flags.isTornOff = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menu->delegate) {
|
WMPostNotificationName("EditMenuItemSelected", menu, NULL);
|
||||||
|
|
||||||
|
if (menu->delegate && menu->delegate->itemSelected) {
|
||||||
(*menu->delegate->itemSelected)(menu->delegate, menu, item);
|
(*menu->delegate->itemSelected)(menu->delegate, menu, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -730,18 +827,6 @@ handleEvents(XEvent *event, void *data)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
handleActionEvents(XEvent *event, void *data)
|
|
||||||
{
|
|
||||||
// WEditMenu *mPtr = (WEditMenu*)data;
|
|
||||||
|
|
||||||
switch (event->type) {
|
|
||||||
case ButtonPress:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------- Menu Label Editing ------------------------ */
|
/* -------------------------- Menu Label Editing ------------------------ */
|
||||||
|
|
||||||
|
|
||||||
@@ -887,39 +972,39 @@ slideWindow(Display *dpy, Window win, int srcX, int srcY, int dstX, int dstY)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static WEditMenu*
|
static int errorHandler(Display *d, XErrorEvent *ev)
|
||||||
getEditMenuForWindow(WEditMenu **menus, Window window)
|
|
||||||
{
|
{
|
||||||
while (*menus) {
|
/* just ignore */
|
||||||
if (W_VIEW_DRAWABLE((*menus)->view) == window) {
|
return 0;
|
||||||
return *menus;
|
|
||||||
}
|
|
||||||
menus++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static WEditMenu*
|
static WEditMenu*
|
||||||
findMenuInWindow(Display *dpy, Window toplevel, int x, int y,
|
findMenuInWindow(Display *dpy, Window toplevel, int x, int y)
|
||||||
WEditMenu **menus)
|
|
||||||
{
|
{
|
||||||
Window foo, bar;
|
Window foo, bar;
|
||||||
Window *children;
|
Window *children;
|
||||||
unsigned nchildren;
|
unsigned nchildren;
|
||||||
int i;
|
int i;
|
||||||
WEditMenu *menu;
|
WEditMenu *menu;
|
||||||
|
WMView *view;
|
||||||
|
int (*oldHandler)(Display *, XErrorEvent *);
|
||||||
|
|
||||||
menu = getEditMenuForWindow(menus, toplevel);
|
view = W_GetViewForXWindow(dpy, toplevel);
|
||||||
if (menu)
|
if (view && view->self && WMWidgetClass(view->self) == EditMenuClass) {
|
||||||
return menu;
|
menu = (WEditMenu*)view->self;
|
||||||
|
if (menu->flags.acceptsDrop) {
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!XQueryTree(dpy, toplevel, &foo, &bar,
|
if (!XQueryTree(dpy, toplevel, &foo, &bar,
|
||||||
&children, &nchildren) || children == NULL) {
|
&children, &nchildren) || children == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldHandler = XSetErrorHandler(errorHandler);
|
||||||
|
|
||||||
/* first window that contains the point is the one */
|
/* first window that contains the point is the one */
|
||||||
for (i = nchildren-1; i >= 0; i--) {
|
for (i = nchildren-1; i >= 0; i--) {
|
||||||
XWindowAttributes attr;
|
XWindowAttributes attr;
|
||||||
@@ -932,7 +1017,7 @@ findMenuInWindow(Display *dpy, Window toplevel, int x, int y,
|
|||||||
|
|
||||||
tmp = children[i];
|
tmp = children[i];
|
||||||
|
|
||||||
menu = findMenuInWindow(dpy, tmp, x - attr.x, y - attr.y, menus);
|
menu = findMenuInWindow(dpy, tmp, x - attr.x, y - attr.y);
|
||||||
if (menu) {
|
if (menu) {
|
||||||
XFree(children);
|
XFree(children);
|
||||||
return menu;
|
return menu;
|
||||||
@@ -940,6 +1025,8 @@ findMenuInWindow(Display *dpy, Window toplevel, int x, int y,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XSetErrorHandler(oldHandler);
|
||||||
|
|
||||||
XFree(children);
|
XFree(children);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1001,6 +1088,9 @@ handleItemDrop(WEditMenu *menu, WEditMenuItem *item, int x, int y)
|
|||||||
W_ReparentView(item->view, menu->view, 0, index*menu->itemHeight);
|
W_ReparentView(item->view, menu->view, 0, index*menu->itemHeight);
|
||||||
|
|
||||||
item->parent = menu;
|
item->parent = menu;
|
||||||
|
if (item->submenu) {
|
||||||
|
item->submenu->parent = menu;
|
||||||
|
}
|
||||||
|
|
||||||
updateMenuContents(menu);
|
updateMenuContents(menu);
|
||||||
}
|
}
|
||||||
@@ -1018,8 +1108,10 @@ dragMenu(WEditMenu *menu)
|
|||||||
|
|
||||||
XGetGeometry(scr->display, W_VIEW_DRAWABLE(menu->view), &blaw, &dx, &dy,
|
XGetGeometry(scr->display, W_VIEW_DRAWABLE(menu->view), &blaw, &dx, &dy,
|
||||||
&blau, &blau, &blau, &blau);
|
&blau, &blau, &blau, &blau);
|
||||||
|
|
||||||
XTranslateCoordinates(scr->display, W_VIEW_DRAWABLE(menu->view),
|
XTranslateCoordinates(scr->display, W_VIEW_DRAWABLE(menu->view),
|
||||||
scr->rootWin, dx, dy, &dx, &dy, &blaw);
|
scr->rootWin, dx, dy, &dx, &dy, &blaw);
|
||||||
|
|
||||||
dx = menu->dragX - dx;
|
dx = menu->dragX - dx;
|
||||||
dy = menu->dragY - dy;
|
dy = menu->dragY - dy;
|
||||||
|
|
||||||
@@ -1028,6 +1120,9 @@ dragMenu(WEditMenu *menu)
|
|||||||
GrabModeAsync, GrabModeAsync, None, scr->defaultCursor,
|
GrabModeAsync, GrabModeAsync, None, scr->defaultCursor,
|
||||||
CurrentTime);
|
CurrentTime);
|
||||||
|
|
||||||
|
if (menu->parent)
|
||||||
|
WTearOffEditMenu(menu->parent, menu);
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
WMNextEvent(scr->display, &ev);
|
WMNextEvent(scr->display, &ev);
|
||||||
|
|
||||||
@@ -1051,6 +1146,26 @@ dragMenu(WEditMenu *menu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static WEditMenu*
|
||||||
|
duplicateMenu(WEditMenu *menu)
|
||||||
|
{
|
||||||
|
WEditMenu *nmenu;
|
||||||
|
WEditMenuItem *title;
|
||||||
|
|
||||||
|
if (menu->flags.isTitled) {
|
||||||
|
title = WMGetFromBag(menu->items, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
nmenu = WCreateEditMenu(WMWidgetScreen(menu), title->label);
|
||||||
|
|
||||||
|
memcpy(&nmenu->flags, &menu->flags, sizeof(menu->flags));
|
||||||
|
nmenu->delegate = menu->delegate;
|
||||||
|
|
||||||
|
WMRealizeWidget(nmenu);
|
||||||
|
|
||||||
|
return nmenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dragItem(WEditMenu *menu, WEditMenuItem *item)
|
dragItem(WEditMenu *menu, WEditMenuItem *item)
|
||||||
@@ -1068,6 +1183,7 @@ dragItem(WEditMenu *menu, WEditMenuItem *item)
|
|||||||
int orix, oriy;
|
int orix, oriy;
|
||||||
Bool enteredMenu = False;
|
Bool enteredMenu = False;
|
||||||
WMSize oldSize = item->view->size;
|
WMSize oldSize = item->view->size;
|
||||||
|
WEditMenuItem *dritem = item;
|
||||||
WEditMenu *dmenu = NULL;
|
WEditMenu *dmenu = NULL;
|
||||||
|
|
||||||
|
|
||||||
@@ -1082,9 +1198,6 @@ dragItem(WEditMenu *menu, WEditMenuItem *item)
|
|||||||
|
|
||||||
selectItem(menu, NULL);
|
selectItem(menu, NULL);
|
||||||
|
|
||||||
assert(menu->dropTargets != NULL);
|
|
||||||
|
|
||||||
|
|
||||||
win = scr->rootWin;
|
win = scr->rootWin;
|
||||||
|
|
||||||
XTranslateCoordinates(dpy, W_VIEW_DRAWABLE(item->view), win,
|
XTranslateCoordinates(dpy, W_VIEW_DRAWABLE(item->view), win,
|
||||||
@@ -1097,19 +1210,12 @@ dragItem(WEditMenu *menu, WEditMenuItem *item)
|
|||||||
W_RealizeView(dview);
|
W_RealizeView(dview);
|
||||||
|
|
||||||
if (menu->flags.isFactory) {
|
if (menu->flags.isFactory) {
|
||||||
WEditMenuItem *nitem;
|
dritem = WCreateEditMenuItem(menu, item->label, False);
|
||||||
|
|
||||||
nitem = WCreateEditMenuItem(menu, item->label, False);
|
W_ReparentView(dritem->view, dview, 0, 0);
|
||||||
|
WMResizeWidget(dritem, oldSize.width, oldSize.height);
|
||||||
if (menu->delegate) {
|
WMRealizeWidget(dritem);
|
||||||
(*menu->delegate->itemCloned)(menu->delegate, menu, item, nitem);
|
WMMapWidget(dritem);
|
||||||
}
|
|
||||||
item = nitem;
|
|
||||||
|
|
||||||
W_ReparentView(item->view, dview, 0, 0);
|
|
||||||
WMResizeWidget(item, oldSize.width, oldSize.height);
|
|
||||||
WMRealizeWidget(item);
|
|
||||||
WMMapWidget(item);
|
|
||||||
} else {
|
} else {
|
||||||
W_ReparentView(item->view, dview, 0, 0);
|
W_ReparentView(item->view, dview, 0, 0);
|
||||||
}
|
}
|
||||||
@@ -1133,15 +1239,15 @@ dragItem(WEditMenu *menu, WEditMenuItem *item)
|
|||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
XQueryPointer(dpy, win, &blaw, &blaw, &blai, &blai, &x, &y, &blau);
|
XQueryPointer(dpy, win, &blaw, &blaw, &blai, &blai, &x, &y, &blau);
|
||||||
|
|
||||||
dmenu = findMenuInWindow(dpy, win, x, y, menu->dropTargets);
|
dmenu = findMenuInWindow(dpy, win, x, y);
|
||||||
|
|
||||||
if (dmenu) {
|
if (dmenu) {
|
||||||
handleDragOver(dmenu, dview, item, x - dx, y - dy);
|
handleDragOver(dmenu, dview, dritem, x - dx, y - dy);
|
||||||
enteredMenu = True;
|
enteredMenu = True;
|
||||||
} else {
|
} else {
|
||||||
if (enteredMenu) {
|
if (enteredMenu) {
|
||||||
W_ResizeView(dview, oldSize.width, oldSize.height);
|
W_ResizeView(dview, oldSize.width, oldSize.height);
|
||||||
W_ResizeView(item->view, oldSize.width, oldSize.height);
|
W_ResizeView(dritem->view, oldSize.width, oldSize.height);
|
||||||
enteredMenu = False;
|
enteredMenu = False;
|
||||||
}
|
}
|
||||||
W_MoveView(dview, x - dx, y - dy);
|
W_MoveView(dview, x - dx, y - dy);
|
||||||
@@ -1160,12 +1266,44 @@ dragItem(WEditMenu *menu, WEditMenuItem *item)
|
|||||||
}
|
}
|
||||||
XUngrabPointer(dpy, CurrentTime);
|
XUngrabPointer(dpy, CurrentTime);
|
||||||
|
|
||||||
if (menu->flags.isFactory && !enteredMenu) {
|
|
||||||
slideWindow(dpy, W_VIEW_DRAWABLE(dview), x-dx, y-dy, orix, oriy);
|
if (!enteredMenu) {
|
||||||
|
Bool rem = True;
|
||||||
|
|
||||||
|
if (!menu->flags.isFactory) {
|
||||||
|
WMUnmapWidget(dritem);
|
||||||
|
if (menu->delegate && menu->delegate->shouldRemoveItem) {
|
||||||
|
rem = (*menu->delegate->shouldRemoveItem)(menu->delegate,
|
||||||
|
menu, item);
|
||||||
|
}
|
||||||
|
WMMapWidget(dritem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rem || menu->flags.isFactory) {
|
||||||
|
slideWindow(dpy, W_VIEW_DRAWABLE(dview), x-dx, y-dy, orix, oriy);
|
||||||
|
|
||||||
|
if (!menu->flags.isFactory) {
|
||||||
|
WRemoveEditMenuItem(menu, dritem);
|
||||||
|
handleItemDrop(dmenu ? dmenu : menu, dritem, orix, oriy);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
WRemoveEditMenuItem(menu, dritem);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
WRemoveEditMenuItem(menu, item);
|
WRemoveEditMenuItem(menu, dritem);
|
||||||
if (enteredMenu) {
|
|
||||||
handleItemDrop(dmenu, item, x-dy, y-dy);
|
if (menu->delegate && menu->delegate->itemCloned) {
|
||||||
|
(*menu->delegate->itemCloned)(menu->delegate, menu,
|
||||||
|
item, dritem);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleItemDrop(dmenu, dritem, x-dy, y-dy);
|
||||||
|
|
||||||
|
if (item->submenu && menu->flags.isFactory) {
|
||||||
|
WEditMenu *submenu;
|
||||||
|
|
||||||
|
submenu = duplicateMenu(item->submenu);
|
||||||
|
WSetEditMenuSubmenu(dmenu, dritem, submenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1217,11 +1355,18 @@ handleItemClick(XEvent *event, void *data)
|
|||||||
static void
|
static void
|
||||||
destroyEditMenu(WEditMenu *mPtr)
|
destroyEditMenu(WEditMenu *mPtr)
|
||||||
{
|
{
|
||||||
|
WEditMenuItem *item;
|
||||||
|
WMBagIterator iter;
|
||||||
|
|
||||||
WMRemoveNotificationObserver(mPtr);
|
WMRemoveNotificationObserver(mPtr);
|
||||||
|
|
||||||
WMFreeBag(mPtr->items);
|
WM_ITERATE_BAG(mPtr->items, item, iter) {
|
||||||
|
if (item->submenu) {
|
||||||
|
WMDestroyWidget(item->submenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
free(mPtr->dropTargets);
|
WMFreeBag(mPtr->items);
|
||||||
|
|
||||||
free(mPtr);
|
free(mPtr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,65 @@ typedef struct W_EditMenuItem WEditMenuItem;
|
|||||||
typedef struct WEditMenuDelegate {
|
typedef struct WEditMenuDelegate {
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
void (*itemCloned)(struct WEditMenuDelegate*, WEditMenu *menu,
|
void (*itemCloned)(struct WEditMenuDelegate*, WEditMenu*,
|
||||||
WEditMenuItem *origItem, WEditMenuItem *newItem);
|
WEditMenuItem*, WEditMenuItem *);
|
||||||
void (*itemSelected)(struct WEditMenuDelegate*, WEditMenu *menu,
|
void (*itemSelected)(struct WEditMenuDelegate*, WEditMenu*,
|
||||||
WEditMenuItem *item);
|
WEditMenuItem*);
|
||||||
void (*itemDeselected)(struct WEditMenuDelegate*, WEditMenu *menu,
|
void (*itemDeselected)(struct WEditMenuDelegate*, WEditMenu*,
|
||||||
WEditMenuItem *item);
|
WEditMenuItem*);
|
||||||
|
Bool (*shouldRemoveItem)(struct WEditMenuDelegate*, WEditMenu*,
|
||||||
|
WEditMenuItem*);
|
||||||
} WEditMenuDelegate;
|
} WEditMenuDelegate;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
WEditMenuItem *WCreateEditMenuItem(WMWidget *parent, char *title,
|
||||||
|
Bool isTitle);
|
||||||
|
|
||||||
|
|
||||||
|
char *WGetEditMenuItemTitle(WEditMenuItem *item);
|
||||||
|
|
||||||
|
void *WGetEditMenuItemData(WEditMenuItem *item);
|
||||||
|
|
||||||
|
void WSetEditMenuItemData(WEditMenuItem *item, void *data,
|
||||||
|
WMCallback *destroyer);
|
||||||
|
|
||||||
|
WEditMenu *WCreateEditMenu(WMScreen *scr, char *title);
|
||||||
|
|
||||||
|
WEditMenu *WCreateEditMenuPad(WMWidget *parent);
|
||||||
|
|
||||||
|
void WSetEditMenuDelegate(WEditMenu *mPtr, WEditMenuDelegate *delegate);
|
||||||
|
|
||||||
|
WEditMenuItem *WInsertMenuItemWithTitle(WEditMenu *mPtr, int index,
|
||||||
|
char *title);
|
||||||
|
|
||||||
|
WEditMenuItem *WAddMenuItemWithTitle(WEditMenu *mPtr, char *title);
|
||||||
|
|
||||||
|
void WSetEditMenuTitle(WEditMenu *mPtr, char *title);
|
||||||
|
|
||||||
|
void WSetEditMenuAcceptsDrop(WEditMenu *mPtr, Bool flag);
|
||||||
|
|
||||||
|
void WSetEditMenuSubmenu(WEditMenu *mPtr, WEditMenuItem *item,
|
||||||
|
WEditMenu *submenu);
|
||||||
|
|
||||||
|
|
||||||
|
WEditMenu *WGetEditMenuSubmenu(WEditMenu *mPtr, WEditMenuItem *item);
|
||||||
|
|
||||||
|
void WRemoveEditMenuItem(WEditMenu *mPtr, WEditMenuItem *item);
|
||||||
|
|
||||||
|
void WSetEditMenuSelectable(WEditMenu *mPtr, Bool flag);
|
||||||
|
|
||||||
|
void WSetEditMenuEditable(WEditMenu *mPtr, Bool flag);
|
||||||
|
|
||||||
|
void WSetEditMenuIsFactory(WEditMenu *mPtr, Bool flag);
|
||||||
|
|
||||||
|
void WSetEditMenuMinSize(WEditMenu *mPtr, WMSize size);
|
||||||
|
|
||||||
|
void WSetEditMenuMaxSize(WEditMenu *mPtr, WMSize size);
|
||||||
|
|
||||||
|
WMPoint WGetEditMenuLocationForSubmenu(WEditMenu *mPtr, WEditMenu *submenu);
|
||||||
|
|
||||||
|
void WTearOffEditMenu(WEditMenu *menu, WEditMenu *submenu);
|
||||||
|
|
||||||
|
Bool WEditMenuIsTornOff(WEditMenu *mPtr);
|
||||||
|
|||||||
Reference in New Issue
Block a user