X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a68962fc90d4abe5025a465b464599e2b471d97c..5c8ac0b6ca243b5bcc6c5e98b229c66abe932884:/src/generic/datavgen.cpp diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 1233de7dc4..07585c579f 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -33,6 +33,7 @@ #include "wx/timer.h" #include "wx/settings.h" #include "wx/msgdlg.h" + #include "wx/dcscreen.h" #endif #include "wx/stockitem.h" @@ -63,14 +64,16 @@ static const int PADDING_TOPBOTTOM = 1; #define USE_NATIVE_HEADER_WINDOW 1 -class wxDataViewHeaderWindowBase : public wxControl +// NB: for some reason, this class must be dllexport'ed or we get warnings from +// MSVC in DLL build +class WXDLLIMPEXP_ADV wxDataViewHeaderWindowBase : public wxControl { public: wxDataViewHeaderWindowBase() { m_owner = NULL; } bool Create(wxDataViewCtrl *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size, + const wxPoint &pos, const wxSize &size, const wxString &name) { return wxWindow::Create(parent, id, pos, size, wxNO_BORDER, name); @@ -86,10 +89,10 @@ public: virtual wxDataViewColumn *GetColumn(unsigned int n) { wxASSERT(m_owner); - wxDataViewColumn *ret = m_owner->GetColumn(n); + wxDataViewColumn *ret = m_owner->GetColumn(n); wxASSERT(ret); - return ret; + return ret; } protected: @@ -114,12 +117,12 @@ public: const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, const wxString &name = wxT("wxdataviewctrlheaderwindow") ) - { + { Create(parent, id, pos, size, name); } bool Create(wxDataViewCtrl *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size, + const wxPoint &pos, const wxSize &size, const wxString &name); ~wxDataViewHeaderWindowMSW(); @@ -159,13 +162,13 @@ public: const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, const wxString &name = wxT("wxdataviewctrlheaderwindow") ) - { + { Init(); Create(parent, id, pos, size, name); } bool Create(wxDataViewCtrl *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size, + const wxPoint &pos, const wxSize &size, const wxString &name); ~wxGenericDataViewHeaderWindow() @@ -173,6 +176,8 @@ public: delete m_resizeCursor; } + virtual void UpdateDisplay() { Refresh(); } + // event handlers: void OnPaint( wxPaintEvent &event ); @@ -191,7 +196,7 @@ protected: bool m_dirty; // needs refresh? int m_column; // index of the column being resized int m_currentX; // divider line position in logical (unscrolled) coords - int m_minX; // minimal position beyond which the divider line + int m_minX; // minimal position beyond which the divider line // can't be dragged in logical coords // the pen used to draw the current column width drag line @@ -241,50 +246,11 @@ public: void Notify(); }; -//----------------------------------------------------------------------------- -// wxDataViewTextCtrlWrapper: wraps a wxTextCtrl for inline editing -//----------------------------------------------------------------------------- - -class wxDataViewTextCtrlWrapper : public wxEvtHandler -{ -public: - // NB: text must be a valid object but not Create()d yet - wxDataViewTextCtrlWrapper( wxDataViewMainWindow *owner, - wxTextCtrl *text, - wxDataViewListModel *model, - unsigned int col, unsigned int row, - wxRect cellLabel ); - - wxTextCtrl *GetText() const { return m_text; } - - void AcceptChangesAndFinish(); - -protected: - void OnChar( wxKeyEvent &event ); - void OnKeyUp( wxKeyEvent &event ); - void OnKillFocus( wxFocusEvent &event ); - - bool AcceptChanges(); - void Finish(); - -private: - wxDataViewMainWindow *m_owner; - wxTextCtrl *m_text; - wxString m_startValue; - wxDataViewListModel *m_model; - unsigned int m_col; - unsigned int m_row; - bool m_finished; - bool m_aboutToFinish; - - DECLARE_EVENT_TABLE() -}; - //----------------------------------------------------------------------------- // wxDataViewMainWindow //----------------------------------------------------------------------------- -WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection, +WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection, WXDLLIMPEXP_ADV); class wxDataViewMainWindow: public wxWindow @@ -323,14 +289,13 @@ public: void OnInternalIdle(); void OnRenameTimer(); - void FinishEditing( wxTextCtrl *text ); void ScrollWindow( int dx, int dy, const wxRect *rect = NULL ); bool HasCurrentRow() { return m_currentRow != (unsigned int)-1; } void ChangeCurrentRow( unsigned int row ); - bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE); }; + bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE); } bool IsEmpty() { return GetRowCount() == 0; } int GetCountPerPage() const; @@ -365,11 +330,10 @@ private: bool m_dirty; wxDataViewColumn *m_currentCol; - unsigned int m_currentRow; + unsigned int m_currentRow; wxDataViewSelection m_selection; wxDataViewRenameTimer *m_renameTimer; - wxDataViewTextCtrlWrapper *m_textctrlWrapper; bool m_lastOnSame; bool m_hasFocus; @@ -426,7 +390,7 @@ public: IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase) -wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, +wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode, int align) : wxDataViewRendererBase( varianttype, mode, align ) @@ -456,7 +420,6 @@ wxDC *wxDataViewRenderer::GetDC() return m_dc; } - // --------------------------------------------------------- // wxDataViewCustomRenderer // --------------------------------------------------------- @@ -475,7 +438,7 @@ wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewCustomRenderer) -wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, +wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, wxDataViewCellMode mode, int align ) : wxDataViewCustomRenderer( varianttype, mode, align ) { @@ -493,6 +456,26 @@ bool wxDataViewTextRenderer::GetValue( wxVariant& WXUNUSED(value) ) const return false; } +bool wxDataViewTextRenderer::HasEditorCtrl() +{ + return true; +} + +wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent, + wxRect labelRect, const wxVariant &value ) +{ + return new wxTextCtrl( parent, wxID_ANY, value, + wxPoint(labelRect.x,labelRect.y), + wxSize(labelRect.width,labelRect.height) ); +} + +bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant &value ) +{ + wxTextCtrl *text = (wxTextCtrl*) editor; + value = text->GetValue(); + return true; +} + bool wxDataViewTextRenderer::Render( wxRect cell, wxDC *dc, int state ) { wxDataViewCtrl *view = GetOwner()->GetOwner(); @@ -524,7 +507,7 @@ wxSize wxDataViewTextRenderer::GetSize() const IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewCustomRenderer) -wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, +wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, wxDataViewCellMode mode, int align ) : wxDataViewCustomRenderer( varianttype, mode, align ) { @@ -615,8 +598,8 @@ bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state return true; } -bool wxDataViewToggleRenderer::Activate( wxRect WXUNUSED(cell), - wxDataViewListModel *model, +bool wxDataViewToggleRenderer::Activate( wxRect WXUNUSED(cell), + wxDataViewListModel *model, unsigned int col, unsigned int row ) { bool value = !m_toggle; @@ -781,7 +764,7 @@ wxSize wxDataViewDateRenderer::GetSize() const return wxSize(x,y+d); } -bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewListModel *model, +bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewListModel *model, unsigned int col, unsigned int row ) { wxVariant variant; @@ -807,7 +790,7 @@ bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewListMode IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn, wxDataViewColumnBase) -wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell, +wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags ) : wxDataViewColumnBase( title, cell, model_column, width, align, flags ) @@ -819,7 +802,7 @@ wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *c Init(width < 0 ? wxDVC_DEFAULT_WIDTH : width); } -wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell, +wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags ) : wxDataViewColumnBase( bitmap, cell, model_column, width, align, flags ) @@ -838,6 +821,7 @@ void wxDataViewColumn::Init( int width ) { m_width = width; m_minWidth = wxDVC_DEFAULT_MINWIDTH; + m_ascending = true; } void wxDataViewColumn::SetResizeable( bool resizeable ) @@ -866,17 +850,24 @@ void wxDataViewColumn::SetSortable( bool sortable ) m_flags |= wxDATAVIEW_COL_SORTABLE; else m_flags &= ~wxDATAVIEW_COL_SORTABLE; + + // Update header button + if (GetOwner()) + GetOwner()->OnColumnChange(); } -void wxDataViewColumn::SetSortOrder( bool WXUNUSED(ascending) ) +void wxDataViewColumn::SetSortOrder( bool ascending ) { - // TODO + m_ascending = ascending; + + // Update header button + if (GetOwner()) + GetOwner()->OnColumnChange(); } bool wxDataViewColumn::IsSortOrderAscending() const { - // TODO - return true; + return m_ascending; } void wxDataViewColumn::SetInternalWidth( int width ) @@ -924,7 +915,7 @@ int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick); IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindowMSW, wxWindow) bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size, + const wxPoint &pos, const wxSize &size, const wxString &name ) { m_owner = parent; @@ -940,16 +931,16 @@ bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, // create the native WC_HEADER window: WXHWND hwndParent = (HWND)parent->GetHandle(); WXDWORD msStyle = WS_CHILD | HDS_BUTTONS | HDS_HORZ | HDS_HOTTRACK | HDS_FULLDRAG; - m_hWnd = CreateWindowEx(0, - WC_HEADER, - (LPCTSTR) NULL, + m_hWnd = CreateWindowEx(0, + WC_HEADER, + (LPCTSTR) NULL, msStyle, x, y, w, h, - (HWND)hwndParent, - (HMENU)-1, - wxGetInstance(), + (HWND)hwndParent, + (HMENU)-1, + wxGetInstance(), (LPVOID) NULL); - if (m_hWnd == NULL) + if (m_hWnd == NULL) { wxLogLastError(_T("CreateWindowEx")); return false; @@ -959,7 +950,7 @@ bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, // to call wxDataViewHeaderWindow::MSWOnNotify SubclassWin(m_hWnd); - // the following is required to get the default win's font for + // the following is required to get the default win's font for // header windows and must be done befor sending the HDM_LAYOUT msg SetFont(GetFont()); @@ -967,24 +958,24 @@ bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, HDLAYOUT hdl; WINDOWPOS wp; - // Retrieve the bounding rectangle of the parent window's - // client area, and then request size and position values - // from the header control. - ::GetClientRect((HWND)hwndParent, &rcParent); - - hdl.prc = &rcParent; - hdl.pwpos = ℘ - if (!SendMessage((HWND)m_hWnd, HDM_LAYOUT, 0, (LPARAM) &hdl)) + // Retrieve the bounding rectangle of the parent window's + // client area, and then request size and position values + // from the header control. + ::GetClientRect((HWND)hwndParent, &rcParent); + + hdl.prc = &rcParent; + hdl.pwpos = ℘ + if (!SendMessage((HWND)m_hWnd, HDM_LAYOUT, 0, (LPARAM) &hdl)) { wxLogLastError(_T("SendMessage")); return false; } - - // Set the size, position, and visibility of the header control. - SetWindowPos((HWND)m_hWnd, - wp.hwndInsertAfter, - wp.x, wp.y, - wp.cx, wp.cy, + + // Set the size, position, and visibility of the header control. + SetWindowPos((HWND)m_hWnd, + wp.hwndInsertAfter, + wp.x, wp.y, + wp.cx, wp.cy, wp.flags | SWP_SHOWWINDOW); // set our size hints: wxDataViewCtrl will put this wxWindow inside @@ -1006,7 +997,7 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay() // remove old columns for (int j=0, max=Header_GetItemCount((HWND)m_hWnd); j < max; j++) Header_DeleteItem((HWND)m_hWnd, 0); - + // add the updated array of columns to the header control unsigned int cols = GetOwner()->GetColumnCount(); unsigned int added = 0; @@ -1018,7 +1009,7 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay() HDITEM hdi; hdi.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH; - hdi.pszText = (wxChar *) col->GetTitle().c_str(); + hdi.pszText = (wxChar *) col->GetTitle().wx_str(); hdi.cxy = col->GetWidth(); hdi.cchTextMax = sizeof(hdi.pszText)/sizeof(hdi.pszText[0]); hdi.fmt = HDF_LEFT | HDF_STRING; @@ -1029,7 +1020,7 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay() hdi.lParam = (LPARAM)i; // the native wxMSW implementation of the header window - // draws the column separator COLUMN_WIDTH_OFFSET pixels + // draws the column separator COLUMN_WIDTH_OFFSET pixels // on the right: to correct this effect we make the column // exactly COLUMN_WIDTH_OFFSET wider (for the first column): if (i == 0) @@ -1052,9 +1043,9 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay() // such alignment is not allowed for the column header! wxFAIL; } - - SendMessage((HWND)m_hWnd, HDM_INSERTITEM, - (WPARAM)added, (LPARAM)&hdi); + + SendMessage((HWND)m_hWnd, HDM_INSERTITEM, + (WPARAM)added, (LPARAM)&hdi); added++; } } @@ -1106,13 +1097,13 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA break; case HDN_ITEMCHANGING: - if (nmHDR->pitem != NULL && + if (nmHDR->pitem != NULL && (nmHDR->pitem->mask & HDI_WIDTH) != 0) { int minWidth = GetColumnFromHeader(nmHDR)->GetMinWidth(); if (nmHDR->pitem->cxy < minWidth) { - // do not allow the user to resize this column under + // do not allow the user to resize this column under // its minimal width: *result = TRUE; } @@ -1124,7 +1115,7 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA case HDN_ENDDRAG: // user has finished reordering a column // update the width of the modified column: - if (nmHDR->pitem != NULL && + if (nmHDR->pitem != NULL && (nmHDR->pitem->mask & HDI_WIDTH) != 0) { unsigned int idx = GetColumnIdxFromHeader(nmHDR); @@ -1143,7 +1134,7 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA case HDN_ITEMCLICK: { unsigned int idx = GetColumnIdxFromHeader(nmHDR); - wxEventType evt = nmHDR->iButton == 0 ? + wxEventType evt = nmHDR->iButton == 0 ? wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK : wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK; SendEvent(evt, idx); @@ -1187,7 +1178,7 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA ZeroMemory(&hd, sizeof(hd)); hd.mask = HDI_WIDTH; hd.cxy = w; - Header_SetItem(GetHwnd(), + Header_SetItem(GetHwnd(), nmHDR->iItem, // NOTE: we don't want 'idx' here! &hd); @@ -1203,7 +1194,7 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA return true; } -void wxDataViewHeaderWindowMSW::ScrollWindow(int WXUNUSED(dx), int WXUNUSED(dy), +void wxDataViewHeaderWindowMSW::ScrollWindow(int WXUNUSED(dx), int WXUNUSED(dy), const wxRect *WXUNUSED(rect)) { wxSize ourSz = GetClientSize(); @@ -1213,14 +1204,14 @@ void wxDataViewHeaderWindowMSW::ScrollWindow(int WXUNUSED(dx), int WXUNUSED(dy), int x1 = 0, y1 = 0; m_owner->CalcUnscrolledPosition(0, 0, &x1, &y1); - // put this window on top of our parent and - SetWindowPos((HWND)m_hWnd, HWND_TOP, -x1, 0, - ownerSz.GetWidth() + x1, ourSz.GetHeight(), + // put this window on top of our parent and + SetWindowPos((HWND)m_hWnd, HWND_TOP, -x1, 0, + ownerSz.GetWidth() + x1, ourSz.GetHeight(), SWP_SHOWWINDOW); } -void wxDataViewHeaderWindowMSW::DoSetSize(int WXUNUSED(x), int WXUNUSED(y), - int WXUNUSED(w), int WXUNUSED(h), +void wxDataViewHeaderWindowMSW::DoSetSize(int WXUNUSED(x), int WXUNUSED(y), + int WXUNUSED(w), int WXUNUSED(h), int WXUNUSED(f)) { // the wxDataViewCtrl's internal wxBoxSizer will call this function when @@ -1241,8 +1232,8 @@ BEGIN_EVENT_TABLE(wxGenericDataViewHeaderWindow, wxWindow) END_EVENT_TABLE() bool wxGenericDataViewHeaderWindow::Create(wxDataViewCtrl *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size, - const wxString &name ) + const wxPoint &pos, const wxSize &size, + const wxString &name ) { m_owner = parent; @@ -1298,13 +1289,23 @@ void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) int cw = col->GetWidth(); int ch = h; + wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE; + if (col->IsSortable()) + { + if (col->IsSortOrderAscending()) + sortArrow = wxHDR_SORT_ICON_UP; + else + sortArrow = wxHDR_SORT_ICON_DOWN; + } + wxRendererNative::Get().DrawHeaderButton ( this, dc, wxRect(xpos, 0, cw, ch-1), m_parent->IsEnabled() ? 0 - : (int)wxCONTROL_DISABLED + : (int)wxCONTROL_DISABLED, + sortArrow ); // align as required the column title: @@ -1327,7 +1328,7 @@ void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) // always center the title vertically: int y = wxMax((ch - titleSz.GetHeight()) / 2, HEADER_VERT_BORDER); - dc.SetClippingRegion( xpos+HEADER_HORIZ_BORDER, + dc.SetClippingRegion( xpos+HEADER_HORIZ_BORDER, HEADER_VERT_BORDER, wxMax(cw - 2 * HEADER_HORIZ_BORDER, 1), // width wxMax(ch - 2 * HEADER_VERT_BORDER, 1)); // height @@ -1353,7 +1354,7 @@ void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent &event ) if (m_isDragging) { - // we don't draw the line beyond our window, + // we don't draw the line beyond our window, // but we allow dragging it there int w = 0; GetClientSize( &w, NULL ); @@ -1361,13 +1362,13 @@ void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent &event ) w -= 6; // erase the line if it was drawn - if (m_currentX < w) + if (m_currentX < w) DrawCurrent(); - if (event.ButtonUp()) + if (event.ButtonUp()) { m_isDragging = false; - if (HasCapture()) + if (HasCapture()) ReleaseMouse(); m_dirty = true; @@ -1398,22 +1399,22 @@ void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent &event ) // find the column where this event occured int countCol = m_owner->GetColumnCount(); - for (int column = 0; column < countCol; column++) + for (int column = 0; column < countCol; column++) { wxDataViewColumn *p = GetColumn(column); - if (p->IsHidden()) + if (p->IsHidden()) continue; // skip if not shown xpos += p->GetWidth(); m_column = column; - if ((abs(x-xpos) < 3) && (y < 22)) + if ((abs(x-xpos) < 3) && (y < 22)) { hit_border = true; break; } - if (x < xpos) + if (x < xpos) { // inside the column break; @@ -1433,7 +1434,7 @@ void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent &event ) } else if (event.LeftDown() || event.RightUp()) { - if (hit_border && event.LeftDown() && resizeable) + if (hit_border && event.LeftDown() && resizeable) { m_isDragging = true; CaptureMouse(); @@ -1442,7 +1443,7 @@ void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent &event ) } else // click on a column { - wxEventType evt = event.LeftDown() ? + wxEventType evt = event.LeftDown() ? wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK : wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK; SendEvent(evt, m_column); @@ -1450,7 +1451,7 @@ void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent &event ) } else if (event.Moving()) { - if (hit_border && resizeable) + if (hit_border && resizeable) m_currentCursor = m_resizeCursor; else m_currentCursor = wxSTANDARD_CURSOR; @@ -1510,149 +1511,6 @@ void wxDataViewRenameTimer::Notify() m_owner->OnRenameTimer(); } -//----------------------------------------------------------------------------- -// 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 ); - } -} - //----------------------------------------------------------------------------- // wxDataViewMainWindow //----------------------------------------------------------------------------- @@ -1685,14 +1543,13 @@ wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID i m_lastOnSame = false; m_renameTimer = new wxDataViewRenameTimer( this ); - m_textctrlWrapper = NULL; // TODO: user better initial values/nothing selected m_currentCol = NULL; m_currentRow = 0; // TODO: we need to calculate this smartly - m_lineHeight = + m_lineHeight = #ifdef __WXMSW__ 17; #else @@ -1728,7 +1585,6 @@ void wxDataViewMainWindow::OnRenameTimer() if ( m_dirty ) wxSafeYield(); - int xpos = 0; unsigned int cols = GetOwner()->GetColumnCount(); unsigned int i; @@ -1742,47 +1598,43 @@ void wxDataViewMainWindow::OnRenameTimer() break; xpos += c->GetWidth(); } - wxRect labelRect( xpos, m_currentRow * m_lineHeight, + wxRect labelRect( xpos, m_currentRow * m_lineHeight, m_currentCol->GetWidth(), m_lineHeight ); - wxClassInfo *textControlClass = CLASSINFO(wxTextCtrl); + GetOwner()->CalcScrolledPosition( labelRect.x, labelRect.y, + &labelRect.x, &labelRect.y); - wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject(); - m_textctrlWrapper = new wxDataViewTextCtrlWrapper(this, text, GetOwner()->GetModel(), - m_currentCol->GetModelColumn(), m_currentRow, labelRect ); -} - -void wxDataViewMainWindow::FinishEditing( wxTextCtrl *text ) -{ - delete text; - m_textctrlWrapper = NULL; - SetFocus(); - // SetFocusIgnoringChildren(); + m_currentCol->GetRenderer()->StartEditing( m_currentRow, labelRect ); } bool wxDataViewMainWindow::RowAppended() { - return false; + UpdateDisplay(); + return true; } bool wxDataViewMainWindow::RowPrepended() { - return false; + UpdateDisplay(); + return true; } bool wxDataViewMainWindow::RowInserted( unsigned int WXUNUSED(before) ) { - return false; + UpdateDisplay(); + return true; } bool wxDataViewMainWindow::RowDeleted( unsigned int WXUNUSED(row) ) { - return false; + UpdateDisplay(); + return true; } bool wxDataViewMainWindow::RowChanged( unsigned int WXUNUSED(row) ) { - return false; + UpdateDisplay(); + return true; } bool wxDataViewMainWindow::ValueChanged( unsigned int WXUNUSED(col), unsigned int row ) @@ -1799,14 +1651,14 @@ bool wxDataViewMainWindow::ValueChanged( unsigned int WXUNUSED(col), unsigned in bool wxDataViewMainWindow::RowsReordered( unsigned int *WXUNUSED(new_order) ) { - Refresh(); - + UpdateDisplay(); return true; } bool wxDataViewMainWindow::Cleared() { - return false; + UpdateDisplay(); + return true; } void wxDataViewMainWindow::UpdateDisplay() @@ -1867,7 +1719,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) // compute which items needs to be redrawn unsigned int item_start = wxMax( 0, (update.y / m_lineHeight) ); - unsigned int item_count = + unsigned int item_count = wxMin( (int)(((update.y + update.height) / m_lineHeight) - item_start + 1), (int)(model->GetRowCount() - item_start) ); unsigned int item_last = item_start + item_count; @@ -1936,7 +1788,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) } // Draw last vertical rule - dc.DrawLine(x, item_start * m_lineHeight, + dc.DrawLine(x, item_start * m_lineHeight, x, item_last * m_lineHeight); } @@ -2048,7 +1900,7 @@ int wxDataViewMainWindow::GetEndOfLastCol() const unsigned int i; for (i = 0; i < GetOwner()->GetColumnCount(); i++) { - const wxDataViewColumn *c = + const wxDataViewColumn *c = wx_const_cast(wxDataViewCtrl*, GetOwner())->GetColumn( i ); if (!c->IsHidden()) @@ -2069,7 +1921,7 @@ unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const unsigned int wxDataViewMainWindow::GetLastVisibleRow() const { wxSize client_size = GetClientSize(); - m_owner->CalcUnscrolledPosition( client_size.x, client_size.y, + m_owner->CalcUnscrolledPosition( client_size.x, client_size.y, &client_size.x, &client_size.y ); return wxMin( GetRowCount()-1, ((unsigned)client_size.y/m_lineHeight)+1 ); @@ -2452,7 +2304,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) wxVariant value; model->GetValue( value, col->GetModelColumn(), current ); cell->SetValue( value ); - wxRect cell_rect( xpos, current * m_lineHeight, + wxRect cell_rect( xpos, current * m_lineHeight, col->GetWidth(), m_lineHeight ); cell->Activate( cell_rect, model, col->GetModelColumn(), current ); } @@ -2588,7 +2440,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) // Update selection here... m_currentCol = col; - m_lastOnSame = !forceClick && ((col == oldCurrentCol) && + m_lastOnSame = !forceClick && ((col == oldCurrentCol) && (current == oldCurrentRow)) && oldWasSelected; } } @@ -2638,7 +2490,7 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator ) { - if (!wxControl::Create( parent, id, pos, size, + if (!wxControl::Create( parent, id, pos, size, style | wxScrolledWindowStyle|wxSUNKEN_BORDER, validator)) return false;