diff --git a/Gtk4/CMakeLists.txt b/Gtk4/CMakeLists.txt index 6555617..ae153ba 100644 --- a/Gtk4/CMakeLists.txt +++ b/Gtk4/CMakeLists.txt @@ -55,7 +55,8 @@ set(RESOURCE_LIST gnome-fs-directory.png gnome-fs-regular.png STRIPBLANKS appmenu.xml - STRIPBLANKS stack.ui) + STRIPBLANKS stack.ui + STRIPBLANKS leftpanel.ui) compile_gresources(RESOURCE_FILE XML_OUT diff --git a/Gtk4/res/image_label.ui b/Gtk4/res/image_label.ui new file mode 100644 index 0000000..6a06e4a --- /dev/null +++ b/Gtk4/res/image_label.ui @@ -0,0 +1,16 @@ + + + + + + + 16 + + + + + label + + + + diff --git a/Gtk4/res/leftpanel.ui b/Gtk4/res/leftpanel.ui index db154d5..26fbac8 100644 --- a/Gtk4/res/leftpanel.ui +++ b/Gtk4/res/leftpanel.ui @@ -1,284 +1,347 @@ - - - - True - False - - - True - False - - - True - False - gtk-about - + - 300 + 320 400 - False - + start + 0 + - True - True + 1 + 1 left - True + 1 - - True - False - vertical - - - audacious - True - True - True - none - True + + + + 1 + vertical + + + 1 + 1 + 1 + 0 + + + + + 16 + audacious + + + + + audacious + 1 + + + + + + + + + 1 + 1 + 1 + 0 + + + + + 16 + gedit + + + + + Gedit Text Editor + 1 + + + + + + + + + 1 + 1 + 1 + 0 + + + + + 16 + vlc + + + + + VLC Media Player + 1 + + + + + + + + + + + + - - False - True - 0 - - - - - Gedit Text Editor - True - True - True - image2 - none - True + + + + 1 + Applications (Linux) - - False - True - 1 - - - - - VLC Media Player - True - True - True - image1 - none - True - - - False - True - 2 - - - - - - - - + - - - True - False - Applications (Linux) - - - False - - - - True - False - vertical - - - VLC Media Player - True - True - True - none - True - - - False - True - 0 - - - - - Notepad - True - True - True - none - True - - - False - True - 1 - - - - - - - - - - - - - + 1 - - - - - True - False - Applications (Win32) + + + 1 + vertical + + + 1 + 1 + 1 + 0 + + + + + 16 + vlc + + + + + VLC Media Player + 1 + + + + + + + + + 1 + 1 + 1 + 0 + + + + + 16 + gedit + + + + + Notepad + 1 + + + + + + + + + + + + + + + + + + + + 1 + Applications (Win32) + + - - 1 - False - - - True - False - vertical - - - About - True - True - True - image3 - none - - - False - True - 0 - - - - - File Manager - True - True - True - none - - - False - True - 1 - - - - - Drawing App - True - True - True - none - - - False - True - 2 - - - - - Guess Game - True - True - True - none - - - False - True - 3 - - - - - Simple Text Editor - True - True - True - none - - - False - True - 4 - - - - + 2 - - - - - True - False - General Apps + + + 1 + vertical + + + 1 + 1 + 1 + 0 + + + + + 16 + mygtkui_about + + + + + About + 1 + + + + + + + + + 1 + 1 + 1 + 0 + + + + + 16 + drawing_app + + + + + Drawing App + 1 + + + + + + + + + 1 + 1 + 1 + 0 + + + + + 16 + file-app + + + + + File Manager + 1 + + + + + + + + + 1 + 1 + 1 + 0 + + + + + 16 + game + + + + + Guess Game + 1 + + + + + + + + + 1 + 1 + 1 + 0 + Run + + + + + 1 + 1 + 1 + 0 + + + + + 16 + gedit + + + + + Simple Text Editor + 1 + + + + + + + + + + + 1 + General Apps + + - - 2 - False - - + - - True - False + diff --git a/Gtk4/src/LeftPanel.cpp b/Gtk4/src/LeftPanel.cpp index 534b100..bb317ee 100644 --- a/Gtk4/src/LeftPanel.cpp +++ b/Gtk4/src/LeftPanel.cpp @@ -1,6 +1,7 @@ #include #include #include "LeftPanel.h" +#include "MainWin.h" // #include "game.h" // #include "TextEditor.h" // #include "drawing.h" @@ -8,6 +9,20 @@ struct _LeftPanel{ GtkBox parent; + GtkWindow * parent_win; + GtkWidget * popover1; + GtkWidget * btnstart; + GtkWidget * btnaud; + GtkWidget * btngedit; + GtkWidget * btnvlc; + GtkWidget * btn_vlc; + GtkWidget * btn_note; + GtkWidget * btnabout; + GtkWidget * btnfiles; + GtkWidget * btndraw; + GtkWidget * btngame; + GtkWidget * btnrun; + GtkWidget * btneditor; }; G_DEFINE_TYPE(LeftPanel,left_panel,GTK_TYPE_BOX) @@ -37,9 +52,49 @@ static void btnvlc_win32(GtkWidget *widget,gpointer data){ fifth.detach(); } -static void left_panel_init(LeftPanel * panel){} +void left_panel_set_parent(LeftPanel * self,GtkWindow * parent_win1){ + self->parent_win = parent_win1; +} -static void left_panel_class_init(LeftPanelClass * klass){} +static void left_panel_init(LeftPanel * panel){ + gtk_widget_init_template(GTK_WIDGET(panel)); + + //Set Image for start button + gtk_menu_button_set_label(GTK_MENU_BUTTON(panel->btnstart),"Start"); + + //Connect Signals + g_signal_connect(panel->btnaud,"clicked",G_CALLBACK(btnaud_clicked),NULL); + g_signal_connect_swapped(panel->btnaud,"clicked",G_CALLBACK(gtk_popover_popdown),panel->popover1); + g_signal_connect(panel->btnvlc,"clicked",G_CALLBACK(btnvlc_clicked),NULL); + g_signal_connect_swapped(panel->btnvlc,"clicked",G_CALLBACK(gtk_popover_popdown),panel->popover1); + g_signal_connect(panel->btngedit,"clicked",G_CALLBACK(btngedit_clicked),NULL); + g_signal_connect_swapped(panel->btngedit,"clicked",G_CALLBACK(gtk_popover_popdown),panel->popover1); + g_signal_connect(panel->btn_note,"clicked",G_CALLBACK(btnnote_clicked),NULL); + g_signal_connect_swapped(panel->btn_note,"clicked",G_CALLBACK(gtk_popover_popdown),panel->popover1); + g_signal_connect(panel->btn_vlc,"clicked",G_CALLBACK(btnvlc_win32),NULL); + g_signal_connect_swapped(panel->btn_vlc,"clicked",G_CALLBACK(gtk_popover_popdown),panel->popover1); + g_signal_connect(panel->btnabout,"clicked",G_CALLBACK(btnabout_clicked),panel->parent_win); + g_signal_connect_swapped(panel->btnabout,"clicked",G_CALLBACK(gtk_popover_popdown),panel->popover1); +} + +static void left_panel_class_init(LeftPanelClass * klass){ + gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS(klass), + "/org/gtk/daleclack/leftpanel.ui"); + + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,popover1); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btnstart); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btnaud); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btngedit); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btnvlc); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btn_vlc); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btn_note); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btnabout); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btndraw); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btnfiles); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btngame); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btnrun); + gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(klass),LeftPanel,btneditor); +} LeftPanel * left_panel_new(){ return (LeftPanel*)g_object_new(left_panel_get_type(),NULL); @@ -52,49 +107,6 @@ LeftPanel * left_panel_new(){ // } // void add_leftpanel(GtkBuilder *builder,GtkFixed *fixed){ -// //Get Left panel -// GtkBuilder *panel2=gtk_builder_new_from_resource("/gtk42/leftpanel.ui"); -// GObject *panel=gtk_builder_get_object(panel2,"left_panel"); -// //Set start button and image -// GObject *btn_image=gtk_builder_get_object(panel2,"btn_image"); -// GdkPixbuf *pixbuf=gdk_pixbuf_new_from_resource("/gtk42/icon.png",NULL); -// GdkPixbuf *sized=gdk_pixbuf_scale_simple(pixbuf,40,40,GDK_INTERP_BILINEAR); -// gtk_image_set_from_pixbuf(GTK_IMAGE(btn_image),sized); -// //Get popover window -// GObject *popover=gtk_builder_get_object(panel2,"popover1"); -// //Button image -// GtkWidget *img_vlc=gtk_image_new_from_resource("/gtk42/vlc.png"); -// GtkWidget *img_aud=gtk_image_new_from_resource("/gtk42/audacious.png"); -// GtkWidget *img_gedit=gtk_image_new_from_resource("/gtk42/gedit.png"); -// //Audacious bin exec -// GObject *btn_audacious=gtk_builder_get_object(panel2,"btnaud"); -// gtk_button_set_image(GTK_BUTTON(btn_audacious),img_aud); -// g_signal_connect(btn_audacious,"clicked",G_CALLBACK(btnaud_clicked),NULL); -// g_signal_connect_swapped(btn_audacious,"clicked",G_CALLBACK(gtk_widget_hide),popover); -// //vlc exec button for linux -// GObject *btnvlc=gtk_builder_get_object(panel2,"btnvlc"); -// GObject *img_vlc1=gtk_builder_get_object(panel2,"image1"); -// gtk_image_set_from_resource(GTK_IMAGE(img_vlc1),"/gtk42/vlc.png"); -// g_signal_connect(btnvlc,"clicked",G_CALLBACK(btnvlc_clicked),NULL); -// g_signal_connect_swapped(btnvlc,"clicked",G_CALLBACK(gtk_widget_hide),popover); -// //Start Gedit Text Editor -// GObject *btngedit=gtk_builder_get_object(panel2,"btngedit"); -// GObject *img_gedit1=gtk_builder_get_object(panel2,"image2"); -// gtk_image_set_from_resource(GTK_IMAGE(img_gedit1),"/gtk42/gedit.png"); -// g_signal_connect(btngedit,"clicked",G_CALLBACK(btngedit_clicked),NULL); -// g_signal_connect_swapped(btngedit,"clicked",G_CALLBACK(gtk_widget_hide),popover); -// //Notepad on windows -// GObject *btnnote=gtk_builder_get_object(panel2,"btn_note"); -// gtk_button_set_image(GTK_BUTTON(btnnote),img_gedit); -// g_signal_connect(btnnote,"clicked",G_CALLBACK(btnnote_clicked),NULL); -// g_signal_connect_swapped(btnnote,"clicked",G_CALLBACK(gtk_widget_hide),popover); -// //VLC on windows -// GObject *btn_vlc=gtk_builder_get_object(panel2,"btn_vlc"); -// gtk_button_set_image(GTK_BUTTON(btn_vlc),img_vlc); -// g_signal_connect(btn_vlc,"clicked",G_CALLBACK(btnvlc_win32),NULL); -// g_signal_connect_swapped(btn_vlc,"clicked",G_CALLBACK(gtk_widget_hide),popover); -// //Get main window -// GObject *window=gtk_builder_get_object(builder,"window"); // //Gtk31 application // GObject *btngame=gtk_builder_get_object(panel2,"btngame"); // g_signal_connect(btngame,"clicked",G_CALLBACK(gamemain),window); diff --git a/Gtk4/src/LeftPanel.h b/Gtk4/src/LeftPanel.h index eb29b07..43cb1b6 100644 --- a/Gtk4/src/LeftPanel.h +++ b/Gtk4/src/LeftPanel.h @@ -6,16 +6,4 @@ G_DECLARE_FINAL_TYPE(LeftPanel,left_panel,LEFT,PANEL,GtkBox) LeftPanel * left_panel_new(); -// void add_leftpanel(GtkBuilder *builder,GtkFixed *fixed); - -// void btnfiles_clicked(GtkWidget *widget,GtkWindow *parent); - -//void btnvlc_clicked(GtkWidget *widget,gpointer data); - -//void btngedit_clicked(GtkWidget *widget,gpointer data); - -//void btnaud_clicked(GtkWidget *widget,gpointer data); - -//void btnnote_clicked(GtkWidget *widget,gpointer data); - -//void btnvlc_win32(GtkWidget *widget,gpointer data); +void left_panel_set_parent(LeftPanel * self,GtkWindow * parent_win1); diff --git a/Gtk4/src/MainStack.cpp b/Gtk4/src/MainStack.cpp index 14e330f..b856eb8 100644 --- a/Gtk4/src/MainStack.cpp +++ b/Gtk4/src/MainStack.cpp @@ -1,4 +1,5 @@ #include "MainStack.h" +#include "LeftPanel.h" static gboolean change_time(gpointer data){ //Get local time @@ -19,7 +20,7 @@ static void stack_login(GtkWidget *widget,GtkStack * stack){ gtk_stack_set_visible_child_name(stack,"main_page"); } -GtkWidget * create_main_stack(GtkWidget * left_box,GMenuModel * model){ +GtkWidget * create_main_stack(MainWin * win,GMenuModel * model){ GtkBuilder * stack_builder; stack_builder = gtk_builder_new_from_resource("/org/gtk/daleclack/stack.ui"); @@ -42,7 +43,10 @@ GtkWidget * create_main_stack(GtkWidget * left_box,GMenuModel * model){ gtk_menu_button_set_popover(GTK_MENU_BUTTON(menubtn),popover); //Box for LeftPanel - left_box = (GtkWidget*)gtk_builder_get_object(stack_builder,"leftbox"); + GtkWidget * left_box = (GtkWidget*)gtk_builder_get_object(stack_builder,"leftbox"); + LeftPanel * panel = left_panel_new(); + left_panel_set_parent(panel,GTK_WINDOW(win)); + gtk_box_append(GTK_BOX(left_box),GTK_WIDGET(panel)); return main_stack; } diff --git a/Gtk4/src/MainStack.h b/Gtk4/src/MainStack.h index 7195c63..6a5b2fe 100644 --- a/Gtk4/src/MainStack.h +++ b/Gtk4/src/MainStack.h @@ -2,5 +2,6 @@ #include #include +#include "MainWin.h" -GtkWidget * create_main_stack(GtkWidget * left_box,GMenuModel * model); +GtkWidget * create_main_stack(MainWin * win,GMenuModel * model); diff --git a/Gtk4/src/MainWin.cpp b/Gtk4/src/MainWin.cpp index 4f7ec93..3697145 100644 --- a/Gtk4/src/MainWin.cpp +++ b/Gtk4/src/MainWin.cpp @@ -17,7 +17,6 @@ struct _MainWin{ GtkGesture * gesture; GtkWidget * popover; GtkWidget * stack; - GtkWidget * leftbox; int width,height; BackMode back_mode; }; @@ -143,7 +142,7 @@ static void about_activated(GSimpleAction * action, GVariant * parmeter, gpointe "program-name","My_GtkUI", "version",version, "copyright", "© 2019—2021 The Xe Project", - "comments", "A program that simulates desktop", + "comments", "A program that simulates desktop (Gtk4 Version)", "authors",authors, "license-type",GTK_LICENSE_GPL_3_0, "logo-icon-name","My_GtkUI", @@ -152,6 +151,10 @@ static void about_activated(GSimpleAction * action, GVariant * parmeter, gpointe g_free(version); } +void btnabout_clicked(GtkWidget * widget,gpointer data){ + about_activated(NULL,NULL,data); +} + static void gesture_pressed(GtkGestureClick *self,int n_press,double x,double y,MainWin * win){ //When third button is pressed, show popover menu GdkRectangle rect; @@ -207,7 +210,7 @@ static void main_win_init(MainWin * win){ gtk_widget_add_controller(win->overlay,GTK_EVENT_CONTROLLER(win->gesture)); //Add Main Page - win->stack = create_main_stack(win->leftbox,model); + win->stack = create_main_stack(win,model); gtk_widget_set_halign(GTK_WIDGET(win->stack),GTK_ALIGN_FILL); gtk_widget_set_valign(GTK_WIDGET(win->stack),GTK_ALIGN_FILL); gtk_overlay_add_overlay(GTK_OVERLAY(win->overlay),GTK_WIDGET(win->stack)); diff --git a/Gtk4/src/MainWin.h b/Gtk4/src/MainWin.h index c6f4f54..f830755 100644 --- a/Gtk4/src/MainWin.h +++ b/Gtk4/src/MainWin.h @@ -5,3 +5,5 @@ G_DECLARE_FINAL_TYPE(MainWin,main_win,MAIN,WIN,GtkApplicationWindow) MainWin * main_win_new(GtkApplication *app); + +void btnabout_clicked(GtkWidget * widget,gpointer data);