Source code of Windows XP (NT5)
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.

246 lines
7.2 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, 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 (lpwd->dwFlags & WDFLAG_SINGLEAPP)
  135. {
  136. PIFWIZERR err = ConfigRealModeOptions(lpwd, NULL,
  137. CRMOACTION_DEFAULT);
  138. if (err == PIFWIZERR_SUCCESS ||
  139. err == PIFWIZERR_UNSUPPORTEDOPT)
  140. {
  141. iResult = 0;
  142. }
  143. }
  144. else
  145. {
  146. if (CreateLink(lpwd))
  147. {
  148. iResult = 0;
  149. }
  150. }
  151. }
  152. if (iResult != 0)
  153. {
  154. GetTitleSetActive(lpwd);
  155. }
  156. SetDlgMsgResult(hDlg, WM_NOTIFY, iResult);
  157. }
  158. break;
  159. case PSN_RESET:
  160. if(lpwd)
  161. {
  162. CleanUpWizData(lpwd);
  163. }
  164. break;
  165. default:
  166. return FALSE;
  167. }
  168. }
  169. break;
  170. case WM_INITDIALOG:
  171. lpwd = InitWizSheet(hDlg, lParam, 0);
  172. if(lpwd)
  173. {
  174. Edit_LimitText(GetDlgItem(hDlg, IDC_TITLE), ARRAYSIZE(lpwd->szProgDesc)-1);
  175. }
  176. break;
  177. case WMPRIV_POKEFOCUS:
  178. {
  179. HWND hTitle = GetDlgItem(hDlg, IDC_TITLE);
  180. SetFocus(hTitle);
  181. Edit_SetSel(hTitle, 0, -1);
  182. break;
  183. }
  184. case WM_DESTROY:
  185. case WM_HELP:
  186. case WM_CONTEXTMENU:
  187. break;
  188. case WM_COMMAND:
  189. switch (GET_WM_COMMAND_ID(wParam, lParam))
  190. {
  191. case IDHELP:
  192. break;
  193. case IDC_TITLE:
  194. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  195. {
  196. case EN_CHANGE:
  197. if(lpwd)
  198. {
  199. EnableNextFinish(lpwd);
  200. }
  201. break;
  202. }
  203. break;
  204. } // end of switch on WM_COMMAND
  205. break;
  206. default:
  207. return FALSE;
  208. } // end of switch on message
  209. return TRUE;
  210. } // GetTitleDlgProc