1 /* -*- tab-width: 4 -*-
2  *
3  * Electric(tm) VLSI Design Systems
4  *
5  * File: graphqtdlg.cpp
6  * Dialogs implementation on Qt
7  * Written by: Dmitry Nadezhin, Instutute for Design Problems in Microelectronics, Russian Academy of Sciences
8  *
9  * Copyright (c) 2001 Static Free Software.
10  *
11  * Electric(tm) is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * Electric(tm) is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with Electric(tm); see the file COPYING.  If not, write to
23  * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
24  * Boston, Mass 02111-1307, USA.
25  *
26  * Static Free Software
27  * 4119 Alpine Road
28  * Portola Valley, California 94028
29  * info@staticfreesoft.com
30  */
31 
32 #include "global.h"
33 #include "graphqt.h"
34 #include "graphqtdlg.h"
35 #include "edialogs.h"
36 
37 #include <qapplication.h>
38 #include <qbitmap.h>
39 #include <qbuttongroup.h>
40 #include <qclipboard.h>
41 #include <qcombobox.h>
42 #include <qcursor.h>
43 #include <qlineedit.h>
44 #include <qobjectlist.h>
45 #include <qpainter.h>
46 #include <qprogressbar.h>
47 #include <qpushbutton.h>
48 #include <qradiobutton.h>
49 #include <qsignalmapper.h>
50 #include <qtimer.h>
51 #include <qwmatrix.h>
52 
53 #define GTRACE          0       /* etrace flag of usual graphics trace */
54 
55 /****** the dialogs ******/
56 
57 #define MAXSCROLLMULTISELECT 1000
58 
59 #define DIALOGNUM            16
60 #define DIALOGDEN            12
61 #define MAXICONS             20
62 
63 /* maximal time (in ms) to wait for next event */
64 #define MAXEVENTTIME         100
65 
66 static EDialogPrivate *gra_firstactivemodaldialog = 0;
67 static EDialogPrivate *gra_firstmodelessdialog = 0;
68 
69 extern EApplication *gra;
70 
71 static INTBIG gra_dialogstringpos;
72 extern "C"
73 {
74 	static int gra_stringposascending(const void *e1, const void *e2);
75 }
76 
77 
78 /****************************** C Dialog API  ******************************/
79 
80 /*
81  * Routine to initialize a dialog described by "dialog".
82  * Returns the address of the dialog object (0 if dialog cannot be initialized).
83  */
DiaInitDialog(DIALOG * dialog)84 void *DiaInitDialog(DIALOG *dialog)
85 {
86 	return(new EDialogModal( dialog ));
87 }
88 
89 /*
90  * Routine to handle actions and return the next item hit.
91  */
DiaNextHit(void * vdia)92 INTBIG DiaNextHit(void *vdia)
93 {
94 	EDialog *dia = (EDialog *)vdia;
95 	return(dia->nextHit());
96 }
97 
DiaDoneDialog(void * vdia)98 void DiaDoneDialog(void *vdia)
99 {
100 	EDialog *dia = (EDialog *)vdia;
101 	delete dia;
102 }
103 
104 /*
105  * Routine to change the size of the dialog
106  */
DiaResizeDialog(void * vdia,INTBIG wid,INTBIG hei)107 void DiaResizeDialog(void *vdia, INTBIG wid, INTBIG hei)
108 {
109 	EDialog *dia = (EDialog *)vdia;
110 	dia->resizeDialog( wid, hei );
111 }
112 
113 /*
114  * Routine to forces dialog be displayed on top of other windows
115  */
DiaBringToTop(void * vdia)116 void DiaBringToTop(void *vdia)
117 {
118 	EDialog *dia = (EDialog *)vdia;
119 	dia->bringToTop();
120 }
121 
122 /*
123  * Routine to set the text in item "item" to "msg"
124  */
DiaSetText(void * vdia,INTBIG item,CHAR * msg)125 void DiaSetText(void *vdia, INTBIG item, CHAR *msg)
126 {
127 	EDialog *dia = (EDialog *)vdia;
128 	dia->setText(item, msg);
129 }
130 
131 /*
132  * Routine to return the text in item "item"
133  */
DiaGetText(void * vdia,INTBIG item)134 CHAR *DiaGetText(void *vdia, INTBIG item)
135 {
136 	EDialog *dia = (EDialog *)vdia;
137 	return(dia->getText(item));
138 }
139 
140 /*
141  * Routine to set the value in item "item" to "value"
142  */
DiaSetControl(void * vdia,INTBIG item,INTBIG value)143 void DiaSetControl(void *vdia, INTBIG item, INTBIG value)
144 {
145 	EDialog *dia = (EDialog *)vdia;
146 	dia->setControl(item, value);
147 }
148 
149 /*
150  * Routine to return the value in item "item"
151  */
DiaGetControl(void * vdia,INTBIG item)152 INTBIG DiaGetControl(void *vdia, INTBIG item)
153 {
154 	EDialog *dia = (EDialog *)vdia;
155 	return(dia->getControl(item));
156 }
157 
158 /*
159  * Routine to check item "item" to make sure that there is
160  * text in it.  If so, it returns true.  Otherwise it beeps and returns false.
161  */
DiaValidEntry(void * vdia,INTBIG item)162 BOOLEAN DiaValidEntry(void *vdia, INTBIG item)
163 {
164 	EDialog *dia = (EDialog *)vdia;
165 	return(dia->validEntry(item));
166 }
167 
168 /*
169  * Routine to dim item "item"
170  */
DiaDimItem(void * vdia,INTBIG item)171 void DiaDimItem(void *vdia, INTBIG item)
172 {
173 	EDialog *dia = (EDialog *)vdia;
174 	dia->dimItem(item);
175 }
176 
177 /*
178  * Routine to un-dim item "item"
179  */
DiaUnDimItem(void * vdia,INTBIG item)180 void DiaUnDimItem(void *vdia, INTBIG item)
181 {
182 	EDialog *dia = (EDialog *)vdia;
183 	dia->unDimItem(item);
184 }
185 
186 /*
187  * Routine to change item "item" to be a message rather
188  * than editable text
189  */
DiaNoEditControl(void * vdia,INTBIG item)190 void DiaNoEditControl(void *vdia, INTBIG item)
191 {
192 	EDialog *dia = (EDialog *)vdia;
193 	dia->noEditControl(item);
194 }
195 
196 /*
197  * Routine to change item "item" to be editable text rather
198  * than a message
199  */
DiaEditControl(void * vdia,INTBIG item)200 void DiaEditControl(void *vdia, INTBIG item)
201 {
202 	EDialog *dia = (EDialog *)vdia;
203 	dia->editControl(item);
204 }
205 
DiaOpaqueEdit(void * vdia,INTBIG item)206 void DiaOpaqueEdit(void *vdia, INTBIG item)
207 {
208 	EDialog *dia = (EDialog *)vdia;
209 	dia->opaqueEdit(item);
210 }
211 
212 /*
213  * Routine to cause item "item" to be the default button
214  */
DiaDefaultButton(void * vdia,INTBIG item)215 void DiaDefaultButton(void *vdia, INTBIG item)
216 {
217 	EDialog *dia = (EDialog *)vdia;
218 	dia->defaultButton(item);
219 }
220 
221 /*
222  * Routine to change the icon in item "item" to be the 32x32 bitmap (128 bytes) at "addr".
223  */
DiaChangeIcon(void * vdia,INTBIG item,UCHAR1 * addr)224 void DiaChangeIcon(void *vdia, INTBIG item, UCHAR1 *addr)
225 {
226 	EDialog *dia = (EDialog *)vdia;
227 	dia->changeIcon(item, addr);
228 }
229 
230 /*
231  * Routine to change item "item" into a popup with "count" entries
232  * in "names".
233  */
DiaSetPopup(void * vdia,INTBIG item,INTBIG count,CHAR ** names)234 void DiaSetPopup(void *vdia, INTBIG item, INTBIG count, CHAR **names)
235 {
236 	EDialog *dia = (EDialog *)vdia;
237 	dia->setPopup(item, count, names);
238 }
239 
240 /*
241  * Routine to change popup item "item" so that the current entry is "entry".
242  */
DiaSetPopupEntry(void * vdia,INTBIG item,INTBIG entry)243 void DiaSetPopupEntry(void *vdia, INTBIG item, INTBIG entry)
244 {
245 	EDialog *dia = (EDialog *)vdia;
246 	dia->setPopupEntry(item, entry);
247 }
248 
249 /*
250  * Routine to return the current item in popup menu item "item".
251  */
DiaGetPopupEntry(void * vdia,INTBIG item)252 INTBIG DiaGetPopupEntry(void *vdia, INTBIG item)
253 {
254 	EDialog *dia = (EDialog *)vdia;
255 	return(dia->getPopupEntry(item));
256 }
257 
DiaInitTextDialog(void * vdia,INTBIG item,BOOLEAN (* toplist)(CHAR **),CHAR * (* nextinlist)(void),void (* donelist)(void),INTBIG sortpos,INTBIG flags)258 void DiaInitTextDialog(void *vdia, INTBIG item, BOOLEAN (*toplist)(CHAR **), CHAR *(*nextinlist)(void),
259 	void (*donelist)(void), INTBIG sortpos, INTBIG flags)
260 {
261 	EDialog *dia = (EDialog *)vdia;
262 	dia->initTextDialog(item, toplist, nextinlist, donelist, sortpos, flags);
263 }
264 
DiaLoadTextDialog(void * vdia,INTBIG item,BOOLEAN (* toplist)(CHAR **),CHAR * (* nextinlist)(void),void (* donelist)(void),INTBIG sortpos)265 void DiaLoadTextDialog(void *vdia, INTBIG item, BOOLEAN (*toplist)(CHAR **), CHAR *(*nextinlist)(void),
266 	void (*donelist)(void), INTBIG sortpos)
267 {
268 	EDialog *dia = (EDialog *)vdia;
269 	dia->loadTextDialog(item, toplist, nextinlist, donelist, sortpos);
270 }
271 
272 /*
273  * Routine to stuff line "line" at the end of the edit buffer.
274  */
DiaStuffLine(void * vdia,INTBIG item,CHAR * line)275 void DiaStuffLine(void *vdia, INTBIG item, CHAR *line)
276 {
277 	EDialog *dia = (EDialog *)vdia;
278 	dia->stuffLine(item, line);
279 }
280 
281 /*
282  * Routine to select line "line" of scroll item "item".
283  */
DiaSelectLine(void * vdia,INTBIG item,INTBIG line)284 void DiaSelectLine(void *vdia, INTBIG item, INTBIG line)
285 {
286 	EDialog *dia = (EDialog *)vdia;
287 	dia->selectLine(item, line);
288 }
289 
290 /*
291  * Routine to select "count" lines in "lines" of scroll item "item".
292  */
DiaSelectLines(void * vdia,INTBIG item,INTBIG count,INTBIG * lines)293 void DiaSelectLines(void *vdia, INTBIG item, INTBIG count, INTBIG *lines)
294 {
295 	EDialog *dia = (EDialog *)vdia;
296 	dia->selectLines(item, count, lines);
297 }
298 
299 /*
300  * Returns the currently selected line in the scroll list "item".
301  */
DiaGetCurLine(void * vdia,INTBIG item)302 INTBIG DiaGetCurLine(void *vdia, INTBIG item)
303 {
304 	EDialog *dia = (EDialog *)vdia;
305 	return(dia->getCurLine(item));
306 }
307 
308 /*
309  * Returns the currently selected lines in the scroll list "item".  The returned
310  * array is terminated with -1.
311  */
DiaGetCurLines(void * vdia,INTBIG item)312 INTBIG *DiaGetCurLines(void *vdia, INTBIG item)
313 {
314 	EDialog *dia = (EDialog *)vdia;
315 	return(dia->getCurLines(item));
316 }
317 
DiaGetNumScrollLines(void * vdia,INTBIG item)318 INTBIG DiaGetNumScrollLines(void *vdia, INTBIG item)
319 {
320 	EDialog *dia = (EDialog *)vdia;
321 	return(dia->getNumScrollLines(item));
322 }
323 
DiaGetScrollLine(void * vdia,INTBIG item,INTBIG line)324 CHAR *DiaGetScrollLine(void *vdia, INTBIG item, INTBIG line)
325 {
326 	EDialog *dia = (EDialog *)vdia;
327 	return(dia->getScrollLine(item, line));
328 }
329 
DiaSetScrollLine(void * vdia,INTBIG item,INTBIG line,CHAR * msg)330 void DiaSetScrollLine(void *vdia, INTBIG item, INTBIG line, CHAR *msg)
331 {
332 	EDialog *dia = (EDialog *)vdia;
333 	dia->setScrollLine(item, line, msg);
334 }
335 
DiaSynchVScrolls(void * vdia,INTBIG item1,INTBIG item2,INTBIG item3)336 void DiaSynchVScrolls(void *vdia, INTBIG item1, INTBIG item2, INTBIG item3)
337 {
338 	EDialog *dia = (EDialog *)vdia;
339 	dia->synchVScrolls(item1, item2, item3);
340 }
341 
DiaUnSynchVScrolls(void * vdia)342 void DiaUnSynchVScrolls(void *vdia)
343 {
344 	EDialog *dia = (EDialog *)vdia;
345 	dia->unSynchVScrolls();
346 }
347 
DiaItemRect(void * vdia,INTBIG item,RECTAREA * rect)348 void DiaItemRect(void *vdia, INTBIG item, RECTAREA *rect)
349 {
350 	EDialog *dia = (EDialog *)vdia;
351 	dia->itemRect(item, rect);
352 }
353 
DiaPercent(void * vdia,INTBIG item,INTBIG percent)354 void DiaPercent(void *vdia, INTBIG item, INTBIG percent)
355 {
356 	EDialog *dia = (EDialog *)vdia;
357 	dia->percent(item, percent);
358 }
359 
DiaRedispRoutine(void * vdia,INTBIG item,void (* routine)(RECTAREA *,void *))360 void DiaRedispRoutine(void *vdia, INTBIG item, void (*routine)(RECTAREA*, void*))
361 {
362 	EDialog *dia = (EDialog *)vdia;
363 	dia->redispRoutine(item, routine);
364 }
365 
DiaAllowUserDoubleClick(void * vdia)366 void DiaAllowUserDoubleClick(void *vdia)
367 {
368 	EDialog *dia = (EDialog *)vdia;
369 	dia->allowUserDoubleClick();
370 }
371 
DiaFillPoly(void * vdia,INTBIG item,INTBIG * xv,INTBIG * yv,INTBIG count,INTBIG r,INTBIG g,INTBIG b)372 void DiaFillPoly(void *vdia, INTBIG item, INTBIG *xv, INTBIG *yv, INTBIG count, INTBIG r, INTBIG g, INTBIG b)
373 {
374 	EDialog *dia = (EDialog *)vdia;
375 	dia->fillPoly(item, xv, yv, count, r, g, b);
376 }
377 
DiaDrawRect(void * vdia,INTBIG item,RECTAREA * rect,INTBIG r,INTBIG g,INTBIG b)378 void DiaDrawRect(void *vdia, INTBIG item, RECTAREA *rect, INTBIG r, INTBIG g, INTBIG b)
379 {
380 	EDialog *dia = (EDialog *)vdia;
381 	dia->drawRect(item, rect, r, g, b);
382 }
383 
DiaFrameRect(void * vdia,INTBIG item,RECTAREA * r)384 void DiaFrameRect(void *vdia, INTBIG item, RECTAREA *r)
385 {
386 	EDialog *dia = (EDialog *)vdia;
387 	dia->frameRect(item, r);
388 }
389 
DiaInvertRect(void * vdia,INTBIG item,RECTAREA * r)390 void DiaInvertRect(void *vdia, INTBIG item, RECTAREA *r)
391 {
392 	EDialog *dia= (EDialog *)vdia;
393 	dia->invertRect(item, r);
394 }
395 
DiaDrawLine(void * vdia,INTBIG item,INTBIG fx,INTBIG fy,INTBIG tx,INTBIG ty,INTBIG mode)396 void DiaDrawLine(void *vdia, INTBIG item, INTBIG fx, INTBIG fy, INTBIG tx, INTBIG ty, INTBIG mode)
397 {
398 	EDialog *dia = (EDialog *)vdia;
399 	dia->drawLine(item, fx, fy, tx, ty, mode);
400 }
401 
DiaSetTextSize(void * vdia,INTBIG size)402 void DiaSetTextSize(void *vdia, INTBIG size)
403 {
404 	EDialog *dia = (EDialog *)vdia;
405 	dia->setTextSize(size);
406 }
407 
DiaGetTextInfo(void * vdia,CHAR * msg,INTBIG * wid,INTBIG * hei)408 void DiaGetTextInfo(void *vdia, CHAR *msg, INTBIG *wid, INTBIG *hei)
409 {
410 	EDialog *dia = (EDialog *)vdia;
411 	dia->getTextInfo(msg, wid, hei);
412 }
413 
DiaPutText(void * vdia,INTBIG item,CHAR * msg,INTBIG x,INTBIG y)414 void DiaPutText(void *vdia, INTBIG item, CHAR *msg, INTBIG x, INTBIG y)
415 {
416 	EDialog *dia = (EDialog *)vdia;
417 	dia->putText(item, msg, x, y);
418 }
419 
DiaTrackCursor(void * vdia,void (* eachdown)(INTBIG x,INTBIG y))420 void DiaTrackCursor(void *vdia, void (*eachdown)(INTBIG x, INTBIG y))
421 {
422 	EDialog *dia = (EDialog *)vdia;
423 	dia->trackCursor(eachdown);
424 }
425 
DiaGetMouse(void * vdia,INTBIG * x,INTBIG * y)426 void DiaGetMouse(void *vdia, INTBIG *x, INTBIG *y)
427 {
428 	EDialog *dia = (EDialog *)vdia;
429 	dia->getMouse(x, y);
430 }
431 
432 /****************************** EDialog class ******************************/
433 
EDialog(DIALOG * dialog)434 EDialog::EDialog(DIALOG *dialog )
435     : d(0), itemdesc( dialog )
436 {
437 	/* be sure the dialog is translated */
438 	DiaTranslate( dialog );
439 }
440 
~EDialog()441 EDialog::~EDialog()
442 {
443 	/* remove this from the list of active modal dialogs */
444     if (d->isModal()) gra_firstactivemodaldialog = d->nexttdialog;
445 
446     /* adjust the dialog position if it was moved */
447     QPoint disp = (d->pos() - d->iniPos) * DIALOGDEN / DIALOGNUM;
448     itemdesc->windowRect.left += disp.x();
449     itemdesc->windowRect.right += disp.x();
450     itemdesc->windowRect.top += disp.y();
451     itemdesc->windowRect.bottom += disp.y();
452 
453 	d->dia = 0;
454     d->deleteLater();
455 	gra->toolTimeSlice();
456 }
457 
reset()458 void EDialog::reset()
459 {
460 }
461 
462 /*
463  * Routine to handle actions and return the next item hit.
464  */
nextHit(void)465 INTBIG EDialog::nextHit(void)
466 {
467 #ifdef ETRACE
468 	etrace(GTRACE, "{ DiaNextHit\n");
469 #endif
470 	/* flush the screen */
471 	flushscreen();
472 
473 	while(d->itemHit == -1)
474 	{
475 #if 0
476 		QTimer timer( d );
477 		timer.start( MAXEVENTTIME, TRUE );
478 		qApp->processOneEvent();
479 #else
480 		qApp->processEvents(MAXEVENTTIME);
481 #endif
482 	}
483 	INTBIG item = d->itemHit;
484 	d->itemHit = -1;
485 #ifdef ETRACE
486 	etrace(GTRACE, "} DiaNextHit: item=%d\n", item);
487 #endif
488 	return(item);
489 }
490 
itemHitAction(INTBIG itemHit)491 void EDialog::itemHitAction(INTBIG itemHit)
492 {
493     if (d->itemHit != -1 && d->itemHit != itemHit) ttyputerr(_("Dialog hit lost"));
494     d->itemHit = itemHit;
495 }
496 
showExtension(BOOLEAN showIt)497 void EDialog::showExtension( BOOLEAN showIt )
498 {
499 	if (d->extension())
500 	{
501 		d->showExtension( showIt );
502 		return;
503 	}
504     if (itemdesc->briefHeight == 0) return;
505     if (isExtended == showIt) return;
506     isExtended = showIt;
507     RECTAREA& r = itemdesc->windowRect;
508 	int wid = r.right - r.left;
509 	int hei = (isExtended ? r.bottom  - r.top : itemdesc->briefHeight );
510     d->setFixedSize( d->scaledialogcoordinate(wid), d->scaledialogcoordinate(hei) );
511 }
512 
extension()513 BOOLEAN EDialog::extension()
514 {
515     return isExtended;
516 }
517 
resizeDialog(INTBIG wid,INTBIG hei)518 void EDialog::resizeDialog(INTBIG wid, INTBIG hei)
519 {
520 #ifdef ETRACE
521     etrace(GTRACE, "{ DiaResizeDialog wid=%d hei=%d\n", wid, hei);
522 #endif
523     d->setFixedSize( d->scaledialogcoordinate(wid), d->scaledialogcoordinate(hei) );
524 #ifdef ETRACE
525     etrace(GTRACE, "} DiaResizeDialog\n");
526 #endif
527 }
528 
bringToTop()529 void EDialog::bringToTop()
530 {
531     d->raise();
532 }
533 
534 extern "C" DIALOG us_eprogressdialog, us_progressdialog;
535 
536 /*
537  * Routine to set the text in item "item" to "msg"
538  */
setText(INTBIG item,char * msg)539 void EDialog::setText(INTBIG item, char *msg)
540 {
541 	bool highlight = FALSE;
542 	if (item < 0)
543 	{
544 		item = -item;
545 		highlight = TRUE;
546 	}
547 	item--;
548 	INTBIG type = itemdesc->list[item].type;
549 	QString qmsg = QString::fromLocal8Bit( msg );
550 	switch (type&ITEMTYPE) {
551 	case EDITTEXT: {
552 	    QLineEdit *lineEdit = (QLineEdit*)d->items[item];
553 	    QObject::disconnect(lineEdit,SIGNAL(textChanged(const QString&)),d->mapper,SLOT(map()));
554 	    lineEdit->setText ( qmsg );
555 	    lineEdit->setCursorPosition( lineEdit->text().length() );
556 	    if (highlight) lineEdit->selectAll(); else lineEdit->deselect();
557 	    QObject::connect(lineEdit,SIGNAL(textChanged(const QString&)),d->mapper,SLOT(map()));
558 	}
559 	break;
560 	case MESSAGE: {
561 	  QLabel *label = (QLabel*)d->items[item];
562 	  label->setText( qmsg );
563 	  if (itemdesc == &us_eprogressdialog || itemdesc == &us_progressdialog)
564 		  {
565 			  label->repaint();
566 			  qApp->flush();
567 		  }
568 	}
569 	break;
570 	case BUTTON:
571 	case DEFBUTTON:
572 	case CHECK:
573 	case RADIO: {
574 	  QButton *button = (QButton*)d->items[item];
575 	  button->setText( qmsg );
576 	}
577 	break;
578 	default:
579 	  qDebug("Bad itemtype in DiaSetText %lx", type);
580 	}
581 }
582 
583 /*
584  * Routine to return the text in item "item"
585  */
getText(INTBIG item)586 char *EDialog::getText(INTBIG item)
587 {
588 	item--;
589 	INTBIG type = itemdesc->list[item].type;
590 	switch (type&ITEMTYPE) {
591 	case EDITTEXT: {
592 	    QLineEdit *lineEdit = (QLineEdit*)d->items[item];
593 	    QString qstr = lineEdit->text();
594 	    return d->localize( qstr );
595 	}
596 	break;
597 	case MESSAGE: {
598 	    QLabel *label = (QLabel*)d->items[item];
599 	    return d->localize( label->text() );
600 	}
601 	break;
602 	default:
603 	    qDebug("Bad itemtype in DiaGetText %lx", type);
604 	}
605 	return("");
606 }
607 
608 /*
609  * Routine to set the value in item "item" to "value"
610  */
setControl(INTBIG item,INTBIG value)611 void EDialog::setControl(INTBIG item, INTBIG value)
612 {
613 	item--;
614 	INTBIG type = itemdesc->list[item].type;
615 	switch (type&ITEMTYPE) {
616         case RADIO:
617             {
618                 QRadioButton *radio = (QRadioButton*)d->items[item];
619                 radio->setChecked( value );
620             }
621             break;
622         case CHECK:
623             if ((type&ITEMTYPEEXT) == AUTOCHECK)
624             {
625                 QCheckBox *check = (ECheckField*)d->items[item];
626                 check->setChecked( value );
627             } else
628             {
629                 ECheckField *check = (ECheckField*)d->items[item];
630                 check->setChecked( value );
631             }
632             break;
633         default:
634             qDebug("Bad itemtype in DiaSetControl %lx", type);
635 	}
636 }
637 
638 /*
639  * Routine to return the value in item "item"
640  */
getControl(INTBIG item)641 INTBIG EDialog::getControl(INTBIG item)
642 {
643 	item--;
644 	INTBIG type = itemdesc->list[item].type;
645 	switch (type&ITEMTYPE) {
646         case RADIO:
647             {
648                 QRadioButton *radio = (QRadioButton*)d->items[item];
649                 return(radio->isChecked());
650             }
651             break;
652         case CHECK:
653             if ((type&ITEMTYPEEXT) == AUTOCHECK)
654             {
655                 QCheckBox *check = (ECheckField*)d->items[item];
656                 return(check->isChecked());
657             } else
658             {
659                 ECheckField *check = (ECheckField*)d->items[item];
660                 return(check->isChecked());
661             }
662             break;
663         default:
664             qDebug("Bad itemtype in DiaGetControl %lx", type);
665             return(0);
666 	}
667 }
668 
669 /*
670  * Routine to check item "item" to make sure that there is
671  * text in it.  If so, it returns true.  Otherwise it beeps and returns false.
672  */
validEntry(INTBIG item)673 BOOLEAN EDialog::validEntry(INTBIG item)
674 {
675 	char *msg = getText( item );
676 	while (*msg == ' ' || *msg == '\t') msg++;
677 	if (*msg != 0) return(TRUE);
678 	ttybeep(SOUNDBEEP, TRUE);
679 	return(FALSE);
680 }
681 
682 /*
683  * Routine to dim item "item"
684  */
dimItem(INTBIG item)685 void EDialog::dimItem(INTBIG item)
686 {
687 	item--;
688 	QWidget *widget = d->items[item];
689 	widget->setEnabled( FALSE );
690 }
691 
692 /*
693  * Routine to un-dim item "item"
694  */
unDimItem(INTBIG item)695 void EDialog::unDimItem(INTBIG item)
696 {
697 	item--;
698 	QWidget *widget = d->items[item];
699 	widget->setEnabled( TRUE );
700 }
701 
702 /*
703  * Routine to change item "item" to be a message rather
704  * than editable text
705  */
noEditControl(INTBIG item)706 void EDialog::noEditControl(INTBIG item)
707 {
708 	item--;
709 	INTBIG type = itemdesc->list[item].type;
710 	switch (type&ITEMTYPE) {
711 	case EDITTEXT: {
712 	    QLineEdit *lineEdit = (QLineEdit*)d->items[item];
713 	    lineEdit->setReadOnly( TRUE );
714 	}
715 	break;
716 	default:
717 	    qDebug("Bad itemtype in DiaNoEditControl %lx", type);
718 	}
719 }
720 
721 /*
722  * Routine to change item "item" to be editable text rather
723  * than a message
724  */
editControl(INTBIG item)725 void EDialog::editControl(INTBIG item)
726 {
727 	item--;
728 	INTBIG type = itemdesc->list[item].type;
729 	switch (type&ITEMTYPE) {
730 	case EDITTEXT: {
731 	    QLineEdit *lineEdit = (QLineEdit*)d->items[item];
732 	    lineEdit->setReadOnly( FALSE );
733 	}
734 	break;
735 	default:
736 	    qDebug("Bad itemtype in DiaEditControl %lx", type);
737 	}
738 }
739 
opaqueEdit(INTBIG item)740 void EDialog::opaqueEdit(INTBIG item)
741 {
742 	item--;
743 	INTBIG type = itemdesc->list[item].type;
744 	switch (type&ITEMTYPE) {
745 	case EDITTEXT: {
746 	    QLineEdit *lineEdit = (QLineEdit*)d->items[item];
747 	    lineEdit->setEchoMode( QLineEdit::Password );
748 	}
749 	break;
750 	default:
751 	    qDebug("Bad itemtype in DiaOpaqueText %lx", type);
752 	}
753 }
754 
755 /*
756  * Routine to cause item "item" to be the default button
757  */
defaultButton(INTBIG item)758 void EDialog::defaultButton(INTBIG item)
759 {
760 //	qDebug("DiaDefaultButton %d", item);
761 	item--;
762 	INTBIG type = itemdesc->list[item].type;
763 	switch (type&ITEMTYPE) {
764 	case BUTTON:
765 	case DEFBUTTON: {
766 	    QPushButton *button = (QPushButton*)d->items[item];
767 	    button->setDefault( TRUE );
768 //	    button->setFocus();
769 	}
770 	break;
771 	default:
772 	    qDebug("Bad itemtype in DiaDefaultButton %lx", type);
773 	}
774 }
775 
changeIcon(INTBIG item,UCHAR1 * addr)776 void EDialog::changeIcon(INTBIG item, UCHAR1 *addr)
777 {
778 	item--;
779 	INTBIG type = itemdesc->list[item].type;
780 	switch (type&ITEMTYPE) {
781 	case ICON: {
782 	    EIconField *icon = (EIconField*)d->items[item];
783 	    itemdesc->list[item].data = (INTBIG)addr;
784 	    icon->setBits( addr );
785 	}
786 	break;
787 	default:
788 	    qDebug("Bad itemtype in DiaChangeIcon %lx", type);
789 	}
790 }
791 
792 /*
793  * Routine to change item "item" into a popup with "count" entries
794  * in "names".
795  */
setPopup(INTBIG item,INTBIG count,char ** names)796 void EDialog::setPopup(INTBIG item, INTBIG count, char **names)
797 {
798 	item--;
799 	INTBIG type = itemdesc->list[item].type;
800 	switch (type&ITEMTYPE) {
801 	case POPUP: {
802 	    QComboBox *comboBox = (QComboBox*)d->items[item];
803 	    comboBox->clear();
804 	    for (int i = 0; i < count; i++) {
805 	        comboBox->insertItem( QString::fromLocal8Bit( names[i] ), i );
806 	    }
807 	}
808 	break;
809 	default:
810 	    qDebug("Bad itemtype in DiaSetPopup %lx", type);
811 	}
812 }
813 
814 /*
815  * Routine to change popup item "item" so that the current entry is "entry".
816  */
setPopupEntry(INTBIG item,INTBIG entry)817 void EDialog::setPopupEntry(INTBIG item, INTBIG entry)
818 {
819 	item--;
820 	INTBIG type = itemdesc->list[item].type;
821 	switch (type&ITEMTYPE) {
822 	case POPUP: {
823 	    QComboBox *comboBox = (QComboBox*)d->items[item];
824 	    comboBox->setCurrentItem( entry );
825 	}
826 	break;
827 	default:
828 	    qDebug("Bad itemtype in DiaSetPopupEntry %lx", type);
829 	}
830 }
831 
832 /*
833  * Routine to return the current item in popup menu item "item".
834  */
getPopupEntry(INTBIG item)835 INTBIG EDialog::getPopupEntry(INTBIG item)
836 {
837 	item--;
838 	INTBIG type = itemdesc->list[item].type;
839 	switch (type&ITEMTYPE) {
840 	case POPUP: {
841 	    QComboBox *comboBox = (QComboBox*)d->items[item];
842 	    return comboBox->currentItem();
843 	}
844 	break;
845 	default:
846 	    qDebug("Bad itemtype in DiaSetPopup %lx", type);
847 	}
848 	return(0);
849 }
850 
initTextDialog(INTBIG item,BOOLEAN (* toplist)(char **),char * (* nextinlist)(void),void (* donelist)(void),INTBIG sortpos,INTBIG flags)851 void EDialog::initTextDialog(INTBIG item, BOOLEAN (*toplist)(char **), char *(*nextinlist)(void),
852 	void (*donelist)(void), INTBIG sortpos, INTBIG flags)
853 {
854 	item--;
855 	EScrollField *scroll = (EScrollField*)d->items[item];
856 	if ((flags&SCDOUBLEQUIT) != 0)
857 	{
858 		INTBIG type0 = itemdesc->list[0].type&ITEMTYPE;
859 		Q_ASSERT( type0 == DEFBUTTON || type0 == BUTTON );
860 		QPushButton *button0 = (QPushButton*)d->items[0];
861 		d->connect(scroll,SIGNAL(doubleClicked(QListBoxItem*)),button0,SLOT(animateClick()));
862 	}
863 	if ((flags&SCFIXEDWIDTH) != 0) {
864 	    QFont fixedfont( QString::null );
865 	    fixedfont.setStyleHint( QFont::TypeWriter );
866 	    fixedfont.setFixedPitch( TRUE );
867 	    scroll->setFont( fixedfont );
868 	}
869 	loadTextDialog( item+1, toplist, nextinlist, donelist, sortpos);
870 }
871 
loadTextDialog(INTBIG item,BOOLEAN (* toplist)(char **),char * (* nextinlist)(void),void (* donelist)(void),INTBIG sortpos)872 void EDialog::loadTextDialog(INTBIG item, BOOLEAN (*toplist)(char **), char *(*nextinlist)(void),
873 	void (*donelist)(void), INTBIG sortpos)
874 {
875 	INTBIG i, it;
876 	char *next, **list, line[256];
877 	QString qstr;
878 
879 	item--;
880 	EScrollField *scroll = (EScrollField*)d->items[item];
881 
882 	scroll->blockSignals( TRUE );
883 
884 	/* clear the list */
885 	scroll->clear();
886 
887 	if (sortpos < 0)
888 	{
889 		/* unsorted: load the list directly */
890 		line[0] = 0;
891 		next = line;
892 		(void)(*toplist)(&next);
893 		for(it=0; ; it++)
894 		{
895 			next = (*nextinlist)();
896 			if (next == 0) break;
897 			qstr = QString::fromLocal8Bit( next );
898 			scroll->insertItem( qstr );
899 		}
900 		(*donelist)();
901 	} else
902 	{
903 		/* count the number of items to be put in the text editor */
904 		line[0] = 0;
905 		next = line;
906 		(void)(*toplist)(&next);
907 		for(it=0; ; it++) if ((*nextinlist)() == 0) break;
908 		(*donelist)();
909 
910 		/* allocate space for the strings */
911 		list = 0;
912 		if (it > 0)
913 		{
914 			list = (char **)emalloc(it * (sizeof (char *)), el_tempcluster);
915 			if (list == 0) return;
916 		}
917 
918 		/* get the list */
919 		line[0] = 0;
920 		next = line;
921 		(void)(*toplist)(&next);
922 		for(i=0; i<it; i++)
923 		{
924 			next = (*nextinlist)();
925 			if (next == 0) next = "???";
926 			list[i] = (char *)emalloc(strlen(next)+1, el_tempcluster);
927 			if (list[i] == 0) return;
928 			strcpy(list[i], next);
929 		}
930 		(*donelist)();
931 
932 		/* sort the list */
933 		gra_dialogstringpos = sortpos;
934 		esort(list, it, sizeof (char *), gra_stringposascending);
935 
936 		/* stuff the list into the text editor */
937 		for(i=0; i<it; i++)
938 		{
939 			qstr = QString::fromLocal8Bit( list[i] );
940 			scroll->insertItem( qstr );
941 		}
942 
943 		/* deallocate the list */
944 		if (it > 0)
945 		{
946 			for(i=0; i<it; i++) efree((char *)list[i]);
947 			efree((char *)(char *)list);
948 		}
949 	}
950 	if (it > 0) scroll->setSelected( 0, TRUE );
951 
952 	scroll->blockSignals( FALSE );
953 }
954 
955 /*
956  * Routine to stuff line "line" at the end of the edit buffer.
957  */
stuffLine(INTBIG item,char * line)958 void EDialog::stuffLine(INTBIG item, char *line)
959 {
960 	item--;
961 	EScrollField *scroll = (EScrollField*)d->items[item];
962 	QString qstr = QString::fromLocal8Bit( line );
963 	scroll->blockSignals( TRUE );
964 	scroll->insertItem( qstr );
965 	scroll->blockSignals( FALSE );
966 }
967 
968 /*
969  * Routine to select line "line" of scroll item "item".
970  */
selectLine(INTBIG item,INTBIG line)971 void EDialog::selectLine(INTBIG item, INTBIG line)
972 {
973 	item--;
974 	EScrollField *scroll = (EScrollField*)d->items[item];
975 	scroll->blockSignals( TRUE );
976 	if (line < 0) scroll->clearSelection(); else scroll->setSelected( line, TRUE );
977 	scroll->blockSignals( FALSE );
978 
979 	/* make sure lines are visible */
980 	int first = scroll->topItem();
981 	int visible = scroll->numItemsVisible();
982 	if (line < first || line >= first+visible-1) {
983 		first = QMAX( line - visible/2 , 0);
984 		scroll->setTopItem( first );
985 	}
986 }
987 
988 /*
989  * Routine to select "count" lines in "lines" of scroll item "item".
990  */
selectLines(INTBIG item,INTBIG count,INTBIG * lines)991 void EDialog::selectLines(INTBIG item, INTBIG count, INTBIG *lines)
992 {
993 	item--;
994 	EScrollField *scroll = (EScrollField*)d->items[item];
995 	scroll->blockSignals( TRUE );
996 	scroll->clearSelection();
997 	int low=0, high=0;
998 	for(int i=0; i<count; i++)
999 	{
1000 		int line = lines[i];
1001 		scroll->setSelected( i, TRUE );
1002 		if (i == 0) low = high = line; else
1003 		{
1004 			if (line < low) low = line;
1005 			if (line > high) high = line;
1006 		}
1007 	}
1008 	scroll->blockSignals( FALSE );
1009 
1010 	/* make sure lines are visible */
1011 	int first = scroll->topItem();
1012 	int visible = scroll->numItemsVisible();
1013 	if (high < first || low >= first+visible) scroll->setTopItem( low );
1014 }
1015 
1016 /*
1017  * Returns the currently selected line in the scroll list "item".
1018  */
getCurLine(INTBIG item)1019 INTBIG EDialog::getCurLine(INTBIG item)
1020 {
1021 	item--;
1022 	EScrollField *scroll = (EScrollField*)d->items[item];
1023 	int selected = scroll->currentItem();
1024 	return(selected);
1025 }
1026 
1027 /*
1028  * Returns the currently selected lines in the scroll list "item".  The returned
1029  * array is terminated with -1.
1030  */
getCurLines(INTBIG item)1031 INTBIG *EDialog::getCurLines(INTBIG item)
1032 {
1033 	static INTBIG selected[MAXSCROLLMULTISELECT];
1034 
1035 	item--;
1036 	EScrollField *scroll = (EScrollField*)d->items[item];
1037 	int count = 0;
1038 	for (uint i = 0; i < scroll->count(); i++) {
1039 	  if (scroll->isSelected( i ) && count < MAXSCROLLMULTISELECT - 1) {
1040 	    selected[count] = i;
1041 	    count++;
1042 	  }
1043 	}
1044 	selected[count] = -1;
1045 	return(selected);
1046 }
1047 
1048 /*
1049  * Returns the number of lines in the scroll list "item".
1050  */
getNumScrollLines(INTBIG item)1051 INTBIG EDialog::getNumScrollLines(INTBIG item)
1052 {
1053 	item--;
1054 	EScrollField *scroll = (EScrollField*)d->items[item];
1055 	return(scroll->count());
1056 }
1057 
getScrollLine(INTBIG item,INTBIG line)1058 char *EDialog::getScrollLine(INTBIG item, INTBIG line)
1059 {
1060 	item--;
1061 	EScrollField *scroll = (EScrollField*)d->items[item];
1062 	return d->localize( scroll->text( line ) );
1063 }
1064 
setScrollLine(INTBIG item,INTBIG line,char * msg)1065 void EDialog::setScrollLine(INTBIG item, INTBIG line, char *msg)
1066 {
1067 	item--;
1068 	EScrollField *scroll = (EScrollField*)d->items[item];
1069 	QString qmsg = QString::fromLocal8Bit( msg );
1070 	scroll->blockSignals( TRUE );
1071 	scroll->changeItem( qmsg, line );
1072 	scroll->blockSignals( FALSE );
1073 }
1074 
synchVScrolls(INTBIG item1,INTBIG item2,INTBIG item3)1075 void EDialog::synchVScrolls(INTBIG item1, INTBIG item2, INTBIG item3)
1076 {
1077 	if (item1 <= 0 || item1 > itemdesc->items) return;
1078 	if (item2 <= 0 || item2 > itemdesc->items) return;
1079 	if (item3 < 0 || item3 > itemdesc->items) return;
1080 	if (d->numlocks >= MAXLOCKS) return;
1081 	d->lock1[d->numlocks] = ((EScrollField*)d->items[item1 - 1])->verticalScrollBar();
1082 	d->lock2[d->numlocks] = ((EScrollField*)d->items[item2 - 1])->verticalScrollBar();
1083 	d->lock3[d->numlocks] = item3 > 0 ? ((EScrollField*)d->items[item3 - 1])->verticalScrollBar() : 0;
1084 
1085 	QObject::connect(d->lock1[d->numlocks],SIGNAL(valueChanged(int)), d->lock2[d->numlocks],SLOT(setValue(int)));
1086 	if(d->lock3[d->numlocks])
1087 	{
1088 		QObject::connect(d->lock2[d->numlocks],SIGNAL(valueChanged(int)), d->lock3[d->numlocks],SLOT(setValue(int)));
1089 		QObject::connect(d->lock3[d->numlocks],SIGNAL(valueChanged(int)), d->lock1[d->numlocks],SLOT(setValue(int)));
1090 	} else
1091 	{
1092 		QObject::connect(d->lock2[d->numlocks],SIGNAL(valueChanged(int)), d->lock1[d->numlocks],SLOT(setValue(int)));
1093 	}
1094 	d->numlocks++;
1095 }
1096 
unSynchVScrolls(void)1097 void EDialog::unSynchVScrolls(void)
1098 {
1099 	while (d->numlocks > 0) {
1100 		d->numlocks--;
1101 
1102 		QObject::disconnect(d->lock1[d->numlocks],SIGNAL(valueChanged(int)), d->lock2[d->numlocks],SLOT(setValue(int)));
1103 		if(d->lock3[d->numlocks])
1104 		{
1105 			QObject::disconnect(d->lock2[d->numlocks],SIGNAL(valueChanged(int)), d->lock3[d->numlocks],SLOT(setValue(int)));
1106 			QObject::disconnect(d->lock3[d->numlocks],SIGNAL(valueChanged(int)), d->lock1[d->numlocks],SLOT(setValue(int)));
1107 		} else
1108 		{
1109 			QObject::disconnect(d->lock2[d->numlocks],SIGNAL(valueChanged(int)), d->lock1[d->numlocks],SLOT(setValue(int)));
1110 		}
1111 	}
1112 }
1113 
itemRect(INTBIG item,RECTAREA * rect)1114 void EDialog::itemRect(INTBIG item, RECTAREA *rect)
1115 {
1116 	item--;
1117 	if (item < 0 || item >= itemdesc->items) return;
1118 	rect->left = itemdesc->list[item].r.left+1;
1119 	rect->right = itemdesc->list[item].r.right-1;
1120 	rect->top = itemdesc->list[item].r.top+1;
1121 	rect->bottom = itemdesc->list[item].r.bottom-1;
1122 }
1123 
percent(INTBIG item,INTBIG percent)1124 void EDialog::percent(INTBIG item, INTBIG percent)
1125 {
1126 	item--;
1127 	QProgressBar *progress = (QProgressBar*)d->items[item];
1128 	progress->setProgress( percent );
1129 	qApp->flush();
1130 }
1131 
redispRoutine(INTBIG item,void (* routine)(RECTAREA * rect,void * dia))1132 void EDialog::redispRoutine(INTBIG item, void (*routine)(RECTAREA *rect, void *dia))
1133 {
1134     item--;
1135     Q_ASSERT( (itemdesc->list[item].type&ITEMTYPE) == USERDRAWN );
1136     EUserDrawnField *user = (EUserDrawnField*)d->items[item];
1137     user->redispRoutine = routine;
1138 	user->dia = this;
1139 }
1140 
allowUserDoubleClick(void)1141 void EDialog::allowUserDoubleClick(void)
1142 {
1143 	INTBIG type0 = itemdesc->list[0].type&ITEMTYPE;
1144 	Q_ASSERT( type0 == DEFBUTTON || type0 == BUTTON );
1145 	QPushButton *button0 = (QPushButton*)d->items[0];
1146 
1147 	for( int i=0; i<itemdesc->items; i++)
1148 	{
1149 		if((itemdesc->list[i].type&ITEMTYPE) == USERDRAWN)
1150 		{
1151 			EUserDrawnField *user = (EUserDrawnField*)d->items[i];
1152 			user->doubleClickAllowed = TRUE;
1153 			QObject::connect(user,SIGNAL(doubleClicked()),button0,SLOT(animateClick()));
1154 		}
1155 	}
1156 }
1157 
fillPoly(INTBIG item,INTBIG * xv,INTBIG * yv,INTBIG count,INTBIG r,INTBIG g,INTBIG b)1158 void EDialog::fillPoly(INTBIG item, INTBIG *xv, INTBIG *yv, INTBIG count, INTBIG r, INTBIG g, INTBIG b)
1159 {
1160     item--;
1161     Q_ASSERT( (itemdesc->list[item].type&ITEMTYPE) == USERDRAWN );
1162     int xoff = itemdesc->list[item].r.left;
1163     int yoff = itemdesc->list[item].r.top;
1164     QPainter p( d->items[item] );
1165     QPointArray pointlist( count );
1166     for( int i=0; i<count; i++ ) {
1167         pointlist.setPoint( i, d->scaledialogcoordinate(xv[i]-xoff) ,
1168 			       d->scaledialogcoordinate(yv[i]-yoff) );
1169     }
1170     p.setPen( Qt::NoPen );
1171     p.setBrush( QColor( r, g, b ) );
1172     p.drawPolygon( pointlist );
1173 }
1174 
drawRect(INTBIG item,RECTAREA * rect,INTBIG r,INTBIG g,INTBIG b)1175 void EDialog::drawRect(INTBIG item, RECTAREA *rect, INTBIG r, INTBIG g, INTBIG b)
1176 {
1177     item--;
1178     Q_ASSERT( (itemdesc->list[item].type&ITEMTYPE) == USERDRAWN );
1179     int xoff = itemdesc->list[item].r.left;
1180     int yoff = itemdesc->list[item].r.top;
1181     QPainter p( d->items[item] );
1182     int x1 = d->scaledialogcoordinate(rect->left-xoff);
1183     int y1 = d->scaledialogcoordinate(rect->top-yoff);
1184     int x2 = d->scaledialogcoordinate(rect->right-xoff);
1185     int y2 = d->scaledialogcoordinate(rect->bottom-yoff);
1186     p.setPen( Qt::NoPen );
1187     p.setBrush( QColor( r, g, b ) );
1188     p.drawRect( x1, y1, x2 - x1, y2 - y1 );
1189 }
1190 
frameRect(INTBIG item,RECTAREA * r)1191 void EDialog::frameRect(INTBIG item, RECTAREA *r)
1192 {
1193     item--;
1194     Q_ASSERT( (itemdesc->list[item].type&ITEMTYPE) == USERDRAWN );
1195     int xoff = itemdesc->list[item].r.left;
1196     int yoff = itemdesc->list[item].r.top;
1197     QPainter p( d->items[item] );
1198     int x1 = d->scaledialogcoordinate(r->left-xoff);
1199     int y1 = d->scaledialogcoordinate(r->top-yoff);
1200     int x2 = d->scaledialogcoordinate(r->right-xoff);
1201     int y2 = d->scaledialogcoordinate(r->bottom-yoff);
1202     p.setPen( Qt::black );
1203     p.setBrush( Qt::white );
1204     p.drawRect( x1, y1, x2 - x1, y2 - y1 );
1205 }
1206 
invertRect(INTBIG item,RECTAREA * r)1207 void EDialog::invertRect(INTBIG item, RECTAREA *r)
1208 {
1209     item--;
1210     Q_ASSERT( (itemdesc->list[item].type&ITEMTYPE) == USERDRAWN );
1211     int xoff = itemdesc->list[item].r.left;
1212     int yoff = itemdesc->list[item].r.top;
1213     QPainter p( d->items[item] );
1214     int x1 = d->scaledialogcoordinate(r->left-xoff);
1215     int y1 = d->scaledialogcoordinate(r->top-yoff);
1216     int x2 = d->scaledialogcoordinate(r->right-xoff);
1217     int y2 = d->scaledialogcoordinate(r->bottom-yoff);
1218     p.setRasterOp( Qt::NotROP );
1219     p.drawRect( x1, y1, x2 - x1, y2 - y1 );
1220 }
1221 
drawLine(INTBIG item,INTBIG fx,INTBIG fy,INTBIG tx,INTBIG ty,INTBIG mode)1222 void EDialog::drawLine(INTBIG item, INTBIG fx, INTBIG fy, INTBIG tx, INTBIG ty, INTBIG mode)
1223 {
1224     item--;
1225     Q_ASSERT( (itemdesc->list[item].type&ITEMTYPE) == USERDRAWN );
1226     int xoff = itemdesc->list[item].r.left;
1227     int yoff = itemdesc->list[item].r.top;
1228     QPainter p( d->items[item] );
1229     int x1 = d->scaledialogcoordinate(fx-xoff);
1230     int y1 = d->scaledialogcoordinate(fy-yoff);
1231     int x2 = d->scaledialogcoordinate(tx-xoff);
1232     int y2 = d->scaledialogcoordinate(ty-yoff);
1233     switch( mode ) {
1234     case DLMODEON:
1235         p.setPen( Qt::black );
1236 	break;
1237     case DLMODEOFF:
1238         p.setPen( Qt::white );
1239 	break;
1240     case DLMODEINVERT:
1241         p.setRasterOp( Qt::NotROP );
1242 	break;
1243     }
1244     p.drawLine( x1, y1, x2, y2 );
1245 }
1246 
setTextSize(INTBIG size)1247 void EDialog::setTextSize(INTBIG size)
1248 {
1249     d->userFont.setPixelSize( size );
1250 }
1251 
getTextInfo(char * msg,INTBIG * wid,INTBIG * hei)1252 void EDialog::getTextInfo(char *msg, INTBIG *wid, INTBIG *hei)
1253 {
1254     QPainter p( d );
1255     p.setFont( d->userFont );
1256     QSize size = p.fontMetrics().boundingRect( QString::fromLocal8Bit( msg ) ).size();
1257     size = size * DIALOGDEN / DIALOGNUM;
1258     *wid = size.width();
1259     *hei = size.height();
1260 }
1261 
putText(INTBIG item,char * msg,INTBIG x,INTBIG y)1262 void EDialog::putText(INTBIG item, char *msg, INTBIG x, INTBIG y)
1263 {
1264     item--;
1265     Q_ASSERT( (itemdesc->list[item].type&ITEMTYPE) == USERDRAWN );
1266     int xoff = itemdesc->list[item].r.left;
1267     int yoff = itemdesc->list[item].r.top;
1268     QPainter p( d->items[item] );
1269     int x1 = d->scaledialogcoordinate(x-xoff);
1270     int y1 = d->scaledialogcoordinate(y-yoff);
1271     p.setPen( Qt::black );
1272     p.setFont( d->userFont );
1273     p.drawText( x1, y1 + p.fontMetrics().ascent(), QString::fromLocal8Bit( msg ) );
1274 }
1275 
trackCursor(void (* eachdown)(INTBIG x,INTBIG y))1276 void EDialog::trackCursor(void (*eachdown)(INTBIG x, INTBIG y))
1277 {
1278     /* find user defined field which grab mouse */
1279     EUserDrawnField *user = 0;
1280     for( int i=0; i<itemdesc->items && user == 0; i++ ) {
1281         if ((itemdesc->list[i].type&ITEMTYPE) != USERDRAWN) continue;
1282 		user = (EUserDrawnField*)d->items[i];
1283 		if (!user->buttonPressed) user = 0;
1284     }
1285     if (user) {
1286         user->eachdown = eachdown;
1287         qApp->enter_loop();
1288         Q_ASSERT( user->eachdown == 0 );
1289     }
1290 }
1291 
getMouse(INTBIG * x,INTBIG * y)1292 void EDialog::getMouse(INTBIG *x, INTBIG *y)
1293 {
1294     QPoint pos = d->mapFromGlobal( QCursor::pos() ) * DIALOGDEN / DIALOGNUM;
1295     *x = pos.x();
1296     *y = pos.y();
1297 }
1298 
itemNamesFromUi(char * uiFile,BOOLEAN ext)1299 QStrList *EDialog::itemNamesFromUi( char *uiFile, BOOLEAN ext )
1300 {
1301 #ifdef QTSTRETCH
1302     EDialogPrivate *d = EDialogPrivate::loadUi( 0, uiFile, ext );
1303     if (d == 0) return 0;
1304 	/* load the items */
1305     QStrList *slist = new QStrList( TRUE );
1306     slist->setAutoDelete( TRUE );
1307     QObjectList ol ( *d->children() );
1308     QCString name;
1309 	for(uint li = 0; li < ol.count(); li++)
1310 	{
1311         if (!ol.at(li)->isWidgetType()) continue;
1312         QWidget *widget = (QWidget*)ol.at(li);
1313         slist->append( widget->name() );
1314 	}
1315     return slist;
1316 #else
1317 	Q_UNUSED( uiFile );
1318 	Q_UNUSED( ext );
1319     return 0;
1320 #endif
1321 }
1322 
EDialogModal(DIALOG * dialog)1323 EDialogModal::EDialogModal( DIALOG *dialog )
1324 	: EDialog( dialog ), in_loop(FALSE), result(Rejected)
1325 {
1326 	QWidget *base=0;
1327 
1328 	/* make the dialog structure */
1329 	if (gra_firstactivemodaldialog != 0) base = gra_firstactivemodaldialog;
1330 #ifndef MACOSX
1331 	else if (el_curwindowpart == NOWINDOWPART) base = qApp->mainWidget(); else
1332 		base = ((QWidget*)el_curwindowpart->frame->draw)->parentWidget();
1333 #endif
1334 
1335     d = new EDialogPrivate( base, itemDesc()->movable );
1336     d->init( this, TRUE );
1337 
1338 	/* add this to the list of active dialogs */
1339     d->nexttdialog = gra_firstactivemodaldialog;
1340     gra_firstactivemodaldialog = d;
1341 	d->showMe();
1342 }
1343 
exec()1344 EDialogModal::DialogCode EDialogModal::exec()
1345 {
1346     ttyputerr(_("exec() is not implemented"));
1347     return Rejected;
1348 }
1349 
1350 #ifdef QTSTRETCH
EWidgetFactory()1351 EWidgetFactory::EWidgetFactory()
1352     : QWidgetFactory()
1353 {
1354 }
1355 
createWidget(const QString & className,QWidget * parent,const char * name) const1356 QWidget* EWidgetFactory::createWidget( const QString& className, QWidget *parent, const char *name) const
1357 {
1358     if (className == "EScrollField") return new EScrollField( parent );
1359     if (className == "EDialogPrivate") return new EDialogPrivate( parent, name );
1360     QCString s = className.latin1();
1361     printf("createWidget %s\n", (const char*)s);
1362     return 0;
1363 }
1364 
1365 EWidgetFactory *widgetFactory = 0;
1366 
loadUi(QWidget * parent,char * uiFile,bool ext)1367 EDialogPrivate *EDialogPrivate::loadUi( QWidget *parent, char *uiFile, bool ext )
1368 {
1369     if (widgetFactory == 0)
1370     {
1371         widgetFactory = new EWidgetFactory();
1372         QWidgetFactory::addWidgetFactory( widgetFactory );
1373     }
1374 
1375     void *infstr = initinfstr();
1376     formatinfstr(infstr, "%sui/%s%s.ui", el_libdir, uiFile, (ext ? "_ext" : "") );
1377     return (EDialogPrivate*)QWidgetFactory::create(returninfstr(infstr), 0, parent );
1378 }
1379 #endif
1380 
EDialogModeless(DIALOG * dialog)1381 EDialogModeless::EDialogModeless( DIALOG *dialog )
1382     : EDialog( dialog )
1383 {
1384 	/* make the dialog structure */
1385 #  ifdef QTSTRETCH
1386     if (dialog->uiFile != 0)
1387     {
1388         d = EDialogPrivate::loadUi( qApp->mainWidget(), dialog->uiFile );
1389         if (d != 0)
1390         {
1391             d->dia = this;
1392 			if (dialog->briefHeight != 0)
1393 			{
1394 				EDialogPrivate *ext = EDialogPrivate::loadUi( d, dialog->uiFile, TRUE );
1395 				if (ext != 0)
1396 				{
1397 					d->setExtension( ext );
1398 					d->setOrientation( Qt::Vertical );
1399 				} else
1400 				{
1401 					delete d;
1402 					d = 0;
1403 				}
1404 			}
1405         }
1406 		if (d != 0)
1407 		{
1408             if (d->checkChildren()) return;
1409             delete d;
1410 		}
1411     }
1412 #  endif
1413     d = new EDialogPrivate( qApp->mainWidget(), itemDesc()->movable );
1414     d->init( this, FALSE );
1415 
1416 	/* add this to the list of modeless dialogs */
1417     d->nexttdialog = gra_firstmodelessdialog;
1418     gra_firstmodelessdialog = d;
1419 
1420 }
1421 
DiaCloseAllModeless()1422 void DiaCloseAllModeless()
1423 {
1424     EDialogPrivate *p;
1425 
1426     for (p = gra_firstmodelessdialog; p != 0; p = p->nexttdialog)
1427     {
1428         EDialogModeless *dia = (EDialogModeless*)p->dia;
1429         dia->hide();
1430         dia->reset();
1431     }
1432 }
1433 
show()1434 void EDialogModeless::show()
1435 {
1436     d->show();
1437     d->raise();
1438 }
1439 
hide()1440 void EDialogModeless::hide()
1441 {
1442     d->hide();
1443 	gra->toolTimeSlice();
1444 }
1445 
isHidden()1446 bool EDialogModeless::isHidden()
1447 {
1448     return d->isHidden();
1449 }
1450 
EDialogPrivate(QWidget * parent,const char * name)1451 EDialogPrivate::EDialogPrivate(QWidget *parent, const char *name )
1452     : QDialog( parent, name ),
1453       numlocks( 0 ), mapper( 0 ), dia( 0 ), nexttdialog( 0 ), itemHit( -1 )
1454 {
1455 }
1456 
~EDialogPrivate()1457 EDialogPrivate::~EDialogPrivate()
1458 {
1459 #ifdef DOUBLESELECT
1460 	gra->activationChange();
1461 #endif
1462 }
1463 
init(EDialog * dia,bool modal)1464 void EDialogPrivate::init( EDialog *dia, bool modal )
1465 {
1466 	INTBIG i, j, itemtype, x, y, wid, hei;
1467     DIALOG *dialog = dia->itemDesc();
1468 
1469     EDialogPrivate::dia = dia;
1470     if (modal) setWFlags(WShowModal);
1471 
1472 	getdialogcoordinates(&dialog->windowRect, &x, &y, &wid, &hei);
1473     if (dialog->briefHeight != 0)
1474         hei = scaledialogcoordinate( dialog->briefHeight );
1475     setFixedSize( wid, hei );
1476     move( x, y );
1477 	setCaption( QString::fromLocal8Bit( dialog->movable ) );
1478 
1479 	/* load the items */
1480 	mapper = new QSignalMapper( this, "mapper");
1481 	connect(mapper,SIGNAL(mapped(int)),this,SLOT(action(int)));
1482 	QWidget *focus = 0;
1483 	QPushButton *defbutton = 0;
1484 	QPushButton *buttonzero = 0;
1485 	for(i=0; i<dialog->items; i++)
1486 	{
1487 		getdialogcoordinates(&dialog->list[i].r, &x, &y, &wid, &hei);
1488 		itemtype = dialog->list[i].type;
1489 		QString unimsg = QString::fromLocal8Bit( dialog->list[i].msg );
1490 		QWidget *widget = 0;
1491 		QPushButton *button;
1492 		ECheckField *check;
1493         QCheckBox *autocheck;
1494 		QRadioButton *radio;
1495 		QProgressBar *progress;
1496 		QLineEdit *lineEdit;
1497 		QLabel *label;
1498 		QComboBox *comboBox;
1499 		EUserDrawnField *user;
1500 
1501 		switch (itemtype&ITEMTYPE)
1502 		{
1503 			case BUTTON:
1504 			case DEFBUTTON:
1505                 widget = button = new QPushButton(unimsg, this);
1506 				connect(button,SIGNAL(clicked()),mapper,SLOT(map()));
1507 				if (i == 0) buttonzero = button;
1508 				if ((itemtype&ITEMTYPE) == DEFBUTTON) defbutton = button;
1509 				break;
1510 			case CHECK:
1511                 if ((itemtype&ITEMTYPEEXT) == AUTOCHECK)
1512                 {
1513                     widget = autocheck = new QCheckBox(unimsg, this );
1514                     connect(autocheck,SIGNAL(clicked()),mapper,SLOT(map()));
1515                 } else
1516                 {
1517                     widget = check = new ECheckField(unimsg, this );
1518                     connect(check,SIGNAL(clicked()),mapper,SLOT(map()));
1519                 }
1520 				break;
1521 			case RADIO:
1522 				widget = radio = new QRadioButton(unimsg, this );
1523 				connect(radio,SIGNAL(clicked()),mapper,SLOT(map()));
1524                 if ((itemtype&ITEMTYPEEXT) != RADIO)
1525                 {
1526                     /* Radio-button group */
1527                     int exttype = itemtype&ITEMTYPEEXT;
1528                     /* check if this is the last button in the group */
1529                     for (j = i + 1; j < dialog->items; j++)
1530                         if ((dialog->list[j].type&ITEMTYPEEXT) == exttype) break;
1531                     if (j == dialog->items)
1532                     {
1533                         /* last button, hence make the group */
1534                         QButtonGroup *group = new QButtonGroup(this);
1535                         for (j = 0; j < i; j++)
1536                         {
1537                             if ((dialog->list[j].type&ITEMTYPEEXT) == exttype)
1538                                 group->insert( (QRadioButton*)( items[j] ) );
1539                         }
1540                         group->insert( radio );
1541                         group->hide();
1542                     }
1543                 }
1544 				break;
1545 			case EDITTEXT:
1546 				widget = lineEdit = new QLineEdit( this );
1547 #if 1
1548 				widget->installEventFilter( this );
1549 #endif
1550 				connect(lineEdit,SIGNAL(textChanged(const QString&)),mapper,SLOT(map()));
1551 				if (focus == 0) focus = lineEdit;
1552 				break;
1553 			case MESSAGE:
1554 				widget = label = new QLabel( unimsg, this );
1555                 label->setAlignment( AlignAuto | AlignTop | ExpandTabs | WordBreak | BreakAnywhere);
1556 				break;
1557 			case PROGRESS:
1558 				widget = progress = new QProgressBar( 100, this );
1559 				break;
1560 			case DIVIDELINE:
1561 				widget = new QWidget( this );
1562 				widget->setBackgroundMode( PaletteForeground );
1563 				break;
1564 			case USERDRAWN:
1565 				widget = user = new EUserDrawnField ( this, &dialog->list[i] );
1566 				user->dia = dia;
1567 				connect(user,SIGNAL(clicked()),mapper,SLOT(map()));
1568 				break;
1569 			case POPUP:
1570 				widget = comboBox = new QComboBox( this );
1571 				connect(comboBox,SIGNAL(activated(int)),mapper,SLOT(map()));
1572 				break;
1573 			case ICON:
1574 				{
1575 					dialog->list[i].data = (INTBIG)dialog->list[i].msg;
1576 					EIconField *icon = new EIconField( this, &dialog->list[i] );
1577 					widget = icon;
1578 					if ((itemtype&INACTIVE) == 0)
1579 					{
1580 						connect(icon, SIGNAL(clicked()), mapper, SLOT(map()));
1581 					}
1582 				}
1583 				break;
1584 			case SCROLL:
1585 			case SCROLLMULTI:
1586 				{
1587 			        EScrollField *scroll;
1588 					widget = scroll = new EScrollField( this );
1589 					connect(scroll,SIGNAL(selectionChanged()),mapper,SLOT(map()));
1590 					if ((itemtype&ITEMTYPE) == SCROLLMULTI)
1591 						scroll->setSelectionMode( EScrollField::Extended );
1592 				}
1593 				break;
1594 			default:
1595 				break;
1596 		}
1597 		items[i] = widget;
1598 		if (widget != 0) {
1599             widget->setFixedSize( wid, hei );
1600             widget->move( x, y );
1601 			mapper->setMapping( widget, i );
1602 		}
1603 	}
1604 	if (defbutton == 0 && buttonzero != 0) defbutton = buttonzero;
1605 	if (defbutton != 0) defbutton->setDefault(TRUE);
1606 	if (focus == 0) focus = defbutton;
1607 	if (focus == 0) focus = items[0];
1608 	if (focus != 0) focus->setFocus();
1609 }
1610 
showMe()1611 void EDialogPrivate::showMe()
1612 {
1613     QWidget::show();
1614     iniPos = pos();
1615     itemHit = -1;
1616 }
1617 
localize(QString qstr)1618 char *EDialogPrivate::localize (QString qstr)
1619 {
1620     static QCString str[2];
1621 	static int i = 0;
1622 
1623     str[i] = qstr.local8Bit();
1624     const char *s = str[i];
1625 	i = (i + 1) % (sizeof(str)/sizeof(str[0]));
1626     return((char*)s);
1627 }
1628 
1629 #ifdef QTSTRETCH
1630 #define REORDER
checkChildren()1631 bool EDialogPrivate::checkChildren()
1632 {
1633 	INTBIG i, j, itemtype;
1634     DIALOG *dialog = dia->itemDesc();
1635 #ifdef REORDER
1636 	char line[40];
1637 #endif
1638 
1639 	/* load the items */
1640 	mapper = new QSignalMapper( this, "mapper");
1641 	connect(mapper,SIGNAL(mapped(int)),this,SLOT(action(int)));
1642 	QWidget *focus = 0;
1643 	QPushButton *defbutton = 0;
1644 	QPushButton *buttonzero = 0;
1645 #ifdef REORDER
1646 	for (i = 0; i < dialog->items; i++) items[i] = 0;
1647 #else
1648     i = 0;
1649 #endif
1650 
1651 	for (uint isExt = FALSE; isExt <= (dialog->briefHeight != 0); isExt++)
1652 	{
1653 		QObjectList ol ( *(isExt ? extension()->children() : children() ) );
1654 		for(uint li = 0; li < ol.count(); li++)
1655 		{
1656 			if (!ol.at(li)->isWidgetType() || ol.at(li) == extension()) continue;
1657 			QWidget *widget = (QWidget*)ol.at(li);
1658 #ifdef REORDER
1659 			strncpy(line, widget->name(), sizeof(line));
1660 			for (i = 0; i < (int)sizeof(line); i++)
1661 				if (line[i] == '_' || i == sizeof(line)-1) line[i] = 0;
1662 			i = atol(line)-1;
1663 			if (i < 0 || i >= dialog->items)
1664 			{
1665 				ttyputerr("Invalid dialog item number %s", widget->name());
1666 				return FALSE;
1667 			}
1668 			if (items[i])
1669 			{
1670 				ttyputerr("Duplicated dialog item number %s", widget->name());
1671 				return FALSE;
1672 			}
1673 #else
1674 			if (i >= dialog->items)
1675 			{
1676 				ttyputerr("Too many items in .ui");
1677 				return FALSE;
1678 			}
1679 #endif
1680 
1681 			itemtype = dialog->list[i].type;
1682 			switch (itemtype&ITEMTYPE)
1683 			{
1684 				case BUTTON:
1685 				case DEFBUTTON:
1686 					if (!widget->isA("QPushButton"))
1687 					{
1688 						ttyputerr("Invalid item %d BUTTON in .ui", i);
1689 						return FALSE;
1690 					}
1691 					{
1692 						QPushButton *button = (QPushButton*)widget;
1693 						connect(button,SIGNAL(clicked()),mapper,SLOT(map()));
1694 						if (i == 0) buttonzero = button;
1695 						if ((itemtype&ITEMTYPE) == DEFBUTTON) defbutton = button;
1696 					}
1697 					break;
1698 				case CHECK:
1699 					if ((itemtype&ITEMTYPEEXT) == AUTOCHECK)
1700 					{
1701 						if (!widget->isA("QCheckBox"))
1702 						{
1703 							ttyputerr("Invalid item %d AUTOCHECK in .ui", i);
1704 							return FALSE;
1705 						}
1706 						connect(widget,SIGNAL(clicked()),mapper,SLOT(map()));
1707 					} else
1708 					{
1709 						if (!widget->isA("ECheckField"))
1710 						{
1711 							ttyputerr("Invalid item %d CHECK in .ui", i);
1712 							return FALSE;
1713 						}
1714 						connect(widget,SIGNAL(clicked()),mapper,SLOT(map()));
1715 					}
1716 					break;
1717 				case RADIO:
1718 					if (!widget->isA("QRadioButton"))
1719 					{
1720 						ttyputerr("Invalid item %d RADIO in .ui", i);
1721 						return FALSE;
1722 					}
1723 					connect(widget,SIGNAL(clicked()),mapper,SLOT(map()));
1724 					if ((itemtype&ITEMTYPEEXT) != RADIO)
1725 					{
1726 						/* Radio-button group */
1727 						int exttype = itemtype&ITEMTYPEEXT;
1728 						/* check if this is the last button in the group */
1729 						for (j = i + 1; j < dialog->items; j++)
1730 							if ((dialog->list[j].type&ITEMTYPEEXT) == exttype) break;
1731 						if (j == dialog->items)
1732 						{
1733 							/* last button, hence make the group */
1734 							QButtonGroup *group = new QButtonGroup(this);
1735 							for (j = 0; j < i; j++)
1736 							{
1737 								if ((dialog->list[j].type&ITEMTYPEEXT) == exttype)
1738 									group->insert( (QRadioButton*)( items[j] ) );
1739 							}
1740 							group->insert( (QRadioButton*)widget );
1741 							group->hide();
1742 						}
1743 					}
1744 					break;
1745 				case EDITTEXT:
1746 					if (!widget->isA("QLineEdit"))
1747 					{
1748 						ttyputerr("Invalid item %d EDITTEXT in .ui", i);
1749 						return FALSE;
1750 					}
1751 					connect(widget,SIGNAL(textChanged(const QString&)),mapper,SLOT(map()));
1752 					if (focus == 0) focus = widget;
1753 					break;
1754 				case MESSAGE:
1755 					if (!widget->isA("QLabel"))
1756 					{
1757 						ttyputerr("Invalid item %d MESSAGE in .ui", i);
1758 						return FALSE;
1759 					}
1760 					break;
1761 				case PROGRESS:
1762 					if (!widget->isA("QProgressBar"))
1763 					{
1764 						ttyputerr("Invalid item %d PROGRESS in .ui", i);
1765 						return FALSE;
1766 					}
1767 					break;
1768 				case DIVIDELINE:
1769 					if (!widget->isA("QWidget"))
1770 					{
1771 						ttyputerr("Invalid item %d DIVIDELINE in .ui", i);
1772 						return FALSE;
1773 					}
1774 					widget->setBackgroundMode( PaletteForeground );
1775 					break;
1776 				case USERDRAWN:
1777 					if (!widget->isA("EUserDrawnField"))
1778 					{
1779 						ttyputerr("Invalid item %d USERDRAWN in .ui", i);
1780 						return FALSE;
1781 					}
1782 					((EUserDrawnField*)widget)->dia = dia;
1783 					connect(widget,SIGNAL(clicked()),mapper,SLOT(map()));
1784 					break;
1785 				case POPUP:
1786 					if (!widget->isA("QComboBox"))
1787 					{
1788 						ttyputerr("Invalid item %d POPUP in .ui", i);
1789 						return FALSE;
1790 					}
1791 					connect(widget,SIGNAL(activated(int)),mapper,SLOT(map()));
1792 					break;
1793 				case ICON:
1794 					{
1795 						if (!widget->isA("EIconField"))
1796 						{
1797 							ttyputerr("Invalid item %d ICON in .ui", i);
1798 							return FALSE;
1799 						}
1800 						dialog->list[i].data = (INTBIG)dialog->list[i].msg;
1801 						if ((itemtype&INACTIVE) == 0)
1802 						{
1803 							connect(widget, SIGNAL(clicked()), mapper, SLOT(map()));
1804 						}
1805 					}
1806 					break;
1807 				case SCROLL:
1808 				case SCROLLMULTI:
1809 					if (!widget->isA("EScrollField"))
1810 					{
1811 						ttyputerr("Invalid item %d SCROLL in .ui", i);
1812 						return FALSE;
1813 					}
1814 					connect(widget,SIGNAL(selectionChanged()),mapper,SLOT(map()));
1815 					if ((itemtype&ITEMTYPE) == SCROLLMULTI)
1816 						((EScrollField*)widget)->setSelectionMode( EScrollField::Extended );
1817 					break;
1818 				default:
1819 					break;
1820 			}
1821 #ifdef REORDER
1822 			items[i] = widget;
1823 			mapper->setMapping( widget, i );
1824 #else
1825 			items[i] = widget;
1826 			mapper->setMapping( widget, i );
1827 			i++;
1828 #endif
1829 		}
1830 	}
1831 #ifdef REORDER
1832 	for (i = 0; i < dialog->items; i++)
1833 	{
1834 		if (!items[i])
1835 		{
1836 			ttyputerr("Dialog item %d is absent", i+1);
1837 			return FALSE;
1838 		}
1839 	}
1840 #else
1841     if (i != dialog->items)
1842     {
1843         ttyputerr("Too few items in .ui");
1844         return FALSE;
1845     }
1846 #endif
1847 	if (defbutton == 0 && buttonzero != 0) defbutton = buttonzero;
1848 	if (defbutton != 0) defbutton->setDefault(TRUE);
1849 	if (focus == 0) focus = defbutton;
1850 	if (focus == 0) focus = items[0];
1851 	if (focus != 0) focus->setFocus();
1852     return TRUE;
1853 }
1854 #endif
1855 
1856 /*
1857  * Routine to convert dialog coordinates
1858  */
getdialogcoordinates(RECTAREA * rect,INTBIG * x,INTBIG * y,INTBIG * wid,INTBIG * hei)1859 void EDialogPrivate::getdialogcoordinates(RECTAREA *rect, INTBIG *x, INTBIG *y, INTBIG *wid, INTBIG *hei)
1860 {
1861 	*x = scaledialogcoordinate(rect->left);
1862 	*y = scaledialogcoordinate(rect->top);
1863 	*wid = scaledialogcoordinate(rect->right - rect->left);
1864 	*hei = scaledialogcoordinate(rect->bottom - rect->top);
1865 }
1866 
scaledialogcoordinate(INTBIG x)1867 INTBIG EDialogPrivate::scaledialogcoordinate(INTBIG x)
1868 {
1869 	return((x * DIALOGNUM + DIALOGDEN/2) / DIALOGDEN);
1870 }
1871 
action(int id)1872 void EDialogPrivate::action(int id)
1873 {
1874     INTBIG item;
1875 
1876     item = ((int)id) & 0xFFFF;
1877 	if ( dia )
1878 		dia->itemHitAction( item+1 );
1879 }
1880 
closeEvent(QCloseEvent * e)1881 void EDialogPrivate::closeEvent( QCloseEvent *e )
1882 {
1883     e->ignore();
1884 }
1885 
keyPressEvent(QKeyEvent * e)1886 void EDialogPrivate::keyPressEvent( QKeyEvent *e )
1887 {
1888     /* handle escape key (fakes a click on item 2 */
1889     if( e->key() == Key_Escape && isModal() && dia )
1890 	{
1891 		dia->itemHitAction(2);
1892 		return;
1893 	}
1894     QDialog::keyPressEvent( e );
1895 }
1896 
eventFilter(QObject * watched,QEvent * e)1897 bool EDialogPrivate::eventFilter( QObject *watched, QEvent *e )
1898 {
1899 #ifdef ETRACE
1900     if (e->type () == QEvent::KeyPress) {
1901 		QKeyEvent* ke = (QKeyEvent*) e;
1902 		etrace(GTRACE, "  EDialogPrivate::eventFilter %s KeyPress <%c>\n", watched->className(), ke->ascii());
1903 	} else if (e->type() != QEvent::Paint && e->type() != QEvent::MouseMove)
1904 	{
1905 		/* Event type codes are in "/qt/include/qevent.h" */
1906 		etrace(GTRACE, "  EDialogPrivate::eventFilter %s type=%d\n", watched->className(), e->type());
1907 	}
1908 #endif
1909     return QWidget::eventFilter( watched, e );
1910 }
1911 
1912 /******************************** Check Field ********************************/
1913 
ECheckField(QString & text,QWidget * parent)1914 ECheckField::ECheckField( QString &text, QWidget *parent )
1915     : QCheckBox( text, parent )
1916 {
1917     checked = FALSE;
1918 }
1919 
~ECheckField()1920 ECheckField::~ECheckField()
1921 {
1922     if (isChecked() != QCheckBox::isChecked())
1923         ttyputerr(_("CheckBox field appearance differs from value"));
1924 }
1925 
isChecked()1926 bool ECheckField::isChecked()
1927 {
1928     return checked;
1929 }
1930 
setChecked(bool value)1931 void ECheckField::setChecked( bool value )
1932 {
1933     checked = value;
1934     QCheckBox::setChecked( value );
1935 }
1936 
1937 /******************************** Scroll Field ********************************/
1938 
EScrollField(QWidget * parent)1939 EScrollField::EScrollField( QWidget *parent )
1940     : QListBox( parent )
1941 {
1942 }
1943 
keyPressEvent(QKeyEvent * e)1944 void EScrollField::keyPressEvent( QKeyEvent *e )
1945 {
1946 	if ( e->key() == Key_Enter || e->key() == Key_Return)
1947 	{
1948 		e->ignore();
1949 		return;
1950 	}
1951     if ( e->key() == Key_C && (e->state() & ControlButton) ||
1952 	 e->key() == Key_F16) { // Copy key on Sun keyboards
1953         qDebug( "Copy list");
1954         QStringList strList;
1955         for( uint i=0; i < count(); i++) strList.append( text( i ) );
1956 	qApp->clipboard()->setText( strList.join( "\n" ) );
1957 	qDebug( qApp->clipboard()->text() );
1958         return;
1959     }
1960     QListBox::keyPressEvent( e );
1961 }
1962 
1963 /****************************** Icon Field ******************************/
1964 
EIconField(QWidget * parent,DIALOGITEM * item)1965 EIconField::EIconField( QWidget *parent, DIALOGITEM *item )
1966     : QLabel( parent )
1967 {
1968     setBits( (uchar*)item->data );
1969 }
1970 
setBits(uchar * bits)1971 void EIconField::setBits( uchar *bits )
1972 {
1973     QBitmap bitmap(32, 32, bits, FALSE);
1974     QWMatrix m;
1975     double scale = (double)DIALOGNUM / double(DIALOGDEN);
1976     m.scale( scale, scale );
1977     QPixmap pixmap = bitmap.xForm( m );
1978     setPixmap( pixmap );
1979 }
1980 
mousePressEvent(QMouseEvent * e)1981 void EIconField::mousePressEvent( QMouseEvent *e )
1982 {
1983 	Q_UNUSED( e );
1984     emit clicked();
1985 };
1986 
1987 /****************************** User Drawn Field ******************************/
1988 
EUserDrawnField(QWidget * parent,DIALOGITEM * item)1989 EUserDrawnField::EUserDrawnField(QWidget *parent, DIALOGITEM *item)
1990   : QWidget(parent), it(item), redispRoutine(0), buttonPressed(FALSE), eachdown(0), doubleClickAllowed(FALSE)
1991 {
1992 }
1993 
mouseMoveEvent(QMouseEvent * e)1994 void EUserDrawnField::mouseMoveEvent( QMouseEvent *e )
1995 {
1996     if (eachdown == 0) return;
1997     QPoint pos = mapToParent( e->pos() ) * DIALOGDEN / DIALOGNUM;
1998     (*eachdown)( pos.x(), pos.y() );
1999 }
2000 
mouseDoubleClickEvent(QMouseEvent * e)2001 void EUserDrawnField::mouseDoubleClickEvent( QMouseEvent *e )
2002 {
2003 	Q_UNUSED( e );
2004     buttonPressed = TRUE;
2005     if (doubleClickAllowed)
2006       emit doubleClicked();
2007     else
2008       emit clicked();
2009 }
2010 
mousePressEvent(QMouseEvent * e)2011 void EUserDrawnField::mousePressEvent( QMouseEvent *e )
2012 {
2013 	Q_UNUSED( e );
2014     buttonPressed = TRUE;
2015     emit clicked();
2016 }
2017 
mouseReleaseEvent(QMouseEvent * e)2018 void EUserDrawnField::mouseReleaseEvent( QMouseEvent *e )
2019 {
2020 	Q_UNUSED( e );
2021     buttonPressed = FALSE;
2022     if (eachdown != 0) {
2023         eachdown = 0;
2024         qApp->exit_loop();
2025     }
2026 }
2027 
paintEvent(QPaintEvent * e)2028 void EUserDrawnField::paintEvent( QPaintEvent *e )
2029 {
2030 	Q_UNUSED( e );
2031     RECTAREA rect;
2032     rect.left = it->r.left+1;
2033     rect.right = it->r.right-1;
2034     rect.top = it->r.top+1;
2035     rect.bottom = it->r.bottom-1;
2036     if ( redispRoutine )
2037         (*redispRoutine)(&rect, dia);
2038 }
2039 
2040 
2041 
2042 /****************************** DIALOG SUPPORT ******************************/
2043 
2044 /*
2045  * Helper routine for "DiaLoadTextDialog" that makes strings go in ascending order.
2046  */
gra_stringposascending(const void * e1,const void * e2)2047 int gra_stringposascending(const void *e1, const void *e2)
2048 {
2049 	REGISTER char *c1, *c2;
2050 
2051 	c1 = *((char **)e1);
2052 	c2 = *((char **)e2);
2053 	return(namesame(&c1[gra_dialogstringpos], &c2[gra_dialogstringpos]));
2054 }
2055 
2056