universal implementation for iphone
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54818 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
232
src/osx/iphone/nonownedwnd.mm
Normal file
232
src/osx/iphone/nonownedwnd.mm
Normal file
@@ -0,0 +1,232 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: src/mac/cocoa/nonownedwnd.mm
|
||||||
|
// Purpose: non owned window for iphone
|
||||||
|
// Author: Stefan Csomor
|
||||||
|
// Modified by:
|
||||||
|
// Created: 2008-06-20
|
||||||
|
// RCS-ID: $Id: nonownedwnd.mm 48805 2007-09-19 14:52:25Z SC $
|
||||||
|
// Copyright: (c) Stefan Csomor
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/osx/private.h"
|
||||||
|
|
||||||
|
#include "wx/nonownedwnd.h"
|
||||||
|
#include "wx/frame.h"
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowIPhoneImpl , wxNonOwnedWindowImpl )
|
||||||
|
|
||||||
|
wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl( wxNonOwnedWindow* nonownedwnd) :
|
||||||
|
wxNonOwnedWindowImpl(nonownedwnd)
|
||||||
|
{
|
||||||
|
m_macWindow = NULL;
|
||||||
|
m_macFullScreenData = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl()
|
||||||
|
{
|
||||||
|
m_macWindow = NULL;
|
||||||
|
m_macFullScreenData = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl()
|
||||||
|
{
|
||||||
|
[m_macWindow release];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::Destroy()
|
||||||
|
{
|
||||||
|
wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
|
||||||
|
long style, long extraStyle, const wxString& name )
|
||||||
|
{
|
||||||
|
m_macWindow = [UIWindow alloc];
|
||||||
|
|
||||||
|
UIWindowLevel level = UIWindowLevelNormal;
|
||||||
|
|
||||||
|
// most styles are not supported on the iphone
|
||||||
|
|
||||||
|
if ( style & wxFRAME_TOOL_WINDOW )
|
||||||
|
{
|
||||||
|
level = UIWindowLevelAlert; ;
|
||||||
|
}
|
||||||
|
else if ( ( style & wxPOPUP_WINDOW ) )
|
||||||
|
{
|
||||||
|
level = UIWindowLevelAlert;;
|
||||||
|
}
|
||||||
|
else if ( ( style & wxCAPTION ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if ( ( style & wxFRAME_DRAWER ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ( style & wxSTAY_ON_TOP ) )
|
||||||
|
level = UIWindowLevelAlert;
|
||||||
|
CGRect r = CGRectMake( 0, 0, size.x, size.y) ;
|
||||||
|
|
||||||
|
[m_macWindow initWithFrame:r ];
|
||||||
|
|
||||||
|
[m_macWindow setWindowLevel:level];
|
||||||
|
// [m_macWindow makeKeyAndOrderFront:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const
|
||||||
|
{
|
||||||
|
return m_macWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::Raise()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::Lower()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::Show(bool show)
|
||||||
|
{
|
||||||
|
[m_macWindow setHidden:(show ? NO : YES)];
|
||||||
|
if ( show )
|
||||||
|
{
|
||||||
|
//[m_macWindow orderFront: self];
|
||||||
|
[m_macWindow makeKeyWindow];
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout)
|
||||||
|
{
|
||||||
|
return Show(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::Update()
|
||||||
|
{
|
||||||
|
// TODO [m_macWindow displayIfNeeded];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::SetTransparent(wxByte alpha)
|
||||||
|
{
|
||||||
|
[m_macWindow setAlpha:(CGFloat) alpha/255.0];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::SetBackgroundColour(const wxColour& col )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::SetExtraStyle( long exStyle )
|
||||||
|
{
|
||||||
|
// no special styles supported
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::MoveWindow(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
CGRect r = CGRectMake( 0,0,width,height) ;
|
||||||
|
[m_macWindow setFrame:r];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::GetPosition( int &x, int &y ) const
|
||||||
|
{
|
||||||
|
CGRect r = [m_macWindow frame];
|
||||||
|
x = r.origin.x;
|
||||||
|
y = r.origin.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::GetSize( int &width, int &height ) const
|
||||||
|
{
|
||||||
|
CGRect rect = [m_macWindow frame];
|
||||||
|
width = rect.size.width;
|
||||||
|
height = rect.size.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::GetContentArea( int& left, int &right, int &width, int &height ) const
|
||||||
|
{
|
||||||
|
CGRect rect = [m_macWindow frame];
|
||||||
|
width = rect.size.width;
|
||||||
|
height = rect.size.height;
|
||||||
|
left = 0;
|
||||||
|
right = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::SetShape(const wxRegion& region)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
|
||||||
|
{
|
||||||
|
// TODO change title of app ?
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::IsMaximized() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::IsIconized() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::Iconize( bool iconize )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const
|
||||||
|
{
|
||||||
|
return m_macFullScreenData != NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxNonOwnedWindowIPhoneImpl::ShowFullScreen(bool show, long style)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::RequestUserAttention(int WXUNUSED(flags))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::ScreenToWindow( int *x, int *y )
|
||||||
|
{
|
||||||
|
CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
|
||||||
|
p = [m_macWindow convertPoint:p fromWindow:nil];
|
||||||
|
if ( x )
|
||||||
|
*x = p.x;
|
||||||
|
if ( y )
|
||||||
|
*y = p.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNonOwnedWindowIPhoneImpl::WindowToScreen( int *x, int *y )
|
||||||
|
{
|
||||||
|
CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
|
||||||
|
p = [m_macWindow convertPoint:p toWindow:nil];
|
||||||
|
if ( x )
|
||||||
|
*x = p.x;
|
||||||
|
if ( y )
|
||||||
|
*y = p.y;
|
||||||
|
}
|
||||||
|
|
280
src/osx/iphone/utils.mm
Normal file
280
src/osx/iphone/utils.mm
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: src/mac/cocoa/utils.mm
|
||||||
|
// Purpose: various cocoa utility functions
|
||||||
|
// Author: Stefan Csomor
|
||||||
|
// Modified by:
|
||||||
|
// Created: 1998-01-01
|
||||||
|
// RCS-ID: $Id: utils.mm 48805 2007-09-19 14:52:25Z SC $
|
||||||
|
// Copyright: (c) Stefan Csomor
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/utils.h"
|
||||||
|
|
||||||
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/intl.h"
|
||||||
|
#include "wx/app.h"
|
||||||
|
#if wxUSE_GUI
|
||||||
|
#include "wx/toplevel.h"
|
||||||
|
#include "wx/font.h"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/apptrait.h"
|
||||||
|
|
||||||
|
#include "wx/osx/private.h"
|
||||||
|
|
||||||
|
#if wxUSE_GUI
|
||||||
|
#include "wx/osx/private/timer.h"
|
||||||
|
#include "wx/osx/dcclient.h"
|
||||||
|
#endif // wxUSE_GUI
|
||||||
|
|
||||||
|
#if wxOSX_USE_IPHONE
|
||||||
|
|
||||||
|
#include <AudioToolbox/AudioServices.h>
|
||||||
|
|
||||||
|
#if wxUSE_BASE
|
||||||
|
|
||||||
|
// Emit a beeeeeep
|
||||||
|
void wxBell()
|
||||||
|
{
|
||||||
|
// would be kSystemSoundID_UserPreferredAlert but since the headers aren't correct, add it manually
|
||||||
|
AudioServicesPlayAlertSound(0x00001000 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Common Event Support
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@interface wxAppDelegate : NSObject <UIApplicationDelegate> {
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation wxAppDelegate
|
||||||
|
|
||||||
|
- (void)applicationDidFinishLaunching:(UIApplication *)application {
|
||||||
|
wxTheApp->OnInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
bool wxApp::CallOnInit()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxApp::OnRun()
|
||||||
|
{
|
||||||
|
wxMacAutoreleasePool pool;
|
||||||
|
char* appname = "test";
|
||||||
|
UIApplicationMain( 1, &appname, nil, @"wxAppDelegate" );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxMacWakeUp()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxUSE_BASE
|
||||||
|
|
||||||
|
#if wxUSE_GUI
|
||||||
|
|
||||||
|
// TODO : reorganize
|
||||||
|
|
||||||
|
extern wxFont* CreateNormalFont()
|
||||||
|
{
|
||||||
|
return new wxFont([UIFont systemFontSize] , wxSWISS, wxNORMAL, wxNORMAL, FALSE, "Helvetica" );
|
||||||
|
}
|
||||||
|
|
||||||
|
extern wxFont* CreateSmallFont()
|
||||||
|
{
|
||||||
|
return new wxFont([UIFont smallSystemFontSize] , wxSWISS, wxNORMAL, wxNORMAL, FALSE, "Helvetica" );
|
||||||
|
}
|
||||||
|
|
||||||
|
extern UIFont* CreateUIFont( const wxFont& font )
|
||||||
|
{
|
||||||
|
return [UIFont fontWithName:wxCFStringRef(font.GetFaceName() ).AsNSString() size:font.GetPointSize()];
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void DrawTextInContext( CGContextRef context, CGPoint where, UIFont *font, NSString* text )
|
||||||
|
{
|
||||||
|
bool contextChanged = ( UIGraphicsGetCurrentContext() != context );
|
||||||
|
if ( contextChanged )
|
||||||
|
UIGraphicsPushContext(context);
|
||||||
|
|
||||||
|
[text drawAtPoint:where withFont:font];
|
||||||
|
|
||||||
|
if ( contextChanged )
|
||||||
|
UIGraphicsPopContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern CGSize MeasureTextInContext( UIFont *font, NSString* text )
|
||||||
|
{
|
||||||
|
return [text sizeWithFont:font];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxClientDisplayRect(int *x, int *y, int *width, int *height)
|
||||||
|
{
|
||||||
|
CGRect r = [[UIScreen mainScreen] applicationFrame];
|
||||||
|
if ( x )
|
||||||
|
*x = r.origin.x;
|
||||||
|
if ( y )
|
||||||
|
*y = r.origin.y;
|
||||||
|
if ( width )
|
||||||
|
*width = r.size.width;
|
||||||
|
if ( height )
|
||||||
|
*height = r.size.height;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGetMousePosition( int* x, int* y )
|
||||||
|
{
|
||||||
|
// wxPoint pt = wxFromNSPoint(NULL, [NSEvent mouseLocation]);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns depth of screen
|
||||||
|
int wxDisplayDepth()
|
||||||
|
{
|
||||||
|
return 32; // TODO can we determine this ?
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get size of display
|
||||||
|
void wxDisplaySize(int *width, int *height)
|
||||||
|
{
|
||||||
|
CGRect bounds = [[UIScreen mainScreen] bounds];
|
||||||
|
|
||||||
|
if ( width )
|
||||||
|
*width = (int)bounds.size.width ;
|
||||||
|
if ( height )
|
||||||
|
*height = (int)bounds.size.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
|
||||||
|
{
|
||||||
|
return new wxOSXTimerImpl(timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
int gs_wxBusyCursorCount = 0;
|
||||||
|
extern wxCursor gMacCurrentCursor;
|
||||||
|
wxCursor gMacStoredActiveCursor;
|
||||||
|
|
||||||
|
// Set the cursor to the busy cursor for all windows
|
||||||
|
void wxBeginBusyCursor(const wxCursor *cursor)
|
||||||
|
{
|
||||||
|
if (gs_wxBusyCursorCount++ == 0)
|
||||||
|
{
|
||||||
|
gMacStoredActiveCursor = gMacCurrentCursor;
|
||||||
|
cursor->MacInstall();
|
||||||
|
|
||||||
|
wxSetCursor(*cursor);
|
||||||
|
}
|
||||||
|
//else: nothing to do, already set
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore cursor to normal
|
||||||
|
void wxEndBusyCursor()
|
||||||
|
{
|
||||||
|
wxCHECK_RET( gs_wxBusyCursorCount > 0,
|
||||||
|
wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
|
||||||
|
|
||||||
|
if (--gs_wxBusyCursorCount == 0)
|
||||||
|
{
|
||||||
|
gMacStoredActiveCursor.MacInstall();
|
||||||
|
gMacStoredActiveCursor = wxNullCursor;
|
||||||
|
|
||||||
|
wxSetCursor(wxNullCursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// true if we're between the above two calls
|
||||||
|
bool wxIsBusy()
|
||||||
|
{
|
||||||
|
return (gs_wxBusyCursorCount > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxGetKeyState (wxKeyCode key)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
|
||||||
|
{
|
||||||
|
// wxScreenDC is derived from wxWindowDC, so a screen dc will
|
||||||
|
// call this method when a Blit is performed with it as a source.
|
||||||
|
if (!m_window)
|
||||||
|
return wxNullBitmap;
|
||||||
|
|
||||||
|
wxSize sz = m_window->GetSize();
|
||||||
|
|
||||||
|
int left = subrect != NULL ? subrect->x : 0 ;
|
||||||
|
int top = subrect != NULL ? subrect->y : 0 ;
|
||||||
|
int width = subrect != NULL ? subrect->width : sz.x;
|
||||||
|
int height = subrect != NULL ? subrect->height : sz.y ;
|
||||||
|
|
||||||
|
wxBitmap bmp = wxBitmap(width, height, 32);
|
||||||
|
|
||||||
|
CGContextRef context = (CGContextRef)bmp.GetHBITMAP();
|
||||||
|
|
||||||
|
CGContextSaveGState(context);
|
||||||
|
|
||||||
|
|
||||||
|
CGContextTranslateCTM( context, 0, height );
|
||||||
|
CGContextScaleCTM( context, 1, -1 );
|
||||||
|
|
||||||
|
if ( subrect )
|
||||||
|
CGContextTranslateCTM( context, -subrect->x, -subrect->y ) ;
|
||||||
|
|
||||||
|
UIGraphicsPushContext(context);
|
||||||
|
[ (NSView*) m_window->GetHandle() drawRect:CGRectMake(left, top, width, height ) ];
|
||||||
|
UIGraphicsPopContext();
|
||||||
|
CGContextRestoreGState(context);
|
||||||
|
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxUSE_GUI
|
||||||
|
|
||||||
|
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
|
||||||
|
{
|
||||||
|
// get OS version
|
||||||
|
int major, minor;
|
||||||
|
|
||||||
|
wxString release = wxCFStringRef( [ [UIDevice currentDevice] systemVersion] ).AsString() ;
|
||||||
|
|
||||||
|
if ( release.empty() ||
|
||||||
|
wxSscanf(release.c_str(), wxT("%d.%d"), &major, &minor) != 2 )
|
||||||
|
{
|
||||||
|
// failed to get version string or unrecognized format
|
||||||
|
major =
|
||||||
|
minor = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( verMaj )
|
||||||
|
*verMaj = major;
|
||||||
|
if ( verMin )
|
||||||
|
*verMin = minor;
|
||||||
|
|
||||||
|
return wxOS_MAC_OSX_DARWIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxGetOsDescription()
|
||||||
|
{
|
||||||
|
wxString release = wxCFStringRef( [ [UIDevice currentDevice] systemName] ).AsString() ;
|
||||||
|
|
||||||
|
return release;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // wxOSX_USE_IPHONE
|
483
src/osx/iphone/window.mm
Normal file
483
src/osx/iphone/window.mm
Normal file
@@ -0,0 +1,483 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: src/osx/iphone/window.mm
|
||||||
|
// Purpose: widgets (non tlw) for iphone
|
||||||
|
// Author: Stefan Csomor
|
||||||
|
// Modified by:
|
||||||
|
// Created: 2008-06-20
|
||||||
|
// RCS-ID: $Id: window.mm 48805 2007-09-19 14:52:25Z SC $
|
||||||
|
// Copyright: (c) Stefan Csomor
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/osx/private.h"
|
||||||
|
|
||||||
|
#include "wx/event.h"
|
||||||
|
#include "wx/nonownedwnd.h"
|
||||||
|
#include "wx/frame.h"
|
||||||
|
|
||||||
|
@interface wxUIView : UIView
|
||||||
|
{
|
||||||
|
wxWidgetImpl* m_impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)drawRect: (CGRect) rect;
|
||||||
|
|
||||||
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||||
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||||
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||||
|
- (void)handleTouchEvent:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||||
|
|
||||||
|
- (void)setImplementation: (wxWidgetImpl *) theImplementation;
|
||||||
|
- (wxWidgetImpl*) implementation;
|
||||||
|
- (BOOL) isFlipped;
|
||||||
|
- (BOOL) becomeFirstResponder;
|
||||||
|
- (BOOL) resignFirstResponder;
|
||||||
|
|
||||||
|
@end // wxUIView
|
||||||
|
|
||||||
|
@interface wxUIContentView : wxUIView
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface wxUIContentViewController : UIViewController
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
void SetupMouseEvent( wxMouseEvent &wxevent , NSSet* touches, UIEvent * nsEvent )
|
||||||
|
{
|
||||||
|
UInt32 modifiers = 0 ;
|
||||||
|
UITouch *touch = [touches anyObject];
|
||||||
|
|
||||||
|
// these parameters are not given for all events
|
||||||
|
UInt32 button = 0; // no secondary button
|
||||||
|
UInt32 clickCount = [touch tapCount];
|
||||||
|
UInt32 mouseChord = 0; // TODO does this exist for cocoa
|
||||||
|
|
||||||
|
// will be overridden
|
||||||
|
wxevent.m_x = 0;
|
||||||
|
wxevent.m_y = 0;
|
||||||
|
wxevent.m_shiftDown = 0;
|
||||||
|
wxevent.m_controlDown = 0;
|
||||||
|
wxevent.m_altDown = 0;
|
||||||
|
wxevent.m_metaDown = 0;
|
||||||
|
wxevent.m_clickCount = clickCount;
|
||||||
|
wxevent.SetTimestamp( [touch timestamp] ) ;
|
||||||
|
/*
|
||||||
|
// a control click is interpreted as a right click
|
||||||
|
bool thisButtonIsFakeRight = false ;
|
||||||
|
if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
|
||||||
|
{
|
||||||
|
button = kEventMouseButtonSecondary ;
|
||||||
|
thisButtonIsFakeRight = true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise we report double clicks by connecting a left click with a ctrl-left click
|
||||||
|
if ( clickCount > 1 && button != g_lastButton )
|
||||||
|
clickCount = 1 ;
|
||||||
|
// we must make sure that our synthetic 'right' button corresponds in
|
||||||
|
// mouse down, moved and mouse up, and does not deliver a right down and left up
|
||||||
|
|
||||||
|
if ( cEvent.GetKind() == kEventMouseDown )
|
||||||
|
{
|
||||||
|
g_lastButton = button ;
|
||||||
|
g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( button == 0 )
|
||||||
|
{
|
||||||
|
g_lastButton = 0 ;
|
||||||
|
g_lastButtonWasFakeRight = false ;
|
||||||
|
}
|
||||||
|
else if ( g_lastButton == kEventMouseButtonSecondary && g_lastButtonWasFakeRight )
|
||||||
|
button = g_lastButton ;
|
||||||
|
|
||||||
|
// Adjust the chord mask to remove the primary button and add the
|
||||||
|
// secondary button. It is possible that the secondary button is
|
||||||
|
// already pressed, e.g. on a mouse connected to a laptop, but this
|
||||||
|
// possibility is ignored here:
|
||||||
|
if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
|
||||||
|
mouseChord = ((mouseChord & ~1U) | 2U);
|
||||||
|
|
||||||
|
if(mouseChord & 1U)
|
||||||
|
wxevent.m_leftDown = true ;
|
||||||
|
if(mouseChord & 2U)
|
||||||
|
wxevent.m_rightDown = true ;
|
||||||
|
if(mouseChord & 4U)
|
||||||
|
wxevent.m_middleDown = true ;
|
||||||
|
|
||||||
|
*/
|
||||||
|
// translate into wx types
|
||||||
|
int eventType = [touch phase];
|
||||||
|
switch (eventType)
|
||||||
|
{
|
||||||
|
case UITouchPhaseBegan :
|
||||||
|
switch ( button )
|
||||||
|
{
|
||||||
|
case 0 :
|
||||||
|
wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case UITouchPhaseEnded :
|
||||||
|
switch ( button )
|
||||||
|
{
|
||||||
|
case 0 :
|
||||||
|
wxevent.SetEventType( wxEVT_LEFT_UP ) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case UITouchPhaseMoved :
|
||||||
|
wxevent.SetEventType( wxEVT_MOTION ) ;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@implementation wxUIView
|
||||||
|
|
||||||
|
- (id) initWithFrame: (CGRect) frame
|
||||||
|
{
|
||||||
|
if ( self = [super initWithFrame:frame])
|
||||||
|
{
|
||||||
|
// additional inits
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
// additional deallocs
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)drawRect: (CGRect) rect
|
||||||
|
{
|
||||||
|
if ( m_impl )
|
||||||
|
{
|
||||||
|
CGContextRef context = (CGContextRef) UIGraphicsGetCurrentContext();
|
||||||
|
CGContextSaveGState( context );
|
||||||
|
// draw background
|
||||||
|
|
||||||
|
CGContextSetFillColorWithColor( context, m_impl->GetWXPeer()->GetBackgroundColour().GetCGColor());
|
||||||
|
CGContextFillRect(context, rect );
|
||||||
|
|
||||||
|
if ( [ self isFlipped ] == NO )
|
||||||
|
{
|
||||||
|
CGContextTranslateCTM( context, 0, [self bounds].size.height );
|
||||||
|
CGContextScaleCTM( context, 1, -1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_impl->GetWXPeer()->MacSetCGContextRef( context );
|
||||||
|
|
||||||
|
m_impl->GetWXPeer()->GetUpdateRegion() =
|
||||||
|
wxRegion(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height) ;
|
||||||
|
|
||||||
|
wxPaintEvent event;
|
||||||
|
event.SetTimestamp(0); // todo
|
||||||
|
event.SetEventObject(m_impl->GetWXPeer());
|
||||||
|
m_impl->GetWXPeer()->HandleWindowEvent(event);
|
||||||
|
|
||||||
|
CGContextRestoreGState( context );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
|
{
|
||||||
|
[self handleTouchEvent:touches withEvent:event];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
|
{
|
||||||
|
[self handleTouchEvent:touches withEvent:event];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
|
{
|
||||||
|
[self handleTouchEvent:touches withEvent:event];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)handleTouchEvent:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
|
{
|
||||||
|
CGPoint clickLocation;
|
||||||
|
UITouch *touch = [touches anyObject];
|
||||||
|
clickLocation = [touch locationInView:self];
|
||||||
|
|
||||||
|
wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
|
||||||
|
SetupMouseEvent( wxevent , touches, event ) ;
|
||||||
|
wxevent.m_x = clickLocation.x;
|
||||||
|
wxevent.m_y = clickLocation.y;
|
||||||
|
wxevent.SetEventObject( m_impl->GetWXPeer() ) ;
|
||||||
|
wxevent.SetId( m_impl->GetWXPeer()->GetId() ) ;
|
||||||
|
m_impl->GetWXPeer()->HandleWindowEvent(wxevent);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setImplementation: (wxWidgetImpl *) theImplementation
|
||||||
|
{
|
||||||
|
m_impl = theImplementation;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (wxWidgetImpl*) implementation
|
||||||
|
{
|
||||||
|
return m_impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isFlipped
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) becomeFirstResponder
|
||||||
|
{
|
||||||
|
BOOL r = [super becomeFirstResponder];
|
||||||
|
if ( r )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) resignFirstResponder
|
||||||
|
{
|
||||||
|
BOOL r = [super resignFirstResponder];
|
||||||
|
if ( r )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@end // wxUIView
|
||||||
|
|
||||||
|
@implementation wxUIContentView
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation wxUIContentViewController
|
||||||
|
|
||||||
|
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
|
||||||
|
{
|
||||||
|
CGRect fr = [self.view frame];
|
||||||
|
// CGRect cv = [[self.view superview] frame];
|
||||||
|
// CGRect bounds = CGRectMake( 0,0,fr.size.width, fr.size.height);
|
||||||
|
// [[self.view superview] setFrame: fr ];
|
||||||
|
// [self.view setFrame: bounds];
|
||||||
|
// [self.view setNeedsDisplayInRect:bounds];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS( wxWidgetIPhoneImpl , wxWidgetImpl )
|
||||||
|
|
||||||
|
wxWidgetIPhoneImpl::wxWidgetIPhoneImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
|
||||||
|
wxWidgetImpl( peer, isRootControl ), m_osxView(w)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
wxWidgetIPhoneImpl::wxWidgetIPhoneImpl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::Init()
|
||||||
|
{
|
||||||
|
m_osxView = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxWidgetIPhoneImpl::~wxWidgetIPhoneImpl()
|
||||||
|
{
|
||||||
|
[m_osxView setImplementation:NULL];
|
||||||
|
[m_osxView release];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxWidgetIPhoneImpl::IsVisible() const
|
||||||
|
{
|
||||||
|
// TODO Superviews
|
||||||
|
return [m_osxView isHidden] == NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::SetVisibility( bool visible )
|
||||||
|
{
|
||||||
|
[m_osxView setHidden:(visible ? NO:YES)];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::Raise()
|
||||||
|
{
|
||||||
|
[[m_osxView superview] bringSubviewToFront:m_osxView];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::Lower()
|
||||||
|
{
|
||||||
|
[[m_osxView superview] sendSubviewToBack:m_osxView];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::ScrollRect( const wxRect *rect, int dx, int dy )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::Move(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
CGRect r = CGRectMake( x, y, width, height) ;
|
||||||
|
[m_osxView setFrame:r];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::GetPosition( int &x, int &y ) const
|
||||||
|
{
|
||||||
|
CGRect r = [m_osxView frame];
|
||||||
|
x = r.origin.x;
|
||||||
|
y = r.origin.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::GetSize( int &width, int &height ) const
|
||||||
|
{
|
||||||
|
CGRect rect = [m_osxView frame];
|
||||||
|
width = rect.size.width;
|
||||||
|
height = rect.size.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
|
||||||
|
{
|
||||||
|
left = top = 0;
|
||||||
|
GetSize( width, height );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::SetNeedsDisplay( const wxRect* where )
|
||||||
|
{
|
||||||
|
if ( where )
|
||||||
|
{
|
||||||
|
CGRect r = CGRectMake( where->x, where->y, where->width, where->height) ;
|
||||||
|
[m_osxView setNeedsDisplayInRect:r];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
[m_osxView setNeedsDisplay];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxWidgetIPhoneImpl::GetNeedsDisplay() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
// return [m_osxView needsDisplay];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxWidgetIPhoneImpl::CanFocus() const
|
||||||
|
{
|
||||||
|
return [m_osxView canBecomeFirstResponder] == YES;
|
||||||
|
// ? return [m_osxView isUserInteractionEnabled] == YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxWidgetIPhoneImpl::HasFocus() const
|
||||||
|
{
|
||||||
|
return [m_osxView isFirstResponder] == YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxWidgetIPhoneImpl::SetFocus()
|
||||||
|
{
|
||||||
|
// [m_osxView makeKeyWindow] ;
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::RemoveFromParent()
|
||||||
|
{
|
||||||
|
[m_osxView removeFromSuperview];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::Embed( wxWidgetImpl *parent )
|
||||||
|
{
|
||||||
|
UIView* container = parent->GetWXWidget() ;
|
||||||
|
wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
|
||||||
|
[container addSubview:m_osxView];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
|
||||||
|
{
|
||||||
|
CGPoint p = CGPointMake( pt->x , pt->y );
|
||||||
|
p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
|
||||||
|
pt->x = (int)p.x;
|
||||||
|
pt->y = (int)p.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetIPhoneImpl::SetBackgroundColour( const wxColour &col )
|
||||||
|
{
|
||||||
|
// m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Factory methods
|
||||||
|
//
|
||||||
|
|
||||||
|
wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, const wxPoint& pos, const wxSize& size,
|
||||||
|
long style, long extraStyle, const wxString& name)
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
sv.clipsToBounds = YES;
|
||||||
|
sv.contentMode = UIViewContentModeRedraw;
|
||||||
|
sv.clearsContextBeforeDrawing = NO;
|
||||||
|
// sv.backgroundColor = [[UIColor alloc] initWithCGColor:wxpeer->GetBackgroundColour().GetCGColor()];
|
||||||
|
[sv addSubview:v];
|
||||||
|
wxWidgetIPhoneImpl* c = new wxWidgetIPhoneImpl( wxpeer, v );
|
||||||
|
[v setImplementation:c];
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
|
||||||
|
{
|
||||||
|
UIWindow* toplevelwindow = now->GetWXWindow();
|
||||||
|
|
||||||
|
wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:[toplevelwindow bounds]];
|
||||||
|
contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||||
|
wxUIContentViewController* controller = [[wxUIContentViewController alloc] init];
|
||||||
|
controller.view = contentview;
|
||||||
|
/*
|
||||||
|
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
|
||||||
|
// left orientation not yet implemented !
|
||||||
|
if (orientation == UIInterfaceOrientationLandscapeRight )
|
||||||
|
{
|
||||||
|
CGAffineTransform transform = v.transform;
|
||||||
|
|
||||||
|
// Use the status bar frame to determine the center point of the window's content area.
|
||||||
|
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
|
||||||
|
CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);
|
||||||
|
CGPoint center = CGPointMake(bounds.size.height / 2.0, bounds.size.width / 2.0);
|
||||||
|
|
||||||
|
// Set the center point of the view to the center point of the window's content area.
|
||||||
|
v.center = center;
|
||||||
|
|
||||||
|
// Rotate the view 90 degrees around its new center point.
|
||||||
|
transform = CGAffineTransformRotate(transform, ( M_PI / 2.0));
|
||||||
|
v.transform = transform;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl( now, contentview, true );
|
||||||
|
[contentview setImplementation:impl];
|
||||||
|
[toplevelwindow addSubview:contentview];
|
||||||
|
return impl;
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user