#include <wx/log.h>
#include <wx/imaglist.h>
#include <wx/notebook.h>
-
+#include <wx/mac/uma.h>
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// check that the page index is valid
#define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount()))
+const short kwxMacTabLeftMargin = 16 ;
+const short kwxMacTabTopMargin = 30 ;
+const short kwxMacTabRightMargin = 16 ;
+const short kwxMacTabBottomMargin = 16 ;
+
// ----------------------------------------------------------------------------
// event table
// ----------------------------------------------------------------------------
-#if !USE_SHARED_LIBRARIES
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
+
BEGIN_EVENT_TABLE(wxNotebook, wxControl)
EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange)
IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
-#endif
// ============================================================================
// implementation
long style,
const wxString& name)
{
- // base init
- SetName(name);
- SetParent(parent);
-
- m_windowId = id == -1 ? NewControlId() : id;
-
- // style
- m_windowStyle = style;
-
- if ( parent != NULL )
- parent->AddChild(this);
-
- // TODO
-
- return FALSE;
+ Rect bounds ;
+ Str255 title ;
+
+ MacPreControlCreate( parent , id , "" , pos , size ,style, *((wxValidator*)NULL) , name , &bounds , title ) ;
+
+ m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1,
+ kControlTabSmallProc , (long) this ) ;
+
+ MacPostControlCreate() ;
+ return TRUE ;
}
// dtor
int wxNotebook::GetRowCount() const
{
- // TODO
- return 0;
+ return 1;
}
int wxNotebook::SetSelection(int nPage)
wxASSERT( IS_VALID_PAGE(nPage) );
ChangePage(m_nSelection, nPage);
-
- // TODO
- return 0;
+ SetControlValue( m_macControl , m_nSelection + 1 ) ;
+// Boolean enabled = true ;
+
+// SetControlData( m_macControl, m_nSelection + 1, kControlTabEnabledFlagTag, sizeof( Boolean ), (Ptr)&enabled );
+ return m_nSelection;
}
void wxNotebook::AdvanceSelection(bool bForward)
wxASSERT( pPage != NULL );
wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE );
- // TODO: insert native widget page
+ ControlTabInfoRec tie ;
+ Boolean enabled = true ;
+ if ( nPage + 1 > GetControlMaximum( m_macControl ) )
+ {
+ SetControlMaximum( m_macControl , nPage + 1 ) ;
+ }
+
+ tie.version = 0 ;
+ tie.iconSuiteID = 0 ;
+ c2pstrcpy( (StringPtr) tie.name , strText ) ;
+ SetControlData( m_macControl, nPage + 1, kControlTabInfoTag , sizeof( ControlTabInfoRec) , (char*) &tie ) ;
+ SetControlData( m_macControl, m_nSelection + 1, kControlTabEnabledFlagTag, sizeof( Boolean ), (Ptr)&enabled );
// save the pointer to the page
m_aPages.Insert(pPage, nPage);
else if ( m_nSelection == -1 )
m_nSelection = 0;
+ // don't show pages by default (we'll need to adjust their size first)
+ pPage->Show( FALSE ) ;
+
return TRUE;
}
unsigned int nCount = m_aPages.Count();
for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) {
wxNotebookPage *pPage = m_aPages[nPage];
- pPage->SetSize(0, 0, w, h);
+ pPage->SetSize(kwxMacTabLeftMargin, kwxMacTabTopMargin, w - kwxMacTabLeftMargin - kwxMacTabRightMargin,
+ h - kwxMacTabTopMargin - kwxMacTabBottomMargin );
+// pPage->SetSize(0, 0, w, h);
if ( pPage->GetAutoLayout() )
pPage->Layout();
}
// hide the currently active panel and show the new one
void wxNotebook::ChangePage(int nOldSel, int nSel)
{
- wxASSERT( nOldSel != nSel ); // impossible
+ // it's not an error (the message may be generated by the tab control itself)
+ // and it may happen - just do nothing
+ if ( nSel == nOldSel )
+ {
+ wxNotebookPage *pPage = m_aPages[nSel];
+ pPage->Show(FALSE);
+ pPage->Show(TRUE);
+ pPage->SetFocus();
+ return;
+ }
if ( nOldSel != -1 ) {
m_aPages[nOldSel]->Show(FALSE);
m_nSelection = nSel;
}
+void wxNotebook::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
+{
+ wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControlValue(m_macControl) - 1, m_nSelection);
+ event.SetEventObject(this);
+
+ ProcessEvent(event);
+}
+