added support for column images under MSW

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11546 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-09-02 23:47:42 +00:00
parent 5707316c9c
commit 6f806543a4
4 changed files with 109 additions and 80 deletions

View File

@@ -366,9 +366,23 @@ void MyFrame::InitWithReportItems()
{ {
m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
// under MSW for SetColumnWidth() to work we need to create the items with
// images initially
#if 1
wxListItem itemCol;
itemCol.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
itemCol.m_text = "Column 1";
itemCol.m_image = -1;
m_listCtrl->InsertColumn(0, itemCol);
itemCol.m_text = "Column 2";
m_listCtrl->InsertColumn(1, itemCol);
itemCol.m_text = "Column 3";
m_listCtrl->InsertColumn(2, itemCol);
#else
m_listCtrl->InsertColumn(0, "Column 1"); // , wxLIST_FORMAT_LEFT, 140); m_listCtrl->InsertColumn(0, "Column 1"); // , wxLIST_FORMAT_LEFT, 140);
m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140); m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140);
m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140); m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140);
#endif
// to speed up inserting we hide the control temporarily // to speed up inserting we hide the control temporarily
m_listCtrl->Hide(); m_listCtrl->Hide();
@@ -578,13 +592,27 @@ void MyListCtrl::OnCacheHint(wxListEvent& event)
event.GetCacheFrom(), event.GetCacheTo() ); event.GetCacheFrom(), event.GetCacheTo() );
} }
void MyListCtrl::SetColumnImage(int col, int image)
{
wxListItem item;
item.SetMask(wxLIST_MASK_IMAGE);
item.SetImage(image);
SetColumn(col, item);
}
void MyListCtrl::OnColClick(wxListEvent& event) void MyListCtrl::OnColClick(wxListEvent& event)
{ {
wxLogMessage( wxT("OnColumnClick at %d."), event.GetColumn() ); int col = event.GetColumn();
SetColumnImage(col, 0);
wxLogMessage( wxT("OnColumnClick at %d."), col );
} }
void MyListCtrl::OnColRightClick(wxListEvent& event) void MyListCtrl::OnColRightClick(wxListEvent& event)
{ {
int col = event.GetColumn();
SetColumnImage(col, -1);
wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() ); wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
} }

View File

@@ -54,6 +54,8 @@ public:
void OnChar(wxKeyEvent& event); void OnChar(wxKeyEvent& event);
private: private:
void SetColumnImage(int col, int image);
void LogEvent(const wxListEvent& event, const wxChar *eventName); void LogEvent(const wxListEvent& event, const wxChar *eventName);
virtual wxString OnGetItemText(long item, long column) const; virtual wxString OnGetItemText(long item, long column) const;

View File

