- Implemented HEADER_SetBitmapMargin and HEADER_GetBitmapMargin.

- Get rid of some magic numbers in HEADER_DrawItem.
- Fixed the drawing of images from imagelist when the
  HDF_BITMAP_ON_RIGHT flag is set.
This commit is contained in:
Maxime Bellengé 2003-10-14 20:13:42 +00:00 committed by Alexandre Julliard
parent 8147ee1095
commit 5b99b3df29
2 changed files with 72 additions and 25 deletions

View File

@ -3,6 +3,7 @@
* *
* Copyright 1998 Eric Kohl * Copyright 1998 Eric Kohl
* Copyright 2000 Eric Kohl for CodeWeavers * Copyright 2000 Eric Kohl for CodeWeavers
* Copyright 2003 Maxime Bellenge
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -28,8 +29,6 @@
* - Use notification format * - Use notification format
* - Correct the order maintenance code to preserve valid order * - Correct the order maintenance code to preserve valid order
* *
* FIXME:
* - Little flaw when drawing a bitmap on the right side of the text.
*/ */
#include <stdarg.h> #include <stdarg.h>
@ -82,6 +81,7 @@ typedef struct
INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */ INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */ INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
INT iHotItem; /* index of hot item (cursor is over this item) */ INT iHotItem; /* index of hot item (cursor is over this item) */
INT iMargin; /* width of the margin that surrounds a bitmap */
HIMAGELIST himl; /* handle to a image list (may be 0) */ HIMAGELIST himl; /* handle to a image list (may be 0) */
HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */ HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
@ -234,19 +234,19 @@ HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
} }
if (rx >= bmp.bmWidth + 6) { if (rx >= bmp.bmWidth + infoPtr->iMargin) {
cx = bmp.bmWidth; cx = bmp.bmWidth;
} }
else { else {
cx = rx - 6; cx = rx - infoPtr->iMargin;
} }
hdcBitmap = CreateCompatibleDC (hdc); hdcBitmap = CreateCompatibleDC (hdc);
SelectObject (hdcBitmap, phdi->hbm); SelectObject (hdcBitmap, phdi->hbm);
BitBlt (hdc, r.left + 3, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY); BitBlt (hdc, r.left + infoPtr->iMargin, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
DeleteDC (hdcBitmap); DeleteDC (hdcBitmap);
r.left += (bmp.bmWidth + 3); r.left += (bmp.bmWidth + infoPtr->iMargin);
} }
@ -259,9 +259,13 @@ HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp); GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
textRect = r; textRect = r;
DrawTextW (hdc, phdi->pszText, -1, if (phdi->fmt & HDF_STRING) {
&textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT); DrawTextW (hdc, phdi->pszText, -1,
tx = textRect.right - textRect.left; &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
tx = textRect.right - textRect.left;
}
else
tx = 0;
ry = r.bottom - r.top; ry = r.bottom - r.top;
rx = r.right - r.left; rx = r.right - r.left;
@ -277,18 +281,18 @@ HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
} }
if (r.left + tx + bmp.bmWidth + 9 <= r.right) { if (r.left + tx + bmp.bmWidth + 2*infoPtr->iMargin <= r.right) {
cx = bmp.bmWidth; cx = bmp.bmWidth;
xD = r.left + tx + 6; xD = r.left + tx + infoPtr->iMargin;
} }
else { else {
if (rx >= bmp.bmWidth + 6) { if (rx >= bmp.bmWidth + infoPtr->iMargin ) {
cx = bmp.bmWidth; cx = bmp.bmWidth;
xD = r.right - bmp.bmWidth - 3; xD = r.right - bmp.bmWidth - infoPtr->iMargin;
r.right = xD - 3; r.right = xD - infoPtr->iMargin;
} }
else { else {
cx = rx - 3; cx = rx - infoPtr->iMargin;
xD = r.left; xD = r.left;
r.right = r.left; r.right = r.left;
} }
@ -300,21 +304,37 @@ HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
DeleteDC (hdcBitmap); DeleteDC (hdcBitmap);
} }
if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) { if ((phdi->fmt & HDF_IMAGE) && !(phdi->fmt & HDF_BITMAP_ON_RIGHT) && (infoPtr->himl)) {
r.left +=3; r.left += infoPtr->iMargin;
/* FIXME: (r.bottom- (infoPtr->himl->cy))/2 should horicontal center the image ImageList_DrawEx(infoPtr->himl, phdi->iImage, hdc, r.left, r.top + (r.bottom-r.top- infoPtr->himl->cy)/2,
It looks like it doesn't work as expected*/ infoPtr->himl->cx, r.bottom-r.top, CLR_DEFAULT, CLR_DEFAULT, 0);
ImageList_Draw (infoPtr->himl, phdi->iImage,hdc,r.left, (r.bottom- (infoPtr->himl->cy))/2,0); r.left += infoPtr->himl->cx;
r.left += infoPtr->himl->cx;
} }
if ((phdi->fmt & HDF_IMAGE) && (phdi->fmt & HDF_BITMAP_ON_RIGHT) && (infoPtr->himl)) {
RECT textRect;
INT tx;
textRect = r;
if (phdi->fmt & HDF_STRING) {
DrawTextW (hdc, phdi->pszText, -1,
&textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
tx = textRect.right - textRect.left;
}
else
tx = 0;
ImageList_DrawEx(infoPtr->himl, phdi->iImage, hdc, r.left + tx + 2*infoPtr->iMargin,
r.top + (r.bottom-r.top-infoPtr->himl->cy)/2, infoPtr->himl->cx, r.bottom-r.top,
CLR_DEFAULT, CLR_DEFAULT, 0);
}
if (((phdi->fmt & HDF_STRING) if (((phdi->fmt & HDF_STRING)
|| (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP| || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */ HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
&& (phdi->pszText)) { && (phdi->pszText)) {
oldBkMode = SetBkMode(hdc, TRANSPARENT); oldBkMode = SetBkMode(hdc, TRANSPARENT);
r.left += 3 ; r.left += infoPtr->iMargin;
r.right -= 3; r.right -= infoPtr->iMargin;
SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT); SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
DrawTextW (hdc, phdi->pszText, -1, DrawTextW (hdc, phdi->pszText, -1,
&r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE); &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
@ -1092,6 +1112,25 @@ HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
} }
static LRESULT
HEADER_GetBitmapMargin(HWND hwnd)
{
HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
return infoPtr->iMargin;
}
static LRESULT
HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
{
HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
INT oldMargin = infoPtr->iMargin;
infoPtr->iMargin = (INT)wParam;
return oldMargin;
}
static LRESULT static LRESULT
HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam) HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
{ {
@ -1262,6 +1301,7 @@ HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
infoPtr->himl = 0; infoPtr->himl = 0;
infoPtr->iHotItem = -1; infoPtr->iHotItem = -1;
infoPtr->bUnicode = IsWindowUnicode (hwnd); infoPtr->bUnicode = IsWindowUnicode (hwnd);
infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
infoPtr->nNotifyFormat = infoPtr->nNotifyFormat =
SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY); SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
@ -1676,7 +1716,8 @@ HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
/* case HDM_EDITFILTER: */ /* case HDM_EDITFILTER: */
/* case HDM_GETBITMAPMARGIN: */ case HDM_GETBITMAPMARGIN:
return HEADER_GetBitmapMargin(hwnd);
case HDM_GETIMAGELIST: case HDM_GETIMAGELIST:
return HEADER_GetImageList (hwnd); return HEADER_GetImageList (hwnd);
@ -1714,7 +1755,8 @@ HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case HDM_ORDERTOINDEX: case HDM_ORDERTOINDEX:
return HEADER_OrderToIndex(hwnd, wParam); return HEADER_OrderToIndex(hwnd, wParam);
/* case HDM_SETBITMAPMARGIN: */ case HDM_SETBITMAPMARGIN:
return HEADER_SetBitmapMargin(hwnd, wParam);
/* case HDM_SETFILTERCHANGETIMEOUT: */ /* case HDM_SETFILTERCHANGETIMEOUT: */

View File

@ -757,6 +757,11 @@ static const WCHAR WC_HEADERW[] = { 'S','y','s','H','e','a','d','e','r','3','2',
#define HDM_GETORDERARRAY (HDM_FIRST+17) #define HDM_GETORDERARRAY (HDM_FIRST+17)
#define HDM_SETORDERARRAY (HDM_FIRST+18) #define HDM_SETORDERARRAY (HDM_FIRST+18)
#define HDM_SETHOTDIVIDER (HDM_FIRST+19) #define HDM_SETHOTDIVIDER (HDM_FIRST+19)
#define HDM_SETBITMAPMARGIN (HDM_FIRST+20)
#define HDM_GETBITMAPMARGIN (HDM_FIRST+21)
#define HDM_SETFILTERCHANGETIMEOUT (HDM_FIRST+22)
#define HDM_EDITFILTER (HDM_FIRST+23)
#define HDM_CLEARFILTER (HDM_FIRST+24)
#define HDM_GETUNICODEFORMAT CCM_GETUNICODEFORMAT #define HDM_GETUNICODEFORMAT CCM_GETUNICODEFORMAT
#define HDM_SETUNICODEFORMAT CCM_SETUNICODEFORMAT #define HDM_SETUNICODEFORMAT CCM_SETUNICODEFORMAT