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.

483 lines
13 KiB

  1. /*****************************************************************************
  2. D I A L O G S
  3. Name: dialogs.c
  4. Date: 21-Jan-1994
  5. Creator: Unknown
  6. Description:
  7. Dialog handling routines.
  8. *****************************************************************************/
  9. #include <windows.h>
  10. #include <nddeapi.h>
  11. #include <strsafe.h>
  12. #include "common.h"
  13. #include "clipbook.h"
  14. #include "clipbrd.h"
  15. #include "clpbkdlg.h"
  16. #include "cvutil.h"
  17. #include "dialogs.h"
  18. #include "helpids.h"
  19. #include "debugout.h"
  20. #include "ismember.h"
  21. #include "shares.h"
  22. /*
  23. * ConnectDlgProc
  24. */
  25. INT_PTR CALLBACK ConnectDlgProc (
  26. HWND hwnd,
  27. UINT message,
  28. WPARAM wParam,
  29. LPARAM lParam)
  30. {
  31. switch (message)
  32. {
  33. case WM_INITDIALOG:
  34. szConvPartner[0] = '\0';
  35. break;
  36. case WM_COMMAND:
  37. switch (wParam)
  38. {
  39. case IDOK:
  40. GetDlgItemText (hwnd, IDC_CONNECTNAME, szConvPartner, 32);
  41. EndDialog (hwnd, 1);
  42. break;
  43. case IDCANCEL:
  44. szConvPartner[0] = '\0';
  45. EndDialog (hwnd, 0);
  46. break;
  47. default:
  48. return FALSE;
  49. }
  50. break;
  51. default:
  52. return FALSE;
  53. }
  54. return TRUE;
  55. }
  56. /*
  57. * ShareDlgProc
  58. *
  59. * Note: this routine expectes a PNDDESHAREINFO in lParam!
  60. */
  61. INT_PTR CALLBACK ShareDlgProc(
  62. HWND hwnd,
  63. UINT message,
  64. WPARAM wParam,
  65. LPARAM lParam)
  66. {
  67. static PNDDESHAREINFO lpDdeS;
  68. DWORD dwTrustOptions;
  69. DWORD adwTrust[3];
  70. BOOL bRet = TRUE;
  71. // These vars are used for determining if I'm owner of the page
  72. PSID psidPage;
  73. BOOL fDump;
  74. DWORD cbSD;
  75. UINT uRet;
  76. PSECURITY_DESCRIPTOR pSD = NULL;
  77. LPHELPINFO lphi;
  78. const DWORD aHelpIDs[] =
  79. {
  80. IDC_STARTAPP, IDH_STARTAPP,
  81. IDC_MINIMIZED, IDH_MINIMIZED,
  82. IDC_PERMISSIONS, IDH_PERMISSIONS,
  83. 0, 0
  84. };
  85. UINT iCtrlId;
  86. switch (message)
  87. {
  88. case WM_INITDIALOG:
  89. lpDdeS = (PNDDESHAREINFO)lParam;
  90. // set share, always static
  91. SetDlgItemText (hwnd, IDC_STATICSHARENAME, lpDdeS->lpszShareName+1 );
  92. // If the current user doesn't own the page, we gray out the
  93. // "start app" and "run minimized" checkboxes
  94. EnableWindow(GetDlgItem(hwnd, IDC_STARTAPP), FALSE);
  95. EnableWindow(GetDlgItem(hwnd, IDC_MINIMIZED), FALSE);
  96. EnableWindow(GetDlgItem(hwnd, 207), FALSE);
  97. // Figure out who owns the page
  98. psidPage = NULL;
  99. if (!(pSD = LocalAlloc(LPTR, 50)))
  100. {
  101. PERROR(TEXT("Couldn't alloc 50 bytes\r\n"));
  102. break;
  103. }
  104. uRet = NDdeGetShareSecurity (NULL,
  105. lpDdeS->lpszShareName,
  106. OWNER_SECURITY_INFORMATION,
  107. pSD,
  108. 50,
  109. &cbSD);
  110. if (uRet == NDDE_BUF_TOO_SMALL)
  111. {
  112. LocalFree (pSD);
  113. if (!(pSD = LocalAlloc(LPTR, cbSD)))
  114. {
  115. PERROR(TEXT("Couldn't alloc %ld bytes\r\n"), cbSD);
  116. break;
  117. }
  118. uRet = NDdeGetShareSecurity (NULL,
  119. lpDdeS->lpszShareName,
  120. OWNER_SECURITY_INFORMATION,
  121. pSD,
  122. cbSD,
  123. &cbSD);
  124. }
  125. if (NDDE_NO_ERROR != uRet)
  126. {
  127. PERROR(TEXT("GetSec fail %d"), uRet);
  128. break;
  129. }
  130. if (!GetSecurityDescriptorOwner(pSD, &psidPage, &fDump))
  131. {
  132. PERROR(TEXT("Couldn't get owner, even tho we asked\r\n"));
  133. break;
  134. }
  135. if (!psidPage || !IsUserMember(psidPage))
  136. {
  137. PINFO(TEXT("User isn't member of owner\r\n"));
  138. break;
  139. }
  140. EnableWindow (GetDlgItem (hwnd, IDC_STARTAPP), TRUE);
  141. // 207 is the group box around the checkboxes
  142. EnableWindow (GetDlgItem (hwnd, 207), TRUE);
  143. NDdeGetTrustedShare (NULL,
  144. lpDdeS->lpszShareName,
  145. adwTrust,
  146. adwTrust + 1,
  147. adwTrust + 2);
  148. if (!(adwTrust[0] & NDDE_TRUST_SHARE_START))
  149. {
  150. PINFO (TEXT("Buttons shouldn't check\r\n"));
  151. }
  152. else
  153. {
  154. CheckDlgButton(hwnd, IDC_STARTAPP, 1);
  155. EnableWindow (GetDlgItem (hwnd, IDC_MINIMIZED), TRUE);
  156. CheckDlgButton (hwnd,
  157. IDC_MINIMIZED,
  158. (SW_MINIMIZE == (adwTrust[0] & NDDE_CMD_SHOW_MASK)) ? 1 : 0);
  159. }
  160. break;
  161. case WM_COMMAND:
  162. switch (LOWORD(wParam))
  163. {
  164. case IDOK:
  165. dwTrustOptions = NDDE_TRUST_SHARE_INIT;
  166. if (IsDlgButtonChecked(hwnd, IDC_STARTAPP))
  167. {
  168. dwTrustOptions |= NDDE_TRUST_SHARE_START;
  169. if (IsDlgButtonChecked(hwnd, IDC_MINIMIZED))
  170. {
  171. dwTrustOptions |= NDDE_TRUST_CMD_SHOW | SW_MINIMIZE;
  172. }
  173. }
  174. // Update the share start flag.
  175. if (dwTrustOptions & NDDE_TRUST_SHARE_START)
  176. lpDdeS->fStartAppFlag = TRUE;
  177. else
  178. lpDdeS->fStartAppFlag = FALSE;
  179. NDdeSetTrustedShare(NULL, lpDdeS->lpszShareName, dwTrustOptions);
  180. EndDialog (hwnd, TRUE);
  181. break;
  182. case IDCANCEL:
  183. EndDialog (hwnd, FALSE);
  184. break;
  185. case IDC_PERMISSIONS:
  186. EditPermissions2 (hwnd, lpDdeS->lpszShareName, FALSE);
  187. break;
  188. case IDC_STARTAPP:
  189. EnableWindow(GetDlgItem(hwnd, IDC_MINIMIZED),
  190. IsDlgButtonChecked(hwnd, IDC_STARTAPP));
  191. break;
  192. default:
  193. bRet = FALSE;
  194. }
  195. break;
  196. case WM_HELP:
  197. lphi = (LPHELPINFO) lParam;
  198. if (lphi->iContextType == HELPINFO_WINDOW)
  199. {
  200. if ((lphi->iCtrlId == IDC_STARTAPP) ||
  201. (lphi->iCtrlId == IDC_MINIMIZED) ||
  202. (lphi->iCtrlId == IDC_PERMISSIONS) ||
  203. (lphi->iCtrlId == IDOK) ||
  204. (lphi->iCtrlId == IDCANCEL) )
  205. {
  206. WinHelp ( lphi->hItemHandle,
  207. szHelpFile,
  208. HELP_WM_HELP,
  209. (DWORD_PTR) (LPVOID) aHelpIDs);
  210. }
  211. }
  212. else
  213. {
  214. bRet = FALSE;
  215. }
  216. break;
  217. case WM_CONTEXTMENU:
  218. iCtrlId = GetDlgCtrlID( (HWND) wParam );
  219. if ((iCtrlId == IDC_STATICSHARENAME) ||
  220. (iCtrlId == IDC_STARTAPP) ||
  221. (iCtrlId == IDC_MINIMIZED) ||
  222. (iCtrlId == IDC_PERMISSIONS) ||
  223. (iCtrlId == IDOK) ||
  224. (iCtrlId == IDCANCEL) )
  225. {
  226. WinHelp( (HWND) wParam,
  227. szHelpFile,
  228. HELP_CONTEXTMENU,
  229. (DWORD_PTR) (LPVOID) aHelpIDs);
  230. }
  231. break;
  232. //
  233. default:
  234. bRet = FALSE;
  235. }
  236. if (pSD)
  237. LocalFree (pSD);
  238. return bRet;
  239. }
  240. /*
  241. * IsUniqueName
  242. *
  243. * Check to see if the name is unique
  244. */
  245. static BOOL IsUniqueName (PKEEPASDLG_PARAM pParam)
  246. {
  247. PMDIINFO pMDI;
  248. LISTENTRY ListEntry;
  249. PLISTENTRY pLE;
  250. INT i;
  251. if (!(pMDI = GETMDIINFO(hwndLocal)))
  252. return FALSE;
  253. StringCchCopy (ListEntry.name, MAX_PAGENAME_LENGTH + 1, pParam->ShareName);
  254. i = (INT)SendMessage (pMDI->hWndListbox,
  255. LB_FINDSTRING,
  256. (WPARAM)-1,
  257. (LPARAM)(LPCSTR) &ListEntry);
  258. if (LB_ERR != i)
  259. {
  260. SendMessage (pMDI->hWndListbox,
  261. LB_GETTEXT,
  262. i,
  263. (LPARAM)&pLE);
  264. pParam->bAlreadyShared = IsShared (pLE);
  265. return FALSE;
  266. }
  267. return TRUE;
  268. }
  269. /*
  270. * KeepAsDlgProc
  271. *
  272. * Ask the user for a page name.
  273. */
  274. INT_PTR CALLBACK KeepAsDlgProc(
  275. HWND hwnd,
  276. UINT msg,
  277. WPARAM wParam,
  278. LPARAM lParam)
  279. {
  280. static PKEEPASDLG_PARAM pParam;
  281. LPHELPINFO lphi;
  282. const DWORD aHelpIDs[] =
  283. {
  284. IDC_STATICPAGENAME, IDH_KEEPASEDIT,
  285. IDC_KEEPASEDIT, IDH_KEEPASEDIT,
  286. IDC_SHARECHECKBOX, IDH_SHARECHECKBOX,
  287. 0, 0
  288. };
  289. switch (msg)
  290. {
  291. case WM_INITDIALOG:
  292. pParam = (PKEEPASDLG_PARAM)lParam;
  293. pParam->bAlreadyExist = FALSE;
  294. pParam->bAlreadyShared = FALSE;
  295. pParam->ShareName[0] = '\0';
  296. SendDlgItemMessage (hwnd, IDC_KEEPASEDIT, EM_LIMITTEXT, MAX_NDDESHARENAME - 15, 0L);
  297. SendDlgItemMessage (hwnd, IDC_SHARECHECKBOX, BM_SETCHECK, fSharePreference, 0L);
  298. break;
  299. case WM_COMMAND:
  300. switch (wParam)
  301. {
  302. case IDOK:
  303. fSharePreference = (BOOL)SendDlgItemMessage (hwnd,
  304. IDC_SHARECHECKBOX,
  305. BM_GETCHECK,
  306. 0,
  307. 0L );
  308. if (!GetDlgItemText(hwnd, IDC_KEEPASEDIT, pParam->ShareName+1, MAX_PAGENAME_LENGTH))
  309. {
  310. SetFocus (GetDlgItem (hwnd, IDC_KEEPASEDIT));
  311. break;
  312. }
  313. pParam->ShareName[0] = SHR_CHAR;
  314. if (!NDdeIsValidShareName(pParam->ShareName + 1))
  315. {
  316. MessageBoxID (hInst,
  317. hwnd,
  318. IDS_PAGENAMESYNTAX,
  319. IDS_PASTEDLGTITLE,
  320. MB_OK|MB_ICONEXCLAMATION);
  321. break;
  322. }
  323. pParam->ShareName[0] = UNSHR_CHAR;
  324. // make sure name is unique
  325. if ( !IsUniqueName (pParam))
  326. {
  327. if (IDOK != MessageBoxID (hInst,
  328. hwnd,
  329. IDS_NAMEEXISTS,
  330. IDS_PASTEDLGTITLE,
  331. MB_OKCANCEL|MB_ICONEXCLAMATION))
  332. break;
  333. pParam->bAlreadyExist = TRUE;
  334. }
  335. EndDialog( hwnd, TRUE );
  336. break;
  337. case IDCANCEL:
  338. EndDialog( hwnd, FALSE );
  339. break;
  340. default:
  341. return FALSE;
  342. }
  343. break;
  344. case WM_HELP:
  345. lphi = (LPHELPINFO) lParam;
  346. if (lphi->iContextType == HELPINFO_WINDOW)
  347. {
  348. WinHelp ( lphi->hItemHandle,
  349. szHelpFile,
  350. HELP_WM_HELP,
  351. (DWORD_PTR) (LPVOID) aHelpIDs);
  352. }
  353. else
  354. {
  355. return FALSE;
  356. }
  357. break;
  358. case WM_CONTEXTMENU:
  359. WinHelp( (HWND) wParam,
  360. szHelpFile,
  361. HELP_CONTEXTMENU,
  362. (DWORD_PTR) (LPVOID) aHelpIDs);
  363. break;
  364. default:
  365. return FALSE;
  366. }
  367. return TRUE;
  368. }