projects
/
wxWidgets.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Swap client data pointers in wxRearrangeList too.
[wxWidgets.git]
/
src
/
generic
/
notebook.cpp
diff --git
a/src/generic/notebook.cpp
b/src/generic/notebook.cpp
index c9d8269869161cc2d5098f281bf5d9dd3d901dfa..0d2a77c6e05e811679f1a5fedce96696e6c83431 100644
(file)
--- a/
src/generic/notebook.cpp
+++ b/
src/generic/notebook.cpp
@@
-32,10
+32,10
@@
#include "wx/string.h"
#include "wx/log.h"
#include "wx/dcclient.h"
#include "wx/string.h"
#include "wx/log.h"
#include "wx/dcclient.h"
+ #include "wx/settings.h"
#endif
#endif
-#include "wx/settings.h"
-#include "wx/generic/imaglist.h"
+#include "wx/imaglist.h"
#include "wx/generic/tabg.h"
// ----------------------------------------------------------------------------
#include "wx/generic/tabg.h"
// ----------------------------------------------------------------------------
@@
-49,10
+49,7
@@
// event table
// ----------------------------------------------------------------------------
// event table
// ----------------------------------------------------------------------------
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
-
-BEGIN_EVENT_TABLE(wxNotebook, wxControl)
+BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase)
EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange)
EVT_SIZE(wxNotebook::OnSize)
EVT_PAINT(wxNotebook::OnPaint)
EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange)
EVT_SIZE(wxNotebook::OnSize)
EVT_PAINT(wxNotebook::OnPaint)
@@
-61,8
+58,7
@@
BEGIN_EVENT_TABLE(wxNotebook, wxControl)
EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
END_EVENT_TABLE()
EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
END_EVENT_TABLE()
-IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
-IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
+IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase)
// ============================================================================
// implementation
// ============================================================================
// implementation
@@
-72,23
+68,43
@@
IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
// Private class
// ============================================================================
// Private class
// ============================================================================
+WX_DECLARE_HASH_MAP(int, wxNotebookPage*, wxIntegerHash, wxIntegerEqual,
+ wxIntToNotebookPageHashMap);
+
+WX_DECLARE_HASH_MAP(wxNotebookPage*, int, wxPointerHash, wxPointerEqual,
+ wxNotebookPageToIntHashMap);
+
// 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);
// 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);
+
virtual
~wxNotebookTabView(void);
// Called when a tab is activated
virtual void OnTabActivate(int activateId, int deactivateId);
// Allows vetoing
virtual bool OnTabPreActivate(int activateId, int deactivateId);
// Called when a tab is activated
virtual void OnTabActivate(int activateId, int deactivateId);
// Allows vetoing
virtual bool OnTabPreActivate(int activateId, int deactivateId);
+ // map integer ids used by wxTabView to wxNotebookPage pointers
+ int GetId(wxNotebookPage *page);
+ wxNotebookPage *GetPage(int id) { return m_idToPage[id]; }
+
protected:
protected:
- wxNotebook* m_notebook;
+ wxNotebook* m_notebook;
+
+private:
+ wxIntToNotebookPageHashMap m_idToPage;
+ wxNotebookPageToIntHashMap m_pageToId;
+ int m_nextid;
};
};
+static int GetPageId(wxTabView *tabview, wxNotebookPage *page)
+{
+ return static_cast<wxNotebookTabView*>(tabview)->GetId(page);
+}
+
// ----------------------------------------------------------------------------
// wxNotebook construction
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxNotebook construction
// ----------------------------------------------------------------------------
@@
-96,7
+112,7
@@
protected:
// common part of all ctors
void wxNotebook::Init()
{
// common part of all ctors
void wxNotebook::Init()
{
- m_tabView =
(wxNotebookTabView*)
NULL;
+ m_tabView = NULL;
m_nSelection = -1;
}
m_nSelection = -1;
}
@@
-130,13
+146,14
@@
bool wxNotebook::Create(wxWindow *parent,
// base init
SetName(name);
// base init
SetName(name);
+ if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
+ style |= wxBK_TOP;
+
m_windowId = id == wxID_ANY ? NewControlId() : id;
if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name))
return false;
m_windowId = id == wxID_ANY ? NewControlId() : id;
if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name))
return false;
- SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
-
SetTabView(new wxNotebookTabView(this));
return true;
SetTabView(new wxNotebookTabView(this));
return true;
@@
-163,12
+180,18
@@
int wxNotebook::SetSelection(size_t nPage)
wxNotebookPage* pPage = GetPage(nPage);
wxNotebookPage* pPage = GetPage(nPage);
- m_tabView->SetTabSelection(
(int) (long) pPage
);
+ m_tabView->SetTabSelection(
GetPageId(m_tabView, pPage)
);
// TODO
return 0;
}
// TODO
return 0;
}
+int wxNotebook::ChangeSelection(size_t nPage)
+{
+ // FIXME: currently it does generate events too
+ return SetSelection(nPage);
+}
+
#if 0
void wxNotebook::AdvanceSelection(bool bForward)
{
#if 0
void wxNotebook::AdvanceSelection(bool bForward)
{
@@
-188,7
+211,7
@@
bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
wxNotebookPage* page = GetPage(nPage);
if (page)
{
wxNotebookPage* page = GetPage(nPage);
if (page)
{
- m_tabView->SetTabText(
(int) (long) page
, strText);
+ m_tabView->SetTabText(
GetPageId(m_tabView, page)
, strText);
Refresh();
return true;
}
Refresh();
return true;
}
@@
-202,7
+225,7
@@
wxString wxNotebook::GetPageText(size_t nPage) const
wxNotebookPage* page = ((wxNotebook*)this)->GetPage(nPage);
if (page)
wxNotebookPage* page = ((wxNotebook*)this)->GetPage(nPage);
if (page)
- return m_tabView->GetTabText(
(int) (long) page
);
+ return m_tabView->GetTabText(
GetPageId(m_tabView, page)
);
else
return wxEmptyString;
}
else
return wxEmptyString;
}
@@
-259,7
+282,7
@@
bool wxNotebook::DeletePage(size_t nPage)
wxNotebookPage* pPage = GetPage(nPage);
wxNotebookPage* pPage = GetPage(nPage);
- m_tabView->RemoveTab(
(int) (long) pPage
);
+ m_tabView->RemoveTab(
GetPageId(m_tabView, pPage)
);
m_pages.Remove(pPage);
delete pPage;
m_pages.Remove(pPage);
delete pPage;
@@
-273,7
+296,7
@@
bool wxNotebook::DeletePage(size_t nPage)
{
m_nSelection = -1;
{
m_nSelection = -1;
- m_tabView->SetTabSelection(
(int) (long) GetPage(0
), false);
+ m_tabView->SetTabSelection(
GetPageId(m_tabView, GetPage(0)
), false);
if (m_nSelection != 0)
ChangePage(-1, 0);
if (m_nSelection != 0)
ChangePage(-1, 0);
@@
-308,7
+331,7
@@
wxWindow* wxNotebook::DoRemovePage(size_t nPage)
wxNotebookPage* pPage = GetPage(nPage);
wxNotebookPage* pPage = GetPage(nPage);
- m_tabView->RemoveTab(
(int) (long) pPage
);
+ m_tabView->RemoveTab(
GetPageId(m_tabView, pPage)
);
m_pages.Remove(pPage);
m_pages.Remove(pPage);
@@
-387,7
+410,7
@@
bool wxNotebook::InsertPage(size_t nPage,
wxASSERT( pPage != NULL );
wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false );
wxASSERT( pPage != NULL );
wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false );
- m_tabView->AddTab(
(int) (long) pPage
, strText);
+ m_tabView->AddTab(
GetPageId(m_tabView, pPage)
, strText);
if (!bSelect)
pPage->Show(false);
if (!bSelect)
pPage->Show(false);
@@
-399,7
+422,7
@@
bool wxNotebook::InsertPage(size_t nPage,
{
// This will cause ChangePage to be called, via OnSelPage
{
// This will cause ChangePage to be called, via OnSelPage
- m_tabView->SetTabSelection(
(int) (long) pPage
, true);
+ m_tabView->SetTabSelection(
GetPageId(m_tabView, pPage)
, true);
}
// some page must be selected: either this one or the first one if there is
}
// some page must be selected: either this one or the first one if there is
@@
-518,7
+541,7
@@
bool wxNotebook::RefreshLayout(bool force)
return true;
}
return true;
}
-void wxNotebook::OnSelChange(wx
Notebook
Event& event)
+void wxNotebook::OnSelChange(wx
BookCtrl
Event& event)
{
// is it our tab control?
if ( event.GetEventObject() == this )
{
// is it our tab control?
if ( event.GetEventObject() == this )
@@
-542,15
+565,17
@@
void wxNotebook::OnSetFocus(wxFocusEvent& event)
void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
{
void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
{
- if ( event.IsWindowChange() ) {
+ if ( event.IsWindowChange() )
+ {
// change pages
AdvanceSelection(event.GetDirection());
}
else {
// pass to the parent
// change pages
AdvanceSelection(event.GetDirection());
}
else {
// pass to the parent
- if ( GetParent() ) {
+ if ( GetParent() )
+ {
event.SetCurrentFocus(this);
event.SetCurrentFocus(this);
- GetParent()->ProcessEvent(event);
+ GetParent()->Process
Window
Event(event);
}
}
}
}
}
}
@@
-653,7
+678,8
@@
wxRect wxNotebook::GetAvailableClientSize()
IMPLEMENT_CLASS(wxNotebookTabView, wxTabView)
IMPLEMENT_CLASS(wxNotebookTabView, wxTabView)
-wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style): wxTabView(style)
+wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style)
+ : wxTabView(style), m_nextid(1)
{
m_notebook = notebook;
{
m_notebook = notebook;
@@
-666,18
+692,31
@@
wxNotebookTabView::~wxNotebookTabView(void)
{
}
{
}
+int wxNotebookTabView::GetId(wxNotebookPage *page)
+{
+ int& id = m_pageToId[page];
+
+ if (!id)
+ {
+ id = m_nextid++;
+ m_idToPage[id] = page;
+ }
+
+ return id;
+}
+
// Called when a tab is activated
void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId)
{
if (!m_notebook)
return;
// Called when a tab is activated
void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId)
{
if (!m_notebook)
return;
- wx
Notebook
Event event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId());
+ wx
BookCtrl
Event event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId());
// Translate from wxTabView's ids (which aren't position-dependent)
// to wxNotebook's (which are).
// Translate from wxTabView's ids (which aren't position-dependent)
// to wxNotebook's (which are).
- wxNotebookPage* pActive =
(wxNotebookPage*) activateId
;
- wxNotebookPage* pDeactive =
(wxNotebookPage*) deactivateId
;
+ wxNotebookPage* pActive =
GetPage(activateId)
;
+ wxNotebookPage* pDeactive =
GetPage(deactivateId)
;
int activatePos = m_notebook->FindPagePosition(pActive);
int deactivatePos = m_notebook->FindPagePosition(pDeactive);
int activatePos = m_notebook->FindPagePosition(pActive);
int deactivatePos = m_notebook->FindPagePosition(pDeactive);
@@
-695,12
+734,12
@@
bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId)
if (m_notebook)
{
if (m_notebook)
{
- wx
Notebook
Event event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_notebook->GetId());
+ wx
BookCtrl
Event event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_notebook->GetId());
// Translate from wxTabView's ids (which aren't position-dependent)
// to wxNotebook's (which are).
// Translate from wxTabView's ids (which aren't position-dependent)
// to wxNotebook's (which are).
- wxNotebookPage* pActive =
(wxNotebookPage*) activateId
;
- wxNotebookPage* pDeactive =
(wxNotebookPage*) deactivateId
;
+ wxNotebookPage* pActive =
GetPage(activateId)
;
+ wxNotebookPage* pDeactive =
GetPage(deactivateId)
;
int activatePos = m_notebook->FindPagePosition(pActive);
int deactivatePos = m_notebook->FindPagePosition(pDeactive);
int activatePos = m_notebook->FindPagePosition(pActive);
int deactivatePos = m_notebook->FindPagePosition(pDeactive);