Changeset 3351 for trunk/src/comctl32/header.cpp
- Timestamp:
- Apr 8, 2000, 8:32:55 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/header.cpp
r3182 r3351 1 /* $Id: header.cpp,v 1. 4 2000-03-21 17:30:41cbratschi Exp $ */1 /* $Id: header.cpp,v 1.5 2000-04-08 18:32:53 cbratschi Exp $ */ 2 2 /* 3 3 * Header control … … 40 40 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO*)getInfoPtr(hwnd)) 41 41 42 static VOID 43 HEADER_DrawItemImage(HWND hwnd,HDC hdc,HEADER_INFO* infoPtr,HEADER_ITEM* phdi,RECT* r,INT iItem) 42 static INT HEADER_CallbackImage(HWND hwnd,HEADER_INFO* infoPtr,HEADER_ITEM* phdi,INT iItem) 43 { 44 NMHDDISPINFOW nmhdr; 45 46 nmhdr.iItem = iItem; 47 nmhdr.mask = HDI_IMAGE; 48 nmhdr.iImage = 0; 49 nmhdr.lParam = phdi->lParam; 50 sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? HDN_GETDISPINFOW:HDN_GETDISPINFOA,&nmhdr.hdr); 51 52 if (nmhdr.mask & HDI_DI_SETITEM) phdi->iImage = nmhdr.iImage; 53 54 return nmhdr.iImage; 55 } 56 57 static VOID HEADER_DrawItemImage(HWND hwnd,HDC hdc,HEADER_INFO* infoPtr,HEADER_ITEM* phdi,RECT* r,INT iItem) 44 58 { 45 59 if (phdi->fmt & HDF_IMAGE) … … 50 64 51 65 if (phdi->iImage == I_IMAGECALLBACK) 52 { 53 NMHDDISPINFOW nmhdr; 54 55 nmhdr.iItem = iItem; 56 nmhdr.mask = HDI_IMAGE; 57 nmhdr.iImage = 0; 58 nmhdr.lParam = phdi->lParam; 59 sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? HDN_GETDISPINFOW:HDN_GETDISPINFOA,&nmhdr.hdr); 60 61 iImage = nmhdr.iImage; 62 if (nmhdr.mask & HDI_DI_SETITEM) phdi->iImage = iImage; 63 } else iImage = phdi->iImage; 64 66 iImage = HEADER_CallbackImage(hwnd,infoPtr,phdi,iItem); 67 else 68 iImage = phdi->iImage; 69 70 if (iImage == I_IMAGENONE) return; 65 71 if (!ImageList_GetImageInfo(infoPtr->himl,phdi->iImage,&info)) return; 66 72 w = info.rcImage.right-info.rcImage.left; … … 186 192 DeleteDC (hdcBitmap); 187 193 } 194 } 195 196 static WCHAR* HEADER_CallbackText(HWND hwnd,HEADER_INFO* infoPtr,HEADER_ITEM* phdi,INT iItem,BOOL* mustFree) 197 { 198 NMHDDISPINFOW nmhdr; 199 WCHAR* orgPtr; 200 201 nmhdr.iItem = iItem; 202 nmhdr.mask = HDI_TEXT; 203 nmhdr.cchTextMax = phdi->cchTextMax; 204 if (isUnicodeNotify(&infoPtr->header)) 205 { 206 orgPtr = (WCHAR*)COMCTL32_Alloc(phdi->cchTextMax*sizeof(WCHAR)); 207 nmhdr.pszText = orgPtr; 208 if (nmhdr.pszText) nmhdr.pszText[0] = 0; 209 } else 210 { 211 orgPtr = (WCHAR*)COMCTL32_Alloc(phdi->cchTextMax*sizeof(CHAR)); 212 nmhdr.pszText = orgPtr; 213 if (nmhdr.pszText) ((LPSTR)nmhdr.pszText)[0] = 0; 214 } 215 nmhdr.lParam = phdi->lParam; 216 sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? HDN_GETDISPINFOW:HDN_GETDISPINFOA,&nmhdr.hdr); 217 218 if (nmhdr.pszText == LPSTR_TEXTCALLBACKW) 219 { 220 *mustFree = FALSE; 221 return NULL; 222 } 223 224 if (nmhdr.mask & HDI_DI_SETITEM) 225 { 226 if (isUnicodeNotify(&infoPtr->header)) 227 { 228 INT len = nmhdr.pszText ? lstrlenW(nmhdr.pszText):0; 229 230 if (len) 231 { 232 phdi->pszText = (WCHAR*)COMCTL32_Alloc((len+1)*sizeof(WCHAR)); 233 lstrcpyW(phdi->pszText,nmhdr.pszText); 234 } else phdi->pszText = NULL; 235 if (nmhdr.pszText == orgPtr) COMCTL32_Free(nmhdr.pszText); 236 } else 237 { 238 INT len = nmhdr.pszText ? lstrlenA((LPSTR)nmhdr.pszText):0; 239 240 if (len) 241 { 242 phdi->pszText = (WCHAR*)COMCTL32_Alloc((len+1)*sizeof(WCHAR)); 243 lstrcpyAtoW(phdi->pszText,(LPSTR)nmhdr.pszText); 244 } else phdi->pszText = NULL; 245 } 246 COMCTL32_Free(orgPtr); 247 *mustFree = FALSE; 248 249 return phdi->pszText; 250 } 251 if (nmhdr.pszText != orgPtr) 252 { 253 COMCTL32_Free(orgPtr); 254 *mustFree = FALSE; 255 } else *mustFree = TRUE; 256 257 return nmhdr.pszText; 188 258 } 189 259 … … 252 322 { 253 323 UINT uTextJustify; 254 WCHAR *pszText = phdi->pszText,*orgPtr; 324 WCHAR *pszText; 325 BOOL mustFree = FALSE; 255 326 256 327 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER) … … 261 332 262 333 if (phdi->pszText == LPSTR_TEXTCALLBACKW) 263 { 264 NMHDDISPINFOW nmhdr; 265 266 nmhdr.iItem = iItem; 267 nmhdr.mask = HDI_TEXT; 268 nmhdr.cchTextMax = phdi->cchTextMax; 269 if (isUnicodeNotify(&infoPtr->header)) 270 { 271 orgPtr = (WCHAR*)COMCTL32_Alloc(phdi->cchTextMax*sizeof(WCHAR)); 272 nmhdr.pszText = orgPtr; 273 if (nmhdr.pszText) nmhdr.pszText[0] = 0; 274 } else 275 { 276 orgPtr = (WCHAR*)COMCTL32_Alloc(phdi->cchTextMax*sizeof(CHAR)); 277 nmhdr.pszText = orgPtr; 278 if (nmhdr.pszText) ((LPSTR)nmhdr.pszText)[0] = 0; 279 } 280 nmhdr.lParam = phdi->lParam; 281 sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? HDN_GETDISPINFOW:HDN_GETDISPINFOA,&nmhdr.hdr); 282 283 pszText = nmhdr.pszText; 284 if (nmhdr.mask & HDI_DI_SETITEM) 285 { 286 if (isUnicodeNotify(&infoPtr->header)) 287 { 288 INT len = pszText ? lstrlenW(pszText):0; 289 290 if (len) 291 { 292 phdi->pszText = (WCHAR*)COMCTL32_Alloc((len+1)*sizeof(WCHAR)); 293 lstrcpyW(phdi->pszText,pszText); 294 } else phdi->pszText = NULL; 295 if (pszText == orgPtr) COMCTL32_Free(pszText); 296 pszText = phdi->pszText; 297 } else 298 { 299 INT len = nmhdr.pszText ? lstrlenA((LPSTR)nmhdr.pszText):0; 300 301 if (len) 302 { 303 pszText = (WCHAR*)COMCTL32_Alloc((len+1)*sizeof(WCHAR)); 304 lstrcpyAtoW(pszText,(LPSTR)nmhdr.pszText); 305 } else pszText = NULL; 306 if (nmhdr.pszText == orgPtr) COMCTL32_Free(nmhdr.pszText); 307 308 phdi->pszText = pszText; 309 } 310 } 311 } 334 pszText = HEADER_CallbackText(hwnd,infoPtr,phdi,iItem,&mustFree); 335 else 336 pszText = phdi->pszText; 312 337 313 338 if (!(phdi->fmt & HDF_JUSTIFYMASK) || (phdi->fmt & (HDF_LEFT | HDF_CENTER))) … … 330 355 } 331 356 } 332 if ( (phdi->pszText == LPSTR_TEXTCALLBACKW) && (pszText == orgPtr)) COMCTL32_Free(pszText);357 if (mustFree) COMCTL32_Free(pszText); 333 358 } 334 359 … … 1082 1107 1083 1108 1084 static LRESULT 1085 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam) 1109 LRESULT HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam) 1086 1110 { 1087 1111 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd); … … 1097 1121 1098 1122 return TRUE; 1123 } 1124 1125 //useful function for ListView control 1126 1127 DWORD HEADER_GetExpandedColumnTextWidth(HWND hwnd,INT iItem) 1128 { 1129 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd); 1130 INT width = 0; 1131 HEADER_ITEM *phdi; 1132 1133 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem)) return width; 1134 1135 phdi = &infoPtr->items[iItem]; 1136 1137 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) 1138 width += 4; 1139 else 1140 width += 2; 1141 1142 if (phdi->fmt & HDF_OWNERDRAW) 1143 { 1144 //can't calculate ownerdraw 1145 return infoPtr->items[iItem].rect.right-infoPtr->items[iItem].rect.left; 1146 } 1147 1148 if (phdi->fmt & HDF_BITMAP) 1149 { 1150 if (phdi->hbm) 1151 { 1152 BITMAP bmp; 1153 1154 GetObjectA (phdi->hbm,sizeof(BITMAP),(LPVOID)&bmp); 1155 1156 width += bmp.bmWidth+2*infoPtr->xBmpMargin; 1157 } else width += 2*infoPtr->xBmpMargin; 1158 } 1159 1160 if (phdi->fmt & HDF_IMAGE) 1161 { 1162 INT iImage; 1163 IMAGEINFO info; 1164 1165 if (phdi->iImage == I_IMAGECALLBACK) 1166 iImage = HEADER_CallbackImage(hwnd,infoPtr,phdi,iItem); 1167 else 1168 iImage = phdi->iImage; 1169 1170 if (iImage != I_IMAGENONE) 1171 { 1172 if (ImageList_GetImageInfo(infoPtr->himl,phdi->iImage,&info)) 1173 { 1174 width += info.rcImage.right-info.rcImage.left+2*infoPtr->xBmpMargin; 1175 } 1176 } 1177 } 1178 1179 if (phdi->fmt & HDF_STRING) 1180 { 1181 WCHAR* pszText; 1182 BOOL mustFree = FALSE; 1183 HFONT hFont,hOldFont; 1184 SIZE size; 1185 HDC hdc = GetDC(hwnd); 1186 1187 if (phdi->pszText == LPSTR_TEXTCALLBACKW) 1188 pszText = HEADER_CallbackText(hwnd,infoPtr,phdi,iItem,&mustFree); 1189 else 1190 pszText = phdi->pszText; 1191 1192 hFont = infoPtr->hFont ? infoPtr->hFont:GetStockObject(SYSTEM_FONT); 1193 hOldFont = SelectObject(hdc,hFont); 1194 1195 if (GetTextExtentPoint32W(hdc,pszText,lstrlenW(pszText),&size)) 1196 width += size.cx+2*TEXT_MARGIN; 1197 if (mustFree) COMCTL32_Free(pszText); 1198 SelectObject(hdc,hOldFont); 1199 ReleaseDC(hwnd,hdc); 1200 } 1201 1202 return width; 1099 1203 } 1100 1204
Note:
See TracChangeset
for help on using the changeset viewer.