home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cnradv.zip / draw.c < prev    next >
C/C++ Source or Header  |  1993-09-04  |  14KB  |  298 lines

  1. /*********************************************************************
  2.  *----------------------------- DRAW.C ------------------------------*
  3.  *                                                                   *
  4.  * MODULE NAME :  draw.c                 AUTHOR:  Rick Fishman       *
  5.  * DATE WRITTEN:  12-05-92                                           *
  6.  *                                                                   *
  7.  * DESCRIPTION:                                                      *
  8.  *                                                                   *
  9.  *  This module is part of CNRADV.EXE. It contains the functions     *
  10.  *  necessary to implement ownerdraw columns and background.         *
  11.  *                                                                   *
  12.  * NOTE: We use CA_OWNERPAINTBACKGROUND to cause the container to    *
  13.  *       send itself a CM_PAINTBACKGROUND message. We then subclass  *
  14.  *       the container to catch this message and paint the container *
  15.  *       as requested the last time the user selected an item from   *
  16.  *       the Background submenu. We do this for selected colors as   *
  17.  *       well as for a Bitmap. If you simply want to set the back-   *
  18.  *       ground color of the container, WinSetPresParam would be the *
  19.  *       way to go. I mainly did it this way to demonstrate the      *
  20.  *       CA_OWNERPAINTBACKGROUND method. Also this is the only way   *
  21.  *       you could paint a bitmap on the background.                 *
  22.  *                                                                   *
  23.  * IMPORTANT NOTE: While coding this module I found out that when    *
  24.  *                 a container item is selected or unselected, that  *
  25.  *                 causes a CM_PAINTBACKGROUND message for only that *
  26.  *                 record. This is difficult to handle so it is not  *
  27.  *                 being processed correctly at this time. As a      *
  28.  *                 result, when this happens, the bitmap is          *
  29.  *                 compressed to the size of the item and drawn. Not *
  30.  *                 a great effect but to fix this I'd have to store  *
  31.  *                 a bitmap for each container window and bitblt     *
  32.  *                 from an offset from that bitmap. If this were     *
  33.  *                 anything but a sample, I'd do it <g>.             *
  34.  *                                                                   *
  35.  * CALLABLE FUNCTIONS:                                               *
  36.  *                                                                   *
  37.  *  VOID    DrawSubclassCnr( HWND hwndClient );                      *
  38.  *  MRESULT DrawItem( HWND hwndClient, POWNERITEM poi );             *
  39.  *                                                                   *
  40.  * HISTORY:                                                          *
  41.  *                                                                   *
  42.  *  12-05-92 - Program coded.                                        *
  43.  *  07-23-93 - Catch WM_CHAR to get the Shift-F10 keystroke so we    *
  44.  *             can send the client window a CN_CONTEXTMENU message.  *
  45.  *             This compensates for a bug in the container that      *
  46.  *             doesn't send this message if the container is not a   *
  47.  *             child of the frame window.                            *
  48.  *                                                                   *
  49.  *  Rick Fishman                                                     *
  50.  *  Code Blazers, Inc.                                               *
  51.  *  4113 Apricot                                                     *
  52.  *  Irvine, CA. 92720                                                *
  53.  *  CIS ID: 72251,750                                                *
  54.  *                                                                   *
  55.  *                                                                   *
  56.  *********************************************************************/
  57.  
  58. /*********************************************************************/
  59. /*------- Include relevant sections of the OS/2 header files --------*/
  60. /*********************************************************************/
  61.  
  62. #define  INCL_GPIBITMAPS
  63. #define  INCL_GPIPRIMITIVES
  64. #define  INCL_WINDIALOGS
  65. #define  INCL_WINERRORS
  66. #define  INCL_WINFRAMEMGR
  67. #define  INCL_WININPUT
  68. #define  INCL_WINMENUS
  69. #define  INCL_WINSTDCNR
  70. #define  INCL_WINSYS
  71. #define  INCL_WINWINDOWMGR
  72.  
  73. /**********************************************************************/
  74. /*----------------------------- INCLUDES -----------------------------*/
  75. /**********************************************************************/
  76.  
  77. #include <os2.h>
  78. #include <stdarg.h>
  79. #include <stdio.h>
  80. #include <stdlib.h>
  81. #include <string.h>
  82. #include "cnradv.h"
  83.  
  84. /*********************************************************************/
  85. /*------------------- APPLICATION DEFINITIONS -----------------------*/
  86. /*********************************************************************/
  87.  
  88. /**********************************************************************/
  89. /*---------------------------- STRUCTURES ----------------------------*/
  90. /**********************************************************************/
  91.  
  92. /**********************************************************************/
  93. /*----------------------- FUNCTION PROTOTYPES ------------------------*/
  94. /**********************************************************************/
  95.  
  96. static VOID PaintBackground( PINSTANCE pi, POWNERBACKGROUND pob );
  97.  
  98. FNWP wpCnr;
  99.  
  100. /**********************************************************************/
  101. /*------------------------ GLOBAL VARIABLES --------------------------*/
  102. /**********************************************************************/
  103.  
  104. /**********************************************************************/
  105. /*------------------------- DrawSubclassCnr --------------------------*/
  106. /*                                                                    */
  107. /*  SUBCLASS THE CONTAINER SO WE CAN GET CM_PAINTBACKGROUND.          */
  108. /*                                                                    */
  109. /*  INPUT: client window handle                                       */
  110. /*                                                                    */
  111. /*  1.                                                                */
  112. /*                                                                    */
  113. /*  OUTPUT: nothing                                                   */
  114. /*                                                                    */
  115. /*--------------------------------------------------------------------*/
  116. /**********************************************************************/
  117. VOID DrawSubclassCnr( HWND hwndClient )
  118. {
  119.     PINSTANCE pi = INSTDATA( hwndClient );
  120.     HWND      hwndCnr = WinWindowFromID( hwndClient, CNR_DIRECTORY );
  121.  
  122.     if( !pi )
  123.     {
  124.         Msg( "DrawSubclass cant get Inst data. RC(%X)", HWNDERR( hwndClient ) );
  125.  
  126.         return;
  127.     }
  128.  
  129.     // Subclass the container so we can capture the CM_PAINTBACKGROUND message
  130.  
  131.     pi->pfnwpDefCnr = WinSubclassWindow( hwndCnr, wpCnr );
  132.  
  133.     if( !pi->pfnwpDefCnr )
  134.         Msg( "DrawSubclassCnr WinSubclassWindow RC(%X)",HWNDERR( hwndClient ) );
  135. }
  136.  
  137. /**********************************************************************/
  138. /*---------------------------- DrawItem ------------------------------*/
  139. /*                                                                    */
  140. /*  PROCESS A WM_DRAWITEM MESSAGE FOR THE CONTAINER.                  */
  141. /*                                                                    */
  142. /*  INPUT: client window handle                                       */
  143. /*         pointer to an OWNERITEM structure                          */
  144. /*                                                                    */
  145. /*  1.                                                                */
  146. /*                                                                    */
  147. /*  OUTPUT: result of drawing                                         */
  148. /*                                                                    */
  149. /*--------------------------------------------------------------------*/
  150. /**********************************************************************/
  151. MRESULT DrawItem( HWND hwndClient, POWNERITEM poi )
  152. {
  153.     PCNRDRAWITEMINFO pcdii = (PCNRDRAWITEMINFO) poi->hItem;
  154.     CHAR             szAttrs[ 6 ];
  155.     PCNRITEM         pci = (PCNRITEM) pcdii->pRecord;
  156.     PCH              pch = szAttrs;
  157.     COLOR            clrForeground = CLR_RED;
  158.  
  159.     // Let the container draw the column heading
  160.  
  161.     if( !pci )
  162.         return (MRESULT) FALSE;
  163.  
  164.     // We placed this column identifier in pUserData when we set up the columns
  165.     // in create.c. This is just a number that lets us know what column we are
  166.     // in when all we have is a FIELDINFO pointer. The only column that is
  167.     // declared CFA_OWNER is the FILEATTR_COLUMN column, but this is used
  168.     // primarily to point out what methods are available to determine which
  169.     // column we are in if there is more than one ownerdraw column.
  170.  
  171.     if( pcdii->pFieldInfo->pUserData != (PVOID) FILEATTR_COLUMN )
  172.         return (MRESULT) FALSE;
  173.  
  174.     (void) memset( szAttrs, 0, sizeof( szAttrs ) );
  175.  
  176.     if( pci->attrFile & FILE_DIRECTORY )
  177.         *(pch++) = 'D';
  178.  
  179.     if( pci->attrFile & FILE_READONLY )
  180.         *(pch++) = 'R';
  181.  
  182.     if( pci->attrFile & FILE_HIDDEN )
  183.         *(pch++) = 'H';
  184.  
  185.     if( pci->attrFile & FILE_SYSTEM )
  186.         *(pch++) = 'S';
  187.  
  188.     if( pci->attrFile & FILE_ARCHIVED )
  189.         *(pch++) = 'A';
  190.  
  191.     // If record is selected, simulate CRA_SELECTED emphasis. It appears to be
  192.     // up to us to draw the selection state.
  193.  
  194.     if( poi->fsAttribute & CRA_SELECTED )
  195.     {
  196.         clrForeground = SYSCLR_HILITEFOREGROUND;
  197.  
  198.         if( !WinFillRect( poi->hps, &(poi->rclItem), SYSCLR_HILITEBACKGROUND ) )
  199.             Msg( "DrawItem WinFillRect RC(%X)", HWNDERR( hwndClient ) );
  200.     }
  201.  
  202.     poi->rclItem.xLeft += 10;
  203.  
  204.     if( *szAttrs )
  205.         if( !WinDrawText( poi->hps, strlen( szAttrs ), szAttrs, &(poi->rclItem),
  206.                           clrForeground, 0, DT_VCENTER | DT_LEFT ) )
  207.             Msg( "DrawItem WinDrawText RC(%X)", HWNDERR( hwndClient ) );
  208.  
  209.     return (MRESULT) TRUE;
  210. }
  211.  
  212. /**********************************************************************/
  213. /*------------------------------ wpCnr -------------------------------*/
  214. /*                                                                    */
  215. /*  CONTAINER WINDOW PROCEDURE (SUBCLASSED).                          */
  216. /*                                                                    */
  217. /*  INPUT: standard window procedure parameters                       */
  218. /*                                                                    */
  219. /*  1.                                                                */
  220. /*                                                                    */
  221. /*  OUTPUT: result of message processing                              */
  222. /*                                                                    */
  223. /*--------------------------------------------------------------------*/
  224. /**********************************************************************/
  225. MRESULT EXPENTRY wpCnr( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  226. {
  227.     PINSTANCE pi = INSTDATA( PARENT( hwnd ) );
  228.  
  229.     if( !pi )
  230.     {
  231.         Msg( "wpCnr cant get Inst data. RC(%X)", HWNDERR( hwnd ) );
  232.  
  233.         return 0;
  234.     }
  235.  
  236.     switch( msg )
  237.     {
  238.         case CM_PAINTBACKGROUND:
  239.         {
  240.             PaintBackground( pi, (POWNERBACKGROUND) mp1 );
  241.  
  242.             return (MRESULT) TRUE;
  243.         }
  244.  
  245.         case WM_CHAR:
  246.             if( SHORT1FROMMP( mp1 ) & KC_VIRTUALKEY &&
  247.                 SHORT1FROMMP( mp1 ) & KC_SHIFT &&
  248.                 SHORT2FROMMP( mp2 ) == VK_F10 )
  249.             {
  250.                 WinSendMsg( OWNER( hwnd ), WM_CONTROL,
  251.                             MPFROM2SHORT( WinQueryWindowUShort( hwnd, QWS_ID ),
  252.                                           CN_CONTEXTMENU ), NULL );
  253.                 return (MRESULT) TRUE;
  254.             }
  255.  
  256.             break;
  257.     }
  258.  
  259.     return pi->pfnwpDefCnr( hwnd, msg, mp1, mp2 );
  260. }
  261.  
  262. /**********************************************************************/
  263. /*------------------------- PaintBackground --------------------------*/
  264. /*                                                                    */
  265. /*  PROCESS THE CM_PAINTBACKGROUND MESSAGE.                           */
  266. /*                                                                    */
  267. /*  INPUT: pointer to OWNERBACKGROUND structure                       */
  268. /*                                                                    */
  269. /*  1.                                                                */
  270. /*                                                                    */
  271. /*  OUTPUT: nothing                                                   */
  272. /*                                                                    */
  273. /*--------------------------------------------------------------------*/
  274. /**********************************************************************/
  275. static VOID PaintBackground( PINSTANCE pi, POWNERBACKGROUND pob )
  276. {
  277.     // clrBackground is initially set to CLR_WHITE during window initialization.
  278.     // The user can change this by selecting a color from the Background
  279.     // submenu. If they choose Bitmap from that submenu, we set clrBackground
  280.     // to 0, meaning we should draw the bitmap. This bitmap was created in
  281.     // ProgInit in CNRADV.C. It is destroyed in ProgTerm in that same module.
  282.  
  283.     if( pi->clrBackground )
  284.     {
  285.         if( !WinFillRect( pob->hps, &(pob->rclBackground), pi->clrBackground ) )
  286.             Msg( "PaintBackground WinFillRect RC(%X)", HWNDERR( pob->hwnd ) );
  287.     }
  288.     else
  289.         if( !WinDrawBitmap( pob->hps, hbmBackground, NULL,
  290.                           (PPOINTL) &(pob->rclBackground), 0, 0, DBM_STRETCH ) )
  291.             Msg( "PaintBackground WinDrawBitmap RC(%X)",
  292.                  HWNDERR( pob->hwnd ) );
  293. }
  294.  
  295. /*************************************************************************
  296.  *                     E N D     O F     S O U R C E                     *
  297.  *************************************************************************/
  298.