From 9379c0d752144826342fa2688a77aa5cccea3d9b Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 29 Oct 2006 19:17:00 +0000 Subject: [PATCH] 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 --- docs/latex/wx/tlw.tex | 23 +++++++++ docs/latex/wx/window.tex | 45 ++---------------- include/wx/gtk/toplevel.h | 4 ++ include/wx/toplevel.h | 4 ++ include/wx/window.h | 39 +++++++++------- src/common/toplvcmn.cpp | 17 +++++++ src/common/wincmn.cpp | 17 ------- src/gtk/frame.cpp | 13 ------ src/gtk/toplevel.cpp | 98 ++++++++++++++++++++++----------------- 9 files changed, 129 insertions(+), 131 deletions(-) diff --git a/docs/latex/wx/tlw.tex b/docs/latex/wx/tlw.tex index f0134fd902..75320a9040 100644 --- a/docs/latex/wx/tlw.tex +++ b/docs/latex/wx/tlw.tex @@ -280,6 +280,29 @@ Unavailable on full keyboard machines. \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} \func{void}{SetRightMenu}{\param{int}{ id = wxID\_ANY}, \param{const wxString\&}{ label = wxEmptyString}, \param{wxMenu *}{ subMenu = NULL}} diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index 2ea573f0a9..fc2585ede5 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -767,8 +767,7 @@ Merges the window's best size into the min size and returns the result. \wxheading{See also} \helpref{wxWindow::GetBestSize}{wxwindowgetbestsize},\rtfsp -\helpref{wxWindow::SetBestFittingSize}{wxwindowsetbestfittingsize},\rtfsp -\helpref{wxWindow::SetSizeHints}{wxwindowsetsizehints} +\helpref{wxWindow::SetBestFittingSize}{wxwindowsetbestfittingsize} \membersection{wxWindow::GetBestSize}\label{wxwindowgetbestsize} @@ -2675,8 +2674,7 @@ needs of the window for layout. \helpref{wxWindow::SetSize}{wxwindowsetsize},\rtfsp \helpref{wxWindow::GetBestSize}{wxwindowgetbestsize},\rtfsp -\helpref{wxWindow::GetBestFittingSize}{wxwindowgetbestfittingsize},\rtfsp -\helpref{wxWindow::SetSizeHints}{wxwindowsetsizehints} +\helpref{wxWindow::GetBestFittingSize}{wxwindowgetbestfittingsize} \membersection{wxWindow::SetCaret}\label{wxwindowsetcaret} @@ -3292,42 +3290,9 @@ implements the following methods:\par \membersection{wxWindow::SetSizeHints}\label{wxwindowsetsizehints} -\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. - -\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. +This method does nothing for a normal wxWindow and is only kept +for backwards compatibility. The actual implementation is in +\helpref{wxTopLevelWindow::SetSizeHints}{wxtoplevelwindowsetsizehints}. \membersection{wxWindow::SetSizer}\label{wxwindowsetsizer} diff --git a/include/wx/gtk/toplevel.h b/include/wx/gtk/toplevel.h index cd48f4f7e1..9886b2a8b1 100644 --- a/include/wx/gtk/toplevel.h +++ b/include/wx/gtk/toplevel.h @@ -121,6 +121,10 @@ protected: int width, int height, 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 DoGetClientSize( int *width, int *height ) const; diff --git a/include/wx/toplevel.h b/include/wx/toplevel.h index 737019df45..bde3440ec7 100644 --- a/include/wx/toplevel.h +++ b/include/wx/toplevel.h @@ -250,6 +250,10 @@ public: virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ; 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 // toolbar which may shift the origin of the client area virtual void DoClientToScreen(int *x, int *y) const; diff --git a/include/wx/window.h b/include/wx/window.h index 38c73a5c10..58d24c8201 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -389,26 +389,26 @@ public: // set virtual size to satisfy children 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, int maxW = wxDefaultCoord, int maxH = 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, const wxSize& maxSize=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, - int maxW = wxDefaultCoord, int maxH = wxDefaultCoord, - int incW = wxDefaultCoord, int incH = wxDefaultCoord ); + virtual void DoSetSizeHints( int minW, int minH, + int maxW = wxDefaultCoord, int maxH = 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, int maxW = wxDefaultCoord, int maxH = wxDefaultCoord ); @@ -418,17 +418,20 @@ public: 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. virtual wxSize GetMaxSize() const { return wxSize( m_maxWidth, m_maxHeight ); } virtual wxSize GetMinSize() const { return wxSize( m_minWidth, m_minHeight ); } - void SetMinSize(const wxSize& minSize) { SetSizeHints(minSize); } - void SetMaxSize(const wxSize& maxSize) { SetSizeHints(GetMinSize(), maxSize); } + // If a class doesn't override GetMinSize() or GetMaxSize() + // 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 // windows this is just the client area of the window, but for diff --git a/src/common/toplvcmn.cpp b/src/common/toplvcmn.cpp index aa07d2f096..88350bebcf 100644 --- a/src/common/toplvcmn.cpp +++ b/src/common/toplvcmn.cpp @@ -140,6 +140,23 @@ bool wxTopLevelWindowBase::IsLastBeforeExit() const // 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) { GetPosition(x,y); diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 44b93da89d..421497abad 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -615,23 +615,6 @@ wxPoint wxWindowBase::GetClientAreaOrigin() const 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 ) { if ( m_windowVariant != variant ) diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index 5c01cae6db..08a0d0e713 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -352,19 +352,6 @@ void wxFrame::GtkOnSize() 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 // Rewrite this terrible code to using GtkVBox diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index d243ce4b58..85f4b536dd 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -958,6 +958,59 @@ void wxTopLevelWindowGTK::DoSetClientSize( int width, int height ) 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() { // avoid recursions @@ -995,49 +1048,8 @@ void wxTopLevelWindowGTK::GtkOnSize() if (m_mainWidget) { - // 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 ); - - /* 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. */ - + // m_mainWidget holds the menubar, the toolbar and the client area, + // which is represented by m_wxwindow. int client_x = m_miniEdge; int client_y = m_miniEdge + m_miniTitle; int client_w = m_width - 2*m_miniEdge;