1/* 2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#ifndef __LP64__ 30 31#import "CarbonWindowFrame.h" 32#import "CarbonWindowAdapter.h" 33#import "CarbonWindowContentView.h" 34#import <Foundation/NSGeometry.h> 35#import <Foundation/NSString.h> 36#import <HIToolbox/MacWindows.h> 37 38#import "WebTypesInternal.h" 39 40@interface NSView(Secret) 41- (void)_setWindow:(NSWindow *)window; 42@end 43 44@class NSButton; 45/* 46 47@interface NSThemeFrame(NSHijackedClassMethods) 48 49+ (float)_titlebarHeight:(unsigned int)style; 50 51@end 52*/ 53 54@implementation CarbonWindowFrame 55 56 57- (NSRect)titlebarRect 58{ 59 NSRect titlebarRect; 60 NSRect boundsRect; 61 62 boundsRect = [self bounds]; 63 64 CarbonWindowAdapter *carbonWindow; 65 carbonWindow = (CarbonWindowAdapter *)[self window]; 66 WindowRef windowRef = [carbonWindow windowRef]; 67 Rect globalBounds; 68 GetWindowBounds (windowRef, kWindowTitleBarRgn, &globalBounds); 69 70 titlebarRect.origin.x = boundsRect.origin.x; 71 titlebarRect.size.width = boundsRect.size.width; 72 titlebarRect.size.height = globalBounds.bottom - globalBounds.top; 73 titlebarRect.origin.y = NSMaxY(boundsRect) - titlebarRect.size.height; 74 75 return titlebarRect; 76} 77 78// Given a content rectangle and style mask, return a corresponding frame rectangle. 79+ (NSRect)frameRectForContentRect:(NSRect)contentRect styleMask:(NSUInteger)style { 80 81 // We don't bother figuring out a good value, because content rects weren't so meaningful for NSCarbonWindows in the past, but this might not be a good assumption anymore. M.P. Warning - 12/5/00 82 return contentRect; 83 84} 85 86+ (NSRect)contentRectForFrameRect:(NSRect)frameRect styleMask:(NSUInteger)style { 87 88 // We don't bother figuring out a good value, because content rects weren't so meaningful for NSCarbonWindows in the past, but this might not be a good assumption anymore. KW - copied from +frameRectForContentRect:styleMask 89 return frameRect; 90 91} 92 93+ (NSSize)minFrameSizeForMinContentSize:(NSSize)cSize styleMask:(NSUInteger)style { 94 // See comments above. We don't make any assumptions about the relationship between content rects and frame rects 95 return cSize; 96} 97 98- (NSRect)frameRectForContentRect:(NSRect)cRect styleMask:(NSUInteger)style { 99 return [[self class] frameRectForContentRect: cRect styleMask:style]; 100} 101- (NSRect)contentRectForFrameRect:(NSRect)fRect styleMask:(NSUInteger)style { 102 return [[self class] contentRectForFrameRect: fRect styleMask:style]; 103} 104- (NSSize)minFrameSizeForMinContentSize:(NSSize)cSize styleMask:(NSUInteger)style { 105 return [[self class] minFrameSizeForMinContentSize:cSize styleMask: style]; 106} 107 108// Initialize. 109- (id)initWithFrame:(NSRect)inFrameRect styleMask:(unsigned int)inStyleMask owner:(NSWindow *)inOwningWindow { 110 111 // Parameter check. 112 if (![inOwningWindow isKindOfClass:[CarbonWindowAdapter class]]) NSLog(@"CarbonWindowFrames can only be owned by CarbonWindowAdapters."); 113 114 // Do the standard Cocoa thing. 115 self = [super initWithFrame:inFrameRect]; 116 if (!self) return nil; 117 118 // Record what we'll need later. 119 _styleMask = inStyleMask; 120 121 // Do what NSFrameView's method of the same name does. 122 [self _setWindow:inOwningWindow]; 123 [self setNextResponder:inOwningWindow]; 124 125 // Done. 126 return self; 127 128} 129 130 131// Deallocate. 132- (void)dealloc { 133 134 // Simple. 135 [super dealloc]; 136 137} 138 139 140// Sink a method invocation. 141- (void)_setFrameNeedsDisplay:(BOOL)needsDisplay { 142 143} 144 145 146// Sink a method invocation. 147- (void)_setSheet:(BOOL)sheetFlag { 148 149} 150 151 152// Sink a method invocation. 153- (void)_updateButtonState { 154 155} 156 157#if 0 158// Sink a method invocation. 159- (void)_windowChangedKeyState { 160} 161#endif 162 163// Toolbar methods that NSWindow expects to be there. 164- (BOOL)_canHaveToolbar { return NO; } 165- (BOOL)_toolbarIsInTransition { return NO; } 166- (BOOL)_toolbarIsShown { return NO; } 167- (BOOL)_toolbarIsHidden { return NO; } 168- (void)_showToolbarWithAnimation:(BOOL)animate {} 169- (void)_hideToolbarWithAnimation:(BOOL)animate {} 170- (float)_distanceFromToolbarBaseToTitlebar { return 0; } 171 172 173// Refuse to admit there's a close button on the window. 174- (NSButton *)closeButton { 175 176 // Simple. 177 return nil; 178} 179 180 181// Return what's asked for. 182- (unsigned int)styleMask { 183 184 // Simple. 185 return _styleMask; 186 187} 188 189 190// Return what's asked for. 191- (NSRect)dragRectForFrameRect:(NSRect)frameRect { 192 193 // Do what NSThemeFrame would do. 194 // If we just return NSZeroRect here, _NXMakeWindowVisible() gets all befuddled in the sheet-showing case, a window-moving loop is entered, and the sheet gets moved right off of the screen. M.P. Warning - 3/23/01 195 NSRect dragRect; 196 dragRect.size.height = 27;//[NSThemeFrame _titlebarHeight:[self styleMask]]; 197 dragRect.origin.y = NSMaxY(frameRect) - dragRect.size.height; 198 dragRect.size.width = frameRect.size.width; 199 dragRect.origin.x = frameRect.origin.x; 200 return dragRect; 201 202} 203 204 205// Return what's asked for. 206- (BOOL)isOpaque { 207 208 // Return a value that will make -[NSWindow displayIfNeeded] on our Carbon window actually work. 209 return YES; 210 211} 212 213 214// Refuse to admit there's a minimize button on the window. 215- (NSButton *)minimizeButton { 216 217 // Simple. 218 return nil; 219 220} 221 222 223// Do the right thing for a Carbon window. 224- (void)setTitle:(NSString *)title { 225 226 CarbonWindowAdapter *carbonWindow; 227 OSStatus osStatus; 228 WindowRef windowRef; 229 230 // Set the Carbon window's title. 231 carbonWindow = (CarbonWindowAdapter *)[self window]; 232 windowRef = [carbonWindow windowRef]; 233 osStatus = SetWindowTitleWithCFString(windowRef, (CFStringRef)title); 234 if (osStatus!=noErr) NSLog(@"A Carbon window's title couldn't be set."); 235 236} 237 238 239// Return what's asked for. 240- (NSString *)title { 241 242 CFStringRef windowTitle; 243 CarbonWindowAdapter *carbonWindow; 244 NSString *windowTitleAsNSString; 245 OSStatus osStatus; 246 WindowRef windowRef; 247 248 // Return the Carbon window's title. 249 carbonWindow = (CarbonWindowAdapter *)[self window]; 250 windowRef = [carbonWindow windowRef]; 251 osStatus = CopyWindowTitleAsCFString(windowRef, &windowTitle); 252 if (osStatus==noErr) { 253 windowTitleAsNSString = (NSString *)windowTitle; 254 } else { 255 NSLog(@"A Carbon window's title couldn't be gotten."); 256 windowTitleAsNSString = @""; 257 } 258 return [windowTitleAsNSString autorelease]; 259 260} 261 262 263// Return what's asked for. 264- (float)_sheetHeightAdjustment { 265 266 // Do what NSThemeFrame would do. 267 return 22;//[NSThemeFrame _titlebarHeight:([self styleMask] & ~NSDocModalWindowMask)]; 268 269} 270 271// Return what's asked for. 272- (float)_maxTitlebarTitleRect { 273 274 // Do what NSThemeFrame would do. 275 return 22;//[NSThemeFrame _titlebarHeight:([self styleMask] & ~NSDocModalWindowMask)]; 276 277} 278 279- (void)_clearDragMargins { 280} 281 282- (void)_resetDragMargins { 283} 284 285 286@end // implementation NSCarbonWindowFrame 287 288#endif 289