From 63dc09b62c3a6430c671b8fd5ebd4be691167173 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Sun, 7 Sep 2014 12:10:50 +0200 Subject: [PATCH] Provide DoEvents function in front-ends A routine to process all pending events in a non-blocking way is now provided in the Xaw, GTK+ and WinBoard front-ends, so that time-consuming tasks (such as PGN loading or opening-book creation) can call it to keep the user control over the application alive. --- frontend.h | 1 + gtk/xboard.c | 6 ++++++ winboard/winboard.c | 35 +++++++++++++++++++++++++++++------ xaw/xboard.c | 7 +++++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/frontend.h b/frontend.h index 6dcc1f7..a81fd4b 100644 --- a/frontend.h +++ b/frontend.h @@ -108,6 +108,7 @@ void Raw P((void)); void Colorize P((ColorClass cc, int continuation)); char *InterpretFileName P((char *name, char *dir)); void DoSleep P((int n)); +void DoEvents P((void)); char *UserName P((void)); char *HostName P((void)); diff --git a/gtk/xboard.c b/gtk/xboard.c index d6f47d7..de8c897 100644 --- a/gtk/xboard.c +++ b/gtk/xboard.c @@ -1191,6 +1191,12 @@ gtk_main_iteration(); return 0; } +void +DoEvents () +{ + while(gtk_events_pending()) gtk_main_iteration(); +} + RETSIGTYPE TermSizeSigHandler (int sig) { diff --git a/winboard/winboard.c b/winboard/winboard.c index 088badb..3515cb3 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -786,12 +786,14 @@ void ThawUI() * \*---------------------------------------------------------------------------*/ +static void HandleMessage P((MSG *message)); +static HANDLE hAccelMain, hAccelNoAlt, hAccelNoICS; + int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; - HANDLE hAccelMain, hAccelNoAlt, hAccelNoICS; // INITCOMMONCONTROLSEX ex; debugFP = stderr; @@ -823,6 +825,17 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 0, /* lowest message to examine */ 0)) /* highest message to examine */ { + HandleMessage(msg); + } + + + return (msg.wParam); /* Returns the value from PostQuitMessage */ +} + +static void +HandleMessage (MSG *message) +{ + MSG msg = *message; if(msg.message == WM_CHAR && msg.wParam == '\t') { // [HGM] navigate: switch between all windows with tab @@ -890,7 +903,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, if(currentElement < 5 && IsIconic(hwndMain)) ShowWindow(hwndMain, SW_RESTORE); // all open together SetFocus(h); - continue; // this message now has been processed + return; // this message now has been processed } } @@ -909,14 +922,24 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, if(chatHandle[i] && IsDialogMessage(chatHandle[i], &msg)) { done = 1; break; } - if(done) continue; // [HGM] chat: end patch + if(done) return; // [HGM] chat: end patch TranslateMessage(&msg); /* Translates virtual key codes */ DispatchMessage(&msg); /* Dispatches message to window */ } - } - +} - return (msg.wParam); /* Returns the value from PostQuitMessage */ +void +DoEvents () +{ /* Dispatch pending messages */ + MSG msg; + while (PeekMessage(&msg, /* message structure */ + NULL, /* handle of window receiving the message */ + 0, /* lowest message to examine */ + 0, /* highest message to examine */ + PM_REMOVE)) + { + HandleMessage(msg); + } } /*---------------------------------------------------------------------------*\ diff --git a/xaw/xboard.c b/xaw/xboard.c index 02149e5..17a9752 100644 --- a/xaw/xboard.c +++ b/xaw/xboard.c @@ -1353,6 +1353,13 @@ main (int argc, char **argv) return 0; } +void +DoEvents () +{ + XtInputMask m; + while((m = XtAppPending(appContext))) XtAppProcessEvent(appContext, m); +} + RETSIGTYPE TermSizeSigHandler (int sig) { -- 1.7.0.4