-
Notifications
You must be signed in to change notification settings - Fork 1
/
axSubW.c
501 lines (430 loc) · 15.7 KB
/
axSubW.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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/*************************************************************************\
* 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.
\*************************************************************************/
/* axSubW.c */
/************************DESCRIPTION***********************************
This file contains subWindow handling routines.
**********************************************************************/
/********************************************************************
Public functions defined in axSubW.c
static void scrollBarMovedCallback() Adjust viewOffset when
subWindow scrollbar is moved
void setParentLink() Set parentLink for subWindow
void setLineRoutine() Set subWindow routine names
void markSelectedWidget() Mark new and unmark old subWindow widgets
void initializeSubWindow() Initialize subWindow fields
void setViewConfigCount() Put count in subWindow viewCount field
void invokeSubWindowUpdate() Update each line of subWindow
struct subWindow *createSubWindow() Alloc space for a subWindow structure
void createSubWindowWidgets() Create all subWindow widgets
int calcRowCount() Calculate the number of subWindow rows(lines)
int calcRowYValue() Calculate the subWindow y value for row(line)
void adjustScrollBar() Set new scrollbar values when subWindow
view has changed
void exposeResizeCallback() Redraw subWindows if resize has occurred
void defaultTreeSelection() Make 1st line treeWindow default selection
void initSevrAbove() Initialize severity above indicator
void initSevrBelow() Initialize severity below indicator
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <X11/StringDefs.h>
#include <Xm/Xm.h>
#include <Xm/DrawingA.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/ScrollBar.h>
#include <Xm/ScrolledW.h>
#include <Xm/Text.h>
#include "alh.h"
#include "sllLib.h"
#include "line.h"
#include "axSubW.h"
#include "axArea.h"
#include "ax.h"
/* globals */
extern Pixel bg_pixel[ALH_ALARM_NSEV];
/***************************************************
scrollBarMovedCallback
****************************************************/
static void scrollBarMovedCallback(Widget widget,struct subWindow *subWindow,
XmScrollBarCallbackStruct *cbs)
{
if ((int)subWindow->viewOffset == cbs->value) return;
subWindow->viewOffset = cbs->value;
redraw(subWindow,0);
}
/***************************************************
setParentLink
****************************************************/
void setParentLink(struct subWindow *subWindow,void *link)
{
subWindow->parentLink = link;
}
/***************************************************
setLineRoutine
****************************************************/
void setLineRoutine(void *area,struct subWindow *subWindow,int program)
{
/* Set line widget creation/modify routines to default values */
if (isTreeWindow(area,subWindow)) {
subWindow->alViewNth = ( void *(*)())alViewNthTreeW;
subWindow->alViewNext = ( void *(*)())alViewNextTreeW;
subWindow->alViewMaxSevrN = alViewMaxSevrNTreeW;
} else {
subWindow->alViewNth = (void *(*)())alViewNthGroupW;
subWindow->alViewNext = (void *(*)())alViewNextGroupW;
subWindow->alViewMaxSevrN = alViewMaxSevrNGroupW;
}
}
/***************************************************
markSelectedWidget
****************************************************/
void markSelectedWidget(struct subWindow *subWindow,Widget newWidget)
{
static Pixel armColor=0;
static Pixel backgroundColor=0;
static Pixel bottomShadowColor=0;
static Pixel topShadowColor=0;
Widget oldWidget;
oldWidget = subWindow->selectionWidget;
if (oldWidget == newWidget ) return;
if (oldWidget) {
XtVaGetValues(oldWidget,
XmNbackground, &backgroundColor,
XmNarmColor, &armColor,
XmNtopShadowColor, &topShadowColor,
XmNbottomShadowColor,&bottomShadowColor,
(XtPointer)NULL);
XtVaSetValues(oldWidget,
XmNbackground, armColor,
XmNarmColor, backgroundColor,
XmNtopShadowColor, bottomShadowColor,
XmNbottomShadowColor,topShadowColor,
NULL);
}
if (newWidget) {
XtVaGetValues(newWidget,
XmNbackground, &backgroundColor,
XmNarmColor, &armColor,
XmNtopShadowColor, &topShadowColor,
XmNbottomShadowColor,&bottomShadowColor,
(XtPointer)NULL);
XtVaSetValues(newWidget,
XmNbackground, armColor,
XmNarmColor, backgroundColor,
XmNtopShadowColor, bottomShadowColor,
XmNbottomShadowColor,topShadowColor,
NULL);
}
subWindow->selectionWidget = newWidget;
markActiveWidget(subWindow->area,newWidget);
}
/***************************************************
initializeSubWindow
****************************************************/
void initializeSubWindow(struct subWindow *subWindow)
{
subWindow->modified = FALSE;
subWindow->viewOffset = 0;
/* Make NULL the selected group */
subWindow->selectionLink = NULL;
subWindow->parentLink = NULL;
subWindow->viewConfigCount = 0;
subWindow->oldViewConfigCount = 0;
initializeLines((SNODE *)subWindow->lines);
}
/***************************************************
setViewConfigCount
****************************************************/
void setViewConfigCount(struct subWindow *subWindow,int count)
{
subWindow->viewConfigCount = count;
/*
subWindow->oldViewConfigCount = 0;
*/
}
/***************************************************
invokeSubWindowUpdate
****************************************************/
void invokeSubWindowUpdate(struct subWindow *subWindow)
{
SLIST *lines;
struct anyLine *line;
void *link=0;
int linkType;
if (subWindow->modified){
redraw(subWindow,0);
subWindow->modified = 0;
return;
}
lines = subWindow->lines;
if (!lines) return;
/* update modified lines */
line = (struct anyLine *)sllFirst(lines);
while (line){
invokeLinkUpdate((GCLINK *)line->link,line->linkType);
if (line->link ){
link = line->link;
linkType = line->linkType;
}
line = (struct anyLine *)sllNext(line);
}
/* update the severity below indicator */
if (link) {
link = (subWindow->alViewNext)(link,&linkType);
if (link) initSevrBelow(subWindow,link);
}
/* update the severity above indicator */
link = (subWindow->alViewNth)(subWindow->parentLink,&linkType,0);
initSevrAbove(subWindow,link);
}
/***************************************************
createSubWindow
****************************************************/
struct subWindow *createSubWindow(void *area)
{
struct subWindow *subWindow;
subWindow =(struct subWindow *)calloc(1,sizeof(struct subWindow));
subWindow->area = (void *)area;
/* allocate and initialize a list for line data */
subWindow->lines = (SLIST *)calloc(1,sizeof(SLIST));
sllInit(subWindow->lines);
return(subWindow);
}
/***************************************************
createSubWindowWidgets
****************************************************/
void createSubWindowWidgets(struct subWindow *subWindow,Widget parent)
{
Pixel color=0;
Dimension width=0;
/* Create a Form for sevr indicators and scrollbar */
subWindow->form_vsb = XtVaCreateWidget("form_vsb",
xmFormWidgetClass, parent,
XmNorientation, XmVERTICAL,
XmNadjustLast, TRUE,
XmNtopAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
subWindow->sevrAboveInd = XtVaCreateManagedWidget("sevrAboveInd",
xmLabelWidgetClass, subWindow->form_vsb,
XmNlabelType, XmPIXMAP,
XmNborderWidth, 1,
XmNtopAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
NULL);
subWindow->sevrBelowInd = XtVaCreateManagedWidget(" ",
xmLabelWidgetClass, subWindow->form_vsb,
XmNlabelType, XmPIXMAP,
XmNborderWidth, 1,
XmNrightAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
/* Create vertical scrollbar for the tree area */
subWindow->vsb = XtVaCreateManagedWidget("vsb",
xmScrollBarWidgetClass, subWindow->form_vsb,
XmNorientation, XmVERTICAL,
XmNrepeatDelay, 200,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, subWindow->sevrAboveInd,
XmNbottomAttachment, XmATTACH_WIDGET,
XmNbottomWidget, subWindow->sevrBelowInd,
XmNrightAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
NULL);
/* manage the Form for sevr indicators and scrollbar in the sub */
XtManageChild(subWindow->form_vsb);
/* use same callback for all callback reasons */
XtAddCallback(subWindow->vsb,
XmNvalueChangedCallback,
(XtCallbackProc)scrollBarMovedCallback, subWindow);
XtAddCallback(subWindow->vsb,
XmNdragCallback,
(XtCallbackProc)scrollBarMovedCallback, subWindow);
XtVaGetValues(subWindow->vsb,
XmNwidth, &width,
XmNtroughColor, &color,
NULL);
XtVaSetValues(subWindow->sevrAboveInd,
XmNbackground, color,
XmNheight, width,
XmNwidth, width,
NULL);
XtVaSetValues(subWindow->sevrBelowInd,
XmNbackground, color,
XmNheight, width,
XmNwidth, width,
NULL);
/* Create DrawingArea to hold the line widgets */
subWindow->drawing_area = XtVaCreateManagedWidget("drawing_area",
xmDrawingAreaWidgetClass, parent,
XmNresizePolicy, XmRESIZE_NONE,
XmNmarginHeight, 3,
XmNspacing, 0,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
NULL);
}
/***************************************************
calcRowCount
****************************************************/
int calcRowCount(struct subWindow *subWindow)
{
int viewRowCount;
viewRowCount =(int)((int)(subWindow->viewHeight-2*subWindow->marginHeight)/
(int)(2+subWindow->rowHeight));
return(viewRowCount);
}
/***************************************************
calcRowYValue
****************************************************/
int calcRowYValue(struct subWindow *subWindow,int lineNo)
{
int yValue;
yValue = (int)(2+subWindow->rowHeight)*lineNo + subWindow->marginHeight;
return(yValue);
}
/***************************************************
adjustScrollBar
****************************************************/
void adjustScrollBar(struct subWindow *subWindow)
{
/* adjust scrollbar and slider if viewRowCount or viewConfigCount changed*/
if ( !subWindow->viewRowCount || !subWindow->viewConfigCount)
XtUnmanageChild(subWindow->form_vsb);
if ( subWindow->viewRowCount != subWindow->oldViewRowCount ||
subWindow->viewConfigCount != subWindow->oldViewConfigCount ){
if ( XtIsManaged(subWindow->form_vsb) == TRUE )
XtUnmanageChild(subWindow->form_vsb);
/* set slider values */
XtVaSetValues(subWindow->vsb,
XmNvalue, subWindow->viewOffset,
XmNmaximum, Mmax(subWindow->viewRowCount,
subWindow->viewConfigCount),
XmNsliderSize, Mmax(subWindow->viewRowCount, 1),
XmNpageIncrement, Mmax(subWindow->viewRowCount-1, 1),
(XtPointer)NULL);
/* manage/unmanage scrollbar */
if ( subWindow->viewConfigCount <= subWindow->viewRowCount ){
if ( XtIsManaged(subWindow->form_vsb) == TRUE ){
XtUnmanageChild(subWindow->form_vsb);
}
} else {
if ( XtIsManaged(subWindow->form_vsb) == FALSE ){
XtManageChild(subWindow->form_vsb);
}
}
subWindow->oldViewConfigCount = subWindow->viewConfigCount;
subWindow->oldViewRowCount = subWindow->viewRowCount;
}
}
/***************************************************
exposeResizeCallback
****************************************************/
void exposeResizeCallback(Widget widget,struct subWindow *subWindow,
XEvent *cbs)
{
Dimension oldViewHeight;
/*
if (cbs->reason == XmCR_EXPOSE){
return;
}
*/
oldViewHeight = subWindow->viewHeight;
XtVaGetValues(subWindow->drawing_area,
XmNheight, &subWindow->viewHeight,
XmNmarginHeight, &subWindow->marginHeight,
NULL);
subWindow->oldViewRowCount = subWindow->viewRowCount;
if ( subWindow->rowHeight ){
subWindow->viewRowCount = calcRowCount(subWindow);
}
if (subWindow->viewRowCount <= 0) return;
redraw(subWindow,0);
/* because redraw is slow we get into trouble with following stmnts
with many frequent calls to resize
*/
#if 0
if (subWindow->viewHeight == oldViewHeight) return;
if (subWindow->viewHeight < oldViewHeight) {
if (subWindow->viewRowCount < subWindow->viewConfigCount){
redraw(subWindow,subWindow->viewRowCount);
} else return;
} else{
redraw(subWindow,subWindow->oldViewRowCount);
}
#endif
}
/***************************************************
defaultTreeSelection
****************************************************/
void defaultTreeSelection(ALINK *area)
{
struct subWindow *treeWindow;
struct subWindow *groupWindow;
struct anyLine *line;
WLINE *wline;
treeWindow = (struct subWindow *)area->treeWindow;
groupWindow = (struct subWindow *)area->groupWindow;
if (!treeWindow->lines) return;
line = (struct anyLine *)sllFirst(treeWindow->lines);
if (!line) return;
wline = (WLINE *)(line->wline);
markSelectedWidget(treeWindow,wline->name);
markSelection(treeWindow, line);
/* groupWindow must now display contents of new treeWindow selection */
groupWindow->parentLink = line->link;
groupWindow->viewConfigCount =
alViewAdjustGroupW((GLINK *)line->link,area->viewFilter);
groupWindow->viewOffset = 0;
redraw(groupWindow,0);
}
/***************************************************
initSevrAbove
****************************************************/
void initSevrAbove(struct subWindow *subWindow,void *link)
{
int sevrAbove;
if ( XtIsManaged(subWindow->form_vsb) == TRUE ){
sevrAbove = (subWindow->alViewMaxSevrN)(link,subWindow->viewOffset);
#if XmVersion && XmVersion >= 1002
XmChangeColor(subWindow->sevrAboveInd,bg_pixel[sevrAbove]);
#else
XtVaSetValues(subWindow->sevrAboveInd,XmNbackground,
bg_pixel[sevrAbove],NULL);
#endif
}
}
/***************************************************
initSevrBelow
****************************************************/
void initSevrBelow(struct subWindow *subWindow,void *link)
{
int sevrBelow,n;
if ( XtIsManaged(subWindow->form_vsb) == TRUE ){
n = subWindow->viewConfigCount - subWindow->viewOffset - subWindow->viewRowCount;
sevrBelow = (subWindow->alViewMaxSevrN)(link,n);
if (sevrBelow < 0 ) return;
#if XmVersion && XmVersion >= 1002
XmChangeColor(subWindow->sevrBelowInd,bg_pixel[sevrBelow]);
#else
XtVaSetValues(subWindow->sevrBelowInd,XmNbackground,bg_pixel[sevrBelow],NULL);
#endif
}
}