-
Notifications
You must be signed in to change notification settings - Fork 2
/
PExtraLabels.cxx
130 lines (114 loc) · 3.29 KB
/
PExtraLabels.cxx
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
//
// File: PExtraLabels.cxx
//
// Description: Mix-in utility class to provide simple mechanism for adding extra
// pairs of labels to one or two RowColumn parents.
//
// Created: P. Harvey - 03/16/00
//
#include <stdio.h>
#include "PExtraLabels.h"
PExtraLabels::PExtraLabels()
{
mExtraNum = 0;
mFirstExtraRow = 0;
mPane1 = NULL;
mPane2 = NULL;
}
PExtraLabels::~PExtraLabels()
{
}
void PExtraLabels::SetExtraPanes(Widget w1, Widget w2)
{
mPane1 = w1;
mPane2 = w2;
}
void PExtraLabels::ClearExtraLabels()
{
for (int i=0; i<mExtraNum; ++i) {
mExtraValue[i].SetString("-");
}
}
void PExtraLabels::SetExtraLabel(int num, char *str)
{
mExtraValue[num].SetString(str);
}
// SetExtraNum - set the number of extra labels
// - returns non-zero if the number of extra labels was changed
int PExtraLabels::SetExtraNum(int newNum)
{
int i, pos, rows, count, num;
char buff[32];
Arg wargs[1];
Widget widgets[2*kMaxExtraLabels];
int changed = 0;
if (!mPane1) return(changed);
// calculate new number of extra data fields to display
if (newNum > kMaxExtraLabels) newNum = kMaxExtraLabels;
// set the label strings of labels that already exist
for (i=0; i<mExtraNum && i<newNum; ++i) {
sprintf(buff,"%s:",GetLabelString(i));
mExtraLabel[i].SetString(buff);
}
if (mExtraNum > newNum) {
// remove unnecessary labels
count = 0;
num = mExtraNum - newNum; // number of widget pairs to remove
for (i=mExtraNum-1; i>=newNum; --i) {
widgets[count] = mExtraLabel[i].GetWidget();
widgets[count+num] = mExtraValue[i].GetWidget();
++count;
}
if (mPane1 == mPane2) {
// unmanage all widgets at once (to reduce flickering)
XtUnmanageChildren(widgets, 2*count);
} else {
XtUnmanageChildren(widgets, count);
XtUnmanageChildren(widgets+num, count);
}
// destroy the widgets
do {
--mExtraNum;
mExtraLabel[mExtraNum].DestroyLabel();
mExtraValue[mExtraNum].DestroyLabel();
} while (mExtraNum > newNum);
changed = 1;
} else if (mExtraNum<newNum && mExtraNum<kMaxExtraLabels) {
// add necessary labels
count = 0;
rows = mFirstExtraRow + newNum;
if (newNum > kMaxExtraLabels) {
newNum = kMaxExtraLabels; // limit the maximum number of labels
}
num = newNum - mExtraNum; // number of widget pairs to add
do {
pos = mFirstExtraRow + mExtraNum;
if (mPane1 == mPane2) {
// I must admit, I don't understand this positioning,
// but it works by trial and error, so here it is
XtSetArg(wargs[0], XmNpositionIndex, pos + rows + 1);
} else {
XtSetArg(wargs[0], XmNpositionIndex, pos);
}
mExtraValue[mExtraNum].CreateLabel("-", mPane2, wargs, 1, 0);
widgets[count] = mExtraValue[mExtraNum].GetWidget();
XtSetArg(wargs[0], XmNpositionIndex, pos);
sprintf(buff,"%s:",GetLabelString(mExtraNum));
mExtraLabel[mExtraNum].CreateLabel(buff, mPane1, wargs, 1, 0);
widgets[count+num] = mExtraLabel[mExtraNum].GetWidget();
++count; // count pairs of widgets added
++mExtraNum;
++rows;
} while (mExtraNum < newNum);
// manage all widgets at once (to reduce flickering)
if (mPane1 == mPane2) {
XtManageChildren(widgets, 2*count);
} else {
// must manage children separately if they have different parents
XtManageChildren(widgets, count);
XtManageChildren(widgets+num, count);
}
changed = 1;
}
return(changed);
}