diff --git a/Gtk4/CMakeLists.txt b/Gtk4/CMakeLists.txt
index b53f568..6b71e84 100644
--- a/Gtk4/CMakeLists.txt
+++ b/Gtk4/CMakeLists.txt
@@ -54,7 +54,8 @@ set(RESOURCE_LIST
icons/scalable/status/system.svg
gnome-fs-directory.png
gnome-fs-regular.png
- STRIPBLANKS appmenu.xml)
+ STRIPBLANKS appmenu.xml
+ STRIPBLANKS stack.ui)
compile_gresources(RESOURCE_FILE
XML_OUT
@@ -67,7 +68,7 @@ compile_gresources(RESOURCE_FILE
# It depends on the output RESOURCE_FILE.
add_custom_target(resource ALL DEPENDS ${RESOURCE_FILE})
-set(SOURCES src/main.cpp src/MainWin.cpp)
+set(SOURCES src/main.cpp src/MainWin.cpp src/MainStack.cpp)
# Step 4:Add the resource to compile list and compile
if(WIN32)
diff --git a/Gtk4/res/stack.ui b/Gtk4/res/stack.ui
new file mode 100644
index 0000000..65235a7
--- /dev/null
+++ b/Gtk4/res/stack.ui
@@ -0,0 +1,216 @@
+
+
+
+
+
+
+
diff --git a/Gtk4/res/window.ui b/Gtk4/res/window.ui
deleted file mode 100644
index 1012dc7..0000000
--- a/Gtk4/res/window.ui
+++ /dev/null
@@ -1,51 +0,0 @@
-
-
-
-
-
- True
- False
- user-home
-
-
- False
- gtk(42)
- 640
- 360
- True
- gtk4-icon
-
-
- True
- False
-
-
- 100
- 80
- True
- False
- gtk-missing-image
-
-
-
-
- Home
- 100
- 80
- True
- True
- True
- image1
- none
- top
- True
-
-
- 70
- 30
-
-
-
-
-
-
diff --git a/Gtk4/src/MainStack.cpp b/Gtk4/src/MainStack.cpp
new file mode 100644
index 0000000..14e330f
--- /dev/null
+++ b/Gtk4/src/MainStack.cpp
@@ -0,0 +1,48 @@
+#include "MainStack.h"
+
+static gboolean change_time(gpointer data){
+ //Get local time
+ time_t t;
+ struct tm *local;
+ t=time(NULL);
+ local=localtime(&t);
+ //Format the time and set the time
+ char current_time[20];
+ sprintf(current_time,"%02d:%02d %04d/%02d/%02d",
+ local->tm_hour,local->tm_min,local->tm_year+1900,local->tm_mon+1,local->tm_mday);
+ //g_print("%s\n",current_time);
+ gtk_label_set_label(GTK_LABEL(data),current_time);
+ return TRUE;
+}
+
+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){
+ GtkBuilder * stack_builder;
+ stack_builder = gtk_builder_new_from_resource("/org/gtk/daleclack/stack.ui");
+
+ //Get Main Widget
+ GtkWidget * main_stack;
+ main_stack = (GtkWidget*)gtk_builder_get_object(stack_builder,"stack");
+
+ //Login Button
+ GtkWidget * btnlogin = (GtkWidget*)gtk_builder_get_object(stack_builder,"btnlogin");
+ g_signal_connect(btnlogin,"clicked",G_CALLBACK(stack_login),main_stack);
+
+ //Time Label
+ GtkWidget * label_time = (GtkWidget*)gtk_builder_get_object(stack_builder,"label_time");
+ g_timeout_add(100,change_time,label_time);
+
+ //Menu Button
+ GtkWidget * menubtn = (GtkWidget*)gtk_builder_get_object(stack_builder,"menu_button");
+ GtkWidget * popover = gtk_popover_menu_new_from_model(model);
+ gtk_widget_set_halign(popover,GTK_ALIGN_END);
+ gtk_menu_button_set_popover(GTK_MENU_BUTTON(menubtn),popover);
+
+ //Box for LeftPanel
+ left_box = (GtkWidget*)gtk_builder_get_object(stack_builder,"leftbox");
+
+ return main_stack;
+}
diff --git a/Gtk4/src/MainStack.h b/Gtk4/src/MainStack.h
new file mode 100644
index 0000000..7195c63
--- /dev/null
+++ b/Gtk4/src/MainStack.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#include
+#include
+
+GtkWidget * create_main_stack(GtkWidget * left_box,GMenuModel * model);
diff --git a/Gtk4/src/MainWin.cpp b/Gtk4/src/MainWin.cpp
index 5585ec9..4f7ec93 100644
--- a/Gtk4/src/MainWin.cpp
+++ b/Gtk4/src/MainWin.cpp
@@ -1,6 +1,8 @@
#include "MainWin.h"
+#include "MainStack.h"
#include "winpe.xpm"
#include "img7.xpm"
+#include "image_types.h"
enum class BackMode{
DEFAULT_1,
@@ -14,17 +16,70 @@ struct _MainWin{
GtkWidget * overlay;
GtkGesture * gesture;
GtkWidget * popover;
+ GtkWidget * stack;
+ GtkWidget * leftbox;
int width,height;
BackMode back_mode;
};
G_DEFINE_TYPE(MainWin,main_win,GTK_TYPE_APPLICATION_WINDOW)
-static void change_background(GtkWindow * dialog,int response,MainWin *win){
- gtk_window_destroy(dialog);
+static void change_background(GtkNativeDialog * dialog,int response,MainWin *win){
+ if(response == GTK_RESPONSE_ACCEPT){
+ GFile * file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog));
+ char * filename = g_file_get_path(file);
+
+ //Set Image from the file
+ GdkPixbuf * pixbuf, * sized;
+ pixbuf = gdk_pixbuf_new_from_file(filename,NULL);
+ sized = gdk_pixbuf_scale_simple(pixbuf,win->width,win->height,GDK_INTERP_BILINEAR);
+ gtk_picture_set_pixbuf(GTK_PICTURE(win->background),sized);
+
+ //Change Mode and free memory
+ win->back_mode = BackMode::CUSTOM;
+ g_object_unref(pixbuf);
+ g_object_unref(sized);
+ g_object_unref(file);
+ g_free(filename);
+ }
+ gtk_native_dialog_destroy(dialog);
}
static void background_dialog(GSimpleAction * action, GVariant * parmeter, gpointer data){
+ GtkFileChooserNative * dialog = gtk_file_chooser_native_new("Open Image File",GTK_WINDOW(data),
+ GTK_FILE_CHOOSER_ACTION_OPEN,"OK","Cancel");
+
+ GtkFileFilter * filter_image = gtk_file_filter_new();
+ gtk_file_filter_set_name(filter_image,"Image Files");
+
+ //For Systems supported mime type and not supported, use different way
+ if(mime_type_supported()){
+ gtk_file_filter_add_mime_type(filter_image,"image/*");
+ }else{
+ for(int i=0;supported_globs !=NULL && supported_globs[i]!=NULL;i++){
+ const char * glob = supported_globs[i];
+ gtk_file_filter_add_pattern(filter_image,glob);
+ }
+ }
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter_image);
+
+ GtkFileFilter * filter_any = gtk_file_filter_new();
+ gtk_file_filter_set_name(filter_any,"Any Files");
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter_any);
+
+ g_signal_connect(dialog,"response",G_CALLBACK(change_background),data);
+ gtk_native_dialog_show(GTK_NATIVE_DIALOG(dialog));
+}
+
+static void logout_activated(GSimpleAction * action, GVariant * parmeter, gpointer data){
+ MainWin * win = MAIN_WIN(data);
+ gtk_stack_set_visible_child_name(GTK_STACK(win->stack),"login_page");
+}
+
+static void quit_activated(GSimpleAction * action, GVariant * parmeter, gpointer data){
+ gtk_window_destroy(GTK_WINDOW(data));
+}
+static void winsize_activated(GSimpleAction * action, GVariant * parmeter, gpointer data){
}
static void default_background1(GSimpleAction * action, GVariant * parmeter, gpointer data){
@@ -72,7 +127,29 @@ static void refresh_activated(GSimpleAction * action, GVariant * parmeter, gpoin
static void about_activated(GSimpleAction * action, GVariant * parmeter, gpointer data){
GtkWindow * win =GTK_WINDOW(data);
-
+ const char *authors[]={
+ "Dale Clack",
+ "GCR_CMake on github https://github.com/Makman2/GCR_CMake",
+ NULL
+ };
+ char *version;
+ version=g_strdup_printf("4.0-Beta1\nRunning Against GTK %d.%d.%d",
+ gtk_get_major_version(),
+ gtk_get_minor_version(),
+ gtk_get_micro_version());
+ GtkWidget *dialog;
+ dialog=gtk_about_dialog_new();
+ gtk_show_about_dialog(win,
+ "program-name","My_GtkUI",
+ "version",version,
+ "copyright", "© 2019—2021 The Xe Project",
+ "comments", "A program that simulates desktop",
+ "authors",authors,
+ "license-type",GTK_LICENSE_GPL_3_0,
+ "logo-icon-name","My_GtkUI",
+ "title","About My GtkUI (Gtk4 Version)",
+ NULL);
+ g_free(version);
}
static void gesture_pressed(GtkGestureClick *self,int n_press,double x,double y,MainWin * win){
@@ -90,7 +167,11 @@ static GActionEntry entries[] = {
{"back",background_dialog,NULL,NULL,NULL},
{"default1",default_background1,NULL,NULL,NULL},
{"default2",default_background2,NULL,NULL,NULL},
- {"refresh",refresh_activated,NULL,NULL,NULL}
+ {"refresh",refresh_activated,NULL,NULL,NULL},
+ {"about",about_activated,NULL,NULL,NULL},
+ {"logout",logout_activated,NULL,NULL,NULL},
+ {"quit",quit_activated,NULL,NULL,NULL},
+ {"size",winsize_activated,NULL,NULL,NULL}
};
static void main_win_init(MainWin * win){
@@ -125,6 +206,12 @@ static void main_win_init(MainWin * win){
g_signal_connect(win->gesture,"pressed",G_CALLBACK(gesture_pressed),win);
gtk_widget_add_controller(win->overlay,GTK_EVENT_CONTROLLER(win->gesture));
+ //Add Main Page
+ win->stack = create_main_stack(win->leftbox,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));
+
gtk_window_set_child(GTK_WINDOW(win),win->overlay);
g_object_unref(menu_builder);
}
diff --git a/Gtk4/src/panel1.cpp b/Gtk4/src/panel1.cpp
deleted file mode 100644
index 643c8c0..0000000
--- a/Gtk4/src/panel1.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-#include
-#include "panel1.h"
-#include "winconf.h"
-#include "background.h"
-
-static gboolean change_time(gpointer data){
- //Get local time
- time_t t;
- struct tm *local;
- t=time(NULL);
- local=localtime(&t);
- //Format the time and set the time
- char current_time[20];
- sprintf(current_time,"%02d:%02d %04d/%02d/%02d",
- local->tm_hour,local->tm_min,local->tm_year+1900,local->tm_mon+1,local->tm_mday);
- //g_print("%s\n",current_time);
- gtk_label_set_label(GTK_LABEL(data),current_time);
- return TRUE;
-}
-
-void add_toppanel(GtkBuilder *builder,GtkFixed *fixed){
- //Get position
- int width=640,height=480;
- get_config(&width,&height);
- //Get panel
- GtkBuilder *panel=gtk_builder_new_from_resource("/gtk42/toppanel.ui");
- GObject *panel1=gtk_builder_get_object(panel,"btnbox");
- gtk_widget_set_size_request(GTK_WIDGET(panel1),width,15);
- //Get timer label and set time
- GObject *label_time=gtk_builder_get_object(panel,"label_time");
- g_timeout_add(100,change_time,label_time);
- //Get popover window
- GObject *popover=gtk_builder_get_object(panel,"popover1");
- //Get button for change background
- GObject *btn_back=gtk_builder_get_object(panel,"btnback");
- GObject *img_back=gtk_builder_get_object(panel,"image3");
- gtk_image_set_from_resource(GTK_IMAGE(img_back),"/gtk42/graphics.png");
- //gtk_button_set_image(GTK_BUTTON(btn_back),GTK_WIDGET(img_back));
- gtk_button_set_always_show_image(GTK_BUTTON(btn_back),TRUE);
- g_signal_connect(btn_back,"clicked",G_CALLBACK(fileopen),builder);
- g_signal_connect_swapped(btn_back,"clicked",G_CALLBACK(gtk_widget_hide),popover);
- //Config button
- GObject *btn_conf=gtk_builder_get_object(panel,"btnset");
- GObject *img_set=gtk_builder_get_object(panel,"image5");
- gtk_image_set_from_resource(GTK_IMAGE(img_set),"/gtk42/system.png");
- //gtk_button_set_image(GTK_BUTTON(btn_conf),GTK_WIDGET(img_set));
- gtk_button_set_always_show_image(GTK_BUTTON(btn_conf),TRUE);
- g_signal_connect(btn_conf,"clicked",G_CALLBACK(conf_dialog),builder);
- g_signal_connect_swapped(btn_conf,"clicked",G_CALLBACK(gtk_widget_hide),popover);
- //Get Exit button
- GObject *btn_exit=gtk_builder_get_object(panel,"PanelExit");
- GObject *img_exit=gtk_builder_get_object(panel,"image4");
- gtk_image_set_from_resource(GTK_IMAGE(img_exit),"/gtk42/log-out.png");
- //gtk_button_set_image(GTK_BUTTON(btn_exit),GTK_WIDGET(img_exit));
- gtk_button_set_always_show_image(GTK_BUTTON(btn_exit),TRUE);
- GObject *window=gtk_builder_get_object(builder,"window");
- g_signal_connect_swapped(btn_exit,"clicked",G_CALLBACK(gtk_widget_destroy),window);
- gtk_fixed_put(fixed,GTK_WIDGET(panel1),0,0);
-}
diff --git a/Gtk4/src/panel1.h b/Gtk4/src/panel1.h
deleted file mode 100644
index 59be4f8..0000000
--- a/Gtk4/src/panel1.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef __TIMER_H_
-#define __TIMER_H_
-
-#include
-
-//gboolean change_time(gpointer data);
-
-void add_toppanel(GtkBuilder *builder,GtkFixed *fixed);
-
-#endif