mirror of https://github.com/daleclack/My_GtkUi
Add Prefs window
This commit is contained in:
parent
e28b4ca062
commit
d8f1fc1c69
|
@ -1,13 +1,16 @@
|
|||
#include "MainWin.h"
|
||||
#include "MyStack.h"
|
||||
|
||||
struct _MainWin{
|
||||
struct _MainWin
|
||||
{
|
||||
GtkApplicationWindow parent_class;
|
||||
MyPrefs *prefs_win;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(MainWin, main_win, GTK_TYPE_APPLICATION_WINDOW)
|
||||
|
||||
static void main_win_init(MainWin *win){
|
||||
static void main_win_init(MainWin *win)
|
||||
{
|
||||
// Initalize window
|
||||
// gtk_window_set_default_size(GTK_WINDOW(win), 1024, 576);
|
||||
gtk_window_set_icon_name(GTK_WINDOW(win), "My_GtkUI");
|
||||
|
@ -17,8 +20,21 @@ static void main_win_init(MainWin *win){
|
|||
create_main_stack(GTK_WINDOW(win));
|
||||
}
|
||||
|
||||
static void main_win_class_init(MainWinClass *win_class){}
|
||||
static void main_win_class_init(MainWinClass *win_class) {}
|
||||
|
||||
MainWin *main_win_new(GtkApplication *app){
|
||||
void main_win_set_prefs(MainWin *win, MyPrefs *prefs)
|
||||
{
|
||||
// Set Preferences widget
|
||||
win->prefs_win = prefs;
|
||||
}
|
||||
|
||||
MyPrefs *main_win_get_prefs(MainWin *win)
|
||||
{
|
||||
// Get Preferences widget
|
||||
return win->prefs_win;
|
||||
}
|
||||
|
||||
MainWin *main_win_new(GtkApplication *app)
|
||||
{
|
||||
return MAIN_WIN(g_object_new(main_win_get_type(), "application", app, NULL));
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "MyPrefs.h"
|
||||
|
||||
// Declare type for main window
|
||||
G_DECLARE_FINAL_TYPE(MainWin, main_win, MAIN, WIN, GtkApplicationWindow)
|
||||
|
||||
// Create a new main window
|
||||
MainWin *main_win_new(GtkApplication *app);
|
||||
|
||||
// The Preference widget
|
||||
void main_win_set_prefs(MainWin *win, MyPrefs *prefs);
|
||||
MyPrefs *main_win_get_prefs(MainWin *win);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "MainWin.h"
|
||||
#include "MyStack.h"
|
||||
#include "MyDock.h"
|
||||
#include "MyPrefs.h"
|
||||
|
@ -10,6 +11,15 @@ static void btnlogin_clicked(GtkWidget *widget, GtkStack *stack)
|
|||
gtk_stack_set_visible_child_name(stack, "main_page1");
|
||||
}
|
||||
|
||||
static void back_activated(GSimpleAction *actions,
|
||||
GVariant *parmeter,
|
||||
gpointer win)
|
||||
{
|
||||
// Show preferences window
|
||||
MyPrefs *prefs = main_win_get_prefs(MAIN_WIN(win));
|
||||
gtk_window_present(GTK_WINDOW(prefs));
|
||||
}
|
||||
|
||||
static void logout_activated(GSimpleAction *action,
|
||||
GVariant *parmeter,
|
||||
gpointer win)
|
||||
|
@ -77,6 +87,7 @@ void create_main_stack(GtkWindow *win)
|
|||
static GActionEntry entries[] = {
|
||||
{"logout", logout_activated, NULL, NULL, NULL},
|
||||
{"quit", quit_activated, NULL, NULL, NULL},
|
||||
{"back", back_activated, NULL, NULL, NULL},
|
||||
{"about", about_activated, NULL, NULL, NULL}};
|
||||
|
||||
// Create a builder
|
||||
|
@ -114,5 +125,11 @@ void create_main_stack(GtkWindow *win)
|
|||
// Link Signals
|
||||
g_signal_connect(btnlogin, "clicked", G_CALLBACK(btnlogin_clicked), stack);
|
||||
|
||||
// Add Preferences window
|
||||
GtkWidget *main_back = my_dock_get_background(MY_DOCK(dock));
|
||||
MyPrefs *prefs = my_prefs_new(main_back);
|
||||
gtk_window_set_transient_for(GTK_WINDOW(prefs), win);
|
||||
main_win_set_prefs(MAIN_WIN(win), prefs);
|
||||
|
||||
gtk_window_set_child(win, stack);
|
||||
}
|
||||
|
|
|
@ -8,14 +8,22 @@ struct _MyPrefs{
|
|||
|
||||
G_DEFINE_TYPE(MyPrefs, my_prefs, GTK_TYPE_WINDOW)
|
||||
|
||||
gboolean my_prefs_closed(GtkWindow *window)
|
||||
{
|
||||
gtk_widget_set_visible(GTK_WIDGET(window), FALSE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void my_prefs_init(MyPrefs *self){}
|
||||
|
||||
static void my_prefs_class_init(MyPrefsClass *klass)
|
||||
{}
|
||||
|
||||
GtkWidget *my_prefs_new(GtkWidget *back)
|
||||
{
|
||||
GtkWidget *prefs_win = GTK_WIDGET(g_object_new(my_prefs_get_type(), NULL));
|
||||
GTK_WINDOW_CLASS(klass)->close_request = my_prefs_closed;
|
||||
}
|
||||
|
||||
MyPrefs *my_prefs_new(GtkWidget *back)
|
||||
{
|
||||
MyPrefs *prefs_win = MY_PREFS(g_object_new(my_prefs_get_type(), NULL));
|
||||
MY_PREFS(prefs_win)->background = back;
|
||||
return prefs_win;
|
||||
}
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
G_DECLARE_FINAL_TYPE(MyPrefs, my_prefs, MY, PREFS, GtkWindow)
|
||||
|
||||
GtkWidget *my_prefs_new(GtkWidget *back);
|
||||
MyPrefs *my_prefs_new(GtkWidget *back);
|
||||
|
|
Loading…
Reference in New Issue