1 /** DGui project file.
2 
3 Copyright: Trogu Antonio Davide 2011-2013
4 
5 License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 
7 Authors: Trogu Antonio Davide
8 */
9 module dguihub.core.windowclass;
10 
11 import std.utf : toUTFz;
12 import dguihub.core.charset;
13 import dguihub.core.winapi;
14 import dguihub.core.exception;
15 import dguihub.core.utils;
16 import dguihub.canvas;
17 
18 enum {
19    // Windows Classes
20    WC_BUTTON = "Button",
21    WC_COMBOBOXEX = "ComboBoxEx32",
22    WC_LISTBOX = "ListBox",
23    WC_LISTVIEW = "SysListView32",
24    WC_PROGRESSBAR = "msctls_progress32",
25    WC_RICHEDIT = "RichEdit20W",
26    WC_STATUSBAR = "msctls_statusbar32",
27    WC_TABCONTROL = "SysTabControl32",
28    WC_EDIT = "EDIT",
29    WC_TOOLBAR = "ToolBarWindow32",
30    WC_TRACKBAR = "msctls_trackbar32",
31    WC_TOOLTIP = "tooltips_class32",
32    WC_TREEVIEW = "SysTreeView32",
33    //WC_STATIC 		= "STATIC",
34 
35    // DGui Classes
36    WC_DPANEL = "DPanel",
37    WC_FORM = "DForm",
38    WC_DBUTTON = "DButton",
39    WC_DCHECKBOX = "DCheckBox",
40    WC_DRADIOBUTTON = "DRadioButton",
41    WC_DCOMBOBOX = "DComboBox",
42    WC_DLABEL = "DLabel",
43    WC_DLISTBOX = "DListBox",
44    WC_DPICTUREBOX = "DPicturebox",
45    WC_DLISTVIEW = "DListView",
46    WC_DPROGRESSBAR = "DProgressBar",
47    WC_DRICHEDIT = "DRichTextBox",
48    WC_DSTATUSBAR = "DStatusBar",
49    WC_DTABCONTROL = "DTabControl",
50    WC_DEDIT = "DTextBox",
51    WC_DTOOLBAR = "DToolBar",
52    WC_DTRACKBAR = "DTrackBar",
53    WC_DTOOLTIP = "DToolTip",
54    WC_DTREEVIEW = "DTreeView",
55    WC_DGRIDPANEL = "DGridPanel",
56    WC_DSPLITPANEL = "DSplitPanel",
57 }
58 
59 enum ClassStyles : uint {
60    none = 0x00000000,
61    vRedraw = 0x00000001,
62    hRedraw = 0x00000002,
63    keyCVTWindow = 0x00000004,
64    doubleClicks = 0x00000008,
65    ownDC = 0x00000020,
66    classDC = 0x00000040,
67    parentDC = 0x00000080,
68    noKeyCVT = 0x00000100,
69    noClose = 0x00000200,
70    saveBits = 0x00000800,
71    byteAlignClient = 0x00001000,
72    byteAlignWindow = 0x00002000,
73    globalClass = 0x00004000,
74    IME = 0x00010000,
75 }
76 
77 final class WindowClass {
78    public static void register(string className, ClassStyles classStyle,
79          Cursor cursor, WNDPROC wndProc) {
80       WNDCLASSEXW wc;
81       wc.cbSize = WNDCLASSEXW.sizeof;
82 
83       if (!getClassInfoEx(className, &wc)) {
84          if (!registerClassEx(className, cursor ? cursor.handle
85                : SystemCursors.arrow.handle, null, wndProc, classStyle)) {
86             throwException!(Win32Exception)("Windows Class '%s' not created", className);
87          }
88       }
89    }
90 
91    public static WNDPROC superclass(string oldClassName, string newClassName, WNDPROC newWndProc) {
92       WNDCLASSEXW oldWc = void, newWc = void;
93 
94       oldWc.cbSize = WNDCLASSEXW.sizeof;
95       newWc.cbSize = WNDCLASSEXW.sizeof;
96 
97       const(wchar)* pNewClassName = toUTFz!(const(wchar)*)(newClassName);
98       getClassInfoEx(oldClassName, &oldWc);
99 
100       if (!getClassInfoEx(newClassName, &newWc)) // IF Class Non Found THEN
101       {
102          newWc = oldWc;
103          newWc.style &= ~ClassStyles.globalClass; // Remove Global Class
104 
105          newWc.lpfnWndProc = newWndProc;
106          newWc.lpszClassName = pNewClassName;
107          newWc.hInstance = getHInstance();
108          //newWc.hbrBackground = null;
109 
110          if (!registerClassEx(&newWc)) {
111             throwException!(Win32Exception)("Windows Class '%s' not created", newClassName);
112          }
113       }
114 
115       return oldWc.lpfnWndProc; //Back to the original window procedure
116    }
117 }