-
Notifications
You must be signed in to change notification settings - Fork 2
/
awEdit.c
440 lines (359 loc) · 10.9 KB
/
awEdit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 Deutches Elektronen-Synchrotron in der Helmholtz-
* Gemelnschaft (DESY).
* Copyright (c) 2002 Berliner Speicherring-Gesellschaft fuer Synchrotron-
* Strahlung mbH (BESSY).
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/* awEdit.c */
/************************DESCRIPTION***********************************
This file contains routines for edit functions
**********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Xm/Xm.h>
#include "alarm.h"
#include "alh.h"
#include "line.h"
#include "axSubW.h"
#include "alLib.h"
#include "axArea.h"
#include "sllLib.h"
#include "ax.h"
#define KEEP 0
#define ALH_DELETE 1
static struct undoInfo {
GCLINK *link;
int linkType;
GCLINK *configLink;
int command;
int delete;
} undoData;
struct clipInfo {
GCLINK *link;
int linkType;
} clipData = {
0, 0 };
/******************************************************
editUndoSet
******************************************************/
void editUndoSet(GCLINK *link,int linkType,GCLINK *configLink,
int command,int delete)
{
/* delete unused configLink group or channel */
/*
if (delete && link && link != configLink){
if (undoData.linkType == GROUP)
alRemoveGroup((GLINK *)undoData.link);
else
alRemoveChan((CLINK *)undoData.link);
}
*/
undoData.link = link;
undoData.linkType = linkType;
undoData.configLink = configLink;
undoData.command = command;
}
/******************************************************
editUndoGet
******************************************************/
void editUndoGet(GCLINK **plink,int *plinkType,GCLINK **pconfigLink)
{
static int undoInit=1;
if (undoInit) {
undoData.link=NULL;
undoData.linkType=0;
undoData.configLink=NULL;
undoInit =0;
}
*plink = undoData.link;
*plinkType = undoData.linkType;
*pconfigLink = undoData.configLink;
}
/******************************************************
editUndoGetCommand
******************************************************/
int editUndoGetCommand()
{
return undoData.command;
}
/******************************************************
editClipboardGet
******************************************************/
void editClipboardGet(GCLINK **plink,int *plinkType)
{
if (clipData.linkType == GROUP){
*plink = (GCLINK *)alCopyGroup((GLINK *)clipData.link);
} else {
*plink = (GCLINK *)alCopyChan((CLINK *)clipData.link);
}
*plinkType = clipData.linkType;
}
/******************************************************
editClipboardSet
******************************************************/
void editClipboardSet(GCLINK *link,int linkType)
{
if (clipData.linkType == GROUP)
alDeleteGroup((GLINK *)clipData.link);
else
alDeleteChan((CLINK *)clipData.link);
if (linkType == GROUP){
clipData.link = (GCLINK *)alCopyGroup((GLINK *)link);
} else {
clipData.link = (GCLINK *)alCopyChan((CLINK *)link);
}
clipData.linkType = linkType;
}
/******************************************************
editCutLink
******************************************************/
void editCutLink(ALINK *area,GCLINK *link,int linkType)
{
struct subWindow *groupWindow,*treeWindow;
GLINK *parent;
GCLINK *linkTemp;
int diffCount, count=0;
struct anyLine *treeLine;
struct anyLine *groupLine;
struct anyLine *line;
WLINE *wline=0;
Widget pushButton = 0;
XmPushButtonCallbackStruct *cbs=NULL;
if (!link) return;
treeWindow = area->treeWindow;
groupWindow = area->groupWindow;
diffCount = link->viewCount;
treeLine = (struct anyLine *)link->lineTreeW;
groupLine = (struct anyLine *)link->lineGroupW;
/* treeWindow selection */
if (link == treeWindow->selectionLink){
/* adjust lines of treeWindow*/
/*
line= treeLine;
count = diffCount;
while (count){
line->link = 0;
line = (struct anyLine *)sllNext(line);
if (!line) break;
count--;
}
*/
/* adjust lines in groupWindow */
/*
line = (struct anyLine *)sllFirst(groupWindow->lines);
while (line){
line->link = 0;
line = (struct anyLine *)sllNext(line);
}
*/
/* adjust treeWindow viewCount */
linkTemp=link;
while (TRUE){
linkTemp = (GCLINK *)linkTemp->parent;
if (linkTemp == NULL ) break;
linkTemp->viewCount -= diffCount;
count = linkTemp->viewCount;
}
setViewConfigCount(area->treeWindow,count);
/* update line data */
/*
link->lineTreeW = NULL;
link->lineGroupW = NULL;
*/
/* remove selected group from parent's childlist*/
alRemoveGroup((GLINK *)link);
/* adjust treeSym for treeWindow */
parent = (GLINK *)link->parent;
alViewAdjustTreeW(parent, NOCHANGE, area->viewFilter);
/* redraw tree window */
line = (struct anyLine *)parent->lineTreeW;
if (line) {
redraw(treeWindow, line->lineNo);
wline = (WLINE *)line->wline;
if (wline) pushButton = wline->name;
}
else redraw(treeWindow,0);
/* adjust groupWindow */
groupWindow = area->groupWindow;
groupWindow->parentLink = parent;
groupWindow->viewConfigCount = alViewAdjustGroupW((GLINK *)parent,
area->viewFilter);
/* redraw Group window */
if (pushButton) nameTreeW_callback(pushButton, line, cbs);
}
/* groupWindow selection */
else if (link == groupWindow->selectionLink){
/* adjust groupWindow selection */
markSelectedWidget(groupWindow,0);
markSelection(groupWindow, 0);
/* make treeWindow selection the active selection */
area->selectionWindow = treeWindow;
area->selectionWidget = treeWindow->selectionWidget;
area->selectionLink = treeWindow->selectionLink;
area->selectionType = GROUP;
/* update dialog windows */
axUpdateDialogs(area);
/* adjust treeWindow */
if (treeLine) {
/* adjust lines of treeWindow*/
line = treeLine;
count = diffCount;
while (count){
line->link = 0;
line = (struct anyLine *)sllNext(line);
if (!line) break;
count--;
}
/* adjust viewCount of treeWindow*/
linkTemp = link;
while (TRUE){
linkTemp = (GCLINK *)linkTemp->parent;
if (linkTemp == NULL ) break;
linkTemp->viewCount -= diffCount;
count = linkTemp->viewCount;
}
setViewConfigCount(area->treeWindow,count);
}
/* adjust line of groupWindow */
groupLine->link = 0;
/* adjust viewCount of groupWindow*/
groupWindow->viewConfigCount -= 1;
/* delete selected group or channel */
if (groupLine->linkType == GROUP){
alRemoveGroup((GLINK *)link);
} else {
alRemoveChan((CLINK *)link);
}
/* adjust treeSym for treeWindow */
parent = (GLINK *)link->parent;
alViewAdjustTreeW(parent, NOCHANGE, area->viewFilter);
/* redraw windows */
if (treeLine){
line = (struct anyLine *)parent->lineTreeW;
if (line) redraw(treeWindow, line->lineNo);
else redraw(treeWindow,0);
}
redraw(groupWindow,groupLine->lineNo);
}
/* not a selection */
else {
/* delete selected group or channel */
if (groupLine->linkType == GROUP){
alRemoveGroup((GLINK *)link);
} else {
alRemoveChan((CLINK *)link);
}
/* adjust treeWindow */
if (treeLine) {
/* adjust lines of treeWindow*/
line = treeLine;
count = diffCount;
while (count){
line->link = 0;
line = (struct anyLine *)sllNext(line);
if (!line) break;
count--;
}
/* adjust viewCount of treeWindow*/
linkTemp = link;
while (TRUE){
linkTemp = (GCLINK *)linkTemp->parent;
if (linkTemp == NULL ) break;
linkTemp->viewCount -= diffCount;
count = linkTemp->viewCount;
}
setViewConfigCount(area->treeWindow,count);
/* adjust treeSym for treeWindow */
parent = (GLINK *)link->parent;
alViewAdjustTreeW(parent, NOCHANGE, area->viewFilter);
/* redraw windows */
line = (struct anyLine *)parent->lineTreeW;
if (line) redraw(treeWindow, line->lineNo);
else redraw(treeWindow,0);
}
if (groupLine) {
/* adjust line of groupWindow */
groupLine->link = 0;
/* adjust viewCount of groupWindow*/
groupWindow->viewConfigCount -= 1;
redraw(groupWindow,groupLine->lineNo);
}
}
/* update arrow */
if (link->parent->lineTreeW)
awRowWidgets(link->parent->lineTreeW,area);
if (link->parent->lineGroupW)
awRowWidgets(link->parent->lineGroupW,area);
}
/******************************************************
editInsertFile
******************************************************/
void editInsertFile(char *filename,ALINK *area)
{
GCLINK *newLink;
GLINK *linkHold;
linkHold = (GLINK *)sllFirst(area->pmainGroup);
alGetConfig(area->pmainGroup,filename,CA_CONNECT_NO);
if (!sllFirst(area->pmainGroup)){
createDialog(area->form_main,XmDIALOG_ERROR,filename,
" is not a valid alarm configuration file.");
return;
}
newLink = (GCLINK *)sllFirst(area->pmainGroup);
((GCLINK *)newLink)->viewCount = 1;
area->pmainGroup->p1stgroup = linkHold;
editPasteLink(area, newLink, GROUP);
}
/******************************************************
editPasteLink
******************************************************/
void editPasteLink(ALINK *area,GCLINK *newLink,int linkType)
{
struct subWindow *treeWindow;
GCLINK *parentLink;
GCLINK *selectLink;
int selectType;
if (!newLink) return;
selectLink = (GCLINK *)area->selectionLink;
selectType = area->selectionType;
treeWindow = area->treeWindow;
editUndoSet( NULL, linkType, (GCLINK *)newLink,
MENU_EDIT_UNDO_CUT_NOSELECT, ALH_DELETE);
if (linkType == GROUP){
/* add/insert group link */
parentLink = treeWindow->selectionLink;
if ( selectLink == parentLink || selectLink == NULL ||
selectType == CHANNEL ){
alPrecedeGroup((GLINK *)parentLink, NULL, (GLINK *)newLink);
} else {
alPrecedeGroup((GLINK *)parentLink,(GLINK *)selectLink,
(GLINK *)newLink);
}
awViewNewGroup(area, (GCLINK *)newLink);
} else {
/* add/insert channel link */
parentLink = treeWindow->selectionLink;
if ( selectLink == parentLink || selectLink == NULL ||
selectType == GROUP){
alPrecedeChan((GLINK *)parentLink, NULL, (CLINK *)newLink);
} else {
alPrecedeChan((GLINK *)parentLink,(CLINK *)selectLink,
(CLINK *)newLink);
}
awViewNewChan(area, (GCLINK *)newLink);
}
/* update arrow */
if (newLink->parent->lineTreeW)
awRowWidgets(newLink->parent->lineTreeW,area);
if (newLink->parent->lineGroupW)
awRowWidgets(newLink->parent->lineGroupW,area);
}