1 // Written by Christopher E. Miller
2 // See the included license.txt for copyright and license details.
3 
4 module dfl.commondialog;
5 
6 import core.sys.windows.windows;
7 
8 import dfl.exception;
9 import dfl.application;
10 import dfl.base;
11 import dfl.control;
12 import dfl.drawing;
13 import dfl.event;
14 
15 //public import dfl.filedialog;
16 //public import dfl.folderdialog;
17 //public import dfl.colordialog;
18 //public import dfl.fontdialog;
19 
20 abstract class CommonDialog {
21 
22    abstract void reset();
23 
24    // Uses currently active window of the application as owner.
25    abstract DialogResult showDialog();
26 
27    abstract DialogResult showDialog(IWindow owner);
28 
29    Event!(CommonDialog, HelpEventArgs) helpRequest;
30 
31 protected:
32 
33    // See the CDN_* Windows notification messages.
34    LRESULT hookProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
35       switch (msg) {
36          case WM_NOTIFY:
37             NMHDR* nmhdr;
38             nmhdr = cast(NMHDR*) lparam;
39             switch (nmhdr.code) {
40                case CDN_HELP:
41                   Point pt;
42                   GetCursorPos(&pt.point);
43                   onHelpRequest(new HelpEventArgs(pt));
44                   break;
45 
46                default:
47             }
48             break;
49 
50          default:
51       }
52       return 0;
53    }
54 
55    // TODO: implement.
56    //LRESULT ownerWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
57 
58    void onHelpRequest(HelpEventArgs ea) {
59       helpRequest(this, ea);
60    }
61 
62    abstract bool runDialog(HWND owner);
63 
64    package final void _cantrun() {
65       throw new DflException("Error running dialog");
66    }
67 }