]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/notebook.cpp
fix for crash when using wxEXEC_NODISABLE
[wxWidgets.git] / src / msw / notebook.cpp
index f4614c1267df3133e92cc9bdd35448244deb220e..e73853067695a35904562411e68d26c33f9ae508 100644 (file)
 #include  "wx/control.h"
 #include  "wx/notebook.h"
 #include  "wx/app.h"
+#include  "wx/sysopt.h"
 
 #include  "wx/msw/private.h"
 
-// Windows standard headers
-#ifndef   __WIN95__
-  #error  "wxNotebook is only supported Windows 95 and above"
-#endif    //Win95
-
-#include  <windowsx.h>  // for SetWindowFont
+#include  <windowsx.h>
 
 #ifdef __GNUWIN32_OLD__
     #include "wx/msw/gnuwin32/extra.h"
 #endif
 
-#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
+#if !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
     #include <commctrl.h>
 #endif
 
@@ -257,13 +253,58 @@ bool wxNotebook::Create(wxWindow *parent,
         }
     }
 
+    LPCTSTR className = WC_TABCONTROL;
+
+    // SysTabCtl32 class has natively CS_HREDRAW and CS_VREDRAW enabled and it
+    // causes horrible flicker when resizing notebook, so get rid of it by
+    // using a class without these styles (but otherwise identical to it)
+    if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) )
+    {
+        static ClassRegistrar s_clsNotebook;
+        if ( !s_clsNotebook.IsInitialized() )
+        {
+            // get a copy of standard class and modify it
+            WNDCLASS wc;
+
+            if ( ::GetClassInfo(::GetModuleHandle(NULL), WC_TABCONTROL, &wc) )
+            {
+                wc.lpszClassName = wxT("_wx_SysTabCtl32");
+                wc.style &= ~(CS_HREDRAW | CS_VREDRAW);
+
+                s_clsNotebook.Register(wc);
+            }
+            else
+            {
+                wxLogLastError(_T("GetClassInfoEx(SysTabCtl32)"));
+            }
+        }
+
+        // use our custom class if available but fall back to the standard
+        // notebook if we failed to register it
+        if ( s_clsNotebook.IsRegistered() )
+        {
+            // it's ok to use c_str() here as the static s_clsNotebook object
+            // has sufficiently long lifetime
+            className = s_clsNotebook.GetName().c_str();
+        }
+    }
+
     if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL,
                         wxDefaultValidator, name) )
         return false;
 
-    if ( !MSWCreateControl(WC_TABCONTROL, wxEmptyString, pos, size) )
+    if ( !MSWCreateControl(className, wxEmptyString, pos, size) )
         return false;
 
+    if (HasFlag(wxNB_NOPAGETHEME) || (wxSystemOptions::HasOption(wxT("msw.notebook.themed-background")) &&
+                                      wxSystemOptions::GetOptionInt(wxT("msw.notebook.themed-background")) == 0))
+    {
+        wxColour col = GetThemeBackgroundColour();
+        if (col.Ok())
+        {
+            SetBackgroundColour(col);
+        }
+    }
     return true;
 }
 
@@ -439,7 +480,7 @@ wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
     wxSize sizeTotal = sizePage;
 
     // We need to make getting tab size part of the wxWidgets API.
