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

*** empty log message ***

This commit is contained in:
id
1999-04-16 19:56:08 +00:00
parent 4b609a4ddc
commit 6c22352007
4 changed files with 345 additions and 303 deletions

View File

@@ -207,7 +207,7 @@ WMCreateTextField(WMWidget *parent)
WMAX((tPtr->view->size.height - WMFontHeight(tPtr->font))/2, 1); WMAX((tPtr->view->size.height - WMFontHeight(tPtr->font))/2, 1);
WMCreateEventHandler(tPtr->view, EnterWindowMask|LeaveWindowMask WMCreateEventHandler(tPtr->view, EnterWindowMask|LeaveWindowMask
|ButtonPressMask|KeyPressMask|Button1MotionMask, |ButtonReleaseMask|ButtonPressMask|KeyPressMask|Button1MotionMask,
handleTextFieldActionEvents, tPtr); handleTextFieldActionEvents, tPtr);
tPtr->flags.cursorOn = 1; tPtr->flags.cursorOn = 1;
@@ -562,6 +562,7 @@ paintCursor(TextField *tPtr)
XDrawRectangle(screen->display, tPtr->view->window, screen->xorGC, XDrawRectangle(screen->display, tPtr->view->window, screen->xorGC,
cx, tPtr->offsetWidth, 1, cx, tPtr->offsetWidth, 1,
tPtr->view->size.height - 2*tPtr->offsetWidth - 1); tPtr->view->size.height - 2*tPtr->offsetWidth - 1);
printf("%d %d\n",cx,tPtr->cursorPosition);
*/ */
XDrawLine(screen->display, tPtr->view->window, screen->xorGC, XDrawLine(screen->display, tPtr->view->window, screen->xorGC,
cx, tPtr->offsetWidth, cx, cx, tPtr->offsetWidth, cx,
@@ -677,9 +678,15 @@ paintTextField(TextField *tPtr)
? tPtr->selection.position + tPtr->selection.count ? tPtr->selection.position + tPtr->selection.count
: tPtr->selection.position; : tPtr->selection.position;
/*
rx = tx + WMWidthOfString(tPtr->font, rx = tx + WMWidthOfString(tPtr->font,
&(tPtr->text[tPtr->viewPosition]), &(tPtr->text[tPtr->viewPosition]),
count); count)
- WMWidthOfString(tPtr->font,
tPtr->text,tPtr->viewPosition);
*/
rx = tPtr->offsetWidth + 1 + WMWidthOfString(tPtr->font,tPtr->text,count)
- WMWidthOfString(tPtr->font,tPtr->text,tPtr->viewPosition);
XSetBackground(screen->display, screen->textFieldGC, XSetBackground(screen->display, screen->textFieldGC,
screen->gray->color.pixel); screen->gray->color.pixel);
@@ -1060,59 +1067,117 @@ handleTextFieldActionEvents(XEvent *event, void *data)
switch (event->type) { switch (event->type) {
case KeyPress: case KeyPress:
if (tPtr->flags.enabled && tPtr->flags.focused) if (tPtr->flags.enabled && tPtr->flags.focused)
handleTextFieldKeyPress(tPtr, event); handleTextFieldKeyPress(tPtr, event);
break; break;
case MotionNotify: case MotionNotify:
if (tPtr->flags.enabled && (event->xmotion.state & Button1Mask)) { if (tPtr->flags.enabled && (event->xmotion.state & Button1Mask)) {
if (!tPtr->selection.count) {
tPtr->selection.position = tPtr->cursorPosition;
}
tPtr->cursorPosition = pointToCursorPosition(tPtr, if (tPtr->viewPosition < tPtr->textLen && event->xmotion.x >
event->xmotion.x); tPtr->usableWidth) {
if (WMWidthOfString(tPtr->font,
&(tPtr->text[tPtr->viewPosition]),
tPtr->cursorPosition-tPtr->viewPosition)
> tPtr->usableWidth) {
tPtr->viewPosition++;
}
}
else if (tPtr->viewPosition > 0 && event->xmotion.x < 0) {
paintCursor(tPtr);
tPtr->viewPosition--;
}
tPtr->selection.count = tPtr->cursorPosition if (!tPtr->selection.count) {
- tPtr->selection.position; tPtr->selection.position = tPtr->cursorPosition;
}
tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x);
tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position;
/*
printf("notify %d %d\n",event->xmotion.x,tPtr->usableWidth);
*/
paintCursor(tPtr);
paintTextField(tPtr);
paintTextField(tPtr);
} }
break; break;
case ButtonPress: case ButtonPress:
if (tPtr->flags.enabled && !tPtr->flags.focused) { switch (tPtr->flags.alignment) {
WMSetFocusToWidget(tPtr); int textWidth;
tPtr->cursorPosition = pointToCursorPosition(tPtr, case WARight:
event->xbutton.x); textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen);
paintTextField(tPtr); if (tPtr->flags.enabled && !tPtr->flags.focused) {
} else if (tPtr->flags.focused) { WMSetFocusToWidget(tPtr);
tPtr->cursorPosition = pointToCursorPosition(tPtr, } else if (tPtr->flags.focused) {
event->xbutton.x); tPtr->selection.count = 0;
tPtr->selection.count = 0; }
paintTextField(tPtr); if(textWidth < tPtr->usableWidth){
} tPtr->cursorPosition = pointToCursorPosition(tPtr,
if (event->xbutton.button == Button2 && tPtr->flags.enabled) { event->xbutton.x - tPtr->usableWidth
char *text; + textWidth);
}
else tPtr->cursorPosition = pointToCursorPosition(tPtr,
event->xbutton.x);
/*
tPtr->cursorPosition = pointToCursorPosition(tPtr,
event->xbutton.x);
tPtr->cursorPosition += tPtr->usableWidth - textWidth;
}
text = W_GetTextSelection(tPtr->view->screen, tPtr->cursorPosition = pointToCursorPosition(tPtr,
tPtr->view->screen->clipboardAtom); event->xbutton.x);
if (!text) { */
text = W_GetTextSelection(tPtr->view->screen, XA_CUT_BUFFER0); paintTextField(tPtr);
} break;
if (text) {
WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition); case WALeft:
XFree(text); if (tPtr->flags.enabled && !tPtr->flags.focused) {
WMPostNotificationName(WMTextDidChangeNotification, tPtr, WMSetFocusToWidget(tPtr);
NULL); tPtr->cursorPosition = pointToCursorPosition(tPtr,
} event->xbutton.x);
} paintTextField(tPtr);
} else if (tPtr->flags.focused) {
tPtr->cursorPosition = pointToCursorPosition(tPtr,
event->xbutton.x);
tPtr->selection.count = 0;
paintTextField(tPtr);
}
if (event->xbutton.button == Button2 && tPtr->flags.enabled) {
char *text;
text = W_GetTextSelection(tPtr->view->screen,
tPtr->view->screen->clipboardAtom);
if (!text) {
text = W_GetTextSelection(tPtr->view->screen, XA_CUT_BUFFER0);
}
if (text) {
WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition);
XFree(text);
WMPostNotificationName(WMTextDidChangeNotification, tPtr, NULL);
}
}
break;
}
break; break;
case ButtonRelease: case ButtonRelease:
{
break; int count;
XSetSelectionOwner(tPtr->view->screen->display,
XA_PRIMARY, None, CurrentTime);
count = tPtr->selection.count < 0
? tPtr->selection.position + tPtr->selection.count
: tPtr->selection.position;
XStoreBuffer(tPtr->view->screen->display,
&tPtr->text[count] , abs(tPtr->selection.count), 0);
}
break;
} }
} }

