Merge branch 'x11-layout-fix'

See https://github.com/wxWidgets/wxWidgets/pull/1638
This commit is contained in:
Vadim Zeitlin
2019-11-08 14:52:56 +01:00
3 changed files with 25 additions and 44 deletions

View File

@@ -101,9 +101,6 @@ protected:
const wxString& label) wxOVERRIDE; const wxString& label) wxOVERRIDE;
virtual wxSize DoGetBestClientSize() const wxOVERRIDE; virtual wxSize DoGetBestClientSize() const wxOVERRIDE;
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO) wxOVERRIDE;
virtual void DoDraw(wxControlRenderer *renderer) wxOVERRIDE; virtual void DoDraw(wxControlRenderer *renderer) wxOVERRIDE;
// get the bounding rect for the given tool // get the bounding rect for the given tool

View File

@@ -563,33 +563,6 @@ wxSize wxToolBar::DoGetBestClientSize() const
return wxSize(m_maxWidth, m_maxHeight); return wxSize(m_maxWidth, m_maxHeight);
} }
void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
int old_width, old_height;
GetSize(&old_width, &old_height);
wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags);
// Correct width and height if needed.
if ( width == wxDefaultCoord || height == wxDefaultCoord )
{
int tmp_width, tmp_height;
GetSize(&tmp_width, &tmp_height);
if ( width == wxDefaultCoord )
width = tmp_width;
if ( height == wxDefaultCoord )
height = tmp_height;
}
// We must refresh the frame size when the toolbar changes size
// otherwise the toolbar can be shown incorrectly
if ( old_width != width || old_height != height )
{
SendSizeEventToParent();
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxToolBar drawing // wxToolBar drawing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -98,6 +98,26 @@ wxEND_EVENT_TABLE()
// helper functions // helper functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
namespace
{
// Passing size with a 0 component to X11 functions results in a BadValue X
// error, so ensure we never do it by using the smallest valid size instead.
inline void EnsureValidXWindowSize(int& x, int& y)
{
if ( x <= 0 )
x = 1;
if ( y <= 0 )
y = 1;
}
inline void EnsureValidXWindowSize(wxSize& size)
{
EnsureValidXWindowSize(size.x, size.y);
}
} // anonymous namespace
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// constructors // constructors
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -155,13 +175,8 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
xparent = (Window) parent->X11GetMainWindow(); xparent = (Window) parent->X11GetMainWindow();
} }
// Size (not including the border) must be nonzero (or a Value error results)!
// Note: The Xlib manual doesn't mention this restriction of XCreateWindow.
wxSize size2(size); wxSize size2(size);
if (size2.x <= 0) EnsureValidXWindowSize(size2);
size2.x = 20;
if (size2.y <= 0)
size2.y = 20;
wxPoint pos2(pos); wxPoint pos2(pos);
if (pos2.x == wxDefaultCoord) if (pos2.x == wxDefaultCoord)
@@ -258,10 +273,7 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
} }
// Make again sure the size is nonzero. // Make again sure the size is nonzero.
if (size2.x <= 0) EnsureValidXWindowSize(size2);
size2.x = 1;
if (size2.y <= 0)
size2.y = 1;
#if wxUSE_NANOX #if wxUSE_NANOX
backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()); backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
@@ -920,16 +932,13 @@ void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (width != wxDefaultCoord) if (width != wxDefaultCoord)
{ {
new_w = width; new_w = width;
if (new_w <= 0)
new_w = 20;
} }
if (height != wxDefaultCoord) if (height != wxDefaultCoord)
{ {
new_h = height; new_h = height;
if (new_h <= 0)
new_h = 20;
} }
EnsureValidXWindowSize(new_w, new_h);
DoMoveWindow( new_x, new_y, new_w, new_h ); DoMoveWindow( new_x, new_y, new_w, new_h );
} }
@@ -941,6 +950,7 @@ void wxWindowX11::DoSetClientSize(int width, int height)
wxCHECK_RET( xwindow, wxT("invalid window") ); wxCHECK_RET( xwindow, wxT("invalid window") );
EnsureValidXWindowSize(width, height);
XResizeWindow( wxGlobalDisplay(), xwindow, width, height ); XResizeWindow( wxGlobalDisplay(), xwindow, width, height );
if (m_mainWindow != m_clientWindow) if (m_mainWindow != m_clientWindow)
@@ -956,6 +966,7 @@ void wxWindowX11::DoSetClientSize(int width, int height)
height -= border.y + border.height; height -= border.y + border.height;
} }
EnsureValidXWindowSize(width, height);
XResizeWindow( wxGlobalDisplay(), xwindow, width, height ); XResizeWindow( wxGlobalDisplay(), xwindow, width, height );
} }
} }