/*
*
* Sample Code for Gtk+ Programming in C, 1st Edition, Prentice Hall
*
* Copyright 2000 - 2002 Syd Logan, All Rights Reserved
*
* This code is distributed without warranty. You are free to use this
* code for any purpose, however, if this code is republished or
* redistributed in its original form, as hardcopy or electronically,
* then you must include this copyright notice along with the code.
*
* Questions or comments regarding this code or any bugs it contains can
* be directed to the author via e-mail at slogan@cts.com
*
*/
#include <gtk/gtk.h>
// forward declarations to avoid compiler warnings
void ResetSettingsMenuItems( void );
void UpdateChildren( void );
void MessageBox( char *message );
#define VERSION_MAJOR 1
#define VERSION_MINOR 0
// some globals to make life easy
static GtkWidget *container;
static GNode *root;
static GNode *current;
static int n = 1;
// tree node
typedef struct _boxdata {
GtkWidget *container; // the vbox or hbox instance
int spacing; // current spacing
gboolean homogeneous; // current homogeneous
int padding; // current padding
gboolean fill; // current child fill
gboolean expand; // current child expand
} BoxData;
// used to hold callback data for settings dialog
typedef struct _settingsData {
GtkWidget *dialog; // Padding/Spacing dialog
GtkWidget *pad_entry; // Padding entry widget
GtkWidget *space_entry; // Space entry widget
} SettingsData;
static SettingsData settingsData; // dialog is modal, only need one
// dump tree to stdout
gboolean
traverse_func( GNode *node, gpointer data )
{
int i;
// indent
for ( i = 0; i < g_node_depth( node ) - 1; i++ )
printf( " " );
// print the node
printf( "Node %x parent %x [%x] %s %s\n", node, node->parent,
((BoxData *) node->data)->container,
(GTK_IS_VBOX(((BoxData *)node->data)->container)
? "VBox" : "Hbox" ), (node == current ? "<--" : "" ) );
return( FALSE ); // continue traversal
}
void
dump_tree( gpointer data, guint callback_action, GtkWidget *w )
{
printf( "Tree Dump ********************************************************************\n" );
printf( "<-- is current box\n" );
g_node_traverse( root, G_PRE_ORDER, G_TRAVERSE_ALL, 999,
traverse_func, NULL );
}
// traversal functions
static void
go_up( gpointer data, guint callback_action, GtkWidget *w )
{
if ( current != root ) {
current = current->parent;
container = (GtkWidget *)((BoxData *)current->data)->container;
}
dump_tree( (gpointer) NULL, 0, (GtkWidget *) NULL );
ResetSettingsMenuItems();
}
static void
go_down( gpointer data, guint callback_action, GtkWidget *w )
{
GNode *node;
node = g_node_first_child( current );
if ( node != (GNode *) NULL )
current = node;
container = (GtkWidget *)((BoxData *)current->data)->container;
dump_tree( (gpointer) NULL, 0, (GtkWidget *) NULL );
ResetSettingsMenuItems();
}
static void
go_previous( gpointer data, guint callback_action, GtkWidget *w )
{
GNode *node;
node = g_node_prev_sibling( current );
if ( node != (GNode *) NULL )
current = node;
container = (GtkWidget *)((BoxData *)current->data)->container;
dump_tree( (gpointer) NULL, 0, (GtkWidget *) NULL );
ResetSettingsMenuItems();
}
static void
go_next( gpointer data, guint callback_action, GtkWidget *w )
{
GNode *node;
node = g_node_next_sibling( current );
if ( node != (GNode *) NULL )
current = node;
container = (GtkWidget *)((BoxData *)current->data)->container;
dump_tree( (gpointer) NULL, 0, (GtkWidget *) NULL );
ResetSettingsMenuItems();
}
// box add functions
static void
add_horz_box( gpointer data, guint callback_action, GtkWidget *w )
{
GtkWidget *hbox;
GNode *node;
BoxData *boxData;
boxData = g_malloc( sizeof( BoxData ) );
hbox = gtk_hbox_new(FALSE, 0);
boxData->container = hbox;
boxData->homogeneous = FALSE;
boxData->fill = TRUE;
boxData->expand = TRUE;
boxData->padding = 0;
boxData->spacing = 0;
if ( callback_action == 0 )
gtk_box_pack_start( GTK_BOX(container), hbox,
boxData->expand, boxData->fill, boxData->padding );
else
gtk_box_pack_end( GTK_BOX(container), hbox,
boxData->expand, boxData->fill, boxData->padding );
node = g_node_new( (gpointer) boxData );
g_node_insert( current, -1, node );
dump_tree( (gpointer) NULL, 0, (GtkWidget *) NULL );
ResetSettingsMenuItems();
gtk_widget_show (hbox);
}
static void
add_vert_box( gpointer data, guint callback_action, GtkWidget *w )
{
GtkWidget *vbox;
GNode *node;
BoxData *boxData;
boxData = g_malloc( sizeof( BoxData ) );
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(container), vbox);
boxData->container = vbox;
boxData->homogeneous = FALSE;
boxData->fill = TRUE;
boxData->expand = TRUE;
boxData->padding = 0;
boxData->spacing = 0;
if ( callback_action == 0 )
gtk_box_pack_start( GTK_BOX(container), vbox,
boxData->expand, boxData->fill, boxData->padding );
else
gtk_box_pack_end( GTK_BOX(container), vbox,
boxData->expand, boxData->fill, boxData->padding );
node = g_node_new( (gpointer) boxData );
g_node_insert( current, -1, node );
dump_tree( (gpointer) NULL, 0, (GtkWidget *) NULL );
ResetSettingsMenuItems();
gtk_widget_show (vbox);
}
// child (button) widget add functions
static void
add_button_to_box_start( gpointer data, guint callback_action, GtkWidget *w )
{
GtkWidget *button;
char buf[ 64 ];
sprintf( buf, "Start %d Box %x", n++, container );
button = gtk_button_new_with_label( buf );
gtk_box_pack_start( GTK_BOX(container), button,
((BoxData *) current->data)->expand,
((BoxData *) current->data)->fill,
((BoxData *) current->data)->padding );
gtk_widget_show(button);
}
static void
add_button_to_box_end( gpointer data, guint callback_action, GtkWidget *w )
{
GtkWidget *button;
char buf[ 64 ];
sprintf( buf, "End %d Box %x", n++, container );
button = gtk_button_new_with_label( buf );
gtk_box_pack_end( GTK_BOX(container), button,
((BoxData *) current->data)->expand,
((BoxData *) current->data)->fill,
((BoxData *) current->data)->padding );
gtk_widget_show (button);
}
// padding and spacing dialog
static void
ClickedCallback(GtkWidget *widget, gpointer unused)
{
char *data;
int spacing;
data = gtk_entry_get_text( GTK_ENTRY(settingsData.pad_entry) );
((BoxData *) current->data)->padding = atoi( data );
// get the spacing
data = gtk_entry_get_text( GTK_ENTRY(settingsData.space_entry) );
spacing = ((BoxData *) current->data)->spacing = atoi( data );
// make the change to spacing
gtk_box_set_spacing(GTK_BOX(((BoxData *) current->data)->container),
spacing);
UpdateChildren();
gtk_widget_destroy( settingsData.dialog );
}
// make changes to children after a setting change
void
UpdateChildren( void )
{
GtkBoxChild *child;
GList *children;
GtkBox *box;
gboolean expand, fill;
int padding;
GtkPackType type;
box = GTK_BOX(((BoxData *) current->data)->container);
children = box->children;
while ( children != (GList *) NULL ) {
child = (GtkBoxChild *) children->data;
gtk_box_query_child_packing(box, (GtkWidget *)child->widget,
&expand, &fill, &padding, &type );
gtk_box_set_child_packing(box, (GtkWidget *) child->widget,
((BoxData *) current->data)->expand,
((BoxData *) current->data)->fill,
((BoxData *) current->data)->padding, type );
children = children->next;
}
}
// user canceled the settings dialog
static void
CancelCallback(GtkWidget *widget, GtkWidget *dialog_window)
{
gtk_widget_destroy( dialog_window );
}
// display a dialog to get padding and spacing values
void
GetPaddingAndSpacing( void )
{
GtkWidget *button, *label, *entry, *hbox, *dialog_window;
char buf[ 64 ];
// create the dialog and set attributes
settingsData.dialog = dialog_window = gtk_dialog_new();
gtk_window_set_modal(GTK_WINDOW(dialog_window), TRUE);
gtk_window_position(GTK_WINDOW (dialog_window),
GTK_WIN_POS_MOUSE);
gtk_window_set_title(GTK_WINDOW(dialog_window),
"Padding and Sp
没有合适的资源?快使用搜索试试~ 我知道了~
Gtk+ Programming in C
共286个文件
c:111个
makefile:100个
xpm:52个
3星 · 超过75%的资源 需积分: 14 24 下载量 21 浏览量
2017-10-15
23:56:48
上传
评论 3
收藏 5.44MB RAR 举报
温馨提示
Sample Code for Gtk+ Programming in C, 1st Edition, Prentice Hall Syd Logan
资源推荐
资源详情
资源评论
收起资源包目录
Gtk+ Programming in C (286个子文件)
box.c 18KB
toolbar.c 12KB
ttt.c 8KB
itemfactory.c 8KB
notebook.c 8KB
gtkclist.c 7KB
tree.c 7KB
notebook.c 6KB
tree.c 6KB
drawing.c 6KB
progressbar.c 6KB
menu.c 6KB
gtklist.c 5KB
gtkframe.c 5KB
itemfactory.c 5KB
tree.c 5KB
spinbutton.c 5KB
gtklabel.c 5KB
text.c 5KB
gtkpreview.c 4KB
itemfactory.c 4KB
events4.c 4KB
adjust.c 4KB
tree.c 4KB
tree.c 4KB
calendar.c 4KB
args3.c 4KB
adjust.c 4KB
itemfactory.c 4KB
fixed.c 3KB
hscroll.c 3KB
scale.c 3KB
gtkclist.c 3KB
toolbar.c 3KB
itemfactory.c 3KB
layout.c 3KB
tree.c 3KB
gtkframe.c 3KB
args.c 3KB
combo3.c 3KB
gtkimage.c 3KB
tipsquery.c 3KB
args2.c 3KB
adjust.c 3KB
gtkhseparator.c 3KB
gtkvseparator.c 3KB
packer.c 3KB
gtkarrow.c 3KB
yesno.c 3KB
gtkpixmap.c 3KB
events2.c 3KB
layout.c 3KB
adjust.c 3KB
toolbar.c 3KB
combo2.c 3KB
packer.c 3KB
paned.c 2KB
gtkfontsel.c 2KB
colorsel.c 2KB
packer.c 2KB
packer.c 2KB
notebook.c 2KB
hellogtk+.c 2KB
packer.c 2KB
packer.c 2KB
packer.c 2KB
signals.c 2KB
ruler.c 2KB
packer.c 2KB
packer.c 2KB
packer.c 2KB
buttonbox.c 2KB
colorseldialog.c 2KB
gtkbutton.c 2KB
events3.c 2KB
packer.c 2KB
gtkfontsel.c 2KB
casts.c 2KB
packer.c 2KB
packer.c 2KB
gtkfilesel.c 2KB
combo.c 2KB
combo.c 2KB
gtkbutton.c 2KB
paned.c 2KB
paned.c 2KB
table.c 2KB
packer.c 2KB
packer.c 2KB
hints.c 2KB
table.c 2KB
table.c 2KB
colorsel.c 2KB
box.c 2KB
layout.c 2KB
priority.c 2KB
packer.c 2KB
table.c 2KB
events1.c 2KB
snoop.c 2KB
共 286 条
- 1
- 2
- 3
资源评论
- 编程是技术也是艺术2020-07-04只是代码,没太注意。
jiangdmdr
- 粉丝: 57
- 资源: 774
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功