Applied patch [ 608866 ] wxGrid: vertical column label text

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19248 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2003-02-18 14:25:34 +00:00
parent 0878fb4c7d
commit d43851f77e
2 changed files with 154 additions and 13 deletions

View File

@@ -1122,11 +1122,13 @@ public:
// //
void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&, void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
int horizontalAlignment = wxALIGN_LEFT, int horizontalAlignment = wxALIGN_LEFT,
int verticalAlignment = wxALIGN_TOP ); int verticalAlignment = wxALIGN_TOP,
int textOrientation = wxHORIZONTAL );
void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&, void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&,
int horizontalAlignment = wxALIGN_LEFT, int horizontalAlignment = wxALIGN_LEFT,
int verticalAlignment = wxALIGN_TOP ); int verticalAlignment = wxALIGN_TOP,
int textOrientation = wxHORIZONTAL );
// Split a string containing newline chararcters into an array of // Split a string containing newline chararcters into an array of
@@ -1238,6 +1240,7 @@ public:
wxFont GetLabelFont() { return m_labelFont; } wxFont GetLabelFont() { return m_labelFont; }
void GetRowLabelAlignment( int *horiz, int *vert ); void GetRowLabelAlignment( int *horiz, int *vert );
void GetColLabelAlignment( int *horiz, int *vert ); void GetColLabelAlignment( int *horiz, int *vert );
int GetColLabelTextOrientation();
wxString GetRowLabelValue( int row ); wxString GetRowLabelValue( int row );
wxString GetColLabelValue( int col ); wxString GetColLabelValue( int col );
wxColour GetGridLineColour() { return m_gridLineColour; } wxColour GetGridLineColour() { return m_gridLineColour; }
@@ -1252,6 +1255,7 @@ public:
void SetLabelFont( const wxFont& ); void SetLabelFont( const wxFont& );
void SetRowLabelAlignment( int horiz, int vert ); void SetRowLabelAlignment( int horiz, int vert );
void SetColLabelAlignment( int horiz, int vert ); void SetColLabelAlignment( int horiz, int vert );
void SetColLabelTextOrientation( int textOrientation );
void SetRowLabelValue( int row, const wxString& ); void SetRowLabelValue( int row, const wxString& );
void SetColLabelValue( int col, const wxString& ); void SetColLabelValue( int col, const wxString& );
void SetGridLineColour( const wxColour& ); void SetGridLineColour( const wxColour& );
@@ -1328,6 +1332,12 @@ public:
// and also set the grid size to just fit its contents // and also set the grid size to just fit its contents
void AutoSize(); void AutoSize();
// autosize row height depending on label text
void AutoSizeRowLabelSize( int row );
// autosize column width depending on label text
void AutoSizeColLabelSize( int col );
// column won't be resized to be lesser width - this must be called during // column won't be resized to be lesser width - this must be called during
// the grid creation because it won't resize the column if it's already // the grid creation because it won't resize the column if it's already
// narrower than the minimal width // narrower than the minimal width
@@ -1707,6 +1717,7 @@ protected:
int m_rowLabelVertAlign; int m_rowLabelVertAlign;
int m_colLabelHorizAlign; int m_colLabelHorizAlign;
int m_colLabelVertAlign; int m_colLabelVertAlign;
int m_colLabelTextOrientation;
bool m_defaultRowLabelValues; bool m_defaultRowLabelValues;
bool m_defaultColLabelValues; bool m_defaultColLabelValues;

View File

