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.

235 lines
6.5 KiB

  1. #include "precomp.h"
  2. // Private forward decalarations
  3. static BOOL CALLBACK enumComboBoxChildrenWndProc(HWND hwndChild, LPARAM lParam);
  4. static BOOL isCtrlWithFocus(HWND hCtrl);
  5. void InitSysFont(HWND hDlg, int iCtrlID)
  6. {
  7. static HFONT s_hfontSys = NULL;
  8. LOGFONT lf;
  9. HDC hDC;
  10. HWND hwndCtrl = GetDlgItem(hDlg, iCtrlID);
  11. HFONT hFont;
  12. int cyLogPixels;
  13. hDC = GetDC(NULL);
  14. if (hDC == NULL)
  15. return;
  16. cyLogPixels = GetDeviceCaps(hDC, LOGPIXELSY);
  17. ReleaseDC(NULL, hDC);
  18. if (s_hfontSys == NULL) {
  19. LOGFONT lfTemp;
  20. HFONT hfontDef = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
  21. GetObject(hfontDef, sizeof(lfTemp), &lfTemp);
  22. hFont = GetWindowFont(hwndCtrl);
  23. if (hFont != NULL)
  24. if (GetObject(hFont, sizeof(LOGFONT), (PVOID)&lf)) {
  25. StrCpy(lf.lfFaceName, lfTemp.lfFaceName);
  26. lf.lfQuality = lfTemp.lfQuality;
  27. lf.lfPitchAndFamily = lfTemp.lfPitchAndFamily;
  28. lf.lfCharSet = lfTemp.lfCharSet;
  29. s_hfontSys = CreateFontIndirect(&lf);
  30. }
  31. }
  32. if (iCtrlID == 0xFFFF)
  33. return;
  34. if (s_hfontSys != NULL)
  35. SetWindowFont(hwndCtrl, s_hfontSys, FALSE);
  36. }
  37. UINT GetRadioButton(HWND hDlg, UINT idFirst, UINT idLast)
  38. {
  39. for (UINT id = idFirst; id <= idLast; id++)
  40. if (IsDlgButtonChecked(hDlg, id))
  41. return id;
  42. return 0;
  43. }
  44. BOOL EnableDlgItems(HWND hDlg, const PINT pidCtrls, UINT cidCtrls, BOOL fEnable /*= TRUE*/)
  45. {
  46. HWND hCtrl;
  47. UINT i;
  48. BOOL fTotalSuccess;
  49. if (hDlg == NULL || pidCtrls == NULL || cidCtrls == 0)
  50. return FALSE;
  51. fTotalSuccess = TRUE;
  52. for (i = 0; i < cidCtrls; i++) {
  53. hCtrl = GetDlgItem(hDlg, *(pidCtrls + i));
  54. if (hCtrl == NULL) {
  55. fTotalSuccess = FALSE;
  56. continue;
  57. }
  58. if (fEnable != IsWindowEnabled(hCtrl))
  59. EnableWindow(hCtrl, fEnable);
  60. }
  61. return fTotalSuccess;
  62. }
  63. BOOL SetDlgItemFocus(HWND hDlg, int iCtrlID, BOOL fUsePropertySheet /*= FALSE*/)
  64. { // Back, Next, Finish
  65. static UINT s_rgidReserved[] = { 0x3023, 0x3024, 0x3025, IDHELP, IDCANCEL };
  66. HWND hCtrl;
  67. DWORD dwStyle;
  68. UINT i;
  69. if (fUsePropertySheet) {
  70. for (i = 0; i < countof(s_rgidReserved); i++)
  71. if ((UINT)iCtrlID == s_rgidReserved[i])
  72. break;
  73. if (i < countof(s_rgidReserved))
  74. hDlg = GetParent(hDlg);
  75. }
  76. hCtrl = GetDlgItem(hDlg, iCtrlID);
  77. if (hCtrl == NULL)
  78. return FALSE;
  79. ASSERT(IsWindowEnabled(hCtrl) && IsWindowVisible(hCtrl));
  80. SetFocus(hCtrl);
  81. dwStyle = GetWindowLong(hCtrl, GWL_STYLE);
  82. if (HasFlag(dwStyle, BS_PUSHBUTTON))
  83. Button_SetStyle(hCtrl, BS_DEFPUSHBUTTON, TRUE);
  84. return TRUE;
  85. }
  86. BOOL EnsureDialogFocus(HWND hDlg, int idFocus, int idBackup, BOOL fUsePropertySheet /*= FALSE*/)
  87. {
  88. HWND hCtrl;
  89. DWORD dwStyle;
  90. hCtrl = GetDlgItem(hDlg, idFocus);
  91. if (hCtrl == NULL)
  92. return FALSE;
  93. if (!isCtrlWithFocus(hCtrl))
  94. return TRUE;
  95. dwStyle = GetWindowLong(hCtrl, GWL_STYLE);
  96. if (HasFlag(dwStyle, BS_DEFPUSHBUTTON) && !HasFlag(dwStyle, BS_USERBUTTON))
  97. Button_SetStyle(hCtrl, BS_PUSHBUTTON, TRUE);
  98. return SetDlgItemFocus(hDlg, idBackup, fUsePropertySheet);
  99. }
  100. BOOL EnsureDialogFocus(HWND hDlg, const PINT pidFocus, UINT cidFocus, int idBackup, BOOL fUsePropertySheet /*= FALSE*/)
  101. {
  102. HWND hCtrl;
  103. DWORD dwStyle;
  104. UINT i;
  105. if (pidFocus == NULL || cidFocus == 0)
  106. return FALSE;
  107. hCtrl = NULL;
  108. for (i = 0; i < cidFocus; i++) {
  109. hCtrl = GetDlgItem(hDlg, *(pidFocus + i));
  110. if (hCtrl == NULL)
  111. return FALSE;
  112. if (isCtrlWithFocus(hCtrl))
  113. break;
  114. }
  115. if (i >= cidFocus)
  116. return TRUE;
  117. ASSERT(hCtrl != NULL);
  118. dwStyle = GetWindowLong(hCtrl, GWL_STYLE);
  119. if (HasFlag(dwStyle, BS_DEFPUSHBUTTON) && !HasFlag(dwStyle, BS_USERBUTTON))
  120. Button_SetStyle(hCtrl, BS_PUSHBUTTON, TRUE);
  121. return SetDlgItemFocus(hDlg, idBackup, fUsePropertySheet);
  122. }
  123. void SetDlgItemTextTriState(HWND hDlg, INT nIDDlgText, INT nIDDlgCheck, LPCTSTR lpString, BOOL fChecked)
  124. {
  125. CheckDlgButton(hDlg, nIDDlgCheck, fChecked ? BST_CHECKED : BST_UNCHECKED);
  126. EnableDlgItem2(hDlg, nIDDlgText, fChecked);
  127. SetDlgItemText(hDlg, nIDDlgText, lpString);
  128. }
  129. BOOL GetDlgItemTextTriState(HWND hDlg, INT nIDDlgText, INT nIDDlgCheck, LPTSTR lpString, int nMaxCount)
  130. {
  131. GetDlgItemText(hDlg, nIDDlgText, lpString, nMaxCount);
  132. return (IsDlgButtonChecked(hDlg, nIDDlgCheck) == BST_CHECKED);
  133. }
  134. void IsTriStateValid(HWND hDlg, INT nIDDlgText, INT nIDDlgCheck, LPINT pnStatus,
  135. LPCTSTR pcszErrMsg, LPCTSTR pcszTitle)
  136. {
  137. TCHAR szBuf[INTERNET_MAX_URL_LENGTH];
  138. if (*pnStatus == TS_CHECK_ERROR || *pnStatus == TS_CHECK_SKIP)
  139. return;
  140. *pnStatus = TS_CHECK_OK;
  141. if (IsDlgButtonChecked(hDlg, nIDDlgCheck) == BST_CHECKED)
  142. {
  143. GetDlgItemText(hDlg, nIDDlgText, szBuf, countof(szBuf));
  144. if (ISNULL(szBuf))
  145. {
  146. if (MessageBox(hDlg, pcszErrMsg, pcszTitle, MB_ICONQUESTION|MB_YESNO) == IDNO)
  147. {
  148. SetFocus(GetDlgItem(hDlg, nIDDlgText));
  149. *pnStatus = TS_CHECK_ERROR;
  150. }
  151. else
  152. *pnStatus = TS_CHECK_SKIP;
  153. }
  154. }
  155. }
  156. /////////////////////////////////////////////////////////////////////////////
  157. // Implementation helpers routines (private)
  158. static BOOL CALLBACK enumComboBoxChildrenWndProc(HWND hwndChild, LPARAM lParam)
  159. {
  160. UNREFERENCED_PARAMETER(lParam);
  161. // check to see if this child window of the combo box has focus
  162. if (hwndChild == GetFocus())
  163. return FALSE; // stop enumeration
  164. return TRUE;
  165. }
  166. static BOOL isCtrlWithFocus(HWND hCtrl)
  167. {
  168. DWORD dwStyle;
  169. if (hCtrl == GetFocus())
  170. return TRUE;
  171. dwStyle = GetWindowLong(hCtrl, GWL_STYLE);
  172. // Check to see if this is a combo box with a hidden edit control
  173. if ((HasFlag(dwStyle, CBS_DROPDOWN) || HasFlag(dwStyle, CBS_SIMPLE)) &&
  174. !(HasFlag(dwStyle, CBS_DROPDOWN) && HasFlag(dwStyle, CBS_SIMPLE)))
  175. {
  176. if (!EnumChildWindows(hCtrl, (WNDENUMPROC)enumComboBoxChildrenWndProc, 0))
  177. return TRUE;
  178. }
  179. return FALSE;
  180. }