#ifndef __TWIN32__
#ifdef __GNUWIN32__
+#ifndef wxUSE_NORLANDER_HEADERS
#include "wx/msw/gnuwin32/extra.h"
#endif
#endif
+#endif
-#if !defined(__GNUWIN32__) || defined(__TWIN32__)
+#if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
#include <commctrl.h>
#endif
BEGIN_EVENT_TABLE(wxNotebook, wxControl)
EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange)
- // doesn't work yet EVT_WINDOW_CREATE(wxNotebook::OnWindowCreate)
- EVT_SIZE(wxNotebook::OnWindowCreate)
+ EVT_SIZE(wxNotebook::OnSize)
EVT_SET_FOCUS(wxNotebook::OnSetFocus)
const wxString& name)
{
// base init
- CreateBase(parent, id, pos, size, style, name);
+ if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
+ return FALSE;
// colors and font
m_backgroundColour = wxColour(GetSysColor(COLOR_BTNFACE));
int wxNotebook::SetSelection(int nPage)
{
- wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, "notebook page out of range" );
+ wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("notebook page out of range") );
ChangePage(m_nSelection, nPage);
bool wxNotebook::SetPageText(int nPage, const wxString& strText)
{
- wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, "notebook page out of range" );
+ wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("notebook page out of range") );
TC_ITEM tcItem;
tcItem.mask = TCIF_TEXT;
- tcItem.pszText = (char *)strText.c_str();
+ tcItem.pszText = (wxChar *)strText.c_str();
return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0;
}
wxString wxNotebook::GetPageText(int nPage) const
{
- wxCHECK_MSG( IS_VALID_PAGE(nPage), "", "notebook page out of range" );
+ wxCHECK_MSG( IS_VALID_PAGE(nPage), _T(""), _T("notebook page out of range") );
- char buf[256];
+ wxChar buf[256];
TC_ITEM tcItem;
tcItem.mask = TCIF_TEXT;
tcItem.pszText = buf;
int wxNotebook::GetPageImage(int nPage) const
{
- wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, "notebook page out of range" );
+ wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("notebook page out of range") );
TC_ITEM tcItem;
tcItem.mask = TCIF_IMAGE;
bool wxNotebook::SetPageImage(int nPage, int nImage)
{
- wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, "notebook page out of range" );
+ wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("notebook page out of range") );
TC_ITEM tcItem;
tcItem.mask = TCIF_IMAGE;
// remove one page from the notebook
bool wxNotebook::DeletePage(int nPage)
{
- wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, "notebook page out of range" );
+ wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("notebook page out of range") );
+
+ if ( m_nSelection == nPage ) {
+ // advance selection backwards - the page being deleted shouldn't be left
+ // selected
+ AdvanceSelection(FALSE);
+ }
TabCtrl_DeleteItem(m_hwnd, nPage);
delete m_aPages[nPage];
m_aPages.Remove(nPage);
+ if ( m_aPages.IsEmpty() ) {
+ // no selection if the notebook became empty
+ m_nSelection = -1;
+ }
+
return TRUE;
}
// remove one page from the notebook, without deleting
bool wxNotebook::RemovePage(int nPage)
{
- wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, "notebook page out of range" );
+ wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("notebook page out of range") );
TabCtrl_DeleteItem(m_hwnd, nPage);
if (!strText.IsEmpty())
{
tcItem.mask |= TCIF_TEXT;
- tcItem.pszText = (char *)strText.c_str();
+ tcItem.pszText = (wxChar *)strText.c_str();
}
else
- tcItem.pszText = (char *) NULL;
+ tcItem.pszText = (wxChar *) NULL;
if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 ) {
- wxLogError("Can't create the notebook page '%s'.", strText.c_str());
+ wxLogError(_T("Can't create the notebook page '%s'."), strText.c_str());
return FALSE;
}
// this updates internal flag too - otherwise it will get out of sync
pPage->Show(FALSE);
+ // FIXME this is ugly, I'm breaking my own rules... but needed to get display
+ // right (why?)
+ wxSizeEvent event;
+ OnSize(event);
+
return TRUE;
}
// wxNotebook callbacks
// ----------------------------------------------------------------------------
-void wxNotebook::OnWindowCreate(wxWindowCreateEvent& event)
+void wxNotebook::OnSize(wxSizeEvent& event)
{
// make sure the current page is shown and has focus (it's useful because all
// pages are created invisible initially)
{
// is it our tab control?
if ( event.GetEventObject() == this )
- ChangePage(event.GetOldSelection(), event.GetSelection());
+ {
+ // don't call ChangePage() here because it will generate redundant
+ // notification events
+ int sel = event.GetOldSelection();
+ if ( sel != -1 )
+ m_aPages[sel]->Show(FALSE);
+
+ sel = event.GetSelection();
+ if ( sel != -1 )
+ {
+ wxNotebookPage *pPage = m_aPages[sel];
+ pPage->Show(TRUE);
+ pPage->SetFocus();
+ }
+
+ m_nSelection = sel;
+ }
// we want to give others a chance to process this message as well
event.Skip();