From d6c11fa975af689cc570ee6f1cfc5322fa7fd564 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Tue, 6 Feb 2007 04:59:29 +0000 Subject: [PATCH] simplify wxGTK DoSetSizeHints logic, respect size increments git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44376 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/tlw.tex | 8 +++--- src/gtk/toplevel.cpp | 66 +++++++++++++++---------------------------- 3 files changed, 28 insertions(+), 47 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 153d114869..ff0c93d733 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -30,6 +30,7 @@ All: wxGTK: - Implemented support for underlined fonts in wxStaticText +- wxTopLevelWindow::SetSizeHints size increments now work wxMSW: diff --git a/docs/latex/wx/tlw.tex b/docs/latex/wx/tlw.tex index a62ba361a4..5c949d8c1b 100644 --- a/docs/latex/wx/tlw.tex +++ b/docs/latex/wx/tlw.tex @@ -305,16 +305,16 @@ A simpler interface for setting the size hints than 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{incW}{Specifies the increment for sizing the width (GTK/Motif/Xt only).} -\docparam{incH}{Specifies the increment for sizing the height (Motif/Xt only).} +\docparam{incH}{Specifies the increment for sizing the height (GTK/Motif/Xt only).} -\docparam{incSize}{Increment size (Motif/Xt only).} +\docparam{incSize}{Increment size (GTK/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. +the given bounds. The resizing increments are only significant under GTK, Motif or Xt. \membersection{wxTopLevelWindow::SetRightMenu}\label{wxtoplevelwindowsetrightmenu} diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index fc5605303f..cb8a7b56ac 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -960,51 +960,31 @@ void wxTopLevelWindowGTK::DoSetSizeHints( int minW, int minH, int incW, int incH ) { wxTopLevelWindowBase::DoSetSizeHints( minW, minH, maxW, maxH, incW, incH ); - - if (m_widget) + + const wxSize minSize = GetMinSize(); + const wxSize maxSize = GetMaxSize(); + GdkGeometry hints; + int hints_mask = 0; + if (minSize.x > 0 || minSize.y > 0) { - 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 ); + hints_mask |= GDK_HINT_MIN_SIZE; + hints.min_width = minSize.x > 0 ? minSize.x : 0; + hints.min_height = minSize.y > 0 ? minSize.y : 0; } + if (maxSize.x > 0 || maxSize.y > 0) + { + hints_mask |= GDK_HINT_MAX_SIZE; + hints.max_width = maxSize.x > 0 ? maxSize.x : INT_MAX; + hints.max_height = maxSize.y > 0 ? maxSize.y : INT_MAX; + } + if (incW > 0 || incH > 0) + { + hints_mask |= GDK_HINT_RESIZE_INC; + hints.width_inc = incW > 0 ? incW : 1; + hints.height_inc = incH > 0 ? incH : 1; + } + gtk_window_set_geometry_hints( + (GtkWindow*)m_widget, NULL, &hints, (GdkWindowHints)hints_mask); }