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

Last change on this file since 2875 was 2875, checked in by cbratschi, 26 years ago

C -> C++, WINE animate, treeview WM_VSCROLL fixed

File size: 4.4 KB
Line 
1/* $Id: CCBase.cpp,v 1.1 2000-02-23 17:09:39 cbratschi 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
10#include "winbase.h"
11#include "comctl32.h"
12#include "ccbase.h"
13
14BOOL checkVersion(INT iVersion)
15{
16 return TRUE; //CB: todo
17}
18
19//init-done
20
21PVOID initControl(HWND hwnd,DWORD dwSize)
22{
23 COMCTL32_HEADER *infoPtr;
24
25 if (dwSize < sizeof(COMCTL32_HEADER)) return NULL;
26
27 infoPtr = (COMCTL32_HEADER*)COMCTL32_Alloc(dwSize);
28
29 if (!infoPtr) return NULL;
30
31 setInfoPtr(hwnd,infoPtr);
32 infoPtr->dwSize = dwSize;
33 infoPtr->iVersion = 0;
34 infoPtr->fUnicode = IsWindowUnicode(hwnd);
35 infoPtr->uNotifyFormat = sendNotifyFormat(GetParent(hwnd),hwnd,NF_QUERY);
36
37 return infoPtr;
38}
39
40VOID doneControl(HWND hwnd)
41{
42 COMCTL32_HEADER *infoPtr = getInfoPtr(hwnd);
43
44 if (infoPtr)
45 {
46 COMCTL32_Free(infoPtr);
47 setInfoPtr(hwnd,NULL);
48 }
49}
50
51//Default message handler
52
53LRESULT defComCtl32Proc(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam,BOOL unicode)
54{
55 COMCTL32_HEADER *infoPtr;
56
57 switch (Msg)
58 {
59 case CCM_GETVERSION:
60 infoPtr = getInfoPtr(hwnd);
61 return infoPtr ? infoPtr->iVersion:0;
62
63 case CCM_SETVERSION:
64 infoPtr = getInfoPtr(hwnd);
65 if (infoPtr)
66 {
67 if (checkVersion((INT)wParam))
68 {
69 INT oldVersion;
70
71 oldVersion = infoPtr->iVersion;
72 infoPtr->iVersion = (INT)wParam;
73 return oldVersion;
74 } else return -1;
75 } else return 0;
76
77 case CCM_GETUNICODEFORMAT:
78 infoPtr = getInfoPtr(hwnd);
79 return infoPtr ? infoPtr->fUnicode:IsWindowUnicode(hwnd);
80
81 case CCM_SETUNICODEFORMAT:
82 infoPtr = getInfoPtr(hwnd);
83 if (infoPtr)
84 {
85 BOOL oldFormat;
86
87 oldFormat = infoPtr->fUnicode;
88 infoPtr->fUnicode = (INT)wParam;
89 return oldFormat;
90 } else return IsWindowUnicode(hwnd);
91
92 case WM_NOTIFY:
93 {
94 infoPtr = getInfoPtr(hwnd);
95
96 if (!infoPtr) break;
97
98 if (lParam == NF_REQUERY)
99 {
100 infoPtr->uNotifyFormat = sendNotifyFormat(GetParent(hwnd),hwnd,NF_QUERY);
101 if ((infoPtr->uNotifyFormat != NFR_ANSI) && (infoPtr->uNotifyFormat != NFR_UNICODE))
102 infoPtr->uNotifyFormat = IsWindowUnicode(GetParent(hwnd)) ? NFR_UNICODE:NFR_ANSI;
103 return infoPtr->uNotifyFormat;
104 } else if (lParam == NF_QUERY)
105 {
106 return infoPtr->uNotifyFormat;
107 }
108 break;
109 }
110 }
111
112 if (unicode)
113 return DefWindowProcW(hwnd,Msg,wParam,lParam);
114 else
115 return DefWindowProcA(hwnd,Msg,wParam,lParam);
116}
117
118LRESULT defComCtl32ProcA(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam)
119{
120 return defComCtl32Proc(hwnd,Msg,wParam,lParam,FALSE);
121}
122
123LRESULT defComCtl32ProcW(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam)
124{
125 return defComCtl32Proc(hwnd,Msg,wParam,lParam,TRUE);
126}
127
128//Notifications
129
130LRESULT sendNotify(HWND hwnd,UINT code)
131{
132 NMHDR nmhdr;
133
134 nmhdr.hwndFrom = hwnd;
135 nmhdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
136 nmhdr.code = code;
137
138 return SendMessageA(hwnd,WM_NOTIFY,nmhdr.idFrom,(LPARAM)&nmhdr);
139}
140
141LRESULT sendNotify(HWND hwnd,UINT code,LPNMHDR nmhdr)
142{
143 if (!nmhdr) return 0;
144
145 nmhdr->hwndFrom = hwnd;
146 nmhdr->idFrom = GetWindowLongA(hwnd,GWL_ID);
147 nmhdr->code = code;
148
149 return SendMessageA(hwnd,WM_NOTIFY,nmhdr->idFrom,(LPARAM)nmhdr);
150}
151
152LRESULT sendNotifyFormat(HWND hwnd,HWND hwndFrom,LPARAM command)
153{
154 return SendMessageA(hwnd,WM_NOTIFYFORMAT,hwndFrom,command);
155}
156
157LRESULT sendCommand(HWND hwnd,UINT wNotifyCode)
158{
159 return SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),wNotifyCode),(LPARAM)hwnd);
160}
161
162//Tooltips
163
164HWND createToolTip(HWND hwnd,UINT flags)
165{
166 HWND hwndToolTip;
167 NMTOOLTIPSCREATED nmttc;
168 TTTOOLINFOA ti;
169
170 hwndToolTip =
171 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
172 CW_USEDEFAULT, CW_USEDEFAULT,
173 CW_USEDEFAULT, CW_USEDEFAULT,
174 hwnd, 0, 0, 0);
175
176 if (!hwndToolTip) return 0;
177
178 /* Send NM_TOOLTIPSCREATED notification */
179 nmttc.hwndToolTips = hwndToolTip;
180 sendNotify(hwnd,NM_TOOLTIPSCREATED,&nmttc.hdr);
181
182 ZeroMemory(&ti,sizeof(TTTOOLINFOA));
183 ti.cbSize = sizeof(TTTOOLINFOA);
184 ti.uFlags = flags;
185 ti.hwnd = hwnd;
186 ti.uId = 0;
187 ti.lpszText = "";
188 SetRectEmpty (&ti.rect);
189
190 SendMessageA(hwndToolTip,TTM_ADDTOOLA,0,(LPARAM)&ti);
191
192 return hwndToolTip;
193}
194
195VOID destroyToolTip(HWND hwndToolTip)
196{
197 if (hwndToolTip) DestroyWindow(hwndToolTip);
198}
Note: See TracBrowser for help on using the repository browser.