home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / dynamicp / bdraw / draw.c < prev    next >
Text File  |  1997-04-02  |  11KB  |  300 lines

  1. /*====START_GENERATED_PROLOG======================================
  2.  */
  3. /*
  4.  *   COMPONENT_NAME: oddynamicpart
  5.  *
  6.  *   CLASSES: none
  7.  *
  8.  *   ORIGINS: 82,27
  9.  *
  10.  *
  11.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12.  *   All Rights Reserved
  13.  *   Licensed Materials - Property of IBM
  14.  *   US Government Users Restricted Rights - Use, duplication or
  15.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16.  *
  17.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23.  *   OR PERFORMANCE OF THIS SOFTWARE.
  24.  */
  25. /*====END_GENERATED_PROLOG========================================
  26.  */
  27. /* @(#) 1.10 com/src/samples/dynamicp/bdraw/draw.c, oddynamicpart, od96os2, odos29712d 2/18/97 13:53:57 [3/21/97 17:44:35]
  28. *******************************************************************
  29. ** Name: void Draw
  30. **
  31. ** Description:  Render the part's contents on the screen.
  32. **               This method currently draws entire picture.  It
  33. **               should be modified to only draw invalid pieces.
  34. **
  35. *******************************************************************
  36. */
  37.  
  38. try {
  39.   int contentExtent;   // use this to hide differences between OS/2 and Windows origins
  40.   #ifdef _PLATFORM_OS2_
  41.     contentExtent = 0; // OS/2 origin is bottom left
  42.   #elif defined(_PLATFORM_WIN32_)
  43.     contentExtent = drawYdimension; // Windows origin is (strangely) top right
  44.   #endif
  45.   try {
  46.  
  47.     // Disable printing
  48. #ifdef _PLATFORM_OS2_
  49.    if (facet->GetCanvas(ev)->HasPlatformPrintJob(ev,kODPM))
  50. #elif defined(_PLATFORM_WIN32_)
  51.    if (facet->GetCanvas(ev)->HasPlatformPrintJob(ev,kODWin32))
  52. #endif
  53.        printf("Printing\n");//nd
  54. //nd   return;
  55.  
  56.     /////////////////////////////////////////////////////////////
  57.     // If displayed in a root window, blank out old position
  58.     // If the part is a root part, we should blank out the
  59.     // area around the current used area.
  60.     if (facet->GetFrame(ev)->IsRoot(ev)) {
  61.  
  62.       ODShape *shape = facet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL);
  63.  
  64.       ODTransform *contentXform = facet->AcquireWindowContentTransform(ev, facet->GetCanvas(ev));
  65.       ODTransform *frameXform = facet->AcquireWindowFrameTransform(ev, facet->GetCanvas(ev));
  66.  
  67.       ODRect trect     = {0, ODIntToFixed(drawYdimension-contentExtent),
  68.                           ODIntToFixed(drawXdimension), ODIntToFixed(contentExtent)};
  69.  
  70.       ODShape *figFrameShape = shape->Copy(ev);
  71.       figFrameShape->Transform(ev, frameXform);
  72.       ODShape *figFigShape = shape->NewShape(ev);
  73.       figFigShape->SetRectangle(ev, &trect);
  74.       if (contentXform) {
  75.         figFigShape->Transform(ev, contentXform);
  76.         figFrameShape->Subtract(ev, figFigShape);
  77. #ifdef _PLATFORM_WIN32_
  78.         figFrameShape->InverseTransform(ev, contentXform);
  79. #endif
  80.         contentXform->Release(ev);
  81.       } /* endif */
  82.       frameXform->Release(ev);
  83.       try {
  84.         HPS hps;
  85.         CFocus f(facet, invalidShape, &hps);
  86.  
  87.         // overdraw current (old) position
  88.         IPresSpaceHandle DrawHps(hps);
  89.         IGraphicContext DrawConText(DrawHps);
  90.  
  91.         ODHighlight highlight = facet->GetHighlight(ev);
  92.         if (highlight==kODNoHighlight) {
  93.           DrawConText.setBackgroundColor(_BackColor);
  94.         } else {
  95.           if (highlight==kODFullHighlight) {
  96.             DrawConText.setBackgroundColor(_TextColor);
  97.           } else {
  98.             if (highlight==kODDimHighlight) {
  99.               DrawConText.setBackgroundColor(_BackColor);
  100.             } /* endif */
  101.           } /* endif */
  102.         } /* endif */
  103.         DrawConText.setPenColor(DrawConText.backgroundColor());
  104.         DrawConText.setFillColor(DrawConText.backgroundColor());
  105.  
  106.         IRegionHandle drawHandle = figFrameShape->GetRegion(ev);
  107.         IGRegion DrawRegion = drawHandle;
  108.         DrawRegion.drawOn(DrawConText);
  109.       } catch (IException &exc) {
  110.          reportIException(exc);
  111.       } catch (...) {
  112.          reportAnyException(ev);
  113.       } /* end try */
  114.  
  115.       shape->Release(ev);
  116.       figFrameShape->Release(ev);
  117.       figFigShape->Release(ev);
  118.     } /* endif isRoot */
  119.   } catch (IException &exc) {
  120.      reportIException(exc);
  121.   } catch (...) {
  122.      reportAnyException(ev);
  123.   }/* end try */
  124.  
  125.   // Now draw the figure
  126.   try {
  127.  
  128.     HPS hps;
  129.     CFocus f(facet, invalidShape, &hps);     // Set up drawing environment
  130.  
  131.     // Using the Integer Constuctor with the HPS from CFocus
  132.     IPresSpaceHandle DrawHps(hps);
  133.  
  134.     // Using the IPresSpaceHandle Constructor to create my Graphic Context
  135.     IGraphicContext DrawConText(DrawHps);
  136.  
  137.     long FontSize = drawYdimension / 20;
  138.     _Font->setPointSize(FontSize);
  139.     _Font->useBitmapOnly(false);
  140.     _Font->useNonPropOnly(false);
  141.     _Font->useVectorOnly(true);
  142.     _Message->setFont(*_Font);
  143.  
  144.     // Creation of an IGRectange object representing the text box at the bottom
  145.  
  146.     IRectangle DrawBotRect(0,                        //left
  147.                            contentExtent,            //bottom
  148.                            drawXdimension+1,         //right
  149. #ifdef _PLATFORM_OS2_
  150.                            abs(contentExtent  - (_Font->maxCharHeight()+_Font->maxDescender()))+7
  151. #elif defined(_PLATFORM_WIN32_)
  152.                            abs(contentExtent  -  _Font->maxCharHeight()   )
  153. #endif
  154.                           );
  155.     IGRectangle GDrawBotRect(DrawBotRect);
  156.  
  157.     IRectangle DrawTopRect(DrawBotRect.left(),
  158. #ifdef _PLATFORM_OS2_
  159.                            DrawBotRect.top(),
  160. #else
  161.                            DrawBotRect.bottom()+1,
  162. #endif
  163.                            DrawBotRect.right(),
  164.                            drawYdimension - contentExtent);
  165.  
  166.     // draw the figure
  167.  
  168.     // Draw the bitmap
  169.     DrawConText.setBackgroundMixMode(IGraphicBundle::backLeaveAlone);
  170.     DrawConText.setMixMode(IGraphicBundle::overPaint);
  171.  
  172.  
  173.     // Setting the Background and Fill color for the Graphic Context
  174.  
  175.     ODHighlight highlight = facet->GetHighlight(ev);
  176.     long rasterOperation;
  177.     if (highlight==kODNoHighlight) {
  178.       DrawConText.setBackgroundColor(_BackColor);
  179.       DrawConText.setPenColor(_TextColor);
  180.       rasterOperation = IGBitmap::normal;
  181.     } else {
  182.       if (highlight==kODFullHighlight) {
  183.         DrawConText.setBackgroundColor(_TextColor);
  184.         DrawConText.setPenColor(_BackColor);
  185.         rasterOperation = IGBitmap::invert;
  186.       } else {
  187.         if (highlight==kODDimHighlight) {
  188.           DrawConText.setBackgroundColor(_BackColor);
  189.           DrawConText.setPenColor(_TextColor);
  190.           rasterOperation = IGBitmap::normal;
  191.         } /* endif */
  192.       } /* endif */
  193.     } /* endif */
  194.     DrawConText.setDrawOperation(IGraphicBundle::fill);
  195.  
  196.     try {
  197. #ifdef _PLATFORM_OS2_
  198.       if (facet->GetCanvas(ev)->HasPlatformPrintJob(ev,kODPM))
  199. #elif defined(_PLATFORM_WIN32_)
  200.       if (facet->GetCanvas(ev)->HasPlatformPrintJob(ev,kODWin32))
  201. #endif
  202.       {
  203.         // OpenClass doesn't print bitmaps currently, so we must resort to the native APIs
  204. #ifdef _PLATFORM_OS2_
  205.         HBITMAP hbm = GpiLoadBitmap(hps,(IModuleHandle::Value)_Resources->handle(),
  206.                                     ODBMP,0,0);
  207.         if (hbm) {
  208.           POINTL points[] = { {DrawTopRect.left(),  DrawTopRect.bottom()},
  209.                               {DrawTopRect.right(), DrawTopRect.top()},
  210.                               {0, 0},
  211.                               {_ODBitmap->size().width(), _ODBitmap->size().height()}
  212.                             };
  213.           LONG rc =
  214.           GpiWCBitBlt(hps, hbm,
  215.                       4, points,
  216.                       ROP_SRCCOPY, BBO_IGNORE);
  217.         } /* endif */
  218. #elif defined(_PLATFORM_WIN32_)
  219.         BITMAP bm;
  220.         HPS hMemDC;
  221.         RECT rect;
  222.         HBITMAP hbm = 0;
  223.         string  ModulePathName = kDynamicPartFileName;
  224.         // loading from a resource loses colors, so load from a file
  225.         char bitmapname[256];
  226.         bitmapname[0] = '\0';
  227.         _searchenv("ioddynam.bmp", "PATH", bitmapname);
  228.         if (bitmapname[0] != '\0') {
  229.           hbm = LoadImage(NULL, bitmapname, IMAGE_BITMAP,0,0,
  230.                           LR_LOADFROMFILE | LR_COLOR );
  231.         } /* endif */
  232.         if (hbm == NULL) {
  233.           // didn't load from file
  234.           hbm = LoadBitmap((IModuleHandle::Value)_Resources->handle(),
  235.                            MAKEINTRESOURCE(ODBMP));
  236.         } /* endif */
  237.         GetObject( hbm, sizeof(BITMAP), &bm);
  238.         hMemDC = CreateCompatibleDC( hps);
  239.         SelectObject (hMemDC, hbm);
  240.         SetStretchBltMode(hps, STRETCH_DELETESCANS);
  241.         BOOL rc =
  242.         StretchBlt(hps, 0, 0, DrawTopRect.width(), DrawTopRect.height(),
  243.                    hMemDC, 0, 0, bm.bmWidth, bm.bmHeight,
  244.                    SRCCOPY );
  245.         if (!rc) {
  246.           DWORD lastErr = GetLastError();
  247.           printf("LastError=%x\n",lastErr);
  248.         } else {
  249.           printf("StretchBlt successful\n");
  250.         } /* endif */
  251.         DeleteDC(hMemDC);
  252.         DeleteObject(hbm);
  253. #endif
  254.       } else {
  255.         _ODBitmap->drawOn(DrawConText,
  256.                           DrawTopRect.bottomLeft(),
  257.                           DrawTopRect.topRight(),
  258.                           IPoint(0, 0),
  259.                           _ODBitmap->size(),
  260.                           rasterOperation);
  261.       } /* endif */
  262.     } catch (IException &exc) {
  263.         reportIException(exc);
  264.     } /* end try */
  265.     if (highlight==kODDimHighlight) {
  266.       DrawConText.setFillPattern(IGraphicBundle::halftone);
  267.       DrawConText.setFillColor(_BackColor);
  268.       IGRectangle GDrawTopRect(DrawTopRect);
  269.       GDrawTopRect.drawOn(DrawConText);
  270.       DrawConText.setFillPattern(DrawConText.defaultFillPattern());
  271.     } /* endif */
  272.  
  273.     DrawConText.setFillColor(DrawConText.backgroundColor());
  274.     DrawConText.setBackgroundMixMode(IGraphicBundle::backOverPaint);
  275.     DrawConText.setMixMode(IGraphicBundle::overPaint);
  276.     GDrawBotRect.drawOn(DrawConText);
  277.  
  278.     _Message->setClippingRect(DrawBotRect);
  279.  
  280.     IPoint Msg1Pos(_ScrollPos,
  281. #ifdef _PLATFORM_OS2_
  282.                    DrawBotRect.bottom() + _Font->maxDescender() + _Font->externalLeading() +0
  283. #elif defined(_PLATFORM_WIN32_)
  284.                    DrawBotRect.top() - _Font->maxCharHeight()
  285. #endif
  286.                   );
  287.     _Message->moveTo(Msg1Pos);
  288.     _Message->drawOn(DrawConText);
  289.  
  290.   } catch (IException &exc) {
  291.       reportIException(exc);
  292.   } catch (...) {
  293.       reportAnyException(ev);
  294.   } /* end try */
  295. } catch (IException &exc) {
  296.     reportIException(exc);
  297. } catch (...) {
  298.     reportAnyException(ev);
  299. } /* end try */
  300.