@@ -117,6 +117,10 @@ static void wxConvertFromMSWListItem(HWND hwndListCtrl,
wxListItem& info, wxListItem& info,
/* const */ LV_ITEM& lvItem); /* const */ LV_ITEM& lvItem);
// convert our wxListItem to LV_COLUMN
static void wxConvertToMSWListCol(int col, const wxListItem& item,
LV_COLUMN& lvCol);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// events // events
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -553,9 +557,7 @@ bool wxListCtrl::SetBackgroundColour(const wxColour& col)
bool wxListCtrl::GetColumn(int col, wxListItem& item) const bool wxListCtrl::GetColumn(int col, wxListItem& item) const
{ {
LV_COLUMN lvCol; LV_COLUMN lvCol;
lvCol.mask = 0; wxZeroMemory(lvCol);
lvCol.fmt = 0;
lvCol.pszText = NULL;
if ( item.m_mask & wxLIST_MASK_TEXT ) if ( item.m_mask & wxLIST_MASK_TEXT )
{ {
@@ -564,7 +566,7 @@ bool wxListCtrl::GetColumn(int col, wxListItem& item) const
lvCol.cchTextMax = 512; lvCol.cchTextMax = 512;
} }
bool success = (ListView_GetColumn(GetHwnd(), col, & lvCol) != 0); bool success = ListView_GetColumn(GetHwnd(), col, & lvCol) != 0;
// item.m_subItem = lvCol.iSubItem; // item.m_subItem = lvCol.iSubItem;
item.m_width = lvCol.cx; item.m_width = lvCol.cx;
@@ -592,41 +594,9 @@ bool wxListCtrl::GetColumn(int col, wxListItem& item) const
bool wxListCtrl::SetColumn(int col, wxListItem& item) bool wxListCtrl::SetColumn(int col, wxListItem& item)
{ {
LV_COLUMN lvCol; LV_COLUMN lvCol;
lvCol.mask = 0; wxConvertToMSWListCol(col, item, lvCol);
lvCol.fmt = 0;
lvCol.pszText = NULL;
if ( item.m_mask & wxLIST_MASK_TEXT ) return ListView_SetColumn(GetHwnd(), col, &lvCol) != 0;
{
lvCol.mask |= LVCF_TEXT;
lvCol.pszText = WXSTRINGCAST item.m_text;
lvCol.cchTextMax = 0; // Ignored
}
if ( item.m_mask & wxLIST_MASK_FORMAT )
{
lvCol.mask |= LVCF_FMT;
if ( item.m_format == wxLIST_FORMAT_LEFT )
lvCol.fmt = LVCFMT_LEFT;
if ( item.m_format == wxLIST_FORMAT_RIGHT )
lvCol.fmt = LVCFMT_RIGHT;
if ( item.m_format == wxLIST_FORMAT_CENTRE )
lvCol.fmt = LVCFMT_CENTER;
}
if ( item.m_mask & wxLIST_MASK_WIDTH )
{
lvCol.mask |= LVCF_WIDTH;
lvCol.cx = item.m_width;
if ( lvCol.cx == wxLIST_AUTOSIZE)
lvCol.cx = LVSCW_AUTOSIZE;
else if ( lvCol.cx == wxLIST_AUTOSIZE_USEHEADER)
lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
}
lvCol.mask |= LVCF_SUBITEM;
lvCol.iSubItem = col;
return (ListView_SetColumn(GetHwnd(), col, & lvCol) != 0);
} }
// Gets the column width // Gets the column width
@@ -648,7 +618,7 @@ bool wxListCtrl::SetColumnWidth(int col, int width)
else if ( width2 == wxLIST_AUTOSIZE_USEHEADER) else if ( width2 == wxLIST_AUTOSIZE_USEHEADER)
width2 = LVSCW_AUTOSIZE_USEHEADER; width2 = LVSCW_AUTOSIZE_USEHEADER;
return (ListView_SetColumnWidth(GetHwnd(), col2, width2) != 0); return ListView_SetColumnWidth(GetHwnd(), col2, width2) != 0;
} }
// Gets the number of items that can fit vertically in the // Gets the number of items that can fit vertically in the
@@ -1302,49 +1272,33 @@ long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
long wxListCtrl::InsertColumn(long col, wxListItem& item) long wxListCtrl::InsertColumn(long col, wxListItem& item)
{ {
LV_COLUMN lvCol; LV_COLUMN lvCol;
lvCol.mask = 0; wxConvertToMSWListCol(col, item, lvCol);
lvCol.fmt = 0;
lvCol.pszText = NULL;
if ( item.m_mask & wxLIST_MASK_TEXT ) if ( !(lvCol.mask & LVCF_WIDTH) )
{
lvCol.mask |= LVCF_TEXT;
lvCol.pszText = WXSTRINGCAST item.m_text;
lvCol.cchTextMax = 0; // Ignored
}
if ( item.m_mask & wxLIST_MASK_FORMAT )
{
lvCol.mask |= LVCF_FMT;
if ( item.m_format == wxLIST_FORMAT_LEFT )
lvCol.fmt = LVCFMT_LEFT;
if ( item.m_format == wxLIST_FORMAT_RIGHT )
lvCol.fmt = LVCFMT_RIGHT;
if ( item.m_format == wxLIST_FORMAT_CENTRE )
lvCol.fmt = LVCFMT_CENTER;
}
lvCol.mask |= LVCF_WIDTH;
if ( item.m_mask & wxLIST_MASK_WIDTH )
{
if ( item.m_width == wxLIST_AUTOSIZE)
lvCol.cx = LVSCW_AUTOSIZE;
else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER)
lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
else
lvCol.cx = item.m_width;
}
else
{ {
// always give some width to the new column: this one is compatible // always give some width to the new column: this one is compatible
// with wxGTK // with the generic version
lvCol.mask |= LVCF_WIDTH;
lvCol.cx = 80; lvCol.cx = 80;
} }
lvCol.mask |= LVCF_SUBITEM; // when we insert a column which can contain an image, we must specify this
lvCol.iSubItem = col; // flag right now as doing it later in SetColumn() has no effect
//
// we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no
// way to dynamically set/clear the bitmap as the column without a bitmap
// on the left looks ugly (there is a hole)
//
// unfortunately with my version of comctl32.dll (5.80), the left column
// image is always on the left and it seems that it's a "feature" - I
// didn't find any way to work around it in any case
if ( lvCol.mask & LVCF_IMAGE )
{
lvCol.mask |= LVCF_FMT;
lvCol.fmt |= LVCFMT_BITMAP_ON_RIGHT;
}
bool success = ListView_InsertColumn(GetHwnd(), col, & lvCol) != -1; bool success = ListView_InsertColumn(GetHwnd(), col, &lvCol) != -1;
if ( success ) if ( success )
{ {
m_colCount++; m_colCount++;
@@ -2288,6 +2242,51 @@ static void wxConvertToMSWListItem(const wxListCtrl *ctrl,
lvItem.mask |= LVIF_PARAM; lvItem.mask |= LVIF_PARAM;
} }
static void wxConvertToMSWListCol(int col, const wxListItem& item,
LV_COLUMN& lvCol)
{
wxZeroMemory(lvCol);
if ( item.m_mask & wxLIST_MASK_TEXT )
{
lvCol.mask |= LVCF_TEXT;
lvCol.pszText = (wxChar *)item.m_text.c_str(); // cast is safe
}
if ( item.m_mask & wxLIST_MASK_FORMAT )
{
lvCol.mask |= LVCF_FMT;
if ( item.m_format == wxLIST_FORMAT_LEFT )
lvCol.fmt = LVCFMT_LEFT;
else if ( item.m_format == wxLIST_FORMAT_RIGHT )
lvCol.fmt = LVCFMT_RIGHT;
else if ( item.m_format == wxLIST_FORMAT_CENTRE )
lvCol.fmt = LVCFMT_CENTER;
}
if ( item.m_mask & wxLIST_MASK_WIDTH )
{
lvCol.mask |= LVCF_WIDTH;
if ( item.m_width == wxLIST_AUTOSIZE)
lvCol.cx = LVSCW_AUTOSIZE;
else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER)
lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
else
lvCol.cx = item.m_width;
}
if ( item.m_mask & wxLIST_MASK_IMAGE )
{
if ( wxTheApp->GetComCtl32Version() >= 470 )
{
lvCol.mask |= LVCF_IMAGE;
lvCol.iImage = item.m_image;
}
//else: it doesn't support item images anyhow
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// List event // List event
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -3303,9 +3303,9 @@ bool wxWindowMSW::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
#if wxUSE_MENUS_NATIVE #if wxUSE_MENUS_NATIVE
// is it a menu item? // is it a menu item?
if ( id == 0 ) DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
if ( id == 0 && pDrawStruct->CtlType == ODT_MENU )
{ {
DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData); wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData);
wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
@@ -3344,9 +3344,9 @@ bool wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
{ {
#if wxUSE_OWNER_DRAWN #if wxUSE_OWNER_DRAWN
// is it a menu item? // is it a menu item?
if ( id == 0 ) MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
if ( id == 0 && pMeasureStruct->CtlType == ODT_MENU )
{ {
MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData); wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );