home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xlistbox.cpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  14KB  |  397 lines

  1. #include "xlistbox.h"
  2. #include "xstring.h"
  3. #include "xcombo.h"
  4.  
  5.  
  6. /*@ 
  7. @class XListBox
  8. @parent XControl
  9. @type overview
  10. @symbol _
  11. */
  12.  
  13.  
  14. /*@ 
  15. @class XComboBox
  16. @parent XListBox
  17. @type overview
  18. @symbol _
  19. */
  20.  
  21.  
  22. /*@ XComboBox::IsReadOnly(void) 
  23. @group misc
  24. @remarks Query if the entryfild is in readonly-mode.
  25. @returns BOOL result
  26. */
  27. BOOL XComboBox::IsReadOnly(void) const
  28. {
  29.     return (BOOL) WinSendMsg(winhandle, EM_QUERYREADONLY, 0, 0);
  30. }
  31.  
  32.  
  33. /*@ XComboBox::SetReadOnly(const BOOL readOnly) 
  34. @group misc
  35. @remarks Enable/disable readonly-mode.
  36. @parameters BOOL readOnly  TRUE=enable, FALSE=disable readonly-mose
  37. */
  38. void XComboBox::SetReadOnly(const BOOL readOnly) const
  39. {
  40.     WinSendMsg(winhandle, EM_SETREADONLY, MPFROMSHORT(readOnly), 0);
  41. }
  42.  
  43.  
  44. /*@ XComboBox::GetFirstChar(void) 
  45. @group misc
  46. @remarks Get the index of the first fisible charakter.
  47. @returns SHORT index
  48. */
  49. SHORT XComboBox::GetFirstChar(void) const
  50. {
  51.     return SHORT1FROMMR(WinSendMsg(winhandle, EM_QUERYFIRSTCHAR, 0, 0));
  52. }
  53.  
  54.  
  55. /*@ XComboBox::GetSel(SHORT & start, SHORT & end)
  56. @group clipboard functions
  57. @remarks Get the boundarys of the current selection.
  58. @parameters SHORT& start   starting point of selection<BR>
  59.             SHORT& end     end point
  60. */
  61. void XComboBox::GetSel(SHORT & start, SHORT & end)
  62. {
  63.     MRESULT res = WinSendMsg(winhandle, EM_QUERYSEL, 0, 0);
  64.  
  65.     start = SHORT1FROMMR(res);
  66.     end = SHORT2FROMMR(res);
  67. }
  68.  
  69.  
  70. /*@ XComboBox::SetLimit(const unsigned short len) 
  71. @group misc
  72. @remarks Set maximum number of charakters.
  73. @parameters USHORT length  maximum size
  74. */
  75. void XComboBox::SetLimit(const unsigned short len) const
  76. {
  77.     WinSendMsg(winhandle, EM_SETTEXTLIMIT, MPFROMSHORT(len), 0);
  78. }
  79.  
  80.  
  81. /*@ XComboBox::HasChanged(void) 
  82. @group misc
  83. @remarks Get if the content has changed.
  84. @returns BOOL result
  85. */
  86. BOOL XComboBox::HasChanged(void) const
  87. {
  88.     return SHORT1FROMMR(WinSendMsg(winhandle, EM_QUERYCHANGED, 0, 0));
  89. }
  90.  
  91.  
  92. /*@ XComboBox::EnableOverWrite(const BOOL overWrite) 
  93. @group misc
  94. @remarks Enables/disables overwrite-mode.
  95. @parameters BOOL overwrite    TRUE=overWrite, FALSE=disable overWrite
  96. */
  97. void XComboBox::EnableOverWrite(const BOOL overWrite) const
  98. {
  99.     WinSendMsg(winhandle, EM_SETINSERTMODE, MPFROMSHORT(overWrite), 0);
  100. }
  101.  
  102.  
  103. /*@ XComboBox :: XComboBox(const XWindow * owner, const XRect * rec, const USHORT id, const ULONG style, const char *font)
  104. @group constructors/destructors
  105. @remarks Construct a combobox
  106. @parameters    <t '°' c=2>
  107.                     °XWindow * theOwner        °The owning window.
  108.                °XRect * rectangle         °Position and size of the combobox. You must specify
  109.                                          the size the combobox should have when the listbox is
  110.                                          shown!
  111.                °USHORT ID                 °The ID of the combobox.
  112.                                          Default is zero.
  113.                °ULONG style               °The style of the window. Valid values are:
  114.                                                         <t '°' c=2>
  115.                                              °CB_SIMPLE        °listbox is always shown, the user
  116.                                                               can enter text
  117.                                              °CB_DROPDOWN      °listbox is activated with special
  118.                                                               button, the user can enter text
  119.                                              °CB_DROPDOWNLIST  °listbox is activated with special
  120.                                                               button, the user cannot enter text
  121.                                                         </t>
  122.                                                         Default is CB_DROPDOWN.    
  123.                     °char * font                      °font to use, e.g. "8.Helvetica"
  124.                     </t>
  125. */
  126. XComboBox :: XComboBox(const XWindow * owner, const XRect * rec, const USHORT id, const ULONG style, const char *font):XListBox(rec, style, owner, id, WC_COMBOBOX, font)
  127. {
  128. }
  129.  
  130.  
  131. /*@ XComboBox::IsListShowing(void) 
  132. @group misc
  133. @remarks Get if the list is displayed.
  134. @returns BOOL result
  135. */
  136. BOOL XComboBox::IsListShowing(void) const
  137. {
  138.     return (BOOL) WinSendMsg(winhandle, CBM_ISLISTSHOWING, 0, 0);
  139. }
  140.  
  141.  
  142. /*@ XComboBox::ShowList(const BOOL show) 
  143. @group misc
  144. @remarks Show/hide the list of the combo.
  145. @parameters BOOL show    TRUE=show, FALSE=hide the list
  146. */
  147. void XComboBox::ShowList(const BOOL show) const
  148. {
  149.     WinSendMsg(winhandle, CBM_SHOWLIST, MPFROMSHORT(show), 0);
  150. }
  151.  
  152.  
  153. /*@ XComboBox::Hilite(const BOOL hilite) 
  154. @group misc
  155. @remarks Enable/disable hiliting.
  156. @parameters BOOL hilite    TRUE=enable, FALSE=disable hiliting
  157. */
  158. void XComboBox::Hilite(const BOOL hilite) const
  159. {
  160.     WinSendMsg(winhandle, CBM_HILITE, MPFROMSHORT(hilite), 0);
  161. }
  162.  
  163.  
  164. /*@ XListBox::GetTopIndex(void) 
  165. @group misc
  166. @remarks Returns the index of the first visible entry.
  167. @returns SHORT index
  168. */
  169. SHORT XListBox::GetTopIndex(void) const
  170. {
  171.     return SHORT1FROMMR(WinSendMsg(winhandle, LM_QUERYTOPINDEX, 0, 0));
  172. }
  173.  
  174.  
  175. /*@ XListBox::SetTopIndex(const SHORT index) 
  176. @group misc
  177. @remarks Set the first visible entry.
  178. @parameters SHORT index    index of the first visible entry
  179. */
  180. void XListBox::SetTopIndex(const SHORT index) const
  181. {
  182.     WinSendMsg(winhandle, LM_SETTOPINDEX, MPFROMSHORT(index), 0);
  183. }
  184.  
  185.  
  186. /*@ XListBox::SetItemHeight(const SHORT height) 
  187. @group misc
  188. @remarks Set items height
  189. @parameters SHORT height
  190. */
  191. void XListBox::SetItemHeight(const SHORT height) const
  192. {
  193.     WinSendMsg(winhandle, LM_SETITEMHEIGHT, MPFROMSHORT(height), 0);
  194. }
  195.  
  196.  
  197. /*@ XListBox::SetItemWidth(const SHORT width) 
  198. @group misc
  199. @remarks Set items width
  200. @parameters SHORT width
  201. */
  202. void XListBox::SetItemWidth(const SHORT width) const
  203. {
  204.     WinSendMsg(winhandle, LM_SETITEMWIDTH, MPFROMSHORT(width), 0);
  205. }
  206.  
  207.  
  208. XListBox :: XListBox(const XRect * rec, const ULONG style, const XWindow * owner, const USHORT id, const PSZ className, const char *font):XControl(rec, style, owner, "", className, id, font)
  209. {
  210. }
  211.  
  212.  
  213. /*@ XListBox :: XListBox(const XWindow * owner, const XRect * rec, const USHORT id, const ULONG style, const char *font)
  214. @group constructors/destructors
  215. @remarks Construct a listbox
  216. @parameters    <t '°' c=2>
  217.                     °XWindow * theOwner        °The owning window
  218.                °XRect * rectangle         °Position and size of the listbox
  219.                °USHORT ID                 °The ID of the window.
  220.                                          Default is zero.
  221.                °ULONG style               °The style of the window. Valid values are:
  222.                                                         <t '°' c=2>
  223.                                              °LS_SCROLL    °the listbox gets a horizontal scrollbar
  224.                                              °LS_MULTI     °one ore more items can be selected
  225.                                              °LS_EXTENDED  °extended selection is enabled (should be
  226.                                                           used if LS_MULTI is specified).
  227.                                                         </t>
  228.                                          The values can be or-ed.
  229.                     °char * font                      °font to use, e.g. "8.Helvetica"
  230.                     </t>
  231. */
  232. XListBox :: XListBox(const XWindow * owner, const XRect * rec, const USHORT id, const ULONG style, const char *font):XControl(rec, style, owner, "", WC_LISTBOX, id, font)
  233. {
  234. }
  235.  
  236.  
  237. /*@ XListBox::InsertItem(const char *item, const SHORT pos) 
  238. @group inserting/removing
  239. @remarks Adds a an item to the listbox
  240. @parameters    <t '°' c=2>
  241.                     °char * theTitle           °title of the item
  242.                °SHORT position            °where to insert. You can specify the zero-based index,
  243.                                          LS_LAST (the item is inserted at the end of the list),
  244.                                          LS_ASCENDING (the items are sorted ascending) or
  245.                                          LS_DESCENDING (items are sorted descending)
  246.                                       Default is LS_LAST.
  247.                </t>
  248. @returns       SHORT                     the zero-based index of the item
  249. */
  250. SHORT XListBox::InsertItem(const char *item, const SHORT pos) const
  251. {
  252.     return SHORT1FROMMR(WinSendMsg(winhandle, LM_INSERTITEM, MPFROMSHORT(pos), (PSZ) item));
  253. }
  254.  
  255.  
  256. /*@ XListBox::GetCount(void) 
  257. @group misc
  258. @remarks Returns the count of items.
  259. @returns       SHORT                      the count of items in the listbox
  260. */
  261. SHORT XListBox::GetCount(void) const
  262. {
  263.     return SHORT1FROMMR(WinSendMsg(winhandle, LM_QUERYITEMCOUNT, 0, 0));
  264. }
  265.  
  266.  
  267. /*@ XListBox::GetItemHandle(const SHORT pos) 
  268. @group using handles
  269. @remarks Gets a handle of an item.
  270. @parameters     SHORT theItem             Zero-based index of the item
  271. @returns       LONG                      the handle of the item
  272. */
  273. LONG XListBox::GetItemHandle(const SHORT pos) const
  274. {
  275.     return (LONG) WinSendMsg(winhandle, LM_QUERYITEMHANDLE, MPFROMSHORT(pos), 0);
  276. }
  277.  
  278.  
  279. /*@ XListBox::GetItemText(const SHORT pos, XString * buffer)
  280. @group text input/output
  281. @remarks Get the text of an item
  282. @parameters     SHORT theItem             Zero-based index of the item<BR>
  283.                XString * buffer          buffer which will hold the text
  284. @returns       SHORT                     length of the text
  285. */
  286. SHORT XListBox::GetItemText(const SHORT pos, XString * buffer)
  287. {
  288.     SHORT r = SHORT1FROMMR(WinSendMsg(winhandle, LM_QUERYITEMTEXTLENGTH, MPFROMSHORT(pos), 0));
  289.  
  290.     WinSendMsg(winhandle, LM_QUERYITEMTEXT, MPFROM2SHORT(pos, r + 1), buffer->GetBuffer(r + 1));
  291.     buffer->ReleaseBuffer(r);
  292.     return r;
  293. }
  294.  
  295.  
  296. /*@ XListBox::GetSelection(const SHORT start) 
  297. @group set/query selection
  298. @remarks Returns the zero-based index of the first selected item
  299. which is found after the specified item.
  300. @parameters    SHORT searchAfterItem     Zero-based index of the item behind which
  301.                                          the search starts (defaultt is LS_FIRST)
  302. @returns       SHORT                     Zero-based index of the item found. If
  303.                                          no item is found return is LS_NONE
  304. */
  305. SHORT XListBox::GetSelection(const SHORT start) const
  306. {
  307.     return (BOOL) WinSendMsg(winhandle, LM_QUERYSELECTION, MPFROMSHORT(start), 0);
  308. }
  309.  
  310.  
  311. /*@ XListBox::RemoveAll(void) 
  312. @group inserting/removing
  313. @remarks Removes all items from a listbox.
  314. @returns       BOOL result
  315. */
  316. BOOL XListBox::RemoveAll(void) const
  317. {
  318.     SHORT i = InsertItem("");
  319.  
  320.     SelectItem(i);
  321.     return SHORT1FROMMR(WinSendMsg(winhandle, LM_DELETEALL, 0, 0));
  322. }
  323.  
  324.  
  325. /*@ XListBox::RemoveItem(const SHORT pos) 
  326. @group inserting/removing
  327. @remarks Removes an item
  328. @parameters     SHORT theItem             Zero-based index of the item to remove
  329. */
  330. void XListBox::RemoveItem(const SHORT pos) const
  331. {
  332.     WinSendMsg(winhandle, LM_DELETEITEM, MPFROMSHORT(pos), 0);
  333. }
  334.  
  335.  
  336. /*@ XListBox::SearchString(const char *p, const SHORT start, const SHORT match) 
  337. @group misc
  338. @remarks Search a string in the listbox
  339. @parameters     <t '°' c=2>
  340.                     °char * theText            °text to be searched
  341.                °SHORT startPosition       °Zero-based index of item where to start the search
  342.                °SHORT matchCode           °How to search. Valid values are:
  343.                                                         <t '°' c=2>
  344.                                               °LS_CASESENSITIVE  °search casesensitive
  345.                                               °LS_PREFIX         °search-string must be at the beginning
  346.                                                                 of the items title
  347.                                               °LS_SUBSTRING      °search-string can be in the middle of
  348.                                                                 the items title
  349.                                                         </t>
  350.                                          LS_CASESSENSITIVE can be or-ed with one of the other defines.
  351.                     </t>
  352. @returns       SHORT                     Zero-based index of the item which is found. If no item
  353.                                          is found, LS_NONE is returned.
  354. */
  355. SHORT XListBox::SearchString(const char *p, const SHORT start, const SHORT match) const
  356. {
  357.     return SHORT1FROMMR(WinSendMsg(winhandle, LM_SEARCHSTRING, MPFROM2SHORT(match, start), MPFROMP(p)));
  358. }
  359.  
  360.  
  361. /*@ XListBox::SelectItem(const SHORT pos, const BOOL select) 
  362. @group set/query selection
  363. @remarks Select an item
  364. @parameters     SHORT theItem             Zero-based index of the item to select
  365. */
  366. BOOL XListBox::SelectItem(const SHORT pos, const BOOL select) const
  367. {
  368.     return (BOOL) WinSendMsg(winhandle, LM_SELECTITEM, MPFROMSHORT(pos), MPFROMSHORT(select));
  369. }
  370.  
  371.  
  372. /*@ XListBox::SetItemHandle(const SHORT pos, const LONG handle) 
  373. @group using handles
  374. @remarks Adds a handle to an item
  375. @parameters    SHORT theItem             Zero-based index of the item which
  376.                                          will get the handle<BR>
  377.                LONG theHandle            the handle which is add to the item
  378. @returns       BOOL                      success
  379. */
  380. BOOL XListBox::SetItemHandle(const SHORT pos, const LONG handle) const
  381. {
  382.     return (BOOL) WinSendMsg(winhandle, LM_SETITEMHANDLE, MPFROMSHORT(pos), (MPARAM) handle);
  383. }
  384.  
  385.  
  386. /*@ XListBox::SetItemText(const SHORT pos, const char *p) 
  387. @group text input/output
  388. @remarks Set the text of an item.
  389. @parameters    SHORT theItem             Zero-based index of the item<BR>
  390.                char * theText            the new text
  391. @returns       BOOL                      success
  392. */
  393. BOOL XListBox::SetItemText(const SHORT pos, const char *p) const
  394. {
  395.     return SHORT1FROMMR(WinSendMsg(winhandle, LM_SETITEMTEXT, MPFROMSHORT(pos), MPFROMP(p)));
  396. }
  397.