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.

282 lines
9.8 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. #ifndef NOWINDOWHOSTS
  15. #include "_host.h"
  16. #define CB_LISTBOXID 1000
  17. #define CB_EDITBOXID 1001
  18. enum ITEMMSG {
  19. ITEM_MSG_DRAWLIST = 1,
  20. ITEM_MSG_DRAWCOMBO,
  21. ITEM_MSG_DELETE,
  22. ITEM_MSG_MEASUREITEM,
  23. };
  24. extern "C" LRESULT CALLBACK RichComboBoxWndProc(HWND, UINT, WPARAM, LPARAM);
  25. class CCmbBxWinHost : public CTxtWinHost
  26. {
  27. friend LRESULT CALLBACK RichComboBoxWndProc(HWND, UINT, WPARAM, LPARAM);
  28. public:
  29. typedef enum { // enumeration determining type of combo box
  30. kSimple = 1,
  31. kDropDown = 2,
  32. kDropDownList = 3
  33. } Combotype;
  34. #ifndef NOACCESSIBILITY
  35. //////////////////////// Combobox IAccessible Methods //////////////////////////////
  36. // COMBOBOXES
  37. #define INDEX_COMBOBOX 0
  38. #define INDEX_COMBOBOX_ITEM 1
  39. #define INDEX_COMBOBOX_BUTTON 2
  40. #define INDEX_COMBOBOX_LIST 3
  41. #define CCHILDREN_COMBOBOX 3
  42. public:
  43. // -----------------------------
  44. // IUnknown interface
  45. // -----------------------------
  46. virtual HRESULT WINAPI QueryInterface(REFIID riid, void **ppvObject);
  47. #endif
  48. public:
  49. DWORD _fRightAlign:1; // Determines if the combo box should be right aligned
  50. DWORD _fListVisible:1; // Determines if list is visible
  51. DWORD _fOwnerDraw:1; // owner draw combo box
  52. DWORD _fOwnerDrawVar:1; // owner draw combo box with varibale height
  53. DWORD _fFocus:1; // do we have the focus?
  54. DWORD _fMousedown:1; // if the left button was down
  55. DWORD _fVisible:1; // window is visible
  56. DWORD _fEnabled:1; // window is enabled
  57. DWORD _fNoIntegralHeight:1; // no integral height
  58. DWORD _fCapture:1; // determines if the combo box has mouse cursor captured or not
  59. DWORD _fResizing:1; // flag to indicate we are resizing the window
  60. DWORD _fExtendedUI:1; // flag indicating if extended ui is used
  61. DWORD _fLBCBMessage:1; // flag indicating the message is LBCB_TRACKING
  62. DWORD _fIgnoreChange:1; // flag indicating there was an internal change of text in
  63. // the edit control
  64. DWORD _fIgnoreUpdate:1; // flag indicating if we should ignore the update flag, we need
  65. // this flag because there will be cases where updateWindow is
  66. // needed but we don't want to fire the notification
  67. DWORD _fButtonDown:1; // true when button is pressed
  68. DWORD _fDontWinNotify:1; // true when we don't want to call WinNotify for changes
  69. DWORD _fSendEditChange:1; // true when we need to send CBN_EDITCHANGE after painting the change
  70. // editbox
  71. DWORD _fShutDown:1; // true when we are shutting down
  72. HWND _hwndList; // window handle of listbox
  73. HCURSOR _hcurOld; // handle to the mouse cursor
  74. protected:
  75. RECT _rcWindow; // rect of window which the combo box was created with
  76. RECT _rcButton; // rect of button
  77. RECT _rcList; // rect of listbox
  78. // we have to have a minimum inset for either the right or left
  79. // to account for the button for the combo box
  80. int _dxRInset; // minimum right inset
  81. int _dxLInset; // minimum left inset
  82. int _dxROffset; // indents for right and left these values should be used
  83. int _dxLOffset; // with _dxRInset/_dxLInset to properly calculate the indents
  84. int _dyFont; // Height of the current font, may not necessarily be the system font
  85. int _dyEdit; // height of items
  86. int _cyCombo; // Height of the combo box
  87. int _cxCombo; // Width of the combo box
  88. int _cyList; // Height of the listbox
  89. int _cxList; // Width of the listbox set via CB_SETDROPWIDTH
  90. long _nCursor; // last selected cursor -2 by default
  91. BOOL _bSelOk; // used to help in determining what kind of notification to give
  92. UINT _idCtrl; // ID of control
  93. Combotype _cbType; // current combo box style
  94. CLstBxWinHost* _plbHost; // pointer to listbox host
  95. protected:
  96. // Draws the combo button
  97. void DrawButton(HDC hdc, BOOL bDown);
  98. // Sets the edit controls text to item of the list box
  99. void AutoUpdateEdit(int i);
  100. // Hilite the edit control
  101. void HiliteEdit(BOOL bSelect);
  102. // resizes the list box
  103. void SetDropSize(RECT* prc);
  104. // set the edit size
  105. void SetSizeEdit(int nLeft, int nTop, int nRight, int nBottom);
  106. // get the rect for the listbox
  107. void GetListBoxRect(RECT &rcList);
  108. public:
  109. // Constructor / Destructor
  110. CCmbBxWinHost();
  111. virtual ~CCmbBxWinHost();
  112. // initialization function
  113. virtual BOOL Init(HWND, const CREATESTRUCT *);
  114. // Window creation/destruction
  115. static LRESULT OnNCCreate(HWND hwnd, const CREATESTRUCT *pcs);
  116. static void OnNCDestroy(CCmbBxWinHost *ped);
  117. virtual LRESULT OnCreate(const CREATESTRUCT *pcs);
  118. // Edit control Text helper functions
  119. LRESULT GetEditText(LPTSTR szStr, int nSize);
  120. LRESULT GetTextLength();
  121. // Draws the focus rect for the edit control
  122. void DrawEditFocus(HDC);
  123. // Sets the text in the edit control to the text of the current item in the
  124. // list box
  125. void UpdateEditBox();
  126. // selects the item which has the same text string as the edit control
  127. int UpdateListBox(BOOL);
  128. // hides the listbox
  129. BOOL HideListBox(BOOL, BOOL);
  130. // shows the list box
  131. void ShowListBox(BOOL);
  132. // Used as a way for the listbox to communicate to the combo box about a selection
  133. void SetSelectionInfo(BOOL bOk, int nIdx);
  134. // Update the window but don't send the notification
  135. void UpdateCbWindow()
  136. {
  137. _fIgnoreUpdate = 1;
  138. TxViewChange(TRUE);
  139. _fIgnoreUpdate = 0;
  140. }
  141. BOOL DrawCustomFrame(WPARAM wParam, HDC hDCIn);
  142. /////////////////////////////// message handlers /////////////////////////////////
  143. // Richedit message
  144. LRESULT OnSetTextEx(WPARAM wparam, LPARAM lparam);
  145. // Keyboard messages
  146. virtual LRESULT OnKeyDown(WORD vKey, DWORD dwFlags);
  147. virtual LRESULT OnChar(WORD vKey, DWORD dwFlags);
  148. virtual LRESULT OnSyskeyDown(WORD vKey, DWORD dwFlags);
  149. // mouse messages
  150. LRESULT OnLButtonUp(WPARAM wparam, LPARAM lparam);
  151. LRESULT OnMouseMove(WPARAM wparam, LPARAM lparam);
  152. LRESULT OnMouseWheel(WPARAM wparam, LPARAM lparam);
  153. LRESULT OnSetCursor(WPARAM wparam, LPARAM lparam);
  154. LRESULT OnLButtonDown(WPARAM wparam, LPARAM lparam);
  155. LRESULT OnMouseLeave(WPARAM wparam, LPARAM lparam);
  156. // focus messages
  157. LRESULT OnSetFocus(WPARAM wparam, LPARAM lparam);
  158. LRESULT OnKillFocus(WPARAM wparam, LPARAM lparam);
  159. LRESULT OnCaptureChanged(WPARAM wparam, LPARAM lparam);
  160. // window messages
  161. LRESULT OnPaint(WPARAM, LPARAM);
  162. HRESULT OnCommand(WPARAM wparam, LPARAM lparam);
  163. LRESULT OnSize(WPARAM wparam, LPARAM lparam);
  164. LRESULT OnGetDlgCode(WPARAM wparam, LPARAM lparam);
  165. LRESULT OnEnable(WPARAM wparam, LPARAM lparam);
  166. // rich edit private message
  167. LRESULT OnSetEditStyle(WPARAM wparam, LPARAM lparam);
  168. //@cmember Notify host of events
  169. virtual HRESULT TxNotify(DWORD iNotify, void *pv);
  170. //@cmember Scroll the content of the specified window's client area
  171. virtual void TxScrollWindowEx (INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip,
  172. HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll);
  173. //@cmember Changes the mouse cursor
  174. virtual HCURSOR TxSetCursor2(HCURSOR hcur, BOOL bText)
  175. { return (hcur) ? ::SetCursor(hcur) : ::GetCursor();}
  176. //@cmember InvalidateRect
  177. virtual void TxInvalidateRect(LPCRECT prc, BOOL fMode);
  178. //@cmember Retrieves the coordinates of a window's client area
  179. virtual HRESULT TxGetClientRect(LPRECT prc);
  180. ///////////////////////// combo box message handlers ////////////////////////////
  181. // Calculates the rect's and height's of all the controls
  182. BOOL CbCalcControlRects(RECT* prc, BOOL bCalcChange);
  183. // Retrieves the drop width of the list box
  184. LRESULT CbGetDropWidth();
  185. // sets the drop width of the list box
  186. void CbSetDropWidth(WPARAM wparam);
  187. // Retrieves the item height for either the edit or list box
  188. LRESULT CbGetItemHeight(WPARAM wparam, LPARAM lparam);
  189. // sets the item height for either the edit or list box
  190. LRESULT CbSetItemHeight(WPARAM wparam, LPARAM lparam);
  191. // sets extendedUI mode
  192. LRESULT CbSetExtendedUI(BOOL bExtendedUI);
  193. // retrieves the current extendedUI mode
  194. LRESULT CbGetExtendedUI() const {return _fExtendedUI;}
  195. // forwards the WM_DRAWITEM, WM_DELETEITEM messages to the parent window
  196. LRESULT CbMessageItemHandler(HDC, int, WPARAM, LPARAM);
  197. #ifndef NOACCESSIBILITY
  198. ////////////////////////// IAccessible Methods /////////////////////////////////
  199. HRESULT InitTypeInfo();
  200. STDMETHOD(get_accParent)(IDispatch **ppdispParent);
  201. STDMETHOD(get_accChildCount)(long *pcountChildren);
  202. STDMETHOD(get_accChild)(VARIANT varChild, IDispatch **ppdispChild);
  203. STDMETHOD(get_accName)(VARIANT varChild, BSTR *pszName);
  204. STDMETHOD(get_accValue)(VARIANT varChild, BSTR *pszValue);
  205. STDMETHOD(get_accRole)(VARIANT varChild, VARIANT *pvarRole);
  206. STDMETHOD(get_accState)(VARIANT varChild, VARIANT *pvarState);
  207. STDMETHOD(get_accKeyboardShortcut)(VARIANT varChild, BSTR *pszKeyboardShortcut);
  208. STDMETHOD(get_accFocus)(VARIANT *pvarChild);
  209. STDMETHOD(get_accSelection)(VARIANT *pvarChildren);
  210. STDMETHOD(get_accDefaultAction)(VARIANT varChild, BSTR *pszDefaultAction);
  211. STDMETHOD(accSelect)(long flagsSelect, VARIANT varChild);
  212. STDMETHOD(accLocation)(long *pxLeft, long *pyTop, long *pcxWidth, long *pcyHeight, VARIANT varChild);
  213. STDMETHOD(accNavigate)(long navDir, VARIANT varStart, VARIANT *pvarEndUpAt);
  214. STDMETHOD(accHitTest)(long xLeft, long yTop, VARIANT *pvarChild);
  215. STDMETHOD(accDoDefaultAction)(VARIANT varChild);
  216. #endif // NOACCESSIBILITY
  217. };
  218. #endif // NOWINDOWHOSTS
  219. #endif // _CBHOST_H