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

221
include/wx/bookctrl.h Normal file
View File

@ -0,0 +1,221 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/bookctrl.h
// Purpose: wxBookCtrl: common base class for wxList/Tree/Notebook
// Author: Vadim Zeitlin
// Modified by:
// Created: 19.08.03
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_BOOKCTRL_H_
#define _WX_BOOKCTRL_H_
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface "bookctrl.h"
#endif
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/defs.h"
#if wxUSE_BOOKCTRL
#include "wx/control.h"
#include "wx/dynarray.h"
WX_DEFINE_EXPORTED_ARRAY_NO_PTR(wxWindow *, wxArrayPages);
class WXDLLEXPORT wxImageList;
// ----------------------------------------------------------------------------
// wxBookCtrl
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxBookCtrl : public wxControl
{
public:
// construction
// ------------
wxBookCtrl()
{
Init();
}
wxBookCtrl(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxEmptyString)
{
Init();
(void)Create(parent, id, pos, size, style, name);
}
// quasi ctor
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxEmptyString);
// dtor
virtual ~wxBookCtrl();
// accessors
// ---------
// get number of pages in the dialog
virtual size_t GetPageCount() const { return m_pages.size(); }
// get the panel which represents the given page
virtual wxWindow *GetPage(size_t n) { return m_pages[n]; }
// get the currently selected page or wxNOT_FOUND if none
virtual int GetSelection() const = 0;
// set/get the title of a page
virtual bool SetPageText(size_t n, const wxString& strText) = 0;
virtual wxString GetPageText(size_t n) const = 0;
// image list stuff: each page may have an image associated with it (all
// images belong to the same image list)
// ---------------------------------------------------------------------
// sets the image list to use, it is *not* deleted by the control
virtual void SetImageList(wxImageList *imageList);
// as SetImageList() but we will delete the image list ourselves
void AssignImageList(wxImageList *imageList);
// get pointer (may be NULL) to the associated image list
wxImageList* GetImageList() const { return m_imageList; }
// sets/returns item's image index in the current image list
virtual int GetPageImage(size_t n) const = 0;
virtual bool SetPageImage(size_t n, int imageId) = 0;
// geometry
// --------
// resize the notebook so that all pages will have the specified size
virtual void SetPageSize(const wxSize& size);
// calculate the size of the control from the size of its page
virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0;
// operations
// ----------
// remove one page from the control and delete it
virtual bool DeletePage(size_t n);
// remove one page from the notebook, without deleting it
virtual bool RemovePage(size_t n) { return DoRemovePage(n) != NULL; }
// remove all pages and delete them
virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages); return true; }
// adds a new page to the control
virtual bool AddPage(wxWindow *page,
const wxString& text,
bool bSelect = false,
int imageId = -1)
{
return InsertPage(GetPageCount(), page, text, bSelect, imageId);
}
// the same as AddPage(), but adds the page at the specified position
virtual bool InsertPage(size_t n,
wxWindow *page,
const wxString& text,
bool bSelect = false,
int imageId = -1) = 0;
// set the currently selected page, return the index of the previously
// selected one (or -1 on error)
//
// NB: this function will _not_ generate PAGE_CHANGING/ED events
virtual int SetSelection(size_t n) = 0;
// cycle thru the pages
void AdvanceSelection(bool forward = true)
{
int nPage = GetNextPage(forward);
if ( nPage != -1 )
{
// cast is safe because of the check above
SetSelection((size_t)nPage);
}
}
protected:
// remove the page and return a pointer to it
virtual wxWindow *DoRemovePage(size_t page) = 0;
// our best size is the size which fits all our pages
virtual wxSize DoGetBestSize() const;
// helper: get the next page wrapping if we reached the end
int GetNextPage(bool forward) const;
// common part of all ctors
void Init();
// the array of all pages of this control
wxArrayPages m_pages;
// the associated image list or NULL
wxImageList *m_imageList;
// true if we must delete m_imageList
bool m_ownsImageList;
DECLARE_NO_COPY_CLASS(wxBookCtrl)
};
// ----------------------------------------------------------------------------
// wxBookCtrlEvent: page changing events generated by derived classes
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxBookCtrlEvent : public wxNotifyEvent
{
public:
wxBookCtrlEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
int nSel = -1, int nOldSel = -1)
: wxNotifyEvent(commandType, id)
{
m_nSel = nSel;
m_nOldSel = nOldSel;
}
// accessors
// the currently selected page (-1 if none)
int GetSelection() const { return m_nSel; }
void SetSelection(int nSel) { m_nSel = nSel; }
// the page that was selected before the change (-1 if none)
int GetOldSelection() const { return m_nOldSel; }
void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }
private:
int m_nSel, // currently selected page
m_nOldSel; // previously selected page
};
#endif // wxUSE_BOOKCTRL
#endif // _WX_BOOKCTRL_H_

