From: Vadim Zeitlin Date: Wed, 23 Feb 2000 23:38:00 +0000 (+0000) Subject: 1. wxGCBoolRenderer looks better under MSW X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/b94ae1ea10f3794b36e8ad554381124ee9ec296b 1. wxGCBoolRenderer looks better under MSW 2. wxGCBoolEditor too 3. only alnum keys start editing in-place 4. some memory leaks in wxGrid plugged git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6251 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index b398abc2e6..143d6677e2 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -255,7 +255,8 @@ public: // data structures used for the data type registry // ---------------------------------------------------------------------------- -struct wxGridDataTypeInfo { +struct wxGridDataTypeInfo +{ wxGridDataTypeInfo(const wxString& typeName, wxGridCellRenderer* renderer, wxGridCellEditor* editor) @@ -273,9 +274,11 @@ struct wxGridDataTypeInfo { WX_DEFINE_ARRAY(wxGridDataTypeInfo*, wxGridDataTypeInfoArray); -class WXDLLEXPORT wxGridTypeRegistry { +class WXDLLEXPORT wxGridTypeRegistry +{ public: ~wxGridTypeRegistry(); + void RegisterDataType(const wxString& typeName, wxGridCellRenderer* renderer, wxGridCellEditor* editor); @@ -287,9 +290,6 @@ private: wxGridDataTypeInfoArray m_typeinfo; }; - - - // ---------------------------------------------------------------------------- // conditional compilation // ---------------------------------------------------------------------------- @@ -367,6 +367,8 @@ void wxGridCellEditor::Destroy() { if (m_control) { + m_control->PopEventHandler(TRUE /* delete it*/); + m_control->Destroy(); m_control = NULL; } @@ -801,17 +803,46 @@ void wxGridCellBoolEditor::Create(wxWindow* parent, void wxGridCellBoolEditor::SetSize(const wxRect& r) { + bool resize = FALSE; + wxSize size = m_control->GetSize(); + wxCoord minSize = wxMin(r.width, r.height); + + // check if the checkbox is not too big/small for this cell + wxSize sizeBest = m_control->GetBestSize(); + if ( !(size == sizeBest) ) + { + // reset to default size if it had been made smaller + size = sizeBest; + + resize = TRUE; + } + + if ( size.x >= minSize || size.y >= minSize ) + { + // leave 1 pixel margin + size.x = size.y = minSize - 2; + + resize = TRUE; + } + + if ( resize ) + { + m_control->SetSize(size); + } + // position it in the centre of the rectangle (TODO: support alignment?) - int w, h; - m_control->GetSize(&w, &h); +#if defined(__WXGTK__) || defined (__WXMOTIF__) // the checkbox without label still has some space to the right in wxGTK, // so shift it to the right -#if defined(__WXGTK__) || defined (__WXMOTIF__) - w -= 8; -#endif // GTK && Motif + size.x -= 8; +#elif defined(__WXMSW__) + // here too... + size.x -= 6; + size.y -= 2; +#endif - m_control->Move(r.x + r.width/2 - w/2, r.y + r.height/2 - h/2); + m_control->Move(r.x + r.width/2 - size.x/2, r.y + r.height/2 - size.y/2); } void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr) @@ -1225,8 +1256,14 @@ wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid, wxSize wxGridCellBoolRenderer::ms_sizeCheckMark; +// FIXME these checkbox size calculations are really ugly... + // between checkmark and box -static const wxCoord wxGRID_CHECKMARK_MARGIN = 4; +#ifdef __WXGTK__ + static const wxCoord wxGRID_CHECKMARK_MARGIN = 4; +#else + static const wxCoord wxGRID_CHECKMARK_MARGIN = 2; +#endif wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid, wxGridCellAttr& WXUNUSED(attr), @@ -1267,6 +1304,16 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, // draw a check mark in the centre (ignoring alignment - TODO) wxSize size = GetBestSize(grid, attr, dc, row, col); + + // don't draw outside the cell + wxCoord minSize = wxMin(rect.width, rect.height); + if ( size.x >= minSize || size.y >= minSize ) + { + // and even leave (at least) 1 pixel margin + size.x = size.y = minSize - 2; + } + + // draw a border around checkmark wxRect rectMark; rectMark.x = rect.x + rect.width/2 - size.x/2; rectMark.y = rect.y + rect.height/2 - size.y/2; @@ -1279,8 +1326,13 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN); +#ifdef __WXMSW__ + // looks nicer under MSW + rectMark.x++; +#endif // MSW + bool value; - if (grid.GetTable()->CanGetValueAs(row, col, wxT("bool"))) + if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) value = grid.GetTable()->GetValueAsBool(row, col); else value = !!grid.GetTable()->GetValue(row, col); @@ -1702,7 +1754,8 @@ void wxGridCellAttrProvider::UpdateAttrCols( size_t pos, int numCols ) wxGridTypeRegistry::~wxGridTypeRegistry() { - for (size_t i=0; i= 0 ) + { + m_dragRowOrCol = dragCol; + return; } @@ -4675,14 +4732,6 @@ void wxGrid::OnKeyDown( wxKeyEvent& event ) MovePageDown(); break; - // We don't want these keys to trigger the edit control, any others? - case WXK_SHIFT: - case WXK_ALT: - case WXK_CONTROL: - case WXK_CAPITAL: - event.Skip(); - break; - case WXK_SPACE: if ( !IsEditable() ) { @@ -4692,9 +4741,13 @@ void wxGrid::OnKeyDown( wxKeyEvent& event ) // Otherwise fall through to default default: - // now try the cell edit control - // - if ( !IsCellEditControlEnabled() && CanEnableCellControl() ) + // alphanumeric keys enable the cell edit control + if ( !(event.AltDown() || + event.MetaDown() || + event.ControlDown()) && + isalnum(event.KeyCode()) && + !IsCellEditControlEnabled() && + CanEnableCellControl() ) { EnableCellEditControl(); int row = m_currentCellCoords.GetRow(); @@ -4705,7 +4758,8 @@ void wxGrid::OnKeyDown( wxKeyEvent& event ) } else { - // let others process char events for readonly cells + // let others process char events with modifiers or all + // char events for readonly cells event.Skip(); } break; diff --git a/src/msw/checkbox.cpp b/src/msw/checkbox.cpp index 3e8f804185..97b471a1e3 100644 --- a/src/msw/checkbox.cpp +++ b/src/msw/checkbox.cpp @@ -79,9 +79,14 @@ bool wxCheckBox::Create(wxWindow *parent, m_windowStyle = style; + // VZ: disabling this ugliness which completely breaks checkboxes in wxGrid + // whoever did it, please tell me where and how does the checkbox fail + // to appear +#if 0 wxString Label = label; if (Label == wxT("")) Label = wxT(" "); // Apparently needed or checkbox won't show +#endif // 0 if ( id == -1 ) m_windowId = NewControlId(); @@ -111,7 +116,7 @@ bool wxCheckBox::Create(wxWindow *parent, msStyle |= WS_BORDER; */ - m_hWnd = (WXHWND)CreateWindowEx(exStyle, wxT("BUTTON"), Label, + m_hWnd = (WXHWND)CreateWindowEx(exStyle, wxT("BUTTON"), label, msStyle, 0, 0, 0, 0, (HWND)parent->GetHWND(), (HMENU)m_windowId, diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index bb398e715e..a613f5e12e 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -65,6 +65,10 @@ #define TV_FIRST 0x1100 #endif +#ifndef TVS_CHECKBOXES + #define TVS_CHECKBOXES 0x0100 +#endif + // old headers might miss these messages (comctl32.dll 4.71+ only) #ifndef TVM_SETBKCOLOR #define TVM_SETBKCOLOR (TV_FIRST + 29) @@ -346,10 +350,6 @@ bool wxTreeCtrl::Create(wxWindow *parent, !defined( __WATCOMC__ ) && \ (!defined(__VISUALC__) || (__VISUALC__ > 1010)) -#ifndef TVS_CHECKBOXES -#define TVS_CHECKBOXES 0x0100 -#endif - // we emulate the multiple selection tree controls by using checkboxes: set // up the image list we need for this if we do have multiple selections if ( m_windowStyle & wxTR_MULTIPLE ) @@ -1321,6 +1321,24 @@ void wxTreeCtrl::ScrollTo(const wxTreeItemId& item) wxTextCtrl* wxTreeCtrl::GetEditControl() const { + // normally, we could try to do something like this to return something + // even when the editing was started by the user and not by calling + // EditLabel() - but as nobody has asked for this so far and there might be + // problems in the code below, I leave it disabled for now (VZ) +#if 0 + if ( !m_textCtrl ) + { + HWND hwndText = TreeView_GetEditControl(GetHwnd()); + if ( hwndText ) + { + m_textCtrl = new wxTextCtrl(this, -1); + m_textCtrl->Hide(); + m_textCtrl->SetHWND((WXHWND)hwndText); + } + //else: not editing label right now + } +#endif // 0 + return m_textCtrl; } @@ -1340,6 +1358,8 @@ wxTextCtrl* wxTreeCtrl::EditLabel(const wxTreeItemId& item, { wxASSERT( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)) ); + DeleteTextCtrl(); + HWND hWnd = (HWND) TreeView_EditLabel(GetHwnd(), (HTREEITEM) (WXHTREEITEM) item); // this is not an error - the TVN_BEGINLABELEDIT handler might have @@ -1349,8 +1369,6 @@ wxTextCtrl* wxTreeCtrl::EditLabel(const wxTreeItemId& item, return NULL; } - DeleteTextCtrl(); - m_textCtrl = (wxTextCtrl *)textControlClass->CreateObject(); m_textCtrl->SetHWND((WXHWND)hWnd); m_textCtrl->SubclassWin((WXHWND)hWnd); diff --git a/src/msw/window.cpp b/src/msw/window.cpp index edc10844ea..0be7635f72 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -3034,17 +3034,25 @@ bool wxWindow::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) } if ( win ) + { return win->MSWCommand(cmd, id); - else + } + + // the messages sent from the in-place edit control used by the treectrl + // for label editing have id == 0, but they should _not_ be treated as menu + // messages (they are EN_XXX ones, in fact) so don't translate anything + // coming from a control to wxEVT_COMMAND_MENU_SELECTED + if ( !control ) { - // If no child window, it may be an accelerator, e.g. for - // a popup menu command. + // If no child window, it may be an accelerator, e.g. for a popup menu + // command wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED); event.SetEventObject(this); event.SetId(id); event.SetInt(id); - return ProcessEvent(event); + + return GetEventHandler()->ProcessEvent(event); } return FALSE;