don't return hardcoded constants for empty renderers, introduce wxDVC_DEFAULT_RENDERER_SIZE.

Some code styling review (indentation, long line wrapping, etc)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59392 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2009-03-06 22:56:27 +00:00
parent f453d7eada
commit ce468dc28b
2 changed files with 68 additions and 52 deletions

View File

@@ -32,10 +32,6 @@ class WXDLLIMPEXP_FWD_CORE wxImageList;
#define wxHAS_GENERIC_DATAVIEWCTRL #define wxHAS_GENERIC_DATAVIEWCTRL
#endif #endif
// ----------------------------------------------------------------------------
// wxDataViewCtrl flags
// ----------------------------------------------------------------------------
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDataViewCtrl globals // wxDataViewCtrl globals
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -49,6 +45,13 @@ class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier;
extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr[]; extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr[];
// ----------------------------------------------------------------------------
// wxDataViewCtrl flags
// ----------------------------------------------------------------------------
// size of a wxDataViewRenderer without contents:
#define wxDVC_DEFAULT_RENDERER_SIZE 20
// the default width of new (text) columns: // the default width of new (text) columns:
#define wxDVC_DEFAULT_WIDTH 80 #define wxDVC_DEFAULT_WIDTH 80
@@ -526,7 +529,8 @@ public:
{ m_owner = owner; } { m_owner = owner; }
// getters: // getters:
unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); } unsigned int GetModelColumn() const
{ return static_cast<unsigned int>(m_model_column); }
wxDataViewCtrl *GetOwner() const { return m_owner; } wxDataViewCtrl *GetOwner() const { return m_owner; }
wxDataViewRenderer* GetRenderer() const { return m_renderer; } wxDataViewRenderer* GetRenderer() const { return m_renderer; }
@@ -566,11 +570,17 @@ public:
wxDataViewCtrlBase(); wxDataViewCtrlBase();
virtual ~wxDataViewCtrlBase(); virtual ~wxDataViewCtrlBase();
// model
// -----
virtual bool AssociateModel( wxDataViewModel *model ); virtual bool AssociateModel( wxDataViewModel *model );
wxDataViewModel* GetModel(); wxDataViewModel* GetModel();
const wxDataViewModel* GetModel() const; const wxDataViewModel* GetModel() const;
// short cuts
// column management
// -----------------
wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column, wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
wxAlignment align = wxALIGN_NOT, wxAlignment align = wxALIGN_NOT,
@@ -669,7 +679,6 @@ public:
wxAlignment align = wxALIGN_CENTER, wxAlignment align = wxALIGN_CENTER,
int flags = wxDATAVIEW_COL_RESIZABLE ); int flags = wxDATAVIEW_COL_RESIZABLE );
virtual bool PrependColumn( wxDataViewColumn *col ); virtual bool PrependColumn( wxDataViewColumn *col );
virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col ); virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
virtual bool AppendColumn( wxDataViewColumn *col ); virtual bool AppendColumn( wxDataViewColumn *col );
@@ -688,6 +697,10 @@ public:
virtual wxDataViewColumn *GetSortingColumn() const = 0; virtual wxDataViewColumn *GetSortingColumn() const = 0;
// items management
// ----------------
void SetIndent( int indent ) void SetIndent( int indent )
{ m_indent = indent ; DoSetIndent(); } { m_indent = indent ; DoSetIndent(); }
int GetIndent() const int GetIndent() const

View File

