+ // see if we have enough space for the column label
+
+ // for this we need the width of the text
+ wxCoord wLabel;
+ dc.GetTextExtent(item.GetText(), &wLabel, NULL);
+ wLabel += 2*EXTRA_WIDTH;
+
+ // and the width of the icon, if any
+ static const int MARGIN_BETWEEN_TEXT_AND_ICON = 2;
+ int ix = 0, // init them just to suppress the compiler warnings
+ iy = 0;
+ const int image = item.m_image;
+ wxImageListType *imageList;
+ if ( image != -1 )
+ {
+ imageList = m_owner->m_small_image_list;
+ if ( imageList )
+ {
+ imageList->GetSize(image, ix, iy);
+ wLabel += ix + MARGIN_BETWEEN_TEXT_AND_ICON;
+ }
+ }
+ else
+ {
+ imageList = NULL;
+ }
+
+ // ignore alignment if there is not enough space anyhow
+ int xAligned;
+ switch ( wLabel < cw ? item.GetAlign() : wxLIST_FORMAT_LEFT )
+ {
+ default:
+ wxFAIL_MSG( _T("unknown list item format") );
+ // fall through
+
+ case wxLIST_FORMAT_LEFT:
+ xAligned = x;
+ break;
+
+ case wxLIST_FORMAT_RIGHT:
+ xAligned = x + cw - wLabel;
+ break;
+
+ case wxLIST_FORMAT_CENTER:
+ xAligned = x + (cw - wLabel) / 2;
+ break;
+ }
+
+
+ // if we have an image, draw it on the right of the label
+ if ( imageList )
+ {
+ imageList->Draw
+ (
+ image,
+ dc,
+ xAligned + wLabel - ix - MARGIN_BETWEEN_TEXT_AND_ICON,
+ HEADER_OFFSET_Y + (h - 4 - iy)/2,
+ wxIMAGELIST_DRAW_TRANSPARENT
+ );
+
+ cw -= ix + MARGIN_BETWEEN_TEXT_AND_ICON;
+ }
+
+ // draw the text clipping it so that it doesn't overwrite the column
+ // boundary
+ wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 );
+
+ dc.DrawText( item.GetText(),
+ xAligned + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT );
+
+ x += wCol;