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

  1. /****************************************/
  2. /*    Developer Helper Object Set       */
  3. /*  (C) 1994-95 Thomas E. Bednarz, Jr.  */
  4. /*     All rights reserved              */
  5. /***************************************/
  6.  
  7. /* $Id: listbox.cc 1.2 1995/08/13 03:21:12 teb Exp $ */
  8.  
  9.  
  10. #include"listbox.h"
  11.  
  12. //----------------------------------------------------------------
  13. //  TListBase
  14. TListBase:: TListBase(TWinBase *parent, ULONG resource):
  15.    TControl(parent, resource)
  16. {
  17.  
  18. }
  19.  
  20.  
  21.  
  22. //----------------------------------------------------------------
  23. //  ~TListBase
  24. TListBase:: ~TListBase()
  25. {
  26.  
  27. }
  28.  
  29.  
  30. //-------------------------------------------------------------------
  31. //   getClassName
  32. const char *TListBase::getClassName()
  33. {
  34.    return "TListBase";
  35. }
  36.  
  37.  
  38.  
  39. //-----------------------------------------------------------------
  40. //   addItem
  41. void TListBase::addItemAt(char *item, SHORT at)
  42. {
  43.    if(hwndControl)
  44.       WinInsertLboxItem(hwndControl, at, (PSZ)item);
  45. }
  46.  
  47.  
  48. //-----------------------------------------------------------------
  49. //  deleteItem
  50. void TListBase::deleteItemAt (SHORT itemNo)
  51. {
  52.    WinSendMsg(hwndControl, LM_DELETEITEM, 
  53.               MPFROMSHORT(itemNo), NULL);
  54. }
  55.  
  56.  
  57. //-----------------------------------------------------------------
  58. // addItemFirst
  59. void TListBase::addItemFirst(char *item)
  60. {
  61.    addItemAt(item, 0);
  62. }
  63.  
  64. //-----------------------------------------------------------------
  65. //   addItemLast
  66. void TListBase::addItemLast(char *item)
  67. {
  68.    if (hwndControl)
  69.       addItemAt(item, getNumItems());
  70. }
  71.  
  72. //-----------------------------------------------------------------
  73. //   deleteAll
  74. void TListBase::deleteAll()
  75. {
  76.    if (hwndControl)
  77.    {
  78.       short num = getNumItems();
  79.       while (num >=0)
  80.       {
  81.         WinDeleteLboxItem(hwndControl, 0);
  82.         num--;
  83.       }
  84.    }
  85. }
  86.  
  87.  
  88. //-----------------------------------------------------------------
  89. //   getNumItems
  90. SHORT TListBase::getNumItems()
  91. {
  92.    return WinQueryLboxCount(hwndControl);
  93. }
  94.  
  95. //-----------------------------------------------------------------
  96. //   setItemText
  97. void TListBase::setItemText (char *text, SHORT item)
  98. {
  99.    WinSetLboxItemText(hwndControl,  item, (PSZ)text);
  100. }
  101.  
  102.  
  103. //-----------------------------------------------------------------
  104. //   getSelectedItem
  105. SHORT TListBase::getSelectedItem()
  106. {
  107.    return WinQueryLboxSelectedItem(hwndControl);
  108. }
  109.  
  110.  
  111. //-----------------------------------------------------------------
  112. //   getSelectedItemLength
  113. ULONG TListBase::getSelectedItemLength()
  114. {
  115.    return (ULONG)WinSendMsg(hwndControl, 
  116.                  LM_QUERYITEMTEXTLENGTH,
  117.                  ((MPARAM)(getSelectedItem())), 
  118.                  (MPARAM)0);
  119.  
  120.  
  121.  
  122. //-----------------------------------------------------------------
  123. //   getItemLength
  124. ULONG TListBase::getItemLength(SHORT at)
  125. {
  126.    return (ULONG)WinSendMsg(hwndControl, 
  127.                 LM_QUERYITEMTEXTLENGTH,
  128.                 ((MPARAM)(at)), (MPARAM)0);
  129. }
  130.  
  131.  
  132.  
  133. //-----------------------------------------------------------------
  134. // getItemAt
  135. char *TListBase::getItemAt(SHORT at)
  136. {
  137.    char *buf = NULL;
  138.    ULONG size =  getItemLength(at);
  139.    buf = new char[size+1];
  140.    WinQueryLboxItemText(hwndControl, at, buf, size);
  141.    return buf;
  142. }
  143.  
  144.  
  145.  
  146.  
  147. //-------------------------------------------------------------------
  148. //   TListBox
  149. TListBox::TListBox(TWinBase *parent, ULONG resource):
  150.    TListBase(parent, resource)
  151. {
  152.  
  153. }
  154.  
  155.  
  156. //-------------------------------------------------------------------
  157. //   TListBox
  158. TListBox::TListBox(TWinBase *parent, ULONG id, LONG xPos, LONG yPos,
  159.                   LONG xWidth, LONG yHeight, BOOL adjustPos):
  160.    TListBase(parent, 0)
  161. {
  162.    ULONG style= WS_VISIBLE;
  163.    if (!adjustPos)
  164.       style |= LS_NOADJUSTPOS;
  165.  
  166.    register int i;
  167.    fResource = id;
  168.    hwndControl = WinCreateWindow(
  169.                 fParent->getHWND(),
  170.                 WC_LISTBOX,
  171.                 (PSZ)NULL,
  172.                 style,
  173.                 xPos, yPos,xWidth, yHeight,
  174.                 fParent->getHWND(),
  175.                 HWND_TOP,
  176.                 fResource,
  177.                 NULL, NULL);
  178. }
  179.  
  180.  
  181.  
  182. //-----------------------------------------------------------------
  183. //   TListBox
  184. TListBox::TListBox(TWinBase *parent, ULONG id, LONG xPos, 
  185.                    LONG yPos, LONG xWidth, LONG yHeight, 
  186.                    BOOL adjustPos, char **items, LONG numItems):
  187.    TListBase(parent, 0)
  188. {
  189.    ULONG style= WS_VISIBLE;
  190.    if (!adjustPos)
  191.       style |= LS_NOADJUSTPOS;
  192.  
  193.    register int i;
  194.    fResource = id;
  195.    hwndControl = WinCreateWindow(
  196.                 fParent->getHWND(),
  197.                 WC_LISTBOX,
  198.                 (PSZ)NULL,
  199.                 style,
  200.                 xPos, yPos,xWidth, yHeight,
  201.                 fParent->getHWND(),
  202.                 HWND_TOP,
  203.                 fResource,
  204.                 NULL, NULL);
  205.  
  206.    if (hwndControl != (HWND)NULL)
  207.    {
  208.       for (i=0; i<numItems; i++)
  209.          addItemAt(items[i],i);
  210.    }
  211.  
  212. }
  213.  
  214.  
  215.  
  216. //-------------------------------------------------------------------
  217. //   ~TlistBox
  218. TListBox::~TListBox()
  219. {
  220.  
  221. }
  222.  
  223. //-------------------------------------------------------------------
  224. //   getClassName
  225. const char *TListBox::getClassName()
  226. {
  227.    return "TListBox";
  228. }
  229.  
  230.  
  231. //-------------------------------------------------------------------
  232. //   TComboBox
  233. TComboBox::TComboBox(TWinBase *parent, ULONG resource):
  234.    TListBase(parent, resource)
  235. {
  236.  
  237. }
  238.  
  239.  
  240. //-------------------------------------------------------------------
  241. //   TComboBox
  242. TComboBox::TComboBox(TWinBase *parent, ULONG id, LONG xPos, LONG yPos,
  243.                   LONG xWidth, LONG yHeight, BOOL adjustPos):
  244.    TListBase(parent, 0)
  245. {
  246.    ULONG style= WS_VISIBLE | CBS_SIMPLE; 
  247.    if (!adjustPos)
  248.       style |= LS_NOADJUSTPOS;
  249.  
  250.    register int i;
  251.    fResource = id;
  252.    hwndControl = WinCreateWindow(
  253.                 fParent->getHWND(),
  254.                 WC_COMBOBOX,
  255.                 (PSZ)NULL,
  256.                 0, //style,
  257.                 xPos, yPos,xWidth, yHeight,
  258.                 fParent->getHWND(),
  259.                 HWND_TOP,
  260.                 fResource,
  261.                 NULL, NULL);
  262. }
  263.  
  264.  
  265. //-----------------------------------------------------------------
  266. //   TComboBox
  267. TComboBox::TComboBox(TWinBase *parent, ULONG id, LONG xPos, 
  268.                    LONG yPos, LONG xWidth, LONG yHeight, 
  269.                    BOOL adjustPos, char **items, LONG numItems):
  270.    TListBase(parent, 0)
  271. {
  272.    ULONG style= WS_VISIBLE | CBS_SIMPLE;
  273.    if (!adjustPos)
  274.       style |= LS_NOADJUSTPOS;
  275.  
  276.    register int i;
  277.    fResource = id;
  278.    hwndControl = WinCreateWindow(
  279.                 fParent->getHWND(),
  280.                 WC_COMBOBOX,
  281.                 (PSZ)NULL,
  282.                 0, //style,
  283.                 xPos, yPos,xWidth, yHeight,
  284.                 fParent->getHWND(),
  285.                 HWND_TOP,
  286.                 fResource,
  287.                 NULL, NULL);
  288.  
  289.    if (hwndControl != (HWND)NULL)
  290.    {
  291.       for (i=0; i<numItems; i++)
  292.          addItemAt(items[i],i);
  293.    }
  294.  
  295. }
  296.  
  297.  
  298.  
  299. //-------------------------------------------------------------------
  300. //   ~TComboBox
  301. TComboBox::~TComboBox()
  302. {
  303.  
  304. }
  305.  
  306. //-------------------------------------------------------------------
  307. //   getClassName
  308. const char *TComboBox::getClassName()
  309. {
  310.    return "TComboBox";
  311. }
  312.  
  313.  
  314. //-------------------------------------------------------------------
  315. //   TPullDownList
  316. TPullDownList::TPullDownList(TWinBase *parent, ULONG resource):
  317.    TListBase(parent, resource)
  318. {
  319.  
  320. }
  321.  
  322.  
  323. //-------------------------------------------------------------------
  324. //   TPullDownList
  325. TPullDownList::TPullDownList(TWinBase *parent, ULONG id, LONG xPos, LONG yPos,
  326.                   LONG xWidth, LONG yHeight, BOOL adjustPos):
  327.    TListBase(parent, 0)
  328. {
  329.    ULONG style= WS_VISIBLE | CBS_DROPDOWNLIST;
  330.    if (!adjustPos)
  331.       style |= LS_NOADJUSTPOS;
  332.  
  333.    register int i;
  334.    fResource = id;
  335.    hwndControl = WinCreateWindow(
  336.                 fParent->getHWND(),
  337.                 WC_COMBOBOX,
  338.                 (PSZ)NULL,
  339.                 style,
  340.                 xPos, yPos,xWidth, yHeight,
  341.                 fParent->getHWND(),
  342.                 HWND_TOP,
  343.                 fResource,
  344.                 NULL, NULL);
  345. }
  346.  
  347.  
  348.  
  349. //-----------------------------------------------------------------
  350. //   TPullDownList
  351. TPullDownList::TPullDownList(TWinBase *parent, ULONG id, LONG xPos, 
  352.                    LONG yPos, LONG xWidth, LONG yHeight, 
  353.                    BOOL adjustPos, char **items, LONG numItems):
  354.    TListBase(parent, 0)
  355. {
  356.    ULONG style= WS_VISIBLE | CBS_DROPDOWNLIST;
  357.    if (!adjustPos)
  358.       style |= LS_NOADJUSTPOS;
  359.  
  360.    register int i;
  361.    fResource = id;
  362.    hwndControl = WinCreateWindow(
  363.                 fParent->getHWND(),
  364.                 WC_COMBOBOX,
  365.                 (PSZ)NULL,
  366.                 style,
  367.                 xPos, yPos,xWidth, yHeight,
  368.                 fParent->getHWND(),
  369.                 HWND_TOP,
  370.                 fResource,
  371.                 NULL, NULL);
  372.  
  373.    if (hwndControl != (HWND)NULL)
  374.    {
  375.       for (i=0; i<numItems; i++)
  376.          addItemAt(items[i],i);
  377.    }
  378.  
  379. }
  380.  
  381.  
  382.  
  383. //-------------------------------------------------------------------
  384. //   ~TPullDownList
  385. TPullDownList::~TPullDownList()
  386. {
  387.  
  388. }
  389.  
  390. //-------------------------------------------------------------------
  391. //   getClassName
  392. const char *TPullDownList::getClassName()
  393. {
  394.    return "TPullDownList";
  395. }
  396.  
  397.  
  398. //-------------------------------------------------------------------
  399. //   TPullDown
  400. TPullDown::TPullDown(TWinBase *parent, ULONG resource):
  401.    TListBase(parent, resource)
  402. {
  403.  
  404. }
  405.  
  406.  
  407. //-------------------------------------------------------------------
  408. //   TPullDown
  409. TPullDown::TPullDown(TWinBase *parent, ULONG id, LONG xPos, LONG yPos,
  410.                   LONG xWidth, LONG yHeight, BOOL adjustPos):
  411.    TListBase(parent, 0)
  412. {
  413.    ULONG style= WS_VISIBLE | CBS_DROPDOWN; 
  414.    if (!adjustPos)
  415.       style |= LS_NOADJUSTPOS;
  416.  
  417.    register int i;
  418.    fResource = id;
  419.    hwndControl = WinCreateWindow(
  420.                 fParent->getHWND(),
  421.                 WC_COMBOBOX,
  422.                 (PSZ)NULL,
  423.                 style,
  424.                 xPos, yPos,xWidth, yHeight,
  425.                 fParent->getHWND(),
  426.                 HWND_TOP,
  427.                 fResource,
  428.                 NULL, NULL);
  429. }
  430.  
  431.  
  432.  
  433. //-----------------------------------------------------------------
  434. //   TPullDown
  435. TPullDown::TPullDown(TWinBase *parent, ULONG id, LONG xPos, 
  436.                    LONG yPos, LONG xWidth, LONG yHeight, 
  437.                    BOOL adjustPos, char **items, LONG numItems):
  438.    TListBase(parent, 0)
  439. {
  440.    ULONG style= WS_VISIBLE | CBS_DROPDOWN;
  441.    if (!adjustPos)
  442.       style |= LS_NOADJUSTPOS;
  443.  
  444.    register int i;
  445.    fResource = id;
  446.    hwndControl = WinCreateWindow(
  447.                 fParent->getHWND(),
  448.                 WC_COMBOBOX,
  449.                 (PSZ)NULL,
  450.                 style,
  451.                 xPos, yPos,xWidth, yHeight,
  452.                 fParent->getHWND(),
  453.                 HWND_TOP,
  454.                 fResource,
  455.                 NULL, NULL);
  456.  
  457.    if (hwndControl != (HWND)NULL)
  458.    {
  459.       for (i=0; i<numItems; i++)
  460.          addItemAt(items[i],i);
  461.    }
  462.  
  463. }
  464.  
  465.  
  466.  
  467. //-------------------------------------------------------------------
  468. //   ~TPullDown
  469. TPullDown::~TPullDown()
  470. {
  471.  
  472. }
  473.  
  474. //-------------------------------------------------------------------
  475. //   getClassName
  476. const char *TPullDown::getClassName()
  477. {
  478.    return "TPullDown";
  479. }
  480.  
  481.  
  482.  
  483.