]> git.saurik.com Git - wxWidgets.git/blame - src/common/nbkbase.cpp
Applied patch [ 733425 ] Fix for header rendering problem in CalCtrl
[wxWidgets.git] / src / common / nbkbase.cpp
CommitLineData
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
3fcea4b1
JS
39#ifdef __GNUWIN32_OLD__
40 #include "wx/msw/gnuwin32/extra.h"
41#endif
42
43#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
c09615b8
JS
44#include "wx/msw/private.h"
45#include <commctrl.h>
46#include "wx/msw/winundef.h"
47#endif
48
07b8d7ec
VZ
49// ============================================================================
50// implementation
51// ============================================================================
52
53// ----------------------------------------------------------------------------
54// constructors and destructors
55// ----------------------------------------------------------------------------
56
57void wxNotebookBase::Init()
58{
59 m_imageList = NULL;
60 m_ownsImageList = FALSE;
61}
62
63wxNotebookBase::~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
76void 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
89void wxNotebookBase::AssignImageList(wxImageList* imageList)
90{
91 SetImageList(imageList);
92 m_ownsImageList = TRUE;
93}
94
95// ----------------------------------------------------------------------------
96// geometry
97// ----------------------------------------------------------------------------
98
2ce7af35 99wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage) const
07b8d7ec
VZ
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;
eaf336e0 104
2ce7af35
JS
105 // changed hajokirchhoff -- May, 31st, 2003
106 // moved the __WXMSW__ portion to wxNotebook::CalcSizeFromPage in src/msw/notebook.cpp
107 // where it really belongs.
108 // Question: Shouldn't we make wxNotebookBase::CalcSizeFromPage a pure virtual class.
109 // I'd like this better than this "totally bogus" code here.
07b8d7ec 110 if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) )
eaf336e0 111 {
07b8d7ec 112 sizeTotal.x += 90;
eaf336e0 113 sizeTotal.y += 10;
eaf336e0 114 }
07b8d7ec 115 else
eaf336e0 116 {
eaf336e0 117 sizeTotal.x += 10;
07b8d7ec 118 sizeTotal.y += 40;
eaf336e0 119 }
07b8d7ec
VZ
120
121 return sizeTotal;
122}
123
124// ----------------------------------------------------------------------------
125// pages management
126// ----------------------------------------------------------------------------
127
128bool wxNotebookBase::DeletePage(int nPage)
129{
130 wxNotebookPage *page = DoRemovePage(nPage);
131 if ( !page )
132 return FALSE;
133
134 delete page;
135
136 return TRUE;
137}
138
10199e27
VZ
139wxNotebookPage *wxNotebookBase::DoRemovePage(int nPage)
140{
141 wxCHECK_MSG( nPage >= 0 && (size_t)nPage < m_pages.GetCount(), NULL,
142 _T("invalid page index in wxNotebookBase::DoRemovePage()") );
143
144 wxNotebookPage *pageRemoved = m_pages[nPage];
b54e41c5 145 m_pages.RemoveAt(nPage);
10199e27
VZ
146
147 return pageRemoved;
148}
149
2ce7af35
JS
150wxSize wxNotebookBase::DoGetBestSize() const
151{
152 wxSize bestSize(0,0);
153 size_t nCount = m_pages.Count();
154 // iterate over all pages, get the largest width and height
155 for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
156 wxNotebookPage *pPage = m_pages[nPage];
157 wxSize childBestSize(pPage->GetBestSize());
158 bestSize.SetWidth(max(childBestSize.GetWidth(), bestSize.GetWidth()));
159 bestSize.SetHeight(max(childBestSize.GetHeight(), bestSize.GetHeight()));
160 }
161 // convert display area to window area, adding the size neccessary for the tab control itself
162 return CalcSizeFromPage(bestSize);
163}
164
07b8d7ec
VZ
165int wxNotebookBase::GetNextPage(bool forward) const
166{
167 int nPage;
168
169 int nMax = GetPageCount();
170 if ( nMax-- ) // decrement it to get the last valid index
171 {
172 int nSel = GetSelection();
173
174 // change selection wrapping if it becomes invalid
175 nPage = forward ? nSel == nMax ? 0
176 : nSel + 1
177 : nSel == 0 ? nMax
178 : nSel - 1;
179 }
180 else // notebook is empty, no next page
181 {
182 nPage = -1;
183 }
184
185 return nPage;
186}
187
188#endif // wxUSE_NOTEBOOK
189