home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dho.zip / DHO / SRC / CONTAIN.CC < prev    next >
C/C++ Source or Header  |  1995-08-29  |  5KB  |  177 lines

  1. /****************************************/
  2. /*    Developer Helper Object Set       */
  3. /*  (C) 1994-95 Thomas E. Bednarz, Jr.  */
  4. /*     All rights reserved              */
  5. /***************************************/
  6.  
  7. /* $Id: contain.cc 1.3 1995/08/13 03:21:12 teb Exp teb $ */
  8.  
  9.  
  10.  
  11. #include"contain.h"
  12.  
  13. //----------------------------------------------------------
  14. //  TContainerWindow
  15. TContainerWindow::TContainerWindow(ULONG id, TWinBase *parent, BOOL readOnly):
  16.    TWinBase(id)
  17. {   
  18.    fId = id;
  19.    fParent = parent;
  20.    fReadOnly = readOnly;
  21. }
  22.  
  23.  
  24. //----------------------------------------------------------
  25. //  ~TContainerWindow
  26. TContainerWindow::~TContainerWindow()
  27. {
  28.  
  29. }
  30.  
  31.  
  32. //----------------------------------------------------------
  33. //  Init
  34. BOOL TContainerWindow::init()
  35. {
  36.  
  37.    ULONG style = CCS_AUTOPOSITION;
  38.    if (fReadOnly)
  39.       style |= CCS_READONLY;
  40.  
  41.    hwnd = WinCreateWindow(
  42.                 fParent->getHWND(),
  43.                 WC_CONTAINER,
  44.                 NULL,
  45.                 style,
  46.                 0,0,0,0,
  47.                 fParent->getHWND(),
  48.                 HWND_BOTTOM,
  49.                 fId,
  50.                 NULL, NULL);
  51.  
  52.    return (hwnd != (HWND)NULL);
  53. }
  54.  
  55.  
  56. //----------------------------------------------------------
  57. //  insertItem
  58. void TContainerWindow::insertItem(HPOINTER icon, PSZ iconName)
  59. {
  60.    PRECORDCORE pRecordCore;
  61.    RECORDINSERT recordInsert;
  62.  
  63.     pRecordCore = (PRECORDCORE) WinSendMsg(hwnd, CM_ALLOCRECORD,
  64.                  0, MPFROMLONG(1));
  65.  
  66.     pRecordCore->cb = sizeof(RECORDCORE);
  67.  
  68.     pRecordCore->hptrIcon = icon;
  69.  
  70.     pRecordCore->pszIcon = pRecordCore->pszName =
  71.            pRecordCore->pszText = iconName;
  72.  
  73.    recordInsert.cb = sizeof(RECORDINSERT);
  74.    recordInsert.pRecordParent = NULL;
  75.    recordInsert.pRecordOrder = (PRECORDCORE)CMA_END;
  76.    recordInsert.zOrder = (USHORT)CMA_TOP;
  77.    recordInsert.cRecordsInsert = 1;
  78.    recordInsert.fInvalidateRecord = TRUE;
  79.  
  80.    WinSendMsg(hwnd, CM_INSERTRECORD,
  81.                  (PRECORDCORE)pRecordCore, &recordInsert);
  82.  
  83. }
  84.  
  85.  
  86. //----------------------------------------------------------
  87. //  insertItem
  88. void TContainerWindow::insertItem(LONG iconId, PSZ iconName)
  89. {
  90.    HPOINTER icon;
  91.  
  92.    icon = WinQuerySysPointer(HWND_DESKTOP, iconId,FALSE);
  93.    insertItem(icon, iconName);
  94. }
  95.  
  96.  
  97. //----------------------------------------------------------
  98. //  insertItems
  99. void TContainerWindow::insertItems(PContainerIconInfo items, LONG numItems)
  100. {
  101.    PRECORDCORE pRecordCore, pStartingRecordCore;
  102.    RECORDINSERT recordInsert;
  103.    LONG i;
  104.  
  105.     pRecordCore = (PRECORDCORE) WinSendMsg(hwnd, CM_ALLOCRECORD,
  106.                  0, MPFROMLONG(numItems));
  107.  
  108.     pStartingRecordCore = pRecordCore;
  109.  
  110.    for (i=0; i<numItems; i++)
  111.    {
  112.        pRecordCore->cb = sizeof(RECORDCORE);
  113.        pRecordCore->hptrIcon = WinQuerySysPointer(HWND_DESKTOP, items[i].iconId, FALSE);
  114.  
  115.        pRecordCore->pszIcon = pRecordCore->pszName =
  116.               pRecordCore->pszText = (PSZ)items[i].iconName;
  117.  
  118.       pRecordCore = pRecordCore->preccNextRecord;
  119.    }
  120.  
  121.    recordInsert.cb = sizeof(RECORDINSERT);
  122.    recordInsert.pRecordParent = NULL;
  123.    recordInsert.pRecordOrder = (PRECORDCORE)CMA_END;
  124.    recordInsert.zOrder = (USHORT)CMA_TOP;
  125.    recordInsert.cRecordsInsert = numItems;
  126.    recordInsert.fInvalidateRecord = TRUE;
  127.  
  128.    WinSendMsg(hwnd, CM_INSERTRECORD,
  129.                  (PRECORDCORE)pStartingRecordCore, &recordInsert);
  130. }
  131.  
  132.  
  133. //----------------------------------------------------------
  134. //  setViewType
  135. void TContainerWindow::setViewType(ContainerViewType viewType)
  136. {
  137.    CNRINFO cnrinfo;
  138.    if ( viewType == icon )
  139.        cnrinfo.flWindowAttr = CV_ICON;
  140.    else if ( viewType == name_flowed )
  141.        cnrinfo.flWindowAttr = CV_NAME | CV_FLOW;
  142.    else if ( viewType == name_nonflowed )
  143.        cnrinfo.flWindowAttr = CV_NAME;
  144.    else if ( viewType == text_flowed )
  145.        cnrinfo.flWindowAttr = CV_TEXT | CV_FLOW;
  146.    else if ( viewType == text_nonflowed )
  147.        cnrinfo.flWindowAttr = CV_TEXT;
  148.  
  149.    WinSendMsg(hwnd, CM_SETCNRINFO,
  150.                   &cnrinfo, MPFROMLONG( CMA_FLWINDOWATTR));
  151. }
  152.  
  153. //----------------------------------------------------------
  154. //  removeItem
  155. void TContainerWindow::removeItem(USHORT item)
  156. {
  157.    USHORT removeStyle = CMA_INVALIDATE | CMA_FREE;
  158.    PRECORDCORE start;
  159.    start = (PRECORDCORE)WinSendMsg(hwnd, CM_QUERYRECORD,
  160.                  NULL, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
  161.  
  162.  
  163.    WinSendMsg(hwnd, CM_REMOVERECORD, 
  164.                  start, MPFROM2SHORT(1, removeStyle));
  165. }
  166.  
  167. //----------------------------------------------------------
  168. //  removeAll
  169. void TContainerWindow::removeAll()
  170. {
  171.    USHORT removeStyle = CMA_INVALIDATE | CMA_FREE;
  172.  
  173.    WinSendMsg(hwnd, CM_REMOVERECORD, 
  174.                  NULL, MPFROM2SHORT(0, removeStyle));
  175. }    
  176.  
  177.