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