]> git.saurik.com Git - wxWidgets.git/blob - src/common/bookctrl.cpp
set error to GSOCK_TIMEOUT if the socket timed out (modified and extended patch 1303554)
[wxWidgets.git] / src / common / bookctrl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/bookctrl.cpp
3 // Purpose: wxBookCtrlBase implementation
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 19.08.03
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_BOOKCTRL
28
29 #include "wx/imaglist.h"
30
31 #include "wx/bookctrl.h"
32
33 // ============================================================================
34 // implementation
35 // ============================================================================
36
37 // ----------------------------------------------------------------------------
38 // constructors and destructors
39 // ----------------------------------------------------------------------------
40
41 void wxBookCtrlBase::Init()
42 {
43 m_imageList = NULL;
44 m_ownsImageList = false;
45 }
46
47 bool
48 wxBookCtrlBase::Create(wxWindow *parent,
49 wxWindowID id,
50 const wxPoint& pos,
51 const wxSize& size,
52 long style,
53 const wxString& name)
54 {
55 return wxControl::Create
56 (
57 parent,
58 id,
59 pos,
60 size,
61 style,
62 wxDefaultValidator,
63 name
64 );
65 }
66
67 wxBookCtrlBase::~wxBookCtrlBase()
68 {
69 if ( m_ownsImageList )
70 {
71 // may be NULL, ok
72 delete m_imageList;
73 }
74 }
75
76 // ----------------------------------------------------------------------------
77 // image list
78 // ----------------------------------------------------------------------------
79
80 void wxBookCtrlBase::SetImageList(wxImageList *imageList)
81 {
82 if ( m_ownsImageList )
83 {
84 // may be NULL, ok
85 delete m_imageList;
86
87 m_ownsImageList = false;
88 }
89
90 m_imageList = imageList;
91 }
92
93 void wxBookCtrlBase::AssignImageList(wxImageList* imageList)
94 {
95 SetImageList(imageList);
96
97 m_ownsImageList = true;
98 }
99
100 // ----------------------------------------------------------------------------
101 // geometry
102 // ----------------------------------------------------------------------------
103
104 void wxBookCtrlBase::SetPageSize(const wxSize& size)
105 {
106 SetClientSize(CalcSizeFromPage(size));
107 }
108
109 wxSize wxBookCtrlBase::DoGetBestSize() const
110 {
111 wxSize bestSize;
112
113 // iterate over all pages, get the largest width and height
114 const size_t nCount = m_pages.size();
115 for ( size_t nPage = 0; nPage < nCount; nPage++ )
116 {
117 wxWindow *pPage = m_pages[nPage];
118 wxSize childBestSize(pPage->GetBestSize());
119
120 if ( childBestSize.x > bestSize.x )
121 bestSize.x = childBestSize.x;
122
123 if ( childBestSize.y > bestSize.y )
124 bestSize.y = childBestSize.y;
125 }
126
127 // convert display area to window area, adding the size necessary for the
128 // tabs
129 wxSize best = CalcSizeFromPage(bestSize);
130 CacheBestSize(best);
131 return best;
132 }
133
134 // ----------------------------------------------------------------------------
135 // pages management
136 // ----------------------------------------------------------------------------
137
138 bool
139 wxBookCtrlBase::InsertPage(size_t nPage,
140 wxWindow *page,
141 const wxString& WXUNUSED(text),
142 bool WXUNUSED(bSelect),
143 int WXUNUSED(imageId))
144 {
145 wxCHECK_MSG( page, false, _T("NULL page in wxBookCtrlBase::InsertPage()") );
146 wxCHECK_MSG( nPage <= m_pages.size(), false,
147 _T("invalid page index in wxBookCtrlBase::InsertPage()") );
148
149 m_pages.Insert(page, nPage);
150 InvalidateBestSize();
151
152 return true;
153 }
154
155 bool wxBookCtrlBase::DeletePage(size_t nPage)
156 {
157 wxWindow *page = DoRemovePage(nPage);
158 if ( !page )
159 return false;
160
161 delete page;
162
163 return true;
164 }
165
166 wxWindow *wxBookCtrlBase::DoRemovePage(size_t nPage)
167 {
168 wxCHECK_MSG( nPage < m_pages.size(), NULL,
169 _T("invalid page index in wxBookCtrlBase::DoRemovePage()") );
170
171 wxWindow *pageRemoved = m_pages[nPage];
172 m_pages.RemoveAt(nPage);
173 InvalidateBestSize();
174
175 return pageRemoved;
176 }
177
178 int wxBookCtrlBase::GetNextPage(bool forward) const
179 {
180 int nPage;
181
182 int nMax = GetPageCount();
183 if ( nMax-- ) // decrement it to get the last valid index
184 {
185 int nSel = GetSelection();
186
187 // change selection wrapping if it becomes invalid
188 nPage = forward ? nSel == nMax ? 0
189 : nSel + 1
190 : nSel == 0 ? nMax
191 : nSel - 1;
192 }
193 else // notebook is empty, no next page
194 {
195 nPage = -1;
196 }
197
198 return nPage;
199 }
200
201 #endif // wxUSE_BOOKCTRL
202