Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 5229|回复: 6

lazarus在linux如何添加flash控件

[复制链接]

该用户从未签到

发表于 2010-7-19 15:18:57 | 显示全部楼层 |阅读模式
如题,近日想编写linux下的程序,需要flash控件
回复

使用道具 举报

该用户从未签到

发表于 2010-7-19 23:14:43 | 显示全部楼层
I know that with Macromedia Flash 8 you could create kinda .exe files, so possibily its posible still now, maybe you can add it as a resource and load it depending on the request, but don't know other solutions
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2010-7-19 23:17:59 | 显示全部楼层
if you windows-only, you 可以试试 f-in-box component
这个好像是商业版本的,不过他现在的dll版本好像已经免费了
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2010-7-19 23:21:02 | 显示全部楼层
But IMHO, the most convenient and crossplatform way to embed Flash into application written in Pascal is to write a web application. If you want to deploy to the desktop you can use embedded web server (that can be based e.g. on Ararat Synapse examples) and something like Mozilla Prism as a frontend

如果你是在浏览器上运行,可以试一下下面的demo:
  1. program dgtkflasher;
  2. {$mode delphi}{$H+}
  3. uses
  4.   cthreads,
  5.   Classes, SysUtils, libc, gtk2, gdk2, glib2, math,
  6.   MozillaPluginAPI, gdk2x, x;
  7. var
  8.   window, button, vbox, socket, fixed: pGtkWidget;
  9.   plugin_funcs: TNPPluginFuncs;
  10.   mozilla_funcs: TNPNetscapeFuncs;
  11.   gNP_GetMIMEDescription: TNPP_GetMIMEDescription;
  12.   //gNP_Initialize: TNPP_Initialize;
  13.   gNP_Initialize: TNP_InitializeProc;
  14.   gNP_Shutdown: TNPP_Shutdown;
  15.   gNP_GetValue: TNPP_GetValue;
  16.   plugin: TNPP;
  17. type
  18.   { TPCharArgs }
  19.   TArrayPtr = array[0..16383] of PChar;
  20.   PArrayPtr = ^TArrayPtr;
  21.   TPCharArgs = class
  22.   private
  23.     FCount: Integer;
  24.     FData: PArrayPtr;
  25.   public
  26.     constructor Create;
  27.     destructor Destroy;
  28.     procedure Add(AValue: string);
  29.     property Data: PArrayPtr read FData;
  30.     property Count: Integer read FCount;
  31.   end;
  32. { TPCharArgs }
  33. constructor TPCharArgs.Create;
  34. begin
  35.   inherited;
  36.   GetMem(FData, SizeOf(PChar) * 50);
  37.   FCount := 0;
  38.   FillChar(FData^, SizeOf(PChar) * 50, 0);
  39. end;
  40. destructor TPCharArgs.Destroy;
  41. var
  42.   I: Integer;
  43. begin
  44.   for I := 0 to FCount-1 do
  45.      Dispose(FData^[I]);
  46.   inherited;
  47. end;
  48. procedure TPCharArgs.Add(AValue: string);
  49. begin
  50.      GetMem(FData^[FCount], Length(AValue)+1);
  51.      StrPLCopy(FData^[FCount], AValue, Length(AValue));
  52.      Inc(FCount);
  53. end;
  54. procedure Debug(msg: string; fmt: array of const);
  55. begin
  56.      WriteLn(Format(msg, fmt));
  57. end;
  58. {/*==========================================================================*\\
  59. * Browser-side functions...
  60. \\*==========================================================================*/}
  61. //* Closes and deletes a stream */
  62. function NPN_DestroyStream(instance: PNPP; stream: PNPStream; reason: TNPError): TNPError; cdecl;
  63. begin
  64.      Debug('NPN_DestroyStream instance=%p, stream=%p, reason=%d\\n',
  65.          [instance, stream, reason]);
  66.      Result := NPERR_GENERIC_ERROR;
  67. {$IF 0}
  68.     CURLStream *s = stream->ndata;
  69.     if (!s) {
  70.         return NPERR_GENERIC_ERROR;
  71.     }
  72.     CURLStreamDestroy(s, reason);
  73.     return NPERR_NO_ERROR;
  74. {$ENDIF}
  75. end;
  76. ///* Forces a repaint message for a windowless plug-in */
  77. procedure NPN_ForceRedraw(instance: PNPP); cdecl;
  78. begin
  79.      Debug('NPN_ForceRedraw instance=%p\\n', [instance]);
  80.      //NOT_IMPLEMENTED();
  81. end;
  82. ///* Asks the browser to create a stream for the specified URL */
  83. function NPN_GetURL(instance: PNPP; const url: PChar; const target: PChar): TNPError; cdecl;
  84. begin
  85.     Debug('NPN_GetURL instance=%p, url=%s, target=%s\\n',
  86.           [instance, url, target]);
  87.     if (target <> nil) then
  88.         begin
  89.          //NOT_IMPLEMENTED();
  90.          Result := NPERR_INVALID_PARAM;
  91.              Exit;
  92.         end;
  93.         Result := NPERR_GENERIC_ERROR;
  94. {$IF 0}
  95.     CURLStream *s = CURLStreamNew(instance, url, False, NULL);
  96.     return s ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
  97. {$ENDIF}
  98. end;
  99. ///* Requests creation of a new stream for the specified URL */
  100. function NPN_GetURLNotify(instance: PNPP;
  101.          const url: Pchar;
  102.          const target: PChar;
  103.          notifyData: Pointer): TNPError; cdecl;
  104. begin
  105.     Debug('NPN_GetURLNotify instance=%p, url=%s, target=%s\\n',
  106.           [instance, url, target]);
  107.     if (target <> nil) then
  108.         begin
  109.          //NOT_IMPLEMENTED();
  110.          Result := NPERR_INVALID_PARAM;
  111.              Exit;
  112.         end;
  113.         Result := NPERR_GENERIC_ERROR;
  114. {$IF 0}
  115.     CURLStream *s = CURLStreamNew(instance, url, True, notifyData);
  116.     return s ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
  117. {$ENDIF}
  118. end;
  119. ///* Allows the plug-in to query the browser for information */
  120. function NPN_GetValue(instance: PNPP; variable: TNPNVariable; value: Pointer): TNPError; cdecl;
  121. begin
  122.     Debug('NPN_GetValue instance=%p, variable=%d [%08x]\\n',
  123.           [instance, variable and $ffff, variable]);
  124.     case (variable) of
  125.           NPNVSupportsXEmbedBool:
  126.             PNPBool(value)^ := true;
  127.       {NPNVxDisplay:
  128.             Pointer(Pointer(value)^) := x_display;
  129.         //*(void **)value = x_display;
  130.     NPNVxtAppContext:
  131.             Pointer(Pointer(value)^) := XtDisplayToApplicationContext(x_display);}
  132.     NPNVToolkit:
  133.             PNPNToolkitType(value)^ := NPNVGtk2;
  134.         else
  135.           begin
  136.         Debug('Unhandled variable %d for NPN_GetValue\\n',
  137.             [variable]);
  138.         Result := NPERR_INVALID_PARAM;
  139.                 Exit;
  140.           end;
  141.         end;
  142.     Result := NPERR_NO_ERROR;
  143. end;
  144. {/*
  145. * Invalidates specified drawing area prior to repainting or refreshing a
  146. * windowless plug-in
  147. */}
  148. procedure NPN_InvalidateRect(instance: PNPP; invalidRect: PNPRect); cdecl;
  149. begin
  150.     Debug('NPN_InvalidateRect top=%d, left=%d, bottom=%d, right=%d\\n',
  151.           [invalidRect^.top, invalidRect^.left, invalidRect^.bottom,
  152.           invalidRect^.right]);
  153.     //NOT_IMPLEMENTED();
  154. end;
  155. {/*
  156. * Invalidates specified region prior to repainting or refreshing a
  157. * windowless plug-in.
  158. */}
  159. procedure NPN_InvalidateRegion(instance: PNPP; invalidRegion: Pointer {TNPRegion}); cdecl;
  160. {var
  161.   rect: TXRectangle;}
  162. begin
  163.     //XClipBox(invalidRegion, @rect);
  164.     Debug('NPN_InvalidateRegion', []);
  165.     {Debug('NPN_InvalidateRegion x=%d, y=%d, width=%d, height=%d\\n',
  166.           [rect.x, rect.y, rect.width, rect.height]);}
  167.     //NOT_IMPLEMENTED();
  168. end;
  169. //* Allocates memory from the browser's memory space. */
  170. function NPN_MemAlloc(size: LongWord): Pointer; cdecl;
  171. begin
  172.     Debug('NPN_MemAlloc size=%d\\n', [size]);
  173.         Result := GetMem(size);
  174. end;
  175. //* Requests that the browser free a specified amount of memory. */
  176. function NPN_MemFlush(size: LongWord): LongWord; cdecl;
  177. begin
  178.     Debug('NPN_MemFlush size=%d\\n', [size]);
  179.     Result := 0;
  180. end;
  181. ///* Deallocates a block of allocated memory. */
  182. procedure NPN_MemFree(ptr: Pointer); cdecl;
  183. begin
  184.     Debug('NPN_MemFree ptr=%p\\n', [ptr]);
  185.         FreeMem(ptr);
  186. end;
  187. {/*
  188. * Requests the creation of a new data stream produced by the plug-in and
  189. * consumed by the browser.
  190. */}
  191. type PPNPStream = ^PNPStream;
  192. function NPN_NewStream(instance: PNPP;
  193.           _type: TNPMIMEType;
  194.           const target: PChar;
  195.           stream: PPNPStream): TNPError; cdecl;
  196. begin
  197.     Debug('NPN_NewStream instance=%p, type=%s, target=%s\\n',
  198.           [instance, _type, target]);
  199.     //NOT_IMPLEMENTED();
  200.     Result := NPERR_GENERIC_ERROR;
  201. end;
  202. ///* Posts data to a URL. */
  203. function NPN_PostURL(instance: PNPP;
  204.         const url: PChar;
  205.         const target: PChar;
  206.         len: LongWord;
  207.         const buf: PChar;
  208.         _file: TNPBool): TNPError; cdecl;
  209. begin
  210.     Debug('NPN_PostURL instance=%p, url=%s, target=%s, len=%d, file=%d\\n',
  211.              [instance, url, target, len,_file]);
  212.     if (target <> NULL) then
  213.         begin
  214.         //NOT_IMPLEMENTED();
  215.         Result := NPERR_INVALID_PARAM;
  216.                 Exit;
  217.         end;
  218.         Result := NPERR_GENERIC_ERROR;
  219. {$IF 0}
  220.     CURLStream *s = CURLStreamNewPost(instance, url, False, NULL, buf,
  221.                       len, file);
  222.     return s ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
  223. {$ENDIF}
  224. end;
  225. ///* Posts data to a URL, and receives notification of the result. */
  226. function NPN_PostURLNotify(instance: PNPP;
  227.           const url: PChar;
  228.           const target: PChar;
  229.           len: LongWord;
  230.           const buf: PChar;
  231.           _file: TNPBool;
  232.           notifyData: Pointer): TNPError; cdecl;
  233. begin
  234.     Debug('NPN_PostURLNotify instance=%p, url=%s, target=%s, len=%d, file=%d\\n',
  235.             [instance, url, target, len, _file]);
  236.     if (target <> NULL) then
  237.         begin
  238.         //NOT_IMPLEMENTED();
  239.         Result := NPERR_INVALID_PARAM;
  240.                 Exit;
  241.         end;
  242.         Result := NPERR_GENERIC_ERROR;
  243. {$IF 0}
  244.     CURLStream *s = CURLStreamNewPost(instance, url, True, notifyData, buf,
  245.                       len, file);
  246.     return s ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
  247. {$ENDIF}
  248. end;
  249. ///* Supposed to flush all plugins and reload. */
  250. procedure NPN_ReloadPlugins(reloadPages: TNPBool); cdecl;
  251. begin
  252.     Debug('NPN_ReloadPlugins reloadPages=%d\\n', [reloadPages]);
  253.     //NOT_IMPLEMENTED();
  254. end;
  255. ///* Returns the Java execution environment. */
  256. function NPN_GetJavaEnv(): PJRIEnv; cdecl;
  257. begin
  258.     Debug('NPN_GetJavaEnv\\n', []);
  259.     Result := nil;
  260. end;
  261. //* Returns the Java object associated with the plug-in instance. */
  262. function NPN_GetJavaPeer(instance: PNPP): Tjref; cdecl;
  263. begin
  264.     Debug('NPN_GetJavaPeer instance=%p\\n', [instance]);
  265.     Result := nil;
  266. end;
  267. ///* Requests a range of bytes for a seekable stream. */
  268. function NPN_RequestRead(stream: PNPStream; rangeList: PNPByteRange): TNPError; cdecl;
  269. begin
  270.     Debug('NPN_RequestRead stream=%p\\n', [stream]);
  271.     //NOT_IMPLEMENTED();
  272.     Result := NPERR_GENERIC_ERROR;
  273. end;
  274. //* Sets various modes of plug-in operation. */
  275. function NPN_SetValue(instance: PNPP; variable: TNPPVariable; value: Pointer): TNPError; cdecl;
  276. begin
  277.     Debug('NPN_SetValue instance=%p, variable=%d\\n', [instance, variable]);
  278.     //NOT_IMPLEMENTED();
  279.     Result := NPERR_GENERIC_ERROR;
  280. end;
  281. //* Displays a message on the status line of the browser window. */
  282. procedure NPN_Status(instance: PNPP; const message: PChar); cdecl;
  283. begin
  284.     Debug('NPN_Status instance=%p, message=%s\\n', [instance, message]);
  285.     //NOT_IMPLEMENTED();
  286. end;
  287. ///* Returns the browser's user agent field. */
  288. function NPN_UserAgent(instance: PNPP): PChar; cdecl;
  289. begin
  290.     Result := 'Mozilla/5.0 (X11; U; Linux i686; en-US) Flasher/0.2';
  291. end;
  292. {/*
  293. * Pushes data into a stream produced by the plug-in and consumed by the
  294. * browser.
  295. */}
  296. function NPN_Write(instance: PNPP; stream: PNPStream; len: LongWord; buf: Pointer): LongWord; cdecl;
  297. begin
  298.     Debug('NPN_Write instance=%p, stream=%p, len=%d\\n',
  299.           [instance, stream, len]);
  300.     //NOT_IMPLEMENTED();
  301.     Result := -1;
  302. end;
  303. {/*==========================================================================*\\
  304. * Plugin instance creation, window creation, file reading...
  305. \\*==========================================================================*/}
  306. ///* Create a new plugin instance, passing some very basic arguments */
  307. function CallNew(plugin: PNPP; swf_file: string; width, height: Integer): TNPError;
  308. var
  309.   width_s, height_s: string;
  310.   //args, values: array[0..4] of string;
  311.   args, values: TPCharArgs;
  312.   
  313.   xembed: TNPBool;
  314.   err: TNPError;
  315. begin
  316.     ///* FIXME: Store window state. */
  317.     plugin.ndata := nil;
  318.         width_s := IntToStr(width);
  319.         height_s := IntToStr(height);
  320.         args := TPCharArgs.Create;
  321.         values := TPCharArgs.Create;
  322.         args.Add('SRC');
  323.         args.Add('WIDTH');
  324.         args.Add('HEIGHT');
  325.         args.Add('MENU');
  326.         args.Add('LOOP');
  327.         values.Add(swf_file);
  328.         values.Add(width_s);
  329.         values.Add(height_s);
  330.         values.Add('FALSE');
  331.         values.Add('TRUE');
  332.         //SetLength(args, 5);
  333.         //SetLength(values, 5);
  334.         {args[0] := 'SRC';
  335.         args[1] := 'WIDTH';
  336.         args[2] := 'HEIGHT';
  337.         args[3] := 'MENU';
  338.         args[4] := 'LOOP';
  339.         values[0] := swf_file;
  340.         values[1] := width_s;
  341.         values[2] := height_s;
  342.         values[3] := 'FALSE';
  343.         values[4] := 'TRUE';}
  344.         Result := plugin_funcs.New('application/x-shockwave-flash', plugin,
  345.            Word(NP_EMBED), args.Count, PArrayPchar(args.Data), PArrayPchar(values.Data), nil);
  346.         args.Free;
  347.         values.Free;
  348.         
  349.         {xembed := true;
  350.         err := plugin_funcs.GetValue(plugin, NPPVpluginNeedsXEmbed, @xembed);
  351.         if err <> NPERR_NO_ERROR then
  352.            writeln('ouch');}
  353. end;
  354. //* Create a new Xt window and pass it to the plugin. */
  355. function CallSetWindow(plugin: PNPP; width, height: Integer): TNPError;
  356. var
  357.   ws_info: TNPSetWindowCallbackStruct;
  358.   win: TNPWindow;
  359.   
  360.   draw: PGdkDrawable;
  361.   window: TWindow;
  362.   
  363.   {screen: Integer;
  364.   attr: TXSetWindowAttributes;
  365.   mask: LongWord;
  366.   x_root_win: TWindow;
  367.   x_win: TWindow;
  368.   top_widget: PWidget;
  369.   args: array[0..6] of TArg;
  370.   n: Integer;
  371.   form: PWidget;}
  372. begin
  373.      draw := PGdkDrawable(socket^.window);
  374.      //draw := PGdkDrawable(fixed^.window);
  375.      //draw := gtk_widget_get_parent_window(socket);
  376.      window := GDK_WINDOW_XWINDOW(draw);
  377.      FillChar(ws_info, sizeof(ws_info), 0);
  378.      FillChar(win, sizeof(win), 0);
  379.      ws_info._type := NP_SETWINDOW;
  380.      ws_info.display := GDK_DRAWABLE_XDISPLAY (draw);
  381.      ws_info.visual := GDK_VISUAL_XVISUAL (gdk_drawable_get_visual(draw));
  382.      ws_info.colormap := GDK_COLORMAP_XCOLORMAP (gdk_drawable_get_colormap(draw));
  383.      ws_info.depth := gdk_drawable_get_depth (draw);
  384.      win._type := NPWindowTypeDrawable;
  385.      win.x := 0;
  386.      win.y := 0;
  387.      win.width := width;
  388.      win.height := height;
  389.      win.ws_info := @ws_info;
  390.      //win.window := gtk_socket_get_id(GTK_SOCKET(socket));
  391.      win.window := window;
  392.      //gtk_widget_realize(window);
  393.      //win.window := GDK_WINDOW_XWINDOW(PGdkDrawable(window^.window));
  394.      plugin_funcs.setwindow(plugin, @win);
  395. end;
  396. function SearchFileSize(AFilename: string): Integer;
  397. var
  398.   S: TSearchRec;
  399. begin
  400.    Result := 0;
  401.    if FindFirst(AFilename, faAnyFile, S) = 0 then
  402.       Result := S.Size;
  403.    FindClose(S);
  404. end;
  405. //* Open, read, and write the contents of swf_file to the plugin instance. */
  406. function SendSrcStream(plugin: PNPP; swf_file: string): TNPError;
  407. var
  408.   err: TNPError;
  409.   stream: TNPStream;
  410.   stype: Word;
  411.   swf_fd: TFileStream;
  412.   write_idx: Integer;
  413.   data: array[0..1024*10] of char;
  414.   write_max, bytes_read, bytes_written: Integer;
  415.   pfn: PChar;
  416.   reason: TNPError;
  417. begin
  418.      err := NPERR_NO_ERROR;
  419.      FillChar(stream, sizeof(stream), 0);
  420.      stype := 0;
  421.      if not FileExists(swf_file) then
  422.      begin
  423.         Result := NPERR_FILE_NOT_FOUND;
  424.         Exit;
  425.      end;
  426.      stream.url := PChar(swf_file);
  427.      stream._end := SearchFileSize(swf_file);
  428.      stream.lastmodified := FileAge(swf_file);
  429.      err := plugin_funcs.newstream(plugin,
  430.         'application/x-shockwave-flash', @stream,
  431.         True, stype);
  432.      if (err <> NPERR_NO_ERROR) then
  433.      begin
  434.        Result := err;
  435.      end;
  436.      if ((stype = NP_NORMAL) or (stype = NP_ASFILE)) then
  437.      begin
  438.           swf_fd := TFileStream.Create(swf_file, fmOpenRead);
  439.           write_idx := 0;
  440.           while (stream._end > 0) do
  441.           begin
  442.            write_max :=
  443.               plugin_funcs.writeready(plugin, @stream);
  444.            {Debug("NPP_WriteReady: write_max = %d, end = %d\\n",
  445.               write_max, stream.end);}
  446.            if (write_max <= 0) then
  447.               break;
  448.                bytes_read := MIN(sizeof(data), stream._end);
  449.                bytes_read := swf_fd.Read(data, bytes_read);
  450.            //Debug("fread: bytes_read = %d\\n", bytes_read);
  451.                bytes_written :=    plugin_funcs.write(plugin,
  452.                                   @stream, write_idx,
  453.                   bytes_read,
  454.                   @data);
  455.            {Debug("NPP_Write: offset = %d, end = %d, "
  456.                      "written = %d\\n", write_idx, stream.end,
  457.              bytes_read);}
  458.            if (bytes_written <= 0) then
  459.               break;
  460.                Inc(write_idx, bytes_written);
  461.            Dec(stream._end, bytes_written);
  462.           end;
  463.           swf_fd.Free;
  464.         end;
  465.     if ((stype = NP_ASFILE) or (stype = NP_ASFILEONLY)) then
  466.         begin
  467.              if stream._end = 0 then
  468.                 pfn := PChar(swf_file)
  469.              else
  470.                  pfn := nil;
  471.          plugin_funcs.asfile(plugin, @stream, pfn);
  472.         end;
  473.     if (stype <> NP_SEEK) then
  474.         begin
  475.              if stream._end = 0 then
  476.                 reason := NPRES_DONE
  477.              else
  478.                  reason := NPRES_NETWORK_ERR;
  479.         err := plugin_funcs.destroystream(plugin, @stream, reason);
  480.         end;
  481.     Result := err;
  482. end;
  483. {/*==========================================================================*\\
  484. * Play utility, cmdline parsing, main...
  485. \\*==========================================================================*/}
  486. procedure LoadFlashPlugin();
  487. var
  488.   user_plugin_path: string;
  489.   plugin_path: string;
  490.   dlobj: Pointer;
  491. begin
  492.      //user_plugin_path := '/home/rreale/prog/MozillaPluginPanel/Plugins/flash7/';
  493.      user_plugin_path := '/usr/lib/firefox/plugins/';
  494.      plugin_path := user_plugin_path + 'libflashplayer.so';
  495.      //user_plugin_path := '/home/rreale/.mozilla/plugins/';
  496.      //plugin_path := user_plugin_path + 'libdiamondx.so';
  497.      dlobj := dlopen(PChar(plugin_path), RTLD_LAZY);
  498.      if dlobj = nil then
  499.         raise Exception.Create('Unable to load flash plugin');
  500.      gNP_GetMIMEDescription := dlsym(dlobj, 'NP_GetMIMEDescription');
  501.      gNP_Initialize := dlsym(dlobj, 'NP_Initialize');
  502.      gNP_Shutdown := dlsym(dlobj, 'NP_Shutdown');
  503.      gNP_GetValue := dlsym(dlobj, 'NP_GetValue');
  504. end;
  505. FUNCTION delete_event( widget : pGtkWidget ; event : pGdkEvent ; data : gpointer ) :
  506.       gint; cdecl;
  507. BEGIN
  508. { Returning FALSE from the function, as we do here, causes the --destroy-- signal to be emitted. }
  509. delete_event := 0;
  510. END;
  511. PROCEDURE destroy( widget : pGtkWidget ; data : gpointer ); cdecl;
  512. BEGIN
  513. gtk_main_quit();
  514. END;
  515. procedure window_size_allocate(widget: PGtkWidget;
  516.   allocation: PGtkAllocation;
  517.   user_data: gpointer); cdecl;
  518. begin
  519.     {gtk_widget_set_size_request(fixed,
  520.       allocation.width, allocation.height);}
  521.     {gtk_widget_set_size_request(socket,
  522.       allocation.width, allocation.height);}
  523. end;
  524. procedure socket_size_request(widget: PGtkWidget;
  525.   allocation: PGtkRequisition;
  526.   user_data: gpointer); cdecl;
  527. begin
  528.      //gtk_widget_get_size_request();
  529.      allocation.width := 900;
  530.      allocation.height := 600;
  531.     {gtk_widget_set_size_request(fixed,
  532.       allocation.width, allocation.height);
  533.     gtk_widget_set_size_request(socket,
  534.       allocation.width, allocation.height);}
  535. end;
  536. procedure socket_size_allocate(widget: PGtkWidget;
  537.   allocation: PGtkAllocation;
  538.   user_data: gpointer); cdecl;
  539. begin
  540.      if (socket <> nil) and
  541.         (GTK_WIDGET_REALIZED(socket)) then
  542.         CallSetWindow(@plugin, allocation.width, allocation.height);
  543.     {gtk_widget_set_size_request(fixed,
  544.       allocation.width, allocation.height);}
  545.     {gtk_widget_set_size_request(socket,
  546.       allocation.width, allocation.height);}
  547. end;
  548. procedure InitializeGtk(width, height: Integer);
  549. begin
  550.     window := gtk_window_new(GTK_WINDOW_TOPLEVEL);
  551.     gtk_container_set_border_width(GTK_CONTAINER(window), 10);
  552.     gtk_widget_set_size_request(window, width, height);
  553.     gtk_signal_connect(GTK_OBJECT(window), 'delete_event',
  554.       GTK_SIGNAL_FUNC(@delete_event), NIL);
  555.     gtk_signal_connect(GTK_OBJECT(window), 'destroy',
  556.       GTK_SIGNAL_FUNC(@destroy), NIL);
  557.     gtk_signal_connect(GTK_OBJECT(window), 'size-allocate',
  558.       GTK_SIGNAL_FUNC(@window_size_allocate), NIL);
  559.     {fixed := gtk_fixed_new;
  560.     gtk_fixed_set_has_window(GTK_FIXED(fixed), true);
  561.     gtk_widget_set_size_request(fixed, width, height);
  562.     gtk_container_add(GTK_CONTAINER(window), fixed);}
  563.     //gtk_widget_realize(fixed);
  564.     //vbox := gtk_vbox_new(true, 5);
  565.     {frame := gtk_frame_new('My Frame');
  566.     gtk_box_pack_start(GTK_BOX(vbox), frame, true, false, 0);
  567.     gtk_widget_show(frame);}
  568.     socket := gtk_socket_new;
  569.     //gtk_widget_set_size_request(socket, width, height);
  570.    
  571.     {gtk_signal_connect(GTK_OBJECT(socket), 'size-request',
  572.       GTK_SIGNAL_FUNC(@socket_size_request), NIL);}
  573.     gtk_signal_connect(GTK_OBJECT(socket), 'size-allocate',
  574.       GTK_SIGNAL_FUNC(@socket_size_allocate), NIL);
  575.    
  576.     //gtk_container_add(GTK_CONTAINER(fixed), socket);
  577.     //gtk_box_pack_start(GTK_BOX(vbox), socket, true, false, 0);
  578.     //gtk_widget_realize(socket);
  579.     gtk_container_add(GTK_CONTAINER(window), socket);
  580.     gtk_widget_show(socket);
  581.     //gtk_container_add(GTK_CONTAINER(fixed), vbox);
  582.     //gtk_container_add(GTK_CONTAINER(window), vbox);
  583.     //gtk_widget_show(vbox);
  584.     //gtk_widget_show(fixed);
  585.     gtk_widget_show(window);
  586. end;
  587. procedure InitializeFuncs();
  588. begin
  589.      FillChar(mozilla_funcs, sizeof(mozilla_funcs), 0);
  590.      mozilla_funcs.Size := sizeof(mozilla_funcs);
  591.      mozilla_funcs.Version := (NP_VERSION_MAJOR shl 8) + NP_VERSION_MINOR;
  592.      mozilla_funcs.GetUrl := @NPN_GetURL;
  593.      mozilla_funcs.PostUrl := @NPN_PostURL;
  594.      mozilla_funcs.RequestRead := @NPN_RequestRead;
  595.      mozilla_funcs.NewStream := @NPN_NewStream;
  596.      mozilla_funcs.Write := @NPN_Write;
  597.      mozilla_funcs.DestroyStream := @NPN_DestroyStream;
  598.      mozilla_funcs.Status := @NPN_Status;
  599.      mozilla_funcs.UserAgent := @NPN_UserAgent;
  600.      mozilla_funcs.MemAlloc := @NPN_MemAlloc;
  601.      mozilla_funcs.MemFlush := @NPN_MemFlush;
  602.      mozilla_funcs.MemFlush := @NPN_MemFree;
  603.      mozilla_funcs.ReloadPlugins := @NPN_ReloadPlugins;
  604.      mozilla_funcs.GetJavaEnv := @NPN_GetJavaEnv;
  605.      mozilla_funcs.GetJavaPeer := @NPN_GetJavaPeer;
  606.      mozilla_funcs.GetUrlNotify := @NPN_GetURLNotify;
  607.      mozilla_funcs.PostUrlNotify := @NPN_PostURLNotify;
  608.      mozilla_funcs.GetValue := @NPN_GetValue;
  609.      mozilla_funcs.SetValue := @NPN_SetValue;
  610.      mozilla_funcs.InvalidateRect := @NPN_InvalidateRect;
  611.      FillChar(plugin_funcs, SizeOf(plugin_funcs), 0);
  612.      plugin_funcs.size := SizeOf(plugin_funcs);
  613. end;
  614. procedure Error(msg: string; fmt: array of const);
  615. begin
  616.      raise Exception.CreateFmt(msg, fmt);
  617. end;
  618. {/*
  619. * Helper to manage create a plugin instance, new window, then writing the
  620. * file contents to the instance.
  621. */}
  622. function PlaySwf(plugin: PNPP; swf_file: string; width, height: Integer): TNPError;
  623. var
  624.   err: TNPError;
  625. begin
  626.      err := NPERR_NO_ERROR;
  627.     {/*
  628.      * Without this, Flash segfaults attempting to dynamically invoke
  629.      * gtk_major_mode.  Linking GTK+ means that Flash uses GTK's mainloop
  630.      * for IO and timeouts, which we don't want.
  631.      *
  632.      * FIXME: Is there a better way?
  633.      */}
  634.     //putenv('FLASH_GTK_LIBRARY=');
  635.     err := gNP_Initialize(@mozilla_funcs, @plugin_funcs);
  636.     if (err <> NPERR_NO_ERROR) then
  637.         Error('NP_Initialize result = %d', [err]);
  638.     err := CallNew(plugin, swf_file, width, height);
  639.     if (err <> NPERR_NO_ERROR) then
  640.         Error('NPP_NewProc result = %d', [err]);
  641.     err := CallSetWindow(plugin, width, height);
  642.     if (err <> NPERR_NO_ERROR) then
  643.         Error('NPP_SetWindow result = %d', [err]);
  644.     //Log("Loading: %s\\n", swf_file);
  645.     err := SendSrcStream(plugin, swf_file);
  646.     if (err <> NPERR_NO_ERROR) then
  647.         Error('Writing SWF file, result = %d', [err]);
  648.     Result := NPERR_NO_ERROR;
  649. end;
  650. var
  651.   geometry: string;
  652.   fullscren: Boolean = false;
  653.   baseurl, swf_file: string;
  654.   width: Integer = 700;
  655.   height: Integer = 400;
  656. begin
  657.     swf_file := 'test.swf';
  658.   // must disable floating point exceptions
  659.   SetExceptionMask([exInvalidOp, exDenormalized,
  660.                     exZeroDivide, exOverflow,
  661.                     exUnderflow, exPrecision]);
  662.     gtk_init(@argc, @argv);
  663.     LoadFlashPlugin();
  664.     InitializeGtk(width, height);
  665.     InitializeFuncs();
  666.     PlaySwf(@plugin, swf_file, width, height);
  667.     gtk_main();
  668.    
  669.     gNP_Shutdown();
  670. end.
复制代码
回复 支持 反对

使用道具 举报

该用户从未签到

 楼主| 发表于 2010-7-21 09:20:19 | 显示全部楼层
给的代码真多,不过粘出来的是代行号的,还好可以用openoffice删掉。
不过这些代码应该如何使用呢?编译还是……
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2010-7-21 15:29:32 | 显示全部楼层
参考一下不就可以了
回复 支持 反对

使用道具 举报

该用户从未签到

 楼主| 发表于 2010-7-21 16:01:31 | 显示全部楼层
哦,谢谢了
回复 支持 反对

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2025-5-2 21:18 , Processed in 0.032983 second(s), 10 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表