home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Layout / Border.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  4.2 KB  |  177 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Border.cpp
  3.  
  4.     Contains:    Implementation of active border display routines
  5.  
  6.     Owned by:    Joshua Susser
  7.  
  8.     Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.     
  12.          <3>     10/4/96    JBS        1263682 don't smash active GrafPort, use
  13.                                     correct colors
  14.          <4>     6/20/95    JBS        1257315 change Facet::AcquireWindow to
  15.                                     GetWindow
  16.          <3>     5/26/95    RR        #1251403: Multithreading naming support
  17.          <2>     5/17/95    JBS        1242496 remove SOM_CATCH
  18.          <1>     2/28/95    JBS        first checked in
  19.          <0>     2/28/95    JBS        1198509 created
  20. */
  21.  
  22. /*
  23. These functions are private utilities for use by ODFacet to display and
  24. invalidate the active border.  The functions are platform-dependent, in
  25. that they make direct calls to the platform graphics system.
  26. */
  27.  
  28. #ifndef _BORDER_
  29. #include "Border.h"
  30. #endif
  31.  
  32. #ifndef _ODTYPES_
  33. #include <ODTypes.h>
  34. #endif
  35.  
  36. #ifndef SOM_ODFacet_xh
  37. #include <Facet.xh>
  38. #endif
  39.  
  40. #ifndef SOM_ODCanvas_xh
  41. #include <Canvas.xh>
  42. #endif
  43.  
  44. #ifndef SOM_ODShape_xh
  45. #include <Shape.xh>
  46. #endif
  47.  
  48. #ifndef SOM_ODWindow_xh
  49. #include <Window.xh>
  50. #endif
  51.  
  52. #ifndef __TYPES__
  53. #include <Types.h>
  54. #endif
  55.  
  56. #ifndef __QUICKDRAW__
  57. #include <QuickDraw.h>
  58. #endif
  59.  
  60. #pragma segment ODFacet
  61.  
  62. //==============================================================================
  63. // Constants
  64. //==============================================================================
  65.  
  66.     static const RGBColor rgbWhite =    { 0xFFFF, 0xFFFF, 0xFFFF };
  67.     static const RGBColor rgbBlack =    { 0x0000, 0x0000, 0x0000 };
  68.  
  69. //==============================================================================
  70. // Global variables
  71. //==============================================================================
  72.  
  73. extern Pattern borderPattern;
  74.  
  75. //==============================================================================
  76. // Functions
  77. //==============================================================================
  78.  
  79. //------------------------------------------------------------------------------
  80. // ODDrawBorder
  81. //------------------------------------------------------------------------------
  82.  
  83. void
  84. ODDrawBorder(Environment *ev, ODShape* borderShape, ODFacet* facet)
  85. {
  86.     GrafPtr        savePort;
  87.     GrafPtr        usePort;
  88.     RgnHandle    saveClip;
  89.     ODSShort    saveH;
  90.     ODSShort    saveV;
  91.     RGBColor    saveBack;
  92.     RGBColor    saveFore;
  93.  
  94.     ODWindow* window = facet->GetWindow(ev);
  95.     if ( window != kODNULL )
  96.     {
  97.         GetPort(&savePort);
  98.         
  99.         usePort = (GrafPtr)(window->GetRootFacet(ev)->
  100.                     GetCanvas(ev)->GetPlatformCanvas(ev, kODQuickDraw));
  101.         SetPort(usePort);
  102.  
  103.         // save old GrafPort state so it can be restored later
  104.         saveClip = ODNewRgn();
  105.         GetClip(saveClip);
  106.         saveH = usePort->portRect.left;
  107.         saveV = usePort->portRect.top;
  108.         GetBackColor(&saveBack);
  109.         GetForeColor(&saveFore);
  110.         
  111.         // set the state we need
  112.         SetOrigin(0,0);
  113.         ClipRect(&(ODQDGlobals.thePort->portRect));
  114.         RGBBackColor(&rgbWhite);
  115.         RGBForeColor(&rgbBlack);
  116.  
  117.         // draw the border
  118.         RgnHandle borderRgn = borderShape->GetQDRegion(ev);
  119.         FillRgn(borderRgn, &borderPattern);
  120.  
  121.         // restore GrafPort state
  122.         RGBBackColor(&saveBack);
  123.         RGBForeColor(&saveFore);
  124.         SetOrigin(saveH, saveV);
  125.         SetClip(saveClip);
  126.         ODDisposeHandle((Handle)saveClip);
  127.         
  128.         SetPort(savePort);
  129.     }
  130. }
  131.  
  132. //------------------------------------------------------------------------------
  133. // ODInvalidateBorder
  134. //------------------------------------------------------------------------------
  135.  
  136. void
  137. ODInvalidateBorder(Environment *ev, ODShape* borderShape, ODFacet* facet)
  138. {
  139.     GrafPtr        savePort;
  140.     GrafPtr        usePort;
  141.     RgnHandle    saveClip;
  142.     ODSShort    saveH;
  143.     ODSShort    saveV;
  144.  
  145.     ODWindow* window = facet->GetWindow(ev);
  146.     if ( window != kODNULL )
  147.     {
  148.         GetPort(&savePort);
  149.         
  150.         usePort = (GrafPtr)(window->GetRootFacet(ev)->
  151.                     GetCanvas(ev)->GetPlatformCanvas(ev, kODQuickDraw));
  152.         SetPort(usePort);
  153.  
  154.         // save old GrafPort state so it can be restored later
  155.         saveClip = ODNewRgn();
  156.         GetClip(saveClip);
  157.         saveH = usePort->portRect.left;
  158.         saveV = usePort->portRect.top;
  159.         
  160.         // set the state we need
  161.         SetOrigin(0,0);
  162.         ClipRect(&(ODQDGlobals.thePort->portRect));
  163.     
  164.         // invalidate the border
  165.         RgnHandle borderRgn = borderShape->GetQDRegion(ev);
  166.         InvalRgn(borderRgn);
  167.         
  168.         // restore GrafPort state
  169.         SetOrigin(saveH, saveV);
  170.         SetClip(saveClip);
  171.         ODDisposeHandle((Handle)saveClip);
  172.  
  173.         SetPort(savePort);
  174.     }
  175. }
  176.  
  177.