1 /********************************************************************
2 This file is part of the abs 0.907 distribution.  abs is a spreadsheet
3 with graphical user interface.
4 
5 Copyright (C) 1998-2001  Andr� Bertin (Andre.Bertin@ping.be)
6 
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version if in the same spirit as version 2.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 Concact: abs@pi.be
22          http://home.pi.be/bertin/abs.shtml
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 #include <locale.h>
52 
53 #include "param.h"
54 #include "buildall.h"
55 #include <stdio.h>
56 #include "cblist.h"
57 #include "myscroll.h"
58 #include "mainwin.h"
59 #include "worksheet.h"
60 #include "pixmaps/abs.xpm"
61 #include "callback.h"
62 #include "gr_interf.h"
63 
64 #include "celldialog.h"
65 #include "plotdialog.h"
66 #include "printdialog.h"
67 #include "separator.h"
68 #include "formula.h"
69 #include "popnindex.h"
70 #include "xedit/xedit.h"
71 
72 #include "button.h"
73 
74 #include "application.h"
75 
76 #include "finite_state.h"
77 
78 static String fallback_resources[] =
79 {
80   "*window.width:         800",
81   "*window.height:        600",
82   "abs*background:         #C000C000C000",
83   "abs*foreground:         black",
84   "*keyboardFocusPolicy:           explicit",
85   NULL
86 };
87 
88 
89 
90 
91 typedef struct
92   {
93     Pixel foreground;
94     Pixel background;
95     XFontStruct *font;
96     int ncol;
97     Boolean showsize;
98   }
99 res_data, *res_data_ptr;
100 static res_data res;
101 
102 Pixel absblack;
103 Pixel abswhite;
104 int BatchMode;
105 
106 
107 static XtResource application_resources[] =
108 {
109   {XtNforeground, XtCForeground, XtRPixel, sizeof (Pixel),
110    XtOffset (res_data_ptr, foreground), XtRString, "Black"},
111   {XtNbackground, XtCBackground, XtRPixel, sizeof (Pixel),
112    XtOffset (res_data_ptr, background), XtRString, "White"},
113 };
114 
115 
116 static XrmOptionDescRec options[] =
117 {
118   {"-ncol", "*ncol", XrmoptionSepArg, NULL},
119   {"-fg", "*foreground", XrmoptionSepArg, (XtPointer) NULL},
120   {"-bg", "*background", XrmoptionSepArg, (XtPointer) NULL},
121 
122 };
123 
124 
125 
126 
127 
128 Widget
gettop()129 gettop ()
130 {
131   return ActiveMainwin->toplevel;
132 }
133 
134 
135 
136 static Display *display;
137 XtAppContext app_con;
138 extern int initvb ();
139 
140 int
main(int argc,char ** argv)141 main (int argc, char **argv)
142 {
143   int i = 1;
144 
145 
146   int tmpbatch = 0;
147   setlocale (LC_ALL, "C");
148 
149 #ifndef _AIX_SOURCE
150   setenv ("LANG", "C", 1);
151 #endif
152 
153   state_init ();
154   initvb ();
155 
156   for (i = 1; i < argc; i++)
157     {
158       if (!strncasecmp (argv[i], "-batch", 6))
159 	{
160 	  FS->l1 = StBatch;
161 	  BatchMode = 1;
162 	  tmpbatch = 1;
163 	}
164       if (!strncasecmp (argv[i], "-help", 5))
165 	{
166 	  (void) fprintf (stderr, "Usage: %s [-batch] filename ...\n", argv[0]);
167 	  return 0;
168 	}
169     }
170 
171 
172   if (!BatchMode)
173     xsetup (&argc, argv);
174 
175   for (i = 1; i < argc; i++)
176     {
177       if (argv[i][0] != '-')
178 	{
179 	  m_openfile (argv[i]);
180 	}
181     }
182 
183 
184   setlocale (LC_ALL, "C");
185   if (!BatchMode && !tmpbatch)
186     xmainloop ();
187 
188 
189   return 0;
190 }
191 
192 int
xsetup(int * argc,char ** argv)193 xsetup (int *argc, char **argv)
194 {
195   Widget toplevel;
196   Widget startbase;
197   Widget base;
198   Pixmap startpixmap;
199   Arg args[20];
200 
201 
202   Arg centerArgs[2];
203   Position source_x, source_y;
204   Position dest_x, dest_y;
205   Dimension center_width, center_height;
206   Dimension prompt_width, prompt_height;
207 
208 
209 
210   XtSetLanguageProc ((XtAppContext) NULL,
211 		     (XtLanguageProc) NULL, (XtPointer) NULL);
212 
213 
214 
215   toplevel = XtAppInitialize (&app_con, "abs",
216 			      options, XtNumber (options),
217 			      argc, argv, fallback_resources, NULL, 0);
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230   if (toplevel != NULL)
231     {
232       display = XtDisplayOfObject (toplevel);
233     }
234   if (display == NULL)
235     {
236       fprintf (stderr, "Could not open display.");
237       exit (1);
238     }
239   XtSetArg (args[0], XtNinput, True);
240   XtSetValues (toplevel, args, 1);
241 
242   XtGetApplicationResources (toplevel, &res, application_resources,
243 			     XtNumber (application_resources), NULL, 0);
244 
245 
246 
247 
248   absblack = BlackPixelOfScreen (XtScreen (toplevel));
249   abswhite = WhitePixelOfScreen (XtScreen (toplevel));
250 
251   w_n = 0;
252   w_dim (600, 400);
253   base = XtCreatePopupShell
254     ("ABVisual Editor", transientShellWidgetClass, toplevel, w_args, w_n);
255 
256   ActiveMainwin = newmainwin (toplevel);
257   make_format_dial ();
258   make_plot_dial ();
259   make_print_dial ();
260   make_separator_dial ();
261   make_formula_dial ();
262 
263   w_n = 0;
264   w_dim (462, 319);
265   startbase = XtCreatePopupShell
266     ("abs Starting ...", transientShellWidgetClass, toplevel, w_args, w_n);
267 
268 
269 
270   XtSetArg (centerArgs[0], XtNwidth, &center_width);
271   XtSetArg (centerArgs[1], XtNheight, &center_height);
272   XtGetValues (ActiveMainwin->baseform, centerArgs, 2);
273   XtSetArg (centerArgs[0], XtNwidth, &prompt_width);
274   XtSetArg (centerArgs[1], XtNheight, &prompt_height);
275   XtGetValues (startbase, centerArgs, 2);
276   source_x = (int) (center_width - prompt_width) / 2;
277   source_y = (int) (center_height - prompt_height) / 2;
278   XtTranslateCoords (ActiveMainwin->baseform, source_x, source_y, &dest_x, &dest_y);
279   XtSetArg (centerArgs[0], XtNx, dest_x);
280   XtSetArg (centerArgs[1], XtNy, dest_y);
281   XtSetValues (startbase, centerArgs, 2);
282 
283   XtRealizeWidget (toplevel);
284 
285 
286   XtManageChild (startbase);
287 
288   make_pixmap_from_data (startbase, abs_xpm, &startpixmap);
289   XSetWindowBackgroundPixmap (XtDisplay (startbase), XtWindow (startbase), startpixmap);
290   XFreePixmap (XtDisplay (startbase), startpixmap);
291   XClearWindow (XtDisplay (startbase), XtWindow (startbase));
292   setXparam (ActiveMainwin->dpy, ActiveMainwin->draw_window, ActiveMainwin->toplevel);
293 
294 
295   create_active_mainwin_pixmaps (760, 500);
296 
297   cbsetup (760, 500);
298 
299   XtUnmanageChild (startbase);
300 
301 
302   mainxedit (base);
303   ActiveMainwin->abv_editor = base;
304 
305   XtSetKeyboardFocus (toplevel, ActiveMainwin->commandline_obj->text);
306   return 0;
307 }
308 
309 int
xmainloop()310 xmainloop ()
311 {
312   XtAppMainLoop (app_con);
313   return (0);
314 }
315 
316 
317 
318 
319 
320 
321 
322 
323 
324 
325 
326 
327 
328 
329 
330 
331 
332 
333 
334 
335 
336 
337 
338 
339 
340 
341 
342 
343 
344 
345 
346 
347 
348 
349 
350 
351 
352 
353 
354 
355 
356 
357 
358 
359 
360 
361