created wxBookCtrl which will be tje base class for wxNotebook and wxListbook; moved almost all of wxNotebookBase code into it

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23057 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-08-20 22:57:07 +00:00
parent 87f086bcbd
commit 15aad3b938
13 changed files with 526 additions and 348 deletions

202
src/common/bookctrl.cpp Normal file
View File

@@ -0,0 +1,202 @@
///////////////////////////////////////////////////////////////////////////////
// Name: common/bookctrl.cpp
// Purpose: wxBookCtrl implementation
// Author: Vadim Zeitlin
// Modified by:
// Created: 19.08.03
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "bookctrl.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_BOOKCTRL
#include "wx/imaglist.h"
#include "wx/bookctrl.h"
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// constructors and destructors
// ----------------------------------------------------------------------------
void wxBookCtrl::Init()
{
m_imageList = NULL;
m_ownsImageList = false;
}
bool
wxBookCtrl::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
return wxControl::Create
(
parent,
id,
pos,
size,
style,
wxDefaultValidator,
name
);
}
wxBookCtrl::~wxBookCtrl()
{
if ( m_ownsImageList )
{
// may be NULL, ok
delete m_imageList;
}
}
// ----------------------------------------------------------------------------
// image list
// ----------------------------------------------------------------------------
void wxBookCtrl::SetImageList(wxImageList *imageList)
{
if ( m_ownsImageList )
{
// may be NULL, ok
delete m_imageList;
m_ownsImageList = false;
}
m_imageList = imageList;
}
void wxBookCtrl::AssignImageList(wxImageList* imageList)
{
SetImageList(imageList);
m_ownsImageList = true;
}
// ----------------------------------------------------------------------------
// geometry
// ----------------------------------------------------------------------------
void wxBookCtrl::SetPageSize(const wxSize& size)
{
SetClientSize(CalcSizeFromPage(size));
}
wxSize wxBookCtrl::DoGetBestSize() const
{
wxSize bestSize;
// iterate over all pages, get the largest width and height
const size_t nCount = m_pages.size();
for ( size_t nPage = 0; nPage < nCount; nPage++ )
{
wxWindow *pPage = m_pages[nPage];
wxSize childBestSize(pPage->GetBestSize());
if ( childBestSize.x > bestSize.x )
bestSize.x = childBestSize.x;
if ( childBestSize.y > bestSize.y )
bestSize.y = childBestSize.y;
}
// convert display area to window area, adding the size neccessary for the
// tabs
return CalcSizeFromPage(bestSize);
}
// ----------------------------------------------------------------------------
// pages management
// ----------------------------------------------------------------------------
bool
wxBookCtrl::InsertPage(size_t nPage,
wxWindow *page,
const wxString& text,
bool bSelect,
int imageId)
{
wxCHECK_MSG( page, false, _T("NULL page in wxBookCtrl::InsertPage()") );
wxCHECK_MSG( nPage < m_pages.size(), false,
_T("invalid page index in wxBookCtrl::InsertPage()") );
m_pages.Insert(page, nPage);
return true;
}
bool wxBookCtrl::DeletePage(size_t nPage)
{
wxWindow *page = DoRemovePage(nPage);
if ( !page )
return false;
delete page;
return true;
}
wxWindow *wxBookCtrl::DoRemovePage(size_t nPage)
{
wxCHECK_MSG( nPage < m_pages.size(), NULL,
_T("invalid page index in wxBookCtrl::DoRemovePage()") );
wxWindow *pageRemoved = m_pages[nPage];
m_pages.RemoveAt(nPage);
return pageRemoved;
}
int wxBookCtrl::GetNextPage(bool forward) const
{
int nPage;
int nMax = GetPageCount();
if ( nMax-- ) // decrement it to get the last valid index
{
int nSel = GetSelection();
// change selection wrapping if it becomes invalid
nPage = forward ? nSel == nMax ? 0
: nSel + 1
: nSel == 0 ? nMax
: nSel - 1;
}
else // notebook is empty, no next page
{
nPage = -1;
}
return nPage;
}
#endif // wxUSE_BOOKCTRL

