Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

368 lines
14 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. bltlc.hxx
  7. BLT list control classes: definitions
  8. FILE HISTORY:
  9. RustanL 20-Nov-1990 Created
  10. RustanL 22-Feb-1991 Modified LC hierarchy
  11. RustanL 21-Mar-1991 Folded in code review changes from
  12. CR on 20-Mar-1991 attended by
  13. JimH, GregJ, Hui-LiCh, RustanL.
  14. beng 14-May-1991 Clients depend on blt.hxx
  15. terryk 25-Jul-1991 Add SetItemData, QuerySelCount and
  16. QuerySelItems to LIST_CONTROL class
  17. Add ChangeSel, SetTopIndex
  18. beng 21-Aug-1991 Removed LC_NEW_SEARCH and LC_CURRENT_ITEM
  19. beng 22-Sep-1991 Exiled device combos to devcb.hxx
  20. terryk 22-Mar-1992 Added Insert Item
  21. */
  22. #ifndef _BLT_HXX_
  23. #error "Don't include this file directly; instead, include it through blt.hxx"
  24. #endif // _BLT_HXX_
  25. #ifndef _BLTLC_HXX_
  26. #define _BLTLC_HXX_
  27. #include "string.hxx"
  28. /*************************************************************************
  29. NAME: LIST_CONTROL
  30. SYNOPSIS: base class for BLT list controls (combos and listboxes)
  31. INTERFACE:
  32. LIST_CONTROL() constructor
  33. QueryCount() returns the number of items
  34. AddItemData() add the data item to the listbox
  35. SetItemData() set the item data.
  36. InsertItemData() insert the data item in the listbox
  37. SelectItem() selects an item
  38. SelectItems() selects several items
  39. RemoveSelection() deselects all selected items
  40. DeleteItem() deletes an item
  41. DeleteAllItems() deletes all items (empties the list
  42. control)
  43. QueryCurrentItem() returns the index of the first currently
  44. selected item
  45. QuerySelCount() returns the number of selected items in
  46. the list control
  47. QuerySelItems() return an array of selected items indices
  48. QueryItemHeight() calculate the height of any item in the
  49. listbox. Use default parameter if this is
  50. a fixed-height listbox.
  51. IsItemSelected() returns whether the given item is selected
  52. SetTopIndex() set the top visible item index
  53. QueryTopIndex() returns the index of the topmost visible
  54. SetCaretIndex() set the caret index
  55. QueryCaretIndex() returns the caret index
  56. PARENT: CONTROL_WINDOW
  57. CAVEATS:
  58. QueryCurrentItem was designed for single-selection lists.
  59. Under multiple-select, it returns the first selected item.
  60. Clients should never pass the list control a negative number
  61. as an index.
  62. Saving selection is not implemented for multiple-select.
  63. Set/QueryTopIndex only works on listboxes. (sloppy design)
  64. NOTES:
  65. Although the intersection of functionality of the Windows
  66. combobox and listbox is quite large, there are differences
  67. between the actual messages sent to each. To hide this ugly
  68. artifact, BLT keeps track of whether the list control is a
  69. combo or a listbox. Then, the methods in this hierarchy can
  70. choose messages based on this information.
  71. CODEWORK - factor out listbox-only function into subclass.
  72. If the listbox is multi-select, we attempt to save the entire
  73. selection in _piSavedMultSel. In this case, _iSavedSelection is
  74. used as the count of items in _piSavedMultSel, instead of as an
  75. item index. If this pointer is NULL, then SaveValue could not
  76. allocate enough memory, and the selection is lost.
  77. HISTORY:
  78. RustanL 20-Nov-1990 Created
  79. RustanL 22-Feb-1991 Modified LC hierarchy
  80. RustanL 21-Mar-1991 Folded in code review changes from
  81. CR on 20-Mar-1991 attended by
  82. JimH, GregJ, Hui-LiCh, RustanL.
  83. beng 16-May-1991 Added app-window constructor
  84. terryk 25-Jul-1991 Add the following:
  85. SetItemData()
  86. QuerySelCount()
  87. QuerySelItems()
  88. SetTopIndex()
  89. ChangeSel()
  90. beng 31-Jul-1991 Renamed QMessageInfo to QEventEffects
  91. rustanl 12-Aug-1991 Added IsMultSel
  92. rustanl 13-Aug-1991 Extended several methods to work
  93. with both single and multiple select
  94. list controls. Removed ChangeSel
  95. and instead added a parameter to
  96. SelectItem.
  97. beng 22-Aug-1991 Added QueryTopIndex
  98. beng 04-Oct-1991 Win32 conversion
  99. kevinl 23-Oct-1991 Added InsertItemData
  100. jonn 09-Sep-1993 Moved fns from SET_CONTROL_LISTBOX to LISTBOX
  101. jonn 15-Sep-1993 Added GetCaretIndex and SetCaretIndex
  102. **************************************************************************/
  103. DLL_CLASS LIST_CONTROL : public CONTROL_WINDOW
  104. {
  105. private:
  106. BOOL _fCombo; // is list control a combobox?
  107. INT _iSavedSelection; // saves selection for magic groups.
  108. INT * _piSavedMultSel; // saves selection for multiselect listbox
  109. // in this case, _iSavedSelection is a count
  110. // if NULL, selection was not successfully saved
  111. protected:
  112. LIST_CONTROL( OWNER_WINDOW * powin, CID cid, BOOL fCombo );
  113. LIST_CONTROL( OWNER_WINDOW * powin, CID cid, BOOL fCombo,
  114. XYPOINT xy, XYDIMENSION dxy,
  115. ULONG flStyle, const TCHAR * pszClassName );
  116. ~LIST_CONTROL();
  117. INT AddItemData( VOID * pv );
  118. INT SetItemData( INT iIndex, VOID * pv );
  119. INT InsertItemData( INT i, VOID *pv );
  120. /* Replacement of CONTROL_VALUE virtuals
  121. */
  122. virtual VOID SaveValue( BOOL fInvisible = TRUE );
  123. virtual VOID RestoreValue( BOOL fInvisible = TRUE );
  124. virtual UINT QueryEventEffects( const CONTROL_EVENT & e );
  125. public:
  126. INT QueryCount() const;
  127. VOID SelectItem( INT i, BOOL fSelect = TRUE );
  128. VOID SelectItems( INT * pi, INT c, BOOL fSelect = TRUE );
  129. VOID RemoveSelection();
  130. INT DeleteItem( INT i );
  131. VOID DeleteAllItems();
  132. INT QueryCurrentItem() const;
  133. INT QuerySelCount() const;
  134. APIERR QuerySelItems( INT * piSel, INT ciMax ) const;
  135. UINT QueryItemHeight( UINT ilb = 0) const;
  136. BOOL IsItemSelected( UINT ilb ) const;
  137. VOID SetTopIndex( INT i );
  138. INT QueryTopIndex() const;
  139. VOID SetCaretIndex( INT i, BOOL fPartiallyVisibleOK = FALSE );
  140. INT QueryCaretIndex() const;
  141. BOOL IsCombo() const
  142. { return _fCombo; }
  143. BOOL IsMultSel() const;
  144. };
  145. /*************************************************************************
  146. NAME: STRING_LIST_CONTROL
  147. SYNOPSIS: class containing common denominators of the combobox
  148. and the plain vanilla Windows listbox
  149. INTERFACE: AddItem() adds an item (a string, in fact)
  150. AddItemIdemp() idempotently adds an item (a string)
  151. InsertItem() Insert string item in the specified
  152. location
  153. FindItem() finds the item which has the given
  154. prefix, and returns its index
  155. FindItemExact() finds the item which exactly
  156. matches the given string
  157. QueryItemText() fetches the text of an item
  158. QueryItemLength() returns the string length of a
  159. particular item
  160. QueryItemSize() return the number of bytes needed
  161. to dup an item
  162. PARENT: LIST_CONTROL
  163. HISTORY:
  164. RustanL 22-Feb-1991 Created as a result of modifying
  165. the LIST_CONTROL hierarchy
  166. RustanL 21-Mar-1991 Folded in code review changes from
  167. CR on 20-Mar-1991 attended by
  168. JimH, GregJ, Hui-LiCh, RustanL.
  169. beng 16-May-1991 Added app-window constructor
  170. beng 10-Jun-1991 Added QueryItemSize; changed return
  171. of QueryItemText
  172. beng 21-Aug-1991 Removed LC_CURRENT_ITEM magic value
  173. **************************************************************************/
  174. DLL_CLASS STRING_LIST_CONTROL : public LIST_CONTROL
  175. {
  176. private:
  177. APIERR QueryItemTextAux( TCHAR * pchBuffer, INT i ) const;
  178. protected:
  179. STRING_LIST_CONTROL( OWNER_WINDOW * powin, CID cid, BOOL fCombo );
  180. STRING_LIST_CONTROL( OWNER_WINDOW * powin, CID cid, BOOL fCombo,
  181. XYPOINT xy, XYDIMENSION dxy,
  182. ULONG flStyle, const TCHAR * pszClassName );
  183. public:
  184. INT AddItem( const TCHAR * pch );
  185. INT AddItem( const NLS_STR & nls )
  186. { return AddItem( nls.QueryPch()); }
  187. INT AddItemIdemp( const TCHAR * pch );
  188. INT AddItemIdemp( const NLS_STR & nls )
  189. { return AddItemIdemp( nls.QueryPch()); }
  190. INT InsertItem( INT i, const TCHAR * pch );
  191. INT InsertItem( INT i, const NLS_STR & nls )
  192. { return InsertItem( i, nls.QueryPch() ); }
  193. INT FindItem( const TCHAR * pchPrefix ) const;
  194. INT FindItem( const TCHAR * pchPrefix, INT iLastSearchResult ) const;
  195. INT FindItem( const NLS_STR & nlsPrefix ) const
  196. { return FindItem( nlsPrefix.QueryPch() ); }
  197. INT FindItem( const NLS_STR & nlsPrefix, INT iLastSearchResult ) const
  198. { return FindItem( nlsPrefix.QueryPch(), iLastSearchResult ); }
  199. INT FindItemExact( const TCHAR * pch ) const;
  200. INT FindItemExact( const TCHAR * pch, INT iLastSearchResult ) const;
  201. INT FindItemExact( const NLS_STR & nls ) const
  202. { return FindItemExact( nls.QueryPch() ); }
  203. INT FindItemExact( const NLS_STR & nls, INT iLastSearchResult ) const
  204. { return FindItemExact( nls.QueryPch(), iLastSearchResult ); }
  205. APIERR QueryItemText( NLS_STR * pnls, INT i ) const;
  206. APIERR QueryItemText( NLS_STR * pnls ) const
  207. { return QueryItemText(pnls, QueryCurrentItem()); }
  208. APIERR QueryItemText( TCHAR * pchBuffer, INT cbBuffer, INT i ) const;
  209. APIERR QueryItemText( TCHAR * pchBuffer, INT cbBuffer ) const
  210. { return QueryItemText(pchBuffer, cbBuffer, QueryCurrentItem()); }
  211. INT QueryItemLength( INT i ) const;
  212. INT QueryItemLength() const
  213. { return QueryItemLength(QueryCurrentItem()); }
  214. INT QueryItemSize( INT i ) const;
  215. INT QueryItemSize() const
  216. { return QueryItemSize(QueryCurrentItem()); }
  217. };
  218. /*************************************************************************
  219. NAME: STRING_LISTBOX
  220. SYNOPSIS: class representing the plain vanilla Windows listbox (whose
  221. items consist of strings fitting in one column)
  222. INTERFACE: STRING_LISTBOX() constructor
  223. PARENT: STRING_LIST_CONTROL
  224. HISTORY:
  225. RustanL 22-Feb-1991 Created as a result of modifying
  226. the LIST_CONTROL hierarchy
  227. beng 16-May-1991 Added app-window constructor
  228. DavidHov 21-Jan-1992 Added FONT member
  229. **************************************************************************/
  230. DLL_CLASS STRING_LISTBOX : public STRING_LIST_CONTROL
  231. {
  232. FONT _fontListBox ;
  233. public:
  234. STRING_LISTBOX( OWNER_WINDOW * powin, CID cid,
  235. enum FontType font = FONT_DEFAULT );
  236. STRING_LISTBOX( OWNER_WINDOW * powin, CID cid,
  237. XYPOINT xy, XYDIMENSION dxy,
  238. ULONG flStyle,
  239. const TCHAR * pszClassName = CW_CLASS_LISTBOX,
  240. enum FontType font = FONT_DEFAULT );
  241. };
  242. /*************************************************************************
  243. NAME: COMBOBOX
  244. SYNOPSIS: combo box class
  245. INTERFACE: COMBOBOX() constructor
  246. SetMaxLength() sets the limit on the number of bytes
  247. that a string typed in the combo's
  248. edit field may have (strlen)
  249. PARENT: STRING_LIST_CONTROL
  250. CAVEATS: SetMaxLength should only be called on combos which
  251. contain an SLE. Likewise, the cbMaxLen parameter to the
  252. constructor should always be 0 for combos which don't
  253. have an SLE.
  254. HISTORY:
  255. RustanL 22-Feb-1991 Created as a result of modifying
  256. the LIST_CONTROL hierarchy
  257. beng 16-May-1991 Added app-window constructor
  258. beng 31-Jul-1991 Renamed QMessageInfo to QEventEffects
  259. beng 04-Oct-1991 Win32 conversion
  260. kevinl 19-Nov-1991 Added SelectString
  261. **************************************************************************/
  262. DLL_CLASS COMBOBOX : public STRING_LIST_CONTROL
  263. {
  264. private:
  265. NLS_STR _nlsSaveValue;
  266. protected:
  267. /* See CONTROL_VALUE for more info on the following methods.
  268. */
  269. virtual UINT QueryEventEffects( const CONTROL_EVENT & e );
  270. /* Replacement of CONTROL_VALUE virtuals
  271. */
  272. virtual VOID SaveValue( BOOL fInvisible = TRUE );
  273. virtual VOID RestoreValue( BOOL fInvisible = TRUE );
  274. public:
  275. COMBOBOX( OWNER_WINDOW * powin, CID cid, UINT cbMaxLen = 0 );
  276. COMBOBOX( OWNER_WINDOW * powin, CID cid, UINT cbMaxLen,
  277. XYPOINT xy, XYDIMENSION dxy,
  278. ULONG flStyle, const TCHAR * pszClassName = CW_CLASS_COMBOBOX );
  279. BOOL SetMaxLength( UINT cbMaxLen );
  280. BOOL IsDropDownList() const;
  281. BOOL IsSimple() const;
  282. BOOL IsDropDown() const;
  283. BOOL IsUserEdittable() const
  284. { return IsSimple() || IsDropDown(); }
  285. VOID SelectString();
  286. };
  287. #endif // _BLTLC_HXX_ - end of file