View File

@@ -106,6 +106,14 @@ wAppIconCreateForDock(WScreen *scr, char *command, char *wm_instance,
#ifdef REDUCE_APPICONS #ifdef REDUCE_APPICONS
dicon->num_apps = 0; dicon->num_apps = 0;
#endif #endif
#ifdef DEMATERIALIZE_ICON
{
XSetWindowAttributes attribs;
attribs.save_under = True;
XChangeWindowAttributes(dpy, dicon->icon->core->window,
CWSaveUnder, &attribs);
}
#endif
/* will be overriden by dock */ /* will be overriden by dock */
dicon->icon->core->descriptor.handle_mousedown = appIconMouseDown; dicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
@@ -203,6 +211,14 @@ wAppIconCreate(WWindow *leader_win)
#endif #endif
aicon->icon = wIconCreate(leader_win); aicon->icon = wIconCreate(leader_win);
#ifdef DEMATERIALIZE_ICON
{
XSetWindowAttributes attribs;
attribs.save_under = True;
XChangeWindowAttributes(dpy, aicon->icon->core->window,
CWSaveUnder, &attribs);
}
#endif
/* will be overriden if docked */ /* will be overriden if docked */
aicon->icon->core->descriptor.handle_mousedown = appIconMouseDown; aicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;

View File

@@ -62,9 +62,9 @@ extern proplist_t ReadProplistFromFile(char *file);
extern WPreferences wPreferences; extern WPreferences wPreferences;
typedef struct { typedef struct {
WScreen *screen; WScreen *screen;
WShortKey *key; WShortKey *key;
int key_no; int key_no;
} WUserMenuData; } WUserMenuData;
@@ -74,317 +74,276 @@ notifyClient(WMenu *menu, WMenuEntry *entry){
WUserMenuData *data = entry->clientdata; WUserMenuData *data = entry->clientdata;
WScreen *scr = data->screen; WScreen *scr = data->screen;
Window window; Window window;
int i; int i;
window=scr->focused_window->client_win; window=scr->focused_window->client_win;
for(i=0;i<data->key_no;i++){ for(i=0;i<data->key_no;i++){
event.xkey.type = KeyPress; event.xkey.type = KeyPress;
event.xkey.display = dpy; event.xkey.display = dpy;
event.xkey.window = window; event.xkey.window = window;
event.xkey.subwindow = 0x0; event.xkey.subwindow = 0x0;
event.xkey.x = 0x0; event.xkey.x = 0x0;
event.xkey.y = 0x0; event.xkey.y = 0x0;
event.xkey.x_root = 0x0; event.xkey.x_root = 0x0;
event.xkey.y_root = 0x0; event.xkey.y_root = 0x0;
event.xkey.keycode = data->key[i].keycode; event.xkey.keycode = data->key[i].keycode;
event.xkey.state = data->key[i].modifier; event.xkey.state = data->key[i].modifier;
event.xkey.same_screen = YES; event.xkey.same_screen = YES;
XSendEvent(dpy, window, False, NoEventMask, &event); XSendEvent(dpy, window, False, NoEventMask, &event);
XFlush(dpy); XFlush(dpy);
/* should i release key too? */ }
}
} }
static void static void
removeUserMenudata(void *menudata){ removeUserMenudata(void *menudata){
WUserMenuData *data = menudata; WUserMenuData *data = menudata;
free(data->key); if(data->key) free(data->key);
free(data); free(data);
} }
static WUserMenuData*
convertShortcut(WScreen *scr, proplist_t shortcut){
WUserMenuData *data;
KeySym ksym;
char *k;
char buf[128], *b;
data = malloc(sizeof(WUserMenuData));
data->key = malloc(sizeof(WUserMenuData));
data->key[0].modifier = 0;
strcpy(buf, PLGetString(shortcut));
b = (char*)buf;
/* get modifiers */
while ((k = strchr(b, '+'))!=NULL) {
int mod;
*k = 0;
mod = wXModifierFromKey(b);
if (mod<0) {
free(data);
return NULL;
}
data->key[0].modifier |= mod;
b = k+1;
}
/* get key */
ksym = XStringToKeysym(b);
if (ksym==NoSymbol) {
free(data);
return NULL;
}
data->key[0].keycode = XKeysymToKeycode(dpy, ksym);
if (data->key[0].keycode==0) {
free(data);
return NULL;
}
data->screen = scr;
data->key_no = 1;
return data;
}
static WUserMenuData* static WUserMenuData*
convertShortcuts(WScreen *scr, proplist_t shortcut){ convertShortcuts(WScreen *scr, proplist_t shortcut){
WUserMenuData *data; WUserMenuData *data;
KeySym ksym; KeySym ksym;
char *k; char *k;
char *buffer; char *buffer;
char buf[128], *b; char buf[128], *b;
int keycount,i,j,mod; int keycount,i,j,mod;
if (PLIsString(shortcut)){
keycount = 1;
}
else if (PLIsArray(shortcut)){
keycount = PLGetNumberOfElements(shortcut);
}
else return NULL;
/*for (i=0;i<keycount;i++){*/
data = malloc(sizeof(WUserMenuData));
data->key = malloc(sizeof(WShortKey)*keycount);
for (i=0,j=0;i<keycount;i++) {
data->key[j].modifier = 0;
if (PLIsArray(shortcut)) {
strcpy(buf, PLGetString(PLGetArrayElement(shortcut, i)));
}
else {
strcpy(buf, PLGetString(shortcut));
}
b = (char*)buf;
while ((k = strchr(b, '+'))!=NULL) { if (PLIsString(shortcut)){
*k = 0; keycount = 1;
mod = wXModifierFromKey(b); }
if (mod<0) { else if (PLIsArray(shortcut)){
break; keycount = PLGetNumberOfElements(shortcut);
} }
data->key[j].modifier |= mod; else return NULL;
b = k+1; /*for (i=0;i<keycount;i++){*/
}
if (mod<0) {
continue;
}
ksym = XStringToKeysym(b); data = wmalloc(sizeof(WUserMenuData));
if (ksym==NoSymbol) { if (!data) return NULL;
continue; data->key = wmalloc(sizeof(WShortKey)*keycount);
} if (!data->key) {
free(data);
data->key[j].keycode = XKeysymToKeycode(dpy, ksym); return NULL;
if (data->key[j].keycode) { }
j++;
}
} for (i=0,j=0;i<keycount;i++) {
data->key[j].modifier = 0;
if (PLIsArray(shortcut)) {
strcpy(buf, PLGetString(PLGetArrayElement(shortcut, i)));
}
else {
strcpy(buf, PLGetString(shortcut));
}
b = (char*)buf;
while ((k = strchr(b, '+'))!=NULL) {
*k = 0;
mod = wXModifierFromKey(b);
if (mod<0) {
break;
}
data->key[j].modifier |= mod;
b = k+1;
}
ksym = XStringToKeysym(b);
if (ksym==NoSymbol) {
continue;
}
data->key[j].keycode = XKeysymToKeycode(dpy, ksym);
if (data->key[j].keycode) {
j++;
}
}
keyover: keyover:
/* get key */ /* get key */
if (!j) { if (!j) {
free(data->key); puts("fatal j");
free(data); free(data->key);
} free(data);
data->key_no = j; return NULL;
data->screen = scr; }
data->key_no = j;
return data; data->screen = scr;
return data;
} }
static WMenu* static WMenu*
configureUserMenu(WScreen *scr, proplist_t plum){ configureUserMenu(WScreen *scr, proplist_t plum){
char *mtitle; char *mtitle;
WMenu *menu=NULL; WMenu *menu=NULL;
proplist_t elem, title, command, params; proplist_t elem, title, command, params;
int count,i; int count,i;
WUserMenuData *data; WUserMenuData *data;
if (!plum) return NULL; if (!plum) return NULL;
else if (!PLIsArray(plum)){ if (!PLIsArray(plum)){
PLRelease(plum); return NULL;
return NULL; }
}
count = PLGetNumberOfElements(plum); count = PLGetNumberOfElements(plum);
if (!count) return NULL; if (!count) return NULL;
elem = PLGetArrayElement(plum, 0); elem = PLGetArrayElement(plum, 0);
if (!PLIsString(elem)){ if (!PLIsString(elem)){
return NULL; return NULL;
} }
mtitle = PLGetString(elem); mtitle = PLGetString(elem);
menu=wMenuCreateForApp(scr, mtitle, True); menu=wMenuCreateForApp(scr, mtitle, True);
for(i=1; i<count; i++){ for(i=1; i<count; i++){
elem = PLGetArrayElement(plum,i); elem = PLGetArrayElement(plum,i);
if(PLIsArray(PLGetArrayElement(elem,1))){ if(PLIsArray(PLGetArrayElement(elem,1))){
WMenu *submenu; WMenu *submenu;
WMenuEntry *mentry; WMenuEntry *mentry;
submenu = configureUserMenu(scr,elem); submenu = configureUserMenu(scr,elem);
if (submenu) if (submenu)
mentry = wMenuAddCallback(menu, submenu->frame->title,NULL,NULL); mentry = wMenuAddCallback(menu, submenu->frame->title,
wMenuEntrySetCascade(menu, mentry, submenu); NULL, NULL);
} wMenuEntrySetCascade(menu, mentry, submenu);
else { }
int idx = 0; else {
proplist_t instances=0; int idx = 0;
proplist_t instances=0;
title = PLGetArrayElement(elem,idx++); title = PLGetArrayElement(elem,idx++);
command = PLGetArrayElement(elem,idx++); command = PLGetArrayElement(elem,idx++);
if (PLGetNumberOfElements(elem) >= 3) if (PLGetNumberOfElements(elem) >= 3)
params = PLGetArrayElement(elem,idx++); params = PLGetArrayElement(elem,idx++);
if (!title || !command) if (!title || !command)
return menu; return menu;
if (!strcmp("SHORTCUT",PLGetString(command))){ if (!strcmp("SHORTCUT",PLGetString(command))){
WMenuEntry *entry; WMenuEntry *entry;
data = convertShortcuts(scr, params);
if (data){
entry = wMenuAddCallback(menu, PLGetString(title),
notifyClient, data);
if (PLIsString(params)) {
entry->rtext = GetShortcutString(PLGetString(params));
}
if (entry) {
entry->free_cdata = removeUserMenudata;
if (PLGetNumberOfElements(elem) >= 4){ data = convertShortcuts(scr, params);
instances = PLGetArrayElement(elem,idx++); if (data){
if(PLIsArray(instances)) entry = wMenuAddCallback(menu, PLGetString(title),
if (instances && PLGetNumberOfElements(instances) notifyClient, data);
&& PLIsArray(instances)){
entry->instances = PLRetain(instances);
}
}
}
}
}
/* else if */
} if (entry) {
} if (PLIsString(params)) {
return menu; entry->rtext = GetShortcutString(PLGetString(params));
}
entry->free_cdata = removeUserMenudata;
if (PLGetNumberOfElements(elem) >= 4){
instances = PLGetArrayElement(elem,idx++);
if(PLIsArray(instances))
if (instances && PLGetNumberOfElements(instances)
&& PLIsArray(instances)){
entry->instances = PLRetain(instances);
}
}
}
}
}
}
}
return menu;
} }
void void
wUserMenuRefreshInstances(WMenu *menu, WWindow *wwin) wUserMenuRefreshInstances(WMenu *menu, WWindow *wwin)
{ {
WMenuEntry* entry; WMenuEntry* entry;
int i,j,count,paintflag; int i,j,count,paintflag;
paintflag=0; paintflag=0;
if(!menu) return; if(!menu) return;
for (i=0; i<menu->entry_no; i++) { for (i=0; i<menu->entry_no; i++) {
if (menu->entries[i]->instances){ if (menu->entries[i]->instances){
proplist_t ins; proplist_t ins;
int oldflag; int oldflag;
count = PLGetNumberOfElements(menu->entries[i]->instances); count = PLGetNumberOfElements(menu->entries[i]->instances);
oldflag = menu->entries[i]->flags.enabled; oldflag = menu->entries[i]->flags.enabled;
menu->entries[i]->flags.enabled = 0; menu->entries[i]->flags.enabled = 0;
for (j=0; j<count;j++){ for (j=0; j<count;j++){
ins = PLGetArrayElement(menu->entries[i]->instances,j); ins = PLGetArrayElement(menu->entries[i]->instances,j);
if (!strcmp(wwin->wm_instance,PLGetString(ins))){ if (!strcmp(wwin->wm_instance,PLGetString(ins))){
menu->entries[i]->flags.enabled = 1; menu->entries[i]->flags.enabled = 1;
break; break;
} }
} }
if (oldflag != menu->entries[i]->flags.enabled) if (oldflag != menu->entries[i]->flags.enabled)
paintflag=1; paintflag=1;
} }
} }
for (i=0; i < menu->cascade_no; i++) { for (i=0; i < menu->cascade_no; i++) {
if (!menu->cascades[i]->flags.brother) if (!menu->cascades[i]->flags.brother)
wUserMenuRefreshInstances(menu->cascades[i], wwin); wUserMenuRefreshInstances(menu->cascades[i], wwin);
else else
wUserMenuRefreshInstances(menu->cascades[i]->brother, wwin); wUserMenuRefreshInstances(menu->cascades[i]->brother, wwin);
} }
if(paintflag) if(paintflag)
wMenuPaint(menu); wMenuPaint(menu);
} }
static WMenu* static WMenu*
readUserMenuFile(WScreen *scr, char *file_name) readUserMenuFile(WScreen *scr, char *file_name)
{ {
WMenu *menu=NULL; WMenu *menu;
char *mtitle; char *mtitle;
proplist_t plum, elem, title, command, params;
proplist_t plum, elem, title, command, params; int count,i;
int count,i;
plum = ReadProplistFromFile(file_name); menu=NULL;
/**/ plum = ReadProplistFromFile(file_name);
/**/
if(plum){
menu = configureUserMenu(scr, plum); if(plum){
PLRelease(plum); menu = configureUserMenu(scr, plum);
} PLRelease(plum);
}
return menu; return menu;
} }
WMenu* WMenu*
wUserMenuGet(WScreen *scr, WWindow *wwin){ wUserMenuGet(WScreen *scr, WWindow *wwin){
WMenu *menu = NULL; WMenu *menu = NULL;
char buffer[100]; char buffer[100];
char *prefix, *menufile; char *prefix, *menufile;
prefix = getenv("HOME"); prefix = getenv("HOME");
if (!prefix) if (!prefix)
prefix = "."; prefix = ".";
menufile = malloc(strlen(prefix)+64); /* this file/path code will be replaced :D - ]d */
if (!menufile) return NULL; menufile = malloc(strlen(prefix)+128);
if (!menufile) return NULL;
if (wwin) {
FILE *f; if (wwin) {
sprintf(menufile, "%s/%s.%s.menu", FILE *f;
prefix, wwin->wm_instance, wwin->wm_class); sprintf(menufile, "%s/GNUstep/Library/WindowMaker/UserMenus/%s.%s.menu",
f = fopen(menufile, "r"); prefix, wwin->wm_instance, wwin->wm_class);
if (f) { f = fopen(menufile, "r");
fclose(f); if (f) {
menu = readUserMenuFile(scr, menufile); fclose(f);
} menu = readUserMenuFile(scr, menufile);
} }
}
free(menufile); free(menufile);
return menu; return menu;
} }
#endif /* USER_MENU */ #endif /* USER_MENU */

View File

@@ -206,7 +206,9 @@
/* /*
* Define DEMATERIALIZE_ICON if you want the undocked icon animation * Define DEMATERIALIZE_ICON if you want the undocked icon animation
* to be a progressive disaparison animation. * to be a progressive disaparison animation.
* This will cause all application icons to be created with Save Under
* enable.
*/ */
#undef DEMATERIALIZE_ICON #undef DEMATERIALIZE_ICON