langcard.c

Go to the documentation of this file.
00001 
00002 /*  $Id: langcard.c 1353 2006-05-05 13:52:21Z sethdill $    */
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 #ifdef MACVERSION
00032 #include <uisharing.h>
00033 #include <uisinternal.h>
00034 #endif
00035 
00036 #include "launch.h"
00037 #include "memory.h"
00038 #include "ops.h"
00039 #include "strings.h"
00040 #include "frontierwindows.h"
00041 #include "shell.h"
00042 #include "scrap.h"
00043 #include "shellprivate.h"
00044 #include "shellhooks.h"
00045 #include "shellmenu.h"
00046 #include "lang.h"
00047 #include "langinternal.h"
00048 #include "langipc.h"
00049 #include "process.h"
00050 #ifdef iowaRuntime
00051     #include "iowainit.h"
00052 #endif
00053 
00054 
00055 
00056 
00057 #if !defined (fliowa) && !defined (iowaRuntime)
00058 
00059 static boolean langruncard (hdltreenode hparam1, boolean flmodal, tyvaluerecord *vreturned) {
00060     
00061     return (false);
00062     } /*langruncard*/
00063 
00064 static boolean langismodalcard (hdltreenode hparam1, tyvaluerecord *vreturned) {
00065     
00066     return (false);
00067     } /*langismodalcard*/
00068 
00069 #else
00070 
00071 
00072 typedef void (*tycardeventcallback)(EventRecord *);
00073 typedef long hdlcard;
00074 
00075 extern boolean runCard (Handle hpackedcard, boolean flscriptedcard, short top, short pleft, void * pcallback);
00076 extern boolean runModalCard (Handle, boolean, short, short, tycardeventcallback);
00077 extern boolean runModelessCard (Handle, boolean, short, short, tycardeventcallback);
00078 extern boolean cardIsModal (Handle hpackedcard);
00079 extern WindowPtr getcardrecordwindow (hdlcard card);
00080 extern boolean cardEditCommand (short editcommand);
00081 extern boolean closeCardWindow (WindowPtr w);
00082 extern void appletsegment (void);
00083 
00084 #define iowaInitEvent 1000 /*constants for (*ev).what in callbacks*/
00085 #define iowaButtonHitEvent 1001
00086 #define iowaCloseEvent 1002
00087 #define iowaRunScriptEvent 1003
00088 #define iowaCancelEvent 1004 
00089 #define iowaSetHandleEvent 1005
00090 #define iowaOkeyDokeyEvent 1006
00091 
00092 
00093 static WindowPtr langcardwindow = nil;
00094 
00095 static hdlwindowinfo langcardwindowinfo = nil;
00096 
00097 static Handle langcarddata = nil;
00098 
00099 static boolean flshellclosingwindow = false;
00100 
00101 static unsigned long modalcardstarttime;
00102 
00103 static unsigned long modalcardtimeout = -1; /*maxulong*/
00104 
00105 
00106 static void modalcardeventfilter (EventRecord *ev) {
00107     
00108     /*
00109     4.1b3 dmb: iowaruntime sends us all events, not just ones it does handle,
00110     do we have to be more selective about what we do.
00111     
00112     4.1b13 dmb: use new processevent langcallback for handling events.
00113     
00114     4.1b13 dmb: intercept cmd-XCV for Cut/Copy/Paste.
00115     
00116     4.1b13 dmb: use IdleTime gestalt when checking for card timeout
00117     */
00118     
00119     switch ((*ev).what) {
00120         
00121         case iowaInitEvent:
00122             modalcardstarttime = gettickcount ();
00123             
00124             break;
00125         
00126         case iowaButtonHitEvent:
00127             (*ev).what = iowaRunScriptEvent;
00128             
00129             break;
00130         
00131         case keyDown:
00132             if (((*ev).modifiers & cmdKey) != 0) {
00133                 
00134                 boolean handled = true;
00135                 
00136                 switch ((*ev).message & charCodeMask) {
00137                 
00138                     case 'x':
00139                         cardEditCommand (cutitem); break;
00140                     
00141                     case 'c':
00142                         cardEditCommand (copyitem); break;
00143                     
00144                     case 'v':
00145                         shellwritescrap (textscraptype);
00146                         cardEditCommand (pasteitem); break;
00147                     
00148                     case 'a':
00149                         cardEditCommand (selectallitem); break;
00150                     
00151                     default:
00152                         handled = false; break;
00153                     }
00154                 
00155                 if (handled)
00156                     (*ev).what = nullEvent; /*prevent it from coming around again*/
00157                 }
00158             
00159             break;
00160         
00161         case nullEvent: {
00162             long cardticks = (*ev).when - modalcardstarttime;
00163             long idleticks;
00164             
00165             if (gestalt ('idle', &idleticks))
00166                 cardticks = min (cardticks, idleticks);
00167             
00168             if (cardticks / 60 > modalcardtimeout) {
00169             
00170                 (*ev).what = iowaOkeyDokeyEvent;
00171             
00172                 break;
00173                 }
00174             
00175             (*langcallbacks.processeventcallback) (ev);
00176             
00177             break;
00178             }
00179         
00180         case activateEvt:
00181         case updateEvt:
00182             /*
00183             if (*(long *)&(*ev).where == 'LAND')
00184                 (*langcallbacks.processeventcallback) (ev);
00185             else
00186                 *(long *)&(*ev).where = 'LAND';
00187             
00188             break;
00189             */
00190         case osEvt:
00191         case diskEvt:
00192         case kHighLevelEvent:
00193             (*langcallbacks.processeventcallback) (ev);
00194             
00195             break;
00196         
00197         default:
00198             break;
00199         }  /*switch*/
00200     } /*modalcardeventfilter*/
00201 
00202 
00203 static void modelesscardeventfilter (EventRecord *ev) {
00204     
00205     /*
00206     4.1b1 dmb: maintain a shellwindowinfo record attached to the card window
00207     
00208     4.1b4 dmb: set new fldontownwindow field so that shellclose doesn't 
00209     try to tass Iowa's window.
00210     
00211     5.0b13 dmb: fixed bug setting window title when creating card windowinfo
00212     */
00213     
00214     switch ((*ev).what) {
00215         
00216         case iowaInitEvent: {
00217             hdlcard hcard = (hdlcard) (*ev).message;
00218             WindowPtr w = getcardrecordwindow (hcard);
00219             hdlwindowinfo hinfo, hparent;
00220             bigstring bstitle;
00221             
00222             if (newshellwindowinfo (w, &hinfo)) {
00223                 
00224                 (**hinfo).configresnum = idiowaconfig;
00225                 
00226                 if (shellgetfrontrootinfo (&hparent))
00227                     (**hinfo).parentwindow = hparent;
00228                 
00229                 (**hinfo).processid = getcurrentprocessid ();
00230                 
00231                 (**hinfo).fldontownwindow = true;
00232                 
00233                 windowgettitle (w, bstitle);
00234                 
00235                 shellsetwindowtitle (hinfo, bstitle); // 7.24.97 dmb: was windowsettitle
00236                 }
00237             
00238             break;
00239             }
00240         
00241         case iowaCloseEvent: {
00242             hdlcard hcard = (hdlcard) (*ev).message;
00243             WindowPtr w = getcardrecordwindow (hcard);
00244             hdlwindowinfo hinfo;
00245             
00246             if (!flshellclosingwindow && getwindowinfo (w, &hinfo))
00247                 disposeshellwindowinfo (hinfo);
00248             
00249             break;
00250             }
00251         
00252         case iowaButtonHitEvent:
00253             (*ev).what = iowaRunScriptEvent;
00254             
00255             break;
00256         
00257         case activateEvt:
00258             shellwindowmenudirty ();
00259             
00260             shellforcemenuadjust ();
00261             
00262             break;
00263         
00264         default:
00265             break;
00266         }
00267     } /*modelesscardeventfilter*/
00268 
00269 
00270 static boolean getlinefromhandle (Handle h, unsigned long lnum, bigstring bs) { /*DW 12/31/95*/
00271     
00272     unsigned long ix = 0;
00273     unsigned long ct = gethandlesize (h);
00274     unsigned long linecount = 0;
00275     unsigned char ch;
00276     short lenstring;
00277     
00278     while (true) {
00279         
00280         if (linecount >= (lnum - 1))
00281             break;
00282             
00283         if (ix >= ct) /*ran out of chars, there aren't that many lines*/
00284             return (false);
00285         
00286         ch = (*h) [ix++];
00287         
00288         if (ch == '\r') 
00289             linecount++;
00290         } /*while*/
00291     
00292     lenstring = 0;
00293     
00294     bs [0] = 0;
00295     
00296     while (true) {
00297         
00298         if (ix >= ct)
00299             break;
00300             
00301         ch = (*h) [ix++];
00302         
00303         if (ch == '\r') 
00304             break;
00305         
00306         if (lenstring < 255) {
00307             
00308             lenstring++;
00309             
00310             bs [0] = lenstring;
00311             
00312             bs [lenstring] = ch;
00313             }
00314         } /*while*/
00315     
00316     return (true);
00317     } /*getlinefromhandle*/
00318 
00319 
00320 static boolean getcardparam (hdltreenode hparam1, short pnum, Handle *hcard, bigstring bscard) {
00321 
00322     hdlhashtable htable;
00323     tyvaluerecord val;
00324     bigstring line1, line2;
00325     Handle hpacked;
00326     hdlhashnode hnode;
00327     
00328     if (!getvarvalue (hparam1, pnum, &htable, bscard, &val, &hnode))
00329         return (false);
00330     
00331     if ((val.valuetype != binaryvaluetype) || (getbinarytypeid (val.data.binaryvalue) != 'CARD')) {
00332         
00333         langparamerror (notcarderror, bscard);
00334         
00335         return (false);
00336         }
00337     
00338     if (!copyhandle (val.data.binaryvalue, hcard))
00339         return (false);
00340     
00341     hpacked = *hcard;
00342     
00343     stripbinarytypeid (hpacked);
00344     
00345     getlinefromhandle (hpacked, 1, line1);
00346     
00347     getlinefromhandle (hpacked, 2, line2);
00348     
00349     if (equalstrings (line1, "\pMacBird 1.0 -- 12/31/95")) {
00350     
00351         if (equalstrings (line2, "\prun maconly")) {
00352         
00353             pullfromhandle (hpacked, 0, stringlength (line1) + stringlength (line2) + 2, nil);
00354             }
00355         }
00356         
00357     return (true);
00358     } /*getcardparam*/
00359 
00360 
00361 boolean langruncard (hdltreenode hparam1, boolean flmodal, tyvaluerecord *vreturned) {
00362 #pragma unused(flmodal)
00363 
00364     /*
00365     4.0b7 dmb: use new embedded birdruncard
00366     */
00367     
00368     Handle hcard;
00369     bigstring bscard;
00370     boolean fl;
00371     
00372     flnextparamislast = true;
00373     
00374     if (!getcardparam (hparam1, 1, &hcard, bscard))
00375         return (false);
00376     
00377     /*
00378     if (wsGlobals.windowserver == nil) {
00379         
00380         if (!uisInit (nil, 0, 'LAND', noMenuSharing)) {
00381             
00382             disposehandle (hcard);
00383             
00384             langerror (0);
00385             
00386             return (false);
00387             }
00388         }
00389     
00390     if (flmodal)
00391         fl = uisRunModalHandle (hcard, true, bscard, 0, 0, &modalcardeventfilter);
00392     else
00393         fl = uisOpenHandle (hcard, true, bscard, 0, 0, nil);
00394 
00395     uisClose ();
00396     */
00397     
00398     if (cardIsModal (hcard) || !iscurrentapplication (langipcself)) {
00399         
00400         shellactivate (); /*4.1.1b1 dmb*/
00401         
00402         shellmodaldialogmenuadjust ();
00403         
00404         fl = runModalCard (hcard, true, 0, 0, modalcardeventfilter);
00405         
00406         shellforcemenuadjust ();
00407         }
00408     else
00409         fl = runModelessCard (hcard, true, 0, 0, modelesscardeventfilter);
00410     
00411     disposehandle (hcard);
00412     
00413     if (!fl) {
00414         
00415         langparamerror (cantruncarderror, bscard);
00416         
00417         return (false);
00418         }
00419     
00420     setbooleanvalue (true, vreturned);
00421     
00422     return (true);
00423     } /*langruncard*/
00424 
00425 
00426 boolean langismodalcard (hdltreenode hparam1, tyvaluerecord *vreturned) {
00427     
00428     Handle hcard;
00429     bigstring bscard;
00430     
00431     flnextparamislast = true;
00432     
00433     if (!getcardparam (hparam1, 1, &hcard, bscard))
00434         return (false);
00435     
00436     return (setbooleanvalue (cardIsModal (hcard), vreturned));
00437     } /*langismodalcard*/
00438 
00439 
00440 boolean langsetmodalcardtimeout (hdltreenode hparam1, tyvaluerecord *vreturned) {
00441     
00442     flnextparamislast = true;
00443     
00444     if (!getlongvalue (hparam1, 1, (long *) &modalcardtimeout))
00445         return (false);
00446     
00447     return (setbooleanvalue (true, vreturned));
00448     } /*langismodalcard*/
00449 
00450 
00451 static boolean langcardgettargetdata (short id) {
00452     
00453     return (id == -1); /*true if target type is generic -- a shell verb*/
00454     } /*langcardgettargetdata*/
00455 
00456 
00457 static boolean langcardcut (void) {
00458     
00459     return (cardEditCommand (cutitem));
00460     } /*langcardcut*/
00461 
00462 
00463 static boolean langcardcopy (void) {
00464     
00465     return (cardEditCommand (copyitem));
00466     } /*langcardcopy*/
00467 
00468 
00469 static boolean langcardpaste (void) {
00470     
00471     shellwritescrap (textscraptype);
00472     
00473     return (cardEditCommand (pasteitem));
00474     } /*langcardpaste*/
00475 
00476 
00477 static boolean langcardclear (void) {
00478     
00479     return (cardEditCommand (clearitem));
00480     } /*langcardclear*/
00481 
00482 
00483 static boolean langcardselectall (void) {
00484     
00485     return (true);
00486     } /*langcardselectall*/
00487 
00488 
00489 static boolean langcardclose (void) {
00490     
00491     flshellclosingwindow = true;
00492     
00493     closeCardWindow (shellwindow);
00494     
00495     flshellclosingwindow = false;
00496     
00497     return (true);
00498     } /*langcardclose*/
00499 
00500 
00501 boolean langcardstart (void) {
00502     
00503     /*
00504     set up callback routines record, and link our data into the shell's 
00505     data structure.
00506     
00507     4.1b4 dmb: set closeroutine so that we call closeCardWindow
00508     */
00509     
00510     ptrcallbacks langcardcallbacks;
00511     register ptrcallbacks cb;
00512     
00513     if (!iowaInit ())
00514         return (false);
00515     
00516     appletsegment (); /*4.1b7 dmb*/
00517     
00518     shellnewcallbacks (&langcardcallbacks);
00519     
00520     cb = langcardcallbacks; /*copy into register*/
00521     
00522     loadconfigresource (idiowaconfig, &(*cb).config);
00523     
00524     (*cb).configresnum = idiowaconfig;
00525     
00526     (*cb).windowholder = &langcardwindow;
00527     
00528     (*cb).dataholder = (Handle *) &langcarddata;
00529     
00530     (*cb).infoholder = &langcardwindowinfo; 
00531     
00532     (*cb).gettargetdataroutine = &langcardgettargetdata;
00533     
00534     (*cb).cutroutine = &langcardcut;
00535     
00536     (*cb).copyroutine = &langcardcopy;
00537     
00538     (*cb).pasteroutine = &langcardpaste;
00539     
00540     (*cb).clearroutine = &langcardclear;
00541     
00542     (*cb).selectallroutine = &langcardselectall;
00543     
00544     (*cb).closeroutine = &langcardclose;
00545     
00546     /*
00547     (*cb).activateroutine = (callback) &langcardactivate;
00548     
00549     (*cb).updateroutine = &langcardupdate;
00550     
00551     (*cb).mouseroutine = &langcardmousedown;
00552     
00553     (*cb).keystrokeroutine = &langcardkeystroke;
00554     
00555     (*cb).adjustcursorroutine = (callback) &langcardadjustcursor;
00556     */
00557     
00558     return (true);
00559     } /*langcardstart*/
00560 
00561 #endif
00562 
00563 
00564 
00565 

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