AdvComboBox.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /////////////////////////////////////////////////////////////////////////////
  2. // AdvComboBox.h : header file
  3. //
  4. // CAdvComboBox Control
  5. // Version: 2.1
  6. // Date: September 2002
  7. // Author: Mathias Tunared
  8. // Email: Mathias@inorbit.com
  9. // Copyright (c) 2002. All Rights Reserved.
  10. //
  11. // This code, in compiled form or as source code, may be redistributed
  12. // unmodified PROVIDING it is not sold for profit without the authors
  13. // written consent, and providing that this notice and the authors name
  14. // and all copyright notices remains intact.
  15. //
  16. // This file is provided "as is" with no expressed or implied warranty.
  17. // The author accepts no liability for any damage/loss of business that
  18. // this product may cause.
  19. //
  20. /////////////////////////////////////////////////////////////////////////////
  21. #ifndef ADVCOMBOBOX_H
  22. #define ADVCOMBOBOX_H
  23. #include "DropListBox.h"
  24. #include "DropWnd.h"
  25. #include "AdvComboEdit.h"
  26. #include <tchar.h>
  27. typedef std::basic_string<TCHAR> tstring;
  28. #define WM_ON_DROPDOWN_BUTTON WM_USER+101
  29. #define ACBS_FLAT 0x0001
  30. #define ACBS_STANDARD 0x0002
  31. #define ACBS_CHECKED 0x0004
  32. #define ACBS_AUTOAPPEND 0x0008
  33. #define ACBS_AUTOSUGGEST 0x0010
  34. #pragma warning( disable : 4251 )
  35. #pragma warning( disable : 4786 )
  36. #pragma warning( disable : 4275 )
  37. #include <list>
  38. #include <map>
  39. #include <string>
  40. using namespace std;
  41. void AFXAPI DDX_ACBIndex( CDataExchange* pDX, int nIDC, int& index );
  42. void AFXAPI DDX_ACBString( CDataExchange* pDX, int nIDC, CString& value );
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CAdvComboBox window
  45. //#define ADVCOMBOBOXCTRL_CLASSNAME _T("AdvComboBoxCtrl") // Window class name
  46. #define ADVCOMBOBOXCTRL_CLASSNAME _T("SuperComboBox") // Window class name
  47. class CAdvComboBox : public CWnd
  48. {
  49. // Construction
  50. public:
  51. CAdvComboBox( BOOL bInst = FALSE, CWnd * pParent = NULL );
  52. DECLARE_DYNAMIC(CAdvComboBox)
  53. // Attributes
  54. public:
  55. CWnd * GetDropWnd() { return m_pDropWnd; }
  56. // Operations
  57. public:
  58. // Overrides
  59. // ClassWizard generated virtual function overrides
  60. //{{AFX_VIRTUAL(CAdvComboBox)
  61. public:
  62. virtual BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );
  63. virtual BOOL PreTranslateMessage(MSG* pMsg);
  64. protected:
  65. virtual void PreSubclassWindow();
  66. //}}AFX_VIRTUAL
  67. virtual void OnEscapeKey() {}; //+++
  68. virtual void OnComboComplete() {}; //+++
  69. // Implementation
  70. public:
  71. void LoadString( UINT nStringID = 0 );
  72. int GetDefaultVisibleItems();
  73. void SetDefaultVisibleItems( int nItems = -1 );
  74. virtual CFont* GetFont() {return m_pFont;}
  75. int GetMinVisibleItems();
  76. void SetMinVisibleItems( int nMinItems );
  77. BOOL LimitText( int nMaxChars );
  78. BOOL SetEditSel( int nStartChar, int nEndChar );
  79. DWORD GetEditSel();
  80. int FindStringExact( int nIndexStart, LPCTSTR lpszFind );
  81. int InsertString( int nIndex, LPCTSTR lpszString );
  82. int DeleteString( UINT nIndex );
  83. BOOL GetExtendedUI();
  84. int SetExtendedUI( BOOL bExtended = TRUE );
  85. BOOL GetDroppedState();
  86. void GetDroppedControlRect( LPRECT lprect );
  87. void ShowDropDown( BOOL bShowIt = TRUE );
  88. int InitStorage( int nItems, UINT nBytes );
  89. int SetTopIndex( int nIndex );
  90. int GetTopIndex();
  91. void SetItemChecked( int nIndex, BOOL bChecked );
  92. BOOL GetItemChecked( int nIndex );
  93. void SetItemDisabled( int nIndex, BOOL bDisabled );
  94. BOOL GetItemDisabled( int nIndex );
  95. void ResetContent();
  96. void* GetItemDataPtr( int nIndex );
  97. int SetItemDataPtr( int nIndex, void* pData );
  98. DWORD GetItemData( int nIndex );
  99. int SetItemData( int nIndex, DWORD dwItemData );
  100. int SetCurSel( int nSelect );
  101. int GetCount();
  102. int GetCurSel();
  103. void SetText( LPCTSTR lpszText );
  104. void GetText( CString& rString );
  105. int GetText( LPTSTR lpszText );
  106. int AddString( LPCTSTR lpszString );
  107. int FindString( int nStartAfter, LPCTSTR lpszString );
  108. int SelectString( int nStartAfter, LPCTSTR lpszString );
  109. void GetLBText( int nIndex, CString& rString );
  110. int GetLBText( int nIndex, LPTSTR lpszText );
  111. int GetLBTextLen(int nIndex );
  112. int SetItemHeight( int nIndex, int nHeight );
  113. virtual ~CAdvComboBox();
  114. CRect& GetComboRect() { return m_rcCombo; }
  115. void ModifyACBStyle( UINT nRemoveStyle, UINT nAddStyle );
  116. BOOL PointInWindow( CPoint ptScreenPoint );
  117. UINT GetComboWidth(); //+++
  118. // Generated message map functions
  119. protected:
  120. //{{AFX_MSG(CAdvComboBox)
  121. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  122. afx_msg void OnPaint();
  123. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  124. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  125. afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
  126. afx_msg void OnSize(UINT nType, int cx, int cy);
  127. afx_msg void OnSetFocus(CWnd* pOldWnd);
  128. afx_msg void OnKillFocus(CWnd* pNewWnd);
  129. afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
  130. afx_msg void OnEnable(BOOL bEnable);
  131. afx_msg void OnChildActivate();
  132. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  133. afx_msg void OnTimer(UINT nIDEvent);
  134. afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  135. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  136. afx_msg void OnActivateApp(BOOL bActive, DWORD hTask);
  137. //}}AFX_MSG
  138. afx_msg void OnMouseLeave();
  139. afx_msg LONG OnSelectedItem( WPARAM wParam, LPARAM lParam );
  140. afx_msg LONG OnDropdownButton( WPARAM wParam, LPARAM lParam );
  141. afx_msg LONG OnDestroyDropdownList( WPARAM wParam, LPARAM lParam );
  142. afx_msg void OnKillfocusEdit();
  143. afx_msg void OnSetfocusEdit();
  144. afx_msg void OnChangeEdit();
  145. afx_msg void OnUpdateEdit();
  146. // ComboBox messages
  147. afx_msg LONG OnAddString( WPARAM wParam, LPARAM lString );
  148. afx_msg LONG OnSetCurSel( WPARAM wIndex, LPARAM lParam );
  149. afx_msg LONG OnGetCurSel( WPARAM wParam, LPARAM lParam );
  150. afx_msg LONG OnSelectString( WPARAM wItemStart, LPARAM lString );
  151. afx_msg LONG OnGetCount( WPARAM wParam, LPARAM lParam );
  152. afx_msg LONG OnResetContent( WPARAM wParam, LPARAM lParam );
  153. afx_msg LONG OnGetLBText( WPARAM wIndex, LPARAM lString );
  154. afx_msg LONG OnGetLBTextLen( WPARAM wIndex, LPARAM lParam );
  155. afx_msg LONG OnGetTopIndex( WPARAM wParam, LPARAM lParam );
  156. afx_msg LONG OnSetTopIndex( WPARAM wIndex, LPARAM lParam );
  157. DECLARE_MESSAGE_MAP()
  158. BOOL RegisterWindowClass();
  159. private:
  160. void CreateDropList( list<LIST_ITEM> &droplist );
  161. void SelPrevItem();
  162. void SelNextItem();
  163. void SelPrevPage();
  164. void SelNextPage();
  165. BOOL m_bInst;
  166. CWnd * m_pParent;
  167. int m_nCurSel;
  168. CAdvComboEdit* m_pEdit; //+++
  169. tstring m_strEdit;
  170. CFont* m_pFont;
  171. DWORD m_dwStyle;
  172. DWORD m_dwACBStyle;
  173. CRect m_rcCombo;
  174. CRect m_rcStaticWnd;
  175. CRect m_rcDropWnd;
  176. CDropWnd* m_pDropWnd;
  177. CRect m_rcDropButton;
  178. BOOL m_bDropListVisible;
  179. bool m_bDropRectStored;
  180. list<LIST_ITEM> m_list;
  181. list<LIST_ITEM>::iterator m_iter;
  182. int m_zDelta; // MouseWheel...
  183. bool m_bHasFocus;
  184. bool m_bHasSentFocus;
  185. bool m_bSelItem;
  186. bool m_bFirstPaint;
  187. int m_nMinVisItems;
  188. bool m_bCodeCreate;
  189. BOOL m_bAutoAppend;
  190. bool m_bDropButtonHot;
  191. bool m_bTrackMouseLeave;
  192. int m_nDefaultDropItems; // Number of items to be shown when dropwindow first shown.
  193. };
  194. //{{AFX_INSERT_LOCATION}}
  195. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  196. #endif //ADVCOMBOBOX_H