Version:
~ [ 10.0 ] ~
** Warning: Cannot open xref database.
1
2 /* $Id: dialogs.c,v 1.7 2005/09/30 15:29:18 icreedon Exp $ */
3
4 /******************************************************************************
5
6 UserLand Frontier(tm) -- High performance Web content management,
7 object database, system-level and Internet scripting environment,
8 including source code editing and debugging.
9
10 Copyright (C) 1992-2004 UserLand Software, Inc.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
26 ******************************************************************************/
27
28 #include "frontier.h"
29 #include "standard.h"
30
31 #include "quickdraw.h"
32 #include "bitmaps.h"
33 #include "cursor.h"
34 #include "font.h"
35 #include "launch.h"
36 #include "kb.h"
37 #include "memory.h"
38 #include "resources.h"
39 #include "scrap.h"
40 #include "strings.h"
41 #include "frontierwindows.h"
42 #include "ops.h"
43 #include "shell.h"
44 #include "shellmenu.h"
45 #include "shell.rsrc.h"
46 #include "dialogs.h"
47 #include "lang.h"
48 #include "mac.h"
49 #include "langinternal.h" /* 2005-09-26 creedon */
50 #include "tablestructure.h" /* 2005-09-26 creedon */
51
52 #ifdef flcomponent
53
54 #include <SetUpA5.h>
55
56 #endif
57
58
59 #define windowevents (updateMask + activMask)
60
61
62 short dialogcountitems (DialogPtr pdialog) {
63
64 //Code change by Timothy Paustian Sunday, April 30, 2000 9:40:09 PM
65 //Changed to Opaque call for Carbon
66 //switched to use CountDITL. This has been around since OS 7
67 return CountDITL(pdialog);
68 } /*dialogcountitems*/
69
70
71 static void dialoggeteditbuffer (DialogPtr pdialog, TEHandle *hbuffer) {
72
73 //Code change by Timothy Paustian Sunday, April 30, 2000 9:43:36 PM
74 //Changed to Opaque call for Carbon
75 //check this I need to check to see if this is a memory leak or not.
76 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
77 //DialogItemType itemType = 0;
78 //Handle h;
79 //Rect r = {0,0,0,0};
80 //SInt16 whichField = 0;
81
82 *hbuffer = GetDialogTextEditHandle((DialogRef) pdialog);
83
84 #else
85 //old code
86 *hbuffer = (*(DialogPeek) pdialog).textH;
87 #endif
88 } /*dialoggeteditbuffer*/
89
90
91 void boldenbutton (DialogPtr pdialog, short itemnumber) {
92
93 /*
94 draw a thick black ring around the OK button in the dialog.
95 */
96
97 PenState savePen;
98 short itemtype;
99 Handle itemhandle;
100 Rect itemrect;
101
102 //Code change by Timothy Paustian Wednesday, July 12, 2000 12:39:52 PM
103 //pushport was doing an implicit cast from a dialogPtr to a GrafPtr
104 //This is allowed in MacOS, but not in carbon. This was causing a crash.
105 CGrafPtr thePort;
106 #if TARGET_API_MAC_CARBON == 1
107 thePort = GetDialogPort(pdialog);
108 #else
109 thePort = (CGrafPtr)pdialog;
110 #endif
111
112 pushport (thePort);
113
114 GetPenState (&savePen); /*save the old pen state*/
115
116 GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect); /*get the item's rect*/
117
118 insetrect (&itemrect, -4, -4);
119
120 PenSize (3, 3); /*make the pen fatter*/
121
122 FrameRoundRect (&itemrect, 16, 16); /*draw the ring*/
123
124 SetPenState (&savePen); /*restore the pen state*/
125
126 popport ();
127 } /*boldenbutton*/
128
129
130 void positiondialogwindow (DialogPtr pdialog) {
131
132 register short h, v;
133 Rect rdialog, rscreen;
134 CGrafPtr thePort;
135
136 getcurrentscreenbounds (&rscreen);
137 //Code change by Timothy Paustian Sunday, April 30, 2000 9:44:58 PM
138 //Changed to Opaque call for Carbon
139 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
140 thePort = GetDialogPort(pdialog);
141 GetPortBounds(thePort, &rdialog);
142 #else
143 //old code
144 #pragma unused(thePort)
145 rdialog = (*pdialog).portRect;
146 #endif
147
148 h = rscreen.left + (((rscreen.right - rscreen.left) - (rdialog.right - rdialog.left)) / 2);
149
150 v = rscreen.top + (((rscreen.bottom - rscreen.top) - (rdialog.bottom - rdialog.top)) / 3);
151
152 #if TARGET_API_MAC_CARBON == 1
153 {
154 WindowPtr theWind = GetDialogWindow(pdialog);
155 movewindow(theWind, h, v);
156 }
157 #else
158 movewindow (pdialog, h, v);
159 #endif
160 } /*positiondialogwindow*/
161
162
163 static boolean dialogitemtypeiscontrol (short itemtype) {
164
165 register short x;
166
167 x = itemtype % itemDisable; /*ignore enabledness*/
168
169 return ((x >= ctrlItem) && (x <= (ctrlItem + resCtrl)));
170 } /*dialogitemtypeiscontrol*/
171
172
173 void disabledialogitem (DialogPtr pdialog, short itemnumber) {
174
175 /*
176 3/6/91 dmb: also dim if the item is a control
177 */
178
179 short itemtype;
180 Handle itemhandle;
181 Rect itemrect;
182
183 GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect);
184
185 if (itemtype < itemDisable) { /*it is enabled, disable it*/
186
187 SetDialogItem (pdialog, itemnumber, itemtype + itemDisable, itemhandle, &itemrect);
188
189 if (dialogitemtypeiscontrol (itemtype))
190 HiliteControl ((ControlHandle) itemhandle, 255);
191 }
192 } /*disabledialogitem*/
193
194
195 void enabledialogitem (DialogPtr pdialog, short itemnumber) {
196
197 short itemtype;
198 Handle itemhandle;
199 Rect itemrect;
200
201 GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect);
202
203 if (itemtype >= itemDisable) { /*it is disabled, enable it*/
204
205 SetDialogItem (pdialog, itemnumber, itemtype - itemDisable, itemhandle, &itemrect);
206
207 if (dialogitemtypeiscontrol (itemtype))
208 HiliteControl ((ControlHandle) itemhandle, 0);
209 }
210 } /*enabledialogitem*/
211
212
213 void hidedialogitem (DialogPtr pdialog, short itemnumber) {
214
215 HideDialogItem (pdialog, itemnumber);
216 } /*hidedialogitem*/
217
218
219 void showdialogitem (DialogPtr pdialog, short itemnumber) {
220
221 ShowDialogItem (pdialog, itemnumber);
222 } /*showdialogitem*/
223
224
225 void setdefaultitem (DialogPtr pdialog, short defaultitem) {
226
227 //Code change by Timothy Paustian Sunday, April 30, 2000 9:47:39 PM
228 //Changed to Opaque call for Carbon
229 SetDialogDefaultItem(pdialog, defaultitem);
230 //old code
231 //(*(DialogPeek) pdialog).aDefItem = defaultitem; /*filter will bolden this*/
232 } /*setdefaultitem*/
233
234
235 static boolean dialogitemisenabled (DialogPtr pdialog, short item) {
236
237 short itemtype;
238 Handle itemhandle;
239 Rect itemrect;
240
241 GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
242
243 return ((itemtype & itemDisable) == 0);
244 } /*dialogitemisenabled*/
245
246
247 boolean dialogitemisbutton (DialogPtr pdialog, short item) {
248
249 short itemtype;
250 Handle itemhandle;
251 Rect itemrect;
252
253 if (item <= 0)
254 return (false);
255
256 GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
257
258 return (dialogitemtypeiscontrol (itemtype));
259 } /*dialogitemisbutton*/
260
261
262 static boolean dialogitemisedittext (DialogPtr pdialog, short item) {
263
264 short itemtype;
265 Handle itemhandle;
266 Rect itemrect;
267
268 GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
269
270 return (itemtype & editText);
271 } /*dialogitemisedittext*/
272
273
274 static boolean dialoghasedititems (DialogPtr pdialog) {
275
276 register short i;
277 register short ctitems;
278
279 ctitems = dialogcountitems (pdialog);
280
281 for (i = 1; i <= ctitems; i++)
282 if (dialogitemisedittext (pdialog, i))
283 return (true);
284
285 return (false);
286 } /*dialoghasedititems*/
287
288
289 static void dialoggetbuttonstring (DialogPtr pdialog, short item, bigstring bs) {
290
291 short itemtype;
292 Handle itemhandle;
293 Rect itemrect;
294 //Code change by Timothy Paustian Sunday, April 30, 2000 9:57:08 PM
295 //Changed to Opaque call for Carbon
296 ControlRef theControl;
297 Str255 controlTitle;
298
299 GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
300 //Code change by Timothy Paustian Sunday, April 30, 2000 9:57:41 PM
301 //Changed to Opaque call for Carbon
302 //watch this one. What happens if this is a bad cast to a ControlRef?
303 theControl = (ControlRef) itemhandle;
304 GetControlTitle(theControl, controlTitle);
305 copystring (controlTitle, bs);
306 //old code
307 //copystring ((**(ControlRef) itemhandle).contrlTitle, bs);
308 } /*dialoggetbuttonstring*/
309
310
311 static void dialogsetbuttonstring (DialogPtr pdialog, short item, bigstring bs) {
312
313 short itemtype;
314 Handle itemhandle;
315 Rect itemrect;
316
317 GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
318
319 SetControlTitle ((ControlHandle) itemhandle, bs);
320 } /*dialogsetbuttonstring*/
321
322
323 DialogPtr newmodaldialog (short id, short defaultitem) {
324
325 /*
326 2/7/92 dmb: if dialoghasedititems, force shell to export scrap
327
328 2/10/92 dmb: added call to new shellactivate
329
330 3.0.1b1 dmb: don't call shellactivate if the dialog isn't of a modal
331 design, i.e. a dBoxProc window. currently, the only case where
332 this isn't so is Frontier's about window / splash screen. having
333 the splash screen force Frontier to the front is bad news for
334 background launching. it even crashes!
335 */
336
337 register DialogPtr pdialog;
338 long appA5;
339
340 #ifdef fldebug
341
342 if (GetResource ('DLOG', id) == nil)
343 DebugStr ("\pmissing DLOG resource");
344
345 #endif
346
347 #ifdef flcomponent
348
349 appA5 = SetUpCurA5 ();
350
351 #endif
352
353 pdialog = GetNewDialog (id, nil, (WindowRef) -1L);
354
355 #ifdef flcomponent
356
357 RestoreA5 (appA5);
358
359 #endif
360
361 if (pdialog == nil)
362 return (nil);
363
364 positiondialogwindow (pdialog);
365
366 setdefaultitem (pdialog, defaultitem);
367
368 if (dialoghasedititems (pdialog))
369 shellwritescrap (textscraptype);
370
371 #if TARGET_API_MAC_CARBON == 1
372 {
373 WindowPtr theWind = GetDialogWindow(pdialog);
374 if (GetWVariant (theWind) == dBoxProc) /*make sure we're in front before posting modal dialog*/
375 shellactivate ();
376 }
377 #else
378 if (GetWVariant (pdialog) == dBoxProc) /*make sure we're in front before posting modal dialog*/
379 shellactivate ();
380 #endif
381 return (pdialog);
382 } /*newmodaldialog*/
383
384
385 void disposemodaldialog (DialogPtr pdialog) {
386
387 /*
388 7/20/92 dmb: don't do partial event loop for runtime.
389
390 1/21/93 dmb: use langpartialeventloop when a script is running
391
392 2.1b dmb: if this was an out-of-memory alert, the partial event loop is
393 bad news. it's always tende to cause problems, so and shouldn't really
394 be necessary. so let's just not do it!
395 */
396
397 DisposeDialog (pdialog);
398
399 #if 0 //ndef flruntime
400
401 /*handle all pending activate & update events*/
402
403 if (flscriptrunning)
404 langpartialeventloop (windowevents);
405 else
406 shellpartialeventloop (windowevents);
407
408 #endif
409 } /*disposemodaldialog*/
410
411
412 void setdialogcheckbox (DialogPtr pdialog, short item, boolean fl) {
413
414 /*
415 change the value of the checkbox.
416 */
417
418 short itemtype;
419 Rect itemrect;
420 Handle itemhandle;
421
422 GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
423
424 SetControlValue ((ControlHandle) itemhandle, fl);
425 } /*setdialogcheckbox*/
426
427
428 boolean getdialogcheckbox (DialogPtr pdialog, short item) {
429
430 /*
431 get the value of the checkbox, either a 1 or a 0.
432 */
433
434 short itemtype;
435 Rect itemrect;
436 Handle itemhandle;
437
438 GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
439
440 return (bitboolean (GetControlValue ((ControlHandle) itemhandle)));
441 } /*getdialogcheckbox*/
442
443
444 void toggledialogcheckbox (DialogPtr pdialog, short item) {
445
446 /*
447 if the checkbox is on, turn it off, and vice versa.
448 */
449
450 short itemtype;
451 Rect itemrect;
452 Handle itemhandle;
453
454 GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
455
456 SetControlValue ((ControlHandle) itemhandle, !GetControlValue ((ControlHandle) itemhandle));
457 } /*toggledialogcheckbox*/
458
459
460 boolean setdialogradiovalue (DialogPtr pdialog, short firstitem, short lastitem, short val) {
461
462 /*
463 set the value of the radio button range. val is zero-based; valid
464 values range from zero to (firstitem - lastitem)
465 */
466
467 register short item;
468 register boolean flon;
469
470 for (item = firstitem; item <= lastitem; ++item) {
471
472 flon = val == (item - firstitem);
473
474 if (flon != getdialogcheckbox (pdialog, item))
475 setdialogcheckbox (pdialog, item, flon);
476 }
477
478 return (true);
479 } /*getdialogradiovalue*/
480
481
482 short getdialogradiovalue (DialogPtr pdialog, short firstitem, short lastitem) {
483
484 /*
485 set the value of the radio button range. val is zero-based; returned
486 value will range from zero to (firstitem - lastitem).
487
488 if none of the radio buttons are set, returns -1.
489 */
490
491 register short item;
492
493 for (item = firstitem; item <= lastitem; ++item) {
494
495 if (getdialogcheckbox (pdialog, item))
496 return (item - firstitem);
497 }
498
499 return (-1);
500 } /*getdialogradiovalue*/
501
502
503 void getdialogtext (DialogPtr pdialog, short itemnumber, bigstring bs) {
504
505 short itemtype;
506 Handle itemhandle;
507 Rect itemrect;
508
509 GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect);
510 GetDialogItemText (itemhandle, bs);
511
512 } /*getdialogtext*/
513
514
515 static void dialogscanspecialchars (bigstring bs) {
516
517 register short i, ct;
518
519 ct = stringlength (bs);
520
521 for (i = 1; i <= ct; i++) {
522
523 register char ch = bs [i];
524
525 if (ch == '¨') /*option-R maps to the return char*/
526 ch = chreturn;
527
528 bs [i] = ch;
529 } /*for*/
530 } /*dialogscanspecialchars*/
531
532 #if !flruntime
533
534 void setdialogicon (DialogPtr pdialog, short itemnumber, short iconnum) {
535
536 Handle hicon;
537 short itemtype;
538 Handle itemhandle;
539 Rect itemrect;
540
541 hicon = GetIcon (iconnum);
542
543 if (hicon != nil) {
544
545 GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect);
546
547 SetDialogItem (pdialog, itemnumber, itemtype, hicon, &itemrect);
548 }
549 } /*setdialogicon*/
550
551 #endif
552
553 void setdialogtext (DialogPtr pdialog, short itemnumber, bigstring bs) {
554
555 /*
556 6/12/92 dmb: if the item is the active text item, select the new text
557 */
558
559 OSStatus err = noErr;
560 short itemtype;
561 Handle itemhandle;
562 Rect itemrect;
563 char s[256];
564 ControlRef C;
565 dialogscanspecialchars (bs);
566
567
568 GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect);
569 SetDialogItemText (itemhandle, bs);
570 err = GetDialogItemAsControl (pdialog,itemnumber,&C);
571 if (err==noErr) {
572 X0_p2cstrcpy(s,bs);
573 err = SetControlData (C,kControlEditTextPart,kControlEditTextTextTag,strlen(s),s);
574 }
575
576
577 //Code change by Timothy Paustian Sunday, April 30, 2000 10:02:10 PM
578 //Changed to Opaque call for Carbon
579 //change to use a new routine that finds the item in focus
580
581 if (itemnumber == GetDialogKeyboardFocusItem(pdialog))
582 dialogselectall (pdialog);
583
584
585 //old code
586 //if (itemnumber == (*(DialogPeek) pdialog).editField + 1) /*6/12/92*/
587 // dialogselectall (pdialog);
588
589 /*closebitmap (pdialog);*/
590 } /*setdialogtext*/
591
592
593 void selectdialogtext (DialogPtr pdialog, short itemnumber) {
594 OSStatus err = noErr;
595 ControlRef C;
596 ControlEditTextSelectionRec selection = { 0, 32000 };
597 // SelectDialogItemText (pdialog, itemnumber, 0, infinity); /*select all text*/
598
599 err = GetDialogItemAsControl (pdialog,itemnumber,&C);
600 if (err==noErr) {
601 err = SetControlData(C, kControlEntireControl,kControlEditTextSelectionTag, sizeof(ControlEditTextSelectionRec),&selection);
602 } else SelectDialogItemText (pdialog, itemnumber, 0, infinity); /*select all text*/
603
604 }
605
606
607
608 short getdialogint (DialogPtr pdialog, short itemnumber) {
609
610 /*
611 get an integer from an edittext item in the dialog.
612 */
613
614 bigstring bs;
615 long num;
616
617 getdialogtext (pdialog, itemnumber, bs);
618
619 stringtonumber (bs, &num);
620
621 return ((short) num);
622 } /*getdialogint*/
623
624
625 void setdialogint (DialogPtr pdialog, short itemnumber, short num) {
626
627 bigstring bs;
628
629 NumToString (num, bs);
630
631 setdialogtext (pdialog, itemnumber, bs);
632 } /*setdialogint*/
633
634
635 OSType getdialogostype (DialogPtr pdialog, short itemnumber) {
636
637 /*
638 get an OSType from an edittext item.
639 */
640
641 bigstring bs;
642 OSType type;
643
644 getdialogtext (pdialog, itemnumber, bs);
645
646 stringtoostype (bs, &type);
647
648 return (type);
649 } /*getdialogostype*/
650
651
652 void setdialogostype (DialogPtr pdialog, short itemnumber, OSType type) {
653
654 bigstring bs;
655
656 ostypetostring (type, bs);
657
658 setdialogtext (pdialog, itemnumber, bs);
659 } /*setdialogostype*/
660
661
662 void setdialogbutton (DialogPtr pdialog, short itemnumber, bigstring bs) {
663
664 /*
665 6/11/93 dmb: don't use bitmaps; doesn't work on SF buttons
666 */
667
668 short itemtype;
669 Handle itemhandle;
670 Rect r;
671
672 GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &r);
673
674 /*
675 openbitmapcopy (r, pdialog);
676 */
677
678 SetControlTitle ((ControlHandle) itemhandle, bs);
679
680 /*
681 closebitmap (pdialog);
682
683 validrect (r);
684 */
685 } /*setdialogbutton*/
686
687
688 void dialoggetobjectrect (DialogPtr pdialog, short objectnumber, Rect *r) {
689
690 short itemtype;
691 Handle itemhandle;
692
693 GetDialogItem (pdialog, objectnumber, &itemtype, &itemhandle, r);
694 } /*dialoggetobjectrect*/
695
696
697 void dialogsetobjectrect (DialogPtr pdialog, short objectnumber, Rect r) {
698
699 short itemtype;
700 Handle itemhandle;
701 Rect itemrect;
702
703 GetDialogItem (pdialog, objectnumber, &itemtype, &itemhandle, &itemrect);
704
705 SetDialogItem (pdialog, objectnumber, itemtype, itemhandle, &r);
706
707 if (itemtype & editText) { /*it's an edittext item, set its rects and wordwrap*/
708
709 TEHandle hbuffer;
710
711 dialoggeteditbuffer (pdialog, &hbuffer);
712
713 (**hbuffer).viewRect = r;
714
715 (**hbuffer).destRect = r;
716
717 TECalText (hbuffer);
718 }
719 } /*dialogsetobjectrect*/
720
721 #if !flruntime
722
723 boolean dialogsetfontsize (DialogPtr pdialog, short font, short size) {
724
725 /*
726 2.1b9 dmb: including leading in line height calculation
727 */
728
729 TEHandle hbuffer;
730 register TEHandle h;
731
732 dialoggeteditbuffer (pdialog, &hbuffer);
733
734 h = hbuffer; /*copy into register*/
735
736 (**h).txFont = font;
737
738 (**h).txSize = size;
739
740 pushstyle (font, size, 0);
741
742 (**h).fontAscent = globalfontinfo.ascent;
743
744 (**h).lineHeight = globalfontinfo.ascent + globalfontinfo.descent + globalfontinfo.leading;
745
746 popstyle ();
747
748 TECalText (h);
749
750 return (true);
751 } /*dialogsetfontsize*/
752
753
754 boolean ptinuseritem (Point pt, DialogPtr pdialog, short item) {
755
756 Rect r;
757
758 dialoggetobjectrect (pdialog, item, &r);
759
760 return (pointinrect (pt, r));
761 } /*ptinuseritem*/
762
763 #endif
764
765 boolean setuseritemdrawroutine (DialogPtr pdialog, short item, dialogcallback drawroutine) {
766
767 short itemtype;
768 Handle itemhandle;
769 Rect itemrect;
770
771 GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
772
773 assert (itemtype % itemDisable == userItem);
774
775 SetDialogItem (pdialog, item, itemtype, (Handle) drawroutine, &itemrect);
776
777 return (true);
778 } /*setuseritemdrawroutine*/
779
780
781 static void highlightdialogbutton (DialogPtr pdialog, short itemnumber, boolean flon) {
782
783 register DialogPtr p = pdialog;
784 register short val;
785 short itemtype;
786 Handle itemhandle;
787 Rect itembox;
788
789 if (pdialog == nil) /*defensive driving*/
790 return;
791
792 GetDialogItem (p, itemnumber, &itemtype, &itemhandle, &itembox);
793
794 if (flon)
795 val = kControlButtonPart;
796 else
797 val = 0;
798
799 HiliteControl ((ControlHandle) itemhandle, val);
800 } /*highlightdialogbutton*/
801
802
803 static boolean dialogsimulatehit (DialogPtr pdialog, short item) {
804
805 /*
806 8/26/91 dmb: block event during delay. otherwise, silly behavior (like
807 handling updates) or even crashes (when running a scripted dialog) can
808 occur
809 */
810
811 if (dialogitemisbutton (pdialog, item) && dialogitemisenabled (pdialog, item)) {
812
813 highlightdialogbutton (pdialog, item, true);
814
815 shellblockevents (); /*limit background processing during delay*/
816
817 delayticks (8);
818
819 shellpopevents ();
820
821 highlightdialogbutton (pdialog, item, false);
822
823 return (true);
824 }
825
826 return (false);
827 } /*dialogsimulatehit*/
828
829
830 static boolean dialogmapkeystroke (DialogPtr pdialog, bigstring bsmap, short *item) {
831
832 /*
833 map a keystroke onto a dialog item. if no match, return false.
834
835 for buttons, if the keystroke matches the first character of the button name,
836 we return true with that item. makes your choice of button names strategic.
837
838 to get the number of items in the list, pull the first two bytes out of the
839 dialog's itemhandle and add one. an obvious problem if Apple changes the format
840 of an item list handle.
841
842 10/10/91 dmb: now take string to map instead of a character. if bsmap is
843 longer than a single character, we look for an exact match (still ignoring case).
844
845 2/7/92 dmb: use dialoghasedititems instead of looping through item list.
846 */
847
848 register short i;
849 register boolean flcmdkeyrequired;
850 short ctitems;
851 bigstring bs;
852 boolean flsinglechar;
853
854 alllower (bsmap); /*search is unicase*/
855
856 ctitems = dialogcountitems (pdialog);
857
858 flsinglechar = stringlength (bsmap) == 1;
859
860 if (flsinglechar) { /*mapping a single character -- check command key*/
861
862 flcmdkeyrequired = dialoghasedititems (pdialog);
863
864 if (flcmdkeyrequired && !cmdkeydown ())
865 return (false);
866 }
867
868 for (i = 1; i <= ctitems; i++) {
869
870 if (dialogitemisbutton (pdialog, i)) {
871
872 dialoggetbuttonstring (pdialog, i, bs);
873
874 if (stringlength (bs) > 0) {
875
876 if (flsinglechar)
877 setstringlength (bs, 1);
878
879 alllower (bs);
880
881 if (equalstrings (bs, bsmap)) {
882
883 *item = i;
884
885 return (true);
886 }
887 }
888 }
889 } /*for*/
890
891 return (false); /*no mapping for the character*/
892 } /*dialogmapkeystroke*/
893
894
895 static short passworditem = -1;
896
897
898 static void passwordprocesskey (DialogPtr pdialog, char chkb, EventRecord *ev, short *item) {
899
900 TEHandle hte;
901 char *buffer;
902 short start, end;
903 short len;
904 //Code change by Timothy Paustian Sunday, April 30, 2000 10:07:30 PM
905 //Changed to Opaque call for Carbon
906 //I think this is what is desired, but this may break this code.
907 //SInt16 dialItem = - 1;
908 if( GetDialogKeyboardFocusItem(pdialog) != passworditem)
909 return;
910 //old code
911 //dialItem = (*(DialogPeek) pdialog).editField;
912 //if (dialItem != passworditem - 1) /*it's not the password item, nothing to do*/
913 // return;
914
915 switch (chkb) {
916
917 case chtab: case chleftarrow: case chrightarrow:
918 case chuparrow: case chdownarrow:
919 return;
920
921 } /*switch*/
922
923 #if TARGET_API_MAC_CARBON == 1
924 {
925 WindowPtr theWind = GetDialogWindow(pdialog);
926 buffer = (char *) GetWRefCon (theWind);
927 }
928 #else
929 buffer = (char *) GetWRefCon (pdialog);
930 #endif
931 //Code change by Timothy Paustian Sunday, April 30, 2000 10:13:01 PM
932 //Changed to Opaque call for Carbon
933 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
934 hte = GetDialogTextEditHandle(pdialog);
935 #else
936 //old code
937 hte = (*(DialogPeek) pdialog).textH;
938 #endif
939
940 start = (**hte).selStart;
941
942 end = (**hte).selEnd;
943
944 if ((start != end) || (chkb == chbackspace)) {
945
946 setstringlength (buffer, 0);
947
948 TESetSelect (0, 32767, hte);
949
950 TEDelete (hte);
951
952 return;
953 }
954
955 len = stringlength (buffer) + 1;
956
957 buffer [len] = chkb;
958
959 setstringlength (buffer, len);
960
961 (*ev).message = '\xA5';
962 } /*passwordprocesskey*/
963
964
965 pascal boolean modaldialogcallback (DialogPtr pdialog, EventRecord *ev, short *item) {
966
967 /*
968 standard dialog & alert event filtering.
969
970 10/3/90 dmb: check result of dialogsimulatehit (which now checks enabledness).
971 only process background tasks on null events; dialog events have priority.
972 also, get default item instead of assuming item 1, and handle boldening.
973
974 8/26/91 dmb: after backgrounding, make sure we're still in front. otherwise,
975 the dialog manager will crash
976
977 10/14/91 dmb: set shellevent.when to deter overzealous agent processing
978 */
979 //Code change by Timothy Paustian Sunday, April 30, 2000 10:13:28 PM
980 //Changed to Opaque call for Carbon
981 short defaultitem = GetDialogDefaultItem(pdialog);
982 //old codde
983 //short defaultitem = (*(DialogPeek) pdialog).aDefItem; /*was set by newmodaldialog*/
984 bigstring bsbutton;
985 short whatevent = (*ev).what;
986 //why was hit a short?
987 boolean eventHandled = false;
988
989 //register short hit = 0;
990
991 #if !TARGET_API_MAC_CARBON && defined(flcomponent)
992 long curA5 = SetUpAppA5 ();
993 #endif
994
995 if (whatevent != nullEvent) { /*non-null event; set global event time for background logic*/
996
997 shellevent.when = (*ev).when;
998 }
999 //I need to change this so it hands of key presses for default handling
1000 switch (whatevent) {
1001
1002 case keyDown: case autoKey: {
1003
1004 register char chkb;
1005 register boolean flcmdkey;
1006
1007 chkb = (*ev).message & charCodeMask;
1008
1009 flcmdkey = ((*ev).modifiers & cmdKey) == cmdKey;
1010
1011 if ((chkb == chreturn) || (chkb == chenter)) { /*user hit return or enter*/
1012
1013 if (defaultitem == 0)
1014 break;
1015
1016 if (!dialogsimulatehit (pdialog, defaultitem))
1017 break;
1018
1019 *item = defaultitem;
1020
1021 eventHandled = true; /*the dialog manager's version of true*/
1022
1023 break;
1024 }
1025
1026 if ((chkb == chescape) || ((chkb == '.') && flcmdkey)) { /*escape or cmd-period*/
1027
1028 shellgetstring (cancelbuttonstring, bsbutton);
1029 }
1030 else
1031 setstringwithchar (chkb, bsbutton);
1032
1033 if (passworditem > 0)
1034 passwordprocesskey (pdialog, chkb, ev, item);
1035
1036 if (dialogmapkeystroke (pdialog, bsbutton, item)) {
1037
1038 if (MenuKey ((*ev).message & charCodeMask)) { /*will be handled by system*/
1039
1040 HiliteMenu (0);
1041
1042 break;
1043 }
1044
1045 if (!dialogsimulatehit (pdialog, *item))
1046 break;
1047
1048 eventHandled = true;
1049
1050 break;
1051 }
1052 break; /*keydown or autokey*/
1053 }
1054
1055 case updateEvt:
1056
1057 if ((defaultitem > 0) && ((*ev).message == (long) pdialog))
1058 boldenbutton (pdialog, defaultitem);
1059 #if TARGET_API_MAC_CARBON == 1
1060 {
1061 CGrafPtr thePort = GetDialogPort(pdialog);
1062 QDFlushPortBuffer(thePort, nil);
1063 }
1064 #endif
1065 break;
1066
1067 case nullEvent:
1068
1069 /*
1070 shellblockevents (); /%all events are blocked when modal dialog is in front%/
1071
1072 if (flscriptrunning)
1073 langbackgroundtask ();
1074 else
1075 shellbackgroundtask ();
1076
1077 shellpopevents ();
1078 */
1079 //Code change Timothy Paustian 9/16/00
1080 //This is a bit of a hack, but it works. The contents of the port
1081 //need to be flushed on screen. The only way I could figure to do this
1082 //was to do it at every null event. The whole thing should be rewritten
1083 //at some points to use ModalDialog Correctly.
1084 #if TARGET_API_MAC_CARBON == 1
1085 {
1086 WindowRef pWindow = GetDialogWindow(pdialog);
1087 CGrafPtr thePort = GetDialogPort(pdialog);
1088
1089 SelectWindow(pWindow);
1090 QDFlushPortBuffer(thePort, nil);
1091 }
1092 #else
1093 SelectWindow (pdialog); /*make sure no one has screwed around with us*/
1094 #endif
1095 break;
1096
1097 } /*switch*/
1098
1099 #if !TARGET_API_MAC_CARBON && defined(flcomponent)
1100 RestoreA5 (curA5);
1101 #endif
1102 return (eventHandled); /*the dialog manager's version of false*/
1103 } /*modaldialogcallback*/
1104
1105
1106 //Code change by Timothy Paustian Sunday, May 7, 2000 11:07:09 PM
1107 //Changed to Opaque call for Carbon
1108
1109 #if !TARGET_RT_MAC_CFM
1110
1111 static short runmodaldialog (void) {
1112
1113 short itemnumber;
1114
1115 setcursortype (cursorisarrow);
1116
1117 #ifdef flcomponent
1118 {
1119 ProcPtr filter = (ProcPtr) modaldialogcallback;
1120 #if !TARGET_API_MAC_CARBON && defined(flcomponent)
1121 long appA5 = SetUpCurA5 (); /*for system*/
1122 #endif
1123
1124 ModalDialog ((ModalFilterUPP) filter, &itemnumber);
1125
1126 #if !TARGET_API_MAC_CARBON && defined(flcomponent)
1127 RestoreA5 (appA5);
1128 #endif
1129 }
1130 #else
1131
1132 ModalDialog (&modaldialogcallback, &itemnumber);
1133
1134 #endif
1135
1136 return (itemnumber);
1137 } /*runmodaldialog*/
1138
1139 #else
1140
1141 #if !TARGET_API_MAC_CARBON
1142 static RoutineDescriptor modalfilterdesc = BUILD_ROUTINE_DESCRIPTOR (uppModalFilterProcInfo, modaldialogcallback);
1143 #endif
1144
1145 static short runmodaldialog (void) {
1146
1147 short itemnumber;
1148 #if TARGET_API_MAC_CARBON == 1
1149 ModalFilterUPP filter = NewModalFilterUPP(modaldialogcallback);
1150 #else
1151 ModalFilterUPP filter = &modalfilterdesc;
1152 #endif
1153
1154 setcursortype (cursorisarrow);
1155
1156 shellmodaldialogmenuadjust ();
1157
1158 #if flcomponent && !TARGET_API_MAC_CARBON
1159 {
1160 long appA5 = SetUpCurA5 (); /*for system*/
1161
1162 ModalDialog (filter, &itemnumber);
1163
1164 RestoreA5 (appA5);
1165 }
1166 #else
1167
1168 //while(itemnumber != 1 && itemnumber != 2 && itemnumber != 3)
1169 // {
1170 ModalDialog (filter, &itemnumber);
1171 // }
1172 #endif
1173 #if TARGET_API_MAC_CARBON == 1
1174 DisposeModalFilterUPP(filter);
1175 #endif
1176 shellforcemenuadjust ();
1177
1178 return (itemnumber);
1179 } /*runmodaldialog*/
1180
1181 #endif
1182
1183 #if !flruntime
1184
1185 void dialogupdate (EventRecord *event, DialogPtr pdialog) {
1186
1187 /*
1188 for modeless dialogs, we can't use DialogSelect here, because we're
1189 being called within a Begin/EndUpdate pair
1190 */
1191
1192 short item;
1193 //Code change by Timothy Paustian Sunday, April 30, 2000 10:16:35 PM
1194 //Changed to Opaque call for Carbon
1195 //who ever calls this, it is only references from langdialogupdate and that is not
1196 //called in Frontier as far as I can see. I bet it is called as a call back, but I
1197 //haven't found out how.
1198 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
1199 CGrafPtr thePort;
1200 RgnHandle dialRgn = NewRgn();
1201 thePort = GetDialogPort(pdialog);
1202 dialRgn = GetPortVisibleRegion(thePort, dialRgn);
1203 UpdateDialog (pdialog, dialRgn);
1204 //Code change by Timothy Paustian Friday, September 15, 2000 9:01:04 PM
1205 //Mac OS X uses double buffered windows. If you are not calling WaitNextEvent
1206 //you have to tell the OS to flush the contents of the offscreen buffer
1207 //to the screen. Use QDFlushPortBuffer to do this.
1208 QDFlushPortBuffer(thePort, dialRgn);
1209 DisposeRgn(dialRgn);
1210 #else
1211 //old code
1212 UpdateDialog (pdialog, (*pdialog).visRgn);
1213 #endif
1214
1215 modaldialogcallback (pdialog, event, &item);
1216 } /*dialogupdate*/
1217
1218
1219 boolean dialogevent (EventRecord *event, DialogPtr pdialog, short *itemnumber) {
1220
1221 /*
1222 if the event refers to an item in pdialog's item list, return the item number
1223 and true, otherwise return false.
1224 */
1225
1226 DialogPtr dlog;
1227
1228 if (pdialog == nil) /*no dialog open*/
1229 return (false);
1230
1231 if (!IsDialogEvent (event))
1232 return (false);
1233
1234 if (modaldialogcallback (pdialog, event, itemnumber)) /*special keystroke*/
1235 return (true);
1236
1237 if (!DialogSelect (event, &dlog, itemnumber))
1238 return (false);
1239
1240 return (dlog == pdialog); /*click in another dialog?*/
1241 } /*dialogevent*/
1242
1243
1244 boolean dialogidle (DialogPtr pdialog) {
1245
1246 TEHandle hbuffer;
1247
1248 dialoggeteditbuffer (pdialog, &hbuffer);
1249
1250 if (hbuffer != nil)
1251 TEIdle (hbuffer);
1252
1253 return (true);
1254 } /*dialogidle*/
1255
1256
1257 boolean dialogactivate (DialogPtr pdialog, boolean flactivate) {
1258
1259 TEHandle hbuffer;
1260
1261 dialoggeteditbuffer (pdialog, &hbuffer);
1262
1263 if (hbuffer != nil) {
1264
1265 if (flactivate)
1266 TEActivate (hbuffer);
1267 else
1268 TEDeactivate (hbuffer);
1269 }
1270
1271 return (true);
1272 } /*dialogactivate*/
1273
1274
1275 boolean dialoggetselect (DialogPtr pdialog, short *startsel, short *endsel) {
1276
1277 TEHandle hbuffer;
1278
1279 dialoggeteditbuffer (pdialog, &hbuffer);
1280
1281 if (hbuffer != nil) {
1282
1283 *startsel = (**hbuffer).selStart + 1;
1284
1285 *endsel = (**hbuffer).selEnd + 1;
1286 }
1287
1288 return (true);
1289 } /*dialoggetselect*/
1290
1291 #endif
1292
1293 boolean dialogsetselect (DialogPtr pdialog, short startsel, short endsel) {
1294
1295 TEHandle hbuffer;
1296 if (pdialog == nil) return false;
1297
1298
1299
1300 dialoggeteditbuffer (pdialog, &hbuffer);
1301
1302 if (hbuffer != nil)
1303 TESetSelect (startsel, endsel, hbuffer);
1304
1305
1306 return (true);
1307 } /*dialogsetselect*/
1308
1309
1310 boolean dialogselectall (DialogPtr pdialog) {
1311
1312 OSStatus err = noErr;
1313
1314 #if TARGET_API_MAC_CARBON == 1
1315 WindowClass wclass;
1316
1317 /* 12/9/2004 smd: use carbon's casting function, as "(WindowRef)pdialog" doesn't work */
1318 WindowPtr pwin = GetDialogWindow (pdialog);
1319
1320 err = GetWindowClass (pwin, &wclass);
1321 if (err==noErr) {
1322 if (wclass == kModalWindowClass) {
1323 // it's a dialog
1324 return (dialogsetselect (pdialog, 0, infinity));
1325 } else if (wclass == kDocumentWindowClass) {
1326
1327 // it's not a dialog, it's an olde-tyme window. The Find window, for example.
1328 return (dialogsetselect (GetDialogFromWindow (pwin), 0, infinity));
1329 }
1330
1331 } /*dialogselectall*/
1332 return 0;
1333 #else
1334 return (dialogsetselect (pdialog, 0, infinity));
1335 #endif
1336 }
1337
1338 #if 1 // !flruntime -- we can rely on the linker to omit these now
1339
1340 short savedialog (bigstring bsfname) {
1341
1342 /*
1343 returns 1, 2 or 3.
1344
1345 if the user said yes, save the changes, the result is 1.
1346
1347 if the user said no, discard the changes, the result is 2.
1348
1349 if the user said cancel, continue editing, the result is 3.
1350
1351 12/20/91 dmb: if file name is nil, just prompt for quit
1352
1353 1/3/92 dmb: removed code for quit dialog
1354 */
1355
1356 register DialogPtr pdialog;
1357 register short itemnumber;
1358
1359 /*
1360 register short id;
1361
1362 if (bsfname == nil) /%file wasn't dirty; just want to confirm Quit%/
1363 id = quitdialogid;
1364 else
1365 id = savedialogid;
1366
1367 if ((pdialog = newmodaldialog (id, saveyesitem)) == nil)
1368 return (1);
1369 */
1370
1371 if ((pdialog = newmodaldialog (savedialogid, saveyesitem)) == nil)
1372 return (1);
1373
1374 ParamText (bsfname, nil, nil, nil);
1375 #if TARGET_API_MAC_CARBON == 1
1376 {
1377 WindowRef pWind = GetDialogWindow(pdialog);
1378 ShowWindow(pWind);
1379 }
1380 #else
1381 ShowWindow (pdialog);
1382 #endif
1383
1384 itemnumber = runmodaldialog ();
1385
1386 disposemodaldialog (pdialog);
1387
1388 switch (itemnumber) {
1389
1390 case saveyesitem:
1391 return (1);
1392
1393 case savenoitem:
1394 return (2);
1395
1396 case savecancelitem:
1397 return (3);
1398 } /*switch*/
1399
1400 return (1);
1401 } /*savedialog*/
1402
1403
1404 short replacevariabledialog (bigstring bsitem) {
1405
1406 /*
1407 2005-09-26 creedon: changed order of buttons, default is Duplicate which is the safe option
1408 replace use of replacedialogid with threewaydialog function, easier to maintain one dialog resource, than several
1409
1410 return 1 if the user clicked on Replace, 2 if Duplicate, 3 if Cancel.
1411 */
1412
1413 /* register DialogPtr pdialog;
1414
1415 sysbeep ();
1416
1417 ParamText (bsitem, nil, nil, nil);
1418
1419 if ((pdialog = newmodaldialog (replacedialogid, replacereplaceitem)) == nil)
1420 return (1);
1421
1422 #if TARGET_API_MAC_CARBON == 1
1423 {
1424 WindowRef pWind = GetDialogWindow(pdialog);
1425 ShowWindow(pWind);
1426 }
1427 #else
1428 ShowWindow (pdialog);
1429 #endif
1430 itemnumber = runmodaldialog ();
1431
1432 disposemodaldialog (pdialog); */
1433
1434 register short itemnumber;
1435 bigstring bs, prompt;
1436 bigstring nobutton, yesbutton;
1437 boolean fl, flExpertMode = false;
1438
1439 getstringlist (langerrorlist, replaceitemerror, prompt);
1440
1441 parsedialogstring (prompt, bsitem, nil, nil, nil, prompt);
1442
1443 getsystemtablescript (idreplacedialogexpertmode, bs); // "user.prefs.flReplaceDialogExpertMode"
1444
1445 pushhashtable (roottable);
1446
1447 disablelangerror ();
1448
1449 fl = langrunstring (bs, bs);
1450
1451 enablelangerror ();
1452
1453 pophashtable ();
1454
1455 if (fl)
1456 stringisboolean (bs, &flExpertMode);
1457
1458 if (flExpertMode) {
1459 copystring (duplicatebuttontext, nobutton);
1460 copystring (replacebuttontext, yesbutton);
1461 }
1462 else {
1463 copystring (duplicatebuttontext, yesbutton);
1464 copystring (replacebuttontext, nobutton);
1465 }
1466
1467 itemnumber = threewaydialog (prompt, yesbutton, nobutton, cancelbuttontext);
1468
1469 if (!flExpertMode)
1470 switch (itemnumber) {
1471
1472 case 1:
1473 itemnumber = 2;
1474
1475 break;
1476
1477 case 2:
1478 itemnumber = 1;
1479 break;
1480
1481 }
1482
1483 switch (itemnumber) {
1484
1485 case replacereplaceitem:
1486 return (1);
1487
1488 case replaceduplicateitem:
1489 return (2);
1490
1491 case replacecancelitem:
1492 return (3);
1493 } /*switch*/
1494
1495 return (1);
1496 } /*replacevariabledialog*/
1497
1498
1499 boolean revertdialog (bigstring bsfname) {
1500
1501 /*
1502 put up the standard "revert" dialog, with the provided file name and return
1503 true if the user clicked on ok. false if cancel was clicked.
1504 */
1505
1506 register DialogPtr pdialog;
1507 register short itemnumber;
1508
1509 ParamText (bsfname, nil, nil, nil);
1510
1511 if ((pdialog = newmodaldialog (revertdialogid, revertokitem)) == nil)
1512 return (false);
1513 #if TARGET_API_MAC_CARBON == 1
1514 {
1515 WindowRef pWind = GetDialogWindow(pdialog);
1516 ShowWindow(pWind);
1517 }
1518 #else
1519 ShowWindow (pdialog);
1520 #endif
1521 itemnumber = runmodaldialog ();
1522
1523 disposemodaldialog (pdialog);
1524
1525 return (itemnumber == revertokitem);
1526 } /*revertdialog*/
1527
1528
1529 boolean askdialog (bigstring bsprompt, bigstring bsanswer) {
1530
1531 /*
1532 put up the standard "ask" dialog, with the provided prompt and return
1533 true if the user clicked on ok. the answer is in bsanswer.
1534 */
1535
1536 register DialogPtr pdialog;
1537 register short itemnumber;
1538
1539 ParamText (bsprompt, nil, nil, nil);
1540
1541 if ((pdialog = newmodaldialog (askdialogid, askokitem)) == nil)
1542 return (false);
1543
1544 setdialogtext (pdialog, askansweritem, bsanswer);
1545
1546 // selectdialogtext (pdialog, askansweritem);
1547
1548 #if TARGET_API_MAC_CARBON == 1
1549 {
1550 WindowRef pWind = GetDialogWindow(pdialog);
1551 ShowWindow(pWind);
1552
1553 }
1554 #else
1555 ShowWindow (pdialog);
1556 #endif
1557
1558 #if TARGET_API_MAC_CARBON == 1
1559
1560 while (true) {
1561
1562 #endif
1563
1564 itemnumber = runmodaldialog ();
1565
1566 #if TARGET_API_MAC_CARBON == 1
1567
1568 if (itemnumber == askokitem || itemnumber == askcancelitem)
1569 break;
1570
1571 } /*while*/
1572
1573 #endif
1574
1575 getdialogtext (pdialog, askansweritem, bsanswer);
1576
1577 disposemodaldialog (pdialog);
1578
1579 return (itemnumber == askokitem);
1580 } /*askdialog*/
1581
1582
1583 boolean twowaydialog (bigstring bsprompt, bigstring okbutton, bigstring cancelbutton) {
1584
1585 register DialogPtr pdialog;
1586 register short item;
1587
1588 if ((pdialog = newmodaldialog (twowaydialogid, twowayokitem)) == nil)
1589 return (false);
1590
1591 setdialogtext (pdialog, twowaymsgitem, bsprompt);
1592
1593 dialogsetbuttonstring (pdialog, twowayokitem, okbutton);
1594
1595 dialogsetbuttonstring (pdialog, twowaycancelitem, cancelbutton);
1596
1597 #if TARGET_API_MAC_CARBON == 1
1598 {
1599 WindowRef pWind = GetDialogWindow(pdialog);
1600 ShowWindow(pWind);
1601 }
1602 #else
1603 ShowWindow (pdialog);
1604 #endif
1605
1606 item = runmodaldialog ();
1607
1608 disposemodaldialog (pdialog);
1609
1610 return (item == twowayokitem);
1611 } /*twowaydialog*/
1612
1613
1614 short threewaydialog (bigstring bsprompt, bigstring yesbutton, bigstring nobutton, bigstring cancelbutton) {
1615
1616 register DialogPtr pdialog;
1617 register short item;
1618
1619 if ((pdialog = newmodaldialog (threewaydialogid, threewayyesitem)) == nil)
1620 return (false);
1621
1622 setdialogtext (pdialog, threewaymsgitem, bsprompt);
1623
1624 dialogsetbuttonstring (pdialog, threewaycancelitem, cancelbutton);
1625
1626 dialogsetbuttonstring (pdialog, threewaynoitem, nobutton);
1627
1628 dialogsetbuttonstring (pdialog, threewayyesitem, yesbutton);
1629
1630 #if TARGET_API_MAC_CARBON == 1
1631 {
1632 WindowRef pWind = GetDialogWindow(pdialog);
1633 ShowWindow(pWind);
1634 }
1635 #else
1636 ShowWindow (pdialog);
1637 #endif
1638 item = runmodaldialog ();
1639
1640 disposemodaldialog (pdialog);
1641
1642 switch (item) {
1643
1644 case threewaycancelitem:
1645 return (3);
1646
1647 case threewaynoitem:
1648 return (2);
1649
1650 case threewayyesitem:
1651 default:
1652 return (1);
1653 } /*switch*/
1654 } /*threewaydialog*/
1655
1656
1657 boolean intdialog (bigstring bsprompt, short *intval) {
1658
1659 register DialogPtr pdialog;
1660 register short itemnumber;
1661 bigstring bs;
1662
1663 if ((pdialog = newmodaldialog (intdialogid, intokitem)) == nil)
1664 return (false);
1665
1666 setdialogtext (pdialog, intpromptitem, bsprompt);
1667
1668 shorttostring (*intval, bs);
1669
1670 setdialogtext (pdialog, intintitem, bs);
1671
1672 selectdialogtext (pdialog, intintitem);
1673
1674 #if TARGET_API_MAC_CARBON == 1
1675 {
1676 WindowRef pWind = GetDialogWindow(pdialog);
1677 ShowWindow(pWind);
1678 }
1679 #else
1680 ShowWindow (pdialog);
1681 #endif
1682 itemnumber = runmodaldialog ();
1683
1684 getdialogtext (pdialog, intintitem, bs);
1685
1686 stringtoshort (bs, intval);
1687
1688 disposemodaldialog (pdialog);
1689
1690 return (itemnumber == intokitem);
1691 } /*intdialog*/
1692
1693
1694 boolean chardialog (bigstring bsprompt, short *charval) {
1695
1696 register DialogPtr pdialog;
1697 register char ch;
1698 register short itemnumber;
1699 bigstring bs;
1700
1701 if ((pdialog = newmodaldialog (chardialogid, charokitem)) == nil)
1702 return (false);
1703
1704 setdialogtext (pdialog, charpromptitem, bsprompt);
1705
1706 setstringwithchar (*charval, bs);
1707
1708 setdialogtext (pdialog, charvalitem, bs);
1709
1710 selectdialogtext (pdialog, charvalitem);
1711
1712 #if TARGET_API_MAC_CARBON == 1
1713 {
1714 WindowRef pWind = GetDialogWindow(pdialog);
1715 ShowWindow(pWind);
1716 }
1717 #else
1718 ShowWindow (pdialog);
1719 #endif
1720 while (true) {
1721
1722 itemnumber = runmodaldialog ();
1723
1724 getdialogtext (pdialog, charvalitem, bs);
1725
1726 if (isemptystring (bs))
1727 ch = chnul;
1728 else
1729 ch = bs [1];
1730
1731 ch = uppercasechar (ch); /*cmd-keystrokes must be uppercase*/
1732
1733 switch (itemnumber) {
1734
1735 case charokitem: case charcancelitem:
1736 *charval = ch;
1737
1738 disposemodaldialog (pdialog);
1739
1740 return (itemnumber == charokitem);
1741
1742 default:
1743 setstringwithchar (ch, bs);
1744
1745 setdialogtext (pdialog, charvalitem, bs);
1746
1747 selectdialogtext (pdialog, charvalitem);
1748
1749 break;
1750 }
1751 }
1752 } /*chardialog*/
1753
1754 #endif
1755
1756
1757 boolean msgdialog (bigstring bsprompt) {
1758
1759 /*
1760 put up the standard "msg" dialog, with the provided prompt and return
1761 true if the user clicked on ok. false if cancel was clicked.
1762 */
1763
1764 register DialogPtr pdialog;
1765 register short itemnumber;
1766
1767 if ((pdialog = newmodaldialog (msgdialogid, msgokitem)) == nil) /*error; assume OK*/
1768 return (true);
1769
1770 setdialogtext (pdialog, msgmsgitem, bsprompt);
1771
1772 #if TARGET_API_MAC_CARBON == 1
1773 {
1774 WindowRef pWind = GetDialogWindow(pdialog);
1775 ShowWindow(pWind);
1776 }
1777 #else
1778 ShowWindow (pdialog);
1779 #endif
1780 itemnumber = runmodaldialog ();
1781
1782 disposemodaldialog (pdialog);
1783
1784 return (itemnumber == msgokitem);
1785 } /*msgdialog*/
1786
1787
1788 short customalert (short id, bigstring bsprompt) {
1789
1790 /*
1791 put up the dialog with the indicated id, and run it.
1792
1793 **** currently using DisposDialog so it can be called from standard file;
1794 frontshellwindow should be smarter!
1795 */
1796
1797 register DialogPtr pdialog;
1798 register short itemnumber;
1799
1800 if ((pdialog = newmodaldialog (id, 1)) == nil)
1801 return (0);
1802
1803 setdialogtext (pdialog, 2, bsprompt);
1804
1805 #if TARGET_API_MAC_CARBON == 1
1806 {
1807 WindowRef pWind = GetDialogWindow(pdialog);
1808 ShowWindow(pWind);
1809 }
1810 #else
1811 ShowWindow (pdialog); /*make sure it's visible now that values are set*/
1812 #endif
1813 itemnumber = runmodaldialog ();
1814
1815 DisposeDialog (pdialog);
1816
1817 return (itemnumber);
1818 } /*customalert*/
1819
1820
1821 boolean alertdialog (bigstring bsprompt) {
1822
1823 /*
1824 put up the standard "alert" dialog, with the provided prompt and return
1825 true if the user clicked on ok. false if cancel was clicked.
1826 */
1827
1828 register DialogPtr pdialog;
1829 register short itemnumber;
1830
1831 sysbeep ();
1832
1833 if ((pdialog = newmodaldialog (alertdialogid, alertokitem)) == nil)
1834 return (false);
1835
1836 setdialogtext (pdialog, alertmsgitem, bsprompt);
1837
1838 #if TARGET_API_MAC_CARBON == 1
1839 {
1840 WindowRef pWind = GetDialogWindow(pdialog);
1841 ShowWindow(pWind);
1842 }
1843 #else
1844 ShowWindow (pdialog);
1845 #endif
1846 itemnumber = runmodaldialog ();
1847
1848 disposemodaldialog (pdialog);
1849
1850 return (itemnumber == alertokitem);
1851 } /*alertdialog*/
1852
1853
1854 boolean alertstring (short iderror) {
1855
1856 bigstring bs;
1857
1858 getstringlist (alertstringlistnumber, iderror, bs);
1859
1860 return (alertdialog (bs));
1861 } /*alertstring*/
1862
1863
1864 boolean customdialog (short id, short defaultitem, dialogcallback itemhitcallback) {
1865
1866 /*
1867 put up the dialog with the indicated id, and run it until the
1868 callback says we're done.
1869 */
1870
1871 register DialogPtr pdialog;
1872 register short itemnumber;
1873
1874 if ((pdialog = newmodaldialog (id, defaultitem)) == nil)
1875 return (false);
1876
1877 if ((*itemhitcallback) (pdialog, -1)) { /*special value tells callback to initialize fields*/
1878
1879 dialogselectall (pdialog); /*in case there's a text item*/
1880
1881 #if TARGET_API_MAC_CARBON == 1
1882 {
1883 WindowRef pWind = GetDialogWindow(pdialog);
1884 ShowWindow(pWind);
1885 }
1886 #else
1887 ShowWindow (pdialog); /*make sure it's visible now that values are set*/
1888 #endif
1889
1890 while (true) {
1891
1892 itemnumber = runmodaldialog ();
1893
1894 if (!(*itemhitcallback) (pdialog, itemnumber))
1895 break;
1896 }
1897 }
1898
1899 disposemodaldialog (pdialog);
1900
1901 return (true);
1902 } /*customdialog*/
1903
1904
1905 boolean askpassword (bigstring passprompt, bigstring password) {
1906
1907 /*
1908 3.0.1 dmb: if id is not the empty string, start with the password item selected
1909 */
1910
1911 register DialogPtr pdialog;
1912 register short itemnumber;
1913
1914 ParamText (passprompt, nil, nil, nil);
1915
1916 if ((pdialog = newmodaldialog (askdialogid, askokitem)) == nil)
1917 return (false);
1918
1919 setemptystring (password);
1920 #if TARGET_API_MAC_CARBON == 1
1921 {
1922 WindowRef pWind = GetDialogWindow(pdialog);
1923 SetWRefCon (pWind, (long) password);
1924 }
1925 #else
1926
1927 SetWRefCon (pdialog, (long) password);
1928
1929 #endif
1930
1931 // setdialogtext (pdialog, passworditem, password);
1932 // setdialogtext (pdialog, iditem, id);
1933
1934 setdialogtext (pdialog, askansweritem, password);
1935
1936 //selectdialogtext (pdialog, askansweritem);
1937 #if TARGET_API_MAC_CARBON == 1
1938 {
1939 WindowRef pWind = GetDialogWindow(pdialog);
1940 ShowWindow(pWind);
1941 }
1942 #else
1943 ShowWindow (pdialog);
1944 #endif
1945
1946 passworditem = askansweritem;
1947
1948 #if TARGET_API_MAC_CARBON == 1
1949
1950 while (true) {
1951
1952 #endif
1953
1954 itemnumber = runmodaldialog ();
1955
1956 #if TARGET_API_MAC_CARBON == 1
1957
1958 if (itemnumber == askokitem || itemnumber == askcancelitem)
1959 break;
1960
1961 } /*while*/
1962
1963 #endif
1964
1965 passworditem = -1;
1966
1967 // getdialogtext (pdialog, iditem, id);
1968 // xxx getdialogtext (pdialog, askansweritem, password);
1969
1970 disposemodaldialog (pdialog);
1971
1972 return (itemnumber == askokitem);
1973 } /*askpassword*/
1974
1975
1976 boolean initdialogs (void) {
1977
1978 #ifdef flcomponent
1979 //Code change by Timothy Paustian Sunday, May 7, 2000 11:10:48 PM
1980 //In Carbon this is not needed.
1981 #if !TARGET_CARBON
1982 RememberA5 ();
1983 #endif /*for filters, callbacks*/
1984 #endif
1985
1986 return (true);
1987 } /*dialoginit*/
1988
1989
1990 char X0_p2cstrcpy(char *dst, StringPtr src)
1991 {
1992 register short len = src[0], i;
1993
1994 for(i=0; i<len; i++)
1995 dst[i] = src[i+1];
1996
1997 dst[i] = 0x00;
1998
1999 return (*dst);
2000 }
2001
2002
2003
2004
2005
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.