-//-----------------------------------------------------------------------------
-// wxDataViewTextCtrlWrapper: wraps a wxTextCtrl for inline editing
-//-----------------------------------------------------------------------------
-
-BEGIN_EVENT_TABLE(wxDataViewTextCtrlWrapper, wxEvtHandler)
- EVT_CHAR (wxDataViewTextCtrlWrapper::OnChar)
- EVT_KEY_UP (wxDataViewTextCtrlWrapper::OnKeyUp)
- EVT_KILL_FOCUS (wxDataViewTextCtrlWrapper::OnKillFocus)
-END_EVENT_TABLE()
-
-wxDataViewTextCtrlWrapper::wxDataViewTextCtrlWrapper(
- wxDataViewMainWindow *owner,
- wxTextCtrl *text,
- wxDataViewListModel *model,
- unsigned int col, unsigned int row,
- wxRect rectLabel )
-{
- m_owner = owner;
- m_model = model;
- m_row = row;
- m_col = col;
- m_text = text;
-
- m_finished = false;
- m_aboutToFinish = false;
-
- wxVariant value;
- model->GetValue( value, col, row );
- m_startValue = value.GetString();
-
- m_owner->GetOwner()->CalcScrolledPosition(
- rectLabel.x, rectLabel.y, &rectLabel.x, &rectLabel.y );
-
- m_text->Create( owner, wxID_ANY, m_startValue,
- wxPoint(rectLabel.x-2,rectLabel.y-2),
- wxSize(rectLabel.width+7,rectLabel.height+4) );
- m_text->SetFocus();
-
- m_text->PushEventHandler(this);
-}
-
-void wxDataViewTextCtrlWrapper::AcceptChangesAndFinish()
-{
- m_aboutToFinish = true;
-
- // Notify the owner about the changes
- AcceptChanges();
-
- // Even if vetoed, close the control (consistent with MSW)
- Finish();
-}
-
-void wxDataViewTextCtrlWrapper::OnChar( wxKeyEvent &event )
-{
- switch ( event.m_keyCode )
- {
- case WXK_RETURN:
- AcceptChangesAndFinish();
- break;
-
- case WXK_ESCAPE:
- // m_owner->OnRenameCancelled( m_itemEdited );
- Finish();
- break;
-
- default:
- event.Skip();
- }
-}
-
-void wxDataViewTextCtrlWrapper::OnKeyUp( wxKeyEvent &event )
-{
- if (m_finished)
- {
- event.Skip();
- return;
- }
-
- // auto-grow the textctrl
- wxSize parentSize = m_owner->GetSize();
- wxPoint myPos = m_text->GetPosition();
- wxSize mySize = m_text->GetSize();
- int sx, sy;
- m_text->GetTextExtent(m_text->GetValue() + _T("MM"), &sx, &sy);
- if (myPos.x + sx > parentSize.x)
- sx = parentSize.x - myPos.x;
- if (mySize.x > sx)
- sx = mySize.x;
- m_text->SetSize(sx, wxDefaultCoord);
-
- event.Skip();
-}
-
-void wxDataViewTextCtrlWrapper::OnKillFocus( wxFocusEvent &event )
-{
- if ( !m_finished && !m_aboutToFinish )
- {
- AcceptChanges();
- //if ( !AcceptChanges() )
- // m_owner->OnRenameCancelled( m_itemEdited );
-
- Finish();
- }
-
- // We must let the native text control handle focus
- event.Skip();
-}
-
-bool wxDataViewTextCtrlWrapper::AcceptChanges()
-{
- const wxString value = m_text->GetValue();
-
- if ( value == m_startValue )
- // nothing changed, always accept
- return true;
-
-// if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
- // vetoed by the user
-// return false;
-
- // accepted, do rename the item
- wxVariant variant;
- variant = value;
- m_model->SetValue( variant, m_col, m_row );
- m_model->ValueChanged( m_col, m_row );
-
- return true;
-}
-
-void wxDataViewTextCtrlWrapper::Finish()
-{
- if ( !m_finished )
- {
- m_finished = true;
-
- m_text->RemoveEventHandler(this);
- m_owner->FinishEditing(m_text);
-
- // delete later
- wxPendingDelete.Append( this );
- }
-}
-