-    wxSize tabSize(0, 0);
+    wxSize tabSize;
     if (GetPageCount() > 0)
     {
         RECT rect;
@@ -586,7 +627,7 @@ bool wxNotebook::InsertPage(size_t nPage,
     }
 
     // and the text
-    if ( !strText.IsEmpty() )
+    if ( !strText.empty() )
     {
         tcItem.mask |= TCIF_TEXT;
         tcItem.pszText = (wxChar *)strText.c_str(); // const_cast
@@ -650,6 +691,7 @@ bool wxNotebook::InsertPage(size_t nPage,
         SetSelection(selNew);
 
     InvalidateBestSize();
+
     return true;
 }
 
@@ -684,49 +726,68 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
 
 void wxNotebook::OnSize(wxSizeEvent& event)
 {
-  // fit the notebook page to the tab control's display area
-  RECT rc;
-  rc.left = rc.top = 0;
-  GetSize((int *)&rc.right, (int *)&rc.bottom);
-
-  // there seems to be a bug in the implementation of TabCtrl_AdjustRect(): it
-  // returns completely false values for multiline tab controls after the tabs
-  // are added but before getting the first WM_SIZE (off by ~50 pixels, see
-  //
-  // http://sf.net/tracker/index.php?func=detail&aid=645323&group_id=9863&atid=109863
-  //
-  // and the only work around I could find was this ugly hack... without it
-  // simply toggling the "multiline" checkbox in the notebook sample resulted
-  // in a noticeable page displacement
-  if ( HasFlag(wxNB_MULTILINE) )
-  {
-      // avoid an infinite recursion: we get another notification too!
-      static bool s_isInOnSize = false;
+    // update the background brush
+#if wxUSE_UXTHEME
+    UpdateBgBrush();
+#endif // wxUSE_UXTHEME
 
-      if ( !s_isInOnSize )
-      {
-          s_isInOnSize = true;
-          SendMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED,
-                      MAKELPARAM(rc.right, rc.bottom));
-          s_isInOnSize = false;
-      }
-  }
+    // fit all the notebook pages to the tab control's display area
 
-  TabCtrl_AdjustRect(m_hwnd, false, &rc);
+    RECT rc;
+    rc.left = rc.top = 0;
+    GetSize((int *)&rc.right, (int *)&rc.bottom);
 
-  int width = rc.right - rc.left,
-      height = rc.bottom - rc.top;
-  size_t nCount = m_pages.Count();
-  for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
-    wxNotebookPage *pPage = m_pages[nPage];
-    pPage->SetSize(rc.left, rc.top, width, height);
-  }
+    // save the total size, we'll use it below
+    int widthNbook = rc.right - rc.left,
+        heightNbook = rc.bottom - rc.top;
+
+    // there seems to be a bug in the implementation of TabCtrl_AdjustRect(): it
+    // returns completely false values for multiline tab controls after the tabs
+    // are added but before getting the first WM_SIZE (off by ~50 pixels, see
+    //
+    // http://sf.net/tracker/index.php?func=detail&aid=645323&group_id=9863&atid=109863
+    //
+    // and the only work around I could find was this ugly hack... without it
+    // simply toggling the "multiline" checkbox in the notebook sample resulted
+    // in a noticeable page displacement
+    if ( HasFlag(wxNB_MULTILINE) )
+    {
+        // avoid an infinite recursion: we get another notification too!
+        static bool s_isInOnSize = false;
 
-#if wxUSE_UXTHEME
-  UpdateBgBrush();
-#endif // wxUSE_UXTHEME
+        if ( !s_isInOnSize )
+        {
+            s_isInOnSize = true;
+            SendMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED,
+                    MAKELPARAM(rc.right, rc.bottom));
+            s_isInOnSize = false;
+        }
+    }
 
-  event.Skip();
+    TabCtrl_AdjustRect(m_hwnd, false, &rc);
+
+    int width = rc.right - rc.left,
+        height = rc.bottom - rc.top;
+    size_t nCount = m_pages.Count();
+    for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
+        wxNotebookPage *pPage = m_pages[nPage];
+        pPage->SetSize(rc.left, rc.top, width, height);
+    }
+
+
+    // unless we had already repainted everything, we now need to refresh
+    if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) )
+    {
+        // invalidate areas not covered by pages
+        RefreshRect(wxRect(0, 0, widthNbook, rc.top), false);
+        RefreshRect(wxRect(0, rc.top, rc.left, height), false);
+        RefreshRect(wxRect(0, rc.bottom, widthNbook, heightNbook - rc.bottom),
+                    false);
+        RefreshRect(wxRect(rc.right, rc.top, widthNbook - rc.bottom, height),
+                    false);
+    }
+
+    event.Skip();
 }
 
 void wxNotebook::OnSelChange(wxNotebookEvent& event)
