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

📄 ch-widgetoverview.html

📁 gtk 开发手册和参考文档。 包括gtk glib gdk等
💻 HTML
字号:
<HTML><HEAD><TITLE>Widget Overview</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="PREVIOUS"TITLE="Table Packing Example"HREF="sec-tablepackingexamples.html"><LINKREL="NEXT"TITLE="Widget Hierarchy"HREF="sec-widgethierarchy.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%">  <tr>    <td bgcolor="#FFFFFF" valign=top nowrap>    <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A>      <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR>      </td>  <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="CHAPTER"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-tablepackingexamples.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-widgethierarchy.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="CH-WIDGETOVERVIEW">Chapter 5. Widget Overview</A></H1><DIVCLASS="TOC"><DL><DT><B>Table of Contents</B></DT><DT>5.1. <AHREF="ch-widgetoverview.html#SEC-CASTING">Casting</A></DT><DT>5.2. <AHREF="sec-widgethierarchy.html">Widget Hierarchy</A></DT><DT>5.3. <AHREF="sec-widgetswithoutwindows.html">Widgets Without Windows</A></DT></DL></DIV><P>The general steps to creating a widget in GTK are:</P><P></P><OLTYPE="1"><LI><P> gtk_*_new - one of various functions to create a new widget.These are all detailed in this section.</P></LI><LI><P> Connect all signals and events we wish to use to theappropriate handlers.</P></LI><LI><P> Set the attributes of the widget.</P></LI><LI><P> Pack the widget into a container using the appropriate callsuch as gtk_container_add() or gtk_box_pack_start().</P></LI><LI><P> gtk_widget_show() the widget.</P></LI></OL><P>gtk_widget_show() lets GTK know that we are done setting theattributes of the widget, and it is ready to be displayed. You mayalso use gtk_widget_hide to make it disappear again. The order inwhich you show the widgets is not important, but I suggest showing thewindow last so the whole window pops up at once rather than seeing theindividual widgets come up on the screen as they're formed. Thechildren of a widget (a window is a widget too) will not be displayeduntil the window itself is shown using the gtk_widget_show() function.</P><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-CASTING">5.1. Casting</A></H1><P>You'll notice as you go on that GTK uses a type casting system. Thisis always done using macros that both test the ability to cast thegiven item, and perform the cast. Some common ones you will see are:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">  GTK_WIDGET(widget)  GTK_OBJECT(object)  GTK_SIGNAL_FUNC(function)  GTK_CONTAINER(container)  GTK_WINDOW(window)  GTK_BOX(box)</PRE></TD></TR></TABLE><P>These are all used to cast arguments in functions. You'll see them in theexamples, and can usually tell when to use them simply by looking at thefunction's declaration.</P><P>As you can see below in the class hierarchy, all GtkWidgets arederived from the Object base class. This means you can use a widgetin any place the function asks for an object - simply use the<TTCLASS="LITERAL">GTK_OBJECT()</TT> macro.</P><P>For example:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gtk_signal_connect( GTK_OBJECT(button), "clicked",                    GTK_SIGNAL_FUNC(callback_function), callback_data);</PRE></TD></TR></TABLE><P>This casts the button into an object, and provides a cast for thefunction pointer to the callback.</P><P>Many widgets are also containers. If you look in the class hierarchybelow, you'll notice that many widgets derive from the Containerclass. Any one of these widgets may be used with the<TTCLASS="LITERAL">GTK_CONTAINER</TT> macro to pass them to functions that ask forcontainers.</P><P>Unfortunately, these macros are not extensively covered in thetutorial, but I recommend taking a look through the GTK headerfiles. It can be very educational. In fact, it's not difficult tolearn how a widget works just by looking at the function declarations.</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sec-tablepackingexamples.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sec-widgethierarchy.html">Next &#62;&#62;&#62;</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Table Packing Example</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top">&nbsp;</TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Widget Hierarchy</TD></TR></TABLE></DIV>        </td>    </tr></table>  </td>  </tr></table></body></BODY></HTML>

⌨️ 快捷键说明

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