Debian Codegraph @

xo/wdialog.cxx

raw
1 /* wdialog.cxx
2 $Id: wdialog.cxx,v 1.12 1998/10/15 04:17:25 elf Exp $
3
4 written by Marc Singer
5 16 May 1997
6
7 This file is part of the project XO. See the file README for
8 more information.
9
10 Copyright (C) 1997 Marc Singer
11
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 in a file called COPYING along with this program; if not, write to
24 the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
25 02139, USA.
26
27 -----------
28 DESCRIPTION
29 -----------
30
31 */
32
33 #include "standard.h"
34
35 #include "ldisplay.h"
36 //#include "lwindowclass.h"
37 #include "lwindow.h"
38 #include "wdialog.h"
39 #include "wbutton.h"
40 #include "wtext.h"
41
42
43 typedef struct {
44 Font fid; // Default dialog font, used for dlg units
45 int id; // ID for identifying
46 int unitWidth; // Width of a dialog character
47 int unitHeight; // Height of a dialog character
48 LResNode* pNodeResource; // Resource node
49 } DIALOG_INFO;
50
51 #define EVENT_MASK ( ButtonPressMask \
52 | ButtonReleaseMask \
53 | ExposureMask \
54 | EnterWindowMask \
55 | LeaveWindowMask)
56 EventMap g_rgEHDialog[] = {
57 { CreateSelfNotify, (PFNEvent) &WDialog::createself },
58 { 0, NULL },
59 };
60
61
62 WDialog* WDialog::create (LWindow* pWindowOwner, char* szFileResource, int id)
63 {
64 // Parse the resource file, **FIXME**
65 // this should be done in LResNode
66
67 FILE* fp = fopen (szFileResource, "r");
68 yyin = fp;
69 yyparse ();
70 fclose (fp);
71
72 // Extract dialog specific information
73 int rgi[4] = { 0, 0, 0, 0 };
74
75 LResNode* pNode = LResNode::locate ("dialog", id);
76 if (!pNode)
77 return NULL;
78
79 WDialog* pWindow = new WDialog (pWindowOwner->display ()
80 ->find_template ("dialog"));
81 pWindow->m_pNodeResource = pNode;
82
83 // {
84 // LResNode* pNodeArg = pNode->enum_args ();
85 // if (pNodeArg)
86 // pNodeArg->integer (&id);
87 // }
88 pWindow->id (id);
89
90 for (pNode = pNode->find_resources (); pNode; pNode = pNode->next ()) {
91 char* sz = pNode->keyword ();
92 if (!sz)
93 continue;
94
95 int* pi;
96 if (!strcasecmp (sz, "origin"))
97 pi = &rgi[0];
98 else if (!strcasecmp (sz, "extent"))
99 pi = &rgi[2];
100 else
101 continue;
102
103 int i = 0;
104 for (LResNode* pNodeArg = pNode;
105 i < 2 && (pNodeArg = pNodeArg->enum_args ());) {
106 if (pNodeArg->integer (pi)) {
107 *pi++ *= (i ? pWindow->m_unitHeight : pWindow->m_unitWidth);
108 ++i;
109 }
110 float r;
111 if (pNodeArg->real (&r)) {
112 *pi++ = int (r* (i ? pWindow->m_unitHeight : pWindow->m_unitWidth));
113 ++i;
114 }
115 }
116 }
117
118 pWindow->owner (pWindowOwner, pWindow->id ());
119 pWindow->position (rgi[0], rgi[1], rgi[2], rgi[3]);
120 pWindow->LWindow::create (NULL);
121 pWindow->map ();
122
123 return pWindow;
124 }
125
126
127 void WDialog::createself (XoCreateSelfWindowEvent* pEvent)
128 {
129 fprintf (stderr, "create dialog\n");
130 LResNode* pNode = m_pNodeResource;
131
132 // Create the child windows
133 for (pNode = pNode->find_resources (); pNode; pNode = pNode->next ()) {
134 char* sz = pNode->keyword ();
135 if (!sz)
136 continue;
137 if (!strcasecmp (sz, "pushbutton"))
138 create_pushbutton (pEvent, pNode);
139 if (!strcasecmp (sz, "textedit"))
140 create_textedit (pEvent, pNode);
141 }
142 m_pNodeResource = NULL;
143 }
144
145
146 void WDialog::create_pushbutton (XoCreateSelfWindowEvent* /* pEvent */,
147 LResNode* pNode)
148 {
149 char* szTitle = NULL;
150 int rgi[4] = { 0, 0, 0, 0 };
151
152 WButton* pWindow = new WButton (m_pDisplay->find_template ("button"));
153
154 int id = 0;
155 {
156 LResNode* pNodeArg = pNode->enum_args ();
157 if (pNodeArg)
158 pNodeArg->integer (&id);
159 }
160
161 pWindow->id (id);
162
163 for (pNode = pNode->find_resources (); pNode; pNode = pNode->next ()) {
164 char* sz = pNode->keyword ();
165 if (!sz)
166 continue;
167
168 int* pi;
169 if (!strcasecmp (sz, "origin"))
170 pi = &rgi[0];
171 else if (!strcasecmp (sz, "extent"))
172 pi = &rgi[2];
173 else if (!strcasecmp (sz, "title")) {
174 LResNode* pNodeArg = pNode->enum_args ();
175 pNodeArg->string (&szTitle);
176 continue;
177 }
178 else
179 continue;
180
181 int i = 0;
182 for (LResNode* pNodeArg = pNode;
183 i < 2 && (pNodeArg = pNodeArg->enum_args ());) {
184 if (pNodeArg->integer (pi)) {
185 *pi++ *= (i ? m_unitHeight : m_unitWidth);
186 ++i;
187 }
188 float r;
189 if (pNodeArg->real (&r)) {
190 *pi++ = int (r* (i ? m_unitHeight : m_unitWidth));
191 ++i;
192 }
193 }
194 }
195
196 pWindow->text (szTitle);
197 pWindow->owner (owner (), ((this->id () << 16) | id));
198 pWindow->position (rgi[0], rgi[1], rgi[2], rgi[3]);
199 pWindow->create (this);
200 pWindow->map ();
201 }
202
203
204 void WDialog::create_textedit (XoCreateSelfWindowEvent* /* pEvent */,
205 LResNode* pNode)
206 {
207 char* szText = NULL;
208 int rgi[4] = { 0, 0, 0, 0 };
209
210 WTextEdit* pWindow = new WTextEdit (m_pDisplay->find_template ("text"));
211
212 int id = 0;
213 {
214 LResNode* pNodeArg = pNode->enum_args ();
215 if (pNodeArg)
216 pNodeArg->integer (&id);
217 }
218
219 pWindow->id (id);
220
221 for (pNode = pNode->find_resources (); pNode; pNode = pNode->next ()) {
222 char* sz = pNode->keyword ();
223 if (!sz)
224 continue;
225
226 int* pi;
227 if (!strcasecmp (sz, "origin"))
228 pi = &rgi[0];
229 else if (!strcasecmp (sz, "extent"))
230 pi = &rgi[2];
231 else if (!strcasecmp (sz, "text")) {
232 LResNode* pNodeArg = pNode->enum_args ();
233 pNodeArg->string (&szText);
234 continue;
235 }
236 else
237 continue;
238
239 int i = 0;
240 for (LResNode* pNodeArg = pNode;
241 i < 2 && (pNodeArg = pNodeArg->enum_args ());) {
242 if (pNodeArg->integer (pi)) {
243 *pi++ *= (i ? m_unitHeight : m_unitWidth);
244 ++i;
245 }
246 float r;
247 if (pNodeArg->real (&r)) {
248 *pi++ = int (r* (i ? m_unitHeight : m_unitWidth));
249 ++i;
250 }
251 }
252 }
253
254 // pWindow->owner (pWindowParent->owner (), (void*) ((pInfo->id << 16) | id));
255 pWindow->position (rgi[0], rgi[1], rgi[2], rgi[3]);
256 pWindow->create (this);
257 if (szText)
258 pWindow->text (szText);
259 pWindow->map ();
260 }
261
262
263 void WDialog::register_template (LDisplay* pDisplay)
264 {
265 WDialog* pWindow = new WDialog (pDisplay);
266 pWindow->event_map (g_rgEHDialog);
267 pWindow->select_events (EVENT_MASK);
268
269 XrmValue value;
270 pDisplay->find_resource ("xo.dialog.font", "Toolkit.Dialog.Font",
271 NULL, &value);
272 XFontStruct* pFont = pDisplay->find_font (value.addr);
273 if (pFont) {
274 pWindow->m_fid = pFont->fid;
275 pWindow->m_unitWidth
276 = pFont->per_char['m' - pFont->min_char_or_byte2].width;
277 // pInfo->unitWidth
278 // = (pFont->min_bounds.width + pFont->max_bounds.width)/2;
279 pWindow->m_unitHeight = pFont->max_bounds.ascent
280 + pFont->max_bounds.descent;
281 }
282
283 pDisplay->hash_template ("dialog", pWindow);
284
285 // pClass->set_background_pixel (XBlackPixel (pDisplay->display (), 0));
286 // pClass->set_bit_gravity (SouthEastGravity);
287 }