source: trunk/src/comctl32/CCBase.cpp@ 8706

Last change on this file since 8706 was 8382, checked in by sandervl, 23 years ago

merge with latest Wine

File size: 10.0 KB
Line 
1/* $Id: CCBase.cpp,v 1.10 2002-05-08 11:24:58 sandervl Exp $ */
2/*
3 * COMCTL32 Base Functions and Macros for all Controls
4 *
5 * Copyright 2000 Christoph Bratschi (cbratschi@datacomm.ch)
6 *
7 * parts from WINE code
8 */
9#include <winuser.h>
10#include <string.h>
11#include <wcstr.h>
12#include "winbase.h"
13#include "comctl32.h"
14#include <commctrl.h>
15#include "ccbase.h"
16
17BOOL checkVersion(INT iVersion)
18{
19 return iVersion <= COMCTL32_VERSION;
20}
21
22//init-done
23
24PVOID initControl(HWND hwnd,DWORD dwSize)
25{
26 COMCTL32_HEADER *infoPtr;
27
28 if (dwSize < sizeof(COMCTL32_HEADER)) return NULL;
29
30 infoPtr = (COMCTL32_HEADER*)COMCTL32_Alloc(dwSize);
31
32 if (!infoPtr) return NULL;
33
34 setInfoPtr(hwnd,infoPtr);
35 ZeroMemory(infoPtr,dwSize);
36 infoPtr->dwSize = dwSize;
37 infoPtr->iVersion = 0;
38 infoPtr->fUnicode = IsWindowUnicode(hwnd);
39 infoPtr->uNotifyFormat = sendNotifyFormat(GetParent(hwnd),hwnd,NF_QUERY);
40 infoPtr->hwndNotify = GetParent(hwnd);
41
42 return infoPtr;
43}
44
45VOID doneControl(HWND hwnd)
46{
47 COMCTL32_HEADER *infoPtr = getInfoPtr(hwnd);
48
49 if (infoPtr)
50 {
51 COMCTL32_Free(infoPtr);
52 setInfoPtr(hwnd,NULL);
53 }
54}
55
56//Default message handler
57
58LRESULT defComCtl32Proc(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam,BOOL unicode)
59{
60 COMCTL32_HEADER *infoPtr;
61
62 switch (Msg)
63 {
64 case CCM_GETVERSION:
65 infoPtr = getInfoPtr(hwnd);
66 return infoPtr ? infoPtr->iVersion:0;
67
68 case CCM_SETVERSION:
69 infoPtr = getInfoPtr(hwnd);
70 if (infoPtr)
71 {
72 if (checkVersion((INT)wParam))
73 {
74 INT oldVersion;
75
76 oldVersion = infoPtr->iVersion;
77 infoPtr->iVersion = (INT)wParam;
78 return oldVersion;
79 } else return -1;
80 } else return 0;
81
82 case CCM_GETUNICODEFORMAT:
83 infoPtr = getInfoPtr(hwnd);
84 return infoPtr ? infoPtr->fUnicode:IsWindowUnicode(hwnd);
85
86 case CCM_SETUNICODEFORMAT:
87 infoPtr = getInfoPtr(hwnd);
88 if (infoPtr)
89 {
90 BOOL oldFormat;
91
92 oldFormat = infoPtr->fUnicode;
93 infoPtr->fUnicode = (INT)wParam;
94 return oldFormat;
95 } else return IsWindowUnicode(hwnd);
96
97 case WM_NOTIFYFORMAT:
98 {
99 infoPtr = getInfoPtr(hwnd);
100
101 if (!infoPtr) break;
102
103 if (lParam == NF_REQUERY)
104 {
105 infoPtr->uNotifyFormat = sendNotifyFormat(GetParent(hwnd),hwnd,NF_QUERY);
106 if ((infoPtr->uNotifyFormat != NFR_ANSI) && (infoPtr->uNotifyFormat != NFR_UNICODE))
107 infoPtr->uNotifyFormat = IsWindowUnicode(GetParent(hwnd)) ? NFR_UNICODE:NFR_ANSI;
108 return infoPtr->uNotifyFormat;
109 } else if (lParam == NF_QUERY)
110 {
111 return infoPtr->uNotifyFormat;
112 }
113 break;
114 }
115
116 case CCM_SETNOTIFYWINDOW:
117 {
118 infoPtr = getInfoPtr(hwnd);
119
120 if (!infoPtr) break;
121
122 infoPtr->hwndNotify = (HWND)wParam;
123
124 break;
125 }
126 }
127
128 if (unicode)
129 return DefWindowProcW(hwnd,Msg,wParam,lParam);
130 else
131 return DefWindowProcA(hwnd,Msg,wParam,lParam);
132}
133
134LRESULT defComCtl32ProcA(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam)
135{
136 return defComCtl32Proc(hwnd,Msg,wParam,lParam,FALSE);
137}
138
139LRESULT defComCtl32ProcW(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam)
140{
141 return defComCtl32Proc(hwnd,Msg,wParam,lParam,TRUE);
142}
143
144//Notifications
145
146BOOL isUnicodeNotify(COMCTL32_HEADER *infoPtr)
147{
148 if (!infoPtr) return FALSE;
149
150 return infoPtr->uNotifyFormat == NFR_UNICODE;
151}
152
153BOOL isUnicodeNotify(HWND hwnd)
154{
155 COMCTL32_HEADER *infoPtr = getInfoPtr(hwnd);
156
157 return isUnicodeNotify(infoPtr);
158}
159
160HWND getNotifyWindow(COMCTL32_HEADER *infoPtr)
161{
162 if (!infoPtr) return 0;
163
164 return infoPtr->hwndNotify;
165}
166
167HWND getNotifyWindow(HWND hwnd)
168{
169 COMCTL32_HEADER *infoPtr = getInfoPtr(hwnd);
170
171 return getNotifyWindow(infoPtr);
172}
173
174LRESULT sendNotify(HWND hwnd,UINT code)
175{
176 NMHDR nmhdr;
177
178 nmhdr.hwndFrom = hwnd;
179 nmhdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
180 nmhdr.code = code;
181
182 return SendMessageA(getNotifyWindow(hwnd),WM_NOTIFY,nmhdr.idFrom,(LPARAM)&nmhdr);
183}
184
185LRESULT sendNotify(HWND hwndFrom,HWND hwndTo,UINT code)
186{
187 NMHDR nmhdr;
188
189 nmhdr.hwndFrom = hwndFrom;
190 nmhdr.idFrom = GetWindowLongA(hwndFrom,GWL_ID);
191 nmhdr.code = code;
192
193 return SendMessageA(hwndTo,WM_NOTIFY,nmhdr.idFrom,(LPARAM)&nmhdr);
194}
195
196LRESULT sendNotify(HWND hwnd,UINT code,LPNMHDR nmhdr)
197{
198 if (!nmhdr) return 0;
199
200 nmhdr->hwndFrom = hwnd;
201 nmhdr->idFrom = GetWindowLongA(hwnd,GWL_ID);
202 nmhdr->code = code;
203
204 return SendMessageA(getNotifyWindow(hwnd),WM_NOTIFY,nmhdr->idFrom,(LPARAM)nmhdr);
205}
206
207LRESULT sendNotify(HWND hwndFrom,HWND hwndTo,UINT code,LPNMHDR nmhdr)
208{
209 if (!nmhdr) return 0;
210
211 nmhdr->hwndFrom = hwndFrom;
212 nmhdr->idFrom = GetWindowLongA(hwndFrom,GWL_ID);
213 nmhdr->code = code;
214
215 return SendMessageA(hwndTo,WM_NOTIFY,nmhdr->idFrom,(LPARAM)nmhdr);
216}
217
218LRESULT sendNotifyFormat(HWND hwnd,HWND hwndFrom,LPARAM command)
219{
220 return SendMessageA(hwnd,WM_NOTIFYFORMAT,hwndFrom,command);
221}
222
223LRESULT sendCommand(HWND hwnd,UINT wNotifyCode)
224{
225 return SendMessageA(getNotifyWindow(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),wNotifyCode),(LPARAM)hwnd);
226}
227
228LRESULT sendHScroll(HWND hwnd,UINT wNotifyCode)
229{
230 return SendMessageA(getNotifyWindow(hwnd),WM_HSCROLL,(WPARAM)wNotifyCode,(LPARAM)hwnd);
231}
232
233LRESULT sendVScroll(HWND hwnd,UINT wNotifyCode)
234{
235 return SendMessageA(getNotifyWindow(hwnd),WM_VSCROLL,(WPARAM)wNotifyCode,(LPARAM)hwnd);
236}
237
238//Tooltips
239
240HWND createToolTip(HWND hwnd,UINT flags,BOOL addtool)
241{
242 HWND hwndToolTip;
243 NMTOOLTIPSCREATED nmttc;
244 TTTOOLINFOA ti;
245
246 hwndToolTip =
247 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
248 CW_USEDEFAULT, CW_USEDEFAULT,
249 CW_USEDEFAULT, CW_USEDEFAULT,
250 hwnd, 0, 0, 0);
251
252 if (!hwndToolTip) return 0;
253
254 /* Send NM_TOOLTIPSCREATED notification */
255 nmttc.hwndToolTips = hwndToolTip;
256 sendNotify(hwnd,NM_TOOLTIPSCREATED,&nmttc.hdr);
257
258 if (addtool)
259 {
260 ZeroMemory(&ti,sizeof(TTTOOLINFOA));
261 ti.cbSize = sizeof(TTTOOLINFOA);
262 ti.uFlags = flags;
263 ti.hwnd = hwnd;
264 ti.uId = 0;
265 ti.lpszText = "";
266 SetRectEmpty (&ti.rect);
267
268 SendMessageA(hwndToolTip,TTM_ADDTOOLA,0,(LPARAM)&ti);
269 }
270
271 return hwndToolTip;
272}
273
274VOID destroyToolTip(HWND hwndToolTip)
275{
276 if (hwndToolTip) DestroyWindow(hwndToolTip);
277}
278
279//stub control
280
281VOID drawStubControl(HWND hwnd,HDC hdc)
282{
283 RECT rect;
284 HBRUSH brush = CreateSolidBrush(RGB(0,0,255));
285 HPEN pen = CreatePen(PS_SOLID,0,RGB(255,0,0)),oldPen;
286 COLORREF oldColor;
287
288 GetClientRect(hwnd,&rect);
289 FillRect(hdc,&rect,brush);
290 oldPen = SelectObject(hdc,pen);
291 MoveToEx(hdc,0,0,NULL);
292 LineTo(hdc,rect.right,rect.bottom);
293 MoveToEx(hdc,rect.right,0,NULL);
294 LineTo(hdc,0,rect.bottom);
295 SelectObject(hdc,oldPen);
296 oldColor = SetTextColor(hdc,RGB(255,255,255));
297 DrawTextA(hdc,"Unimplemented Control!",-1,&rect,DT_CENTER | DT_SINGLELINE | DT_VCENTER);
298 SetTextColor(hdc,oldColor);
299
300 DeleteObject(brush);
301 DeleteObject(pen);
302}
303
304//string functions
305
306//compare ANSI with UNICODE string
307INT lstrcmpAtoW(CHAR* textA,WCHAR* textW)
308{
309 INT len,res;
310 WCHAR* tmp;
311
312 len = lstrlenA(textA);
313 if (len > 0)
314 {
315 len++;
316 tmp = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR));
317 lstrcpyAtoW(tmp,textA);
318 } else tmp = NULL;
319
320 res = lstrcmpW(tmp,textW);
321
322 if (tmp) COMCTL32_Free(tmp);
323 return res;
324}
325
326INT lstrcmpAW(WCHAR *textA,BOOL textaunicode,WCHAR *textB,BOOL textbunicode)
327{
328 if (textaunicode)
329 {
330 if (textbunicode)
331 {
332 return lstrcmpW(textA,textB);
333 } else
334 {
335 return lstrcmpAtoW((LPSTR)textB,textA);
336 }
337 } else
338 {
339 if (textbunicode)
340 {
341 return lstrcmpAtoW((LPSTR)textA,textB);
342 } else
343 {
344 return lstrcmpA((LPSTR)textA,(LPSTR)textB);
345 }
346 }
347}
348
349//NOTE for lstrcmpni*: both buffers must be at least shortLen+1 characters long!
350
351INT lstrcmpniA(CHAR *textA,CHAR *textB,INT len)
352{
353 CHAR tmp1,tmp2;
354 INT res;
355
356 tmp1 = textA[len];
357 textA[len] = 0;
358 tmp2 = textB[len];
359 textB[len] = 0;
360
361 res = lstrcmpiA(textA,textB);
362
363 textA[len] = tmp1;
364 textB[len] = tmp2;
365 return res;
366}
367
368INT lstrcmpniAtoW(CHAR *textA,WCHAR* textB,INT len)
369{
370 WCHAR *tmp;
371 INT res;
372
373 tmp = (WCHAR*)COMCTL32_Alloc((len+1)*sizeof(WCHAR));
374 lstrcpynAtoW(tmp,textA,len+1);
375
376 res = lstrcmpniW(tmp,textB,len);
377
378 COMCTL32_Free(tmp);
379 return res;
380}
381
382
383INT lstrcmpniW(WCHAR *textA,WCHAR *textB,INT len)
384{
385 WCHAR tmp1,tmp2;
386 INT res;
387
388 tmp1 = textA[len];
389 textA[len] = 0;
390 tmp2 = textB[len];
391 textB[len] = 0;
392
393 res = lstrcmpiW(textA,textB);
394
395 textA[len] = tmp1;
396 textB[len] = tmp2;
397 return res;
398}
399
400INT lstrcmpniAW(WCHAR *textA,BOOL unicodeA,WCHAR *textB,BOOL unicodeB,INT len)
401{
402 if (unicodeA)
403 {
404 if (unicodeB)
405 {
406 return lstrcmpniW(textA,textB,len);
407 } else
408 {
409 return lstrcmpniAtoW((LPSTR)textB,textA,len);
410 }
411 } else
412 {
413 if (unicodeB)
414 {
415 return lstrcmpniAtoW((LPSTR)textA,textB,len);
416 } else
417 {
418 return lstrcmpniA((LPSTR)textA,(LPSTR)textB,len);
419 }
420 }
421}
422
423CHAR* lstrstrA(CHAR *text,CHAR *subtext)
424{
425 return strstr(text,subtext);
426}
427
428WCHAR* lstrstrW(WCHAR *text,WCHAR *subtext)
429{
430 return (WCHAR*)wcswcs((const wchar_t*)text,(wchar_t*)subtext);
431}
432
433//NOTE: less information in ASCII subtext
434CHAR* lstrstrAtoW(CHAR *text,WCHAR *subtext)
435{
436 INT len;
437 CHAR *tmp,*res;
438
439 len = lstrlenW(subtext);
440 if (len > 0)
441 {
442 len++;
443 tmp = (CHAR*)COMCTL32_Alloc(len);
444 lstrcpyWtoA(tmp,subtext);
445 } else tmp = NULL;
446
447 res = strstr(text,tmp);
448
449 if (tmp) COMCTL32_Free(tmp);
450 return res;
451}
452
453WCHAR* lstrstrWtoA(WCHAR *text,CHAR *subtext)
454{
455 INT len;
456 WCHAR *tmp,*res;
457
458 len = lstrlenA(subtext);
459 if (len > 0)
460 {
461 len++;
462 tmp = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR));
463 lstrcpyAtoW(tmp,subtext);
464 } else tmp = NULL;
465
466 res = (WCHAR*)wcswcs((const wchar_t*)text,(wchar_t*)tmp);
467
468 if (tmp) COMCTL32_Free(tmp);
469 return res;
470}
471
472WCHAR* lstrstrAW(WCHAR *text,BOOL textunicode,WCHAR *subtext,BOOL subtextunicode)
473{
474 if (textunicode)
475 {
476 if (subtextunicode)
477 {
478 return lstrstrW(text,subtext);
479 } else
480 {
481 return lstrstrWtoA(text,(LPSTR)subtext);
482 }
483 } else
484 {
485 if (subtextunicode)
486 {
487 return (WCHAR*)lstrstrAtoW((LPSTR)text,subtext);
488 } else
489 {
490 return (WCHAR*)lstrstrA((LPSTR)text,(LPSTR)subtext);
491 }
492 }
493}
Note: See TracBrowser for help on using the repository browser.