diff --git a/docs/changes.txt b/docs/changes.txt index 412b909d03..cd3c7fa1a7 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -597,6 +597,7 @@ All (GUI): wxGTK: - Fix mouse handling in wxNotebook containing wxListCtrl (Charlie Fenton). +- Fix layout of wxSearchCtrl to not truncate text in it. wxMSW: diff --git a/include/wx/generic/srchctlg.h b/include/wx/generic/srchctlg.h index c61ddee751..4eaa8e1ca4 100644 --- a/include/wx/generic/srchctlg.h +++ b/include/wx/generic/srchctlg.h @@ -238,6 +238,9 @@ private: // Implement pure virtual function inherited from wxCompositeWindow. virtual wxWindowList GetCompositeWindowParts() const; + // Position the child controls using the current window size. + void DoLayoutControls(); + #if wxUSE_MENUS void PopupSearchMenu(); #endif // wxUSE_MENUS diff --git a/src/generic/srchctlg.cpp b/src/generic/srchctlg.cpp index ccf7ccbcfc..758a195cc9 100644 --- a/src/generic/srchctlg.cpp +++ b/src/generic/srchctlg.cpp @@ -38,17 +38,6 @@ // the margin between the text control and the search/cancel buttons static const wxCoord MARGIN = 2; -// border around all controls to compensate for wxSIMPLE_BORDER -#if defined(__WXMSW__) -static const wxCoord BORDER = 0; -static const wxCoord ICON_MARGIN = 2; -static const wxCoord ICON_OFFSET = 2; -#else -static const wxCoord BORDER = 2; -static const wxCoord ICON_MARGIN = 0; -static const wxCoord ICON_OFFSET = 0; -#endif - #define LIGHT_STEP 160 // ---------------------------------------------------------------------------- @@ -127,7 +116,7 @@ protected: // // This is a bit ugly and it would arguably be better to use whatever size // the base class version returns and just centre the text vertically in - // the search control but I failed to modify the code in LayoutControls() + // the search control but I failed to modify the code in DoLayoutControls() // to do this easily and as there is much in that code I don't understand // (notably what is the logic for buttons sizing?) I prefer to not touch it // at all. @@ -381,8 +370,7 @@ void wxSearchCtrl::SetMenu( wxMenu* menu ) m_searchButton->Refresh(); } } - wxRect rect = GetRect(); - LayoutControls(0, 0, rect.GetWidth(), rect.GetHeight()); + DoLayoutControls(); } wxMenu* wxSearchCtrl::GetMenu() @@ -405,8 +393,7 @@ void wxSearchCtrl::ShowSearchButton( bool show ) RecalcBitmaps(); } - wxRect rect = GetRect(); - LayoutControls(0, 0, rect.GetWidth(), rect.GetHeight()); + DoLayoutControls(); } bool wxSearchCtrl::IsSearchButtonVisible() const @@ -424,8 +411,7 @@ void wxSearchCtrl::ShowCancelButton( bool show ) } m_cancelButtonVisible = show; - wxRect rect = GetRect(); - LayoutControls(0, 0, rect.GetWidth(), rect.GetHeight()); + DoLayoutControls(); } bool wxSearchCtrl::IsCancelButtonVisible() const @@ -470,30 +456,36 @@ wxSize wxSearchCtrl::DoGetBestSize() const // buttons are square and equal to the height of the text control int height = sizeText.y; return wxSize(sizeSearch.x + searchMargin + sizeText.x + cancelMargin + sizeCancel.x + 2*horizontalBorder, - height + 2*BORDER); + height) + DoGetBorderSize(); } void wxSearchCtrl::DoMoveWindow(int x, int y, int width, int height) { wxSearchCtrlBase::DoMoveWindow(x, y, width, height); - LayoutControls(0, 0, width, height); + DoLayoutControls(); } -void wxSearchCtrl::LayoutControls(int x, int y, int width, int height) +void wxSearchCtrl::LayoutControls(int WXUNUSED(x), int WXUNUSED(y), + int WXUNUSED(width), int WXUNUSED(height)) +{ + DoLayoutControls(); +} + +void wxSearchCtrl::DoLayoutControls() { if ( !m_text ) return; + const wxSize sizeTotal = GetClientSize(); + int width = sizeTotal.x, + height = sizeTotal.y; + wxSize sizeText = m_text->GetBestSize(); // make room for the search menu & clear button - int horizontalBorder = ( sizeText.y - sizeText.y * 14 / 21 ) / 2; - x += horizontalBorder; - y += BORDER; + int horizontalBorder = 1 + ( sizeText.y - sizeText.y * 14 / 21 ) / 2; + int x = horizontalBorder; width -= horizontalBorder*2; - height -= BORDER*2; - if (width < 0) width = 0; - if (height < 0) height = 0; wxSize sizeSearch(0,0); wxSize sizeCancel(0,0); @@ -524,13 +516,17 @@ void wxSearchCtrl::LayoutControls(int x, int y, int width, int height) // position the subcontrols inside the client area - m_searchButton->SetSize(x, y + ICON_OFFSET - 1, sizeSearch.x, height); - m_text->SetSize( x + sizeSearch.x + searchMargin, - y + ICON_OFFSET - BORDER, - textWidth, - height); - m_cancelButton->SetSize(x + sizeSearch.x + searchMargin + textWidth + cancelMargin, - y + ICON_OFFSET - 1, sizeCancel.x, height); + m_searchButton->SetSize(x, (height - sizeSearch.y) / 2, + sizeSearch.x, height); + x += sizeSearch.x; + x += searchMargin; + + m_text->SetSize(x, 0, textWidth, height); + x += textWidth; + x += cancelMargin; + + m_cancelButton->SetSize(x, (height - sizeCancel.y) / 2, + sizeCancel.x, height); } wxWindowList wxSearchCtrl::GetCompositeWindowParts() const @@ -1130,7 +1126,7 @@ void wxSearchCtrl::RecalcBitmaps() } wxSize sizeText = m_text->GetBestSize(); - int bitmapHeight = sizeText.y - 2 * ICON_MARGIN; + int bitmapHeight = sizeText.y - 4; int bitmapWidth = sizeText.y * 20 / 14; if ( !m_searchBitmapUser ) @@ -1177,7 +1173,7 @@ void wxSearchCtrl::RecalcBitmaps() m_cancelBitmap.GetWidth() != bitmapHeight ) { - m_cancelBitmap = RenderCancelBitmap(bitmapHeight-BORDER-1,bitmapHeight-BORDER-1); // square + m_cancelBitmap = RenderCancelBitmap(bitmapHeight,bitmapHeight); // square m_cancelButton->SetBitmapLabel(m_cancelBitmap); } // else this bitmap was set by user, don't alter @@ -1200,9 +1196,7 @@ void wxSearchCtrl::OnSetFocus( wxFocusEvent& /*event*/ ) void wxSearchCtrl::OnSize( wxSizeEvent& WXUNUSED(event) ) { - int width, height; - GetSize(&width, &height); - LayoutControls(0, 0, width, height); + DoLayoutControls(); } #if wxUSE_MENUS