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