API  0.9.10
CPFlashView.j
Go to the documentation of this file.
1 /*
2  * CPFlashView.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2008, 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 var IEFlashCLSID = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
26 
30 @implementation CPFlashView : CPView
31 {
32  CPFlashMovie _flashMovie;
33 
34  CPDictionary _params;
35  CPDictionary _paramElements;
36 #if PLATFORM(DOM)
37  DOMElement _DOMParamElement;
38  DOMElement _DOMObjectElement;
39 #endif
40 }
41 
42 - (id)initWithFrame:(CGRect)aFrame
43 {
44  self = [super initWithFrame:aFrame];
45 
46  if (self)
47  {
48 #if PLATFORM(DOM)
50  {
51  _DOMObjectElement = document.createElement(@"object");
52  _DOMObjectElement.id = [self elementID];
53  _DOMObjectElement.width = @"100%";
54  _DOMObjectElement.height = @"100%";
55  _DOMObjectElement.style.top = @"0px";
56  _DOMObjectElement.style.left = @"0px";
57  _DOMObjectElement.type = @"application/x-shockwave-flash";
58  _DOMParamElement = document.createElement(@"param");
59  _DOMParamElement.name = @"movie";
60 
61  _DOMObjectElement.appendChild(_DOMParamElement);
62 
63  _DOMElement.appendChild(_DOMObjectElement);
64  }
65  else
66  [self _rebuildIEObjects];
67 #endif
68  }
69 
70  return self;
71 }
72 
73 - (void)setFlashMovie:(CPFlashMovie)aFlashMovie
74 {
75  if (_flashMovie == aFlashMovie)
76  return;
77 
78  _flashMovie = aFlashMovie;
79 #if PLATFORM(DOM)
81  {
82  _DOMParamElement.value = [aFlashMovie filename];
83  _DOMObjectElement.data = [aFlashMovie filename];
84  }
85  else
86  [self _rebuildIEObjects];
87 #endif
88 }
89 
91 {
92  return _flashMovie;
93 }
94 
95 - (void)setFlashVars:(CPDictionary)aDictionary
96 {
97  var varString = @"",
98  enumerator = [aDictionary keyEnumerator],
99  key;
100 
101  if (key = [enumerator nextObject])
102  varString = [varString stringByAppendingFormat:@"%@=%@", key, [aDictionary objectForKey:key]];
103 
104  while (key = [enumerator nextObject])
105  varString = [varString stringByAppendingFormat:@"&%@=%@", key, [aDictionary objectForKey:key]];
106 
107  if (!_params)
108  _params = @{};
109 
110  [_params setObject:varString forKey:@"flashvars"];
111  [self setParameters:_params];
112 }
113 
115 {
116  return [_params objectForKey:@"flashvars"];
117 }
118 
119 - (void)setParameters:(CPDictionary)aDictionary
120 {
121 #if PLATFORM(DOM)
122  if (_paramElements && !CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
123  {
124  var elements = [_paramElements allValues],
125  count = [elements count];
126 
127  for (var i = 0; i < count; i++)
128  _DOMObjectElement.removeChild([elements objectAtIndex:i]);
129  }
130 #endif
131  if (!_params)
132  _params = aDictionary;
133  else
134  [_params addEntriesFromDictionary:aDictionary];
135 #if PLATFORM(DOM)
137  {
138  _paramElements = @{};
139 
140  var enumerator = [_params keyEnumerator],
141  key;
142 
143  while (_DOMObjectElement && (key = [enumerator nextObject]) !== nil)
144  {
145  var param = document.createElement(@"param");
146  param.name = key;
147  param.value = [_params objectForKey:key];
148 
149  _DOMObjectElement.appendChild(param);
150 
151  [_paramElements setObject:param forKey:key];
152  }
153  }
154  else
155  [self _rebuildIEObjects];
156 #endif
157 }
158 
160 {
161  return _params;
162 }
163 
164 #if PLATFORM(DOM)
165 - (void)_rebuildIEObjects
166 {
167  _DOMElement.innerHTML = @"";
168  if (![_flashMovie filename])
169  return;
170 
171  var paramString = [CPString stringWithFormat:@"<param name='movie' value='%@' />", [_flashMovie filename]],
172  paramEnumerator = [_params keyEnumerator],
173  key;
174 
175  while ((key = [paramEnumerator nextObject]) !== nil)
176  paramString = [paramString stringByAppendingFormat:@"<param name='%@' value='%@' />", key, [_params objectForKey:key]];
177 
178  _DOMObjectElement = document.createElement(@"object");
179  _DOMElement.appendChild(_DOMObjectElement);
180 
181  _DOMObjectElement.outerHTML = [CPString stringWithFormat:@"<object id=%@ classid=%@ width=%@ height=%@>%@</object>", [self elementID], IEFlashCLSID, CGRectGetWidth([self bounds]), CGRectGetHeight([self bounds]), paramString];
182 }
183 #endif
184 
186 {
187  return @"CPFV_" + [self UID];
188 }
189 
190 - (void)mouseMoved:(CPEvent)sommit
191 {
192  [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
193 }
194 
195 - (void)mouseDragged:(CPEvent)anEvent
196 {
197  [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
198 }
199 
200 - (void)mouseDown:(CPEvent)anEvent
201 {
202  [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
203 }
204 
205 - (void)mouseUp:(CPEvent)anEvent
206 {
207  [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
208 }
209 
210 @end
id initWithFrame:(CGRect aFrame)
Definition: CPView.j:334
var IEFlashCLSID
Definition: CPFlashView.j:25
CPEnumerator keyEnumerator()
Definition: CPDictionary.j:429
CGRect bounds()
Definition: CPView.j:1302
A mutable key-value pair collection.
Definition: CPDictionary.h:2
CPWindow window()
Definition: CPView.j:503
CPString filename()
Definition: CPFlashMovie.j:60
An immutable string (collection of characters).
Definition: CPString.h:2
id objectForKey:(id aKey)
Definition: CPDictionary.j:515
CPInternetExplorerBrowserEngine
CPFlashMovie flashMovie()
Definition: CPFlashView.j:90
void setParameters:(CPDictionary aDictionary)
Definition: CPFlashView.j:119
CPString elementID()
Definition: CPFlashView.j:185
CPDictionary flashVars()
Definition: CPFlashView.j:114
Definition: CPEvent.h:2
function CPBrowserIsEngine(anEngine)
CPPlatformWindow platformWindow()
Definition: CPWindow.j:384
CPDictionary parameters()
Definition: CPFlashView.j:159
Definition: CPView.j:136
id stringWithFormat:(CPString format, [,] ...)
Definition: CPString.j:166