projects
/
wxWidgets.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added test bitmap.
[wxWidgets.git]
/
src
/
generic
/
notebook.cpp
diff --git
a/src/generic/notebook.cpp
b/src/generic/notebook.cpp
index ec05ba70b4f967934ca7f60f86bcf3e5c9657ec2..1d62732c1a160649971cf9fbf27b5b33d594fab5 100644
(file)
--- a/
src/generic/notebook.cpp
+++ b/
src/generic/notebook.cpp
@@
-1,6
+1,6
@@
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-// Name: notebook.cpp
-// Purpose: implementation of wxNotebook
+// Name:
src/generic/
notebook.cpp
+// Purpose:
generic
implementation of wxNotebook
// Author: Julian Smart
// Modified by:
// Created: 17/09/98
// Author: Julian Smart
// Modified by:
// Created: 17/09/98
@@
-17,29
+17,25
@@
// headers
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
-#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"
#ifdef __BORLANDC__
// For compilers that support precompilation, includes "wx.h".
#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"
// ----------------------------------------------------------------------------
@@
-47,7
+43,7
@@
// ----------------------------------------------------------------------------
// check that the page index is valid
// ----------------------------------------------------------------------------
// check that the page index is valid
-#define IS_VALID_PAGE(nPage) ((
(nPage) >= 0) && ((nPage) < GetPageCount()
))
+#define IS_VALID_PAGE(nPage) ((
nPage) < GetPageCount(
))
// ----------------------------------------------------------------------------
// event table
// ----------------------------------------------------------------------------
// event table
@@
-76,23
+72,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 wx_static_cast(wxNotebookTabView*, tabview)->GetId(page);
+}
+
// ----------------------------------------------------------------------------
// wxNotebook construction
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxNotebook construction
// ----------------------------------------------------------------------------
@@
-134,6
+150,9
@@
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))
m_windowId = id == wxID_ANY ? NewControlId() : id;
if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name))
@@
-167,7
+186,7
@@
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;
@@
-192,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;
}
@@
-206,12
+225,12
@@
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;
}
-int wxNotebook::GetPageImage(size_t
nPage
) const
+int wxNotebook::GetPageImage(size_t
WXUNUSED_UNLESS_DEBUG(nPage)
) const
{
wxASSERT( IS_VALID_PAGE(nPage) );
{
wxASSERT( IS_VALID_PAGE(nPage) );
@@
-219,7
+238,8
@@
int wxNotebook::GetPageImage(size_t nPage) const
return 0;
}
return 0;
}
-bool wxNotebook::SetPageImage(size_t nPage, int nImage)
+bool wxNotebook::SetPageImage(size_t WXUNUSED_UNLESS_DEBUG(nPage),
+ int WXUNUSED(nImage))
{
wxASSERT( IS_VALID_PAGE(nPage) );
{
wxASSERT( IS_VALID_PAGE(nPage) );
@@
-228,19
+248,19
@@
bool wxNotebook::SetPageImage(size_t nPage, int nImage)
}
// set the size (the same for all pages)
}
// set the size (the same for all pages)
-void wxNotebook::SetPageSize(const wxSize&
size
)
+void wxNotebook::SetPageSize(const wxSize&
WXUNUSED(size)
)
{
// TODO
}
// set the padding between tabs (in pixels)
{
// TODO
}
// set the padding between tabs (in pixels)
-void wxNotebook::SetPadding(const wxSize&
padding
)
+void wxNotebook::SetPadding(const wxSize&
WXUNUSED(padding)
)
{
// TODO
}
// set the size of the tabs for wxNB_FIXEDWIDTH controls
{
// TODO
}
// set the size of the tabs for wxNB_FIXEDWIDTH controls
-void wxNotebook::SetTabSize(const wxSize&
sz
)
+void wxNotebook::SetTabSize(const wxSize&
WXUNUSED(sz)
)
{
// TODO
}
{
// TODO
}
@@
-262,24
+282,24
@@
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;
if (m_pages.GetCount() == 0)
{
m_pages.Remove(pPage);
delete pPage;
if (m_pages.GetCount() == 0)
{
- m_nSelection = -1;
- m_tabView->SetTabSelection(-1, false);
+
m_nSelection = -1;
+
m_tabView->SetTabSelection(-1, false);
}
else if (m_nSelection > -1)
{
}
else if (m_nSelection > -1)
{
- 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);
}
RefreshLayout(false);
}
RefreshLayout(false);
@@
-311,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);
@@
-385,12
+405,12
@@
bool wxNotebook::InsertPage(size_t nPage,
wxNotebookPage *pPage,
const wxString& strText,
bool bSelect,
wxNotebookPage *pPage,
const wxString& strText,
bool bSelect,
- int
imageId
)
+ int
WXUNUSED(imageId)
)
{
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);
@@
-402,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
@@
-656,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;
@@
-669,6
+690,19
@@
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)
{
// Called when a tab is activated
void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId)
{
@@
-679,8
+713,8
@@
void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId)
// 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);
@@
-702,8
+736,8
@@
bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId)
// 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);
@@
-719,4
+753,4
@@
bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId)
return retval;
}
return retval;
}
-#endif //
__WXPALMOS__
+#endif //
wxUSE_NOTEBOOK