comparison dwt/widgets/Link.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children b4846fd3437a
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
90 LINK_FOREGROUND = new RGB (0, 51, 153); 90 LINK_FOREGROUND = new RGB (0, 51, 153);
91 if (OS.COMCTL32_MAJOR >= 6) { 91 if (OS.COMCTL32_MAJOR >= 6) {
92 WNDCLASS lpWndClass; 92 WNDCLASS lpWndClass;
93 OS.GetClassInfo (null, LinkClass.ptr, &lpWndClass); 93 OS.GetClassInfo (null, LinkClass.ptr, &lpWndClass);
94 LinkProc = lpWndClass.lpfnWndProc; 94 LinkProc = lpWndClass.lpfnWndProc;
95 /*
96 * Feature in Windows. The SysLink window class
97 * does not include CS_DBLCLKS. This means that these
98 * controls will not get double click messages such as
99 * WM_LBUTTONDBLCLK. The fix is to register a new
100 * window class with CS_DBLCLKS.
101 *
102 * NOTE: Screen readers look for the exact class name
103 * of the control in order to provide the correct kind
104 * of assistance. Therefore, it is critical that the
105 * new window class have the same name. It is possible
106 * to register a local window class with the same name
107 * as a global class. Since bits that affect the class
108 * are being changed, it is possible that other native
109 * code, other than DWT, could create a control with
110 * this class name, and fail unexpectedly.
111 */
112 auto hInstance = OS.GetModuleHandle (null);
113 auto hHeap = OS.GetProcessHeap ();
114 lpWndClass.hInstance = hInstance;
115 lpWndClass.style &= ~OS.CS_GLOBALCLASS;
116 lpWndClass.style |= OS.CS_DBLCLKS;
117 int byteCount = LinkClass.length * TCHAR.sizeof;
118 auto lpszClassName = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
119 OS.MoveMemory (lpszClassName, LinkClass.ptr, byteCount);
120 lpWndClass.lpszClassName = lpszClassName;
121 OS.RegisterClass (&lpWndClass);
122 OS.HeapFree (hHeap, 0, lpszClassName);
95 } else { 123 } else {
96 LinkProc = null; 124 LinkProc = null;
97 } 125 }
98 static_this_completed = true; 126 static_this_completed = true;
99 } 127 }
163 addListener (DWT.DefaultSelection, typedListener); 191 addListener (DWT.DefaultSelection, typedListener);
164 } 192 }
165 193
166 override int callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { 194 override int callWindowProc (HWND hwnd, int msg, int wParam, int lParam) {
167 if (handle is null) return 0; 195 if (handle is null) return 0;
168 if (LinkProc !is null) return OS.CallWindowProc (LinkProc, hwnd, msg, wParam, lParam); 196 if (LinkProc !is null) {
197 /*
198 * Feature in Windows. By convention, native Windows controls
199 * check for a non-NULL wParam, assume that it is an HDC and
200 * paint using that device. The SysLink control does not.
201 * The fix is to check for an HDC and use WM_PRINTCLIENT.
202 */
203 switch (msg) {
204 case OS.WM_PAINT:
205 if (wParam !is 0) {
206 OS.SendMessage (hwnd, OS.WM_PRINTCLIENT, wParam, 0);
207 return 0;
208 }
209 break;
210 default:
211 }
212 return OS.CallWindowProc (LinkProc, hwnd, msg, wParam, lParam);
213 }
169 return OS.DefWindowProc (hwnd, msg, wParam, lParam); 214 return OS.DefWindowProc (hwnd, msg, wParam, lParam);
170 } 215 }
171 216
172 override public Point computeSize (int wHint, int hHint, bool changed) { 217 override public Point computeSize (int wHint, int hHint, bool changed) {
173 checkWidget (); 218 checkWidget ();
176 int width, height; 221 int width, height;
177 if (OS.COMCTL32_MAJOR >= 6) { 222 if (OS.COMCTL32_MAJOR >= 6) {
178 auto hDC = OS.GetDC (handle); 223 auto hDC = OS.GetDC (handle);
179 auto newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 224 auto newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
180 auto oldFont = OS.SelectObject (hDC, newFont); 225 auto oldFont = OS.SelectObject (hDC, newFont);
181 TCHAR[] buffer = StrToTCHARs (getCodePage (), parse (text)); 226 if (text.length > 0) {
182 RECT rect; 227 TCHAR[] buffer = StrToTCHARs (getCodePage (), parse (text));
183 int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX; 228 RECT rect;
184 if (wHint !is DWT.DEFAULT) { 229 int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX;
185 flags |= OS.DT_WORDBREAK; 230 if (wHint !is DWT.DEFAULT) {
186 rect.right = wHint; 231 flags |= OS.DT_WORDBREAK;
187 } 232 rect.right = wHint;
188 OS.DrawText (hDC, buffer.ptr, buffer.length, &rect, flags); 233 }
189 width = rect.right - rect.left; 234 OS.DrawText (hDC, buffer.ptr, buffer.length, &rect, flags);
190 height = rect.bottom; 235 width = rect.right - rect.left;
236 height = rect.bottom;
237 } else {
238 TEXTMETRIC lptm;
239 OS.GetTextMetrics (hDC, &lptm);
240 width = 0;
241 height = lptm.tmHeight;
242 }
191 if (newFont !is null) OS.SelectObject (hDC, oldFont); 243 if (newFont !is null) OS.SelectObject (hDC, oldFont);
192 OS.ReleaseDC (handle, hDC); 244 OS.ReleaseDC (handle, hDC);
193 } else { 245 } else {
194 int layoutWidth = layout.getWidth (); 246 int layoutWidth = layout.getWidth ();
195 //TEMPORARY CODE 247 //TEMPORARY CODE
525 } 577 }
526 index++; 578 index++;
527 } 579 }
528 if (start < length_) { 580 if (start < length_) {
529 int tmp = parseMnemonics (buffer, start, tagStart, result); 581 int tmp = parseMnemonics (buffer, start, tagStart, result);
530 int mnemonic = parseMnemonics (buffer, linkStart, index, result); 582 int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length_, result);
531 if (mnemonic is -1) mnemonic = tmp; 583 if (mnemonic is -1) mnemonic = tmp;
532 mnemonics [linkIndex] = mnemonic; 584 mnemonics [linkIndex] = mnemonic;
533 } else { 585 } else {
534 mnemonics [linkIndex] = -1; 586 mnemonics [linkIndex] = -1;
535 } 587 }
724 * NOTE: Call the window proc with WM_KEYDOWN rather than WM_CHAR 776 * NOTE: Call the window proc with WM_KEYDOWN rather than WM_CHAR
725 * so that the key that was ignored during WM_KEYDOWN is processed. 777 * so that the key that was ignored during WM_KEYDOWN is processed.
726 * This allows the application to cancel an operation that is normally 778 * This allows the application to cancel an operation that is normally
727 * performed in WM_KEYDOWN from WM_CHAR. 779 * performed in WM_KEYDOWN from WM_CHAR.
728 */ 780 */
729 int code = callWindowProc (handle, OS.WM_KEYDOWN, wParam, lParam); 781 int /*long*/ code = callWindowProc (handle, OS.WM_KEYDOWN, wParam, lParam);
730 return new LRESULT (code); 782 return new LRESULT (code);
731 default: 783 default:
732 } 784 }
733 785
734 } 786 }
736 } 788 }
737 789
738 override LRESULT WM_GETDLGCODE (int wParam, int lParam) { 790 override LRESULT WM_GETDLGCODE (int wParam, int lParam) {
739 LRESULT result = super.WM_GETDLGCODE (wParam, lParam); 791 LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
740 if (result !is null) return result; 792 if (result !is null) return result;
741 int index, count, code = 0; 793 int index, count;
794 int /*long*/ code = 0;
742 if (OS.COMCTL32_MAJOR >= 6) { 795 if (OS.COMCTL32_MAJOR >= 6) {
743 LITEM item; 796 LITEM item;
744 item.mask = OS.LIF_ITEMINDEX | OS.LIF_STATE; 797 item.mask = OS.LIF_ITEMINDEX | OS.LIF_STATE;
745 item.stateMask = OS.LIS_FOCUSED; 798 item.stateMask = OS.LIS_FOCUSED;
746 index = 0; 799 index = 0;
770 } 823 }
771 824
772 override LRESULT WM_GETFONT (int wParam, int lParam) { 825 override LRESULT WM_GETFONT (int wParam, int lParam) {
773 LRESULT result = super.WM_GETFONT (wParam, lParam); 826 LRESULT result = super.WM_GETFONT (wParam, lParam);
774 if (result !is null) return result; 827 if (result !is null) return result;
775 int code = callWindowProc (handle, OS.WM_GETFONT, wParam, lParam); 828 int /*long*/ code = callWindowProc (handle, OS.WM_GETFONT, wParam, lParam);
776 if (code !is 0) return new LRESULT (code); 829 if (code !is 0) return new LRESULT (code);
777 if (font is null) font = defaultFont (); 830 if (font is null) font = defaultFont ();
778 return new LRESULT ( cast(int) font); 831 return new LRESULT ( cast(int) font);
779 } 832 }
780 833
808 override LRESULT WM_LBUTTONDOWN (int wParam, int lParam) { 861 override LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
809 LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam); 862 LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
810 if (result is LRESULT.ZERO) return result; 863 if (result is LRESULT.ZERO) return result;
811 if (OS.COMCTL32_MAJOR < 6) { 864 if (OS.COMCTL32_MAJOR < 6) {
812 if (focusIndex !is -1) setFocus (); 865 if (focusIndex !is -1) setFocus ();
813 int x = lParam & 0xFFFF; 866 int x = OS.GET_X_LPARAM (lParam);
814 int y = lParam >> 16; 867 int y = OS.GET_Y_LPARAM (lParam);
815 int offset = layout.getOffset (x, y, null); 868 int offset = layout.getOffset (x, y, null);
816 int oldSelectionX = selection.x; 869 int oldSelectionX = selection.x;
817 int oldSelectionY = selection.y; 870 int oldSelectionY = selection.y;
818 selection.x = offset; 871 selection.x = offset;
819 selection.y = -1; 872 selection.y = -1;
846 override LRESULT WM_LBUTTONUP (int wParam, int lParam) { 899 override LRESULT WM_LBUTTONUP (int wParam, int lParam) {
847 LRESULT result = super.WM_LBUTTONUP (wParam, lParam); 900 LRESULT result = super.WM_LBUTTONUP (wParam, lParam);
848 if (result is LRESULT.ZERO) return result; 901 if (result is LRESULT.ZERO) return result;
849 if (OS.COMCTL32_MAJOR < 6) { 902 if (OS.COMCTL32_MAJOR < 6) {
850 if (mouseDownIndex is -1) return result; 903 if (mouseDownIndex is -1) return result;
851 int x = lParam & 0xFFFF; 904 int x = OS.GET_X_LPARAM (lParam);
852 int y = lParam >> 16; 905 int y = OS.GET_Y_LPARAM (lParam);
853 Rectangle [] rects = getRectangles (mouseDownIndex); 906 Rectangle [] rects = getRectangles (mouseDownIndex);
854 for (int i = 0; i < rects.length; i++) { 907 for (int i = 0; i < rects.length; i++) {
855 Rectangle rect = rects [i]; 908 Rectangle rect = rects [i];
856 if (rect.contains (x, y)) { 909 if (rect.contains (x, y)) {
857 Event event = new Event (); 910 Event event = new Event ();
863 } 916 }
864 mouseDownIndex = -1; 917 mouseDownIndex = -1;
865 return result; 918 return result;
866 } 919 }
867 920
921 override LRESULT WM_NCHITTEST (int wParam, int lParam) {
922 LRESULT result = super.WM_NCHITTEST (wParam, lParam);
923 if (result !is null) return result;
924
925 /*
926 * Feature in Windows. For WM_NCHITTEST, the Syslink window proc
927 * returns HTTRANSPARENT when mouse is over plain text. The fix is
928 * to always return HTCLIENT.
929 */
930 if (OS.COMCTL32_MAJOR >= 6) return new LRESULT (OS.HTCLIENT);
931
932 return result;
933 }
934
868 override LRESULT WM_MOUSEMOVE (int wParam, int lParam) { 935 override LRESULT WM_MOUSEMOVE (int wParam, int lParam) {
869 LRESULT result = super.WM_MOUSEMOVE (wParam, lParam); 936 LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
870 if (OS.COMCTL32_MAJOR < 6) { 937 if (OS.COMCTL32_MAJOR < 6) {
871 int x = lParam & 0xFFFF; 938 int x = OS.GET_X_LPARAM (lParam);
872 int y = lParam >> 16; 939 int y = OS.GET_Y_LPARAM (lParam);
873 if (OS.GetKeyState (OS.VK_LBUTTON) < 0) { 940 if (OS.GetKeyState (OS.VK_LBUTTON) < 0) {
874 int oldSelection = selection.y; 941 int oldSelection = selection.y;
875 selection.y = layout.getOffset (x, y, null); 942 selection.y = layout.getOffset (x, y, null);
876 if (selection.y !is oldSelection) { 943 if (selection.y !is oldSelection) {
877 int newSelection = selection.y; 944 int newSelection = selection.y;