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.

509 lines
14 KiB

  1. /* dlgprocs.c - Packager-specific dialog routines.
  2. */
  3. #include "packager.h"
  4. #include <shellapi.h>
  5. #include <commdlg.h>
  6. #include "dialogs.h"
  7. // #include "..\..\library\shell.h"
  8. // HACK: Copied from shsemip.h
  9. #ifdef WINNT
  10. WINSHELLAPI int WINAPI PickIconDlg(HWND hwnd, LPWSTR pwszIconPath, UINT cchIconPath, int *piIconIndex);
  11. int PkgPickIconDlg(HWND hwnd, LPSTR pszIconPath, UINT cbIconPath, int *piIconIndex);
  12. #else
  13. WINSHELLAPI int WINAPI PickIconDlg(HWND hwnd, LPSTR pwszIconPath, UINT cchIconPath, int *piIconIndex);
  14. # define PkgPickIconDlg(h, s, c, p) PickIconDlg(h, s, c, p)
  15. #endif
  16. #define CBCUSTFILTER 40
  17. static CHAR szPathField[CBPATHMAX];
  18. static CHAR szDirField[CBPATHMAX];
  19. static CHAR szStarDotEXE[] = "*.EXE";
  20. static CHAR szShellDll[] = "shell32.dll";
  21. static CHAR szCommand[CBCMDLINKMAX];
  22. static CHAR szIconText[CBPATHMAX];
  23. /*--------------------------------------------------------------------------*/
  24. /* */
  25. /* MyDialogBox() - */
  26. /* */
  27. /*--------------------------------------------------------------------------*/
  28. INT_PTR MyDialogBox(
  29. UINT idd,
  30. HWND hwndParent,
  31. DLGPROC lpfnDlgProc
  32. )
  33. {
  34. return DialogBoxAfterBlock(MAKEINTRESOURCE(idd), hwndParent, lpfnDlgProc);
  35. }
  36. #ifdef WINNT
  37. /*
  38. * NT's PickIconDlg is UNICODE only, so thunk it here
  39. */
  40. /* PkgPickIconDlg() -
  41. *
  42. * hwnd - window
  43. * pszIconPath - ANSI path for icon suggested icon file (also output buffer that holds real icon file)
  44. * cchIconPath - size of the buffer in chars pointed to pszIconPath. NOT the string length!
  45. * piIconIndex - receives the index of the icon
  46. *
  47. */
  48. int PkgPickIconDlg(HWND hwnd, LPSTR pszIconPath, UINT cchIconPath, int *piIconIndex) {
  49. WCHAR wszPath[MAX_PATH+1];
  50. int iRet;
  51. MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszIconPath, -1, wszPath, ARRAYSIZE(wszPath));
  52. iRet = PickIconDlg(hwnd, wszPath, cchIconPath, piIconIndex);
  53. wszPath[MAX_PATH] = L'\0'; // Make sure text is zero terminated, even if it is garbage
  54. WideCharToMultiByte( CP_ACP, 0, wszPath, -1, pszIconPath, cchIconPath, NULL, NULL );
  55. return iRet;
  56. }
  57. #endif
  58. /* IconDialog() -
  59. *
  60. */
  61. BOOL
  62. IconDialog(
  63. LPIC lpic
  64. )
  65. {
  66. char szIconPath[MAX_PATH];
  67. int iDlgIcon = lpic->iDlgIcon;
  68. StringCchCopy(szIconPath, ARRAYSIZE(szIconPath), (*lpic->szIconPath) ? lpic->szIconPath : szShellDll);
  69. if (PkgPickIconDlg(ghwndPane[APPEARANCE],
  70. szIconPath, sizeof(szIconPath)/sizeof(char), &iDlgIcon))
  71. {
  72. StringCchCopy(lpic->szIconPath, ARRAYSIZE(lpic->szIconPath), szIconPath);
  73. lpic->iDlgIcon = iDlgIcon;
  74. GetCurrentIcon(lpic);
  75. return TRUE;
  76. }
  77. return FALSE;
  78. }
  79. /* ChangeCmdLine() - Summons the Command Line... dialog.
  80. *
  81. */
  82. BOOL
  83. ChangeCmdLine(
  84. LPCML lpcml
  85. )
  86. {
  87. StringCchCopy(szCommand, ARRAYSIZE(szCommand), lpcml->szCommand);
  88. if (DialogBoxAfterBlock(MAKEINTRESOURCE(DTCHANGECMDTEXT),
  89. ghwndPane[CONTENT], fnChangeCmdText) != IDOK)
  90. return FALSE;
  91. StringCchCopy(lpcml->szCommand, ARRAYSIZE(lpcml->szCommand), szCommand);
  92. CmlFixBounds(lpcml);
  93. return TRUE;
  94. }
  95. /* ChangeLabel() - Summons the Label... dialog.
  96. *
  97. */
  98. VOID
  99. ChangeLabel(
  100. LPIC lpic
  101. )
  102. {
  103. INT iPane = APPEARANCE;
  104. StringCchCopy(szIconText, ARRAYSIZE(szIconText), lpic->szIconText);
  105. if (DialogBoxAfterBlock(MAKEINTRESOURCE(DTCHANGETEXT),
  106. ghwndPane[iPane], fnChangeText)
  107. && lstrcmp(lpic->szIconText, szIconText))
  108. {
  109. // label has changed, set the undo object.
  110. if (glpobjUndo[iPane])
  111. DeletePaneObject(glpobjUndo[iPane], gptyUndo[iPane]);
  112. gptyUndo[iPane] = ICON;
  113. glpobjUndo[iPane] = IconClone (lpic);
  114. StringCchCopy(lpic->szIconText, ARRAYSIZE(lpic->szIconText), szIconText);
  115. }
  116. }
  117. /**************************** Dialog Functions ****************************/
  118. /* fnChangeCmdText() - Command Line... dialog procedure.
  119. */
  120. INT_PTR CALLBACK
  121. fnChangeCmdText(
  122. HWND hDlg,
  123. UINT msg,
  124. WPARAM wParam,
  125. LPARAM lParam
  126. )
  127. {
  128. LPSTR psz;
  129. switch (msg)
  130. {
  131. case WM_INITDIALOG:
  132. SetDlgItemText(hDlg, IDD_COMMAND, szCommand);
  133. SendDlgItemMessage(hDlg, IDD_COMMAND, EM_LIMITTEXT, CBCMDLINKMAX - 1, 0L);
  134. PostMessage(hDlg, WM_NEXTDLGCTL,
  135. (WPARAM)GetDlgItem(hDlg, IDD_COMMAND), 1L);
  136. break;
  137. case WM_COMMAND:
  138. switch (LOWORD(wParam))
  139. {
  140. case IDD_LABEL:
  141. PostMessage(hDlg, WM_NEXTDLGCTL,
  142. (WPARAM)GetDlgItem(hDlg, IDD_COMMAND), 1L);
  143. break;
  144. case IDOK:
  145. GetDlgItemText(hDlg, IDD_COMMAND, szCommand, CBCMDLINKMAX);
  146. /*
  147. * Eat leading spaces to make Afrikaners in high places
  148. * happy.
  149. */
  150. psz = szCommand;
  151. while(*psz == CHAR_SPACE)
  152. psz++;
  153. if( psz != szCommand ) {
  154. LPSTR pszDst = szCommand;
  155. while(*psz) {
  156. *pszDst++ = *psz++;
  157. }
  158. /* copy null across */
  159. *pszDst = *psz;
  160. }
  161. // FALL THROUGH TO IDCANCEL
  162. case IDCANCEL:
  163. EndDialog(hDlg, LOWORD(wParam));
  164. }
  165. }
  166. return FALSE;
  167. }
  168. /* fnProperties() - Link Properties... dialog
  169. */
  170. INT_PTR CALLBACK
  171. fnProperties(
  172. HWND hDlg,
  173. UINT msg,
  174. WPARAM wParam,
  175. LPARAM lParam
  176. )
  177. {
  178. HWND hwndLB = GetDlgItem(hDlg, IDD_LISTBOX);
  179. switch (msg)
  180. {
  181. case WM_REDRAW:
  182. SendMessage(hwndLB, WM_SETREDRAW, 0, 0L);
  183. case WM_INITDIALOG:
  184. {
  185. BOOL fChangeLink = TRUE;
  186. HANDLE hData = NULL;
  187. LONG otFocus;
  188. LPSTR lpstrData = NULL;
  189. LPSTR lpstrTemp;
  190. LPOLEOBJECT lpObject;
  191. LPVOID lpobjFocus;
  192. LPVOID lpobjFocusUndo;
  193. OLEOPT_UPDATE update;
  194. CHAR szType[CBMESSAGEMAX];
  195. CHAR szFull[CBMESSAGEMAX * 4];
  196. INT idButton;
  197. INT iPane;
  198. iPane = (GetTopWindow(ghwndFrame) == ghwndPane[CONTENT]);
  199. lpobjFocus = glpobj[iPane];
  200. lpobjFocusUndo = glpobjUndo[iPane];
  201. lpObject = ((LPPICT)lpobjFocus)->lpObject;
  202. // Reset the list box
  203. SendMessage(hwndLB, LB_RESETCONTENT, 0, 0L);
  204. if (msg == WM_INITDIALOG)
  205. {
  206. // If it wasn't a link it doesn't belong
  207. OleQueryType(lpObject, &otFocus);
  208. if (otFocus != OT_LINK)
  209. {
  210. ghwndError = ghwndFrame;
  211. EndDialog(hDlg, TRUE);
  212. break;
  213. }
  214. PicSaveUndo(lpobjFocus);
  215. ghwndError = hDlg;
  216. }
  217. //
  218. // Redrawing the string, get the update options and
  219. // the button state for IDD_AUTO/IDD_MANUAL.
  220. //
  221. Error(OleGetLinkUpdateOptions(lpObject, &update));
  222. switch (update)
  223. {
  224. case oleupdate_always:
  225. LoadString(ghInst, IDS_AUTO, szType, CBMESSAGEMAX);
  226. idButton = IDD_AUTO;
  227. break;
  228. case oleupdate_oncall:
  229. LoadString(ghInst, IDS_MANUAL, szType, CBMESSAGEMAX);
  230. idButton = IDD_MANUAL;
  231. break;
  232. default:
  233. LoadString(ghInst, IDS_CANCELED, szType, CBMESSAGEMAX);
  234. idButton = -1;
  235. // Disable the change link button
  236. fChangeLink = FALSE;
  237. }
  238. //
  239. // Retrieve the server name (try it from Undo
  240. // if the object has been frozen)
  241. //
  242. if (Error(OleGetData(lpObject, gcfLink, &hData)) || !hData)
  243. {
  244. OleQueryType(lpObject, &otFocus);
  245. if (otFocus != OT_STATIC)
  246. {
  247. ErrorMessage(E_GET_FROM_CLIPBOARD_FAILED);
  248. return TRUE;
  249. }
  250. if (gptyUndo[iPane] == PICTURE &&
  251. (Error(OleGetData(((LPPICT)lpobjFocusUndo)->lpObject,
  252. gcfLink, &hData)) || !hData))
  253. {
  254. ErrorMessage(E_GET_FROM_CLIPBOARD_FAILED);
  255. return TRUE;
  256. }
  257. }
  258. // The link format is: "szClass0szDocument0szItem00"
  259. if (hData && (lpstrData = GlobalLock(hData)))
  260. {
  261. // Retrieve the server's class ID
  262. RegGetClassId(szFull, ARRAYSIZE(szFull), lpstrData);
  263. StringCchCat(szFull, ARRAYSIZE(szFull), "\t");
  264. // Display the Document and Item names
  265. while (*lpstrData++)
  266. ;
  267. // Strip off the path name and drive letter
  268. lpstrTemp = lpstrData;
  269. while (*lpstrTemp)
  270. {
  271. if (*lpstrTemp == '\\' || *lpstrTemp == ':')
  272. lpstrData = lpstrTemp + 1;
  273. if (gbDBCS)
  274. {
  275. lpstrTemp = CharNext(lpstrTemp);
  276. }
  277. else
  278. {
  279. lpstrTemp++;
  280. }
  281. }
  282. // Append the file name
  283. StringCchCat(szFull, ARRAYSIZE(szFull), lpstrData);
  284. StringCchCat(szFull, ARRAYSIZE(szFull), "\t");
  285. // Append the item name
  286. while (*lpstrData++)
  287. ;
  288. StringCchCat(szFull, ARRAYSIZE(szFull), lpstrData);
  289. StringCchCat(szFull, ARRAYSIZE(szFull), "\t");
  290. GlobalUnlock(hData);
  291. }
  292. else
  293. {
  294. StringCchCopy(szFull, ARRAYSIZE(szFull), "\t\t\t");
  295. }
  296. // Append the type of link
  297. StringCchCat(szFull, ARRAYSIZE(szFull), szType);
  298. // Draw the link in the list box
  299. SendMessage(hwndLB, LB_INSERTSTRING, (WPARAM) - 1, (LPARAM)szFull);
  300. if (msg == WM_REDRAW)
  301. {
  302. SendMessage(hwndLB, WM_SETREDRAW, 1, 0L);
  303. InvalidateRect(hwndLB, NULL, TRUE);
  304. Dirty();
  305. }
  306. // Uncheck those buttons that shouldn't be checked
  307. if (IsDlgButtonChecked(hDlg, IDD_AUTO) && (idButton != IDD_AUTO))
  308. CheckDlgButton(hDlg, IDD_AUTO, FALSE);
  309. if (IsDlgButtonChecked(hDlg, IDD_MANUAL) && (idButton != IDD_MANUAL))
  310. CheckDlgButton(hDlg, IDD_MANUAL, FALSE);
  311. // Check the dialog button, as appropriate
  312. if ((idButton == IDD_AUTO) || (idButton == IDD_MANUAL))
  313. CheckDlgButton(hDlg, idButton, TRUE);
  314. // Enable the other buttons appropriately
  315. EnableWindow(GetDlgItem(hDlg, IDD_CHANGE),
  316. ((otFocus != OT_STATIC) && fChangeLink));
  317. EnableWindow(GetDlgItem(hDlg, IDD_EDIT), (otFocus != OT_STATIC));
  318. EnableWindow(GetDlgItem(hDlg, IDD_PLAY), (otFocus != OT_STATIC));
  319. EnableWindow(GetDlgItem(hDlg, IDD_UPDATE), (otFocus != OT_STATIC));
  320. EnableWindow(GetDlgItem(hDlg, IDD_CHANGE), (otFocus != OT_STATIC));
  321. EnableWindow(GetDlgItem(hDlg, IDD_MANUAL), (otFocus != OT_STATIC));
  322. EnableWindow(GetDlgItem(hDlg, IDD_AUTO), (otFocus != OT_STATIC));
  323. EnableWindow(GetDlgItem(hDlg, IDD_FREEZE), (otFocus != OT_STATIC));
  324. return TRUE;
  325. }
  326. case WM_COMMAND:
  327. switch (LOWORD(wParam))
  328. {
  329. case IDCANCEL:
  330. PostMessage(ghwndFrame, WM_COMMAND, IDM_UNDO, 0L);
  331. case IDOK:
  332. ghwndError = ghwndFrame;
  333. EndDialog(hDlg, TRUE);
  334. return TRUE;
  335. default:
  336. break;
  337. }
  338. SendMessage(ghwndPane[GetTopWindow(ghwndFrame) == ghwndPane[CONTENT]],
  339. WM_COMMAND, wParam, 0L);
  340. switch (LOWORD(wParam))
  341. {
  342. // Dismiss the dialog on Edit/Activate
  343. case IDD_EDIT:
  344. case IDD_PLAY:
  345. ghwndError = ghwndFrame;
  346. EndDialog(hDlg, TRUE);
  347. return TRUE;
  348. default:
  349. break;
  350. }
  351. break;
  352. }
  353. return FALSE;
  354. }
  355. /* fnChangeText() - Label... dialog
  356. */
  357. INT_PTR CALLBACK
  358. fnChangeText(
  359. HWND hDlg,
  360. UINT msg,
  361. WPARAM wParam,
  362. LPARAM lParam
  363. )
  364. {
  365. switch (msg)
  366. {
  367. case WM_INITDIALOG:
  368. SetDlgItemText(hDlg, IDD_ICONTEXT, szIconText);
  369. SendDlgItemMessage(hDlg, IDD_ICONTEXT, EM_LIMITTEXT, 39, 0L);
  370. PostMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, IDD_ICONTEXT),
  371. 1L);
  372. break;
  373. case WM_COMMAND:
  374. switch (LOWORD(wParam))
  375. {
  376. case IDD_LABEL:
  377. PostMessage(hDlg, WM_NEXTDLGCTL,
  378. (WPARAM)GetDlgItem(hDlg, IDD_ICONTEXT), 1L);
  379. break;
  380. case IDOK:
  381. GetDlgItemText(hDlg, IDD_ICONTEXT, szIconText, CBMESSAGEMAX);
  382. EndDialog(hDlg, TRUE);
  383. break;
  384. case IDCANCEL:
  385. EndDialog(hDlg, FALSE);
  386. break;
  387. }
  388. }
  389. return FALSE;
  390. }
  391. /* fnInvalidLink() - Invalid Link dialog
  392. *
  393. * This is the two button "Link unavailable" dialog box.
  394. */
  395. INT_PTR CALLBACK
  396. fnInvalidLink(
  397. HWND hDlg,
  398. UINT msg,
  399. WPARAM wParam,
  400. LPARAM lParam
  401. )
  402. {
  403. switch (msg)
  404. {
  405. case WM_COMMAND:
  406. switch (LOWORD(wParam))
  407. {
  408. case IDOK:
  409. case IDD_CHANGE:
  410. EndDialog(hDlg, LOWORD(wParam));
  411. }
  412. }
  413. return FALSE;
  414. }