Make wxWindow::SetSizeHints() do nothing.

Make wxTLW::SetSizeHints() set the various m_minWidth etc. fields.
  Override SetSizeHints() in wxGTK to call the relevant gtk funcion
    only there and not in every resize.
  Make GetMinWidth() etc. non-virtual.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42646 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2006-10-29 19:17:00 +00:00
parent 7a9763046b
commit 9379c0d752
9 changed files with 129 additions and 131 deletions

View File

@@ -280,6 +280,29 @@ Unavailable on full keyboard machines.
\helpref{wxTopLevelWindow::SetRightMenu}{wxtoplevelwindowsetrightmenu}. \helpref{wxTopLevelWindow::SetRightMenu}{wxtoplevelwindowsetrightmenu}.
\membersection{wxTopLevelWindow::SetSizeHints}\label{wxtoplevelwindowsetsizehints}
\func{virtual void}{SetSizeHints}{\param{int}{ minW}, \param{int}{ minH}, \param{int}{ maxW=-1}, \param{int}{ maxH=-1},
\param{int}{ incW=-1}, \param{int}{ incH=-1}}
\func{void}{SetSizeHints}{\param{const wxSize\&}{ minSize},
\param{const wxSize\&}{ maxSize=wxDefaultSize}, \param{const wxSize\&}{ incSize=wxDefaultSize}}
Allows specification of minimum and maximum window sizes, and window size increments.
If a pair of values is not set (or set to -1), the default values will be used.
\docparam{incW}{Specifies the increment for sizing the width (Motif/Xt only).}
\docparam{incH}{Specifies the increment for sizing the height (Motif/Xt only).}
\docparam{incSize}{Increment size (Motif/Xt only).}
\wxheading{Remarks}
If this function is called, the user will not be able to size the window outside
the given bounds. The resizing increments are only significant under Motif or Xt.
\membersection{wxTopLevelWindow::SetRightMenu}\label{wxtoplevelwindowsetrightmenu} \membersection{wxTopLevelWindow::SetRightMenu}\label{wxtoplevelwindowsetrightmenu}
\func{void}{SetRightMenu}{\param{int}{ id = wxID\_ANY}, \param{const wxString\&}{ label = wxEmptyString}, \param{wxMenu *}{ subMenu = NULL}} \func{void}{SetRightMenu}{\param{int}{ id = wxID\_ANY}, \param{const wxString\&}{ label = wxEmptyString}, \param{wxMenu *}{ subMenu = NULL}}

View File

@@ -767,8 +767,7 @@ Merges the window's best size into the min size and returns the result.
\wxheading{See also} \wxheading{See also}
\helpref{wxWindow::GetBestSize}{wxwindowgetbestsize},\rtfsp \helpref{wxWindow::GetBestSize}{wxwindowgetbestsize},\rtfsp
\helpref{wxWindow::SetBestFittingSize}{wxwindowsetbestfittingsize},\rtfsp \helpref{wxWindow::SetBestFittingSize}{wxwindowsetbestfittingsize}
\helpref{wxWindow::SetSizeHints}{wxwindowsetsizehints}
\membersection{wxWindow::GetBestSize}\label{wxwindowgetbestsize} \membersection{wxWindow::GetBestSize}\label{wxwindowgetbestsize}
@@ -2675,8 +2674,7 @@ needs of the window for layout.
\helpref{wxWindow::SetSize}{wxwindowsetsize},\rtfsp \helpref{wxWindow::SetSize}{wxwindowsetsize},\rtfsp
\helpref{wxWindow::GetBestSize}{wxwindowgetbestsize},\rtfsp \helpref{wxWindow::GetBestSize}{wxwindowgetbestsize},\rtfsp
\helpref{wxWindow::GetBestFittingSize}{wxwindowgetbestfittingsize},\rtfsp \helpref{wxWindow::GetBestFittingSize}{wxwindowgetbestfittingsize}
\helpref{wxWindow::SetSizeHints}{wxwindowsetsizehints}
\membersection{wxWindow::SetCaret}\label{wxwindowsetcaret} \membersection{wxWindow::SetCaret}\label{wxwindowsetcaret}
@@ -3292,42 +3290,9 @@ implements the following methods:\par
\membersection{wxWindow::SetSizeHints}\label{wxwindowsetsizehints} \membersection{wxWindow::SetSizeHints}\label{wxwindowsetsizehints}
\func{virtual void}{SetSizeHints}{\param{int}{ minW}, \param{int}{ minH}, \param{int}{ maxW=-1}, \param{int}{ maxH=-1}, This method does nothing for a normal wxWindow and is only kept
\param{int}{ incW=-1}, \param{int}{ incH=-1}} for backwards compatibility. The actual implementation is in
\helpref{wxTopLevelWindow::SetSizeHints}{wxtoplevelwindowsetsizehints}.
\func{void}{SetSizeHints}{\param{const wxSize\&}{ minSize},
\param{const wxSize\&}{ maxSize=wxDefaultSize}, \param{const wxSize\&}{ incSize=wxDefaultSize}}
Allows specification of minimum and maximum window sizes, and window size increments.
If a pair of values is not set (or set to -1), the default values will be used.
\wxheading{Parameters}
\docparam{minW}{Specifies the minimum width allowable.}
\docparam{minH}{Specifies the minimum height allowable.}
\docparam{maxW}{Specifies the maximum width allowable.}
\docparam{maxH}{Specifies the maximum height allowable.}
\docparam{incW}{Specifies the increment for sizing the width (Motif/Xt only).}
\docparam{incH}{Specifies the increment for sizing the height (Motif/Xt only).}
\docparam{minSize}{Minimum size.}
\docparam{maxSize}{Maximum size.}
\docparam{incSize}{Increment size (Motif/Xt only).}
\wxheading{Remarks}
If this function is called, the user will not be able to size the window outside the
given bounds.
The resizing increments are only significant under Motif or Xt.
\membersection{wxWindow::SetSizer}\label{wxwindowsetsizer} \membersection{wxWindow::SetSizer}\label{wxwindowsetsizer}

