API  0.9.10
CPPlatformWindow.j
Go to the documentation of this file.
1 /*
2  * CPPlatformWindow.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2010, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
24 
25 @global CPApp
26 
27 @typedef DOMWindow
28 
30 
31 @implementation CPPlatformWindow : CPObject
32 {
33  CGRect _contentRect;
34 
35  CPInteger _level;
36  BOOL _hasShadow;
37  unsigned _shadowStyle;
38  CPString _title;
39  BOOL _shouldUpdateContentRect;
40  BOOL _hasInitializeInstanceWithWindow;
41 
42 #if PLATFORM(DOM)
43  DOMWindow _DOMWindow;
44 
45  DOMElement _DOMBodyElement;
46  DOMElement _DOMFocusElement;
47  DOMElement _DOMEventGuard;
48  DOMElement _DOMScrollingElement;
49  id _hideDOMScrollingElementTimeout;
50 
51  CPArray _windowLevels;
52  CPDictionary _windowLayers;
53 
54  BOOL _mouseIsDown;
55  BOOL _mouseDownIsRightClick;
56  int _firstMouseDownButton;
57  CGPoint _lastMouseEventLocation;
58  CPWindow _mouseDownWindow;
59  CPTimeInterval _lastMouseUp;
60  CPTimeInterval _lastMouseDown;
61 
62  Object _charCodes;
63  unsigned _keyCode;
64  unsigned _lastKey;
65  BOOL _capsLockActive;
66 
67  BOOL _DOMEventMode;
68 
69  CPPlatformPasteboard _platformPasteboard;
70 
71  CPString _overriddenEventType;
72 
73  CPWindow _currentKeyWindow;
74  CPWindow _previousKeyWindow;
75 
76  CPWindow _currentMainWindow;
77  CPWindow _previousMainWindow;
78 #endif
79 }
80 
82 {
83  return [CPSet set];
84 }
85 
87 {
88 #if PLATFORM(DOM)
90 #else
91  return NO;
92 #endif
93 }
94 
96 {
97  return PrimaryPlatformWindow;
98 }
99 
100 + (void)setPrimaryPlatformWindow:(CPPlatformWindow)aPlatformWindow
101 {
102  PrimaryPlatformWindow = aPlatformWindow;
103 }
104 
105 - (id)initWithContentRect:(CGRect)aRect
106 {
107  self = [super init];
108 
109  if (self)
110  {
111  _contentRect = CGRectMakeCopy(aRect);
112 
113 #if PLATFORM(DOM)
114  _windowLevels = [];
115  _windowLayers = @{};
116 
117  _charCodes = {};
118 
119  _platformPasteboard = [CPPlatformPasteboard new];
120 #endif
121  }
122 
123  return self;
124 }
125 
126 - (id)initWithWindow:(CPWindow)aWindow
127 {
128  self = [self initWithContentRect:CGRectMakeCopy([aWindow frame])];
129 
130  _hasInitializeInstanceWithWindow = YES;
131  [aWindow setPlatformWindow:self];
132  [aWindow setFullPlatformWindow:YES];
133 
134  return self;
135 }
136 
137 - (id)init
138 {
139  return [self initWithContentRect:CGRectMake(0.0, 0.0, 400.0, 500.0)];
140 }
141 
142 - (CGRect)contentRect
143 {
144  return CGRectMakeCopy(_contentRect);
145 }
146 
147 - (CGRect)contentBounds
148 {
149  var contentBounds = [self contentRect];
150 
151  contentBounds.origin = CGPointMakeZero();
152 
153  return contentBounds;
154 }
155 
156 - (CGRect)visibleFrame
157 {
158  var frame = [self contentBounds];
159 
160  frame.origin = CGPointMakeZero();
161 
162  if ([CPMenu menuBarVisible] && [CPPlatformWindow primaryPlatformWindow] === self)
163  {
164  var menuBarHeight = [[CPApp mainMenu] menuBarHeight];
165 
166  frame.origin.y += menuBarHeight;
167  frame.size.height -= menuBarHeight;
168  }
169 
170  return frame;
171 }
172 
174 {
175  return [self visibleFrame];
176 }
177 
178 - (void)setContentRect:(CGRect)aRect
179 {
180  if (!aRect || CGRectEqualToRect(_contentRect, aRect))
181  return;
182 
183  _contentRect = CGRectMakeCopy(aRect);
184 
185 #if PLATFORM(DOM)
186  [self updateNativeContentRect];
187 #endif
188 }
189 
191 {
192  [self setContentRect:[self nativeContentRect]];
193 }
194 
195 - (CGPoint)convertBaseToScreen:(CGPoint)aPoint
196 {
197  var contentRect = [self contentRect];
198 
199  return CGPointMake(aPoint.x + CGRectGetMinX(contentRect), aPoint.y + CGRectGetMinY(contentRect));
200 }
201 
202 - (CGPoint)convertScreenToBase:(CGPoint)aPoint
203 {
204  var contentRect = [self contentRect];
205 
206  return CGPointMake(aPoint.x - CGRectGetMinX(contentRect), aPoint.y - CGRectGetMinY(contentRect));
207 }
208 
209 - (BOOL)isVisible
210 {
211 #if PLATFORM(DOM)
212  return _DOMWindow !== NULL && _DOMWindow !== undefined;
213 #else
214  return NO;
215 #endif
216 }
217 
218 - (void)deminiaturize:(id)sender
219 {
220 #if PLATFORM(DOM)
221  if (_DOMWindow && typeof _DOMWindow["cpDeminiaturize"] === "function")
222  _DOMWindow.cpDeminiaturize();
223 #endif
224 }
225 
226 - (void)miniaturize:(id)sender
227 {
228 #if PLATFORM(DOM)
229  if (_DOMWindow && typeof _DOMWindow["cpMiniaturize"] === "function")
230  _DOMWindow.cpMiniaturize();
231 #endif
232 }
233 
234 - (void)moveWindow:(CPWindow)aWindow fromLevel:(int)fromLevel toLevel:(int)toLevel
235 {
236 #if PLATFORM(DOM)
237  if (!aWindow._isVisible)
238  return;
239 
240  var fromLayer = [self layerAtLevel:fromLevel create:NO],
241  toLayer = [self layerAtLevel:toLevel create:YES];
242 
243  [fromLayer removeWindow:aWindow];
244  [toLayer insertWindow:aWindow atIndex:CPNotFound];
245 #endif
246 }
247 
248 - (void)setLevel:(CPInteger)aLevel
249 {
250  _level = aLevel;
251 
252 #if PLATFORM(DOM)
253  if (_DOMWindow && _DOMWindow.cpSetLevel)
254  _DOMWindow.cpSetLevel(aLevel);
255 #endif
256 }
257 
258 - (void)setHasShadow:(BOOL)shouldHaveShadow
259 {
260  _hasShadow = shouldHaveShadow;
261 
262 #if PLATFORM(DOM)
263  if (_DOMWindow && _DOMWindow.cpSetHasShadow)
264  _DOMWindow.cpSetHasShadow(shouldHaveShadow);
265 #endif
266 }
267 
268 - (void)setShadowStyle:(int)aStyle
269 {
270  _shadowStyle = aStyle;
271 
272 #if PLATFORM(DOM)
273  if (_DOMWindow && _DOMWindow.cpSetShadowStyle)
274  _shadowStyle.cpSetShadowStyle(aStyle);
275 #endif
276 }
277 
279 {
280  return [CPPlatform isBrowser];
281 }
282 
283 - (void)_setTitle:(CPString)aTitle window:(CPWindow)aWindow
284 {
285  _title = aTitle;
286 
287 #if PLATFORM(DOM)
288  if (_DOMWindow &&
289  _DOMWindow.document &&
290  ([aWindow isFullPlatformWindow]))
291  {
292  _DOMWindow.document.title = _title;
293  }
294 #endif
295 }
296 
298 {
299  return _title;
300 }
301 
302 - (BOOL)_canUpdateContentRect
303 {
304  // We onyl update the contentRect with the frame of the bridgeless window if we have initialized the platform with the method initWithWindow:
305  return _shouldUpdateContentRect && _hasInitializeInstanceWithWindow;
306 }
307 
308 - (BOOL)_hasInitializeInstanceWithWindow
309 {
310  return _hasInitializeInstanceWithWindow;
311 }
312 
313 - (void)_setShouldUpdateContentRect:(BOOL)aBoolean
314 {
315  _shouldUpdateContentRect = aBoolean;
316 }
317 
318 @end
319 
320 #if PLATFORM(BROWSER)
321 #endif
Definition: CPMenu.h:2
global CPApp typedef DOMWindow var PrimaryPlatformWindow
CGRect frame
id initWithContentRect:(CGRect aRect)
void setPlatformWindow:(CPPlatformWindow aPlatformWindow)
Definition: CPWindow.j:394
void updateFromNativeContentRect()
A mutable key-value pair collection.
Definition: CPDictionary.h:2
CPSet visiblePlatformWindows()
An immutable string (collection of characters).
Definition: CPString.h:2
CPInternetExplorerBrowserEngine
void setContentRect:(CGRect aRect)
CGRect frame()
Definition: CPWindow.j:664
id init()
Definition: CPObject.j:145
void setFullPlatformWindow:(BOOL shouldBeFullPlatformWindow)
Definition: CPWindow.j:561
function CPBrowserIsEngine(anEngine)
BOOL supportsFullPlatformWindows()
BOOL isBrowser()
Definition: CPPlatform.j:33
BOOL supportsMultipleInstances()
CPPlatformWindow primaryPlatformWindow()