Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->系统管理 ->正文

GTK v1.2 Tutorial(英文)

来源:Linux-cn.com 作者:Webmaster 时间:2007-05-05 点击: [收藏] [投稿]

10.4 Layout Container

  The Layout container is similar to the Fixed container except that it implements an infinite (where infinity is less than 2^32) scrolling area. The X window system has a limitation where windows can be at most 32767 pixels wide or tall. The Layout container gets around this limitation by doing some exotic stuff using window and bit gravities, so that you can have smooth scrolling even when you have many child widgets in your scrolling area.

  A Layout container is created using:


GtkWidget *gtk_layout_new( GtkAdjustment *hadjustment,
 GtkAdjustment *vadjustment );

  As you can see, you can optionally specify the Adjustment objects that the Layout widget will use for its scrolling.

  You can add and move widgets in the Layout container using the following two functions:


void gtk_layout_put( GtkLayout *layout,
GtkWidget *widget,gint x,gint y );
void gtk_layout_move( GtkLayout *layout,
GtkWidget *widget,gint x,gint y );

  The size of the Layout container can be set using the next function:


void gtk_layout_set_size( GtkLayout *layout,
guintwidth,guintheight );

  Layout containers are one of the very few widgets in the GTK widget set that actively repaint themselves on screen as they are changed using the above functions (the vast majority of widgets queue requests which are then processed when control returns to the gtk_main() function).

  When you want to make a large number of changes to a Layout container, you can use the following two functions to disable and re-enable this repainting functionality:


void gtk_layout_freeze( GtkLayout *layout );
void gtk_layout_thaw( GtkLayout *layout );

  The final four functions for use with Layout widgets are for manipulating the horizontal and vertical adjustment widgets:


GtkAdjustment* gtk_layout_get_hadjustment( GtkLayout *layout );
GtkAdjustment* gtk_layout_get_vadjustment( GtkLayout *layout );
void gtk_layout_set_hadjustment( GtkLayout *layout,
GtkAdjustment *adjustment );
void gtk_layout_set_vadjustment( GtkLayout *layout,
GtkAdjustment *adjustment);

10.5 Frames

  Frames can be used to enclose one or a group of widgets with a box which can optionally be labelled. The position of the label and the style of the box can be altered to suit.

  A Frame can be created with the following function:


GtkWidget *gtk_frame_new( const gchar *label );

  The label is by default placed in the upper left hand corner of the frame. A value of NULL for the label argument will result in no label being displayed. The text of the label can be changed using the next function.


void gtk_frame_set_label( GtkFrame*frame,const gchar *label );

  The position of the label can be changed using this function:


void gtk_frame_set_label_align( GtkFrame *frame,
gfloatxalign,gfloatyalign );

  xalign and yalign take values between 0.0 and 1.0. xalign indicates the position of the label along the top horizontal of the frame. yalign is not currently used. The default value of xalign is 0.0 which places the label at the left hand end of the frame.

  The next function alters the style of the box that is used to outline the frame.


void gtk_frame_set_shadow_type( GtkFrame*frame,GtkShadowTypetype);

  The type argument can take one of the following values:

  GTK_SHADOW_NONE

  GTK_SHADOW_IN

  GTK_SHADOW_OUT

  GTK_SHADOW_ETCHED_IN (the default)

  GTK_SHADOW_ETCHED_OUT

  The following code example illustrates the use of the Frame widget.


/* example-start frame frame.c */
#include <gtk/gtk.h>
int main( int argc,
char *argv[] )
{
/* GtkWidget is the storage type for widgets */
GtkWidget *window;
GtkWidget *frame;
GtkWidget *button;
gint i;
/* Initialise GTK */
gtk_init(&argc, &argv);
/* Create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Frame Example");
/* Here we connect the "destroy" event to a signal handler */ 
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_widget_set_usize(window, 300, 300);
/* Sets the border width of the window. */
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
/* Create a Frame */
frame = gtk_frame_new(NULL);
gtk_container_add(GTK_CONTAINER(window), frame);
/* Set the frame's label */
gtk_frame_set_label( GTK_FRAME(frame), "GTK Frame Widget" );
/* Align the label at the right of the frame */
gtk_frame_set_label_align( GTK_FRAME(frame), 1.0, 0.0);
/* Set the style of the frame */
gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_ETCHED_OUT);
gtk_widget_show(frame);
/* Display the window */
gtk_widget_show (window);
/* Enter the event loop */
gtk_main ();
return(0);
}
/* example-end */


 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:GTK入门导引   下一篇:GDK Reference Manual

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号