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.

801 lines
24 KiB

  1. //--------------------------------------------------------------------------
  2. // Newfldr.cpp
  3. //--------------------------------------------------------------------------
  4. #include "pch.hxx"
  5. #include "imagelst.h"
  6. #include "newfldr.h"
  7. #include <ourguid.h>
  8. #include "conman.h"
  9. #include "storutil.h"
  10. #include "storecb.h"
  11. #include "shlwapip.h"
  12. #include "instance.h"
  13. #include "demand.h"
  14. //--------------------------------------------------------------------------
  15. // Constants
  16. //--------------------------------------------------------------------------
  17. #define WM_SETFOLDERSELECT (WM_USER + 1666)
  18. //--------------------------------------------------------------------------
  19. // SELECTFOLDER
  20. //--------------------------------------------------------------------------
  21. typedef struct tagSELECTFOLDER {
  22. DWORD op;
  23. FOLDERID idCurrent; // Current Selected Folder
  24. FOLDERDIALOGFLAGS dwFlags; // Folder dialog flags
  25. LPSTR pszTitle; // Title of the dialog box
  26. LPSTR pszText; // Why are you asking for a folder
  27. FOLDERID idSelected; // The selected folder
  28. CTreeViewFrame *pFrame; // Treeview frame object
  29. BOOL fPending;
  30. CStoreDlgCB *pCallback;
  31. FOLDERID idParent;
  32. char szName[CCHMAX_FOLDER_NAME];
  33. } SELECTFOLDER, *LPSELECTFOLDER;
  34. //--------------------------------------------------------------------------
  35. // NEWFOLDERDIALOGINIT
  36. //--------------------------------------------------------------------------
  37. typedef struct tagNEWFOLDERDIALOGINIT {
  38. IN FOLDERID idParent;
  39. OUT FOLDERID idNew;
  40. BOOL fPending;
  41. IN CStoreDlgCB *pCallback;
  42. char szName[CCHMAX_FOLDER_NAME];
  43. } NEWFOLDERDIALOGINIT, *LPNEWFOLDERDIALOGINIT;
  44. //--------------------------------------------------------------------------
  45. // SelectFolderDlgProc
  46. //--------------------------------------------------------------------------
  47. INT_PTR CALLBACK SelectFolderDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  48. INT_PTR CALLBACK NewFolderDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  49. HRESULT CreateNewFolder(HWND hwnd, LPCSTR pszName, FOLDERID idParent, LPFOLDERID pidNew, IStoreCallback *pCallback);
  50. BOOL EnabledFolder(HWND hwnd, LPSELECTFOLDER pSelect, FOLDERID idFolder);
  51. HRESULT GetCreatedFolderId(FOLDERID idParent, LPCSTR pszName, FOLDERID *pid);
  52. BOOL SelectFolder_HandleCommand(HWND hwnd, WORD wID, LPSELECTFOLDER pSelect);
  53. void SelectFolder_HandleStoreComplete(HWND hwnd, LPSELECTFOLDER pSelect);
  54. //--------------------------------------------------------------------------
  55. // Globals
  56. //--------------------------------------------------------------------------
  57. static FOLDERID g_idPrevSel = FOLDERID_LOCAL_STORE;
  58. //--------------------------------------------------------------------------
  59. // SelectFolderDialog
  60. //--------------------------------------------------------------------------
  61. HRESULT SelectFolderDialog(
  62. IN HWND hwnd,
  63. IN DWORD op,
  64. IN FOLDERID idCurrent,
  65. IN FOLDERDIALOGFLAGS dwFlags,
  66. IN_OPT LPCSTR pszTitle,
  67. IN_OPT LPCSTR pszText,
  68. OUT_OPT LPFOLDERID pidSelected)
  69. {
  70. // Locals
  71. HRESULT hr=S_OK;
  72. UINT uAnswer;
  73. SELECTFOLDER Select={0};
  74. // Trace
  75. TraceCall("SelectFolderDialog");
  76. // Invalid Args
  77. Assert(IsWindow(hwnd));
  78. Assert(((int) op) >= SFD_SELECTFOLDER && op < SFD_LAST);
  79. // Initialize Select Folder
  80. Select.op = op;
  81. if (SFD_MOVEFOLDER == op || (!!(dwFlags & FD_FORCEINITSELFOLDER) && FOLDERID_ROOT != idCurrent))
  82. {
  83. Assert(idCurrent != FOLDERID_INVALID);
  84. Select.idCurrent = idCurrent;
  85. }
  86. else
  87. {
  88. Select.idCurrent = g_idPrevSel;
  89. }
  90. Select.dwFlags = dwFlags | TREEVIEW_DIALOG;
  91. if (g_dwAthenaMode & MODE_OUTLOOKNEWS)
  92. Select.dwFlags |= TREEVIEW_NOIMAP | TREEVIEW_NOHTTP;
  93. Select.pszTitle = (LPSTR)pszTitle;
  94. Select.pszText = (LPSTR)pszText;
  95. Select.pCallback = new CStoreDlgCB;
  96. if (Select.pCallback == NULL)
  97. return(E_OUTOFMEMORY);
  98. // Create the Dialog Box
  99. if (IDOK != DialogBoxParam(g_hLocRes, ((op == SFD_NEWFOLDER) ? MAKEINTRESOURCE(iddCreateFolder) : MAKEINTRESOURCE(iddSelectFolder)), hwnd, SelectFolderDlgProc, (LPARAM)&Select))
  100. {
  101. hr = TraceResult(hrUserCancel);
  102. goto exit;
  103. }
  104. // Return selected folderid
  105. g_idPrevSel = Select.idSelected;
  106. if (pidSelected)
  107. *pidSelected = Select.idSelected;
  108. exit:
  109. Select.pCallback->Release();
  110. // Done
  111. return hr;
  112. }
  113. //--------------------------------------------------------------------------
  114. // SelectFolderDlgProc
  115. //--------------------------------------------------------------------------
  116. INT_PTR CALLBACK SelectFolderDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  117. {
  118. // Locals
  119. FOLDERINFO info;
  120. HRESULT hr;
  121. BOOL fEnable;
  122. LPSELECTFOLDER pSelect;
  123. HWND hwndT;
  124. HWND hwndTree;
  125. CHAR sz[256];
  126. WORD wID;
  127. RECT rc;
  128. FOLDERID id;
  129. NEWFOLDERDIALOGINIT NewFolder;
  130. FOLDERINFO Folder;
  131. CTreeView *pTreeView;
  132. // Trace
  133. TraceCall("SelectFolderDlgProc");
  134. // Get pSelect
  135. pSelect = (LPSELECTFOLDER)GetWndThisPtr(hwnd);
  136. switch (msg)
  137. {
  138. case WM_INITDIALOG:
  139. // Better not have it yet
  140. Assert(NULL == pSelect);
  141. // Set pSelect
  142. pSelect = (LPSELECTFOLDER)lParam;
  143. // Set This pointer
  144. SetWndThisPtr(hwnd, (LPSELECTFOLDER)lParam);
  145. if (pSelect->op != SFD_SELECTFOLDER)
  146. {
  147. Assert(pSelect->pCallback != NULL);
  148. pSelect->pCallback->Initialize(hwnd);
  149. }
  150. if (pSelect->op == SFD_NEWFOLDER)
  151. {
  152. hwndT = GetDlgItem(hwnd, idcFolderEdit);
  153. SetIntlFont(hwndT);
  154. SendMessage(hwndT, EM_LIMITTEXT, CCHMAX_FOLDER_NAME - 1, 0);
  155. }
  156. else if (ISFLAGSET(pSelect->dwFlags, FD_NONEWFOLDERS))
  157. {
  158. ShowWindow(GetDlgItem(hwnd, idcNewFolderBtn), SW_HIDE);
  159. }
  160. // Set the title
  161. if (pSelect->pszTitle != NULL)
  162. {
  163. // Must be a string resourceid
  164. if (IS_INTRESOURCE(pSelect->pszTitle))
  165. {
  166. // Load the String
  167. AthLoadString(PtrToUlong(pSelect->pszTitle), sz, ARRAYSIZE(sz));
  168. // Set Temp
  169. SetWindowText(hwnd, sz);
  170. }
  171. // Otherwise, just use the string
  172. else
  173. SetWindowText(hwnd, pSelect->pszTitle);
  174. }
  175. // Do we have some status text
  176. if (pSelect->pszText != NULL)
  177. {
  178. // Must be a resource string id
  179. if (IS_INTRESOURCE(pSelect->pszText))
  180. {
  181. // Load the String
  182. AthLoadString(PtrToUlong(pSelect->pszText), sz, ARRAYSIZE(sz));
  183. // Set Temp
  184. SetWindowText(GetDlgItem(hwnd, idcTreeViewText), sz);
  185. }
  186. // Otherwise, just use the string
  187. else
  188. SetWindowText(GetDlgItem(hwnd, idcTreeViewText), pSelect->pszText);
  189. }
  190. // Set the treeview font
  191. hwndT = GetDlgItem(hwnd, idcTreeView);
  192. Assert(hwndT != NULL);
  193. SetIntlFont(hwndT);
  194. GetWindowRect(hwndT, &rc);
  195. MapWindowPoints(NULL, hwnd, (LPPOINT)&rc, 2);
  196. DestroyWindow(hwndT);
  197. // Create a Frame
  198. pSelect->pFrame = new CTreeViewFrame;
  199. if (NULL == pSelect->pFrame)
  200. {
  201. EndDialog(hwnd, IDCANCEL);
  202. return FALSE;
  203. }
  204. // Initialzie the tree view frame
  205. if (FAILED(pSelect->pFrame->Initialize(hwnd, &rc, (TREEVIEW_FLAGS & pSelect->dwFlags))))
  206. {
  207. EndDialog(hwnd, IDCANCEL);
  208. return FALSE;
  209. }
  210. // Get the Tree View Object from the Frame
  211. pTreeView = pSelect->pFrame->GetTreeView();
  212. // Get the Window Handle
  213. if (SUCCEEDED(pTreeView->GetWindow(&hwndTree)))
  214. {
  215. hwndT = GetDlgItem(hwnd, idcTreeViewText);
  216. SetWindowPos(hwndTree, hwndT, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOSIZE);
  217. }
  218. // Refresh the Treeview
  219. pTreeView->Refresh();
  220. // Set current selection
  221. if (FAILED(pTreeView->SetSelection(pSelect->idCurrent, 0)))
  222. {
  223. pSelect->idCurrent = g_idPrevSel;
  224. pTreeView->SetSelection(pSelect->idCurrent, 0);
  225. }
  226. // Center Myself
  227. CenterDialog(hwnd);
  228. // Done
  229. return(TRUE);
  230. case WM_SETFOLDERSELECT:
  231. // Validate Params
  232. Assert(wParam != NULL && pSelect != NULL);
  233. // Get the Tree View Object
  234. pTreeView = pSelect->pFrame->GetTreeView();
  235. // Validate
  236. Assert(pTreeView != NULL);
  237. // Set current selection
  238. pTreeView->SetSelection((FOLDERID)wParam, 0);
  239. // Done
  240. return(TRUE);
  241. case WM_STORE_COMPLETE:
  242. SelectFolder_HandleStoreComplete(hwnd, pSelect);
  243. return(TRUE);
  244. case WM_COMMAND:
  245. // Get the Command Id
  246. wID = LOWORD(wParam);
  247. return(SelectFolder_HandleCommand(hwnd, wID, pSelect));
  248. case TVM_SELCHANGED:
  249. // Possibly disable choosing the newly selected folder based on flags we were given
  250. fEnable = EnabledFolder(hwnd, pSelect, (FOLDERID)lParam);
  251. // Enable the OK Button
  252. EnableWindow(GetDlgItem(hwnd, IDOK), fEnable);
  253. // Get the new folder button hwnd
  254. hwndT = GetDlgItem(hwnd, SFD_SELECTFOLDER == pSelect->op ? idcNewFolderBtn : IDOK);
  255. if (hwndT != NULL)
  256. {
  257. // Get Folder Info
  258. if (SUCCEEDED(g_pStore->GetFolderInfo((FOLDERID)lParam, &Folder)))
  259. {
  260. // fEnable
  261. fEnable = Folder.idFolder != FOLDERID_ROOT &&
  262. Folder.tyFolder != FOLDER_NEWS &&
  263. !ISFLAGSET(Folder.dwFlags, FOLDER_NOCHILDCREATE);
  264. // Enable/disable the window
  265. EnableWindow(hwndT, fEnable);
  266. // Free
  267. g_pStore->FreeRecord(&Folder);
  268. }
  269. }
  270. // Done
  271. return(TRUE);
  272. case TVM_DBLCLICK:
  273. // If Not Creating a Folder:
  274. if (pSelect->op != SFD_NEWFOLDER)
  275. {
  276. // If the OK button isn't enabled, I can't select this folder
  277. if (FALSE == IsWindowEnabled(GetDlgItem(hwnd, IDOK)))
  278. return(TRUE);
  279. pTreeView = pSelect->pFrame->GetTreeView();
  280. id = pTreeView->GetSelection();
  281. hr = g_pStore->GetFolderInfo(id, &info);
  282. if (SUCCEEDED(hr))
  283. {
  284. if (!FHasChildren(&info, TRUE))
  285. SelectFolder_HandleCommand(hwnd, IDOK, pSelect);
  286. g_pStore->FreeRecord(&info);
  287. }
  288. }
  289. // Done
  290. return(TRUE);
  291. case WM_DESTROY:
  292. // Close the Tree View
  293. if (pSelect != NULL && pSelect->pFrame != NULL)
  294. {
  295. // Close the TreeView
  296. pSelect->pFrame->CloseTreeView();
  297. // Release the Frame
  298. SideAssert(pSelect->pFrame->Release() == 0);
  299. }
  300. // Done
  301. return(TRUE);
  302. }
  303. // Done
  304. return(FALSE);
  305. }
  306. //--------------------------------------------------------------------------
  307. // SelectFolderDlgProc
  308. //--------------------------------------------------------------------------
  309. INT_PTR CALLBACK NewFolderDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  310. {
  311. // Locals
  312. HRESULT hr;
  313. LPNEWFOLDERDIALOGINIT pNew;
  314. WORD wID;
  315. FOLDERID id;
  316. HWND hwndEdit;
  317. // Trace
  318. TraceCall("NewFolderDlgProc");
  319. // Get This
  320. pNew = (LPNEWFOLDERDIALOGINIT)GetWndThisPtr(hwnd);
  321. // Handle the Message
  322. switch (msg)
  323. {
  324. case WM_INITDIALOG:
  325. // Shouldn't Have This
  326. Assert(pNew == NULL);
  327. // Set pNew
  328. pNew = (LPNEWFOLDERDIALOGINIT)lParam;
  329. // Set this Pointer
  330. SetWndThisPtr(hwnd, (LPNEWFOLDERDIALOGINIT)lParam);
  331. Assert(pNew->pCallback != NULL);
  332. pNew->pCallback->Initialize(hwnd);
  333. // Get the Folder Name Edit
  334. hwndEdit = GetDlgItem(hwnd, idtxtFolderName);
  335. // Correct for intl.
  336. SetIntlFont(hwndEdit);
  337. // Limit the text
  338. SendMessage(hwndEdit, EM_LIMITTEXT, CCHMAX_FOLDER_NAME - 1, 0);
  339. // Center
  340. CenterDialog(hwnd);
  341. // Done
  342. return(TRUE);
  343. case WM_STORE_COMPLETE:
  344. Assert(pNew->fPending);
  345. pNew->fPending = FALSE;
  346. hr = pNew->pCallback->GetResult();
  347. if (hr == S_FALSE)
  348. {
  349. EndDialog(hwnd, IDCANCEL);
  350. }
  351. else if (SUCCEEDED(hr))
  352. {
  353. hr = GetCreatedFolderId(pNew->idParent, pNew->szName, &id);
  354. if (SUCCEEDED(hr))
  355. pNew->idNew = id;
  356. else
  357. pNew->idNew = pNew->idParent;
  358. EndDialog(hwnd, IDOK);
  359. }
  360. else
  361. {
  362. // No need to put up error dialog, CStoreDlgCB already did this on failed OnComplete
  363. hwndEdit = GetDlgItem(hwnd, idtxtFolderName);
  364. SendMessage(hwndEdit, EM_SETSEL, 0, -1);
  365. SetFocus(hwndEdit);
  366. }
  367. return(TRUE);
  368. case WM_COMMAND:
  369. // Get the Command Id
  370. wID = LOWORD(wParam);
  371. // Handle the Command
  372. switch (wID)
  373. {
  374. case IDOK:
  375. if (pNew->fPending)
  376. return(TRUE);
  377. Assert(pNew->pCallback != NULL);
  378. pNew->pCallback->Reset();
  379. hwndEdit = GetDlgItem(hwnd, idtxtFolderName);
  380. GetWindowText(hwndEdit, pNew->szName, ARRAYSIZE(pNew->szName));
  381. // Try to Create the Folder
  382. hr = CreateNewFolder(hwnd, pNew->szName, pNew->idParent, &pNew->idNew, (IStoreCallback *)pNew->pCallback);
  383. if (hr == E_PENDING)
  384. {
  385. pNew->fPending = TRUE;
  386. break;
  387. }
  388. else if (FAILED(hr))
  389. {
  390. AthErrorMessageW(hwnd, MAKEINTRESOURCEW(idsAthena), MAKEINTRESOURCEW(idsErrCreateNewFld), hr);
  391. SendMessage(hwndEdit, EM_SETSEL, 0, -1);
  392. SetFocus(hwndEdit);
  393. break;
  394. }
  395. // End the dialog
  396. EndDialog(hwnd, IDOK);
  397. // done
  398. return(TRUE);
  399. case IDCANCEL:
  400. if (pNew->fPending)
  401. pNew->pCallback->Cancel();
  402. else
  403. // End the dialog
  404. EndDialog(hwnd, IDCANCEL);
  405. // Done
  406. return(TRUE);
  407. }
  408. // Done
  409. break;
  410. }
  411. // Done
  412. return(FALSE);
  413. }
  414. //--------------------------------------------------------------------------
  415. // CreateNewFolder
  416. //--------------------------------------------------------------------------
  417. HRESULT CreateNewFolder(HWND hwnd, LPCSTR pszName, FOLDERID idParent, LPFOLDERID pidNew, IStoreCallback *pCallback)
  418. {
  419. // Locals
  420. HRESULT hr;
  421. ULONG cchFolder;
  422. FOLDERINFO Folder;
  423. // Trace
  424. TraceCall("CreateNewFolder");
  425. Assert(pCallback != NULL);
  426. // Get Text Length
  427. cchFolder = lstrlen(pszName);
  428. // Invalid
  429. if (0 == cchFolder)
  430. return(STORE_E_BADFOLDERNAME);
  431. // Filup the Folder Info
  432. ZeroMemory(&Folder, sizeof(FOLDERINFO));
  433. Folder.idParent = idParent;
  434. Folder.tySpecial = FOLDER_NOTSPECIAL;
  435. Folder.pszName = (LPSTR)pszName;
  436. Folder.dwFlags = FOLDER_SUBSCRIBED;
  437. // Create the Folder
  438. hr = g_pStore->CreateFolder(NOFLAGS, &Folder, pCallback);
  439. if (hr == E_PENDING)
  440. return(hr);
  441. // Return the Folder Id
  442. if (pidNew)
  443. *pidNew = Folder.idFolder;
  444. // Done
  445. return (hr);
  446. }
  447. //--------------------------------------------------------------------------
  448. // EnabledFolder
  449. //--------------------------------------------------------------------------
  450. BOOL EnabledFolder(HWND hwnd, LPSELECTFOLDER pSelect, FOLDERID idFolder)
  451. {
  452. // Locals
  453. BOOL fRet = FALSE;
  454. FOLDERINFO Folder;
  455. // Trace
  456. TraceCall("EnabledFolder");
  457. // Get Folder Info
  458. if (FAILED(g_pStore->GetFolderInfo(idFolder, &Folder)))
  459. goto exit;
  460. // FD_DISABLEROOT
  461. if (ISFLAGSET(pSelect->dwFlags, FD_DISABLEROOT) && FOLDERID_ROOT == idFolder)
  462. goto exit;
  463. // FD_DISABLEINBOX
  464. if (ISFLAGSET(pSelect->dwFlags, FD_DISABLEINBOX) && FOLDER_INBOX == Folder.tySpecial)
  465. goto exit;
  466. // FD_DISABLEOUTBOX
  467. if (ISFLAGSET(pSelect->dwFlags, FD_DISABLEOUTBOX) && FOLDER_OUTBOX == Folder.tySpecial)
  468. goto exit;
  469. // FD_DISABLESENTITEMS
  470. if (ISFLAGSET(pSelect->dwFlags, FD_DISABLESENTITEMS) && FOLDER_SENT == Folder.tySpecial)
  471. goto exit;
  472. // FD_DISABLESERVERS
  473. if (ISFLAGSET(pSelect->dwFlags, FD_DISABLESERVERS) && ISFLAGSET(Folder.dwFlags, FOLDER_SERVER))
  474. goto exit;
  475. fRet = TRUE;
  476. exit:
  477. // Cleanup
  478. g_pStore->FreeRecord(&Folder);
  479. // Default
  480. return fRet;
  481. }
  482. HRESULT GetCreatedFolderId(FOLDERID idParent, LPCSTR pszName, FOLDERID *pid)
  483. {
  484. HRESULT hr;
  485. HLOCK hLock;
  486. FOLDERINFO Folder = {0};
  487. Assert(pszName != NULL);
  488. Assert(pid != NULL);
  489. hr = g_pStore->Lock(&hLock);
  490. if (FAILED(hr))
  491. return(hr);
  492. Folder.idParent = idParent;
  493. Folder.pszName = (LPSTR)pszName;
  494. if (DB_S_FOUND == g_pStore->FindRecord(IINDEX_ALL, COLUMNS_ALL, &Folder, NULL))
  495. {
  496. *pid = Folder.idFolder;
  497. g_pStore->FreeRecord(&Folder);
  498. }
  499. else
  500. {
  501. hr = E_FAIL;
  502. }
  503. g_pStore->Unlock(&hLock);
  504. return(hr);
  505. }
  506. BOOL SelectFolder_HandleCommand(HWND hwnd, WORD wID, LPSELECTFOLDER pSelect)
  507. {
  508. HRESULT hr;
  509. HWND hwndT;
  510. FOLDERID id=FOLDERID_INVALID;
  511. NEWFOLDERDIALOGINIT NewFolder;
  512. CTreeView *pTreeView;
  513. switch (wID)
  514. {
  515. case idcNewFolderBtn:
  516. pTreeView = pSelect->pFrame->GetTreeView();
  517. ZeroMemory(&NewFolder, sizeof(NEWFOLDERDIALOGINIT));
  518. NewFolder.idParent = pTreeView->GetSelection();
  519. NewFolder.pCallback = new CStoreDlgCB;
  520. if (NewFolder.pCallback == NULL)
  521. // TODO: an error message might be helpful
  522. return(TRUE);
  523. // Launch the dialog to create a new folder
  524. if (IDOK == DialogBoxParam(g_hLocRes, MAKEINTRESOURCE(iddNewFolder), hwnd, NewFolderDlgProc, (LPARAM)&NewFolder))
  525. {
  526. // Select the new folder
  527. PostMessage(hwnd, WM_SETFOLDERSELECT, (WPARAM)NewFolder.idNew, 0);
  528. }
  529. NewFolder.pCallback->Release();
  530. return(TRUE);
  531. case IDOK:
  532. if (pSelect->fPending)
  533. return(TRUE);
  534. pTreeView = pSelect->pFrame->GetTreeView();
  535. pSelect->idSelected = pTreeView->GetSelection();
  536. switch (pSelect->op)
  537. {
  538. case SFD_SELECTFOLDER:
  539. break;
  540. case SFD_NEWFOLDER:
  541. Assert(pSelect->pCallback != NULL);
  542. pSelect->pCallback->Reset();
  543. hwndT = GetDlgItem(hwnd, idcFolderEdit);
  544. GetWindowText(hwndT, pSelect->szName, ARRAYSIZE(pSelect->szName));
  545. hr = CreateNewFolder(hwnd, pSelect->szName, pSelect->idSelected, &id, (IStoreCallback *)pSelect->pCallback);
  546. if (hr == E_PENDING)
  547. {
  548. pSelect->fPending = TRUE;
  549. pSelect->idParent = pSelect->idSelected;
  550. return(TRUE);
  551. }
  552. else if (STORE_S_ALREADYEXISTS == hr)
  553. {
  554. AthMessageBoxW(hwnd, MAKEINTRESOURCEW(idsAthena), MAKEINTRESOURCEW(idsErrCreateExists), 0, MB_OK | MB_ICONEXCLAMATION);
  555. SendMessage(hwndT, EM_SETSEL, 0, -1);
  556. SetFocus(hwndT);
  557. return(TRUE);
  558. }
  559. else if (FAILED(hr))
  560. {
  561. AthErrorMessageW(hwnd, MAKEINTRESOURCEW(idsAthena), MAKEINTRESOURCEW(idsErrCreateNewFld), hr);
  562. SendMessage(hwndT, EM_SETSEL, 0, -1);
  563. SetFocus(hwndT);
  564. return(TRUE);
  565. }
  566. pSelect->idSelected = id;
  567. break;
  568. case SFD_MOVEFOLDER:
  569. Assert(pSelect->pCallback != NULL);
  570. pSelect->pCallback->Reset();
  571. hr = g_pStore->MoveFolder(pSelect->idCurrent, pSelect->idSelected, 0, (IStoreCallback *)pSelect->pCallback);
  572. if (hr == E_PENDING)
  573. {
  574. pSelect->fPending = TRUE;
  575. return(TRUE);
  576. }
  577. else if (FAILED(hr))
  578. {
  579. AthErrorMessageW(hwnd, MAKEINTRESOURCEW(idsAthena), MAKEINTRESOURCEW(idsErrFolderMove), hr);
  580. return(TRUE);
  581. }
  582. pSelect->idSelected = id;
  583. break;
  584. default:
  585. Assert(FALSE);
  586. break;
  587. }
  588. EndDialog(hwnd, IDOK);
  589. return(TRUE);
  590. case IDCANCEL:
  591. if (pSelect->fPending)
  592. pSelect->pCallback->Cancel();
  593. else
  594. EndDialog(hwnd, IDCANCEL);
  595. return(TRUE);
  596. default:
  597. break;
  598. }
  599. return(FALSE);
  600. }
  601. void SelectFolder_HandleStoreComplete(HWND hwnd, LPSELECTFOLDER pSelect)
  602. {
  603. HRESULT hr;
  604. FOLDERID id;
  605. HWND hwndT;
  606. Assert(pSelect->op != SFD_SELECTFOLDER);
  607. Assert(pSelect->fPending);
  608. pSelect->fPending = FALSE;
  609. hr = pSelect->pCallback->GetResult();
  610. if (hr == S_FALSE)
  611. {
  612. EndDialog(hwnd, IDCANCEL);
  613. return;
  614. }
  615. switch (pSelect->op)
  616. {
  617. case SFD_NEWFOLDER:
  618. if (SUCCEEDED(hr))
  619. {
  620. hr = GetCreatedFolderId(pSelect->idParent, pSelect->szName, &id);
  621. if (SUCCEEDED(hr))
  622. pSelect->idSelected = id;
  623. else
  624. pSelect->idSelected = pSelect->idParent;
  625. EndDialog(hwnd, IDOK);
  626. }
  627. else
  628. {
  629. // No need to put up error dialog, CStoreDlgCB already did this on failed OnComplete
  630. hwndT = GetDlgItem(hwnd, idcFolderEdit);
  631. SendMessage(hwndT, EM_SETSEL, 0, -1);
  632. SetFocus(hwndT);
  633. }
  634. break;
  635. case SFD_MOVEFOLDER:
  636. if (SUCCEEDED(hr))
  637. {
  638. pSelect->idSelected = pSelect->idCurrent;
  639. EndDialog(hwnd, IDOK);
  640. }
  641. else if (FAILED(hr))
  642. {
  643. AthErrorMessageW(hwnd, MAKEINTRESOURCEW(idsAthena), MAKEINTRESOURCEW(idsErrFolderMove), hr);
  644. }
  645. break;
  646. default:
  647. Assert(FALSE);
  648. break;
  649. }
  650. }