home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / cdity / smartwin_src.lha / SmartWIN / source / Patch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-16  |  4.7 KB  |  269 lines

  1. /*
  2. **    SmartWIN
  3. **
  4. **        © 1996 by Timo C. Nentwig
  5. **        All Rights Reserved !
  6. **
  7. **        Tcn@oxygen.in-berlin.de
  8. **
  9. */
  10.  
  11. /// #include
  12.  
  13. #include "GST.h"
  14. #include "Protos.h"
  15.  
  16. ///
  17. /// proto
  18.  
  19. static struct Window *        (*__asm    Old_OpenWindowTagList) (REG (a0) struct NewWindow *, REG (a1) struct TagItem *, REG (a6) struct Library *);
  20. proto  struct Window * __saveds __asm    New_OpenWindowTagList  (REG (a0) struct NewWindow *, REG (a1) struct TagItem *, REG (a6) struct Library *);
  21.  
  22. static BOOL    CheckWindow  (const struct NewWindow *NWin, const struct TagItem *WA_Flags_Tag, struct TagItem *TList);
  23. proto  BOOL    InstallWedge (VOID);
  24. proto  VOID    RemoveWedge  (VOID);
  25.  
  26. ///
  27.  
  28.     // TRUE if patch is installed
  29.  
  30. static BOOL    PatchInstalled = FALSE;
  31.  
  32.     // Patch struct
  33.  
  34. struct Patch
  35. {
  36.  
  37.     UWORD    Instruction;
  38.     APTR     Function;
  39.  
  40. } *Patch;
  41.  
  42. /// CheckWindow ()
  43.  
  44.     /*
  45.      *    FUNCTION    Install the patch.
  46.      *
  47.      *    NOTE
  48.      *
  49.      *    EXAMPLE     CheckWindow (NewWindow, TagList);
  50.      *
  51.      */
  52.  
  53. static BOOL
  54. CheckWindow (const struct NewWindow *NWin, const struct TagItem *WA_Flags_Tag, struct TagItem *TList)
  55. {
  56.  
  57.     BOOL    GoOn = TRUE;
  58.  
  59.         // Only WB windows
  60.  
  61.     if (Set -> WBOnly)
  62.     {
  63.  
  64.         if (GetTagData (WA_WBenchWindow, FALSE, TList) == TRUE)
  65.         {
  66.  
  67.             GoOn = TRUE;
  68.  
  69.         }
  70.         else if (NWin)
  71.         {
  72.  
  73.             if (NWin -> Flags & WFLG_WBENCHWINDOW)
  74.             {
  75.  
  76.                 GoOn = TRUE;
  77.  
  78.             }
  79.  
  80.         }
  81.         else if (WA_Flags_Tag)
  82.         {
  83.  
  84.             if (WA_Flags_Tag -> ti_Data & WFLG_WBENCHWINDOW)
  85.             {
  86.  
  87.                 GoOn = TRUE;
  88.  
  89.             }
  90.  
  91.         }
  92.         else
  93.         {
  94.  
  95.             GoOn = FALSE;
  96.  
  97.         }
  98.  
  99.     }
  100.  
  101.     return (GoOn);
  102.  
  103. }
  104.  
  105. ///
  106. /// InstallWedge ()
  107.  
  108.     /*
  109.      *    FUNCTION    Install the patch.
  110.      *
  111.      *    NOTE
  112.      *
  113.      *    EXAMPLE     InstallWedge ();
  114.      *
  115.      */
  116.  
  117. BOOL
  118. InstallWedge (VOID)
  119. {
  120.  
  121.     if (Patch = AllocStruct (Patch))
  122.     {
  123.  
  124.         Forbid();
  125.  
  126.         Patch -> Instruction = 0x4ef9;
  127.         Patch -> Function    = (APTR) New_OpenWindowTagList;
  128.  
  129.             // Patch function: OpenWindowTagList() (-0x25e)
  130.  
  131.         Old_OpenWindowTagList = SetFunction ((struct Library *) IntuitionBase, -0x25e, (APTR) Patch);
  132.  
  133.             // Make sure data gets written to memory
  134.  
  135.         CacheClearU();
  136.  
  137.             // Patch installed
  138.  
  139.         PatchInstalled = TRUE;
  140.  
  141.         Permit();
  142.  
  143.         return (TRUE);
  144.  
  145.     }
  146.  
  147.     return (FALSE);
  148.  
  149. }
  150.  
  151. ///
  152. /// RemoveWedge ()
  153.  
  154.     /*
  155.      *    FUNCTION    Remove the patch.
  156.      *
  157.      *    NOTE
  158.      *
  159.      *    EXAMPLE     RemoveWedge ();
  160.      *
  161.      */
  162.  
  163. VOID
  164. RemoveWedge (VOID)
  165. {
  166.  
  167.     if (PatchInstalled)
  168.     {
  169.  
  170.         Forbid();
  171.  
  172.             // Redirect pointer to original function
  173.  
  174.         Patch -> Function = (APTR) Old_OpenWindowTagList;
  175.  
  176.             // Make sure the data gets written to memory
  177.  
  178.         CacheClearU();
  179.  
  180.         Permit();
  181.  
  182.             // Patch removed
  183.  
  184.         PatchInstalled = FALSE;
  185.  
  186.     }
  187.  
  188. }
  189.  
  190. ///
  191. /// New_OpenWindowTagList ()
  192.  
  193.     /*
  194.      *    FUNCTION    Patch for OpenWindowTagList() using
  195.      *                always smart refresh.
  196.      *
  197.      *    NOTE
  198.      *
  199.      */
  200.  
  201. struct Window * __saveds __asm
  202. New_OpenWindowTagList (REG (a0) struct NewWindow *newWindow, REG (a1) struct TagItem *tagList, REG (a6) struct Library *IntuitionBase)
  203. {
  204.  
  205.     static struct      Window     *WindowPtr;
  206.     static struct      TagItem    *TagListClone;
  207.     static struct      TagItem    *WA_Flags_Tag;
  208.  
  209.     TagListClone = CloneTagItems (tagList);
  210.     WA_Flags_Tag = FindTagItem   (WA_Flags, TagListClone);
  211.  
  212.         // Should we 'smart' this window ?
  213.  
  214.     if (CheckWindow (newWindow, WA_Flags_Tag, TagListClone))
  215.     {
  216.  
  217.             // Modify NewWindow structure
  218.  
  219.         if (newWindow)
  220.         {
  221.  
  222.             newWindow -> Flags &= ~WFLG_SIMPLE_REFRESH;         // clear simple refresh bit
  223.             newWindow -> Flags |=  WFLG_SMART_REFRESH;          // set smart refresh bit
  224.  
  225.         }
  226.  
  227.             // Modify WA_Flags
  228.  
  229.         if (WA_Flags_Tag)
  230.         {
  231.  
  232.             WA_Flags_Tag -> ti_Data &= ~WFLG_SIMPLE_REFRESH;    // clear simple refresh bit
  233.             WA_Flags_Tag -> ti_Data |=  WFLG_SMART_REFRESH;     // set smart refresh bit
  234.  
  235.         }
  236.  
  237.             // Modify TagList, thanks to Olaf Barthel here
  238.  
  239.         if (TagListClone)
  240.         {
  241.  
  242.             Tag    Filter [] = { WA_SimpleRefresh, WA_SmartRefresh, TAG_END };
  243.  
  244.             FilterTagItems (TagListClone, Filter, TAGFILTER_NOT);
  245.  
  246.         }
  247.  
  248.     }
  249.  
  250.         // Open 'smarted' window
  251.  
  252.     WindowPtr = (*Old_OpenWindowTagList) (newWindow, TagListClone, IntuitionBase);
  253.  
  254.         // Free our TagList
  255.  
  256.     if (TagListClone)
  257.     {
  258.  
  259.         FreeTagItems (TagListClone);
  260.  
  261.     }
  262.  
  263.     return (WindowPtr);
  264.  
  265. }
  266.  
  267. ///
  268.  
  269.