cancoonwindow.c

Go to the documentation of this file.
00001 
00002 /*  $Id: cancoonwindow.c 1254 2006-04-12 20:27:14Z 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 #include "memory.h"
00032 #include "bitmaps.h"
00033 #include "cursor.h"
00034 #include "file.h"
00035 #include "font.h"
00036 #include "icon.h"
00037 #include "kb.h"
00038 #include "mouse.h"
00039 #include "ops.h"
00040 #include "popup.h"
00041 #include "quickdraw.h"
00042 #include "search.h"
00043 #include "smallicon.h"
00044 #include "sounds.h"
00045 #include "strings.h"
00046 #include "textedit.h"
00047 #include "frontierwindows.h"
00048 #include "windowlayout.h"
00049 #include "zoom.h"
00050 #include "shell.h"
00051 #include "shellprivate.h"
00052 #include "shellbuttons.h"
00053 #include "cancoon.h"
00054 #include "cancooninternal.h"
00055 #include "tableformats.h"
00056 #include "tablestructure.h"
00057 #include "tableverbs.h"
00058 #include "command.h"
00059 
00060 /*
00061 implements the "home" window in CanCoon -- the topmost window, the one with a flag to
00062 lift the hood, and buttons that zoom you to neat places.
00063 */
00064 
00065 
00066 
00067 static boolean ccrun (short idscript) {
00068     
00069     bigstring bsscript;
00070     bigstring bsresult;
00071     
00072     if (!getsystemtablescript (idscript, bsscript)) {
00073         
00074         sysbeep ();
00075         
00076         return (false);
00077         }
00078     
00079     return (langrunstringnoerror (bsscript, bsresult));
00080     } /*ccrun*/
00081 
00082 
00083 boolean cchelpcommand (void) {
00084     
00085     return (ccrun (idtechsupportscript));
00086     } /*cchelpcommand*/
00087 
00088 
00089 boolean ccflipflag (void) {
00090     
00091     return (false);
00092     } /*ccflipflag*/
00093 
00094 /*
00095     ccwindowsetglobals is the site of a crashing bug.
00096 
00097     http://linux2.userland.com/users/admin/static/drWatsonLogs/SUPERHONKER/24593835.txt
00098     http://linux2.userland.com/users/admin/static/drWatsonLogs/SUPERHONKER/24629842.txt
00099     http://linux2.userland.com/users/admin/static/drWatsonLogs/SUPERHONKER/24817036.txt
00100 
00101     function: ccwindowstart (actually: ccwindowsetglobals)
00102         00405d00 7459             jz      ccwindowstart+0x1e9 (00405d5b)
00103 
00104         00405d02 8b4dfc           mov     ecx,[ebp-0x4]          ss:011785be=????????
00105         00405d05 8b11             mov     edx,[ecx]              ds:022df948=022df950
00106         00405d07 83baf600000000   cmp   dword ptr [edx+0xf6],0x0 ds:95e000f6=00f6ba83
00107         00405d0e 744b             jz      ccwindowstart+0x1e9 (00405d5b)
00108         
00109         00405d10 8b45fc           mov     eax,[ebp-0x4]          ss:011785be=????????
00110         00405d13 8b08             mov     ecx,[eax]              ds:95e00000=????????
00111         00405d15 8b91f6000000     mov     edx,[ecx+0xf6]         ds:022dfa3e=95e00000
00112         00405d1b 891524405300   mov [cancoondata (00534024)],edx ds:00534024=95e00000
00113 
00114         00405d21 a124405300     mov eax,[cancoondata (00534024)] ds:00534024=95e00000
00115 FAULT ->00405d26 8b08             mov     ecx,[eax]              ds:95e00000=518b088b
00116         00405d28 8b5104           mov     edx,[ecx+0x4]          ds:0332e34e=????????
00117         00405d2b 8b02             mov     eax,[edx]              ds:95e00000=????????
00118         00405d2d 8b0d9c595300                                    ds:0053599c=022df8e0
00119                                   mov     ecx,[tableformatsdata (0053599c)]
00120         00405d33 3b4842           cmp     ecx,[eax+0x42]         ds:96e4ea06=7542483b
00121         00405d36 7509             jnz     ccwindowstart+0x1cf (00405d41)
00122 
00123         00405d38 c745f800000000   mov    dword ptr [ebp-0x8],0x0 ss:011785be=????????
00124         00405d3f eb1a             jmp     ccwindowstart+0x1e9 (00405d5b)
00125 
00126         00405d41 6a52             push    0x52
00127         00405d43 68ac735200       push    0x5273ac
00128         00405d48 68dc735200       push    0x5273dc
00129         00405d4d e82ecfffff       call    __assert (00402c80)
00130 
00131 
00132         The crash occurs when we dereference (*cancoondata) in the assert.
00133 
00134 
00135         Theory 1: cancoondata was disposed somewhere but not set to nil.
00136 
00137         Theory 2: cancoondata was set to an uninitialized value.
00138 
00139 
00140         Note: cancoondata = (**tableformatsdata).refcon
00141 
00142         (**shellwindowinfo).hdata == tableformatsdata (?)
00143 
00144         cancooncallbacks.dataholder = &tableformatsdata
00145 
00146         tablecallbacks.dataholder = &tableformatsdata
00147 
00148         See tablepushformats, tablepopformats in tableformats.c:
00149             only used in tablepacktable in tablepack.c [not a likely candiate]
00150         
00151         See tablenewformatsrecord in tableformats.c
00152             --> tableverbsetupdisplay in tableexternal.c
00153                 --> ccwindowsetuptableview in cancoonwindow.c [cancoondata is linked to (**hf).refcon]
00154                 --> tableedit in tableexternal.c [site of cmd-enter-period crash on Mac!!!]
00155 */
00156 
00157 static boolean ccwindowsetglobals (void) {
00158     
00159     register hdltableformats hf = tableformatsdata;
00160     
00161     if (hf && (**hf).refcon) { // cancoon record has been linked
00162     
00163         cancoondata = (hdlcancoonrecord) (**hf).refcon;
00164         
00165         assert (tableformatsdata == (**(**cancoondata).hroottable).hashtableformats);
00166         }
00167     
00168     tableformatswindow = cancoonwindow;
00169     
00170     tableformatswindowinfo = cancoonwindowinfo;
00171     
00172     return (tableverbsetglobals ());
00173     
00174     } /*ccwindowsetglobals*/
00175 
00176 
00177 void ccwindowsetup (boolean flbigwindow, boolean floldversion) {
00178 #pragma unused (flbigwindow)
00179 
00180     /*
00181     called when cc is booting, the window hasn't shown up on the screen yet,
00182     we get a chance to change the size of the window.  we don't remember whether
00183     the flag was up or down, the window always comes up with the flag up.
00184     
00185     1/21/91 dmb: routine now works for new files.  someone didn't do enough 
00186     testing...
00187     
00188     9/10/91 dmb: don't reset the height of the window; we save the state of 
00189     flbigwindow now.
00190     
00191     12/20/91 dmb: to support new files, we set the bottom again, but now take 
00192     flbigwindow parameter
00193     */
00194     
00195     (**cancoondata).fldirty = floldversion;
00196     } /*ccwindowsetup*/
00197 
00198 
00199 boolean cctoggleflag (void) {
00200     
00201     register hdlcancoonrecord hc = cancoondata;
00202     
00203     (**hc).flflagdisabled = !(**hc).flflagdisabled;
00204     
00205     windowinval (cancoonwindow);
00206     
00207     return (true);
00208     } /*cctoggleflag*/
00209 
00210 
00211 boolean cctoggleagentspopup (void) {
00212     
00213     register hdlcancoonrecord hc = cancoondata;
00214     
00215     (**hc).flpopupdisabled = !(**hc).flpopupdisabled;
00216     
00217     windowinval (cancoonwindow);
00218     
00219     return (true);
00220     } /*cctoggleagentspopup*/
00221 
00222 
00223 static boolean ccwindowpreclose (WindowPtr w) {
00224     
00225     /*
00226     5.0a23 dmb: if we're a conditions are right, just hide the root window
00227     
00228     6.2b16 AR: No longer treat guest roots any different from the main root
00229     */
00230     
00231     if (!keyboardstatus.flshiftkey  // shift disables root hiding
00232         && (w == cancoonwindow)         // a root window
00233         && !flshellclosingall           // not quitting
00234         /*&& !(**cancoondata).flguestroot*/) {  // not a guest root
00235         
00236         assert (w == shellwindow);
00237         
00238         opcloseoutline (); //prepare for dormancy, not in a window anymore
00239         
00240         shellhidewindow (shellwindowinfo);
00241         
00242         return (false);
00243         }
00244     
00245     return (ccpreclose (w));
00246     } /*ccpreclose*/
00247 
00248 
00249 static boolean ccwindowclose (void) {
00250     
00251     /*
00252     5.0d16 dmb: if we're a beginner and Frontier isn't quitting, 
00253     just hide the window
00254     */
00255     
00256     if (!tableverbclose ())
00257         return (false);
00258     
00259     return (ccclose ());
00260     } /*ccwindowclose*/
00261 
00262 
00263 static boolean ccwindowsetuptableview (void) {
00264     
00265     /*
00266     in order to function correctly as a table window, the window info record 
00267     must be linked to a tableformats record, not a cancoon record. we're called 
00268     after initially loading a cancoon record. we set up the table formats and 
00269     make the cancoon record hang off of it (as well as vice-versa), so the 
00270     tableformatsrecord can be the master, windowinfo-wise
00271 
00272     5.0a5 dmb: move and reize the window according to the tableformats windowrect
00273     (the Mac version was relying on the shell's window resource, which we should 
00274     omit now, since it's not xplat. must save and restore colwidths, since the 
00275     window will be resized semi-randomly before the correct size.
00276     
00277     5.0a20: finishing touches (?) of guest databases, make them children of the host
00278     */
00279     
00280     register hdlcancoonrecord hc = cancoondata;
00281     hdlhashtable ht;
00282     hdltableformats hf;
00283     short colwidths [maxtablecols];
00284     
00285     ht = (**hc).hroottable;
00286 
00287     hf = (**ht).hashtableformats;
00288     
00289     if (hf == nil)
00290         colwidths [0] = 0;
00291     else
00292         moveleft ((**hf).colwidths, colwidths, maxtablecols * sizeof (short));
00293     
00294     tableverbsetupdisplay (ht, cancoonwindowinfo);
00295     
00296     if (hf == nil) // just created
00297         hf = (**ht).hashtableformats;
00298     else
00299         moveleft (colwidths, (**hf).colwidths, maxtablecols * sizeof (short));
00300     
00301     (**hf).refcon = (long) hc; /*link cancoonglobals to tableformats*/
00302     
00303     /*
00304     (**cancoonwindowinfo).hdata = (Handle) hf; //link tableformats to windowinfo
00305     
00306     shellsetglobals (cancoonwindow);
00307     
00308     tableresetformatsrects ();
00309     */
00310     
00311     (**outlinedata).flwindowopen = true;
00312     
00313     (**ht).flwindowopen = true;
00314     
00315     shellmoveandsizewindow (cancoonwindowinfo, (**hf).windowrect);
00316 
00317     if ((**hc).fldirty)
00318         shellzoomwindow (cancoonwindowinfo, true);
00319     
00320     if ((**hc).flguestroot) {
00321         
00322         /*
00323         hdlwindowinfo hroot;
00324         
00325         if (!ccfindrootwindow (&hroot))
00326             return (false);
00327         
00328         (**cancoonwindowinfo).parentwindow = hroot;
00329         */
00330         
00331         langexternalregisterwindow ((hdlexternalvariable) (**hc).hrootvariable);
00332         }
00333     
00334     return (true);
00335     } /*ccwindowsetuptableview*/
00336 
00337 
00338 static boolean ccwindowloadfile (hdlfilenum fnum, short rnum) {
00339     
00340     if (!ccloadfile (fnum, rnum))
00341         return (false);
00342     
00343     return (ccwindowsetuptableview ());
00344     } /*ccwindowloadfile*/
00345 
00346 
00347 static boolean ccwindownewrecord (void) {
00348     
00349     if (!ccnewrecord ())
00350         return (false);
00351     
00352     return (ccwindowsetuptableview ());
00353     } /*ccwindownewrecord*/
00354 
00355 
00356 static boolean ccwindowdisposerecord (void) {
00357     
00358     /*
00359     5.1.5 dmb: call new purgefrommenubarlist to get rid of any installed menus
00360     */
00361     register hdlcancoonrecord hc = cancoondata;
00362 
00363     if (hc == NULL)
00364         return (true);
00365     
00366     if ((**hc).flguestroot) {
00367         
00368         langexternalunregisterwindow (cancoonwindowinfo);
00369         
00370         purgefrommenubarlist ((long) (**hc).hdatabase);
00371         }
00372 
00373     ccdisposerecord ();
00374 
00375     //shellexitmaineventloop ();
00376 
00377     return (true);
00378     } /*ccwindowdisposerecord*/
00379 
00380 
00381 static boolean findrootvisit (WindowPtr w, ptrvoid refcon) {
00382     
00383     hdlwindowinfo hinfo;
00384     
00385     if (getwindowinfo (w, &hinfo)) {
00386         
00387         hdltableformats hf = (hdltableformats) (**hinfo).hdata;
00388         
00389         if (hf && ((**hf).refcon == (long) cancoonglobals)) { // got it
00390 
00391             WindowPtr *pw = (WindowPtr *) refcon;
00392         
00393             *pw = w;
00394             
00395             return (false);
00396             }
00397         }
00398     
00399     return (true); // keep visiting
00400     } /*findrootvisit*/
00401 
00402 
00403 boolean ccfindrootwindow (hdlwindowinfo *hinfo) {
00404     
00405     WindowPtr w;
00406     
00407     if (hinfo == nil) // a convenience for our callers, handle nil for don't care
00408         return (true);
00409     
00410     *hinfo = nil;
00411     
00412     if (shellvisittypedwindows (idcancoonconfig, findrootvisit, &w))
00413         return (false);
00414     
00415     return (getwindowinfo (w, hinfo));
00416     } /*ccfindrootwindow*/
00417 
00418 
00419 hdldatabaserecord ccwindowgetdatabase (WindowPtr w) {
00420     
00421     /*
00422     5.1.5b15 dmb: a useful piece of abstraction, used for updating in tableexternal.c
00423     */
00424 
00425     hdlwindowinfo hinfo;
00426     hdltableformats hf;
00427 
00428     if (getwindowinfo (w, &hinfo)) {
00429         
00430         hf = (hdltableformats) (**hinfo).hdata;
00431         
00432         if (hf != nil)
00433             return (tablegetdatabase ((**hf).htable));
00434         }
00435 
00436     return (nil);
00437     } /*ccwindowgetdatabase*/
00438 
00439 
00440 boolean ccwindowstart (void) {
00441     
00442     /*
00443     set up callback routines record, and link our data into the shell's 
00444     data structure.
00445     */
00446     
00447     ptrcallbacks cancooncallbacks;
00448     register ptrcallbacks cb;
00449     short ixtableconfig;
00450     
00451     ccinitverbs ();
00452     
00453     /*
00454     langcallbacks.msgverbcallback = (callback) &ccmsg;
00455     */
00456     
00457     langcallbacks.codereplacedcallback = &cccodereplaced;
00458     
00459     shellnewcallbacks (&cancooncallbacks);
00460     
00461     cb = cancooncallbacks; /*copy into register*/
00462     
00463     if (!shellfindcallbacks (idtableconfig, &ixtableconfig))
00464         shellerrormessage (BIGSTRING ("\x24" "must initialize table before cancoon"));
00465      
00466     *cb = globalsarray [ixtableconfig]; // start with table callbacks
00467     
00468     loadconfigresource (idcancoonconfig, &(*cb).config);
00469     
00470     (*cb).configresnum = idcancoonconfig;
00471     
00472     (*cb).windowholder = &cancoonwindow;
00473     
00474     (*cb).dataholder = (Handle *) &tableformatsdata;
00475     
00476     (*cb).infoholder = &cancoonwindowinfo;
00477     
00478     (*cb).loadroutine = &ccwindowloadfile;
00479     
00480     (*cb).loadspecialroutine = &ccloadspecialfile;
00481     
00482     (*cb).saveroutine = &ccsavefile;
00483     
00484     (*cb).newrecordroutine = &ccwindownewrecord;
00485     
00486     (*cb).disposerecordroutine = &ccwindowdisposerecord;
00487     
00488     (*cb).setdatabaseroutine = &ccsetdatabase;
00489     
00490     (*cb).getdatabaseroutine = &ccgetdatabase;
00491     
00492     (*cb).setsuperglobalsroutine = &ccsetsuperglobals;
00493     
00494     (*cb).backgroundroutine = &ccbackground;
00495     
00496     (*cb).fnumchangedroutine = &ccfnumchanged;
00497     
00498     (*cb).findusedblocksroutine = &ccfindusedblocks;
00499     
00500     (*cb).precloseroutine = &ccwindowpreclose;
00501     
00502     (*cb).closeroutine = &ccwindowclose;
00503     
00504     (*cb).childcloseroutine = &ccchildclose;
00505         
00506     (*cb).setglobalsroutine = &ccwindowsetglobals;
00507     
00508     (*cb).pushroutine = &oppushglobals;
00509 
00510     (*cb).poproutine = &oppopglobals;
00511     
00512     /*
00513     (*cb).getvariableroutine = &tablegetvariableroutine;
00514     
00515     (*cb).updateroutine = &tableverbupdate;
00516     
00517     (*cb).activateroutine = &tableverbactivate;
00518     
00519     (*cb).getcontentsizeroutine = &tableverbgetcontentsize;
00520     
00521     (*cb).resetrectsroutine = &tableverbresetrects;
00522     
00523     (*cb).resizeroutine = &tableverbresize;
00524     
00525     (*cb).scrollroutine = &opscroll;
00526     
00527     (*cb).setscrollbarroutine = &opresetscrollbars;
00528     
00529     (*cb).mouseroutine = &tableverbmousedown;
00530     
00531     (*cb).keystrokeroutine = &tableverbkeystroke;
00532     
00533     (*cb).titleclickroutine = &tableverbtitleclick;
00534     
00535     (*cb).cutroutine = &opcut;
00536     
00537     (*cb).copyroutine = &opcopy;
00538     
00539     (*cb).pasteroutine = &tableverbpaste;
00540     
00541     (*cb).clearroutine = &opclear;
00542     
00543     (*cb).selectallroutine = &opselectall;
00544     
00545     (*cb).getundoglobalsroutine = &tableeditgetundoglobals;
00546     
00547     (*cb).setundoglobalsroutine = &tableeditsetundoglobals;
00548     
00549     (*cb).idleroutine = &tableverbidle;
00550     
00551     (*cb).adjustcursorroutine = &tableverbadjustcursor;
00552     
00553     (*cb).gettargetdataroutine = &tableverbgettargetdata;
00554     
00555     (*cb).settextmoderoutine = &opsettextmode;
00556     
00557     (*cb).fontroutine = &tableverbsetfont;
00558     
00559     (*cb).sizeroutine = &tableverbsetsize;
00560     
00561     (*cb).setselectioninforoutine = &tablesetselectioninfo;
00562     
00563     (*cb).searchroutine = &tableverbsearch;
00564     
00565     (*cb).executeroutine = &tableverbruncursor;
00566     
00567     (*cb).setprintinfoproutine = &opsetprintinfo;
00568     
00569     (*cb).printroutine = &opprint;
00570     */
00571     
00572     return (true);
00573     } /*ccwindowstart*/
00574 
00575 

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