CarbonWindowFrame.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. #ifndef __LP64__
  29. #import "CarbonWindowFrame.h"
  30. #import "CarbonWindowAdapter.h"
  31. #import "CarbonWindowContentView.h"
  32. #import <Foundation/NSGeometry.h>
  33. #import <Foundation/NSString.h>
  34. #import <HIToolbox/MacWindows.h>
  35. #import "WebTypesInternal.h"
  36. @interface NSView(Secret)
  37. - (void)_setWindow:(NSWindow *)window;
  38. @end
  39. @class NSButton;
  40. /*
  41. @interface NSThemeFrame(NSHijackedClassMethods)
  42. + (float)_titlebarHeight:(unsigned int)style;
  43. @end
  44. */
  45. @implementation CarbonWindowFrame
  46. - (NSRect)titlebarRect
  47. {
  48. NSRect titlebarRect;
  49. NSRect boundsRect;
  50. boundsRect = [self bounds];
  51. CarbonWindowAdapter *carbonWindow;
  52. carbonWindow = (CarbonWindowAdapter *)[self window];
  53. WindowRef windowRef = [carbonWindow windowRef];
  54. Rect globalBounds;
  55. GetWindowBounds (windowRef, kWindowTitleBarRgn, &globalBounds);
  56. titlebarRect.origin.x = boundsRect.origin.x;
  57. titlebarRect.size.width = boundsRect.size.width;
  58. titlebarRect.size.height = globalBounds.bottom - globalBounds.top;
  59. titlebarRect.origin.y = NSMaxY(boundsRect) - titlebarRect.size.height;
  60. return titlebarRect;
  61. }
  62. // Given a content rectangle and style mask, return a corresponding frame rectangle.
  63. + (NSRect)frameRectForContentRect:(NSRect)contentRect styleMask:(NSUInteger)style {
  64. // 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
  65. return contentRect;
  66. }
  67. + (NSRect)contentRectForFrameRect:(NSRect)frameRect styleMask:(NSUInteger)style {
  68. // 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
  69. return frameRect;
  70. }
  71. + (NSSize)minFrameSizeForMinContentSize:(NSSize)cSize styleMask:(NSUInteger)style {
  72. // See comments above. We don't make any assumptions about the relationship between content rects and frame rects
  73. return cSize;
  74. }
  75. - (NSRect)frameRectForContentRect:(NSRect)cRect styleMask:(NSUInteger)style {
  76. return [[self class] frameRectForContentRect: cRect styleMask:style];
  77. }
  78. - (NSRect)contentRectForFrameRect:(NSRect)fRect styleMask:(NSUInteger)style {
  79. return [[self class] contentRectForFrameRect: fRect styleMask:style];
  80. }
  81. - (NSSize)minFrameSizeForMinContentSize:(NSSize)cSize styleMask:(NSUInteger)style {
  82. return [[self class] minFrameSizeForMinContentSize:cSize styleMask: style];
  83. }
  84. // Initialize.
  85. - (id)initWithFrame:(NSRect)inFrameRect styleMask:(unsigned int)inStyleMask owner:(NSWindow *)inOwningWindow {
  86. // Parameter check.
  87. if (![inOwningWindow isKindOfClass:[CarbonWindowAdapter class]]) NSLog(@"CarbonWindowFrames can only be owned by CarbonWindowAdapters.");
  88. // Do the standard Cocoa thing.
  89. self = [super initWithFrame:inFrameRect];
  90. if (!self) return nil;
  91. // Record what we'll need later.
  92. _styleMask = inStyleMask;
  93. // Do what NSFrameView's method of the same name does.
  94. [self _setWindow:inOwningWindow];
  95. [self setNextResponder:inOwningWindow];
  96. // Done.
  97. return self;
  98. }
  99. // Deallocate.
  100. - (void)dealloc {
  101. // Simple.
  102. [super dealloc];
  103. }
  104. // Sink a method invocation.
  105. - (void)_setFrameNeedsDisplay:(BOOL)needsDisplay {
  106. }
  107. // Sink a method invocation.
  108. - (void)_setSheet:(BOOL)sheetFlag {
  109. }
  110. // Sink a method invocation.
  111. - (void)_updateButtonState {
  112. }
  113. #if 0
  114. // Sink a method invocation.
  115. - (void)_windowChangedKeyState {
  116. }
  117. #endif
  118. // Toolbar methods that NSWindow expects to be there.
  119. - (BOOL)_canHaveToolbar { return NO; }
  120. - (BOOL)_toolbarIsInTransition { return NO; }
  121. - (BOOL)_toolbarIsShown { return NO; }
  122. - (BOOL)_toolbarIsHidden { return NO; }
  123. - (void)_showToolbarWithAnimation:(BOOL)animate {}
  124. - (void)_hideToolbarWithAnimation:(BOOL)animate {}
  125. - (float)_distanceFromToolbarBaseToTitlebar { return 0; }
  126. // Refuse to admit there's a close button on the window.
  127. - (NSButton *)closeButton {
  128. // Simple.
  129. return nil;
  130. }
  131. // Return what's asked for.
  132. - (unsigned int)styleMask {
  133. // Simple.
  134. return _styleMask;
  135. }
  136. // Return what's asked for.
  137. - (NSRect)dragRectForFrameRect:(NSRect)frameRect {
  138. // Do what NSThemeFrame would do.
  139. // 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
  140. NSRect dragRect;
  141. dragRect.size.height = 27;//[NSThemeFrame _titlebarHeight:[self styleMask]];
  142. dragRect.origin.y = NSMaxY(frameRect) - dragRect.size.height;
  143. dragRect.size.width = frameRect.size.width;
  144. dragRect.origin.x = frameRect.origin.x;
  145. return dragRect;
  146. }
  147. // Return what's asked for.
  148. - (BOOL)isOpaque {
  149. // Return a value that will make -[NSWindow displayIfNeeded] on our Carbon window actually work.
  150. return YES;
  151. }
  152. // Refuse to admit there's a minimize button on the window.
  153. - (NSButton *)minimizeButton {
  154. // Simple.
  155. return nil;
  156. }
  157. // Do the right thing for a Carbon window.
  158. - (void)setTitle:(NSString *)title {
  159. CarbonWindowAdapter *carbonWindow;
  160. OSStatus osStatus;
  161. WindowRef windowRef;
  162. // Set the Carbon window's title.
  163. carbonWindow = (CarbonWindowAdapter *)[self window];
  164. windowRef = [carbonWindow windowRef];
  165. osStatus = SetWindowTitleWithCFString(windowRef, (CFStringRef)title);
  166. if (osStatus!=noErr) NSLog(@"A Carbon window's title couldn't be set.");
  167. }
  168. // Return what's asked for.
  169. - (NSString *)title {
  170. CFStringRef windowTitle;
  171. CarbonWindowAdapter *carbonWindow;
  172. NSString *windowTitleAsNSString;
  173. OSStatus osStatus;
  174. WindowRef windowRef;
  175. // Return the Carbon window's title.
  176. carbonWindow = (CarbonWindowAdapter *)[self window];
  177. windowRef = [carbonWindow windowRef];
  178. osStatus = CopyWindowTitleAsCFString(windowRef, &windowTitle);
  179. if (osStatus==noErr) {
  180. windowTitleAsNSString = (NSString *)windowTitle;
  181. } else {
  182. NSLog(@"A Carbon window's title couldn't be gotten.");
  183. windowTitleAsNSString = @"";
  184. }
  185. return [windowTitleAsNSString autorelease];
  186. }
  187. // Return what's asked for.
  188. - (float)_sheetHeightAdjustment {
  189. // Do what NSThemeFrame would do.
  190. return 22;//[NSThemeFrame _titlebarHeight:([self styleMask] & ~NSDocModalWindowMask)];
  191. }
  192. // Return what's asked for.
  193. - (float)_maxTitlebarTitleRect {
  194. // Do what NSThemeFrame would do.
  195. return 22;//[NSThemeFrame _titlebarHeight:([self styleMask] & ~NSDocModalWindowMask)];
  196. }
  197. - (void)_clearDragMargins {
  198. }
  199. - (void)_resetDragMargins {
  200. }
  201. @end // implementation NSCarbonWindowFrame
  202. #endif