View File

@@ -33,85 +33,12 @@
#ifndef WX_PRECOMP
#endif //WX_PRECOMP
#include "wx/imaglist.h"
#include "wx/notebook.h"
#ifdef __GNUWIN32_OLD__
#include "wx/msw/gnuwin32/extra.h"
#endif
#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
#include "wx/msw/private.h"
#include <commctrl.h>
#include "wx/msw/winundef.h"
#endif
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// constructors and destructors
// ----------------------------------------------------------------------------
void wxNotebookBase::Init()
{
m_imageList = NULL;
m_ownsImageList = FALSE;
}
bool
wxNotebookBase::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
return wxControl::Create
(
parent,
id,
pos,
size,
style,
wxDefaultValidator,
name
);
}
wxNotebookBase::~wxNotebookBase()
{
if ( m_ownsImageList )
{
// may be NULL, ok
delete m_imageList;
}
}
// ----------------------------------------------------------------------------
// image list
// ----------------------------------------------------------------------------
void wxNotebookBase::SetImageList(wxImageList* imageList)
{
if ( m_ownsImageList )
{
// may be NULL, ok
delete m_imageList;
m_ownsImageList = FALSE;
}
m_imageList = imageList;
}
void wxNotebookBase::AssignImageList(wxImageList* imageList)
{
SetImageList(imageList);
m_ownsImageList = TRUE;
}
// ----------------------------------------------------------------------------
// geometry
// ----------------------------------------------------------------------------
@@ -136,77 +63,5 @@ wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage) const
return sizeTotal;
}
wxSize wxNotebookBase::DoGetBestSize() const
{
wxSize bestSize;
// iterate over all pages, get the largest width and height
const size_t nCount = m_pages.Count();
for ( size_t nPage = 0; nPage < nCount; nPage++ )
{
wxNotebookPage *pPage = m_pages[nPage];
wxSize childBestSize(pPage->GetBestSize());
if ( childBestSize.x > bestSize.x )
bestSize.x = childBestSize.x;
if ( childBestSize.y > bestSize.y )
bestSize.y = childBestSize.y;
}
// convert display area to window area, adding the size neccessary for the
// tabs
return CalcSizeFromPage(bestSize);
}
// ----------------------------------------------------------------------------
// pages management
// ----------------------------------------------------------------------------
bool wxNotebookBase::DeletePage(int nPage)
{
wxNotebookPage *page = DoRemovePage(nPage);
if ( !page )
return FALSE;
delete page;
return TRUE;
}
wxNotebookPage *wxNotebookBase::DoRemovePage(int nPage)
{
wxCHECK_MSG( nPage >= 0 && (size_t)nPage < m_pages.GetCount(), NULL,
_T("invalid page index in wxNotebookBase::DoRemovePage()") );
wxNotebookPage *pageRemoved = m_pages[nPage];
m_pages.RemoveAt(nPage);
return pageRemoved;
}
int wxNotebookBase::GetNextPage(bool forward) const
{
int nPage;
int nMax = GetPageCount();
if ( nMax-- ) // decrement it to get the last valid index
{
int nSel = GetSelection();
// change selection wrapping if it becomes invalid
nPage = forward ? nSel == nMax ? 0
: nSel + 1
: nSel == 0 ? nMax
: nSel - 1;
}
else // notebook is empty, no next page
{
nPage = -1;
}
return nPage;
}
#endif // wxUSE_NOTEBOOK

View File

