/*-----------------------------------------------------------------------*/
static void  PrintBlockText(POBJECT pObj,WINDOWINFO *pwi)
{
   PBTEXTPRINT p,pTmp;
   POINTL      ptl;

   if (!pObj->pvData)
      return;

   p = (PBTEXTPRINT)pObj->pvData;

   do
   {
      ptl.x = (LONG)(p->ptlf.x * pwi->usFormWidth);
      ptl.y = (LONG)(p->ptlf.y * pwi->usFormHeight);
      GpiSetCurrentPosition(pwi->hps,&ptl);
      if (p->pszString)
         drawCharString(pwi,(LONG)strlen(p->pszString),
                        p->pszString,
                        pObj->lWidth,
                        p->fxBreakExtra,
                        p->iBreakCount);
      pTmp = p;
      p = p->next;
      del_ptextprint(pTmp); /* Kill this printer block */
   } while (p);

   pObj->pvData = NULL;
}
void DrawBox( HWND hwnd )
{
  HPS hps;
  POINTL pointl;

  // Get a cached PS for the window

  hps = WinGetPS( hwnd );

  pointl.x = pointl.y = 0;

  // Set the current position to (0,0)

  GpiSetCurrentPosition( hps, &pointl );

  pointl.x = pointl.y = 10;

  // Draw a 10 by 10 box from the current position in the
  // current color.

  GpiBox( hps, DRO_OUTLINE, &pointl,0,0 );

  // Free the cached PS

  WinReleasePS( hps );

 }
