Use available space better in wxDataViewCtrl date renderer in wxOSX.

Try to show as much useful information as possible for the available width,
notably show the time fully, including seconds, which was never done before.

Also add a date column to the dataview sample to allow seeing how this works
in practice.

See #16640.
This commit is contained in:
Hartwig Wiesmann
2015-07-18 02:11:27 +02:00
committed by Vadim Zeitlin
parent 8e0799e3e5
commit 7feaa794bc
4 changed files with 24 additions and 19 deletions

View File

@@ -640,6 +640,8 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
wxALIGN_NOT, wxALIGN_NOT,
wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE); wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE);
m_ctrl[1]->AppendDateColumn("date",
MyListModel::Col_Date);
m_attributes = m_attributes =
new wxDataViewColumn("attributes", new wxDataViewColumn("attributes",
new wxDataViewTextRenderer, new wxDataViewTextRenderer,

View File

@@ -428,6 +428,10 @@ void MyListModel::GetValueByRow( wxVariant &variant,
} }
break; break;
case Col_Date:
variant = wxDateTime(1, wxDateTime::Jan, 2000).Add(wxTimeSpan(row));
break;
case Col_TextWithAttr: case Col_TextWithAttr:
{ {
static const char *labels[5] = static const char *labels[5] =
@@ -454,6 +458,7 @@ bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col,
switch ( col ) switch ( col )
{ {
case Col_EditableText: case Col_EditableText:
case Col_Date:
return false; return false;
case Col_IconText: case Col_IconText:
@@ -524,6 +529,7 @@ bool MyListModel::SetValueByRow( const wxVariant &variant,
} }
return true; return true;
case Col_Date:
case Col_TextWithAttr: case Col_TextWithAttr:
case Col_Custom: case Col_Custom:
wxLogError("Cannot edit the column %d", col); wxLogError("Cannot edit the column %d", col);

View File

@@ -194,6 +194,7 @@ public:
{ {
Col_EditableText, Col_EditableText,
Col_IconText, Col_IconText,
Col_Date,
Col_TextWithAttr, Col_TextWithAttr,
Col_Custom, Col_Custom,
Col_Max Col_Max

View File

@@ -2999,31 +2999,27 @@ bool wxDataViewDateRenderer::MacRender()
// in the first instance; but as this is often impossible due to // in the first instance; but as this is often impossible due to
// space restrictions the style is shortened per loop; finally, if // space restrictions the style is shortened per loop; finally, if
// the shortest time and date format does not fit into the cell // the shortest time and date format does not fit into the cell
// the time part is dropped; remark: the time part itself is not // the time part is dropped
// modified per iteration loop and only uses the short style,
// means that only the hours and minutes are being shown
// GetObject() returns a date for testing the size of a date object // GetObject() returns a date for testing the size of a date object
[GetNativeData()->GetItemCell() setObjectValue:GetNativeData()->GetObject()]; [GetNativeData()->GetItemCell() setObjectValue:GetNativeData()->GetObject()];
[[GetNativeData()->GetItemCell() formatter] setTimeStyle:NSDateFormatterShortStyle];
for (int dateFormatterStyle=4; dateFormatterStyle>0; --dateFormatterStyle) bool formatFound = false;
int dateFormatterStyle = kCFDateFormatterFullStyle;
while ( !formatFound && (dateFormatterStyle > 0) )
{ {
[[GetNativeData()->GetItemCell() formatter] setDateStyle:(NSDateFormatterStyle)dateFormatterStyle]; int timeFormatterStyle = dateFormatterStyle;
if (dateFormatterStyle == 1)
while ( !formatFound && (timeFormatterStyle >= dateFormatterStyle - 1) )
{ {
// if the shortest style for displaying the date and time [[GetNativeData()->GetItemCell() formatter] setDateStyle:(NSDateFormatterStyle)dateFormatterStyle];
// is too long to be fully visible remove the time part of [[GetNativeData()->GetItemCell() formatter] setTimeStyle:(NSDateFormatterStyle)timeFormatterStyle];
// the date: if ( [GetNativeData()->GetItemCell() cellSize].width <= [GetNativeData()->GetColumnPtr() width] )
if ([GetNativeData()->GetItemCell() cellSize].width > [GetNativeData()->GetColumnPtr() width]) formatFound = true;
[[GetNativeData()->GetItemCell() formatter] setTimeStyle:NSDateFormatterNoStyle]; else
{ --timeFormatterStyle;
// basically not necessary as the loop would end anyway
// but let's save the last comparison
break;
}
} }
else if ([GetNativeData()->GetItemCell() cellSize].width <= [GetNativeData()->GetColumnPtr() width]) --dateFormatterStyle;
break;
} }
// set data (the style is set by the previous loop); on OSX the // set data (the style is set by the previous loop); on OSX the
// date has to be specified with respect to UTC; in wxWidgets the // date has to be specified with respect to UTC; in wxWidgets the