Mercurial > dwindows
comparison mac/dw.m @ 1489:4c1c44af201a
Added auto-positioning and auto-sizing code for Mac.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 24 Dec 2011 17:30:25 +0000 |
parents | 7216f4301364 |
children | 5393b56ec6d0 |
comparison
equal
deleted
inserted
replaced
1488:6771fa426ba4 | 1489:4c1c44af201a |
---|---|
744 @end | 744 @end |
745 | 745 |
746 @interface DWWindow : NSWindow | 746 @interface DWWindow : NSWindow |
747 { | 747 { |
748 int redraw; | 748 int redraw; |
749 int shown; | |
749 } | 750 } |
750 -(void)sendEvent:(NSEvent *)theEvent; | 751 -(void)sendEvent:(NSEvent *)theEvent; |
751 -(void)keyDown:(NSEvent *)theEvent; | 752 -(void)keyDown:(NSEvent *)theEvent; |
752 -(void)mouseDragged:(NSEvent *)theEvent; | 753 -(void)mouseDragged:(NSEvent *)theEvent; |
753 -(int)redraw; | 754 -(int)redraw; |
754 -(void)setRedraw:(int)val; | 755 -(void)setRedraw:(int)val; |
756 -(int)shown; | |
757 -(void)setShown:(int)val; | |
755 @end | 758 @end |
756 | 759 |
757 @implementation DWWindow | 760 @implementation DWWindow |
758 -(void)sendEvent:(NSEvent *)theEvent | 761 -(void)sendEvent:(NSEvent *)theEvent |
759 { | 762 { |
767 } | 770 } |
768 -(void)keyDown:(NSEvent *)theEvent { } | 771 -(void)keyDown:(NSEvent *)theEvent { } |
769 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } | 772 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } |
770 -(int)redraw { return redraw; } | 773 -(int)redraw { return redraw; } |
771 -(void)setRedraw:(int)val { redraw = val; } | 774 -(void)setRedraw:(int)val { redraw = val; } |
775 -(int)shown { return shown; } | |
776 -(void)setShown:(int)val { shown = val; } | |
772 @end | 777 @end |
773 | 778 |
774 /* Subclass for a render area type */ | 779 /* Subclass for a render area type */ |
775 @interface DWRender : NSControl | 780 @interface DWRender : NSControl |
776 { | 781 { |
7570 */ | 7575 */ |
7571 int API dw_window_show(HWND handle) | 7576 int API dw_window_show(HWND handle) |
7572 { | 7577 { |
7573 NSObject *object = handle; | 7578 NSObject *object = handle; |
7574 | 7579 |
7575 if([ object isKindOfClass:[ NSWindow class ] ]) | 7580 if([ object isMemberOfClass:[ DWWindow class ] ]) |
7576 { | 7581 { |
7577 NSWindow *window = handle; | 7582 DWWindow *window = handle; |
7578 NSRect rect = [window frame]; | 7583 NSRect rect = [[window contentView] frame]; |
7584 | |
7579 if([window isMiniaturized]) | 7585 if([window isMiniaturized]) |
7580 { | 7586 { |
7581 [window deminiaturize:nil]; | 7587 [window deminiaturize:nil]; |
7582 } | 7588 } |
7583 /* If we haven't been sized by a call.. */ | 7589 /* If we haven't been sized by a call.. */ |
7584 if(rect.size.width < 5 || rect.size.height < 5) | 7590 if(rect.size.width <= 1 || rect.size.height <= 1) |
7585 { | 7591 { |
7586 /* Make a sane default size because MacOS won't automatically */ | 7592 /* Determine the contents size */ |
7587 [window setContentSize:NSMakeSize(200,150)]; | 7593 dw_window_set_size(handle, 0, 0); |
7594 } | |
7595 if(![window shown]) | |
7596 { | |
7597 rect = [window frame]; | |
7598 | |
7599 /* If the position was not set... generate a default | |
7600 * default one in a similar pattern to SHELLPOSITION. | |
7601 */ | |
7602 if(rect.origin.x <= 1 || rect.origin.y <= 1) | |
7603 { | |
7604 static int defaultx = 0, defaulty; | |
7605 int cx = dw_screen_width(), cy = dw_screen_height(); | |
7606 int maxx = cx / 4, maxy = cy / 4; | |
7607 NSPoint point; | |
7608 | |
7609 defaultx += 20; | |
7610 defaulty += 20; | |
7611 if(defaultx > maxx) | |
7612 defaultx = 20; | |
7613 if(defaulty > maxy) | |
7614 defaulty = 20; | |
7615 | |
7616 point.x = defaultx; | |
7617 /* Take into account menu bar and inverted Y */ | |
7618 point.y = cy - defaulty - (int)rect.size.height - 20; | |
7619 | |
7620 [window setFrameOrigin:point]; | |
7621 [window setShown:YES]; | |
7622 } | |
7588 } | 7623 } |
7589 [[window contentView] showWindow]; | 7624 [[window contentView] showWindow]; |
7590 [window makeKeyAndOrderFront:nil]; | 7625 [window makeKeyAndOrderFront:nil]; |
7591 } | 7626 } |
7592 return 0; | 7627 return 0; |