wxGrid::wxGrid()
{
- // in order to make sure that a size event is not
- // trigerred in a unfinished state
- m_cornerLabelWin = NULL;
- m_rowLabelWin = NULL;
- m_colLabelWin = NULL;
- m_gridWin = NULL;
+ InitVars();
}
wxGrid::wxGrid( wxWindow *parent,
long style,
const wxString& name )
{
+ InitVars();
Create(parent, id, pos, size, style, name);
}
void wxGrid::Create()
{
- // set to true by CreateGrid
- m_created = false;
-
// create the type registry
m_typeRegistry = new wxGridTypeRegistry;
- m_selection = NULL;
-
- m_table = (wxGridTableBase *) NULL;
- m_ownTable = false;
m_cellEditCtrlEnabled = false;
return m_created;
}
+void wxGrid::InitVars()
+{
+ m_created = false;
+
+ m_cornerLabelWin = NULL;
+ m_rowLabelWin = NULL;
+ m_colLabelWin = NULL;
+ m_gridWin = NULL;
+
+ m_table = NULL;
+ m_ownTable = false;
+
+ m_selection = NULL;
+ m_defaultCellAttr = NULL;
+ m_typeRegistry = NULL;
+ m_winCapture = NULL;
+}
+
void wxGrid::Init()
{
m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH;
}
}
+ // the grid may be too small to have enough space for the labels yet, don't
+ // size the windows to negative sizes in this case
+ int gw = cw - m_rowLabelWidth;
+ int gh = ch - m_colLabelHeight;
+ if (gw < 0)
+ gw = 0;
+ if (gh < 0)
+ gh = 0;
+
if ( m_cornerLabelWin && m_cornerLabelWin->IsShown() )
m_cornerLabelWin->SetSize( 0, 0, m_rowLabelWidth, m_colLabelHeight );
if ( m_colLabelWin && m_colLabelWin->IsShown() )
- m_colLabelWin->SetSize( m_rowLabelWidth, 0, cw - m_rowLabelWidth, m_colLabelHeight );
+ m_colLabelWin->SetSize( m_rowLabelWidth, 0, gw, m_colLabelHeight );
if ( m_rowLabelWin && m_rowLabelWin->IsShown() )
- m_rowLabelWin->SetSize( 0, m_colLabelHeight, m_rowLabelWidth, ch - m_colLabelHeight );
+ m_rowLabelWin->SetSize( 0, m_colLabelHeight, m_rowLabelWidth, gh );
if ( m_gridWin && m_gridWin->IsShown() )
- m_gridWin->SetSize( m_rowLabelWidth, m_colLabelHeight, cw - m_rowLabelWidth, ch - m_colLabelHeight );
+ m_gridWin->SetSize( m_rowLabelWidth, m_colLabelHeight, gw, gh );
}
// this is called when the grid table sends a message
{
// Don't do anything if between Begin/EndBatch...
// EndBatch() will do all this on the last nested one anyway.
- if (! GetBatchCount())
+ if ( m_created && !GetBatchCount() )
{
// Refresh to get correct scrolled position:
wxScrolledWindow::Refresh(eraseb, rect);
// Split multi-line text up into an array of strings.
// Any existing contents of the string array are preserved.
//
+// TODO: refactor wxTextFile::Read() and reuse the same code from here
void wxGrid::StringToLines( const wxString& value, wxArrayString& lines ) const
{
int startPos = 0;
}
else
{
- lines.Add( value.Mid(startPos, pos) );
+ lines.Add( tVal.Mid(startPos, pos) );
}
startPos += pos + 1;
}
- if ( startPos < (int)value.length() )
+ if ( startPos < (int)tVal.length() )
{
- lines.Add( value.Mid( startPos ) );
+ lines.Add( tVal.Mid( startPos ) );
}
}
return rect;
}
+// ----------------------------------------------------------------------------
+// drop target
+// ----------------------------------------------------------------------------
+
+#if wxUSE_DRAG_AND_DROP
+
+// this allow setting drop target directly on wxGrid
+void wxGrid::SetDropTarget(wxDropTarget *dropTarget)
+{
+ GetGridWindow()->SetDropTarget(dropTarget);
+}
+
+#endif // wxUSE_DRAG_AND_DROP
+
// ----------------------------------------------------------------------------
// grid event classes
// ----------------------------------------------------------------------------