home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / Spotlight Hack / source / layers.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-21  |  10.4 KB  |  279 lines  |  [TEXT/CWIE]

  1. #ifndef __LAYERMGR__
  2. #define __LAYERMGR__
  3.  
  4. #include <Processes.h>
  5. #include <MixedMode.h>
  6.  
  7. //Subject: UNofficial description of 2 Layer Manager calls
  8. //From: Hugues Marty, hugues@isoftfr.isoft.fr
  9. //Date: 28 Aug 92 08:11:24 GMT
  10. //
  11. //
  12. //
  13. //This post contains a header and an example of how to use some calls of
  14. //the UNDOCUMENTED (as long as I know) Layer Manager which comes along
  15. //with System 7.  Of course, this is NOT an official document, and is
  16. //here for information only. I don't have News access at the moment (I'm
  17. //sending this via e-mail), so please send mail me copies if you post
  18. //follow-ups.
  19. //
  20. //PS: it only describes 2 calls of the LayerDispatch trap (0xA829).
  21. //PPS: seems to work under 7.1 beta.
  22.  
  23. /* Part of the undocumented Layer Manager structures and calls
  24.  * Information found with the help of MacsBug under MacOS 7.0.
  25.  * Please note that using this information may make your mac
  26.  * explode (hey, this could be a subject for a QuickTime moovie !);
  27.  * so use at your own risks, this may break in the future,
  28.  * etc.. (usual disclaimeer).
  29.  * I only wish that Apple will document this manager in a very near
  30.  * future (let's dream...).
  31.  *
  32.  * What I found was that a layer is associated with each running
  33.  * applications (if it has a user-interface), which groups all
  34.  * windows of that application. This is how you can hide an application
  35.  * (remember 'applications' menu under system 7) and get the list of
  36.  * other applications windows. Have fun.
  37.  *
  38.  * PS : If you have more information on the Layer Manager, please
  39.  * let me know! You can join me at hugues@isoft.fr
  40.  */
  41.  
  42. //    11FEB93        Added descriptions of several more selectors;
  43. //                other minor improvements.
  44. //                Michael Hecht, Michael_Hecht@mac.sas.com
  45.  
  46. //    3/3/98        Added PPC support. It's not extremely well-tested,
  47. //                but you should be able to get it to work easily.
  48. //                BTW, I could not get ForEachLayerWindowDo() to work.
  49. //                David Kamholz, davekam@pobox.com
  50.  
  51. // The _LayerDispatch trap
  52. #define _LayerDispatch    0xA829
  53.  
  54. // LayerRecord is similar to a WindowRecord.
  55. typedef WindowPtr LayerPtr;
  56.  
  57. // This records some information on the process which owns
  58. // the layer... Most of it is not clear (there are pointers
  59. // to other LayerRecords, to a heap zone, etc. in the unknown
  60. // parts)
  61. typedef struct {
  62.     long                unknown1;
  63.     OSType                signature;            // The process sig.
  64.     OSType                creator;            // The process creator
  65.     char                unknown2[24];
  66.     ProcessSerialNumber    layerPSN;            // The process PSN
  67.     char                unknown3[40];
  68.     Handle                moreLayerInfo;        // This handle is 212 bytes sized.
  69. } LayerInfo, *LayerInfoPtr;
  70.  
  71. typedef struct {
  72.     GrafPort            port;                // txSize == 0xDEAD
  73.     short                windowKind;
  74.     Boolean                visible;            // the layer's visibility: HideWindow
  75.     Boolean                hilited;
  76.     Boolean                metaLayer;            // a layer of layers
  77.     Boolean                spareFlag;
  78.     RgnHandle            strucRgn;
  79.     RgnHandle            contRgn;
  80.     RgnHandle            updateRgn;
  81.     Handle                windowDefProc;
  82.     LayerPtr            parentLayer;        // layer of which this is a member
  83.     AuxWinHandle        auxWinHead;            // this layer's AuxWinHead
  84.     short                titleWidth;
  85.     AuxCtlHandle        auxCtlHead;            // this layer's AuxCtlHead
  86.     LayerPtr            nextLayer;            // next layer in the chain
  87.     WindowPtr            windowList;            // this layer's WindowList
  88.     LayerInfoPtr        layerInfo;            // this layer's add'l info: GetWRefCon
  89. } LayerRecord, *LayerPeek;
  90.  
  91.  
  92. typedef short    WindowActionCode;
  93. enum {
  94.     kNextWindow = 0,
  95.     kNextLayer = 700,
  96.     kBreak
  97. };
  98.  
  99. typedef pascal WindowActionCode (*LayerActionProcPtr)(
  100.     WindowPtr theWindow, LayerPtr theLayer, long refCon);
  101. typedef STACK_UPP_TYPE(LayerActionProcPtr) LayerActionUPP;
  102.  
  103. enum {
  104.     uppLayerActionProcInfo = kPascalStackBased
  105.         | RESULT_SIZE(SIZE_CODE(sizeof(WindowActionCode)))
  106.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))
  107.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(LayerPtr)))
  108.         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
  109. };
  110.  
  111. #define NewLayerActionProc(userRoutine) (LayerActionUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppLayerActionProcInfo, GetCurrentArchitecture())
  112. #define CallLayerActionProc(userRoutine, theWindow, theLayer, refCon) CALL_THREE_PARAMETER_UPP((userRoutine), uppLayerActionProcInfo, theWindow, theLayer, refCon)
  113.  
  114. #define kAllLayers ((LayerPtr)-1)
  115.  
  116. // Call the action proc for each window in each layer
  117. #ifdef powerc
  118.     enum {
  119.         uppForEachLayerWindowDoInfo = kD0DispatchedPascalStackBased
  120.             | RESULT_SIZE(SIZE_CODE(sizeof(WindowActionCode)))
  121.             | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
  122.             | REGISTER_RESULT_LOCATION(kRegisterD0)
  123.             | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(LayerPtr)))
  124.             | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(LayerPtr)))
  125.             | DISPATCHED_STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(LayerPtr)))
  126.             | DISPATCHED_STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(LayerActionUPP)))
  127.             | DISPATCHED_STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
  128.     };
  129.  
  130.     #define ForEachLayerWindowDo(layer1, layer2, layer3, layerAction, refCon) \
  131.         (WindowActionCode)CallUniversalProc( \
  132.         NGetTrapAddress(_LayerDispatch, ToolTrap), uppForEachLayerWindowDoInfo, layer1, layer2, layer3, layerAction, refCon, 0x00F8)
  133. #else
  134.     pascal WindowActionCode ForEachLayerWindowDo(
  135.         LayerPtr layer1, LayerPtr layer2, LayerPtr layer3,
  136.         LayerActionUPP layerAction, long refCon ) = { 0x70F8, _LayerDispatch };
  137. #endif
  138.  
  139. // Return the window's layer
  140. #ifdef powerc
  141.     enum {
  142.         uppWindowLayerInfo = kD0DispatchedPascalStackBased
  143.             | RESULT_SIZE(SIZE_CODE(sizeof(LayerPtr)))
  144.             | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
  145.             | REGISTER_RESULT_LOCATION(kRegisterD0)
  146.             | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))
  147.     };
  148.  
  149.     #define WindowLayer(theWindow) (LayerPtr)CallUniversalProc( \
  150.         NGetTrapAddress(_LayerDispatch, ToolTrap), uppWindowLayerInfo, theWindow, 0x00F9)        
  151. #else
  152.     pascal LayerPtr WindowLayer( WindowPtr theWindow ) = { 0x70F9, _LayerDispatch };
  153. #endif
  154.  
  155. // Return the frontmost visible window in the given layer
  156. #ifdef powerc
  157.     enum {
  158.         uppLayerFrontVisibleWindow = kD0DispatchedPascalStackBased
  159.             | RESULT_SIZE(SIZE_CODE(sizeof(WindowPtr)))
  160.             | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
  161.             | REGISTER_RESULT_LOCATION(kRegisterD0)
  162.             | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(LayerPtr)))
  163.     };
  164.  
  165.     #define LayerFrontVisibleWindow(theLayer) (WindowPtr)CallUniversalProc( \
  166.         NGetTrapAddress(_LayerDispatch, ToolTrap), uppLayerFrontVisibleWindow, theLayer, 0x00FD)        
  167. #else
  168.     pascal WindowPtr LayerFrontVisibleWindow( LayerPtr theLayer ) = { 0x70FD, _LayerDispatch };
  169. #endif
  170.  
  171. // Return the frontmost visible window on the desktop
  172. #ifdef powerc
  173.     enum {
  174.         uppDeskFrontVisibleWindowInfo = kD0DispatchedPascalStackBased
  175.             | RESULT_SIZE(SIZE_CODE(sizeof(WindowPtr)))
  176.             | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
  177.             | REGISTER_RESULT_LOCATION(kRegisterD0)
  178.     };
  179.  
  180.     #define DeskFrontVisibleWindow() (WindowPtr)CallUniversalProc( \
  181.         NGetTrapAddress(_LayerDispatch, ToolTrap), uppDeskFrontVisibleWindowInfo, 0x00FE)        
  182. #else
  183.     pascal WindowPtr DeskFrontVisibleWindow( void ) = { 0x70FE, _LayerDispatch };
  184. #endif
  185.  
  186. // Return the desktop's layer (contains all other layers)
  187. #ifdef powerc
  188.     enum {
  189.         uppDeskLayerInfo = kD0DispatchedPascalStackBased
  190.             | RESULT_SIZE(SIZE_CODE(sizeof(LayerPtr)))
  191.             | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
  192.             | REGISTER_RESULT_LOCATION(kRegisterD0)
  193.     };
  194.  
  195.     #define DeskLayer() (LayerPtr)CallUniversalProc( \
  196.         NGetTrapAddress(_LayerDispatch, ToolTrap), uppDeskLayerInfo, 0x00FF)        
  197. #else
  198.     pascal LayerPtr DeskLayer( void ) = { 0x70FF, _LayerDispatch };
  199. #endif
  200.  
  201. // Return TRUE if theLayer is really a LayerPtr; return FALSE if it's a WindowPtr
  202. #ifdef powerc
  203.     enum {
  204.         uppIsLayerInfo = kD0DispatchedPascalStackBased
  205.             | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  206.             | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
  207.             | REGISTER_RESULT_LOCATION(kRegisterD0)
  208.             | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(LayerPtr)))
  209.     };
  210.  
  211.     #define IsLayer(theLayer) (Boolean)CallUniversalProc( \
  212.         NGetTrapAddress(_LayerDispatch, ToolTrap), uppIsLayerInfo, theLayer, 0x0002)        
  213. #else
  214.     pascal Boolean IsLayer( LayerPtr theLayer ) = { 0x7002, _LayerDispatch };
  215. #endif
  216.  
  217. // Return the current process' layer
  218. #ifdef powerc
  219.     enum {
  220.         uppCurrentLayerInfo = kD0DispatchedPascalStackBased
  221.             | RESULT_SIZE(SIZE_CODE(sizeof(LayerPtr)))
  222.             | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
  223.             | REGISTER_RESULT_LOCATION(kRegisterD0)
  224.     };
  225.  
  226.     #define CurrentLayer() (LayerPtr)CallUniversalProc( \
  227.         NGetTrapAddress(_LayerDispatch, ToolTrap), uppCurrentLayerInfo, 0x0003)
  228. #else
  229.     pascal LayerPtr CurrentLayer( void ) = { 0x7003, _LayerDispatch };
  230. #endif    
  231.  
  232. // Return the first window of this layer.
  233. #ifdef powerc
  234.     enum {
  235.         uppLayerFrontWindowInfo = kD0DispatchedPascalStackBased
  236.             | RESULT_SIZE(SIZE_CODE(sizeof(LayerPtr)))
  237.             | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
  238.             | REGISTER_RESULT_LOCATION(kRegisterD0)
  239.             | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(LayerPtr)))
  240.     };
  241.  
  242.     #define LayerFrontWindow(theLayer) (WindowPtr)CallUniversalProc( \
  243.         NGetTrapAddress(_LayerDispatch, ToolTrap), uppLayerFrontWindowInfo, theLayer, 0x0006)
  244. #else
  245.     pascal WindowPtr LayerFrontWindow( LayerPtr theLayer ) = { 0x7006, _LayerDispatch };
  246. #endif
  247.  
  248. // All-layer version of FindWindow
  249. #ifdef powerc
  250.     enum {
  251.         uppFindLayerWindow = kD0DispatchedPascalStackBased
  252.             | RESULT_SIZE(SIZE_CODE(sizeof(short)))
  253.             | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(SIZE_CODE(sizeof(short)))
  254.             | REGISTER_RESULT_LOCATION(kRegisterD0)
  255.             | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Point)))
  256.             | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(WindowPtr*)))
  257.     };
  258.  
  259.     #define FindLayerWindow(where, foundWindow) (short)CallUniversalProc( \
  260.         NGetTrapAddress(_LayerDispatch, ToolTrap), uppFindLayerWindow, where, foundWindow, 0x0007)
  261. #else
  262.     pascal short FindLayerWindow( Point where, WindowPtr *foundWindow ) = { 0x7007, _LayerDispatch };
  263. #endif
  264.  
  265. // macros
  266.  
  267. #define LayerVisible(theLayer)    (((LayerPeek)theLayer)->visible)
  268. #define GetNextLayer(theLayer) (((LayerPeek)theLayer)->nextLayer)
  269. #define GetLayerInfo(theLayer) (((LayerPeek)theLayer)->layerInfo)
  270. #define HideLayer(theLayer) HideWindow((WindowPtr)theLayer)
  271. #define ShowLayer(theLayer) ShowWindow((WindowPtr)theLayer)
  272. #define ShowHideLayer(theLayer,showFlag) ShowHide((WindowPtr)theLayer, showFlag)
  273.  
  274. // GetLayerName will return an address in a handle. Be aware of that.
  275. #define GetLayerName(theLayer) \
  276. (unsigned char *) ( (*GetLayerInfo(theLayer)->moreLayerInfo) + 0x38)
  277.  
  278. #endif
  279.