1 /** \file   isepicwidget.c
2  * \brief   Widget to control ISEPIC resources
3  *
4  * \autor   Bas Wassink <b.wassink@ziggo.nl>
5  */
6 
7 /*
8  * $VICERES IsepicCartridgeEnabled  x64 x64sc xscpu64 x128
9  * $VICERES Isepicfilename          x64 x64sc xscpu64 x128
10  * $VICERES IsepicSwitch            x64 x64sc xscpu64 x128
11  * $VICERES IsepicImageWrite        x64 x64sc xscpu64 x128
12  */
13 
14 /*
15  * This file is part of VICE, the Versatile Commodore Emulator.
16  * See README for copyright notice.
17  *
18  *  This program is free software; you can redistribute it and/or modify
19  *  it under the terms of the GNU General Public License as published by
20  *  the Free Software Foundation; either version 2 of the License, or
21  *  (at your option) any later version.
22  *
23  *  This program is distributed in the hope that it will be useful,
24  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *  GNU General Public License for more details.
27  *
28  *  You should have received a copy of the GNU General Public License
29  *  along with this program; if not, write to the Free Software
30  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
31  *  02111-1307  USA.
32  *
33  */
34 
35 #include "vice.h"
36 
37 #include <gtk/gtk.h>
38 
39 #include "basedialogs.h"
40 #include "basewidgets.h"
41 #include "carthelpers.h"
42 #include "cartimagewidget.h"
43 #include "cartridge.h"
44 #include "debug_gtk3.h"
45 #include "machine.h"
46 #include "openfiledialog.h"
47 #include "resources.h"
48 #include "savefiledialog.h"
49 #include "widgethelpers.h"
50 
51 #include "isepicwidget.h"
52 
53 
54 /** \brief  Handler for the "state-set" event of the "IsepicSwitch" resource
55  *
56  * \param[in]   widget      switch widget
57  * \param[in]   state       new state of \a widget
58  * \param[in]   user_data   unused
59  *
60  * \return  FALSE
61  */
on_isepic_switch_state_set(GtkWidget * widget,gboolean state,gpointer user_data)62 static gboolean on_isepic_switch_state_set(GtkWidget *widget, gboolean state,
63         gpointer user_data)
64 {
65     resources_set_int("IsepicSwitch", state);
66     return FALSE;
67 }
68 
69 
70 /** \brief  Create ISEPIC switch button
71  *
72  * \return  GtkCheckButton
73  */
create_isepic_switch_widget(void)74 static GtkWidget *create_isepic_switch_widget(void)
75 {
76     GtkWidget *grid;
77     GtkWidget *label;
78     GtkWidget *button;
79     int state;
80 
81     grid = gtk_grid_new();
82     gtk_grid_set_column_spacing(GTK_GRID(grid), 8);
83     g_object_set(grid, "margin-left", 16, NULL);
84 
85     label = gtk_label_new("Isepic switch");
86     gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1);
87 
88     button = gtk_switch_new();
89     resources_get_int("IsepicSwitch", &state);
90     gtk_switch_set_active(GTK_SWITCH(button), state);
91     gtk_grid_attach(GTK_GRID(grid), button, 1, 0, 1, 1);
92     gtk_widget_show_all(grid);
93 
94     g_signal_connect(button, "state-set", G_CALLBACK(on_isepic_switch_state_set),
95             NULL);
96     return grid;
97 }
98 
99 
100 /** \brief  Create widget to load/save ISEPIC image file
101  *
102  * \return  GtkGrid
103  */
create_isepic_image_widget(GtkWidget * parent)104 static GtkWidget *create_isepic_image_widget(GtkWidget *parent)
105 {
106     return cart_image_widget_create(parent, "ISEPIC image",
107             "Isepicfilename", "IsepicImageWrite",
108             carthelpers_save_func, carthelpers_flush_func,
109             carthelpers_can_save_func, carthelpers_can_flush_func,
110             CARTRIDGE_NAME_ISEPIC, CARTRIDGE_ISEPIC);
111 }
112 
113 
114 /** \brief  Create widget to control ISEPIC resources
115  *
116  * \param[in]   parent  parent widget, used for dialogs
117  *
118  * \return  GtkGrid
119  */
isepic_widget_create(GtkWidget * parent)120 GtkWidget *isepic_widget_create(GtkWidget *parent)
121 {
122     GtkWidget *grid;
123     GtkWidget *isepic_enable_widget;
124     GtkWidget *isepic_image;
125     GtkWidget *isepic_switch;
126 
127 
128     grid = gtk_grid_new();
129     gtk_grid_set_column_spacing(GTK_GRID(grid), 8);
130     gtk_grid_set_row_spacing(GTK_GRID(grid), 8);
131 
132     isepic_enable_widget = carthelpers_create_enable_check_button(
133             CARTRIDGE_NAME_ISEPIC, CARTRIDGE_ISEPIC);
134     gtk_grid_attach(GTK_GRID(grid), isepic_enable_widget, 0, 0, 1, 1);
135 
136     isepic_switch = create_isepic_switch_widget();
137     gtk_grid_attach(GTK_GRID(grid), isepic_switch, 0, 1, 1, 1);
138 
139     isepic_image = create_isepic_image_widget(parent);
140     gtk_grid_attach(GTK_GRID(grid), isepic_image, 0, 2, 1, 1);
141 
142     gtk_widget_show_all(grid);
143     return grid;
144 }
145