📄 misc.c
字号:
/* * File: misc.c * Auth: lxw */#include <gtk/gtk.h>#include "gmclient.h"static GtkWidget *filew;
static char *sFilename = NULL;
static gint current_list_row=0;static GtkAccelGroup *accel_group;
static gchar current_list_selection[4096];static gint current_radiobutton=0;static void internalRadioButton(GtkWidget *widget, gint t);static void internalClistSelect(GtkWidget *list, gint c, gint r);static gchar *szFontName = NULL;
/*
* Structure to eliminate global variables
*/
typedef struct {
GtkWidget *dialog;
GdkColor *color;
} typColorDialogInfo;
typedef struct {
GtkWidget *progressbar;
GtkWidget *window;
int bProgressUp;
int nLastPct;
} typProgressData;
static typProgressData *pdata = NULL;
void NO_FUNC(){}void endProgram(GtkWidget *widget,gpointer data){ gtk_widget_destroy(widget); }/*-----------------------------------/ create gtk window/ tilte -- 标题/ size_x -- 宽度/ size_y -- 高度/ position_x --行起始位址 / position_y --列起始位址 / border -- 边框距/ window_destroy --回呼函数,取消窗口/-------------------------------------*/GtkWidget *createWindow(char *title, gint size_x, gint size_y, gint position_x, gint position_y, gint border, GtkSignalFunc window_destroy){ GtkWidget *i_win; i_win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_usize(GTK_WIDGET(i_win), size_x, size_y); gtk_signal_connect(GTK_OBJECT(i_win), "delete_event", GTK_SIGNAL_FUNC(window_destroy), i_win); gtk_window_set_title(GTK_WINDOW(i_win), title); if(position_x == 0 && position_y == 0) gtk_window_set_position(GTK_WINDOW(i_win), GTK_WIN_POS_CENTER); else gtk_widget_set_uposition(GTK_WIDGET(i_win), position_x, position_y); gtk_container_border_width(GTK_CONTAINER(i_win), border); gtk_widget_show(i_win); if(accel_group == NULL) accel_group=gtk_accel_group_new(); gtk_accel_group_attach(accel_group,GTK_OBJECT(i_win)); return i_win;}/*-----------------------------------/ create gtk window/ tilte -- 标题/ size_x -- 宽度/ size_y -- 高度/ position_x --行起始位址 / position_y --列起始位址 / border -- 边框距/ window_destroy --回呼函数,取消窗口/-------------------------------------*/GtkWidget *createDialogWindow(char *title, gint size_x, gint size_y,gint position_x, gint position_y, gint border, GtkSignalFunc window_destroy){ GtkWidget *i_win; i_win = gtk_window_new( GTK_WINDOW_DIALOG ); gtk_widget_set_usize(GTK_WIDGET(i_win), size_x, size_y); gtk_signal_connect(GTK_OBJECT(i_win), "delete_event", GTK_SIGNAL_FUNC(window_destroy), i_win); gtk_window_set_title(GTK_WINDOW(i_win), title); if(position_x == 0 && position_y == 0) gtk_window_set_position(GTK_WINDOW(i_win), GTK_WIN_POS_CENTER); else gtk_widget_set_uposition(GTK_WIDGET(i_win), position_x, position_y); gtk_container_border_width(GTK_CONTAINER(i_win), border); gtk_widget_show(i_win); if(accel_group == NULL) accel_group=gtk_accel_group_new(); gtk_accel_group_attach(accel_group,GTK_OBJECT(i_win)); return i_win;}/*------------------------------------/ create box 建立容器/ parent --父窗口或容器/ placement -- 容器内构件排列位置 / VERTICAL--纵向 HORIZONTAL--横向/ border -- 容器边框距/-------------------------------------*/GtkWidget *createBox(GtkWidget *parent, gint placement, gint border){ GtkWidget *i_box;// e_assert_widget(parent, "parent is not a GtkWidget"); if(placement == VERTICAL) i_box = gtk_vbox_new(FALSE, 0); else i_box = gtk_hbox_new(FALSE, 0); if(GTK_IS_CONTAINER(parent)) gtk_container_add(GTK_CONTAINER(parent), i_box); else gtk_box_pack_start(GTK_BOX(parent), i_box, TRUE, TRUE, 0); gtk_container_border_width(GTK_CONTAINER(i_box), border); gtk_widget_show(i_box); return i_box;}/*------------------------------------/ create table 建立容器/ parent --父窗口或容器/ row -- 行数/ col -- 列数/ homogeneous -- 容器内构件排列方式 / TRUE FALSE/-------------------------------------*/GtkWidget *createTable(GtkWidget *parent,gint row,gint col, gint homogeneous){ GtkWidget *i_table;// e_assert_widget(parent, "parent is not a GtkWidget"); i_table=gtk_table_new(row,col,homogeneous); if(GTK_IS_CONTAINER(parent)) gtk_container_add(GTK_CONTAINER(parent), i_table); else gtk_box_pack_start(GTK_BOX(parent), i_table, TRUE, TRUE, 0); gtk_widget_show(i_table); return i_table;}/*------------------------------------/ create fix box 建立容器 在容器之中/ parent --容器/ placement -- 容器内构件排列位置 / VERTICAL--纵向 HORIZONTAL--横向/ border -- 容器边框距/-------------------------------------*/GtkWidget *createBoxFixed(GtkWidget *parent, gint placement, gint border){ GtkWidget *i_box;// e_assert_widget(parent, "parent is not a GtkWidget"); if(placement == VERTICAL) i_box = gtk_vbox_new(FALSE, 0); else i_box = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(parent), i_box, FALSE, FALSE, 0); gtk_container_border_width(GTK_CONTAINER(i_box), border); gtk_widget_show(i_box); return i_box;}/*------------------------------------/ create dialog box 建立选择对话框/ title -- 对话框标题/ context -- 对话框内容 / callback -- 确认回呼函数/-------------------------------------*/void createDialogBox(gchar *title, gchar *context,gint x,gint y, GtkSignalFunc callback){ GtkWidget *tmpwin; GtkWidget *tmpvbox; GtkWidget *label; GtkWidget *i_box2,*i_but; tmpwin = createDialogWindow(title,x,y,0,0,5, GTK_SIGNAL_FUNC(endProgram)); tmpvbox = createBox(tmpwin,VERTICAL,0); /* --- Create a descriptive label --- */ label = gtk_label_new (context); /* --- Put some room around the label text --- */ gtk_misc_set_padding (GTK_MISC (label), 10, 10); /* --- Add label to designated area on dialog --- */ gtk_box_pack_start (GTK_BOX (tmpvbox), label, TRUE, TRUE, 0); /* --- Show the label --- */ gtk_widget_show (label); i_box2 = gtk_hbutton_box_new(); gtk_button_box_set_layout(GTK_BUTTON_BOX(i_box2), SPREAD); gtk_button_box_set_spacing(GTK_BUTTON_BOX(i_box2), 10); gtk_box_pack_start(GTK_BOX(tmpvbox), i_box2, FALSE, FALSE, 0); gtk_widget_show(i_box2); i_but = gtk_button_new_with_label("确认"); gtk_signal_connect_object(GTK_OBJECT(i_but), "clicked", GTK_SIGNAL_FUNC(callback),GTK_OBJECT(tmpwin)); gtk_box_pack_start(GTK_BOX(i_box2), i_but, TRUE, TRUE, 0); gtk_widget_show(i_but); i_but = gtk_button_new_with_label("取消"); gtk_signal_connect_object(GTK_OBJECT(i_but), "clicked", GTK_SIGNAL_FUNC(endProgram),GTK_OBJECT(tmpwin)); gtk_box_pack_start(GTK_BOX(i_box2), i_but, TRUE, TRUE, 0); gtk_widget_show(i_but); gtk_grab_add(tmpwin);}/*--------------------------------------------/ create paned 建立窗口分割构件/ parent --父窗口或容器/ placement -- 分割方式 / VERTICAL--纵向 HORIZONTAL--横向/ handle--柄高度/ gutter--分割条高度/---------------------------------------------*/GtkWidget *createPaned(GtkWidget *parent, gint placement, gint handle,gint gutter){ GtkWidget *paned; if(placement == VERTICAL) paned = gtk_vpaned_new(); else paned = gtk_hpaned_new(); gtk_container_add (GTK_CONTAINER(parent), paned); gtk_paned_set_handle_size (GTK_PANED(paned),handle); gtk_paned_set_gutter_size (GTK_PANED(paned),gutter); gtk_widget_show (paned); return paned;}/*----------------------------------------/ create enrty 建立输入框/ parent --父窗口或容器/ initial_text -- 初始化字串/-------------------------------------------*/GtkWidget *createEntry(GtkWidget *parent, gchar *initial_text){ GtkWidget *i_entry;// e_assert_widget(parent, "parent is not a GtkWidget"); i_entry = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(i_entry), initial_text); if(GTK_IS_CONTAINER(parent)) gtk_container_add(GTK_CONTAINER(parent),i_entry ); else gtk_box_pack_start(GTK_BOX(parent), i_entry,FALSE,FALSE, 0); gtk_widget_show(i_entry); return i_entry;}/*---------------------------------------------------/ create enrty with max length建立指定字符数输入框/ parent --父窗口或容器/ initial_text -- 初始化字串/ num --最多输入字符数/----------------------------------------------------*/GtkWidget *createEntryWithMaxLength(GtkWidget *parent, gchar *initial_text,gint num){ GtkWidget *i_entry;// e_assert_widget(parent, "parent is not a GtkWidget"); i_entry = gtk_entry_new_with_max_length(num); gtk_entry_set_text(GTK_ENTRY(i_entry), initial_text); if(GTK_IS_CONTAINER(parent)) gtk_container_add(GTK_CONTAINER(parent),i_entry ); else gtk_box_pack_start(GTK_BOX(parent), i_entry,FALSE,FALSE, 0); gtk_widget_show(i_entry); return i_entry;}/*---------------------------------------------------/ create Combo box建立选项输入框/ parent --父窗口或容器/ items -- 列表数据项/----------------------------------------------------*/GtkWidget *createComboBox(GtkWidget *parent,GList *items){ GtkWidget *i_combo; i_combo=gtk_combo_new(); gtk_combo_set_popdown_strings(GTK_COMBO(i_combo),items); if(GTK_IS_CONTAINER(parent)) gtk_container_add(GTK_CONTAINER(parent),i_combo ); else gtk_box_pack_start(GTK_BOX(parent),i_combo, FALSE, FALSE, 0); gtk_widget_show(i_combo); return i_combo;}/*----------------------------------------------------/ 取出选项输入框中内容/-----------------------------------------------*/char * getComboBoxText(GtkWidget *combobox){ return gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combobox)->entry));}/*----------------------------------------/ create frame 建立标签框架/ parent --父窗口或容器/ text -- 标签框名称/ xalign,yalign -- 名称位址/ type -- 标签框类型/ GTK_SHADOW_NONE / GTK_SHADOW_IN / GTK_SHADOW_OUT / GTK_SHADOW_ETCHED_IN (the default) / GTK_SHADOW_ETCHED_OUT //-------------------------------------------*/GtkWidget *createFrame(GtkWidget *parent, gchar *text, gfloat xalign,gfloat yalign,GtkShadowType type){ GtkWidget *frame; /* Create a Frame */ frame = gtk_frame_new(NULL); if(GTK_IS_CONTAINER(parent)) gtk_container_add(GTK_CONTAINER(parent),frame ); else gtk_box_pack_start(GTK_BOX(parent), frame,FALSE,FALSE, 0); /* Set the frames label */ gtk_frame_set_label( GTK_FRAME(frame), text); /* Align the label at the right of the frame */ gtk_frame_set_label_align( GTK_FRAME(frame), xalign,yalign); /* Set the style of the frame */ gtk_frame_set_shadow_type( GTK_FRAME(frame),type); gtk_widget_show(frame); return frame;}/*----------------------------------------/ create frame from table 建立标签框架在table 构件中/ parent -- table 构件/ text -- 标签框名称/ left,right,top,bottom -- table 中位址/ xalign,yalign -- 名称位址/ type -- 标签框类型/ GTK_SHADOW_NONE / GTK_SHADOW_IN / GTK_SHADOW_OUT / GTK_SHADOW_ETCHED_IN (the default) / GTK_SHADOW_ETCHED_OUT //-------------------------------------------*/GtkWidget *createFrameFromTable(GtkWidget *parent, gchar *text,gint left,gint right,gint top,gint bottom, gfloat xalign,gfloat yalign,GtkShadowType type){ GtkWidget *tframe; // if(!GTK_IS_TABLE(parent)) return NULL; /* Create a Frame */ tframe = gtk_frame_new(NULL); gtk_table_attach(GTK_TABLE(parent),tframe, left,right,top,bottom, GTK_EXPAND |GTK_SHRINK, GTK_EXPAND |GTK_SHRINK, 0,0); /* Set the frames label */ gtk_frame_set_label( GTK_FRAME(tframe),text); /* Align the label at the right of the frame */ gtk_frame_set_label_align( GTK_FRAME(tframe), xalign,yalign); /* Set the style of the frame */ gtk_frame_set_shadow_type(GTK_FRAME(tframe), type); gtk_widget_show(tframe); return tframe;}/*----------------------------------------/ create label 建立标签构件/ parent --父窗口或容器/ text -- 初始化字串/-------------------------------------------*/GtkWidget *createLabel(GtkWidget *parent, gchar *text){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -