3
* VBox frontends: Qt GUI ("VirtualBox"):
4
* Declarations of utility classes and functions for handling Darwin Cocoa
9
* Copyright (C) 2009 Sun Microsystems, Inc.
11
* This file is part of VirtualBox Open Source Edition (OSE), as
12
* available from http://www.virtualbox.org. This file is free software;
13
* you can redistribute it and/or modify it under the terms of the GNU
14
* General Public License (GPL) as published by the Free Software
15
* Foundation, in version 2 as it comes in the "COPYING" file of the
16
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20
* Clara, CA 95054 USA or visit http://www.sun.com if you need
21
* additional information or have any questions.
24
#include "VBoxUtils-darwin.h"
26
#include <iprt/assert.h>
28
#import <AppKit/NSEvent.h>
29
#import <AppKit/NSColor.h>
31
NativeWindowRef darwinToNativeWindowImpl (NativeViewRef aView)
33
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
35
NativeWindowRef window = NULL;
37
window = [aView window];
43
NativeViewRef darwinToNativeViewImpl (NativeWindowRef aWindow)
45
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
47
NativeViewRef view = NULL;
49
view = [aWindow contentView];
55
void darwinSetShowsToolbarButtonImpl (NativeWindowRef aWindow, bool aEnabled)
57
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
59
[aWindow setShowsToolbarButton:aEnabled];
64
void darwinSetShowsResizeIndicatorImpl (NativeWindowRef aWindow, bool aEnabled)
66
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
68
[aWindow setShowsResizeIndicator:aEnabled];
73
void darwinSetHidesAllTitleButtonsImpl (NativeWindowRef aWindow)
75
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
77
NSButton *closeButton = [aWindow standardWindowButton:NSWindowCloseButton];
78
if (closeButton != Nil)
79
[closeButton setHidden:YES];
80
NSButton *minButton = [aWindow standardWindowButton:NSWindowMiniaturizeButton];
82
[minButton setHidden:YES];
83
NSButton *zoomButton = [aWindow standardWindowButton:NSWindowZoomButton];
84
if (zoomButton != Nil)
85
[zoomButton setHidden:YES];
86
NSButton *iconButton = [aWindow standardWindowButton:NSWindowDocumentIconButton];
87
if (iconButton != Nil)
88
[iconButton setHidden:YES];
93
void darwinSetShowsWindowTransparentImpl (NativeWindowRef aWindow, bool aEnabled)
95
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
99
[aWindow setOpaque:NO];
100
[aWindow setBackgroundColor:[NSColor clearColor]];
101
[aWindow setHasShadow:NO];
105
[aWindow setOpaque:YES];
106
[aWindow setBackgroundColor:[NSColor windowBackgroundColor]];
107
[aWindow setHasShadow:YES];
114
* Calls the + (void)setMouseCoalescingEnabled:(BOOL)flag class method.
116
* @param fEnabled Whether to enable or disable coalescing.
118
void darwinSetMouseCoalescingEnabled (bool aEnabled)
120
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
122
[NSEvent setMouseCoalescingEnabled:aEnabled];
127
void darwinWindowAnimateResizeImpl (NativeWindowRef aWindow, int x, int y, int width, int height)
129
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
131
/* It seems that Qt doesn't return the height of the window with the
132
* toolbar height included. So add this size manually. Could easily be that
133
* the Trolls fix this in the final release. */
134
NSToolbar *toolbar = [aWindow toolbar];
135
NSRect windowFrame = [aWindow frame];
136
int toolbarHeight = 0;
137
if(toolbar && [toolbar isVisible])
138
toolbarHeight = NSHeight (windowFrame) - NSHeight ([[aWindow contentView] frame]);
139
int h = height + toolbarHeight;
140
int h1 = h - NSHeight (windowFrame);
141
windowFrame.size.height = h;
142
windowFrame.origin.y -= h1;
144
[aWindow setFrame:windowFrame display:YES animate:YES];
149
void darwinWindowInvalidateShadowImpl (NativeWindowRef aWindow)
151
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
153
[aWindow invalidateShadow];