X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2015f2b308851b2c1ec5f6ce9e998ae40cff3691..cb73e6001f891ae46b12a1e4ca39b93649cb6099:/src/msw/notebook.cpp diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 0cd903edfe..e0b47ea855 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -9,7 +9,7 @@ // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "notebook.h" #endif @@ -32,6 +32,7 @@ #include "wx/event.h" #include "wx/control.h" #include "wx/notebook.h" +#include "wx/app.h" #include "wx/msw/private.h" @@ -42,22 +43,37 @@ #include // for SetWindowFont -#ifndef __TWIN32__ - #ifdef __GNUWIN32_OLD__ - #include "wx/msw/gnuwin32/extra.h" - #endif +#ifdef __GNUWIN32_OLD__ + #include "wx/msw/gnuwin32/extra.h" #endif -#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__)) +#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)) #include #endif +#include "wx/msw/winundef.h" + +#if wxUSE_UXTHEME +#include "wx/msw/uxtheme.h" + +#include "wx/radiobut.h" +#include "wx/radiobox.h" +#include "wx/checkbox.h" +#include "wx/bmpbuttn.h" +#include "wx/statline.h" +#include "wx/statbox.h" +#include "wx/stattext.h" +#include "wx/slider.h" +#include "wx/scrolwin.h" +#include "wx/panel.h" +#endif + // ---------------------------------------------------------------------------- // macros // ---------------------------------------------------------------------------- // check that the page index is valid -#define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount())) +#define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount()) // hide the ugly cast #define m_hwnd (HWND)GetHWND() @@ -83,6 +99,10 @@ // event table // ---------------------------------------------------------------------------- +#include + +WX_DEFINE_LIST( wxNotebookPageInfoList ) ; + DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) @@ -96,7 +116,57 @@ BEGIN_EVENT_TABLE(wxNotebook, wxControl) EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) END_EVENT_TABLE() +#if wxUSE_EXTENDED_RTTI + +IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook, wxControl,"wx/notebook.h") +IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo, wxObject , "wx/notebook.h" ) + +template<> const wxTypeInfo* wxGetTypeInfo( wxNotebookPageInfoList * ) +{ + static wxCollectionTypeInfo s_typeInfo( (wxTypeInfo*) wxGetTypeInfo( (wxNotebookPageInfo **) NULL) ) ; + return &s_typeInfo ; +} + +template<> void wxCollectionToVariantArray( wxNotebookPageInfoList const &theList, wxxVariantArray &value) +{ + wxListCollectionToVariantArray( theList , value ) ; +} + +WX_BEGIN_PROPERTIES_TABLE(wxNotebook) + WX_PROPERTY_COLLECTION( PageInfos , wxNotebookPageInfoList , wxNotebookPageInfo* , AddPageInfo , GetPageInfos ) +/* + notebookpage + object + object_ref + label + selected + style + usenotebooksizer +*/ +WX_END_PROPERTIES_TABLE() + +WX_BEGIN_HANDLERS_TABLE(wxNotebook) +WX_END_HANDLERS_TABLE() + +WX_CONSTRUCTOR_4( wxNotebook , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size ) + + +WX_BEGIN_PROPERTIES_TABLE(wxNotebookPageInfo) + WX_READONLY_PROPERTY( Page , wxNotebookPage* , GetPage , ) + WX_READONLY_PROPERTY( Text , wxString , GetText , wxEmptyString ) + WX_READONLY_PROPERTY( Selected , bool , GetSelected , false ) + WX_READONLY_PROPERTY( ImageId , int , GetImageId , -1 ) +WX_END_PROPERTIES_TABLE() + +WX_BEGIN_HANDLERS_TABLE(wxNotebookPageInfo) +WX_END_HANDLERS_TABLE() + +WX_CONSTRUCTOR_4( wxNotebookPageInfo , wxNotebookPage* , Page , wxString , Text , bool , Selected , int , ImageId ) + +#else IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo, wxObject ) +#endif IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) // ============================================================================ @@ -107,6 +177,19 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) // wxNotebook construction // ---------------------------------------------------------------------------- +const wxNotebookPageInfoList& wxNotebook::GetPageInfos() const +{ + wxNotebookPageInfoList* list = const_cast< wxNotebookPageInfoList* >( &m_pageInfos ) ; + WX_CLEAR_LIST( wxNotebookPageInfoList , *list ) ; + for( size_t i = 0 ; i < GetPageCount() ; ++i ) + { + wxNotebookPageInfo *info = new wxNotebookPageInfo() ; + info->Create( const_cast(this)->GetPage(i) , GetPageText(i) , GetSelection() == int(i) , GetPageImage(i) ) ; + list->Append( info ) ; + } + return m_pageInfos ; +} + // common part of all ctors void wxNotebook::Init() { @@ -141,12 +224,25 @@ bool wxNotebook::Create(wxWindow *parent, long style, const wxString& name) { - // base init + // Does ComCtl32 support non-top tabs? + int verComCtl32 = wxApp::GetComCtl32Version(); + if ( verComCtl32 < 470 || verComCtl32 >= 600 ) + { + if (style & wxNB_BOTTOM) + style &= ~wxNB_BOTTOM; + + if (style & wxNB_LEFT) + style &= ~wxNB_LEFT; + + if (style & wxNB_RIGHT) + style &= ~wxNB_RIGHT; + } + if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL, wxDefaultValidator, name) ) return FALSE; - if ( !MSWCreateControl(WC_TABCONTROL, _T(""), pos, size) ) + if ( !MSWCreateControl(WC_TABCONTROL, wxEmptyString, pos, size) ) return FALSE; SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE))); @@ -187,7 +283,7 @@ WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const // wxNotebook accessors // ---------------------------------------------------------------------------- -int wxNotebook::GetPageCount() const +size_t wxNotebook::GetPageCount() const { // consistency check wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(m_hwnd) ); @@ -200,11 +296,11 @@ int wxNotebook::GetRowCount() const return TabCtrl_GetRowCount(m_hwnd); } -int wxNotebook::SetSelection(int nPage) +int wxNotebook::SetSelection(size_t nPage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); - if ( nPage != m_nSelection ) + if ( int(nPage) != m_nSelection ) { wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); event.SetSelection(nPage); @@ -223,7 +319,7 @@ int wxNotebook::SetSelection(int nPage) return m_nSelection; } -bool wxNotebook::SetPageText(int nPage, const wxString& strText) +bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) { wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); @@ -234,9 +330,9 @@ bool wxNotebook::SetPageText(int nPage, const wxString& strText) return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0; } -wxString wxNotebook::GetPageText(int nPage) const +wxString wxNotebook::GetPageText(size_t nPage) const { - wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("notebook page out of range") ); wxChar buf[256]; TC_ITEM tcItem; @@ -251,7 +347,7 @@ wxString wxNotebook::GetPageText(int nPage) const return str; } -int wxNotebook::GetPageImage(int nPage) const +int wxNotebook::GetPageImage(size_t nPage) const { wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); @@ -261,7 +357,7 @@ int wxNotebook::GetPageImage(int nPage) const return TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ? tcItem.iImage : -1; } -bool wxNotebook::SetPageImage(int nPage, int nImage) +bool wxNotebook::SetPageImage(size_t nPage, int nImage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); @@ -313,6 +409,33 @@ void wxNotebook::SetTabSize(const wxSize& sz) ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y)); } +wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const +{ + wxSize sizeTotal = sizePage; + + // We need to make getting tab size part of the wxWindows API. + wxSize tabSize(0, 0); + if (GetPageCount() > 0) + { + RECT rect; + TabCtrl_GetItemRect((HWND) GetHWND(), 0, & rect); + tabSize.x = rect.right - rect.left; + tabSize.y = rect.bottom - rect.top; + } + if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) ) + { + sizeTotal.x += tabSize.x + 7; + sizeTotal.y += 7; + } + else + { + sizeTotal.x += 7; + sizeTotal.y += tabSize.y + 7; + } + + return sizeTotal; +} + void wxNotebook::AdjustPageSize(wxNotebookPage *page) { wxCHECK_RET( page, _T("NULL page in wxNotebook::AdjustPageSize") ); @@ -333,7 +456,7 @@ void wxNotebook::AdjustPageSize(wxNotebookPage *page) // ---------------------------------------------------------------------------- // remove one page from the notebook, without deleting -wxNotebookPage *wxNotebook::DoRemovePage(int nPage) +wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage) { wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage); if ( !pageRemoved ) @@ -350,12 +473,12 @@ wxNotebookPage *wxNotebook::DoRemovePage(int nPage) { // change the selected page if it was deleted or became invalid int selNew; - if ( m_nSelection == GetPageCount() ) + if ( m_nSelection == int(GetPageCount()) ) { // last page deleted, make the new last page the new selection selNew = m_nSelection - 1; } - else if ( nPage <= m_nSelection ) + else if ( int(nPage) <= m_nSelection ) { // we must show another page, even if it has the same index selNew = m_nSelection; @@ -368,7 +491,8 @@ wxNotebookPage *wxNotebook::DoRemovePage(int nPage) // for some unknown reason if the tab control shows the up-down // control (i.e. when there are too many pages) -- otherwise after // deleting a page nothing at all is shown - m_pages[m_nSelection]->Refresh(); + if (m_nSelection >= 0) + m_pages[m_nSelection]->Refresh(); } if ( selNew != -1 ) @@ -386,8 +510,8 @@ wxNotebookPage *wxNotebook::DoRemovePage(int nPage) // remove all pages bool wxNotebook::DeleteAllPages() { - int nPageCount = GetPageCount(); - int nPage; + size_t nPageCount = GetPageCount(); + size_t nPage; for ( nPage = 0; nPage < nPageCount; nPage++ ) delete m_pages[nPage]; @@ -401,7 +525,7 @@ bool wxNotebook::DeleteAllPages() } // same as AddPage() but does it at given position -bool wxNotebook::InsertPage(int nPage, +bool wxNotebook::InsertPage(size_t nPage, wxNotebookPage *pPage, const wxString& strText, bool bSelect, @@ -414,6 +538,27 @@ bool wxNotebook::InsertPage(int nPage, wxASSERT_MSG( pPage->GetParent() == this, _T("notebook pages must have notebook as parent") ); +#if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO + static bool g_TestedForTheme = FALSE; + static bool g_UseTheme = FALSE; + if (!g_TestedForTheme) + { + int commCtrlVersion = wxTheApp->GetComCtl32Version() ; + + g_UseTheme = (commCtrlVersion >= 600); + g_TestedForTheme = TRUE; + } + + // Automatically apply the theme background, + // changing the colour of the panel to match the + // tab page colour. This won't work well with all + // themes but it's a start. + if (g_UseTheme && wxUxThemeEngine::Get() && pPage->IsKindOf(CLASSINFO(wxPanel))) + { + ApplyThemeBackground(pPage, GetThemeBackgroundColour()); + } +#endif + // add a new tab to the control // ---------------------------- @@ -474,7 +619,7 @@ bool wxNotebook::InsertPage(int nPage, // if the inserted page is before the selected one, we must update the // index of the selected page - if ( nPage <= m_nSelection ) + if ( int(nPage) <= m_nSelection ) { // one extra page added m_nSelection++; @@ -494,6 +639,31 @@ bool wxNotebook::InsertPage(int nPage, return TRUE; } +int wxNotebook::HitTest(const wxPoint& pt, long *flags) const +{ + TC_HITTESTINFO hitTestInfo; + hitTestInfo.pt.x = pt.x; + hitTestInfo.pt.y = pt.y; + int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo); + + if ( flags ) + { + *flags = 0; + + if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE) + *flags |= wxNB_HITTEST_NOWHERE; + if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM) + *flags |= wxNB_HITTEST_ONITEM; + if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON) + *flags |= wxNB_HITTEST_ONICON; + if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL) + *flags |= wxNB_HITTEST_ONLABEL; + } + + return item; +} + + // ---------------------------------------------------------------------------- // wxNotebook callbacks // ---------------------------------------------------------------------------- @@ -576,9 +746,9 @@ void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) // OnSetFocus() because we don't know which direction the focus came // from in this case and so can't choose between setting the focus to // first or last panel child - wxWindow *parent = GetParent(); - if ( event.GetEventObject() == parent ) + // the cast is here to fic a GCC ICE + if ( ((wxWindow*)event.GetEventObject()) == parent ) { // no, it doesn't come from child, case (b): forward to a page if ( m_nSelection != -1 ) @@ -675,4 +845,99 @@ bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) return processed; } +// Windows only: attempts to get colour for UX theme page background +wxColour wxNotebook::GetThemeBackgroundColour() +{ +#if wxUSE_UXTHEME + if (wxUxThemeEngine::Get()) + { + wxUxThemeHandle hTheme(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 + ); + + wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor)); + return colour; + } + } +#endif // wxUSE_UXTHEME + + return GetBackgroundColour(); +} + +// Windows only: attempts to apply the UX theme page background to this page +#if wxUSE_UXTHEME +void wxNotebook::ApplyThemeBackground(wxWindow* window, const wxColour& colour) +#else +void wxNotebook::ApplyThemeBackground(wxWindow*, const wxColour&) +#endif +{ +#if wxUSE_UXTHEME + // Don't set the background for buttons since this will + // switch it into ownerdraw mode + if (window->IsKindOf(CLASSINFO(wxButton)) && !window->IsKindOf(CLASSINFO(wxBitmapButton))) + // This is essential, otherwise you'll see dark grey + // corners in the buttons. + ((wxButton*)window)->wxControl::SetBackgroundColour(colour); + else if (window->IsKindOf(CLASSINFO(wxStaticText)) || + window->IsKindOf(CLASSINFO(wxStaticBox)) || + window->IsKindOf(CLASSINFO(wxStaticLine)) || + window->IsKindOf(CLASSINFO(wxRadioButton)) || + window->IsKindOf(CLASSINFO(wxRadioBox)) || + window->IsKindOf(CLASSINFO(wxCheckBox)) || + window->IsKindOf(CLASSINFO(wxBitmapButton)) || + window->IsKindOf(CLASSINFO(wxSlider)) || + window->IsKindOf(CLASSINFO(wxPanel)) || + (window->IsKindOf(CLASSINFO(wxNotebook)) && (window != this)) || + window->IsKindOf(CLASSINFO(wxScrolledWindow)) + ) + { + window->SetBackgroundColour(colour); + } + + for ( wxWindowList::compatibility_iterator node = window->GetChildren().GetFirst(); node; node = node->GetNext() ) + { + wxWindow *child = node->GetData(); + ApplyThemeBackground(child, colour); + } +#endif +} + +long wxNotebook::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) +{ + static bool g_TestedForTheme = FALSE; + static bool g_UseTheme = FALSE; + switch ( nMsg ) + { + case WM_ERASEBKGND: + { + if (!g_TestedForTheme) + { + int commCtrlVersion = wxTheApp->GetComCtl32Version() ; + + g_UseTheme = (commCtrlVersion >= 600); + g_TestedForTheme = TRUE; + } + + // If using XP themes, it seems we can get away + // with not drawing a background, which reduces flicker. + if (g_UseTheme) + return TRUE; + } + } + + return wxControl::MSWWindowProc(nMsg, wParam, lParam); +} + + #endif // wxUSE_NOTEBOOK