?? tnw-tut-5.html
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD> <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9"> <TITLE>The TinyWidgets Tutorial: The Widgets</TITLE> <LINK HREF="tnw-tut-6.html" REL=next> <LINK HREF="tnw-tut-4.html" REL=previous> <LINK HREF="tnw-tut.html#toc5" REL=contents></HEAD><BODY><A HREF="tnw-tut-6.html">Next</A><A HREF="tnw-tut-4.html">Previous</A><A HREF="tnw-tut.html#toc5">Contents</A><HR><H2><A NAME="s5">5. The Widgets</A></H2><H2><A NAME="TN_WINDOW"></A> <A NAME="ss5.1">5.1 TN_WINDOW</A></H2><P><P><H3>Introduction</H3><P>This is the Window widget. For every application you will need atleast one window. All other widgets can be added to a Window widget. The parent for the window widget must be the widget returned by <I>tnAppInitialize</I>. <P><H3>Specifications</H3><P>A Window can take the following optional properties in the call to <I>tnCreateWidget</I>.<UL><LI>TN_BGCOLOR : Background color for the window (defaults to grey).</LI><LI>TN_CAPTION : The window title. The default window title is "Window".</LI></UL><P>Examples:<P>A window specification with a window title "My App"<P><BLOCKQUOTE><CODE><HR><PRE>window1 = tnCreateWidget(TN_WINDOW,main_widget,50,50,TN_HEIGHT,200,TN_WIDTH,200,TN_CAPTION,"My App",TN_END);</PRE><HR></CODE></BLOCKQUOTE><P><H3>Callbacks</H3><P>The following callbacks can be specified when calling <I>tnRegisterCallBack</I> for a window.<UL><LI> CLICKED : Event occurs when user clicks on the window.</LI><LI> CLOSED : Event occurs when user clicks on the close button of the window. If the user wishes to terminate his application with the closing of a particular window, he must call <A HREF="tnw-tut-3.html#tnEndApp">tnEndApp</A> in this callback.</LI></UL><P><H3>Utility Functions</H3><P>The following utility functions have been provided to manipulate the properties of the window<P><BLOCKQUOTE><CODE><HR><PRE>tnGetClickedPos(TN_WIDGET *window, int *x, int *y)</PRE><HR></CODE></BLOCKQUOTE>Description : Returns the x and y co-ordinates where the last clicked event occured on the window. The co-ordinates are relative to the upper left corner of the window.<P><BLOCKQUOTE><CODE><HR><PRE>tnGetWindowTitle(TN_WIDGET *window, char *title)</PRE><HR></CODE></BLOCKQUOTE>Returns : The currently set title of the window.<P><BLOCKQUOTE><CODE><HR><PRE>tnSetWindowTitle(TN_WIDGET *window, char *title)</PRE><HR></CODE></BLOCKQUOTE>Description : Sets the window title as specified.<P><P><H2><A NAME="TN_BUTTON"></A> <A NAME="ss5.2">5.2 TN_BUTTON</A></H2><P><P><H3>Introduction</H3><P>This is the Push Button widget. It can be placed inside a window widget. The push button supports either a text caption or a pixmap as its face.<P><H3>Specifications</H3><P>By default a button has a caption which is set to "Button".The following properties can be specified optionally for a button while calling <I>tnCreateWidget</I><UL><LI>TN_PIXMAP : Set to TN_TRUE if pixmap on the button is to be specified.</LI><LI>TN_CAPTION : Specifies the caption to be used when TN_PIXMAP is not set.</LI><LI>TN_FILENAME : Specifies the pixmap filename if TN_PIXMAP is set.</LI></UL>Examples:<P>A button specification with pixmap file "/usr/share/pixmaps/foo.xpm"<P><BLOCKQUOTE><CODE><HR><PRE>mybutton=tnCreateWidget(TN_BUTTON,mywindow,10,10,TN_HEIGHT,50,TN_WIDTH,50, TN_PIXMAP,TN_TRUE, TN_FILENAME,"/usr/share/pixmaps/foo.xpm", TN_END); </PRE><HR></CODE></BLOCKQUOTE><P>A button with default values and a caption "TinyWidgets"<BLOCKQUOTE><CODE><HR><PRE>mybutton=tnCreateWidget(TN_BUTTON,mywindow,10,10, TN_CAPTION,"TinyWidgets", TN_END);</PRE><HR></CODE></BLOCKQUOTE><P><P><H3>Callbacks</H3><P>The following callbacks can be specified while calling <I>tnRegisterCallBack</I> for a button.<UL><LI>CLICKED : Event occurs when user clicks and releases the button.</LI></UL><P><H3>Utility Functions</H3><P>The following utility functions can be used for a button to access and change its properties.<BLOCKQUOTE><CODE><HR><PRE>int tnGetButtonPressed(TN_WIDGET *widget)</PRE><HR></CODE></BLOCKQUOTE>Description: Get the button number for the last CLICKED event on the button.<P>Returns: A mask containing set bits for number of mouse buttons which were involved in the clicked event.<BLOCKQUOTE><CODE><HR><PRE>int tnSetButtonPixmap(TN_WIDGET *widget,char *filename)</PRE><HR></CODE></BLOCKQUOTE>Description: Sets pixmap for the face of a button.<P>Returns: 1 on success, -1 on failure.<BLOCKQUOTE><CODE><HR><PRE>int tnRemoveButtonPixmap(TN_WIDGET *widget)</PRE><HR></CODE></BLOCKQUOTE>Description: Removes a pixmap on the face of the button and sets empty caption.<P>Returns: 1 on success, -1 on failure.<BLOCKQUOTE><CODE><HR><PRE>int tnSetButtonCaption(TN_WIDGET *widget,char *caption)</PRE><HR></CODE></BLOCKQUOTE>Description: Sets a caption on the face of a button.<P>Returns: 1 on success, 0 if a pixmap already present on button, -1 on failure.<BLOCKQUOTE><CODE><HR><PRE>int tnGetButtonCaption(TN_WIDGET *widget,char *caption)</PRE><HR></CODE></BLOCKQUOTE>Description: Copies the caption of the button into the string pointed by <I>caption</I><P>Returns: 1 on success, -1 on failure.<BLOCKQUOTE><CODE><HR><PRE>TN_HASPIXMAP(TN_WIDGET *widget)</PRE><HR></CODE></BLOCKQUOTE>Description: This is a macro that returns 1 if the face of the button is a pixmap , 0 otherwise.<P>Returns: 1 if face has a pixmap, 0 otherwise.<H2><A NAME="TN_LABEL"></A> <A NAME="ss5.3">5.3 TN_LABEL</A></H2><P>This is the static label widget. It provides the facility of adding static text labels to a window widget. The label supports various fonts,font sizes and colors. By default the label is black colored and automatically resizes itself according to the font size.<H3>Specifications</H3><P>By default a label has a caption which is set to "Label".The following properties can be specified optionally for a label while calling <I>tnCreateWidget</I><P><UL><LI>TN_CAPTION : Specifies the caption to be used for the label.</LI><LI>TN_FONTNAME : Specifies the name of the font to be used for the label.</LI><LI>TN_FONTSIZE : Specifies the font size to be used for the label.</LI><LI>TN_FGCOLOR : Specifies the foreground color to be used for the label.</LI><LI>TN_BGCOLOR : Specifies the background color to be used for the label.</LI></UL><P>Examples:<P>A label specification with foreground black,background white and caption "Hello World!"<P><BLOCKQUOTE><CODE><HR><PRE>mylabel=tnCreateWidget(TN_LABEL,mywindow,10,10, TN_CAPTION,"Hello World!", TN_BGCOLOR,TN_RGB(255,255,255), TN_FGCOLOR,TN_RGB(0,0,0), TN_END); </PRE><HR></CODE></BLOCKQUOTE><P>A label with a caption "TinyWidgets",and with <I>courier new</I> font, size 16 points <BLOCKQUOTE><CODE><HR><PRE>mylabel=tnCreateWidget(TN_LABEL,mywindow,10,10, TN_FONTNAME,"cour", TN_FONTSIZE,16, TN_CAPTION,"TinyWidgets", TN_END);</PRE><HR></CODE></BLOCKQUOTE><P><H3>Callbacks</H3><P>The following callbacks can be specified while calling <I>tnRegisterCallBack</I> for a label.<UL><LI>CLICKED : Event occurs when user clicks and releases the label.</LI></UL><P><H3>Utility Functions</H3><P>The following utility functions can be used for a label to access and change its properties.<P><BLOCKQUOTE><CODE><HR><PRE>int tnSetLabelCaption(TN_WIDGET *widget, char *caption)</PRE><HR></CODE></BLOCKQUOTE>Description: Sets the caption for a label to <I>caption</I><P>Returns: 1 on success, -1 on failure.<P><BLOCKQUOTE><CODE><HR><PRE>int tnSetLabelCaptionColor(TN_WIDGET *widget, TN_COLOR color)</PRE><HR></CODE></BLOCKQUOTE>Description: Sets the color of the caption to <I>color</I> for the label<P>Returns: 1 on success, -1 on error.<P><BLOCKQUOTE><CODE><HR><PRE>TN_COLOR tnGetLabelCaptionColor(TN_WIDGET *widget)</PRE><HR></CODE></BLOCKQUOTE>Description: Gets the color of caption for the label <P>Returns: The color of caption on success , -1 on error.<BLOCKQUOTE><CODE><HR><PRE>int tnGetLabelCaption(TN_WIDGET *widget,char *caption)</PRE><HR></CODE></BLOCKQUOTE>Description: Gets the caption for the label.<P>Returns: 1 on success, -1 on failure.<H2><A NAME="TN_CHECKBUTTON"></A> <A NAME="ss5.4">5.4 TN_CHECKBUTTON</A></H2><P><H3>Introduction</H3><P>This is the checkbutton widget. It can be placed inside a window widget. It is like a toggle button.<H3>Specification</H3><P>The following properties can be optionally set via the <I>tnCreateWidget</I> call:<UL><LI> TN_CAPTION: The text to be displayed in the check button. It defaults to "Check Button"</LI><LI> TN_FONTNAME: The font (if installed) in which the text is to be displayed.</LI><LI> TN_FONTSIZE: The size of the font in which the text is to be displayed.</LI><LI> TN_FGCOLOR: The color in which the text is to be displayed.</LI><LI> TN_BGCOLOR: The background color of the checkbutton.</LI></UL>Examples:<P>A checkbutton with a caption of "TinyWidgets", to be displayed in Courier Font and fontsize 8.<P><BLOCKQUOTE><CODE><HR><PRE>checkbtn0 = tnCreateWidget(TN_CHECKBUTTON,window0,35,45,TN_FONTNAME,"cour",TN_FONTSIZE,8,TN_CAPTION,"TinyWidgets",TN_END);</PRE><HR></CODE></BLOCKQUOTE><P><H3>Callbacks</H3><P>The following callbacks can be registered for a checkbutton via <I>tnRegisterCallBack</I>.<UL><LI> CLICKED : This event occurs when the user clicks on the checkbutton.</LI></UL><H3>Utility Functions</H3><P>The following utility functions have been provided to manipulate the checkbutton<P><BLOCKQUOTE><CODE><HR><PRE>int tnGetCheckButtonCaption(TN_WIDGET *checkbutton, char *caption)</PRE><HR></CODE></BLOCKQUOTE>Description : Returns the currently set caption of the checkbutton.<P><BLOCKQUOTE><CODE><HR><PRE>int tnSetCheckButtonCaption(TN_WIDGET *checkbutton, char *caption)</PRE><HR></CODE></BLOCKQUOTE>Description : Sets the caption of the checkbutton.<P><BLOCKQUOTE><CODE><HR><PRE>int tnSetCheckButtonStatus(TN_WIDGET *checkbutton, TN_BOOL status)</PRE><HR></CODE></BLOCKQUOTE>Description : Sets the status of the checkbutton as specified.<P><BLOCKQUOTE><CODE><HR><PRE>TN_CHECKBUTTONACTIVE(checkbutton)</PRE><HR></CODE></BLOCKQUOTE>Description : A macro which tests if the checkbutton is active.<P><P><H2><A NAME="TN_RADIOBUTTONGROUP"></A> <A NAME="ss5.5">5.5 TN_RADIOBUTTONGROUP</A></H2><P><H3>Introduction</H3><P>This is the radio button group widget. It can be placed inside a window widget. A radio button group needs to be created for grouping radio buttons. All radio buttons in a group will behave in a mutually exclusive manner. <H3>Specification</H3><P>The default caption for a radio button group is "RadioButton Group". The following properties can be optionally set via the <I>tnCreateWidget</I> call:<UL><LI>TN_CAPTION : The radio button group caption text.</LI></UL><H3>Callbacks</H3><P>The following callbacks can be registered via <I>tnRegisterCallBack</I><UL><LI>CLICKED : a pointer click occurs anywhere withing the radio button group.</LI><LI>SELECTED : a radio button within the group has been selected.</LI></UL><H3>Utility Functions</H3><P><BLOCKQUOTE><CODE><HR><PRE>int tnSetRadioButtonGroupCaption(TN_WIDGET *widget,char *caption)</PRE><HR></CODE></BLOCKQUOTE>Description: Sets the radio button group caption text.<P>Returns: 1 on success. -1 on failure.<BLOCKQUOTE><CODE><HR><PRE>int tnGetRadioButtonGroupCaption(TN_WIDGET *widget,char *caption)</PRE><HR></CODE></BLOCKQUOTE>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -