osawindows.c

Go to the documentation of this file.
00001 
00002 /*  $Id: osawindows.c 1290 2006-04-17 10:53:56Z 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 /*Forked file. Carbon at top, "good" version at bottom. This file should be reconciled later.*/
00029 /*
00030     2004-10-28 aradke: Reconciled the Carbon and Classic versions.
00031 */
00032 
00033 #include "frontier.h"
00034 #include "standard.h"
00035 
00036 #include <uisharing.h>
00037 #include <uisinternal.h>
00038 #include <land.h>
00039 #include "ops.h"
00040 #include "kb.h"
00041 #include "memory.h"
00042 #include "quickdraw.h"
00043 #include "resources.h"
00044 #include "shell.h"
00045 #include "shellmenu.h"
00046 #include "shellprivate.h"
00047 #include "tablestructure.h"
00048 #include "osainternal.h"
00049 #include "osawindows.h"
00050 #include <SetUpA5.h>
00051 
00052 
00053 static WindowPtr osageteventwindow (EventRecord *ev) {
00054     
00055     WindowPtr w;
00056     WindowPtr wfront;
00057     
00058     wfront = FrontWindow ();
00059     
00060     w = nil; /*default*/
00061     
00062     switch ((*ev).what) { /*some events apply to windows other than the frontmost*/
00063         
00064         case nullEvent: 
00065             w = wfront;
00066             
00067             break;
00068         
00069         case keyDown: case autoKey: case keyUp:
00070             w = wfront;
00071             
00072             break;
00073         
00074         case mouseDown: case mouseUp:
00075             FindWindow ((*ev).where, &w);
00076             
00077             break;
00078         
00079         case updateEvt: case activateEvt:
00080             w = (WindowPtr) (*ev).message;
00081             
00082             break;
00083         
00084         case jugglerEvt:
00085             w = wfront;
00086             
00087             break;
00088         
00089         default: /*we don't handle other events*/
00090             break;
00091         } /*switch*/
00092     
00093     return (w);
00094     } /*osageteventwindow*/
00095 
00096 
00097 static boolean removewindowsharinghandlers (void);
00098 
00099 
00100 static pascal ComponentResult handlewindoweventcommand (Handle hglobals, EventRecord *ev, tyWindowSharingGlobals *pwsGlobals) {
00101     
00102     /*
00103     2006-04-17 aradke: update jugglerEvt case for Intel Macs using endianness-agnostic code
00104     */
00105     
00106     #pragma unused (hglobals)
00107 
00108     boolean flcloseallwindows = false;
00109     WindowPtr w;
00110     boolean fl = false;
00111     
00112     if (flosashutdown)
00113         removewindowsharinghandlers ();
00114     
00115     w = osageteventwindow (ev);
00116     
00117     if (!isshellwindow (w))
00118         return (false);
00119     
00120     if (!shellpushglobals (w))
00121         return (false);
00122     
00123     switch ((*ev).what) { /*some events apply to windows other than the frontmost*/
00124         
00125         case nullEvent: 
00126             shellidle ();
00127             
00128             shelladjustcursor ();
00129             
00130             break;
00131         
00132         case jugglerEvt: {
00133             
00134             if ((((*ev).message >> 24) & 0xff) == suspendResumeMessage) /*suspend or resume subevent*/
00135                 shellactivatewindow (w, ((*ev).message & resumeFlag) != 0);
00136             
00137             break;
00138             }
00139         
00140         case keyDown: case autoKey: case keyUp:
00141             setkeyboardstatus ((*ev).message, (*ev).what, (*ev).modifiers); 
00142             
00143             if (keyboardstatus.flcmdkey) {
00144                 
00145                 if (!(*shellglobals.cmdkeyfilterroutine) (keyboardstatus.chkb)) {
00146                     
00147                     fl = true;
00148                     
00149                     break;
00150                     }
00151                 
00152                 if (textchar (keyboardstatus.chkb)) /*pass it up to menu mgr*/
00153                     break;
00154                 }
00155             
00156             /*fall through into default case*/
00157         
00158         default: /*we don't handle other events*/
00159             
00160             langcallbacks.errormessagecallback = &langerrordialog;
00161             
00162             fl = shellprocessevent (ev);
00163             
00164             break;
00165         } /*switch*/
00166     
00167     shellpopglobals ();
00168     
00169     (*pwsGlobals).flcloseallwindows = flcloseallwindows; /****/
00170     
00171     /*
00172     processyield ();
00173     */
00174     
00175     return (fl); /*handled the event -- or not*/
00176     } /*eventhandlercommand*/
00177 
00178 
00179 static pascal ComponentResult windowiscardcommand (Handle hglobals, WindowPtr w) {
00180 #pragma unused (hglobals)
00181 
00182     return (isshellwindow (w));
00183     } /*windowiscardcommand*/
00184 
00185 
00186 static pascal ComponentResult closewindowcommand (Handle hglobals, WindowPtr w) {
00187 #pragma unused (hglobals)
00188 
00189     return (shellclosewindow (w));
00190     } /*closewindowcommand*/
00191 
00192 
00193 static pascal ComponentResult windoweditcommand (Handle hglobals, short editcmd) {
00194 #pragma unused (hglobals)
00195 
00196     register WindowPtr w;
00197     register boolean fl;
00198     
00199     w = FrontWindow ();
00200     
00201     if (!isshellwindow (w))
00202         return (false);
00203     
00204     if (!shellpushglobals (w))
00205         return (false);
00206     
00207     fl = shelleditcommand ((tyeditcommand) editcmd);
00208     
00209     shellpopglobals ();
00210     
00211     return (fl);
00212     } /*windoweditcommand*/
00213 
00214 
00215 static pascal ComponentResult
00216 windowopencommand (
00217         Handle               hglobals,
00218         Handle               h,
00219         short                flscripted,
00220         Str255               windowname,
00221         Point                pt,
00222         uisEventCallback     filter) {
00223 #pragma unused (hglobals, flscripted, windowname, pt, filter)
00224 
00225     /*
00226     2.1b8 dmb: new routine so client can open window at will
00227     */
00228     
00229     bigstring bsname;
00230     hdlhashtable htable; 
00231     tyvaluerecord val;
00232     boolean fl = false;
00233     hdlhashnode hnode;
00234     
00235     texthandletostring (h, bsname);
00236     
00237     pushhashtable (roottable); /*override storage table set up by callosafunction so langrunhandle will set up root*/
00238     
00239     if (langexpandtodotparams (bsname, &htable, bsname)) {
00240         
00241         if (htable == nil)
00242             langsearchpathlookup (bsname, &htable);
00243         
00244         if (hashtablelookup (htable, bsname, &val, &hnode)) {
00245             
00246             if (val.valuetype == externalvaluetype)
00247                 fl = langzoomvalwindow (htable, bsname, val, true);
00248             }
00249         }
00250     
00251     pophashtable ();
00252     
00253     return (fl);
00254     } /*windowopencommand*/
00255 
00256 
00257 static pascal ComponentResult windowcandofunction (short selector) {
00258     
00259     switch (selector) {
00260         
00261         case kComponentOpenSelect:
00262         case kComponentCloseSelect:
00263         case kComponentCanDoSelect:
00264         case kComponentVersionSelect:
00265         
00266         case wsEventHandlerCommand:
00267         case wsWindowIsCardCommand:
00268         case wsCloseWindowCommand:
00269         case wsEditCommand:
00270         case wsRunFromHandleCommand:
00271             return (true);
00272         }
00273     
00274     return (false);
00275     } /*windowcandofunction*/
00276 
00277 
00278 static pascal OSErr handleselectwindow (const AppleEvent *event, AppleEvent *reply, SInt32 refcon) {
00279 #pragma unused (reply, refcon)
00280 
00281     /*
00282     handle the window select event in the current application context.
00283     
00284     in case we're in Frontier, dirty the window menu
00285     */
00286     
00287     OSErr err;
00288     OSType type;
00289     long size;
00290     WindowPtr w;
00291     long curA5;
00292     
00293     err = AEGetParamPtr (event, '----', typeLongInteger, &type, (Ptr) &w, sizeof (w), &size);
00294     
00295     if (err == noErr) {
00296         
00297         SelectWindow (w);
00298         
00299         curA5 = SetUpAppA5 ();
00300         
00301         shellwindowmenudirty ();
00302         
00303         RestoreA5 (curA5);
00304         }
00305     
00306     return (err);
00307     } /*handleselectwindow*/
00308 
00309 
00310 #if TARGET_RT_MAC_CFM || TARGET_RT_MAC_MACHO
00311 
00312     /* proc infos for building routine descriptors and universal procedure pointers */
00313 
00314     enum {
00315         windowcandofunctionProcInfo = kPascalStackBased
00316              | RESULT_SIZE(SIZE_CODE(sizeof(OSAError)))
00317              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
00318              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
00319              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
00320     };
00321     enum {
00322         handlewindoweventcommandProcInfo = kPascalStackBased
00323              | RESULT_SIZE(SIZE_CODE(sizeof(OSAError)))
00324              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
00325              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
00326              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
00327     };
00328     enum {
00329         windowiscardcommandProcInfo = kPascalStackBased
00330              | RESULT_SIZE(SIZE_CODE(sizeof(OSAError)))
00331              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
00332              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
00333              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
00334     };
00335     enum {
00336         closewindowcommandProcInfo = kPascalStackBased
00337              | RESULT_SIZE(SIZE_CODE(sizeof(OSAError)))
00338              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
00339              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
00340              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
00341     };
00342     enum {
00343         windoweditcommandProcInfo = kPascalStackBased
00344              | RESULT_SIZE(SIZE_CODE(sizeof(OSAError)))
00345              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
00346              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
00347              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
00348     };
00349     enum {
00350         windowopencommandProcInfo = kPascalStackBased
00351              | RESULT_SIZE(SIZE_CODE(sizeof(OSAError)))
00352              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
00353              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
00354              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
00355     };
00356     
00357     #if TARGET_API_MAC_CARBON == 1
00358 
00359         /*
00360         For Carbon we have to build univeral procedure pointers at runtime.
00361         So we just declare the UPPs here.
00362         */
00363         
00364         ComponentFunctionUPP        windowcandofunctionDesc;
00365         ComponentFunctionUPP        handlewindoweventcommandDesc;
00366         ComponentFunctionUPP        windowiscardcommandDesc;
00367         ComponentFunctionUPP        closewindowcommandDesc;
00368         ComponentFunctionUPP        windoweditcommandDesc;
00369         ComponentFunctionUPP        windowopencommandDesc;
00370         
00371         #define windowcandofunctionUPP (windowcandofunctionDesc)
00372         #define handlewindoweventcommandUPP (handlewindoweventcommandDesc)
00373         #define windowiscardcommandUPP (windowiscardcommandDesc)
00374         #define closewindowcommandUPP (closewindowcommandDesc)
00375         #define windoweditcommandUPP (windoweditcommandDesc)
00376         #define windowopencommandUPP (windowopencommandDesc)
00377 
00378     #else
00379         
00380         /*
00381             For the Classic Mac OS API, routine descriptors are built by the compiler.
00382             Just define the UPPs as pointers to these routine descriptors.
00383         */
00384 
00385         static RoutineDescriptor windowcandofunctionDesc = BUILD_ROUTINE_DESCRIPTOR (windowcandofunctionProcInfo, windowcandofunction);
00386         static RoutineDescriptor handlewindoweventcommandDesc = BUILD_ROUTINE_DESCRIPTOR (handlewindoweventcommandProcInfo, handlewindoweventcommand);
00387         static RoutineDescriptor windowiscardcommandDesc = BUILD_ROUTINE_DESCRIPTOR (windowiscardcommandProcInfo, windowiscardcommand);
00388         static RoutineDescriptor closewindowcommandDesc = BUILD_ROUTINE_DESCRIPTOR (closewindowcommandProcInfo, closewindowcommand);
00389         static RoutineDescriptor windoweditcommandDesc = BUILD_ROUTINE_DESCRIPTOR (windoweditcommandProcInfo, windoweditcommand);
00390         static RoutineDescriptor windowopencommandDesc = BUILD_ROUTINE_DESCRIPTOR (windowopencommandProcInfo, windowopencommand);
00391         
00392         #define windowcandofunctionUPP (&windowcandofunctionDesc)
00393         #define handlewindoweventcommandUPP (&handlewindoweventcommandDesc)
00394         #define windowiscardcommandUPP (&windowiscardcommandDesc)
00395         #define closewindowcommandUPP (&closewindowcommandDesc)
00396         #define windoweditcommandUPP (&windoweditcommandDesc)
00397         #define windowopencommandUPP (&windowopencommandDesc)
00398 
00399     #endif
00400 
00401 #else
00402 
00403     /* For Mac 68k (non-CFM) just use function pointers */
00404     
00405     #define windowcandofunctionUPP  ((ComponentFunctionUPP) windowcandofunction)
00406     #define handlewindoweventcommandUPP ((ComponentFunctionUPP) handlewindoweventcommand)
00407     #define windowiscardcommandUPP  ((ComponentFunctionUPP) windowiscardcommand)
00408     #define closewindowcommandUPP   ((ComponentFunctionUPP) closewindowcommand)
00409     #define windoweditcommandUPP    ((ComponentFunctionUPP) windoweditcommand)
00410     #define windowopencommandUPP    ((ComponentFunctionUPP) windowopencommand)
00411 
00412 #endif
00413 
00414 
00415 #if TARGET_RT_MAC_CFM || TARGET_RT_MAC_MACHO
00416 
00417     #if TARGET_API_MAC_CARBON
00418 
00419         //Code change by Timothy Paustian Friday, July 21, 2000 11:41:07 PM
00420         //Let's see if we can get away with just installing this.
00421         AEEventHandlerUPP   handleselectwindowDesc = nil;
00422 
00423         #define handleselectwindowUPP (handleselectwindowDesc)
00424 
00425     #else
00426         
00427         static RoutineDescriptor handleselectwindowDesc = BUILD_ROUTINE_DESCRIPTOR (uppAEEventHandlerProcInfo, handleselectwindow);
00428     
00429         #define handleselectwindowUPP (&handleselectwindowDesc)
00430 
00431     #endif
00432 
00433 #else
00434 
00435     #define handleselectwindowUPP handleselectwindow
00436 
00437 #endif
00438 
00439 
00440 static boolean installwindowsharinghandlers (void) {
00441     
00442     OSErr err;
00443     
00444     #if TARGET_API_MAC_CARBON   
00445         if (handleselectwindowDesc == nil)
00446             handleselectwindowDesc = NewAEEventHandlerUPP(handleselectwindow);
00447     #endif
00448         
00449     err = AEInstallEventHandler ('SHUI', 'selw', handleselectwindowUPP, 0, false);
00450     
00451     return (err == noErr);
00452     } /*installwindowsharinghandlers*/
00453 
00454 
00455 static boolean removewindowsharinghandlers (void) {
00456     
00457     OSErr err;
00458     
00459     err = AERemoveEventHandler ('SHUI', 'selw', handleselectwindowUPP, false);
00460 
00461     #if TARGET_API_MAC_CARBON
00462     
00463         if (handleselectwindowDesc != nil)
00464             DisposeAEEventHandlerUPP(handleselectwindowDesc);
00465         
00466         DisposeComponentFunctionUPP(windowcandofunctionDesc);
00467         DisposeComponentFunctionUPP(handlewindoweventcommandDesc);
00468         DisposeComponentFunctionUPP(windowiscardcommandDesc);
00469         DisposeComponentFunctionUPP(closewindowcommandDesc);
00470         DisposeComponentFunctionUPP(windoweditcommandDesc);
00471         DisposeComponentFunctionUPP(windowopencommandDesc);
00472     #endif
00473 
00474     
00475     return (err == noErr);
00476     } /*removewindowsharinghandlers*/
00477 
00478     
00479 static pascal ComponentResult windowsharingdispatch (register ComponentParameters *params, Handle storage) {
00480     
00481     /*
00482     2.1b8 dmb: added case for wsRunFromHandleCommand
00483     */
00484     
00485     ComponentResult result = noErr;
00486     short what = (*params).what;
00487     
00488     switch (what) {
00489         
00490         case kComponentOpenSelect: { /*can't call subroutine because a5 isn't ours*/
00491             
00492             hdlcomponentglobals hglobals;
00493             Component self = (Component) (*params).params [0];
00494             long selfa5;
00495             long clienta5;
00496             
00497             selfa5 = GetComponentRefcon (self);
00498             
00499             clienta5 = SetUpAppA5 ();
00500             
00501             #if !TARGET_API_MAC_CARBON
00502                 SetComponentInstanceA5 ((ComponentInstance) self, selfa5);
00503             #endif
00504 
00505             if (newcomponentglobals (self, clienta5, &hglobals))
00506                 SetComponentInstanceStorage ((ComponentInstance) self, (Handle) hglobals);
00507             else
00508                 result = memFullErr;
00509             
00510             installwindowsharinghandlers ();
00511             
00512             /*
00513             initprocess ();
00514             */
00515             
00516             RestoreA5 (clienta5);
00517             
00518             break;
00519             }
00520         
00521         case kComponentCloseSelect:
00522         
00523             disposecomponentglobals ((hdlcomponentglobals) storage);
00524             
00525             removewindowsharinghandlers ();
00526             
00527             /*
00528             processclose ();
00529             */
00530             
00531             result = noErr; /***maybe look for shared windows & close them*/
00532             
00533             break;
00534         
00535         case kComponentCanDoSelect:
00536         
00537             result = CallComponentFunction (params, windowcandofunctionUPP);
00538             
00539             break;
00540         
00541         case kComponentVersionSelect:
00542         
00543             result = 0x04100100;
00544         
00545             break;
00546         
00547         case wsEventHandlerCommand:
00548         
00549             result = callosafunction (storage, params, handlewindoweventcommandUPP);
00550             
00551             break;
00552         
00553         case wsWindowIsCardCommand:
00554         
00555             result = CallComponentFunctionWithStorage (storage, params, windowiscardcommandUPP);
00556             
00557             break;
00558         
00559         case wsCloseWindowCommand:
00560         
00561             result = callosafunction (storage, params, closewindowcommandUPP);
00562             
00563             break;
00564         
00565         case wsEditCommand:
00566         
00567             result = callosafunction (storage, params, windoweditcommandUPP);
00568             
00569             break;
00570         
00571         case wsRunFromHandleCommand:
00572         
00573             result = callosafunction (storage, params, windowopencommandUPP);
00574             
00575             break;
00576         
00577         default:
00578         
00579             result = badComponentSelector;
00580             
00581             break;
00582         }
00583     
00584     return (result);
00585     } /*windowsharingdispatch*/
00586 
00587 
00588 boolean initwindowsharingcomponent (void) {
00589     
00590     /*
00591     register the window sharing component.
00592     */
00593     
00594     Component comp;
00595     
00596     #if !TARGET_API_MAC_CARBON
00597         RememberA5 ();
00598     #endif
00599     
00600     #if TARGET_API_MAC_CARBON
00601         windowcandofunctionDesc = NewComponentFunctionUPP((ProcPtr) windowcandofunction, windowcandofunctionProcInfo);
00602         handlewindoweventcommandDesc = NewComponentFunctionUPP((ProcPtr) handlewindoweventcommand, handlewindoweventcommandProcInfo);
00603         windowiscardcommandDesc = NewComponentFunctionUPP((ProcPtr) windowiscardcommand, windowiscardcommandProcInfo);
00604         closewindowcommandDesc = NewComponentFunctionUPP((ProcPtr) closewindowcommand, closewindowcommandProcInfo);
00605         windoweditcommandDesc = NewComponentFunctionUPP((ProcPtr) windoweditcommand, windoweditcommandProcInfo);
00606         windowopencommandDesc = NewComponentFunctionUPP((ProcPtr) windowopencommand, windowopencommandProcInfo);
00607     #endif
00608         
00609     comp = osaregistercomponent (wsComponentType, 0, &windowsharingdispatch, frontierstring, windowsharingcomponentstring);
00610     
00611     if (comp == nil)
00612         return (false);
00613     
00614     installwindowsharinghandlers (); /*we need to support them too*/
00615     
00616     return (true);
00617     } /*initwindowsharingcomponent*/

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