1 /* NIGHTFALL Light Curve Synthesis Program */
2 /* Copyright (C) 1998 Rainer Wichmann */
3 /* */
4 /* This program is free software; you can redistribute it */
5 /* and/or modify */
6 /* it under the terms of the GNU General Public License as */
7 /* published by */
8 /* the Free Software Foundation; either version 2 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* This program is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with this program; if not, write to the Free Software */
18 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /* ANSI C forbids an empty source file, so put this outside */
21
22 #include <math.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <float.h>
27
28 #include "Light.h"
29
30 #ifdef _WITH_GTK
31 #ifdef GDK_DISABLE_DEPRECATED
32 GdkPixmap* gdk_pixmap_create_from_xpm_d (GdkDrawable *drawable,
33 GdkBitmap **mask,
34 const GdkColor *transparent_color,
35 gchar **data);
36 #endif
37
38 static char my_full_data[1024] = "\0"; /* path to datafile */
39 static int first_datafile = OFF; /* flag */
40 static char my_full_cfg[1024] = "\0"; /* path to cfgfile */
41 static int first_cfgfile = OFF; /* flag */
42 static char my_full_out[1024] = "./Nightfall.cfg"; /* path to out cfgfile */
43
44 static GtkWidget *dialog; /* error dialog box */
45 static gint PopErr = OFF; /* flag error dialog active */
46
47 /******************************************************************
48 @package nightfall
49 @author Rainer Wichmann (rwichman@lsw.uni-heidelberg.de)
50 @version 1.0
51 @short Destroy error dialog window
52 @tip function arguments are not used
53 @param (GtkWidget) *widget Discarded
54 @param (gpointer) *data Discarded
55 @return (void)
56 @heading Graphical User Interface
57 *******************************************************************/
delete_dialog(GtkWidget * widget,gpointer * data)58 void delete_dialog (GtkWidget *widget, gpointer *data)
59 {
60 gtk_widget_destroy (dialog);
61 PopErr = OFF;
62 return;
63 }
64
65 /******************************************************************
66 @package nightfall
67 @author Rainer Wichmann (rwichman@lsw.uni-heidelberg.de)
68 @version 1.0
69 @short Error handler
70 @param (char) *message The error message
71 @return (void)
72 @heading Graphical User Interface
73 *******************************************************************/
make_dialog(char * message)74 void make_dialog (char *message)
75 {
76
77 #ifdef HAVE_GNOME
78
79 dialog = gnome_message_box_new(_(message), GNOME_MESSAGE_BOX_WARNING,
80 GNOME_STOCK_BUTTON_OK, NULL);
81 gnome_dialog_set_close(GNOME_DIALOG(dialog), TRUE);
82 gtk_window_set_modal (GTK_WINDOW(dialog), TRUE);
83 gtk_widget_show(dialog);
84
85 #else
86
87 GtkWidget *label;
88 GtkWidget *button;
89 GtkWidget *box1;
90 GtkWidget *separator;
91 char newmsg[128+12] = "**ERROR**: ";
92
93 strncat(newmsg, message, 128);
94 #ifdef USING_GTK2
95 dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
96 #else
97 dialog = gtk_window_new (GTK_WINDOW_DIALOG);
98 #endif
99 /* gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE); */
100 gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
101 GTK_SIGNAL_FUNC (delete_dialog), NULL);
102
103 box1 = gtk_vbox_new (FALSE, 0);
104 gtk_container_add (GTK_CONTAINER (dialog), box1);
105 gtk_container_set_border_width (GTK_CONTAINER (box1), 5);
106
107 label = gtk_label_new (message);
108 gtk_box_pack_start (GTK_BOX (box1), label, FALSE, TRUE, 5);
109 gtk_widget_show (label);
110
111 separator = gtk_hseparator_new ();
112 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
113 gtk_widget_show (separator);
114
115 button = gtk_button_new_with_label ("OK");
116 gtk_signal_connect (GTK_OBJECT (button), "clicked",
117 GTK_SIGNAL_FUNC (delete_dialog), NULL);
118 gtk_box_pack_start (GTK_BOX (box1), button, FALSE, TRUE, 5);
119 (GTK_WIDGET_FLAGS (button) |= (GTK_CAN_DEFAULT));
120 gtk_widget_grab_default (button);
121 gtk_widget_show (button);
122
123 gtk_widget_show (box1);
124
125 gtk_widget_show (dialog);
126
127 PopErr = ON;
128
129 /* avoid second error dialog PopUp while first still active */
130
131 while (PopErr == ON) {
132 while (gtk_events_pending()) gtk_main_iteration();
133 }
134
135 #endif
136
137 return;
138 }
139
140 /******************************************************************
141 @package nightfall
142 @author Rainer Wichmann (rwichman@lsw.uni-heidelberg.de)
143 @version 1.0
144 @short Read data file
145 @param (GtkWidget) *w Discarded
146 @param (GtkFileSelection) *fs File selection
147 @return (void)
148 @heading Graphical User Interface
149 *******************************************************************/
file_ok_sel(GtkWidget * w,GtkFileSelection * fs)150 void file_ok_sel (GtkWidget *w, GtkFileSelection *fs)
151 {
152 const char *file_ptr; /* filename */
153
154 file_ptr = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
155
156 if (strlen(file_ptr) < sizeof(my_full_data) -1)
157 strcpy(my_full_data,file_ptr);
158
159 /* read in the data */
160 Read(file_ptr);
161
162 updatepage3 ();
163
164 gtk_widget_destroy (GTK_WIDGET (fs));
165
166 return;
167 }
168
169 /******************************************************************
170 @package nightfall
171 @author Rainer Wichmann (rwichman@lsw.uni-heidelberg.de)
172 @version 1.0
173 @short Callback function for 'Read Data'
174 @param (GtkWidget) *widget Discarded
175 @param (gpointer) *data Discarded
176 @return (void)
177 @heading Graphical User Interface
178 *******************************************************************/
select_file(GtkWidget * widget,gpointer * data)179 void select_file (GtkWidget *widget, gpointer *data)
180 {
181 GtkWidget *filew; /* file selector */
182 char *pwd; /* present working dir */
183 char my_data[] = "/ty_booV.dat"; /* filename */
184 FILE *test; /* filehandle */
185
186 /* set default filename, but only at first call */
187
188 if (first_datafile == OFF) {
189
190 strncpy(my_full_data, data_data_fls(),
191 (sizeof(my_full_data)-sizeof(my_data)-1));
192 strcat(my_full_data, my_data);
193
194 /* check if file exist, otherwise fall back on PWD/data */
195
196 test = fopen(my_full_data, "r");
197
198 if (test != NULL) {
199 fclose(test);
200 } else {
201 pwd = getenv("PWD");
202 if (pwd != NULL) {
203 if (strlen(pwd) < (sizeof(my_full_data)-strlen(my_data)-1))
204 strcpy(my_full_data, pwd);
205 strcat(my_full_data, my_data);
206 }
207 }
208 first_datafile = ON;
209
210 }
211
212
213 /* Create a new file selection widget */
214 filew = gtk_file_selection_new ("Data file selection");
215
216 gtk_signal_connect (GTK_OBJECT (filew), "destroy",
217 (GtkSignalFunc) gtk_widget_destroy,
218 GTK_OBJECT (filew));
219
220 /* Connect the ok_button to file_ok_sel function */
221 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
222 "clicked", (GtkSignalFunc) file_ok_sel, filew );
223
224 /* Connect the cancel_button to destroy the widget */
225 gtk_signal_connect_object
226 (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button),
227 "clicked", (GtkSignalFunc) gtk_widget_destroy,
228 GTK_OBJECT (filew));
229
230 /* set the default filename */
231 gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew),
232 my_full_data);
233
234 gtk_widget_show(filew);
235
236 return;
237 }
238
239
240 /******************************************************************
241 @package nightfall
242 @author Rainer Wichmann (rwichman@lsw.uni-heidelberg.de)
243 @version 1.0
244 @short Read configuration file
245 @param (GtkWidget) *w Discarded
246 @param (GtkFileSelection) *fs File selection
247 @return (void)
248 @heading Graphical User Interface
249 *******************************************************************/
config_ok_sel(GtkWidget * w,GtkFileSelection * fs)250 void config_ok_sel (GtkWidget *w, GtkFileSelection *fs)
251 {
252 const char *file_ptr; /* filename */
253 int blah; /* mandatory args, discarded */
254
255 file_ptr = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
256
257 if (strlen(file_ptr) < sizeof(my_full_cfg) -1 && strlen(file_ptr) > 1)
258 strcpy(my_full_cfg, file_ptr);
259
260 ParseConfig(file_ptr, &blah);
261
262 UpdateGui();
263
264 updatepage3 ();
265
266 gtk_widget_destroy (GTK_WIDGET (fs));
267
268 return;
269 }
270
271 /******************************************************************
272 @package nightfall
273 @author Rainer Wichmann (rwichman@lsw.uni-heidelberg.de)
274 @version 1.0
275 @short Callback function for 'Read Config'
276 @param (GtkWidget) *widget Discarded
277 @param (gpointer) *data Discarded
278 @return (void)
279 @heading Graphical User Interface
280 *******************************************************************/
select_config(GtkWidget * widget,gpointer * data)281 void select_config (GtkWidget *widget, gpointer *data)
282 {
283 GtkWidget *filew; /* file selector */
284 char *pwd; /* present working dir */
285 char my_cfg[] = "/ty_boo.cfg"; /* filename */
286 FILE *test; /* filehandle */
287
288 /* set default filename, but only at first call */
289
290 if (first_cfgfile == OFF) {
291
292 strncpy(my_full_cfg, data_cfg_fls(),
293 (sizeof(my_full_cfg)-sizeof(my_cfg)-1));
294 strcat(my_full_cfg, my_cfg);
295
296 /* check if file exist, otherwise fall back on PWD/cfg */
297
298 test = fopen(my_full_cfg, "r");
299
300 if (test != NULL) {
301 fclose(test);
302 } else {
303 pwd = getenv("PWD");
304 if (pwd != NULL) {
305 if (strlen(pwd) < (sizeof(my_full_cfg)-strlen(my_cfg)-1))
306 strcpy(my_full_cfg, pwd);
307 strcat(my_full_cfg, my_cfg);
308 }
309 }
310 first_cfgfile = ON;
311
312 }
313
314 /* Create a new file selection widget */
315 filew = gtk_file_selection_new ("File selection");
316
317 gtk_signal_connect (GTK_OBJECT (filew), "destroy",
318 (GtkSignalFunc) gtk_widget_destroy,
319 GTK_OBJECT (filew));
320
321 /* Connect the ok_button to file_ok_sel function */
322 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
323 "clicked", (GtkSignalFunc) config_ok_sel, filew );
324
325 /* Connect the cancel_button to destroy the widget */
326 gtk_signal_connect_object
327 (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button),
328 "clicked", (GtkSignalFunc) gtk_widget_destroy,
329 GTK_OBJECT (filew));
330
331 /* set the default filename */
332 gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew),
333 my_full_cfg);
334
335 gtk_widget_show(filew);
336
337 return;
338 }
339
340
341 /******************************************************************
342 @package nightfall
343 @author Rainer Wichmann (rwichman@lsw.uni-heidelberg.de)
344 @version 1.0
345 @short Write output configuration filename
346 @param (GtkWidget) *w Discarded
347 @param (GtkFileSelection) *fs File selection
348 @return (void)
349 @heading Graphical User Interface
350 *******************************************************************/
config_ok_out(GtkWidget * w,GtkFileSelection * fs)351 void config_ok_out (GtkWidget *w, GtkFileSelection *fs)
352 {
353
354 const char *file_ptr; /* filename */
355
356 file_ptr = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
357
358 if (strlen(file_ptr) < sizeof(my_full_out) -1 && strlen(file_ptr) > 1)
359 strcpy(my_full_out, file_ptr);
360
361 WriteConfig(file_ptr);
362
363 gtk_widget_destroy (GTK_WIDGET (fs));
364 }
365
366
367 /******************************************************************
368 @package nightfall
369 @author Rainer Wichmann (rwichman@lsw.uni-heidelberg.de)
370 @version 1.0
371 @short Callback function for 'Write Config'
372 @param (GtkWidget) *widget Discarded
373 @param (gpointer) *data Discarded
374 @return (void)
375 @heading Graphical User Interface
376 *******************************************************************/
out_config(GtkWidget * widget,gpointer * data)377 void out_config (GtkWidget *widget, gpointer *data)
378 {
379 GtkWidget *filew; /* file selector */
380
381 /* Create a new file selection widget */
382 filew = gtk_file_selection_new ("File selection");
383
384 gtk_signal_connect (GTK_OBJECT (filew), "destroy",
385 (GtkSignalFunc) gtk_widget_destroy,
386 GTK_OBJECT (filew));
387
388 /* Connect the ok_button to file_ok_sel function */
389 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
390 "clicked", (GtkSignalFunc) config_ok_out, filew );
391
392 /* Connect the cancel_button to destroy the widget */
393 gtk_signal_connect_object
394 (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button),
395 "clicked", (GtkSignalFunc) gtk_widget_destroy,
396 GTK_OBJECT (filew));
397
398 /* set the default filename */
399 gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew),
400 my_full_out);
401
402 gtk_widget_show(filew);
403
404 return;
405 }
406
407 /******************************************************************
408 @package nightfall
409 @author David Bryant <d_bryant@lincoln.college.adelaide.edu.au>
410 @version original version without any modifications
411 @short Convenience function to create a pixmap widget from data
412 @long This function is taken from the 'geg' program,
413 version 0.15.0, without any modifications except for
414 error handling. Copyright is
415 with the author of 'geg', David Bryant.
416 ('geg' is distributed under the
417 terms of the GNU General Public License).
418 @param (GtkWidget) *widget The top window
419 @param (gchar) **data The data, a .xpm array
420 @return (GtkWidget *) The pixmap widget
421 @heading Graphical User Interface
422 *******************************************************************/
423 GtkWidget *
create_pixmap(GtkWidget * widget,gchar ** data)424 create_pixmap(GtkWidget *widget, gchar **data)
425 {
426 GtkStyle *style;
427 GdkBitmap *mask;
428 GdkPixmap *gdk_pixmap;
429 GtkWidget *gtk_pixmap;
430
431 style = gtk_widget_get_style(widget);
432 if (style == NULL)
433 {
434 nf_error(_(errmsg[21]));
435 return NULL;
436 }
437
438 gdk_pixmap =
439 gdk_pixmap_create_from_xpm_d(widget->window,
440 &mask, &style->bg[GTK_STATE_NORMAL],
441 data);
442
443 if (gdk_pixmap == NULL)
444 {
445 nf_error(_(errmsg[22]));
446 return NULL;
447 }
448
449 gtk_pixmap = gtk_pixmap_new(gdk_pixmap, mask);
450
451 if (gtk_pixmap == NULL)
452 {
453 nf_error(_(errmsg[22]));
454 return NULL;
455 }
456
457 gtk_widget_show(gtk_pixmap);
458
459 return(gtk_pixmap);
460 }
461
462
463 #endif
464