cvs: peardoc /en/package gtk.xml /en/package/gtk filedrop.xml /en/package/gtk/filedrop example.xml intro.xml widgetsupport.xml

From: Date: Sat, 06 Nov 2004 16:26:06 +0000
Subject: cvs: peardoc /en/package gtk.xml /en/package/gtk filedrop.xml /en/package/gtk/filedrop example.xml intro.xml widgetsupport.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-5087@lists.php.net to get a copy of this message
cweiske Sat Nov 6 11:26:06 2004 EDT Added files: /peardoc/en/package gtk.xml /peardoc/en/package/gtk filedrop.xml /peardoc/en/package/gtk/filedrop example.xml intro.xml widgetsupport.xml Log: Initial documentation for the Gtk_FileDrop widget

http://cvs.php.net/co.php/peardoc/en/package/gtk.xml?r=1.1&p=1 Index: peardoc/en/package/gtk.xml +++ peardoc/en/package/gtk.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <chapter id="package.gtk"> <title>Gtk</title> <para> Provides useful packages for the <ulink url="http://gtk.php.net">PHP-Gtk</ulink> extension. </para> <sect1> <title /> <simpara /> </sect1> &package.gtk.filedrop; </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/peardoc/en/package/gtk/filedrop.xml?r=1.1&p=1 Index: peardoc/en/package/gtk/filedrop.xml +++ peardoc/en/package/gtk/filedrop.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <sect1 id="package.gtk.filedrop"> <title>FileDrop</title> <para> Setting up GtkWidgets to accept files via Drag'n'Drop in a very easy way. </para> &package.gtk.filedrop.intro; <!-- &package.gtk.filedrop.constants;--> &package.gtk.filedrop.widgetsupport; &package.gtk.filedrop.example; <!-- &package.gtk.filedrop;--> </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/peardoc/en/package/gtk/filedrop/example.xml?r=1.1&p=1 Index: peardoc/en/package/gtk/filedrop/example.xml +++ peardoc/en/package/gtk/filedrop/example.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk.filedrop.example"> <refnamediv> <refname>Example</refname> <refpurpose> How to use Gtk_FileDrop </refpurpose> </refnamediv> <refsect1> <title>Using Gtk_FileDrop</title> <example> <title>General setup</title> <programlisting role="php"> <![CDATA[ <?php $accepted_types = array( 'text/html', 'text/plain', '.dat' ); Gtk_FileDrop::attach($widget, $accepted_types); ?> ]]> </programlisting> <para> Here we set up the array of accepted file types: The widget shall accept files with MIME-Type <literal>text/html</literal>, <literal>text/plain</literal> and files ending with <literal>.dat</literal>. After this we set up the <literal>$widget</literal> to accept this files. </para> </example> <example> <title>Accepting directories</title> <programlisting role="php"> <![CDATA[ $accepted_types = array( 'inode/directory', ); ]]> </programlisting> <simpara> The MIME type <literal>inode/directory</literal> has to be used if the widget shall accept directories. </simpara> </example> <note> <simpara> When a file is dropped over a widget which accepts directories only, the directory of the filename is used. </simpara> </note> <example> <title>Setup with callback</title> <programlisting role="php"> <![CDATA[ <?php function filesDropped($widget, $arFiles) { foreach($arFiles as $strFile) { echo "The file \"$strFile\" has been dropped\r\n"; } } $accepted_types = array( 'text/html', 'text/plain', '.dat' ); Gtk_FileDrop::attach($widget, $accepted_types, 'filesDropped', false); ?> ]]> </programlisting> <para> In this example we use a callback function to print out all dropped files to the console. Further we determine the fourth parameter as <literal>false</literal> which means that the widget's value is not changed automatically. </para> <para> To use the callback with objects, you pass an array with the reference of the object: <example> <title>Using a callback</title> <programlisting role="php"> <![CDATA[ <?php Gtk_FileDrop::attach($widget, $accepted_types, array( &$this, 'filesDropped')); ?> ]]> </programlisting> </example> </para> </example> <example> <title>Working example</title> <programlisting role="php"> <![CDATA[ <?php if (!extension_loaded('gtk')) { dl('php_gtk.' . PHP_SHLIB_SUFFIX); } require_once('Gtk/FileDrop.php'); $window = &new GtkWindow(); $window->set_default_size(300, 30); $window->connect_object('destroy', array('gtk', 'main_quit')); $window->show(); $entry =& new GtkEntry(); $window->add($entry); $entry->set_text('drop text files on me'); Gtk_FileDrop::attach($entry, array('text/plain')); $window->show_all(); gtk::main(); ?> ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/peardoc/en/package/gtk/filedrop/intro.xml?r=1.1&p=1 Index: peardoc/en/package/gtk/filedrop/intro.xml +++ peardoc/en/package/gtk/filedrop/intro.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk.filedrop.intro"> <refnamediv> <refname>Introduction</refname> <refpurpose> Why using Gtk_FileDrop? </refpurpose> </refnamediv> <refsect1 id="packages.gtk.filedrop.intro.contrib"> <title>Contributors</title> <para> <itemizedlist> <listitem><simpara>Christian Weiske</simpara></listitem> </itemizedlist> </para> </refsect1> <refsect1 id="packages.gtk.filedrop.intro.desc"> <title>Description</title> <para> <classname>Gtk_FileDrop</classname> provides an easy interface to set up GtkWidgets to receive files via Drag'n'Drop. Widgets can be told to accept a number of MIME-Types as well as a number of file extensions. Values of widgets can automatically be set when drops with valid files occur, or a callback function can be specified which is invoked in this case. </para> <para> Now one may think that the whole setup process is really simple and would not need a class like this to make widgets accept files. That is right. The setup for making widgets accept drops is an ease - but there are two more steps to do: <orderedlist> <listitem><simpara>Make the widget accept only some types of files</simpara></listitem> <listitem><simpara>Convert the dropped filenames to usable filenames</simpara></listitem> </orderedlist> </para> <para> The first item is not so hard to implement; we do this by either checking the file extension, or using the MIME_Type package to get the mime type. (Note: <literal>*</literal> is supported). </para> <para> The second item is the main problem as all applications seem to ignore the standard for file name exchange and cook their own soup (so using their own format) when passing the file names. This package knows the differences and converts the dropped strings into usable local filenames, regardless of the format the source application uses. For a deeper insight in this topic you should read the <ulink url="http://gtk.php.net/manual/en/tutorials.filednd.urilist.php" >PHP-Gtk FileDrop tutorial</ulink>. </para> <note> <simpara>A note about Mozilla/Firefox: Mozilla provides file names only with mime type <literal>text/plain</literal> only instead of <literal>text/uri-list</literal>. If we would accept this type as well, the problem arises that every text could be dropped - if it is a file or not. That's why the decision was made not to accept drops from Mozilla.</simpara> </note> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/peardoc/en/package/gtk/filedrop/widgetsupport.xml?r=1.1&p=1 Index: peardoc/en/package/gtk/filedrop/widgetsupport.xml +++ peardoc/en/package/gtk/filedrop/widgetsupport.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk.filedrop.widgetsupport"> <refnamediv> <refname>Widget support</refname> <refpurpose> Drops handled on different widget types </refpurpose> </refnamediv> <refsect1> <title>Natively supported widgets</title> <simpara> By default, the dropped files are displayed in the widget, e.g. if you drop a file over a <literal>GtkEntry</literal>, the text value of the widget will be overwritten to the filename. </simpara> <simpara> As not all widgets have such simple values, Gtk_FileDrop has built-in support for a number of widget classes and acts different on different types. </simpara> <table> <title>Widget support</title> <tgroup cols="2"> <thead> <row> <entry>Widget class</entry> <entry>Action taken</entry> </row> </thead> <tbody> <row> <entry>GtkEntry</entry> <entry>Entry value is replaced with first file</entry> </row> <row> <entry>GtkLabel</entry> <entry>Label text is replaced with first file</entry> </row> <row> <entry>GtkButton</entry> <entry>Label text is replaced with first file if the first and only child is a GtkLabel</entry> </row> <row> <entry>GtkToggleButton</entry> <entry>Label text is replaced with first file if the first and only child is a GtkLabel</entry> </row> <row> <entry>GtkRadioButton</entry> <entry>Label text is replaced with first file if the first and only child is a GtkLabel</entry> </row> <row> <entry>GtkCheckButton</entry> <entry>Label text is replaced with first file if the first and only child is a GtkLabel</entry> </row> <row> <entry>GtkCombo</entry> <entry>The entry text is replaced with the first file. The list is not affected.</entry> </row> <row> <entry>GtkFileSelection</entry> <entry>File name of the file dialog is set to the first dropped file. The directory is changed to the directory name of the file, and the file name (without directory) is set in the file name entry. </entry> </row> <row> <entry>GtkList</entry> <entry>Every accepted file is appended at the end of the list. </entry> </row> </tbody> </tgroup> </table> <para> Beside the automatic actions, you can specify a callback as the third parameter of the <literal>attach</literal> function which is called with the widget itself and an array of accepted files as parameters. </para> </refsect1> </refentry>
« previous php.pear.doc (#5087) next »