- // horizontal alignment:
- if (align & wxALIGN_CENTER_HORIZONTAL)
- item_rect.x = cell_rect.x + (cell_rect.width / 2) - (size.x / 2);
- else if (align & wxALIGN_RIGHT)
- item_rect.x = cell_rect.x + cell_rect.width - size.x;
- // else: wxALIGN_LEFT is the default
+ // take alignment into account only if there is enough space, otherwise
+ // show as much contents as possible
+ //
+ // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
+ // return hard-coded size which can be more than they need and if we
+ // trusted their GetSize() we'd draw the text out of cell bounds
+ // entirely
+
+ if ( size.x < cell_rect.width )
+ {
+ if (align & wxALIGN_CENTER_HORIZONTAL)
+ item_rect.x += (cell_rect.width - size.x)/2;
+ else if (align & wxALIGN_RIGHT)
+ item_rect.x += cell_rect.width - size.x;
+ // else: wxALIGN_LEFT is the default
+
+ item_rect.width = size.x;
+ }