Add gtk15

This commit is contained in:
daleclack 2020-11-07 09:26:21 +08:00
parent 870f78eaf3
commit 07bed5c8ab
4 changed files with 164 additions and 0 deletions

37
Gtk3/gtk15/gtk15.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="gtk15" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/gtk15" 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/gtk15" 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/gtk15/gtk15.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="0" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

32
Gtk3/gtk15/gtk33.ui Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="window_position">center</property>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkFixed">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">button</property>
<property name="width_request">100</property>
<property name="height_request">50</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="x">165</property>
<property name="y">237</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

85
Gtk3/gtk15/main.cpp Normal file
View File

@ -0,0 +1,85 @@
#include<gtk/gtk.h>
void add(GtkWidget *widget,gpointer data){//This function can change progress bar value
gdouble new_val;
new_val=gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(data));
if(new_val>=1.0) new_val=0.0;
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(data),new_val+0.05);
}
void change(GtkWidget *widget,gpointer data){
//This function is for change progress bar orinentation:right ro left or left to right
switch(gtk_progress_bar_get_inverted(GTK_PROGRESS_BAR(data))){
case TRUE:
gtk_progress_bar_set_inverted(GTK_PROGRESS_BAR(data),FALSE);break;
case FALSE:
gtk_progress_bar_set_inverted(GTK_PROGRESS_BAR(data),TRUE);break;
default:break;
}
}
void change_text(GtkWidget *widget,gpointer data){
//This function is for change progress bar text
const gchar *progress_text;
GtkWidget *dialog;
GtkWidget *entry;
GtkWidget *content_area;
dialog=gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog),"Change Progress Bar Text");
gtk_window_set_default_size(GTK_WINDOW(dialog),300,150);
gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
gtk_dialog_add_button(GTK_DIALOG(dialog),"OK",GTK_RESPONSE_OK);
content_area=gtk_dialog_get_content_area(GTK_DIALOG(dialog));
entry=gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(entry),"Progress...");
gtk_container_add(GTK_CONTAINER(content_area),entry);
gtk_widget_show(entry);
gtk_dialog_run(GTK_DIALOG(dialog));
progress_text=gtk_entry_get_text(GTK_ENTRY(entry));
//g_print(progress_text);
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(data),progress_text);
gtk_widget_destroy(dialog);
}
int main(int argc,char *argv[]){
GtkWidget *window;//Create objects
GtkWidget *fixed;
GtkWidget *btn_add;
GtkWidget *btn_change;
GtkWidget *btn_exit;
GtkWidget *btn_change_text;
GtkWidget *progress;
gtk_init(&argc,&argv);//gtk+ initial
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);//Create a gtk window
g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);//make application exit when main window destroy
gtk_window_set_title(GTK_WINDOW(window),"gtk (15)");//window title
gtk_window_set_default_size(GTK_WINDOW(window),300,200);//window size
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);//window position
fixed=gtk_fixed_new();//Create a fixed container
gtk_container_add(GTK_CONTAINER(window),fixed);//Add the container to window
progress=gtk_progress_bar_new();//Create a progress bar and set some attributes
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress),"Hello");
gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(progress),TRUE);
gtk_widget_set_size_request(progress,300,30);
gtk_fixed_put(GTK_FIXED(fixed),progress,0,5);
btn_add=gtk_button_new_with_label("Add");//Create "Add progress" button
gtk_widget_set_size_request(btn_add,150,40);
gtk_fixed_put(GTK_FIXED(fixed),btn_add,0,80);
g_signal_connect(G_OBJECT(btn_add),"clicked",G_CALLBACK(add),(gpointer)progress);
btn_change=gtk_button_new_with_label("Change");//Create "Change orientation" button
gtk_widget_set_size_request(btn_change,150,40);
gtk_fixed_put(GTK_FIXED(fixed),btn_change,150,80);
g_signal_connect(G_OBJECT(btn_change),"clicked",G_CALLBACK(change),(gpointer)progress);
btn_change_text=gtk_button_new_with_label("Change Text");//Create "Change Progress Text" button
gtk_widget_set_size_request(btn_change_text,150,40);
gtk_fixed_put(GTK_FIXED(fixed),btn_change_text,0,130);
g_signal_connect(G_OBJECT(btn_change_text),"clicked",G_CALLBACK(change_text),(gpointer)progress);
btn_exit=gtk_button_new_with_label("Exit");//Create "Exit" button
gtk_widget_set_size_request(btn_exit,150,40);
gtk_fixed_put(GTK_FIXED(fixed),btn_exit,150,130);
g_signal_connect(G_OBJECT(btn_exit),"clicked",G_CALLBACK(gtk_main_quit),NULL);
progress=gtk_progress_bar_new();
gtk_widget_show_all(window);//Show everything
gtk_main();
return 0;
}