mirror of https://github.com/daleclack/My_GtkUi
Restore window for calc app
This commit is contained in:
parent
9bee854523
commit
555b608568
|
@ -26,7 +26,8 @@ link_directories (${GTK_LIBRARY_DIRS})
|
|||
set(SOURCES src/core/main.cpp src/core/MainWin.cpp src/core/MyStack.cpp
|
||||
src/core/MyItem.cpp src/ui/MyDock.cpp src/ui/MyFinder.cpp src/ui/MyPrefs.cpp
|
||||
src/ui/AppView.cpp src/file_app/FileColumnView.cpp src/file_app/FileGridView.cpp
|
||||
src/file_app/FileWindow.cpp src/game_app/GameApp.cpp)
|
||||
src/file_app/FileWindow.cpp src/game_app/GameApp.cpp src/calc_app/calc.cpp
|
||||
src/calc_app/CalcApp.cpp)
|
||||
|
||||
#Compile resources with GCR_CMake
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<object class="GtkWindow" id="window">
|
||||
<template class="CalcApp" parent="GtkWindow">
|
||||
<!-- <object class="GtkWindow" id="window"> -->
|
||||
<property name="default-width">440</property>
|
||||
<property name="default-height">260</property>
|
||||
<property name="child">
|
||||
|
@ -315,5 +316,6 @@
|
|||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</template>
|
||||
<!-- </object> -->
|
||||
</interface>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_DECLARE_FINAL_TYPE(CalcApp, calc_app, CALC, APP, GtkWindow)
|
||||
|
||||
CalcApp *calc_app_new();
|
|
@ -1,33 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
class CalcApp : public Gtk::Window
|
||||
{
|
||||
public:
|
||||
static CalcApp *create();
|
||||
CalcApp(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Glade);
|
||||
|
||||
private:
|
||||
// Main GtkBuilder
|
||||
Glib::RefPtr<Gtk::Builder> ref_builder;
|
||||
|
||||
// Calculator Class
|
||||
int pos;
|
||||
bool focused;
|
||||
Glib::ustring tmp;
|
||||
|
||||
// Child widgets
|
||||
Gtk::Entry *entry_ans;
|
||||
Gtk::Button *btns[18], *btnback, *btnclear, *btnanswer,
|
||||
*btnsqrt, *btnpow;
|
||||
|
||||
// Signal Handlers
|
||||
void btns_clicked(Gtk::Button *button);
|
||||
void btnclear_clicked();
|
||||
void btnback_clicked();
|
||||
void btnanswer_clicked();
|
||||
void btnpow_clicked();
|
||||
void btnsqrt_clicked();
|
||||
void entry_ans_focus();
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
#include "CalcApp.h"
|
||||
#include "calc.h"
|
||||
|
||||
struct _CalcApp
|
||||
{
|
||||
GtkWindow parent_instance;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(CalcApp, calc_app, GTK_TYPE_WINDOW)
|
||||
|
||||
static void calc_app_dispose(GObject *object)
|
||||
{
|
||||
gtk_widget_dispose_template(GTK_WIDGET(object),
|
||||
calc_app_get_type());
|
||||
G_OBJECT_CLASS(calc_app_parent_class)->dispose(object);
|
||||
}
|
||||
|
||||
static void calc_app_init(CalcApp *self)
|
||||
{
|
||||
gtk_widget_init_template(GTK_WIDGET(self));
|
||||
}
|
||||
|
||||
static void calc_app_class_init(CalcAppClass *klass)
|
||||
{
|
||||
G_OBJECT_CLASS(klass)->dispose = calc_app_dispose;
|
||||
gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS(klass),
|
||||
"/org/gtk/daleclack/calcapp.ui");
|
||||
}
|
||||
|
||||
CalcApp *calc_app_new()
|
||||
{
|
||||
return CALC_APP(g_object_new(calc_app_get_type(), NULL));
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
#include "AppView.h"
|
||||
#include "FileWindow.h"
|
||||
#include "GameApp.h"
|
||||
#include "CalcApp.h"
|
||||
|
||||
enum PadPage
|
||||
{
|
||||
|
@ -36,6 +37,7 @@ struct _MyDock
|
|||
MyPrefs *prefs_win; // Prefs window
|
||||
FileWindow *file_win; // File Broswer window
|
||||
GameApp *game_win; // The Guess Game
|
||||
CalcApp *calc_win; // Calc App
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(MyDock, my_dock, GTK_TYPE_BOX)
|
||||
|
@ -236,6 +238,47 @@ static gboolean game_win_closed(GtkWidget *game_win, MyDock *dock)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void padcalc_clicked(GtkWindow *window, MyDock *dock)
|
||||
{
|
||||
// When the window visible, unminimize it
|
||||
if (gtk_widget_get_visible(GTK_WIDGET((dock->calc_win))))
|
||||
{
|
||||
gtk_window_unminimize(GTK_WINDOW(dock->calc_win));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show the window
|
||||
gtk_window_set_transient_for(GTK_WINDOW(dock->calc_win), dock->parent_win);
|
||||
gtk_window_present(GTK_WINDOW(dock->calc_win));
|
||||
}
|
||||
gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_calc), "calcapp_running");
|
||||
btnlaunch_clicked(NULL, dock);
|
||||
}
|
||||
|
||||
static void btncalc_clicked(GtkWidget *widget, MyDock *dock)
|
||||
{
|
||||
// When the window visible, control window state
|
||||
if (gtk_widget_get_visible(GTK_WIDGET((dock->calc_win))))
|
||||
{
|
||||
window_ctrl(GTK_WINDOW(dock->calc_win), dock->parent_win);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show the window
|
||||
gtk_window_set_transient_for(GTK_WINDOW(dock->calc_win), dock->parent_win);
|
||||
gtk_window_present(GTK_WINDOW(dock->calc_win));
|
||||
}
|
||||
gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_calc), "calcapp_running");
|
||||
}
|
||||
|
||||
static gboolean calc_win_closed(GtkWidget *calc_win, MyDock *dock)
|
||||
{
|
||||
// Hide the window
|
||||
gtk_widget_set_visible(calc_win, FALSE);
|
||||
gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_calc), "calcapp");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void my_dock_get_widgets(MyDock *self)
|
||||
{
|
||||
// Get widgets
|
||||
|
@ -346,6 +389,12 @@ static void my_dock_init(MyDock *self)
|
|||
g_signal_connect(self->padgame, "clicked", G_CALLBACK(padgame_clicked), self);
|
||||
g_signal_connect(self->game_win, "close-request", G_CALLBACK(game_win_closed), self);
|
||||
|
||||
// Create Calculator App Window
|
||||
self->calc_win = calc_app_new();
|
||||
g_signal_connect(self->btncalc, "clicked", G_CALLBACK(btncalc_clicked), self);
|
||||
g_signal_connect(self->padcalc, "clicked", G_CALLBACK(padcalc_clicked), self);
|
||||
g_signal_connect(self->calc_win, "close-request", G_CALLBACK(calc_win_closed), self);
|
||||
|
||||
// Add finder
|
||||
self->finder = my_finder_new(GTK_ORIENTATION_HORIZONTAL, 5);
|
||||
gtk_box_append(GTK_BOX(self->finder_box), self->finder);
|
||||
|
|
Loading…
Reference in New Issue