langdialog.c

Go to the documentation of this file.
00001 
00002 /*  $Id: langdialog.c 567 2006-02-08 21:35:17Z andreradke $    */
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 "frontierwindows.h"
00032 #include "dialogs.h"
00033 #include "shellhooks.h"
00034 #include "lang.h"
00035 #include "langinternal.h"
00036 #include "process.h"
00037 
00038 
00039 
00040 
00041 #define userevents (mDownMask + mUpMask + keyDownMask + keyUpMask + autoKeyMask)
00042 
00043 #define maxnesteddialogs 3
00044 
00045 typedef struct tydialogglobals {
00046     
00047     hdltreenode hcode; /*itemhit callback function call code tree*/
00048     
00049     DialogPtr pdialog; /*the dialog itself*/
00050     } tydialogglobals;
00051 
00052 
00053 DialogPtr langmodaldialog = nil;
00054 
00055 
00056 static tydialogglobals dialogstack [maxnesteddialogs];
00057 
00058 static short topdialog = 0;
00059 
00060 static hdltreenode hitemhitcallback;
00061 
00062 
00063 
00064 
00065 static void pushdialogcall (void) {
00066     
00067     dialogstack [topdialog].hcode = hitemhitcallback;
00068     
00069     dialogstack [topdialog++].pdialog = langmodaldialog;
00070     } /*pushdialogcall*/
00071 
00072 
00073 static void popdialogcall (void) {
00074     
00075     hitemhitcallback = dialogstack [--topdialog].hcode;
00076     
00077     langmodaldialog = dialogstack [topdialog].pdialog;
00078     } /*popdialogcall*/
00079 
00080 
00081 boolean langdialogrunning (void) {
00082     
00083     return (langmodaldialog != nil);
00084     } /*langdialogrunning*/
00085 
00086 
00087 static boolean langvaliddialogitem (short itemnum) {
00088     
00089     if ((itemnum < 1) || (itemnum > dialogcountitems (langmodaldialog))) {
00090         
00091         langlongparamerror (dialogitemnumerror, (long) itemnum);
00092         
00093         return (false);
00094         }
00095     
00096     return (true);
00097     } /*langvaliddialogitem*/
00098 
00099 
00100 static boolean langdialoggetitemparam (hdltreenode hfirst, short pnum, short *itemnum) {
00101     
00102     if (!langdialogrunning ()) { /*factored run-time check*/
00103         
00104         langparamerror (dialognotrunningerror, bsfunctionname);
00105         
00106         return (false);
00107         }
00108     
00109     if (!getintvalue (hfirst, pnum, itemnum))
00110         return (false);
00111     
00112     return (langvaliddialogitem (*itemnum));
00113     } /*langdialoggetitemparam*/
00114 
00115 
00116 boolean langgetdialogvalue (hdltreenode hparam1, tyvaluerecord *vreturned) {
00117     
00118     /*
00119     8/12/91 dmb: fixed bug getting value out of resCtrls
00120     
00121     3.0.2 dmb: return the title of buttons instead of zero
00122     */
00123     
00124     register tyvaluerecord *v = vreturned;
00125     short itemnum;
00126     short itemtype;
00127     Handle itemhandle;
00128     Rect itemrect;
00129     bigstring bs;
00130     
00131     flnextparamislast = true;
00132     
00133     if (!langdialoggetitemparam (hparam1, 1, &itemnum))
00134         return (false);
00135     
00136 #if MACVERSION
00137     GetDialogItem (langmodaldialog, itemnum, &itemtype, &itemhandle, &itemrect);
00138     
00139     switch (itemtype % itemDisable) { /*ignore enabledness*/
00140         
00141         case ctrlItem + chkCtrl:
00142         case ctrlItem + radCtrl:
00143             
00144             setbooleanvalue (bitboolean (GetControlValue ((ControlHandle) itemhandle)), v);
00145             
00146             break;
00147         
00148         case ctrlItem + btnCtrl: /*3.0.2*/
00149             
00150             GetControlTitle ((ControlHandle) itemhandle, bs);
00151             
00152             setstringvalue (bs, v);
00153             
00154             break;
00155         
00156         case ctrlItem + resCtrl:
00157             
00158             setintvalue (GetControlValue ((ControlHandle) itemhandle), v);
00159             
00160             break;
00161         
00162         case statText:
00163         case editText:
00164             
00165             GetDialogItemText (itemhandle, bs);
00166             
00167             setstringvalue (bs, v);
00168             
00169             break;
00170         
00171         default:
00172             setlongvalue (0, v);
00173             
00174             break;
00175         }
00176 #endif
00177 
00178     // *** WIN95 not implemented
00179 
00180     return (true);
00181     } /*langgetdialogvalue*/
00182 
00183 
00184 boolean langsetdialogvalue (hdltreenode hparam1, tyvaluerecord *vreturned) {
00185     
00186     /*
00187     10/7/91 dmb: use setdialogtext instead of SetIText, so that our 
00188     dialog routines can munge special characters (specifically, '@')
00189     */
00190     
00191     short itemnum;
00192     short itemtype;
00193     Handle itemhandle;
00194     Rect itemrect;
00195     boolean flvalue;
00196     short intvalue;
00197     bigstring bsvalue;
00198     
00199     if (!langdialoggetitemparam (hparam1, 1, &itemnum))
00200         return (false);
00201     
00202     setbooleanvalue (true, vreturned); /*optimism*/
00203     
00204 #if MACVERSION
00205     GetDialogItem (langmodaldialog, itemnum, &itemtype, &itemhandle, &itemrect);
00206     
00207     flnextparamislast = true;
00208     
00209     switch (itemtype % itemDisable) { /*ignore enabledness*/
00210         
00211         case ctrlItem + chkCtrl:
00212         case ctrlItem + radCtrl:
00213             
00214             if (!getbooleanvalue (hparam1, 2, &flvalue))
00215                 return (false);
00216             
00217             SetControlValue ((ControlHandle) itemhandle, flvalue);
00218             
00219             break;
00220         
00221         case ctrlItem + btnCtrl:
00222             
00223             if (!getstringvalue (hparam1, 2, bsvalue))
00224                 return (false);
00225             
00226             SetControlTitle ((ControlHandle) itemhandle, bsvalue);
00227             
00228             break;
00229         
00230         case ctrlItem + resCtrl:
00231             
00232             if (!getintvalue (hparam1, 2, &intvalue))
00233                 return (false);
00234             
00235             SetControlValue ((ControlHandle) itemhandle, intvalue);
00236             
00237             break;
00238         
00239         case statText:
00240         case editText:
00241             
00242             if (!getstringvalue (hparam1, 2, bsvalue))
00243                 return (false);
00244             
00245             setdialogtext (langmodaldialog, itemnum, bsvalue); /*so bsvalue gets preprocessed*/
00246             
00247             /*
00248             SetIText (itemhandle, bsvalue);
00249             */
00250             
00251             break;
00252         
00253         default:
00254             flnextparamislast = false; /*we didn't ask for a parameter*/
00255             
00256             (*vreturned).data.flvalue = false; /*didn't work out*/
00257             
00258             break;
00259         }
00260 #endif
00261 
00262     // *** WIN95 not implemented
00263 
00264     return (true);
00265     } /*langsetdialogvalue*/
00266 
00267 
00268 boolean langsetdialogitemenable (hdltreenode hparam1, tyvaluerecord *vreturned) {
00269     
00270     short itemnum;
00271     boolean fl;
00272     
00273     if (!langdialoggetitemparam (hparam1, 1, &itemnum))
00274         return (false);
00275     
00276     flnextparamislast = true;
00277     
00278     if (!getbooleanvalue (hparam1, 2, &fl))
00279         return (false);
00280     
00281     if (fl)
00282         enabledialogitem (langmodaldialog, itemnum);
00283     else
00284         disabledialogitem (langmodaldialog, itemnum);
00285     
00286     setbooleanvalue (true, vreturned);
00287     
00288     return (true);
00289     } /*langsetdialogitemenable*/
00290 
00291 
00292 boolean langsetdialogitemvis (hdltreenode hparam1, boolean fl, tyvaluerecord *vreturned) {
00293     
00294     short itemnum;
00295     
00296     flnextparamislast = true;
00297     
00298     if (!langdialoggetitemparam (hparam1, 1, &itemnum))
00299         return (false);
00300     
00301     if (fl)
00302         showdialogitem (langmodaldialog, itemnum);
00303     else
00304         hidedialogitem (langmodaldialog, itemnum);
00305     
00306     setbooleanvalue (true, vreturned);
00307     
00308     return (true);
00309     } /*langsetdialogitemvis*/
00310 
00311 #if isFrontier && !flruntime
00312 
00313 static boolean langdialogeventhook (EventRecord *ev, WindowPtr w) {
00314     
00315     /*
00316     2.1b3 dmb: don't drop activate events
00317     */
00318     
00319     short item;
00320     short ix;
00321     boolean fllangdialog;
00322     DialogPtr pdialog;
00323     //Code change by Timothy Paustian Saturday, April 29, 2000 10:54:25 PM
00324     //Changed to Opaque call for Carbon
00325     RgnHandle   visRgn;
00326     
00327     fllangdialog = (w == (WindowPtr) langmodaldialog);
00328     
00329     for (ix = 0; (!fllangdialog) && (ix < topdialog); ++ix)
00330         if ((WindowPtr) dialogstack [ix].pdialog == w)
00331             fllangdialog = true;
00332     
00333     if (!fllangdialog) /*not one of our dialogs -- don't hook*/
00334         return (true);
00335     
00336     switch ((*ev).what) {
00337         
00338         case activateEvt:
00339             DialogSelect (ev, &pdialog, &item);
00340             
00341             break;
00342         
00343         case updateEvt:
00344             BeginUpdate (w);
00345             //Code change by Timothy Paustian Saturday, April 29, 2000 10:56:01 PM
00346             //Changed to Opaque call for Carbon
00347             //not tested yet.
00348             #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00349             visRgn = NewRgn();
00350             GetWindowRegion(w, kWindowUpdateRgn, visRgn);
00351             UpdateDialog ((DialogRef) w, visRgn);
00352             DisposeRgn(visRgn);
00353             #else
00354             #pragma unused(visRgn)
00355             //old code
00356             UpdateDialog (w, (*w).visRgn);
00357             #endif
00358             modaldialogcallback ((DialogPtr) w, ev, &item);
00359             
00360             EndUpdate (w);
00361             
00362             break;
00363         }
00364     
00365     return (false); /*ignore the event*/
00366     } /*langdialogeventhook*/
00367 
00368 #endif
00369 
00370 static boolean langdialogitemhit (DialogPtr pdialog, short itemnumber) {
00371     
00372     /*
00373     we're going to call the handler code with itemnumber as a parameter.
00374     
00375     we'll form the code tree for the parameter list (itemnumber) by hand.
00376     
00377     7/29/92 dmb: different event handling for runtime.
00378     
00379     1/18/93 dmb: fldisableyield global is now a counter
00380     
00381     2.1b11 dmb: don't disable yield if we're debugging
00382     */
00383     
00384     hdltreenode hparam;
00385     tyvaluerecord val;
00386     boolean fl;
00387     boolean fldebugging = false;
00388     
00389     cleartmpstack ();
00390     
00391     setintvalue (itemnumber, &val);
00392     
00393     if (!newconstnode (val, &hparam))
00394         return (false);
00395     
00396     pushdialogcall ();
00397     
00398     langmodaldialog = pdialog; /*make visible to langdialogeventhook, etc.*/
00399     
00400     if (topdialog == 1) { /*only need one event hook for all nested dialogs*/
00401         
00402         #if !isFrontier
00403             ++fldisableyield;
00404         
00405         #else
00406             fldebugging = debuggingcurrentprocess ();
00407             
00408             if (!fldebugging)
00409                 ++fldisableyield;
00410             
00411             shellpusheventhook (&langdialogeventhook);
00412         #endif
00413         }
00414     
00415     fl = langhandlercall (hitemhitcallback, hparam, &val);
00416     
00417     if (topdialog == 1) {
00418     
00419         #if !isFrontier
00420             --fldisableyield;
00421             
00422         #else
00423             shellpopeventhook ();
00424             
00425             if (!fldebugging)
00426                 --fldisableyield;
00427         #endif
00428         }
00429     
00430     popdialogcall ();
00431     
00432     langdisposetree (hparam);
00433     
00434     if ((WindowPtr) pdialog != getfrontwindow ()) /*this can happen under the debugger*/
00435         windowbringtofront ((WindowPtr) pdialog);
00436     
00437     if (!fl)
00438         return (false);
00439     
00440     if (!coercetoboolean (&val))
00441         return (false);
00442     
00443     return (val.data.flvalue);
00444     } /*langdialogitemhit*/
00445 
00446 
00447 boolean langrundialog (hdltreenode hparam1, tyvaluerecord *vreturned) {
00448     
00449     /*
00450     run a modal dialog.  we're expecting to be called with three arguments:
00451         
00452         rundialog (dialogid, defaultitem, itemhitcallback)
00453     
00454     after extracting these value, we construct a code tree for:
00455         
00456         itemhitcallback^
00457     
00458     and place the result in hitemhitcallback.  langdialogitemhit will 
00459     construct a parameter list for each call, and call back to the item 
00460     hit routine.
00461     */
00462     
00463     short dialogid;
00464     short defaultitem;
00465     tyvaluerecord val;
00466     hdltreenode htree;
00467     boolean fl;
00468     
00469     if (topdialog == maxnesteddialogs /*langdialogrunning ()*/ ) {
00470         
00471         langerror (cantnestdialogserror);
00472         
00473         return (false);
00474         }
00475     
00476     if (!getintvalue (hparam1, 1, &dialogid))
00477         return (false);
00478     
00479     if (!getintvalue (hparam1, 2, &defaultitem))
00480         return (false);
00481     
00482     flnextparamislast = true;
00483     
00484     if (!getaddressparam (hparam1, 3, &val))
00485         return (false);
00486     
00487     if (!pushfunctionreference (val, &htree))
00488         return (false);
00489     
00490     hitemhitcallback = htree; /*make visible to langdialogitemhit*/
00491     
00492     fl = customdialog (dialogid, defaultitem, &langdialogitemhit);
00493     
00494     langdisposetree (htree);
00495     
00496     if (!fl) {
00497         
00498         langlongparamerror (cantloaddialogerror, dialogid);
00499         
00500         return (false);
00501         }
00502     
00503     setbooleanvalue (true, vreturned);
00504     
00505     return (true);
00506     } /*langrundialog*/
00507 
00508 
00509 
00510 

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