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.

802 lines
26 KiB

  1. /* @doc INTERNAL
  2. *
  3. * @module _HOST.H Text Host for Window's Rich Edit Control |
  4. *
  5. *
  6. * Original Author: <nl>
  7. * Christian Fortini
  8. * Murray Sargent
  9. *
  10. * History: <nl>
  11. * 8/1/95 ricksa Revised interface definition
  12. */
  13. #ifndef _HOST_H
  14. #define _HOST_H
  15. #include "textserv.h"
  16. #include "textsrv2.h"
  17. #include "dynarray.hxx"
  18. #ifndef NOACCESSIBILITY
  19. // UNDONE:
  20. // Need to include this file int the project
  21. #include "oleacc.h"
  22. #endif
  23. /*
  24. * TXTEFFECT
  25. *
  26. * @enum Defines different background styles control
  27. */
  28. enum TXTEFFECT {
  29. TXTEFFECT_NONE = 0, //@emem no special backgoround effect
  30. TXTEFFECT_SUNKEN, //@emem draw a "sunken 3-D" look
  31. };
  32. // @doc EXTERNAL
  33. // ============================ CTxtWinHost ================================================
  34. // Implement the windowed version of the Plain Text control
  35. /*
  36. * CTxtWinHost
  37. *
  38. * @class Text Host for Window's Rich Edit Control implementation class
  39. *
  40. */
  41. class CTxtWinHost : public ITextHost2
  42. #ifndef NOACCESSIBILITY
  43. , public IAccessible
  44. #endif
  45. {
  46. public:
  47. HWND _hwnd; // control window
  48. HWND _hwndParent; // parent window
  49. ITextServices *_pserv; // pointer to Text Services object
  50. ULONG _crefs; // reference count
  51. // Properties
  52. DWORD _dwStyle; // style bits
  53. DWORD _dwExStyle; // extended style bits
  54. unsigned _fBorder :1; // control has border
  55. unsigned _fInBottomless :1; // inside bottomless callback
  56. unsigned _fInDialogBox :1; // control is in a dialog box
  57. unsigned _fEnableAutoWordSel :1; // enable Word style auto word selection?
  58. unsigned _fIconic :1; // control window is iconic
  59. unsigned _fHidden :1; // control window is hidden
  60. unsigned _fNotSysBkgnd :1; // not using system background color
  61. unsigned _fWindowLocked :1; // window is locked (no update)
  62. unsigned _fRegisteredForDrop :1; // whether host has registered for drop
  63. unsigned _fVisible :1; // Whether window is visible or not.
  64. unsigned _fResized :1; // resized while hidden
  65. unsigned _fDisabled :1; // Window is disabled.
  66. unsigned _fKeyMaskSet :1; // if ENM_KEYEVENTS has been set
  67. unsigned _fMouseMaskSet :1; // if ENM_MOUSEEVENTS has been set
  68. unsigned _fScrollMaskSet :1; // if ENM_SCROLLEVENTS has been set
  69. unsigned _fUseSpecialSetSel :1; // TRUE = use EM_SETSEL hack to not select
  70. // empty controls to make dialog boxes work.
  71. unsigned _fEmSetRectCalled :1; // TRUE - application called EM_SETRECT
  72. unsigned _fAccumulateDBC :1; // TRUE - need to cumulate ytes from 2 WM_CHAR msgs
  73. // we are in this mode when we receive VK_PROCESSKEY
  74. unsigned _fANSIwindow :1; // TRUE - window created as "RichEdit20A"
  75. unsigned _fTextServiceFree :1; // TRUE - Text Services freed at shutdown.
  76. COLORREF _crBackground; // background color
  77. RECT _rcViewInset; // view rect inset /r client rect
  78. HIMC _oldhimc; // previous IME Context
  79. // TODO: the following could be a two-bit field as part of the unsigned field above
  80. DWORD _usIMEMode; // mode of IME operation
  81. // either 0 or ES_SELFIME or ES_NOIME
  82. HPALETTE _hpal; // Logical palette to use.
  83. TCHAR _chPassword; // Password char. If null, no password
  84. TCHAR _chLeadByte; // use when we are in _fAccumulateDBC mode
  85. SHORT _sWidth; // Last client width given by WM_SIZE
  86. char _yInset;
  87. char _xInset;
  88. CTxtWinHost *_pnextdel;
  89. public:
  90. // Initialization
  91. virtual BOOL Init(
  92. HWND hwnd,
  93. const CREATESTRUCT *pcs,
  94. BOOL fIsAnsi,
  95. BOOL fIs10Mode);
  96. void SetScrollBarsForWmEnable(BOOL fEnable);
  97. void OnSetMargins(
  98. DWORD fwMargin,
  99. DWORD xLeft,
  100. DWORD xRight);
  101. virtual void SetScrollInfo(
  102. INT fnBar,
  103. BOOL fRedraw);
  104. // helpers
  105. HRESULT CreateTextServices();
  106. void * CreateNmhdr(UINT uiCode, LONG cb);
  107. void HostRevokeDragDrop(void);
  108. void HostRegisterDragDrop();
  109. void DrawSunkenBorder(HWND hwnd, HDC hdc);
  110. void OnSunkenWindowPosChanging(HWND hwnd, WINDOWPOS *pwndpos);
  111. LRESULT OnSize(HWND hwnd, WORD fwSizeType, int nWidth, int nHeight);
  112. virtual TXTEFFECT TxGetEffects() const;
  113. HRESULT OnTxVisibleChange(BOOL fVisible);
  114. void SetDefaultInset();
  115. BOOL IsTransparentMode()
  116. {
  117. return (_dwExStyle & WS_EX_TRANSPARENT);
  118. }
  119. // Keyboard messages
  120. virtual LRESULT OnKeyDown(WORD vKey, DWORD dwFlags);
  121. virtual LRESULT OnChar(WORD vKey, DWORD dwFlags);
  122. // System notifications
  123. virtual void OnSysColorChange();
  124. virtual LRESULT OnGetDlgCode(WPARAM wparam, LPARAM lparam);
  125. // Other messages
  126. LRESULT OnGetOptions() const;
  127. void OnSetOptions(WORD wOp, DWORD eco);
  128. void OnSetReadOnly(BOOL fReadOnly);
  129. void OnGetRect(LPRECT prc);
  130. void OnSetRect(LPRECT prc, BOOL fNewBehavior, BOOL fRedraw);
  131. public:
  132. CTxtWinHost();
  133. virtual ~CTxtWinHost();
  134. void Shutdown();
  135. // Window creation/destruction
  136. static CTxtWinHost *OnNCCreate(
  137. HWND hwnd,
  138. const CREATESTRUCT *pcs,
  139. BOOL fIsAnsi,
  140. BOOL fIs10Mode);
  141. static void OnNCDestroy(CTxtWinHost *ped);
  142. virtual LRESULT OnCreate(const CREATESTRUCT *pcs);
  143. // -----------------------------
  144. // IUnknown interface
  145. // -----------------------------
  146. virtual HRESULT WINAPI QueryInterface(REFIID riid, void **ppvObject);
  147. virtual ULONG WINAPI AddRef(void);
  148. virtual ULONG WINAPI Release(void);
  149. // -----------------------------
  150. // ITextHost interface
  151. // -----------------------------
  152. //@cmember Get the DC for the host
  153. virtual HDC TxGetDC();
  154. //@cmember Release the DC gotten from the host
  155. virtual INT TxReleaseDC(HDC hdc);
  156. //@cmember Show the scroll bar
  157. virtual BOOL TxShowScrollBar(INT fnBar, BOOL fShow);
  158. //@cmember Enable the scroll bar
  159. virtual BOOL TxEnableScrollBar (INT fuSBFlags, INT fuArrowflags);
  160. //@cmember Set the scroll range
  161. virtual BOOL TxSetScrollRange(
  162. INT fnBar,
  163. LONG nMinPos,
  164. INT nMaxPos,
  165. BOOL fRedraw);
  166. //@cmember Set the scroll position
  167. virtual BOOL TxSetScrollPos (INT fnBar, INT nPos, BOOL fRedraw);
  168. //@cmember InvalidateRect
  169. virtual void TxInvalidateRect(LPCRECT prc, BOOL fMode);
  170. //@cmember Send a WM_PAINT to the window
  171. virtual void TxViewChange(BOOL fUpdate);
  172. //@cmember Create the caret
  173. virtual BOOL TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight);
  174. //@cmember Show the caret
  175. virtual BOOL TxShowCaret(BOOL fShow);
  176. //@cmember Set the caret position
  177. virtual BOOL TxSetCaretPos(INT x, INT y);
  178. //@cmember Create a timer with the specified timeout
  179. virtual BOOL TxSetTimer(UINT idTimer, UINT uTimeout);
  180. //@cmember Destroy a timer
  181. virtual void TxKillTimer(UINT idTimer);
  182. //@cmember Scroll the content of the specified window's client area
  183. virtual void TxScrollWindowEx (
  184. INT dx,
  185. INT dy,
  186. LPCRECT lprcScroll,
  187. LPCRECT lprcClip,
  188. HRGN hrgnUpdate,
  189. LPRECT lprcUpdate,
  190. UINT fuScroll);
  191. //@cmember Get mouse capture
  192. virtual void TxSetCapture(BOOL fCapture);
  193. //@cmember Set the focus to the text window
  194. virtual void TxSetFocus();
  195. //@cmember Establish a new cursor shape
  196. virtual void TxSetCursor(HCURSOR hcur, BOOL fText);
  197. //@cmember Changes the mouse cursor
  198. virtual HCURSOR TxSetCursor2(HCURSOR hcur, BOOL bText) { return ::SetCursor(hcur);}
  199. //@cmember Notification that text services is freed
  200. virtual void TxFreeTextServicesNotification();
  201. //@cmember Converts screen coordinates of a specified point to the client coordinates
  202. virtual BOOL TxScreenToClient (LPPOINT lppt);
  203. //@cmember Converts the client coordinates of a specified point to screen coordinates
  204. virtual BOOL TxClientToScreen (LPPOINT lppt);
  205. //@cmember Request host to activate text services
  206. virtual HRESULT TxActivate( LONG * plOldState );
  207. //@cmember Request host to deactivate text services
  208. virtual HRESULT TxDeactivate( LONG lNewState );
  209. //@cmember Retrieves the coordinates of a window's client area
  210. virtual HRESULT TxGetClientRect(LPRECT prc);
  211. //@cmember Get the view rectangle relative to the inset
  212. virtual HRESULT TxGetViewInset(LPRECT prc);
  213. //@cmember Get the default character format for the text
  214. virtual HRESULT TxGetCharFormat(const CHARFORMAT **ppCF );
  215. //@cmember Get the default paragraph format for the text
  216. virtual HRESULT TxGetParaFormat(const PARAFORMAT **ppPF);
  217. //@cmember Get the background color for the window
  218. virtual COLORREF TxGetSysColor(int nIndex);
  219. //@cmember Get the background (either opaque or transparent)
  220. virtual HRESULT TxGetBackStyle(TXTBACKSTYLE *pstyle);
  221. //@cmember Get the maximum length for the text
  222. virtual HRESULT TxGetMaxLength(DWORD *plength);
  223. //@cmember Get the bits representing requested scroll bars for the window
  224. virtual HRESULT TxGetScrollBars(DWORD *pdwScrollBar);
  225. //@cmember Get the character to display for password input
  226. virtual HRESULT TxGetPasswordChar(TCHAR *pch);
  227. //@cmember Get the accelerator character
  228. virtual HRESULT TxGetAcceleratorPos(LONG *pcp);
  229. //@cmember Get the native size
  230. virtual HRESULT TxGetExtent(LPSIZEL lpExtent);
  231. //@cmember Notify host that default character format has changed
  232. virtual HRESULT OnTxCharFormatChange (const CHARFORMAT * pcf);
  233. //@cmember Notify host that default paragraph format has changed
  234. virtual HRESULT OnTxParaFormatChange (const PARAFORMAT * ppf);
  235. //@cmember Bulk access to bit properties
  236. virtual HRESULT TxGetPropertyBits(DWORD dwMask, DWORD *pdwBits);
  237. //@cmember Notify host of events
  238. virtual HRESULT TxNotify(DWORD iNotify, void *pv);
  239. // FE Support Routines for handling the Input Method Context
  240. //#ifdef WIN95_IME
  241. virtual HIMC TxImmGetContext(void);
  242. virtual void TxImmReleaseContext(HIMC himc);
  243. //#endif
  244. //@cmember Returns HIMETRIC size of the control bar.
  245. virtual HRESULT TxGetSelectionBarWidth (LONG *lSelBarWidth);
  246. // ITextHost2 methods
  247. virtual BOOL TxIsDoubleClickPending();
  248. virtual HRESULT TxGetWindow(HWND *phwnd);
  249. virtual HRESULT TxSetForegroundWindow();
  250. virtual HPALETTE TxGetPalette();
  251. virtual HRESULT TxGetFEFlags(LONG *pFlags);
  252. virtual HRESULT TxGetEditStyle(DWORD dwItem, DWORD *pdwData);
  253. virtual HRESULT TxGetWindowStyles(DWORD *pdwStyle, DWORD *pdwExStyle);
  254. #ifndef NOACCESSIBILITY
  255. ITypeInfo *_pTypeInfo;
  256. virtual HRESULT InitTypeInfo() {return E_NOTIMPL;}
  257. ////////////////////////// IDispatch Methods /////////////////////////////////
  258. STDMETHOD(GetTypeInfoCount)(UINT __RPC_FAR *pctinfo);
  259. STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo);
  260. STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR __RPC_FAR *rgszNames, UINT cNames,
  261. LCID lcid, DISPID __RPC_FAR *rgDispId);
  262. STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pDispParams,
  263. VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr);
  264. ////////////////////////// IAccessible Methods /////////////////////////////////
  265. STDMETHOD(get_accParent)(IDispatch **ppdispParent) {return S_FALSE;}
  266. STDMETHOD(get_accChildCount)(long *pcountChildren) {return S_FALSE;}
  267. STDMETHOD(get_accChild)(VARIANT varChild, IDispatch **ppdispChild) {return S_FALSE;}
  268. STDMETHOD(get_accName)(VARIANT varChild, BSTR *pszName) {return S_FALSE;}
  269. STDMETHOD(get_accValue)(VARIANT varChild, BSTR *pszValue) {return S_FALSE;}
  270. STDMETHOD(get_accDescription)(VARIANT varChild, BSTR *pszDescription) {return S_FALSE;}
  271. STDMETHOD(get_accRole)(VARIANT varChild, VARIANT *pvarRole) {return S_FALSE;}
  272. STDMETHOD(get_accState)(VARIANT varChild, VARIANT *pvarState) {return S_FALSE;}
  273. STDMETHOD(get_accHelp)(VARIANT varChild, BSTR *pszHelp) {return S_FALSE;}
  274. STDMETHOD(get_accHelpTopic)(BSTR *pszHelpFile, VARIANT varChild, long *pidTopic) {return S_FALSE;}
  275. STDMETHOD(get_accKeyboardShortcut)(VARIANT varChild, BSTR *pszKeyboardShortcut) {return S_FALSE;}
  276. STDMETHOD(get_accFocus)(VARIANT *pvarChild) {return S_FALSE;}
  277. STDMETHOD(get_accSelection)(VARIANT *pvarChildren) {return S_FALSE;}
  278. STDMETHOD(get_accDefaultAction)(VARIANT varChild, BSTR *pszDefaultAction) {return S_FALSE;}
  279. STDMETHOD(accSelect)(long flagsSelect, VARIANT varChild) {return S_FALSE;}
  280. STDMETHOD(accLocation)(long *pxLeft, long *pyTop, long *pcxWidth, long *pcyHeight, VARIANT varChild)
  281. {return S_FALSE;}
  282. STDMETHOD(accNavigate)(long navDir, VARIANT varStart, VARIANT *pvarEndUpAt) {return S_FALSE;}
  283. STDMETHOD(accHitTest)(long xLeft, long yTop, VARIANT *pvarChild) {return S_FALSE;}
  284. STDMETHOD(accDoDefaultAction)(VARIANT varChild) {return S_FALSE;}
  285. STDMETHOD(put_accName)(VARIANT varChild, BSTR szName) {return S_FALSE;}
  286. STDMETHOD(put_accValue)(VARIANT varChild, BSTR szValue) {return S_FALSE;}
  287. #endif // NOACCESSIBILITY
  288. };
  289. // Work around some client's (MSN chat) problems with host deletions.
  290. void DeleteDanglingHosts();
  291. #define LBS_COMBOBOX 0x8000L
  292. #define LBCB_TRACKING WM_USER+2
  293. #define LBCBM_PREPARE 1
  294. #define LBCBM_START 2
  295. #define LBCBM_END 3
  296. // mask for LBCBM messages
  297. #define LBCBM_PREPARE_SETFOCUS 1
  298. #define LBCBM_PREPARE_SAVECURSOR 2
  299. class CLbData
  300. {
  301. public:
  302. unsigned _fSelected :1; // indicates if the item has been selected
  303. long _dwData; // Item data
  304. };
  305. struct CHARSORTINFO
  306. {
  307. WCHAR* str;
  308. int sz;
  309. };
  310. #define CHECKNOERROR(x) if (NOERROR != x) goto CleanExit
  311. class CCmbBxWinHost;
  312. class CLstBxWinHost : public CTxtWinHost
  313. {
  314. public:
  315. typedef enum {
  316. //kNoSel = 0, //LBS_NOSEL
  317. kSingle = 1, //LBS_SIMPLE
  318. kMultiple = 2, //LBS_MULTIPLESEL
  319. kExtended = 3, //LBS_EXTENDEDSEL
  320. kCombo = 8 //Combo box
  321. } Listtype;
  322. #ifndef ACCESSIBILITY
  323. public:
  324. // -----------------------------
  325. // IUnknown interface
  326. // -----------------------------
  327. virtual HRESULT WINAPI QueryInterface(REFIID riid, void **ppvObject);
  328. #endif
  329. private:
  330. short _cWheelDelta; //contains the delta values for mouse wheels
  331. int _nTopIdx; //the item index at the top of list
  332. //Do not touch this unless you know what you are doing!!
  333. public:
  334. unsigned int _fOwnerDraw :1; //indicates if list box is owner draw
  335. unsigned int _fSort :1; //determines if the list should be sorted
  336. unsigned int _fNoIntegralHeight :1; //indicates if the size of the listbox should be readjusted according
  337. //how many items can be fully displayed
  338. unsigned int _fDisableScroll:1; //indicates if scroll bar should be displayed at all times
  339. unsigned int _fNotify :1; //notifies parent dialog of activities done in list box.
  340. unsigned int _fSingleSel :1; // Indicates the list box is a single selection item
  341. unsigned int _fMouseDown :1; // Indicates if the mouse is down
  342. unsigned int _fFocus :1; // determines if the control has focus
  343. unsigned int _fCapture :1; // determines if mouse capture is set
  344. unsigned int _fSearching :1; // indicates if we are in type searching mode
  345. unsigned int _fDblClick :1; // flag indicating double click was received
  346. unsigned int _fNoResize :1; // internal flag to tell us if we should ignore resize messages
  347. unsigned int _fNotifyWinEvt :1; // Indicates only Notify Win Event (ACCESSIBILITY use)
  348. Listtype _fLstType; //indicates current type of list box or combo box
  349. #ifndef NOACCESSIBILITY
  350. DWORD _dwWinEvent; // Win Event code (ACCESSIBILITY use)
  351. int _nAccessibleIdx; // Index (ACCESSIBILITY use)
  352. #endif
  353. protected:
  354. UINT _idCtrl; // control's unique id
  355. COLORREF _crSelFore; //Selected Forground color
  356. COLORREF _crSelBack; //Selected Background color
  357. COLORREF _crDefFore; //Default Forground color
  358. COLORREF _crDefBack; //Default Background color
  359. RECT _rcViewport; //drawable area for the items
  360. long _nyFont; // Font pixel size in y direction
  361. long _nyItem; //Height of the items in the list box
  362. int _nViewSize; //number of items which is viewable at the same time
  363. int _nCount; //Number of items in the list box
  364. int _nAnchor; //Indicates the top selected item
  365. //NOTE:
  366. // In a single sel list box only _nCursor is used
  367. int _nCursor; //Indicates the current item which has the focus
  368. int _nOldCursor; //The old cursor position for combo boxes
  369. int _stvidx; // This is for a hack to workaround a bug when the display
  370. // is frozen ITextRange doesn't cache to scroll change
  371. int _nidxSearch; // Number of characters in search string
  372. WCHAR* _pwszSearch; // pointer to allocated string
  373. CDynamicArray<CLbData> _rgData; // Array/link list of the item data
  374. LPARAM _nPrevMousePos; // Last position from Mousemove message
  375. CCmbBxWinHost* _pcbHost; // pointer to combo box win host
  376. protected:
  377. // Changes the background color
  378. BOOL SetColors(DWORD, DWORD, long, long);
  379. // Makes sure the top item is displayed at the top of the view
  380. BOOL ScrollToView(long nTop);
  381. // Sets the requested item to be at the top of the viewable space
  382. BOOL SetTopViewableItem(long);
  383. // Searches if a given index qualifies as a match
  384. BOOL FindString(long idx, LPCTSTR szSearch, BOOL bExact);
  385. // helper function for the OnMouseMove function
  386. void MouseMoveHelper(int, BOOL);
  387. // Set the height of each item in the list box in the given range
  388. int SetItemsHeight(int,BOOL);
  389. public:
  390. CLstBxWinHost();
  391. virtual ~CLstBxWinHost();
  392. void ResizeInset();
  393. // initialization function
  394. virtual BOOL Init(HWND, const CREATESTRUCT *);
  395. // calculates the height of each item
  396. void UpdateViewArea();
  397. // Window creation/destruction
  398. static LRESULT OnNCCreate(HWND hwnd, const CREATESTRUCT *pcs);
  399. static void OnNCDestroy(CLstBxWinHost *ped);
  400. virtual LRESULT OnCreate(const CREATESTRUCT *pcs);
  401. ////////////////////////// helper functions ////////////////////////////////////
  402. static wchar_t * wcscat(wchar_t * dst, const wchar_t * src)
  403. {
  404. wchar_t * cp = dst;
  405. while(*cp) cp++; // find null character in first string
  406. while( *cp++ = *src++ ); // Copy src over dst
  407. return( dst );
  408. }
  409. // given a source string the destination string contains a sorted version
  410. // separated by <CR>
  411. int SortInsertList(WCHAR* pszDst, WCHAR* pszSrc);
  412. // Sets the indents for the listbox
  413. BOOL SetListIndent(int fLeftIndent);
  414. // Equivalent to CompareString except int is a reference to an item index
  415. int CompareIndex(LPCTSTR szInsert, int nIndex);
  416. // Returns the position a string should be in a sorted list
  417. int GetSortedPosition(LPCTSTR, int, int);
  418. // Updates the system color settings
  419. void UpdateSysColors();
  420. // Inits search string
  421. void InitSearch();
  422. // Prevents the window from updating itself
  423. inline void Freeze();
  424. // Frees the window to update itself
  425. inline void Unfreeze();
  426. // Retrieves the range give the top and bottom index
  427. BOOL GetRange(long, long, ITextRange**);
  428. // Inserts the string at the requested index
  429. BOOL InsertString(long, LPCTSTR);
  430. // Removes the string from the listbox
  431. BOOL RemoveString(long, long);
  432. // Retrieves the string at the requested index
  433. long GetString(long, PWCHAR);
  434. // Deselects all the items in the list box
  435. BOOL ResetContent();
  436. // Retrieves the nearest valid item from a given point
  437. int GetItemFromPoint(const POINT *);
  438. // Tells if a given points is within the listbox's rect
  439. BOOL PointInRect(const POINT *);
  440. // Sets the cursor position and draws the rect
  441. void SetCursor(HDC, int, BOOL);
  442. // Recalulates the height so no partial text will be displayed
  443. BOOL RecalcHeight(int, int);
  444. // returns of listbox is single selection
  445. inline BOOL IsSingleSelection() const {return _fSingleSel;}
  446. // Returns the current top index
  447. inline long GetTopIndex() const { return _nTopIdx;}
  448. // Checks if the mouse has been captured
  449. inline BOOL GetCapture() const { return _fCapture;}
  450. // return the item count
  451. inline int GetCount() const {return _nCount;}
  452. // returns the anchor position
  453. inline int GetAnchor() const {return _nAnchor;}
  454. // returns the cursor position
  455. inline int GetCursor() const {return _nCursor;}
  456. // returns the viewsize
  457. inline int GetViewSize() const {return _nViewSize;}
  458. // returns the font height
  459. inline int GetFontHeight() const {return _nyFont;}
  460. // returns the item height
  461. inline int GetItemHeight() const {return _nyItem;}
  462. // returns the displays freeze count
  463. inline short FreezeCount() const;
  464. // initialize mouse wheel variable to zero
  465. inline void InitWheelDelta() { _cWheelDelta = 0;}
  466. inline BOOL IsItemViewable(long x) const
  467. {
  468. return (GetTopIndex() <= x && (x - GetTopIndex()) * _nyItem < _rcViewport.bottom);
  469. }
  470. // Determines if index is selected
  471. inline BOOL IsSelected(long nIdx)
  472. {
  473. #ifdef _DEBUG
  474. Assert(nIdx < -1 || _nCount <= nIdx);
  475. if (nIdx < -1 || _nCount <= nIdx) return FALSE;
  476. #endif
  477. if (nIdx < 0)
  478. return FALSE;
  479. else
  480. return _rgData[nIdx]._fSelected;
  481. }
  482. // Returns the ItemData of a given index
  483. inline long GetData(long nIdx)
  484. {
  485. return _rgData.Get(nIdx)._dwData;
  486. }
  487. // Returns TRUE if point is within the client area of listbox
  488. /////////////////////ListBox Message Handling functions /////////////////////////
  489. // Set the height of the items in the list box
  490. BOOL LbSetItemHeight(int nHeight);
  491. // Set the selection state for the items in the range
  492. BOOL LbSetSelection(long, long, int, long, long);
  493. // Sets the requested item to be at the top of the list box
  494. long LbSetTopIndex(long);
  495. // Makes sure the requested index is visible
  496. BOOL LbShowIndex(long, BOOL);
  497. // Retrieves the index give a string and starting position
  498. long LbFindString(long, LPCTSTR, BOOL);
  499. // Inserts the string at the requested location
  500. long LbInsertString(long, LPCTSTR);
  501. // Range to delete
  502. long LbDeleteString(long, long);
  503. // Sets the Item data
  504. void LbSetItemData(long, long, long);
  505. // returns the item rect of a given index
  506. BOOL LbGetItemRect(int, RECT*);
  507. // Notifies parent when an item is deleted
  508. void LbDeleteItemNotify(int, int);
  509. // Owner draw function
  510. void LbDrawItemNotify(HDC, int, UINT, UINT);
  511. // used to insert a list of strings rather than individually
  512. int LbBatchInsert(WCHAR* psz);
  513. ///////////////////////// Message Map functions //////////////////////////////
  514. // if subclassed then make these functions virtual
  515. // Handles the WM_MOUSEMOVE message
  516. LRESULT OnMouseWheel(WPARAM, LPARAM);
  517. // Handles the WM_LBUTTONDOWN message
  518. LRESULT OnLButtonDown(WPARAM wparam, LPARAM lparam);
  519. // Handles the WM_MOUSEMOVE message
  520. LRESULT OnMouseMove(WPARAM, LPARAM);
  521. // Handles the WM_LBUTTONUP message
  522. LRESULT OnLButtonUp(WPARAM, LPARAM, int ff = 0);
  523. // Handles the WM_VSCROLL message
  524. LRESULT OnVScroll(WPARAM, LPARAM);
  525. // Handles the WM_TIMER message
  526. LRESULT OnTimer(WPARAM, LPARAM);
  527. // Handles the WM_KEYDOWN message
  528. LRESULT OnKeyDown(WPARAM, LPARAM, int);
  529. // Hanldes the WM_CAPTURECHANGED message
  530. LRESULT OnCaptureChanged(WPARAM, LPARAM);
  531. // Handles the WM_CHAR message
  532. virtual LRESULT OnChar(WORD, DWORD);
  533. // Handles the WM_SYSCOLORCHANGE message
  534. virtual void OnSysColorChange();
  535. // Handles the WM_SETCURSOR message
  536. LRESULT OnSetCursor();
  537. //////////////////////////// overridden Tx fn's ////////////////////////////////
  538. //@cmember Get the bits representing requested scroll bars for the window
  539. virtual HRESULT TxGetScrollBars(DWORD *pdwScrollBar);
  540. //@cmember Bulk access to bit properties
  541. virtual HRESULT TxGetPropertyBits(DWORD, DWORD *);
  542. virtual TXTEFFECT TxGetEffects() const;
  543. //@cmember Notify host of events
  544. virtual HRESULT TxNotify(DWORD iNotify, void *pv);
  545. //@cmember Show the scroll bar
  546. virtual BOOL TxShowScrollBar(INT fnBar, BOOL fShow);
  547. //@cmember Enable the scroll bar
  548. virtual BOOL TxEnableScrollBar (INT fuSBFlags, INT fuArrowflags);
  549. //@cmember Show the caret
  550. virtual BOOL TxShowCaret(BOOL fShow) {return TRUE;}
  551. //@cmember Create the caret
  552. virtual BOOL TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight) {return FALSE;}
  553. //@cmember Set the scroll range
  554. virtual void SetScrollInfo(INT, BOOL);
  555. /////////////////////////// Combobox helper fn's ///////////////////////////////
  556. void OnCBTracking(WPARAM, LPARAM);
  557. static int QSort(CHARSORTINFO rg[], int nStart, int nEnd);
  558. #ifndef NOACCESSIBILITY
  559. HRESULT InitTypeInfo();
  560. ////////////////////////// IAccessible Methods /////////////////////////////////
  561. STDMETHOD(get_accParent)(IDispatch **ppdispParent);
  562. STDMETHOD(get_accName)(VARIANT varChild, BSTR *pszName);
  563. STDMETHOD(get_accChildCount)(long *pcountChildren);
  564. STDMETHOD(get_accRole)(VARIANT varChild, VARIANT *pvarRole);
  565. STDMETHOD(get_accState)(VARIANT varChild, VARIANT *pvarState);
  566. STDMETHOD(get_accKeyboardShortcut)(VARIANT varChild, BSTR *pszKeyboardShortcut);
  567. STDMETHOD(get_accFocus)(VARIANT *pvarChild);
  568. STDMETHOD(get_accSelection)(VARIANT *pvarChildren);
  569. STDMETHOD(get_accDefaultAction)(VARIANT varChild, BSTR *pszDefaultAction);
  570. STDMETHOD(accSelect)(long flagsSelect, VARIANT varChild);
  571. STDMETHOD(accLocation)(long *pxLeft, long *pyTop, long *pcxWidth, long *pcyHeight, VARIANT varChild);
  572. STDMETHOD(accNavigate)(long navDir, VARIANT varStart, VARIANT *pvarEndUpAt);
  573. STDMETHOD(accHitTest)(long xLeft, long yTop, VARIANT *pvarChild);
  574. STDMETHOD(accDoDefaultAction)(VARIANT varChild);
  575. #endif // NOACCESSIBILITY
  576. };
  577. #ifndef NOACCESSIBILITY
  578. // --------------------------------------------------------------------------
  579. //
  580. // Although CListBoxSelection() is based off of IEnumVARIANT.
  581. // It will hand back the proper IDs so you can pass them to the real
  582. // listbox parent object.
  583. //
  584. // --------------------------------------------------------------------------
  585. class CListBoxSelection : public IEnumVARIANT
  586. {
  587. public:
  588. // IUnknown
  589. virtual STDMETHODIMP QueryInterface(REFIID, void**);
  590. virtual STDMETHODIMP_(ULONG) AddRef(void);
  591. virtual STDMETHODIMP_(ULONG) Release(void);
  592. // IEnumVARIANT
  593. virtual STDMETHODIMP Next(ULONG celt, VARIANT* rgvar, ULONG * pceltFetched);
  594. virtual STDMETHODIMP Skip(ULONG celt);
  595. virtual STDMETHODIMP Reset(void);
  596. virtual STDMETHODIMP Clone(IEnumVARIANT ** ppenum);
  597. CListBoxSelection(int, int, LPINT);
  598. ~CListBoxSelection();
  599. protected:
  600. int _cRef;
  601. int _idChildCur;
  602. int _cSel;
  603. LPINT _piSel;
  604. };
  605. #endif
  606. #ifndef DEBUG
  607. #define AttCheckRunTotals(_fCF)
  608. #define AttCheckPFRuns(_fCF)
  609. #endif
  610. #define ECO_STYLES (ECO_AUTOVSCROLL | ECO_AUTOHSCROLL | ECO_NOHIDESEL | \
  611. ECO_READONLY | ECO_WANTRETURN | ECO_SAVESEL | \
  612. ECO_SELECTIONBAR | ES_NOIME | ES_SELFIME )
  613. #endif // _HOST_H