]>
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 | |
34 | #include "wx/notebook.h" | |
35 | #include "wx/imaglist.h" | |
36 | #endif //WX_PRECOMP | |
37 | ||
38 | // ============================================================================ | |
39 | // implementation | |
40 | // ============================================================================ | |
41 | ||
42 | // ---------------------------------------------------------------------------- | |
43 | // constructors and destructors | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
46 | void wxNotebookBase::Init() | |
47 | { | |
48 | m_imageList = NULL; | |
49 | m_ownsImageList = FALSE; | |
50 | } | |
51 | ||
52 | wxNotebookBase::~wxNotebookBase() | |
53 | { | |
54 | if ( m_ownsImageList ) | |
55 | { | |
56 | // may be NULL, ok | |
57 | delete m_imageList; | |
58 | } | |
59 | } | |
60 | ||
61 | // ---------------------------------------------------------------------------- | |
62 | // image list | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
65 | void wxNotebookBase::SetImageList(wxImageList* imageList) | |
66 | { | |
67 | if ( m_ownsImageList ) | |
68 | { | |
69 | // may be NULL, ok | |
70 | delete m_imageList; | |
71 | ||
72 | m_ownsImageList = FALSE; | |
73 | } | |
74 | ||
75 | m_imageList = imageList; | |
76 | } | |
77 | ||
78 | void wxNotebookBase::AssignImageList(wxImageList* imageList) | |
79 | { | |
80 | SetImageList(imageList); | |
81 | m_ownsImageList = TRUE; | |
82 | } | |
83 | ||
84 | // ---------------------------------------------------------------------------- | |
85 | // geometry | |
86 | // ---------------------------------------------------------------------------- | |
87 | ||
88 | wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage) | |
89 | { | |
90 | // this was just taken from wxNotebookSizer::CalcMin() and is, of | |
91 | // course, totally bogus - just like the original code was | |
92 | wxSize sizeTotal = sizePage; | |
93 | if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) ) | |
94 | sizeTotal.x += 90; | |
95 | else | |
96 | sizeTotal.y += 40; | |
97 | ||
98 | return sizeTotal; | |
99 | } | |
100 | ||
101 | // ---------------------------------------------------------------------------- | |
102 | // pages management | |
103 | // ---------------------------------------------------------------------------- | |
104 | ||
105 | bool wxNotebookBase::DeletePage(int nPage) | |
106 | { | |
107 | wxNotebookPage *page = DoRemovePage(nPage); | |
108 | if ( !page ) | |
109 | return FALSE; | |
110 | ||
111 | delete page; | |
112 | ||
113 | return TRUE; | |
114 | } | |
115 | ||
10199e27 VZ |
116 | wxNotebookPage *wxNotebookBase::DoRemovePage(int nPage) |
117 | { | |
118 | wxCHECK_MSG( nPage >= 0 && (size_t)nPage < m_pages.GetCount(), NULL, | |
119 | _T("invalid page index in wxNotebookBase::DoRemovePage()") ); | |
120 | ||
121 | wxNotebookPage *pageRemoved = m_pages[nPage]; | |
122 | m_pages.Remove(nPage); | |
123 | ||
124 | return pageRemoved; | |
125 | } | |
126 | ||
07b8d7ec VZ |
127 | int wxNotebookBase::GetNextPage(bool forward) const |
128 | { | |
129 | int nPage; | |
130 | ||
131 | int nMax = GetPageCount(); | |
132 | if ( nMax-- ) // decrement it to get the last valid index | |
133 | { | |
134 | int nSel = GetSelection(); | |
135 | ||
136 | // change selection wrapping if it becomes invalid | |
137 | nPage = forward ? nSel == nMax ? 0 | |
138 | : nSel + 1 | |
139 | : nSel == 0 ? nMax | |
140 | : nSel - 1; | |
141 | } | |
142 | else // notebook is empty, no next page | |
143 | { | |
144 | nPage = -1; | |
145 | } | |
146 | ||
147 | return nPage; | |
148 | } | |
149 | ||
150 | #endif // wxUSE_NOTEBOOK | |
151 |