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.

232 lines
6.8 KiB

  1. //
  2. // GetTitle.C
  3. //
  4. // Copyright (C) Microsoft, 1994,1995 All Rights Reserved.
  5. //
  6. // History:
  7. // ral 5/23/94 - First pass
  8. // 3/20/95 [stevecat] - NT port & real clean up, unicode, etc.
  9. //
  10. //
  11. #include "priv.h"
  12. #include "appwiz.h"
  13. //
  14. // Enables the appropriate buttons depending upon the state of the
  15. // description edit control and what type of shortcut we're trying to
  16. // make.
  17. //
  18. void EnableNextFinish(LPWIZDATA lpwd)
  19. {
  20. DWORD dwEnable = PSWIZB_BACK;
  21. if (GetWindowTextLength(GetDlgItem(lpwd->hwnd, IDC_TITLE)) > 0)
  22. {
  23. //
  24. // If this is a "known" application then enalble finish, else next.
  25. //
  26. dwEnable |= (lpwd->dwFlags & (WDFLAG_APPKNOWN | WDFLAG_COPYLINK)) ?
  27. PSWIZB_FINISH : PSWIZB_NEXT;
  28. }
  29. PropSheet_SetWizButtons(GetParent(lpwd->hwnd), dwEnable);
  30. }
  31. //
  32. // Called from PSN_SETACTIVE. Assumes lpwd->hwnd already initialized.
  33. //
  34. void GetTitleSetActive(LPWIZDATA lpwd)
  35. {
  36. //
  37. // Most of the code to process this was moved into the Next button
  38. // processing of the previous page as there were some failure cases
  39. // that we could not get a title that we should detect before we
  40. // allow the user to change to this page... HOWEVER, there are some
  41. // cases where we can't determine the name until we get to this page.
  42. // If we don't have a name for the sortcut, try to figure one out here.
  43. //
  44. if (lpwd->szProgDesc[0] == 0)
  45. {
  46. DetermineDefaultTitle(lpwd);
  47. }
  48. SetDlgItemText(lpwd->hwnd, IDC_TITLE, lpwd->szProgDesc);
  49. EnableNextFinish(lpwd);
  50. PostMessage(lpwd->hwnd, WMPRIV_POKEFOCUS, 0, 0);
  51. }
  52. //
  53. // Check to see if link name is a duplicate. If it is then ask the user
  54. // if they want to replace the old link. If they say "no" then this function
  55. // returns FALSE.
  56. //
  57. BOOL GetTitleNextPushed(LPWIZDATA lpwd)
  58. {
  59. TCHAR szLinkName[MAX_PATH];
  60. GetDlgItemText(lpwd->hwnd, IDC_TITLE, lpwd->szProgDesc, ARRAYSIZE(lpwd->szProgDesc));
  61. if (lpwd->szProgDesc[0] == 0)
  62. {
  63. return(FALSE);
  64. }
  65. if( ( PathCleanupSpec( lpwd->lpszFolder, lpwd->szProgDesc ) != 0 ) ||
  66. !GetLinkName( szLinkName, ARRAYSIZE(szLinkName), lpwd ) )
  67. {
  68. ShellMessageBox(g_hinst, lpwd->hwnd, MAKEINTRESOURCE(IDS_MODNAME),
  69. 0, MB_OK | MB_ICONEXCLAMATION);
  70. return(FALSE);
  71. }
  72. if (PathFileExists(szLinkName))
  73. {
  74. //
  75. // Obscure boundary case. If we're creating a new link and the user
  76. // happens to want to name it exactly it's current name then we'll let
  77. // them do it without a warning.
  78. //
  79. if (lpwd->lpszOriginalName && lstrcmpi(lpwd->lpszOriginalName, szLinkName) == 0)
  80. {
  81. TraceMsg(TF_ERROR, "%s", "Unbelieveable! User selected exactly the same name");
  82. return(TRUE);
  83. }
  84. return(IDYES == ShellMessageBox(g_hinst, lpwd->hwnd,
  85. MAKEINTRESOURCE(IDS_DUPLINK), 0,
  86. MB_YESNO | MB_DEFBUTTON1 | MB_ICONHAND,
  87. lpwd->szProgDesc));
  88. }
  89. return(TRUE);
  90. }
  91. //
  92. // Dialog procedure for title dialog
  93. //
  94. BOOL_PTR CALLBACK GetTitleDlgProc(HWND hDlg, UINT message , WPARAM wParam, LPARAM lParam)
  95. {
  96. NMHDR FAR *lpnm = NULL;
  97. LPPROPSHEETPAGE lpPropSheet = (LPPROPSHEETPAGE)(GetWindowLongPtr(hDlg, DWLP_USER));
  98. LPWIZDATA lpwd = NULL;
  99. if (lpPropSheet)
  100. {
  101. lpwd = (LPWIZDATA)lpPropSheet->lParam;
  102. }
  103. switch(message)
  104. {
  105. case WM_NOTIFY:
  106. lpnm = (NMHDR FAR *)lParam;
  107. if(lpnm)
  108. {
  109. switch(lpnm->code)
  110. {
  111. case PSN_SETACTIVE:
  112. if(lpwd)
  113. {
  114. lpwd->hwnd = hDlg;
  115. GetTitleSetActive(lpwd);
  116. }
  117. break;
  118. case PSN_WIZNEXT:
  119. if(lpwd)
  120. {
  121. if (!GetTitleNextPushed(lpwd))
  122. {
  123. GetTitleSetActive(lpwd);
  124. SetDlgMsgResult(hDlg, WM_NOTIFY, -1);
  125. }
  126. }
  127. break;
  128. case PSN_WIZFINISH:
  129. if(lpwd)
  130. {
  131. int iResult = -1;
  132. if (GetTitleNextPushed(lpwd))
  133. {
  134. if (CreateLink(lpwd))
  135. {
  136. iResult = 0;
  137. }
  138. }
  139. if (iResult != 0)
  140. {
  141. GetTitleSetActive(lpwd);
  142. }
  143. SetDlgMsgResult(hDlg, WM_NOTIFY, iResult);
  144. }
  145. break;
  146. case PSN_RESET:
  147. if(lpwd)
  148. {
  149. CleanUpWizData(lpwd);
  150. }
  151. break;
  152. default:
  153. return FALSE;
  154. }
  155. }
  156. break;
  157. case WM_INITDIALOG:
  158. lpwd = InitWizSheet(hDlg, lParam, 0);
  159. if(lpwd)
  160. {
  161. Edit_LimitText(GetDlgItem(hDlg, IDC_TITLE), ARRAYSIZE(lpwd->szProgDesc)-1);
  162. }
  163. break;
  164. case WMPRIV_POKEFOCUS:
  165. {
  166. HWND hTitle = GetDlgItem(hDlg, IDC_TITLE);
  167. SetFocus(hTitle);
  168. Edit_SetSel(hTitle, 0, -1);
  169. break;
  170. }
  171. case WM_DESTROY:
  172. case WM_HELP:
  173. case WM_CONTEXTMENU:
  174. break;
  175. case WM_COMMAND:
  176. switch (GET_WM_COMMAND_ID(wParam, lParam))
  177. {
  178. case IDHELP:
  179. break;
  180. case IDC_TITLE:
  181. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  182. {
  183. case EN_CHANGE:
  184. if(lpwd)
  185. {
  186. EnableNextFinish(lpwd);
  187. }
  188. break;
  189. }
  190. break;
  191. } // end of switch on WM_COMMAND
  192. break;
  193. default:
  194. return FALSE;
  195. } // end of switch on message
  196. return TRUE;
  197. } // GetTitleDlgProc