home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / Canvas.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  17KB  |  581 lines

  1. /* @(#)Z 1.7 com/src/imaging/Canvas.cpp, odimaging, od96os2, odos29712d 97/03/21 17:18:17 (96/10/29 09:24:55) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odimaging
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //       
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29. //********************************************************************/
  30. /*  Licensed Materials - Property of IBM                            */
  31. /*                                                                  */
  32. /*                                                                  */
  33. /* Copyright (C) International Business Machines Corp., 1994.       */
  34. /* Copyright (C) Apple Computer, Inc., 1994                         */
  35. /*                                                                  */
  36. /*  US Government Users Restricted Rights -                         */
  37. /*  Use, duplication, or disclosure restricted                      */
  38. /*  by GSA ADP Schedule Contract with IBM Corp.                     */
  39. /*                                                                  */
  40. /*  IBM Change History (most recent first):                         */
  41. /*          5/15/96 jab  Corrections for OS/2 port.                 */
  42. /*          3/11/96 jab  Merge with Apple DR4.                      */
  43. /*                       Changes for cross-platform support.        */
  44. /*  120604  4/28/95 ced  Merge with B1C16 Apple code.               */
  45. /*  <OS2>   8/27/94 MAP  Port A8C3                                  */
  46. /*                                                                  */
  47. /********************************************************************/
  48. /*
  49.     File:        Canvas.cpp
  50.  
  51.     Contains:    ODCanvas, a Macintosh drawing environment.
  52.  
  53.     Owned by:    Jens Alfke
  54.     Owned by:    Jens Alfke, Joshua Susser
  55.  
  56.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  57.  
  58.     Change History (most recent first):
  59.  
  60.          <9>     9/18/95    JBS        1285042 don't use QD grafport calls for
  61.                                     in/validation when printing
  62.          <8>      8/7/95    JBS        1275083 added Invalidate & Validate (moved
  63.                                     from ODFacet)
  64.          <7>     5/25/95    jpa        Use new GX headers [1241078, 1253324]
  65.          <6>     3/20/95    jpa        Create gxViewPort when asked for it
  66.                                     [1218787]. SOM_CATCH --> SOM_TRY [1224355].
  67.          <5>     12/5/94    jpa        Fixes from code review. [1203923]
  68.          <4>     9/29/94    RA        1189812: Mods for 68K build.
  69.          <3>     8/17/94    jpa        Function prefixes. [1181512]
  70.          <2>      8/8/94    jpa        API changes for multiformat canvases & bias
  71.                                     transforms [1179683, 1178688]
  72.          <1>     6/15/94    jpa        first checked in
  73.  
  74.     To Do:
  75.     In Progress:
  76. */
  77.  
  78.  
  79. #define ODCanvas_Class_Source
  80. #define VARIABLE_MACROS
  81. #include <Canvas.xih>
  82.  
  83. #include <PlatCanv.xih>
  84.  
  85. #ifdef _PLATFORM_OS2_
  86. #define INCL_WINWINDOWMGR
  87. #include <os2.h>
  88. #endif
  89.  
  90. #ifdef _PLATFORM_MACINTOSH_
  91. #ifndef _REALSHPE_
  92. #include "RealShpe.h"    /* For gGX */
  93. #endif
  94. #endif  // _PLATFORM_MACINTOSH_
  95.  
  96. #ifndef _EXCEPT_
  97. #include <Except.h>
  98. #endif
  99.  
  100. #ifdef _PLATFORM_MACINTOSH_
  101. #ifndef __GXENVIRONMENT__
  102. #include <GXEnvironment.h>
  103. #endif
  104. #endif  // _PLATFORM_MACINTOSH_
  105.  
  106.  
  107.  
  108. //------------------------------------------------------------------------------
  109. // CreatePlatformCanvas
  110. //------------------------------------------------------------------------------
  111.  
  112. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_AIX_)
  113. SOM_Scope ODPlatformCanvas* SOMLINK ODCanvasCreatePlatformCanvas(ODCanvas *somSelf, Environment *ev,
  114.         ODGraphicsSystem g,
  115.     ODBoolean isDynamic,
  116.     ODBoolean isOffScreen )
  117. {
  118.   ODCanvasData *somThis = ODCanvasGetData(somSelf);
  119.   ODCanvasMethodDebug("ODCanvas","CreatePlatformCanvas");
  120.  
  121.   ODPlatformCanvas* newPC;
  122.   ODPlatformCanvas *c = new ODPlatformCanvas;
  123.  
  124.   SOM_TRY
  125.  
  126.     newPC = c->CreateConcreteCanvas( ev, g, isDynamic, isOffScreen );
  127.     delete c;
  128.     return newPC;
  129.  
  130.   SOM_CATCH_ALL
  131.     delete c;
  132.     return kODNULL;
  133.   SOM_ENDTRY
  134.  
  135. }
  136.  
  137. #endif  // _PLATFORM_WIN32_
  138.  
  139.  
  140. //------------------------------------------------------------------------------
  141. // InitCanvas
  142. //------------------------------------------------------------------------------
  143.  
  144. SOM_Scope void  SOMLINK ODCanvasInitCanvas(ODCanvas *somSelf, Environment *ev,
  145.         ODGraphicsSystem graphicsSystem,
  146. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_AIX_)
  147.         ODPlatformCanvas *platformCanvas,
  148. #else
  149.         ODPlatformCanvas platformCanvas,
  150. #endif
  151.         ODBoolean isDynamic,
  152.         ODBoolean isOffscreen)
  153. {
  154.     ODCanvasData *somThis = ODCanvasGetData(somSelf);
  155.     ODCanvasMethodDebug("ODCanvas","InitCanvas");
  156.     
  157.     somSelf->InitBaseCanvas( ev, isDynamic, isOffscreen );
  158.  
  159.     // 
  160.     // OS/2 Specific code
  161.     //
  162. #ifdef _PLATFORM_OS2_
  163.  
  164.     // OS/2 Specific code
  165.     if ( graphicsSystem == kODPM )
  166.        _fPlatformCanvas = platformCanvas;
  167.     else
  168.        ODSetSOMException( ev, kODErrInvalidGraphicsSystem );
  169.  
  170. #endif  // _PLATFORM_OS2_
  171.  
  172.  
  173.     // 
  174.     // Windows Specific code
  175.     //
  176. #ifdef _PLATFORM_WIN32_
  177.  
  178.     if ( (graphicsSystem == kODWin32) || (graphicsSystem == kODWin95) || (graphicsSystem == kODWinNT) ) 
  179.        _fPlatformCanvas = platformCanvas;
  180.     else
  181.        ODSetSOMException( ev, kODErrInvalidGraphicsSystem );
  182.  
  183. #endif  // _PLATFORM_WIN32_
  184.  
  185.     // 
  186.     // AIX Specific code
  187.     //
  188. #ifdef _PLATFORM_AIX_
  189.  
  190.     if ( graphicsSystem == kODAIX )
  191.        _fPlatformCanvas = platformCanvas;
  192.     else
  193.        ODSetSOMException( ev, kODErrInvalidGraphicsSystem );
  194.  
  195. #endif  // _PLATFORM_AIX_
  196.  
  197.     // 
  198.     // Macintosh Specific code
  199.     //
  200. #ifdef _PLATFORM_MACINTOSH_
  201.  
  202.     if( graphicsSystem == kODQuickDraw )
  203.         _fQDCanvas= platformCanvas;
  204.     else if( graphicsSystem == kODQuickDrawGX )
  205.         _fGXCanvas = platformCanvas;
  206.     else
  207.         ODSetSOMException(ev, kODErrInvalidGraphicsSystem);
  208.  
  209. #endif  // _PLATFORM_MACINTOSH_
  210.  
  211. }
  212.  
  213.  
  214. //------------------------------------------------------------------------------
  215. // HasPlatformCanvas
  216. //------------------------------------------------------------------------------
  217.  
  218. SOM_Scope ODBoolean  SOMLINK ODCanvasHasPlatformCanvas(ODCanvas *somSelf, Environment *ev,
  219.         ODGraphicsSystem g)
  220. {
  221.     ODCanvasData *somThis = ODCanvasGetData(somSelf);
  222.     ODCanvasMethodDebug("ODCanvas","HasPlatformCanvas");
  223.  
  224.  
  225.     // 
  226.     // OS/2 Specific code
  227.     //
  228. #ifdef _PLATFORM_OS2_
  229.  
  230.     if( g == kODPM )
  231.        return ( _fPlatformCanvas != kODNULL );
  232.     else
  233.        return kODFalse;
  234.  
  235. #endif  // _PLATFORM_OS2_
  236.  
  237.  
  238.     // 
  239.     // Windows Specific code
  240.     //
  241. #ifdef _PLATFORM_WIN32_
  242.  
  243.     if ( (g == kODWin32) || (g == kODWin95) || (g == kODWinNT) ) 
  244.        return ( _fPlatformCanvas != kODNULL );
  245.     else
  246.        return kODFalse;
  247.  
  248. #endif  // _PLATFORM_WIN32
  249.  
  250.  
  251.     // 
  252.     // AIX Specific code
  253.     //
  254. #ifdef _PLATFORM_AIX_
  255.  
  256.     if (g == kODAIX)
  257.        return ( _fPlatformCanvas != kODNULL );
  258.     else
  259.        return kODFalse;
  260.  
  261. #endif  // _PLATFORM_AIX
  262.  
  263.  
  264.     // 
  265.     // Macintosh Specific code
  266.     //
  267. #ifdef _PLATFORM_MACINTOSH_
  268.  
  269.     if( g == kODQuickDraw )
  270.         return _fQDCanvas != kODNULL;
  271.     else if( g == kODQuickDrawGX )
  272.         return _fGXCanvas != kODNULL || (gGX && _fQDCanvas != kODNULL);
  273.     else
  274.         return kODFalse;
  275.  
  276. #endif  // _PLATFORM_MACINTOSH_
  277.  
  278. }
  279.  
  280. //------------------------------------------------------------------------------
  281. // GetPlatformCanvas
  282. //------------------------------------------------------------------------------
  283.  
  284. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_AIX_)
  285. SOM_Scope ODPlatformCanvas* SOMLINK ODCanvasGetPlatformCanvas(ODCanvas *somSelf, Environment *ev,
  286. #else
  287. SOM_Scope ODPlatformCanvas  SOMLINK ODCanvasGetPlatformCanvas(ODCanvas *somSelf, Environment *ev,
  288. #endif
  289.         ODGraphicsSystem g)
  290. {
  291.     ODCanvasData *somThis = ODCanvasGetData(somSelf);
  292.     ODCanvasMethodDebug("ODCanvas","GetPlatformCanvas");
  293.  
  294.  
  295.     // 
  296.     // OS/2 Specific code
  297.     //
  298. #ifdef _PLATFORM_OS2_
  299.  
  300.     ODPlatformCanvas* c;
  301.     if( g == kODPM )  {
  302.        c = _fPlatformCanvas;
  303.        return c;
  304.     }
  305.     else
  306.        c = kODNULL;
  307.  
  308. #endif // _PLATFORM_OS2_
  309.  
  310.  
  311.  
  312.     // 
  313.     // Windows Specific code
  314.     //
  315. #ifdef _PLATFORM_WIN32_
  316.  
  317.     ODPlatformCanvas* c;
  318.     if ( (g == kODWin32) || (g == kODWin95) || (g == kODWinNT) )  {
  319.        c = _fPlatformCanvas;
  320.        return c;
  321.     }
  322.     else
  323.        c = kODNULL;
  324.  
  325. #endif // _PLATFORM_WIN32_
  326.  
  327.  
  328.  
  329.     // 
  330.     // AIX Specific code
  331.     //
  332. #ifdef _PLATFORM_AIX_
  333.  
  334.     ODPlatformCanvas* c;
  335.     if ( g == kODAIX ) {
  336.        c = _fPlatformCanvas;
  337.        return c;
  338.     }
  339.     else
  340.        c = kODNULL;
  341.  
  342. #endif // _PLATFORM_AIX_
  343.  
  344.  
  345.  
  346.     // 
  347.     // Macintosh Specific code
  348.     //
  349. #ifdef _PLATFORM_MACINTOSH_
  350.  
  351.     ODPlatformCanvas c;
  352.     if( g == kODQuickDraw )
  353.         c= _fQDCanvas;
  354.     else if( g == kODQuickDrawGX ) {
  355.         if( !_fGXCanvas ) {
  356.             (void) ODCanvas__GetGXViewport(somSelf,ev);
  357.             if( ev->_major )
  358.                 return kODNULL;
  359.         }
  360.         c = _fGXCanvas;
  361.     } else
  362.         c = kODNULL;
  363.  
  364. #endif  // _PLATFORM_MACINTOSH_
  365.  
  366.     
  367.     if( c == kODNULL )
  368.         ODSetSOMException( ev, kODErrInvalidGraphicsSystem );
  369.     return c;
  370.  
  371. }
  372.  
  373.  
  374. //------------------------------------------------------------------------------
  375. // SetPlatformCanvas
  376. //------------------------------------------------------------------------------
  377.  
  378. SOM_Scope void  SOMLINK ODCanvasSetPlatformCanvas(ODCanvas *somSelf, Environment *ev,
  379.         ODGraphicsSystem g,
  380. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_AIX_)
  381.         ODPlatformCanvas* c)
  382. #else
  383.         ODPlatformCanvas c)
  384. #endif
  385. {
  386.     ODCanvasData *somThis = ODCanvasGetData(somSelf);
  387.     ODCanvasMethodDebug("ODCanvas","SetPlatformCanvas");
  388.  
  389.  
  390.  
  391.     // 
  392.     // OS/2 Specific code
  393.     //
  394. #ifdef _PLATFORM_OS2_
  395.  
  396.     if ( g == kODPM )
  397.       _fPlatformCanvas = c;
  398.     else
  399.       ODSetSOMException( ev, kODErrInvalidGraphicsSystem );
  400.  
  401. #endif // _PLATFORM_OS2_
  402.  
  403.  
  404.     // 
  405.     // Windows Specific code
  406.     //
  407. #ifdef _PLATFORM_WIN32_
  408.  
  409.     if ( (g == kODWin32) || (g == kODWin95) || (g == kODWinNT) ) 
  410.       _fPlatformCanvas = c;
  411.     else
  412.       ODSetSOMException( ev, kODErrInvalidGraphicsSystem );
  413.  
  414. #endif // _PLATFORM_WIN32_
  415.  
  416.  
  417.  
  418.     // 
  419.     // AIX Specific code
  420.     //
  421. #ifdef _PLATFORM_AIX_
  422.  
  423.     if ( g == kODAIX )
  424.       _fPlatformCanvas = c;
  425.     else
  426.       ODSetSOMException( ev, kODErrInvalidGraphicsSystem );
  427.  
  428. #endif // _PLATFORM_AIX_
  429.  
  430.  
  431.     // 
  432.     // Macintosh Specific code
  433.     //
  434. #ifdef _PLATFORM_MACINTOSH_
  435.  
  436.     if( g == kODQuickDraw )
  437.         _fQDCanvas= c;
  438.     else if( g == kODQuickDrawGX )
  439.         _fGXCanvas = c;
  440.     else
  441.         ODSetSOMException(ev, kODErrInvalidGraphicsSystem);
  442.  
  443. #endif  // _PLATFORM_MACINTOSH_
  444.  
  445. }
  446.  
  447.  
  448. // 
  449. // Macintosh Specific methods
  450. //
  451. #ifdef _PLATFORM_MACINTOSH_
  452.  
  453. //------------------------------------------------------------------------------
  454. // GetQDPort
  455. //------------------------------------------------------------------------------
  456.  
  457. SOM_Scope GrafPtr  SOMLINK ODCanvas__GetQDPort(ODCanvas *somSelf, Environment *ev)
  458. {
  459.     ODCanvasData *somThis = ODCanvasGetData(somSelf);
  460.     ODCanvasMethodDebug("ODCanvas","GetQDPort");
  461.  
  462.     if( !_fQDCanvas )
  463.         ODSetSOMException(ev, kODErrInvalidGraphicsSystem);
  464.     return (GrafPtr)_fQDCanvas;
  465. }
  466.  
  467.  
  468. //------------------------------------------------------------------------------
  469. // GetGXViewport
  470. //------------------------------------------------------------------------------
  471.  
  472. SOM_Scope ODPlatformCanvas  SOMLINK ODCanvas__GetGXViewport(ODCanvas *somSelf, Environment *ev)
  473. {
  474.     ODCanvasData *somThis = ODCanvasGetData(somSelf);
  475.     ODCanvasMethodDebug("ODCanvas","GetGXViewport");
  476.  
  477.     if( !_fGXCanvas ) {
  478.         SOM_TRY
  479.             if( !gGX || !_fQDCanvas )
  480.                 THROW(kODErrInvalidGraphicsSystem);
  481.             else if( somSelf->IsOffscreen(ev) ) {
  482.                 THROW(kODErrNotImplemented);    // $$$$$
  483.             } else {
  484.                 ClearGXError();
  485.                 gxViewPort v = GXGetWindowViewPort((WindowPtr)_fQDCanvas);
  486.                 if( !v )
  487.                     v = GXNewWindowViewPort((WindowPtr)_fQDCanvas);
  488.                 ThrowIfFirstGXError();
  489.                 _fGXCanvas = (ODPlatformCanvas) v;
  490.             }
  491.         SOM_CATCH_ALL
  492.         SOM_ENDTRY
  493.     }
  494.     return _fGXCanvas;
  495. }
  496.  
  497.  
  498. //
  499. // jab 03/13/96
  500. //
  501. // In the Apple DR4 drop, the ODCanvas overrode the Invalidate and 
  502. // Validate methods though it's not very clear as to why.  The OS/2 
  503. // implementation of ODCanvas from 02/13/96 did not override these methods.
  504. // At this time, it appears as though the overridding of these methods
  505. // in ODCanvas is necessary in the Mac implementation, but may not be 
  506. // necessary in other implementations.  We can always override these
  507. // methods, if necessary, on a platform by platform basis.  We'll have to
  508. // change the IDL for ODCanvas to not override these methods and simply
  509. // use the parent's implementation.
  510. //
  511.  
  512.  
  513. //------------------------------------------------------------------------------
  514. // Invalidate
  515. //------------------------------------------------------------------------------
  516.  
  517. SOM_Scope void  SOMLINK ODCanvas__Invalidate(ODCanvas *somSelf, Environment *ev,
  518.         ODShape* shape)
  519. {
  520.     ODCanvasData *somThis = ODCanvasGetData(somSelf);
  521.     ODCanvasMethodDebug("ODCanvas","Invalidate");
  522.  
  523.     SOM_TRY
  524.  
  525.     if ( somSelf->IsOffscreen(ev) )
  526.         parent_Invalidate(somSelf, ev, shape);
  527.     else if ( _fQDCanvas != kODNULL
  528.             && !somSelf->HasPlatformPrintJob(ev, kODQuickDraw) )
  529.     {
  530.         GrafPtr savedPort;
  531.         GrafPtr windowPort = (GrafPtr)_fQDCanvas;
  532.         GetPort(&savedPort);
  533.         SetPort(windowPort);
  534.         short oldLeft = windowPort->portRect.left;
  535.         short oldTop = windowPort->portRect.top;
  536.         SetOrigin(0, 0);
  537.         InvalRgn(shape->GetQDRegion(ev));
  538.         SetOrigin(oldLeft, oldTop);
  539.         SetPort(savedPort);
  540.     }
  541.         
  542.     SOM_CATCH_ALL
  543.     SOM_ENDTRY
  544. }
  545.  
  546. //------------------------------------------------------------------------------
  547. // Validate
  548. //------------------------------------------------------------------------------
  549.  
  550. SOM_Scope void  SOMLINK ODCanvas__Validate(ODCanvas *somSelf, Environment *ev,
  551.         ODShape* shape)
  552. {
  553.     ODCanvasData *somThis = ODCanvasGetData(somSelf);
  554.     ODCanvasMethodDebug("ODCanvas","Validate");
  555.  
  556.     SOM_TRY
  557.  
  558.     if ( somSelf->IsOffscreen(ev) )
  559.         parent_Validate(somSelf, ev, shape);
  560.     else if ( _fQDCanvas != kODNULL
  561.             && !somSelf->HasPlatformPrintJob(ev, kODQuickDraw) )
  562.     {
  563.         GrafPtr savedPort;
  564.         GrafPtr windowPort = (GrafPtr)_fQDCanvas;
  565.         GetPort(&savedPort);
  566.         SetPort(windowPort);
  567.         short oldLeft = windowPort->portRect.left;
  568.         short oldTop = windowPort->portRect.top;
  569.         SetOrigin(0, 0);
  570.         ValidRgn(shape->GetQDRegion(ev));
  571.         SetOrigin(oldLeft, oldTop);
  572.         SetPort(savedPort);
  573.     }
  574.         
  575.     SOM_CATCH_ALL
  576.     SOM_ENDTRY
  577. }
  578.  
  579. #endif  // _PLATFORM_MACINTOSH
  580.  
  581.