home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CNRDTL.ZIP / CNFUNC.C next >
C/C++ Source or Header  |  1992-09-18  |  9KB  |  252 lines

  1. // cnfunc.c -- Container utility functions
  2.  
  3. //--------------------------------------------------------------
  4. //
  5. //  cnfunc.c
  6. //
  7. //      Container utility functions
  8. //
  9. //--------------------------------------------------------------
  10.  
  11. #define INCL_WIN
  12. #include <os2.h>
  13.  
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. #include "cnfunc.h"
  18.  
  19.  
  20. #define MAXMSGSIZE  255                 // Max size of string
  21.  
  22.  
  23. //--------------------------------------------------------------
  24. //  UtilLoadString - load a string from the resource file
  25. //--------------------------------------------------------------
  26.  
  27. PSZ UtilLoadString (            // Load string from res
  28. USHORT  usStringID,             // I - String identifier
  29. HAB     hab,                    // I - Current HAB
  30. HMODULE hmod)                   // I - Resource module or NULL
  31. {
  32.     PSZ     pszBuf;             // String buffer
  33.  
  34.     pszBuf = malloc (MAXMSGSIZE);
  35.     if (WinLoadString (hab, hmod, usStringID, MAXMSGSIZE, 
  36.                        pszBuf) == 0)
  37.     {
  38.         free (pszBuf);
  39.         return (NULL);
  40.     }
  41.  
  42.     return (pszBuf);            // Return -> string
  43. }
  44.  
  45.  
  46. //--------------------------------------------------------------
  47. //
  48. //  CnCreateDetailsView
  49. //
  50. //      Create the details view of the container.  This requires
  51. //      setting up the column information.
  52. //
  53. //--------------------------------------------------------------
  54.  
  55. USHORT CnCreateDetailsView (            // Create details view
  56. HWND    hwndContainer,                  // I - container window
  57. USHORT  cColumns,                       // I - Number of colums
  58. COLDESC acd[],                          // IO->column descriptor
  59. SHORT   sLastLeftColumn,                // I - Last column in 
  60.                                         // left split window
  61.                                         //     -1 means no split
  62. LONG    lPctSplitBarPos,                // Percent of cntr width 
  63.                                         // to set split bar
  64. USHORT  idTitle,                        // I - container hdg id
  65. HMODULE hmod)                           // I -hmod for resources
  66. {
  67.     USHORT      i;                      // Loop counter
  68.  
  69.     CNRINFO     cnrinfo;                // Cntr info structure
  70.     PFIELDINFO  pFieldInfoHead;         // --> First field
  71.     PFIELDINFO  pFieldInfo;             // --> Current field
  72.     FIELDINFOINSERT FieldInsertInfo;
  73.  
  74.     PCOLDESC    pcd;                    // Column descriptor
  75.  
  76.     //----------------------------------------------------------
  77.     //  Get container text information
  78.     //----------------------------------------------------------
  79.  
  80.     for (pcd = acd, i = 0; i < cColumns; i++, pcd++)
  81.     {
  82.         if (pcd->pszTitle == NULL)
  83.             pcd->pszTitle = UtilLoadString (pcd->idTitle,
  84.                             WinQueryAnchorBlock (hwndContainer),
  85.                                             hmod);
  86.     }
  87.  
  88.  
  89.     //----------------------------------------------------------
  90.     //  Initialize the container for a simple details view
  91.     //----------------------------------------------------------
  92.  
  93.     memset (&cnrinfo, 0, sizeof(CNRINFO));
  94.     cnrinfo.cb = sizeof (CNRINFO);
  95.     
  96.     // Set for Details View, with column titles, with icons and
  97.     // not bitmaps, include a container title, with a separator
  98.     // bar underneath it, and don't let the user change title
  99.     cnrinfo.flWindowAttr = CV_DETAIL            |
  100.                            CA_DETAILSVIEWTITLES |
  101.                            CA_CONTAINERTITLE    |
  102.                            CA_TITLESEPARATOR;
  103.                            
  104.     cnrinfo.pszCnrTitle = UtilLoadString (idTitle,
  105.                             WinQueryAnchorBlock (hwndContainer),
  106.                             hmod);
  107.  
  108.     WinSendMsg (hwndContainer, CM_SETCNRINFO,
  109.                 MPFROMP (&cnrinfo),
  110.                 MPFROMLONG (CMA_FLWINDOWATTR | CMA_CNRTITLE));
  111.     
  112.  
  113.     //----------------------------------------------------------
  114.     //  Get memory for the column information
  115.     //----------------------------------------------------------
  116.  
  117.     pFieldInfoHead = (PFIELDINFO) PVOIDFROMMR (
  118.                             WinSendMsg (hwndContainer,
  119.                                         CM_ALLOCDETAILFIELDINFO,
  120.                                         MPFROMSHORT (cColumns),
  121.                                         0));
  122.  
  123.     pFieldInfo = pFieldInfoHead;        // Start at top of list
  124.  
  125.  
  126.     //----------------------------------------------------------
  127.     //  Load the field info structures
  128.     //----------------------------------------------------------
  129.  
  130.     for (pcd = acd, i = 0; i < cColumns; i++, pcd++)
  131.     {
  132.         pFieldInfo->cb          = sizeof (FIELDINFO);
  133.         pFieldInfo->flData      = pcd->flAttributes;
  134.         pFieldInfo->flTitle     = pcd->flTitle; 
  135.         pFieldInfo->pTitleData  = pcd->pszTitle;
  136.         pFieldInfo->offStruct   = pcd->offField;
  137.         pFieldInfo->pUserData   = NULL;
  138.         pFieldInfo->cxWidth     = pcd->cxWidth;
  139.  
  140.         if (sLastLeftColumn >= 0)
  141.         {
  142.             if (sLastLeftColumn == i)
  143.             {
  144.                 SWP     swp;
  145.                 WinQueryWindowPos (hwndContainer, &swp);
  146.                 cnrinfo.pFieldInfoLast = pFieldInfo;
  147.                 cnrinfo.xVertSplitbar  = 
  148.                                (swp.cx * lPctSplitBarPos) / 100;
  149.                 WinSendMsg (hwndContainer, CM_SETCNRINFO,
  150.                             MPFROMP (&cnrinfo),
  151.                             MPFROMLONG (CMA_PFIELDINFOLAST | 
  152.                                         CMA_XVERTSPLITBAR));
  153.             }
  154.         }
  155.         pFieldInfo = pFieldInfo->pNextFieldInfo;
  156.     };
  157.  
  158.  
  159.     //----------------------------------------------------------
  160.     //  Construct the FIELDINFOINSERT structure that describes
  161.     //  the number of fields to be inserted, where they are to 
  162.     //  be inserted, etc.
  163.     //----------------------------------------------------------
  164.  
  165.     memset (&FieldInsertInfo, 0, sizeof(FIELDINFOINSERT));
  166.     FieldInsertInfo.cb               = sizeof (FIELDINFOINSERT);
  167.     FieldInsertInfo.pFieldInfoOrder  = (PFIELDINFO) CMA_END;
  168.     FieldInsertInfo.cFieldInfoInsert = cColumns;
  169.     FieldInsertInfo.fInvalidateFieldInfo = TRUE;
  170.  
  171.  
  172.     //----------------------------------------------------------
  173.     //  Insert the fields.
  174.     //----------------------------------------------------------
  175.  
  176.     WinSendMsg (hwndContainer, CM_INSERTDETAILFIELDINFO,
  177.                 MPFROMP (pFieldInfoHead),
  178.                 MPFROMP (&FieldInsertInfo));
  179.     return 0;
  180.  
  181. }
  182.  
  183.  
  184.  
  185. //--------------------------------------------------------------
  186. //
  187. //  CnDestroyDetailsView
  188. //
  189. //      Destroy the details view of the container.  This
  190. //      requires freeing column information.
  191. //
  192. //--------------------------------------------------------------
  193.  
  194. USHORT CnDestroyDetailsView (   // Destroy details view
  195. HWND    hwndContainer,          // I - Handle to cntr window
  196. USHORT  cColumns,               // I - Number of colums
  197. COLDESC acd[])                  // IO--> column descriptor
  198. {
  199.     USHORT      i;              // Loop counter
  200.     PCOLDESC    pcd;            // Column descriptor entry
  201.     CNRINFO     cnrinfo;        // Container info structure
  202.  
  203.  
  204.     //----------------------------------------------------------
  205.     //  Remove any column titles loaded into memory
  206.     //----------------------------------------------------------
  207.     
  208.     for (pcd = acd, i = 0; i < cColumns; i++, pcd++)
  209.     {
  210.         if (    (pcd->pszTitle != NULL)
  211.              && (pcd->idTitle != 0) )
  212.         {
  213.             free (pcd->pszTitle);
  214.             pcd->pszTitle = NULL;
  215.         }
  216.     }
  217.  
  218.     
  219.     //----------------------------------------------------------
  220.     //  Remove the column heading from memory
  221.     //----------------------------------------------------------
  222.  
  223.     WinSendMsg (hwndContainer,
  224.                 CM_QUERYCNRINFO,
  225.                 MPFROMP(&cnrinfo),
  226.                 MPFROMSHORT (sizeof(CNRINFO)));
  227.                 
  228.     free (cnrinfo.pszCnrTitle);
  229.     
  230.                 
  231.     //----------------------------------------------------------
  232.     //  Remove the column information of the container
  233.     //----------------------------------------------------------
  234.  
  235.     WinSendMsg (hwndContainer,
  236.                 CM_REMOVEDETAILFIELDINFO,
  237.                 0,
  238.                 MPFROM2SHORT (0, CMA_FREE));
  239.  
  240.  
  241.     //----------------------------------------------------------
  242.     //  Remove any records in the container
  243.     //----------------------------------------------------------
  244.  
  245.     WinSendMsg (hwndContainer,
  246.                 CM_REMOVERECORD,
  247.                 0,
  248.                 MPFROM2SHORT (0, CMA_FREE));
  249.  
  250.     return 0;
  251. }
  252.