]>
git.saurik.com Git - wxWidgets.git/blob - src/stubs/notebook.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: implementation of wxNotebook
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #pragma implementation "notebook.h"
23 #include <wx/string.h>
25 #include <wx/imaglist.h>
26 #include <wx/notebook.h>
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 // check that the page index is valid
33 #define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount()))
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 #if !USE_SHARED_LIBRARIES
40 BEGIN_EVENT_TABLE(wxNotebook
, wxControl
)
41 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange
)
43 EVT_SIZE(wxNotebook::OnSize
)
44 EVT_SET_FOCUS(wxNotebook::OnSetFocus
)
45 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey
)
48 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
, wxControl
)
49 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent
, wxCommandEvent
)
52 // ============================================================================
54 // ============================================================================
56 // ----------------------------------------------------------------------------
57 // wxNotebook construction
58 // ----------------------------------------------------------------------------
60 // common part of all ctors
61 void wxNotebook::Init()
67 // default for dynamic class
68 wxNotebook::wxNotebook()
73 // the same arguments as for wxControl
74 wxNotebook::wxNotebook(wxWindow
*parent
,
83 Create(parent
, id
, pos
, size
, style
, name
);
87 bool wxNotebook::Create(wxWindow
*parent
,
98 m_windowId
= id
== -1 ? NewControlId() : id
;
101 m_windowStyle
= style
;
103 if ( parent
!= NULL
)
104 parent
->AddChild(this);
112 wxNotebook::~wxNotebook()
116 // ----------------------------------------------------------------------------
117 // wxNotebook accessors
118 // ----------------------------------------------------------------------------
119 int wxNotebook::GetPageCount() const
121 return m_aPages
.Count();
124 int wxNotebook::GetRowCount() const
130 int wxNotebook::SetSelection(int nPage
)
132 wxASSERT( IS_VALID_PAGE(nPage
) );
134 ChangePage(m_nSelection
, nPage
);
140 void wxNotebook::AdvanceSelection(bool bForward
)
142 int nSel
= GetSelection();
143 int nMax
= GetPageCount() - 1;
145 SetSelection(nSel
== nMax
? 0 : nSel
+ 1);
147 SetSelection(nSel
== 0 ? nMax
: nSel
- 1);
150 bool wxNotebook::SetPageText(int nPage
, const wxString
& strText
)
152 wxASSERT( IS_VALID_PAGE(nPage
) );
158 wxString
wxNotebook::GetPageText(int nPage
) const
160 wxASSERT( IS_VALID_PAGE(nPage
) );
166 int wxNotebook::GetPageImage(int nPage
) const
168 wxASSERT( IS_VALID_PAGE(nPage
) );
174 bool wxNotebook::SetPageImage(int nPage
, int nImage
)
176 wxASSERT( IS_VALID_PAGE(nPage
) );
182 void wxNotebook::SetImageList(wxImageList
* imageList
)
184 m_pImageList
= imageList
;
188 // ----------------------------------------------------------------------------
189 // wxNotebook operations
190 // ----------------------------------------------------------------------------
192 // remove one page from the notebook
193 bool wxNotebook::DeletePage(int nPage
)
195 wxCHECK( IS_VALID_PAGE(nPage
), FALSE
);
197 // TODO: delete native widget page
199 delete m_aPages
[nPage
];
200 m_aPages
.Remove(nPage
);
205 // remove one page from the notebook, without deleting the window
206 bool wxNotebook::RemovePage(int nPage
)
208 wxCHECK( IS_VALID_PAGE(nPage
), FALSE
);
210 m_aPages
.Remove(nPage
);
216 bool wxNotebook::DeleteAllPages()
218 // TODO: delete native widget pages
220 int nPageCount
= GetPageCount();
222 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
223 delete m_aPages
[nPage
];
230 // add a page to the notebook
231 bool wxNotebook::AddPage(wxNotebookPage
*pPage
,
232 const wxString
& strText
,
236 return InsertPage(GetPageCount(), pPage
, strText
, bSelect
, imageId
);
239 // same as AddPage() but does it at given position
240 bool wxNotebook::InsertPage(int nPage
,
241 wxNotebookPage
*pPage
,
242 const wxString
& strText
,
246 wxASSERT( pPage
!= NULL
);
247 wxCHECK( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), FALSE
);
249 // TODO: insert native widget page
251 // save the pointer to the page
252 m_aPages
.Insert(pPage
, nPage
);
254 // some page must be selected: either this one or the first one if there is
255 // still no selection
257 m_nSelection
= nPage
;
258 else if ( m_nSelection
== -1 )
264 // ----------------------------------------------------------------------------
265 // wxNotebook callbacks
266 // ----------------------------------------------------------------------------
268 // @@@ OnSize() is used for setting the font when it's called for the first
269 // time because doing it in ::Create() doesn't work (for unknown reasons)
270 void wxNotebook::OnSize(wxSizeEvent
& event
)
272 static bool s_bFirstTime
= TRUE
;
273 if ( s_bFirstTime
) {
274 // TODO: any first-time-size processing.
275 s_bFirstTime
= FALSE
;
278 // TODO: all this may or may not be necessary for your platform
280 // emulate page change (it's esp. important to do it first time because
281 // otherwise our page would stay invisible)
282 int nSel
= m_nSelection
;
286 // fit the notebook page to the tab control's display area
290 unsigned int nCount
= m_aPages
.Count();
291 for ( unsigned int nPage
= 0; nPage
< nCount
; nPage
++ ) {
292 wxNotebookPage
*pPage
= m_aPages
[nPage
];
293 pPage
->SetSize(0, 0, w
, h
);
294 if ( pPage
->GetAutoLayout() )
298 // Processing continues to next OnSize
302 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
304 // is it our tab control?
305 if ( event
.GetEventObject() == this )
306 ChangePage(event
.GetOldSelection(), event
.GetSelection());
308 // we want to give others a chance to process this message as well
312 void wxNotebook::OnSetFocus(wxFocusEvent
& event
)
314 // set focus to the currently selected page if any
315 if ( m_nSelection
!= -1 )
316 m_aPages
[m_nSelection
]->SetFocus();
321 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
323 if ( event
.IsWindowChange() ) {
325 AdvanceSelection(event
.GetDirection());
328 // pass to the parent
330 event
.SetCurrentFocus(this);
331 GetParent()->ProcessEvent(event
);
336 // ----------------------------------------------------------------------------
337 // wxNotebook base class virtuals
338 // ----------------------------------------------------------------------------
340 // override these 2 functions to do nothing: everything is done in OnSize
342 void wxNotebook::SetConstraintSizes(bool /* recurse */)
344 // don't set the sizes of the pages - their correct size is not yet known
345 wxControl::SetConstraintSizes(FALSE
);
348 bool wxNotebook::DoPhase(int /* nPhase */)
353 void wxNotebook::Command(wxCommandEvent
& event
)
355 wxFAIL_MSG("wxNotebook::Command not implemented");
358 // ----------------------------------------------------------------------------
359 // wxNotebook helper functions
360 // ----------------------------------------------------------------------------
362 // hide the currently active panel and show the new one
363 void wxNotebook::ChangePage(int nOldSel
, int nSel
)
365 wxASSERT( nOldSel
!= nSel
); // impossible
367 if ( nOldSel
!= -1 ) {
368 m_aPages
[nOldSel
]->Show(FALSE
);
371 wxNotebookPage
*pPage
= m_aPages
[nSel
];
378 void wxNotebook::SetTabSize(const wxSize
& sz
)