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.

235 lines
7.9 KiB

  1. /* @doc INTERNAL
  2. *
  3. * @module _CBHOST.H Combobox Host for Window's Rich Edit Control |
  4. *
  5. *
  6. * Original Author: <nl>
  7. * Jerry Kim
  8. *
  9. * History: <nl>
  10. * 01/30/98 v-jerrki created
  11. */
  12. #ifndef _CBHOST_H
  13. #define _CBHOST_H
  14. #include "_host.h"
  15. #define CB_LISTBOXID 1000
  16. #define CB_EDITBOXID 1001
  17. #define ITEM_MSG_DRAWLIST 1
  18. #define ITEM_MSG_DRAWCOMBO 2
  19. #define ITEM_MSG_DELETE 3
  20. class CCmbBxWinHost : public CTxtWinHost
  21. {
  22. friend LRESULT CALLBACK RichComboBoxWndProc(HWND, UINT, WPARAM, LPARAM);
  23. public:
  24. typedef enum { // enumeration determining type of combo box
  25. kSimple = 1,
  26. kDropDown = 2,
  27. kDropDownList = 3
  28. } Combotype;
  29. #ifndef ACCESSIBILITY
  30. public:
  31. // -----------------------------
  32. // IUnknown interface
  33. // -----------------------------
  34. virtual HRESULT WINAPI QueryInterface(REFIID riid, void **ppvObject);
  35. #endif
  36. public:
  37. unsigned int _fRightAlign:1; // Determines if the combo box should be right aligned
  38. unsigned int _fListVisible:1; // Determines if list is visible
  39. unsigned int _fOwnerDraw:1; // owner draw combo box
  40. unsigned int _fFocus:1; // do we have the focus?
  41. unsigned int _fMousedown:1; // if the left button was down
  42. unsigned int _fVisible:1; // window is visible
  43. unsigned int _fEnabled:1; // window is enabled
  44. unsigned int _fNoIntegralHeight:1; // no integral height
  45. unsigned int _fCapture:1; // determines if the combo box has mouse cursor captured or not
  46. unsigned int _fResizing:1; // flag to indicate we are resizing the window
  47. unsigned int _fExtendedUI:1; // flag indicating if extended ui is used
  48. unsigned int _fLBCBMessage:1; // flag indicating the message is LBCB_TRACKING
  49. unsigned int _fIgnoreChange:1; // flag indicating there was an internal change of text in
  50. // the edit control
  51. unsigned int _fIgnoreUpdate:1; // flag indicating if we should ignore the update flag, we need
  52. // this flag because there will be cases where updateWindow is
  53. // needed but we don't want to fire the notification
  54. HWND _hwndList; // window handle of listbox
  55. HCURSOR _hcurOld; // handle to the mouse cursor
  56. protected:
  57. RECT _rcWindow; // rect of window which the combo box was created with
  58. RECT _rcButton; // rect of button
  59. RECT _rcList; // rect of listbox
  60. // we have to have a minimum inset for either the right or left
  61. // to account for the button for the combo box
  62. int _dxRInset; // minimum right inset
  63. int _dxLInset; // minimum left inset
  64. int _dxROffset; // indents for right and left these values should be used
  65. int _dxLOffset; // with _dxRInset/_dxLInset to properly calculate the indents
  66. int _dyFont; // Height of the current font, may not necessarily be the system font
  67. int _dyEdit; // height of items
  68. int _cyCombo; // Height of the combo box
  69. int _cxCombo; // Width of the combo box
  70. int _cyList; // Height of the listbox
  71. long _nCursor; // last selected cursor -2 by default
  72. BOOL _bSelOk; // used to help in determining what kind of notification to give
  73. UINT _idCtrl; // ID of control
  74. Combotype _cbType; // current combo box style
  75. CLstBxWinHost* _plbHost; // pointer to listbox host
  76. protected:
  77. // Draws the combo button
  78. void DrawButton(HDC hdc, BOOL bDown);
  79. // Sets the edit controls text to item of the list box
  80. void AutoUpdateEdit(int i);
  81. // Hilite the edit control
  82. void HiliteEdit(BOOL bSelect);
  83. // resizes the list box
  84. void SetDropSize(RECT* prc);
  85. // set the edit size
  86. void SetSizeEdit(int nLeft, int nTop, int nRight, int nBottom);
  87. public:
  88. // Constructor / Destructor
  89. CCmbBxWinHost();
  90. virtual ~CCmbBxWinHost();
  91. // initialization function
  92. virtual BOOL Init(HWND, const CREATESTRUCT *);
  93. // Window creation/destruction
  94. static LRESULT OnNCCreate(HWND hwnd, const CREATESTRUCT *pcs);
  95. static void OnNCDestroy(CCmbBxWinHost *ped);
  96. virtual LRESULT OnCreate(const CREATESTRUCT *pcs);
  97. // Edit control Text helper functions
  98. LRESULT GetEditText(LPTSTR szStr, int nSize);
  99. LRESULT GetTextLength();
  100. // Draws the focus rect for the edit control
  101. void DrawEditFocus(HDC);
  102. // Sets the text in the edit control to the text of the current item in the
  103. // list box
  104. void UpdateEditBox();
  105. // selects the item which has the same text string as the edit control
  106. int UpdateListBox(BOOL);
  107. // hides the listbox
  108. BOOL HideListBox(BOOL, BOOL);
  109. // shows the list box
  110. void ShowListBox(BOOL);
  111. // Used as a way for the listbox to communicate to the combo box about a selection
  112. void SetSelectionInfo(BOOL bOk, int nIdx);
  113. // Update the window but don't send the notification
  114. void UpdateCbWindow()
  115. {
  116. _fIgnoreUpdate = 1;
  117. TxViewChange(TRUE);
  118. _fIgnoreUpdate = 0;
  119. }
  120. /////////////////////////////// message handlers /////////////////////////////////
  121. // Richedit message
  122. LRESULT OnSetTextEx(WPARAM wparam, LPARAM lparam);
  123. // Keyboard messages
  124. virtual LRESULT OnKeyDown(WORD vKey, DWORD dwFlags);
  125. virtual LRESULT OnChar(WORD vKey, DWORD dwFlags);
  126. virtual LRESULT OnSyskeyDown(WORD vKey, DWORD dwFlags);
  127. // mouse messages
  128. LRESULT OnLButtonUp(WPARAM wparam, LPARAM lparam);
  129. LRESULT OnMouseMove(WPARAM wparam, LPARAM lparam);
  130. LRESULT OnMouseWheel(WPARAM wparam, LPARAM lparam);
  131. LRESULT OnSetCursor(WPARAM wparam, LPARAM lparam);
  132. LRESULT OnLButtonDown(WPARAM wparam, LPARAM lparam);
  133. // focus messages
  134. LRESULT OnSetFocus(WPARAM wparam, LPARAM lparam);
  135. LRESULT OnKillFocus(WPARAM wparam, LPARAM lparam);
  136. LRESULT OnCaptureChanged(WPARAM wparam, LPARAM lparam);
  137. // window messages
  138. LRESULT OnPaint(WPARAM, LPARAM);
  139. HRESULT OnCommand(WPARAM wparam, LPARAM lparam);
  140. LRESULT OnSize(WPARAM wparam, LPARAM lparam);
  141. LRESULT OnGetDlgCode(WPARAM wparam, LPARAM lparam);
  142. LRESULT OnEnable(WPARAM wparam, LPARAM lparam);
  143. //@cmember Notify host of events
  144. virtual HRESULT TxNotify(DWORD iNotify, void *pv);
  145. //@cmember Changes the mouse cursor
  146. virtual HCURSOR TxSetCursor2(HCURSOR hcur, BOOL bText)
  147. { return (hcur) ? ::SetCursor(hcur) : ::GetCursor();}
  148. ///////////////////////// combo box message handlers ////////////////////////////
  149. // Calculates the rect's and height's of all the controls
  150. BOOL CbCalcControlRects(RECT* prc, BOOL bCalcChange);
  151. // Retrieves the item height for either the edit or list box
  152. LRESULT CbGetItemHeight(BOOL bEdit);
  153. // sets the item height for either the edit or list box
  154. LRESULT CbSetItemHeight(BOOL bEdit, int nHeight);
  155. // sets extendedUI mode
  156. LRESULT CbSetExtendedUI(BOOL bExtendedUI);
  157. // retrieves the current extendedUI mode
  158. LRESULT CbGetExtendedUI() const {return _fExtendedUI;}
  159. // forwards the WM_DRAWITEM, WM_DELETEITEM messages to the parent window
  160. LRESULT CbMessageItemHandler(HDC, int, WPARAM, LPARAM);
  161. #ifndef NOACCESSIBILITY
  162. ////////////////////////// IAccessible Methods /////////////////////////////////
  163. HRESULT InitTypeInfo();
  164. STDMETHOD(get_accParent)(IDispatch **ppdispParent);
  165. STDMETHOD(get_accChildCount)(long *pcountChildren);
  166. STDMETHOD(get_accChild)(VARIANT varChild, IDispatch **ppdispChild);
  167. STDMETHOD(get_accName)(VARIANT varChild, BSTR *pszName);
  168. STDMETHOD(get_accValue)(VARIANT varChild, BSTR *pszValue);
  169. STDMETHOD(get_accRole)(VARIANT varChild, VARIANT *pvarRole);
  170. STDMETHOD(get_accState)(VARIANT varChild, VARIANT *pvarState);
  171. STDMETHOD(get_accKeyboardShortcut)(VARIANT varChild, BSTR *pszKeyboardShortcut);
  172. STDMETHOD(get_accFocus)(VARIANT *pvarChild);
  173. STDMETHOD(get_accSelection)(VARIANT *pvarChildren);
  174. STDMETHOD(get_accDefaultAction)(VARIANT varChild, BSTR *pszDefaultAction);
  175. STDMETHOD(accSelect)(long flagsSelect, VARIANT varChild);
  176. STDMETHOD(accLocation)(long *pxLeft, long *pyTop, long *pcxWidth, long *pcyHeight, VARIANT varChild);
  177. STDMETHOD(accNavigate)(long navDir, VARIANT varStart, VARIANT *pvarEndUpAt);
  178. STDMETHOD(accHitTest)(long xLeft, long yTop, VARIANT *pvarChild);
  179. STDMETHOD(accDoDefaultAction)(VARIANT varChild);
  180. #endif // NOACCESSIBILITY
  181. };
  182. #endif // _CBHOST_H