This repository has been archived by the owner on Oct 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.c
173 lines (143 loc) · 4.73 KB
/
gui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* Xep128: Minimalistic Enterprise-128 emulator with focus on "exotic" hardware
Copyright (C)2016 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
http://xep128.lgb.hu/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifdef _WIN32
# include <windows.h>
# define XEP128_HWND sdl_wminfo.info.win.window
#elif defined(XEP128_GTK)
# include <gtk/gtk.h>
#endif
#include "xep128.h"
#include "gui.h"
#define XEP128_NEED_SDL_WMINFO
#include "screen.h"
#include "fileio.h"
#if defined(_WIN32) || defined (XEP128_GTK)
#define XEP128_GUI_C
#endif
#ifdef XEP128_GUI_C
static void store_dir_from_file_selection ( char *store_dir, const char *filename, int dialog_mode )
{
if (store_dir && (dialog_mode & XEPGUI_FSEL_FLAG_STORE_DIR)) {
if ((dialog_mode & 0xFF) == XEPGUI_FSEL_DIRECTORY)
strcpy(store_dir, filename);
else {
char *p = strrchr(filename, DIRSEP[0]);
if (p) {
memcpy(store_dir, filename, p - filename + 1);
store_dir[p - filename + 1] = '\0';
}
}
}
}
#endif
#ifdef _WIN32
/* ---------------------------------------- Windows STUFFS based on Win32 native APIs ---------------------------------------- */
int xepgui_init ( void )
{
return 0;
}
void xepgui_iteration ( void )
{
}
int xepgui_file_selector ( int dialog_mode, const char *dialog_title, char *default_dir, char *selected, int path_max_size )
{
int res;
OPENFILENAME ofn; // common dialog box structure
ZeroMemory(&ofn, sizeof ofn);
ofn.lStructSize = sizeof ofn;
ofn.hwndOwner = 0; // XEP128_HWND;
ofn.lpstrFile = selected;
*selected = '\0'; // sets to zero, since it seems windows dialog handler also used this as input?
ofn.nMaxFile = path_max_size;
ofn.lpstrFilter = NULL; // "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 0; // 1
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = default_dir ? default_dir : NULL;
ofn.lpstrTitle = dialog_title;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
res = !GetOpenFileName(&ofn);
if (res) {
int err = CommDlgExtendedError();
*selected = '\0';
DEBUG("GUI: file selector (Windows) error code: %04Xh for HWND owner %p" NL, err, ofn.hwndOwner);
if (err)
ERROR_WINDOW("Windows CommDlgExtendedError: %04Xh for HWND owner %p", err, ofn.hwndOwner);
} else
store_dir_from_file_selection(default_dir, selected, dialog_mode);
xepgui_iteration();
sdl_burn_events();
return res;
}
#elif defined(XEP128_GTK)
/* ---------------------------------------- LINUX/UNIX STUFFS based on GTK ---------------------------------------- */
int xepgui_init ( void )
{
if (!gtk_init_check(NULL, NULL)) {
ERROR_WINDOW("Cannot initialize GTK");
return 1;
}
xepgui_iteration(); // consume possible peding (if any?) GTK stuffs after initialization - maybe not needed at all?
return 0;
}
void xepgui_iteration ( void )
{
while (gtk_events_pending())
gtk_main_iteration();
}
int xepgui_file_selector ( int dialog_mode, const char *dialog_title, char *default_dir, char *selected, int path_max_size )
{
GtkWidget *dialog;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
gint res;
dialog = gtk_file_chooser_dialog_new(dialog_title,
NULL, // parent window!
action,
"_Cancel",
GTK_RESPONSE_CANCEL,
"_Open",
GTK_RESPONSE_ACCEPT,
NULL
);
if (default_dir)
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), default_dir);
*selected = '\0';
res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
char *filename;
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
if (strlen(filename) < path_max_size) {
strcpy(selected, filename);
store_dir_from_file_selection(default_dir, filename, dialog_mode);
} else
res = GTK_RESPONSE_CANCEL;
g_free(filename);
}
gtk_widget_destroy(dialog);
xepgui_iteration();
sdl_burn_events();
return res != GTK_RESPONSE_ACCEPT;
}
#else
/* ----------------------------- NO GUI IS AVAILABLE ---------------------- */
int xepgui_init ( void ) {
return 0;
}
void xepgui_iteration ( void ) {
}
int xepgui_file_selector ( int dialog_mode, const char *dialog_title, char *default_dir, char *selected, int path_max_size ) {
return 1;
}
#endif