API  0.9.7
 All Classes Files Functions Variables Macros Groups Pages
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 @class CPMenu
25 @class CPPlatformPasteboard
26 
27 @global CPApp
28 
29 var PrimaryPlatformWindow = NULL;
30 
31 @implementation CPPlatformWindow : CPObject
32 {
33  CGRect _contentRect;
34 
35  CPInteger _level;
36  BOOL _hasShadow;
37  unsigned _shadowStyle;
38  CPString _title;
39 
40 #if PLATFORM(DOM)
41  DOMWindow _DOMWindow;
42 
43  DOMElement _DOMBodyElement;
44  DOMElement _DOMFocusElement;
45  DOMElement _DOMEventGuard;
46  DOMElement _DOMScrollingElement;
47  id _hideDOMScrollingElementTimeout;
48 
49  CPArray _windowLevels;
50  CPDictionary _windowLayers;
51 
52  BOOL _mouseIsDown;
53  BOOL _mouseDownIsRightClick;
54  CGPoint _lastMouseEventLocation;
55  CPWindow _mouseDownWindow;
56  CPTimeInterval _lastMouseUp;
57  CPTimeInterval _lastMouseDown;
58 
59  Object _charCodes;
60  unsigned _keyCode;
61  unsigned _lastKey;
62  BOOL _capsLockActive;
63 
64  BOOL _DOMEventMode;
65 
66  CPPlatformPasteboard _platformPasteboard;
67 
68  CPString _overriddenEventType;
69 #endif
70 }
71 
72 + (CPSet)visiblePlatformWindows
73 {
74  return [CPSet set];
75 }
76 
77 + (BOOL)supportsMultipleInstances
78 {
79 #if PLATFORM(DOM)
81 #else
82  return NO;
83 #endif
84 }
85 
86 + (CPPlatformWindow)primaryPlatformWindow
87 {
88  return PrimaryPlatformWindow;
89 }
90 
91 + (void)setPrimaryPlatformWindow:(CPPlatformWindow)aPlatformWindow
92 {
93  PrimaryPlatformWindow = aPlatformWindow;
94 }
95 
96 - (id)initWithContentRect:(CGRect)aRect
97 {
98  self = [super init];
99 
100  if (self)
101  {
102  _contentRect = CGRectMakeCopy(aRect);
103 
104 #if PLATFORM(DOM)
105  _windowLevels = [];
106  _windowLayers = @{};
107 
108  _charCodes = {};
109 #endif
110  }
111 
112  return self;
113 }
114 
115 - (id)init
116 {
117  return [self initWithContentRect:CGRectMake(0.0, 0.0, 400.0, 500.0)];
118 }
119 
120 - (CGRect)contentRect
121 {
122  return CGRectMakeCopy(_contentRect);
123 }
124 
125 - (CGRect)contentBounds
126 {
127  var contentBounds = [self contentRect];
128 
129  contentBounds.origin = CGPointMakeZero();
130 
131  return contentBounds;
132 }
133 
134 - (CGRect)visibleFrame
135 {
136  var frame = [self contentBounds];
137 
138  frame.origin = CGPointMakeZero();
139 
140  if ([CPMenu menuBarVisible] && [CPPlatformWindow primaryPlatformWindow] === self)
141  {
142  var menuBarHeight = [[CPApp mainMenu] menuBarHeight];
143 
144  frame.origin.y += menuBarHeight;
145  frame.size.height -= menuBarHeight;
146  }
147 
148  return frame;
149 }
150 
151 - (CGRect)usableContentFrame
152 {
153  return [self visibleFrame];
154 }
155 
156 - (void)setContentRect:(CGRect)aRect
157 {
158  if (!aRect || CGRectEqualToRect(_contentRect, aRect))
159  return;
160 
161  _contentRect = CGRectMakeCopy(aRect);
162 
163 #if PLATFORM(DOM)
164  [self updateNativeContentRect];
165 #endif
166 }
167 
168 - (void)updateFromNativeContentRect
169 {
170  [self setContentRect:[self nativeContentRect]];
171 }
172 
173 - (CGPoint)convertBaseToScreen:(CGPoint)aPoint
174 {
175  var contentRect = [self contentRect];
176 
177  return CGPointMake(aPoint.x + CGRectGetMinX(contentRect), aPoint.y + CGRectGetMinY(contentRect));
178 }
179 
180 - (CGPoint)convertScreenToBase:(CGPoint)aPoint
181 {
182  var contentRect = [self contentRect];
183 
184  return CGPointMake(aPoint.x - CGRectGetMinX(contentRect), aPoint.y - CGRectGetMinY(contentRect));
185 }
186 
187 - (BOOL)isVisible
188 {
189 #if PLATFORM(DOM)
190  return _DOMWindow !== NULL;
191 #else
192  return NO;
193 #endif
194 }
195 
196 - (void)deminiaturize:(id)sender
197 {
198 #if PLATFORM(DOM)
199  if (_DOMWindow && typeof _DOMWindow["cpDeminiaturize"] === "function")
200  _DOMWindow.cpDeminiaturize();
201 #endif
202 }
203 
204 - (void)miniaturize:(id)sender
205 {
206 #if PLATFORM(DOM)
207  if (_DOMWindow && typeof _DOMWindow["cpMiniaturize"] === "function")
208  _DOMWindow.cpMiniaturize();
209 #endif
210 }
211 
212 - (void)moveWindow:(CPWindow)aWindow fromLevel:(int)fromLevel toLevel:(int)toLevel
213 {
214 #if PLATFORM(DOM)
215  if (!aWindow._isVisible)
216  return;
217 
218  var fromLayer = [self layerAtLevel:fromLevel create:NO],
219  toLayer = [self layerAtLevel:toLevel create:YES];
220 
221  [fromLayer removeWindow:aWindow];
222  [toLayer insertWindow:aWindow atIndex:CPNotFound];
223 #endif
224 }
225 
226 - (void)setLevel:(CPInteger)aLevel
227 {
228  _level = aLevel;
229 
230 #if PLATFORM(DOM)
231  if (_DOMWindow && _DOMWindow.cpSetLevel)
232  _DOMWindow.cpSetLevel(aLevel);
233 #endif
234 }
235 
236 - (void)setHasShadow:(BOOL)shouldHaveShadow
237 {
238  _hasShadow = shouldHaveShadow;
239 
240 #if PLATFORM(DOM)
241  if (_DOMWindow && _DOMWindow.cpSetHasShadow)
242  _DOMWindow.cpSetHasShadow(shouldHaveShadow);
243 #endif
244 }
245 
246 - (void)setShadowStyle:(int)aStyle
247 {
248  _shadowStyle = aStyle;
249 
250 #if PLATFORM(DOM)
251  if (_DOMWindow && _DOMWindow.cpSetShadowStyle)
252  _shadowStyle.cpSetShadowStyle(aStyle);
253 #endif
254 }
255 
256 - (BOOL)supportsFullPlatformWindows
257 {
258  return [CPPlatform isBrowser];
259 }
260 
261 - (void)_setTitle:(CPString)aTitle window:(CPWindow)aWindow
262 {
263  _title = aTitle;
264 
265 #if PLATFORM(DOM)
266  if (_DOMWindow &&
267  _DOMWindow.document &&
268  ([aWindow isFullPlatformWindow]))
269  {
270  _DOMWindow.document.title = _title;
271  }
272 #endif
273 }
274 
275 - (CPString)title
276 {
277  return _title;
278 }
279 
280 @end
281 
282 #if PLATFORM(BROWSER)
283 #endif