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 "popnindex.h"
52 #include "button.h"
53 #include "info_dialog.h"
54 #include "inputbox.h"
55 #include "workbook.h"
56 #include "mainwin.h"
57 #include "left.xpm"
58 #include "right.xpm"
59 #include "first.xpm"
60 #include "last.xpm"
61
62 #include "callback.h"
63 #include "gr_interf.h"
64
65 static struct menuEntry popupMenuEntries[] =
66 {
67 {"Cut", m_cut},
68 {"Copy", m_copy},
69 {"Paste", m_paste},
70 {"Copy Down", m_copyd},
71 {"Copy Right", m_copyr},
72 };
73
74
75
76 Widget
make_alone_popup(Widget _toplevel,char * name)77 make_alone_popup (Widget _toplevel, char *name)
78 {
79 Arg args[20];
80 register int n;
81 Widget popupmenu, entry;
82 int i;
83 n = 0;
84
85
86 XtSetArg (args[n], XtNinput, True);
87 n++;
88
89 popupmenu = XtCreatePopupShell
90 ("popupMenu", simpleMenuWidgetClass, _toplevel, args, n);
91
92 for (i = 0; i < XtNumber (popupMenuEntries); i++)
93 {
94 entry = XtCreateManagedWidget (popupMenuEntries[i].name,
95 smeBSBObjectClass, popupmenu, NULL, (Cardinal) 0);
96 XtAddCallback (entry, XtNcallback, popupMenuEntries[i].function, NULL);
97 }
98
99
100
101 return popupmenu;
102 }
103
104
105 void
changesheetname(w,pointer,event,ctd)106 changesheetname (w, pointer, event, ctd)
107 Widget w;
108 XtPointer pointer;
109 XEvent *event;
110 Boolean *ctd;
111 {
112 int s = 0;
113 int sheet = -1;
114 char *value;
115 int i;
116
117 if (((XButtonEvent *) event)->button == Button1)
118 {
119 int s = 0;
120 for (s = 0; s < 20; s++)
121 if (w == ActiveMainwin->selectsheet[s])
122 cb_changesheet (s + ActiveWorkbook->first_vis_wks);
123 return;
124 }
125
126 if (((XButtonEvent *) event)->button != Button3)
127 return;
128
129 for (s = 0; s < 20; s++)
130 if (w == ActiveMainwin->selectsheet[s])
131 sheet = s + ActiveWorkbook->first_vis_wks;
132
133 if (sheet < 0)
134 return;
135
136 value = inputbox ("New worksheet name:", "worksheet name", ActiveWorkbook->Worksheets[sheet]->Name);
137 if (value != NULL)
138 if (strlen (value) > 0)
139 {
140 for (i = 0; i < ActiveWorkbook->nbworksheet; i++)
141 {
142 if (strcasecmp (ActiveWorkbook->Worksheets[i]->Name, value) == 0)
143 {
144 Inform ("Worksheet name allready in use!", NULL);
145 return;
146 }
147 }
148
149 worksheet_setname (ActiveWorkbook->Worksheets[sheet], value);
150 }
151 }
152
153
154 static Widget thumbpar;
155
156 void
build_thumb(Widget parent)157 build_thumb (Widget parent)
158 {
159 int i;
160 int width;
161 int pos = 0;
162 char *name = "?";
163
164 ActiveMainwin->first = make_button_pixmap (ActiveMainwin->sheetbtn, "first", first_xpm,
165 cb_first_sheet, NULL);
166 w_n = 0;
167 w_rel (NULL, 0, 0);
168 w_set (ActiveMainwin->first);
169
170 ActiveMainwin->previous = make_button_pixmap (ActiveMainwin->sheetbtn, "previous", left_xpm, cb_previous_sheet, NULL);
171 w_n = 0;
172 w_relv (NULL, 0);
173 w_relh (ActiveMainwin->first, 0);
174 w_set (ActiveMainwin->previous);
175
176 ActiveMainwin->next = make_button_pixmap (ActiveMainwin->sheetbtn, "next", right_xpm,
177 cb_next_sheet, NULL);
178 w_n = 0;
179 w_relh (ActiveMainwin->previous, 0);
180 w_relv (NULL, 0);
181 w_set (ActiveMainwin->next);
182
183 ActiveMainwin->last = make_button_pixmap (ActiveMainwin->sheetbtn, "last", last_xpm,
184 cb_last_sheet, NULL);
185 w_n = 0;
186 w_relh (ActiveMainwin->next, 0);
187 w_relv (NULL, 0);
188 w_set (ActiveMainwin->last);
189
190
191 thumbpar = parent;
192
193
194 for (i = 0; i < 20; i++)
195 {
196 width = 20;
197 w_n = 0;
198 w_relv (NULL, 0);
199 w_relh (NULL, pos);
200
201 w_dim (width + 15, 20);
202 w_bord (0);
203 pos += width + 15;
204 XtSetArg (w_args[w_n], XtNbackground, absblack);
205 w_n++;
206 XtSetArg (w_args[w_n], XtNforeground, abswhite);
207 w_n++;
208
209 if (i == 0)
210 {
211 XtSetArg (w_args[w_n - 2], XtNforeground, absblack);
212 XtSetArg (w_args[w_n - 1], XtNbackground, abswhite);
213
214
215
216 }
217
218
219
220
221 if (i > 0)
222 {
223
224
225
226 }
227 ActiveMainwin->selectsheet[i] = XtCreateWidget (name, commandWidgetClass, parent, w_args, w_n);
228
229 XtAddEventHandler (ActiveMainwin->selectsheet[i], ButtonReleaseMask, True, changesheetname, ActiveMainwin->selectsheet[i]);
230
231 }
232 return;
233 }
234
235 int
rebuild_thumb()236 rebuild_thumb ()
237 {
238 int i, j;
239 int width;
240 int nb;
241 int pos = 0;
242 char *name;
243
244 if (ActiveWorkbook == NULL)
245 return -1;
246 if (BatchMode)
247 return 0;
248
249 for (i = 0; i < 20; i++)
250 if (ActiveMainwin->selectsheet[i] != NULL)
251 {
252 XtUnmanageChild (ActiveMainwin->selectsheet[i]);
253 }
254 nb = ActiveWorkbook->nbworksheet;
255 j = 0;
256 for (i = ActiveWorkbook->first_vis_wks; i < nb && j < 19; i++)
257 {
258 name = ActiveWorkbook->Worksheets[i]->Name;
259 if (name == NULL)
260 name = "?";
261 width = gettextw (name, strlen (name), 1, 0, 2) + 25;
262 w_n = 0;
263 w_relh (NULL, pos);
264 w_dim (width, 20);
265 XtSetArg (w_args[w_n], XtNlabel, name);
266 w_n++;
267
268 pos += width;
269 if (ActiveWorkbook->Worksheets[i] == ActiveWorkbook->activeworksheet)
270 {
271 XtSetArg (w_args[w_n], XtNforeground, absblack);
272 w_n++;
273 XtSetArg (w_args[w_n], XtNbackground, abswhite);
274 w_n++;
275
276
277
278
279 }
280
281 else
282 {
283 XtSetArg (w_args[w_n], XtNbackground, absblack);
284 w_n++;
285 XtSetArg (w_args[w_n], XtNforeground, abswhite);
286 w_n++;
287
288
289
290
291 }
292
293 w_set (ActiveMainwin->selectsheet[j]);
294 XtManageChild (ActiveMainwin->selectsheet[j]);
295 j++;
296 }
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312 return 0;
313 }
314
315 void
cb_previous_sheet()316 cb_previous_sheet ()
317 {
318 if (ActiveWorkbook == NULL)
319 return;
320 if (ActiveWorkbook->first_vis_wks > 0)
321 ActiveWorkbook->first_vis_wks--;
322 rebuild_thumb ();
323 }
324
325 void
cb_next_sheet()326 cb_next_sheet ()
327 {
328 if (ActiveWorkbook == NULL)
329 return;
330 if (ActiveWorkbook->first_vis_wks < ActiveWorkbook->nbworksheet - 1)
331 ActiveWorkbook->first_vis_wks++;
332 rebuild_thumb ();
333 }
334
335 void
cb_last_sheet()336 cb_last_sheet ()
337 {
338 if (ActiveWorkbook == NULL)
339 return;
340 ActiveWorkbook->first_vis_wks = ActiveWorkbook->nbworksheet - 2;
341 rebuild_thumb ();
342 }
343 void
cb_first_sheet()344 cb_first_sheet ()
345 {
346 if (ActiveWorkbook == NULL)
347 return;
348 ActiveWorkbook->first_vis_wks = 0;
349 rebuild_thumb ();
350 }
351