Properly saved window enable state in windows/dialoghelper.c.

This commit is contained in:
Pietro Gagliardi 2015-05-31 11:01:10 -04:00
parent f9f5abc802
commit 60eb38ddcb
1 changed files with 9 additions and 4 deletions

View File

@ -3,11 +3,10 @@
// see http://stackoverflow.com/questions/25494914/is-there-something-like-cdn-filecancel-analogous-to-cdn-fileok-for-getting-when#comment40420049_25494914 // see http://stackoverflow.com/questions/25494914/is-there-something-like-cdn-filecancel-analogous-to-cdn-fileok-for-getting-when#comment40420049_25494914
// TODO reconcile this with users being able to enable/disable windows
struct dialogDisableWindow { struct dialogDisableWindow {
HWND hwnd; HWND hwnd;
uintmax_t n; uintmax_t n;
BOOL prevstate;
UT_hash_handle hh; UT_hash_handle hh;
}; };
@ -39,9 +38,15 @@ void dialogHelperUnregisterWindow(HWND hwnd)
static void dialogBegin(void) static void dialogBegin(void)
{ {
struct dialogDisableWindow *d; struct dialogDisableWindow *d;
BOOL prevstate;
for (d = windows; d != NULL; d = d->hh.next) { for (d = windows; d != NULL; d = d->hh.next) {
EnableWindow(d->hwnd, FALSE); prevstate = EnableWindow(d->hwnd, FALSE);
// store the previous state in case the window was already disabled by the user
// (TODO test)
// note the !; EnableWindow() returns TRUE if window was previously /disabled/
if (d->n == 0)
d->prevstate = !prevstate;
d->n++; d->n++;
} }
} }
@ -53,7 +58,7 @@ static void dialogEnd(void)
for (d = windows; d != NULL; d = d->hh.next) { for (d = windows; d != NULL; d = d->hh.next) {
d->n--; d->n--;
if (d->n == 0) if (d->n == 0)
EnableWindow(d->hwnd, TRUE); EnableWindow(d->hwnd, d->prevstate);
} }
} }