]>
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
);
206 bool wxNotebook::DeleteAllPages()
208 // TODO: delete native widget pages
210 int nPageCount
= GetPageCount();
212 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
213 delete m_aPages
[nPage
];
220 // add a page to the notebook
221 bool wxNotebook::AddPage(wxNotebookPage
*pPage
,
222 const wxString
& strText
,
226 return InsertPage(GetPageCount(), pPage
, strText
, bSelect
, imageId
);
229 // same as AddPage() but does it at given position
230 bool wxNotebook::InsertPage(int nPage
,
231 wxNotebookPage
*pPage
,
232 const wxString
& strText
,
236 wxASSERT( pPage
!= NULL
);
237 wxCHECK( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), FALSE
);
239 // TODO: insert native widget page
241 // save the pointer to the page
242 m_aPages
.Insert(pPage
, nPage
);
244 // some page must be selected: either this one or the first one if there is
245 // still no selection
247 m_nSelection
= nPage
;
248 else if ( m_nSelection
== -1 )
254 // ----------------------------------------------------------------------------
255 // wxNotebook callbacks
256 // ----------------------------------------------------------------------------
258 // @@@ OnSize() is used for setting the font when it's called for the first
259 // time because doing it in ::Create() doesn't work (for unknown reasons)
260 void wxNotebook::OnSize(wxSizeEvent
& event
)
262 static bool s_bFirstTime
= TRUE
;
263 if ( s_bFirstTime
) {
264 // TODO: any first-time-size processing.
265 s_bFirstTime
= FALSE
;
268 // TODO: all this may or may not be necessary for your platform
270 // emulate page change (it's esp. important to do it first time because
271 // otherwise our page would stay invisible)
272 int nSel
= m_nSelection
;
276 // fit the notebook page to the tab control's display area
280 uint nCount
= m_aPages
.Count();
281 for ( uint nPage
= 0; nPage
< nCount
; nPage
++ ) {
282 wxNotebookPage
*pPage
= m_aPages
[nPage
];
283 pPage
->SetSize(0, 0, w
, h
);
284 if ( pPage
->GetAutoLayout() )
288 // Processing continues to next OnSize
292 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
294 // is it our tab control?
295 if ( event
.GetEventObject() == this )
296 ChangePage(event
.GetOldSelection(), event
.GetSelection());
298 // we want to give others a chance to process this message as well
302 void wxNotebook::OnSetFocus(wxFocusEvent
& event
)
304 // set focus to the currently selected page if any
305 if ( m_nSelection
!= -1 )
306 m_aPages
[m_nSelection
]->SetFocus();
311 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
313 if ( event
.IsWindowChange() ) {
315 AdvanceSelection(event
.GetDirection());
318 // pass to the parent
320 event
.SetCurrentFocus(this);
321 GetParent()->ProcessEvent(event
);
326 // ----------------------------------------------------------------------------
327 // wxNotebook base class virtuals
328 // ----------------------------------------------------------------------------
330 // override these 2 functions to do nothing: everything is done in OnSize
332 void wxNotebook::SetConstraintSizes(bool /* recurse */)
334 // don't set the sizes of the pages - their correct size is not yet known
335 wxControl::SetConstraintSizes(FALSE
);
338 bool wxNotebook::DoPhase(int /* nPhase */)
343 void wxNotebook::Command(wxCommandEvent
& event
)
345 wxFAIL_MSG("wxNotebook::Command not implemented");
348 // ----------------------------------------------------------------------------
349 // wxNotebook helper functions
350 // ----------------------------------------------------------------------------
352 // hide the currently active panel and show the new one
353 void wxNotebook::ChangePage(int nOldSel
, int nSel
)
355 wxASSERT( nOldSel
!= nSel
); // impossible
357 if ( nOldSel
!= -1 ) {
358 m_aPages
[nOldSel
]->Show(FALSE
);
361 wxNotebookPage
*pPage
= m_aPages
[nSel
];