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.

178 lines
3.9 KiB

  1. // File: BitmapButton.cpp
  2. #include "precomp.h"
  3. #include "GenControls.h"
  4. #include <windowsx.h>
  5. CEditText::CEditText() : m_hbrBack(NULL), m_pNotify(NULL)
  6. {
  7. }
  8. CEditText::~CEditText()
  9. {
  10. SetColors(NULL, 0, 0);
  11. SetFont(NULL);
  12. if (NULL != m_pNotify)
  13. {
  14. m_pNotify->Release();
  15. m_pNotify = NULL;
  16. }
  17. }
  18. BOOL CEditText::Create(
  19. HWND hWndParent, // Parent of the edit control
  20. DWORD dwStyle, // Edit control style
  21. DWORD dwExStyle, // Extended window style
  22. LPCTSTR szTitle, // Initial text for the edit control
  23. IEditTextChange *pNotify // Object to notify of changes
  24. )
  25. {
  26. if (!CFillWindow::Create(
  27. hWndParent, // Window parent
  28. 0, // ID of the child window
  29. TEXT("NMEditText"), // Window name
  30. 0, // Window style; WS_CHILD|WS_VISIBLE will be added to this
  31. dwExStyle|WS_EX_CONTROLPARENT // Extended window style
  32. ))
  33. {
  34. return(FALSE);
  35. }
  36. // Create the actual edit control and save it away
  37. m_edit = CreateWindowEx(0, TEXT("edit"), szTitle,
  38. WS_CHILD|WS_VISIBLE|WS_TABSTOP|dwStyle,
  39. 0, 0, 10, 10, GetWindow(), 0,
  40. reinterpret_cast<HINSTANCE>(GetWindowLongPtr(hWndParent, GWLP_HINSTANCE)),
  41. NULL);
  42. HWND edit = GetEdit();
  43. FORWARD_WM_SETFONT(edit, m_hfText, TRUE, ::SendMessage);
  44. m_pNotify = pNotify;
  45. if (NULL != m_pNotify)
  46. {
  47. m_pNotify->AddRef();
  48. }
  49. return(TRUE);
  50. }
  51. // Not actually implemented yet; should use the font to determine a size
  52. void CEditText::GetDesiredSize(SIZE *ppt)
  53. {
  54. CFillWindow::GetDesiredSize(ppt);
  55. }
  56. // HACKHACK georgep: This object now owns the brush
  57. void CEditText::SetColors(HBRUSH hbrBack, COLORREF back, COLORREF fore)
  58. {
  59. // Store off the colors and brush
  60. if (NULL != m_hbrBack)
  61. {
  62. DeleteObject(m_hbrBack);
  63. }
  64. m_hbrBack = hbrBack;
  65. m_crBack = back;
  66. m_crFore = fore;
  67. InvalidateRect(GetEdit(), NULL, TRUE);
  68. }
  69. // HACKHACK georgep: This object now owns the font
  70. void CEditText::SetFont(HFONT hf)
  71. {
  72. if (NULL != m_hfText)
  73. {
  74. DeleteObject(m_hfText);
  75. }
  76. m_hfText = hf;
  77. // Tell the edit control the font to use
  78. HWND edit = GetEdit();
  79. if (NULL != edit)
  80. {
  81. FORWARD_WM_SETFONT(edit, hf, TRUE, ::SendMessage);
  82. }
  83. }
  84. LRESULT CEditText::ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  85. {
  86. switch (message)
  87. {
  88. HANDLE_MSG(GetWindow(), WM_CTLCOLOREDIT, OnCtlColor);
  89. HANDLE_MSG(GetWindow(), WM_COMMAND , OnCommand);
  90. HANDLE_MSG(GetWindow(), WM_NCDESTROY , OnNCDestroy);
  91. }
  92. return(CFillWindow::ProcessMessage(hwnd, message, wParam, lParam));
  93. }
  94. HBRUSH CEditText::OnCtlColor(HWND hwnd, HDC hdc, HWND hwndChild, int type)
  95. {
  96. // Do default processing if there is no brush
  97. if (NULL == m_hbrBack)
  98. {
  99. return(FORWARD_WM_CTLCOLOREDIT(hwnd, hdc, hwndChild, CFillWindow::ProcessMessage));
  100. }
  101. // Set the colors in the DC, and return the brush
  102. SetBkColor(hdc, m_crBack);
  103. SetTextColor(hdc, m_crFore);
  104. return(m_hbrBack);
  105. }
  106. // Sets the text for the control
  107. void CEditText::SetText(
  108. LPCTSTR szText // The text to set
  109. )
  110. {
  111. SetWindowText(GetChild(), szText);
  112. }
  113. // Gets the text for the control; returns the total text length
  114. int CEditText::GetText(
  115. LPTSTR szText, // Where to put the text
  116. int nLen // The length of the buffer
  117. )
  118. {
  119. GetWindowText(GetChild(), szText, nLen);
  120. return(GetWindowTextLength(GetChild()));
  121. }
  122. void CEditText::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  123. {
  124. switch (codeNotify)
  125. {
  126. case EN_UPDATE:
  127. if (NULL != m_pNotify)
  128. {
  129. m_pNotify->OnTextChange(this);
  130. }
  131. break;
  132. case EN_SETFOCUS:
  133. SetHotControl(this);
  134. case EN_KILLFOCUS:
  135. if (NULL != m_pNotify)
  136. {
  137. m_pNotify->OnFocusChange(this, EN_SETFOCUS==codeNotify);
  138. }
  139. break;
  140. }
  141. FORWARD_WM_COMMAND(hwnd, id, hwndCtl, codeNotify, CFillWindow::ProcessMessage);
  142. }
  143. void CEditText::OnNCDestroy(HWND hwnd)
  144. {
  145. if (NULL != m_pNotify)
  146. {
  147. m_pNotify->Release();
  148. m_pNotify = NULL;
  149. }
  150. FORWARD_WM_NCDESTROY(hwnd, CFillWindow::ProcessMessage);
  151. }