dialogs.c

Go to the documentation of this file.
00001 
00002 /*  $Id: dialogs.c 1202 2006-04-05 22:52:08Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "quickdraw.h"
00032 #include "bitmaps.h"
00033 #include "cursor.h"
00034 #include "font.h"
00035 #include "launch.h"
00036 #include "kb.h"
00037 #include "memory.h"
00038 #include "resources.h"
00039 #include "scrap.h"
00040 #include "strings.h"
00041 #include "frontierwindows.h"
00042 #include "ops.h"
00043 #include "shell.h"
00044 #include "shellmenu.h"
00045 #include "shell.rsrc.h"
00046 #include "dialogs.h"
00047 #include "lang.h"
00048 #include "mac.h"
00049 #include "langinternal.h" /* 2005-09-26 creedon */
00050 #include "tablestructure.h" /* 2005-09-26 creedon */
00051 
00052 #ifdef flcomponent
00053 
00054     #include <SetUpA5.h>
00055 
00056 #endif
00057 
00058 
00059 #define windowevents (updateMask + activMask)
00060 
00061 
00062 short dialogcountitems (DialogPtr pdialog) {
00063     
00064     //Code change by Timothy Paustian Sunday, April 30, 2000 9:40:09 PM
00065     //Changed to Opaque call for Carbon
00066     //switched to use CountDITL. This has been around since OS 7
00067     return CountDITL(pdialog);
00068     } /*dialogcountitems*/
00069 
00070 
00071 static void dialoggeteditbuffer (DialogPtr pdialog, TEHandle *hbuffer) {
00072     
00073     //Code change by Timothy Paustian Sunday, April 30, 2000 9:43:36 PM
00074     //Changed to Opaque call for Carbon
00075     //check this I need to check to see if this is a memory leak or not. 
00076     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00077         //DialogItemType    itemType = 0;
00078         //Handle                h;
00079         //Rect              r = {0,0,0,0};
00080         //SInt16                whichField = 0;
00081 
00082         *hbuffer = GetDialogTextEditHandle((DialogRef) pdialog);
00083     
00084     #else
00085         //old code
00086         *hbuffer = (*(DialogPeek) pdialog).textH;
00087     #endif
00088     } /*dialoggeteditbuffer*/
00089 
00090 
00091 void boldenbutton (DialogPtr pdialog, short itemnumber) {
00092 
00093     /*
00094     draw a thick black ring around the OK button in the dialog.  
00095     */
00096     
00097     PenState savePen;
00098     short itemtype;
00099     Handle itemhandle;
00100     Rect itemrect;
00101     
00102     //Code change by Timothy Paustian Wednesday, July 12, 2000 12:39:52 PM
00103     //pushport was doing an implicit cast from a dialogPtr to a GrafPtr
00104     //This is allowed in MacOS, but not in carbon. This was causing a crash.
00105     CGrafPtr    thePort;
00106     #if TARGET_API_MAC_CARBON == 1
00107     thePort = GetDialogPort(pdialog);
00108     #else
00109     thePort = (CGrafPtr)pdialog;
00110     #endif
00111         
00112     pushport (thePort);
00113     
00114     GetPenState (&savePen); /*save the old pen state*/
00115     
00116     GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect); /*get the item's rect*/
00117     
00118     insetrect (&itemrect, -4, -4);
00119     
00120     PenSize (3, 3); /*make the pen fatter*/
00121     
00122     FrameRoundRect (&itemrect, 16, 16); /*draw the ring*/
00123 
00124     SetPenState (&savePen); /*restore the pen state*/
00125     
00126     popport ();
00127     } /*boldenbutton*/
00128 
00129 
00130 void positiondialogwindow (DialogPtr pdialog) {
00131 
00132     register short h, v;
00133     Rect rdialog, rscreen;
00134     CGrafPtr    thePort;
00135     
00136     getcurrentscreenbounds (&rscreen);
00137     //Code change by Timothy Paustian Sunday, April 30, 2000 9:44:58 PM
00138     //Changed to Opaque call for Carbon
00139     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00140     thePort = GetDialogPort(pdialog);
00141     GetPortBounds(thePort, &rdialog);
00142     #else
00143     //old code
00144     #pragma unused(thePort)
00145     rdialog = (*pdialog).portRect;
00146     #endif
00147     
00148     h = rscreen.left + (((rscreen.right - rscreen.left) - (rdialog.right - rdialog.left)) / 2);
00149     
00150     v = rscreen.top + (((rscreen.bottom - rscreen.top) - (rdialog.bottom - rdialog.top)) / 3);
00151     
00152     #if TARGET_API_MAC_CARBON == 1
00153     {
00154     WindowPtr theWind = GetDialogWindow(pdialog);
00155     movewindow(theWind, h, v);
00156     }
00157     #else
00158     movewindow (pdialog, h, v);
00159     #endif
00160     } /*positiondialogwindow*/
00161 
00162 
00163 static boolean dialogitemtypeiscontrol (short itemtype) {
00164     
00165     register short x;
00166     
00167     x = itemtype % itemDisable; /*ignore enabledness*/
00168     
00169     return ((x >= ctrlItem) && (x <= (ctrlItem + resCtrl))); 
00170     } /*dialogitemtypeiscontrol*/
00171 
00172 
00173 void disabledialogitem (DialogPtr pdialog, short itemnumber) {
00174     
00175     /*
00176     3/6/91 dmb: also dim if the item is a control
00177     */
00178     
00179     short itemtype;
00180     Handle itemhandle;
00181     Rect itemrect;
00182     
00183     GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect);
00184     
00185     if (itemtype < itemDisable) { /*it is enabled, disable it*/
00186         
00187         SetDialogItem (pdialog, itemnumber, itemtype + itemDisable, itemhandle, &itemrect);
00188         
00189         if (dialogitemtypeiscontrol (itemtype))
00190             HiliteControl ((ControlHandle) itemhandle, 255);
00191         }
00192     } /*disabledialogitem*/
00193 
00194 
00195 void enabledialogitem (DialogPtr pdialog, short itemnumber) {
00196     
00197     short itemtype;
00198     Handle itemhandle;
00199     Rect itemrect;
00200     
00201     GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect);
00202     
00203     if (itemtype >= itemDisable) { /*it is disabled, enable it*/
00204         
00205         SetDialogItem (pdialog, itemnumber, itemtype - itemDisable, itemhandle, &itemrect);
00206         
00207         if (dialogitemtypeiscontrol (itemtype))
00208             HiliteControl ((ControlHandle) itemhandle, 0);
00209         }
00210     } /*enabledialogitem*/
00211 
00212 
00213 void hidedialogitem (DialogPtr pdialog, short itemnumber) {
00214     
00215     HideDialogItem (pdialog, itemnumber);
00216     } /*hidedialogitem*/
00217     
00218 
00219 void showdialogitem (DialogPtr pdialog, short itemnumber) {
00220     
00221     ShowDialogItem (pdialog, itemnumber);
00222     } /*showdialogitem*/
00223     
00224 
00225 void setdefaultitem (DialogPtr pdialog, short defaultitem) {
00226     
00227     //Code change by Timothy Paustian Sunday, April 30, 2000 9:47:39 PM
00228     //Changed to Opaque call for Carbon
00229     SetDialogDefaultItem(pdialog, defaultitem);
00230     //old code
00231     //(*(DialogPeek) pdialog).aDefItem = defaultitem; /*filter will bolden this*/
00232     } /*setdefaultitem*/
00233 
00234 
00235 static boolean dialogitemisenabled (DialogPtr pdialog, short item) {
00236     
00237     short itemtype;
00238     Handle itemhandle;
00239     Rect itemrect;
00240     
00241     GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
00242     
00243     return ((itemtype & itemDisable) == 0);
00244     } /*dialogitemisenabled*/
00245 
00246 
00247 boolean dialogitemisbutton (DialogPtr pdialog, short item) {
00248     
00249     short itemtype;
00250     Handle itemhandle;
00251     Rect itemrect;
00252     
00253     if (item <= 0)
00254         return (false);
00255     
00256     GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
00257     
00258     return (dialogitemtypeiscontrol (itemtype));
00259     } /*dialogitemisbutton*/
00260     
00261 
00262 static boolean dialogitemisedittext (DialogPtr pdialog, short item) {
00263     
00264     short itemtype;
00265     Handle itemhandle;
00266     Rect itemrect;
00267     
00268     GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
00269     
00270     return (itemtype & editText); 
00271     } /*dialogitemisedittext*/
00272     
00273 
00274 static boolean dialoghasedititems (DialogPtr pdialog) {
00275     
00276     register short i;
00277     register short ctitems;
00278     
00279     ctitems = dialogcountitems (pdialog);
00280     
00281     for (i = 1; i <= ctitems; i++) 
00282         if (dialogitemisedittext (pdialog, i))
00283             return (true);
00284     
00285     return (false);
00286     } /*dialoghasedititems*/
00287 
00288 
00289 static void dialoggetbuttonstring (DialogPtr pdialog, short item, bigstring bs) {
00290     
00291     short itemtype;
00292     Handle itemhandle;
00293     Rect itemrect;
00294     //Code change by Timothy Paustian Sunday, April 30, 2000 9:57:08 PM
00295     //Changed to Opaque call for Carbon
00296     ControlRef  theControl;
00297     Str255      controlTitle;
00298     
00299     GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
00300     //Code change by Timothy Paustian Sunday, April 30, 2000 9:57:41 PM
00301     //Changed to Opaque call for Carbon
00302     //watch this one. What happens if this is a bad cast to a ControlRef?
00303     theControl = (ControlRef) itemhandle;
00304     GetControlTitle(theControl, controlTitle);
00305     copystring (controlTitle, bs);
00306     //old code
00307     //copystring ((**(ControlRef) itemhandle).contrlTitle, bs);
00308     } /*dialoggetbuttonstring*/
00309 
00310 
00311 static void dialogsetbuttonstring (DialogPtr pdialog, short item, bigstring bs) {
00312     
00313     short itemtype;
00314     Handle itemhandle;
00315     Rect itemrect;
00316 
00317     GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
00318     
00319     SetControlTitle ((ControlHandle) itemhandle, bs);
00320     } /*dialogsetbuttonstring*/
00321 
00322 
00323 DialogPtr newmodaldialog (short id, short defaultitem) {
00324     
00325     /*
00326     2/7/92 dmb: if dialoghasedititems, force shell to export scrap
00327     
00328     2/10/92 dmb: added call to new shellactivate
00329     
00330     3.0.1b1 dmb: don't call shellactivate if the dialog isn't of a modal 
00331     design, i.e. a dBoxProc window. currently, the only case where 
00332     this isn't so is Frontier's about window / splash screen.  having 
00333     the splash screen force Frontier to the front is bad news for 
00334     background launching. it even crashes! 
00335     */
00336     
00337     register DialogPtr pdialog;
00338     long appA5;
00339     
00340     #ifdef fldebug
00341     
00342     if (GetResource ('DLOG', id) == nil)
00343         DebugStr ("\pmissing DLOG resource");
00344     
00345     #endif
00346     
00347     #ifdef flcomponent
00348     
00349     appA5 = SetUpCurA5 ();
00350     
00351     #endif
00352     
00353     pdialog = GetNewDialog (id, nil, (WindowRef) -1L);
00354     
00355     #ifdef flcomponent
00356     
00357     RestoreA5 (appA5);
00358     
00359     #endif
00360     
00361     if (pdialog == nil) 
00362         return (nil);
00363     
00364     positiondialogwindow (pdialog);
00365     
00366     setdefaultitem (pdialog, defaultitem);
00367     
00368     if (dialoghasedititems (pdialog))
00369         shellwritescrap (textscraptype);
00370     
00371     #if TARGET_API_MAC_CARBON == 1
00372     {
00373     WindowPtr   theWind = GetDialogWindow(pdialog);
00374     if (GetWVariant (theWind) == dBoxProc) /*make sure we're in front before posting modal dialog*/
00375         shellactivate ();
00376     }
00377     #else
00378     if (GetWVariant (pdialog) == dBoxProc) /*make sure we're in front before posting modal dialog*/
00379         shellactivate ();
00380     #endif
00381     return (pdialog);
00382     } /*newmodaldialog*/
00383 
00384 
00385 void disposemodaldialog (DialogPtr pdialog) {
00386     
00387     /*
00388     7/20/92 dmb: don't do partial event loop for runtime.
00389     
00390     1/21/93 dmb: use langpartialeventloop when a script is running
00391     
00392     2.1b dmb: if this was an out-of-memory alert, the partial event loop is 
00393     bad news. it's always tende to cause problems, so and shouldn't really 
00394     be necessary. so let's just not do it!
00395     */
00396     
00397     DisposeDialog (pdialog);
00398     
00399     #if 0 //ndef flruntime
00400     
00401         /*handle all pending activate & update events*/
00402         
00403         if (flscriptrunning)
00404             langpartialeventloop (windowevents);
00405         else
00406             shellpartialeventloop (windowevents);
00407     
00408     #endif
00409     } /*disposemodaldialog*/
00410 
00411 
00412 void setdialogcheckbox (DialogPtr pdialog, short item, boolean fl) {
00413 
00414     /*
00415     change the value of the checkbox.
00416     */
00417 
00418     short itemtype;
00419     Rect itemrect;
00420     Handle itemhandle;
00421     
00422     GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
00423         
00424     SetControlValue ((ControlHandle) itemhandle, fl);
00425     } /*setdialogcheckbox*/
00426 
00427 
00428 boolean getdialogcheckbox (DialogPtr pdialog, short item) {
00429 
00430     /*
00431     get the value of the checkbox, either a 1 or a 0.
00432     */
00433 
00434     short itemtype;
00435     Rect itemrect;
00436     Handle itemhandle;
00437     
00438     GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
00439     
00440     return (bitboolean (GetControlValue ((ControlHandle) itemhandle)));
00441     } /*getdialogcheckbox*/
00442 
00443 
00444 void toggledialogcheckbox (DialogPtr pdialog, short item) {
00445 
00446     /*
00447     if the checkbox is on, turn it off, and vice versa.
00448     */
00449 
00450     short itemtype;
00451     Rect itemrect;
00452     Handle itemhandle;
00453     
00454     GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
00455     
00456     SetControlValue ((ControlHandle) itemhandle, !GetControlValue ((ControlHandle) itemhandle));
00457     } /*toggledialogcheckbox*/
00458 
00459 
00460 boolean setdialogradiovalue (DialogPtr pdialog, short firstitem, short lastitem, short val) {
00461 
00462     /*
00463     set the value of the radio button range.  val is zero-based; valid 
00464     values range from zero to (firstitem - lastitem)
00465     */
00466     
00467     register short item;
00468     register boolean flon;
00469     
00470     for (item = firstitem; item <= lastitem; ++item) {
00471         
00472         flon = val == (item - firstitem);
00473         
00474         if (flon != getdialogcheckbox (pdialog, item))
00475             setdialogcheckbox (pdialog, item, flon);
00476         }
00477     
00478     return (true);
00479     } /*getdialogradiovalue*/
00480 
00481 
00482 short getdialogradiovalue (DialogPtr pdialog, short firstitem, short lastitem) {
00483     
00484     /*
00485     set the value of the radio button range.  val is zero-based; returned 
00486     value will range from zero to (firstitem - lastitem).
00487     
00488     if none of the radio buttons are set, returns -1.
00489     */
00490     
00491     register short item;
00492     
00493     for (item = firstitem; item <= lastitem; ++item) {
00494         
00495         if (getdialogcheckbox (pdialog, item))
00496             return (item - firstitem);
00497         }
00498     
00499     return (-1);
00500     } /*getdialogradiovalue*/
00501 
00502 
00503 void getdialogtext (DialogPtr pdialog, short itemnumber, bigstring bs) {
00504     
00505     short itemtype;
00506     Handle itemhandle;
00507     Rect itemrect;
00508     
00509     GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect);
00510     GetDialogItemText (itemhandle, bs);
00511     
00512     } /*getdialogtext*/
00513 
00514 
00515 static void dialogscanspecialchars (bigstring bs) {
00516 
00517     register short i, ct;
00518     
00519     ct = stringlength (bs);
00520     
00521     for (i = 1; i <= ct; i++) {
00522         
00523         register char ch = bs [i];
00524         
00525         if (ch == '') /*option-R maps to the return char*/
00526             ch = chreturn;
00527             
00528         bs [i] = ch;
00529         } /*for*/
00530     } /*dialogscanspecialchars*/
00531     
00532 #if !flruntime
00533 
00534 void setdialogicon (DialogPtr pdialog, short itemnumber, short iconnum) {
00535     
00536     Handle hicon;
00537     short itemtype;
00538     Handle itemhandle;
00539     Rect itemrect;
00540 
00541     hicon = GetIcon (iconnum); 
00542     
00543     if (hicon != nil) {
00544     
00545         GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect);
00546     
00547         SetDialogItem (pdialog, itemnumber, itemtype, hicon, &itemrect);
00548         }
00549     } /*setdialogicon*/
00550     
00551 #endif
00552 
00553 void setdialogtext (DialogPtr pdialog, short itemnumber, bigstring bs) {
00554     
00555     /*
00556     6/12/92 dmb: if the item is the active text item, select the new text
00557     */
00558     
00559     OSStatus err = noErr;   
00560     short itemtype;
00561     Handle itemhandle;
00562     Rect itemrect;
00563     char    s[256];
00564     ControlRef  C;
00565     dialogscanspecialchars (bs);
00566     
00567     
00568     GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect);
00569     SetDialogItemText (itemhandle, bs); 
00570 err = GetDialogItemAsControl (pdialog,itemnumber,&C);
00571 if (err==noErr) {
00572         X0_p2cstrcpy(s,bs);
00573     err = SetControlData (C,kControlEditTextPart,kControlEditTextTextTag,strlen(s),s);
00574     }
00575 
00576     
00577     //Code change by Timothy Paustian Sunday, April 30, 2000 10:02:10 PM
00578     //Changed to Opaque call for Carbon
00579     //change to use a new routine that finds the item in focus
00580 
00581     if (itemnumber == GetDialogKeyboardFocusItem(pdialog))
00582         dialogselectall (pdialog);
00583 
00584 
00585     //old code
00586     //if (itemnumber == (*(DialogPeek) pdialog).editField + 1) /*6/12/92*/
00587     //  dialogselectall (pdialog);
00588     
00589     /*closebitmap (pdialog);*/
00590     } /*setdialogtext*/
00591 
00592 
00593 void selectdialogtext (DialogPtr pdialog, short itemnumber) {
00594     OSStatus err = noErr;
00595     ControlRef  C;
00596     ControlEditTextSelectionRec    selection = { 0, 32000 };
00597 //  SelectDialogItemText (pdialog, itemnumber, 0, infinity); /*select all text*/
00598     
00599     err = GetDialogItemAsControl (pdialog,itemnumber,&C);
00600     if (err==noErr) {
00601         err = SetControlData(C, kControlEntireControl,kControlEditTextSelectionTag, sizeof(ControlEditTextSelectionRec),&selection);
00602     } else SelectDialogItemText (pdialog, itemnumber, 0, infinity); /*select all text*/
00603     
00604 }
00605 
00606 
00607 
00608 short getdialogint (DialogPtr pdialog, short itemnumber) {
00609     
00610     /*
00611     get an integer from an edittext item in the dialog.
00612     */
00613     
00614     bigstring bs;
00615     long num;
00616     
00617     getdialogtext (pdialog, itemnumber, bs);
00618     
00619     stringtonumber (bs, &num);
00620     
00621     return ((short) num);
00622     } /*getdialogint*/
00623     
00624     
00625 void setdialogint (DialogPtr pdialog, short itemnumber, short num) {
00626     
00627     bigstring bs;
00628     
00629     NumToString (num, bs);
00630     
00631     setdialogtext (pdialog, itemnumber, bs);
00632     } /*setdialogint*/
00633     
00634     
00635 OSType getdialogostype (DialogPtr pdialog, short itemnumber) {
00636     
00637     /*
00638     get an OSType from an edittext item.
00639     */
00640     
00641     bigstring bs;
00642     OSType type;
00643     
00644     getdialogtext (pdialog, itemnumber, bs);
00645     
00646     stringtoostype (bs, &type);
00647     
00648     return (type);
00649     } /*getdialogostype*/
00650     
00651     
00652 void setdialogostype (DialogPtr pdialog, short itemnumber, OSType type) {
00653     
00654     bigstring bs;
00655     
00656     ostypetostring (type, bs);
00657     
00658     setdialogtext (pdialog, itemnumber, bs);
00659     } /*setdialogostype*/
00660     
00661     
00662 void setdialogbutton (DialogPtr pdialog, short itemnumber, bigstring bs) {
00663     
00664     /*
00665     6/11/93 dmb: don't use bitmaps; doesn't work on SF buttons
00666     */
00667     
00668     short itemtype;
00669     Handle itemhandle;
00670     Rect r;
00671     
00672     GetDialogItem (pdialog, itemnumber, &itemtype, &itemhandle, &r);
00673     
00674     /*
00675     openbitmapcopy (r, pdialog);
00676     */
00677     
00678     SetControlTitle ((ControlHandle) itemhandle, bs);
00679     
00680     /*
00681     closebitmap (pdialog);
00682     
00683     validrect (r);
00684     */
00685     } /*setdialogbutton*/
00686     
00687 
00688 void dialoggetobjectrect (DialogPtr pdialog, short objectnumber, Rect *r) {
00689 
00690     short itemtype;
00691     Handle itemhandle;
00692     
00693     GetDialogItem (pdialog, objectnumber, &itemtype, &itemhandle, r);
00694     } /*dialoggetobjectrect*/
00695     
00696     
00697 void dialogsetobjectrect (DialogPtr pdialog, short objectnumber, Rect r) {
00698 
00699     short itemtype;
00700     Handle itemhandle;
00701     Rect itemrect;
00702     
00703     GetDialogItem (pdialog, objectnumber, &itemtype, &itemhandle, &itemrect);
00704     
00705     SetDialogItem (pdialog, objectnumber, itemtype, itemhandle, &r);
00706     
00707     if (itemtype & editText) { /*it's an edittext item, set its rects and wordwrap*/
00708         
00709         TEHandle hbuffer;
00710         
00711         dialoggeteditbuffer (pdialog, &hbuffer);
00712         
00713         (**hbuffer).viewRect = r;
00714         
00715         (**hbuffer).destRect = r;
00716         
00717         TECalText (hbuffer);
00718         }
00719     } /*dialogsetobjectrect*/
00720     
00721 #if !flruntime
00722 
00723 boolean dialogsetfontsize (DialogPtr pdialog, short font, short size) {
00724     
00725     /*
00726     2.1b9 dmb: including leading in line height calculation
00727     */
00728     
00729     TEHandle hbuffer;
00730     register TEHandle h;
00731     
00732     dialoggeteditbuffer (pdialog, &hbuffer);
00733     
00734     h = hbuffer; /*copy into register*/
00735     
00736     (**h).txFont = font;
00737     
00738     (**h).txSize = size;
00739     
00740     pushstyle (font, size, 0);
00741     
00742     (**h).fontAscent = globalfontinfo.ascent;
00743     
00744     (**h).lineHeight = globalfontinfo.ascent + globalfontinfo.descent + globalfontinfo.leading;
00745     
00746     popstyle ();
00747     
00748     TECalText (h);
00749     
00750     return (true);
00751     } /*dialogsetfontsize*/
00752     
00753 
00754 boolean ptinuseritem (Point pt, DialogPtr pdialog, short item) {
00755     
00756     Rect r;
00757     
00758     dialoggetobjectrect (pdialog, item, &r);
00759     
00760     return (pointinrect (pt, r));
00761     } /*ptinuseritem*/
00762     
00763 #endif
00764 
00765 boolean setuseritemdrawroutine (DialogPtr pdialog, short item, dialogcallback drawroutine) {
00766     
00767     short itemtype;
00768     Handle itemhandle;
00769     Rect itemrect;
00770     
00771     GetDialogItem (pdialog, item, &itemtype, &itemhandle, &itemrect);
00772     
00773     assert (itemtype % itemDisable == userItem);
00774     
00775     SetDialogItem (pdialog, item, itemtype, (Handle) drawroutine, &itemrect);
00776     
00777     return (true);
00778     } /*setuseritemdrawroutine*/
00779     
00780 
00781 static void highlightdialogbutton (DialogPtr pdialog, short itemnumber, boolean flon) {
00782     
00783     register DialogPtr p = pdialog;
00784     register short val;
00785     short itemtype;
00786     Handle itemhandle;
00787     Rect itembox;
00788     
00789     if (pdialog == nil) /*defensive driving*/
00790         return;
00791         
00792     GetDialogItem (p, itemnumber, &itemtype, &itemhandle, &itembox);
00793     
00794     if (flon)
00795         val = kControlButtonPart;
00796     else
00797         val = 0;
00798     
00799     HiliteControl ((ControlHandle) itemhandle, val); 
00800     } /*highlightdialogbutton*/
00801 
00802 
00803 static boolean dialogsimulatehit (DialogPtr pdialog, short item) {
00804     
00805     /*
00806     8/26/91 dmb: block event during delay.  otherwise, silly behavior (like 
00807     handling updates) or even crashes (when running a scripted dialog) can
00808     occur
00809     */
00810     
00811     if (dialogitemisbutton (pdialog, item) && dialogitemisenabled (pdialog, item)) {
00812     
00813         highlightdialogbutton (pdialog, item, true);
00814         
00815         shellblockevents (); /*limit background processing during delay*/
00816         
00817         delayticks (8);
00818         
00819         shellpopevents ();
00820         
00821         highlightdialogbutton (pdialog, item, false);
00822         
00823         return (true);
00824         }
00825     
00826     return (false);
00827     } /*dialogsimulatehit*/
00828 
00829 
00830 static boolean dialogmapkeystroke (DialogPtr pdialog, bigstring bsmap, short *item) {
00831     
00832     /*
00833     map a keystroke onto a dialog item.  if no match, return false.
00834     
00835     for buttons, if the keystroke matches the first character of the button name,
00836     we return true with that item.  makes your choice of button names strategic.
00837     
00838     to get the number of items in the list, pull the first two bytes out of the
00839     dialog's itemhandle and add one.  an obvious problem if Apple changes the format
00840     of an item list handle.
00841     
00842     10/10/91 dmb: now take string to map instead of a character.  if bsmap is 
00843     longer than a single character, we look for an exact match (still ignoring case).
00844     
00845     2/7/92 dmb: use dialoghasedititems instead of looping through item list.
00846     */
00847     
00848     register short i;
00849     register boolean flcmdkeyrequired;
00850     short ctitems;
00851     bigstring bs;
00852     boolean flsinglechar;
00853     
00854     alllower (bsmap); /*search is unicase*/
00855     
00856     ctitems = dialogcountitems (pdialog);
00857     
00858     flsinglechar = stringlength (bsmap) == 1;
00859     
00860     if (flsinglechar) { /*mapping a single character -- check command key*/
00861         
00862         flcmdkeyrequired = dialoghasedititems (pdialog);
00863         
00864         if (flcmdkeyrequired && !cmdkeydown ())
00865             return (false);
00866         }
00867     
00868     for (i = 1; i <= ctitems; i++) {
00869         
00870         if (dialogitemisbutton (pdialog, i)) {
00871             
00872             dialoggetbuttonstring (pdialog, i, bs);
00873             
00874             if (stringlength (bs) > 0) {
00875                 
00876                 if (flsinglechar)
00877                     setstringlength (bs, 1);
00878                 
00879                 alllower (bs);
00880                 
00881                 if (equalstrings (bs, bsmap)) {
00882                     
00883                     *item = i;
00884                     
00885                     return (true);
00886                     }
00887                 }   
00888             }
00889         } /*for*/
00890     
00891     return (false); /*no mapping for the character*/
00892     } /*dialogmapkeystroke*/
00893 
00894 
00895 static short passworditem = -1;
00896 
00897 
00898 static void passwordprocesskey (DialogPtr pdialog, char chkb, EventRecord *ev, short *item) {
00899 #pragma unused (item)
00900 
00901     TEHandle hte;
00902     char *buffer;
00903     short start, end;
00904     short len;
00905     //Code change by Timothy Paustian Sunday, April 30, 2000 10:07:30 PM
00906     //Changed to Opaque call for Carbon
00907     //I think this is what is desired, but this may break this code.
00908     //SInt16    dialItem = - 1;
00909     if( GetDialogKeyboardFocusItem(pdialog) != passworditem)
00910         return;
00911     //old code
00912     //dialItem = (*(DialogPeek) pdialog).editField;
00913     //if (dialItem != passworditem - 1) /*it's not the password item, nothing to do*/
00914     //  return;
00915     
00916     switch (chkb) {
00917         
00918         case chtab: case chleftarrow: case chrightarrow:
00919         case chuparrow: case chdownarrow:
00920             return;
00921             
00922         } /*switch*/
00923     
00924     #if TARGET_API_MAC_CARBON == 1
00925     {
00926     WindowPtr theWind = GetDialogWindow(pdialog);
00927     buffer = (char *) GetWRefCon (theWind);
00928     }
00929     #else
00930     buffer = (char *) GetWRefCon (pdialog);
00931     #endif
00932     //Code change by Timothy Paustian Sunday, April 30, 2000 10:13:01 PM
00933     //Changed to Opaque call for Carbon
00934     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00935     hte = GetDialogTextEditHandle(pdialog);
00936     #else
00937     //old code
00938     hte = (*(DialogPeek) pdialog).textH;
00939     #endif
00940     
00941     start = (**hte).selStart;
00942     
00943     end = (**hte).selEnd;
00944     
00945     if ((start != end) || (chkb == chbackspace)) {
00946     
00947         setstringlength (buffer, 0);
00948         
00949         TESetSelect (0, 32767, hte);
00950         
00951         TEDelete (hte);
00952         
00953         return;
00954         }
00955     
00956     len = stringlength (buffer) + 1;
00957     
00958     buffer [len] = chkb;
00959     
00960     setstringlength (buffer, len);
00961         
00962     (*ev).message = '\xA5';
00963     } /*passwordprocesskey*/
00964     
00965 
00966 pascal boolean modaldialogcallback (DialogPtr pdialog, EventRecord *ev, short *item) {
00967     
00968     /*
00969     standard dialog & alert event filtering.
00970     
00971     10/3/90 dmb: check result of dialogsimulatehit (which now checks enabledness). 
00972     only process background tasks on null events; dialog events have priority. 
00973     also, get default item instead of assuming item 1, and handle boldening.
00974     
00975     8/26/91 dmb: after backgrounding, make sure we're still in front.  otherwise, 
00976     the dialog manager will crash
00977     
00978     10/14/91 dmb: set shellevent.when to deter overzealous agent processing
00979     */
00980     //Code change by Timothy Paustian Sunday, April 30, 2000 10:13:28 PM
00981     //Changed to Opaque call for Carbon
00982     short defaultitem = GetDialogDefaultItem(pdialog);
00983     //old codde
00984     //short defaultitem = (*(DialogPeek) pdialog).aDefItem; /*was set by newmodaldialog*/
00985     bigstring bsbutton;
00986     short whatevent = (*ev).what;
00987     //why was hit a short?
00988     boolean eventHandled = false;
00989     
00990     //register short hit = 0;
00991     
00992     #if !TARGET_API_MAC_CARBON && defined(flcomponent)
00993         long curA5 = SetUpAppA5 ();
00994     #endif
00995     
00996     if (whatevent != nullEvent) { /*non-null event; set global event time for background logic*/
00997         
00998         shellevent.when = (*ev).when;
00999         }
01000     //I need to change this so it hands of key presses for default handling
01001     switch (whatevent) {
01002                 
01003         case keyDown: case autoKey: {
01004             
01005             register char chkb;
01006             register boolean flcmdkey;
01007     
01008             chkb = (*ev).message & charCodeMask;
01009             
01010             flcmdkey = ((*ev).modifiers & cmdKey) == cmdKey;
01011             
01012             if ((chkb == chreturn) || (chkb == chenter)) { /*user hit return or enter*/
01013                 
01014                 if (defaultitem == 0)
01015                     break;
01016                 
01017                 if (!dialogsimulatehit (pdialog, defaultitem))
01018                     break;
01019                 
01020                 *item = defaultitem;
01021                 
01022                 eventHandled = true; /*the dialog manager's version of true*/
01023                 
01024                 break;
01025                 }
01026             
01027             if ((chkb == chescape) || ((chkb == '.') && flcmdkey)) { /*escape or cmd-period*/
01028                 
01029                 shellgetstring (cancelbuttonstring, bsbutton);
01030                 }
01031             else
01032                 setstringwithchar (chkb, bsbutton);
01033             
01034             if (passworditem > 0)
01035                 passwordprocesskey (pdialog, chkb, ev, item);
01036                 
01037             if (dialogmapkeystroke (pdialog, bsbutton, item)) {
01038                 
01039                 if (MenuKey ((*ev).message & charCodeMask)) { /*will be handled by system*/
01040                     
01041                     HiliteMenu (0);
01042                     
01043                     break;
01044                     }
01045                 
01046                 if (!dialogsimulatehit (pdialog, *item))
01047                     break;
01048                 
01049                 eventHandled = true;
01050                 
01051                 break;
01052                 }
01053             break; /*keydown or autokey*/
01054             }
01055         
01056         case updateEvt:
01057         
01058             if ((defaultitem > 0) && ((*ev).message == (long) pdialog))
01059                 boldenbutton (pdialog, defaultitem);
01060             #if TARGET_API_MAC_CARBON == 1
01061                 {
01062                 CGrafPtr thePort = GetDialogPort(pdialog);
01063                 QDFlushPortBuffer(thePort, nil);    
01064                 }
01065             #endif
01066             break;
01067         
01068         case nullEvent:
01069             
01070             /*
01071             shellblockevents (); /%all events are blocked when modal dialog is in front%/
01072             
01073             if (flscriptrunning)
01074                 langbackgroundtask ();
01075             else
01076                 shellbackgroundtask ();
01077             
01078             shellpopevents ();
01079             */
01080             //Code change Timothy Paustian 9/16/00
01081             //This is a bit of a hack, but it works. The contents of the port
01082             //need to be flushed on screen. The only way I could figure to do this
01083             //was to do it at every null event. The whole thing should be rewritten
01084             //at some points to use ModalDialog Correctly.
01085             #if TARGET_API_MAC_CARBON == 1
01086                 {
01087                 WindowRef lpWindow = GetDialogWindow(pdialog);
01088                 CGrafPtr thePort = GetDialogPort(pdialog);
01089                 
01090                 SelectWindow(lpWindow);
01091                 QDFlushPortBuffer(thePort, nil);    
01092                 }
01093             #else
01094                 SelectWindow (pdialog); /*make sure no one has screwed around with us*/
01095             #endif
01096             break;
01097         
01098         } /*switch*/
01099     
01100     #if !TARGET_API_MAC_CARBON && defined(flcomponent)
01101         RestoreA5 (curA5);
01102     #endif
01103     return (eventHandled); /*the dialog manager's version of false*/
01104     } /*modaldialogcallback*/
01105 
01106 
01107 //Code change by Timothy Paustian Sunday, May 7, 2000 11:07:09 PM
01108 //Changed to Opaque call for Carbon
01109 
01110 #if !TARGET_RT_MAC_CFM
01111 
01112 static short runmodaldialog (void) {
01113     
01114     short itemnumber;
01115     
01116     setcursortype (cursorisarrow);
01117     
01118     #ifdef flcomponent
01119         {
01120         ProcPtr filter = (ProcPtr) modaldialogcallback;
01121         #if !TARGET_API_MAC_CARBON && defined(flcomponent)
01122             long appA5 = SetUpCurA5 (); /*for system*/
01123         #endif
01124         
01125         ModalDialog ((ModalFilterUPP) filter, &itemnumber);
01126         
01127         #if !TARGET_API_MAC_CARBON && defined(flcomponent)
01128             RestoreA5 (appA5);
01129         #endif
01130         }
01131     #else
01132     
01133         ModalDialog (&modaldialogcallback, &itemnumber);
01134         
01135     #endif
01136     
01137     return (itemnumber);
01138     } /*runmodaldialog*/
01139 
01140 #else
01141 
01142 #if !TARGET_API_MAC_CARBON
01143 static RoutineDescriptor modalfilterdesc = BUILD_ROUTINE_DESCRIPTOR (uppModalFilterProcInfo, modaldialogcallback);
01144 #endif
01145 
01146 static short runmodaldialog (void) {
01147     
01148     short itemnumber;
01149     #if TARGET_API_MAC_CARBON == 1
01150     ModalFilterUPP filter = NewModalFilterUPP(modaldialogcallback);
01151     #else   
01152     ModalFilterUPP filter = &modalfilterdesc;
01153     #endif
01154         
01155     setcursortype (cursorisarrow);
01156     
01157     shellmodaldialogmenuadjust ();
01158     
01159     #if flcomponent && !TARGET_API_MAC_CARBON
01160         {
01161         long appA5 = SetUpCurA5 (); /*for system*/
01162         
01163         ModalDialog (filter, &itemnumber);
01164         
01165         RestoreA5 (appA5);
01166         }
01167     #else
01168     
01169 //while(itemnumber != 1 && itemnumber != 2 && itemnumber != 3)
01170 //  {
01171         ModalDialog (filter, &itemnumber);
01172 //  }
01173     #endif
01174     #if TARGET_API_MAC_CARBON == 1
01175     DisposeModalFilterUPP(filter);
01176     #endif
01177     shellforcemenuadjust ();
01178     
01179     return (itemnumber);
01180     } /*runmodaldialog*/
01181     
01182 #endif
01183 
01184 #if !flruntime
01185 
01186 void dialogupdate (EventRecord *event, DialogPtr pdialog) {
01187     
01188     /*
01189     for modeless dialogs, we can't use DialogSelect here, because we're 
01190     being called within a Begin/EndUpdate pair
01191     */
01192     
01193     short item;
01194     //Code change by Timothy Paustian Sunday, April 30, 2000 10:16:35 PM
01195     //Changed to Opaque call for Carbon
01196     //who ever calls this, it is only references from langdialogupdate and that is not
01197     //called in Frontier as far as I can see. I bet it is called as a call back, but I 
01198     //haven't found out how.
01199     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
01200     CGrafPtr    thePort;
01201     RgnHandle   dialRgn = NewRgn();
01202     thePort = GetDialogPort(pdialog);
01203     dialRgn = GetPortVisibleRegion(thePort, dialRgn);
01204     UpdateDialog (pdialog, dialRgn);
01205     //Code change by Timothy Paustian Friday, September 15, 2000 9:01:04 PM
01206     //Mac OS X uses double buffered windows. If you are not calling WaitNextEvent
01207     //you have to tell the OS to flush the contents of the offscreen buffer
01208     //to the screen. Use QDFlushPortBuffer to do this.
01209     QDFlushPortBuffer(thePort, dialRgn);
01210     DisposeRgn(dialRgn);
01211     #else
01212     //old code
01213     UpdateDialog (pdialog, (*pdialog).visRgn);
01214     #endif
01215     
01216     modaldialogcallback (pdialog, event, &item);
01217     } /*dialogupdate*/
01218 
01219     
01220 boolean dialogevent (EventRecord *event, DialogPtr pdialog, short *itemnumber) {
01221     
01222     /*
01223     if the event refers to an item in pdialog's item list, return the item number
01224     and true, otherwise return false.
01225     */
01226     
01227     DialogPtr dlog;
01228     
01229     if (pdialog == nil) /*no dialog open*/
01230         return (false);
01231     
01232     if (!IsDialogEvent (event)) 
01233         return (false);
01234     
01235     if (modaldialogcallback (pdialog, event, itemnumber)) /*special keystroke*/
01236         return (true);
01237     
01238     if (!DialogSelect (event, &dlog, itemnumber))
01239         return (false);
01240     
01241     return (dlog == pdialog); /*click in another dialog?*/
01242     } /*dialogevent*/
01243 
01244 
01245 boolean dialogidle (DialogPtr pdialog) {
01246     
01247     TEHandle hbuffer;
01248     
01249     dialoggeteditbuffer (pdialog, &hbuffer);
01250     
01251     if (hbuffer != nil)
01252         TEIdle (hbuffer);
01253     
01254     return (true);
01255     } /*dialogidle*/
01256     
01257     
01258 boolean dialogactivate (DialogPtr pdialog, boolean flactivate) {
01259     
01260     TEHandle hbuffer;
01261     
01262     dialoggeteditbuffer (pdialog, &hbuffer);
01263     
01264     if (hbuffer != nil) {
01265         
01266         if (flactivate)
01267             TEActivate (hbuffer);
01268         else
01269             TEDeactivate (hbuffer);
01270         }
01271     
01272     return (true);
01273     } /*dialogactivate*/
01274 
01275 
01276 boolean dialoggetselect (DialogPtr pdialog, short *startsel, short *endsel) {
01277     
01278     TEHandle hbuffer;
01279     
01280     dialoggeteditbuffer (pdialog, &hbuffer);
01281     
01282     if (hbuffer != nil)  {
01283         
01284         *startsel = (**hbuffer).selStart + 1;
01285         
01286         *endsel = (**hbuffer).selEnd + 1;
01287         }
01288     
01289     return (true);
01290     } /*dialoggetselect*/
01291 
01292 #endif
01293 
01294 boolean dialogsetselect (DialogPtr pdialog, short startsel, short endsel) {
01295     
01296     TEHandle hbuffer;
01297     if (pdialog == nil) return false;
01298 
01299 
01300     
01301     dialoggeteditbuffer (pdialog, &hbuffer);
01302     
01303     if (hbuffer != nil) 
01304         TESetSelect (startsel, endsel, hbuffer);
01305 
01306     
01307     return (true);
01308     } /*dialogsetselect*/
01309 
01310 
01311 boolean dialogselectall (DialogPtr pdialog) {
01312     
01313     OSStatus        err = noErr;
01314 
01315     #if TARGET_API_MAC_CARBON == 1
01316         WindowClass     wclass;
01317         
01318         /* 12/9/2004 smd: use carbon's casting function, as "(WindowRef)pdialog" doesn't work */
01319         WindowPtr   pwin = GetDialogWindow (pdialog);
01320         
01321         err = GetWindowClass (pwin, &wclass);
01322         if (err==noErr) {
01323             if (wclass == kModalWindowClass) {
01324                 // it's a dialog
01325                 return (dialogsetselect (pdialog, 0, infinity));
01326             } else if (wclass == kDocumentWindowClass) {
01327             
01328                 // it's not a dialog, it's an olde-tyme window. The Find window, for example.
01329                 return (dialogsetselect (GetDialogFromWindow (pwin), 0, infinity));
01330             }
01331             
01332     } /*dialogselectall*/
01333         return 0;
01334     #else
01335         return (dialogsetselect (pdialog, 0, infinity));
01336     #endif
01337 }
01338 
01339 #if 1   // !flruntime -- we can rely on the linker to omit these now
01340 
01341 short savedialog (bigstring bsfname) {
01342     
01343     /*
01344     returns 1, 2 or 3.
01345     
01346     if the user said yes, save the changes, the result is 1.
01347     
01348     if the user said no, discard the changes, the result is 2.
01349     
01350     if the user said cancel, continue editing, the result is 3.
01351     
01352     12/20/91 dmb: if file name is nil, just prompt for quit
01353     
01354     1/3/92 dmb: removed code for quit dialog
01355     */
01356     
01357     register DialogPtr pdialog;
01358     register short itemnumber;
01359     
01360     /*
01361     register short id;
01362     
01363     if (bsfname == nil) /%file wasn't dirty; just want to confirm Quit%/
01364         id = quitdialogid;
01365     else
01366         id = savedialogid;
01367     
01368     if ((pdialog = newmodaldialog (id, saveyesitem)) == nil)
01369         return (1);
01370     */
01371     
01372     if ((pdialog = newmodaldialog (savedialogid, saveyesitem)) == nil)
01373         return (1);
01374     
01375     ParamText (bsfname, nil, nil, nil);
01376     #if TARGET_API_MAC_CARBON == 1
01377     {
01378     WindowRef pWind = GetDialogWindow(pdialog);
01379     ShowWindow(pWind);
01380     }
01381     #else
01382     ShowWindow (pdialog);
01383     #endif  
01384     
01385     itemnumber = runmodaldialog ();
01386     
01387     disposemodaldialog (pdialog);
01388     
01389     switch (itemnumber) {
01390         
01391         case saveyesitem: 
01392             return (1);
01393         
01394         case savenoitem: 
01395             return (2);
01396         
01397         case savecancelitem: 
01398             return (3);
01399         } /*switch*/
01400     
01401     return (1);
01402     } /*savedialog*/
01403 
01404 
01405 short replacevariabledialog (bigstring bsitem) {
01406     
01407     /*
01408     2005-09-26 creedon: changed order of buttons, default is Duplicate which is the safe option
01409                      replace use of replacedialogid with threewaydialog function, easier to maintain one dialog resource, than several
01410     
01411     return 1 if the user clicked on Replace, 2 if Duplicate, 3 if Cancel.
01412     */
01413 
01414     /* register DialogPtr pdialog;
01415     
01416     sysbeep ();
01417         
01418     ParamText (bsitem, nil, nil, nil);
01419     
01420     if ((pdialog = newmodaldialog (replacedialogid, replacereplaceitem)) == nil)
01421         return (1);
01422     
01423     #if TARGET_API_MAC_CARBON == 1
01424     {
01425     WindowRef pWind = GetDialogWindow(pdialog);
01426     ShowWindow(pWind);
01427     }
01428     #else
01429     ShowWindow (pdialog);
01430     #endif
01431     itemnumber = runmodaldialog ();
01432     
01433     disposemodaldialog (pdialog); */
01434     
01435     register short itemnumber;
01436     bigstring bs, prompt;
01437     bigstring nobutton, yesbutton;
01438     boolean fl, flExpertMode = false;
01439     
01440     getstringlist (langerrorlist, replaceitemerror, prompt);
01441 
01442     parsedialogstring (prompt, bsitem, nil, nil, nil, prompt);
01443 
01444     getsystemtablescript (idreplacedialogexpertmode, bs); // "user.prefs.flReplaceDialogExpertMode"
01445 
01446     pushhashtable (roottable);
01447 
01448     disablelangerror ();
01449     
01450     fl = langrunstring (bs, bs);
01451     
01452     enablelangerror ();
01453     
01454     pophashtable ();
01455     
01456     if (fl)
01457         stringisboolean (bs, &flExpertMode);
01458     
01459     if (flExpertMode) {
01460         copystring (duplicatebuttontext, nobutton);
01461         copystring (replacebuttontext, yesbutton);
01462         }
01463     else {
01464         copystring (duplicatebuttontext, yesbutton);
01465         copystring (replacebuttontext, nobutton);
01466         }
01467 
01468     itemnumber = threewaydialog (prompt, yesbutton, nobutton, cancelbuttontext);
01469 
01470     if (!flExpertMode)
01471         switch (itemnumber) {
01472         
01473             case 1:
01474                 itemnumber = 2;
01475                 
01476                 break;
01477             
01478             case 2:
01479                 itemnumber = 1;
01480                 break;
01481             
01482             }
01483     
01484     switch (itemnumber) {
01485         
01486         case replacereplaceitem: 
01487             return (1);
01488         
01489         case replaceduplicateitem:
01490             return (2);
01491         
01492         case replacecancelitem: 
01493             return (3);
01494         } /*switch*/
01495     
01496     return (1);
01497     } /*replacevariabledialog*/
01498 
01499 
01500 boolean revertdialog (bigstring bsfname) {
01501     
01502     /*
01503     put up the standard "revert" dialog, with the provided file name and return
01504     true if the user clicked on ok.  false if cancel was clicked.
01505     */
01506     
01507     register DialogPtr pdialog;
01508     register short itemnumber;
01509     
01510     ParamText (bsfname, nil, nil, nil);
01511     
01512     if ((pdialog = newmodaldialog (revertdialogid, revertokitem)) == nil)
01513         return (false);
01514     #if TARGET_API_MAC_CARBON == 1
01515     {
01516     WindowRef pWind = GetDialogWindow(pdialog);
01517     ShowWindow(pWind);
01518     }
01519     #else
01520     ShowWindow (pdialog);   
01521     #endif
01522     itemnumber = runmodaldialog ();
01523     
01524     disposemodaldialog (pdialog);
01525     
01526     return (itemnumber == revertokitem);
01527     } /*revertdialog*/
01528 
01529 
01530 boolean askdialog (bigstring bsprompt, bigstring bsanswer) {
01531     
01532     /*
01533     put up the standard "ask" dialog, with the provided prompt and return
01534     true if the user clicked on ok.  the answer is in bsanswer.
01535     */
01536     
01537     register DialogPtr pdialog;
01538     register short itemnumber;
01539     
01540     ParamText (bsprompt, nil, nil, nil);
01541     
01542     if ((pdialog = newmodaldialog (askdialogid, askokitem)) == nil)
01543         return (false);
01544     
01545     setdialogtext (pdialog, askansweritem, bsanswer);
01546     
01547 //  selectdialogtext (pdialog, askansweritem);
01548     
01549     #if TARGET_API_MAC_CARBON == 1
01550     {
01551     WindowRef pWind = GetDialogWindow(pdialog);
01552     ShowWindow(pWind);
01553     
01554     }
01555     #else
01556     ShowWindow (pdialog);
01557     #endif
01558     
01559     #if TARGET_API_MAC_CARBON == 1
01560     
01561         while (true) {
01562     
01563     #endif
01564     
01565     itemnumber = runmodaldialog ();
01566     
01567     #if TARGET_API_MAC_CARBON == 1
01568     
01569         if (itemnumber == askokitem || itemnumber == askcancelitem)
01570             break;
01571             
01572         } /*while*/
01573     
01574     #endif
01575     
01576     getdialogtext (pdialog, askansweritem, bsanswer);
01577     
01578     disposemodaldialog (pdialog);
01579     
01580     return (itemnumber == askokitem);
01581     } /*askdialog*/
01582 
01583 
01584 boolean twowaydialog (bigstring bsprompt, bigstring okbutton, bigstring cancelbutton) {
01585     
01586     register DialogPtr pdialog;
01587     register short item;
01588     
01589     if ((pdialog = newmodaldialog (twowaydialogid, twowayokitem)) == nil)
01590         return (false);
01591     
01592     setdialogtext (pdialog, twowaymsgitem, bsprompt);
01593     
01594     dialogsetbuttonstring (pdialog, twowayokitem, okbutton);
01595     
01596     dialogsetbuttonstring (pdialog, twowaycancelitem, cancelbutton);
01597     
01598     #if TARGET_API_MAC_CARBON == 1
01599     {
01600     WindowRef pWind = GetDialogWindow(pdialog);
01601     ShowWindow(pWind);
01602     }
01603     #else
01604     ShowWindow (pdialog);
01605     #endif
01606     
01607     item = runmodaldialog ();
01608     
01609     disposemodaldialog (pdialog);
01610     
01611     return (item == twowayokitem);
01612     } /*twowaydialog*/
01613 
01614 
01615 short threewaydialog (bigstring bsprompt, bigstring yesbutton, bigstring nobutton, bigstring cancelbutton) {
01616     
01617     register DialogPtr pdialog;
01618     register short item;
01619     
01620     if ((pdialog = newmodaldialog (threewaydialogid, threewayyesitem)) == nil)
01621         return (false);
01622     
01623     setdialogtext (pdialog, threewaymsgitem, bsprompt);
01624     
01625     dialogsetbuttonstring (pdialog, threewaycancelitem, cancelbutton);
01626     
01627     dialogsetbuttonstring (pdialog, threewaynoitem, nobutton);
01628     
01629     dialogsetbuttonstring (pdialog, threewayyesitem, yesbutton);
01630     
01631     #if TARGET_API_MAC_CARBON == 1
01632     {
01633     WindowRef pWind = GetDialogWindow(pdialog);
01634     ShowWindow(pWind);
01635     }
01636     #else
01637     ShowWindow (pdialog);
01638     #endif
01639     item = runmodaldialog ();
01640     
01641     disposemodaldialog (pdialog);
01642     
01643     switch (item) {
01644         
01645         case threewaycancelitem:
01646             return (3);
01647             
01648         case threewaynoitem:
01649             return (2);
01650             
01651         case threewayyesitem:
01652         default:
01653             return (1);
01654         } /*switch*/
01655     } /*threewaydialog*/
01656     
01657     
01658 boolean intdialog (bigstring bsprompt, short *intval) {
01659     
01660     register DialogPtr pdialog;
01661     register short itemnumber;
01662     bigstring bs;
01663     
01664     if ((pdialog = newmodaldialog (intdialogid, intokitem)) == nil)
01665         return (false);
01666     
01667     setdialogtext (pdialog, intpromptitem, bsprompt);
01668     
01669     shorttostring (*intval, bs);
01670     
01671     setdialogtext (pdialog, intintitem, bs);
01672     
01673     selectdialogtext (pdialog, intintitem);
01674     
01675     #if TARGET_API_MAC_CARBON == 1
01676     {
01677     WindowRef pWind = GetDialogWindow(pdialog);
01678     ShowWindow(pWind);
01679     }
01680     #else
01681     ShowWindow (pdialog);
01682     #endif
01683     itemnumber = runmodaldialog ();
01684 
01685     getdialogtext (pdialog, intintitem, bs);
01686     
01687     stringtoshort (bs, intval);
01688     
01689     disposemodaldialog (pdialog);
01690     
01691     return (itemnumber == intokitem);
01692     } /*intdialog*/
01693 
01694 
01695 boolean chardialog (bigstring bsprompt, short *charval) {
01696     
01697     register DialogPtr pdialog;
01698     register char ch;
01699     register short itemnumber;
01700     bigstring bs;
01701     
01702     if ((pdialog = newmodaldialog (chardialogid, charokitem)) == nil)
01703         return (false);
01704     
01705     setdialogtext (pdialog, charpromptitem, bsprompt);
01706     
01707     setstringwithchar (*charval, bs);
01708     
01709     setdialogtext (pdialog, charvalitem, bs);
01710     
01711     selectdialogtext (pdialog, charvalitem);
01712     
01713     #if TARGET_API_MAC_CARBON == 1
01714     {
01715     WindowRef pWind = GetDialogWindow(pdialog);
01716     ShowWindow(pWind);
01717     }
01718     #else
01719     ShowWindow (pdialog);
01720     #endif
01721     while (true) {
01722         
01723         itemnumber = runmodaldialog ();
01724         
01725         getdialogtext (pdialog, charvalitem, bs);
01726         
01727         if (isemptystring (bs))
01728             ch = chnul;
01729         else
01730             ch = bs [1];
01731         
01732         ch = uppercasechar (ch); /*cmd-keystrokes must be uppercase*/
01733         
01734         switch (itemnumber) {
01735             
01736             case charokitem: case charcancelitem:
01737                 *charval = ch;
01738                 
01739                 disposemodaldialog (pdialog);
01740                 
01741                 return (itemnumber == charokitem);
01742             
01743             default:
01744                 setstringwithchar (ch, bs);
01745                 
01746                 setdialogtext (pdialog, charvalitem, bs);
01747                 
01748                 selectdialogtext (pdialog, charvalitem);
01749                 
01750                 break;
01751             }
01752         }
01753     } /*chardialog*/
01754 
01755 #endif
01756 
01757 
01758 boolean msgdialog (bigstring bsprompt) {
01759     
01760     /*
01761     put up the standard "msg" dialog, with the provided prompt and return
01762     true if the user clicked on ok.  false if cancel was clicked.
01763     */
01764     
01765     register DialogPtr pdialog;
01766     register short itemnumber;
01767     
01768     if ((pdialog = newmodaldialog (msgdialogid, msgokitem)) == nil) /*error; assume OK*/
01769         return (true);
01770     
01771     setdialogtext (pdialog, msgmsgitem, bsprompt);
01772     
01773     #if TARGET_API_MAC_CARBON == 1
01774     {
01775     WindowRef pWind = GetDialogWindow(pdialog);
01776     ShowWindow(pWind);
01777     }
01778     #else
01779     ShowWindow (pdialog);
01780     #endif
01781     itemnumber = runmodaldialog ();
01782     
01783     disposemodaldialog (pdialog);
01784     
01785     return (itemnumber == msgokitem);
01786     } /*msgdialog*/
01787 
01788 
01789 short customalert (short id, bigstring bsprompt) {
01790     
01791     /*
01792     put up the dialog with the indicated id, and run it.
01793     
01794     **** currently using DisposDialog so it can be called from standard file;
01795     frontshellwindow should be smarter!
01796     */
01797     
01798     register DialogPtr pdialog;
01799     register short itemnumber;
01800     
01801     if ((pdialog = newmodaldialog (id, 1)) == nil)
01802         return (0);
01803     
01804     setdialogtext (pdialog, 2, bsprompt);
01805     
01806     #if TARGET_API_MAC_CARBON == 1
01807     {
01808     WindowRef pWind = GetDialogWindow(pdialog);
01809     ShowWindow(pWind);
01810     }
01811     #else
01812     ShowWindow (pdialog); /*make sure it's visible now that values are set*/
01813     #endif
01814     itemnumber = runmodaldialog ();
01815     
01816     DisposeDialog (pdialog);
01817     
01818     return (itemnumber);
01819     } /*customalert*/
01820 
01821 
01822 boolean alertdialog (bigstring bsprompt) {
01823     
01824     /*
01825     put up the standard "alert" dialog, with the provided prompt and return
01826     true if the user clicked on ok.  false if cancel was clicked.
01827     */
01828     
01829     register DialogPtr pdialog;
01830     register short itemnumber;
01831     
01832     sysbeep ();
01833     
01834     if ((pdialog = newmodaldialog (alertdialogid, alertokitem)) == nil)
01835         return (false);
01836     
01837     setdialogtext (pdialog, alertmsgitem, bsprompt);
01838     
01839     #if TARGET_API_MAC_CARBON == 1
01840     {
01841     WindowRef pWind = GetDialogWindow(pdialog);
01842     ShowWindow(pWind);
01843     }
01844     #else
01845     ShowWindow (pdialog);
01846     #endif
01847     itemnumber = runmodaldialog ();
01848     
01849     disposemodaldialog (pdialog);
01850     
01851     return (itemnumber == alertokitem);
01852     } /*alertdialog*/
01853 
01854 
01855 boolean alertstring (short iderror) {
01856     
01857     bigstring bs;
01858     
01859     getstringlist (alertstringlistnumber, iderror, bs);
01860     
01861     return (alertdialog (bs));
01862     } /*alertstring*/
01863 
01864 
01865 boolean customdialog (short id, short defaultitem, dialogcallback itemhitcallback) {
01866     
01867     /*
01868     put up the dialog with the indicated id, and run it until the 
01869     callback says we're done.
01870     */
01871     
01872     register DialogPtr pdialog;
01873     register short itemnumber;
01874     
01875     if ((pdialog = newmodaldialog (id, defaultitem)) == nil)
01876         return (false);
01877     
01878     if ((*itemhitcallback) (pdialog, -1)) { /*special value tells callback to initialize fields*/
01879         
01880         dialogselectall (pdialog); /*in case there's a text item*/
01881         
01882         #if TARGET_API_MAC_CARBON == 1
01883         {
01884         WindowRef pWind = GetDialogWindow(pdialog);
01885         ShowWindow(pWind);
01886         }
01887         #else
01888         ShowWindow (pdialog); /*make sure it's visible now that values are set*/
01889         #endif
01890                 
01891         while (true) {
01892             
01893             itemnumber = runmodaldialog ();
01894             
01895             if (!(*itemhitcallback) (pdialog, itemnumber))
01896                 break;
01897             }
01898         }
01899     
01900     disposemodaldialog (pdialog);
01901     
01902     return (true);
01903     } /*customdialog*/
01904 
01905 
01906 boolean askpassword (bigstring passprompt, bigstring password) {
01907     
01908     /*
01909     3.0.1 dmb: if id is not the empty string, start with the password item selected
01910     */
01911     
01912     register DialogPtr pdialog;
01913     register short itemnumber;
01914     
01915     ParamText (passprompt, nil, nil, nil);
01916     
01917     if ((pdialog = newmodaldialog (askdialogid, askokitem)) == nil)
01918         return (false);
01919         
01920     setemptystring (password);
01921     #if TARGET_API_MAC_CARBON == 1
01922     {
01923     WindowRef pWind = GetDialogWindow(pdialog);
01924     SetWRefCon (pWind, (long) password);
01925     }
01926     #else
01927 
01928     SetWRefCon (pdialog, (long) password);
01929     
01930     #endif
01931     
01932 //  setdialogtext (pdialog, passworditem, password);    
01933 //  setdialogtext (pdialog, iditem, id);
01934     
01935     setdialogtext (pdialog, askansweritem, password);
01936     
01937     //selectdialogtext (pdialog, askansweritem);
01938     #if TARGET_API_MAC_CARBON == 1
01939     {
01940     WindowRef pWind = GetDialogWindow(pdialog);
01941     ShowWindow(pWind);
01942     }
01943     #else
01944     ShowWindow (pdialog);
01945     #endif
01946     
01947     passworditem = askansweritem;
01948     
01949     #if TARGET_API_MAC_CARBON == 1
01950     
01951         while (true) {
01952     
01953     #endif
01954 
01955     itemnumber = runmodaldialog ();
01956     
01957     #if TARGET_API_MAC_CARBON == 1
01958     
01959         if (itemnumber == askokitem || itemnumber == askcancelitem)
01960             break;
01961             
01962         } /*while*/
01963 
01964     #endif
01965     
01966     passworditem = -1;
01967     
01968 //  getdialogtext (pdialog, iditem, id);
01969     // xxx getdialogtext (pdialog, askansweritem, password);
01970     
01971     disposemodaldialog (pdialog);
01972     
01973     return (itemnumber == askokitem);
01974     } /*askpassword*/
01975 
01976 
01977 boolean initdialogs (void) {
01978     
01979     #ifdef flcomponent
01980         //Code change by Timothy Paustian Sunday, May 7, 2000 11:10:48 PM
01981         //In Carbon this is not needed.
01982         #if !TARGET_CARBON
01983         RememberA5 ();
01984         #endif /*for filters, callbacks*/
01985     #endif
01986     
01987     return (true);
01988     } /*dialoginit*/
01989 
01990 
01991 char X0_p2cstrcpy(char *dst, StringPtr src) 
01992 {
01993     register short  len = src[0], i;
01994     
01995     for(i=0; i<len; i++)
01996         dst[i] = src[i+1];
01997         
01998     dst[i] = 0x00;
01999         
02000     return (*dst);
02001 }
02002 
02003 
02004 
02005 

Generated on Wed May 31 18:19:46 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6