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 dgui.core.controls.reflectedcontrol;
10 
11 public import dgui.core.controls.control;
12 
13 abstract class ReflectedControl: Control
14 {
15 	private void reflectMessageToChild(ref Message m)
16 	{
17 		HWND hFrom = void; //Inizializzata sotto
18 
19 		switch(m.msg)
20 		{
21 			case WM_NOTIFY:
22 				NMHDR* pNotify = cast(NMHDR*)m.lParam;
23 				hFrom = pNotify.hwndFrom;
24 				break;
25 
26 			case WM_MEASUREITEM:
27 			{
28 				MEASUREITEMSTRUCT* pMeasureItem = cast(MEASUREITEMSTRUCT*)m.lParam;
29 
30 				switch(pMeasureItem.CtlType)
31 				{
32 					case ODT_COMBOBOX:
33 						hFrom = GetParent(cast(HWND)pMeasureItem.CtlID);
34 						break;
35 
36 					case ODT_MENU:
37 						hFrom = this._handle; // Set the owner of the menu (this window)
38 						break;
39 
40 					default:
41 						hFrom = cast(HWND)pMeasureItem.CtlID;
42 						break;
43 				}
44 			}
45 			break;
46 
47 			case WM_DRAWITEM:
48 			{
49 				DRAWITEMSTRUCT* pDrawItem = cast(DRAWITEMSTRUCT*)m.lParam;
50 
51 				switch(pDrawItem.CtlType)
52 				{
53 					case ODT_COMBOBOX:
54 						hFrom = GetParent(pDrawItem.hwndItem);
55 						break;
56 
57 					case ODT_MENU:
58 						hFrom = this._handle; // Set the owner of the menu (this window)
59 						break;
60 
61 					default:
62 						hFrom = cast(HWND)pDrawItem.hwndItem;
63 						break;
64 				}
65 			}
66 			break;
67 
68 			default: // WM_COMMAND
69 				hFrom = cast(HWND)m.lParam;
70 				break;
71 		}
72 
73 		/* If 'hFrom' is this window, the notification is sent by menus */
74 		Control c = winCast!(Control)(GetWindowLongW(hFrom, GWL_USERDATA));
75 
76 		if(c)
77 		{
78 			c.sendMessage(DGUI_REFLECTMESSAGE, cast(WPARAM)&m, 0);
79 		}
80 	}
81 
82 	protected override void wndProc(ref Message m)
83 	{
84 		switch(m.msg)
85 		{
86 			case WM_NOTIFY, WM_COMMAND, WM_MEASUREITEM, WM_DRAWITEM, WM_CTLCOLOREDIT, WM_CTLCOLORBTN:
87 			{
88 				this.originalWndProc(m); //Components like: ComboBoxEx need this one!
89 
90 				if(ReflectedControl.hasBit(this._cBits, ControlBits.canNotify)) //Avoid fake notification messages caused by component's properties (like text(), checked(), ...)
91 				{
92 					this.reflectMessageToChild(m);
93 				}
94 			}
95 			break;
96 
97 			default:
98 				super.wndProc(m);
99 				break;
100 		}
101 	}
102 }