]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/frame.cpp
1. added range checks in wxGridStringTable
[wxWidgets.git] / src / msw / frame.cpp
index e338b71c0a2b4673c9f176be1fce302e51f9f6cd..08d33b8b77bbe025a0b9cb1828bbb293059320e7 100644 (file)
     #include "wx/dialog.h"
     #include "wx/settings.h"
     #include "wx/dcclient.h"
+    #include "wx/mdi.h"
 #endif // WX_PRECOMP
 
 #include "wx/msw/private.h"
 
 #if wxUSE_STATUSBAR
     #include "wx/statusbr.h"
-
-    #if wxUSE_NATIVE_STATUSBAR
-        #include "wx/msw/statbr95.h"
-    #endif
+    #include "wx/generic/statusbr.h"
 #endif // wxUSE_STATUSBAR
 
 #if wxUSE_TOOLBAR
@@ -62,7 +60,7 @@
 
 extern wxWindowList wxModelessWindows;
 extern wxList WXDLLEXPORT wxPendingDelete;
-extern wxChar *wxFrameClassName;
+extern const wxChar *wxFrameClassName;
 extern wxMenu *wxCurrentPopupMenu;
 
 // ----------------------------------------------------------------------------
@@ -101,6 +99,16 @@ void wxFrame::Init()
 #if wxUSE_TOOLTIPS
     m_hwndToolTip = 0;
 #endif
