Tweaked the layout sample a bit for wxGridBagSizer
[wxWidgets.git] / src / msw / toplevel.cpp
index 961cd90c52989723b0181b633318bb2344bfb7da..d73404fc54ac533931d6361e4d64e456de0691b5 100644 (file)
@@ -17,7 +17,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
     #pragma implementation "toplevel.h"
 #endif
 
@@ -43,7 +43,9 @@
 #include "wx/msw/private.h"
 #include "wx/msw/winundef.h"
 
-#ifdef CreateDialog
+// This can't be undefed in winundef.h or
+// there are further errors
+#if defined(__WXWINCE__) && defined(CreateDialog)
 #undef CreateDialog
 #endif
 
@@ -156,7 +158,12 @@ WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
     if ( style & wxFRAME_TOOL_WINDOW )
         msflags |= WS_POPUP;
     else
-        msflags |= WS_OVERLAPPED;
+    {
+#ifdef __WXWINCE__
+        if (msflags & WS_BORDER)
+#endif
+            msflags |= WS_OVERLAPPED;
+    }
 
     // border and caption styles
     if ( style & wxRESIZE_BORDER )
@@ -165,15 +172,21 @@ WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
         msflags |= WS_THICKFRAME;
 #endif
     }
+    else if ( exflags && ((style & wxBORDER_DOUBLE) || (style & wxBORDER_RAISED)) )
+        *exflags |= WS_EX_DLGMODALFRAME;
     else if ( !(style & wxBORDER_NONE) )
         msflags |= WS_BORDER;
+#ifndef __WXWINCE__
     else
         msflags |= WS_POPUP;
+#endif
 
     if ( style & wxCAPTION )
         msflags |= WS_CAPTION;
+#ifndef __WXWINCE__
     else
         msflags |= WS_POPUP;
+#endif
 
     // next translate the individual flags
     if ( style & wxMINIMIZE_BOX )
@@ -202,13 +215,16 @@ WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
 
     if ( exflags )
     {
-#if !defined(__WIN16__) 
+#if !defined(__WIN16__)
         if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) )
         {
             if ( style & wxFRAME_TOOL_WINDOW )
             {
                 // create the palette-like window
                 *exflags |= WS_EX_TOOLWINDOW;
+
+                // tool windows shouldn't appear on the taskbar (as documented)
+                style |= wxFRAME_NO_TASKBAR;
             }
 
             // We have to solve 2 different problems here:
@@ -336,10 +352,12 @@ bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate,
     if ( exflags )
     {
         ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exflags);
-        ::SetWindowPos(GetHwnd(), NULL, 0, 0, 0, 0,
+        ::SetWindowPos(GetHwnd(),
+                       exflags & WS_EX_TOPMOST ? HWND_TOPMOST : 0,
+                       0, 0, 0, 0,
                        SWP_NOSIZE |
                        SWP_NOMOVE |
-                       SWP_NOZORDER |
+                       (exflags & WS_EX_TOPMOST ? 0 : SWP_NOZORDER) |
                        SWP_NOACTIVATE);
     }
 
@@ -427,7 +445,7 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent,
                                  long style,
                                  const wxString& name)
 {
-    bool ret = false;
+    bool ret wxDUMMY_INITIALIZE(false);
 
     // init our fields
     Init();
@@ -845,17 +863,22 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
 {
     if ( event.GetActive() )
     {
-        // restore focus to the child which was last focused
+        // restore focus to the child which was last focused unless we already
+        // have it
         wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd);
 
-        wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
-                                            : NULL;
-        if ( !parent )
+        wxWindow *winFocus = FindFocus();
+        if ( !winFocus || wxGetTopLevelParent(winFocus) != this )
         {
-            parent = this;
-        }
+            wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
+                                                : NULL;
+            if ( !parent )
+            {
+                parent = this;
+            }
 
-        wxSetFocusToChild(parent, &m_winLastFocused);
+            wxSetFocusToChild(parent, &m_winLastFocused);
+        }
     }
     else // deactivating
     {
@@ -866,23 +889,12 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
         {
             // let it know that it doesn't have focus any more
             m_winLastFocused->HandleKillFocus((WXHWND)NULL);
-        }
 
-        // so we NULL it out if it's a child from some other frame
-        wxWindow *win = m_winLastFocused;
-        while ( win )
-        {
-            if ( win->IsTopLevel() )
+            // and don't remember it if it's a child from some other frame
+            if ( wxGetTopLevelParent(m_winLastFocused) != this )
             {
-                if ( win != this )
-                {
-                    m_winLastFocused = NULL;
-                }
-
-                break;
+                m_winLastFocused = NULL;
             }
-
-            win = win->GetParent();
         }
 
         wxLogTrace(_T("focus"),
@@ -897,7 +909,10 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
 
 // the DialogProc for all wxWindows dialogs
 LONG APIENTRY _EXPORT
-wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+wxDlgProc(HWND WXUNUSED(hDlg),
+          UINT message,
+          WPARAM WXUNUSED(wParam),
+          LPARAM WXUNUSED(lParam))
 {
     switch ( message )
     {