Example #3
0
void PMWindowImp::DeviceRect (
    Coord x0, Coord y0, Coord x1, Coord y1
) {
    Coord left = min(x0, x1);
    Coord right = max(x0, x1);
    Coord bottom = min(y0, y1);
    Coord top = max(y0, y1);
/*
*/
    PPOINTL point[4];
/*
*/
    point[0].x = left;    point[0].y = top;
    point[1].x = right;   point[1].y = top;
    point[2].x = right;   point[2].y = bottom;
    point[3].x = left;    point[3].y = bottom;
/*
*/
    if (
        (GpiBeginPath(_hps, 1L) == false) ||
        (GpiSetCurrentPosition(_hps, &point[3]) == false) ||
        (GpiPolyLine(_hps, 4L, point) == GPI_ERROR)  ||
        (GpiEndPath(_hps) == false)
    ) {
        // report error
/*
*/
    } else {
        GpiStrokePath(_hps, 1L, 0L);
    }
}
//--------------------------------------------------------------------------
//
// DrawShearedBox
//
// --------------------------------------------------------------------------
void DrawShearedBox( HWND hwnd )
{
  HPS hps;
  POINTL pointl;
  MATRIXLF m;

  // Get a cached PS for the window

  hps = WinGetPS( hwnd );

  // Query the current contents of the model transform

  GpiQueryModelTransformMatrix( hps, 9L, &m );

  m.fxM21 = MAKEFIXED(1,0); // tan(45)
 // m.fxM22 = MAKEFIXED(1,0); // identity

  // Replace the model transform with our modified one

  GpiSetModelTransformMatrix( hps, 9L, &m, TRANSFORM_REPLACE );


  // Set the current position to (0,100)

  pointl.x = 400; pointl.y = 200;

  GpiSetCurrentPosition( hps, &pointl );

  // Draw a 100 by 100 box from the current position in the
  // current color.

  pointl.x = pointl.y = 100;

  GpiSetColor( hps, CLR_BLUE );
  GpiSetPattern( hps, PATSYM_HALFTONE );

  GpiBox( hps, DRO_OUTLINEFILL, &pointl,0,0 );

  // Free the cached PS

  WinReleasePS( hps );
}
//--------------------------------------------------------------------------
//
// DrawTransformedBox
//
// --------------------------------------------------------------------------
void DrawTransformedBox( HWND hwnd )
{
  HPS hps;
  POINTL pointl;
  MATRIXLF m;

  // Get a cached PS for the window

  hps = WinGetPS( hwnd );

  // Query the current contents of the model transform

  GpiQueryModelTransformMatrix( hps, 9L, &m );

  m.lM31  = 100;                 // Translate the x coordinates
  m.lM32  = 100;                 // Translate the y coordinates
  m.fxM11 = MAKEFIXED(10,0);     // Scale up the x coordinates
  m.fxM22 = MAKEFIXED(10,0);     // Scale up the y coordinates

  // Replace the model transform with our modified one

  GpiSetModelTransformMatrix( hps, 9L, &m, TRANSFORM_REPLACE );


  // Set the current position to (0,0)

  pointl.x = pointl.y = 0;

  GpiSetCurrentPosition( hps, &pointl );

  // Draw a 10 by 10 box from the current position in the
  // current color.

  pointl.x = pointl.y = 10;

  GpiBox( hps, DRO_OUTLINE, &pointl,0,0 );

  // Free the cached PS

  WinReleasePS( hps );
}
VOID MainPaint(HWND hwnd)
{
    RECTL  rclUpdate;
    RECTL  rclWnd;
    RECTL  rclDraw;

    HPS hps;
    POINTL pt;
    LONG        LineHeight;
    LONG        Descender;
    PCHAR  pText;
    LONG   ptTextStart;
static
    LONG   Inc[] = { 10, 10, 10,
                     12, 12, 12,
                     14, 14, 14,
                     16, 16, 16,
                     18, 18, 18,
                     20, 20, 20,
                     22, 22, 22,
                     24, 24, 24
                   };

//BIDI
static
    PCHAR   TextLines[] = {
            "~DrawText",             //0
            "CharString",            //1
            "CharStringAt",          //2
            "CharStringPos",         //3
            "CharStringPosAt",       //4
            "DrawText(QueryRect)",   //5
            "QueryCharStringPos",    //6
            "QueryCharStringPosAt",  //7
            "QueryTextBox"           //8
            };

static
    PCHAR   TextLines_API[] = {
            "WinDrawText:",                 //0
            "GpiCharString:",               //1
            "GpiCharStringAt:",             //2
            "GpiCharStringPos:",            //3
            "GpiCharStringPosAt:",          //4
            "WinDrawText(QueryRect):",      //5
            "GpiQueryCharStringPos:",       //6
            "GpiQueryCharStringPosAt:",     //7
            "GpiQueryTextBox:",             //8
            "Current Clipboard TextBuffer:" //9
            };

    ULONG   GpiBidiAttr;
    ULONG   NullBidiAttr = 0L;

    hps = WinBeginPaint(hwnd, NULLHANDLE, (PRECTL)&rclUpdate);

    // Get the bidi attribute of the presentation space, so that
    // we can flip/flip between a NULL bidiattribute and this one
    //
    GpiBidiAttr = GpiQueryBidiAttr(hps);


    /* fill update rectangle with window color */
    WinFillRect(hps, (PRECTL)&rclUpdate, SYSCLR_PAGEBACKGROUND );

    CalcLineHeight(hps, &LineHeight, &Descender);

    GpiSetColor    ( hps, CLR_BLUE ) ;
    GpiSetBackColor( hps, CLR_RED  ) ;

    WinQueryWindowRect(hwnd, (PRECTL)&rclWnd);
    ptTextStart = rclWnd.xRight * 2/5  ;

    // -------------------------------------
    // WinDrawText!
    // -------------------------------------
    pt.x = 0;
    pt.y = rclWnd.yTop - LineHeight + Descender;

    rclDraw.xLeft   = rclWnd.xLeft;
    rclDraw.xRight  = rclWnd.xRight;
    rclDraw.yBottom = pt.y - Descender;
    rclDraw.yTop    = rclDraw.yBottom + LineHeight ;

    GpiSetBidiAttr(hps, NullBidiAttr);

    pText = TextLines_API[0];
    WinDrawText ( hps, strlen(pText), pText, &rclDraw, 0L, 0L,
                  DT_LEFT | DT_ERASERECT | DT_TEXTATTRS | DT_MNEMONIC );

    rclDraw.xLeft = ptTextStart;

    GpiSetBidiAttr(hps, GpiBidiAttr);

    pText = TextLines[0];
    WinDrawText ( hps, strlen(pText), pText, &rclDraw, 0L, 0L,
                  DT_LEFT | DT_ERASERECT | DT_TEXTATTRS | DT_MNEMONIC );

    // -------------------------------------
    // GpiCharString
    // -------------------------------------
    pt.y -=  LineHeight;
    pt.x = 0;
    GpiSetCurrentPosition( hps, &pt ) ;
    pText = TextLines_API[1];
    GpiSetBidiAttr(hps, NullBidiAttr);
    GpiCharString(hps, strlen(pText), pText);

    pt.x = ptTextStart;
    GpiSetCurrentPosition( hps, &pt ) ;
    pText = TextLines[1];
    GpiSetBidiAttr(hps, GpiBidiAttr);
    GpiCharString(hps, strlen(pText), pText);

    // -------------------------------------
    //  GpiCharStringAt
    // -------------------------------------
    pt.y -=  LineHeight ;
    pt.x = 0;
    pText = TextLines_API[2];
    GpiSetBidiAttr(hps, NullBidiAttr);
    GpiCharStringAt(hps, &pt, strlen(pText), pText);

    pt.x = ptTextStart;
    pText = TextLines[2];
    GpiSetBidiAttr(hps, GpiBidiAttr);
    GpiCharStringAt(hps, &pt, strlen(pText), pText);

    // -------------------------------------
    //  GpiCharStringPos
    // -------------------------------------
    pt.y -=  LineHeight ;
    pt.x = 0;
    GpiSetCurrentPosition( hps, &pt ) ;

    rclDraw.xLeft   = rclWnd.xLeft;
    rclDraw.xRight  = ptTextStart - 4;
    rclDraw.yBottom = pt.y - Descender;
    rclDraw.yTop    = rclDraw.yBottom + LineHeight ;

    pText = TextLines_API[3];
    GpiSetBidiAttr(hps, NullBidiAttr);
    GpiCharStringPos(hps, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
                     strlen(pText), pText, &Inc[0] );

    rclDraw.xLeft   = ptTextStart;
    rclDraw.xRight  = rclWnd.xRight;
    rclDraw.yBottom = pt.y - Descender  ;
    rclDraw.yTop    = rclDraw.yBottom + LineHeight ;

    pt.x            = ptTextStart;
    GpiSetCurrentPosition( hps, &pt ) ;

    pText = TextLines[3];
    GpiSetBidiAttr(hps, GpiBidiAttr);
    GpiCharStringPos(hps, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
                     strlen(pText), pText, &Inc[0]);


    // -------------------------------------
    //  GpiCharStringPosAt
    // -------------------------------------
    pt.y -=  LineHeight ;
    pt.x = 0;

    rclDraw.xLeft   = rclWnd.xLeft;
    rclDraw.xRight  = ptTextStart - 4;
    rclDraw.yBottom = pt.y - Descender  ;
    rclDraw.yTop    = rclDraw.yBottom + LineHeight ;

    pText = TextLines_API[4];
    GpiSetBidiAttr(hps, NullBidiAttr);
    GpiCharStringPosAt(hps, &pt, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
                       strlen(pText), pText, &Inc[0] );

    rclDraw.xLeft   = ptTextStart;
    rclDraw.xRight  = rclWnd.xRight;
    rclDraw.yBottom = pt.y - Descender  ;
    rclDraw.yTop    = rclDraw.yBottom + LineHeight ;
    pt.x            = ptTextStart;

    pText = TextLines[4];
    GpiSetBidiAttr(hps, GpiBidiAttr);
    GpiCharStringPosAt(hps, &pt, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
                       strlen(pText), pText, &Inc[0]);

    // -------------------------------------
    //  Current Clipboard TextBuffer
    //
    //  This is used as a means of "looking inside" the
    //  clipbaord. (This is a clipboard viewer for the poor...)
    //  This part shows the text in szPasteText.
    //  To operate:
    //  - Copy/Cut text from anywhere to the clipbaord.
    //  - select:    Edit --> Paste --> No Conversion
    //  - The clipboard text will be shown (UNMODIFIED BUFFER)
    //    in our window.
    // -------------------------------------
    pt.y -=  LineHeight ;
    pt.x = 0;

    pText = TextLines_API[9];
    GpiSetBidiAttr(hps, NullBidiAttr);
    GpiCharStringAt(hps, &pt, strlen(pText), pText);

    pt.x            = ptTextStart;
    pText           = szPasteText;
    GpiCharStringAt(hps, &pt, strlen(pText), pText);

//BIDI- end

    /*
     * Add painting routines here.  Hps is now the HPS for
     * the window and rclUpdate contains the update rectangle.
     */

    WinEndPaint(hps);

}   /* MainPaint() */
SOM_Scope void  SOMLINK ShapePartAdjustViewTypeShapes(ShapePart *somSelf,
                                                       Environment *ev,
                                                       ODFrame* frame)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartAdjustViewTypeShapes");

    try
    {
      // Call parent
      ShapePart_parent_SimplePart_AdjustViewTypeShapes(somSelf, ev, frame);

      ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev); // Get facets for frame
      ODFacet*    facet            = facets->First(ev);              // Assume 1 facet
      delete facets;

      ODRect rect;
      ODTypeToken viewType = frame->GetViewType(ev);

      // Override SimplePart's behavior only if this is an embedded part displaying as frame.
      if((viewType == somThis->fSession->Tokenize(ev,kODViewAsFrame)) &&
         (!frame->IsRoot(ev)))
      {

         // Set the used and active shape to a circle.
         int         width, height;
         ODRgnHandle hrgnUsedAndActive;
         ODRect      box;

         ODCanvas *canvas = facet->GetCanvas(ev);

#ifdef _PLATFORM_OS2_
         HPS       hps;
         hps = ((ODOS2WindowCanvas*) canvas->GetPlatformCanvas(ev, kODPM))->GetPS(ev); // Obtain a PS
#endif //_PLATFORM_OS2_

         TempODShape frameShape = frame->AcquireFrameShape(ev, canvas); // Get bounding box
         frameShape->GetBoundingBox(ev, &box);                          //  of frame
         width  = FixedToInt(box.right)-FixedToInt(box.left);           // circle to be
         height = abs(FixedToInt(box.top)-FixedToInt(box.bottom));      // constructed

#ifdef _PLATFORM_OS2_
         Point center;
         center.x = width/2;
         center.y = height/2;
         int rad  = (width < height) ? center.x : center.y;             // get radius
         GpiBeginPath(hps,1L);                                          // Define GPI path
         GpiSetCurrentPosition(hps , &center);                          // for circle
         GpiFullArc(hps,DRO_OUTLINE,MAKEFIXED(rad,0));
         GpiEndPath(hps);
         hrgnUsedAndActive = GpiPathToRegion(hps, 1, FPATH_ALTERNATE);  // Convert path to GPI region
         ((ODOS2WindowCanvas *)canvas->GetPlatformCanvas(ev, kODPM))->ReleasePS(ev); // Release the canvas
#elif defined(_PLATFORM_WIN32_)

         hrgnUsedAndActive = CreateEllipticRgn(0,0,width,height);       // region from Ellipse box
#endif //_PLATFORM_WIN32_

         if(hrgnUsedAndActive)
         {
            // Use TempODShape so this object won't have to be released.
            TempODShape usedAndActiveShape = frame->CreateShape(ev);       // create a shape
            usedAndActiveShape->SetRegion(ev, hrgnUsedAndActive);          // assign the region to the shape

            // Set used and active shapes to the newly defined shape
            frame->ChangeUsedShape(ev, usedAndActiveShape, kODNULL);
            if(facet)
            {
              facet->ChangeActiveShape(ev, usedAndActiveShape, kODNULL);
            }
         } // hrgnUsedAndActive
      } // viewtype is frame and frame isn't root
      else
      {
         // Reset used and active shapes to frame shape
         frame->ChangeUsedShape(ev, kODNULL, kODNULL);
         if(facet)
         {
           facet->ChangeActiveShape(ev, kODNULL, kODNULL);
         }

      }
    }
    catch(...)
    {
    }
}
//--------------------------------------------------------------------------
//
// RotateBox
//
// --------------------------------------------------------------------------
void RotateBox( HWND hwnd )
{
  HPS hps;
  POINTL pointlBox, pointlStart;
  MATRIXLF m;
  LONG i;

  // Get a cached PS for the window

  hps = WinGetPS( hwnd );

  // This time let's draw the boxes in blue

  GpiSetColor( hps, CLR_BLUE );

  // For this simple example, we will choose an arbitary position
  // as the anchor point for each box of (400,400). This will be
  // the point about which each box is rotated. A nice
  // alternative, as a small enhancement, would be to make the
  // start position be wherever the mouse is clicked in the
  // window.

  pointlStart.x = 400;
  pointlStart.y = 400;

  // Query the current contents of the model transform

  GpiQueryModelTransformMatrix( hps, 9L, &m );

  // Setup our box coordinates to be 100 by 100 from wherever
  // the start position is.

  pointlBox.y = pointlStart.y + 100;
  pointlBox.x = pointlStart.x + 100;

  // Draw a series of boxes, each time around the loop we'll
  // rotate through an extra 10 degrees, replacing the transform
  // with our newly calculated one.

  for ( i=0; i<360; i+=10 )
  {
    GpiRotate( hps
             , &m
             , TRANSFORM_REPLACE
             , MAKEFIXED(i,0)
             , &pointlStart );

    GpiSetModelTransformMatrix( hps, 9L, &m, TRANSFORM_REPLACE );

    GpiSetCurrentPosition( hps, &pointlStart );

    // Draw a 100 by 100 box. Note that we issue a normal box
    // drawing request. Blissfully unaware that the transform
    // we setup will cause our box to be rotated.

    GpiBox( hps, DRO_OUTLINE, &pointlBox,0,0 );
  }

  // Free the cached PS

  WinReleasePS( hps );

}