From 2f82899bba49ec8c6683aeffccaba030ad95da6d Mon Sep 17 00:00:00 2001
From: Julian Smart <julian@anthemion.co.uk>
Date: Fri, 25 Aug 2000 15:51:23 +0000
Subject: [PATCH] Fixed sample; enhanced wxLayoutAlgorithm to give remaining
 space to last window

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8185 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/layalgor.tex  |  5 ++++-
 samples/dialogs/dialogs.cpp |  2 +-
 src/generic/laywin.cpp      | 30 +++++++++++++++++++++++++++++-
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/docs/latex/wx/layalgor.tex b/docs/latex/wx/layalgor.tex
index e4d58e3264..76a36feb10 100644
--- a/docs/latex/wx/layalgor.tex
+++ b/docs/latex/wx/layalgor.tex
@@ -141,5 +141,8 @@ The MDI client window is set to occupy the remaining space.
 
 Lays out the children of a normal frame or other window.
 
-{\it mainWindow} is set to occupy the remaining space.
+{\it mainWindow} is set to occupy the remaining space. If this is not specified, then
+the last window that responds to a calculate layout event in query mode will get the remaining space
+(that is, a non-query OnCalculateLayout event will not be sent to this window and the window will be set
+to the remaining size).
 
diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp
index 8617990daa..a33bc636d3 100644
--- a/samples/dialogs/dialogs.cpp
+++ b/samples/dialogs/dialogs.cpp
@@ -473,7 +473,7 @@ void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::ModelessDlg(wxCommandEvent& event)
 {
-    bool show = GetMenuBar()->IsChecked(event.GetInt());
+    bool show = GetMenuBar()->IsChecked(event.GetId());
 
     if ( show )
     {
diff --git a/src/generic/laywin.cpp b/src/generic/laywin.cpp
index 409814e682..9234449935 100644
--- a/src/generic/laywin.cpp
+++ b/src/generic/laywin.cpp
@@ -249,12 +249,35 @@ bool wxLayoutAlgorithm::LayoutWindow(wxWindow* parent, wxWindow* mainWindow)
     wxCalculateLayoutEvent event;
     event.SetRect(rect);
 
+    // Find the last layout-aware window, so we can make it fill all remaining
+    // space.
+    wxWindow* lastAwareWindow = NULL;
     wxNode* node = parent->GetChildren().First();
     while (node)
     {
         wxWindow* win = (wxWindow*) node->Data();
 
-        if (win != mainWindow)
+        if (win->IsShown())
+        {
+            wxCalculateLayoutEvent tempEvent(win->GetId());
+            tempEvent.SetEventObject(win);
+            tempEvent.SetFlags(wxLAYOUT_QUERY);
+            tempEvent.SetRect(event.GetRect());
+            if (win->GetEventHandler()->ProcessEvent(tempEvent))
+                lastAwareWindow = win;
+        }
+
+        node = node->Next();
+    }
+
+    node = parent->GetChildren().First();
+    while (node)
+    {
+        wxWindow* win = (wxWindow*) node->Data();
+
+        // If mainWindow is NULL and we're at the last window,
+        // skip this, because we'll simply make it fit the remaining space.
+        if ((win != mainWindow) && (mainWindow != NULL || win != lastAwareWindow))
         {
             event.SetId(win->GetId());
             event.SetEventObject(win);
@@ -270,6 +293,11 @@ bool wxLayoutAlgorithm::LayoutWindow(wxWindow* parent, wxWindow* mainWindow)
 
     if (mainWindow)
         mainWindow->SetSize(rect.x, rect.y, rect.width, rect.height);
+    else if (lastAwareWindow)
+    {
+        // Fit the remaining space
+        lastAwareWindow->SetSize(rect.x, rect.y, rect.width, rect.height);
+    }
 
     return TRUE;
 }
-- 
2.50.0

