mirror of https://github.com/buggins/dlangui.git
allow processing of window close event - e.g. to disable closing if there is unsaved data - issue #60 implemented for win32 backend
This commit is contained in:
parent
26d9481506
commit
d34ffd75a1
|
@ -276,6 +276,22 @@ class Window {
|
||||||
/// set handler for files dropped to app window
|
/// set handler for files dropped to app window
|
||||||
@property Window onFilesDropped(void delegate(string[]) handler) { _onFilesDropped = handler; return this; }
|
@property Window onFilesDropped(void delegate(string[]) handler) { _onFilesDropped = handler; return this; }
|
||||||
|
|
||||||
|
protected bool delegate() _onCanClose;
|
||||||
|
/// get handler for closing of app (it must return true to allow immediate close, false to cancel close or close window later)
|
||||||
|
@property bool delegate() onCanClose() { return _onCanClose; }
|
||||||
|
/// set handler for closing of app (it must return true to allow immediate close, false to cancel close or close window later)
|
||||||
|
@property Window onCanClose(bool delegate() handler) { _onCanClose = handler; return this; }
|
||||||
|
|
||||||
|
/// calls onCanClose handler if set to check if system may close window
|
||||||
|
bool handleCanClose() {
|
||||||
|
if (!_onCanClose)
|
||||||
|
return true;
|
||||||
|
bool res = _onCanClose();
|
||||||
|
if (!res)
|
||||||
|
update(true); // redraw window if it was decided to not close immediately
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// hide tooltip if shown and cancel tooltip timer if set
|
/// hide tooltip if shown and cancel tooltip timer if set
|
||||||
void hideTooltip() {
|
void hideTooltip() {
|
||||||
|
|
|
@ -1164,6 +1164,13 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
DragFinish(hdrop);
|
DragFinish(hdrop);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
case WM_CLOSE:
|
||||||
|
if (window !is null) {
|
||||||
|
if (!window.handleCanClose())
|
||||||
|
return 0; // prevent closing
|
||||||
|
}
|
||||||
|
// default handler inside DefWindowProc will close window
|
||||||
|
break;
|
||||||
case WM_GETMINMAXINFO:
|
case WM_GETMINMAXINFO:
|
||||||
case WM_NCCREATE:
|
case WM_NCCREATE:
|
||||||
case WM_NCCALCSIZE:
|
case WM_NCCALCSIZE:
|
||||||
|
|
Loading…
Reference in New Issue