home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-28 | 19.5 KB | 605 lines | [TEXT/MPS ] |
- /*
- File: ODSessn.cpp
-
- Contains: ODSession class implementation
-
- Owned by: Nick Pilch
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <4> 19.07.1996 NP 1370120: don't purge objects that don't
- exist!
- <3> 6/21/96 RA T10025: Set Binding before InitBinding
- because Binding needs to call session for
- ref to itself
- <50> 10/8/95 TJ Fixes Recomended by Refball
- <49> 4/10/95 NP 1287722: Change signature of
- ODSession::GetUserName.
- <48> 25/09/95 NP 1280561: Check results of operator new.
- <47> 8/29/95 DM 1276569: FB3:ODSession::GetUserName can
- return bogus string
- <46> 8/29/95 RR # 1276401 Register Mouse Focus
- <45> 8/16/95 NP 1242634: Remove #define PLATFORMFILEVIRTUAL
- when PlatformFile has no virt. methods.
- <44> 8/3/95 RR #1257260: Collapse B classes. Remove
- somInit methods. Don't call IsInitialized
- or SubclassResponsibility
- <43> 7/27/95 CC 1153788: Use std C library routines rand
- and srand for generating unique update ids.
- <42> 5/30/95 CG #1252280 BB: PStrToIntl should not be used
- by OpenDoc.
- <41> 5/26/95 DM 1251403: Multithreading naming support.
- <40> 5/24/95 CG #1239535 BB: Added temporary work around.
- <39> 5/11/95 NP 1242421: Fix exception handling
- <38> 5/11/95 VL 1238421: Implemented Purge.
- <37> 4/26/95 CG 1211082 BB: 5$ Bugs need to be evaluated
- and removed from Core
- <36> 4/5/95 CG #1216169 BB, #1221135: When Editors folder
- or OpenDoc Libraries folder is missing,
- OpenDoc quits and displays error.
- <35> 3/27/95 CC 1231902: Pass ODSession to
- InitTranslation().
- <34> 3/7/95 RR #1220929 Caching of foci in ODWindowState
- necessitated reordering of Inits
- <33> 2/16/95 CG #1207793: defined resource id constant.
- <32> 2/10/95 CG #1177475: Need to initialize translation
- object before nameSpaceManager.
- <31> 12/13/94 SS 1205663 - changed ODQD to gODQD
- <30> 12/5/94 jpa Added global ODQD & initialization code
- [1203926]
- <29> 11/30/94 RR Include time.h
- <28> 11/15/94 NP 1200193-The Shell should instantiate its
- Semantic Interface.
- <27> 11/15/94 NP 1200132-Removed instantiation of Shell
- Semantic Interface from here.
- <26> 10/7/94 CC 1191489 - Moved UniqueUpdateID() in from
- base class.
- <25> 9/9/94 NP 1184043: Change to InitSemanticInterface.
- <24> 8/22/94 TÇ #1182448 System Process quits when no
- OpenDoc documents are running
- <23> 8/19/94 NP 1181622: Ownership fix.
- <22> 8/13/94 TÇ #1180814 Added support for ODPartWrapper
- API and removed a chr(16) on line #288
- which was randomly introduced by projector?
- <21> 8/12/94 NP 1180762-added setters for getters. moved
- stuff to B file. Removed GetSemtInterface.
- <20> 8/3/94 CC Register the clipboard focus.
- <19> 8/3/94 VL 1153123: Storage to ODStor.
- <18> 8/2/94 TÇ bug# for #17 right below was #1178167
- <17> 8/2/94 TÇ added TOKENTABLECORRUPTED to work around
- heap corruption occuring when fTokenTable
- was deleted. Changed deletes to
- ODDeleteObject.
- <16> 7/29/94 CG Removed Object registration APIs from
- session.
- <15> 7/21/94 TÇ explicitly create & delete a PlatformFile
- to make sure it is not deadstripped, added
- #define PLATFORMFILEVIRTUAL
- <14> 7/11/94 TÇ added GetInfo, SetInfo, set _fInfo in
- InitSession
- <13> 7/11/94 NP Fixed compile problem in GetUserName.
- <12> 7/8/94 NP Fix GetUserName.
- <11> 7/7/94 RR Initialize dispatcher AFTER token table
- <10> 7/1/94 NP Change to InitSIHelper.
- <9> 7/1/94 CG Uncommented code in GetUserName.
- <8> 6/30/94 CG Uncommented messaging-related fields and
- methods, moved StdDisp initialization to
- Dispatch.cpp.
- <7> 6/28/94 VL Use DragDrp.
- <6> 6/28/94 VL Fixed parameters to InitStorageSystem.
- <5> 6/24/94 CG Initialization clean up.
- <4> 6/23/94 CG Somverted original implementation.
- <3> 6/19/94 MB Implement GetDefaultHeap
- <2> 6/18/94 MB Add memory component
- <1> 6/14/94 CG first checked in
- ------------------------------------------------------------
- <7> 6/6/94 jpa Eliminate spurious ASLM header include.
- [1153437]
- <6> 6/1/94 CG Moved fPreferences to nameSpaceManager and
- changed session to use public binding
- object.
- <5> 5/27/94 CG #1165186: Abstracted prefs out of binding.
- <4> 5/9/94 MB #1162181: Changes necessary to install MMM.
- <3> 4/1/94 TÇ #1154941: Get OpenDoc source to actually
- compile for PowerPC
- <2> 3/31/94 eeh bug #1153999: PStrToIntl interface changed.
- <1> 3/28/94 CG first checked in
- <6> 3/26/94 NP 1153512. Object Registration API needed.
- <5> 3/26/94 NP 1153504. InitSemanticInterface.
- <4> 3/25/94 CC Change name of included file to
- <LinkMgr.xh>. (1153348)
- <3> 3/15/94 MB Changes to support SCpp/ASLM builds,
- #1150864.
- <2> 2/28/94 CG (no bug #) Changed call to GetSystemPool()
- to XMPGetSystemHeap().
- <39> 2/9/94 TÇ Throw to THROW
- <38> 2/7/94 TÇ more PPC header fixes
- <37> 2/4/94 TÇ fixes to compile with PPC Universal headers
- <36> 2/3/94 CG System Session gets created in InitSession.
- <35> 2/1/94 RR Call InitSessionForPlatform in InitSession
- <34> 1/28/94 CC Added UniqueUpdateID().
- <33> 1/15/94 RR WinState.h->WinStat.h,
- Dispatch.h->Disptch.h
- <32> 1/14/94 NP Init changes.
- <31> 1/14/94 CG Added include for new NmSpcMgr.h.
- <30> 1/12/94 CG Added fBinding field and calls to new
- ODBinding and InitBinding.
- <29> 1/12/94 VL Init changes.
- <28> 12/20/93 RR New constructor/init interface
- <27> 12/15/93 TÇ more InitObject changes, rename
- Initialize() method call for ClipBoard and
- NameSpaceManager
- <26> 12/8/93 CC Create and Initialize Link Manager object
- <25> 12/3/93 TÇ Stop including ODError.h, it is included
- as ErrorDef.h inside Except.h
- <24> 12/2/93 CC Call InitClipboard().
- <23> 11/16/93 RR Register stddispatchmodule for
- kHighLevelEvent
- <22> 11/15/93 NP Changed XMPSymbols to ODNameSpaceManager.
- <21> 10/28/93 NP GetType returns a boolean instead of
- throwing an exception.
- <20> 10/22/93 NP Added session parameter to ODNameResolver
- constructor.
- <19> 10/20/93 CC Added session parameter to ODClipboard
- constructor
- <18> 9/20/93 NP Changed order of ODMessageInterface and
- ODNameResolver initialization.
- <17> 8/11/93 RR Added code to install standard dispatch
- module (moved from dispatcher)
- <16> 7/28/93 NP Added GetSession function.
- <15> 7/21/93 TÇ change destructor to delete fTokenTable
- before deleting fNameSpaceManager (~TokenTable
- seemed to need fNameSpaceManager)
- <14> 7/12/93 CG Added fShellSemtInterface and
- AcquireShellSemtInterface() to Session class.
- <13> 6/23/93 RCR Initialize TokenTable before arbitrator.
- <12> 6/22/93 NP Added Tokenize methods.
- <11> 5/18/93 NP Changed call to ODMessageInterface
- constructor.
- <10> 4/28/93 NP File name changes.
- <9> 4/27/93 NP Uncommented last comments.
- <8> 4/27/93 NP Commented out the construction of some
- objects. Fixed OpenODSession.
- <7> 4/23/93 NP Removed warning from Purge.
- <6> 4/23/93 NP Fixed GetStorageSystem.
- <5> 4/23/93 NP Fixed Purge.
- <4> 4/23/93 NP Fixed call to ODSemanticInterface
- constructor.
- <3> 4/23/93 NP Fixed Initialize to call Initialize members
- for objects it creates. Uncommented
- constructor and zeroed out fields in it.
- <2> 4/22/93 RCR Add Session:: to Initialize. Remove ODMethod
- <1> 4/21/93 NP first checked in
-
- To Do: 1276569: when name is not found return empty string from GetUserName()
- */
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <info.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- #ifndef SOM_ODLinkManager_xh
- #include <LinkMgr.xh>
- #endif
-
- #ifndef SOM_ODNameSpaceManager_xh
- #include <NmSpcMg.xh>
- #endif
-
- #ifndef SOM_ODMessageInterface_xh
- #include <MssgIntf.xh>
- #endif
-
- #ifndef SOM_ODNameResolver_xh
- #include <NamRslvr.xh>
- #endif
-
- #ifndef _SIHELPER_
- #include "SIHelper.h"
- #endif
-
- #ifndef SOM_ODUndo_xh
- #include <undo.xh>
- #endif
-
- #ifndef SOM_ODBinding_xh
- #include <ODBindng.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #ifndef _TOKNTABL_
- #include "ToknTabl.h"
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __TIME_H__
- #include <time.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <script.h>
- #endif
-
- #ifndef __STDLIB__
- #include <StdLib.h>
- #endif
-
- #define ODSession_Class_Source
- #define VARIABLE_MACROS
- #include <ODSessn.xih>
-
- #pragma segment ODSession
-
-
- //------------------------------------------------------------------------------
- // Globals
- //------------------------------------------------------------------------------
-
- QDGlobals * const gODQD = kODNULL; // Declared in PlfmDef.h
-
- //------------------------------------------------------------------------------
- // Constants
- //------------------------------------------------------------------------------
-
- #define kMacUserNameResID -16096 // this Macintosh system resource id is not
- // defined in universal headers as of 2/13/95
-
- //==============================================================================
- // ODSession
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ODSession: InitSession
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODSessionInitSession(ODSession *somSelf, Environment *ev)
- {
- ODSessionMethodDebug("ODSession","InitSession");
-
- SOM_TRY
-
- somSelf->InitBaseSession(ev);
-
- // Initialize ODQDGlobals, a pointer to the QuickDraw globals. The variable
- // is declared as const so nobody else can modify it, so to initialize it
- // we have to do some fancy casting. (We can't initialize it statically since
- // the QD globals aren't set up at that point.)
- *(QDGlobals**)&gODQD
- = (QDGlobals*)( *(char**)LMGetCurrentA5()
- - sizeof(QDGlobals) + sizeof(GrafPtr));
-
- // Initialize the random number seed for UniqueUpdateID
- srand(time((time_t *) kODNULL));
-
- ODStorageSystem* storageSystem = new ODStorageSystem;
- THROW_IF_NULL(storageSystem);
- storageSystem->InitStorageSystem(ev, somSelf);
- somSelf->SetStorageSystem(ev, storageSystem);
- ODClipboard* clipboard = new ODClipboard;
- THROW_IF_NULL(clipboard);
- clipboard->InitClipboard(ev, somSelf);
- somSelf->SetClipboard(ev, clipboard);
- ODInfo* info = new ODInfo;
- THROW_IF_NULL(info);
- info->InitInfo(ev, somSelf);
- somSelf->SetInfo(ev, info);
- ODLinkManager* linkManager = new ODLinkManager;
- THROW_IF_NULL(linkManager);
- linkManager->InitLinkManager(ev, somSelf);
- somSelf->SetLinkManager(ev, linkManager);
-
- ODTranslation* translation = new ODTranslation;
- THROW_IF_NULL(translation);
- translation->InitTranslation(ev, somSelf);
- somSelf->SetTranslation(ev, translation);
-
- ODNameResolver* nameResolver = new ODNameResolver;
- THROW_IF_NULL(nameResolver);
- nameResolver->InitNameResolver(ev, somSelf);
- somSelf->SetNameResolver(ev, nameResolver);
- ODMessageInterface* messageInterface = new ODMessageInterface;
- THROW_IF_NULL(messageInterface);
- messageInterface->InitMessageInterface(ev, somSelf);
- somSelf->SetMessageInterface(ev, messageInterface);
-
- ODUndo* undo = new ODUndo;
- THROW_IF_NULL(undo);
- undo->InitUndo(ev);
- somSelf->SetUndo(ev, undo);
-
- ODNameSpaceManager* nameSpaceManager = new ODNameSpaceManager;
- THROW_IF_NULL(nameSpaceManager);
- // Note that InitNameSpaceManager needs to ask the session for itself
- // during init time!
- somSelf->SetNameSpaceManager(ev, nameSpaceManager);
- nameSpaceManager->InitNameSpaceManager(ev, somSelf);
- ODBinding* binding = new ODBinding;
- THROW_IF_NULL(binding);
- somSelf->SetBinding(ev, binding);
- binding->InitBinding(ev, somSelf);
- // Note that InitBinding needs to ask the session for itself
- // during init time to support the BndNSUtils.
-
- TokenTable* tt = new TokenTable(somSelf->GetNameSpaceManager(ev));
- THROW_IF_NULL(tt);
- tt->Initialize();
- somSelf->SetTokenTable(ev, tt);
-
- ODWindowState* windowState = new ODWindowState; // Must be after token table
- THROW_IF_NULL(windowState);
- windowState->InitWindowState(ev, somSelf);
- somSelf->SetWindowState(ev, windowState);
- ODDragAndDrop* dragAndDrop = new ODDragAndDrop;
- THROW_IF_NULL(dragAndDrop);
- dragAndDrop->InitDragAndDrop(ev, somSelf); // Must be after Window State
- somSelf->SetDragAndDrop(ev, dragAndDrop);
- ODArbitrator* arbitrator = new ODArbitrator; // Must be after token table
- THROW_IF_NULL(arbitrator);
- arbitrator->InitArbitrator(ev, somSelf);
- somSelf->SetArbitrator(ev, arbitrator);
- ODDispatcher* dispatcher = new ODDispatcher; // Must be after token table
- THROW_IF_NULL(dispatcher);
- // Note that InitDispatcher needs to ask the session for itself
- // during init time!
- somSelf->SetDispatcher(ev, dispatcher);
- dispatcher->InitDispatcher(ev, somSelf);
-
- // temporary work around for #1239535
- somSelf->GetNameSpaceManager(ev)->SynchNSTable(ev); // Must be after dispatcher
-
- arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODKeyFocus),kODNULL);
- arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODMenuFocus),kODNULL);
- arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODSelectionFocus),kODNULL);
- arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODModalFocus),kODNULL);
- arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODMouseFocus),kODNULL);
- arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODScrollingFocus),kODNULL);
- arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODClipboardFocus),kODNULL);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
- #if 0
- //------------------------------------------------------------------------------
- // ODSession: ~ODSession
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODSessionsomUninit(ODSession *somSelf)
- {
- ODSessionMethodDebug("ODSession","somUninit");
-
- ODSession_parents_somUninit(somSelf);
- }
- #endif /* 0 */
- //------------------------------------------------------------------------------
- // ODSession: Purge
- //------------------------------------------------------------------------------
-
- SOM_Scope ODSize SOMLINK ODSessionPurge(ODSession *somSelf, Environment *ev,
- ODSize size)
- {
- ODSessionMethodDebug("ODSession","Purge");
-
- // dh - Wrap all purge calls in a SOM_TRY block. Also aggregate the total of the
- // amount purged in each call and return that value.
- // You might wonder why I wraped each individual call to the session object's Purge
- // method in another nested TRY block. This is necessary because I cannot
- // guarantee that each session object, which can be replaced or patched, will not
- // throw, thus stopping purging for the other objects. This also makes the code
- // harder to read.
- ODSize purged = 0; ODVolatile( purged );
-
- SOM_TRY
- TRY
- ODArbitrator* Arbitrator = somSelf->GetArbitrator(ev);
- if (Arbitrator)
- purged += somSelf->GetArbitrator(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODBinding* Binding = somSelf->GetBinding(ev);
- if (Binding)
- purged += somSelf->GetBinding(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODClipboard* Clipboard = somSelf->GetClipboard(ev);
- if (Clipboard)
- purged += somSelf->GetClipboard(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODDispatcher* Dispatcher = somSelf->GetDispatcher(ev);
- if (Dispatcher)
- purged += somSelf->GetDispatcher(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODDragAndDrop* DragAndDrop = somSelf->GetDragAndDrop(ev);
- if (DragAndDrop)
- purged += somSelf->GetDragAndDrop(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODLinkManager* LinkManager = somSelf->GetLinkManager(ev);
- if (LinkManager)
- purged += somSelf->GetLinkManager(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODMessageInterface* MessageInterface = somSelf->GetMessageInterface(ev);
- if (MessageInterface)
- purged += somSelf->GetMessageInterface(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODNameResolver* NameResolver = somSelf->GetNameResolver(ev);
- if (NameResolver)
- purged += somSelf->GetNameResolver(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODNameSpaceManager* NameSpaceManager = somSelf->GetNameSpaceManager(ev);
- if (NameSpaceManager)
- purged += somSelf->GetNameSpaceManager(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODStorageSystem* StorageSystem = somSelf->GetStorageSystem(ev);
- if (StorageSystem)
- purged += somSelf->GetStorageSystem(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODTranslation* Translation = somSelf->GetTranslation(ev);
- if (Translation)
- purged += somSelf->GetTranslation(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODUndo* Undo = somSelf->GetUndo(ev);
- if (Undo)
- purged += somSelf->GetUndo(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
- TRY
- ODWindowState* WindowState = somSelf->GetWindowState(ev);
- if (WindowState)
- purged += somSelf->GetWindowState(ev)->Purge(ev, size);
- CATCH_ALL
- ENDTRY
-
-
- purged += parent_Purge(somSelf, ev, size);
-
- SOM_CATCH_ALL
- WARN("Error %ld trying to purge in ODSessionPurge",ErrorCode());
- SetErrorCode(kODNoError); // Eat the exception; Purge should not
- // propagate it because clients function
- // fine whether memory was purged or not.
- SOM_ENDTRY
-
- return purged;
- }
-
- //------------------------------------------------------------------------------
- // ODSession: GetUserName
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODSessionGetUserName(ODSession *somSelf, Environment *ev,
- ODIText* name)
- {
- ODSessionMethodDebug("ODSession","GetUserName");
-
- StringHandle userName;
-
- SOM_TRY
- ASSERT(name, kODErrIllegalNullInput);
-
- //ODScriptCode script = GetScriptManagerVariable(smSysScript);
- ODScriptCode script = FontToScript(GetAppFont());
- ODLangCode lang = GetScriptVariable(script, smScriptLang);
-
- name->format = kODTraditionalMacText;
- name->text._buffer = kODNULL;
- SetITextBufferSize(name, sizeof(ODTradITextDataHeader), kODFalse);
- SetITextScriptCode(name, script);
- SetITextLangCode(name, lang);
-
- userName = GetString(kMacUserNameResID);
- if (userName)
- {
- ODLockHandle((ODHandle)userName);
- SetITextString(name, (StringPtr)*userName);
- // name = CreateITextPString(script, lang, (StringPtr)(*userName));
-
- ODUnlockHandle((ODHandle)userName);
- ReleaseResource((Handle)userName);
- }
- else
- SetITextString(name, "");
- // name = CreateITextPString(script, lang, (StringPtr) "");
-
- *name = *name;
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODSession: UniqueUpdateID
- //------------------------------------------------------------------------------
-
- SOM_Scope ODUpdateID SOMLINK ODSessionUniqueUpdateID(ODSession *somSelf, Environment *ev)
- {
- ODSessionMethodDebug("ODSession","UniqueUpdateID");
-
- return (ODUpdateID) rand();
- }
-