From 1b41d56ad029af50e1168e1a77e6e8432a349965 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 10 Jan 2001 04:24:11 +0000 Subject: [PATCH] - updated code to use the new runmodal loop where necessary. - made the WMRunModalLoop() reentrant (a modal panel can have its own modal panel and so on) by saving the modal related information when entering the modal loop and restoring it after. --- WINGs/wevent.c | 2 +- WINGs/wfilepanel.c | 59 +++++++++++++----------------------------------------- WINGs/widgets.c | 12 ++++++++--- WINGs/wpanel.c | 12 +++++------ 4 files changed, 30 insertions(+), 55 deletions(-) diff --git a/WINGs/wevent.c b/WINGs/wevent.c index ab646eab..d596cb02 100644 --- a/WINGs/wevent.c +++ b/WINGs/wevent.c @@ -601,7 +601,7 @@ WMHandleEvent(XEvent *event) } - if (view->screen->modal && toplevel!=view->screen->modalView + if (view->screen->modalLoop && toplevel!=view->screen->modalView && !toplevel->flags.worksWhenModal) { if (event->type == KeyPress || event->type == KeyRelease || event->type == MotionNotify || event->type == ButtonPress diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index c8974979..2fb6765e 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -42,7 +42,6 @@ typedef struct W_FilePanel { struct { unsigned int canExit:1; unsigned int canceled:1; /* clicked on cancel */ - unsigned int done:1; unsigned int filtered:1; unsigned int canChooseFiles:1; unsigned int canChooseDirectories:1; @@ -381,7 +380,6 @@ WMRunModalFilePanelForDirectory(WMFilePanel *panel, WMWindow *owner, WMSetFilePanelDirectory(panel, path); - panel->flags.done = 0; switch(panel->flags.panelType) { case WP_OPEN: if (fileTypes) @@ -402,15 +400,9 @@ WMRunModalFilePanelForDirectory(WMFilePanel *panel, WMWindow *owner, WMSetLabelText(panel->titleLabel, name); - scr->modalView = W_VIEW(panel->win); WMMapWidget(panel->win); - scr->modal = 1; - while (!panel->flags.done) { - WMNextEvent(scr->display, &event); - WMHandleEvent(&event); - } - scr->modal = 0; + WMRunModalLoop(scr, W_VIEW(panel->win)); /* Must withdraw window because the next time we map * it, it might have a different transient owner. @@ -653,41 +645,19 @@ showError(WMScreen *scr, WMWindow *owner, char *s, char *file) static void createDir(WMButton *bPre, WMFilePanel *panel) { - char *directory_name; - char *directory; - char *file; - char *s; + char *dirName, *directory, *file, *s; WMScreen *scr = WMWidgetScreen(panel->win); - WMInputPanel *_panel; - - _panel = WMCreateInputPanel(scr, panel->win, - "Create Directory", "Enter directory name", "", "OK", "Cancel"); - scr->modalView = W_VIEW(_panel->win); - WMMapWidget(_panel->win); - scr->modal = 1; - while (!_panel->done || WMScreenPending(scr)) { - XEvent event; - WMNextEvent(scr->display, &event); - WMHandleEvent(&event); - } - scr->modal = 0; - if (_panel->result == WAPRDefault) - directory_name = WMGetTextFieldText(_panel->text); - else { - WMDestroyInputPanel(_panel); + dirName = WMRunInputPanel(scr, panel->win, "Create Directory", + "Enter directory name", "", "OK", "Cancel"); + if (!dirName) return; - } - - WMDestroyInputPanel(_panel); directory = getCurrentFileName(panel); - { - char *s = strrchr(directory,'/'); - if (s) s[1] = 0; - } + s = strrchr(directory,'/'); + if (s) s[1] = 0; - if (directory_name[0] == '/') { + if (dirName[0] == '/') { directory[0] = 0; } else { while ((s = strstr(directory,"//"))) { @@ -697,15 +667,15 @@ createDir(WMButton *bPre, WMFilePanel *panel) } if ((s = strrchr(directory, '/')) && !s[1]) s[0] = 0; } - while ((s = strstr(directory_name,"//"))) { + while ((s = strstr(dirName,"//"))) { int i; for (i = 2;s[i] == '/';i++); strcpy(s, &s[i-1]); } - if ((s = strrchr(directory_name, '/')) && !s[1]) s[0] = 0; + if ((s = strrchr(dirName, '/')) && !s[1]) s[0] = 0; - file = wmalloc(strlen(directory_name)+strlen(directory)+1); - sprintf(file, "%s/%s", directory, directory_name); + file = wmalloc(strlen(dirName)+strlen(directory)+1); + sprintf(file, "%s/%s", directory, dirName); while ((s = strstr(file,"//"))) { int i; for (i = 2;s[i] == '/';i++); @@ -726,10 +696,9 @@ createDir(WMButton *bPre, WMFilePanel *panel) } else WMSetFilePanelDirectory(panel, file); - wfree(directory_name); + wfree(dirName); wfree(directory); wfree(file); - } static void @@ -1002,7 +971,7 @@ buttonClick(WMButton *bPtr, WMFilePanel *panel) range.count = range.position = 0; WMSelectTextFieldRange(panel->fileField, range); - panel->flags.done = 1; + WMBreakModalLoop(WMWidgetScreen(bPtr)); } diff --git a/WINGs/widgets.c b/WINGs/widgets.c index abb2ed32..8feae066 100644 --- a/WINGs/widgets.c +++ b/WINGs/widgets.c @@ -1048,8 +1048,11 @@ WMBreakModalLoop(WMScreen *scr) void WMRunModalLoop(WMScreen *scr, WMView *view) { - WMScreen *scr = view->screen; - + /* why is scr passed if is determined from the view? */ + /*WMScreen *scr = view->screen;*/ + int oldModalLoop = scr->modalLoop; + WMView *oldModalView = scr->modalView; + scr->modalView = view; scr->modalLoop = 1; @@ -1059,7 +1062,10 @@ WMRunModalLoop(WMScreen *scr, WMView *view) WMNextEvent(scr->display, &event); WMHandleEvent(&event); } -} + + scr->modalView = oldModalView; + scr->modalLoop = oldModalLoop; +} Display* diff --git a/WINGs/wpanel.c b/WINGs/wpanel.c index edf80728..8dd5c74d 100644 --- a/WINGs/wpanel.c +++ b/WINGs/wpanel.c @@ -130,14 +130,14 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, WMMapWidget(panel->vbox); hbox = WMCreateBox(panel->vbox); - WSetBoxHorizontal(hbox, True); + WMSetBoxHorizontal(hbox, True); WMMapWidget(hbox); - WMAddBoxSubview(panel->vbox, WMWidgetView(hbox), False, True, 80, 0, 0, 5); + WMAddBoxSubview(panel->vbox, WMWidgetView(hbox), False, True, 80, 0, 5); panel->iLbl = WMCreateLabel(hbox); WMSetLabelImagePosition(panel->iLbl, WIPImageOnly); WMMapWidget(panel->iLbl); - WMAddBoxSubview(hbox, WMWidgetView(panel->iLbl), False, True, 64, 0, 0, 10); + WMAddBoxSubview(hbox, WMWidgetView(panel->iLbl), False, True, 64, 0, 10); if (scrPtr->applicationIcon) { WMSetLabelImage(panel->iLbl, scrPtr->applicationIcon); @@ -151,7 +151,7 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, panel->tLbl = WMCreateLabel(hbox); WMMapWidget(panel->tLbl); WMAddBoxSubview(hbox, WMWidgetView(panel->tLbl), True, True, - 64, 0, 0, 0); + 64, 0, 0); WMSetLabelText(panel->tLbl, title); WMSetLabelTextAlignment(panel->tLbl, WALeft); WMSetLabelFont(panel->tLbl, largeFont); @@ -172,7 +172,7 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, panel->mLbl = WMCreateLabel(panel->win); WMMapWidget(panel->mLbl); WMAddBoxSubview(panel->vbox, WMWidgetView(panel->mLbl), True, True, - WMFontHeight(scrPtr->normalFont)*4, 0, 0, 5); + WMFontHeight(scrPtr->normalFont)*4, 0, 5); WMSetLabelText(panel->mLbl, msg); WMSetLabelTextAlignment(panel->mLbl, WACenter); } @@ -180,7 +180,7 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, hbox = WMCreateBox(panel->vbox); WMSetBoxHorizontal(hbox, True); WMMapWidget(hbox); - WMAddBoxSubview(panel->vbox, hbox, False, True, 24, 0, 0, 0); + WMAddBoxSubview(panel->vbox, WMWidgetView(hbox), False, True, 24, 0, 0); /* create buttons */ if (otherButton) -- 2.11.4.GIT