projects
/
wxWidgets.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix compilation for MinGW with wxUSE_IPV6==1.
[wxWidgets.git]
/
src
/
generic
/
notebook.cpp
diff --git
a/src/generic/notebook.cpp
b/src/generic/notebook.cpp
index fe376a12022086889fe081e22f57a9526a26c710..560ea1000f97381aaf2452d58c2dba0e30ce558f 100644
(file)
--- a/
src/generic/notebook.cpp
+++ b/
src/generic/notebook.cpp
@@
-21,17
+21,21
@@
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#include "wx/wxprec.h"
#ifdef __BORLANDC__
-#pragma hdrstop
+
#pragma hdrstop
#endif
#endif
-#if
ndef __WXPALMOS__
+#if
wxUSE_NOTEBOOK
-#include "wx/string.h"
-#include "wx/log.h"
-#include "wx/settings.h"
-#include "wx/generic/imaglist.h"
#include "wx/notebook.h"
#include "wx/notebook.h"
-#include "wx/dcclient.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/string.h"
+ #include "wx/log.h"
+ #include "wx/dcclient.h"
+ #include "wx/settings.h"
+#endif
+
+#include "wx/imaglist.h"
#include "wx/generic/tabg.h"
// ----------------------------------------------------------------------------
#include "wx/generic/tabg.h"
// ----------------------------------------------------------------------------
@@
-45,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)
@@
-57,9
+58,6
@@
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)
-
// ============================================================================
// implementation
// ============================================================================
// ============================================================================
// implementation
// ============================================================================
@@
-68,23
+66,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:
// 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);
+
wxNotebookTabView(wxNotebook* notebook, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
+
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
// ----------------------------------------------------------------------------
@@
-92,8
+110,8
@@
protected:
// common part of all ctors
void wxNotebook::Init()
{
// common part of all ctors
void wxNotebook::Init()
{
- m_tabView =
(wxNotebookTabView*)
NULL;
- m_
nS
election = -1;
+ m_tabView = NULL;
+ m_
s
election = -1;
}
// default for dynamic class
}
// default for dynamic class
@@
-126,13
+144,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;
@@
-159,12
+178,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)
{
@@
-184,7
+209,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;
}
@@
-198,7
+223,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;
}
@@
-247,32
+272,32
@@
bool wxNotebook::DeletePage(size_t nPage)
{
wxCHECK( IS_VALID_PAGE(nPage), false );
{
wxCHECK( IS_VALID_PAGE(nPage), false );
- if (m_
nS
election != -1)
+ if (m_
s
election != -1)
{
{
- m_pages[m_
nS
election]->Show(false);
- m_pages[m_
nS
election]->Lower();
+ m_pages[m_
s
election]->Show(false);
+ m_pages[m_
s
election]->Lower();
}
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;
if (m_pages.GetCount() == 0)
{
m_pages.Remove(pPage);
delete pPage;
if (m_pages.GetCount() == 0)
{
-
m_nS
election = -1;
- m_tabView->SetTabSelection(-1, false);
+
m_s
election = -1;
+
m_tabView->SetTabSelection(-1, false);
}
}
- else if (m_
nS
election > -1)
+ else if (m_
s
election > -1)
{
{
-
m_nS
election = -1;
+
m_s
election = -1;
-
m_tabView->SetTabSelection((int) (long) GetPage(0
), false);
+
m_tabView->SetTabSelection(GetPageId(m_tabView, GetPage(0)
), false);
-
if (m_nS
election != 0)
- ChangePage(-1, 0);
+
if (m_s
election != 0)
+
ChangePage(-1, 0);
}
RefreshLayout(false);
}
RefreshLayout(false);
@@
-304,22
+329,22
@@
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);
if (m_pages.GetCount() == 0)
{
m_pages.Remove(pPage);
if (m_pages.GetCount() == 0)
{
- m_
nS
election = -1;
+ m_
s
election = -1;
m_tabView->SetTabSelection(-1, true);
}
m_tabView->SetTabSelection(-1, true);
}
- else if (m_
nS
election > -1)
+ else if (m_
s
election > -1)
{
// Only change the selection if the page we
// deleted was the selection.
{
// Only change the selection if the page we
// deleted was the selection.
- if (nPage == (size_t)m_
nS
election)
+ if (nPage == (size_t)m_
s
election)
{
{
- m_
nS
election = -1;
+ m_
s
election = -1;
// Select the first tab. Generates a ChangePage.
m_tabView->SetTabSelection(0, true);
}
// Select the first tab. Generates a ChangePage.
m_tabView->SetTabSelection(0, true);
}
@@
-328,8
+353,8
@@
wxWindow* wxNotebook::DoRemovePage(size_t nPage)
// We must adjust which tab we think is selected.
// If greater than the page we deleted, it must be moved down
// a notch.
// We must adjust which tab we think is selected.
// If greater than the page we deleted, it must be moved down
// a notch.
- if (size_t(m_
nS
election) > nPage)
- m_
nS
election -- ;
+ if (size_t(m_
s
election) > nPage)
+ m_
s
election -- ;
}
}
}
}
@@
-383,7
+408,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);
@@
-395,12
+420,12
@@
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
// still no selection
}
// some page must be selected: either this one or the first one if there is
// still no selection
- if ( m_
nS
election == -1 )
+ if ( m_
s
election == -1 )
ChangePage(-1, 0);
RefreshLayout(false);
ChangePage(-1, 0);
RefreshLayout(false);
@@
-514,12
+539,12
@@
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 )
{
- if (event.GetSelection() != m_
nS
election)
+ if (event.GetSelection() != m_
s
election)
ChangePage(event.GetOldSelection(), event.GetSelection());
}
ChangePage(event.GetOldSelection(), event.GetSelection());
}
@@
-530,23
+555,25
@@
void wxNotebook::OnSelChange(wxNotebookEvent& event)
void wxNotebook::OnSetFocus(wxFocusEvent& event)
{
// set focus to the currently selected page if any
void wxNotebook::OnSetFocus(wxFocusEvent& event)
{
// set focus to the currently selected page if any
- if ( m_
nS
election != -1 )
- m_pages[m_
nS
election]->SetFocus();
+ if ( m_
s
election != -1 )
+ m_pages[m_
s
election]->SetFocus();
event.Skip();
}
void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
{
event.Skip();
}
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);
}
}
}
}
}
}
@@
-599,7
+626,7
@@
void wxNotebook::ChangePage(int nOldSel, int nSel)
pPage->Raise();
pPage->SetFocus();
pPage->Raise();
pPage->SetFocus();
- m_
nS
election = nSel;
+ m_
s
election = nSel;
}
void wxNotebook::OnMouseEvent(wxMouseEvent& event)
}
void wxNotebook::OnMouseEvent(wxMouseEvent& event)
@@
-649,7
+676,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;
@@
-662,18
+690,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);
@@
-691,12
+732,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);
@@
-712,4
+753,4
@@
bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId)
return retval;
}
return retval;
}
-#endif //
__WXPALMOS__
+#endif //
wxUSE_NOTEBOOK