home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dho.zip / DHO / SRC / SOURCE.ZIP / combobox.cc < prev    next >
C/C++ Source or Header  |  1995-08-27  |  5KB  |  187 lines

  1. /****************************************/
  2. /*    Developer Helper Object Set       */
  3. /*  (C) 1994-95 Thomas E. Bednarz, Jr.  */
  4. /*     All rights reserved              */
  5. /***************************************/
  6.  
  7. /* $Id: combobox.cc 1.2 1995/08/13 03:21:12 teb Exp $ */
  8.  
  9.  
  10. #include"combobox.h"
  11.  
  12.  
  13. //-------------------------------------------------------------------
  14. //   TComboBox
  15. TComboBox::TComboBox(TWinBase *parent, ULONG resource):
  16.    TControl(parent, resource)
  17. {
  18.  
  19. }
  20.  
  21. //-------------------------------------------------------------------
  22. //   TComboBox
  23. TComboBox::TComboBox(TWinBase *parent, ULONG id, LONG xPos, LONG yPos,
  24.                   LONG xWidth, LONG yHeight, BOOL adjustPos):
  25.    TControl(parent, 0)
  26. {
  27.    ULONG style= WS_VISIBLE;
  28.    if (!adjustPos)
  29.       style |= LS_NOADJUSTPOS;
  30.  
  31.    register int i;
  32.    fResource = id;
  33.    hwndControl = WinCreateWindow(
  34.                 fParent->getHWND(),
  35.                 WC_COMBOBOX,
  36.                 (PSZ)NULL,
  37.                 style,
  38.                 xPos, yPos,xWidth, yHeight,
  39.                 fParent->getHWND(),
  40.                 HWND_TOP,
  41.                 fResource,
  42.                 NULL, NULL);
  43. }
  44.  
  45. //-------------------------------------------------------------------
  46. //   TComboBox
  47. TComboBox::TComboBox(TWinBase *parent, ULONG id, LONG xPos, LONG yPos,
  48.                   LONG xWidth, LONG yHeight, BOOL adjustPos, char **items, LONG numItems):
  49.    TControl(parent, 0)
  50. {
  51.    ULONG style= WS_VISIBLE;
  52.    if (!adjustPos)
  53.       style |= LS_NOADJUSTPOS;
  54.  
  55.    register int i;
  56.    fResource = id;
  57.    hwndControl = WinCreateWindow(
  58.                 fParent->getHWND(),
  59.                 WC_LISTBOX,
  60.                 (PSZ)NULL,
  61.                 style,
  62.                 xPos, yPos,xWidth, yHeight,
  63.                 fParent->getHWND(),
  64.                 HWND_TOP,
  65.                 fResource,
  66.                 NULL, NULL);
  67.  
  68.    if (hwndControl!=NULL)
  69.    {
  70.       for (i=0; i<numItems; i++)
  71.          addItemAt(items[i],i);
  72.    }
  73.  
  74. }
  75.  
  76.  
  77.  
  78. //-------------------------------------------------------------------
  79. //   ~TComboBox
  80. TComboBox::~TComboBox()
  81. {
  82.  
  83. }
  84.  
  85.  
  86. //-------------------------------------------------------------------
  87. //   getClassName
  88. const char *TComboBox::getClassName()
  89. {
  90.    return "TComboBox";
  91. }
  92.  
  93.  
  94. //-------------------------------------------------------------------
  95. //   addItem
  96. void TComboBox::addItemAt(char *item, SHORT at)
  97. {
  98.    WinInsertLboxItem(hwndControl, at, (PSZ)item);
  99. }
  100.  
  101.  
  102. //-------------------------------------------------------------------
  103. //   deleteItem
  104. void TComboBox::deleteItemAt (SHORT itemNo)
  105. {
  106.    short remaining;
  107.       remaining = WinDeleteLboxItem(hwndControl, itemNo);
  108. }
  109.  
  110.  
  111. //-------------------------------------------------------------------
  112. //   addItemFirst
  113. void TComboBox::addItemFirst(char *item)
  114. {
  115.    addItemAt(item, 0);
  116. }
  117.  
  118. //-------------------------------------------------------------------
  119. //   addItemLast
  120. void TComboBox::addItemLast(char *item)
  121. {
  122.    addItemAt(item, getNumItems());
  123. }
  124.  
  125. //-------------------------------------------------------------------
  126. //   deleteAll
  127. void TComboBox::deleteAll()
  128. {
  129.    short num = getNumItems();
  130.    while (num >=0)
  131.    {
  132.      WinDeleteLboxItem(hwndControl, 0);
  133.      num--;
  134.    }
  135. }
  136.  
  137.  
  138. //-------------------------------------------------------------------
  139. //   getNumItems
  140. SHORT TComboBox::getNumItems()
  141. {
  142.    return WinQueryLboxCount(hwndControl);
  143. }
  144.  
  145. //-------------------------------------------------------------------
  146. //   setItemText
  147. void TComboBox::setItemText (char *text, SHORT item)
  148. {
  149.    WinSetLboxItemText(hwndControl,  item, (PSZ)text);
  150. }
  151.  
  152.  
  153. //-------------------------------------------------------------------
  154. //   
  155. SHORT TComboBox::getSelectedItem()
  156. {
  157.    return WinQueryLboxSelectedItem(hwndControl);
  158. }
  159.  
  160.  
  161. //-------------------------------------------------------------------
  162. //   
  163. ULONG TComboBox::getSelectedItemLength()
  164. {
  165.    return (ULONG)WinSendMsg(hwndControl, LM_QUERYITEMTEXTLENGTH,((MPARAM)(getSelectedItem())), (MPARAM)0);
  166.  
  167.  
  168. //-------------------------------------------------------------------
  169. //   
  170. ULONG TComboBox::getItemLength(SHORT at)
  171. {
  172.    return (ULONG)WinSendMsg(hwndControl, LM_QUERYITEMTEXTLENGTH,((MPARAM)(at)), (MPARAM)0);
  173. }
  174.  
  175.  
  176. //-------------------------------------------------------------------
  177. // 
  178. char *TComboBox::getItemAt(SHORT at)
  179. {
  180.    char *buf = NULL;
  181.    ULONG size =  getItemLength(at);
  182.    buf = new char[size+1];
  183.    WinQueryLboxItemText(hwndControl, at, buf, size);
  184.    return buf;
  185. }
  186.