2020-12-20 11:22:22 +08:00
|
|
|
#include "gtkwin.h"
|
|
|
|
#include "test.h"
|
2020-12-21 18:37:01 +08:00
|
|
|
#include "winpe.xpm"
|
2020-12-21 12:09:59 +08:00
|
|
|
#include "360.xpm"
|
|
|
|
|
2020-12-23 21:07:43 +08:00
|
|
|
//Get a GtkImage from xpm.data
|
2020-12-21 12:09:59 +08:00
|
|
|
void Icon::get_image(const gchar **str,int width,int height){
|
|
|
|
pixbuf=gdk_pixbuf_new_from_xpm_data(str);
|
|
|
|
sized=gdk_pixbuf_scale_simple(pixbuf,width,height,GDK_INTERP_BILINEAR);
|
|
|
|
img1=gtk_image_new_from_pixbuf(sized);
|
|
|
|
}
|
2020-12-20 11:22:22 +08:00
|
|
|
|
|
|
|
//Initalize GtkButton
|
|
|
|
void GtkBtn::init(const gchar *str,int width,int height){
|
|
|
|
button=gtk_button_new_with_label(str);
|
|
|
|
gtk_widget_set_size_request(button,width,height);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Link "clicked" signal
|
|
|
|
void GtkBtn::signal_clicked(pfun func,gpointer data){
|
|
|
|
g_signal_connect(button,"clicked",G_CALLBACK(func),data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//put widget int layout
|
|
|
|
void Winlayout::put(GtkWidget *child,int x,int y){
|
|
|
|
gtk_layout_put(GTK_LAYOUT(layout),child,x,y);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Initalize Gtklayout
|
|
|
|
void Winlayout::init(){
|
2020-12-21 18:37:01 +08:00
|
|
|
Icon background;
|
|
|
|
background.get_image(winpe,400,300);
|
|
|
|
put(background.img1,0,0);
|
2020-12-26 10:54:00 +08:00
|
|
|
|
|
|
|
Combobox combo1;
|
|
|
|
combo1.init(100,50);
|
|
|
|
put(combo1.combo,150,70);
|
|
|
|
|
2020-12-20 11:22:22 +08:00
|
|
|
GtkBtn button1;
|
|
|
|
button1.init("Test",100,50);
|
2020-12-26 10:54:00 +08:00
|
|
|
button1.signal_clicked(print,(gpointer)combo1.combo);
|
|
|
|
put(button1.button,150,170);
|
2020-12-20 11:22:22 +08:00
|
|
|
}
|
|
|
|
|
2020-12-23 21:07:43 +08:00
|
|
|
//Initalize GtkHeader
|
2020-12-20 22:14:40 +08:00
|
|
|
void WinHeader::init(GtkWidget *window){
|
|
|
|
MenuBar menubar;
|
|
|
|
menubar.menu_init(window);
|
2020-12-20 20:50:10 +08:00
|
|
|
gtk_header_bar_set_show_close_button(_header,TRUE);
|
2020-12-21 12:09:59 +08:00
|
|
|
gtk_header_bar_set_decoration_layout(_header,"close,minimize,maximize:icon");
|
2020-12-20 22:14:40 +08:00
|
|
|
pack_start(menubar.menubar);
|
|
|
|
}
|
|
|
|
|
2020-12-23 21:07:43 +08:00
|
|
|
//pack widgets on GtkHeader
|
2020-12-20 22:14:40 +08:00
|
|
|
void WinHeader::pack_start(GtkWidget *child){
|
|
|
|
gtk_header_bar_pack_start(_header,child);
|
|
|
|
}
|
|
|
|
|
2020-12-23 21:07:43 +08:00
|
|
|
//Append item to GtkMenuBar
|
2020-12-20 22:14:40 +08:00
|
|
|
void MenuBar::menubar_append(Menuitem child){
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menubar),child.menuitem);
|
|
|
|
}
|
|
|
|
|
2020-12-23 21:07:43 +08:00
|
|
|
//Initalize the menu
|
2020-12-20 22:14:40 +08:00
|
|
|
void MenuBar::menu_init(GtkWidget *window){
|
|
|
|
Menuitem menuitem2;
|
|
|
|
Menu menu;
|
|
|
|
menuitem2.menuitem_init("File",NULL,NULL);
|
|
|
|
menubar_append(menuitem2);
|
|
|
|
menu.set_submenu(menuitem2);
|
|
|
|
menuitem2.menuitem_init("Exit",quit,(gpointer)window);
|
|
|
|
menu.menu_append(menuitem2);
|
2020-12-21 18:37:01 +08:00
|
|
|
|
|
|
|
menuitem2.menuitem_init("config",NULL,NULL);
|
|
|
|
menubar_append(menuitem2);
|
|
|
|
menu.set_submenu(menuitem2);
|
2020-12-26 11:11:22 +08:00
|
|
|
menuitem2.menuitem_init("Change config",config_activate,NULL);
|
|
|
|
menu.menu_append(menuitem2);
|
2020-12-25 13:35:42 +08:00
|
|
|
menuitem2.menuitem_init("Change config1",config1_activate,NULL);
|
|
|
|
menu.menu_append(menuitem2);
|
2020-12-25 23:44:06 +08:00
|
|
|
menuitem2.menuitem_init("Change config2",config2_activate,NULL);
|
2020-12-21 18:37:01 +08:00
|
|
|
menu.menu_append(menuitem2);
|
|
|
|
|
2020-12-20 22:14:40 +08:00
|
|
|
menuitem2.menuitem_init("Help",NULL,NULL);
|
|
|
|
menubar_append(menuitem2);
|
2020-12-21 18:37:01 +08:00
|
|
|
menu.set_submenu(menuitem2);
|
2020-12-22 19:33:36 +08:00
|
|
|
menuitem2.menuitem_init("About",about_activate,NULL);
|
2020-12-21 18:37:01 +08:00
|
|
|
menu.menu_append(menuitem2);
|
2020-12-20 22:14:40 +08:00
|
|
|
}
|
|
|
|
|
2020-12-23 21:07:43 +08:00
|
|
|
//append item to GtkMenu
|
2020-12-20 22:14:40 +08:00
|
|
|
void Menu::menu_append(Menuitem child){
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu),child.menuitem);
|
|
|
|
}
|
|
|
|
|
2020-12-26 11:11:22 +08:00
|
|
|
//Set a submenu of a menuitem
|
2020-12-20 22:14:40 +08:00
|
|
|
void Menu::set_submenu(Menuitem menuitem){
|
|
|
|
menu=gtk_menu_new();
|
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem.menuitem),menu);
|
|
|
|
}
|
|
|
|
|
2020-12-26 11:11:22 +08:00
|
|
|
//initalize menuitem
|
2020-12-20 22:14:40 +08:00
|
|
|
void Menuitem::menuitem_init(const gchar *str,pfun func,gpointer data){
|
|
|
|
menuitem=gtk_menu_item_new_with_label(str);
|
|
|
|
if(func!=NULL){
|
|
|
|
g_signal_connect(menuitem,"activate",G_CALLBACK(func),data);
|
|
|
|
}
|
2020-12-20 20:50:10 +08:00
|
|
|
}
|
|
|
|
|
2020-12-20 11:22:22 +08:00
|
|
|
//Add widget to window
|
|
|
|
void GtkWin::add(GtkWidget *widget){
|
|
|
|
gtk_container_add(GTK_CONTAINER(window),widget);
|
|
|
|
}
|
|
|
|
|
2020-12-26 11:11:22 +08:00
|
|
|
//Initalize window
|
2020-12-20 11:22:22 +08:00
|
|
|
void GtkWin::win_init(GtkApplication *app,int width,int height){
|
2020-12-21 12:09:59 +08:00
|
|
|
Icon icon1;
|
|
|
|
icon1.get_image(_60,50,50);
|
2020-12-20 11:22:22 +08:00
|
|
|
//Create a window and set window proprites
|
|
|
|
window=gtk_application_window_new(app);
|
|
|
|
_window=GTK_WINDOW(window);
|
|
|
|
gtk_window_set_default_size(_window,width,height);
|
|
|
|
gtk_window_set_position(_window,GTK_WIN_POS_CENTER);
|
2020-12-21 12:09:59 +08:00
|
|
|
gtk_window_set_icon(_window,icon1.pixbuf);
|
2020-12-20 20:50:10 +08:00
|
|
|
//Set window titlebar
|
|
|
|
WinHeader header1;
|
2020-12-20 22:14:40 +08:00
|
|
|
header1.init(window);
|
2020-12-20 20:50:10 +08:00
|
|
|
set_titlebar(header1.header);
|
2020-12-20 11:22:22 +08:00
|
|
|
//Put a layout
|
|
|
|
Winlayout layout1;
|
|
|
|
layout1.init();
|
|
|
|
add(layout1.layout);
|
|
|
|
}
|
|
|
|
|
2020-12-26 11:11:22 +08:00
|
|
|
//Set the window titlwbar as a custom widget
|
2020-12-20 20:50:10 +08:00
|
|
|
void GtkWin::set_titlebar(GtkWidget *title){
|
|
|
|
gtk_window_set_titlebar(_window,title);
|
|
|
|
}
|
|
|
|
|
2020-12-20 11:22:22 +08:00
|
|
|
//Show everything
|
|
|
|
void GtkWin::show_all(){
|
|
|
|
gtk_widget_show_all(window);
|
|
|
|
}
|
2020-12-22 19:33:36 +08:00
|
|
|
|
2020-12-26 11:11:22 +08:00
|
|
|
//Pack widget at a gtkbox
|
2020-12-22 19:33:36 +08:00
|
|
|
void HBox::pack_start(GtkWidget *child,gboolean expand,gboolean full,gint padding){
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox),child,expand,full,padding);
|
|
|
|
}
|
2020-12-26 10:54:00 +08:00
|
|
|
|
2020-12-26 11:11:22 +08:00
|
|
|
//Append item to a combo box
|
2020-12-26 10:54:00 +08:00
|
|
|
void Combobox::append_item(const gchar *str){
|
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo),str);
|
|
|
|
}
|
|
|
|
|
2020-12-26 11:11:22 +08:00
|
|
|
//Initalize combo box
|
2020-12-26 10:54:00 +08:00
|
|
|
void Combobox::init(int width,int height){
|
|
|
|
combo=gtk_combo_box_text_new();
|
|
|
|
gtk_widget_set_size_request(combo,width,height);
|
2020-12-26 11:11:22 +08:00
|
|
|
append_item("config");
|
2020-12-26 10:54:00 +08:00
|
|
|
append_item("config_1");
|
|
|
|
append_item("config_2");
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(combo),0);
|
|
|
|
}
|