#include "wx/event.h"
#include "wx/control.h"
#include "wx/notebook.h"
-#include "wx/sysopt.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
BEGIN_EVENT_TABLE(wxNotebook, wxControl)
EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange)
-
EVT_SIZE(wxNotebook::OnSize)
-
EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
END_EVENT_TABLE()
wxFLAGS_MEMBER(wxNB_LEFT)
wxFLAGS_MEMBER(wxNB_RIGHT)
wxFLAGS_MEMBER(wxNB_BOTTOM)
+ wxFLAGS_MEMBER(wxNB_NOPAGETHEME)
+ wxFLAGS_MEMBER(wxNB_FLAT)
wxEND_FLAGS( wxNotebookStyle )
#endif
IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
+// ----------------------------------------------------------------------------
+// local functions
+// ----------------------------------------------------------------------------
+
+// apparently DrawThemeBackground() modifies the rect passed to it and if we
+// don't call this function there are some drawing artifacts which are only
+// visible with some non default themes; so modify the rect here so that it
+// still paints the correct area
+static void AdjustRectForThemeBg(RECT& rc)
+{
+ // magic numbers needed to compensate for DrawThemeBackground()
+ rc.left -= 2;
+ rc.top -= 2;
+ rc.right += 4;
+ rc.bottom += 5;
+}
+
// ============================================================================
// implementation
// ============================================================================
long style,
const wxString& name)
{
- // some versions of comctl32.dll 6.0 included with Windows XP don't
- // support non-top tabs (the control is simply not rendered correctly) but
- // we can't detect which ones, so be pessimistic by default and disable non
- // top tabs under XP but allow the user to override this by using a special
- // system option
- bool nonTopTabsOk = wxSystemOptions::GetOptionInt(_T("msw.xp-tab-ok")) != 0;
- if ( !nonTopTabsOk )
+ // comctl32.dll 6.0 doesn't support non-top tabs with visual styles (the
+ // control is simply not rendered correctly), so disable them in this case
+ const int verComCtl32 = wxApp::GetComCtl32Version();
+ if ( verComCtl32 == 600 )
{
- int verComCtl32 = wxApp::GetComCtl32Version();
- nonTopTabsOk = verComCtl32 < 470 || verComCtl32 >= 600;
+ // check if we use themes at all -- if we don't, we're still ok
+#if wxUSE_UXTHEME
+ if ( wxUxThemeEngine::GetIfActive() )
+#endif
+ {
+ style &= ~(wxNB_BOTTOM | wxNB_LEFT | wxNB_RIGHT);
+ }
}
- if ( !nonTopTabsOk )
+ 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) )
{
- style &= ~(wxNB_BOTTOM | wxNB_LEFT | wxNB_RIGHT);
+ 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 wxUSE_UXTHEME
+ if ( HasFlag(wxNB_NOPAGETHEME) ||
+ wxSystemOptions::IsFalse(wxT("msw.notebook.themed-background")) )
+ {
+ 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(m_hwnd, CCM_SETVERSION, COMCTL32_VERSION, 0);
+ if (!m_hasBgCol)
+ SetBackgroundColour(*wxWHITE);
+ }
+#endif
return true;
}
else if ( style & wxNB_LEFT )
tabStyle |= TCS_VERTICAL;
else if ( style & wxNB_RIGHT )
- tabStyle |= TCS_VERTICAL | TCS_RIGHT;
+ tabStyle |= TCS_VERTICAL | TCS_RIGHT;
// ex style
if ( exstyle )
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;
}
// and the text
- if ( !strText.IsEmpty() )
+ if ( !strText.empty() )
{
tcItem.mask |= TCIF_TEXT;
tcItem.pszText = (wxChar *)strText.c_str(); // const_cast
SetSelection(selNew);
InvalidateBestSize();
+
return true;
}
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;
+#if wxUSE_UXTHEME
+ // background bitmap size has changed, update the brush using it too
+ UpdateBgBrush();
+#endif // wxUSE_UXTHEME
- if ( !s_isInOnSize )
- {
- s_isInOnSize = true;
- SendMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED,
- MAKELPARAM(rc.right, rc.bottom));
- s_isInOnSize = false;
- }
- }
+ if ( GetPageCount() == 0 )
+ {
+ // Prevents droppings on resize, but does cause some flicker
+ // when there are no pages.
+ Refresh(false);
+ event.Skip();
+ return;
+ }
- TabCtrl_AdjustRect(m_hwnd, false, &rc);
+ // fit all the notebook pages to the tab control's display area
- 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);
- }
+ RECT rc;
+ rc.left = rc.top = 0;
+ GetSize((int *)&rc.right, (int *)&rc.bottom);
-#if wxUSE_UXTHEME
- UpdateBgBrush();
-#endif // wxUSE_UXTHEME
+ // 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;
- event.Skip();
+ if ( !s_isInOnSize )
+ {
+ s_isInOnSize = true;
+ SendMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED,
+ MAKELPARAM(rc.right, rc.bottom));
+ s_isInOnSize = false;
+ }
+ }
+
+ 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)
#if wxUSE_UXTHEME
-void wxNotebook::UpdateBgBrush()
+WXHBRUSH wxNotebook::QueryBgBitmap()
{
- if ( m_hbrBackground )
- ::DeleteObject((HBRUSH)m_hbrBackground);
+ RECT rc;
+ ::GetClientRect(GetHwnd(), &rc);
- if ( wxUxThemeEngine::GetIfActive() )
- {
- RECT rc;
- GetWindowRect(GetHwnd(), &rc);
+ // adjust position
+ TabCtrl_AdjustRect(GetHwnd(), false, &rc);
- WindowHDC hDC(GetHwnd());
- MemoryHDC hDCMem(hDC);
- CompatibleBitmap hBmp(hDC, rc.right - rc.left, rc.bottom - rc.top);
+ WindowHDC hDC(GetHwnd());
+ MemoryHDC hDCMem(hDC);
+ CompatibleBitmap hBmp(hDC, rc.right, rc.bottom);
- SelectInHDC selectBmp(hDCMem, hBmp);
+ SelectInHDC selectBmp(hDCMem, hBmp);
+
+ wxUxThemeHandle theme(this, L"TAB");
+ if ( theme )
+ {
+ AdjustRectForThemeBg(rc);
+
+ wxUxThemeEngine::Get()->DrawThemeBackground
+ (
+ theme,
+ (WXHDC)hDCMem,
+ 9 /* TABP_PANE */,
+ 0,
+ &rc,
+ NULL
+ );
+ }
- SendMessage(GetHwnd(), WM_PRINTCLIENT, (WPARAM)(HDC)hDCMem,
- PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT);
+ return (WXHBRUSH)::CreatePatternBrush(hBmp);
+}
+
+void wxNotebook::UpdateBgBrush()
+{
+ if ( m_hbrBackground )
+ ::DeleteObject((HBRUSH)m_hbrBackground);
- m_hbrBackground = (WXHBRUSH)::CreatePatternBrush(hBmp);
+ if ( !m_hasBgCol && wxUxThemeEngine::GetIfActive() )
+ {
+ m_hbrBackground = QueryBgBitmap();
}
else // no themes
{
}
}
-WXHBRUSH wxNotebook::GetThemeBackgroundBrush(WXHDC hDC, wxWindow *win) const
+WXHBRUSH wxNotebook::MSWGetBgBrushForChild(WXHDC hDC, wxWindow *win)
{
if ( m_hbrBackground )
{
{
wxLogLastError(_T("SetBrushOrgEx(notebook bg brush)"));
}
+
+ return m_hbrBackground;
}
- return m_hbrBackground;
+ return wxNotebookBase::MSWGetBgBrushForChild(hDC, win);
}
-void wxNotebook::DoEraseBackground(wxEraseEvent& event)
+wxColour wxNotebook::MSWGetBgColourForChild(wxWindow *WXUNUSED(win))
{
- DoEraseBackground((wxWindow *)event.GetEventObject(),
- (WXHDC)GetHdcOf(*event.GetDC()));
+ if ( m_hasBgCol )
+ return GetBackgroundColour();
+
+ // Experimental: don't do this since we're doing it in wxPanel
+#if 0 // defined(__POCKETPC__) || defined(__SMARTPHONE__)
+ // For some reason, the pages will be grey by default.
+ // Normally they should be white on these platforms.
+ // (However the static control backgrounds are painted
+ // in the correct colour, just not the rest of it.)
+ // So let's give WinCE a hint.
+ else if (!win->m_hasBgCol)
+ return *wxWHITE;
+#endif
+
+ if ( !wxUxThemeEngine::GetIfActive() )
+ return wxNullColour;
+
+ return GetThemeBackgroundColour();
}
-void wxNotebook::DoEraseBackground(wxWindow *win, WXHDC hDC)
+bool
+wxNotebook::MSWPrintChild(wxWindow *win,
+ WXWPARAM wParam,
+ WXLPARAM WXUNUSED(lParam))
{
- // we can either draw the background ourselves or let DrawThemeBackground()
- // do it, but as we already have the correct brush, let's do it ourselves
- // (note that we use the same code in wxControl::MSWControlColor(), so if
- // it breaks, it should at least break in consistent way)
- WXHBRUSH hbr = GetThemeBackgroundBrush(hDC, win);
- if ( hbr )
+ // Don't paint the theme for the child if we have a solid background
+ if ( m_hasBgCol )
+ return false;
+
+
+ RECT rc;
+ ::GetClientRect(GetHwnd(), &rc);
+
+ // adjust position
+ TabCtrl_AdjustRect(GetHwnd(), false, &rc);
+
+ wxUxThemeHandle theme(win, L"TAB");
+ if ( theme )
{
- RECT rectClient;
- ::GetClientRect(GetHwndOf(win), &rectClient);
- ::FillRect((HDC)hDC, &rectClient, (HBRUSH)hbr);
+ // map from this client to win client coords
+ ::MapWindowPoints(GetHwnd(), GetHwndOf(win), (POINT *)&rc, 2);
+
+ AdjustRectForThemeBg(rc);
+ 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);
+ }
+
+ return wxRGBToColour(themeColor);
+ }
+ }
+#endif // wxUSE_UXTHEME
+
+ return GetBackgroundColour();
+}
+
// ----------------------------------------------------------------------------
// wxNotebook base class virtuals
// ----------------------------------------------------------------------------