X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/25057abaacf5ccf30bf136ec2ac430eb61664c3b..730d336601a3ece761b56e7c05d1099352670a25:/src/msw/notebook.cpp diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 3f2390950c..dcf8118edc 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -94,9 +94,7 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) BEGIN_EVENT_TABLE(wxNotebook, wxControl) EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) - EVT_SIZE(wxNotebook::OnSize) - EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) END_EVENT_TABLE() @@ -135,6 +133,8 @@ wxBEGIN_FLAGS( wxNotebookStyle ) wxFLAGS_MEMBER(wxNB_LEFT) wxFLAGS_MEMBER(wxNB_RIGHT) wxFLAGS_MEMBER(wxNB_BOTTOM) + wxFLAGS_MEMBER(wxNB_NOPAGETHEME) + wxFLAGS_MEMBER(wxNB_FLAT) wxEND_FLAGS( wxNotebookStyle ) @@ -180,6 +180,25 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo, wxObject ) #endif IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) +// ---------------------------------------------------------------------------- +// local functions +// ---------------------------------------------------------------------------- + +#ifndef __WXWINCE__ +// 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; +} +#endif + // ============================================================================ // implementation // ============================================================================ @@ -239,6 +258,13 @@ bool wxNotebook::Create(wxWindow *parent, long style, const wxString& name) { +#ifdef __WXWINCE__ + // Not sure why, but without this style, there is no border + // around the notebook tabs. + if (style & wxNB_FLAT) + style |= wxBORDER_SUNKEN; +#endif + // 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(); @@ -296,6 +322,26 @@ bool wxNotebook::Create(wxWindow *parent, 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; } @@ -315,7 +361,7 @@ WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const 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 ) @@ -471,7 +517,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; @@ -618,7 +664,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 @@ -683,16 +729,6 @@ bool wxNotebook::InsertPage(size_t nPage, InvalidateBestSize(); - 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()) - { - pPage->SetBackgroundColour(col); - } - } - return true; } @@ -727,11 +763,20 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const void wxNotebook::OnSize(wxSizeEvent& event) { - // update the background brush #if wxUSE_UXTHEME + // background bitmap size has changed, update the brush using it too UpdateBgBrush(); #endif // wxUSE_UXTHEME + if ( GetPageCount() == 0 ) + { + // Prevents droppings on resize, but does cause some flicker + // when there are no pages. + Refresh(false); + event.Skip(); + return; + } + // fit all the notebook pages to the tab control's display area RECT rc; @@ -924,33 +969,37 @@ void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) #if wxUSE_UXTHEME -WXHANDLE wxNotebook::QueryBgBitmap(wxWindow *win) +WXHBRUSH wxNotebook::QueryBgBitmap() { RECT rc; - GetWindowRect(GetHwnd(), &rc); + ::GetClientRect(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); + CompatibleBitmap hBmp(hDC, rc.right, rc.bottom); SelectInHDC selectBmp(hDCMem, hBmp); - ::SendMessage(GetHwnd(), WM_PRINTCLIENT, - (WPARAM)(HDC)hDCMem, - PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT); - - if ( win ) + wxUxThemeHandle theme(this, L"TAB"); + if ( theme ) { - RECT rc2; - ::GetWindowRect(GetHwndOf(win), &rc2); - - COLORREF c = ::GetPixel(hDCMem, rc2.left - rc.left, rc2.top - rc.top); - - return (WXHANDLE)c; + AdjustRectForThemeBg(rc); + + wxUxThemeEngine::Get()->DrawThemeBackground + ( + theme, + (WXHDC)hDCMem, + 9 /* TABP_PANE */, + 0, + &rc, + NULL + ); } - //else: we are asked to create the brush - return (WXHANDLE)::CreatePatternBrush(hBmp); + return (WXHBRUSH)::CreatePatternBrush(hBmp); } void wxNotebook::UpdateBgBrush() @@ -960,7 +1009,7 @@ void wxNotebook::UpdateBgBrush() if ( !m_hasBgCol && wxUxThemeEngine::GetIfActive() ) { - m_hbrBackground = (WXHBRUSH)QueryBgBitmap(); + m_hbrBackground = QueryBgBitmap(); } else // no themes { @@ -990,17 +1039,63 @@ WXHBRUSH wxNotebook::MSWGetBgBrushForChild(WXHDC hDC, wxWindow *win) return wxNotebookBase::MSWGetBgBrushForChild(hDC, win); } -wxColour wxNotebook::MSWGetBgColourForChild(wxWindow *win) +wxColour wxNotebook::MSWGetBgColourForChild(wxWindow *WXUNUSED(win)) { 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; - COLORREF c = (COLORREF)QueryBgBitmap(win); + return GetThemeBackgroundColour(); +} - return c == CLR_INVALID ? wxNullColour : wxRGBToColour(c); +bool +wxNotebook::MSWPrintChild(wxWindow *win, + WXWPARAM wParam, + WXLPARAM WXUNUSED(lParam)) +{ + // 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 ) + { + // 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 @@ -1043,8 +1138,7 @@ wxColour wxNotebook::GetThemeBackgroundColour() const &themeColor); } - wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor)); - return colour; + return wxRGBToColour(themeColor); } } #endif // wxUSE_UXTHEME