]>
git.saurik.com Git - wxWidgets.git/blob - src/qt/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_backgroundColour
= wxColour(GetSysColor(COLOR_BTNFACE
));
102 m_foregroundColour
= *wxBLACK
;
105 m_windowStyle
= style
;
107 if ( parent
!= NULL
)
108 parent
->AddChild(this);
116 wxNotebook::~wxNotebook()
120 // ----------------------------------------------------------------------------
121 // wxNotebook accessors
122 // ----------------------------------------------------------------------------
123 int wxNotebook::GetPageCount() const
125 return m_aPages
.Count();
128 int wxNotebook::GetRowCount() const
134 int wxNotebook::SetSelection(int nPage
)
136 wxASSERT( IS_VALID_PAGE(nPage
) );
138 ChangePage(m_nSelection
, nPage
);
144 void wxNotebook::AdvanceSelection(bool bForward
)
146 int nSel
= GetSelection();
147 int nMax
= GetPageCount() - 1;
149 SetSelection(nSel
== nMax
? 0 : nSel
+ 1);
151 SetSelection(nSel
== 0 ? nMax
: nSel
- 1);
154 bool wxNotebook::SetPageText(int nPage
, const wxString
& strText
)
156 wxASSERT( IS_VALID_PAGE(nPage
) );
162 wxString
wxNotebook::GetPageText(int nPage
) const
164 wxASSERT( IS_VALID_PAGE(nPage
) );
170 int wxNotebook::GetPageImage(int nPage
) const
172 wxASSERT( IS_VALID_PAGE(nPage
) );
178 bool wxNotebook::SetPageImage(int nPage
, int nImage
)
180 wxASSERT( IS_VALID_PAGE(nPage
) );
186 void wxNotebook::SetImageList(wxImageList
* imageList
)
188 m_pImageList
= imageList
;
192 // ----------------------------------------------------------------------------
193 // wxNotebook operations
194 // ----------------------------------------------------------------------------
196 // remove one page from the notebook
197 bool wxNotebook::DeletePage(int nPage
)
199 wxCHECK( IS_VALID_PAGE(nPage
), FALSE
);
201 // TODO: delete native widget page
203 delete m_aPages
[nPage
];
204 m_aPages
.Remove(nPage
);
210 bool wxNotebook::DeleteAllPages()
212 // TODO: delete native widget pages
214 int nPageCount
= GetPageCount();
216 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
217 delete m_aPages
[nPage
];
224 // add a page to the notebook
225 bool wxNotebook::AddPage(wxNotebookPage
*pPage
,
226 const wxString
& strText
,
230 return InsertPage(GetPageCount(), pPage
, strText
, bSelect
, imageId
);
233 // same as AddPage() but does it at given position
234 bool wxNotebook::InsertPage(int nPage
,
235 wxNotebookPage
*pPage
,
236 const wxString
& strText
,
240 wxASSERT( pPage
!= NULL
);
241 wxCHECK( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), FALSE
);
243 // TODO: insert native widget page
245 // save the pointer to the page
246 m_aPages
.Insert(pPage
, nPage
);
248 // some page must be selected: either this one or the first one if there is
249 // still no selection
251 m_nSelection
= nPage
;
252 else if ( m_nSelection
== -1 )
258 // ----------------------------------------------------------------------------
259 // wxNotebook callbacks
260 // ----------------------------------------------------------------------------
262 // @@@ OnSize() is used for setting the font when it's called for the first
263 // time because doing it in ::Create() doesn't work (for unknown reasons)
264 void wxNotebook::OnSize(wxSizeEvent
& event
)
266 static bool s_bFirstTime
= TRUE
;
267 if ( s_bFirstTime
) {
268 // TODO: any first-time-size processing.
269 s_bFirstTime
= FALSE
;
272 // TODO: all this may or may not be necessary for your platform
274 // emulate page change (it's esp. important to do it first time because
275 // otherwise our page would stay invisible)
276 int nSel
= m_nSelection
;
280 // fit the notebook page to the tab control's display area
284 uint nCount
= m_aPages
.Count();
285 for ( uint nPage
= 0; nPage
< nCount
; nPage
++ ) {
286 wxNotebookPage
*pPage
= m_aPages
[nPage
];
287 pPage
->SetSize(0, 0, w
, h
);
288 if ( pPage
->GetAutoLayout() )
292 // Processing continues to next OnSize
296 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
298 // is it our tab control?
299 if ( event
.GetEventObject() == this )
300 ChangePage(event
.GetOldSelection(), event
.GetSelection());
302 // we want to give others a chance to process this message as well
306 void wxNotebook::OnSetFocus(wxFocusEvent
& event
)
308 // set focus to the currently selected page if any
309 if ( m_nSelection
!= -1 )
310 m_aPages
[m_nSelection
]->SetFocus();
315 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
317 if ( event
.IsWindowChange() ) {
319 AdvanceSelection(event
.GetDirection());
322 // pass to the parent
324 event
.SetCurrentFocus(this);
325 GetParent()->ProcessEvent(event
);
330 // ----------------------------------------------------------------------------
331 // wxNotebook base class virtuals
332 // ----------------------------------------------------------------------------
334 // override these 2 functions to do nothing: everything is done in OnSize
336 void wxNotebook::SetConstraintSizes(bool /* recurse */)
338 // don't set the sizes of the pages - their correct size is not yet known
339 wxControl::SetConstraintSizes(FALSE
);
342 bool wxNotebook::DoPhase(int /* nPhase */)
347 void wxNotebook::Command(wxCommandEvent
& event
)
349 wxFAIL_MSG("wxNotebook::Command not implemented");
352 // ----------------------------------------------------------------------------
353 // wxNotebook helper functions
354 // ----------------------------------------------------------------------------
356 // hide the currently active panel and show the new one
357 void wxNotebook::ChangePage(int nOldSel
, int nSel
)
359 wxASSERT( nOldSel
!= nSel
); // impossible
361 if ( nOldSel
!= -1 ) {
362 m_aPages
[nOldSel
]->Show(FALSE
);
365 wxNotebookPage
*pPage
= m_aPages
[nSel
];