View File

@ -891,6 +891,20 @@
# endif
#endif /* controls */
#if defined(wxUSE_NOTEBOOK)
# if defined(wxUSE_BOOKCTRL) && !wxUSE_BOOKCTRL
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxUSE_BOOKCTRL must be set."
# else
# undef wxUSE_BOOKCTRL
# endif
# endif
# ifndef wxUSE_BOOKCTRL
# define wxUSE_BOOKCTRL 1
# endif
#endif /* wxUSE_NOTEBOOK */
/* wxUniv-specific dependencies */
#if defined(__WXUNIVERSAL__)
# if (wxUSE_COMBOBOX || wxUSE_MENUS) && !wxUSE_POPUPWIN

View File

@ -66,23 +66,23 @@ public:
// set the currently selected page, return the index of the previously
// selected one (or -1 on error)
// NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
int SetSelection(int nPage);
int SetSelection(size_t nPage);
// cycle thru the tabs
// void AdvanceSelection(bool bForward = TRUE);
// get the currently selected page
int GetSelection() const { return m_nSelection; }
// set/get the title of a page
bool SetPageText(int nPage, const wxString& strText);
wxString GetPageText(int nPage) const;
bool SetPageText(size_t nPage, const wxString& strText);
wxString GetPageText(size_t nPage) const;
// get the number of rows for a control with wxNB_MULTILINE style (not all
// versions support it - they will always return 1 then)
virtual int GetRowCount() const ;
// sets/returns item's image index in the current image list
int GetPageImage(int nPage) const;
bool SetPageImage(int nPage, int nImage);
int GetPageImage(size_t nPage) const;
bool SetPageImage(size_t nPage, int nImage);
// control the appearance of the notebook pages
// set the size (the same for all pages)
@ -96,15 +96,15 @@ public:
// operations
// ----------
// remove one page from the notebook, and delete the page.
bool DeletePage(int nPage);
bool DeletePage(size_t nPage);
bool DeletePage(wxNotebookPage* page);
// remove one page from the notebook, without deleting the page.
bool RemovePage(int nPage);
bool RemovePage(size_t nPage);
bool RemovePage(wxNotebookPage* page);
// remove all pages
bool DeleteAllPages();
// the same as AddPage(), but adds it at the specified position
bool InsertPage(int nPage,
bool InsertPage(size_t nPage,
wxNotebookPage *pPage,
const wxString& strText,
bool bSelect = FALSE,

View File

@ -56,17 +56,17 @@ public:
// set the currently selected page, return the index of the previously
// selected one (or -1 on error)
// NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
int SetSelection(int nPage);
int SetSelection(size_t nPage);
// get the currently selected page
int GetSelection() const;
// set/get the title of a page
bool SetPageText(int nPage, const wxString& strText);
wxString GetPageText(int nPage) const;
bool SetPageText(size_t nPage, const wxString& strText);
wxString GetPageText(size_t nPage) const;
// sets/returns item's image index in the current image list
int GetPageImage(int nPage) const;
bool SetPageImage(int nPage, int nImage);
int GetPageImage(size_t nPage) const;
bool SetPageImage(size_t nPage, int nImage);
// control the appearance of the notebook pages
// set the size (the same for all pages)
@ -79,7 +79,7 @@ public:
// operations
// ----------
// remove one page from the notebook
bool DeletePage(int nPage);
bool DeletePage(size_t nPage);
// remove all pages
bool DeleteAllPages();
@ -127,7 +127,7 @@ public:
protected:
// remove one page from the notebook but do not destroy it
virtual wxNotebookPage *DoRemovePage(int nPage);
virtual wxNotebookPage *DoRemovePage(size_t nPage);
private:
// the padding set by SetPadding()

View File

@ -56,17 +56,17 @@ public:
// set the currently selected page, return the index of the previously
// selected one (or -1 on error)
// NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
int SetSelection(int nPage);
int SetSelection(size_t nPage);
// get the currently selected page
int GetSelection() const;
// set/get the title of a page
bool SetPageText(int nPage, const wxString& strText);
wxString GetPageText(int nPage) const;
bool SetPageText(size_t nPage, const wxString& strText);
wxString GetPageText(size_t nPage) const;
// sets/returns item's image index in the current image list
int GetPageImage(int nPage) const;
bool SetPageImage(int nPage, int nImage);
int GetPageImage(size_t nPage) const;
bool SetPageImage(size_t nPage, int nImage);
// control the appearance of the notebook pages
// set the size (the same for all pages)
@ -79,7 +79,7 @@ public:
// operations
// ----------
// remove one page from the notebook
bool DeletePage(int nPage);
bool DeletePage(size_t nPage);
// remove all pages
bool DeleteAllPages();
@ -127,7 +127,7 @@ public:
protected:
// remove one page from the notebook but do not destroy it
virtual wxNotebookPage *DoRemovePage(int nPage);
virtual wxNotebookPage *DoRemovePage(size_t nPage);
private:
// the padding set by SetPadding()

View File

@ -64,17 +64,17 @@ public:
// set the currently selected page, return the index of the previously
// selected one (or -1 on error)
// NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
int SetSelection(int nPage);
int SetSelection(size_t nPage);
// get the currently selected page
int GetSelection() const { return m_nSelection; }
// set/get the title of a page
bool SetPageText(int nPage, const wxString& strText);
wxString GetPageText(int nPage) const;
bool SetPageText(size_t nPage, const wxString& strText);
wxString GetPageText(size_t nPage) const;
// sets/returns item's image index in the current image list
int GetPageImage(int nPage) const;
bool SetPageImage(int nPage, int nImage);
int GetPageImage(size_t nPage) const;
bool SetPageImage(size_t nPage, int nImage);
// control the appearance of the notebook pages
// set the size (the same for all pages)
@ -104,7 +104,7 @@ public:
// remove all pages
bool DeleteAllPages();
// the same as AddPage(), but adds it at the specified position
bool InsertPage(int nPage,
bool InsertPage(size_t nPage,
wxNotebookPage *pPage,
const wxString& strText,
bool bSelect = FALSE,
@ -134,7 +134,7 @@ public:
// -------------------
virtual void Command(wxCommandEvent& event);
protected:
virtual wxNotebookPage *DoRemovePage(int page) ;
virtual wxNotebookPage *DoRemovePage(size_t page) ;
virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ;
// common part of all ctors
void Init();

View File

@ -83,13 +83,13 @@ public:
// set the currently selected page, return the index of the previously
// selected one (or -1 on error)
// NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
int SetSelection(int nPage);
int SetSelection(size_t nPage);
// get the currently selected page
int GetSelection() const { return m_nSelection; }
// set/get the title of a page
bool SetPageText(int nPage, const wxString& strText);
wxString GetPageText(int nPage) const;
bool SetPageText(size_t nPage, const wxString& strText);
wxString GetPageText(size_t nPage) const;
// image list stuff: each page may have an image associated with it. All
// the images belong to an image list, so you have to
@ -100,8 +100,8 @@ public:
void SetImageList(wxImageList* imageList);
// sets/returns item's image index in the current image list
int GetPageImage(int nPage) const;
bool SetPageImage(int nPage, int nImage);
int GetPageImage(size_t nPage) const;
bool SetPageImage(size_t nPage, int nImage);
// currently it's always 1 because wxGTK doesn't support multi-row
// tab controls
@ -123,7 +123,7 @@ public:
// inserts a new page to the notebook (it will be deleted ny the notebook,
// don't delete it yourself). If bSelect, this page becomes active.
bool InsertPage(int nPage,
bool InsertPage(size_t nPage,
wxNotebookPage *pPage,
const wxString& strText,
bool bSelect = FALSE,
@ -172,7 +172,7 @@ protected:
virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle = NULL) const;
// remove one page from the notebook, without deleting
virtual wxNotebookPage *DoRemovePage(int nPage);
virtual wxNotebookPage *DoRemovePage(size_t nPage);
// set the size of the given page to fit in the notebook
void AdjustPageSize(wxNotebookPage *page);

View File

@ -24,9 +24,7 @@
#if wxUSE_NOTEBOOK
#include "wx/control.h"
#include "wx/dynarray.h"
#include "wx/imaglist.h"
#include "wx/bookctrl.h"
// ----------------------------------------------------------------------------
// constants
@ -41,122 +39,46 @@ enum
wxNB_HITTEST_ONITEM = wxNB_HITTEST_ONICON | wxNB_HITTEST_ONLABEL
};
// ----------------------------------------------------------------------------
// types
// ----------------------------------------------------------------------------
// array of notebook pages
typedef wxWindow wxNotebookPage; // so far, any window can be a page
WX_DEFINE_EXPORTED_ARRAY_NO_PTR(wxNotebookPage *, wxArrayPages);
#define wxNOTEBOOK_NAME _T("notebook")
// ----------------------------------------------------------------------------
// wxNotebookBase: define wxNotebook interface
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxNotebookBase : public wxControl
class WXDLLEXPORT wxNotebookBase : public wxBookCtrl
{
public:
// ctor
wxNotebookBase()
// ctors
// -----
wxNotebookBase() { }
wxNotebookBase(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxNOTEBOOK_NAME)
: wxBookCtrl(parent, id, pos, size, style, name)
{
Init();
}
// quasi ctor
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxNOTEBOOK_NAME);
// dtor
virtual ~wxNotebookBase();
// accessors
// ---------
// get number of pages in the dialog
int GetPageCount() const { return (int) m_pages.GetCount(); }
// get the panel which represents the given page
wxNotebookPage *GetPage(int nPage) { return m_pages[nPage]; }
// get the currently selected page
virtual int GetSelection() const = 0;
// set/get the title of a page
virtual bool SetPageText(int nPage, const wxString& strText) = 0;
virtual wxString GetPageText(int nPage) const = 0;
// image list stuff: each page may have an image associated with it (all
// images belong to the same image list)
virtual void SetImageList(wxImageList* imageList);
// as SetImageList() but we will delete the image list ourselves
void AssignImageList(wxImageList* imageList);
// get pointer (may be NULL) to the associated image list
wxImageList* GetImageList() const { return m_imageList; }
// sets/returns item's image index in the current image list
virtual int GetPageImage(int nPage) const = 0;
virtual bool SetPageImage(int nPage, int nImage) = 0;
// wxNotebook-specific additions to wxBookCtrl interface
// -----------------------------------------------------
// get the number of rows for a control with wxNB_MULTILINE style (not all
// versions support it - they will always return 1 then)
virtual int GetRowCount() const { return 1; }
// set the size (the same for all pages)
virtual void SetPageSize(const wxSize& size) = 0;
// set the padding between tabs (in pixels)
virtual void SetPadding(const wxSize& padding) = 0;
// set the size of the tabs for wxNB_FIXEDWIDTH controls
virtual void SetTabSize(const wxSize& sz) = 0;
// calculate the size of the notebook from the size of its page
virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
// operations
// ----------
// remove one page from the notebook and delete it
virtual bool DeletePage(int nPage);
// remove one page from the notebook, without deleting it
virtual bool RemovePage(int nPage) { return DoRemovePage(nPage) != NULL; }
// remove all pages and delete them
virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages); return TRUE; }
// adds a new page to the notebook (it will be deleted by the notebook,
// don't delete it yourself) and make it the current one if bSelect
virtual bool AddPage(wxNotebookPage *pPage,
const wxString& strText,
bool bSelect = FALSE,
int imageId = -1)
{
return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
}
// the same as AddPage(), but adds the page at the specified position
virtual bool InsertPage(int nPage,
wxNotebookPage *pPage,
const wxString& strText,
bool bSelect = FALSE,
int imageId = -1) = 0;
// set the currently selected page, return the index of the previously
// selected one (or -1 on error)
//
// NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
virtual int SetSelection(int nPage) = 0;
// hit test, returns which tab is hit and, optionally, where (icon, label)
// (not implemented on all platforms)
virtual int HitTest(const wxPoint& WXUNUSED(pt),
@ -165,67 +87,31 @@ public:
return wxNOT_FOUND;
}
// cycle thru the tabs
void AdvanceSelection(bool forward = TRUE)
{
int nPage = GetNextPage(forward);
if ( nPage != -1 )
SetSelection(nPage);
}
// implement some base class functions
virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
protected:
// remove the page and return a pointer to it
virtual wxNotebookPage *DoRemovePage(int page);
// return the minimum size large enough to display the largest page entirely
virtual wxSize DoGetBestSize() const;
// common part of all ctors
void Init();
// get the next page wrapping if we reached the end
int GetNextPage(bool forward) const;
wxArrayPages m_pages; // array of pages
wxImageList *m_imageList; // we can have an associated image list
bool m_ownsImageList; // true if we must delete m_imageList
DECLARE_NO_COPY_CLASS(wxNotebookBase)
};
// ----------------------------------------------------------------------------
// notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
// notebook event class and related stuff
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxNotebookEvent : public wxNotifyEvent
class WXDLLEXPORT wxNotebookEvent : public wxBookCtrlEvent
{
public:
wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
int nSel = -1, int nOldSel = -1)
: wxNotifyEvent(commandType, id)
{
m_nSel = nSel;
m_nOldSel = nOldSel;
}
// accessors
// the currently selected page (-1 if none)
int GetSelection() const { return m_nSel; }
void SetSelection(int nSel) { m_nSel = nSel; }
// the page that was selected before the change (-1 if none)
int GetOldSelection() const { return m_nOldSel; }
void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }
: wxBookCtrlEvent(commandType, id, nSel, nOldSel)
{
}
private:
int m_nSel, // currently selected page
m_nOldSel; // previously selected page
DECLARE_DYNAMIC_CLASS_NO_COPY(wxNotebookEvent)
};
// ----------------------------------------------------------------------------
// event types and macros for them
// ----------------------------------------------------------------------------
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, 802)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, 803)