View File

@@ -121,6 +121,10 @@ protected:
int width, int height, int width, int height,
int sizeFlags = wxSIZE_AUTO); int sizeFlags = wxSIZE_AUTO);
virtual void DoSetSizeHints( int minW, int minH,
int maxW = wxDefaultCoord, int maxH = wxDefaultCoord,
int incW = wxDefaultCoord, int incH = wxDefaultCoord );
virtual void DoSetClientSize(int width, int height); virtual void DoSetClientSize(int width, int height);
virtual void DoGetClientSize( int *width, int *height ) const; virtual void DoGetClientSize( int *width, int *height ) const;

View File

@@ -250,6 +250,10 @@ public:
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ; virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
protected: protected:
virtual void DoSetSizeHints( int minW, int minH,
int maxW = wxDefaultCoord, int maxH = wxDefaultCoord,
int incW = wxDefaultCoord, int incH = wxDefaultCoord );
// the frame client to screen translation should take account of the // the frame client to screen translation should take account of the
// toolbar which may shift the origin of the client area // toolbar which may shift the origin of the client area
virtual void DoClientToScreen(int *x, int *y) const; virtual void DoClientToScreen(int *x, int *y) const;

View File

@@ -389,26 +389,26 @@ public:
// set virtual size to satisfy children // set virtual size to satisfy children
virtual void FitInside(); virtual void FitInside();
// set min/max size of the window
// Methods for setting size hints. This is only used
// for toplevel windows.
virtual void SetSizeHints( int minW, int minH, virtual void SetSizeHints( int minW, int minH,
int maxW = wxDefaultCoord, int maxH = wxDefaultCoord, int maxW = wxDefaultCoord, int maxH = wxDefaultCoord,
int incW = wxDefaultCoord, int incH = wxDefaultCoord ) int incW = wxDefaultCoord, int incH = wxDefaultCoord )
{ { DoSetSizeHints(minW, minH, maxW, maxH, incW, incH); }
DoSetSizeHints(minW, minH, maxW, maxH, incW, incH);
}
void SetSizeHints( const wxSize& minSize, void SetSizeHints( const wxSize& minSize,
const wxSize& maxSize=wxDefaultSize, const wxSize& maxSize=wxDefaultSize,
const wxSize& incSize=wxDefaultSize) const wxSize& incSize=wxDefaultSize)
{ { DoSetSizeHints(minSize.x, minSize.y, maxSize.x, maxSize.y, incSize.x, incSize.y); }
DoSetSizeHints(minSize.x, minSize.y,
maxSize.x, maxSize.y,
incSize.x, incSize.y);
}
virtual void DoSetSizeHints(int minW, int minH, virtual void DoSetSizeHints( int minW, int minH,
int maxW = wxDefaultCoord, int maxH = wxDefaultCoord, int maxW = wxDefaultCoord, int maxH = wxDefaultCoord,
int incW = wxDefaultCoord, int incH = wxDefaultCoord ); int incW = wxDefaultCoord, int incH = wxDefaultCoord ) { }
// Methods for setting virtual size hints
// FIXME: What are virtual size hints?
virtual void SetVirtualSizeHints( int minW, int minH, virtual void SetVirtualSizeHints( int minW, int minH,
int maxW = wxDefaultCoord, int maxH = wxDefaultCoord ); int maxW = wxDefaultCoord, int maxH = wxDefaultCoord );
@@ -418,17 +418,20 @@ public:
SetVirtualSizeHints(minSize.x, minSize.y, maxSize.x, maxSize.y); SetVirtualSizeHints(minSize.x, minSize.y, maxSize.x, maxSize.y);
} }
virtual int GetMinWidth() const { return m_minWidth; }
virtual int GetMinHeight() const { return m_minHeight; }
int GetMaxWidth() const { return m_maxWidth; }
int GetMaxHeight() const { return m_maxHeight; }
// Override this method to control the values given to Sizers etc. // Override this method to control the values given to Sizers etc.
virtual wxSize GetMaxSize() const { return wxSize( m_maxWidth, m_maxHeight ); } virtual wxSize GetMaxSize() const { return wxSize( m_maxWidth, m_maxHeight ); }
virtual wxSize GetMinSize() const { return wxSize( m_minWidth, m_minHeight ); } virtual wxSize GetMinSize() const { return wxSize( m_minWidth, m_minHeight ); }
void SetMinSize(const wxSize& minSize) { SetSizeHints(minSize); } // If a class doesn't override GetMinSize() or GetMaxSize()
void SetMaxSize(const wxSize& maxSize) { SetSizeHints(GetMinSize(), maxSize); } // these values will be returned
int GetMinWidth() const { return m_minWidth; }
int GetMinHeight() const { return m_minHeight; }
int GetMaxWidth() const { return m_maxWidth; }
int GetMaxHeight() const { return m_maxHeight; }
void SetMinSize(const wxSize& minSize) { m_minWidth = minSize.x; m_minHeight = minSize.y; }
void SetMaxSize(const wxSize& maxSize) { m_maxWidth = maxSize.x; m_maxHeight = maxSize.y; }
// Methods for accessing the virtual size of a window. For most // Methods for accessing the virtual size of a window. For most
// windows this is just the client area of the window, but for // windows this is just the client area of the window, but for

