From 6b61fe54e1cdc349787c8f2e098bf548a516d488 Mon Sep 17 00:00:00 2001 From: Linas Valiukas Date: Thu, 30 Jun 2011 01:02:17 +0000 Subject: [PATCH] Minimal wxMoNotebook implementation (now sort of works) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WXIOS@68105 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mobile/native/panel.h | 2 +- samples/mobile/demo/demoframe.cpp | 15 +++-- .../mobile/demoios.xcodeproj/project.pbxproj | 4 ++ src/mobile/native/mo_panel_n.mm | 4 +- src/osx/iphone/notebook.mm | 55 +++++++------------ src/osx/iphone/toolbar.mm | 1 + src/osx/iphone/window.mm | 55 ++++++++++++++----- 7 files changed, 75 insertions(+), 61 deletions(-) diff --git a/include/wx/mobile/native/panel.h b/include/wx/mobile/native/panel.h index 74ac1e3a11..2b2b7d8933 100644 --- a/include/wx/mobile/native/panel.h +++ b/include/wx/mobile/native/panel.h @@ -56,7 +56,7 @@ public: virtual ~wxMoPanel(); - // Ignore attempts to hide too + // Ignore attempts to hide panel bool Show(bool show = true); // calls layout for layout constraints and sizers diff --git a/samples/mobile/demo/demoframe.cpp b/samples/mobile/demo/demoframe.cpp index 2a217706f1..9c671cff8b 100755 --- a/samples/mobile/demo/demoframe.cpp +++ b/samples/mobile/demo/demoframe.cpp @@ -375,26 +375,25 @@ void DemoFrame::CreateControls() wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); SetSizer(topSizer); - wxMoStaticText *testStaticText = new wxMoStaticText(this, wxID_ANY, "Hello.", wxDefaultPosition, wxSize(-1, -1), wxNO_BORDER); - - return; - wxMoNotebook* notebook = new wxMoNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxBK_BOTTOM|wxBK_TEXT|wxBK_BITMAP|wxNO_BORDER); topSizer->Add(notebook, 1, wxEXPAND); - wxMoPanel* page1 = new wxMoPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER); + wxMoPanel* page1 = new wxMoPanel(notebook, wxID_ANY, wxPoint(0, 0), wxSize(320, 411), wxNO_BORDER); notebook->AddPage(page1, _("Demo"), true, wxID_TOPRATED); // Items for page 1 { wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); page1->SetSizer(sizer); + + wxMoStaticText *testStaticText = new wxMoStaticText(page1, wxID_ANY, "Hello.", wxPoint(40, 40), wxSize(100, 100), wxNO_BORDER); + wxMoNavigationCtrl* navCtrl = new wxMoNavigationCtrl(page1, wxID_ANY); sizer->Add(navCtrl, 1, wxEXPAND, 0); navCtrl->PushController(new TableDemoController(_("iPhone Demo"), navCtrl)); } - - wxMoPanel* page2 = new wxMoPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER); + + wxMoPanel* page2 = new wxMoPanel(notebook, wxID_ANY, wxPoint(0, 0), wxSize(320, 411), wxNO_BORDER); notebook->AddPage(page2, _("Navigation"), false, wxID_SEARCH); // Items for page 2 @@ -408,7 +407,7 @@ void DemoFrame::CreateControls() navCtrl->PushController(new DemoViewController(_("Demo View 1"), navCtrl, 1)); } - wxMoPanel* page3 = new wxMoPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER); + wxMoPanel* page3 = new wxMoPanel(notebook, wxID_ANY, wxPoint(0, 0), wxSize(320, 411), wxNO_BORDER); notebook->AddPage(page3, _("Scrolling"), false, wxID_CONTACTS); notebook->SetBadge(2, wxT("1")); diff --git a/samples/mobile/demoios.xcodeproj/project.pbxproj b/samples/mobile/demoios.xcodeproj/project.pbxproj index 6d9dc1b1d2..afbad1a647 100755 --- a/samples/mobile/demoios.xcodeproj/project.pbxproj +++ b/samples/mobile/demoios.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 406DAC1F13B508E0002E4240 /* demoframe.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 406DAC1D13B508E0002E4240 /* demoframe.cpp */; }; 407EE18312F04CD500D0F171 /* libwx_osx_iphone.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4074F5E912ED969C00693A3F /* libwx_osx_iphone.a */; }; 407EE18A12F04CF900D0F171 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 407EE18912F04CF900D0F171 /* AudioToolbox.framework */; }; + B9133F9513BBC9FB0024E59E /* srchctrl.mm in Sources */ = {isa = PBXBuildFile; fileRef = B9133F9413BBC9FB0024E59E /* srchctrl.mm */; }; B9DF073E13B9FCF700D6F0D8 /* button.mm in Sources */ = {isa = PBXBuildFile; fileRef = B9DF072E13B9FCF700D6F0D8 /* button.mm */; }; B9DF073F13B9FCF700D6F0D8 /* checkbox.mm in Sources */ = {isa = PBXBuildFile; fileRef = B9DF072F13B9FCF700D6F0D8 /* checkbox.mm */; }; B9DF074013B9FCF700D6F0D8 /* dialog.mm in Sources */ = {isa = PBXBuildFile; fileRef = B9DF073013B9FCF700D6F0D8 /* dialog.mm */; }; @@ -91,6 +92,7 @@ 407EE18912F04CF900D0F171 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 409CBDC913B13C7100AB1F39 /* wxdebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = wxdebug.xcconfig; path = ../../build/osx/wxdebug.xcconfig; sourceTree = SOURCE_ROOT; }; 409CBDCA13B13C7100AB1F39 /* wxrelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = wxrelease.xcconfig; path = ../../build/osx/wxrelease.xcconfig; sourceTree = SOURCE_ROOT; }; + B9133F9413BBC9FB0024E59E /* srchctrl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = srchctrl.mm; path = ../../src/osx/iphone/srchctrl.mm; sourceTree = SOURCE_ROOT; }; B9DF070813B9FCD800D6F0D8 /* app.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = app.h; sourceTree = ""; }; B9DF070913B9FCD800D6F0D8 /* barbutton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = barbutton.h; sourceTree = ""; }; B9DF070A13B9FCD800D6F0D8 /* bmpbutton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bmpbutton.h; sourceTree = ""; }; @@ -274,6 +276,7 @@ B9DF073613B9FCF700D6F0D8 /* notebook.mm */, B9DF073713B9FCF700D6F0D8 /* scrolbar.mm */, B9DF073813B9FCF700D6F0D8 /* slider.mm */, + B9133F9413BBC9FB0024E59E /* srchctrl.mm */, B9DF073913B9FCF700D6F0D8 /* stattext.mm */, B9DF073A13B9FCF700D6F0D8 /* textctrl.mm */, B9DF073B13B9FCF700D6F0D8 /* toolbar.mm */, @@ -501,6 +504,7 @@ B9DF074B13B9FCF700D6F0D8 /* toolbar.mm in Sources */, B9DF074C13B9FCF700D6F0D8 /* utils.mm in Sources */, B9DF074D13B9FCF700D6F0D8 /* window.mm in Sources */, + B9133F9513BBC9FB0024E59E /* srchctrl.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/mobile/native/mo_panel_n.mm b/src/mobile/native/mo_panel_n.mm index 30de1f94cb..ab52ee68e3 100755 --- a/src/mobile/native/mo_panel_n.mm +++ b/src/mobile/native/mo_panel_n.mm @@ -87,9 +87,7 @@ void wxMoPanel::DoSetSize(int x, int y, UIView *view = (UIView *)GetPeer()->GetWXWidget(); NSLog(@"attempt to set size; curr. panel: %@", view); - [view setFrame:CGRectMake(20, 20, 80, 80)]; - [view setBackgroundColor:[UIColor redColor]]; - [view setOpaque:YES]; + //[view setFrame:CGRectMake(20, 20, 80, 80)]; } // ---------------------------------------------------------------------------- diff --git a/src/osx/iphone/notebook.mm b/src/osx/iphone/notebook.mm index 568596eb7b..15ad5d331d 100644 --- a/src/osx/iphone/notebook.mm +++ b/src/osx/iphone/notebook.mm @@ -33,9 +33,10 @@ #pragma mark - #pragma mark Cocoa + #pragma mark UITabBarController -@interface wxUITabBarController : UITabBarController +@interface wxUITabBarController : UITabBarController { } @@ -64,9 +65,9 @@ class wxNotebookIPhoneImpl : public wxWidgetIPhoneImpl { public: - wxNotebookIPhoneImpl( wxWindowMac* peer , WXWidget w ) : wxWidgetIPhoneImpl(peer, w) + wxNotebookIPhoneImpl( wxWindowMac* peer , wxUITabBarController *tabBarController, WXWidget w ) : wxWidgetIPhoneImpl(peer, w) { - + m_tabBarController = tabBarController; } // Ignore attempts to set position/size @@ -83,9 +84,7 @@ public: void GetContentArea( int &left , int &top , int &width , int &height ) const { - UITabBar *tabBar = (UITabBar *)m_osxView; - - CGRect r = tabBar.bounds; + CGRect r = m_osxView.bounds; left = (int)r.origin.x; top = (int)r.origin.y; width = (int)r.size.width; @@ -94,35 +93,27 @@ public: void SetValue( wxInt32 value ) { - UITabBar *tabBar = (UITabBar *) m_osxView; - wxUITabBarController *tabBarController = (wxUITabBarController *)[tabBar delegate]; - // avoid 'changed' events when setting the tab programmatically - [tabBarController setDelegate:nil]; - [tabBarController setSelectedIndex:(value-1)]; - [tabBarController setDelegate:tabBarController]; + [m_tabBarController setDelegate:nil]; + [m_tabBarController setSelectedIndex:(value-1)]; + [m_tabBarController setDelegate:m_tabBarController]; } wxInt32 GetValue() const { - UITabBar *tabBar = (UITabBar *) m_osxView; - wxUITabBarController *tabBarController = (wxUITabBarController *)[tabBar delegate]; - return [tabBarController selectedIndex]+1; + return [m_tabBarController selectedIndex]+1; } void SetMaximum( wxInt32 maximum ) { - UITabBar *tabBar = (UITabBar *) m_osxView; - wxUITabBarController *tabBarController = (wxUITabBarController *)[tabBar delegate]; - - int tabCount = [[tabBarController viewControllers] count]; + int tabCount = [[m_tabBarController viewControllers] count]; if (maximum != tabCount) { - NSMutableArray *controllers = [NSMutableArray arrayWithArray:[tabBarController viewControllers]]; + NSMutableArray *controllers = [NSMutableArray arrayWithArray:[m_tabBarController viewControllers]]; // avoid 'changed' events when setting the tab programmatically - [tabBarController setDelegate:nil]; + [m_tabBarController setDelegate:nil]; if ( maximum > tabCount ) { @@ -142,8 +133,8 @@ public: [controllers removeObjectsInRange:removeRange]; } - [tabBarController setViewControllers:controllers]; - [tabBarController setDelegate:tabBarController]; + [m_tabBarController setViewControllers:controllers]; + [m_tabBarController setDelegate:m_tabBarController]; } } @@ -152,17 +143,14 @@ public: int pageCount = notebook.GetPageCount(); SetMaximum( pageCount ); - - UITabBar *tabBar = (UITabBar *) m_osxView; - wxUITabBarController *tabBarController = (wxUITabBarController *)[tabBar delegate]; - + // avoid 'changed' events when setting the tab programmatically - [tabBarController setDelegate:nil]; + [m_tabBarController setDelegate:nil]; for ( int i = 0 ; i < pageCount ; ++i ) { wxNotebookPage* page = notebook.GetPage(i); - UIViewController *controller = [[tabBarController viewControllers] objectAtIndex:i]; + UIViewController *controller = [[m_tabBarController viewControllers] objectAtIndex:i]; int pageImage = notebook.GetPageImage(i); UITabBarSystemItem systemItem = UITabBarSystemItemHistory; @@ -191,9 +179,11 @@ public: [controller setTitle:tabTitle]; } - [tabBarController setDelegate:tabBarController]; + [m_tabBarController setDelegate:m_tabBarController]; } +private: + wxUITabBarController *m_tabBarController; }; wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer, @@ -210,12 +200,9 @@ wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer, CGRect tabBarFrame = controller.tabBar.frame; tabBarFrame.origin.y -= 20; [controller.tabBar setFrame:tabBarFrame]; - [controller setDelegate:controller]; - CGRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; - - wxWidgetIPhoneImpl* c = new wxNotebookIPhoneImpl( wxpeer, controller.tabBar ); + wxWidgetIPhoneImpl* c = new wxNotebookIPhoneImpl( wxpeer, controller, controller.view ); return c; } diff --git a/src/osx/iphone/toolbar.mm b/src/osx/iphone/toolbar.mm index 23649e2c1f..7032383134 100644 --- a/src/osx/iphone/toolbar.mm +++ b/src/osx/iphone/toolbar.mm @@ -317,6 +317,7 @@ bool wxToolBar::Create( toolbar.barStyle = UIBarStyleDefault; break; } + m_macToolbar = toolbar; SetPeer(new wxWidgetIPhoneImpl( this, toolbar )); diff --git a/src/osx/iphone/window.mm b/src/osx/iphone/window.mm index 8c901b90f5..6f19c76a0c 100644 --- a/src/osx/iphone/window.mm +++ b/src/osx/iphone/window.mm @@ -71,6 +71,9 @@ CGRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const - (BOOL) becomeFirstResponder; - (BOOL) resignFirstResponder; + +- (NSString *)description; + @end // @@ -287,6 +290,27 @@ void wxOSX_drawRect(UIView* self, SEL _cmd, CGRect rect) return impl->drawRect(&rect, self, _cmd); } +NSString *wxOSX_description(UIView* self, SEL _cmd) +{ + wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self ); + if (impl == NULL) + return @"N/A"; + + NSMutableString *description = [NSMutableString stringWithString:@""]; + [description appendFormat:@"<%@: 0x%08x; superClass = %@; frame = %@; hidden = %@; opaque = %@; alpha = %f; backgroundColor = %@>", + NSStringFromClass([self class]), + self, + NSStringFromClass([self superclass]), + NSStringFromCGRect(self.frame), + (self.hidden ? @"YES" : @"NO"), + (self.opaque ? @"YES" : @"NO"), + self.alpha, + [self.backgroundColor description]]; + + return [NSString stringWithString:description]; + + // > +} void wxOSXIPhoneClassAddWXMethods(Class c) { @@ -296,6 +320,7 @@ void wxOSXIPhoneClassAddWXMethods(Class c) class_addMethod(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" ); class_addMethod(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" ); class_addMethod(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_CGRect={_CGPoint=ff}{_CGSize=ff}}" ); + class_addMethod(c, @selector(description), (IMP) wxOSX_description, "c@:" ); } // @@ -481,17 +506,11 @@ void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to void wxWidgetIPhoneImpl::SetBackgroundColour( const wxColour &col ) { - CGFloat red = (CGFloat)random()/(CGFloat)RAND_MAX; - CGFloat blue = (CGFloat)random()/(CGFloat)RAND_MAX; - CGFloat green = (CGFloat)random()/(CGFloat)RAND_MAX; - - m_osxView.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0]; - //m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()]; + m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()]; } bool wxWidgetIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style) { - /* if ( style == wxBG_STYLE_PAINT ) [m_osxView setOpaque: YES ]; else @@ -499,7 +518,6 @@ bool wxWidgetIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style) [m_osxView setOpaque: NO ]; m_osxView.backgroundColor = [UIColor clearColor]; } - */ return true; } @@ -508,7 +526,8 @@ void wxWidgetIPhoneImpl::SetLabel(const wxString& title, wxFontEncoding encoding if ( [m_osxView respondsToSelector:@selector(setTitle:forState:) ] ) { wxCFStringRef cf( title , encoding ); - [m_osxView setTitle:cf.AsNSString() forState:UIControlStateNormal ]; + [m_osxView setTitle:cf.AsNSString() + forState:UIControlStateNormal ]; } else if ( [m_osxView respondsToSelector:@selector(setStringValue:) ] ) { @@ -806,19 +825,25 @@ void wxWidgetIPhoneImpl::controlTextDidChange() // Factory methods // -wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent), - wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size, - long WXUNUSED(style), long WXUNUSED(extraStyle)) +wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), + const wxPoint& pos, + const wxSize& size, + long WXUNUSED(style), + long WXUNUSED(extraStyle)) { UIView* sv = (wxpeer->GetParent()->GetHandle() ); CGRect r = CGRectMake( pos.x, pos.y, size.x, size.y) ; // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ; - wxUIView* v = [[wxUIView alloc] initWithFrame:r]; + //wxUIView* v = [[wxUIView alloc] initWithFrame:r]; + UIView* v = [[UIView alloc] initWithFrame:r]; sv.clipsToBounds = YES; sv.contentMode = UIViewContentModeRedraw; - sv.clearsContextBeforeDrawing = NO; + //sv.clearsContextBeforeDrawing = NO; + //sv.backgroundColor = [UIColor greenColor]; + sv.clearsContextBeforeDrawing = YES; wxWidgetIPhoneImpl* c = new wxWidgetIPhoneImpl( wxpeer, v, false, true ); return c; } -