API 0.9.5
AppKit/Platform/CPPlatformWindow.j
Go to the documentation of this file.
00001 /*
00002  * CPPlatformWindow.j
00003  * AppKit
00004  *
00005  * Created by Francisco Tolmasky.
00006  * Copyright 2010, 280 North, Inc.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 
00024 
00025 var PrimaryPlatformWindow   = NULL;
00026 
00027 @implementation CPPlatformWindow : CPObject
00028 {
00029     CGRect          _contentRect;
00030 
00031     CPInteger       _level;
00032     BOOL            _hasShadow;
00033     unsigned        _shadowStyle;
00034     CPString        _title;
00035 
00036 #if PLATFORM(DOM)
00037     DOMWindow       _DOMWindow;
00038 
00039     DOMElement      _DOMBodyElement;
00040     DOMElement      _DOMFocusElement;
00041     DOMElement      _DOMEventGuard;
00042     DOMElement      _DOMScrollingElement;
00043     id              _hideDOMScrollingElementTimeout;
00044 
00045     CPArray         _windowLevels;
00046     CPDictionary    _windowLayers;
00047 
00048     BOOL            _mouseIsDown;
00049     BOOL            _mouseDownIsRightClick;
00050     CGPoint         _lastMouseEventLocation;
00051     CPWindow        _mouseDownWindow;
00052     CPTimeInterval  _lastMouseUp;
00053     CPTimeInterval  _lastMouseDown;
00054 
00055     Object          _charCodes;
00056     unsigned        _keyCode;
00057     unsigned        _lastKey;
00058     BOOL            _capsLockActive;
00059     BOOL            _ignoreNativeCopyOrCutEvent;
00060     BOOL            _ignoreNativePastePreparation;
00061 
00062     BOOL            _DOMEventMode;
00063 
00064     // Native Pasteboard Support
00065     DOMElement      _DOMPasteboardElement;
00066     CPEvent         _pasteboardKeyDownEvent;
00067 
00068     CPString        _overriddenEventType;
00069 #endif
00070 }
00071 
00072 + (CPSet)visiblePlatformWindows
00073 {
00074     return [CPSet set];
00075 }
00076 
00077 + (BOOL)supportsMultipleInstances
00078 {
00079 #if PLATFORM(DOM)
00080     return !CPBrowserIsEngine(CPInternetExplorerBrowserEngine);
00081 #else
00082     return NO;
00083 #endif
00084 }
00085 
00086 + (CPPlatformWindow)primaryPlatformWindow
00087 {
00088     return PrimaryPlatformWindow;
00089 }
00090 
00091 + (void)setPrimaryPlatformWindow:(CPPlatformWindow)aPlatformWindow
00092 {
00093     PrimaryPlatformWindow = aPlatformWindow;
00094 }
00095 
00096 - (id)initWithContentRect:(CGRect)aRect
00097 {
00098     self = [super init];
00099 
00100     if (self)
00101     {
00102         _contentRect = _CGRectMakeCopy(aRect);
00103 
00104 #if PLATFORM(DOM)
00105         _windowLevels = [];
00106         _windowLayers = [CPDictionary dictionary];
00107 
00108         _charCodes = {};
00109 #endif
00110     }
00111 
00112     return self;
00113 }
00114 
00115 - (id)init
00116 {
00117     return [self initWithContentRect:_CGRectMake(0.0, 0.0, 400.0, 500.0)];
00118 }
00119 
00120 - (CGRect)contentRect
00121 {
00122     return _CGRectMakeCopy(_contentRect);
00123 }
00124 
00125 - (CGRect)contentBounds
00126 {
00127     var contentBounds = [self contentRect];
00128 
00129     contentBounds.origin = _CGPointMakeZero();
00130 
00131     return contentBounds;
00132 }
00133 
00134 - (CGRect)visibleFrame
00135 {
00136     var frame = [self contentBounds];
00137 
00138     frame.origin = CGPointMakeZero();
00139 
00140     if ([CPMenu menuBarVisible] && [CPPlatformWindow primaryPlatformWindow] === self)
00141     {
00142         var menuBarHeight = [[CPApp mainMenu] menuBarHeight];
00143 
00144         frame.origin.y += menuBarHeight;
00145         frame.size.height -= menuBarHeight;
00146     }
00147 
00148     return frame;
00149 }
00150 
00151 - (CGRect)usableContentFrame
00152 {
00153     return [self visibleFrame];
00154 }
00155 
00156 - (void)setContentRect:(CGRect)aRect
00157 {
00158     if (!aRect || _CGRectEqualToRect(_contentRect, aRect))
00159         return;
00160 
00161     _contentRect = _CGRectMakeCopy(aRect);
00162 
00163 #if PLATFORM(DOM)
00164      [self updateNativeContentRect];
00165 #endif
00166 }
00167 
00168 - (void)updateFromNativeContentRect
00169 {
00170     [self setContentRect:[self nativeContentRect]];
00171 }
00172 
00173 - (CGPoint)convertBaseToScreen:(CGPoint)aPoint
00174 {
00175     var contentRect = [self contentRect];
00176 
00177     return _CGPointMake(aPoint.x + _CGRectGetMinX(contentRect), aPoint.y + _CGRectGetMinY(contentRect));
00178 }
00179 
00180 - (CGPoint)convertScreenToBase:(CGPoint)aPoint
00181 {
00182     var contentRect = [self contentRect];
00183 
00184     return _CGPointMake(aPoint.x - _CGRectGetMinX(contentRect), aPoint.y - _CGRectGetMinY(contentRect));
00185 }
00186 
00187 - (BOOL)isVisible
00188 {
00189 #if PLATFORM(DOM)
00190     return _DOMWindow !== NULL;
00191 #else
00192     return NO;
00193 #endif
00194 }
00195 
00196 - (void)deminiaturize:(id)sender
00197 {
00198 #if PLATFORM(DOM)
00199     if (_DOMWindow && typeof _DOMWindow["cpDeminiaturize"] === "function")
00200         _DOMWindow.cpDeminiaturize();
00201 #endif
00202 }
00203 
00204 - (void)miniaturize:(id)sender
00205 {
00206 #if PLATFORM(DOM)
00207     if (_DOMWindow && typeof _DOMWindow["cpMiniaturize"] === "function")
00208         _DOMWindow.cpMiniaturize();
00209 #endif
00210 }
00211 
00212 - (void)moveWindow:(CPWindow)aWindow fromLevel:(int)fromLevel toLevel:(int)toLevel
00213 {
00214 #if PLATFORM(DOM)
00215     if (!aWindow._isVisible)
00216         return;
00217 
00218     var fromLayer = [self layerAtLevel:fromLevel create:NO],
00219         toLayer = [self layerAtLevel:toLevel create:YES];
00220 
00221     [fromLayer removeWindow:aWindow];
00222     [toLayer insertWindow:aWindow atIndex:CPNotFound];
00223 #endif
00224 }
00225 
00226 - (void)setLevel:(CPInteger)aLevel
00227 {
00228     _level = aLevel;
00229 
00230 #if PLATFORM(DOM)
00231     if (_DOMWindow && _DOMWindow.cpSetLevel)
00232         _DOMWindow.cpSetLevel(aLevel);
00233 #endif
00234 }
00235 
00236 - (void)setHasShadow:(BOOL)shouldHaveShadow
00237 {
00238     _hasShadow = shouldHaveShadow;
00239 
00240 #if PLATFORM(DOM)
00241     if (_DOMWindow && _DOMWindow.cpSetHasShadow)
00242         _DOMWindow.cpSetHasShadow(shouldHaveShadow);
00243 #endif
00244 }
00245 
00246 - (void)setShadowStyle:(int)aStyle
00247 {
00248     _shadowStyle = aStyle;
00249 
00250 #if PLATFORM(DOM)
00251     if (_DOMWindow && _DOMWindow.cpSetShadowStyle)
00252         _shadowStyle.cpSetShadowStyle(aStyle);
00253 #endif
00254 }
00255 
00256 - (BOOL)supportsFullPlatformWindows
00257 {
00258     return [CPPlatform isBrowser];
00259 }
00260 
00261 - (void)_setTitle:(CPString)aTitle window:(CPWindow)aWindow
00262 {
00263     _title = aTitle;
00264 
00265 #if PLATFORM(DOM)
00266     if (_DOMWindow && _DOMWindow.document
00267         && (aWindow === [CPApp mainWindow] || [aWindow platformWindow] !== [CPPlatformWindow primaryPlatformWindow]))
00268         _DOMWindow.document.title = _title;
00269 #endif
00270 }
00271 
00272 - (CPString)title
00273 {
00274     return _title;
00275 }
00276 
00277 @end
00278 
00279 #if PLATFORM(BROWSER)
00280 #endif
 All Classes Files Functions Variables Defines