1 /***********************************************************************/
2 /* Open Visualization Data Explorer */
3 /* (C) Copyright IBM Corp. 1989,1999 */
4 /* ALL RIGHTS RESERVED */
5 /* This code licensed under the */
6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
7 /***********************************************************************/
8
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11
12
13
14
15 #include <Xm/Xm.h>
16
17 #include "XmDX.h"
18 #include "DXStrings.h"
19 #include "WorkSpaceGrid.h"
20 #include "ErrorDialogManager.h"
21
WorkSpaceGrid()22 WorkSpaceGrid::WorkSpaceGrid()
23 {
24 this->setDefaultConfiguration();
25 }
26 //
27 // Use the default grid configuration.
28 //
setDefaultConfiguration()29 void WorkSpaceGrid::setDefaultConfiguration()
30 {
31 this->active = FALSE;
32 this->width = this->height = 50;
33 this->x_alignment = this->y_alignment = XmALIGNMENT_NONE;
34 }
35
alignmentString()36 char *WorkSpaceGrid::alignmentString()
37 {
38 char *align = new char[4];
39
40 switch (this->y_alignment)
41 {
42 case XmALIGNMENT_BEGINNING:
43 align[0] = 'U';
44 break;
45 case XmALIGNMENT_CENTER:
46 align[0] = 'C';
47 break;
48 case XmALIGNMENT_END:
49 align[0] = 'L';
50 break;
51 case XmALIGNMENT_NONE:
52 align[0] = 'N';
53 break;
54 }
55 switch (this->x_alignment)
56 {
57 case XmALIGNMENT_BEGINNING:
58 align[1] = 'L';
59 break;
60 case XmALIGNMENT_CENTER:
61 align[1] = 'C';
62 break;
63 case XmALIGNMENT_END:
64 align[1] = 'R';
65 break;
66 case XmALIGNMENT_NONE:
67 align[1] = 'N';
68 break;
69 }
70 align[2] = '\0';
71
72 return align;
73 }
parseAlignment(const char * align)74 void WorkSpaceGrid::parseAlignment(const char *align)
75 {
76
77 switch(align[0])
78 {
79 case 'U':
80 this->y_alignment = XmALIGNMENT_BEGINNING;
81 break;
82 case 'C':
83 this->y_alignment = XmALIGNMENT_CENTER;
84 break;
85 case 'L':
86 this->y_alignment = XmALIGNMENT_END;
87 break;
88 case 'N':
89 this->y_alignment = XmALIGNMENT_NONE;
90 break;
91 case '\0':
92 this->y_alignment = XmALIGNMENT_CENTER;
93 this->x_alignment = XmALIGNMENT_CENTER;
94 return;
95 }
96 switch(align[1])
97 {
98 case 'L':
99 this->x_alignment = XmALIGNMENT_BEGINNING;
100 break;
101 case 'C':
102 case '\0':
103 this->x_alignment = XmALIGNMENT_CENTER;
104 break;
105 case 'R':
106 this->x_alignment = XmALIGNMENT_END;
107 break;
108 case 'N':
109 this->x_alignment = XmALIGNMENT_NONE;
110 break;
111 }
112 }
113
114 //
115 // Parse a control panel's 'layout' comment.
116 //
printComments(FILE * f)117 boolean WorkSpaceGrid::printComments(FILE *f)
118 {
119 char *s = this->getCommentString();
120 boolean r;
121
122 if (!s)
123 return TRUE;
124
125 if (fputs(s,f) < 0)
126 r = FALSE;
127 else
128 r = TRUE;
129
130 if (s) delete s;
131
132 return r;
133 }
134 //
135 // Parse a control panel's 'layout' comment.
136 // The returned string must be deleted by the caller
137 //
getCommentString()138 char *WorkSpaceGrid::getCommentString()
139 {
140 int w, h;
141
142 char *r = new char[96];
143 char *s = this->alignmentString();
144 this->getSpacing(w,h);
145 sprintf(r, "// layout: snap = %d, width = %d, height = %d, align = %s\n",
146 (this->isActive() ? 1 : 0),
147 w,
148 h,
149 s);
150
151 if (s) delete s;
152
153 return r;
154
155 }
156 //
157 // Parse a control panel's 'layout' comment.
158 //
parseComment(const char * comment,const char * filename,int lineno)159 boolean WorkSpaceGrid::parseComment(const char *comment,
160 const char *filename, int lineno)
161 {
162 int items_parsed;
163 int snap;
164 int width;
165 int height;
166 char alignment[8];
167
168 if (!EqualSubstring(comment+1,"layout",6))
169 return FALSE;
170
171 items_parsed =
172 sscanf(comment,
173 " layout: snap = %d, width = %d, height = %d, align = %[^\n]",
174 &snap,
175 &width,
176 &height,
177 alignment);
178 /*
179 * If not parsed correctly, error.
180 */
181 if (items_parsed != 4)
182 {
183 #if 0
184 (_parse_widget, "#10001", "grid", _parse_file, yylineno);
185 #else
186 ErrorMessage("Bad 'layout' panel comment (file %s, line %d)",
187 filename, lineno);
188 #endif
189 return TRUE;
190 }
191
192 /*
193 * Save the grid information for later use.
194 */
195 this->setActive(snap > 0);
196 this->setSpacing(width, height);
197 this->parseAlignment(alignment);
198
199 return TRUE;
200 }
201
202