]>
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 BEGIN_EVENT_TABLE(wxNotebook
, wxControl
)
40 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange
)
42 EVT_SIZE(wxNotebook::OnSize
)
43 EVT_SET_FOCUS(wxNotebook::OnSetFocus
)
44 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey
)
47 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
, wxControl
)
48 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent
, wxCommandEvent
)
50 // ============================================================================
52 // ============================================================================
54 // ----------------------------------------------------------------------------
55 // wxNotebook construction
56 // ----------------------------------------------------------------------------
58 // common part of all ctors
59 void wxNotebook::Init()
65 // default for dynamic class
66 wxNotebook::wxNotebook()
71 // the same arguments as for wxControl
72 wxNotebook::wxNotebook(wxWindow
*parent
,
81 Create(parent
, id
, pos
, size
, style
, name
);
85 bool wxNotebook::Create(wxWindow
*parent
,
96 m_windowId
= id
== -1 ? NewControlId() : id
;
99 m_windowStyle
= style
;
101 if ( parent
!= NULL
)
102 parent
->AddChild(this);
110 wxNotebook::~wxNotebook()
114 // ----------------------------------------------------------------------------
115 // wxNotebook accessors
116 // ----------------------------------------------------------------------------
117 int wxNotebook::GetPageCount() const
119 return m_aPages
.Count();
122 int wxNotebook::GetRowCount() const
128 int wxNotebook::SetSelection(int nPage
)
130 wxASSERT( IS_VALID_PAGE(nPage
) );
132 ChangePage(m_nSelection
, nPage
);
138 void wxNotebook::AdvanceSelection(bool bForward
)
140 int nSel
= GetSelection();
141 int nMax
= GetPageCount() - 1;
143 SetSelection(nSel
== nMax
? 0 : nSel
+ 1);
145 SetSelection(nSel
== 0 ? nMax
: nSel
- 1);
148 bool wxNotebook::SetPageText(int nPage
, const wxString
& strText
)
150 wxASSERT( IS_VALID_PAGE(nPage
) );
156 wxString
wxNotebook::GetPageText(int nPage
) const
158 wxASSERT( IS_VALID_PAGE(nPage
) );
164 int wxNotebook::GetPageImage(int nPage
) const
166 wxASSERT( IS_VALID_PAGE(nPage
) );
172 bool wxNotebook::SetPageImage(int nPage
, int nImage
)
174 wxASSERT( IS_VALID_PAGE(nPage
) );
180 void wxNotebook::SetImageList(wxImageList
* imageList
)
182 m_pImageList
= imageList
;
186 // ----------------------------------------------------------------------------
187 // wxNotebook operations
188 // ----------------------------------------------------------------------------
190 // remove one page from the notebook
191 bool wxNotebook::DeletePage(int nPage
)
193 wxCHECK( IS_VALID_PAGE(nPage
), FALSE
);
195 // TODO: delete native widget page
197 delete m_aPages
[nPage
];
198 m_aPages
.Remove(nPage
);
203 // remove one page from the notebook, without deleting the window
204 bool wxNotebook::RemovePage(int nPage
)
206 wxCHECK( IS_VALID_PAGE(nPage
), FALSE
);
208 m_aPages
.Remove(nPage
);
214 bool wxNotebook::DeleteAllPages()
216 // TODO: delete native widget pages
218 int nPageCount
= GetPageCount();
220 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
221 delete m_aPages
[nPage
];
228 // add a page to the notebook
229 bool wxNotebook::AddPage(wxNotebookPage
*pPage
,
230 const wxString
& strText
,
234 return InsertPage(GetPageCount(), pPage
, strText
, bSelect
, imageId
);
237 // same as AddPage() but does it at given position
238 bool wxNotebook::InsertPage(int nPage
,
239 wxNotebookPage
*pPage
,
240 const wxString
& strText
,
244 wxASSERT( pPage
!= NULL
);
245 wxCHECK( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), FALSE
);
247 // TODO: insert native widget page
249 // save the pointer to the page
250 m_aPages
.Insert(pPage
, nPage
);
252 // some page must be selected: either this one or the first one if there is
253 // still no selection
255 m_nSelection
= nPage
;
256 else if ( m_nSelection
== -1 )
262 // ----------------------------------------------------------------------------
263 // wxNotebook callbacks
264 // ----------------------------------------------------------------------------
266 // @@@ OnSize() is used for setting the font when it's called for the first
267 // time because doing it in ::Create() doesn't work (for unknown reasons)
268 void wxNotebook::OnSize(wxSizeEvent
& event
)
270 static bool s_bFirstTime
= TRUE
;
271 if ( s_bFirstTime
) {
272 // TODO: any first-time-size processing.
273 s_bFirstTime
= FALSE
;
276 // TODO: all this may or may not be necessary for your platform
278 // emulate page change (it's esp. important to do it first time because
279 // otherwise our page would stay invisible)
280 int nSel
= m_nSelection
;
284 // fit the notebook page to the tab control's display area
288 unsigned int nCount
= m_aPages
.Count();
289 for ( unsigned int nPage
= 0; nPage
< nCount
; nPage
++ ) {
290 wxNotebookPage
*pPage
= m_aPages
[nPage
];
291 pPage
->SetSize(0, 0, w
, h
);
292 if ( pPage
->GetAutoLayout() )
296 // Processing continues to next OnSize
300 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
302 // is it our tab control?
303 if ( event
.GetEventObject() == this )
304 ChangePage(event
.GetOldSelection(), event
.GetSelection());
306 // we want to give others a chance to process this message as well
310 void wxNotebook::OnSetFocus(wxFocusEvent
& event
)
312 // set focus to the currently selected page if any
313 if ( m_nSelection
!= -1 )
314 m_aPages
[m_nSelection
]->SetFocus();
319 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
321 if ( event
.IsWindowChange() ) {
323 AdvanceSelection(event
.GetDirection());
326 // pass to the parent
328 event
.SetCurrentFocus(this);
329 GetParent()->ProcessEvent(event
);
334 // ----------------------------------------------------------------------------
335 // wxNotebook base class virtuals
336 // ----------------------------------------------------------------------------
338 // override these 2 functions to do nothing: everything is done in OnSize
340 void wxNotebook::SetConstraintSizes(bool /* recurse */)
342 // don't set the sizes of the pages - their correct size is not yet known
343 wxControl::SetConstraintSizes(FALSE
);
346 bool wxNotebook::DoPhase(int /* nPhase */)
351 void wxNotebook::Command(wxCommandEvent
& event
)
353 wxFAIL_MSG("wxNotebook::Command not implemented");
356 // ----------------------------------------------------------------------------
357 // wxNotebook helper functions
358 // ----------------------------------------------------------------------------
360 // hide the currently active panel and show the new one
361 void wxNotebook::ChangePage(int nOldSel
, int nSel
)
363 wxASSERT( nOldSel
!= nSel
); // impossible
365 if ( nOldSel
!= -1 ) {
366 m_aPages
[nOldSel
]->Show(FALSE
);
369 wxNotebookPage
*pPage
= m_aPages
[nSel
];
376 void wxNotebook::SetTabSize(const wxSize
& sz
)