Include missing.h
[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 #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 wxNotebookBase::~wxNotebookBase()
64 {
65 if ( m_ownsImageList )
66 {
67 // may be NULL, ok
68 delete m_imageList;
69 }
70 }
71
72 // ----------------------------------------------------------------------------
73 // image list
74 // ----------------------------------------------------------------------------
75
76 void wxNotebookBase::SetImageList(wxImageList* imageList)
77 {
78 if ( m_ownsImageList )
79 {
80 // may be NULL, ok
81 delete m_imageList;
82
83 m_ownsImageList = FALSE;
84 }
85
86 m_imageList = imageList;
87 }
88
89 void wxNotebookBase::AssignImageList(wxImageList* imageList)
90 {
91 SetImageList(imageList);
92 m_ownsImageList = TRUE;
93 }
94
95 // ----------------------------------------------------------------------------
96 // geometry
97 // ----------------------------------------------------------------------------
98
99 wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage)
100 {
101 // this was just taken from wxNotebookSizer::CalcMin() and is, of
102 // course, totally bogus - just like the original code was
103 wxSize sizeTotal = sizePage;
104
105 // Slightly less bogus, at least under Windows.
106 // We need to make getting tab size part of the wxWindows API.
107 #ifdef __WXMSW__
108 wxSize tabSize(0, 0);
109 if (GetPageCount() > 0)
110 {
111 RECT rect;
112 TabCtrl_GetItemRect((HWND) GetHWND(), 0, & rect);
113 tabSize.x = rect.right - rect.left;
114 tabSize.y = rect.bottom - rect.top;
115 }
116 if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) )
117 {
118 sizeTotal.x += tabSize.x + 7;
119 sizeTotal.y += 7;
120 }
121 else
122 {
123 sizeTotal.x += 7;
124 sizeTotal.y += tabSize.y + 7;
125 }
126 #else
127 if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) )
128 {
129 sizeTotal.x += 90;
130 sizeTotal.y += 10;
131 }
132 else
133 {
134 sizeTotal.x += 10;
135 sizeTotal.y += 40;
136 }
137 #endif
138
139 return sizeTotal;
140 }
141
142 // ----------------------------------------------------------------------------
143 // pages management
144 // ----------------------------------------------------------------------------
145
146 bool wxNotebookBase::DeletePage(int nPage)
147 {
148 wxNotebookPage *page = DoRemovePage(nPage);
149 if ( !page )
150 return FALSE;
151
152 delete page;
153
154 return TRUE;
155 }
156
157 wxNotebookPage *wxNotebookBase::DoRemovePage(int nPage)
158 {
159 wxCHECK_MSG( nPage >= 0 && (size_t)nPage < m_pages.GetCount(), NULL,
160 _T("invalid page index in wxNotebookBase::DoRemovePage()") );
161
162 wxNotebookPage *pageRemoved = m_pages[nPage];
163 m_pages.RemoveAt(nPage);
164
165 return pageRemoved;
166 }
167
168 int wxNotebookBase::GetNextPage(bool forward) const
169 {
170 int nPage;
171
172 int nMax = GetPageCount();
173 if ( nMax-- ) // decrement it to get the last valid index
174 {
175 int nSel = GetSelection();
176
177 // change selection wrapping if it becomes invalid
178 nPage = forward ? nSel == nMax ? 0
179 : nSel + 1
180 : nSel == 0 ? nMax
181 : nSel - 1;
182 }
183 else // notebook is empty, no next page
184 {
185 nPage = -1;
186 }
187
188 return nPage;
189 }
190
191 #endif // wxUSE_NOTEBOOK
192