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.

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