DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK)
DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK)
DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK)
+DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_BEGIN_DRAG)
DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK)
DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK)
DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK)
wxGrid* grid)
{
wxString value = Combo()->GetValue();
- bool changed = value != m_startValue;
-
- if ( changed )
- grid->GetTable()->SetValue(row, col, value);
+ if ( value == m_startValue )
+ return false;
- m_startValue = wxEmptyString;
- if (m_allowOthers)
- Combo()->SetValue(m_startValue);
- else
- Combo()->SetSelection(0);
+ grid->GetTable()->SetValue(row, col, value);
- return changed;
+ return true;
}
void wxGridCellChoiceEditor::Reset()
wxGridCellAttr *attrrow = m_data->m_rowAttrs.GetAttr(row);
wxGridCellAttr *attrcol = m_data->m_colAttrs.GetAttr(col);
- if((attrcell != attrrow) && (attrrow !=attrcol) && (attrcell != attrcol)){
- // Two or move are non NULL
+ if((attrcell != attrrow) && (attrrow != attrcol) && (attrcell != attrcol)){
+ // Two or more are non NULL
attr = new wxGridCellAttr;
attr->SetKind(wxGridCellAttr::Merged);
//m_data->m_mergeAttr.SetAttr(attr, row, col);
}
else
- {
+ {
// one or none is non null return it or null.
if(attrrow) attr = attrrow;
- if(attrcol) attr = attrcol;
- if(attrcell) attr = attrcell;
+ if(attrcol)
+ {
+ if(attr)
+ attr->DecRef();
+ attr = attrcol;
+ }
+ if(attrcell)
+ {
+ if(attr)
+ attr->DecRef();
+ attr = attrcell;
+ }
}
}
break;
attr = m_data->m_cellAttrs.GetAttr(row, col);
break;
case (wxGridCellAttr::Col):
- attr = m_data->m_colAttrs.GetAttr(col);
+ attr = m_data->m_colAttrs.GetAttr(col);
break;
case (wxGridCellAttr::Row):
- attr = m_data->m_rowAttrs.GetAttr(row);
+ attr = m_data->m_rowAttrs.GetAttr(row);
break;
default:
// unused as yet...
wxCONSTRUCTOR_5( wxGrid , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
/*
- TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
+ TODO : Expose more information of a list's layout etc. via appropriate objects (\81à la NotebookPageInfo)
*/
#else
IMPLEMENT_DYNAMIC_CLASS( wxGrid, wxScrolledWindow )
m_rowMinHeights(GRID_HASH_SIZE)
{
Create();
+ SetBestFittingSize(size);
}
bool wxGrid::Create(wxWindow *parent, wxWindowID id,
m_rowMinHeights = wxLongToLongHashMap(GRID_HASH_SIZE) ;
Create() ;
-
+ SetBestFittingSize(size);
return true;
}
m_canDragRowSize = true;
m_canDragColSize = true;
m_canDragGridSize = true;
+ m_canDragCell = false;
m_dragLastPos = -1;
m_dragRowOrCol = -1;
m_isDragging = false;
int cw, ch;
GetClientSize( &cw, &ch );
- if ( m_cornerLabelWin->IsShown() )
+ if ( m_cornerLabelWin && m_cornerLabelWin->IsShown() )
m_cornerLabelWin->SetSize( 0, 0, m_rowLabelWidth, m_colLabelHeight );
- if ( m_colLabelWin->IsShown() )
+ if ( m_colLabelWin && m_colLabelWin->IsShown() )
m_colLabelWin->SetSize( m_rowLabelWidth, 0, cw-m_rowLabelWidth, m_colLabelHeight);
- if ( m_rowLabelWin->IsShown() )
+ if ( m_rowLabelWin && m_rowLabelWin->IsShown() )
m_rowLabelWin->SetSize( 0, m_colLabelHeight, m_rowLabelWidth, ch-m_colLabelHeight);
- if ( m_gridWin->IsShown() )
+ if ( m_gridWin && m_gridWin->IsShown() )
m_gridWin->SetSize( m_rowLabelWidth, m_colLabelHeight, cw-m_rowLabelWidth, ch-m_colLabelHeight);
}
XYToCell( x, y, coords );
int cell_rows, cell_cols;
+ bool isFirstDrag = !m_isDragging;
GetCellSize( coords.GetRow(), coords.GetCol(), &cell_rows, &cell_cols );
if ((cell_rows < 0) || (cell_cols < 0))
{
m_selectingKeyboard = coords;
HighlightBlock ( m_selectingKeyboard, coords );
}
+ else if ( CanDragCell() )
+ {
+ if ( isFirstDrag )
+ {
+ if ( m_selectingKeyboard == wxGridNoCellCoords)
+ m_selectingKeyboard = coords;
+
+ SendEvent( wxEVT_GRID_CELL_BEGIN_DRAG,
+ coords.GetRow(),
+ coords.GetCol(),
+ event );
+ }
+ }
else
{
if ( !IsSelection() )
m_defaultCellAttr->SetFont(font);
}
+
+// For editors and renderers the type registry takes precedence over the
+// default attr, so we need to register the new editor/renderer for the string
+// data type in order to make setting a default editor/renderer appear to
+// work correctly.
+
void wxGrid::SetDefaultRenderer(wxGridCellRenderer *renderer)
{
- m_defaultCellAttr->SetRenderer(renderer);
+ RegisterDataType(wxGRID_VALUE_STRING,
+ renderer,
+ GetDefaultEditorForType(wxGRID_VALUE_STRING));
}
void wxGrid::SetDefaultEditor(wxGridCellEditor *editor)
{
- m_defaultCellAttr->SetEditor(editor);
+ RegisterDataType(wxGRID_VALUE_STRING,
+ GetDefaultRendererForType(wxGRID_VALUE_STRING),
+ editor);
}
// ----------------------------------------------------------------------------
wxGridCellAttr *wxGrid::GetOrCreateCellAttr(int row, int col) const
{
wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
+ bool canHave = ((wxGrid*)this)->CanHaveAttributes();
- wxCHECK_MSG( m_table, attr,
- _T("we may only be called if CanHaveAttributes() returned true and then m_table should be !NULL") );
+ wxCHECK_MSG( canHave, attr, _T("Cell attributes not allowed"));
+ wxCHECK_MSG( m_table, attr, _T("must have a table") );
attr = m_table->GetAttr(row, col, wxGridCellAttr::Cell);
if ( !attr )
m_canDragGridSize = enable;
}
+void wxGrid::EnableDragCell( bool enable )
+{
+ m_canDragCell = enable;
+}
void wxGrid::SetDefaultRowSize( int height, bool resizeExistingRows )
{
width = self->SetOrCalcColumnSizes(true);
height = self->SetOrCalcRowSizes(true);
+ if (!width) width=100;
+ if (!height) height=80;
+
+ // Round up to a multiple the scroll rate NOTE: this still doesn't get rid
+ // of the scrollbars, is there any magic incantaion for that?
+ int xpu, ypu;
+ GetScrollPixelsPerUnit(&xpu, &ypu);
+ if (xpu)
+ width += 1 + xpu - (width % xpu);
+ if (ypu)
+ height += 1 + ypu - (height % ypu);
+
+ // limit to 1/4 of the screen size
int maxwidth, maxheight;
wxDisplaySize( & maxwidth, & maxheight );
-
+ maxwidth /= 2;
+ maxheight /= 2;
if ( width > maxwidth ) width = maxwidth;
if ( height > maxheight ) height = maxheight;
- return wxSize( width, height );
+
+ wxSize best(width, height);
+ // NOTE: This size should be cached, but first we need to add calls to
+ // InvalidateBestSize everywhere that could change the results of this
+ // calculation.
+ // CacheBestSize(size);
+ return best;
}
void wxGrid::Fit()