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 "menubar.h"
52 #include "separator.h"
53 #include "memory.h"
54 #include "file_selector.h"
55 #include "separator.h"
56 #include "main.h"
57 #include "application.h"
58
59 #include "workbook.h"
60 #include "worksheet.h"
61 #include "info_dialog.h"
62 #include "printdialog.h"
63 #include "formula.h"
64 #include "celldialog.h"
65 #include "plotdialog.h"
66 #include "mainwin.h"
67 #include "inputbox.h"
68 #include "cb.h"
69
70 #include "project.h"
71 #include "macrodialog.h"
72 #include "pastedialog.h"
73 #include "button.h"
74 #include "callback.h"
75 #include "callback_app.h"
76
77
78
79 static char menuTranslations[] =
80 "<EnterWindow>: highlight() \n\
81 <LeaveWindow>: reset() \n\
82 <BtnDown>: reset() PopupMenu() ";
83
84 static char menupopupTranslations[] =
85 "<EnterWindow>: highlight() \n\
86 <LeaveWindow>: unhighlight() \n\
87 <BtnMotion>: highlight() \n\
88 <BtnUp>: MenuPopdown() notify() unhighlight()";
89
90 #define BtnEle 1
91 #define EntryEle 2
92 #define SeparatorEle 3
93
94
95 static Menu_ele filepopup[] =
96 {
97 {"New", EntryEle, NULL, m_newfile},
98 {"0pen...", EntryEle, NULL, X11m_openfile},
99 {"Close", EntryEle, NULL, m_closefile},
100 {"Separ1", SeparatorEle, NULL, m_close},
101 {"Save", EntryEle, NULL, X11m_savefile},
102 {"Save As...", EntryEle, NULL, X11m_saveasfile},
103 {"Separ2", SeparatorEle, NULL, m_close},
104 {"Print", EntryEle, NULL, X11m_print},
105 {"Separ3", SeparatorEle, NULL, m_close},
106 {"Exit", EntryEle, NULL, m_exit},
107 {NULL, 0, NULL, NULL},
108 };
109
110
111
112
113 static Menu_ele editpopup[] =
114 {
115 {"Cut", EntryEle, NULL, m_cut},
116 {"Copy", EntryEle, NULL, m_copy},
117 {"Paste", EntryEle, NULL, m_paste},
118 {"Paste Special...", EntryEle, NULL, X11m_paste_special},
119 {"Separ4", SeparatorEle, NULL, m_close},
120 {"Copy Down", EntryEle, NULL, m_copyd},
121 {"Copy Right", EntryEle, NULL, m_copyr},
122 {"Separ5", SeparatorEle, NULL, m_close},
123 {"Delete line", EntryEle, NULL, m_delline},
124 {"Delete column", EntryEle, NULL, m_delcolumn},
125 {"Delete sheet", EntryEle, NULL, m_delsheet},
126
127
128
129
130 {NULL, 0, NULL, NULL},
131 };
132
133 static Menu_ele insertpopup[] =
134 {
135
136 {"Line", EntryEle, NULL, m_insertline},
137 {"Column", EntryEle, NULL, m_insertcolumn},
138 {"Chart", EntryEle, NULL, m_createplot},
139 {"Sheet", EntryEle, NULL, m_addsheet},
140 {"Separ7", SeparatorEle, NULL, m_close},
141 {"Function...", EntryEle, NULL, X11m_formula},
142 {NULL, 0, NULL, NULL},
143 };
144
145
146
147 static Menu_ele formatpopup[] =
148 {
149 {"Cell...", EntryEle, NULL, X11m_formatnumber},
150 {"Adjust Line", EntryEle, NULL, formatline},
151 {"Adjust Column", EntryEle, NULL, formatcolumn},
152 {"Adjust Sheet", EntryEle, NULL, m_fit},
153 {"Sheet name...", EntryEle, NULL, X11m_sheetname},
154 {NULL, 0, NULL, NULL},
155 };
156
157
158 static Menu_ele drawpopup[] =
159 {
160 {"Line", EntryEle, NULL, m_plotline},
161 {"Rectangle", EntryEle, NULL, m_plotrect},
162 {"Arc", EntryEle, NULL, m_plotarc},
163 {"Ellipse", EntryEle, NULL, m_plotcircle},
164 {"Button", EntryEle, NULL, m_plotbutton},
165 {"->Edit On", EntryEle, NULL, m_editdraw},
166 {"->Edit Off", EntryEle, NULL, m_exitdraw},
167 {NULL, 0, NULL, NULL},
168 };
169
170 static Menu_ele chartpopup[] =
171 {
172 {"Create", EntryEle, NULL, m_createplot},
173 {"Option...", EntryEle, NULL, X11m_plotoption},
174 {"Redraw", EntryEle, NULL, cb_redrawgra},
175 {NULL, 0, NULL, NULL},
176 };
177
178 static Menu_ele toolpopup[] =
179 {
180 {"Insert Data File...", EntryEle, NULL, X11m_insertfile},
181 {"Export Data File...", EntryEle, NULL, X11m_exportfile},
182 {"Separ8", SeparatorEle, NULL, m_close},
183 {"Audit Cell", EntryEle, NULL, m_auditcell},
184 {"Separ9", SeparatorEle, NULL, m_close},
185 {"Rec Macro", EntryEle, NULL, X11m_macrorec},
186 {"Stop Recording", EntryEle, NULL, X11m_macrostop},
187 {"Play Macro...", EntryEle, NULL, X11m_macroplay},
188 {"Separ10", SeparatorEle, NULL, m_close},
189 {"ABVisual...", EntryEle, NULL, X11m_macro},
190 {NULL, 0, NULL, NULL},
191 };
192
193 static Menu_ele viewpopup[] =
194 {
195 {"Buttonbar", EntryEle, NULL, buttonbar_onoff},
196 {"Formatbar", EntryEle, NULL, formatbar_onoff},
197 {NULL, 0, NULL, NULL},
198 };
199
200 static Menu_ele windowpopup[] =
201 {
202 {NULL, 0, NULL, NULL},
203 };
204
205 static Menu_ele helppopup[] =
206 {
207 {"About...", EntryEle, NULL, m_about},
208 {"On line...", EntryEle, NULL, m_online},
209 {NULL, 0, NULL, NULL},
210 };
211
212 static Menu_ele rootmenu[] =
213 {
214 {"File", BtnEle, filepopup, nocb},
215 {"Edit", BtnEle, editpopup, nocb},
216 {"Insert", BtnEle, insertpopup, nocb},
217 {"Format", BtnEle, formatpopup, nocb},
218 {"Draw", BtnEle, drawpopup, nocb},
219 {"Chart", BtnEle, chartpopup, nocb},
220 {"Tools", BtnEle, toolpopup, nocb},
221 {"View", BtnEle, viewpopup, nocb},
222 {"Windows", BtnEle, windowpopup, nocb},
223 {"?", BtnEle, helppopup, nocb},
224 {NULL, 0, NULL, NULL},
225 };
226
227
228 void
nocb()229 nocb ()
230 {
231 }
232
233 void
X11m_openfile()234 X11m_openfile ()
235 {
236 MakePrompt (gettop (), "open file:", m_openfile, "defaut.abs");
237 }
238
239 void
X11m_savefile()240 X11m_savefile ()
241 {
242 savefile ();
243 }
244
245 void
X11m_saveasfile()246 X11m_saveasfile ()
247 {
248 MakePrompt (gettop (), "save file:", m_saveasfile, "defaut.abs");
249 }
250
251 void
X11m_insertfile()252 X11m_insertfile ()
253 {
254 X11m_separator (INSERTFILE);
255
256
257
258 }
259
260 void
X11m_exportfile()261 X11m_exportfile ()
262 {
263 X11m_separator (EXPORTFILE);
264
265 }
266
267
268 void
X11m_paste_special()269 X11m_paste_special ()
270 {
271 PasteMakePrompt (gettop (), "Paste", NULL, NULL);
272 }
273
274 void
X11m_macro()275 X11m_macro ()
276 {
277 if (ActiveWorkbook == NULL)
278 return;
279 editmacro (ActiveWorkbook->project, 0);
280 }
281
282 void
X11m_macroplay()283 X11m_macroplay ()
284 {
285 MacroMakePrompt (gettop (), "Macro", playmacro, "defaut.abs");
286 }
287
288 void
X11m_macrorec()289 X11m_macrorec ()
290 {
291 char *name;
292 if (ActiveWorkbook == NULL)
293 return;
294 name = inputbox ("Macro name:", "macro name", NULL);
295 if (name != NULL)
296 {
297 if (strlen (name) > 0)
298 {
299 recordmacro (ActiveWorkbook->project, name);
300 }
301 else
302 {
303 Inform ("Bad macro name!", NULL);
304 }
305 }
306 else
307 {
308 Inform ("Bad macro name!", NULL);
309 }
310
311 }
312
313 void
X11m_macrostop()314 X11m_macrostop ()
315 {
316 stoprecordmacro ();
317 }
318
319 void
X11m_sheetname()320 X11m_sheetname ()
321 {
322 char *value;
323 int i;
324 if (ActiveWorkbook == NULL)
325 return;
326 if (ActiveWorksheet == NULL)
327 return;
328
329 value = inputbox ("New worksheet name:", "worksheet name", ActiveWorksheet->Name);
330 if (value != NULL)
331 if (strlen (value) > 0)
332 {
333 for (i = 0; i < ActiveWorkbook->nbworksheet; i++)
334 {
335 if (strcasecmp (ActiveWorkbook->Worksheets[i]->Name, value) == 0)
336 {
337 Inform ("Worksheet name allready in use!", NULL);
338 return;
339 }
340 }
341
342 worksheet_setname (ActiveWorksheet, value);
343 }
344
345 }
346
347
348
349 void
X11m_formatborder()350 X11m_formatborder ()
351 {
352
353 }
354
355 void
m_print(char * filename)356 m_print (char *filename)
357 {
358
359 }
360
361 void
m_close()362 m_close ()
363 {
364
365 }
366
367 Widget
make_bar_button(Widget menu_bar,char * name)368 make_bar_button (Widget menu_bar, char *name)
369 {
370 Arg args[20];
371 register int n;
372 n = 0;
373 XtSetArg (args[n], XtNborderWidth, 0);
374 n++;
375 XtSetArg (args[n], XtNhighlightThickness, 1);
376 n++;
377 return XtCreateManagedWidget
378 (name, menuButtonWidgetClass, menu_bar, args, n);
379 }
380
381 Widget
make_popup(Widget bar_button,char * name,char * button_name,struct menuEntry * menuentry,int num)382 make_popup (Widget bar_button, char *name, char *button_name, struct menuEntry * menuentry, int num)
383 {
384 Arg args[20];
385 register int n;
386 Widget popupmenu, entry;
387 int i;
388 n = 0;
389
390 XtSetArg (args[0], XtNmenuName, name);
391 XtSetValues (bar_button, args, (Cardinal) 1);
392 popupmenu = XtCreatePopupShell
393 (name, simpleMenuWidgetClass, bar_button, args, n);
394 for (i = 0; i < num; i++)
395 {
396 entry = XtCreateManagedWidget (menuentry[i].name,
397 smeBSBObjectClass, popupmenu,
398 NULL, (Cardinal) 0);
399 XtAddCallback (entry, XtNcallback, menuentry[i].function, NULL);
400 }
401
402 return popupmenu;
403
404 }
405
406 Widget
add_entry(Widget popupmenu,char * name,void (* func)())407 add_entry (Widget popupmenu, char *name, void (*func) ())
408 {
409 Widget entry = XtCreateManagedWidget (name,
410 smeBSBObjectClass, popupmenu,
411 NULL, (Cardinal) 0);
412 XtAddCallback (entry, XtNcallback, func, NULL);
413 return entry;
414 }
415
416
417
418 static int level;
419 static Widget popupmenu[10];
420 static Widget windowname[20];
421 static int nwin = 0;
422
423 int
add_window_name(char * name)424 add_window_name (char *name)
425 {
426 int i = 0;
427 while (i < 10 && strncmp (rootmenu[i].name, "Windows", 7))
428 i++;
429
430 if (nwin == 20)
431 return -1;
432
433 windowname[nwin] = add_entry (popupmenu[i], name, m_changewin);
434 nwin++;
435 return 0;
436 }
437
438 int
remove_window_name(char * name)439 remove_window_name (char *name)
440 {
441 int j;
442 int i = 0;
443
444 while (i < nwin && strcmp (XtName (windowname[i]), name))
445 i++;
446
447 if (i == nwin)
448 return 0;
449
450 XtUnmanageChild (windowname[i]);
451 XtDestroyWidget (windowname[i]);
452
453 nwin--;
454
455 for (j = i; j < nwin; j++)
456 windowname[j] = windowname[j + 1];
457
458 return 0;
459 }
460
461
462 int
recursive_build(Menubar * mb_obj,Widget parent,Menu_ele * menu)463 recursive_build (Menubar * mb_obj, Widget parent, Menu_ele * menu)
464 {
465 int i;
466 Arg args[20];
467 register int n = 0;
468 Widget entry, button;
469 XtTranslations menu_trans_table;
470 XtTranslations menu_popup_trans_table;
471 menu_trans_table = XtParseTranslationTable (menuTranslations);
472 menu_popup_trans_table = XtParseTranslationTable (menupopupTranslations);
473
474
475 i = 0;
476 level++;
477
478 while (menu[i].name != NULL)
479 {
480 switch (menu[i].type)
481 {
482 case BtnEle:
483 {
484 n = 0;
485 XtSetArg (args[n], XtNborderWidth, 0);
486 n++;
487 XtSetArg (args[n], XtNhighlightThickness, 1);
488 n++;
489 button = XtCreateManagedWidget (menu[i].name, menuButtonWidgetClass, parent, args, n);
490 XtOverrideTranslations (button, menu_trans_table);
491
492
493
494
495 n = 0;
496 XtSetArg (args[n], XtNmenuName, menu[i].name);
497 n++;
498 XtSetValues (button, args, n);
499 n = 0;
500 popupmenu[i] = XtCreatePopupShell (menu[i].name, simpleMenuWidgetClass, button, args, n);
501 XtOverrideTranslations (popupmenu[i], menu_popup_trans_table);
502
503
504
505
506
507 recursive_build (mb_obj, popupmenu[i], menu[i].popup);
508 break;
509 }
510 case EntryEle:
511 {
512 entry = XtCreateManagedWidget (menu[i].name, smeBSBObjectClass, parent,
513 NULL, (Cardinal) 0);
514 XtAddCallback (entry, XtNcallback, menu[i].cb, NULL);
515 break;
516 }
517 case SeparatorEle:
518 {
519 entry = XtCreateManagedWidget (menu[i].name, smeLineObjectClass, parent,
520 NULL, (Cardinal) 0);
521 break;
522 }
523 }
524 i++;
525 }
526 level--;
527 return 0;
528 }
529
530 Menubar *
newmenubar(Widget menubar)531 newmenubar (Widget menubar)
532 {
533 Menubar *mb_obj;
534 mb_obj = (Menubar *) absmalloc (sizeof (Menubar), "newmenubar:mb_obj ");
535
536
537
538
539
540
541
542
543
544 level = 0;
545 recursive_build (mb_obj, menubar, rootmenu);
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565 return mb_obj;
566 }
567