Still more space around notebook pages...
[wxWidgets.git] / src / common / nbkbase.cpp
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
34 #endif //WX_PRECOMP
35
36 #include "wx/imaglist.h"
37 #include "wx/notebook.h"
38
39 // ============================================================================
40 // implementation
41 // ============================================================================
42
43 // ----------------------------------------------------------------------------
44 // constructors and destructors
45 // ----------------------------------------------------------------------------
46
47 void wxNotebookBase::Init()
48 {
49 m_imageList = NULL;
50 m_ownsImageList = FALSE;
51 }
52
53 wxNotebookBase::~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
66 void 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
79 void wxNotebookBase::AssignImageList(wxImageList* imageList)
80 {
81 SetImageList(imageList);
82 m_ownsImageList = TRUE;
83 }
84
85 // ----------------------------------------------------------------------------
86 // geometry
87 // ----------------------------------------------------------------------------
88
89 wxSize 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;
94
95 // Mac has large notebook borders.
96
97 if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) )
98 {
99 sizeTotal.x += 90;
100 #ifdef __WXMAC__
101 sizeTotal.y += 20;
102 #else
103 sizeTotal.y += 10;
104 #endif
105 }
106 else
107 {
108 #ifdef __WXMAC__
109 sizeTotal.x += 32; // This is OK for Aqua.
110 #else
111 sizeTotal.x += 10;
112 #endif
113 sizeTotal.y += 40;
114 }
115
116 return sizeTotal;
117 }
118
119 // ----------------------------------------------------------------------------
120 // pages management
121 // ----------------------------------------------------------------------------
122
123 bool wxNotebookBase::DeletePage(int nPage)
124 {
125 wxNotebookPage *page = DoRemovePage(nPage);
126 if ( !page )
127 return FALSE;
128
129 delete page;
130
131 return TRUE;
132 }
133
134 wxNotebookPage *wxNotebookBase::DoRemovePage(int nPage)
135 {
136 wxCHECK_MSG( nPage >= 0 && (size_t)nPage < m_pages.GetCount(), NULL,
137 _T("invalid page index in wxNotebookBase::DoRemovePage()") );
138
139 wxNotebookPage *pageRemoved = m_pages[nPage];
140 m_pages.RemoveAt(nPage);
141
142 return pageRemoved;
143 }
144
145 int wxNotebookBase::GetNextPage(bool forward) const
146 {
147 int nPage;
148
149 int nMax = GetPageCount();
150 if ( nMax-- ) // decrement it to get the last valid index
151 {
152 int nSel = GetSelection();
153
154 // change selection wrapping if it becomes invalid
155 nPage = forward ? nSel == nMax ? 0
156 : nSel + 1
157 : nSel == 0 ? nMax
158 : nSel - 1;
159 }
160 else // notebook is empty, no next page
161 {
162 nPage = -1;
163 }
164
165 return nPage;
166 }
167
168 #endif // wxUSE_NOTEBOOK
169