Leaked source code of windows server 2003
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.

1066 lines
32 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. bltlb.hxx
  7. BLT listbox control classes: definitions
  8. FILE HISTORY:
  9. RustanL 13-Feb-1991 Created
  10. RustanL 22-Feb-1991 Modified for revised LC hierarchy
  11. rustanl 22-Mar-1991 Rolled in code review changes
  12. from CR on 20-Mar-1991, attended by
  13. JimH, GregJ, Hui-LiCh, RustanL.
  14. gregj 08-Apr-1991 Reintegrated caching listbox
  15. gregj 01-May-1991 Added GUILTT support
  16. beng 14-May-1991 Made clients depend on blt.hxx
  17. rustanl 07-Aug-1991 Added METALLIC_STR_DTE
  18. rustanl 04-Sep-1991 Added ReplaceItem
  19. KeithMo 23-Oct-1991 Added forward references.
  20. beng 19-Apr-1992 Added LISTBOX, LAZY_LISTBOX
  21. jonn 25-Apr-1992 Disabled LAZY_LISTBOX build fix
  22. beng 10-May-1992 Re-enabled (given 1.264)
  23. beng 01-Jun-1992 Changed GUILTT support
  24. jonn 04-Aug-1992 HAW-for-Hawaii support
  25. jonn 11-Aug-1992 HAW-for-Hawaii for other LBs
  26. Yi-HsinS 10-Dec-1992 Support variable size LBI in BLT_LISTBOX
  27. */
  28. #ifndef _BLT_HXX_
  29. #error "Don't include this file directly; instead, include it through blt.hxx"
  30. #endif // _BLT_HXX_
  31. #ifndef _BLTLB_HXX_
  32. #define _BLTLB_HXX_
  33. #include "bltbitmp.hxx" // DISPLAY_MAP
  34. #include "bltfont.hxx" // FONT
  35. //
  36. // Forward references.
  37. //
  38. DLL_CLASS DTE;
  39. DLL_CLASS DM_DTE;
  40. DLL_CLASS DMID_DTE;
  41. DLL_CLASS STR_DTE;
  42. DLL_CLASS MULTILINE_STR_DTE;
  43. DLL_CLASS METALLIC_STR_DTE;
  44. DLL_CLASS DISPLAY_TABLE;
  45. DLL_CLASS LBI;
  46. DLL_CLASS LISTBOX;
  47. DLL_CLASS BLT_LISTBOX;
  48. DLL_CLASS LAZY_LISTBOX;
  49. DLL_CLASS SET_CONTROL;
  50. // Maximum number of columns in a listbox
  51. #define MAX_DISPLAY_TABLE_ENTRIES 10
  52. /**********************************************************************
  53. NAME: GUILTT_INFO
  54. SYNOPSIS: Packaged parameters for use in GUILTT processing
  55. INTERFACE: pnlsOut - string into which to place output
  56. errOut - error code to return
  57. HISTORY:
  58. gregj 01-May-1991 Created
  59. beng 14-Feb-1992 Win32 conversion
  60. beng 01-Jun-1992 GUILTT changes
  61. **********************************************************************/
  62. struct GUILTT_INFO
  63. {
  64. NLS_STR * pnlsOut;
  65. APIERR errOut;
  66. };
  67. /**********************************************************************
  68. NAME: HAW_FOR_HAWAII_INFO (hawinfo)
  69. SYNOPSIS: Packaged parameters for use in
  70. BLT_LISTBOX::CD_Char_HAWforHawaii()
  71. INTERFACE: _nls: string containing current HAW prefix
  72. _time: time when this prefix will time out
  73. HISTORY:
  74. jonn 04-Aug-1992 HAW-for-Hawaii support
  75. **********************************************************************/
  76. DLL_CLASS HAW_FOR_HAWAII_INFO : public BASE
  77. {
  78. public:
  79. NLS_STR _nls;
  80. LONG _time;
  81. HAW_FOR_HAWAII_INFO();
  82. ~HAW_FOR_HAWAII_INFO();
  83. };
  84. /**********************************************************************
  85. NAME: DTE
  86. SYNOPSIS: Display table entry abstract class
  87. INTERFACE: Paint() - paint function
  88. AppendDataTo() - returns GUILTT information
  89. PARENT: BASE
  90. CAVEATS:
  91. While most DTEs cannot fail construction, a few, such
  92. as DMID_DTE, can.
  93. HISTORY:
  94. RustanL 13-Feb-1991 Created
  95. gregj 01-May-1991 Added GUILTT support
  96. beng 10-Jul-1991 Changed Paint protocol; inherits
  97. from BASE
  98. beng 04-Oct-1991 Win32 conversion
  99. beng 07-Nov-1991 Inlined (empty) ctor
  100. beng 01-Jun-1992 GUILTT changes
  101. **********************************************************************/
  102. DLL_CLASS DTE: public BASE
  103. {
  104. protected:
  105. DTE() { }
  106. public:
  107. virtual VOID Paint( HDC hdc, const RECT * prect ) const = 0;
  108. virtual UINT QueryLeftMargin() const;
  109. virtual APIERR AppendDataTo( NLS_STR * pnlsOut ) const = 0;
  110. };
  111. /**********************************************************************
  112. NAME: DM_DTE
  113. SYNOPSIS: DTE which works with a DISPLAY_MAP
  114. INTERFACE: DM_DTE() - constructor
  115. Paint() - paint function
  116. AppendDataTo() - support for GUILTT
  117. QueryDisplayWidth() - Returns the width (including
  118. left margin) that the DTE
  119. will require in order to be
  120. displayed in full
  121. QueryDisplayMap() - Get the display map
  122. PARENT: DTE
  123. USES: DISPLAY_MAP
  124. NOTES: CODEWORK. If it would prove useful, QueryDisplayWidth
  125. could be made virtual at the DTE level, and would then
  126. always return the width (including the left margin)
  127. needed to fully display the DTE.
  128. HISTORY:
  129. RustanL 13-Feb-1991 Created
  130. gregj 01-May-1991 Added GUILTT support
  131. beng 10-Jul-1991 Changed Paint
  132. rustanl 03-Sep-1991 Added QueryDisplayWidth method
  133. beng 04-Oct-1991 Win32 conversion
  134. beng 07-Nov-1991 Unsigned width
  135. beng 01-Jun-1992 GUILTT changes
  136. **********************************************************************/
  137. DLL_CLASS DM_DTE : public DTE
  138. {
  139. private:
  140. DISPLAY_MAP * _pdm;
  141. protected:
  142. DM_DTE();
  143. VOID SetPdm( DISPLAY_MAP * pdm );
  144. public:
  145. DM_DTE( DISPLAY_MAP * pdm );
  146. virtual VOID Paint( HDC hdc, const RECT * prect ) const;
  147. virtual APIERR AppendDataTo( NLS_STR * pnlsOut ) const;
  148. UINT QueryDisplayWidth() const;
  149. DISPLAY_MAP *QueryDisplayMap( VOID ) const
  150. { return _pdm; }
  151. };
  152. /**********************************************************************
  153. NAME: DMID_DTE
  154. SYNOPSIS: DTE which works from a DMID.
  155. It constructs the DM for the client.
  156. INTERFACE: DMID_DTE() - constructor
  157. ~DMID_DTE() - destructor
  158. PARENT: DM_DTE
  159. USES: DISPLAY_MAP
  160. CAVEATS:
  161. Since this constructs a DM, *it can fail construction*.
  162. HISTORY:
  163. RustanL 13-Feb-1991 Created
  164. beng 10-Jul-1991 Added caveat
  165. **********************************************************************/
  166. DLL_CLASS DMID_DTE : public DM_DTE
  167. {
  168. private:
  169. DISPLAY_MAP _dm;
  170. public:
  171. DMID_DTE( DMID dmid );
  172. };
  173. /**********************************************************************
  174. NAME: STR_DTE
  175. SYNOPSIS: DTE which presents a simple string
  176. INTERFACE: STR_DTE() - constructor
  177. Paint() - paint function
  178. GetData() - support for GUILTT
  179. SetPch() - Painting Optimization
  180. PARENT: DTE
  181. USES:
  182. CAVEATS:
  183. NOTES:
  184. Should this use NLS_STR? Its string is presented to the user.
  185. Need to rethink SetPch.
  186. HISTORY:
  187. RustanL 13-Feb-1991 Created
  188. gregj 01-May-1991 Added GUILTT support
  189. beng 20-May-1991 Made _pch pointer-to-const
  190. kevinl 30-May-1991 Added SetPch member
  191. beng 10-Jul-1991 Changed Paint
  192. beng 04-Oct-1991 Win32 conversion
  193. beng 07-Nov-1991 Inlined ctor
  194. beng 01-Jun-1992 GUILTT changes
  195. **********************************************************************/
  196. DLL_CLASS STR_DTE : public DTE
  197. {
  198. private:
  199. const TCHAR * _pch;
  200. public:
  201. STR_DTE( const TCHAR * pch ) : _pch(pch) { }
  202. VOID SetPch( const TCHAR * pch )
  203. { _pch = pch; }
  204. const TCHAR *QueryPch( VOID ) const
  205. { return _pch; }
  206. virtual VOID Paint( HDC hdc, const RECT * prect ) const;
  207. virtual APIERR AppendDataTo( NLS_STR * pnlsOut ) const;
  208. };
  209. /*************************************************************************
  210. NAME: METALLIC_STR_DTE
  211. SYNOPSIS: DTE which presents a simple string, painted in a
  212. metallic colored 3D looking format.
  213. INTERFACE: METALLIC_STR_DTE() - constructor
  214. Paint() - virtual replacement of Paint
  215. method
  216. QueryLeftMargin() - virtual replacement for returning
  217. the left margin which is to
  218. be left in between columns.
  219. QueryVerticalMargins() - static method returning the
  220. number of pixels taken up by
  221. vertical margins when the DTE
  222. is painted
  223. PARENT: STR_DTE
  224. HISTORY:
  225. rustanl 22-Jul-1991 Created
  226. rustanl 07-Aug-1991 Added to BLT
  227. beng 04-Oct-1991 Win32 conversion
  228. beng 08-Nov-1991 Unsigned widths
  229. **************************************************************************/
  230. DLL_CLASS METALLIC_STR_DTE : public STR_DTE
  231. {
  232. private:
  233. static const UINT _dyTopMargin;
  234. static const UINT _dyBottomMargin;
  235. inline static UINT CalcTopTextMargin();
  236. inline static UINT CalcBottomTextMargin();
  237. public:
  238. METALLIC_STR_DTE( const TCHAR * pch ) : STR_DTE( pch ) { }
  239. virtual VOID Paint( HDC hdc, const RECT * prect ) const;
  240. virtual UINT QueryLeftMargin() const;
  241. static UINT QueryVerticalMargins();
  242. };
  243. /**********************************************************************
  244. NAME: MULTILINE_STR_DTE
  245. SYNOPSIS: DTE which presents a multi-line string
  246. INTERFACE: MULTILINE_STR_DTE() - constructor
  247. Paint() - paint function
  248. PARENT: STR_DTE
  249. USES:
  250. CAVEATS:
  251. NOTES:
  252. HISTORY:
  253. Yi-HsinS 13-Dec-1992 Created
  254. **********************************************************************/
  255. DLL_CLASS MULTILINE_STR_DTE : public STR_DTE
  256. {
  257. public:
  258. MULTILINE_STR_DTE( const TCHAR * pch ) : STR_DTE(pch) {}
  259. virtual VOID Paint( HDC hdc, const RECT * prect ) const;
  260. };
  261. /**********************************************************************
  262. NAME: COUNTED_STR_DTE
  263. SYNOPSIS: DTE which displays a counted (rather than \0 terminated)
  264. string.
  265. INTERFACE: COUNTED_STR_DTE() - constructor
  266. Paint() - paint function
  267. PARENT: STR_DTE
  268. HISTORY:
  269. KeithMo 15-Dec-1992 Created
  270. **********************************************************************/
  271. DLL_CLASS COUNTED_STR_DTE : public STR_DTE
  272. {
  273. private:
  274. INT _cch;
  275. public:
  276. COUNTED_STR_DTE( const TCHAR * pch, INT cch ) : STR_DTE(pch), _cch(cch) {}
  277. INT QueryCount( VOID ) const
  278. { return _cch; }
  279. virtual VOID Paint( HDC hdc, const RECT * prect ) const;
  280. };
  281. #define DEFAULT_DM_DY 1
  282. #define DEFAULT_TEXT_DY 3
  283. /**********************************************************************
  284. NAME: OWNER_DRAW_STR_DTE
  285. SYNOPSIS: STR_DTE which presents a string centered according to nDy
  286. INTERFACE: OWNER_DRAW_STR_DTE() - constructor
  287. Paint() - paint function
  288. PARENT: STR_DTE
  289. USES:
  290. CAVEATS:
  291. NOTES:
  292. HISTORY:
  293. Yi-HsinS 13-Dec-1992 Created
  294. **********************************************************************/
  295. DLL_CLASS OWNER_DRAW_STR_DTE : public STR_DTE
  296. {
  297. private:
  298. INT _nDy;
  299. public:
  300. OWNER_DRAW_STR_DTE( const TCHAR * pch, INT nDy = DEFAULT_TEXT_DY )
  301. : STR_DTE ( pch ),
  302. _nDy( nDy ) { }
  303. virtual VOID Paint( HDC hdc, const RECT * prect ) const;
  304. };
  305. /**********************************************************************
  306. NAME: OWNER_DRAW_DMID_DTE
  307. SYNOPSIS: DMID_DTE in which the owner will paint according to nDy.
  308. INTERFACE: OWNER_DRAW_DMID_DTE() - constructor
  309. Paint() - paint function
  310. PARENT: DMID_DTE
  311. USES:
  312. CAVEATS:
  313. HISTORY:
  314. Yi-HsinS 23-Dec-1992 Created
  315. **********************************************************************/
  316. DLL_CLASS OWNER_DRAW_DMID_DTE : public DMID_DTE
  317. {
  318. private:
  319. INT _nDy;
  320. public:
  321. OWNER_DRAW_DMID_DTE( DMID dmid, INT nDy = DEFAULT_DM_DY )
  322. : DMID_DTE( dmid ),
  323. _nDy( nDy ) {}
  324. virtual VOID Paint( HDC hdc, const RECT * prect ) const;
  325. };
  326. /**********************************************************************
  327. NAME: OWNER_DRAW_MULTILINE_STR_DTE
  328. SYNOPSIS: MULTILINE_STR_DTE which is centered according to _nDy
  329. INTERFACE: OWNER_DRAW_MULTILINE_STR_DTE() - constructor
  330. Paint() - paint function
  331. PARENT: MULTILINE_STR_DTE
  332. USES:
  333. CAVEATS:
  334. NOTES:
  335. HISTORY:
  336. Yi-HsinS 13-Dec-1992 Created
  337. **********************************************************************/
  338. DLL_CLASS OWNER_DRAW_MULTILINE_STR_DTE : public MULTILINE_STR_DTE
  339. {
  340. private:
  341. INT _nDy;
  342. public:
  343. OWNER_DRAW_MULTILINE_STR_DTE( const TCHAR * pch, INT nDy = DEFAULT_TEXT_DY )
  344. : MULTILINE_STR_DTE(pch),
  345. _nDy( nDy ) {}
  346. virtual VOID Paint( HDC hdc, const RECT * prect ) const;
  347. };
  348. /**********************************************************************
  349. NAME: DISPLAY_TABLE
  350. SYNOPSIS: Table of DTEs used by the BLT listbox
  351. INTERFACE:
  352. DISPLAY_TABLE() - constructor
  353. Paint() - paint function
  354. operator[]() - return the specified entry in the display table
  355. CalcColumnWidths() - generate array of column widths
  356. USES: DTE
  357. NOTES:
  358. To use this properly, a listbox should keep an array of column
  359. widths as a member, which it gives to each display table built
  360. within it. That array should be built with CalcColumnWidths
  361. in order to synchronize the spacing of the listbox columns and
  362. their respective column headers (static text controls above
  363. the listbox).
  364. HISTORY:
  365. RustanL 13-Feb-1991 Created
  366. gregj 01-May-1991 Added GUILTT support
  367. beng 04-Oct-1991 Win32 conversion
  368. beng 07-Nov-1991 Unsigned widths
  369. beng 08-Nov-1991 Added CalcColumnWidths
  370. beng 21-Apr-1992 Generalized BLT_LISTBOX to LISTBOX
  371. **********************************************************************/
  372. DLL_CLASS DISPLAY_TABLE
  373. {
  374. private:
  375. const UINT *_pdxColWidth; // points to array of column widths
  376. UINT _cdx;
  377. DTE * _apdte[ MAX_DISPLAY_TABLE_ENTRIES ];
  378. public:
  379. DISPLAY_TABLE( UINT cColumns, const UINT * pdxColWidth );
  380. VOID Paint( LISTBOX * plb, HDC hdc, const RECT * prect,
  381. GUILTT_INFO * pginfo ) const;
  382. VOID Paint( LISTBOX * plb, HDC hdc, const RECT * prect ) const;
  383. DTE * & operator[]( UINT i ) ;
  384. static APIERR CalcColumnWidths( UINT * pdx, UINT cdx,
  385. OWNER_WINDOW * pwnd,
  386. CID cidListbox, BOOL fHaveIcon );
  387. };
  388. /**********************************************************************
  389. NAME: LBI
  390. SYNOPSIS: Listbox item
  391. INTERFACE:
  392. LBI() - constructor
  393. ~LBI() - destructor
  394. Paint() - paint function
  395. Compare() - compare two items in the list box
  396. QueryLeadingChar() - unknown
  397. Compare_HAWforHawaii() - special compare routine for
  398. HAW-for-Hawaii purposes. Redefine iff the
  399. listbox uses CD_Char_HAWforHawaii().
  400. PARENT: BASE
  401. CAVEATS:
  402. CODEWORK - Generalize the QueryLeadingChar protocol for
  403. Haw-for-Hawaii support.
  404. NOTES:
  405. The Paint() method may be called in response to a
  406. GUILTT request as well as for a WM_DRAWITEM message.
  407. The pGUILTT parameter to Paint() should be passed on
  408. to the DISPLAY_TABLE class without modification.
  409. HISTORY:
  410. RustanL 13-Feb-1991 Created
  411. gregj 01-May-1991 Added GUILTT support
  412. beng 20-May-1991 Added OnCompareItem and OnDeleteItem;
  413. QueryLeadingChar now returns WCHAR
  414. beng 04-Oct-1991 Win32 conversion
  415. kevinl 05-Nov-1991 Added IsDestroyable
  416. beng 21-Apr-1992 Generalized BLT_LISTBOX to LISTBOX
  417. jonn 04-Aug-1992 HAW-for-Hawaii support
  418. **********************************************************************/
  419. DLL_CLASS LBI : public BASE
  420. {
  421. protected:
  422. virtual BOOL IsDestroyable();
  423. public:
  424. LBI();
  425. virtual ~LBI();
  426. // Note, CalcHeight is currently only called for variable size items
  427. virtual UINT CalcHeight( UINT nSingleLineHeight );
  428. virtual VOID Paint( LISTBOX * plb, HDC hdc, const RECT * prect,
  429. GUILTT_INFO * pGUILTT ) const;
  430. virtual INT Compare( const LBI * plbi ) const;
  431. virtual INT Compare_HAWforHawaii( const NLS_STR & nls ) const;
  432. virtual WCHAR QueryLeadingChar() const;
  433. // Response code for WM_COMPAREITEM and WM_DELETEITEM
  434. //
  435. static INT OnCompareItem( WPARAM wParam, LPARAM lParam );
  436. static VOID OnDeleteItem( WPARAM wParam, LPARAM lParam );
  437. };
  438. /**********************************************************************
  439. NAME: LISTBOX
  440. SYNOPSIS: Listbox (owner-draw) control class
  441. INTERFACE: LISTBOX() - constructor
  442. InvalidateItem() - invalidate the item
  443. IsReadOnly() - predicate, TRUE if r.o. listbox
  444. QueryScrollPos() - return horizontal scroll position
  445. SetScrollPos() - set scroll position (default 0)
  446. default is zero
  447. PARENT: LIST_CONTROL
  448. USES: FONT
  449. CAVEATS:
  450. All listboxes must have LBS_OWNERDRAWFIXED or LBS_OWNERDRAWVARIABLE.
  451. HISTORY:
  452. beng 19-Apr-1992 Created from old BLT_LISTBOX
  453. beng 01-Jun-1992 Changed GUILTT support
  454. KeithMo 09-Feb-1993 Added Query/SetHorizontalExtent methods.
  455. **********************************************************************/
  456. DLL_CLASS LISTBOX: public LIST_CONTROL
  457. {
  458. private:
  459. BOOL _fReadOnly;
  460. FONT _fontListBox;
  461. UINT _dxScroll; // pane scroll increment, in pels
  462. protected:
  463. // Replacement of virtual CONTROL_WINDOW methods
  464. //
  465. virtual BOOL CD_Draw( DRAWITEMSTRUCT * pdis );
  466. virtual INT CD_VKey( USHORT nVKey, USHORT nLastPos );
  467. // Get a LBI, whether listbox conventional or lazy
  468. //
  469. virtual LBI * RequestLBI( const DRAWITEMSTRUCT * pdis ) = 0;
  470. virtual VOID ReleaseLBI( LBI * plbi ) = 0;
  471. public:
  472. LISTBOX( OWNER_WINDOW * powin, CID cid,
  473. BOOL fReadOnly = FALSE,
  474. enum FontType font = FONT_DEFAULT,
  475. BOOL fIsCombo = FALSE );
  476. LISTBOX( OWNER_WINDOW * powin, CID cid,
  477. XYPOINT xy, XYDIMENSION dxy,
  478. ULONG flStyle,
  479. BOOL fReadOnly = FALSE,
  480. enum FontType font = FONT_DEFAULT,
  481. BOOL fIsCombo = FALSE );
  482. VOID InvalidateItem( INT i, BOOL fErase = TRUE );
  483. BOOL IsReadOnly() const
  484. { return _fReadOnly; }
  485. UINT QueryScrollPos() const
  486. { return _dxScroll; }
  487. VOID SetScrollPos( UINT dxNewPos = 0 );
  488. UINT QueryHorizontalExtent( VOID ) const;
  489. VOID SetHorizontalExtent( UINT dxNewExtent );
  490. };
  491. /**********************************************************************
  492. NAME: BLT_LISTBOX
  493. SYNOPSIS: BLT listbox control class
  494. INTERFACE: BLT_LISTBOX() - constructor
  495. AddItem() - add an item to the listbox
  496. AddItemIdemp() - add an item to the listbox if the
  497. item does not exist already.
  498. SetItem() - set the value of the specified item
  499. FindItem() - find an item from the listbox
  500. QueryItem() - Query item
  501. RemoveItem() - Removes the LBI from the listbox w/o
  502. deleting it
  503. RemoveAllItems - Does RemoveItem to all items in LB
  504. CD_Char_HAWforHawaii() - Standard CD_Char handler for
  505. listboxes with HAW-for-Hawaii functionality.
  506. Redefine CD_Char() to call this. Pass in a
  507. pointer to a HAW_FOR_HAWAII_INFO associated
  508. with this listbox, which must have constructed
  509. successfully. Also redefine
  510. LBI::Compare_HAWforHawaii().
  511. PARENT: LISTBOX
  512. HISTORY:
  513. RustanL 13-Feb-1991 Created
  514. Johnl 05-Apr-1991 Added _fontListBox member, added font
  515. param. to const. & defaulted to
  516. FONT_DEFAULT
  517. gregj 08-Apr-1991 Added extra scrolling members for two
  518. column support
  519. gregj 01-May-1991 Added GUILTT support
  520. beng 16-May-1991 Added app-window constructor
  521. beng 21-Aug-1991 Removed LC_CURRENT_ITEM magic value
  522. beng 15-Oct-1991 Win32 conversion
  523. beng 07-Nov-1991 Removed 2-pane listbox support
  524. beng 19-Apr-1992 Factored out new LISTBOX control
  525. beng 01-Jun-1992 Changed GUILTT support
  526. jonn 04-Aug-1992 HAW-for-Hawaii support
  527. Johnl 27-Oct-1992 Added RemoveItem
  528. Johnl 07-Dec-1992 Added RemoveAllItems
  529. Yi-HsinS 10-Dec-1992 Added CD_Measure for OWNERDRAWVARIABLE listbox
  530. KeithMo 17-Dec-1992 Added InsertItem
  531. **********************************************************************/
  532. DLL_CLASS BLT_LISTBOX : public LISTBOX
  533. {
  534. friend class SET_CONTROL;
  535. private:
  536. UINT _nSingleLineHeight;
  537. VOID SetItem( INT ilbi, LBI * plbi );
  538. // Replacement of virtual LISTBOX methods
  539. //
  540. virtual LBI * RequestLBI( const DRAWITEMSTRUCT * pdis );
  541. virtual VOID ReleaseLBI( LBI * plbi );
  542. protected:
  543. // Replacement of virtual CONTROL_WINDOW methods
  544. //
  545. virtual INT CD_Char( WCHAR wch, USHORT nLastPos );
  546. virtual APIERR CD_Guiltt( INT ilb, NLS_STR * pnlsOut );
  547. INT CD_Char_HAWforHawaii( WCHAR wch,
  548. USHORT nLastPos,
  549. HAW_FOR_HAWAII_INFO * phawinfo );
  550. // note, CD_Measure is currently only called for variable size items
  551. virtual BOOL CD_Measure( MEASUREITEMSTRUCT * pmis );
  552. public:
  553. BLT_LISTBOX( OWNER_WINDOW * powin, CID cid,
  554. BOOL fReadOnly = FALSE,
  555. enum FontType font = FONT_DEFAULT,
  556. BOOL fIsCombo = FALSE );
  557. BLT_LISTBOX( OWNER_WINDOW * powin, CID cid,
  558. XYPOINT xy, XYDIMENSION dxy,
  559. ULONG flStyle,
  560. BOOL fReadOnly = FALSE,
  561. enum FontType font = FONT_DEFAULT,
  562. BOOL fIsCombo = FALSE );
  563. INT AddItem( LBI * plbi );
  564. INT AddItemIdemp( LBI * plbi );
  565. INT InsertItem( INT i, LBI * plbi );
  566. INT FindItem( const LBI & lbi ) const;
  567. LBI * QueryItem( INT i ) const;
  568. LBI * QueryItem() const
  569. { return QueryItem(QueryCurrentItem()); }
  570. LBI * RemoveItem( INT i ) ;
  571. LBI * RemoveItem()
  572. { return RemoveItem( QueryCurrentItem()) ; }
  573. //
  574. // Note that the LBIs must be deleted (and are assumed to be in an
  575. // external list)
  576. //
  577. void RemoveAllItems( void ) ;
  578. APIERR ReplaceItem( INT i, LBI * plbiNew, LBI * * pplbiOld = NULL );
  579. APIERR Resort( void );
  580. UINT QuerySingleLineHeight( VOID )
  581. { return _nSingleLineHeight; }
  582. APIERR CalcSingleLineHeight( VOID );
  583. };
  584. /*************************************************************************
  585. NAME: BLT_COMBOBOX
  586. SYNOPSIS: Owner draw combo box
  587. INTERFACE:
  588. PARENT: BLT_LISTBOX
  589. NOTES: Usage is exactly like a BLT_LISTBOX (i.e., use the same LBIs,
  590. etc) except the container is a combo.
  591. We subclass the window proc so the 'H' for Hawaii will work
  592. (combo boxes don't support this functionality).
  593. HISTORY:
  594. Johnl 21-Oct-1992 Moved out of MPR
  595. **************************************************************************/
  596. DLL_CLASS BLT_COMBOBOX : public BLT_LISTBOX
  597. {
  598. public:
  599. BLT_COMBOBOX( OWNER_WINDOW * powin, CID cid,
  600. BOOL fReadOnly = FALSE,
  601. enum FontType font = FONT_DEFAULT ) ;
  602. BLT_COMBOBOX( OWNER_WINDOW * powin, CID cid,
  603. XYPOINT xy, XYDIMENSION dxy,
  604. ULONG flStyle,
  605. BOOL fReadOnly = FALSE,
  606. enum FontType font = FONT_DEFAULT ) ;
  607. ~BLT_COMBOBOX() ;
  608. BOOL IsDropped( void ) const ;
  609. protected:
  610. /* We do a little bit of subclassing so the H for Hawaii works
  611. */
  612. static LRESULT WINAPI CBSubclassProc( HWND hwnd,
  613. UINT msg,
  614. WPARAM wParam,
  615. LPARAM lParam ) ;
  616. private:
  617. //
  618. // Old window proc (restored when all occurrences of BLT_COMBOBOX are
  619. // destructed.
  620. //
  621. static WNDPROC _OldCBProc ;
  622. //
  623. // Reference count. When this reaches 0, the old window proc is restored
  624. //
  625. static UINT _cReferences ;
  626. } ;
  627. #if defined(WIN32)
  628. /*************************************************************************
  629. NAME: LAZY_LISTBOX
  630. SYNOPSIS: Listbox control which defers line definition
  631. A lazy listbox is a listbox-like control which postpones defining
  632. the contents of a line until that line must be shown. Compare a
  633. conventional listbox control, which requires a BLT_LISTBOX::AddItem
  634. for each line therein before any may be shown.
  635. Do not confuse this control with a "caching" listbox. I think it's
  636. a good idea to decouple any "caching" logic of an app (such as the
  637. event-log viewer) from the "virtual listbox" logic. This control,
  638. then, knows nothing beyond listbox items and indices in the listbox.
  639. It leaves all caching knowledge up to its client application.
  640. To define the particular lazy listbox, derive a class from class
  641. LAZY_LISTBOX which redefines the (pure, virtual) OnNewItem callback.
  642. OnNewItem should return a pointer to a LBI for the i-th element in
  643. the listbox. For instance, you could define it as
  644. return new MY_FABULOUS_LBI(pmumble, i);
  645. Return NULL if you fail to construct any LBI.
  646. Too, if you want to support keyboard H-for-Hawaii manipulation,
  647. redefine the CONTROL_WINDOW::CD_Char member function.
  648. The total number of items is set, and also redefinable
  649. at any time, via LAZY_LISTBOX::SetCount(). Alternately, you can
  650. use the Insert etc. members of LIST_CONTROL.
  651. The LAZY_LISTBOX::Refresh() function tells the listbox to discard all
  652. its entries and start anew.
  653. INTERFACE:
  654. SetCount() - resets the total number of lines in the list
  655. OnNewItem() - callback: returns pointer to a new item. Must
  656. be defined by user
  657. OnDeleteItem() - callback: process the obsolete LBI.
  658. PARENT: LISTBOX
  659. CAVEATS:
  660. A lazy listbox requires the LBS_NODATA and LBS_OWNERDRAWFIXED
  661. styles, and may never have LBS_SORT or LBS_HASSTRINGS.
  662. NOTES:
  663. The lazy listbox demands that the client redefine CD_Char instead
  664. of supporting the LBI::QueryLeadingChar protocol used by its
  665. sibling BLT_LISTBOX, since that protocol would force linear
  666. searches potentially to walk the entire contents of the list.
  667. HISTORY:
  668. beng 27-Nov-1991 Created
  669. beng 16-Apr-1992 Implemented
  670. beng 01-Jun-1992 Changed GUILTT support
  671. KeithMo 17-Dec-1992 Added InsertItem
  672. **************************************************************************/
  673. DLL_CLASS LAZY_LISTBOX: public LISTBOX
  674. {
  675. private:
  676. // Replacement of virtual LISTBOX methods
  677. //
  678. LBI * RequestLBI( const DRAWITEMSTRUCT * pdis );
  679. VOID ReleaseLBI( LBI * plbi );
  680. protected:
  681. // Called by the lazylb when it needs a new item.
  682. // Client must supply suitable implementation.
  683. //
  684. virtual LBI * OnNewItem( UINT i ) = 0;
  685. virtual VOID OnDeleteItem( LBI *plbi );
  686. // Replace control-window implementation
  687. //
  688. virtual APIERR CD_Guiltt( INT ilb, NLS_STR * pnlsOut );
  689. public:
  690. LAZY_LISTBOX( OWNER_WINDOW * pwnd, CID cid,
  691. BOOL fReadOnly = FALSE,
  692. enum FontType font = FONT_DEFAULT );
  693. LAZY_LISTBOX( OWNER_WINDOW * powin, CID cid,
  694. XYPOINT xy, XYDIMENSION dxy,
  695. ULONG flStyle,
  696. BOOL fReadOnly = FALSE,
  697. enum FontType font = FONT_DEFAULT );
  698. // Sets and resets the number of elements in the listbox
  699. //
  700. VOID SetCount( UINT cvlbi );
  701. INT InsertItem( INT i = -1 )
  702. { return InsertItemData( i, NULL ); }
  703. };
  704. #endif // WIN32
  705. /**********************************************************************
  706. NAME: BLT_LISTBOX_HAW
  707. SYNOPSIS: BLT listbox control class with HAW-for-Hawaii support.
  708. Listboxes do not have to inherit from BLT_LISTBOX_HAW
  709. to have HAW-for-Hawaii support, but it does take care
  710. of creating the HAW_FOR_HAWAII_INFO object and
  711. redefining CD_Char() appropriately. The LBIs must
  712. still support Compare_HAWforHawaii.
  713. INTERFACE: BLT_LISTBOX_HAW() - constructor
  714. CD_Char - Standard CD_Char handler for
  715. listboxes with HAW-for-Hawaii functionality.
  716. PARENT: BLT_LISTBOX
  717. HISTORY:
  718. jonn 11-Aug-1992 HAW-for-Hawaii for other LBs
  719. **********************************************************************/
  720. DLL_CLASS BLT_LISTBOX_HAW : public BLT_LISTBOX
  721. {
  722. private:
  723. HAW_FOR_HAWAII_INFO _hawinfo;
  724. protected:
  725. // Replacement of virtual CONTROL_WINDOW methods
  726. //
  727. virtual INT CD_Char( WCHAR wch, USHORT nLastPos );
  728. public:
  729. BLT_LISTBOX_HAW( OWNER_WINDOW * powin, CID cid,
  730. BOOL fReadOnly = FALSE,
  731. enum FontType font = FONT_DEFAULT,
  732. BOOL fIsCombo = FALSE );
  733. BLT_LISTBOX_HAW( OWNER_WINDOW * powin, CID cid,
  734. XYPOINT xy, XYDIMENSION dxy,
  735. ULONG flStyle,
  736. BOOL fReadOnly = FALSE,
  737. enum FontType font = FONT_DEFAULT,
  738. BOOL fIsCombo = FALSE );
  739. };
  740. // The following macro is used by BLT_LISTBOX subclasses to easily implement
  741. // a new QueryItem call, which returns a different type than LBI *.
  742. //
  743. // Usage:
  744. // In public section of class declaration, put
  745. // DECLARE_LB_QUERY_ITEM( type )
  746. // where 'type' is a class derived from LBI.
  747. //
  748. // Notes:
  749. // The macro, nor the compiler, can check if 'type' is indeed a
  750. // type derived from LBI.
  751. //
  752. // As a reminder, despite of the return code from the new QueryItem
  753. // method, BLT does not guarantee that the listbox will only contain
  754. // 'type' LBI items.
  755. //
  756. // In spite of its name, the macro both declares and defines the
  757. // derived inline QueryItem method.
  758. #define DECLARE_LB_QUERY_ITEM( type ) \
  759. type * QueryItem() const \
  760. { return (type *)BLT_LISTBOX::QueryItem(); } \
  761. type * QueryItem( INT i ) const \
  762. { return (type *)BLT_LISTBOX::QueryItem( i ); }
  763. #endif // _BLTLB_HXX_ - end of file