@@ -99,6 +99,7 @@ protected:
return *(GetOwner()->GetColumn(idx)); return *(GetOwner()->GetColumn(idx));
} }
// FIXME: currently unused
virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle) virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
{ {
wxDataViewCtrl * const owner = GetOwner(); wxDataViewCtrl * const owner = GetOwner();
@@ -738,12 +739,8 @@ wxSize wxDataViewTextRenderer::GetSize() const
{ {
const wxDataViewCtrl *view = GetView(); const wxDataViewCtrl *view = GetView();
if (!m_text.empty()) if (!m_text.empty())
{ return view->wxWindowBase::GetTextExtent( m_text );
int x,y; return wxSize(wxDVC_DEFAULT_RENDERER_SIZE,wxDVC_DEFAULT_RENDERER_SIZE);
view->GetTextExtent( m_text, &x, &y );
return wxSize( x, y );
}
return wxSize(80,20);
} }
// --------------------------------------------------------- // ---------------------------------------------------------
@@ -844,7 +841,7 @@ wxSize wxDataViewBitmapRenderer::GetSize() const
else if (m_icon.Ok()) else if (m_icon.Ok())
return wxSize( m_icon.GetWidth(), m_icon.GetHeight() ); return wxSize( m_icon.GetWidth(), m_icon.GetHeight() );
return wxSize(16,16); return wxSize(wxDVC_DEFAULT_RENDERER_SIZE,wxDVC_DEFAULT_RENDERER_SIZE);
} }
// --------------------------------------------------------- // ---------------------------------------------------------
@@ -1304,7 +1301,6 @@ int LINKAGEMODE wxDataViewSelectionCmp( unsigned int row1, unsigned int row2 )
return -1; return -1;
} }
IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow, wxWindow) IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow, wxWindow)
BEGIN_EVENT_TABLE(wxDataViewMainWindow,wxWindow) BEGIN_EVENT_TABLE(wxDataViewMainWindow,wxWindow)
@@ -1771,7 +1767,6 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
cell_rect.x = x_start; cell_rect.x = x_start;
for (unsigned int i = col_start; i < col_last; i++) for (unsigned int i = col_start; i < col_last; i++)
{ {
wxDataViewColumn *col = GetOwner()->GetColumnAt( i ); wxDataViewColumn *col = GetOwner()->GetColumnAt( i );
wxDataViewRenderer *cell = col->GetRenderer(); wxDataViewRenderer *cell = col->GetRenderer();
cell_rect.width = col->GetWidth(); cell_rect.width = col->GetWidth();
@@ -2592,18 +2587,20 @@ int wxDataViewMainWindow::GetLineStart( unsigned int row ) const
if (column->IsHidden()) if (column->IsHidden())
continue; // skip it! continue; // skip it!
if ((col != 0) && model->IsContainer(item) && !model->HasContainerColumns(item)) if ((col != 0) &&
model->IsContainer(item) &&
!model->HasContainerColumns(item))
continue; // skip it! continue; // skip it!
const wxDataViewRenderer *renderer = column->GetRenderer();
wxVariant value; wxVariant value;
model->GetValue( value, item, column->GetModelColumn() ); model->GetValue( value, item, column->GetModelColumn() );
wxDataViewRenderer *renderer2 = const_cast<wxDataViewRenderer*>(renderer);
renderer2->SetValue( value ); wxDataViewRenderer *renderer =
const_cast<wxDataViewRenderer*>(column->GetRenderer());
renderer->SetValue( value );
height = wxMax( height, renderer->GetSize().y ); height = wxMax( height, renderer->GetSize().y );
} }
start += height; start += height;
} }
@@ -2653,14 +2650,17 @@ int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
if (column->IsHidden()) if (column->IsHidden())
continue; // skip it! continue; // skip it!
if ((col != 0) && model->IsContainer(item) && !model->HasContainerColumns(item)) if ((col != 0) &&
model->IsContainer(item) &&
!model->HasContainerColumns(item))
continue; // skip it! continue; // skip it!
const wxDataViewRenderer *renderer = column->GetRenderer();
wxVariant value; wxVariant value;
model->GetValue( value, item, column->GetModelColumn() ); model->GetValue( value, item, column->GetModelColumn() );
wxDataViewRenderer *renderer2 = const_cast<wxDataViewRenderer*>(renderer);
renderer2->SetValue( value ); wxDataViewRenderer *renderer =
const_cast<wxDataViewRenderer*>(column->GetRenderer());
renderer->SetValue( value );
height = wxMax( height, renderer->GetSize().y ); height = wxMax( height, renderer->GetSize().y );
} }
@@ -2703,14 +2703,17 @@ int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const
if (column->IsHidden()) if (column->IsHidden())
continue; // skip it! continue; // skip it!
if ((col != 0) && model->IsContainer(item) && !model->HasContainerColumns(item)) if ((col != 0) &&
model->IsContainer(item) &&
!model->HasContainerColumns(item))
continue; // skip it! continue; // skip it!
const wxDataViewRenderer *renderer = column->GetRenderer();
wxVariant value; wxVariant value;
model->GetValue( value, item, column->GetModelColumn() ); model->GetValue( value, item, column->GetModelColumn() );
wxDataViewRenderer *renderer2 = const_cast<wxDataViewRenderer*>(renderer);
renderer2->SetValue( value ); wxDataViewRenderer *renderer =
const_cast<wxDataViewRenderer*>(column->GetRenderer());
renderer->SetValue( value );
height = wxMax( height, renderer->GetSize().y ); height = wxMax( height, renderer->GetSize().y );
} }