| 1 | /* $Id: CCBase.cpp,v 1.6 2000-03-30 15:39:08 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 |
|
|---|
| 14 | BOOL checkVersion(INT iVersion)
|
|---|
| 15 | {
|
|---|
| 16 | return iVersion <= COMCTL32_VERSION;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | //init-done
|
|---|
| 20 |
|
|---|
| 21 | PVOID 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 | ZeroMemory(infoPtr,dwSize);
|
|---|
| 33 | infoPtr->dwSize = dwSize;
|
|---|
| 34 | infoPtr->iVersion = 0;
|
|---|
| 35 | infoPtr->fUnicode = IsWindowUnicode(hwnd);
|
|---|
| 36 | infoPtr->uNotifyFormat = sendNotifyFormat(GetParent(hwnd),hwnd,NF_QUERY);
|
|---|
| 37 | infoPtr->hwndNotify = GetParent(hwnd);
|
|---|
| 38 |
|
|---|
| 39 | return infoPtr;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | VOID doneControl(HWND hwnd)
|
|---|
| 43 | {
|
|---|
| 44 | COMCTL32_HEADER *infoPtr = getInfoPtr(hwnd);
|
|---|
| 45 |
|
|---|
| 46 | if (infoPtr)
|
|---|
| 47 | {
|
|---|
| 48 | COMCTL32_Free(infoPtr);
|
|---|
| 49 | setInfoPtr(hwnd,NULL);
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | //Default message handler
|
|---|
| 54 |
|
|---|
| 55 | LRESULT defComCtl32Proc(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam,BOOL unicode)
|
|---|
| 56 | {
|
|---|
| 57 | COMCTL32_HEADER *infoPtr;
|
|---|
| 58 |
|
|---|
| 59 | switch (Msg)
|
|---|
| 60 | {
|
|---|
| 61 | case CCM_GETVERSION:
|
|---|
| 62 | infoPtr = getInfoPtr(hwnd);
|
|---|
| 63 | return infoPtr ? infoPtr->iVersion:0;
|
|---|
| 64 |
|
|---|
| 65 | case CCM_SETVERSION:
|
|---|
| 66 | infoPtr = getInfoPtr(hwnd);
|
|---|
| 67 | if (infoPtr)
|
|---|
| 68 | {
|
|---|
| 69 | if (checkVersion((INT)wParam))
|
|---|
| 70 | {
|
|---|
| 71 | INT oldVersion;
|
|---|
| 72 |
|
|---|
| 73 | oldVersion = infoPtr->iVersion;
|
|---|
| 74 | infoPtr->iVersion = (INT)wParam;
|
|---|
| 75 | return oldVersion;
|
|---|
| 76 | } else return -1;
|
|---|
| 77 | } else return 0;
|
|---|
| 78 |
|
|---|
| 79 | case CCM_GETUNICODEFORMAT:
|
|---|
| 80 | infoPtr = getInfoPtr(hwnd);
|
|---|
| 81 | return infoPtr ? infoPtr->fUnicode:IsWindowUnicode(hwnd);
|
|---|
| 82 |
|
|---|
| 83 | case CCM_SETUNICODEFORMAT:
|
|---|
| 84 | infoPtr = getInfoPtr(hwnd);
|
|---|
| 85 | if (infoPtr)
|
|---|
| 86 | {
|
|---|
| 87 | BOOL oldFormat;
|
|---|
| 88 |
|
|---|
| 89 | oldFormat = infoPtr->fUnicode;
|
|---|
| 90 | infoPtr->fUnicode = (INT)wParam;
|
|---|
| 91 | return oldFormat;
|
|---|
| 92 | } else return IsWindowUnicode(hwnd);
|
|---|
| 93 |
|
|---|
| 94 | case WM_NOTIFYFORMAT:
|
|---|
| 95 | {
|
|---|
| 96 | infoPtr = getInfoPtr(hwnd);
|
|---|
| 97 |
|
|---|
| 98 | if (!infoPtr) break;
|
|---|
| 99 |
|
|---|
| 100 | if (lParam == NF_REQUERY)
|
|---|
| 101 | {
|
|---|
| 102 | infoPtr->uNotifyFormat = sendNotifyFormat(GetParent(hwnd),hwnd,NF_QUERY);
|
|---|
| 103 | if ((infoPtr->uNotifyFormat != NFR_ANSI) && (infoPtr->uNotifyFormat != NFR_UNICODE))
|
|---|
| 104 | infoPtr->uNotifyFormat = IsWindowUnicode(GetParent(hwnd)) ? NFR_UNICODE:NFR_ANSI;
|
|---|
| 105 | return infoPtr->uNotifyFormat;
|
|---|
| 106 | } else if (lParam == NF_QUERY)
|
|---|
| 107 | {
|
|---|
| 108 | return infoPtr->uNotifyFormat;
|
|---|
| 109 | }
|
|---|
| 110 | break;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | case CCM_SETNOTIFYWINDOW:
|
|---|
| 114 | {
|
|---|
| 115 | infoPtr = getInfoPtr(hwnd);
|
|---|
| 116 |
|
|---|
| 117 | if (!infoPtr) break;
|
|---|
| 118 |
|
|---|
| 119 | infoPtr->hwndNotify = (HWND)wParam;
|
|---|
| 120 |
|
|---|
| 121 | break;
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | if (unicode)
|
|---|
| 126 | return DefWindowProcW(hwnd,Msg,wParam,lParam);
|
|---|
| 127 | else
|
|---|
| 128 | return DefWindowProcA(hwnd,Msg,wParam,lParam);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | LRESULT defComCtl32ProcA(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam)
|
|---|
| 132 | {
|
|---|
| 133 | return defComCtl32Proc(hwnd,Msg,wParam,lParam,FALSE);
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | LRESULT defComCtl32ProcW(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam)
|
|---|
| 137 | {
|
|---|
| 138 | return defComCtl32Proc(hwnd,Msg,wParam,lParam,TRUE);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | //Notifications
|
|---|
| 142 |
|
|---|
| 143 | BOOL isUnicodeNotify(COMCTL32_HEADER *infoPtr)
|
|---|
| 144 | {
|
|---|
| 145 | if (!infoPtr) return FALSE;
|
|---|
| 146 |
|
|---|
| 147 | return infoPtr->uNotifyFormat == NFR_UNICODE;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | BOOL isUnicodeNotify(HWND hwnd)
|
|---|
| 151 | {
|
|---|
| 152 | COMCTL32_HEADER *infoPtr = getInfoPtr(hwnd);
|
|---|
| 153 |
|
|---|
| 154 | return isUnicodeNotify(infoPtr);
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | HWND getNotifyWindow(COMCTL32_HEADER *infoPtr)
|
|---|
| 158 | {
|
|---|
| 159 | if (!infoPtr) return 0;
|
|---|
| 160 |
|
|---|
| 161 | return infoPtr->hwndNotify;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | HWND getNotifyWindow(HWND hwnd)
|
|---|
| 165 | {
|
|---|
| 166 | COMCTL32_HEADER *infoPtr = getInfoPtr(hwnd);
|
|---|
| 167 |
|
|---|
| 168 | return getNotifyWindow(infoPtr);
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | LRESULT sendNotify(HWND hwnd,UINT code)
|
|---|
| 172 | {
|
|---|
| 173 | NMHDR nmhdr;
|
|---|
| 174 |
|
|---|
| 175 | nmhdr.hwndFrom = hwnd;
|
|---|
| 176 | nmhdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
|
|---|
| 177 | nmhdr.code = code;
|
|---|
| 178 |
|
|---|
| 179 | return SendMessageA(getNotifyWindow(hwnd),WM_NOTIFY,nmhdr.idFrom,(LPARAM)&nmhdr);
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | LRESULT sendNotify(HWND hwndFrom,HWND hwndTo,UINT code)
|
|---|
| 183 | {
|
|---|
| 184 | NMHDR nmhdr;
|
|---|
| 185 |
|
|---|
| 186 | nmhdr.hwndFrom = hwndFrom;
|
|---|
| 187 | nmhdr.idFrom = GetWindowLongA(hwndFrom,GWL_ID);
|
|---|
| 188 | nmhdr.code = code;
|
|---|
| 189 |
|
|---|
| 190 | return SendMessageA(hwndTo,WM_NOTIFY,nmhdr.idFrom,(LPARAM)&nmhdr);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | LRESULT sendNotify(HWND hwnd,UINT code,LPNMHDR nmhdr)
|
|---|
| 194 | {
|
|---|
| 195 | if (!nmhdr) return 0;
|
|---|
| 196 |
|
|---|
| 197 | nmhdr->hwndFrom = hwnd;
|
|---|
| 198 | nmhdr->idFrom = GetWindowLongA(hwnd,GWL_ID);
|
|---|
| 199 | nmhdr->code = code;
|
|---|
| 200 |
|
|---|
| 201 | return SendMessageA(getNotifyWindow(hwnd),WM_NOTIFY,nmhdr->idFrom,(LPARAM)nmhdr);
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | LRESULT sendNotify(HWND hwndFrom,HWND hwndTo,UINT code,LPNMHDR nmhdr)
|
|---|
| 205 | {
|
|---|
| 206 | if (!nmhdr) return 0;
|
|---|
| 207 |
|
|---|
| 208 | nmhdr->hwndFrom = hwndFrom;
|
|---|
| 209 | nmhdr->idFrom = GetWindowLongA(hwndFrom,GWL_ID);
|
|---|
| 210 | nmhdr->code = code;
|
|---|
| 211 |
|
|---|
| 212 | return SendMessageA(hwndTo,WM_NOTIFY,nmhdr->idFrom,(LPARAM)nmhdr);
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | LRESULT sendNotifyFormat(HWND hwnd,HWND hwndFrom,LPARAM command)
|
|---|
| 216 | {
|
|---|
| 217 | return SendMessageA(hwnd,WM_NOTIFYFORMAT,hwndFrom,command);
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | LRESULT sendCommand(HWND hwnd,UINT wNotifyCode)
|
|---|
| 221 | {
|
|---|
| 222 | return SendMessageA(getNotifyWindow(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),wNotifyCode),(LPARAM)hwnd);
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | LRESULT sendHScroll(HWND hwnd,UINT wNotifyCode)
|
|---|
| 226 | {
|
|---|
| 227 | return SendMessageA(getNotifyWindow(hwnd),WM_HSCROLL,(WPARAM)wNotifyCode,(LPARAM)hwnd);
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | LRESULT sendVScroll(HWND hwnd,UINT wNotifyCode)
|
|---|
| 231 | {
|
|---|
| 232 | return SendMessageA(getNotifyWindow(hwnd),WM_VSCROLL,(WPARAM)wNotifyCode,(LPARAM)hwnd);
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | //Tooltips
|
|---|
| 236 |
|
|---|
| 237 | HWND createToolTip(HWND hwnd,UINT flags,BOOL addtool)
|
|---|
| 238 | {
|
|---|
| 239 | HWND hwndToolTip;
|
|---|
| 240 | NMTOOLTIPSCREATED nmttc;
|
|---|
| 241 | TTTOOLINFOA ti;
|
|---|
| 242 |
|
|---|
| 243 | hwndToolTip =
|
|---|
| 244 | CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
|
|---|
| 245 | CW_USEDEFAULT, CW_USEDEFAULT,
|
|---|
| 246 | CW_USEDEFAULT, CW_USEDEFAULT,
|
|---|
| 247 | hwnd, 0, 0, 0);
|
|---|
| 248 |
|
|---|
| 249 | if (!hwndToolTip) return 0;
|
|---|
| 250 |
|
|---|
| 251 | /* Send NM_TOOLTIPSCREATED notification */
|
|---|
| 252 | nmttc.hwndToolTips = hwndToolTip;
|
|---|
| 253 | sendNotify(hwnd,NM_TOOLTIPSCREATED,&nmttc.hdr);
|
|---|
| 254 |
|
|---|
| 255 | if (addtool)
|
|---|
| 256 | {
|
|---|
| 257 | ZeroMemory(&ti,sizeof(TTTOOLINFOA));
|
|---|
| 258 | ti.cbSize = sizeof(TTTOOLINFOA);
|
|---|
| 259 | ti.uFlags = flags;
|
|---|
| 260 | ti.hwnd = hwnd;
|
|---|
| 261 | ti.uId = 0;
|
|---|
| 262 | ti.lpszText = "";
|
|---|
| 263 | SetRectEmpty (&ti.rect);
|
|---|
| 264 |
|
|---|
| 265 | SendMessageA(hwndToolTip,TTM_ADDTOOLA,0,(LPARAM)&ti);
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | return hwndToolTip;
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | VOID destroyToolTip(HWND hwndToolTip)
|
|---|
| 272 | {
|
|---|
| 273 | if (hwndToolTip) DestroyWindow(hwndToolTip);
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | //stub control
|
|---|
| 277 |
|
|---|
| 278 | VOID drawStubControl(HWND hwnd,HDC hdc)
|
|---|
| 279 | {
|
|---|
| 280 | RECT rect;
|
|---|
| 281 | HBRUSH brush = CreateSolidBrush(RGB(0,0,255));
|
|---|
| 282 | HPEN pen = CreatePen(PS_SOLID,0,RGB(255,0,0)),oldPen;
|
|---|
| 283 | COLORREF oldColor;
|
|---|
| 284 |
|
|---|
| 285 | GetClientRect(hwnd,&rect);
|
|---|
| 286 | FillRect(hdc,&rect,brush);
|
|---|
| 287 | oldPen = SelectObject(hdc,pen);
|
|---|
| 288 | MoveToEx(hdc,0,0,NULL);
|
|---|
| 289 | LineTo(hdc,rect.right,rect.bottom);
|
|---|
| 290 | MoveToEx(hdc,rect.right,0,NULL);
|
|---|
| 291 | LineTo(hdc,0,rect.bottom);
|
|---|
| 292 | SelectObject(hdc,oldPen);
|
|---|
| 293 | oldColor = SetTextColor(hdc,RGB(255,255,255));
|
|---|
| 294 | DrawTextA(hdc,"Unimplemented Control!",-1,&rect,DT_CENTER | DT_SINGLELINE | DT_VCENTER);
|
|---|
| 295 | SetTextColor(hdc,oldColor);
|
|---|
| 296 |
|
|---|
| 297 | DeleteObject(brush);
|
|---|
| 298 | DeleteObject(pen);
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | //string functions
|
|---|
| 302 |
|
|---|
| 303 | //compare ANSI with UNICODE string
|
|---|
| 304 | INT lstrcmpAtoW(CHAR* textA,WCHAR* textW)
|
|---|
| 305 | {
|
|---|
| 306 | INT len,res;
|
|---|
| 307 | WCHAR* tmp;
|
|---|
| 308 |
|
|---|
| 309 | len = lstrlenA(textA);
|
|---|
| 310 | if (len > 0)
|
|---|
| 311 | {
|
|---|
| 312 | len++;
|
|---|
| 313 | tmp = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR));
|
|---|
| 314 | lstrcpyAtoW(tmp,textA);
|
|---|
| 315 | } else tmp = NULL;
|
|---|
| 316 |
|
|---|
| 317 | res = lstrcmpW(tmp,textW);
|
|---|
| 318 |
|
|---|
| 319 | if (tmp) COMCTL32_Free(tmp);
|
|---|
| 320 | return res;
|
|---|
| 321 | }
|
|---|