1 /*
2 **
3 ** options_fs.c
4 **
5 ** Copyright (C) 1995, 1996, 1997 Johannes Plass
6 ** Copyright (C) 2004 Jose E. Marchesi
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 3 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with GNU gv; see the file COPYING.  If not, write to
20 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ** Boston, MA 02111-1307, USA.
22 **
23 ** Author:   Johannes Plass (plass@thep.physik.uni-mainz.de)
24 **           Department of Physics
25 **           Johannes Gutenberg-University
26 **           Mainz, Germany
27 **
28 **           Jose E. Marchesi (jemarch@gnu.org)
29 **           GNU Project
30 **
31 */
32 #include "ac_config.h"
33 
34 /*
35 #define MESSAGES
36 */
37 #include "message.h"
38 
39 #include "config.h"
40 
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <ctype.h>
44 
45 #include "paths.h"
46 #include INC_X11(Intrinsic.h)
47 #include INC_X11(StringDefs.h)
48 #include INC_X11(Shell.h)
49 #include "Aaa.h"
50 #include "Button.h"
51 #include "FileSel.h"
52 #include "Switch.h"
53 
54 #include "types.h"
55 #include "callbacks.h"
56 #include "widgets_misc.h"
57 #include "main_resources.h"
58 #include "main_globals.h"
59 #include "misc.h"
60 #include "note.h"
61 #include "options.h"
62 #include "options_fs.h"
63 #include "version.h"
64 
65 static Widget popup,optionControl;
66 static Widget filter,scratch_dir,default_save_dir,filters,dirs;
67 
68 static void options_fs_create(void);
69 static void options_fs_setOptionsAtEntry(void);
70 
71 /*------------------------------------------------------
72   OptionPopupStruct
73 ------------------------------------------------------*/
74 
75 OptionPopupStruct gv_options_fs_struct = {
76   NULL,
77   options_fs_create,
78   options_fs_setOptionsAtEntry,
79   False
80 };
81 
82 OptionPopup gv_options_fs = (OptionPopup) &gv_options_fs_struct;
83 
84 /*------------------------------------------------------
85    options_fs_setOptionsAtEntry
86 ------------------------------------------------------*/
87 
options_fs_setOptionsAtEntry(void)88 static void options_fs_setOptionsAtEntry(void)
89 {
90   String s;
91 
92   BEGINMESSAGE(options_fs_setOptionsAtEntry)
93   SMESSAGE(app_res.scratch_dir)
94   widgets_setText(scratch_dir,  app_res.scratch_dir);
95   SMESSAGE(app_res.default_save_dir)
96   widgets_setText(default_save_dir,  app_res.default_save_dir);
97   SMESSAGE(gv_filters)
98   s = options_squeezeMultiline(gv_filters); widgets_setText(filters,s); XtFree(s);
99   SMESSAGE(gv_dirs)
100   s = options_squeezeMultiline(gv_dirs); widgets_setText(dirs,s); XtFree(s);
101   SMESSAGE(gv_filter)
102   widgets_setText(filter,gv_filter);
103   ENDMESSAGE(options_fs_setOptionsAtEntry)
104 }
105 
106 /*------------------------------------------------------
107    options_fs_cb_apply
108 ------------------------------------------------------*/
109 
options_fs_cb_apply(Widget w _GL_UNUSED,XtPointer client_data _GL_UNUSED,XtPointer call_data _GL_UNUSED)110 static void options_fs_cb_apply(Widget w _GL_UNUSED, XtPointer client_data _GL_UNUSED, XtPointer call_data _GL_UNUSED)
111 {
112    Arg args[5];
113    Cardinal n;
114    static Boolean s_scratch_dir = False;
115    static Boolean s_default_save_dir = False;
116 
117    BEGINMESSAGE(options_fs_cb_apply)
118 
119    options_textApply(scratch_dir,&s_scratch_dir,&app_res.scratch_dir);
120    options_textApply(default_save_dir,&s_default_save_dir,&app_res.default_save_dir);
121    options_textApply(filters,NULL,&gv_filters);
122    options_textApply(dirs,NULL,&gv_dirs);
123    options_textApply(filter,NULL,&gv_filter);
124 							n=0;
125    XtSetArg(args[n], XtNtmpDir, app_res.scratch_dir);	n++;
126    XtSetArg(args[n], XtNfilters, gv_filters);		n++;
127    XtSetArg(args[n], XtNdirs, gv_dirs);			n++;
128    XtSetArg(args[n], XtNfilter, gv_filter);		n++;
129    XtSetValues(FileSel, args, n);
130 
131    ENDMESSAGE(options_fs_cb_apply)
132 }
133 
134 /*------------------------------------------------------
135    options_fs_cb_save
136 ------------------------------------------------------*/
137 
138 static
options_fs_cb_save(Widget w _GL_UNUSED,XtPointer client_data _GL_UNUSED,XtPointer call_data _GL_UNUSED)139 void options_fs_cb_save(Widget w _GL_UNUSED, XtPointer client_data _GL_UNUSED, XtPointer call_data _GL_UNUSED)
140 {
141   int    argn = 0;
142   String argi[30];
143   String argv[30];
144 
145   BEGINMESSAGE(options_fs_cb_save)
146 
147   options_setArg(&(argi[argn]),&(argv[argn]),s_version             ,gv_class       ,versionResource);
148        ++argn;
149   options_setArg(&(argi[argn]),&(argv[argn]),"*filter"              ,gv_class       ,widgets_getText(filter));
150        ++argn;
151   options_setArg(&(argi[argn]),&(argv[argn]),"*filters"             ,gv_class       ,widgets_getText(filters));
152        ++argn;
153   options_setArg(&(argi[argn]),&(argv[argn]),"*dirs"                ,gv_class       ,widgets_getText(dirs));
154        ++argn;
155   options_setArg(&(argi[argn]),&(argv[argn]),s_scratchDir          ,gv_class       ,widgets_getText(scratch_dir));
156        ++argn;
157   options_setArg(&(argi[argn]),&(argv[argn]),s_defaultSaveDir      ,gv_class       ,widgets_getText(default_save_dir));
158        ++argn;
159 
160   options_save(argn,argi,argv);
161   while (--argn >=0) {
162     XtFree(argi[argn]);
163     XtFree(argv[argn]);
164   }
165 
166   ENDMESSAGE(options_fs_cb_save)
167 }
168 
169 /*------------------------------------------------------
170    options_fs_create
171 ------------------------------------------------------*/
172 
options_fs_create(void)173 static void options_fs_create(void)
174 {
175    Arg          args[10];
176    Cardinal     n;
177    Widget       w;
178 
179    BEGINMESSAGE(options_fs_create)
180 
181         						n=0;
182         XtSetArg(args[n], XtNallowShellResize, True);	n++;
183    popup = XtCreatePopupShell("optionfsPopup",transientShellWidgetClass,toplevel, args, n);
184    gv_options_fs->popup = popup;
185 
186          						n=0;
187    optionControl = XtCreateManagedWidget("optionControl",aaaWidgetClass,popup,args,n);
188 
189         						n=0;
190    w = XtCreateManagedWidget("apply", buttonWidgetClass,optionControl, args, n);
191          XtAddCallback(w, XtNcallback, options_fs_cb_apply,NULL);
192          XtInstallAccelerators(optionControl, w);
193    w = XtCreateManagedWidget("save", buttonWidgetClass,optionControl, args, n);
194          XtAddCallback(w, XtNcallback, options_fs_cb_save,NULL);
195          XtInstallAccelerators(optionControl, w);
196    w = XtCreateManagedWidget("dismiss", buttonWidgetClass,optionControl, args, n);
197          XtAddCallback(w, XtNcallback, options_cb_popdown,(XtPointer)gv_options_fs);
198          XtInstallAccelerators(optionControl, w);
199 
200    scratch_dir      = widgets_createLabeledLineTextField("scratchDir",   optionControl);
201    default_save_dir = widgets_createLabeledLineTextField("saveDir",      optionControl);
202    filter           = widgets_createLabeledLineTextField("filter",       optionControl);
203    filters          = widgets_createLabeledTextField("filters", optionControl);
204    dirs             = widgets_createLabeledTextField("dirs", optionControl);
205 
206    options_fs_setOptionsAtEntry();
207    options_realize(popup,optionControl);
208 
209    ENDMESSAGE(options_fs_create)
210 }
211 
212