// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "notebook.h"
#endif
// ----------------------------------------------------------------------------
// 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()
// event table
// ----------------------------------------------------------------------------
+#include <wx/listimpl.cpp>
+
+WX_DEFINE_LIST( wxNotebookPageInfoList ) ;
+
DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
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<wxNotebookPageInfoList::compatibility_iterator>( 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)
// ============================================================================
// 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<wxNotebook*>(this)->GetPage(i) , GetPageText(i) , GetSelection() == int(i) , GetPageImage(i) ) ;
+ list->Append( info ) ;
+ }
+ return m_pageInfos ;
+}
+
// common part of all ctors
void wxNotebook::Init()
{
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)));
// wxNotebook accessors
// ----------------------------------------------------------------------------
-int wxNotebook::GetPageCount() const
+size_t wxNotebook::GetPageCount() const
{
// consistency check
wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(m_hwnd) );
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);
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") );
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;
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") );
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") );
// ----------------------------------------------------------------------------
// 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 )
{
// 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;
// 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 )
// 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];
}
// 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,
_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());
}
// 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++;
// 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 )
#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
window->SetBackgroundColour(colour);
}
- for ( wxWindowList::Node *node = window->GetChildren().GetFirst(); node; node = node->GetNext() )
+ 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