]>
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 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_backgroundColour 
= wxColour(GetSysColor(COLOR_BTNFACE
)); 
 100     m_foregroundColour 
= *wxBLACK 
; 
 103     m_windowStyle 
= style
; 
 105     if ( parent 
!= NULL 
) 
 106         parent
->AddChild(this); 
 114 wxNotebook::~wxNotebook() 
 118 // ---------------------------------------------------------------------------- 
 119 // wxNotebook accessors 
 120 // ---------------------------------------------------------------------------- 
 121 int wxNotebook::GetPageCount() const 
 123     return m_aPages
.Count(); 
 126 int wxNotebook::GetRowCount() const 
 132 int wxNotebook::SetSelection(int nPage
) 
 134     wxASSERT( IS_VALID_PAGE(nPage
) ); 
 136     ChangePage(m_nSelection
, nPage
); 
 142 void wxNotebook::AdvanceSelection(bool bForward
) 
 144     int nSel 
= GetSelection(); 
 145     int nMax 
= GetPageCount() - 1; 
 147         SetSelection(nSel 
== nMax 
? 0 : nSel 
+ 1); 
 149         SetSelection(nSel 
== 0 ? nMax 
: nSel 
- 1); 
 152 bool wxNotebook::SetPageText(int nPage
, const wxString
& strText
) 
 154     wxASSERT( IS_VALID_PAGE(nPage
) ); 
 160 wxString 
wxNotebook::GetPageText(int nPage
) const 
 162     wxASSERT( IS_VALID_PAGE(nPage
) ); 
 168 int wxNotebook::GetPageImage(int nPage
) const 
 170     wxASSERT( IS_VALID_PAGE(nPage
) ); 
 176 bool wxNotebook::SetPageImage(int nPage
, int nImage
) 
 178     wxASSERT( IS_VALID_PAGE(nPage
) ); 
 184 void wxNotebook::SetImageList(wxImageList
* imageList
) 
 186     m_pImageList 
= imageList
; 
 190 // ---------------------------------------------------------------------------- 
 191 // wxNotebook operations 
 192 // ---------------------------------------------------------------------------- 
 194 // remove one page from the notebook 
 195 bool wxNotebook::DeletePage(int nPage
) 
 197     wxCHECK( IS_VALID_PAGE(nPage
), FALSE 
); 
 199     // TODO: delete native widget page 
 201     delete m_aPages
[nPage
]; 
 202     m_aPages
.Remove(nPage
); 
 208 bool wxNotebook::DeleteAllPages() 
 210     // TODO: delete native widget pages 
 212     int nPageCount 
= GetPageCount(); 
 214     for ( nPage 
= 0; nPage 
< nPageCount
; nPage
++ ) 
 215         delete m_aPages
[nPage
]; 
 222 // add a page to the notebook 
 223 bool wxNotebook::AddPage(wxNotebookPage 
*pPage
, 
 224                          const wxString
& strText
, 
 228     return InsertPage(GetPageCount(), pPage
, strText
, bSelect
, imageId
); 
 231 // same as AddPage() but does it at given position 
 232 bool wxNotebook::InsertPage(int nPage
, 
 233                             wxNotebookPage 
*pPage
, 
 234                             const wxString
& strText
, 
 238     wxASSERT( pPage 
!= NULL 
); 
 239     wxCHECK( IS_VALID_PAGE(nPage
) || nPage 
== GetPageCount(), FALSE 
); 
 241     // TODO: insert native widget page 
 243     // save the pointer to the page 
 244     m_aPages
.Insert(pPage
, nPage
); 
 246     // some page must be selected: either this one or the first one if there is  
 247     // still no selection 
 249         m_nSelection 
= nPage
; 
 250     else if ( m_nSelection 
== -1 ) 
 256 // ---------------------------------------------------------------------------- 
 257 // wxNotebook callbacks 
 258 // ---------------------------------------------------------------------------- 
 260 // @@@ OnSize() is used for setting the font when it's called for the first 
 261 //     time because doing it in ::Create() doesn't work (for unknown reasons) 
 262 void wxNotebook::OnSize(wxSizeEvent
& event
) 
 264     static bool s_bFirstTime 
= TRUE
; 
 265     if ( s_bFirstTime 
) { 
 266         // TODO: any first-time-size processing. 
 267         s_bFirstTime 
= FALSE
; 
 270     // TODO: all this may or may not be necessary for your platform 
 272     // emulate page change (it's esp. important to do it first time because 
 273     // otherwise our page would stay invisible) 
 274     int nSel 
= m_nSelection
; 
 278     // fit the notebook page to the tab control's display area 
 282     uint nCount 
= m_aPages
.Count(); 
 283     for ( uint nPage 
= 0; nPage 
< nCount
; nPage
++ ) { 
 284         wxNotebookPage 
*pPage 
= m_aPages
[nPage
]; 
 285         pPage
->SetSize(0, 0, w
, h
); 
 286         if ( pPage
->GetAutoLayout() ) 
 290     // Processing continues to next OnSize 
 294 void wxNotebook::OnSelChange(wxNotebookEvent
& event
) 
 296     // is it our tab control? 
 297     if ( event
.GetEventObject() == this ) 
 298         ChangePage(event
.GetOldSelection(), event
.GetSelection()); 
 300     // we want to give others a chance to process this message as well 
 304 void wxNotebook::OnSetFocus(wxFocusEvent
& event
) 
 306     // set focus to the currently selected page if any 
 307     if ( m_nSelection 
!= -1 ) 
 308         m_aPages
[m_nSelection
]->SetFocus(); 
 313 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
) 
 315     if ( event
.IsWindowChange() ) { 
 317         AdvanceSelection(event
.GetDirection()); 
 320         // pass to the parent 
 322             event
.SetCurrentFocus(this); 
 323             GetParent()->ProcessEvent(event
); 
 328 // ---------------------------------------------------------------------------- 
 329 // wxNotebook base class virtuals 
 330 // ---------------------------------------------------------------------------- 
 332 // override these 2 functions to do nothing: everything is done in OnSize 
 334 void wxNotebook::SetConstraintSizes(bool /* recurse */) 
 336     // don't set the sizes of the pages - their correct size is not yet known 
 337     wxControl::SetConstraintSizes(FALSE
); 
 340 bool wxNotebook::DoPhase(int /* nPhase */) 
 345 void wxNotebook::Command(wxCommandEvent
& event
) 
 347     wxFAIL_MSG("wxNotebook::Command not implemented"); 
 350 // ---------------------------------------------------------------------------- 
 351 // wxNotebook helper functions 
 352 // ---------------------------------------------------------------------------- 
 354 // hide the currently active panel and show the new one 
 355 void wxNotebook::ChangePage(int nOldSel
, int nSel
) 
 357     wxASSERT( nOldSel 
!= nSel 
); // impossible 
 359     if ( nOldSel 
!= -1 ) { 
 360         m_aPages
[nOldSel
]->Show(FALSE
); 
 363     wxNotebookPage 
*pPage 
= m_aPages
[nSel
];