@@ -3970,6 +3970,7 @@ void wxGrid::Init()
m_colLabelHorizAlign = wxALIGN_CENTRE; m_colLabelHorizAlign = wxALIGN_CENTRE;
m_colLabelVertAlign = wxALIGN_CENTRE; m_colLabelVertAlign = wxALIGN_CENTRE;
m_colLabelTextOrientation = wxHORIZONTAL;
m_defaultColWidth = WXGRID_DEFAULT_COL_WIDTH; m_defaultColWidth = WXGRID_DEFAULT_COL_WIDTH;
m_defaultRowHeight = m_gridWin->GetCharHeight(); m_defaultRowHeight = m_gridWin->GetCharHeight();
@@ -4005,10 +4006,8 @@ void wxGrid::Init()
m_selectingTopLeft = wxGridNoCellCoords; m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords; m_selectingBottomRight = wxGridNoCellCoords;
// m_selectionBackground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); m_selectionBackground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
// m_selectionForeground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); m_selectionForeground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
m_selectionBackground = *wxBLACK;
m_selectionForeground = *wxWHITE;
m_editable = TRUE; // default for whole grid m_editable = TRUE; // default for whole grid
@@ -4792,11 +4791,20 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
// //
else if (event.LeftDClick() ) else if (event.LeftDClick() )
{ {
if ( YToEdgeOfRow(y) < 0 ) int row = YToEdgeOfRow(y);
if ( row < 0 )
{ {
row = YToRow(y); row = YToRow(y);
SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event ); SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event );
} }
else
{
// adjust row height depending on label text
AutoSizeRowLabelSize( row );
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
m_dragLastPos = -1;
}
} }
@@ -4998,11 +5006,20 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
// //
if ( event.LeftDClick() ) if ( event.LeftDClick() )
{ {
if ( XToEdgeOfCol(x) < 0 ) int col = XToEdgeOfCol(x);
if ( col < 0 )
{ {
col = XToCol(x); col = XToCol(x);
SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event ); SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event );
} }
else
{
// adjust column width depending on label text
AutoSizeColLabelSize( col );
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
m_dragLastPos = -1;
}
} }
@@ -7065,22 +7082,24 @@ void wxGrid::DrawColLabel( wxDC& dc, int col )
dc.SetTextForeground( GetLabelTextColour() ); dc.SetTextForeground( GetLabelTextColour() );
dc.SetFont( GetLabelFont() ); dc.SetFont( GetLabelFont() );
int hAlign, vAlign; int hAlign, vAlign, orient;
GetColLabelAlignment( &hAlign, &vAlign ); GetColLabelAlignment( &hAlign, &vAlign );
orient = GetColLabelTextOrientation();
wxRect rect; wxRect rect;
rect.SetX( colLeft + 2 ); rect.SetX( colLeft + 2 );
rect.SetY( 2 ); rect.SetY( 2 );
rect.SetWidth( GetColWidth(col) - 4 ); rect.SetWidth( GetColWidth(col) - 4 );
rect.SetHeight( m_colLabelHeight - 4 ); rect.SetHeight( m_colLabelHeight - 4 );
DrawTextRectangle( dc, GetColLabelValue( col ), rect, hAlign, vAlign ); DrawTextRectangle( dc, GetColLabelValue( col ), rect, hAlign, vAlign, orient );
} }
void wxGrid::DrawTextRectangle( wxDC& dc, void wxGrid::DrawTextRectangle( wxDC& dc,
const wxString& value, const wxString& value,
const wxRect& rect, const wxRect& rect,
int horizAlign, int horizAlign,
int vertAlign ) int vertAlign,
int textOrientation )
{ {
wxArrayString lines; wxArrayString lines;
@@ -7092,7 +7111,8 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
lines, lines,
rect, rect,
horizAlign, horizAlign,
vertAlign ); vertAlign,
textOrientation );
} }
@@ -7100,7 +7120,8 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
const wxArrayString& lines, const wxArrayString& lines,
const wxRect& rect, const wxRect& rect,
int horizAlign, int horizAlign,
int vertAlign ) int vertAlign,
int textOrientation )
{ {
long textWidth, textHeight; long textWidth, textHeight;
long lineWidth, lineHeight; long lineWidth, lineHeight;
@@ -7113,20 +7134,34 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
{ {
int l; int l;
float x, y; float x, y;
if( textOrientation == wxHORIZONTAL )
GetTextBoxSize(dc, lines, &textWidth, &textHeight); GetTextBoxSize(dc, lines, &textWidth, &textHeight);
else
GetTextBoxSize( dc, lines, &textHeight, &textWidth );
switch( vertAlign ) switch( vertAlign )
{ {
case wxALIGN_BOTTOM: case wxALIGN_BOTTOM:
if( textOrientation == wxHORIZONTAL )
y = rect.y + (rect.height - textHeight - 1); y = rect.y + (rect.height - textHeight - 1);
else
x = rect.x + rect.width - textWidth;
break; break;
case wxALIGN_CENTRE: case wxALIGN_CENTRE:
if( textOrientation == wxHORIZONTAL )
y = rect.y + ((rect.height - textHeight)/2); y = rect.y + ((rect.height - textHeight)/2);
else
x = rect.x + ((rect.width - textWidth)/2);
break; break;
case wxALIGN_TOP: case wxALIGN_TOP:
default: default:
if( textOrientation == wxHORIZONTAL )
y = rect.y + 1; y = rect.y + 1;
else
x = rect.x + 1;
break; break;
} }
@@ -7138,21 +7173,38 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
switch( horizAlign ) switch( horizAlign )
{ {
case wxALIGN_RIGHT: case wxALIGN_RIGHT:
if( textOrientation == wxHORIZONTAL )
x = rect.x + (rect.width - lineWidth - 1); x = rect.x + (rect.width - lineWidth - 1);
else
y = rect.y + lineWidth + 1;
break; break;
case wxALIGN_CENTRE: case wxALIGN_CENTRE:
if( textOrientation == wxHORIZONTAL )
x = rect.x + ((rect.width - lineWidth)/2); x = rect.x + ((rect.width - lineWidth)/2);
else
y = rect.y + rect.height - ((rect.height - lineWidth)/2);
break; break;
case wxALIGN_LEFT: case wxALIGN_LEFT:
default: default:
if( textOrientation == wxHORIZONTAL )
x = rect.x + 1; x = rect.x + 1;
else
y = rect.y + rect.height - 1;
break; break;
} }
if( textOrientation == wxHORIZONTAL )
{
dc.DrawText( lines[l], (int)x, (int)y ); dc.DrawText( lines[l], (int)x, (int)y );
y += lineHeight; y += lineHeight;
}
else
{
dc.DrawRotatedText( lines[l], (int)x, (int)y, 90.0 );
x += lineHeight;
}
} }
} }
dc.DestroyClippingRegion(); dc.DestroyClippingRegion();
@@ -8271,6 +8323,11 @@ void wxGrid::GetColLabelAlignment( int *horiz, int *vert )
*vert = m_colLabelVertAlign; *vert = m_colLabelVertAlign;
} }
int wxGrid::GetColLabelTextOrientation()
{
return m_colLabelTextOrientation;
}
wxString wxGrid::GetRowLabelValue( int row ) wxString wxGrid::GetRowLabelValue( int row )
{ {
if ( m_table ) if ( m_table )
@@ -8453,6 +8510,26 @@ void wxGrid::SetColLabelAlignment( int horiz, int vert )
} }
} }
// Note: under MSW, the default column label font must be changed because it
// does not support vertical printing
//
// Example: wxFont font(9, wxSWISS, wxNORMAL, wxBOLD);
// pGrid->SetLabelFont(font);
// pGrid->SetColLabelTextOrientation(wxVERTICAL);
//
void wxGrid::SetColLabelTextOrientation( int textOrientation )
{
if( textOrientation == wxHORIZONTAL || textOrientation == wxVERTICAL )
{
m_colLabelTextOrientation = textOrientation;
}
if ( !GetBatchCount() )
{
m_colLabelWin->Refresh();
}
}
void wxGrid::SetRowLabelValue( int row, const wxString& s ) void wxGrid::SetRowLabelValue( int row, const wxString& s )
{ {
if ( m_table ) if ( m_table )
@@ -9324,7 +9401,11 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column )
dc.SetFont( GetLabelFont() ); dc.SetFont( GetLabelFont() );
if ( column ) if ( column )
{
dc.GetTextExtent( GetColLabelValue(col), &w, &h ); dc.GetTextExtent( GetColLabelValue(col), &w, &h );
if( GetColLabelTextOrientation() == wxVERTICAL )
w = h;
}
else else
dc.GetTextExtent( GetRowLabelValue(row), &w, &h ); dc.GetTextExtent( GetRowLabelValue(row), &w, &h );
@@ -9509,6 +9590,55 @@ void wxGrid::AutoSize()
SetClientSize(sizeFit); SetClientSize(sizeFit);
} }
void wxGrid::AutoSizeRowLabelSize( int row )
{
wxArrayString lines;
long w, h;
// Hide the edit control, so it
// won't interfer with drag-shrinking.
if( IsCellEditControlShown() )
{
HideCellEditControl();
SaveEditControlValue();
}
// autosize row height depending on label text
StringToLines( GetRowLabelValue( row ), lines );
wxClientDC dc( m_rowLabelWin );
GetTextBoxSize( dc, lines, &w, &h);
if( h < m_defaultRowHeight )
h = m_defaultRowHeight;
SetRowSize(row, h);
ForceRefresh();
}
void wxGrid::AutoSizeColLabelSize( int col )
{
wxArrayString lines;
long w, h;
// Hide the edit control, so it
// won't interfer with drag-shrinking.
if( IsCellEditControlShown() )
{
HideCellEditControl();
SaveEditControlValue();
}
// autosize column width depending on label text
StringToLines( GetColLabelValue( col ), lines );
wxClientDC dc( m_colLabelWin );
if( GetColLabelTextOrientation() == wxHORIZONTAL )
GetTextBoxSize( dc, lines, &w, &h);
else
GetTextBoxSize( dc, lines, &h, &w);
if( w < m_defaultColWidth )
w = m_defaultColWidth;
SetColSize(col, w);
ForceRefresh();
}
wxSize wxGrid::DoGetBestSize() const wxSize wxGrid::DoGetBestSize() const
{ {
// don't set sizes, only calculate them // don't set sizes, only calculate them