1. fixed wxGTK notebook which was completely broken by the merge
[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 #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
116 int wxNotebookBase::GetNextPage(bool forward) const
117 {
118 int nPage;
119
120 int nMax = GetPageCount();
121 if ( nMax-- ) // decrement it to get the last valid index
122 {
123 int nSel = GetSelection();
124
125 // change selection wrapping if it becomes invalid
126 nPage = forward ? nSel == nMax ? 0
127 : nSel + 1
128 : nSel == 0 ? nMax
129 : nSel - 1;
130 }
131 else // notebook is empty, no next page
132 {
133 nPage = -1;
134 }
135
136 return nPage;
137 }
138
139 #endif // wxUSE_NOTEBOOK
140