home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / TOOLKIT / BIDI / HEBREW / STYLE / STY_PNT.C < prev    next >
C/C++ Source or Header  |  1994-11-17  |  10KB  |  307 lines

  1. /*************************************************************************
  2. *
  3. *  File Name   : STY_PNT.C
  4. *
  5. *  Description :This module contains the code for the
  6. *               main client window painting
  7. *
  8. *  Concepts    : Painting of main client window.
  9. *                BIDI - Added: Bidirectional Language processing sample code.
  10. *
  11. *  API's       : WinBeginPaint
  12. *                WinFillRect
  13. *                WinEndPaint
  14. *
  15. *  Copyright (C) 1992 IBM Corporation
  16. *
  17. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  18. *      sample code created by IBM Corporation. This sample code is not
  19. *      part of any standard or IBM product and is provided to you solely
  20. *      for  the purpose of assisting you in the development of your
  21. *      applications.  The code is provided "AS IS", without
  22. *      warranty of any kind.  IBM shall not be liable for any damages
  23. *      arising out of your use of the sample code, even if they have been
  24. *      advised of the possibility of such damages.                                                    *
  25. *
  26. ************************************************************************/
  27.  
  28. /*  Include files, macros, defined constants, and externs               */
  29.  
  30. #define  INCL_WINSYS
  31. #define  INCL_GPI
  32.  
  33. #include <os2.h>
  34. #include <pmbidi.h>
  35.  
  36. #include <string.h>
  37. #include "sty_main.h"
  38. #include "sty_xtrn.h"
  39.  
  40. /*  Global variables                                                    */
  41.  
  42. /*  Entry point declarations                                            */
  43. static VOID CalcLineHeight(HPS hps, PLONG LineHeight, PLONG Decender );
  44.  
  45. extern CHAR szPasteText[];
  46.  
  47. /****************************************************************
  48.  *  Name:   MainPaint
  49.  *
  50.  *  Description : Main client painting routine
  51.  *
  52.  *  Concepts :  Routine is called whenver the client window
  53.  *              procedure receives a WM_PAINT message begins
  54.  *              painting by calling WinBeginPaint and
  55.  *              retriving the HPS for the window performs any
  56.  *              painting desired ends painting by calling
  57.  *              WinEndPaint
  58.  *
  59.  *  API's :  WinBeginPaint
  60.  *           WinFillRect
  61.  *           WinEndPaint
  62.  *
  63.  *  Parameters : hwnd - handle of window to paint
  64.  *
  65.  *  Returns :  VOID
  66.  *
  67.  ****************************************************************/
  68.  
  69. VOID MainPaint(HWND hwnd)
  70. {
  71.     RECTL  rclUpdate;
  72.     RECTL  rclWnd;
  73.     RECTL  rclDraw;
  74.  
  75.     HPS hps;
  76.     POINTL pt;
  77.     LONG        LineHeight;
  78.     LONG        Descender;
  79.     PCHAR  pText;
  80.     LONG   ptTextStart;
  81. static
  82.     LONG   Inc[] = { 10, 10, 10,
  83.                      12, 12, 12,
  84.                      14, 14, 14,
  85.                      16, 16, 16,
  86.                      18, 18, 18,
  87.                      20, 20, 20,
  88.                      22, 22, 22,
  89.                      24, 24, 24
  90.                    };
  91.  
  92. //BIDI
  93. static
  94.     PCHAR   TextLines[] = {
  95.             "~DrawText",             //0
  96.             "CharString",            //1
  97.             "CharStringAt",          //2
  98.             "CharStringPos",         //3
  99.             "CharStringPosAt",       //4
  100.             "DrawText(QueryRect)",   //5
  101.             "QueryCharStringPos",    //6
  102.             "QueryCharStringPosAt",  //7
  103.             "QueryTextBox"           //8
  104.             };
  105.  
  106. static
  107.     PCHAR   TextLines_API[] = {
  108.             "WinDrawText:",                 //0
  109.             "GpiCharString:",               //1
  110.             "GpiCharStringAt:",             //2
  111.             "GpiCharStringPos:",            //3
  112.             "GpiCharStringPosAt:",          //4
  113.             "WinDrawText(QueryRect):",      //5
  114.             "GpiQueryCharStringPos:",       //6
  115.             "GpiQueryCharStringPosAt:",     //7
  116.             "GpiQueryTextBox:",             //8
  117.             "Current Clipboard TextBuffer:" //9
  118.             };
  119.  
  120.     ULONG   GpiBidiAttr;
  121.     ULONG   NullBidiAttr = 0L;
  122.  
  123.     hps = WinBeginPaint(hwnd, NULLHANDLE, (PRECTL)&rclUpdate);
  124.  
  125.     // Get the bidi attribute of the presentation space, so that
  126.     // we can flip/flip between a NULL bidiattribute and this one
  127.     //
  128.     GpiBidiAttr = GpiQueryBidiAttr(hps);
  129.  
  130.  
  131.     /* fill update rectangle with window color */
  132.     WinFillRect(hps, (PRECTL)&rclUpdate, SYSCLR_PAGEBACKGROUND );
  133.  
  134.     CalcLineHeight(hps, &LineHeight, &Descender);
  135.  
  136.     GpiSetColor    ( hps, CLR_BLUE ) ;
  137.     GpiSetBackColor( hps, CLR_RED  ) ;
  138.  
  139.     WinQueryWindowRect(hwnd, (PRECTL)&rclWnd);
  140.     ptTextStart = rclWnd.xRight * 2/5  ;
  141.  
  142.     // -------------------------------------
  143.     // WinDrawText!
  144.     // -------------------------------------
  145.     pt.x = 0;
  146.     pt.y = rclWnd.yTop - LineHeight + Descender;
  147.  
  148.     rclDraw.xLeft   = rclWnd.xLeft;
  149.     rclDraw.xRight  = rclWnd.xRight;
  150.     rclDraw.yBottom = pt.y - Descender;
  151.     rclDraw.yTop    = rclDraw.yBottom + LineHeight ;
  152.  
  153.     GpiSetBidiAttr(hps, NullBidiAttr);
  154.  
  155.     pText = TextLines_API[0];
  156.     WinDrawText ( hps, strlen(pText), pText, &rclDraw, 0L, 0L,
  157.                   DT_LEFT | DT_ERASERECT | DT_TEXTATTRS | DT_MNEMONIC );
  158.  
  159.     rclDraw.xLeft = ptTextStart;
  160.  
  161.     GpiSetBidiAttr(hps, GpiBidiAttr);
  162.  
  163.     pText = TextLines[0];
  164.     WinDrawText ( hps, strlen(pText), pText, &rclDraw, 0L, 0L,
  165.                   DT_LEFT | DT_ERASERECT | DT_TEXTATTRS | DT_MNEMONIC );
  166.  
  167.     // -------------------------------------
  168.     // GpiCharString
  169.     // -------------------------------------
  170.     pt.y -=  LineHeight;
  171.     pt.x = 0;
  172.     GpiSetCurrentPosition( hps, &pt ) ;
  173.     pText = TextLines_API[1];
  174.     GpiSetBidiAttr(hps, NullBidiAttr);
  175.     GpiCharString(hps, strlen(pText), pText);
  176.  
  177.     pt.x = ptTextStart;
  178.     GpiSetCurrentPosition( hps, &pt ) ;
  179.     pText = TextLines[1];
  180.     GpiSetBidiAttr(hps, GpiBidiAttr);
  181.     GpiCharString(hps, strlen(pText), pText);
  182.  
  183.     // -------------------------------------
  184.     //  GpiCharStringAt
  185.     // -------------------------------------
  186.     pt.y -=  LineHeight ;
  187.     pt.x = 0;
  188.     pText = TextLines_API[2];
  189.     GpiSetBidiAttr(hps, NullBidiAttr);
  190.     GpiCharStringAt(hps, &pt, strlen(pText), pText);
  191.  
  192.     pt.x = ptTextStart;
  193.     pText = TextLines[2];
  194.     GpiSetBidiAttr(hps, GpiBidiAttr);
  195.     GpiCharStringAt(hps, &pt, strlen(pText), pText);
  196.  
  197.     // -------------------------------------
  198.     //  GpiCharStringPos
  199.     // -------------------------------------
  200.     pt.y -=  LineHeight ;
  201.     pt.x = 0;
  202.     GpiSetCurrentPosition( hps, &pt ) ;
  203.  
  204.     rclDraw.xLeft   = rclWnd.xLeft;
  205.     rclDraw.xRight  = ptTextStart - 4;
  206.     rclDraw.yBottom = pt.y - Descender;
  207.     rclDraw.yTop    = rclDraw.yBottom + LineHeight ;
  208.  
  209.     pText = TextLines_API[3];
  210.     GpiSetBidiAttr(hps, NullBidiAttr);
  211.     GpiCharStringPos(hps, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
  212.                      strlen(pText), pText, &Inc[0] );
  213.  
  214.     rclDraw.xLeft   = ptTextStart;
  215.     rclDraw.xRight  = rclWnd.xRight;
  216.     rclDraw.yBottom = pt.y - Descender  ;
  217.     rclDraw.yTop    = rclDraw.yBottom + LineHeight ;
  218.  
  219.     pt.x            = ptTextStart;
  220.     GpiSetCurrentPosition( hps, &pt ) ;
  221.  
  222.     pText = TextLines[3];
  223.     GpiSetBidiAttr(hps, GpiBidiAttr);
  224.     GpiCharStringPos(hps, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
  225.                      strlen(pText), pText, &Inc[0]);
  226.  
  227.  
  228.     // -------------------------------------
  229.     //  GpiCharStringPosAt
  230.     // -------------------------------------
  231.     pt.y -=  LineHeight ;
  232.     pt.x = 0;
  233.  
  234.     rclDraw.xLeft   = rclWnd.xLeft;
  235.     rclDraw.xRight  = ptTextStart - 4;
  236.     rclDraw.yBottom = pt.y - Descender  ;
  237.     rclDraw.yTop    = rclDraw.yBottom + LineHeight ;
  238.  
  239.     pText = TextLines_API[4];
  240.     GpiSetBidiAttr(hps, NullBidiAttr);
  241.     GpiCharStringPosAt(hps, &pt, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
  242.                        strlen(pText), pText, &Inc[0] );
  243.  
  244.     rclDraw.xLeft   = ptTextStart;
  245.     rclDraw.xRight  = rclWnd.xRight;
  246.     rclDraw.yBottom = pt.y - Descender  ;
  247.     rclDraw.yTop    = rclDraw.yBottom + LineHeight ;
  248.     pt.x            = ptTextStart;
  249.  
  250.     pText = TextLines[4];
  251.     GpiSetBidiAttr(hps, GpiBidiAttr);
  252.     GpiCharStringPosAt(hps, &pt, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
  253.                        strlen(pText), pText, &Inc[0]);
  254.  
  255.     // -------------------------------------
  256.     //  Current Clipboard TextBuffer
  257.     //
  258.     //  This is used as a means of "looking inside" the
  259.     //  clipbaord. (This is a clipboard viewer for the poor...)
  260.     //  This part shows the text in szPasteText.
  261.     //  To operate:
  262.     //  - Copy/Cut text from anywhere to the clipbaord.
  263.     //  - select:    Edit --> Paste --> No Conversion
  264.     //  - The clipboard text will be shown (UNMODIFIED BUFFER)
  265.     //    in our window.
  266.     // -------------------------------------
  267.     pt.y -=  LineHeight ;
  268.     pt.x = 0;
  269.  
  270.     pText = TextLines_API[9];
  271.     GpiSetBidiAttr(hps, NullBidiAttr);
  272.     GpiCharStringAt(hps, &pt, strlen(pText), pText);
  273.  
  274.     pt.x            = ptTextStart;
  275.     pText           = szPasteText;
  276.     GpiCharStringAt(hps, &pt, strlen(pText), pText);
  277.  
  278. //BIDI- end
  279.  
  280.     /*
  281.      * Add painting routines here.  Hps is now the HPS for
  282.      * the window and rclUpdate contains the update rectangle.
  283.      */
  284.  
  285.     WinEndPaint(hps);
  286.  
  287. }   /* MainPaint() */
  288.  
  289.  
  290.  
  291.  
  292. static VOID CalcLineHeight(HPS hps, PLONG plLineHeight, PLONG plDescender )
  293. {
  294.     FONTMETRICS FontMetrics;
  295.     GpiQueryFontMetrics(hps, sizeof(FontMetrics), &FontMetrics );
  296.  
  297.     *plLineHeight =  FontMetrics.lMaxBaselineExt  +
  298.                      FontMetrics.lExternalLeading +
  299.                      FontMetrics.lInternalLeading ;
  300.     *plDescender  =  FontMetrics.lMaxDescender    +
  301.                      FontMetrics.lExternalLeading +
  302.                      FontMetrics.lInternalLeading ;
  303.     return;
  304.  
  305. }   /*CalcLineHeight() */
  306.  
  307.