added missing Create() implementation
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #ifdef __GNUWIN32_OLD__
40 #include "wx/msw/gnuwin32/extra.h"
41 #endif
42
43 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
44 #include "wx/msw/private.h"
45 #include <commctrl.h>
46 #include "wx/msw/winundef.h"
47 #endif
48
49 // ============================================================================
50 // implementation
51 // ============================================================================
52
53 // ----------------------------------------------------------------------------
54 // constructors and destructors
55 // ----------------------------------------------------------------------------
56
57 void wxNotebookBase::Init()
58 {
59 m_imageList = NULL;
60 m_ownsImageList = FALSE;
61 }
62
63 bool
64 wxNotebookBase::Create(wxWindow *parent,
65 wxWindowID id,
66 const wxPoint& pos,
67 const wxSize& size,
68 long style,
69 const wxString& name)
70 {
71 return wxControl::Create
72 (
73 parent,
74 id,
75 pos,
76 size,
77 style,
78 wxDefaultValidator,
79 name
80 );
81 }
82
83 wxNotebookBase::~wxNotebookBase()
84 {
85 if ( m_ownsImageList )
86 {
87 // may be NULL, ok
88 delete m_imageList;
89 }
90 }
91
92 // ----------------------------------------------------------------------------
93 // image list
94 // ----------------------------------------------------------------------------
95
96 void wxNotebookBase::SetImageList(wxImageList* imageList)
97 {
98 if ( m_ownsImageList )
99 {
100 // may be NULL, ok
101 delete m_imageList;
102
103 m_ownsImageList = FALSE;
104 }
105
106 m_imageList = imageList;
107 }
108
109 void wxNotebookBase::AssignImageList(wxImageList* imageList)
110 {
111 SetImageList(imageList);
112 m_ownsImageList = TRUE;
113 }
114
115 // ----------------------------------------------------------------------------
116 // geometry
117 // ----------------------------------------------------------------------------
118
119 wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage) const
120 {
121 // this is, of course, totally bogus -- but we must do something by
122 // default because not all ports implement this
123 wxSize sizeTotal = sizePage;
124
125 if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) )
126 {
127 sizeTotal.x += 90;
128 sizeTotal.y += 10;
129 }
130 else // tabs on top/bottom side
131 {
132 sizeTotal.x += 10;
133 sizeTotal.y += 40;
134 }
135
136 return sizeTotal;
137 }
138
139 wxSize wxNotebookBase::DoGetBestSize() const
140 {
141 wxSize bestSize;
142
143 // iterate over all pages, get the largest width and height
144 const size_t nCount = m_pages.Count();
145 for ( size_t nPage = 0; nPage < nCount; nPage++ )
146 {
147 wxNotebookPage *pPage = m_pages[nPage];
148 wxSize childBestSize(pPage->GetBestSize());
149
150 if ( childBestSize.x > bestSize.x )
151 bestSize.x = childBestSize.x;
152
153 if ( childBestSize.y > bestSize.y )
154 bestSize.y = childBestSize.y;
155 }
156
157 // convert display area to window area, adding the size neccessary for the
158 // tabs
159 return CalcSizeFromPage(bestSize);
160 }
161
162 // ----------------------------------------------------------------------------
163 // pages management
164 // ----------------------------------------------------------------------------
165
166 bool wxNotebookBase::DeletePage(int nPage)
167 {
168 wxNotebookPage *page = DoRemovePage(nPage);
169 if ( !page )
170 return FALSE;
171
172 delete page;
173
174 return TRUE;
175 }
176
177 wxNotebookPage *wxNotebookBase::DoRemovePage(int nPage)
178 {
179 wxCHECK_MSG( nPage >= 0 && (size_t)nPage < m_pages.GetCount(), NULL,
180 _T("invalid page index in wxNotebookBase::DoRemovePage()") );
181
182 wxNotebookPage *pageRemoved = m_pages[nPage];
183 m_pages.RemoveAt(nPage);
184
185 return pageRemoved;
186 }
187
188 int wxNotebookBase::GetNextPage(bool forward) const
189 {
190 int nPage;
191
192 int nMax = GetPageCount();
193 if ( nMax-- ) // decrement it to get the last valid index
194 {
195 int nSel = GetSelection();
196
197 // change selection wrapping if it becomes invalid
198 nPage = forward ? nSel == nMax ? 0
199 : nSel + 1
200 : nSel == 0 ? nMax
201 : nSel - 1;
202 }
203 else // notebook is empty, no next page
204 {
205 nPage = -1;
206 }
207
208 return nPage;
209 }
210
211 #endif // wxUSE_NOTEBOOK
212