// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "notebook.h"
#endif
+#ifdef __VMS
+#pragma message disable unscomzer
+#endif
+
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/generic/imaglist.h"
#include "wx/notebook.h"
#include "wx/dcclient.h"
+#include "wx/generic/tabg.h"
// ----------------------------------------------------------------------------
// macros
EVT_MOUSE_EVENTS(wxNotebook::OnMouseEvent)
EVT_SET_FOCUS(wxNotebook::OnSetFocus)
EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
-// EVT_IDLE(wxNotebook::OnIdle)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
// implementation
// ============================================================================
+// ============================================================================
+// Private class
+// ============================================================================
+
+// This reuses wxTabView to draw the tabs.
+class WXDLLEXPORT wxNotebookTabView: public wxTabView
+{
+DECLARE_DYNAMIC_CLASS(wxNotebookTabView)
+public:
+ wxNotebookTabView(wxNotebook* notebook, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
+ ~wxNotebookTabView(void);
+
+ // Called when a tab is activated
+ virtual void OnTabActivate(int activateId, int deactivateId);
+ // Allows vetoing
+ virtual bool OnTabPreActivate(int activateId, int deactivateId);
+
+protected:
+ wxNotebook* m_notebook;
+};
+
// ----------------------------------------------------------------------------
// wxNotebook construction
// ----------------------------------------------------------------------------
m_windowId = id == -1 ? NewControlId() : id;
- // It's like a normal window...
- if (!wxWindow::Create(parent, id, pos, size, style|wxNO_BORDER, name))
+ if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name))
return FALSE;
- SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
SetTabView(new wxNotebookTabView(this));
return 0;
}
-int wxNotebook::SetSelection(int nPage)
+int wxNotebook::SetSelection(size_t nPage)
{
- if (nPage == -1)
- return 0;
-
wxASSERT( IS_VALID_PAGE(nPage) );
#if defined (__WIN16__)
}
#endif
-bool wxNotebook::SetPageText(int nPage, const wxString& strText)
+bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
{
wxASSERT( IS_VALID_PAGE(nPage) );
#if defined (__WIN16__)
return FALSE;
}
-wxString wxNotebook::GetPageText(int nPage) const
+wxString wxNotebook::GetPageText(size_t nPage) const
{
wxASSERT( IS_VALID_PAGE(nPage) );
#endif
}
-int wxNotebook::GetPageImage(int nPage) const
+int wxNotebook::GetPageImage(size_t nPage) const
{
wxASSERT( IS_VALID_PAGE(nPage) );
return 0;
}
-bool wxNotebook::SetPageImage(int nPage, int nImage)
+bool wxNotebook::SetPageImage(size_t nPage, int nImage)
{
wxASSERT( IS_VALID_PAGE(nPage) );
return FALSE;
}
+// set the size (the same for all pages)
+void wxNotebook::SetPageSize(const wxSize& size)
+{
+ // TODO
+}
+
+// set the padding between tabs (in pixels)
+void wxNotebook::SetPadding(const wxSize& padding)
+{
+ // TODO
+}
+
+// set the size of the tabs for wxNB_FIXEDWIDTH controls
+void wxNotebook::SetTabSize(const wxSize& sz)
+{
+ // TODO
+}
+
// ----------------------------------------------------------------------------
// wxNotebook operations
// ----------------------------------------------------------------------------
// remove one page from the notebook and delete it
-bool wxNotebook::DeletePage(int nPage)
+bool wxNotebook::DeletePage(size_t nPage)
{
wxCHECK( IS_VALID_PAGE(nPage), FALSE );
return FALSE;
}
+bool wxNotebook::RemovePage(size_t nPage)
+{
+ return DoRemovePage(nPage) != NULL;
+}
+
// remove one page from the notebook
-bool wxNotebook::RemovePage(int nPage)
+wxWindow* wxNotebook::DoRemovePage(size_t nPage)
{
wxCHECK( IS_VALID_PAGE(nPage), FALSE );
{
// Only change the selection if the page we
// deleted was the selection.
- if (nPage == m_nSelection)
+ if (nPage == (size_t)m_nSelection)
{
m_nSelection = -1;
// Select the first tab. Generates a ChangePage.
- m_tabView->SetTabSelection((int) (long) GetPage(0), TRUE);
+ m_tabView->SetTabSelection(0, TRUE);
}
else
{
// We must adjust which tab we think is selected.
// If greater than the page we deleted, it must be moved down
// a notch.
- if (m_nSelection > nPage)
+ if (size_t(m_nSelection) > nPage)
m_nSelection -- ;
}
}
RefreshLayout(FALSE);
- return TRUE;
+ return pPage;
}
bool wxNotebook::RemovePage(wxNotebookPage* page)
// Find the position of the wxNotebookPage, -1 if not found.
int wxNotebook::FindPagePosition(wxNotebookPage* page) const
{
- int nPageCount = GetPageCount();
- int nPage;
+ size_t nPageCount = GetPageCount();
+ size_t nPage;
for ( nPage = 0; nPage < nPageCount; nPage++ )
if (m_pages[nPage] == page)
return nPage;
{
m_tabView->ClearTabs(TRUE);
- 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,
// This was supposed to cure the non-display of the notebook
// until the user resizes the window.
// What's going on?
-void wxNotebook::OnIdle(wxIdleEvent& event)
+void wxNotebook::OnInternalIdle()
{
+ wxWindow::OnInternalIdle();
+
+#if 0
static bool s_bFirstTime = TRUE;
if ( s_bFirstTime ) {
/*
*/
s_bFirstTime = FALSE;
}
- event.Skip();
+#endif
}
// Implementation: calculate the layout of the view rect
// fit the notebook page to the tab control's display area
- unsigned int nCount = m_pages.Count();
- for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) {
+ size_t nCount = m_pages.Count();
+ for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
wxNotebookPage *pPage = m_pages[nPage];
+ wxRect clientRect = GetAvailableClientSize();
if (pPage->IsShown())
{
- wxRect clientRect = GetAvailableClientSize();
pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height);
if ( pPage->GetAutoLayout() )
pPage->Layout();
m_notebook->GetEventHandler()->ProcessEvent(event);
}
+// Allows Vetoing
+bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId)
+{
+ bool retval = TRUE;
+
+ if (m_notebook)
+ {
+ wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_notebook->GetId());
+
+#if defined (__WIN16__)
+ int activatePos = activateId;
+ int deactivatePos = deactivateId;
+#else
+ // Translate from wxTabView's ids (which aren't position-dependent)
+ // to wxNotebook's (which are).
+ wxNotebookPage* pActive = (wxNotebookPage*) activateId;
+ wxNotebookPage* pDeactive = (wxNotebookPage*) deactivateId;
+
+ int activatePos = m_notebook->FindPagePosition(pActive);
+ int deactivatePos = m_notebook->FindPagePosition(pDeactive);
+
+#endif
+ event.SetEventObject(m_notebook);
+ event.SetSelection(activatePos);
+ event.SetOldSelection(deactivatePos);
+ if (m_notebook->GetEventHandler()->ProcessEvent(event))
+ {
+ retval = event.IsAllowed();
+ }
+ }
+ return retval;
+}