From 1bd71df911439267fb2a006db571af3d45cdc4e5 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Mon, 16 Dec 2002 12:34:06 +0000 Subject: [PATCH] Fixed missing checkbox alignment git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18262 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/generic/grid.h | 6 ++++ src/generic/grid.cpp | 58 +++++++++++++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 495a95b853..7c6c222099 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -21,6 +21,7 @@ All: Stieber) - Improved contrib/utils/convertrc parsing (David J. Cooke) - Fixed handling of URLs and filenames in wxFileSystem +- Implemented alignment for wxGrid bool editor and renderer OLD CHANGES =========== diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 8ece9e5136..164353ff47 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -302,6 +302,9 @@ public: wxControl* GetControl() { return m_control; } void SetControl(wxControl* control) { m_control = control; } + wxGridCellAttr* GetCellAttr() { return m_attr; } + void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; } + // Creates the actual edit control virtual void Create(wxWindow* parent, wxWindowID id, @@ -368,6 +371,9 @@ protected: // the control we show on screen wxControl* m_control; + // a temporary pointer to the attribute being edited + wxGridCellAttr* m_attr; + // if we change the colours/font of the control from the default ones, we // must restore the default later and we save them here between calls to // Show(TRUE) and Show(FALSE) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 405f72dc0d..a286e3706e 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -424,6 +424,7 @@ static inline int GetScrollY(int y) wxGridCellEditor::wxGridCellEditor() { m_control = NULL; + m_attr = NULL; } @@ -1216,7 +1217,32 @@ void wxGridCellBoolEditor::SetSize(const wxRect& r) size.y -= 2; #endif - m_control->Move(r.x + r.width/2 - size.x/2, r.y + r.height/2 - size.y/2); + int hAlign = wxALIGN_CENTRE; + int vAlign = wxALIGN_CENTRE; + if (GetCellAttr()) + GetCellAttr()->GetAlignment(& hAlign, & vAlign); + + int x = 0, y = 0; + if (hAlign == wxALIGN_LEFT) + { + x = r.x + 2; +#ifdef __WXMSW__ + x += 2; +#endif + y = r.y + r.height/2 - size.y/2; + } + else if (hAlign == wxALIGN_RIGHT) + { + x = r.x + r.width - size.x - 2; + y = r.y + r.height/2 - size.y/2; + } + else if (hAlign == wxALIGN_CENTRE) + { + x = r.x + r.width/2 - size.x/2; + y = r.y + r.height/2 - size.y/2; + } + + m_control->Move(x, y); } void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr) @@ -1950,11 +1976,31 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, } // draw a border around checkmark + int vAlign, hAlign; + attr.GetAlignment(& hAlign, &vAlign); + wxRect rectBorder; - rectBorder.x = rect.x + rect.width/2 - size.x/2; - rectBorder.y = rect.y + rect.height/2 - size.y/2; - rectBorder.width = size.x; - rectBorder.height = size.y; + if (hAlign == wxALIGN_CENTRE) + { + rectBorder.x = rect.x + rect.width/2 - size.x/2; + rectBorder.y = rect.y + rect.height/2 - size.y/2; + rectBorder.width = size.x; + rectBorder.height = size.y; + } + else if (hAlign == wxALIGN_LEFT) + { + rectBorder.x = rect.x + 2; + rectBorder.y = rect.y + rect.height/2 - size.y/2; + rectBorder.width = size.x; + rectBorder.height = size.y; + } + else if (hAlign == wxALIGN_RIGHT) + { + rectBorder.x = rect.x + rect.width - size.x - 2; + rectBorder.y = rect.y + rect.height/2 - size.y/2; + rectBorder.width = size.x; + rectBorder.height = size.y; + } bool value; if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) @@ -7388,6 +7434,7 @@ void wxGrid::ShowCellEditControl() rect.SetRight(client_right-1); } + editor->SetCellAttr(attr); editor->SetSize( rect ); editor->Show( TRUE, attr ); @@ -7396,6 +7443,7 @@ void wxGrid::ShowCellEditControl() CalcDimensions(); editor->BeginEdit(row, col, this); + editor->SetCellAttr(NULL); editor->DecRef(); attr->DecRef(); -- 2.45.2