From b6544d19ddd1e4d5af2cef69ec14bb414b179573 Mon Sep 17 00:00:00 2001 From: Ken Thomases Date: Fri, 11 Jan 2013 06:19:36 -0600 Subject: [PATCH] winemac: Implement support for owned windows. --- dlls/winemac.drv/cocoa_window.h | 1 + dlls/winemac.drv/cocoa_window.m | 53 +++++++++++++++++++++++++++++++-- dlls/winemac.drv/macdrv_cocoa.h | 1 + dlls/winemac.drv/window.c | 6 ++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/dlls/winemac.drv/cocoa_window.h b/dlls/winemac.drv/cocoa_window.h index 41e0b903ff0..8533e2abfe6 100644 --- a/dlls/winemac.drv/cocoa_window.h +++ b/dlls/winemac.drv/cocoa_window.h @@ -27,6 +27,7 @@ @interface WineWindow : NSPanel BOOL disabled; BOOL noActivate; BOOL floating; + WineWindow* latentParentWindow; } @end diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m index 16217c28915..e6ae1034fc7 100644 --- a/dlls/winemac.drv/cocoa_window.m +++ b/dlls/winemac.drv/cocoa_window.m @@ -63,6 +63,7 @@ @interface WineWindow () @property (nonatomic) BOOL disabled; @property (nonatomic) BOOL noActivate; @property (nonatomic) BOOL floating; +@property (retain, nonatomic) NSWindow* latentParentWindow; + (void) flipRect:(NSRect*)rect; @@ -81,7 +82,7 @@ - (BOOL) isFlipped @implementation WineWindow - @synthesize disabled, noActivate, floating; + @synthesize disabled, noActivate, floating, latentParentWindow; + (WineWindow*) createWindowWithFeatures:(const struct macdrv_window_features*)wf windowFrame:(NSRect)window_frame @@ -119,6 +120,12 @@ + (WineWindow*) createWindowWithFeatures:(const struct macdrv_window_features*)w return window; } + - (void) dealloc + { + [latentParentWindow release]; + [super dealloc]; + } + + (void) flipRect:(NSRect*)rect { rect->origin.y = NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]) - NSMaxY(*rect); @@ -172,11 +179,23 @@ - (BOOL) orderBelow:(WineWindow*)prev orAbove:(WineWindow*)next [self orderWindow:NSWindowBelow relativeTo:[prev windowNumber]]; else [self orderWindow:NSWindowAbove relativeTo:[next windowNumber]]; + if (latentParentWindow) + { + [latentParentWindow addChildWindow:self ordered:NSWindowAbove]; + self.latentParentWindow = nil; + } } return on_screen; } + - (void) doOrderOut + { + self.latentParentWindow = [self parentWindow]; + [latentParentWindow removeChildWindow:self]; + [self orderOut:nil]; + } + - (BOOL) setFrameIfOnScreen:(NSRect)contentRect { NSArray* screens = [NSScreen screens]; @@ -193,7 +212,7 @@ - (BOOL) setFrameIfOnScreen:(NSRect)contentRect { on_screen = frame_intersects_screens(contentRect, screens); if (!on_screen) - [self orderOut:nil]; + [self doOrderOut]; } oldFrame = [self frame]; @@ -209,6 +228,19 @@ - (BOOL) setFrameIfOnScreen:(NSRect)contentRect return on_screen; } + - (void) setMacDrvParentWindow:(WineWindow*)parent + { + if ([self parentWindow] != parent) + { + [[self parentWindow] removeChildWindow:self]; + self.latentParentWindow = nil; + if ([self isVisible] && parent) + [parent addChildWindow:self ordered:NSWindowAbove]; + else + self.latentParentWindow = parent; + } + } + - (void) setDisabled:(BOOL)newValue { if (disabled != newValue) @@ -368,7 +400,7 @@ void macdrv_hide_cocoa_window(macdrv_window w) WineWindow* window = (WineWindow*)w; OnMainThread(^{ - [window orderOut:nil]; + [window doOrderOut]; }); } @@ -392,3 +424,18 @@ int macdrv_set_cocoa_window_frame(macdrv_window w, const CGRect* new_frame) return on_screen; } + +/*********************************************************************** + * macdrv_set_cocoa_parent_window + * + * Sets the parent window for a Cocoa window. If parent is NULL, clears + * the parent window. + */ +void macdrv_set_cocoa_parent_window(macdrv_window w, macdrv_window parent) +{ + WineWindow* window = (WineWindow*)w; + + OnMainThread(^{ + [window setMacDrvParentWindow:(WineWindow*)parent]; + }); +} diff --git a/dlls/winemac.drv/macdrv_cocoa.h b/dlls/winemac.drv/macdrv_cocoa.h index fa2e083b23f..86a49cec435 100644 --- a/dlls/winemac.drv/macdrv_cocoa.h +++ b/dlls/winemac.drv/macdrv_cocoa.h @@ -144,5 +144,6 @@ extern int macdrv_order_cocoa_window(macdrv_window w, macdrv_window prev, macdrv_window next) DECLSPEC_HIDDEN; extern void macdrv_hide_cocoa_window(macdrv_window w) DECLSPEC_HIDDEN; extern int macdrv_set_cocoa_window_frame(macdrv_window w, const CGRect* new_frame) DECLSPEC_HIDDEN; +extern void macdrv_set_cocoa_parent_window(macdrv_window w, macdrv_window parent) DECLSPEC_HIDDEN; #endif /* __WINE_MACDRV_COCOA_H */ diff --git a/dlls/winemac.drv/window.c b/dlls/winemac.drv/window.c index 232c60ab1ab..21c9e59c0ce 100644 --- a/dlls/winemac.drv/window.c +++ b/dlls/winemac.drv/window.c @@ -301,12 +301,18 @@ static macdrv_window macdrv_get_cocoa_window(HWND hwnd) static void set_cocoa_window_properties(struct macdrv_win_data *data) { DWORD style, ex_style; + HWND owner; + macdrv_window owner_win; struct macdrv_window_features wf; struct macdrv_window_state state; style = GetWindowLongW(data->hwnd, GWL_STYLE); ex_style = GetWindowLongW(data->hwnd, GWL_EXSTYLE); + owner = GetWindow(data->hwnd, GW_OWNER); + owner_win = macdrv_get_cocoa_window(owner); + macdrv_set_cocoa_parent_window(data->cocoa_window, owner_win); + get_cocoa_window_features(data, style, ex_style, &wf); macdrv_set_cocoa_window_features(data->cocoa_window, &wf);