-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainui.c
executable file
·119 lines (105 loc) · 4.7 KB
/
mainui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* ui.c
*
* Created on: 2017年12月19日
* Author: tom
*/
#include "mainui.h"
#include "gresource.h"
typedef struct {
GString *name;
GtkLayout *layout;
GtkStatusbar *status_bar;
} MyMainuiPrivate;
G_DEFINE_TYPE_WITH_CODE(MyMainui, my_mainui, GTK_TYPE_WINDOW,
G_ADD_PRIVATE(MyMainui));
void my_mainui_add_clicked(GtkToolButton *button,gpointer userdata);
void my_mainui_down_info_clicked(GtkToolButton *button,gpointer userdata);
void my_mainui_exec_clicked(GtkToolButton *button,gpointer userdata);
void my_mainui_stop_clicked(GtkToolButton *button,gpointer userdata);
void mainui_open_clicked (GtkMenuItem *item, MyMainui *MyMainui);
void mainui_save_clicked (GtkMenuItem *item, MyMainui *MyMainui);
void mainui_setting_clicked (GtkMenuItem *item, MyMainui *MyMainui);
gboolean my_main_ui_close(GtkWidget *widget,MyMainui *ui);
static void my_mainui_class_init(MyMainuiClass *klass) {
/*gchar*template;
gsize size;
g_file_get_contents("mainui.glade", &template, &size, NULL);
gtk_widget_class_set_template(klass, g_bytes_new_static(template, size));*/
gtk_widget_class_set_template_from_resource(klass,"/org/gtk/mainui.glade");
gtk_widget_class_bind_template_child_private(klass,MyMainui,layout);
gtk_widget_class_bind_template_child_private(klass,MyMainui,status_bar);
gtk_widget_class_bind_template_callback(klass,my_mainui_show_msg);
gtk_widget_class_bind_template_callback(klass,my_mainui_add_clicked);
gtk_widget_class_bind_template_callback(klass,my_mainui_down_info_clicked);
gtk_widget_class_bind_template_callback(klass,my_mainui_exec_clicked);
gtk_widget_class_bind_template_callback(klass,mainui_open_clicked);
gtk_widget_class_bind_template_callback(klass,mainui_save_clicked);
gtk_widget_class_bind_template_callback(klass,mainui_setting_clicked);
gtk_widget_class_bind_template_callback(klass,my_mainui_stop_clicked);
gtk_widget_class_bind_template_callback(klass,my_main_ui_close);
g_signal_new("add_child",MY_TYPE_MAINUI,G_SIGNAL_RUN_LAST,G_STRUCT_OFFSET(MyMainuiClass,add_child),NULL,NULL,NULL,G_TYPE_NONE,0,NULL);
g_signal_new("down-info",MY_TYPE_MAINUI,G_SIGNAL_RUN_LAST,G_STRUCT_OFFSET(MyMainuiClass,info),NULL,NULL,NULL,G_TYPE_NONE,0,NULL);
g_signal_new("exec",MY_TYPE_MAINUI,G_SIGNAL_RUN_LAST,G_STRUCT_OFFSET(MyMainuiClass,exec),NULL,NULL,NULL,G_TYPE_NONE,0,NULL);
g_signal_new("stop",MY_TYPE_MAINUI,G_SIGNAL_RUN_LAST,G_STRUCT_OFFSET(MyMainuiClass,stop),NULL,NULL,NULL,G_TYPE_NONE,0,NULL);
g_signal_new("open",MY_TYPE_MAINUI,G_SIGNAL_RUN_LAST,G_STRUCT_OFFSET(MyMainuiClass,open),NULL,NULL,NULL,G_TYPE_NONE,0,NULL);
g_signal_new("save",MY_TYPE_MAINUI,G_SIGNAL_RUN_LAST,G_STRUCT_OFFSET(MyMainuiClass,save),NULL,NULL,NULL,G_TYPE_NONE,0,NULL);
g_signal_new("setting",MY_TYPE_MAINUI,G_SIGNAL_RUN_LAST,G_STRUCT_OFFSET(MyMainuiClass,setting),NULL,NULL,NULL,G_TYPE_NONE,0,NULL);
}
;
static void my_mainui_init(MyMainui *self) {
gtk_widget_init_template(self);
MyMainuiPrivate *priv=my_mainui_get_instance_private(self);
priv->name=g_string_new("My UI");
}
;
void my_mainui_show_msg(GtkToolButton *button,gpointer userdata){
g_print("%s Clicked\n",gtk_tool_button_get_label(button));
};
MyMainui *my_mainui_new(){
MyMainui *ui=g_object_new(MY_TYPE_MAINUI, NULL);
gtk_widget_show_all(ui);
return ui;
};
void my_mainui_add_clicked(GtkToolButton *button,gpointer userdata){
g_signal_emit_by_name(userdata,"add_child",NULL);
};
void my_mainui_down_info_clicked(GtkToolButton *button,gpointer userdata){
g_signal_emit_by_name(userdata,"down-info",NULL);
};
void my_mainui_exec_clicked(GtkToolButton *button,gpointer userdata){
g_signal_emit_by_name(userdata,"exec",NULL);
};
void my_mainui_stop_clicked(GtkToolButton *button,gpointer userdata){
g_signal_emit_by_name(userdata,"stop",NULL);
};
void mainui_open_clicked (GtkMenuItem *item, MyMainui *MyMainui){
g_signal_emit_by_name(MyMainui,"open",NULL);
};
void mainui_save_clicked (GtkMenuItem *item, MyMainui *MyMainui){
g_signal_emit_by_name(MyMainui,"save",NULL);
};
void mainui_setting_clicked (GtkMenuItem *item, MyMainui *MyMainui){
g_signal_emit_by_name(MyMainui,"setting",NULL);
};
gboolean my_main_ui_close(GtkWidget *widget,MyMainui *ui){
gboolean quit=FALSE;
MyMainui *self=ui;
GtkResponseType repo;
if(!MY_IS_MAINUI(self))self=widget;
GtkDialog *dialog=gtk_message_dialog_new(self,GTK_DIALOG_MODAL,GTK_MESSAGE_QUESTION,GTK_BUTTONS_YES_NO,"是否退出?");
if(gtk_dialog_run(dialog)==GTK_RESPONSE_YES){
quit=TRUE;
}
gtk_widget_destroy(dialog);
if(quit)gtk_main_quit();
return TRUE;
}
GtkLayout *my_mainui_get_layout(MyMainui *self){
MyMainuiPrivate *priv=my_mainui_get_instance_private(self);
return priv->layout;
};
GtkStatusbar *my_mainui_get_statusbar(MyMainui *self){
MyMainuiPrivate *priv=my_mainui_get_instance_private(self);
return priv->status_bar;
};