implement support for right-aligned/centered items owner-drawn items (patch 1699415)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45442 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -148,6 +148,7 @@ wxMSW:
|
|||||||
- Corrected GetChecked() for events from checkable menu items (smanders)
|
- Corrected GetChecked() for events from checkable menu items (smanders)
|
||||||
- Fixed popup menus under Windows NT 4
|
- Fixed popup menus under Windows NT 4
|
||||||
- Fixed bug in wxThread::Wait() in console applications introduced in 2.8.3
|
- Fixed bug in wxThread::Wait() in console applications introduced in 2.8.3
|
||||||
|
- Support right-aligned/centered owner drawn items in wxListCtrl (troelsk)
|
||||||
- Compilation fixed with WXWIN_COMPATIBILITY_2_6==0
|
- Compilation fixed with WXWIN_COMPATIBILITY_2_6==0
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
@@ -2417,22 +2417,22 @@ static RECT GetCustomDrawnItemRect(const NMCUSTOMDRAW& nmcd)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleSubItemPrepaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont)
|
static bool HandleSubItemPrepaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont)
|
||||||
{
|
{
|
||||||
NMCUSTOMDRAW& nmcd = pLVCD->nmcd;
|
NMCUSTOMDRAW& nmcd = pLVCD->nmcd;
|
||||||
|
|
||||||
HDC hdc = nmcd.hdc;
|
HDC hdc = nmcd.hdc;
|
||||||
HWND hwndList = nmcd.hdr.hwndFrom;
|
HWND hwndList = nmcd.hdr.hwndFrom;
|
||||||
|
const int col = pLVCD->iSubItem;
|
||||||
const DWORD item = nmcd.dwItemSpec;
|
const DWORD item = nmcd.dwItemSpec;
|
||||||
|
|
||||||
|
|
||||||
// the font must be valid, otherwise we wouldn't be painting the item at all
|
// the font must be valid, otherwise we wouldn't be painting the item at all
|
||||||
SelectInHDC selFont(hdc, hfont);
|
SelectInHDC selFont(hdc, hfont);
|
||||||
|
|
||||||
// get the rectangle to paint
|
// get the rectangle to paint
|
||||||
RECT rc;
|
RECT rc;
|
||||||
ListView_GetSubItemRect(hwndList, item, pLVCD->iSubItem, LVIR_BOUNDS, &rc);
|
ListView_GetSubItemRect(hwndList, item, col, LVIR_BOUNDS, &rc);
|
||||||
if ( !pLVCD->iSubItem )
|
if ( !col )
|
||||||
{
|
{
|
||||||
// broken ListView_GetSubItemRect() returns the entire item rect for
|
// broken ListView_GetSubItemRect() returns the entire item rect for
|
||||||
// 0th subitem while we really need just the part for this column
|
// 0th subitem while we really need just the part for this column
|
||||||
@@ -2453,7 +2453,7 @@ static void HandleSubItemPrepaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont)
|
|||||||
wxZeroMemory(it);
|
wxZeroMemory(it);
|
||||||
it.mask = LVIF_TEXT | LVIF_IMAGE;
|
it.mask = LVIF_TEXT | LVIF_IMAGE;
|
||||||
it.iItem = item;
|
it.iItem = item;
|
||||||
it.iSubItem = pLVCD->iSubItem;
|
it.iSubItem = col;
|
||||||
it.pszText = text;
|
it.pszText = text;
|
||||||
it.cchTextMax = WXSIZEOF(text);
|
it.cchTextMax = WXSIZEOF(text);
|
||||||
ListView_GetItem(hwndList, &it);
|
ListView_GetItem(hwndList, &it);
|
||||||
@@ -2483,12 +2483,38 @@ static void HandleSubItemPrepaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont)
|
|||||||
|
|
||||||
::SetBkMode(hdc, TRANSPARENT);
|
::SetBkMode(hdc, TRANSPARENT);
|
||||||
|
|
||||||
// TODO: support for centred/right aligned columns
|
UINT fmt = DT_SINGLELINE |
|
||||||
::DrawText(hdc, text, -1, &rc,
|
|
||||||
#ifndef __WXWINCE__
|
#ifndef __WXWINCE__
|
||||||
DT_WORD_ELLIPSIS |
|
DT_WORD_ELLIPSIS |
|
||||||
#endif // __WXWINCE__
|
#endif // __WXWINCE__
|
||||||
DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER);
|
DT_NOPREFIX |
|
||||||
|
DT_VCENTER;
|
||||||
|
|
||||||
|
LV_COLUMN lvCol;
|
||||||
|
wxZeroMemory(lvCol);
|
||||||
|
lvCol.mask = LVCF_FMT;
|
||||||
|
if ( ListView_GetColumn(hwndList, col, &lvCol) )
|
||||||
|
{
|
||||||
|
switch ( lvCol.fmt & LVCFMT_JUSTIFYMASK )
|
||||||
|
{
|
||||||
|
case LVCFMT_LEFT:
|
||||||
|
fmt |= DT_LEFT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LVCFMT_CENTER:
|
||||||
|
fmt |= DT_CENTER;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LVCFMT_RIGHT:
|
||||||
|
fmt |= DT_RIGHT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//else: failed to get alignment, assume it's DT_LEFT (default)
|
||||||
|
|
||||||
|
DrawText(hdc, text, -1, &rc, fmt);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleItemPostpaint(NMCUSTOMDRAW nmcd)
|
static void HandleItemPostpaint(NMCUSTOMDRAW nmcd)
|
||||||
|
Reference in New Issue
Block a user