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.

584 lines
15 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* This file contains the dialog routines for the repagination code. */
  5. #define NOGDICAPMASKS
  6. #define NOVIRTUALKEYCODES
  7. #define NOWINSTYLES
  8. #define NOSYSMETRICS
  9. #define NOMENUS
  10. #define NOICON
  11. #define NOKEYSTATE
  12. #define NOSYSCOMMANDS
  13. #define NORASTEROPS
  14. #define NOSHOWWINDOW
  15. #define NOATOM
  16. #define NOBITMAP
  17. #define NOBRUSH
  18. #define NOCLIPBOARD
  19. #define NOCOLOR
  20. #define NOCREATESTRUCT
  21. #define NODRAWTEXT
  22. #define NOFONT
  23. #define NOGDI
  24. #define NOMB
  25. #define NOMEMMGR
  26. #define NOMENUS
  27. #define NOMETAFILE
  28. #define NOMINMAX
  29. #define NOMSG
  30. #define NOOPENFILE
  31. #define NOPEN
  32. #define NOPOINT
  33. #define NOREGION
  34. #define NOSCROLL
  35. #define NOSOUND
  36. #define NOTEXTMETRIC
  37. #define NOWH
  38. #define NOWINOFFSETS
  39. #define NOWNDCLASS
  40. #define NOCOMM
  41. #include <windows.h>
  42. #include "mw.h"
  43. #include "cmddefs.h"
  44. #include "editdefs.h"
  45. #include "printdef.h"
  46. #include "docdefs.h"
  47. #include "dlgdefs.h"
  48. #include "propdefs.h"
  49. #define NOKCCODES
  50. #include "ch.h"
  51. #include "str.h"
  52. #ifndef INEFFLOCKDOWN
  53. BOOL far PASCAL DialogRepaginate(HWND, unsigned, WORD, LONG);
  54. BOOL far PASCAL DialogSetPage(HWND, unsigned, WORD, LONG);
  55. BOOL far PASCAL DialogPageMark(HWND, unsigned, WORD, LONG);
  56. #endif
  57. fnRepaginate()
  58. {
  59. extern HWND hParentWw;
  60. extern HANDLE hMmwModInstance;
  61. extern CHAR *vpDlgBuf;
  62. #ifdef INEFFLOCKDOWN
  63. extern FARPROC lpDialogRepaginate;
  64. #else
  65. FARPROC lpDialogRepaginate = MakeProcInstance(DialogRepaginate, hMmwModInstance);
  66. #endif
  67. extern BOOL vfPrErr;
  68. extern int vfRepageConfirm;
  69. extern struct SEL selCur;
  70. extern int docCur;
  71. extern int vfSeeSel;
  72. extern int vfOutOfMemory;
  73. CHAR rgbDlgBuf[sizeof(BOOL)];
  74. struct SEL selSave;
  75. #ifndef INEFFLOCKDOWN
  76. if (!lpDialogRepaginate)
  77. {
  78. WinFailure();
  79. return;
  80. }
  81. #endif
  82. /* Create the repaginate dialog box. */
  83. vpDlgBuf = &rgbDlgBuf[0];
  84. switch (OurDialogBox(hMmwModInstance, MAKEINTRESOURCE(dlgRepaginate),
  85. hParentWw, lpDialogRepaginate))
  86. {
  87. case idiOk:
  88. /* Use the print code to repaginate a document. */
  89. DispatchPaintMsg();
  90. /* If memory failure occurred, then punt. */
  91. if (!vfOutOfMemory)
  92. {
  93. if (vfRepageConfirm)
  94. {
  95. /* Save the selection so we can restore it if an error occurs.
  96. */
  97. bltbyte(&selCur, &selSave, sizeof(struct SEL));
  98. /* Set up the undo block. */
  99. SetUndo(uacRepaginate, docCur, cp0, CpMacText(docCur), docNil,
  100. cpNil, cpNil, 0);
  101. }
  102. /* Repaginate the document. */
  103. PrintDoc(docCur, FALSE);
  104. if (vfRepageConfirm && vfPrErr)
  105. {
  106. /* An error occurred; therefore, set the world back to the way
  107. we found it. */
  108. CmdUndo();
  109. /* Reset the selection. */
  110. ClearInsertLine();
  111. Select(selSave.cpFirst, selSave.cpLim);
  112. vfSeeSel = TRUE;
  113. /* Sorry, but docUndo has been clobbered and there is no way to
  114. reset it. */
  115. NoUndo();
  116. }
  117. }
  118. break;
  119. case -1:
  120. /* We didn't even have enough memory to create the dialog box. */
  121. #ifdef WIN30
  122. WinFailure();
  123. #else
  124. Error(IDPMTNoMemory);
  125. #endif
  126. break;
  127. }
  128. #ifndef INEFFLOCKDOWN
  129. if (lpDialogRepaginate)
  130. FreeProcInstance(lpDialogRepaginate);
  131. #endif
  132. }
  133. BOOL far PASCAL DialogRepaginate(hDlg, code, wParam, lParam)
  134. HWND hDlg;
  135. unsigned code;
  136. WORD wParam;
  137. LONG lParam;
  138. {
  139. extern CHAR *vpDlgBuf;
  140. extern BOOL vfRepageConfirm;
  141. extern HWND vhWndMsgBoxParent;
  142. extern int vfCursorVisible;
  143. extern HCURSOR vhcArrow;
  144. BOOL *pfConfirm = (BOOL *)vpDlgBuf;
  145. switch (code)
  146. {
  147. case WM_INITDIALOG:
  148. EnableOtherModeless(FALSE);
  149. CheckDlgButton(hDlg, idiRepageConfirm, *pfConfirm = vfRepageConfirm);
  150. break;
  151. case WM_SETVISIBLE:
  152. if (wParam)
  153. {
  154. EndLongOp(vhcArrow);
  155. }
  156. return(FALSE);
  157. case WM_ACTIVATE:
  158. if (wParam)
  159. {
  160. vhWndMsgBoxParent = hDlg;
  161. }
  162. if (vfCursorVisible)
  163. {
  164. ShowCursor(wParam);
  165. }
  166. return(FALSE);
  167. case WM_COMMAND:
  168. switch (wParam)
  169. {
  170. case idiOk:
  171. vfRepageConfirm = IsDlgButtonChecked(hDlg, idiRepageConfirm);
  172. case idiCancel:
  173. OurEndDialog(hDlg, wParam);
  174. break;
  175. case idiRepageConfirm:
  176. CheckDlgButton(hDlg, idiRepageConfirm, *pfConfirm = !*pfConfirm);
  177. break;
  178. default:
  179. return(FALSE);
  180. break;
  181. }
  182. break;
  183. default:
  184. return(FALSE);
  185. }
  186. return(TRUE);
  187. }
  188. BOOL FSetPage()
  189. {
  190. /* This routine prompts the user for a new position for each page break.
  191. The variable ipldCur is set to point to the print line the user wants as
  192. the first line of the next page. TRUE is returned if the user hits the
  193. "Confirm" button on the dialog box; FALSE if the "Cancel" button is hit. */
  194. extern HWND hParentWw;
  195. extern HANDLE hMmwModInstance;
  196. extern CHAR *vpDlgBuf;
  197. extern int docCur;
  198. #ifdef INEFFLOCKDOWN
  199. extern FARPROC lpDialogSetPage;
  200. #else
  201. FARPROC lpDialogSetPage = MakeProcInstance(DialogSetPage, hMmwModInstance);
  202. #endif
  203. extern int vfOutOfMemory;
  204. extern int vfPrErr;
  205. struct PDB *ppdb = (struct PDB *)vpDlgBuf;
  206. typeCP cp;
  207. #ifndef INEFFLOCKDOWN
  208. if (!lpDialogSetPage)
  209. goto LSPErr;
  210. #endif
  211. /* Show the user where we think the page break should be. The AdjustCp()
  212. call is a kludge to force the redisplay of the first line of the page. */
  213. AdjustCp(docCur, cp = (**ppdb->hrgpld)[ppdb->ipldCur].cp, (typeCP)1,
  214. (typeCP)1);
  215. ClearInsertLine();
  216. Select(cp, CpLimSty(cp, styLine));
  217. PutCpInWwHz(cp);
  218. if (vfOutOfMemory)
  219. {
  220. Abort:
  221. /* If memory failure occurred, then punt. */
  222. vfPrErr = TRUE;
  223. return (FALSE);
  224. }
  225. /* Now, we can create the Set Page dialog box. */
  226. if (DialogBox(hMmwModInstance, MAKEINTRESOURCE(dlgSetPage), hParentWw,
  227. lpDialogSetPage) == -1)
  228. {
  229. /* We didn't even have enough memory to create the dialog box. */
  230. LSPErr:
  231. Error(IDPMTPRFAIL);
  232. goto Abort;
  233. }
  234. #ifndef INEFFLOCKDOWN
  235. if (lpDialogSetPage)
  236. FreeProcInstance(lpDialogSetPage);
  237. #endif
  238. /* Make sure all the windows have been refreshed. */
  239. DispatchPaintMsg();
  240. StartLongOp();
  241. if (vfOutOfMemory)
  242. {
  243. goto Abort;
  244. }
  245. /* If the user wishes to cancel the repagination, then the flag fCancel was
  246. set by the routine handling the message for the dialog box. */
  247. return (!ppdb->fCancel);
  248. }
  249. BOOL far PASCAL DialogSetPage(hWnd, message, wParam, lParam)
  250. HWND hWnd;
  251. unsigned message;
  252. WORD wParam;
  253. LONG lParam;
  254. {
  255. /* This routine processes message sent to the Set Page dialog box. The only
  256. messages that are processed are up and down buttons, and confirm and cancel
  257. commands. */
  258. extern CHAR *vpDlgBuf;
  259. extern int docCur;
  260. extern typeCP vcpFirstParaCache;
  261. extern struct PAP vpapAbs;
  262. extern HWND hParentWw;
  263. extern HWND vhWndMsgBoxParent;
  264. extern int vfCursorVisible;
  265. extern HCURSOR vhcArrow;
  266. register struct PDB *ppdb = (struct PDB *)vpDlgBuf;
  267. typeCP cp;
  268. switch (message)
  269. {
  270. case WM_COMMAND:
  271. switch (wParam)
  272. {
  273. case idiRepUp:
  274. /* Move the page mark towards the beginning of the document one
  275. line, if possible. */
  276. if (ppdb->ipldCur == 1)
  277. {
  278. beep();
  279. return (TRUE);
  280. }
  281. else
  282. {
  283. ppdb->ipldCur--;
  284. goto ShowMove;
  285. }
  286. case idiRepDown:
  287. /* Move the page mark towards the end of the document one line, if
  288. possible. */
  289. if (ppdb->ipldCur == ppdb->ipld)
  290. {
  291. beep();
  292. }
  293. else
  294. {
  295. ppdb->ipldCur++;
  296. ShowMove:
  297. /* Reflect the movement of the page on the screen. */
  298. cp = (**ppdb->hrgpld)[ppdb->ipldCur].cp;
  299. Select(cp, CpLimSty(cp, styLine));
  300. PutCpInWwHz(cp);
  301. }
  302. break;
  303. case idiCancel:
  304. CancelDlg:
  305. /* Let the repaginate routine know that the user wishes to cancel
  306. it. */
  307. ppdb->fCancel = TRUE;
  308. case idiOk:
  309. /* Take down the dialog box. */
  310. EnableWindow(hParentWw, TRUE);
  311. EndDialog(hWnd, NULL);
  312. EnableWindow(hParentWw, FALSE);
  313. vhWndMsgBoxParent = (HWND)NULL;
  314. EndLongOp(vhcArrow);
  315. /* Save the changes made by the user. */
  316. if (!ppdb->fCancel && ppdb->ipldCur != ppdb->ipld)
  317. {
  318. /* The user has moved the page break; therefore, insert a new
  319. page break. */
  320. CHAR rgch[1];
  321. rgch[0] = chSect;
  322. CachePara(docCur, cp = (**ppdb->hrgpld)[ppdb->ipldCur].cp++);
  323. InsertRgch(docCur, cp, rgch, 1, NULL, cp == vcpFirstParaCache ?
  324. &vpapAbs : NULL);
  325. /* Erase the old page mark from the screen. */
  326. AdjustCp(docCur, (**ppdb->hrgpld)[ppdb->ipld].cp, (typeCP)1,
  327. (typeCP)1);
  328. /* Ensure that the page table is correct. */
  329. (**ppdb->hpgtb).rgpgd[ppdb->ipgd].cpMin = cp + 1;
  330. }
  331. /* Change the selection to an insertion bar. */
  332. cp = (**ppdb->hrgpld)[ppdb->ipldCur].cp;
  333. Select(cp, cp);
  334. break;
  335. }
  336. case WM_SETVISIBLE:
  337. if (wParam)
  338. {
  339. EndLongOp(vhcArrow);
  340. }
  341. return(FALSE);
  342. case WM_ACTIVATE:
  343. if (wParam)
  344. {
  345. vhWndMsgBoxParent = hWnd;
  346. }
  347. if (vfCursorVisible)
  348. {
  349. ShowCursor(wParam);
  350. }
  351. return(FALSE); /* so that we leave the activate message to
  352. the dialog manager to take care of setting the focus correctly */
  353. case WM_INITDIALOG:
  354. return (TRUE);
  355. case WM_CLOSE:
  356. goto CancelDlg;
  357. }
  358. return (FALSE);
  359. }
  360. BOOL FPromptPgMark(cp)
  361. typeCP cp;
  362. {
  363. /* This routine prompts the user to either remove or keep the page mark at
  364. cp. The flag fRemove is set to TRUE if the user wishes to remove the mark;
  365. FALSE if he wishes to keep it. FALSE is returned if the user decides to
  366. cancel the repagination; TRUE if he does not. */
  367. extern HWND hParentWw;
  368. extern HANDLE hMmwModInstance;
  369. extern CHAR *vpDlgBuf;
  370. extern int docCur;
  371. #ifdef INEFFLOCKDOWN
  372. extern FARPROC lpDialogPageMark;
  373. #else
  374. FARPROC lpDialogPageMark = MakeProcInstance(DialogPageMark, hMmwModInstance);
  375. #endif
  376. extern int vfOutOfMemory;
  377. extern int vfPrErr;
  378. struct PDB *ppdb = (struct PDB *)vpDlgBuf;
  379. #ifndef INEFFLOCKDOWN
  380. if (!lpDialogPageMark)
  381. goto LPPMErr;
  382. #endif
  383. /* This is a kludge to remove a possible page indicator on the line after
  384. the page mark. */
  385. AdjustCp(docCur, cp + 1, (typeCP)1, (typeCP)1);
  386. /* Show the user the page mark in question. */
  387. ClearInsertLine();
  388. Select(cp, cp + 1);
  389. PutCpInWwHz(cp);
  390. if (vfOutOfMemory)
  391. {
  392. Abort:
  393. /* If memory failure occurred, then punt. */
  394. vfPrErr = TRUE;
  395. #ifndef INEFFLOCKDOWN
  396. if (lpDialogPageMark)
  397. FreeProcInstance(lpDialogPageMark);
  398. #endif
  399. return (FALSE);
  400. }
  401. /* Now, we can create the Page Mark dialog box. */
  402. if (DialogBox(hMmwModInstance, MAKEINTRESOURCE(dlgPageMark), hParentWw,
  403. lpDialogPageMark) == -1)
  404. {
  405. LPPMErr:
  406. /* We didn't even have enough memory to create the dialog box. */
  407. Error(IDPMTPRFAIL);
  408. goto Abort;
  409. }
  410. StartLongOp();
  411. /* Make sure all the windows have been refreshed. */
  412. DispatchPaintMsg();
  413. if (vfOutOfMemory)
  414. {
  415. goto Abort;
  416. }
  417. /* Make the change requested by the user. */
  418. if (!ppdb->fCancel)
  419. {
  420. if (ppdb->fRemove)
  421. {
  422. /* Remove the page mark as the user has requested. */
  423. Replace(docCur, cp, (typeCP)1, fnNil, fc0, fc0);
  424. }
  425. else
  426. {
  427. /* This is a kludge to force the first line after the page mark to
  428. be redisplayed. */
  429. AdjustCp(docCur, cp + 1, (typeCP)1, (typeCP)1);
  430. /* Change the selection to a insertion bar. */
  431. Select(cp, cp);
  432. }
  433. }
  434. #ifndef INEFFLOCKDOWN
  435. if (lpDialogPageMark)
  436. FreeProcInstance(lpDialogPageMark);
  437. #endif
  438. /* If the user wishes to cancel the repagination, then the flag fCancel was
  439. set by the routine handling the message for the dialog box. */
  440. return (!ppdb->fCancel);
  441. }
  442. BOOL far PASCAL DialogPageMark(hWnd, message, wParam, lParam)
  443. HWND hWnd;
  444. unsigned message;
  445. WORD wParam;
  446. LONG lParam;
  447. {
  448. /* The routine handles messages sent to the Page Mark dialog box. The only
  449. meassages of interest are when either the "Cancel", "Keep", or "Remove"
  450. buttons are hit. */
  451. extern CHAR *vpDlgBuf;
  452. extern HWND hParentWw;
  453. extern HWND vhWndMsgBoxParent;
  454. extern int vfCursorVisible;
  455. extern HCURSOR vhcArrow;
  456. struct PDB *ppdb = (struct PDB *)vpDlgBuf;
  457. switch (message)
  458. {
  459. case WM_SETVISIBLE:
  460. if (wParam)
  461. {
  462. EndLongOp(vhcArrow);
  463. }
  464. return(FALSE);
  465. case WM_ACTIVATE:
  466. if (wParam)
  467. {
  468. vhWndMsgBoxParent = hWnd;
  469. }
  470. if (vfCursorVisible)
  471. {
  472. ShowCursor(wParam);
  473. }
  474. return(FALSE);
  475. case WM_INITDIALOG:
  476. return(TRUE);
  477. case WM_COMMAND:
  478. switch (wParam)
  479. {
  480. case idiCancel:
  481. ppdb->fCancel = TRUE;
  482. break;
  483. case idiKeepPgMark:
  484. ppdb->fRemove = FALSE;
  485. break;
  486. case idiRemovePgMark:
  487. ppdb->fRemove = TRUE;
  488. break;
  489. default:
  490. return (FALSE);
  491. }
  492. break;
  493. case WM_CLOSE:
  494. ppdb->fCancel = TRUE;
  495. break;
  496. default:
  497. return (FALSE);
  498. }
  499. /* Take down the dialog box. */
  500. EnableWindow(hParentWw, TRUE);
  501. EndDialog(hWnd, NULL);
  502. EnableWindow(hParentWw, FALSE);
  503. vhWndMsgBoxParent = (HWND)NULL;
  504. EndLongOp(vhcArrow);
  505. return (TRUE);
  506. }
  507.