API 0.9.5
AppKit/CPFlashView.j
Go to the documentation of this file.
00001 /*
00002  * CPFlashView.j
00003  * AppKit
00004  *
00005  * Created by Francisco Tolmasky.
00006  * Copyright 2008, 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 IEFlashCLSID = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
00026 
00030 @implementation CPFlashView : CPView
00031 {
00032     CPFlashMovie    _flashMovie;
00033 
00034     CPDictionary    _params;
00035     CPDictionary    _paramElements;
00036 #if PLATFORM(DOM)
00037     DOMElement      _DOMParamElement;
00038     DOMElement      _DOMObjectElement;
00039     DOMElement      _DOMInnerObjectElement;
00040 #endif
00041 }
00042 
00043 - (id)initWithFrame:(CGRect)aFrame
00044 {
00045     self = [super initWithFrame:aFrame];
00046 
00047     if (self)
00048     {
00049 #if PLATFORM(DOM)
00050         if (!CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00051         {
00052             _DOMObjectElement = document.createElement(@"object");
00053             _DOMObjectElement.width = @"100%";
00054             _DOMObjectElement.height = @"100%";
00055             _DOMObjectElement.style.top = @"0px";
00056             _DOMObjectElement.style.left = @"0px";
00057             _DOMObjectElement.type = @"application/x-shockwave-flash";
00058             _DOMObjectElement.setAttribute(@"classid", IEFlashCLSID);
00059 
00060             _DOMParamElement = document.createElement(@"param");
00061             _DOMParamElement.name = @"movie";
00062 
00063             _DOMInnerObjectElement = document.createElement(@"object");
00064             _DOMInnerObjectElement.width = @"100%";
00065             _DOMInnerObjectElement.height = @"100%";
00066 
00067             _DOMObjectElement.appendChild(_DOMParamElement);
00068             _DOMObjectElement.appendChild(_DOMInnerObjectElement);
00069 
00070             _DOMElement.appendChild(_DOMObjectElement);
00071         }
00072         else
00073             [self _rebuildIEObjects];
00074 #endif
00075     }
00076 
00077     return self;
00078 }
00079 
00080 - (void)setFlashMovie:(CPFlashMovie)aFlashMovie
00081 {
00082     if (_flashMovie == aFlashMovie)
00083         return;
00084 
00085     _flashMovie = aFlashMovie;
00086 #if PLATFORM(DOM)
00087     if (!CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00088     {
00089         _DOMParamElement.value = [aFlashMovie filename];
00090         _DOMInnerObjectElement.data = [aFlashMovie filename];
00091     }
00092     else
00093         [self _rebuildIEObjects];
00094 #endif
00095 }
00096 
00097 - (CPFlashMovie)flashMovie
00098 {
00099     return _flashMovie;
00100 }
00101 
00102 - (void)setFlashVars:(CPDictionary)aDictionary
00103 {
00104     var varString = @"",
00105         enumerator = [aDictionary keyEnumerator];
00106 
00107     var key;
00108     while (key = [enumerator nextObject])
00109         varString = [varString stringByAppendingFormat:@"&%@=%@", key, [aDictionary objectForKey:key]];
00110 
00111     if (!_params)
00112         _params = [CPDictionary dictionary];
00113 
00114     [_params setObject:varString forKey:@"flashvars"];
00115     [self setParameters:_params];
00116 }
00117 
00118 - (CPDictionary)flashVars
00119 {
00120     return [_params objectForKey:@"flashvars"];
00121 }
00122 
00123 - (void)setParameters:(CPDictionary)aDictionary
00124 {
00125 #if PLATFORM(DOM)
00126     if (_paramElements && !CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00127     {
00128         var elements = [_paramElements allValues],
00129             count = [elements count];
00130 
00131         for (var i = 0; i < count; i++)
00132             _DOMObjectElement.removeChild([elements objectAtIndex:i]);
00133     }
00134 #endif
00135     if (!_params)
00136         _params = aDictionary;
00137     else
00138         [_params addEntriesFromDictionary:aDictionary];
00139 #if PLATFORM(DOM)
00140     if (!CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00141     {
00142         _paramElements = [CPDictionary dictionary];
00143 
00144         var enumerator = [_params keyEnumerator],
00145             key;
00146 
00147         while (_DOMObjectElement && (key = [enumerator nextObject]))
00148         {
00149             var param = document.createElement(@"param");
00150             param.name = key;
00151             param.value = [_params objectForKey:key];
00152 
00153             _DOMObjectElement.appendChild(param);
00154 
00155             [_paramElements setObject:param forKey:key];
00156         }
00157     }
00158     else
00159         [self _rebuildIEObjects];
00160 #endif
00161 }
00162 
00163 - (CPDictionary)parameters
00164 {
00165     return _params;
00166 }
00167 
00168 #if PLATFORM(DOM)
00169 - (void)_rebuildIEObjects
00170 {
00171     _DOMElement.innerHTML = @"";
00172     if (![_flashMovie filename])
00173         return;
00174 
00175     var paramString = [CPString stringWithFormat:@"<param name='movie' value='%@' />", [_flashMovie filename]],
00176         paramEnumerator = [_params keyEnumerator],
00177         key;
00178 
00179     while (key = [paramEnumerator nextObject])
00180         paramString = [paramString stringByAppendingFormat:@"<param name='%@' value='%@' />", key, [_params objectForKey:key]];
00181 
00182     _DOMObjectElement = document.createElement(@"object");
00183     _DOMElement.appendChild(_DOMObjectElement);
00184 
00185     _DOMObjectElement.outerHTML = [CPString stringWithFormat:@"<object classid=%@ width=%@ height=%@>%@</object>", IEFlashCLSID, CGRectGetWidth([self bounds]), CGRectGetHeight([self bounds]), paramString];
00186 }
00187 #endif
00188 
00189 - (void)mouseDragged:(CPEvent)anEvent
00190 {
00191     [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
00192 }
00193 
00194 - (void)mouseDown:(CPEvent)anEvent
00195 {
00196     [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
00197 }
00198 
00199 - (void)mouseUp:(CPEvent)anEvent
00200 {
00201     [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
00202 }
00203 
00204 @end
 All Classes Files Functions Variables Defines