View File

@@ -140,6 +140,23 @@ bool wxTopLevelWindowBase::IsLastBeforeExit() const
// wxTopLevelWindow geometry // wxTopLevelWindow geometry
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// set the min/max size of the window
void wxTopLevelWindowBase::DoSetSizeHints(int minW, int minH,
int maxW, int maxH,
int WXUNUSED(incW), int WXUNUSED(incH))
{
// setting min width greater than max width leads to infinite loops under
// X11 and generally doesn't make any sense, so don't allow it
wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) &&
(minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH),
_T("min width/height must be less than max width/height!") );
m_minWidth = minW;
m_maxWidth = maxW;
m_minHeight = minH;
m_maxHeight = maxH;
}
void wxTopLevelWindowBase::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h) void wxTopLevelWindowBase::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h)
{ {
GetPosition(x,y); GetPosition(x,y);

View File

@@ -615,23 +615,6 @@ wxPoint wxWindowBase::GetClientAreaOrigin() const
return wxPoint(0,0); return wxPoint(0,0);
} }
// set the min/max size of the window
void wxWindowBase::DoSetSizeHints(int minW, int minH,
int maxW, int maxH,
int WXUNUSED(incW), int WXUNUSED(incH))
{
// setting min width greater than max width leads to infinite loops under
// X11 and generally doesn't make any sense, so don't allow it
wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) &&
(minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH),
_T("min width/height must be less than max width/height!") );
m_minWidth = minW;
m_maxWidth = maxW;
m_minHeight = minH;
m_maxHeight = maxH;
}
void wxWindowBase::SetWindowVariant( wxWindowVariant variant ) void wxWindowBase::SetWindowVariant( wxWindowVariant variant )
{ {
if ( m_windowVariant != variant ) if ( m_windowVariant != variant )

View File

@@ -352,19 +352,6 @@ void wxFrame::GtkOnSize()
if (m_mainWidget) if (m_mainWidget)
{ {
// set size hints
gint flag = 0; // GDK_HINT_POS;
if ((minWidth != -1) || (minHeight != -1)) flag |= GDK_HINT_MIN_SIZE;
if ((maxWidth != -1) || (maxHeight != -1)) flag |= GDK_HINT_MAX_SIZE;
GdkGeometry geom;
geom.min_width = minWidth;
geom.min_height = minHeight;
geom.max_width = maxWidth;
geom.max_height = maxHeight;
gtk_window_set_geometry_hints( GTK_WINDOW(m_widget),
(GtkWidget*) NULL,
&geom,
(GdkWindowHints) flag );
// TODO // TODO
// Rewrite this terrible code to using GtkVBox // Rewrite this terrible code to using GtkVBox

View File

@@ -958,6 +958,59 @@ void wxTopLevelWindowGTK::DoSetClientSize( int width, int height )
width + m_miniEdge*2, height + m_miniEdge*2 + m_miniTitle, 0); width + m_miniEdge*2, height + m_miniEdge*2 + m_miniTitle, 0);
} }
void wxTopLevelWindowGTK::DoSetSizeHints( int minW, int minH,
int maxW, int maxH,
int incW, int incH )
{
wxTopLevelWindowBase::DoSetSizeHints( minW, minH, maxW, maxH, incW, incH );
if (m_widget)
{
int minWidth = GetMinWidth(),
minHeight = GetMinHeight(),
maxWidth = GetMaxWidth(),
maxHeight = GetMaxHeight();
// set size hints
gint flag = 0; // GDK_HINT_POS;
GdkGeometry geom;
if ((minWidth != -1) || (minHeight != -1)) flag |= GDK_HINT_MIN_SIZE;
if ((maxWidth != -1) || (maxHeight != -1)) flag |= GDK_HINT_MAX_SIZE;
geom.min_width = minWidth;
geom.min_height = minHeight;
// Because of the way we set GDK_HINT_MAX_SIZE above, if either of
// maxHeight or maxWidth is set, we must set them both, else the
// remaining -1 will be taken literally.
// I'm certain this also happens elsewhere, and is the probable
// cause of other such things as:
// Gtk-WARNING **: gtk_widget_size_allocate():
// attempt to allocate widget with width 65535 and height 600
// but I don't have time to track them all now..
//
// Really we need to encapulate all this height/width business and
// stop any old method from ripping at the members directly and
// scattering -1's without regard for who might resolve them later.
geom.max_width = ( maxHeight == -1 ) ? maxWidth
: ( maxWidth == -1 ) ? wxGetDisplaySize().GetWidth()
: maxWidth ;
geom.max_height = ( maxWidth == -1 ) ? maxHeight // ( == -1 here )
: ( maxHeight == -1 ) ? wxGetDisplaySize().GetHeight()
: maxHeight ;
gtk_window_set_geometry_hints( GTK_WINDOW(m_widget),
(GtkWidget*) NULL,
&geom,
(GdkWindowHints) flag );
}
}
void wxTopLevelWindowGTK::GtkOnSize() void wxTopLevelWindowGTK::GtkOnSize()
{ {
// avoid recursions // avoid recursions
@@ -995,49 +1048,8 @@ void wxTopLevelWindowGTK::GtkOnSize()
if (m_mainWidget) if (m_mainWidget)
{ {
// set size hints // m_mainWidget holds the menubar, the toolbar and the client area,
gint flag = 0; // GDK_HINT_POS; // which is represented by m_wxwindow.
GdkGeometry geom;
if ((minWidth != -1) || (minHeight != -1)) flag |= GDK_HINT_MIN_SIZE;
if ((maxWidth != -1) || (maxHeight != -1)) flag |= GDK_HINT_MAX_SIZE;
geom.min_width = minWidth;
geom.min_height = minHeight;
// Because of the way we set GDK_HINT_MAX_SIZE above, if either of
// maxHeight or maxWidth is set, we must set them both, else the
// remaining -1 will be taken literally.
// I'm certain this also happens elsewhere, and is the probable
// cause of other such things as:
// Gtk-WARNING **: gtk_widget_size_allocate():
// attempt to allocate widget with width 65535 and height 600
// but I don't have time to track them all now..
//
// Really we need to encapulate all this height/width business and
// stop any old method from ripping at the members directly and
// scattering -1's without regard for who might resolve them later.
geom.max_width = ( maxHeight == -1 ) ? maxWidth
: ( maxWidth == -1 ) ? wxGetDisplaySize().GetWidth()
: maxWidth ;
geom.max_height = ( maxWidth == -1 ) ? maxHeight // ( == -1 here )
: ( maxHeight == -1 ) ? wxGetDisplaySize().GetHeight()
: maxHeight ;
gtk_window_set_geometry_hints( GTK_WINDOW(m_widget),
(GtkWidget*) NULL,
&geom,
(GdkWindowHints) flag );
/* I revert back to wxGTK's original behaviour. m_mainWidget holds the
* menubar, the toolbar and the client area, which is represented by
* m_wxwindow.
* this hurts in the eye, but I don't want to call SetSize()
* because I don't want to call any non-native functions here. */
int client_x = m_miniEdge; int client_x = m_miniEdge;
int client_y = m_miniEdge + m_miniTitle; int client_y = m_miniEdge + m_miniTitle;
int client_w = m_width - 2*m_miniEdge; int client_w = m_width - 2*m_miniEdge;