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.

471 lines
12 KiB

  1. // File: EditText.h
  2. #ifndef _EDITTEXT_H_
  3. #define _EDITTEXT_H_
  4. #include "GenWindow.h"
  5. #include "GenContainers.h"
  6. class CEditText;
  7. interface IEditTextChange : IUnknown
  8. {
  9. virtual void OnTextChange(CEditText *pEdit) = 0;
  10. virtual void OnFocusChange(CEditText *pEdit, BOOL bSet) = 0;
  11. } ;
  12. // An edit control class that supports using different foreground and
  13. // background colors
  14. class DECLSPEC_UUID("{FD827E00-ACA3-11d2-9C97-00C04FB17782}")
  15. CEditText : public CFillWindow
  16. {
  17. public:
  18. // Default constructor; inits a few intrinsics
  19. CEditText();
  20. // Creates the edit control
  21. BOOL Create(
  22. HWND hWndParent, // Parent of the edit control
  23. DWORD dwStyle=0, // Edit control style
  24. DWORD dwExStyle=0, // Extended window style
  25. LPCTSTR szTitle=TEXT(""), // Initial text for the edit control
  26. IEditTextChange *pNotify=NULL // Object to notify of changes
  27. );
  28. HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID riid, LPVOID *ppv)
  29. {
  30. if (__uuidof(CEditText) == riid)
  31. {
  32. *ppv = this;
  33. AddRef();
  34. return(S_OK);
  35. }
  36. return(CFillWindow::QueryInterface(riid, ppv));
  37. }
  38. void GetDesiredSize(SIZE *ppt);
  39. // Sets the foreground and background colors and brush to use for painting
  40. // Set the brush to NULL to indicate using default colors
  41. void SetColors(HBRUSH hbrBack, COLORREF back, COLORREF fore);
  42. // Sets the font to use in the edit control
  43. void SetFont(HFONT hf);
  44. // Sets the text for the control
  45. void SetText(
  46. LPCTSTR szText // The text to set
  47. );
  48. // Gets the text for the control; returns the total text length
  49. int GetText(
  50. LPTSTR szText, // Where to put the text
  51. int nLen // The length of the buffer
  52. );
  53. protected:
  54. virtual ~CEditText();
  55. virtual LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  56. private:
  57. // The actual edit control
  58. HWND m_edit;
  59. // The background brush
  60. HBRUSH m_hbrBack;
  61. // The background color
  62. COLORREF m_crBack;
  63. // The foreground color
  64. COLORREF m_crFore;
  65. // The font to use
  66. HFONT m_hfText;
  67. // The object ot notify of changes
  68. IEditTextChange *m_pNotify;
  69. // I may turn this into a GetWindow call later
  70. inline HWND GetEdit()
  71. {
  72. return(m_edit);
  73. }
  74. // Needed to change the edit control colors
  75. HBRUSH OnCtlColor(HWND hwnd, HDC hdc, HWND hwndChild, int type);
  76. // Notification of events on the edit control
  77. void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
  78. // To clean stuff up
  79. void OnNCDestroy(HWND hwnd);
  80. } ;
  81. class CButton;
  82. interface IButtonChange : IUnknown
  83. {
  84. virtual void OnClick(CButton *pButton) = 0;
  85. } ;
  86. class DECLSPEC_UUID("{C3AEA4CA-CAB3-11d2-9CA7-00C04FB17782}")
  87. CButton : public CFillWindow
  88. {
  89. public:
  90. CButton();
  91. ~CButton();
  92. BOOL Create(
  93. HWND hWndParent, // The parent window
  94. INT_PTR nId, // The ID of the button for WM_COMMAND messages
  95. LPCTSTR szTitle, // The string to display
  96. DWORD dwStyle=BS_PUSHBUTTON, // The Win32 button style
  97. IButtonChange *pNotify=NULL // Click notifications
  98. );
  99. HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID riid, LPVOID *ppv)
  100. {
  101. if (__uuidof(CButton) == riid)
  102. {
  103. *ppv = this;
  104. AddRef();
  105. return(S_OK);
  106. }
  107. return(CFillWindow::QueryInterface(riid, ppv));
  108. }
  109. // Get/set the icon displayed with this button
  110. void SetIcon(
  111. HICON hIcon // The icon to use for this button
  112. );
  113. HICON GetIcon();
  114. // Get/set the bitmap displayed with this button
  115. void SetBitmap(
  116. HBITMAP hBitmap // The bitmap to use for this button
  117. );
  118. HBITMAP GetBitmap();
  119. // Get/set the checked state of the button
  120. void SetChecked(
  121. BOOL bCheck // TRUE if the button should be checked
  122. );
  123. BOOL IsChecked();
  124. virtual void GetDesiredSize(SIZE *psize);
  125. protected:
  126. virtual LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  127. private:
  128. // Notify handler for clicks
  129. IButtonChange *m_pNotify;
  130. // Store away the icon size to avoid creating many bitmaps
  131. SIZE m_sizeIcon;
  132. // Change the HWND and forward to the parent
  133. void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
  134. } ;
  135. // A button class that uses bitmaps for its different states. Currently only
  136. // pressed and normal are supported
  137. class DECLSPEC_UUID("{E1813EDA-ACA3-11d2-9C97-00C04FB17782}")
  138. CBitmapButton : public CButton
  139. {
  140. public:
  141. // The order of the bitmaps for the states of the button
  142. enum StateBitmaps
  143. {
  144. Normal = 0,
  145. Pressed,
  146. Hot,
  147. Disabled,
  148. NumStates
  149. } ;
  150. // Default constructor; inits a few intrinsics
  151. CBitmapButton();
  152. // Creates the button, using the bitmaps specified
  153. BOOL Create(
  154. HWND hWndParent, // The parent of the button
  155. int nId, // The ID for WM_COMMAND messages
  156. HBITMAP hbStates, // The 2D array of bitmaps for the states of the button,
  157. // vertically in the order specified in the StateBitmaps enum
  158. // and horizontally in the custom states order
  159. UINT nInputStates=NumStates, // The number of input states (Normal, Pressed, Hot, Disabled)
  160. UINT nCustomStates=1, // The number of custom states
  161. IButtonChange *pNotify=NULL // The click handler
  162. );
  163. // Creates the button, using the bitmaps specified
  164. BOOL Create(
  165. HWND hWndParent, // The parent of the button
  166. int nId, // The ID for WM_COMMAND messages
  167. HINSTANCE hInst, // The instance to load the bitmap from
  168. int nIdBitmap, // The ID of the bitmap to use
  169. BOOL bTranslateColors=TRUE, // Use system background colors
  170. UINT nInputStates=NumStates, // The number of input states (Normal, Pressed, Hot, Disabled)
  171. UINT nCustomStates=1, // The number of custom states
  172. IButtonChange *pNotify=NULL // The click handler
  173. );
  174. HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID riid, LPVOID *ppv)
  175. {
  176. if (__uuidof(CBitmapButton) == riid)
  177. {
  178. *ppv = this;
  179. AddRef();
  180. return(S_OK);
  181. }
  182. return(CButton::QueryInterface(riid, ppv));
  183. }
  184. void GetDesiredSize(SIZE *ppt);
  185. // Change the current custom state
  186. void SetCustomState(UINT nCustomState);
  187. // Return the current custom state
  188. UINT GetCustomState() const { return(m_nCustomState); }
  189. // Change to flashing mode
  190. void SetFlashing(int nSeconds);
  191. // Is in flashing mode
  192. UINT IsFlashing() const { return(NoFlash != m_nFlashState); }
  193. static void GetBitmapSizes(HBITMAP parts[], SIZE sizes[], int nParts);
  194. static void LoadBitmaps(
  195. HINSTANCE hInst, // The instance to load the bitmap from
  196. const int ids[], // Array of bitmap ID's
  197. HBITMAP bms[], // Array of HBITMAP's for storing the result
  198. int nBmps, // Number of entries in the arrays
  199. BOOL bTranslateColors=TRUE // Use system background colors
  200. );
  201. protected:
  202. virtual ~CBitmapButton();
  203. virtual LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  204. virtual void SetHot(BOOL bHot);
  205. virtual BOOL IsHot() { return(m_bHot != FALSE); }
  206. void SchedulePaint()
  207. {
  208. InvalidateRect(GetChild(), NULL, FALSE);
  209. }
  210. private:
  211. enum FlashState
  212. {
  213. NoFlash = 0,
  214. ForceHot,
  215. ForceNormal,
  216. } ;
  217. // The number of custom states
  218. UINT m_nCustomStates;
  219. // The current custom state
  220. UINT m_nCustomState;
  221. // The bitmaps for the states of the button, in the order specified in the
  222. // StateBitmaps enum.
  223. HBITMAP m_hbStates;
  224. // The time to stop flashing
  225. DWORD m_endFlashing;
  226. // The number of input states; one of StateBitmaps enum
  227. // HACKHACK georgep: Need to change the number of bits if more states
  228. UINT m_nInputStates : 4;
  229. // The Hot flag
  230. BOOL m_bHot : 1;
  231. // The current flash state; one of FlashState enum
  232. // HACKHACK georgep: Need an extra bit since C++ thinks this is signed
  233. FlashState m_nFlashState : 3;
  234. // Specialized drawing
  235. void OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem);
  236. // Change the HWND and forward to the parent
  237. void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
  238. // Set the Hot control
  239. BOOL OnSetCursor(HWND hwnd, HWND hwndCursor, UINT codeHitTest, UINT msg);
  240. // Handles the flashing button
  241. void OnTimer(HWND hwnd, UINT id);
  242. } ;
  243. class CComboBox;
  244. interface IComboBoxChange : IUnknown
  245. {
  246. virtual void OnTextChange(CComboBox *pCombo) = 0;
  247. virtual void OnFocusChange(CComboBox *pCombo, BOOL bSet) = 0;
  248. virtual void OnSelectionChange(CComboBox *pCombo) = 0;
  249. } ;
  250. // An edit control class that supports using different foreground and
  251. // background colors
  252. class DECLSPEC_UUID("{B4B10DBA-B22F-11d2-9C98-00C04FB17782}")
  253. CComboBox : public CFillWindow
  254. {
  255. public:
  256. // Default constructor; inits a few intrinsics
  257. CComboBox();
  258. operator HWND (void){ return( m_combo ); }
  259. // Creates the edit control
  260. BOOL Create(
  261. HWND hWndParent, // Parent of the edit control
  262. UINT height, // The height of the combo (with drop-down)
  263. DWORD dwStyle=0, // Edit control style
  264. LPCTSTR szTitle=TEXT(""), // Initial text for the edit control
  265. IComboBoxChange *pNotify=NULL // Object to notify of changes
  266. );
  267. HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID riid, LPVOID *ppv)
  268. {
  269. if (__uuidof(CComboBox) == riid)
  270. {
  271. *ppv = this;
  272. AddRef();
  273. return(S_OK);
  274. }
  275. return(CFillWindow::QueryInterface(riid, ppv));
  276. }
  277. void GetDesiredSize(SIZE *ppt);
  278. // Sets the foreground and background colors and brush to use for painting
  279. // Set the brush to NULL to indicate using default colors
  280. void SetColors(HBRUSH hbrBack, COLORREF back, COLORREF fore);
  281. // Sets the font to use in the edit control
  282. void SetFont(HFONT hf);
  283. // Sets the text for the control
  284. void SetText(
  285. LPCTSTR szText // The text to set
  286. );
  287. // Gets the text for the control; returns the total text length
  288. int GetText(
  289. LPTSTR szText, // Where to put the text
  290. int nLen // The length of the buffer
  291. );
  292. // Returns the number of items in the list
  293. int GetNumItems();
  294. // Returns the index of the currently selected item
  295. int GetSelectedIndex();
  296. // Sets the index of the currently selected item
  297. void SetSelectedIndex(int index);
  298. // Adds text to the list; returns the index of the added string
  299. int AddText(
  300. LPCTSTR pszText, // The string to add
  301. LPARAM lUserData=0 // User data to associate with the string
  302. );
  303. // Gets the text for the list item; returns the total text length
  304. // The string is emptied if there is not enough room for the text
  305. int GetText(
  306. UINT index, // The index of the string to get
  307. LPTSTR pszText, // The string buffer to fill
  308. int nLen // User data to associate with the string
  309. );
  310. // Gets the user data for the list item
  311. LPARAM GetUserData(
  312. int index // The index of the user data to get
  313. );
  314. // Removes an item from the list
  315. void RemoveItem(
  316. UINT index // The index of the item to remove
  317. );
  318. virtual void Layout();
  319. protected:
  320. virtual ~CComboBox();
  321. virtual LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  322. // Get the info necessary for displaying a tooltip
  323. virtual void GetSharedTooltipInfo(TOOLINFO *pti);
  324. private:
  325. // The actual ComboBox control
  326. HWND m_combo;
  327. // The background brush
  328. HBRUSH m_hbrBack;
  329. // The background color
  330. COLORREF m_crBack;
  331. // The foreground color
  332. COLORREF m_crFore;
  333. // The font to use
  334. HFONT m_hfText;
  335. // The object ot notify of changes
  336. IComboBoxChange *m_pNotify;
  337. // I may turn this into a GetWindow call later
  338. inline HWND GetComboBox()
  339. {
  340. return(m_combo);
  341. }
  342. // I may turn this into a GetWindow call later
  343. inline HWND GetEdit()
  344. {
  345. // return(reinterpret_cast<HWND>(SendMessage(GetCombo(), CBEM_GETEDITCONTROL, 0, 0));
  346. return(GetComboBox());
  347. }
  348. // Needed to change the edit control colors
  349. HBRUSH OnCtlColor(HWND hwnd, HDC hdc, HWND hwndChild, int type);
  350. // Notification of events on the edit control
  351. void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
  352. // To clean stuff up
  353. void OnNCDestroy(HWND hwnd);
  354. } ;
  355. class CSeparator : public CGenWindow
  356. {
  357. public:
  358. // The Separator style
  359. enum Styles
  360. {
  361. Normal = 0,
  362. Blank,
  363. NumStates
  364. } ;
  365. CSeparator();
  366. BOOL Create(
  367. HWND hwndParent, UINT iStyle = Normal
  368. );
  369. virtual void GetDesiredSize(SIZE *ppt);
  370. void SetDesiredSize(SIZE *psize);
  371. // Put the single child in the middle
  372. virtual void Layout();
  373. private:
  374. // The desired size for the control; defaults to (2,2)
  375. SIZE m_desSize;
  376. UINT m_iStyle : 4;
  377. inline void OnPaint(HWND hwnd);
  378. protected:
  379. virtual LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  380. } ;
  381. #endif // _EDITTEXT_H_