⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-gnomeuiinfo.html

📁 GTK+_ Gnome Application Development
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>  <head>    <title>      Menus and Toolbars with GnomeUIInfo    </title>    <meta name="GENERATOR" content=    "Modular DocBook HTML Stylesheet Version 1.45">    <link rel="HOME" title="GTK+ / Gnome Application Development"    href="ggad.html">    <link rel="UP" title="The Main Window: GnomeApp" href=     "cha-main.html">    <link rel="PREVIOUS" title="The Main Window: GnomeApp" href=     "cha-main.html">    <link rel="NEXT" title="Adding a Status Bar" href="z91.html">  </head>  <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink=   "#840084" alink="#0000FF">    <div class="NAVHEADER">      <table width="100%" border="0" bgcolor="#ffffff" cellpadding=       "1" cellspacing="0">        <tr>          <th colspan="4" align="center">            <font color="#000000" size="2">GTK+ / Gnome Application            Development</font>          </th>        </tr>        <tr>          <td width="25%" bgcolor="#ffffff" align="left">            <a href="cha-main.html"><font color="#0000ff" size="2">            <b>&lt;&lt;&lt; Previous</b></font></a>          </td>          <td width="25%" colspan="2" bgcolor="#ffffff" align=           "center">            <font color="#0000ff" size="2"><b><a href="ggad.html">            <font color="#0000ff" size="2"><b>            Home</b></font></a></b></font>          </td>          <td width="25%" bgcolor="#ffffff" align="right">            <a href="z91.html"><font color="#0000ff" size="2"><b>            Next &gt;&gt;&gt;</b></font></a>          </td>        </tr>      </table>    </div>    <div class="SECT1">      <h1 class="SECT1">        <a name="SEC-GNOMEUIINFO">Menus and Toolbars with <span        class="STRUCTNAME">GnomeUIInfo</span></a>      </h1>      <p>        It's tedious to create large menus, especially if they have        features such as icons and keyboard accelerators. Gnome        provides a simple solution. You assemble a <span class=         "STRUCTNAME">GnomeUIInfo</span> struct as a template for        each menu item, simply listing its characteristics: name,        icon, accelerator, and so on. The Gnome libraries can        automatically create menus from arrays of <span class=         "STRUCTNAME">GnomeUIInfo</span> templates. The same method        works with toolbars.      </p>      <p>        Here's the declaration of <span class="STRUCTNAME">struct        GnomeUIInfo</span>.      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;typedef struct {  GnomeUIInfoType type;  gchar* label;  gchar* hint;    gpointer moreinfo;      gpointer user_data;  gpointer unused_data;  GnomeUIPixmapType pixmap_type;  gpointer pixmap_info;  guint accelerator_key;  GdkModifierType ac_mods;  GtkWidget* widget;} GnomeUIInfo;&#13;</pre>          </td>        </tr>      </table>      <p>        A static initializer is the most convenient way to fill in        the struct (but of course you can create it dynamically if        you prefer). Gnome's routines accept an array of <span        class="STRUCTNAME">GnomeUIInfo</span>, and macros are        provided to simplify and standardize the most common static        initializers. Here's a typical example, a File menu:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;static GnomeUIInfo file_menu[] = {  GNOMEUIINFO_MENU_NEW_ITEM(N_("_New Window"),                            N_("Create a new text viewer window"),                             new_app_cb, NULL),  GNOMEUIINFO_MENU_OPEN_ITEM(open_cb,NULL),  GNOMEUIINFO_MENU_SAVE_AS_ITEM(save_as_cb,NULL),  GNOMEUIINFO_SEPARATOR,  GNOMEUIINFO_MENU_CLOSE_ITEM(close_cb,NULL),  GNOMEUIINFO_MENU_EXIT_ITEM(exit_cb,NULL),  GNOMEUIINFO_END};&#13;</pre>          </td>        </tr>      </table>      <p>        There isn't always a nice macro for the menu item you want,        so sometimes you must manually specify each element of the        struct:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;{   GNOME_APP_UI_ITEM, N_("_Select All"),  N_("Select all cells in the spreadsheet"),   select_all_cb, NULL,  NULL, 0, 0, 'a', GDK_CONTROL_MASK }&#13;</pre>          </td>        </tr>      </table>      <p>        By now you're probably wondering what the struct members        mean. Simple enough. Here's a breakdown:      </p>      <ul>        <li>          <p>            <span class="STRUCTNAME">type</span> is a type marker            from the <span class="STRUCTNAME">            GnomeUIInfoType</span> enumeration. See <a href=             "sec-gnomeuiinfo.html#TAB-UIINFOTYPES">Table            1</a>.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">label</span> is the text of            the menu or toolbar button. It should be marked for            internationalization with the <span class="STRUCTNAME">            N_()</span> macro.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">hint</span> is a long            description of the item's function. For toolbar            buttons, it will appear in a tooltip; for menus, it can            be made to appear in the statusbar.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">moreinfo</span> depends on the            <span class="STRUCTNAME">type</span> of the item. See            <a href="sec-gnomeuiinfo.html#TAB-UIINFOTYPES">Table            1</a>.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">user_data</span> will be            passed to your callback function, if this item type has            a callback.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">unused_data</span> should be            set to <span class="STRUCTNAME">NULL</span>, and is not            used yet. It may be used in future versions of            Gnome.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">pixmap_type</span> is a value            from the <span class="STRUCTNAME">            GnomeUIPixmapType</span> enumeration; its purpose is to            specify the type of the next member, <span class=             "STRUCTNAME">pixmap_info</span>.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">pixmap_info</span> can be raw            pixmap data, a filename, or the name of a Gnome stock            pixmap.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">accelerator_key</span> is the            key to be used as an accelerator for this item . You            can use a character such as <span class="STRUCTNAME">            'a'</span>, or a value from <tt class="FILENAME">            gdk/gdkkeysyms.h</tt>. &#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">ac_mods</span> is a modifier            mask to be used with the accelerator.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">widget</span> should be <span            class="STRUCTNAME">NULL</span>; Gnome fills it in when            it creates the menu item or toolbar button. You can            then retrieve it, if you need to manipulate the widget            in some way.&#13;          </p>        </li>      </ul>      <p>        You might also be wondering why the menu item names contain        an underscore. The underscore is used to mark the key        shortcut for the menu item; translators can move it around        as needed to make it intuitive in their language. Gnome        will parse the menu item name to obtain the accelerator,        then remove the underscore.      </p>      <p>        <a href="sec-gnomeuiinfo.html#TAB-UIINFOTYPES">Table 1</a>        summarizes the possible values for the <span class=         "STRUCTNAME">type</span> field of a <span class=        "STRUCTNAME">GnomeUIInfo</span> struct. See <tt class=         "FILENAME">libgnomeui/gnome-app-helper.h</tt> for more        details. There are actually a few more possible values, but        the others are used internally by the library. The values        in <a href="sec-gnomeuiinfo.html#TAB-UIINFOTYPES">Table        1</a> should be sufficient for application code.      </p>      <div class="TABLE">        <a name="TAB-UIINFOTYPES"></a>        <p>          <b>Table 1. <span class="STRUCTNAME">          GnomeUIInfoType</span> Values</b>        </p>        <table border="1" bgcolor="#E0E0E0" cellspacing="0"        cellpadding="4" class="CALSTABLE">          <tr>            <th align="LEFT" valign="TOP">              <span class="STRUCTNAME">GnomeUIInfoType</span>            </th>            <th align="LEFT" valign="TOP">              Description            </th>            <th align="LEFT" valign="TOP">              <span class="STRUCTNAME">moreinfo</span> Field            </th>          </tr>          <tr>            <td align="LEFT" valign="TOP">              <span class="STRUCTNAME">              GNOME_APP_UI_ENDOFINFO</span>            </td>            <td align="LEFT" valign="TOP">              Terminates a table of <span class="STRUCTNAME">              GnomeUIInfo</span>            </td>            <td align="LEFT" valign="TOP">              None            </td>          </tr>          <tr>            <td align="LEFT" valign="TOP">              <span class="STRUCTNAME">GNOME_APP_UI_ITEM</span>            </td>            <td align="LEFT" valign="TOP">              Normal item (or radio item inside radio group)            </td>            <td align="LEFT" valign="TOP">              Callback function            </td>          </tr>          <tr>            <td align="LEFT" valign="TOP">              <span class="STRUCTNAME">              GNOME_APP_UI_TOGGLEITEM</span>            </td>            <td align="LEFT" valign="TOP">              Toggle/check item            </td>            <td align="LEFT" valign="TOP">              Callback function            </td>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -