Add gtk20

This commit is contained in:
daleclack 2020-11-25 18:17:32 +08:00
parent 7555dc7516
commit 8b6a712b38
4 changed files with 97 additions and 0 deletions

37
Gtk3/gtk20/gtk20.cbp Normal file
View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="gtk20" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/gtk20" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/gtk20" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>

10
Gtk3/gtk20/gtk20.layout Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="41" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

49
Gtk3/gtk20/main.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <gtk/gtk.h>
#include <stdio.h>
void entry_activate(GtkWidget *widget,gpointer data){
//Deal with activate and click signal
//This function is for getting text of entry and write text to a file
const gchar *str;
str=gtk_entry_get_text(GTK_ENTRY(data));
freopen("test1.txt","w",stdout);
g_print("%s\n",str);
fclose(stdout);
}
void activate(GtkApplication *app,gpointer user_data){
//Create a window
GtkWidget *window;
window=gtk_application_window_new(app);
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(window),"gtk (20)");
gtk_window_set_default_size(GTK_WINDOW(window),400,200);
GtkWidget *fixed=gtk_fixed_new();
//Create a entry
GtkWidget *entry=gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(entry),"hello");
gtk_widget_set_size_request(entry,300,50);
gtk_fixed_put(GTK_FIXED(fixed),entry,50,40);
g_signal_connect(G_OBJECT(entry),"activate",G_CALLBACK(entry_activate),(gpointer)entry);
//Create a button with label
GtkWidget *button=gtk_button_new_with_label("Print");
gtk_widget_set_size_request(button,100,50);
gtk_fixed_put(GTK_FIXED(fixed),button,150,100);
g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(entry_activate),(gpointer)entry);
//Add everything to window
gtk_container_add(GTK_CONTAINER(window),fixed);
gtk_widget_show_all(window);
}
int main(int argc,char *argv[]){
//Create a gtk application
GtkApplication *app;
int status;
app=gtk_application_new("com.github.daleclack.gtk20",G_APPLICATION_FLAGS_NONE);
g_signal_connect(app,"activate",G_CALLBACK(activate),NULL);
status=g_application_run(G_APPLICATION(app),argc,argv);
return status;
}

1
Gtk3/gtk20/test1.txt Normal file
View File

@ -0,0 +1 @@
hello