+ dc.DrawLine( x, y, x, y+h-1 ); // left (outer)
+ dc.DrawLine( x, y, x+w-1, y ); // top (outer)
+
+ return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
+}
+
+
+int
+wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win,
+ wxDC& dc,
+ const wxRect& rect,
+ int flags,
+ wxHeaderSortIconType sortArrow,
+ wxHeaderButtonParams* params)
+{
+ int labelWidth = 0;
+
+ // Mark this item as selected. For the generic version we'll just draw an
+ // underline
+ if ( flags & wxCONTROL_SELECTED )
+ {
+ // draw a line at the bottom of the header button, overlaying the
+ // native hot-tracking line (on XP)
+ const int penwidth = 3;
+ int y = rect.y + rect.height + 1 - penwidth;
+ wxColour c = (params && params->m_selectionColour.IsOk()) ?
+ params->m_selectionColour : wxColour(0x66, 0x66, 0x66);
+ wxPen pen(c, penwidth);
+ pen.SetCap(wxCAP_BUTT);
+ dc.SetPen(pen);
+ dc.DrawLine(rect.x, y, rect.x + rect.width, y);
+ }
+
+ // Draw an up or down arrow
+ int arrowSpace = 0;
+ if (sortArrow != wxHDR_SORT_ICON_NONE )
+ {
+ wxRect ar = rect;
+
+ // make a rect for the arrow
+ ar.height = 4;
+ ar.width = 8;
+ ar.y += (rect.height - ar.height)/2;
+ ar.x = ar.x + rect.width - 3*ar.width/2;
+ arrowSpace = 3*ar.width/2; // space to preserve when drawing the label
+
+ wxPoint triPt[3];
+ if ( sortArrow & wxHDR_SORT_ICON_UP )
+ {
+ triPt[0].x = ar.width / 2;
+ triPt[0].y = 0;
+ triPt[1].x = ar.width;
+ triPt[1].y = ar.height;
+ triPt[2].x = 0;
+ triPt[2].y = ar.height;
+ }
+ else
+ {
+ triPt[0].x = 0;
+ triPt[0].y = 0;
+ triPt[1].x = ar.width;
+ triPt[1].y = 0;
+ triPt[2].x = ar.width / 2;
+ triPt[2].y = ar.height;
+ }
+
+ wxColour c = (params && params->m_arrowColour.IsOk()) ?
+ params->m_arrowColour : wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW);
+
+ wxDCPenChanger setPen(dc, c);
+ wxDCBrushChanger setBrush(dc, c);
+
+ wxDCClipper clip(dc, rect);
+ dc.DrawPolygon( 3, triPt, ar.x, ar.y);
+ }
+ labelWidth += arrowSpace;
+
+ int bmpWidth = 0;
+
+ // draw the bitmap if there is one
+ if ( params && params->m_labelBitmap.IsOk() )
+ {
+ int w = params->m_labelBitmap.GetWidth();
+ int h = params->m_labelBitmap.GetHeight();
+
+ const int margin = 1; // an extra pixel on either side of the bitmap
+
+ bmpWidth = w + 2*margin;
+ labelWidth += bmpWidth;
+
+ int x = rect.x + margin;
+ const int y = rect.y + wxMax(1, (rect.height - h) / 2);
+
+ const int extraSpace = rect.width - labelWidth;
+ if ( params->m_labelText.empty() && extraSpace > 0 )
+ {
+ // use the alignment flags
+ switch (params->m_labelAlignment)
+ {
+ default:
+ case wxALIGN_LEFT:
+ break;
+
+ case wxALIGN_CENTER:
+ x += extraSpace/2;
+ break;
+
+ case wxALIGN_RIGHT:
+ x += extraSpace;
+ break;
+ }
+ }
+
+ wxDCClipper clip(dc, rect);
+ dc.DrawBitmap(params->m_labelBitmap, x, y, true);
+ }
+
+ // Draw a label if one is given
+ if ( params && !params->m_labelText.empty() )
+ {
+ const int margin = 5; // number of pixels to reserve on either side of the label
+ labelWidth += 2*margin;
+
+ wxFont font = params->m_labelFont.IsOk() ?
+ params->m_labelFont : win->GetFont();
+ wxColour clr = params->m_labelColour.IsOk() ?
+ params->m_labelColour : win->GetForegroundColour();
+
+ wxString label( params->m_labelText );
+
+ dc.SetFont(font);
+ dc.SetTextForeground(clr);
+ dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
+
+ int tw, th, td;
+ dc.GetTextExtent( label, &tw, &th, &td);
+
+ int x = rect.x + bmpWidth + margin;
+ const int y = rect.y + wxMax(0, (rect.height - (th+td)) / 2);
+
+ // truncate and add an ellipsis (...) if the text is too wide.
+ const int availWidth = rect.width - labelWidth;
+#if wxUSE_CONTROLS
+ if ( tw > availWidth )
+ {
+ label = wxControl::Ellipsize(label,
+ dc,
+ wxELLIPSIZE_END,
+ availWidth,
+ wxELLIPSIZE_FLAGS_NONE);
+ tw = dc.GetTextExtent(label).x;
+ }
+ else // enough space, we can respect alignment
+#endif // wxUSE_CONTROLS
+ {
+ switch (params->m_labelAlignment)
+ {
+ default:
+ case wxALIGN_LEFT:
+ break;
+
+ case wxALIGN_CENTER:
+ x += (availWidth - tw)/2;
+ break;
+
+ case wxALIGN_RIGHT:
+ x += availWidth - tw;
+ break;
+ }
+ }
+
+ dc.DrawText(label, x, y);
+
+ labelWidth += tw;
+ }
+
+ return labelWidth;