00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import <Foundation/CPObject.j>
00024
00025 #import "Platform.h"
00026 #import "../CoreGraphics/CGGeometry.h"
00027
00028
00029 var PrimaryPlatformWindow = NULL;
00030
00031 @implementation CPPlatformWindow : CPObject
00032 {
00033 CGRect _contentRect;
00034
00035 CPInteger _level;
00036 BOOL _hasShadow;
00037 unsigned _shadowStyle;
00038
00039 #if PLATFORM(DOM)
00040 DOMWindow _DOMWindow;
00041
00042 DOMElement _DOMBodyElement;
00043 DOMElement _DOMFocusElement;
00044
00045 CPArray _windowLevels;
00046 CPDictionary _windowLayers;
00047
00048 BOOL _mouseIsDown;
00049 CPWindow _mouseDownWindow;
00050 CPTimeInterval _lastMouseUp;
00051 CPTimeInterval _lastMouseDown;
00052
00053 Object _charCodes;
00054 unsigned _keyCode;
00055 unsigned _lastKey;
00056 BOOL _capsLockActive;
00057 BOOL _ignoreNativeCopyOrCutEvent;
00058 BOOL _ignoreNativePastePreparation;
00059
00060 BOOL _DOMEventMode;
00061
00062
00063 DOMElement _DOMPasteboardElement;
00064 CPEvent _pasteboardKeyDownEvent;
00065
00066 CPString _overriddenEventType;
00067 #endif
00068 }
00069
00070 + (CPSet)visiblePlatformWindows
00071 {
00072 return [CPSet set];
00073 }
00074
00075 + (CPPlatformWindow)primaryPlatformWindow
00076 {
00077 return PrimaryPlatformWindow;
00078 }
00079
00080 + (void)setPrimaryPlatformWindow:(CPPlatformWindow)aPlatformWindow
00081 {
00082 PrimaryPlatformWindow = aPlatformWindow;
00083 }
00084
00085 - (id)initWithContentRect:(CGRect)aRect
00086 {
00087 self = [super init];
00088
00089 if (self)
00090 {
00091 _contentRect = _CGRectMakeCopy(aRect);
00092
00093 #if PLATFORM(DOM)
00094 _windowLevels = [];
00095 _windowLayers = [CPDictionary dictionary];
00096
00097 _charCodes = {};
00098 #endif
00099 }
00100
00101 return self;
00102 }
00103
00104 - (id)init
00105 {
00106 return [self initWithContentRect:_CGRectMake(0.0, 0.0, 400.0, 500.0)];
00107 }
00108
00109 - (CGRect)contentRect
00110 {
00111 return _CGRectMakeCopy(_contentRect);
00112 }
00113
00114 - (CGRect)contentBounds
00115 {
00116 var contentBounds = [self contentRect];
00117
00118 contentBounds.origin = _CGPointMakeZero();
00119
00120 return contentBounds;
00121 }
00122
00123 - (CGRect)visibleFrame
00124 {
00125 var frame = [self contentBounds];
00126
00127 frame.origin = CGPointMakeZero();
00128
00129 if ([CPMenu menuBarVisible] && [CPPlatformWindow primaryPlatformWindow] === self)
00130 {
00131 var menuBarHeight = [[CPApp mainMenu] menuBarHeight];
00132
00133 frame.origin.y += menuBarHeight;
00134 frame.size.height -= menuBarHeight;
00135 }
00136
00137 return frame;
00138 }
00139
00140 - (CGRect)usableContentFrame
00141 {
00142 return [self visibleFrame];
00143 }
00144
00145 - (void)setContentRect:(CGRect)aRect
00146 {
00147 if (!aRect || _CGRectEqualToRect(_contentRect, aRect))
00148 return;
00149
00150 _contentRect = _CGRectMakeCopy(aRect);
00151
00152 [self updateNativeContentRect];
00153 }
00154
00155 - (void)updateFromNativeContentRect
00156 {
00157 [self setContentRect:[self nativeContentRect]];
00158 }
00159
00160 - (CGPoint)convertBaseToScreen:(CGPoint)aPoint
00161 {
00162 var contentRect = [self contentRect];
00163
00164 return _CGPointMake(aPoint.x + _CGRectGetMinX(contentRect), aPoint.y + _CGRectGetMinY(contentRect));
00165 }
00166
00167 - (CGPoint)convertScreenToBase:(CGPoint)aPoint
00168 {
00169 var contentRect = [self contentRect];
00170
00171 return _CGPointMake(aPoint.x - _CGRectGetMinX(contentRect), aPoint.y - _CGRectGetMinY(contentRect));
00172 }
00173
00174 - (BOOL)isVisible
00175 {
00176 #if PLATFORM(DOM)
00177 return _DOMWindow !== NULL;
00178 #else
00179 return NO;
00180 #endif
00181 }
00182
00183 - (void)deminiaturize:(id)sender
00184 {
00185 #if PLATFORM(DOM)
00186 if (_DOMWindow && typeof _DOMWindow["cpDeminiaturize"] === "function")
00187 _DOMWindow.cpDeminiaturize();
00188 #endif
00189 }
00190
00191 - (void)miniaturize:(id)sender
00192 {
00193 #if PLATFORM(DOM)
00194 if (_DOMWindow && typeof _DOMWindow["cpMiniaturize"] === "function")
00195 _DOMWindow.cpMiniaturize();
00196 #endif
00197 }
00198
00199 - (void)moveWindow:(CPWindow)aWindow fromLevel:(int)fromLevel toLevel:(int)toLevel
00200 {
00201 #if PLATFORM(DOM)
00202 if (!aWindow._isVisible)
00203 return;
00204
00205 var fromLayer = [self layerAtLevel:fromLevel create:NO],
00206 toLayer = [self layerAtLevel:toLevel create:YES];
00207
00208 [fromLayer removeWindow:aWindow];
00209 [toLayer insertWindow:aWindow atIndex:CPNotFound];
00210 #endif
00211 }
00212
00213 - (void)setLevel:(CPInteger)aLevel
00214 {
00215 _level = aLevel;
00216
00217 #if PLATFORM(DOM)
00218 if (_DOMWindow && _DOMWindow.cpSetLevel)
00219 _DOMWindow.cpSetLevel(aLevel);
00220 #endif
00221 }
00222
00223 - (void)setHasShadow:(BOOL)shouldHaveShadow
00224 {
00225 _hasShadow = shouldHaveShadow;
00226
00227 #if PLATFORM(DOM)
00228 if (_DOMWindow && _DOMWindow.cpSetHasShadow)
00229 _DOMWindow.cpSetHasShadow(shouldHaveShadow);
00230 #endif
00231 }
00232
00233 - (void)setShadowStyle:(int)aStyle
00234 {
00235 _shadowStyle = aStyle;
00236
00237 #if PLATFORM(DOM)
00238 if (_DOMWindow && _DOMWindow.cpSetShadowStyle)
00239 _shadowStyle.cpSetShadowStyle(aStyle);
00240 #endif
00241 }
00242
00243 - (BOOL)supportsFullPlatformWindows
00244 {
00245 return [CPPlatform isBrowser];
00246 }
00247
00248 @end
00249
00250 #if PLATFORM(BROWSER)
00251 @import "CPPlatformWindow+DOM.j"
00252 #endif