+#if !wxUSE_UXTHEME
+ // ComCtl32 notebook tabs simply don't work unless they're on top if we
+ // have uxtheme, we can work around it later (after control creation), but
+ // if we have been compiled without uxtheme support, we have to clear those
+ // styles
+ if ( HasTroubleWithNonTopTabs() )
+ {
+ style &= ~(wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT);
+ }
+#endif //wxUSE_UXTHEME
+
+#if defined(__WINE__) && wxUSE_UNICODE
+ LPCTSTR className = L"SysTabControl32";
+#else
+ LPCTSTR className = WC_TABCONTROL;
+#endif
+
+#if USE_NOTEBOOK_ANTIFLICKER
+ // 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(NULL, WC_TABCONTROL, &wc) )
+ {
+ gs_wndprocNotebook =
+ reinterpret_cast<WXFARPROC>(wc.lpfnWndProc);
+ wc.lpszClassName = wxT("_wx_SysTabCtl32");
+ wc.style &= ~(CS_HREDRAW | CS_VREDRAW);
+ wc.hInstance = wxGetInstance();
+ wc.lpfnWndProc = wxNotebookWndProc;
+ s_clsNotebook.Register(wc);
+ }
+ else
+ {
+ wxLogLastError(wxT("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();
+ }
+ }
+#endif // USE_NOTEBOOK_ANTIFLICKER
+
+ if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL,
+ wxDefaultValidator, name) )
+ return false;
+
+ if ( !MSWCreateControl(className, wxEmptyString, pos, size) )
+ return false;
+
+#if wxUSE_UXTHEME
+ if ( HasFlag(wxNB_NOPAGETHEME) ||
+ wxSystemOptions::IsFalse(wxT("msw.notebook.themed-background")) )
+ {
+ SetBackgroundColour(GetThemeBackgroundColour());
+ }
+ else // use themed background by default
+ {
+ // create backing store
+ UpdateBgBrush();
+ }
+
+ // comctl32.dll 6.0 doesn't support non-top tabs with visual styles (the
+ // control is simply not rendered correctly), so we disable themes
+ // if possible, otherwise we simply clear the styles.
+ if ( HasTroubleWithNonTopTabs() &&
+ (style & (wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT)) )
+ {
+ // check if we use themes at all -- if we don't, we're still okay
+ if ( wxUxThemeEngine::GetIfActive() )
+ {
+ wxUxThemeEngine::GetIfActive()->SetWindowTheme(GetHwnd(), L"", L"");
+
+ // correct the background color for the new non-themed control
+ SetBackgroundColour(GetThemeBackgroundColour());
+ }
+ }
+#endif // wxUSE_UXTHEME
+
+ // Undocumented hack to get flat notebook style
+ // In fact, we should probably only do this in some
+ // curcumstances, i.e. if we know we will have a border
+ // at the bottom (the tab control doesn't draw it itself)
+#if defined(__POCKETPC__) || defined(__SMARTPHONE__)
+ if (HasFlag(wxNB_FLAT))
+ {
+ SendMessage(GetHwnd(), CCM_SETVERSION, COMCTL32_VERSION, 0);
+ if (!m_hasBgCol)
+ SetBackgroundColour(*wxWHITE);
+ }
+#endif
+ return true;
+}
+
+WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const
+{
+ WXDWORD tabStyle = wxControl::MSWGetStyle(style, exstyle);
+
+ tabStyle |= WS_TABSTOP | TCS_TABS;
+
+ if ( style & wxNB_MULTILINE )
+ tabStyle |= TCS_MULTILINE;
+ if ( style & wxNB_FIXEDWIDTH )
+ tabStyle |= TCS_FIXEDWIDTH;
+
+ if ( style & wxBK_BOTTOM )
+ tabStyle |= TCS_RIGHT;
+ else if ( style & wxBK_LEFT )
+ tabStyle |= TCS_VERTICAL;
+ else if ( style & wxBK_RIGHT )
+ tabStyle |= TCS_VERTICAL | TCS_RIGHT;
+
+ return tabStyle;
+}
+
+wxNotebook::~wxNotebook()
+{
+#if wxUSE_UXTHEME
+ if ( m_hbrBackground )
+ ::DeleteObject((HBRUSH)m_hbrBackground);
+#endif // wxUSE_UXTHEME