+
+    // Data to save/restore when calling ShowFullScreen
+    m_fsStyle = 0;
+    m_fsOldWindowStyle = 0;
+    m_fsStatusBarFields = 0;
+    m_fsStatusBarHeight = 0;
+    m_fsToolBarHeight = 0;
+//    m_fsMenu = 0;
+    m_fsIsMaximized = FALSE;
+    m_fsIsShowing = FALSE;
 }
 
 bool wxFrame::Create(wxWindow *parent,
@@ -186,7 +194,7 @@ void wxFrame::DoGetClientSize(int *x, int *y) const
   ::GetClientRect(GetHwnd(), &rect);
 
 #if wxUSE_STATUSBAR
-  if ( GetStatusBar() )
+  if ( GetStatusBar() && GetStatusBar()->IsShown() )
   {
     int statusX, statusY;
     GetStatusBar()->GetClientSize(&statusX, &statusY);
@@ -223,7 +231,7 @@ void wxFrame::DoSetClientSize(int width, int height)
   int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
 
 #if wxUSE_STATUSBAR
-  if ( GetStatusBar() )
+  if ( GetStatusBar() && GetStatusBar()->IsShown())
   {
     int statusX, statusY;
     GetStatusBar()->GetClientSize(&statusX, &statusY);
@@ -354,14 +362,27 @@ wxStatusBar *wxFrame::OnCreateStatusBar(int number,
 #if wxUSE_NATIVE_STATUSBAR
     if ( UsesNativeStatusBar() )
     {
-        statusBar = new wxStatusBar95(this, id, style);
+        statusBar = (wxStatusBar *)new wxStatusBar95(this, id, style);
 
         statusBar->SetFieldsCount(number);
     }
     else
 #endif
     {
-        statusBar = wxFrameBase::OnCreateStatusBar(number, style, id, name);
+        statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style, name);
+
+        // Set the height according to the font and the border size
+        wxClientDC dc(statusBar);
+        dc.SetFont(statusBar->GetFont());
+
+        wxCoord y;
+        dc.GetTextExtent(_T("X"), NULL, &y );
+
+        int height = (int)( (11*y)/10 + 2*statusBar->GetBorderY());
+
+        statusBar->SetSize(-1, -1, -1, height);
+
+        statusBar->SetFieldsCount(number);
     }
 
     return statusBar;
@@ -369,12 +390,22 @@ wxStatusBar *wxFrame::OnCreateStatusBar(int number,
 
 void wxFrame::PositionStatusBar()
 {
-    // native status bar positions itself
-    if ( m_frameStatusBar
+    if ( !m_frameStatusBar )
+        return;
+
+    // native status bar positions itself, but we must forward the WM_SIZE
+    // messages to it
 #if wxUSE_NATIVE_STATUSBAR
-         && !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))
-#endif
-       )
+    wxStatusBar95 *sb = wxDynamicCast(m_frameStatusBar, wxStatusBar95);
+    if ( sb )
+    {
+        wxSizeEvent event(GetSize(), sb->GetId());
+        event.SetEventObject(sb);
+
+        sb->GetEventHandler()->ProcessEvent(event);
+    }
+    else
+#endif // wxUSE_NATIVE_STATUSBAR
     {
         int w, h;
         GetClientSize(&w, &h);
@@ -479,6 +510,123 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
     wxWindow::OnSysColourChanged(event);
 }
 
+// Pass TRUE to show full screen, FALSE to restore.
+bool wxFrame::ShowFullScreen(bool show, long style)
+{
+    if (show)
+    {
+        if (IsFullScreen())
+            return FALSE;
+
+        m_fsIsShowing = TRUE;
+        m_fsStyle = style;
+
+            wxToolBar *theToolBar = GetToolBar();
+            wxStatusBar *theStatusBar = GetStatusBar();
+
+        int dummyWidth;
+
+        if (theToolBar)
+            theToolBar->GetSize(&dummyWidth, &m_fsToolBarHeight);
+        if (theStatusBar)
+            theStatusBar->GetSize(&dummyWidth, &m_fsStatusBarHeight);
+
+        // zap the toolbar, menubar, and statusbar
+
+        if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
+        {
+            theToolBar->SetSize(-1,0);
+            theToolBar->Show(FALSE);
+        }
+
+        if (style & wxFULLSCREEN_NOMENUBAR)
+            SetMenu((HWND)GetHWND(), (HMENU) NULL);
+
+        // Save the number of fields in the statusbar
+        if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
+        {
+            m_fsStatusBarFields = theStatusBar->GetFieldsCount();
+            SetStatusBar((wxStatusBar*) NULL);
+                delete theStatusBar;
+        }
+        else
+            m_fsStatusBarFields = 0;
+
+        // zap the frame borders
+
+        // save the 'normal' window style
+        m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE);
+
+           // save the old position, width & height, maximize state
+        m_fsOldSize = GetRect();
+            m_fsIsMaximized = IsMaximized();
+
+           // decide which window style flags to turn off
+        LONG newStyle = m_fsOldWindowStyle;
+        LONG offFlags = 0;
+
+        if (style & wxFULLSCREEN_NOBORDER)
+            offFlags |= WS_BORDER;
+        if (style & wxFULLSCREEN_NOCAPTION)
+            offFlags |= (WS_CAPTION | WS_SYSMENU);
+
+        newStyle &= (~offFlags);
+
+        // change our window style to be compatible with full-screen mode
+        SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle);
+
+        // resize to the size of the desktop
+        int width, height;
+
+        RECT rect;
+        ::GetWindowRect(GetDesktopWindow(), &rect);
+        width = rect.right - rect.left;
+        height = rect.bottom - rect.top;
+
+        SetSize(width, height);
+
+        // now flush the window style cache and actually go full-screen
+        SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
+
+        wxSizeEvent event(wxSize(width, height), GetId());
+        GetEventHandler()->ProcessEvent(event);
+
+        return TRUE;
+    }
+    else
+    {
+        if (!IsFullScreen())
+            return FALSE;
+
+        m_fsIsShowing = FALSE;
+
+        wxToolBar *theToolBar = GetToolBar();
+
+        // restore the toolbar, menubar, and statusbar
+        if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
+        {
+            theToolBar->SetSize(-1, m_fsToolBarHeight);
+            theToolBar->Show(TRUE);
+        }
+
+        if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_fsStatusBarFields > 0))
+        {
+            CreateStatusBar(m_fsStatusBarFields);
+            PositionStatusBar();
+        }
+
+        if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
+            SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
+
+        Maximize(m_fsIsMaximized);
+        SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle);
+        SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
+            m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
+
+        return TRUE;
+    }
+}
+
 /*
  * Frame window
  *
@@ -518,7 +666,7 @@ bool wxFrame::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow
 
   // Keep this in wxFrame because it saves recoding this function
   // in wxTinyFrame
-#if wxUSE_ITSY_BITSY
+#if wxUSE_ITSY_BITSY && !defined(__WIN32__)
   if (style & wxTINY_CAPTION_VERT)
     msflags |= IBS_VERTCAPTION;
   if (style & wxTINY_CAPTION_HORIZ)
@@ -559,6 +707,15 @@ bool wxFrame::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow
 // subwindow found.
 void wxFrame::OnActivate(wxActivateEvent& event)
 {
+    if ( !event.GetActive() )
+    {
+        event.Skip();
+
+        return;
+    }
+
+    wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd);
+
     for ( wxWindowList::Node *node = GetChildren().GetFirst();
           node;
           node = node->GetNext() )
@@ -579,7 +736,7 @@ void wxFrame::OnActivate(wxActivateEvent& event)
            )
         {
             child->SetFocus();
-            return;
+            break;
         }
     }
 }
@@ -614,7 +771,7 @@ void wxFrame::PositionToolBar()
     }
 #endif // wxUSE_STATUSBAR
 
-    if ( GetToolBar() )
+    if ( GetToolBar() && GetToolBar()->IsShown() )
     {
         int tw, th;
         GetToolBar()->GetSize(&tw, &th);
@@ -649,9 +806,12 @@ void wxFrame::IconizeChildFrames(bool bIconize)
     {
         wxWindow *win = node->GetData();
 
-        if ( win->IsKindOf(CLASSINFO(wxFrame)) )
+        // the child MDI frames are a special case and should not be touched by
+        // the parent frame - instead, they are managed by the user
+        wxFrame *frame = wxDynamicCast(win, wxFrame);
+        if ( frame && !wxDynamicCast(frame, wxMDIChildFrame) )
         {
-            ((wxFrame *)win)->Iconize(bIconize);
+            frame->Iconize(bIconize);
         }
     }
 }
@@ -763,17 +923,6 @@ bool wxFrame::HandleSize(int x, int y, WXUINT id)
 
     if ( !m_iconized )
     {
-        // forward WM_SIZE to status bar control
-#if wxUSE_NATIVE_STATUSBAR
-        if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
-        {
-            wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
-            event.SetEventObject( m_frameStatusBar );
-
-            ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
-        }
-#endif // wxUSE_NATIVE_STATUSBAR
-
         PositionStatusBar();
         PositionToolBar();