API  1.0.0
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 
45  CPLog.warn("CPFlashView is deprecated and it will be removed in version 1.1.");
46 
47  self = [super initWithFrame:aFrame];
48 
49  if (self)
50  {
51 #if PLATFORM(DOM)
53  {
54  _DOMObjectElement = document.createElement(@"object");
55  _DOMObjectElement.id = [self elementID];
56  _DOMObjectElement.width = @"100%";
57  _DOMObjectElement.height = @"100%";
58  _DOMObjectElement.style.top = @"0px";
59  _DOMObjectElement.style.left = @"0px";
60  _DOMObjectElement.type = @"application/x-shockwave-flash";
61  _DOMParamElement = document.createElement(@"param");
62  _DOMParamElement.name = @"movie";
63 
64  _DOMObjectElement.appendChild(_DOMParamElement);
65 
66  _DOMElement.appendChild(_DOMObjectElement);
67  }
68  else
69  [self _rebuildIEObjects];
70 #endif
71  }
72 
73  return self;
74 }
75 
76 - (void)setFlashMovie:(CPFlashMovie)aFlashMovie
77 {
78  if (_flashMovie == aFlashMovie)
79  return;
80 
81  _flashMovie = aFlashMovie;
82 #if PLATFORM(DOM)
84  {
85  _DOMParamElement.value = [aFlashMovie filename];
86  _DOMObjectElement.data = [aFlashMovie filename];
87  }
88  else
89  [self _rebuildIEObjects];
90 #endif
91 }
92 
93 - (CPFlashMovie)flashMovie
94 {
95  return _flashMovie;
96 }
97 
98 - (void)setFlashVars:(CPDictionary)aDictionary
99 {
100  var varString = @"",
101  enumerator = [aDictionary keyEnumerator],
102  key;
103 
104  if (key = [enumerator nextObject])
105  varString = [varString stringByAppendingFormat:@"%@=%@", key, [aDictionary objectForKey:key]];
106 
107  while (key = [enumerator nextObject])
108  varString = [varString stringByAppendingFormat:@"&%@=%@", key, [aDictionary objectForKey:key]];
109 
110  if (!_params)
111  _params = @{};
112 
113  [_params setObject:varString forKey:@"flashvars"];
114  [self setParameters:_params];
115 }
116 
117 - (CPDictionary)flashVars
118 {
119  return [_params objectForKey:@"flashvars"];
120 }
121 
122 - (void)setParameters:(CPDictionary)aDictionary
123 {
124 #if PLATFORM(DOM)
125  if (_paramElements && !CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
126  {
127  var elements = [_paramElements allValues],
128  count = [elements count];
129 
130  for (var i = 0; i < count; i++)
131  _DOMObjectElement.removeChild([elements objectAtIndex:i]);
132  }
133 #endif
134  if (!_params)
135  _params = aDictionary;
136  else
137  [_params addEntriesFromDictionary:aDictionary];
138 #if PLATFORM(DOM)
140  {
141  _paramElements = @{};
142 
143  var enumerator = [_params keyEnumerator],
144  key;
145 
146  while (_DOMObjectElement && (key = [enumerator nextObject]) !== nil)
147  {
148  var param = document.createElement(@"param");
149  param.name = key;
150  param.value = [_params objectForKey:key];
151 
152  _DOMObjectElement.appendChild(param);
153 
154  [_paramElements setObject:param forKey:key];
155  }
156  }
157  else
158  [self _rebuildIEObjects];
159 #endif
160 }
161 
162 - (CPDictionary)parameters
163 {
164  return _params;
165 }
166 
167 #if PLATFORM(DOM)
168 - (void)_rebuildIEObjects
169 {
170  _DOMElement.innerHTML = @"";
171  if (![_flashMovie filename])
172  return;
173 
174  var paramString = [CPString stringWithFormat:@"<param name='movie' value='%@' />", [_flashMovie filename]],
175  paramEnumerator = [_params keyEnumerator],
176  key;
177 
178  while ((key = [paramEnumerator nextObject]) !== nil)
179  paramString = [paramString stringByAppendingFormat:@"<param name='%@' value='%@' />", key, [_params objectForKey:key]];
180 
181  _DOMObjectElement = document.createElement(@"object");
182  _DOMElement.appendChild(_DOMObjectElement);
183 
184  _DOMObjectElement.outerHTML = [CPString stringWithFormat:@"<object id=%@ classid=%@ width=%@ height=%@>%@</object>", [self elementID], IEFlashCLSID, CGRectGetWidth([self bounds]), CGRectGetHeight([self bounds]), paramString];
185 }
186 #endif
187 
188 - (CPString)elementID
189 {
190  return @"CPFV_" + [self UID];
191 }
192 
193 - (void)mouseMoved:(CPEvent)sommit
194 {
195  [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
196 }
197 
198 - (void)mouseDragged:(CPEvent)anEvent
199 {
200  [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
201 }
202 
203 - (void)mouseDown:(CPEvent)anEvent
204 {
205  [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
206 }
207 
208 - (void)mouseUp:(CPEvent)anEvent
209 {
210  [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
211 }
212 
213 @end
id initWithFrame:(CGRect aFrame)
Definition: CPView.j:351
var IEFlashCLSID
Definition: CPFlashView.j:25
CPEnumerator keyEnumerator()
Definition: CPDictionary.j:429
A mutable key-value pair collection.
Definition: CPDictionary.h:2
CPWindow window()
Definition: CPView.j:527
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
void setParameters:(CPDictionary aDictionary)
Definition: CPFlashView.j:122
CPString elementID()
Definition: CPFlashView.j:188
Definition: CPEvent.h:2
function CPBrowserIsEngine(anEngine)
CPPlatformWindow platformWindow()
Definition: CPWindow.j:389
Definition: CPView.j:137
id stringWithFormat:(CPString format, [,] ...)
Definition: CPString.j:166