X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fc10daf37cbfc1620543d8128ed265b374240501..9a78988fedc6e5364368cd09e60308180d3a7425:/src/msw/notebook.cpp diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index c09e5fc085..9110079e5f 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 @@ -73,7 +73,7 @@ // ---------------------------------------------------------------------------- // 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() @@ -99,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) @@ -112,7 +116,84 @@ BEGIN_EVENT_TABLE(wxNotebook, wxControl) EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) END_EVENT_TABLE() +#if wxUSE_EXTENDED_RTTI +WX_DEFINE_FLAGS( wxNotebookStyle ) + +wxBEGIN_FLAGS( wxNotebookStyle ) + // new style border flags, we put them first to + // use them for streaming out + wxFLAGS_MEMBER(wxBORDER_SIMPLE) + wxFLAGS_MEMBER(wxBORDER_SUNKEN) + wxFLAGS_MEMBER(wxBORDER_DOUBLE) + wxFLAGS_MEMBER(wxBORDER_RAISED) + wxFLAGS_MEMBER(wxBORDER_STATIC) + wxFLAGS_MEMBER(wxBORDER_NONE) + + // old style border flags + wxFLAGS_MEMBER(wxSIMPLE_BORDER) + wxFLAGS_MEMBER(wxSUNKEN_BORDER) + wxFLAGS_MEMBER(wxDOUBLE_BORDER) + wxFLAGS_MEMBER(wxRAISED_BORDER) + wxFLAGS_MEMBER(wxSTATIC_BORDER) + wxFLAGS_MEMBER(wxNO_BORDER) + + // standard window styles + wxFLAGS_MEMBER(wxTAB_TRAVERSAL) + wxFLAGS_MEMBER(wxCLIP_CHILDREN) + wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) + wxFLAGS_MEMBER(wxWANTS_CHARS) + wxFLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE) + wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) + wxFLAGS_MEMBER(wxVSCROLL) + wxFLAGS_MEMBER(wxHSCROLL) + + wxFLAGS_MEMBER(wxNB_FIXEDWIDTH) + wxFLAGS_MEMBER(wxNB_LEFT) + wxFLAGS_MEMBER(wxNB_RIGHT) + wxFLAGS_MEMBER(wxNB_BOTTOM) + +wxEND_FLAGS( wxNotebookStyle ) + +IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook, wxControl,"wx/notebook.h") +IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo, wxObject , "wx/notebook.h" ) + +wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo * , wxNotebookPageInfoList ) ; + +template<> void wxCollectionToVariantArray( wxNotebookPageInfoList const &theList, wxxVariantArray &value) +{ + wxListCollectionToVariantArray( theList , value ) ; +} + +wxBEGIN_PROPERTIES_TABLE(wxNotebook) + wxEVENT_PROPERTY( PageChanging , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING , wxNotebookEvent ) + wxEVENT_PROPERTY( PageChanged , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED , wxNotebookEvent ) + + wxPROPERTY_COLLECTION( PageInfos , wxNotebookPageInfoList , wxNotebookPageInfo* , AddPageInfo , GetPageInfos , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxPROPERTY_FLAGS( WindowStyle , wxNotebookStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style +wxEND_PROPERTIES_TABLE() + +wxBEGIN_HANDLERS_TABLE(wxNotebook) +wxEND_HANDLERS_TABLE() + +wxCONSTRUCTOR_5( wxNotebook , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle) + + +wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo) + wxREADONLY_PROPERTY( Page , wxNotebookPage* , GetPage , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxREADONLY_PROPERTY( Text , wxString , GetText , wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxREADONLY_PROPERTY( Selected , bool , GetSelected , false, 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) + wxREADONLY_PROPERTY( ImageId , int , GetImageId , -1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) +wxEND_PROPERTIES_TABLE() + +wxBEGIN_HANDLERS_TABLE(wxNotebookPageInfo) +wxEND_HANDLERS_TABLE() + +wxCONSTRUCTOR_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) // ============================================================================ @@ -123,6 +204,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() { @@ -216,7 +310,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) ); @@ -229,11 +323,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); @@ -252,7 +346,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") ); @@ -263,7 +357,7 @@ 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), wxEmptyString, wxT("notebook page out of range") ); @@ -280,7 +374,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") ); @@ -290,7 +384,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") ); @@ -389,7 +483,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 ) @@ -406,12 +500,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; @@ -424,7 +518,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 ) @@ -442,8 +537,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]; @@ -457,7 +552,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, @@ -471,11 +566,21 @@ bool wxNotebook::InsertPage(int nPage, _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 (wxUxThemeEngine::Get() && pPage->IsKindOf(CLASSINFO(wxPanel))) + if (g_UseTheme && wxUxThemeEngine::Get() && pPage->IsKindOf(CLASSINFO(wxPanel))) { ApplyThemeBackground(pPage, GetThemeBackgroundColour()); } @@ -541,7 +646,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++; @@ -773,31 +878,36 @@ wxColour wxNotebook::GetThemeBackgroundColour() #if wxUSE_UXTHEME if (wxUxThemeEngine::Get()) { - WXHTHEME hTheme = wxUxThemeEngine::Get()->m_pfnOpenThemeData(GetHWND(), L"TAB"); + wxUxThemeHandle hTheme(this, L"TAB"); if (hTheme) { // This is total guesswork. // See PlatformSDK\Include\Tmschema.h for values COLORREF themeColor; - wxUxThemeEngine::Get()-> - m_pfnGetThemeColor(hTheme, - 10 /* TABP_BODY */, - 1 /* NORMAL */, - 3821, /* FILLCOLORHINT */ - & themeColor); - - wxUxThemeEngine::Get()->m_pfnCloseThemeData(hTheme); + wxUxThemeEngine::Get()->GetThemeColor + ( + hTheme, + 10 /* TABP_BODY */, + 1 /* NORMAL */, + 3821, /* FILLCOLORHINT */ + & themeColor + ); wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor)); return colour; } } -#endif +#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 @@ -830,4 +940,31 @@ void wxNotebook::ApplyThemeBackground(wxWindow* window, const wxColour& 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