@@ -874,7 +935,7 @@ WXHANDLE wxNotebook::QueryBgBitmap(wxWindow *win)
     SelectInHDC selectBmp(hDCMem, hBmp);
 
     ::SendMessage(GetHwnd(), WM_PRINTCLIENT,
-                  (WPARAM)(HDC)hDCMem, 
+                  (WPARAM)(HDC)hDCMem,
                   PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT);
 
     if ( win )
@@ -886,10 +947,9 @@ WXHANDLE wxNotebook::QueryBgBitmap(wxWindow *win)
 
         return (WXHANDLE)c;
     }
-    else // we are asked to create the brush
-    {
-        return (WXHANDLE)::CreatePatternBrush(hBmp);
-    }
+    //else: we are asked to create the brush
+
+    return (WXHANDLE)::CreatePatternBrush(hBmp);
 }
 
 void wxNotebook::UpdateBgBrush()
@@ -942,8 +1002,82 @@ wxColour wxNotebook::MSWGetBgColourForChild(wxWindow *win)
     return c == CLR_INVALID ? wxNullColour : wxRGBToColour(c);
 }
 
+bool
+wxNotebook::MSWPrintChild(wxWindow *win,
+                          WXWPARAM wParam,
+                          WXLPARAM WXUNUSED(lParam))
+{
+    RECT rc;
+    ::GetClientRect(GetHwnd(), &rc);
+    TabCtrl_AdjustRect(GetHwnd(), true, &rc);
+    ::MapWindowPoints(GetHwnd(), GetHwndOf(win), (POINT *)&rc, 2);
+
+    wxUxThemeHandle theme(win, L"TAB");
+    if ( theme )
+    {
+        wxUxThemeEngine::Get()->DrawThemeBackground
+        (
+            theme,
+            (WXHDC)wParam,
+            9 /* TABP_PANE */,
+            0,
+            &rc,
+            NULL
+        );
+    }
+
+    return true;
+}
+
 #endif // wxUSE_UXTHEME
 
+// Windows only: attempts to get colour for UX theme page background
+wxColour wxNotebook::GetThemeBackgroundColour() const
+{
+#if wxUSE_UXTHEME
+    if (wxUxThemeEngine::Get())
+    {
+        wxUxThemeHandle hTheme((wxNotebook*) this, L"TAB");
+        if (hTheme)
+        {
+            // This is total guesswork.
+            // See PlatformSDK\Include\Tmschema.h for values
+            COLORREF themeColor;
+            wxUxThemeEngine::Get()->GetThemeColor(
+                                        hTheme,
+                                        10 /* TABP_BODY */,
+                                        1 /* NORMAL */,
+                                        3821 /* FILLCOLORHINT */,
+                                        &themeColor);
+
+            /*
+            [DS] Workaround for WindowBlinds:
+            Some themes return a near black theme color using FILLCOLORHINT,
+            this makes notebook pages have an ugly black background and makes
+            text (usually black) unreadable. Retry again with FILLCOLOR.
+
+            This workaround potentially breaks appearance of some themes,
+            but in practice it already fixes some themes.
+            */
+            if (themeColor == 1)
+            {
+                wxUxThemeEngine::Get()->GetThemeColor(
+                                            hTheme,
+                                            10 /* TABP_BODY */,
+                                            1 /* NORMAL */,
+                                            3802 /* FILLCOLOR */,
+                                            &themeColor);
+            }
+
+            wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor));
+            return colour;
+        }
+    }
+#endif // wxUSE_UXTHEME
+
+    return GetBackgroundColour();
+}
+
 // ----------------------------------------------------------------------------
 // wxNotebook base class virtuals
 // ----------------------------------------------------------------------------