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

📄 sec-style.html

📁 gtk_text program sample&eg
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>  <head>    <title>      GtkStyle and Themes    </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="GDK Basics" href="cha-gdk.html">    <link rel="PREVIOUS" title="GDK Resource Management" href=     "sec-gdkresourcemgmt.html">    <link rel="NEXT" title="Writing a GtkWidget" href=     "cha-widget.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="sec-gdkresourcemgmt.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="cha-widget.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-STYLE"><span class="STRUCTNAME">        GtkStyle</span> and Themes</a>      </h1>      <p>        <span class="STRUCTNAME">GtkStyle</span> is not part of        GDK, but it is an important abstraction layer between GTK+        and GDK that allows users to customize how widgets are        rendered. Instead of drawing with GDK directly, widgets        should prefer GDK resources from a <span class=        "STRUCTNAME">GtkStyle</span>, and special drawing functions        provided in <tt class="FILENAME">gtk/gtkstyle.h</tt>. Often        there is no appropriate function, but when there is it        should be used.      </p>      <p>        A <span class="STRUCTNAME">GtkStyle</span> stores GDK        resources to be used when drawing widgets. Styles allow        widgets to share these resources, reducing overhead; they        also permit users to customize GTK+'s appearance. Here is        the <span class="STRUCTNAME">GtkStyle</span> struct:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;typedef struct _GtkStyle GtkStyle;struct _GtkStyle{  GtkStyleClass *klass;  GdkColor fg[5];  GdkColor bg[5];  GdkColor light[5];  GdkColor dark[5];  GdkColor mid[5];  GdkColor text[5];  GdkColor base[5];    GdkColor black;  GdkColor white;  GdkFont *font;    GdkGC *fg_gc[5];  GdkGC *bg_gc[5];  GdkGC *light_gc[5];  GdkGC *dark_gc[5];  GdkGC *mid_gc[5];  GdkGC *text_gc[5];  GdkGC *base_gc[5];  GdkGC *black_gc;  GdkGC *white_gc;    GdkPixmap *bg_pixmap[5];    /* private */    gint ref_count;  gint attach_count;    gint depth;  GdkColormap *colormap;    GtkThemeEngine *engine;    gpointer        engine_data;    GtkRcStyle     *rc_style;  GSList         *styles;};&#13;</pre>          </td>        </tr>      </table>      <p>        The private fields should be ignored. The public fields        contain GDK resources for widget rendering. The first group        of fields contains arrays of colors; these arrays are        indexed by the widget state enumeration (<span class=         "STRUCTNAME">GTK_STATE_ACTIVE</span>, etc.). A widget might        use <span class="STRUCTNAME">        widget-&gt;style-&gt;fg[GTK_STATE_NORMAL]</span> to render        text, for example. Each widget has an associated style,        stored in the <span class="STRUCTNAME">style</span> field        of <tt class="CLASSNAME">GtkWidget</tt>.      </p>      <p>        Widgets should use the font stored in their associated        <span class="STRUCTNAME">GtkStyle</span>; they should use        the style's graphics contexts when drawing in the style's        colors.      </p>      <p>        <span class="STRUCTNAME">GtkStyle</span> also contains a        virtual table, <span class="STRUCTNAME">        GtkStyleClass</span>, which can be implemented by a        dynamically-loaded theme engine. The virtual table is quite        large, so it isn't reproduced here. Have a look at <tt        class="FILENAME">gtk/gtkstyle.h</tt>.      </p>      <p>        <tt class="FILENAME">gtk/gtkstyle.h</tt> contains drawing        functions that use a style's virtual table to draw various        GUI elements. There are two variants of each drawing        function. One variant, prefixed with <span class=        "STRUCTNAME">gtk_draw_</span>, renders to any drawable; the        other variant, prefixed with <span class="STRUCTNAME">        gtk_paint_</span>, renders part of a widget. For example,        <tt class="FUNCTION">gtk_draw_shadow()</tt> looks like        this:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;void gtk_draw_shadow  (GtkStyle      *style,                       GdkWindow     *window,                       GtkStateType   state_type,                       GtkShadowType  shadow_type,                       gint           x,                       gint           y,                       gint           width,                       gint           height);&#13;</pre>          </td>        </tr>      </table>      <p>        While <tt class="FUNCTION">gtk_paint_shadow()</tt> adds        <span class="STRUCTNAME">area</span>, <span class=         "STRUCTNAME">widget</span>, and <span class="STRUCTNAME">        detail</span> arguments:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;void gtk_paint_shadow  (GtkStyle     *style,                        GdkWindow    *window,                        GtkStateType  state_type,                        GtkShadowType shadow_type,                        GdkRectangle  *area,                        GtkWidget     *widget,                        gchar         *detail,                        gint           x,                        gint           y,                        gint           width,                        gint           height);&#13;</pre>          </td>        </tr>      </table>      <p>        Each of these corresponds to the <span class="STRUCTNAME">        draw_shadow</span> member in <span class="STRUCTNAME">        GtkStyleClass</span>.      </p>      <p>        All <span class="STRUCTNAME">gtk_paint_</span> functions        add the same three arguments to their <span class=         "STRUCTNAME">gtk_draw_</span> counterparts; the <span        class="STRUCTNAME">area</span> argument is a clipping        rectangle, the <span class="STRUCTNAME">widget</span>        argument is the widget being drawn to, and the <span class=         "STRUCTNAME">detail</span> argument is a hint used by theme        engines. Here's a call to <tt class="FUNCTION">        gtk_paint_shadow()</tt> from the <tt class="CLASSNAME">        GtkEntry</tt> source code, for example:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;  gtk_paint_shadow (widget-&gt;style, widget-&gt;window,                    GTK_STATE_NORMAL, GTK_SHADOW_IN,                    NULL, widget, "entry",                    x, y, width, height);&#13;</pre>          </td>        </tr>      </table>      <p>        Here the <span class="STRUCTNAME">area</span> argument is        <span class="STRUCTNAME">NULL</span>, specifying that no        clipping should be used.      </p>      <p>        Because there are a couple dozen functions in <span class=         "STRUCTNAME">GtkStyleClass</span>, and there are numerous        examples in the GTK+ source code, this book won't describe        them in detail. When writing your own widgets, simply        locate a GTK+ widget that draws a similar graphical        element, and use the same <span class="STRUCTNAME">        gtk_paint_</span> function it uses.      </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="sec-gdkresourcemgmt.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="cha-widget.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>GDK Resource            Management</b></font>          </td>          <td colspan="2" align="right">            <font color="#000000" size="2"><b>Writing a <tt class=             "CLASSNAME">GtkWidget</tt></b></font>          </td>        </tr>      </table>    </div>  </body></html>

⌨️ 快捷键说明

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