X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2142d7ba6ab908a4bb81ab898a44e0e8e1a8bf8d..9a78988fedc6e5364368cd09e60308180d3a7425:/src/msw/notebook.cpp diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 2594af1c81..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) @@ -113,18 +117,82 @@ BEGIN_EVENT_TABLE(wxNotebook, wxControl) 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() -WX_BEGIN_PROPERTIES_TABLE(wxNotebook) -WX_END_PROPERTIES_TABLE() +wxBEGIN_HANDLERS_TABLE(wxNotebook) +wxEND_HANDLERS_TABLE() -WX_BEGIN_HANDLERS_TABLE(wxNotebook) -WX_END_HANDLERS_TABLE() +wxCONSTRUCTOR_5( wxNotebook , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle) -WX_CONSTRUCTOR_4( wxNotebook , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size ) + +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) @@ -136,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() { @@ -229,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) ); @@ -242,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); @@ -265,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") ); @@ -276,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") ); @@ -293,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") ); @@ -303,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") ); @@ -402,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 ) @@ -419,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; @@ -456,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]; @@ -471,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, @@ -485,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()); } @@ -555,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++; @@ -812,7 +903,11 @@ wxColour wxNotebook::GetThemeBackgroundColour() } // 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 @@ -842,10 +937,34 @@ void wxNotebook::ApplyThemeBackground(wxWindow* window, const wxColour& colour) wxWindow *child = node->GetData(); ApplyThemeBackground(child, colour); } -#else - window; - 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