Index: MobileTerminal.m =================================================================== --- MobileTerminal.m (revision 90) +++ MobileTerminal.m (working copy) @@ -26,6 +26,28 @@ #include #include + +/* +UIHardware + (int)deviceOrientation:(BOOL)fp8 +deviceOrientation returns the orientation of the iPhone. +1 normal +2 upside down +3 horizontal - turned left +4 horizontal - turned right +*/ + +typedef struct __GSEvent { + long i0; + long i1; + long eventType; + long i3; + long i4; + long i5; +} __GSEvent; + + + + @interface UITextView (CleanWarnings) -(UIView*) webView; @@ -213,6 +235,8 @@ ShellView* view; +int curOrient; + @implementation ShellKeyboard - (void) show:(id *)mainView shell:(id *)shellView @@ -333,11 +357,41 @@ } } +- (void) msg: (id) msg +{ + [[[view _webView] webView] moveToEndOfDocument:self]; + [view stopCapture]; + [[view _webView] insertText: msg]; + [view startCapture]; +} + +- (void) evtMsg: (id) msg withEvent: (__GSEvent*) et +{ + [[[view _webView] webView] moveToEndOfDocument:self]; + [view stopCapture]; + [[view _webView] insertText: msg]; + [[view _webView] insertText: @"("]; + +[[view _webView] insertText: [[[NSNumber alloc] initWithUnsignedLong: et->eventType] stringValue]]; + [[view _webView] insertText: @", "]; +[[view _webView] insertText: [[[NSNumber alloc] initWithUnsignedLong: et->i3] stringValue]]; + [[view _webView] insertText: @", "]; +[[view _webView] insertText: [[[NSNumber alloc] initWithUnsignedLong: et->i4] stringValue]]; + [[view _webView] insertText: @", "]; +[[view _webView] insertText: [[[NSNumber alloc] initWithUnsignedLong: et->i5] stringValue]]; + + [[view _webView] insertText: @")\n"]; + + [view startCapture]; +} + @end @implementation MobileTerminal +ShellKeyboard *sk; + // Handle signals from he child; just exit on any status change void signal_handler(int signal) { int status; @@ -443,9 +497,13 @@ //DelegateDebug* debugDelegate = [[DelegateDebug alloc] retain]; //[debugDelegate doSomethingWeird]; + curOrient = [UIHardware deviceOrientation: YES]; + ShellKeyboard* keyboard = [[ShellKeyboard alloc] initWithFrame: CGRectMake(0.0f, 240.0, 320.0f, 480.0f)]; + sk = keyboard; + [view setKeyboard:keyboard]; [keyboard setTapDelegate:view]; @@ -465,10 +523,55 @@ [mainView addSubview: barView]; [mainView addSubview: keyboard]; - + [view becomeFirstResponder]; [window setContentView: mainView]; } +- (void)deviceOrientationChanged: (__GSEvent *)fp8 +{ + [sk msg: @"** deviceOrientationChanged" ]; +} + +- (void)myOrientationChanged: (__GSEvent *)event +{ + int newOrient; + + newOrient = [UIHardware deviceOrientation: YES]; + if(newOrient != curOrient) + { + [sk msg: @"\nNew Orientation: "]; + [sk msg: [[[NSNumber alloc] initWithUnsignedLong: newOrient] stringValue]]; + [sk msg: @"\n"]; + + curOrient = newOrient; + } +} + +- (BOOL)handleEvent:(__GSEvent *)event +{ + switch(event->eventType) + { + case 50: //orientation change + [self myOrientationChanged: event]; + return YES; + + case 2002: //quit event + //should perhaps kill -1 the shell + [self terminateWithSuccess]; + return NO; + + case 3: //click + case 3001: //drag + return YES; + + default: + [sk evtMsg: @"handleEvent" withEvent: event ]; + } + + return YES; +} + + @end