X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7848088476db284a94f19eeb24411b45d676ac46..87f0b1323b7ac77f02133b836c8dfee63b0fd387:/src/cocoa/notebook.mm diff --git a/src/cocoa/notebook.mm b/src/cocoa/notebook.mm index 3518e49a50..0a892ca2f3 100644 --- a/src/cocoa/notebook.mm +++ b/src/cocoa/notebook.mm @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: cocoa/notebook.mm +// Name: src/cocoa/notebook.mm // Purpose: wxNotebook // Author: David Elliott // Modified by: @@ -10,14 +10,18 @@ ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" + +#if wxUSE_NOTEBOOK + #ifndef WX_PRECOMP #include "wx/app.h" - #include "wx/notebook.h" #endif //WX_PRECOMP +#include "wx/notebook.h" #include "wx/imaglist.h" #include "wx/cocoa/autorelease.h" #include "wx/cocoa/string.h" +#include "wx/cocoa/objc/objc_uniquifying.h" #import #import @@ -45,6 +49,7 @@ - (NSImage*)image; - (void)setImage:(NSImage*)image; @end // interface WXCTabViewImageItem : NSTabViewItem +WX_DECLARE_GET_OBJC_CLASS(WXCTabViewImageItem,NSTabViewItem) @implementation WXCTabViewImageItem : NSTabViewItem - (id)init @@ -61,6 +66,7 @@ - (void)dealloc { [m_image release]; + [super dealloc]; } - (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel @@ -116,18 +122,12 @@ } @end // implementation WXCTabViewImageItem : NSTabViewItem - -// ======================================================================== -// wxNotebookEvent -// ======================================================================== -DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) -IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) +WX_IMPLEMENT_GET_OBJC_CLASS(WXCTabViewImageItem,NSTabViewItem) // ======================================================================== // wxNotebook // ======================================================================== -IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) + BEGIN_EVENT_TABLE(wxNotebook, wxNotebookBase) END_EVENT_TABLE() WX_IMPLEMENT_COCOA_OWNER(wxNotebook,NSTabView,NSView,NSView) @@ -143,6 +143,23 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID winid, return false; m_cocoaNSView = NULL; SetNSTabView([[NSTabView alloc] initWithFrame:MakeDefaultNSRect(size)]); + + do + { + NSTabViewType tabViewType; + if(style & wxNB_TOP) + tabViewType = NSTopTabsBezelBorder; + else if(style & wxNB_LEFT) + tabViewType = NSLeftTabsBezelBorder; + else if(style & wxNB_RIGHT) + tabViewType = NSRightTabsBezelBorder; + else if(style & wxNB_BOTTOM) + tabViewType = NSBottomTabsBezelBorder; + else + break; + [GetNSTabView() setTabViewType:tabViewType]; + } while(0); + if(m_parent) m_parent->CocoaAddChild(this); SetInitialFrameRect(pos,size); @@ -177,7 +194,7 @@ wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage) [tvitem retain]; [GetNSTabView() removeTabViewItem:tvitem]; // Remove the child window as a notebook page - wxASSERT([tvitem view] == page->GetNSViewForSuperview()); + wxASSERT(static_cast([tvitem view]) == page->GetNSViewForSuperview()); [tvitem setView:nil]; [tvitem release]; // Make it back into a normal child window @@ -197,9 +214,9 @@ bool wxNotebook::InsertPage( size_t pos, { wxAutoNSAutoreleasePool pool; m_pages.Insert(page,pos); - NSTabViewItem *tvitem = [[WXCTabViewImageItem alloc] initWithIdentifier:nil]; + NSTabViewItem *tvitem = [[WX_GET_OBJC_CLASS(WXCTabViewImageItem) alloc] initWithIdentifier:nil]; [tvitem setLabel: wxNSStringWithWxString(title)]; - const wxBitmap *bmp = (imageId!=-1)?m_imageList->GetBitmap(imageId):NULL; + const wxBitmap *bmp = (imageId!=-1)?m_imageList->GetBitmapPtr(imageId):NULL; if(bmp) [(WXCTabViewImageItem*) tvitem setImage: bmp->GetNSImage(true)]; @@ -247,7 +264,7 @@ int wxNotebook::GetPageImage(size_t nPage) const bool wxNotebook::SetPageImage(size_t nPage, int nImage) { - const wxBitmap *bmp = nImage!=-1?m_imageList->GetBitmap(nImage):NULL; + const wxBitmap *bmp = nImage!=-1?m_imageList->GetBitmapPtr(nImage):NULL; if(!bmp) return false; NSTabViewItem *tvitem = [GetNSTabView() tabViewItemAtIndex: nPage]; @@ -257,9 +274,25 @@ bool wxNotebook::SetPageImage(size_t nPage, int nImage) return true; } - int wxNotebook::SetSelection(size_t nPage) { + const int pageOld = GetSelection(); + + if ( !SendPageChangingEvent(nPage) ) + return pageOld; + + int page = ChangeSelection(nPage); + if ( page != wxNOT_FOUND ) + { + SendPageChangedEvent(pageOld); + } + + return page; +} + +int wxNotebook::ChangeSelection(size_t nPage) +{ + wxAutoNSAutoreleasePool pool; [GetNSTabView() selectTabViewItemAtIndex:nPage]; return GetSelection(); } @@ -268,23 +301,25 @@ int wxNotebook::GetSelection() const { NSTabViewItem *selectedItem = [GetNSTabView() selectedTabViewItem]; if(!selectedItem) - return -1; + return wxNOT_FOUND; return [GetNSTabView() indexOfTabViewItem:selectedItem]; } void wxNotebook::CocoaDelegate_tabView_didSelectTabViewItem(WX_NSTabViewItem tabViewItem) { // FIXME: oldSel probably == newSel - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, GetId(), + wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, GetId(), [GetNSTabView() indexOfTabViewItem:tabViewItem], GetSelection()); event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); } bool wxNotebook::CocoaDelegate_tabView_shouldSelectTabViewItem(WX_NSTabViewItem tabViewItem) { - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, GetId(), + wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, GetId(), [GetNSTabView() indexOfTabViewItem:tabViewItem], GetSelection()); event.SetEventObject(this); - return !GetEventHandler()->ProcessEvent(event) || event.IsAllowed(); + return !HandleWindowEvent(event) || event.IsAllowed(); } +#endif // wxUSE_NOTEBOOK