home *** CD-ROM | disk | FTP | other *** search
- #ifndef __LAYERMGR__
- #define __LAYERMGR__
-
- #include <Processes.h>
- #include <MixedMode.h>
-
- //Subject: UNofficial description of 2 Layer Manager calls
- //From: Hugues Marty, hugues@isoftfr.isoft.fr
- //Date: 28 Aug 92 08:11:24 GMT
- //
- //
- //
- //This post contains a header and an example of how to use some calls of
- //the UNDOCUMENTED (as long as I know) Layer Manager which comes along
- //with System 7. Of course, this is NOT an official document, and is
- //here for information only. I don't have News access at the moment (I'm
- //sending this via e-mail), so please send mail me copies if you post
- //follow-ups.
- //
- //PS: it only describes 2 calls of the LayerDispatch trap (0xA829).
- //PPS: seems to work under 7.1 beta.
-
- /* Part of the undocumented Layer Manager structures and calls
- * Information found with the help of MacsBug under MacOS 7.0.
- * Please note that using this information may make your mac
- * explode (hey, this could be a subject for a QuickTime moovie !);
- * so use at your own risks, this may break in the future,
- * etc.. (usual disclaimeer).
- * I only wish that Apple will document this manager in a very near
- * future (let's dream...).
- *
- * What I found was that a layer is associated with each running
- * applications (if it has a user-interface), which groups all
- * windows of that application. This is how you can hide an application
- * (remember 'applications' menu under system 7) and get the list of
- * other applications windows. Have fun.
- *
- * PS : If you have more information on the Layer Manager, please
- * let me know! You can join me at hugues@isoft.fr
- */
-
- // 11FEB93 Added descriptions of several more selectors;
- // other minor improvements.
- // Michael Hecht, Michael_Hecht@mac.sas.com
-
- // 3/3/98 Added PPC support. It's not extremely well-tested,
- // but you should be able to get it to work easily.
- // BTW, I could not get ForEachLayerWindowDo() to work.
- // David Kamholz, davekam@pobox.com
-
- // The _LayerDispatch trap
- #define _LayerDispatch 0xA829
-
- // LayerRecord is similar to a WindowRecord.
- typedef WindowPtr LayerPtr;
-
- // This records some information on the process which owns
- // the layer... Most of it is not clear (there are pointers
- // to other LayerRecords, to a heap zone, etc. in the unknown
- // parts)
- typedef struct {
- long unknown1;
- OSType signature; // The process sig.
- OSType creator; // The process creator
- char unknown2[24];
- ProcessSerialNumber layerPSN; // The process PSN
- char unknown3[40];
- Handle moreLayerInfo; // This handle is 212 bytes sized.
- } LayerInfo, *LayerInfoPtr;
-
- typedef struct {
- GrafPort port; // txSize == 0xDEAD
- short windowKind;
- Boolean visible; // the layer's visibility: HideWindow
- Boolean hilited;
- Boolean metaLayer; // a layer of layers
- Boolean spareFlag;
- RgnHandle strucRgn;
- RgnHandle contRgn;
- RgnHandle updateRgn;
- Handle windowDefProc;
- LayerPtr parentLayer; // layer of which this is a member
- AuxWinHandle auxWinHead; // this layer's AuxWinHead
- short titleWidth;
- AuxCtlHandle auxCtlHead; // this layer's AuxCtlHead
- LayerPtr nextLayer; // next layer in the chain
- WindowPtr windowList; // this layer's WindowList
- LayerInfoPtr layerInfo; // this layer's add'l info: GetWRefCon
- } LayerRecord, *LayerPeek;
-
-
- typedef short WindowActionCode;
- enum {
- kNextWindow = 0,
- kNextLayer = 700,
- kBreak
- };
-
- typedef pascal WindowActionCode (*LayerActionProcPtr)(
- WindowPtr theWindow, LayerPtr theLayer, long refCon);
- typedef STACK_UPP_TYPE(LayerActionProcPtr) LayerActionUPP;
-
- enum {
- uppLayerActionProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(WindowActionCode)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(LayerPtr)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
- };
-
- #define NewLayerActionProc(userRoutine) (LayerActionUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppLayerActionProcInfo, GetCurrentArchitecture())
- #define CallLayerActionProc(userRoutine, theWindow, theLayer, refCon) CALL_THREE_PARAMETER_UPP((userRoutine), uppLayerActionProcInfo, theWindow, theLayer, refCon)
-
- #define kAllLayers ((LayerPtr)-1)
-
- // Call the action proc for each window in each layer
- #ifdef powerc
- enum {
- uppForEachLayerWindowDoInfo = kD0DispatchedPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(WindowActionCode)))
- | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(LayerPtr)))
- | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(LayerPtr)))
- | DISPATCHED_STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(LayerPtr)))
- | DISPATCHED_STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(LayerActionUPP)))
- | DISPATCHED_STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
- };
-
- #define ForEachLayerWindowDo(layer1, layer2, layer3, layerAction, refCon) \
- (WindowActionCode)CallUniversalProc( \
- NGetTrapAddress(_LayerDispatch, ToolTrap), uppForEachLayerWindowDoInfo, layer1, layer2, layer3, layerAction, refCon, 0x00F8)
- #else
- pascal WindowActionCode ForEachLayerWindowDo(
- LayerPtr layer1, LayerPtr layer2, LayerPtr layer3,
- LayerActionUPP layerAction, long refCon ) = { 0x70F8, _LayerDispatch };
- #endif
-
- // Return the window's layer
- #ifdef powerc
- enum {
- uppWindowLayerInfo = kD0DispatchedPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(LayerPtr)))
- | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))
- };
-
- #define WindowLayer(theWindow) (LayerPtr)CallUniversalProc( \
- NGetTrapAddress(_LayerDispatch, ToolTrap), uppWindowLayerInfo, theWindow, 0x00F9)
- #else
- pascal LayerPtr WindowLayer( WindowPtr theWindow ) = { 0x70F9, _LayerDispatch };
- #endif
-
- // Return the frontmost visible window in the given layer
- #ifdef powerc
- enum {
- uppLayerFrontVisibleWindow = kD0DispatchedPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(WindowPtr)))
- | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(LayerPtr)))
- };
-
- #define LayerFrontVisibleWindow(theLayer) (WindowPtr)CallUniversalProc( \
- NGetTrapAddress(_LayerDispatch, ToolTrap), uppLayerFrontVisibleWindow, theLayer, 0x00FD)
- #else
- pascal WindowPtr LayerFrontVisibleWindow( LayerPtr theLayer ) = { 0x70FD, _LayerDispatch };
- #endif
-
- // Return the frontmost visible window on the desktop
- #ifdef powerc
- enum {
- uppDeskFrontVisibleWindowInfo = kD0DispatchedPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(WindowPtr)))
- | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- };
-
- #define DeskFrontVisibleWindow() (WindowPtr)CallUniversalProc( \
- NGetTrapAddress(_LayerDispatch, ToolTrap), uppDeskFrontVisibleWindowInfo, 0x00FE)
- #else
- pascal WindowPtr DeskFrontVisibleWindow( void ) = { 0x70FE, _LayerDispatch };
- #endif
-
- // Return the desktop's layer (contains all other layers)
- #ifdef powerc
- enum {
- uppDeskLayerInfo = kD0DispatchedPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(LayerPtr)))
- | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- };
-
- #define DeskLayer() (LayerPtr)CallUniversalProc( \
- NGetTrapAddress(_LayerDispatch, ToolTrap), uppDeskLayerInfo, 0x00FF)
- #else
- pascal LayerPtr DeskLayer( void ) = { 0x70FF, _LayerDispatch };
- #endif
-
- // Return TRUE if theLayer is really a LayerPtr; return FALSE if it's a WindowPtr
- #ifdef powerc
- enum {
- uppIsLayerInfo = kD0DispatchedPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
- | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(LayerPtr)))
- };
-
- #define IsLayer(theLayer) (Boolean)CallUniversalProc( \
- NGetTrapAddress(_LayerDispatch, ToolTrap), uppIsLayerInfo, theLayer, 0x0002)
- #else
- pascal Boolean IsLayer( LayerPtr theLayer ) = { 0x7002, _LayerDispatch };
- #endif
-
- // Return the current process' layer
- #ifdef powerc
- enum {
- uppCurrentLayerInfo = kD0DispatchedPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(LayerPtr)))
- | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- };
-
- #define CurrentLayer() (LayerPtr)CallUniversalProc( \
- NGetTrapAddress(_LayerDispatch, ToolTrap), uppCurrentLayerInfo, 0x0003)
- #else
- pascal LayerPtr CurrentLayer( void ) = { 0x7003, _LayerDispatch };
- #endif
-
- // Return the first window of this layer.
- #ifdef powerc
- enum {
- uppLayerFrontWindowInfo = kD0DispatchedPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(LayerPtr)))
- | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(LayerPtr)))
- };
-
- #define LayerFrontWindow(theLayer) (WindowPtr)CallUniversalProc( \
- NGetTrapAddress(_LayerDispatch, ToolTrap), uppLayerFrontWindowInfo, theLayer, 0x0006)
- #else
- pascal WindowPtr LayerFrontWindow( LayerPtr theLayer ) = { 0x7006, _LayerDispatch };
- #endif
-
- // All-layer version of FindWindow
- #ifdef powerc
- enum {
- uppFindLayerWindow = kD0DispatchedPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(short)))
- | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Point)))
- | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(WindowPtr*)))
- };
-
- #define FindLayerWindow(where, foundWindow) (short)CallUniversalProc( \
- NGetTrapAddress(_LayerDispatch, ToolTrap), uppFindLayerWindow, where, foundWindow, 0x0007)
- #else
- pascal short FindLayerWindow( Point where, WindowPtr *foundWindow ) = { 0x7007, _LayerDispatch };
- #endif
-
- // macros
-
- #define LayerVisible(theLayer) (((LayerPeek)theLayer)->visible)
- #define GetNextLayer(theLayer) (((LayerPeek)theLayer)->nextLayer)
- #define GetLayerInfo(theLayer) (((LayerPeek)theLayer)->layerInfo)
- #define HideLayer(theLayer) HideWindow((WindowPtr)theLayer)
- #define ShowLayer(theLayer) ShowWindow((WindowPtr)theLayer)
- #define ShowHideLayer(theLayer,showFlag) ShowHide((WindowPtr)theLayer, showFlag)
-
- // GetLayerName will return an address in a handle. Be aware of that.
- #define GetLayerName(theLayer) \
- (unsigned char *) ( (*GetLayerInfo(theLayer)->moreLayerInfo) + 0x38)
-
- #endif
-