]> git.saurik.com Git - wxWidgets.git/blame - src/common/nbkbase.cpp
Applied patch [ 605189 ] add edit cancel notify to wxTreeEvent
[wxWidgets.git] / src / common / nbkbase.cpp
CommitLineData
07b8d7ec
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/common/nbkbase.cpp
3// Purpose: common wxNotebook methods
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 02.07.01
7// RCS-ID: $Id$
8// Copyright: (c) 2001 Vadim Zeitlin
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "notebookbase.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#if wxUSE_NOTEBOOK
32
33#ifndef WX_PRECOMP
07b8d7ec
VZ
34#endif //WX_PRECOMP
35
bd52bee1
JS
36#include "wx/imaglist.h"
37#include "wx/notebook.h"
38
07b8d7ec
VZ
39// ============================================================================
40// implementation
41// ============================================================================
42
43// ----------------------------------------------------------------------------
44// constructors and destructors
45// ----------------------------------------------------------------------------
46
47void wxNotebookBase::Init()
48{
49 m_imageList = NULL;
50 m_ownsImageList = FALSE;
51}
52
53wxNotebookBase::~wxNotebookBase()
54{
55 if ( m_ownsImageList )
56 {
57 // may be NULL, ok
58 delete m_imageList;
59 }
60}
61
62// ----------------------------------------------------------------------------
63// image list
64// ----------------------------------------------------------------------------
65
66void wxNotebookBase::SetImageList(wxImageList* imageList)
67{
68 if ( m_ownsImageList )
69 {
70 // may be NULL, ok
71 delete m_imageList;
72
73 m_ownsImageList = FALSE;
74 }
75
76 m_imageList = imageList;
77}
78
79void wxNotebookBase::AssignImageList(wxImageList* imageList)
80{
81 SetImageList(imageList);
82 m_ownsImageList = TRUE;
83}
84
85// ----------------------------------------------------------------------------
86// geometry
87// ----------------------------------------------------------------------------
88
89wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage)
90{
91 // this was just taken from wxNotebookSizer::CalcMin() and is, of
92 // course, totally bogus - just like the original code was
93 wxSize sizeTotal = sizePage;
eaf336e0 94
07b8d7ec 95 if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) )
eaf336e0 96 {
07b8d7ec 97 sizeTotal.x += 90;
eaf336e0 98 sizeTotal.y += 10;
eaf336e0 99 }
07b8d7ec 100 else
eaf336e0 101 {
eaf336e0 102 sizeTotal.x += 10;
07b8d7ec 103 sizeTotal.y += 40;
eaf336e0 104 }
07b8d7ec
VZ
105
106 return sizeTotal;
107}
108
109// ----------------------------------------------------------------------------
110// pages management
111// ----------------------------------------------------------------------------
112
113bool wxNotebookBase::DeletePage(int nPage)
114{
115 wxNotebookPage *page = DoRemovePage(nPage);
116 if ( !page )
117 return FALSE;
118
119 delete page;
120
121 return TRUE;
122}
123
10199e27
VZ
124wxNotebookPage *wxNotebookBase::DoRemovePage(int nPage)
125{
126 wxCHECK_MSG( nPage >= 0 && (size_t)nPage < m_pages.GetCount(), NULL,
127 _T("invalid page index in wxNotebookBase::DoRemovePage()") );
128
129 wxNotebookPage *pageRemoved = m_pages[nPage];
b54e41c5 130 m_pages.RemoveAt(nPage);
10199e27
VZ
131
132 return pageRemoved;
133}
134
07b8d7ec
VZ
135int wxNotebookBase::GetNextPage(bool forward) const
136{
137 int nPage;
138
139 int nMax = GetPageCount();
140 if ( nMax-- ) // decrement it to get the last valid index
141 {
142 int nSel = GetSelection();
143
144 // change selection wrapping if it becomes invalid
145 nPage = forward ? nSel == nMax ? 0
146 : nSel + 1
147 : nSel == 0 ? nMax
148 : nSel - 1;
149 }
150 else // notebook is empty, no next page
151 {
152 nPage = -1;
153 }
154
155 return nPage;
156}
157
158#endif // wxUSE_NOTEBOOK
159