分类: 嵌入式
2011-11-25 17:16:54
1 结构定义
typedef struct{
[...]
GtkWidget* fileop_dialog; 用来显示GtkFileSelection构件的对话框,可以使用标准的GtkDialog构件来往该对话框中添加或删除子构件
GtkWidget* ok_button;
GtkWidget* cancel_button; 两个主要的按钮,应该对这两个按钮定义信号处理函数,这样才能获得用户所选择的文件
[...]
}GtkFileSelection;
2 文件选择构件的使用
/* 获取用户所选择的文件 */
void store_filename (GtkWidget *widget, gpointer user_data) {
GtkWidget *file_selector = GTK_WIDGET (user_data);
const gchar *selected_filename;
selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector));
g_print ("Selected filename: %s\n", selected_filename);
}
void create_file_selection (void) {
GtkWidget *file_selector;
/* 创建文件选择构件 */
file_selector = gtk_file_selection_new ("Please select a file for editing.");
g_signal_connect (GTK_FILE_SELECTION (file_selector)->ok_button,"clicked", G_CALLBACK(store_filename), file_selector);
/* 当用户单击对话框上的“确定”或“取消”按钮时销毁对话框 */
g_signal_connect_swapped (GTK_FILE_SELECTION (file_selector)->ok_button,
"clicked",
G_CALLBACK (gtk_widget_destroy),
file_selector);
g_signal_connect_swapped (GTK_FILE_SELECTION (file_selector)->cancel_button,
"clicked",
G_CALLBACK (gtk_widget_destroy),
file_selector);
/* 显示文件选择对话框 */
gtk_widget_show (file_selector);
}
3 图片