testing-repository/Gtk3/gtk36/main.cpp

42 lines
1.7 KiB
C++
Raw Normal View History

2021-01-21 12:05:10 +08:00
#include <gtk/gtk.h>
2021-01-22 10:02:05 +08:00
void print_letters(GtkWidget *widget,gpointer data){
const gchar *str=gtk_button_get_label(GTK_BUTTON(widget));
g_print("%s\n",str);
}
void print(GtkWidget *widget,gchar *data){
g_print("%s\n",data);
}
2021-01-21 12:05:10 +08:00
static void gtkmain(GtkApplication *app,gpointer user_data){
2021-01-31 14:37:33 +08:00
GtkBuilder *builder=gtk_builder_new_from_resource("/gtk36/window.ui");
2021-01-21 12:05:10 +08:00
GObject *window=gtk_builder_get_object(builder,"window");
gtk_application_add_window(app,GTK_WINDOW(window));
2021-01-22 10:02:05 +08:00
//charactor buttons
GObject *btn[27];
for(int i=1;i<=26;i++){
char name[10];
sprintf(name,"btn%d",i);
btn[i]=gtk_builder_get_object(builder,name);
g_signal_connect(btn[i],"clicked",G_CALLBACK(print_letters),NULL);
}
GObject *btn_ctrl=gtk_builder_get_object(builder,"btnctrl");
g_signal_connect(btn_ctrl,"clicked",G_CALLBACK(print_letters),NULL);
GObject *btn_alt=gtk_builder_get_object(builder,"btnalt");
g_signal_connect(btn_alt,"clicked",G_CALLBACK(print_letters),NULL);
GObject *btn_space=gtk_builder_get_object(builder,"btnspace");
2021-01-22 10:04:10 +08:00
g_signal_connect(btn_space,"clicked",G_CALLBACK(print),(gpointer)" _");
2021-01-22 10:02:05 +08:00
GObject *btn_enter=gtk_builder_get_object(builder,"btnenter");
g_signal_connect(btn_enter,"clicked",G_CALLBACK(print),(gpointer)"");
GObject *btn_quit=gtk_builder_get_object(builder,"btnquit");
g_signal_connect_swapped(btn_quit,"clicked",G_CALLBACK(gtk_widget_destroy),window);
2021-01-21 12:05:10 +08:00
gtk_widget_show_all(GTK_WIDGET(window));
}
int main(int argc,char *argv[]){
GtkApplication *app;
app=gtk_application_new("com.github.daleclack.gtk36",G_APPLICATION_FLAGS_NONE);
g_signal_connect(app,"activate",G_CALLBACK(gtkmain),NULL);
return g_application_run(G_APPLICATION(app),argc,argv);
}