cvs: php-gtk-doc /en/reference/gtk gtkitemfactory.xml

From: Date: Thu, 22 Jul 2004 19:36:32 +0000
Subject: cvs: php-gtk-doc /en/reference/gtk gtkitemfactory.xml
Groups: php.gtk.doc 
Request: Send a blank email to php-gtk-doc+get-908@lists.php.net to get a copy of this message
cweiske Thu Jul 22 15:36:32 2004 EDT Modified files: /php-gtk-doc/en/reference/gtk gtkitemfactory.xml Log: Found out how the GtkItemFactory works and made the docs for it as well as two nice examples. No need to create menus the normal way any more.

http://cvs.php.net/diff.php/php-gtk-doc/en/reference/gtk/gtkitemfactory.xml?r1=1.3&r2=1.4&ty=u Index: php-gtk-doc/en/reference/gtk/gtkitemfactory.xml diff -u php-gtk-doc/en/reference/gtk/gtkitemfactory.xml:1.3 php-gtk-doc/en/reference/gtk/gtkitemfactory.xml:1.4 --- php-gtk-doc/en/reference/gtk/gtkitemfactory.xml:1.3 Sun Jan 20 14:47:43 2002 +++ php-gtk-doc/en/reference/gtk/gtkitemfactory.xml Thu Jul 22 15:36:32 2004 @@ -4,10 +4,12 @@ <classtitle>GtkItemFactory</classtitle> <classparent>GtkObject</classparent> <shortdesc> - + A factory class for simplified menu creation. </shortdesc> <desc> - + The <classname>GtkItemFactory</classname> is a class which makes it very easy + to create a lot of menu items at once. It supports nested menus, shortcuts and + different menu item types as well. </desc> </classmeta> @@ -15,35 +17,301 @@ <funcsynopsis> <funcprototype> <funcdef> <function>GtkItemFactory</function></funcdef> - <paramdef>int <parameter>container_type</parameter></paramdef> - <paramdef>string <parameter>path</parameter></paramdef> + <paramdef><classname>GtkType</classname> <parameter>container_type</parameter></paramdef> + <paramdef>String <parameter>path</parameter></paramdef> <paramdef><classname>GtkAccelGroup</classname> <parameter>accel_group</parameter></paramdef> </funcprototype> </funcsynopsis> <shortdesc> - + Creates a new instance of this class. </shortdesc> <desc> - + <simpara> + Creates a new instance of the <classname>GtkItemFactory</classname> class. + One factory can be used for one menu, and not more. This means that if you want to have + a standard <classname>GtkMenuBar</classname> at the top of a window and an additional + right-click popup menu, you have to use 2 item factories. + </simpara> + <para> + The <parameter>container_type</parameter> determines, which type the root menu will have: + <classname>GtkMenu</classname>, <classname>GtkMenuBar</classname> or + <classname>GtkOptionMenu</classname>. To get the <classname>GtkType</classname> you want, + just create an object of this specific class and use the <literal>get_type()</literal> + function: + <programlisting role="php"> +<![CDATA[ +$menubar = &new GtkMenuBar(); +$type = $menubar->get_type(); +]]> + </programlisting> + </para> + <simpara> + The <parameter>path</parameter> is a unique name for this menu, enclosed in + <literal>&lt;</literal> and <literal>&gt;</literal>, e.g. <literal>&lt;mainmenu&gt;</literal>. + This path has to be unique in the whole application. + </simpara> + <simpara> + The <parameter>accel_group</parameter> is the accelerator group belonging to this window + and is responsible for the menu shortcuts. It can be <literal>NULL</literal>, but then the + menu shortcuts won't work. + </simpara> + <example> + <title>Using a <classname>GtkItemFactory</classname></title> + <programlisting role="php"> +<![CDATA[ +<?php +if( !extension_loaded('gtk')) { + dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); +} + +$window = &new GtkWindow(); +$window->set_default_size( 300, 20); +$window->connect_object('destroy', array('gtk', 'main_quit')); + +$accelgroup = &new GtkAccelGroup(); +$window->add_accel_group( $accelgroup); + +$dummybar = &new GtkMenuBar(); +$fac = &new GtkItemFactory( $dummybar->get_type(), "<mainmenu>", $accelgroup); + +function quit( $number, $item) { + gtk::main_quit(); +} +$arItems = array( +array( "/_File/_Open", null, null, 0, null ), +array( "/_File/_Save", null, null, 0, null ), +array( "/_File/_Quit", "<CTRL>Q", 'quit', 0, null ) +); + +$fac->create_items( $arItems); + +$window->add( $fac->get_widget( "<mainmenu>")); +$window->show_all(); +gtk::main(); +?> +]]> + </programlisting> + </example> + <simpara> + A more sophisticated example can be found at the + <function class="GtkItemFactory">create_items</function> function. + </simpara> </desc> </constructor> <methods> - <method id="gtk.gtkitemfactory.method.construct"> + <method id="gtk.gtkitemfactory.method.create_items"> <funcsynopsis> <funcprototype> - <funcdef>void <function>construct</function></funcdef> - <paramdef>int <parameter>container_type</parameter></paramdef> - <paramdef>string <parameter>path</parameter></paramdef> - <paramdef><classname>GtkAccelGroup</classname> <parameter>accel_group</parameter></paramdef> + <funcdef>boolean <function>create_items</function></funcdef> + <paramdef>Array <parameter>items</parameter></paramdef> </funcprototype> </funcsynopsis> <shortdesc> - + Creates the whole menu. </shortdesc> <desc> - + <simpara> + You usually create your menu by calling this method with an array full of + menu item definitions. Such a item definition is an array itself and has the + following structure: + <literal>String path, String accelerator, Mixed callback, int callback_action, String type</literal> + </simpara> + <para> + The function can be called several times, causing the new items to be appended to the + existing ones. + <note>If you add a first-level menu item on a second create_items call, + an existing &lt;LastBranch&gt; will lose its right alignment.</note> + </para> + <para> + The <literal>path</literal> is the name describing the path form the top + down to this item. The levels are separated with a slash <literal>/</literal>, + and underscores <literal>_</literal> can be used to create in-menu accelerators. + <programlisting role="php"> +<![CDATA[ +"/_File/_Recent files/_1 test.xml" +"/_File/O_pen" +]]> + </programlisting> + It is not necessary to explicitly create the parent items if + you create a submenu item; this is done automatically. + </para> + + <para> + The <parameter>accelerator</parameter> sets the shortcut for the menu item; it can be + <literal>NULL</literal> or a combination of modifiers and chars. + <table> + <title>Accelerator modifiers</title> + <tgroup cols="1"> + <tbody> + <row> + <entry><literal>&lt;ALT&gt;</literal></entry> + </row> + <row> + <entry><literal>&lt;CTL&gt;</literal> or <literal>&lt;CTRL&gt;</literal> + or <literal>&lt;CONTROL&gt;</literal></entry> + </row> + <row> + <entry><literal>&lt;MOD1&gt;</literal> to <literal>&lt;MOD5&gt;</literal></entry> + </row> + <row> + <entry><literal>&lt;SHFT&gt;</literal> or <literal>&lt;SHIFT&gt;</literal></entry> + </row> + </tbody> + </tgroup> + </table> + </para> + + <simpara> + As usually, the <parameter>callback</parameter> accepts the String of the function to call, + or an array with the reference to an object as first, and the name of the object's function + as the second parameter. This parameter can be <literal>NULL</literal>. + </simpara> + + <simpara> + Unlike many other callback registering functions, this one doesn't support own parameters + as <literal>callback_option</literal>. + Instead, you can give a number (int) only to describe the function of the menu item. So + you can use <literal>1</literal> for opening and <literal>2</literal> for saving to + distinguish both when they use the same callback. The callback function needs to implement + 2 parameters:<literal>int callback_option, GtkMenuItem item</literal>. The parameter has + to be of type int, so a <literal>NULL</literal> cause an error. + </simpara> + + <para> + The <parameter>type</parameter> is a string from this list: + <table> + <title><classname>GtkItemFactory</classname> item types</title> + <tgroup cols="2"> + <thead> + <row> + <entry>Type</entry> + <entry>Description</entry> + </row> + </thead> + <tbody> + <row> + <entry><literal>NULL</literal> or <literal>''</literal> or <literal>&lt;Item&gt;</literal></entry> + <entry>Simple item</entry> + </row> + <row> + <entry><literal>&lt;Title&gt;</literal></entry> + <entry>Title item which can't be clicked.</entry> + </row> + <row> + <entry><literal>&lt;CheckItem&gt;</literal></entry> + <entry>Check item</entry> + </row> + <row> + <entry><literal>&lt;ToggleItem&gt;</literal></entry> + <entry>Toggle item</entry> + </row> + <row> + <entry><literal>&lt;RadioItem&gt;</literal></entry> + <entry>(Root) radio item</entry> + </row> + <row> + <entry><literal>Path</literal></entry> + <entry>Sister radio item for another radio item</entry> + </row> + <row> + <entry><literal>&lt;Tearoff&gt;</literal></entry> + <entry>Tearoff</entry> + </row> + <row> + <entry><literal>&lt;Separator&gt;</literal></entry> + <entry>Separator</entry> + </row> + <row> + <entry><literal>&lt;Branch&gt;</literal></entry> + <entry>Item to hold submenus (optional)</entry> + </row> + <row> + <entry><literal>&lt;LastBranch&gt;</literal></entry> + <entry>Right justified branch. This is only useful for one submenu of a menubar.</entry> + </row> + </tbody> + </tgroup> + </table> + </para> + <example> + <title>Extensive GtkItemFactory::create_items example</title> + <programlisting role="php"> +<![CDATA[ +<?php +if( !extension_loaded('gtk')) { + dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); +} + +$window = &new GtkWindow(); +$window->set_default_size( 300, 20); +$window->connect_object('destroy', array('gtk', 'main_quit')); + +$accelgroup = &new GtkAccelGroup(); +$window->add_accel_group( $accelgroup); + +$dummybar = &new GtkMenuBar(); +$fac = &new GtkItemFactory( $dummybar->get_type(), '<mainmenu>', $accelgroup); + +function menucall( $number, $item) { + switch( $number) { + case 1: echo 'New file'; break; + case 15: echo 'This is a small GtkItemFactory example'; break; + case 20: gtk::main_quit(); break; + default: echo 'Unknown action ' . $number; + } + echo "\r\n"; +} +$arItems = array( +array( '/_File/_New', '<CTRL>N', 'menucall', 1, null ), +array( '/_File/_Open', '<CTRL>O', 'menucall', 2, '' ), +array( '/_File/sep1', null, null, 0, '<Separator>' ), +array( '/_File/_Save', '<CTRL>S', 'menucall', 0, null ), +array( '/_File/Save _as', null, 'menucall', 0, null ), +array( '/_File/sep2', null, null, 0, '<Separator>' ), +array( '/_File/_Quit', '<CTRL>Q', 'menucall', 20, null ), + +array( '/_View', null, null, 0, '<Branch>' ), +array( '/_View/tearoff', null, null, 0, '<Tearoff>' ), +array( '/_View/_Toolbar', null, null, 0, '<CheckItem>' ), +array( '/_View/_Preview', null, null, 0, '<CheckItem>' ), + +array( '/_Colors/tearoff', null, null, 0, '<Tearoff>' ), +array( '/_Colors/Foreground', null, null, 0, '<Title>' ), +array( '/_Colors/White', null, null, 0, '<RadioItem>' ), +array( '/_Colors/Yellow', null, null, 0, '/Colors/White' ), +array( '/_Colors/Orange', null, null, 0, '/Colors/White' ), + +array( '/_Colors/sep1', null, null, 0, '<Separator>' ), +array( '/_Colors/Background', null, null, 0, '<Title>' ), +array( '/_Colors/Black', null, null, 0, '<RadioItem>' ), +array( '/_Colors/Blue', null, null, 0, '/Colors/Black' ), +array( '/_Colors/Red', null, null, 0, '/Colors/Black' ), + +array( '/_Help', null, null, 0, '<LastBranch>' ), +array( '/_Help/_About', 'F1', 'menucall', 15, '<Item>' ) +); + +$fac->create_items( $arItems); + +//By default, the first item of a radio group is selected. We change this +$mnuColorRed = $fac->get_widget( '/Colors/Red'); +$mnuColorRed->set_active( true); + +$arMoreItems = array( +array( '/_View/sep1', null, null, 0, '<Separator>' ), +array( '/_View/more/items/are/appended/here', null, null, 0, null) +); +$fac->create_items( $arMoreItems); + +$window->add( $fac->get_widget( "<mainmenu>")); +$window->show_all(); +gtk::main(); +?> +]]> + </programlisting> + </example> </desc> </method> @@ -51,14 +319,18 @@ <funcsynopsis> <funcprototype> <funcdef><classname>GtkWidget</classname> <function>get_item</function></funcdef> - <paramdef>string <parameter>path</parameter></paramdef> + <paramdef>String <parameter>path</parameter></paramdef> </funcprototype> </funcsynopsis> <shortdesc> - + Obtains the menu item which corresponds to path. </shortdesc> <desc> - + <simpara> + If the widget corresponding to path is a menu item which opens a submenu, + then the item is returned. If you are interested in the submenu, + use <function class="GtkItemFactory">get_widget</function> instead. + </simpara> </desc> </method> @@ -66,14 +338,18 @@ <funcsynopsis> <funcprototype> <funcdef><classname>GtkWidget</classname> <function>get_widget</function></funcdef> - <paramdef>string <parameter>path</parameter></paramdef> + <paramdef>String <parameter>path</parameter></paramdef> </funcprototype> </funcsynopsis> <shortdesc> - + Obtains the widget item which corresponds to path. </shortdesc> <desc> - + <simpara> + If the widget corresponding to path is a menu item which opens a submenu, + then the submenu is returned. If you are interested in the menu item, + use <function class="GtkItemFactory">get_item</function> instead. + </simpara> </desc> </method> @@ -85,10 +361,14 @@ </funcprototype> </funcsynopsis> <shortdesc> - + Obtains the widget which was constructed from the GtkItemFactoryEntry with the given action. </shortdesc> <desc> - + <simpara> + Obtains the widget which was constructed from the GtkItemFactoryEntry with the given action. + If there are multiple items with the same action, the result is undefined. It is NOT an array + as you may have assumed - it is probably one of the items found. + </simpara> </desc> </method> @@ -100,25 +380,18 @@ </funcprototype> </funcsynopsis> <shortdesc> - + Obtains the menu item which was constructed from the first GtkItemFactoryEntry with the given action. </shortdesc> <desc> - - </desc> - </method> - - <method id="gtk.gtkitemfactory.method.create_items"> - <funcsynopsis> - <funcprototype> - <funcdef>XXX <function>create_items</function></funcdef> - <paramdef>XXX</paramdef> - </funcprototype> - </funcsynopsis> - <shortdesc> - - </shortdesc> - <desc> - + <simpara> + Obtains the item which was constructed from the GtkItemFactoryEntry with the given action. + If there are multiple items with the same action, the result is undefined. It is NOT an array + as you may have assumed - it is probably one of the items found. + </simpara> + <simpara> + The difference between <literal>item</literal> and <literal>widget</literal> is explained in + <function class="GtkItemFactory">get_item</function>. + </simpara> </desc> </method> @@ -130,10 +403,12 @@ </funcprototype> </funcsynopsis> <shortdesc> - + Deletes the menu item which was created for path by the given item factory. </shortdesc> <desc> - + <simpara> + Deletes the menu item which was created for path by the given item factory. + </simpara> </desc> </method> @@ -148,10 +423,17 @@ </funcprototype> </funcsynopsis> <shortdesc> - + Pops up the menu at (x, y). </shortdesc> <desc> - + <simpara> + Pops up the complete menu at (x, y). + </simpara> + <simpara> + The mouse_button parameter should be the mouse button pressed to initiate the menu popup. + If the menu popup was initiated by something other than a mouse button press, + such as a mouse button release or a keypress, mouse_button should be 0. + </simpara> </desc> </method>
« previous php.gtk.doc (#908) next »