# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1324747825 0 # Node ID 4c1c44af201a58e72599f34d2f58e85413acd421 # Parent 6771fa426ba493fff13a6582c829cbac01fb1038 Added auto-positioning and auto-sizing code for Mac. diff -r 6771fa426ba4 -r 4c1c44af201a mac/dw.m --- a/mac/dw.m Sat Dec 24 16:01:23 2011 +0000 +++ b/mac/dw.m Sat Dec 24 17:30:25 2011 +0000 @@ -746,12 +746,15 @@ @interface DWWindow : NSWindow { int redraw; + int shown; } -(void)sendEvent:(NSEvent *)theEvent; -(void)keyDown:(NSEvent *)theEvent; -(void)mouseDragged:(NSEvent *)theEvent; -(int)redraw; -(void)setRedraw:(int)val; +-(int)shown; +-(void)setShown:(int)val; @end @implementation DWWindow @@ -769,6 +772,8 @@ -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } -(int)redraw { return redraw; } -(void)setRedraw:(int)val { redraw = val; } +-(int)shown { return shown; } +-(void)setShown:(int)val { shown = val; } @end /* Subclass for a render area type */ @@ -7572,19 +7577,49 @@ { NSObject *object = handle; - if([ object isKindOfClass:[ NSWindow class ] ]) - { - NSWindow *window = handle; - NSRect rect = [window frame]; + if([ object isMemberOfClass:[ DWWindow class ] ]) + { + DWWindow *window = handle; + NSRect rect = [[window contentView] frame]; + if([window isMiniaturized]) { [window deminiaturize:nil]; } /* If we haven't been sized by a call.. */ - if(rect.size.width < 5 || rect.size.height < 5) - { - /* Make a sane default size because MacOS won't automatically */ - [window setContentSize:NSMakeSize(200,150)]; + if(rect.size.width <= 1 || rect.size.height <= 1) + { + /* Determine the contents size */ + dw_window_set_size(handle, 0, 0); + } + if(![window shown]) + { + rect = [window frame]; + + /* If the position was not set... generate a default + * default one in a similar pattern to SHELLPOSITION. + */ + if(rect.origin.x <= 1 || rect.origin.y <= 1) + { + static int defaultx = 0, defaulty; + int cx = dw_screen_width(), cy = dw_screen_height(); + int maxx = cx / 4, maxy = cy / 4; + NSPoint point; + + defaultx += 20; + defaulty += 20; + if(defaultx > maxx) + defaultx = 20; + if(defaulty > maxy) + defaulty = 20; + + point.x = defaultx; + /* Take into account menu bar and inverted Y */ + point.y = cy - defaulty - (int)rect.size.height - 20; + + [window setFrameOrigin:point]; + [window setShown:YES]; + } } [[window contentView] showWindow]; [window makeKeyAndOrderFront:nil];