home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ToolboxModules.h
-
- Contains: stuff
-
- */
-
- #ifndef _TOOLBOXMODULES_
- #define _TOOLBOXMODULES_
- #pragma once
-
- #ifndef __MODULE__
- #include "Module.h"
- #endif
-
- #include <Windows.h>
-
- #if GENERATINGCFM
-
- #include <CodeFragments.h>
-
- inline bool HasCFMSymbol(void *proc) { return proc != (void*) kUnresolvedCFragSymbolAddress; }
- #else
-
- // this must be done as a macro or it won't compile
-
- #define HasCFMSymbol(proc) true
-
- #endif
-
-
- //--------------------------------------------------------------------------------
- class ApplicationHeap : public TModule
- {
- DeclareClassSingle(ApplicationHeap, TModule);
-
- private:
- static ApplicationHeap* gApplicationHeap;
-
- unsigned long fInitialized : 1;
- unsigned long fStackSize : 31;
-
- public:
- ApplicationHeap(long stackSize = 0);
- virtual ~ApplicationHeap();
-
- virtual void Initialize(void); // Do your thing
- virtual bool Initialized(void);
-
- static ApplicationHeap& GetApplicationHeap();
- };
-
- //--------------------------------------------------------------------------------
- class Toolbox : public TModule
- {
- DeclareClassSingle(Toolbox, TModule);
-
- private:
- static Toolbox* gToolbox;
- static bool gInitialized;
- static bool gCanInteract;
- static bool gHasThreads;
-
- public:
- Toolbox();
- virtual ~Toolbox();
-
- virtual bool Validate(void);
- virtual void Initialize(void); // Do your thing
- virtual bool Initialized(void);
-
- static Toolbox& GetToolbox();
-
- inline bool CanInterract() { return gCanInteract; }
- inline bool HasWindowMgr() { return gCanInteract; }
- inline bool HasThreads() { return gHasThreads; }
-
- static bool HasGestalt(OSType selector, long mask = 0);
- static bool HasSymbol(void *proc) { return proc != nil; }
-
- static short FindWindow(Point where, WindowPtr& win);
- };
-
- //--------------------------------------------------------------------------------
- #define FatalErrorAlert(list, string) {}
-
- #if CFMSYSTEMCALLS
- // Use this macro for an entry point to a system library which may be a trap
- // or a CFM library entry point. Noter that we use CFMSYSTEMCALLS instead of
- // GENERATINGCFM here because the Thread we want to be exactly in sync with
- // the existance of the nWORDINLINE macro.
-
- #define ENTRYPOINT(x) ((ProcPtr)(x))
- #else
- #define ENTRYPOINT(x) nil
- #endif
-
-
- //--------------------------------------------------------------------------------
- // an abstract base class for a manager which can be tested for with a
- // Gestalt selector.
- class ToolboxManager : public TModule
- {
- DeclareClassSingleAbstract(ToolboxManager, TModule);
-
- OSType fGestaltSelector;
- long fGestaltValue;
-
- #if GENERATINGCFM
- ProcPtr fLibraryEntry;
- #endif
-
- unsigned long fRequired : 1; // This manager is required for validate step
- unsigned long fAvailable : 1; // This manager is available
-
- unsigned long fInitializeCalled : 1; // We've tried to initialize the manager
- unsigned long fInitialized : 1; // It is initialized
-
- unsigned long fLibraryChecked : 1; // We've checked for the shared library
- unsigned long fLibraryPresent : 1; // It's present
- unsigned long fLibraryRequired : 1; // Library must b present
-
- unsigned long fGestaltCalled : 1; // Gestalt has been called
- unsigned long fGestaltValid : 1; // Gestalt returned noErr
- unsigned long fGestaltRequired : 1; // Bit below must be set
- unsigned long fGestaltBit : 5; // Bit to test for presense
-
- public:
- ToolboxManager(OSType gestaltSelector, short gestaltBit = 0,
- ProcPtr entryPoint = nil, bool required = false);
-
- protected:
- void RuntimeCheck(void);
-
- virtual bool Validate(void); // Check against system, possibly re-order
- virtual bool Initialized(void);
- virtual bool InitializeCalled(void);
- virtual void Initialize(void); // Do your thing
-
- virtual void DoInitialization(void);
- };
-
- //--------------------------------------------------------------------------------
-
- #if !qDebug
-
- inline ApplicationHeap& ApplicationHeap::GetApplicationHeap()
- {
- return *gApplicationHeap;
- }
-
- inline Toolbox& Toolbox::GetToolbox()
- {
- return *gToolbox;
- }
-
- #endif
-
-
- #endif // _TOOLBOXMODULES_
-