Fix generic wxSearchCtrl size/layout code.
Override DoGetBestClientSize() instead of DoGetBestSize(), as we're really computing just the size of our contents and like this we don't need to hard code platform-dependent border sizes in this control itself. Also use the client size in LayoutControls() for the same reason. This also makes it unnecessary to pass it the width and height as it can find them on its own. And x and y were never used in the first place, so remove them too. Finally, center the bitmaps vertically. Closes #16422. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77083 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -207,9 +207,8 @@ protected:
|
||||
virtual bool DoSaveFile(const wxString& file, int fileType) wxOVERRIDE;
|
||||
|
||||
// override the base class virtuals involved into geometry calculations
|
||||
virtual wxSize DoGetBestSize() const wxOVERRIDE;
|
||||
virtual wxSize DoGetBestClientSize() const wxOVERRIDE;
|
||||
virtual void DoMoveWindow(int x, int y, int width, int height) wxOVERRIDE;
|
||||
virtual void LayoutControls(int x, int y, int width, int height);
|
||||
|
||||
virtual void RecalcBitmaps();
|
||||
|
||||
@@ -238,6 +237,9 @@ private:
|
||||
// Implement pure virtual function inherited from wxCompositeWindow.
|
||||
virtual wxWindowList GetCompositeWindowParts() const wxOVERRIDE;
|
||||
|
||||
// Position the child controls using the current window size.
|
||||
void LayoutControls();
|
||||
|
||||
#if wxUSE_MENUS
|
||||
void PopupSearchMenu();
|
||||
#endif // wxUSE_MENUS
|
||||
|
@@ -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
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -381,8 +370,7 @@ void wxSearchCtrl::SetMenu( wxMenu* menu )
|
||||
m_searchButton->Refresh();
|
||||
}
|
||||
}
|
||||
wxRect rect = GetRect();
|
||||
LayoutControls(0, 0, rect.GetWidth(), rect.GetHeight());
|
||||
LayoutControls();
|
||||
}
|
||||
|
||||
wxMenu* wxSearchCtrl::GetMenu()
|
||||
@@ -405,8 +393,7 @@ void wxSearchCtrl::ShowSearchButton( bool show )
|
||||
RecalcBitmaps();
|
||||
}
|
||||
|
||||
wxRect rect = GetRect();
|
||||
LayoutControls(0, 0, rect.GetWidth(), rect.GetHeight());
|
||||
LayoutControls();
|
||||
}
|
||||
|
||||
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());
|
||||
LayoutControls();
|
||||
}
|
||||
|
||||
bool wxSearchCtrl::IsCancelButtonVisible() const
|
||||
@@ -447,7 +433,7 @@ wxString wxSearchCtrl::GetDescriptiveText() const
|
||||
// geometry
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxSize wxSearchCtrl::DoGetBestSize() const
|
||||
wxSize wxSearchCtrl::DoGetBestClientSize() const
|
||||
{
|
||||
wxSize sizeText = m_text->GetBestSize();
|
||||
wxSize sizeSearch(0,0);
|
||||
@@ -470,30 +456,30 @@ 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);
|
||||
}
|
||||
|
||||
void wxSearchCtrl::DoMoveWindow(int x, int y, int width, int height)
|
||||
{
|
||||
wxSearchCtrlBase::DoMoveWindow(x, y, width, height);
|
||||
|
||||
LayoutControls(0, 0, width, height);
|
||||
LayoutControls();
|
||||
}
|
||||
|
||||
void wxSearchCtrl::LayoutControls(int x, int y, int width, int height)
|
||||
void wxSearchCtrl::LayoutControls()
|
||||
{
|
||||
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 +510,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 +1120,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 +1167,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 +1190,7 @@ void wxSearchCtrl::OnSetFocus( wxFocusEvent& /*event*/ )
|
||||
|
||||
void wxSearchCtrl::OnSize( wxSizeEvent& WXUNUSED(event) )
|
||||
{
|
||||
int width, height;
|
||||
GetSize(&width, &height);
|
||||
LayoutControls(0, 0, width, height);
|
||||
LayoutControls();
|
||||
}
|
||||
|
||||
#if wxUSE_MENUS
|
||||
|
Reference in New Issue
Block a user