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