home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / drgfil.zip / trgwin.c < prev    next >
C/C++ Source or Header  |  1993-07-31  |  30KB  |  732 lines

  1. /*********************************************************************
  2.  *                                                                   *
  3.  * MODULE NAME :  trgwin.c               AUTHOR:  Rick Fishman       *
  4.  * DATE WRITTEN:  07-28-93                                           *
  5.  *                                                                   *
  6.  * MODULE DESCRIPTION:                                               *
  7.  *                                                                   *
  8.  *  Part of the 'DRGFILES' drag/drop sample program.                 *
  9.  *                                                                   *
  10.  *  This module takes care of all the code relating to the target    *
  11.  *  window (the window that will be dropped on)                      *
  12.  *                                                                   *
  13.  * NOTES:                                                            *
  14.  *                                                                   *
  15.  *  Some GPI is done to create a 'bullseye' and to display text that *
  16.  *  shows where to drop the icons. This code is not commented very   *
  17.  *  well because it doesn't apply to the problem at hand - Drag/Drop.*
  18.  *  (Plus I'm running out of time to do these samples <g>).          *
  19.  *                                                                   *
  20.  * FUNCTIONS AVALABLE TO OTHER MODULES:                              *
  21.  *                                                                   *
  22.  *   targCreateWindow                                                *
  23.  *                                                                   *
  24.  *                                                                   *
  25.  * HISTORY:                                                          *
  26.  *                                                                   *
  27.  *  07-28-93 - Program coded.                                        *
  28.  *                                                                   *
  29.  *  Rick Fishman                                                     *
  30.  *  Code Blazers, Inc.                                               *
  31.  *  4113 Apricot                                                     *
  32.  *  Irvine, CA. 92720                                                *
  33.  *  CIS ID: 72251,750                                                *
  34.  *                                                                   *
  35.  *********************************************************************/
  36.  
  37. #pragma strings(readonly)   // used for debug version of memory mgmt routines
  38.  
  39. /*********************************************************************/
  40. /*------- Include relevant sections of the OS/2 header files --------*/
  41. /*********************************************************************/
  42.  
  43. #define  INCL_GPICONTROL
  44. #define  INCL_GPILCIDS
  45. #define  INCL_GPIPRIMITIVES
  46. #define  INCL_GPIREGIONS
  47. #define  INCL_WINERRORS
  48. #define  INCL_WINDIALOGS
  49. #define  INCL_WINFRAMEMGR
  50. #define  INCL_WINPOINTERS
  51. #define  INCL_WINRECTANGLES
  52. #define  INCL_WINSHELLDATA
  53. #define  INCL_WINSTDCNR
  54. #define  INCL_WINSTDDRAG
  55. #define  INCL_WINSYS
  56. #define  INCL_WINWINDOWMGR
  57.  
  58. /**********************************************************************/
  59. /*----------------------------- INCLUDES -----------------------------*/
  60. /**********************************************************************/
  61.  
  62. #include <os2.h>
  63. #include <stdarg.h>
  64. #include <stdio.h>
  65. #include <stdlib.h>
  66. #include <string.h>
  67. #include "drgfiles.h"
  68.  
  69. /*********************************************************************/
  70. /*------------------- APPLICATION DEFINITIONS -----------------------*/
  71. /*********************************************************************/
  72.  
  73. #define ID_FRAME           1
  74. #define CNR_DROP           10
  75.  
  76. #define WINDOW_TITLE       "'Drop' Window"
  77.  
  78. #define CLIENT_CLASS       "DragDropTargetWindow"
  79.  
  80. #define FRAME_FLAGS        (FCF_TASKLIST   | FCF_TITLEBAR   | FCF_SYSMENU | \
  81.                             FCF_MINMAX     | FCF_SIZEBORDER | FCF_ICON    | \
  82.                             FCF_ACCELTABLE)
  83.  
  84. #define CONTAINER_STYLES   (CCS_EXTENDSEL | CCS_MINIRECORDCORE | \
  85.                             CCS_AUTOPOSITION)
  86.  
  87. #define FONTFACE_NAME      "Helv"
  88.  
  89. /**********************************************************************/
  90. /*---------------------------- STRUCTURES ----------------------------*/
  91. /**********************************************************************/
  92.  
  93.  
  94. /**********************************************************************/
  95. /*----------------------- FUNCTION PROTOTYPES ------------------------*/
  96. /**********************************************************************/
  97.  
  98. void FileDropped     ( HWND hwndClient, HSTR hstrFileName, USHORT fsDrop );
  99. BOOL FillFattrs      ( HWND hwndClient );
  100. BOOL FillFattrsStruct( HPS hps, HWND hwndClient, PFONTMETRICS pfm );
  101. INT  GetFontCount    ( HPS hps, HWND hwndClient, PBOOL pfUseOurFont );
  102. void PaintClient     ( HWND hwndClient );
  103. void PaintText       ( HPS hps, HWND hwndClient, PRECTL prcl );
  104. void DrawBullsEye    ( HPS hps, HWND hwndClient, PRECTL prcl );
  105.  
  106. FNWP wpClient;
  107.  
  108. /**********************************************************************/
  109. /*------------------------ GLOBAL VARIABLES --------------------------*/
  110. /**********************************************************************/
  111.  
  112. char szDropCnrTitle[] = "Dropped Icons";
  113.  
  114. PSZ szTextLine[] = { "DROP", "IT", "HERE!" };
  115. #define TEXT_LINES (sizeof( szTextLine ) / sizeof( PSZ ))
  116.  
  117. FATTRS fattrs;
  118. LONG   lcid = 1;
  119.  
  120. /**********************************************************************/
  121. /*------------------------- targCreateWindow -------------------------*/
  122. /*                                                                    */
  123. /*  CREATE THE TARGET WINDOW                                          */
  124. /*                                                                    */
  125. /*  PARMS: anchor block handle                                        */
  126. /*                                                                    */
  127. /*  NOTES:                                                            */
  128. /*                                                                    */
  129. /*  RETURNS: frame window handle                                      */
  130. /*                                                                    */
  131. /*--------------------------------------------------------------------*/
  132. /**********************************************************************/
  133. HWND targCreateWindow( HAB hab )
  134. {
  135.     HWND       hwndFrame = NULLHANDLE, hwndClient, hwndCnr;
  136.     FRAMECDATA fcdata;
  137.  
  138.     memset( &fcdata, 0, sizeof fcdata );
  139.     fcdata.cb            = sizeof( FRAMECDATA );
  140.     fcdata.idResources   = ID_RESOURCES;
  141.     fcdata.flCreateFlags = FRAME_FLAGS;
  142.  
  143.     // Create a frame/client window and create a container which will be
  144.     // placed on the right half of the client window.
  145.  
  146.     hwndFrame = WinCreateWindow( HWND_DESKTOP, WC_FRAME, NULL,
  147.                                  FS_NOBYTEALIGN | WS_CLIPCHILDREN,
  148.                                  0, 0, 0, 0, NULLHANDLE, HWND_TOP,
  149.                                  ID_FRAME, &fcdata, NULL );
  150.     if( hwndFrame )
  151.     {
  152.         WinRegisterClass( hab, CLIENT_CLASS, wpClient, CS_SIZEREDRAW, 0 );
  153.  
  154.         hwndClient = WinCreateWindow( hwndFrame, CLIENT_CLASS, NULL, 0, 0, 0, 0,
  155.                                       0, NULLHANDLE, HWND_TOP, FID_CLIENT, NULL,
  156.                                       NULL );
  157.         if( hwndClient )
  158.         {
  159.             hwndCnr = WinCreateWindow( hwndClient, WC_CONTAINER, NULL,
  160.                                        WS_VISIBLE | CONTAINER_STYLES,
  161.                                        0, 0, 0, 0, hwndClient, HWND_TOP,
  162.                                        CNR_DROP, NULL, NULL );
  163.             if( hwndCnr )
  164.                 WinSetWindowText( hwndFrame, WINDOW_TITLE );
  165.             else
  166.             {
  167.                 WinDestroyWindow( hwndFrame );
  168.                 hwndFrame = NULLHANDLE;
  169.                 Msg( "WinCreateWindow(hwndCnr,%s) RC(%X)", WINDOW_TITLE,
  170.                      HABERR( hab ) );
  171.             }
  172.         }
  173.         else
  174.         {
  175.             WinDestroyWindow( hwndFrame );
  176.             hwndFrame = NULLHANDLE;
  177.             Msg( "WinCreateWindow(hwndClient,%s) RC(%X)", WINDOW_TITLE,
  178.                  HABERR( hab ) );
  179.         }
  180.     }
  181.     else
  182.         Msg( "WinCreateWindow(%s) RC(%X)", WINDOW_TITLE, HABERR( hab ) );
  183.  
  184.     if( hwndFrame )
  185.     {
  186.         CNRINFO cnri;
  187.  
  188.         // Set container into Icon view and give it a read-only title
  189.  
  190.         cnri.cb           = sizeof( CNRINFO );
  191.         cnri.pszCnrTitle  = szDropCnrTitle;
  192.         cnri.flWindowAttr = CV_ICON | CA_CONTAINERTITLE | CA_TITLESEPARATOR |
  193.                             CA_TITLEREADONLY;
  194.  
  195.         if( !WinSendMsg( hwndCnr, CM_SETCNRINFO, MPFROMP( &cnri ),
  196.                          MPFROMLONG( CMA_FLWINDOWATTR | CMA_CNRTITLE ) ) )
  197.         {
  198.             WinDestroyWindow( hwndFrame );
  199.             hwndFrame = NULLHANDLE;
  200.             Msg( "CM_SETCNRINFO(%S) RC(%X)", WINDOW_TITLE, HABERR( hab ) );
  201.         }
  202.     }
  203.  
  204.     // Fill the FATTRS structure that will be used for text drawing
  205.     if( hwndFrame )
  206.         if( !FillFattrs( hwndClient ) )
  207.             lcid = 0;
  208.  
  209.     // This allows PM to do all the dirty work involved in being the target of
  210.     // a drop.
  211.  
  212.     if( hwndFrame )
  213.         if( !DrgAcceptDroppedFiles( hwndClient, szTempDir, NULL, DO_COPY,0))
  214.         {
  215.             WinDestroyWindow( hwndFrame );
  216.             hwndFrame = NULLHANDLE;
  217.             Msg( "DrgAcceptDroppedFiles RC(%X)", HABERR( hab ) );
  218.         }
  219.  
  220.     return hwndFrame;
  221. }
  222.  
  223. /**********************************************************************/
  224. /*---------------------------- wpClient ------------------------------*/
  225. /*                                                                    */
  226. /*  CLIENT WINDOW PROCEDURE.                                          */
  227. /*                                                                    */
  228. /*  PARMS: normal winproc parms                                       */
  229. /*                                                                    */
  230. /*  NOTES:                                                            */
  231. /*                                                                    */
  232. /*  RETURNS: MRESULT value                                            */
  233. /*                                                                    */
  234. /*--------------------------------------------------------------------*/
  235. /**********************************************************************/
  236. MRESULT EXPENTRY wpClient( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  237. {
  238.     switch( msg )
  239.     {
  240.         case WM_SIZE:
  241.  
  242.             // Place the container in the right half of the client window.
  243.  
  244.             if( !WinSetWindowPos( WinWindowFromID( hwnd, CNR_DROP ), HWND_TOP,
  245.                                   SHORT1FROMMP( mp2 ) / 2, 0,
  246.                                   SHORT1FROMMP( mp2 ) / 2, SHORT2FROMMP( mp2 ),
  247.                                   SWP_MOVE | SWP_SIZE ) )
  248.                 Msg( "wpClient WM_SIZE of Container RC(%X)", HWNDERR( hwnd ) );
  249.  
  250.             break;
  251.  
  252.         case WM_PAINT:
  253.             PaintClient( hwnd );
  254.             break;
  255.  
  256.         case WM_CLOSE:
  257.  
  258.             // Don't let the message queue be destroyed until the user has
  259.             // closed *both* windows. If WM_CLOSE gets processed by the
  260.             // default window proc, a WM_QUIT message will get posted to the
  261.             // queue which will in effect end this program.
  262.  
  263.             if( hwndDrag )
  264.             {
  265.                 WinDestroyWindow( PARENT( hwnd ) );
  266.                 hwndDrop = NULLHANDLE;
  267.                 WinSetActiveWindow( HWND_DESKTOP, hwndDrag );
  268.                 return 0;
  269.             }
  270.  
  271.             break;
  272.  
  273.         case WM_COMMAND:
  274.  
  275.             // From the F3 accelerator key
  276.  
  277.             if( SHORT1FROMMP( mp1 ) == IDM_EXIT )
  278.             {
  279.                 WinPostMsg( hwnd, WM_CLOSE, NULL, NULL );
  280.                 return 0;
  281.             }
  282.  
  283.             break;
  284.  
  285.         case WM_DESTROY:
  286.  
  287.             // Free all container resources associated with any records that
  288.             // were dropped on our window.
  289.  
  290.             WinSendDlgItemMsg( hwnd, CNR_DROP, CM_REMOVERECORD, NULL,
  291.                                MPFROM2SHORT( 0, CMA_FREE ) );
  292.             break;
  293.  
  294.  
  295.         // These are the only messages that we need to process if we use the
  296.         // DrgAcceptDroppedFiles API.
  297.  
  298.         case DM_DRAGERROR:     // In drgfiles.c
  299.             return DragError( SHORT1FROMMP( mp1 ), SHORT2FROMMP( mp1 ),
  300.                               (HSTR) mp2 );
  301.  
  302.         case DM_DRAGFILECOMPLETE:
  303.             FileDropped( hwnd, (HSTR) mp1, SHORT1FROMMP( mp2 ) );
  304.             return 0;
  305.     }
  306.  
  307.     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  308. }
  309.  
  310. /**********************************************************************/
  311. /*--------------------------- FileDropped ----------------------------*/
  312. /*                                                                    */
  313. /*  PROCESS A DM_DRAGFILECOMPLETE MESSAGE.                            */
  314. /*                                                                    */
  315. /*  PARMS: client window handle,                                      */
  316. /*         HSTR that contains the dropped filename,                   */
  317. /*         flags that indicate what happened on the drop              */
  318. /*                                                                    */
  319. /*  NOTES: PM sends this to the target for each file that was dropped.*/
  320. /*                                                                    */
  321. /*  RETURNS: nothing                                                  */
  322. /*                                                                    */
  323. /*--------------------------------------------------------------------*/
  324. /**********************************************************************/
  325. void FileDropped( HWND hwndClient, HSTR hstrFileName, USHORT fsDrop )
  326. {
  327.     PCNRREC      pCnrRec;
  328.     RECORDINSERT ri;
  329.     HWND         hwndCnr = WinWindowFromID( hwndClient, CNR_DROP );
  330.  
  331.     if( !(fsDrop & DF_SUCCESSFUL) )
  332.         return;
  333.  
  334.     // Insert a record into the container that represents the file that was
  335.     // dropped.
  336.  
  337.     memset( &ri, 0, sizeof ri );
  338.     ri.cb                 = sizeof( RECORDINSERT );
  339.     ri.pRecordOrder       = (PRECORDCORE) CMA_END;
  340.     ri.pRecordParent      = (PRECORDCORE) NULL;
  341.     ri.zOrder             = (USHORT) CMA_TOP;
  342.     ri.cRecordsInsert     = 1;
  343.     ri.fInvalidateRecord  = TRUE;
  344.  
  345.     pCnrRec = WinSendMsg( hwndCnr, CM_ALLOCRECORD, MPFROMLONG( EXTRA_BYTES ),
  346.                           MPFROMLONG( 1 ) );
  347.  
  348.     if( pCnrRec )
  349.     {
  350.         DrgQueryStrName( hstrFileName, sizeof pCnrRec->szFileName,
  351.                          pCnrRec->szFileName );
  352.  
  353.         strcpy( pCnrRec->szFullFileName, szTempDir );
  354.         strcat( pCnrRec->szFullFileName, "\\" );
  355.         strcat( pCnrRec->szFullFileName, pCnrRec->szFileName );
  356.  
  357.         pCnrRec->mrc.hptrIcon = WinLoadFileIcon( pCnrRec->szFullFileName,
  358.                                                  FALSE );
  359.         if( !pCnrRec->mrc.hptrIcon )
  360.             pCnrRec->mrc.hptrIcon =
  361.                 WinQuerySysPointer( HWND_DESKTOP, SPTR_QUESICON, FALSE );
  362.  
  363.         pCnrRec->mrc.pszIcon  = (PSZ) &pCnrRec->szFileName;
  364.  
  365.         if( !WinSendMsg( hwndCnr, CM_INSERTRECORD,
  366.                          MPFROMLONG( pCnrRec ), MPFROMP( &ri ) ) )
  367.             Msg( "FileDropped CM_INSERTRECORD RC(%X)", HWNDERR( hwndClient ) );
  368.     }
  369.     else
  370.         Msg( "FileDropped CM_ALLOCRECORD RC(%X)", HWNDERR( hwndClient ) );
  371. }
  372.  
  373. /**********************************************************************/
  374. /*---------------------------- FillFattrs ----------------------------*/
  375. /*                                                                    */
  376. /*  DO EVERYTHING NECESSARY TO FILL IN THE FATTRS STRUCT FOR OUR FONT */
  377. /*                                                                    */
  378. /*  PARMS: client window handle                                       */
  379. /*                                                                    */
  380. /*  NOTES: We fill in a FATTRS structure for an outline font          */
  381. /*                                                                    */
  382. /*  RETURNS: TRUE or FALSE if successful or not                       */
  383. /*                                                                    */
  384. /*--------------------------------------------------------------------*/
  385. /**********************************************************************/
  386. BOOL FillFattrs( HWND hwndClient )
  387. {
  388.     BOOL         fUseOurFont, fSuccess = FALSE;
  389.     PFONTMETRICS afm;
  390.     HDC          hdc;
  391.     LONG         cFonts;
  392.     INT          i;
  393.     HPS          hps = WinGetPS( hwndClient );
  394.  
  395.     if( hps )
  396.         hdc = GpiQueryDevice( hps );
  397.     else
  398.         Msg( "FillFattrs WinGetPS RC(%X)", HWNDERR( hwndClient ) );
  399.  
  400.     if( hdc && hdc != HDC_ERROR )
  401.     {
  402.         cFonts = GetFontCount( hps, hwndClient, &fUseOurFont );
  403.  
  404.         afm = (PFONTMETRICS) malloc( cFonts * sizeof( FONTMETRICS ) );
  405.  
  406.         if( afm )
  407.         {
  408.             if( GPI_ALTERROR != GpiQueryFonts( hps, QF_PUBLIC,
  409.                                         fUseOurFont ? FONTFACE_NAME : NULL,
  410.                                         &cFonts, sizeof( FONTMETRICS ), afm ) )
  411.             {
  412.                 for( i = 0; i < cFonts; i++)
  413.                 {
  414.                     if( afm[ i ].fsDefn & FM_DEFN_OUTLINE )
  415.                     {
  416.                         if( FillFattrsStruct( hps, hwndClient, &afm[ i ] ) )
  417.                             fSuccess = TRUE;
  418.  
  419.                         break;
  420.                     }
  421.                 }
  422.             }
  423.             else
  424.                 Msg( "FillFattrs GpiQueryFonts RC(%X)", HWNDERR( hwndClient ) );
  425.  
  426.             free( afm );
  427.         }
  428.         else
  429.             Msg( "Out of memory in FillFattrs!" );
  430.     }
  431.     else
  432.         Msg( "FillFattrs GpiQueryDevice RC(%X)", HWNDERR( hwndClient ) );
  433.  
  434.     if( hps )
  435.         WinReleasePS( hps );
  436.  
  437.     return fSuccess;
  438. }
  439.  
  440. /**********************************************************************/
  441. /*------------------------- FillFattrsStruct -------------------------*/
  442. /*                                                                    */
  443. /*  FILL THE FATTRS STRUCTURE FOR THE FONT THAT WE WILL USE.          */
  444. /*                                                                    */
  445. /*  PARMS: presentation space handle,                                 */
  446. /*         client window handle,                                      */
  447. /*         pointer to FONTMETRICS struct for our font                 */
  448. /*                                                                    */
  449. /*  NOTES:                                                            */
  450. /*                                                                    */
  451. /*  RETURNS: TRUE or FALSE if successful or not                       */
  452. /*                                                                    */
  453. /*--------------------------------------------------------------------*/
  454. /**********************************************************************/
  455. BOOL FillFattrsStruct( HPS hps, HWND hwndClient, PFONTMETRICS pfm )
  456. {
  457.     BOOL fSuccess = TRUE;
  458.  
  459.     fattrs.usCodePage = GpiQueryCp( hps );
  460.  
  461.     if( fattrs.usCodePage != GPI_ERROR )
  462.     {
  463.         (void) strcpy( fattrs.szFacename, pfm->szFacename );
  464.  
  465.         fattrs.usRecordLength = sizeof( FATTRS );
  466.         fattrs.idRegistry = pfm->idRegistry;
  467.         fattrs.fsFontUse = FATTR_FONTUSE_OUTLINE;
  468.     }
  469.     else
  470.     {
  471.         fSuccess = FALSE;
  472.         Msg( "FillFattrsStruct GpiQueryCp RC(%X)", HWNDERR( hwndClient ) );
  473.     }
  474.  
  475.     return fSuccess;
  476. }
  477.  
  478. /**********************************************************************/
  479. /*--------------------------- GetFontCount ---------------------------*/
  480. /*                                                                    */
  481. /*  GET A COUNT OF THE FONTS AVAILABLE.                               */
  482. /*                                                                    */
  483. /*  PARMS: presentation space handle,                                 */
  484. /*         client window handle,                                      */
  485. /*         pointer to bool that returns if we are using the original  */
  486. /*           font requested                                           */
  487. /*                                                                    */
  488. /*  NOTES:                                                            */
  489. /*                                                                    */
  490. /*  RETURNS: count of fonts                                           */
  491. /*                                                                    */
  492. /*--------------------------------------------------------------------*/
  493. /**********************************************************************/
  494. int GetFontCount( HPS hps, HWND hwndClient, PBOOL pfUseOurFont )
  495. {
  496.     LONG cFonts, cFontsRequested = 0;
  497.  
  498.     *pfUseOurFont = TRUE;
  499.  
  500.     cFonts = GpiQueryFonts( hps, QF_PUBLIC, FONTFACE_NAME, &cFontsRequested, 0,
  501.                             NULL );
  502.  
  503.     if( cFonts == GPI_ALTERROR )
  504.     {
  505.         cFonts = 0;
  506.  
  507.         Msg( "GetFontCount GpiQueryFonts RC(%X)", HWNDERR( hwndClient ) );
  508.     }
  509.     else if( !cFonts )
  510.     {
  511.         *pfUseOurFont = FALSE;
  512.  
  513.         cFontsRequested  = 0;
  514.  
  515.         cFonts = GpiQueryFonts( hps, QF_PUBLIC, NULL, &cFontsRequested, 0,
  516.                                 NULL );
  517.  
  518.         if( !cFonts )
  519.             Msg( "GetFontCount GpiQueryFonts found NO FONTS in your system!" );
  520.         else if( cFonts == GPI_ALTERROR )
  521.         {
  522.             cFonts = 0;
  523.  
  524.             Msg( "GetFontCount GpiQueryFonts RC(%X)", HWNDERR( hwndClient ) );
  525.         }
  526.     }
  527.  
  528.     return cFonts;
  529. }
  530.  
  531. /**********************************************************************/
  532. /*--------------------------- PaintClient ----------------------------*/
  533. /*                                                                    */
  534. /*  PROCESS THE CLIENT'S WM_PAINT MESSAGE                             */
  535. /*                                                                    */
  536. /*  PARMS: client window handle                                       */
  537. /*                                                                    */
  538. /*  NOTES:                                                            */
  539. /*                                                                    */
  540. /*  RETURNS: nothing                                                  */
  541. /*                                                                    */
  542. /*--------------------------------------------------------------------*/
  543. /**********************************************************************/
  544. void PaintClient( HWND hwndClient )
  545. {
  546.     POINTL ptl;
  547.     HRGN   hrgn;
  548.     RECTL  rcl;
  549.     SWP    swpCnr;
  550.     HPS    hps = WinBeginPaint( hwndClient, NULLHANDLE, NULL );
  551.  
  552.     WinQueryWindowPos( WinWindowFromID( hwndClient, CNR_DROP ), &swpCnr );
  553.     WinQueryWindowRect( hwndClient, &rcl );
  554.  
  555.     GpiErase( hps );
  556.  
  557.     // Put a vertical separator between the left-side of the client and the
  558.     // right side where the container is (the container does not have a border
  559.     // so we have to draw it).
  560.  
  561.     GpiSetColor( hps, SYSCLR_WINDOWFRAME );
  562.     ptl.x = swpCnr.x - 1;
  563.     ptl.y = 0;
  564.     GpiMove( hps, &ptl );
  565.     ptl.y = rcl.yTop;
  566.     GpiLine( hps, &ptl );
  567.  
  568.     // Set up a clipping region for the text (the left half of the client area)
  569.  
  570.     rcl.xRight = ptl.x;
  571.     hrgn = GpiCreateRegion( hps, 1, &rcl );
  572.  
  573.     if( hrgn )
  574.     {
  575.         HRGN hrgnOld;
  576.         LONG lComplexity = GpiSetClipRegion( hps, hrgn, &hrgnOld );
  577.  
  578.         if( lComplexity == RGN_ERROR )
  579.             Msg( "GpiSetClipRegion RC(%X)", HWNDERR( hwndClient ) );
  580.         else
  581.         {
  582.             GpiSetColor( hps, SYSCLR_WINDOWFRAME );
  583.             GpiSetMix( hps, FM_OVERPAINT );
  584.             GpiSetBackColor( hps, SYSCLR_WINDOWFRAME );
  585.             GpiSetBackMix( hps, BM_LEAVEALONE );
  586.             DrawBullsEye( hps, hwndClient, &rcl );
  587.  
  588.             GpiSetColor( hps, CLR_RED );
  589.             PaintText( hps, hwndClient, &rcl );
  590.  
  591.             if( hrgnOld )
  592.                 GpiDestroyRegion( hps, hrgnOld );
  593.         }
  594.  
  595.         GpiDestroyRegion( hps, hrgn );
  596.     }
  597.     else
  598.         Msg( "GpiCreateRegion RC(%X)", HWNDERR( hwndClient ) );
  599.  
  600.     WinEndPaint( hps );
  601. }
  602.  
  603. /**********************************************************************/
  604. /*--------------------------- PaintText ------------------------------*/
  605. /*                                                                    */
  606. /*  PAINT TEXT IN THE CLIENT AREA                                     */
  607. /*                                                                    */
  608. /*  PARMS: presentation space handle,                                 */
  609. /*         client window handle,                                      */
  610. /*         pointer to rectangle to draw into                          */
  611. /*                                                                    */
  612. /*  1.                                                                */
  613. /*                                                                    */
  614. /*  OUTPUT: nothing                                                   */
  615. /*                                                                    */
  616. /*--------------------------------------------------------------------*/
  617. /**********************************************************************/
  618. void PaintText( HPS hps, HWND hwndClient, PRECTL prcl )
  619. {
  620.     RECTL rclText;
  621.  
  622.     if( !WinCopyRect( ANCHOR( hwndClient ), &rclText, prcl ) )
  623.     {
  624.         Msg( "PaintText WinCopyRect RC(%X)", HWNDERR( hwndClient ) );
  625.         return;
  626.     }
  627.  
  628.     if( GPI_ERROR == GpiCreateLogFont( hps, NULL, lcid, &fattrs ) )
  629.         Msg( "PaintText GpiCreateLogFont RC(%X)", HWNDERR( hwndClient ) );
  630.     else
  631.     {
  632.         if( GpiSetCharSet( hps, lcid ) )
  633.         {
  634.             int   cbLongestString = 0;
  635.             ULONG cxChar, cyChar;
  636.             ULONG cxDraw = (rclText.xRight - rclText.xLeft) + 1;
  637.             SIZEF sizf;
  638.             int   i;
  639.  
  640.             for( i = 0; i < TEXT_LINES; i++ )
  641.                 if( strlen( szTextLine[ i ] ) > cbLongestString )
  642.                     cbLongestString = strlen( szTextLine[ i ] );
  643.  
  644.             cxChar = ((rclText.xRight - rclText.xLeft) + 1) / cbLongestString;
  645.             cyChar = ((rclText.yTop - rclText.yBottom) + 1) / TEXT_LINES;
  646.  
  647.             sizf.cx = MAKEFIXED( cxChar, 0 );
  648.             sizf.cy = MAKEFIXED( cyChar, 0 );
  649.  
  650.             if( GpiSetCharBox( hps, &sizf ) )
  651.             {
  652.                 POINTL aptl[ TXTBOX_COUNT ];
  653.  
  654.                 rclText.yBottom = rclText.yTop;
  655.  
  656.                 for( i = 0; i < TEXT_LINES; i++ )
  657.                 {
  658.                     // Center string horizontally
  659.  
  660.                     GpiQueryTextBox( hps, strlen( szTextLine[ i ] ),
  661.                                      szTextLine[ i ], TXTBOX_COUNT, aptl );
  662.                     rclText.xLeft = (cxDraw - aptl[ TXTBOX_CONCAT ].x) / 2;
  663.  
  664.                     rclText.yBottom -= cyChar;
  665.  
  666.                     if( GPI_ERROR == GpiCharStringPosAt( hps,
  667.                                                 (PPOINTL) &rclText, NULL, 0,
  668.                                                 strlen( szTextLine[ i ] ),
  669.                                                 szTextLine[ i ], NULL ) )
  670.                         Msg( "PaintText GpiCharStringPosAt RC(%X)",
  671.                             HWNDERR( hwndClient ) );
  672.                 }
  673.             }
  674.             else
  675.                 Msg( "PaintText GpiSetCharBox RC(%X)", HWNDERR( hwndClient ) );
  676.         }
  677.         else
  678.             Msg( "PaintText GpiSetCharSet RC(%X)", HWNDERR( hwndClient ) );
  679.     }
  680. }
  681.  
  682. /**********************************************************************/
  683. /*-------------------------- DrawBullsEye ----------------------------*/
  684. /*                                                                    */
  685. /*  DRAW A BULLSEYE IN THE CLIENT AREA                                */
  686. /*                                                                    */
  687. /*  PARMS: presentation space handle,                                 */
  688. /*         client window handle,                                      */
  689. /*         pointer to rectangle to draw into                          */
  690. /*                                                                    */
  691. /*  1.                                                                */
  692. /*                                                                    */
  693. /*  OUTPUT: nothing                                                   */
  694. /*                                                                    */
  695. /*--------------------------------------------------------------------*/
  696. /**********************************************************************/
  697. void DrawBullsEye( HPS hps, HWND hwndClient, PRECTL prcl )
  698. {
  699.     ARCPARAMS arcParams;
  700.     POINTL    ptlCenter;
  701.     FIXED     fixedMult;
  702.     ULONG     cxDraw, cyDraw;
  703.     int       i;
  704.  
  705.     cxDraw = (prcl->xRight - prcl->xLeft) + 1;
  706.     cyDraw = (prcl->yTop - prcl->yBottom) + 1;
  707.  
  708.     ptlCenter.x = cxDraw / 2;
  709.     ptlCenter.y = cyDraw / 2;
  710.  
  711.     GpiMove( hps, &ptlCenter );
  712.  
  713.     arcParams.lP = cxDraw / 10;
  714.     arcParams.lQ = cyDraw / 10;
  715.     arcParams.lR = 0;
  716.     arcParams.lS = 0;
  717.  
  718.     GpiSetArcParams( hps, &arcParams );
  719.  
  720.     for( i = 1; i < 11; i++ )
  721.     {
  722.         fixedMult = MAKEFIXED( i, 0 );
  723.  
  724.         if( GPI_ERROR == GpiFullArc( hps, DRO_OUTLINE, fixedMult ) )
  725.             Msg( "DrawBullsEye GpiFullArc RC(%X)", HWNDERR( hwndClient ) );
  726.     }
  727. }
  728.  
  729. /*************************************************************************
  730.  *                     E N D     O F     S O U R C E                     *
  731.  *************************************************************************/
  732.