@@ -155,7 +155,7 @@ int wxNotebook::GetRowCount() const
return 0;
}
int wxNotebook::SetSelection(int nPage)
int wxNotebook::SetSelection(size_t nPage)
{
if (nPage == -1)
return 0;
@@ -185,7 +185,7 @@ void wxNotebook::AdvanceSelection(bool bForward)
}
#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__)
@@ -204,7 +204,7 @@ bool wxNotebook::SetPageText(int nPage, const wxString& strText)
return FALSE;
}
wxString wxNotebook::GetPageText(int nPage) const
wxString wxNotebook::GetPageText(size_t nPage) const
{
wxASSERT( IS_VALID_PAGE(nPage) );
@@ -219,7 +219,7 @@ wxString wxNotebook::GetPageText(int nPage) const
#endif
}
int wxNotebook::GetPageImage(int nPage) const
int wxNotebook::GetPageImage(size_t nPage) const
{
wxASSERT( IS_VALID_PAGE(nPage) );
@@ -227,7 +227,7 @@ int wxNotebook::GetPageImage(int nPage) const
return 0;
}
bool wxNotebook::SetPageImage(int nPage, int nImage)
bool wxNotebook::SetPageImage(size_t nPage, int nImage)
{
wxASSERT( IS_VALID_PAGE(nPage) );
@@ -258,7 +258,7 @@ void wxNotebook::SetTabSize(const wxSize& sz)
// ----------------------------------------------------------------------------
// 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 );
@@ -310,7 +310,7 @@ bool wxNotebook::DeletePage(wxNotebookPage* page)
}
// remove one page from the notebook
bool wxNotebook::RemovePage(int nPage)
bool wxNotebook::RemovePage(size_t nPage)
{
wxCHECK( IS_VALID_PAGE(nPage), FALSE );
@@ -368,8 +368,8 @@ 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;
@@ -381,8 +381,8 @@ bool wxNotebook::DeleteAllPages()
{
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];
@@ -392,7 +392,7 @@ bool wxNotebook::DeleteAllPages()
}
// 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,
@@ -523,8 +523,8 @@ bool wxNotebook::RefreshLayout(bool force)
// 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())

View File

@@ -133,14 +133,14 @@ bool wxNotebook::Create(wxWindow *parent,
// wxNotebook page titles and images
// ----------------------------------------------------------------------------
wxString wxNotebook::GetPageText(int nPage) const
wxString wxNotebook::GetPageText(size_t nPage) const
{
wxCHECK_MSG( IS_VALID_PAGE(nPage), _T(""), _T("invalid notebook page") );
return m_titles[nPage];
}
bool wxNotebook::SetPageText(int nPage, const wxString& strText)
bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
{
wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("invalid notebook page") );
@@ -163,14 +163,14 @@ bool wxNotebook::SetPageText(int nPage, const wxString& strText)
return TRUE;
}
int wxNotebook::GetPageImage(int nPage) const
int wxNotebook::GetPageImage(size_t nPage) const
{
wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") );
return m_images[nPage];
}
bool wxNotebook::SetPageImage(int nPage, int nImage)
bool wxNotebook::SetPageImage(size_t nPage, int nImage)
{
wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("invalid notebook page") );
@@ -202,7 +202,7 @@ wxNotebook::~wxNotebook()
// wxNotebook page switching
// ----------------------------------------------------------------------------
int wxNotebook::SetSelection(int nPage)
int wxNotebook::SetSelection(size_t nPage)
{
wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") );
@@ -277,13 +277,13 @@ int wxNotebook::SetSelection(int nPage)
// wxNotebook pages adding/deleting
// ----------------------------------------------------------------------------
bool wxNotebook::InsertPage(int nPage,
bool wxNotebook::InsertPage(size_t nPage,
wxNotebookPage *pPage,
const wxString& strText,
bool bSelect,
int imageId)
{
int nPages = GetPageCount();
size_t nPages = GetPageCount();
wxCHECK_MSG( nPage == nPages || IS_VALID_PAGE(nPage), FALSE,
_T("invalid notebook page in InsertPage()") );
@@ -360,7 +360,7 @@ bool wxNotebook::DeleteAllPages()
return TRUE;
}
wxNotebookPage *wxNotebook::DoRemovePage(int nPage)
wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage)
{
wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, _T("invalid notebook page") );