View File

@ -67,14 +67,14 @@ public:
// implement wxNotebookBase pure virtuals
// --------------------------------------
virtual int SetSelection(int nPage);
virtual int SetSelection(size_t nPage);
virtual int GetSelection() const { return m_sel; }
virtual bool SetPageText(int nPage, const wxString& strText);
virtual wxString GetPageText(int nPage) const;
virtual bool SetPageText(size_t nPage, const wxString& strText);
virtual wxString GetPageText(size_t nPage) const;
virtual int GetPageImage(int nPage) const;
virtual bool SetPageImage(int nPage, int nImage);
virtual int GetPageImage(size_t nPage) const;
virtual bool SetPageImage(size_t nPage, int nImage);
virtual void SetPageSize(const wxSize& size);
virtual void SetPadding(const wxSize& padding);
@ -84,7 +84,7 @@ public:
virtual bool DeleteAllPages();
virtual bool InsertPage(int nPage,
virtual bool InsertPage(size_t nPage,
wxNotebookPage *pPage,
const wxString& strText,
bool bSelect = FALSE,
@ -120,7 +120,7 @@ public:
void RefreshCurrent();
protected:
virtual wxNotebookPage *DoRemovePage(int nPage);
virtual wxNotebookPage *DoRemovePage(size_t nPage);
// drawing
virtual void DoDraw(wxControlRenderer *renderer);

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") );