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

📄 z170.html

📁 gtk_text program sample&eg
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>  <head>    <title>      GnomeAppBar: A Trivial Composite Widget    </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="Writing a GtkWidget" href=    "cha-widget.html">    <link rel="PREVIOUS" title="GtkVBox: A Windowless Container"    href="z166.html">    <link rel="NEXT" title="Other Examples" href="z171.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="z166.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="z171.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="Z170"><tt class="CLASSNAME">GnomeAppBar</tt>: A        Trivial Composite Widget</a>      </h1>      <p>        This section quickly describes the <tt class="CLASSNAME">        GnomeAppBar</tt> widget; <tt class="CLASSNAME">        GnomeAppBar</tt> demonstrates how to bundle a pre-packed        container and some special functionality into a single new        object. <a href="z91.html#SEC-APPBAR">the section called        <i><tt class="CLASSNAME">GnomeAppBar</tt></i> in the        chapter called <i>The Main Window: <tt class="CLASSNAME">        GnomeApp</tt></i></a> describes <tt class="CLASSNAME">        GnomeAppBar</tt> from a user's point of view.      </p>      <p>        A composite widget derives from some kind of container,        then adds child widgets and sets up callbacks to implement        some sort of functionality. <tt class="CLASSNAME">        GnomeAppBar</tt> derives from <tt class="CLASSNAME">        GtkHBox</tt>; the box is packed with a progress bar and/or        a status line. <tt class="CLASSNAME">GnomeAppBar</tt> has        members in its instance struct to store a stack of status        messages, and it adds some signals to the class struct for        use with its "interactive" mode.      </p>      <p>        As an aside, <tt class="CLASSNAME">GnomeAppBar</tt> does        not follow the GTK+/Gnome naming conventions; because <span        class="STRUCTNAME">Bar</span> is capitalized, the functions        and macros should have an underscore, i.e. <span class=         "STRUCTNAME">app_bar</span> rather than <span class=         "STRUCTNAME">appbar</span>. Don't copy this aspect of the        widget.      </p>      <p>        Here's the implementation of <tt class="FUNCTION">        gnome_appbar_new()</tt>:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;GtkWidget* gnome_appbar_new (gboolean has_progress,                  gboolean has_status,                  GnomePreferencesType interactivity){  GnomeAppBar * ab = gtk_type_new (gnome_appbar_get_type ());  gnome_appbar_construct(ab, has_progress, has_status, interactivity);  return GTK_WIDGET(ab);}voidgnome_appbar_construct(GnomeAppBar * ab,                       gboolean has_progress,                       gboolean has_status,                       GnomePreferencesType interactivity){  GtkBox *box;  g_return_if_fail( ((has_status == FALSE) &amp;&amp;                      (interactivity == GNOME_PREFERENCES_NEVER)) ||                    (has_status == TRUE));   box = GTK_BOX (ab);  box-&gt;spacing = GNOME_PAD_SMALL;  box-&gt;homogeneous = FALSE;  if (has_progress)    ab-&gt;progress = gtk_progress_bar_new();  else    ab-&gt;progress = NULL;  /*   * If the progress meter goes on the right then we place it after we   * create the status line.   */  if (has_progress &amp;&amp; !gnome_preferences_get_statusbar_meter_on_right ())    gtk_box_pack_start (box, ab-&gt;progress, FALSE, FALSE, 0);  if ( has_status ) {    if ( (interactivity == GNOME_PREFERENCES_ALWAYS) ||         ( (interactivity == GNOME_PREFERENCES_USER) &amp;&amp;           gnome_preferences_get_statusbar_interactive()) ) {      ab-&gt;interactive = TRUE;         ab-&gt;status = gtk_entry_new();      gtk_signal_connect (GTK_OBJECT(ab-&gt;status), "delete_text",                          GTK_SIGNAL_FUNC(entry_delete_text_cb),                          ab);      gtk_signal_connect (GTK_OBJECT(ab-&gt;status), "insert_text",                          GTK_SIGNAL_FUNC(entry_insert_text_cb),                          ab);      gtk_signal_connect_after(GTK_OBJECT(ab-&gt;status), "key_press_event",                               GTK_SIGNAL_FUNC(entry_key_press_cb),                               ab);      gtk_signal_connect(GTK_OBJECT(ab-&gt;status), "activate",                         GTK_SIGNAL_FUNC(entry_activate_cb),                         ab);      /* no prompt now */      gtk_entry_set_editable(GTK_ENTRY(ab-&gt;status), FALSE);      gtk_box_pack_start (box, ab-&gt;status, TRUE, TRUE, 0);    }    else {      GtkWidget * frame;            ab-&gt;interactive = FALSE;      frame = gtk_frame_new (NULL);      gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN);            ab-&gt;status = gtk_label_new ("");      gtk_misc_set_alignment (GTK_MISC (ab-&gt;status), 0.0, 0.0);            gtk_box_pack_start (box, frame, TRUE, TRUE, 0);      gtk_container_add (GTK_CONTAINER(frame), ab-&gt;status);            gtk_widget_show (frame);    }  }  else {    ab-&gt;status = NULL;    ab-&gt;interactive = FALSE;  }  if (has_progress &amp;&amp; gnome_preferences_get_statusbar_meter_on_right ())    gtk_box_pack_start (box, ab-&gt;progress, FALSE, FALSE, 0);  if (ab-&gt;status) gtk_widget_show (ab-&gt;status);  if (ab-&gt;progress) gtk_widget_show(ab-&gt;progress);}    </pre>          </td>        </tr>      </table>      <p>        Most of this code could be in the instance initializer;        it's in the constructor instead because it's dependent on        the arguments passed to <tt class="FUNCTION">        gnome_appbar_new()</tt>. There's not much to explain here;        the code is straightforward. Do notice that <tt class=         "FUNCTION">gtk_widget_show()</tt> is called for each child        widget; this ensures that the right thing happens when the        user calls <tt class="FUNCTION">gtk_widget_show()</tt> on        <tt class="CLASSNAME">GnomeAppBar</tt>. Another approach        would be to override the map method and map all children        (normally, containers such as <tt class="CLASSNAME">        GtkBox</tt> only map children that have been shown). When        you're writing a composite container, keep the <tt class=         "FUNCTION">gtk_widget_show_all()</tt> function in mind;        never rely on hiding child widgets, because the user might        accidentally show them.      </p>      <p>        A composite widget is just a special case of extending a        base widget with additional functionality. You can extend        widgets without adding new children to them; for example,        <tt class="CLASSNAME">GtkClock</tt> extends <tt class=         "CLASSNAME">GtkLabel</tt> by constantly changing the label        to reflect the time.      </p>    </div>    <div class="NAVFOOTER">      <br>      <br>      <table width="100%" border="0" bgcolor="#ffffff" cellpadding=       "1" cellspacing="0">        <tr>          <td width="25%" bgcolor="#ffffff" align="left">            <a href="z166.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="z171.html"><font color="#0000ff" size="2"><b>            Next &gt;&gt;&gt;</b></font></a>          </td>        </tr>        <tr>          <td colspan="2" align="left">            <font color="#000000" size="2"><b><tt class=            "CLASSNAME">GtkVBox</tt>: A Windowless            Container</b></font>          </td>          <td colspan="2" align="right">            <font color="#000000" size="2"><b>Other            Examples</b></font>          </td>        </tr>      </table>    </div>  </body></html>

⌨️ 快捷键说明

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