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