browserverbs.c

Go to the documentation of this file.
00001 
00002 /*  $Id: browserverbs.c 355 2005-01-11 22:48:55Z 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  
00029 #include <standard.h>
00030 #include "memory.h"
00031 #include "file.h"
00032 #include "quickdraw.h"
00033 #include "strings.h"
00034 #include "kb.h"
00035 #include "ops.h"
00036 #include "popup.h"
00037 #include "resources.h"
00038 #include "scrollbar.h"
00039 #include "search.h"
00040 #include "windows.h"
00041 #include "windowlayout.h"
00042 #include "zoom.h"
00043 
00044 #include "shell.h"
00045 #include "shellhooks.h"
00046 #include "shellundo.h"
00047 #include "lang.h"
00048 #include "langexternal.h"
00049 #include "tableinternal.h"
00050 #include "tablestructure.h"
00051 #include "cancoon.h"
00052 #include "opinternal.h"
00053 #include "opverbs.h"
00054 #include "claybrowser.h"
00055 #include "claybrowserstruc.h"
00056 //#include "browserverbs.h"
00057 #include "kernelverbdefs.h"
00058 
00059 
00060 
00061 #define browserstringlist 166
00062 #define browsertypestring 1
00063 #define browsersizestring 2
00064 
00065 
00066 #define browsererrorlist 266
00067 #define nobrowsererror 1
00068 #define namenotbrowsererror 2
00069 
00070 
00071 typedef enum tybrowsertoken { /*verbs that are processed by browserverbs.c*/
00072     
00073     zoomscriptfunc,
00074     
00075     ctbrowserverbs
00076     } tybrowsertoken;
00077 
00078 
00079 WindowPtr browserwindow = nil;
00080 
00081 hdlwindowinfo browserwindowinfo = nil;
00082 
00083 hdlclaydata browserdata = nil;
00084 
00085 
00086 
00087 static errornum = 0; /*error number exclusively for browser routines*/
00088 
00089 
00090 static boolean browsersetglobals (void) {
00091     
00092     outlinedata = (**browserdata).houtline; 
00093     
00094     tableformatsdata = (**browserdata).hformats;
00095     
00096     outlinewindow = browserwindow;
00097     
00098     outlinewindowinfo = browserwindowinfo;
00099     
00100     return (opeditsetglobals ());
00101     } /*browsersetglobals*/
00102 
00103 
00104 #define tabletopmargin 3
00105 
00106 
00107 static boolean browserresetrects (hdlwindowinfo hw) {
00108     
00109     register short scrollbarwidth;
00110     register hdlclaydata hc = browserdata;
00111     Rect rcontent;
00112     Rect r;
00113     Rect tablerect, seprect, titlerect, wholerect;
00114     short msgheight;
00115     hdltableformats hformats = tableformatsdata;
00116     #define seprectheight 2 /*height of rectangle separating titles from table content*/
00117     
00118     rcontent = (**hw).contentrect;
00119     
00120     /*set up some values for all rect computations*/ {
00121     
00122         scrollbarwidth = getscrollbarwidth ();
00123         
00124         msgheight = popupheight; 
00125         }
00126     
00127     /*do info.growiconrect*/ {
00128         
00129         shellcalcgrowiconrect (rcontent, hw);
00130         }
00131     
00132     /*do wholerect*/ {
00133         
00134         r = rcontent;
00135         
00136         r.top += tabletopmargin; /*three pixels between titles and top of window*/
00137         
00138         r.bottom -= msgheight + windowmargin;
00139         
00140         r.left += windowmargin;
00141         
00142         r.right -= windowmargin + iconrectwidth + windowmargin + scrollbarwidth;
00143         
00144         wholerect = r;
00145         }
00146     
00147     tablerect = wholerect;
00148     
00149     /*do titlerect, seprect*/ {
00150         
00151         titlerect = tablerect; /*set top, left, right*/
00152         
00153         titlerect.bottom = titlerect.top + (**hc).computedlineinfo.filenamelineheight;
00154         
00155         seprect = tablerect; /*set left, right*/
00156         
00157         seprect.top = titlerect.bottom;
00158         
00159         seprect.bottom = seprect.top + seprectheight;
00160         
00161         tablerect.top = seprect.bottom;
00162         }
00163     
00164     (**hc).wholerect = wholerect;
00165     
00166     (**hc).tablerect = tablerect;
00167     
00168     (**hc).titlerect = titlerect;
00169     
00170     (**hc).seprect = seprect;
00171     
00172     /*do kindpopuprect*/ {
00173         
00174         r.left = tablerect.left + 3; /*flush with left edge of icons*/
00175         
00176         r.right = r.left + popupwidth;
00177         
00178         r.top = tablerect.bottom + ((rcontent.bottom - tablerect.bottom - msgheight) / 2);
00179         
00180         r.bottom = r.top + msgheight;
00181         
00182         (**hc).kindpopuprect = r; 
00183         }
00184         
00185     /*do sortpopuprect*/ {
00186         
00187         r.left = r.right + popupbetweenwidth;
00188         
00189         r.right = r.left + popupwidth;
00190         
00191         (**hc).sortpopuprect = r;
00192         }
00193         
00194     /*do messagerect*/ {
00195         
00196         r.left = r.right + popupbetweenwidth;
00197         
00198         r.right = tablerect.right + scrollbarwidth;
00199         
00200         (**hw).messagerect = r; 
00201         }
00202         
00203     /*do iconrect*/ {
00204     
00205         r.top = tablerect.top;
00206         
00207         r.bottom = r.top + iconrectheight;
00208         
00209         r.right = rcontent.right - windowmargin;
00210         
00211         r.left = r.right - iconrectwidth;
00212         
00213         insetrect (&r, -4, 0); /*a little extra width for title*/
00214         
00215         (**hc).iconrect = r; 
00216         }
00217         
00218     /*do vertscrollbar*/ {
00219         
00220         r = tablerect; /*the space occupied by the grid of cells*/
00221         
00222         r.left = r.right; /*scrollbar is just to right of grid*/
00223         
00224         r.right = r.left + scrollbarwidth;
00225         
00226     //  r.bottom = r.top + (**hformats).nonblankvertpixels;
00227         
00228         setscrollbarrect ((**hw).vertscrollbar, r);
00229         
00230         showscrollbar ((**hw).vertscrollbar);
00231         }
00232     
00233     return (true);
00234     } /*browserresetrects*/
00235     
00236 
00237 static boolean browsergetcontentsize (long *width, long *height) {
00238     
00239     short pixels;
00240     
00241     claygetoutlinesize (width, height);
00242     
00243     pixels = tabletopmargin + windowmargin + popupheight + 4;
00244     
00245     *height += pixels;
00246     
00247     pixels = windowmargin + windowmargin + iconrectwidth + windowmargin + getscrollbarwidth ();
00248     
00249     *width += pixels;
00250     
00251     return (true);
00252     } /*browsergetcontentsize*/
00253 
00254 
00255 static void browserresize (void) {
00256     
00257     Rect r;
00258     
00259     r = (**browserdata).wholerect;
00260     
00261     eraserect (r);
00262     
00263 //  tabledirty ();
00264     
00265     r = (**browserdata).tablerect;
00266     
00267     insetrect (&r, 1, 1);
00268     
00269     opresize (r);
00270     
00271     clayrecalccolwidths (true); /*re-distribute colwidths*/
00272     } /*browserresize*/
00273 
00274 
00275 static boolean browsersetfont (void) {
00276     
00277     return (opsetfont ((**outlinewindowinfo).selectioninfo.fontnum));
00278     } /*browsersetfont*/
00279 
00280 
00281 static boolean browsersetsize (void) {
00282     
00283     return (opsetsize ((**outlinewindowinfo).selectioninfo.fontsize));
00284     } /*browsersetsize*/
00285 
00286 
00287 static boolean browsergettargetdata (short id) {
00288     
00289     /*
00290     a verb is about to be executed that acts on the indicated external type, or 
00291     on any shell window if id == -1.
00292     
00293     return true if we can handle verbs of that type and are able to set the 
00294     relevant globals
00295     */
00296     
00297     switch (id) {
00298         
00299         case -1:
00300             return (true);
00301         
00302         case idoutlineprocessor:
00303             return (true);
00304         
00305         case idwordprocessor:
00306             return (opeditsetglobals ());
00307         
00308         default:
00309             return (false);
00310         }
00311     } /*browsergettargetdata*/
00312 
00313 
00314 static boolean browserclose (void) {
00315     
00316     register hdloutlinerecord ho = outlinedata;
00317     
00318 //  opverbcheckwindowrect (ho);
00319     
00320     killundo (); /*must toss undos before they're stranded*/
00321     
00322     if ((**ho).fldirty) { /*we have to keep the in-memory version around*/
00323         
00324         (**ho).flwindowopen = false;
00325         
00326         opcloseoutline (); /*prepare for dormancy, not in a window anymore*/
00327         }
00328     
00329     return (true);
00330     } /*browserclose*/
00331 
00332 
00333 static void browseridle (void) {
00334     
00335     opidle ();
00336     
00337     browsercommitchanges ();
00338     } /*browsereventloopidle*/
00339     
00340 
00341 static boolean getsystemname (bigstring systemname) { // dmb
00342     
00343     StringHandle h;
00344     
00345     h = GetString (-16413);
00346     
00347     if (ResError () != noErr)
00348         return (false);
00349         
00350     copyheapstring (h, systemname);
00351     
00352     if (stringlength (systemname) == 0)
00353         copystring ("\pUntitled System", systemname);
00354     
00355     return (true);
00356     } /*getsystemname*/
00357 
00358 
00359 static boolean browsernewwindow (void) {
00360     
00361     hdlwindowinfo ha = browserwindowinfo;
00362     hdlclaydata hc = nil;
00363     hdloutlinerecord ho = nil;
00364     Rect rzoom, rwindow;
00365     hdlwindowinfo hparent;
00366     hdltableformats hformats = nil;
00367     tyfilespec fs;
00368     
00369     if (!shellgetfrontrootinfo (&hparent)) /*our parent is the frontmost root window*/
00370         return (false);
00371     
00372     rzoom.top = -1; /*zoom from default rect*/
00373     
00374     if (!newclearhandle (sizeof (tyclaydata), (Handle *) &hc))
00375         return (false);
00376     
00377     browserdata = hc;
00378     
00379     claydefaultlinelayout (&(**hc).linelayout);
00380     
00381     ccgetwindowrect (ixbrowserinfo, &rwindow);
00382     
00383     if (!newoutlinerecord (&ho))
00384         goto error;
00385     
00386     (**hc).houtline = ho;
00387     
00388     (**ho).outlinerefcon = (long) hc;
00389     
00390     (**ho).flusebitmaps = false; 
00391     
00392     if (!browserinitrecord (hc))
00393         goto error;
00394     
00395     if (!newtableformats (&hformats))
00396         goto error;
00397     
00398     (**browserdata).hformats = hformats;
00399     
00400     pushscratchport ();
00401     
00402 //  if (!tableunpackformats (hpackedformats, hformats)) {
00403         
00404         tablesetdimension (hformats, false, 1, fixedctcols);
00405 //      }
00406     
00407     popport ();
00408     
00409 //  if (ho != nil)  
00410 //      getoutlinerect (&(**ho).outlinerect); /*allow callback to change statuspixels, perhaps other window measures*/
00411     
00412     shellpushfrontrootglobals ();
00413     
00414     windowgetfspec (shellwindow, &fs);
00415     
00416     shellpopglobals ();
00417     
00418     if (!newchildwindow (idbrowserconfig, hparent, rwindow, rzoom, fs.name, &browserwindow))
00419         goto error;
00420     
00421 //  windowsetcolor (browserwindow, (**hm).forecolor, true);
00422     
00423 //  windowsetcolor (browserwindow, (**hm).backcolor, false);
00424         
00425     getwindowinfo (browserwindow, &browserwindowinfo);
00426     
00427     (**browserwindowinfo).hdata = (Handle) hc;
00428     
00429     ccnewsubwindow (browserwindowinfo, ixbrowserinfo);
00430     
00431     shellpushglobals (browserwindow); 
00432     
00433     browserresize ();
00434     
00435 //  browsersetfontsize ();
00436     
00437     windowzoom (browserwindow);
00438     
00439     shellpopglobals ();
00440     
00441     return (true);
00442     
00443     error:
00444             
00445         opdisposeoutline (ho, true);
00446         
00447         disposehandle ((Handle) hc);
00448         
00449         return (false);
00450     } /*browsernewwindow*/
00451 
00452 
00453 static boolean browserfindvisit (WindowPtr w) {
00454     
00455     /*
00456     if we're called, the w is a window with the desired config, owned 
00457     the the current root.
00458     
00459     set up browser globals and return false to terminate the visit
00460     */
00461     
00462     browserwindow = w;
00463     
00464     getwindowinfo (w, &browserwindowinfo);
00465     
00466     browserdata = (hdlclaydata) (**browserwindowinfo).hdata;
00467     
00468     return (false);
00469     } /*browserfindvisit*/
00470 
00471 
00472 static boolean browserfindwindow (short idconfig) {
00473     
00474     /*
00475     5/22/91 dmb: use customized visit to limit search to windows belonging to the 
00476     current root.  this allows us to distinguish between the quickscript window 
00477     for each open file.
00478     */
00479     
00480     hdlwindowinfo hroot;
00481     
00482     if (!frontrootwindow (&hroot))
00483         return (false);
00484     
00485     return (!visitownedwindows ((**hroot).macwindow, idconfig, &browserfindvisit));
00486     
00487     /*
00488     return (shellfindwindow (idconfig, &browserwindow, &browserwindowinfo, (Handle *) &browserdata));
00489     */
00490     } /*browserfindwindow*/
00491 
00492 
00493 boolean browseropenmainwindow (void) {
00494     
00495     if (browserfindwindow (idbrowserconfig)) { /*sets browserdata, browserwindow*/
00496         
00497         windowbringtofront (browserwindow);
00498         
00499         return (true);
00500         }
00501     
00502     return (browsernewwindow ());
00503     } /*browseropenmainwindow*/
00504 
00505 
00506 boolean browserstart (void) {
00507     
00508     /*
00509     set up callback routines record, and link our data into the shell's 
00510     data structure.
00511     */
00512     
00513     ptrcallbacks browsercallbacks;
00514     register ptrcallbacks cb;
00515     
00516 //  browserinitverbs ();
00517     
00518 //  meinit ();
00519     
00520     shellnewcallbacks (&browsercallbacks);
00521     
00522     cb = browsercallbacks; /*copy into register*/
00523     
00524     loadconfigresource (idbrowserconfig, &(*cb).config);
00525     
00526     (*cb).configresnum = idbrowserconfig;
00527         
00528     (*cb).windowholder = &browserwindow;
00529     
00530     (*cb).dataholder = (Handle *) &browserdata;
00531     
00532     (*cb).infoholder = &browserwindowinfo;
00533     
00534     (*cb).setglobalsroutine = &browsersetglobals;
00535     
00536     (*cb).updateroutine = &browserupdate;
00537     
00538     (*cb).activateroutine = &opactivate;
00539     
00540     (*cb).getcontentsizeroutine = &browsergetcontentsize;
00541     
00542     (*cb).resetrectsroutine = &browserresetrects;
00543     
00544     (*cb).resizeroutine = &browserresize;
00545     
00546     (*cb).scrollroutine = &opscroll;
00547     
00548     (*cb).setscrollbarroutine = &opresetscrollbars;
00549     
00550     (*cb).mouseroutine = &opmousedown;
00551     
00552     (*cb).keystrokeroutine = &opkeystroke;
00553     
00554 //  (*cb).titleclickroutine = &browsertitleclick;
00555     
00556     (*cb).cutroutine = &opcut;
00557     
00558     (*cb).copyroutine = &opcopy;
00559     
00560     (*cb).pasteroutine = &oppaste;
00561     
00562     (*cb).clearroutine = &opclear;
00563     
00564     (*cb).selectallroutine = &opselectall;
00565     
00566     /*
00567     (*cb).disposerecordroutine = &medispose;
00568     */
00569     
00570     (*cb).closeroutine = &browserclose;
00571     
00572     (*cb).getundoglobalsroutine = &opeditgetundoglobals;
00573     
00574     (*cb).setundoglobalsroutine = &opeditsetundoglobals;
00575     
00576 //  (*cb).childcloseroutine = &browserchildclose;
00577     
00578     (*cb).idleroutine = &browseridle;
00579     
00580     (*cb).adjustcursorroutine = &opsetcursor;
00581     
00582     (*cb).gettargetdataroutine = &browsergettargetdata;
00583     
00584 //  (*cb).getvariableroutine = &browsergetvariable;
00585     
00586     (*cb).settextmoderoutine = &opsettextmode;
00587     
00588     (*cb).fontroutine = &browsersetfont;
00589     
00590     (*cb).sizeroutine = &browsersetsize;
00591     
00592     (*cb).setselectioninforoutine = &opsetselectioninfo;
00593     
00594 //  (*cb).searchroutine = &browsersearch;
00595     
00596 //  (*cb).executeroutine = &browserrunscript;
00597     
00598     (*cb).setprintinfoproutine = &opsetprintinfo;
00599     
00600     (*cb).printroutine = &opprint;
00601     
00602     return (true);
00603     } /*browserstart*/
00604 
00605 
00606 
00607 

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