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.

841 lines
23 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. #define NOSCALABLEFONT
  5. #define NOSYSPARAMSINFO
  6. #define NODBCS
  7. #define NODRIVERS
  8. #define NODEFERWINDOWPOS
  9. #define NOPROFILER
  10. #define NOHELP
  11. #define NOKEYSTATES
  12. #define NOWINMESSAGES
  13. #define NOATOM
  14. #define NOCLIPBOARD
  15. #define NOCOLOR
  16. #define NOCOMM
  17. #define NODRAWTEXT
  18. #define NOGDI
  19. #define NOGDIOBJ
  20. #define NOGDICAPMASKS
  21. #define NOBITMAP
  22. #define NOKEYSTATE
  23. #define NOMENUS
  24. #define NOMETAFILE
  25. #define NOPEN
  26. #define NOOPENFILE
  27. #define NORASTEROPS
  28. #define NORECT
  29. #define NOSCROLL
  30. #define NOSHOWWINDOW
  31. #define NOSOUND
  32. #define NOSYSCOMMANDS
  33. #define NOSYSMETRICS
  34. #define NOTEXTMETRIC
  35. #define NOVIRTUALKEYCODES
  36. #define NOWH
  37. #define NOWINOFFSETS
  38. #define NOWINSTYLES
  39. #define NOUAC
  40. #define NOIDISAVEPRINT
  41. #define NOSTRUNDO
  42. #define NOCTLMGR
  43. #include <windows.h>
  44. #include "mw.h"
  45. #include "cmddefs.h"
  46. #include "docdefs.h"
  47. #include "filedefs.h"
  48. #include "code.h"
  49. #include "debug.h"
  50. #include "dlgdefs.h"
  51. #include "str.h"
  52. #include "propdefs.h"
  53. #include "wwdefs.h"
  54. extern struct WWD rgwwd[];
  55. extern int utCur;
  56. extern int vfInitializing;
  57. extern CHAR szAppName[];
  58. extern struct FCB (**hpfnfcb)[];
  59. extern struct BPS *mpibpbps;
  60. extern int ibpMax;
  61. extern typeTS tsMruBps;
  62. extern int vfSysFull;
  63. extern int ferror;
  64. extern int vfnWriting;
  65. extern int vibpWriting;
  66. extern HANDLE hMmwModInstance;
  67. extern HWND vhWndMsgBoxParent;
  68. extern int vfMemMsgReported;
  69. extern int vfDeactByOtherApp;
  70. extern MSG vmsgLast;
  71. extern HWND vhDlgFind;
  72. extern HWND vhDlgChange;
  73. extern HWND vhDlgRunningHead;
  74. extern HANDLE hParentWw;
  75. #ifdef JAPAN //01/21/93
  76. extern BOOL FontChangeDBCS;
  77. HANDLE hszNoMemorySel = NULL;
  78. #endif
  79. HANDLE hszNoMemory = NULL;
  80. HANDLE hszDirtyDoc = NULL;
  81. HANDLE hszCantPrint = NULL;
  82. HANDLE hszPRFAIL = NULL;
  83. HANDLE hszCantRunM = NULL;
  84. HANDLE hszCantRunF = NULL;
  85. HANDLE hszWinFailure = NULL;
  86. BOOL vfWinFailure = FALSE;
  87. #ifdef INEFFLOCKDOWN
  88. FARPROC lpDialogBadMargins;
  89. #endif
  90. #define FInModeless(hWnd) (hWnd == vhDlgFind || hWnd == vhDlgChange || \
  91. hWnd == vhDlgRunningHead)
  92. CHAR *PchFillPchId( CHAR *, int, int );
  93. NEAR WaitBeforePostMsg(int);
  94. #ifdef CANCELMSG /* During debug, permit an abort for stack traces */
  95. #define MB_MESSAGE (MB_OKCANCEL | MB_APPLMODAL | MB_ICONASTERISK)
  96. #define MB_ERROR (MB_OKCANCEL | MB_APPLMODAL | MB_ICONEXCLAMATION)
  97. #define MB_TROUBLE (MB_OKCANCEL | MB_APPLMODAL | MB_ICONHAND)
  98. #else
  99. #define MB_MESSAGE (MB_OK | MB_APPLMODAL | MB_ICONASTERISK)
  100. #define MB_ERROR (MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION)
  101. #define MB_TROUBLE (MB_OK | MB_APPLMODAL | MB_ICONHAND)
  102. #endif
  103. #define MB_DEFYESQUESTION (MB_YESNOCANCEL | MB_APPLMODAL | MB_ICONHAND)
  104. #define MB_DEFNOQUESTION (MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_APPLMODAL | MB_ICONHAND)
  105. ErrorLevel(IDPMT idpmt)
  106. {
  107. /* A long story. But to fix Winbug #1097, we need to take special
  108. exception for this error message -- when this is displayed in a
  109. low mem situation, this must be system modal (match params used
  110. in FRenderAll() ...pault */
  111. if (idpmt == IDPMTClipLarge)
  112. return(MB_OK | MB_SYSTEMMODAL | MB_ICONHAND);
  113. else
  114. switch (idpmt & MB_ERRMASK)
  115. {
  116. case MB_ERRASTR: /* * level */
  117. return(MB_MESSAGE);
  118. case MB_ERREXCL: /* ! level */
  119. return(MB_ERROR);
  120. case MB_ERRQUES: /* ? level */
  121. return(MB_DEFYESQUESTION);
  122. case MB_ERRHAND: /* HAND level */
  123. return(MB_TROUBLE);
  124. default:
  125. Assert(FALSE);
  126. }
  127. }
  128. int far Abort(response)
  129. int response;
  130. {
  131. for( ; ; );
  132. }
  133. #ifdef DEBUG
  134. ErrorWithMsg(IDPMT idpmt, CHAR *szMessage)
  135. {
  136. #ifdef REALDEBUG
  137. extern int vfOutOfMemory;
  138. CHAR szBuf[cchMaxSz];
  139. int errlevel = ErrorLevel(idpmt);
  140. BOOL fDisableParent = FALSE;
  141. register HWND hWndParent = (vhWndMsgBoxParent == NULL) ?
  142. hParentWw : vhWndMsgBoxParent;
  143. Assert(IsWindow(hWndParent));
  144. if (idpmt == IDPMTNoMemory)
  145. {
  146. vfOutOfMemory = TRUE;
  147. if (vfMemMsgReported)
  148. {
  149. return;
  150. }
  151. vfMemMsgReported = TRUE;
  152. }
  153. if (ferror)
  154. return;
  155. ferror = TRUE;
  156. if (vfInitializing)
  157. return;
  158. CchCopySz( szMessage, PchFillPchId( szBuf, idpmt, sizeof(szBuf) ) );
  159. if (vfDeactByOtherApp && !InSendMessage())
  160. WaitBeforePostMsg(errlevel);
  161. /* force user to answer the error msg */
  162. if (hWndParent != NULL && FInModeless(hWndParent))
  163. {
  164. EnableExcept(hWndParent, FALSE);
  165. }
  166. else
  167. {
  168. if (hWndParent != NULL && !IsWindowEnabled(hWndParent))
  169. {
  170. EnableWindow(hWndParent, TRUE);
  171. fDisableParent = TRUE;
  172. }
  173. EnableOtherModeless(FALSE);
  174. }
  175. if (MessageBox(hWndParent, (LPSTR)szBuf,
  176. (LPSTR)NULL, errlevel) == IDCANCEL)
  177. /* A debugging feature -- show stack trace if he hit "cancel" */
  178. FatalExit( 0 );
  179. if (hWndParent != NULL && FInModeless(hWndParent))
  180. {
  181. EnableExcept(hWndParent, TRUE);
  182. }
  183. else
  184. {
  185. if (fDisableParent)
  186. {
  187. EnableWindow(hWndParent, FALSE);
  188. }
  189. EnableOtherModeless(TRUE);
  190. }
  191. #else
  192. Error( idpmt );
  193. #endif
  194. }
  195. #endif /* DEBUG */
  196. void Error(IDPMT idpmt)
  197. {
  198. extern int vfOutOfMemory;
  199. CHAR szBuf [cchMaxSz];
  200. HANDLE hMsg;
  201. LPCH lpch;
  202. static int nRecurse=0;
  203. int errlevel = ErrorLevel(idpmt);
  204. register HWND hWndParent = (vhWndMsgBoxParent == NULL) ? hParentWw :
  205. vhWndMsgBoxParent;
  206. if (nRecurse)
  207. return;
  208. ++nRecurse;
  209. Assert((hWndParent == NULL) || IsWindow(hWndParent));
  210. if (idpmt == IDPMTNoMemory)
  211. {
  212. vfOutOfMemory = TRUE;
  213. if (vfMemMsgReported)
  214. {
  215. goto end;
  216. }
  217. vfMemMsgReported = TRUE;
  218. }
  219. if (!ferror && !vfInitializing)
  220. {
  221. CloseEveryRfn( FALSE );
  222. switch (idpmt)
  223. {
  224. case IDPMTNoMemory:
  225. #ifdef JAPAN //01/21/93
  226. if(FontChangeDBCS)
  227. hMsg = hszNoMemorySel;
  228. else
  229. hMsg = hszNoMemory;
  230. #else
  231. hMsg = hszNoMemory;
  232. #endif
  233. GetMsg:
  234. if (hMsg == NULL || (lpch = GlobalLock(hMsg)) == NULL)
  235. {
  236. goto end;
  237. }
  238. bltbx(lpch, (LPCH)szBuf, LOWORD(GlobalSize(hMsg)));
  239. GlobalUnlock(hMsg);
  240. break;
  241. case IDPMTCantPrint:
  242. hMsg = hszCantPrint;
  243. goto GetMsg;
  244. case IDPMTPRFAIL:
  245. hMsg = hszPRFAIL;
  246. goto GetMsg;
  247. case IDPMTCantRunM:
  248. hMsg = hszCantRunM;
  249. goto GetMsg;
  250. case IDPMTCantRunF:
  251. hMsg = hszCantRunF;
  252. goto GetMsg;
  253. case IDPMTWinFailure:
  254. hMsg = hszWinFailure;
  255. goto GetMsg;
  256. default:
  257. PchFillPchId( szBuf, idpmt, sizeof(szBuf) );
  258. break;
  259. }
  260. if (vfDeactByOtherApp && !InSendMessage())
  261. {
  262. WaitBeforePostMsg(errlevel);
  263. }
  264. #ifdef CANCELMSG
  265. if (IdPromptBoxSz( hWndParent, szBuf, errlevel ) == IDCANCEL)
  266. {
  267. /* A debugging feature -- show stack trace if he hit "cancel" */
  268. FatalExit( 100 );
  269. }
  270. #else
  271. IdPromptBoxSz( hWndParent, szBuf, errlevel );
  272. #endif
  273. }
  274. if (errlevel != MB_MESSAGE)
  275. {
  276. ferror = TRUE;
  277. }
  278. end:
  279. --nRecurse;
  280. }
  281. /* end of E r r o r */
  282. IdPromptBoxSz( hWndParent, sz, mb )
  283. HWND hWndParent;
  284. CHAR sz[];
  285. int mb;
  286. { /* Put up a message box with string sz. mb specifies buttons to display,
  287. "level" of message (HAND, EXCL, etc.).
  288. hWndParent is the parent of the message box.
  289. Returns the id of the button selected by the user */
  290. int id;
  291. BOOL fDisableParent = FALSE;
  292. extern int wwMac;
  293. int wwMacSave=wwMac;
  294. Assert((hWndParent == NULL) || IsWindow(hWndParent));
  295. if ((mb == MB_ERROR) || (mb == MB_TROUBLE))
  296. {
  297. extern int ferror;
  298. extern int vfInitializing;
  299. if (ferror)
  300. return;
  301. ferror = TRUE;
  302. if (vfInitializing)
  303. return;
  304. }
  305. CloseEveryRfn( FALSE ); /* Protect against disk swap while in message box */
  306. /* don't allow painting doc, it may be in an unpaintable state (5.8.91) v-dougk */
  307. if (mb == MB_TROUBLE)
  308. wwMac=0;
  309. /* force user to answer the msg */
  310. if (hWndParent != NULL && FInModeless(hWndParent))
  311. {
  312. EnableExcept(hWndParent, FALSE);
  313. }
  314. else
  315. {
  316. if (hWndParent != NULL && !IsWindowEnabled(hWndParent))
  317. {
  318. EnableWindow(hWndParent, TRUE);
  319. fDisableParent = TRUE;
  320. }
  321. EnableOtherModeless(FALSE);
  322. }
  323. /* We almost ALWAYS want the parent window to be passed to MessageBox
  324. except in a couple RARE cases where even Write's main text window
  325. hasn't yet gotten displayed. In that case we'll rip out of Windows
  326. if we DO tell MessageBox about it... so NULL is the prescribed hwnd
  327. to pass ..pault */
  328. id = MessageBox((hWndParent == hParentWw && !IsWindowVisible(hWndParent)) ?
  329. NULL : hWndParent, (LPSTR)sz, (LPSTR)szAppName, mb);
  330. if (hWndParent != NULL && FInModeless(hWndParent))
  331. {
  332. EnableExcept(hWndParent, TRUE);
  333. }
  334. else
  335. {
  336. if (fDisableParent)
  337. {
  338. EnableWindow(hWndParent, FALSE);
  339. }
  340. EnableOtherModeless(TRUE);
  341. }
  342. wwMac = wwMacSave;
  343. return id;
  344. }
  345. WinFailure()
  346. {
  347. /* Windows has run out of memory. All we can do is discard all of our
  348. Windows objects and pray the problem goes away. At the very worst, the
  349. might be stuck with a saved document and unable to edit. */
  350. /* FM 9/4/87 - Take out the call to FreeMemoryDC, hopefully to allow
  351. Write to continue formatting lines. */
  352. extern int vfOutOfMemory;
  353. vfOutOfMemory = TRUE;
  354. if (!vfWinFailure)
  355. {
  356. Error(IDPMTWinFailure);
  357. vfWinFailure = TRUE;
  358. }
  359. }
  360. #ifdef DEBUG
  361. DiskErrorWithMsg(idpmt, szMessage)
  362. IDPMT idpmt;
  363. CHAR *szMessage;
  364. #else
  365. DiskError(idpmt)
  366. IDPMT idpmt;
  367. #endif
  368. { /* Description: Given an error message descriptor,
  369. outputs an Alert Box. If the message indicates a serious disk
  370. error, all files are closed and a flag set so that
  371. the user will be restricted to the "Save" option only.
  372. Returns: nothing
  373. */
  374. extern HWND hParentWw;
  375. extern int vfDiskError;
  376. extern int vfInitializing;
  377. int errlevel = ErrorLevel( idpmt );
  378. CHAR rgch[cchMaxSz];
  379. CHAR *pch, *PchFillPchId();
  380. register HWND hWndParent = (vhWndMsgBoxParent == NULL) ? hParentWw : vhWndMsgBoxParent;
  381. Assert( (hWndParent == NULL) || IsWindow(hWndParent));
  382. if (idpmt == IDPMTSDE || idpmt == IDPMTSDE2)
  383. /* Serious disk error, put the guy in "SAVE-ONLY" state */
  384. if (!vfDiskError)
  385. {
  386. vfDiskError = TRUE;
  387. CloseEveryRfn( TRUE );
  388. }
  389. if (ferror || vfInitializing)
  390. /* Only report one error per operation */
  391. /* Don't report errors during inz; FInitWinInfo handles them */
  392. return;
  393. CloseEveryRfn( FALSE ); /* Close floppy files so the guy can change
  394. disks while in the message box. */
  395. pch = PchFillPchId( rgch, idpmt, sizeof(rgch) );
  396. #ifdef REALDEBUG /* Only enable extra message if really debugging */
  397. CchCopySz( szMessage, pch );
  398. #endif
  399. if (vfDeactByOtherApp && !InSendMessage())
  400. WaitBeforePostMsg(errlevel);
  401. #ifdef CANCELMSG
  402. if (IdPromptBoxSz( hWndParent, rgch, errlevel ) == IDCANCEL)
  403. /* A debugging feature -- show stack trace if he hit "cancel" */
  404. FatalExit( 0 );
  405. #else
  406. IdPromptBoxSz( hWndParent, rgch, errlevel );
  407. #endif
  408. ferror = TRUE;
  409. }
  410. /* end of D i s k E r r o r */
  411. ErrorBadMargins(hWnd, xaLeft, xaRight, yaTop, yaBottom)
  412. HWND hWnd;
  413. unsigned xaLeft;
  414. unsigned xaRight;
  415. unsigned yaTop;
  416. unsigned yaBottom;
  417. {
  418. /* Warn the user that the margins for this page must be xaLeft, xaRight,
  419. yaTop, and yaBottom. */
  420. extern CHAR *vpDlgBuf;
  421. extern HANDLE hMmwModInstance;
  422. extern int vfDeactByOtherApp;
  423. unsigned rgzaMargin[4];
  424. #ifndef INEFFLOCKDOWN
  425. extern BOOL far PASCAL DialogBadMargins(HWND, unsigned, WORD, LONG);
  426. FARPROC lpDialogBadMargins;
  427. if (!(lpDialogBadMargins = MakeProcInstance(DialogBadMargins, hMmwModInstance)))
  428. {
  429. WinFailure();
  430. return;
  431. }
  432. #endif
  433. /* These values are kept on the stact to cut down on static variables. */
  434. rgzaMargin[0] = xaLeft;
  435. rgzaMargin[1] = xaRight;
  436. rgzaMargin[2] = yaTop;
  437. rgzaMargin[3] = yaBottom;
  438. vpDlgBuf = (CHAR *)&rgzaMargin[0];
  439. if (vfDeactByOtherApp && !InSendMessage())
  440. WaitBeforePostMsg(MB_ERROR);
  441. /* Create the "error" dialog box. */
  442. DialogBox(hMmwModInstance, MAKEINTRESOURCE(dlgBadMargins), hWnd,
  443. lpDialogBadMargins);
  444. #ifndef INEFFLOCKDOWN
  445. FreeProcInstance(lpDialogBadMargins);
  446. #endif
  447. }
  448. BOOL far PASCAL DialogBadMargins(hDlg, message, wParam, lParam)
  449. HWND hDlg;
  450. unsigned message;
  451. WORD wParam;
  452. LONG lParam;
  453. {
  454. /* This routine handles the messages for the Bad Margins dialog box. */
  455. extern CHAR *vpDlgBuf;
  456. extern HWND vhWndMsgBoxParent;
  457. int idi;
  458. unsigned *prgzaMargin = (unsigned *)vpDlgBuf;
  459. switch (message)
  460. {
  461. case WM_INITDIALOG:
  462. /* Disable modeless dialog boxes. */
  463. EnableOtherModeless(FALSE);
  464. /* Set the values of the margins on the dialog box. */
  465. for (idi = idiBMrgLeft; idi <= idiBMrgBottom; idi++, prgzaMargin++)
  466. {
  467. CHAR szT[cchMaxNum];
  468. CHAR *pch = &szT[0];
  469. CchExpZa(&pch, *prgzaMargin, utCur, cchMaxNum);
  470. SetDlgItemText(hDlg, idi, (LPSTR)szT);
  471. }
  472. return (TRUE);
  473. case WM_ACTIVATE:
  474. if (wParam)
  475. {
  476. vhWndMsgBoxParent = hDlg;
  477. }
  478. return(FALSE); /* so that we leave the activate message to
  479. the dialog manager to take care of setting the focus correctly */
  480. case WM_COMMAND:
  481. if (wParam == idiOk)
  482. {
  483. /* Destroy the tabs dialog box and enable any existing modeless
  484. dialog boxes.*/
  485. OurEndDialog(hDlg, NULL);
  486. return (TRUE);
  487. }
  488. }
  489. return (FALSE);
  490. }
  491. /******************* ERROR SITUATION ROUTINES **************************/
  492. FGrowRgbp(cbp)
  493. int cbp;
  494. {
  495. #ifdef CKSM
  496. #ifdef DEBUG
  497. extern unsigned (**hpibpcksm) [];
  498. extern int ibpCksmMax;
  499. #endif
  500. #endif
  501. extern CHAR (*rgbp)[cbSector];
  502. extern CHAR *rgibpHash;
  503. extern int fIbpCheck;
  504. extern int vcCount;
  505. int ibpMaxNew = ibpMax + cbp;
  506. int iibpHashMaxNew;
  507. int cbNew;
  508. extern int ibpMaxFloat;
  509. if (ibpMaxNew > ibpMaxFloat)
  510. return(FALSE);
  511. iibpHashMaxNew = ibpMaxNew * 2 + 1;
  512. cbNew = ibpMaxNew * cbSector * sizeof(CHAR) +
  513. ((iibpHashMaxNew * sizeof(CHAR) + sizeof(int) - 1) & ~1) +
  514. ((ibpMaxNew * sizeof(struct BPS) + sizeof(int) - 1) & ~1);
  515. if (LocalReAlloc((HANDLE)rgbp, cbNew, LPTR) == (HANDLE)NULL
  516. #ifdef CKSM
  517. #ifdef DEBUG
  518. || !FChngSizeH( hpibpcksm, ibpMaxNew, FALSE )
  519. #endif
  520. #endif
  521. )
  522. {
  523. if (cbp == 1)
  524. {
  525. #ifdef CHIC
  526. CommSzNum("Can't grow any more, current ibpMax = ", ibpMax);
  527. #endif
  528. vcCount = 1024; /* so that we wait for a longer period before attemp again */
  529. }
  530. return(FALSE);
  531. }
  532. else
  533. {
  534. int cbRgbpTotalNew = ibpMaxNew * cbSector;
  535. int cbHashOrg = (iibpHashMax * sizeof(CHAR) + sizeof(int) - 1) & ~1;
  536. int cbHashTotalNew = (iibpHashMaxNew * sizeof(CHAR) + sizeof(int) - 1) & ~1;
  537. int cbBpsOrg = (ibpMax * sizeof(struct BPS) + sizeof(int) - 1) & ~1;
  538. int ibp;
  539. struct BPS *pbps;
  540. CHAR *pNew;
  541. /* blt tail end stuff first, in the following order --
  542. mpibpbps, rgibpHash */
  543. pNew = (CHAR *)rgbp + cbRgbpTotalNew + cbHashTotalNew;
  544. bltbyte((CHAR*)mpibpbps, pNew, cbBpsOrg);
  545. mpibpbps = (struct BPS *)pNew;
  546. pNew = (CHAR *)rgbp + cbRgbpTotalNew;
  547. bltbyte((CHAR *)rgibpHash, pNew, cbHashOrg);
  548. rgibpHash = pNew;
  549. for (ibp = 0, pbps = &mpibpbps[0]; ibp < ibpMaxNew; ibp++, pbps++)
  550. {
  551. if (ibp >= ibpMax)
  552. {
  553. /* initialize new bps */
  554. pbps->fn = fnNil;
  555. pbps->ts = tsMruBps - (ibpMax * 4);
  556. }
  557. pbps->ibpHashNext = ibpNil;
  558. }
  559. ibpMax = ibpMaxNew;
  560. iibpHashMax = iibpHashMaxNew;
  561. #ifdef CKSM
  562. #ifdef DEBUG
  563. ibpCksmMax = ibpMax;
  564. #endif
  565. #endif
  566. RehashRgibpHash();
  567. #ifdef CHIC
  568. CommSzNum("ibpMax = ", ibpMax);
  569. #endif
  570. return(TRUE);
  571. }
  572. }
  573. FStillOutOfMemory()
  574. {
  575. /* Return FALSE if there is enough memory available to pop us out of the "out of
  576. memory" state; TRUE otherwise */
  577. extern HANDLE vhReservedSpace;
  578. /* If we have had to give up our reserved space block, re-establish it BEFORE
  579. testing memory availability */
  580. //return vfWinFailure;
  581. if (vhReservedSpace == NULL && (vhReservedSpace = LocalAlloc(LHND, cbReserve))
  582. == NULL)
  583. {
  584. /* Nothing we can do. */
  585. return (TRUE);
  586. }
  587. /* OK, we have our reserve block, but do we have any other memory? (The use of
  588. cbReserve here is abritrary.) */
  589. if (LocalCompact(0) < cbReserve)
  590. {
  591. HANDLE hBuf = LocalAlloc(LMEM_MOVEABLE, cbReserve);
  592. if (hBuf == NULL)
  593. {
  594. return(TRUE);
  595. }
  596. else
  597. {
  598. LocalFree(hBuf);
  599. if (GlobalCompact(0) < cbReserve)
  600. {
  601. HANDLE hBuf = GlobalAlloc(GMEM_MOVEABLE, cbReserve);
  602. if (hBuf == NULL)
  603. {
  604. return(TRUE);
  605. }
  606. else
  607. {
  608. GlobalFree(hBuf);
  609. return(FALSE);
  610. }
  611. }
  612. }
  613. }
  614. return(FALSE);
  615. }
  616. IbpFindSlot(fn)
  617. int fn;
  618. { /*
  619. Description: Called from IbpEnsureValid (file.c) when a disk
  620. full error is generated while trying to write out
  621. scratch file records. A buffer slot for a piece of
  622. file fn must be found
  623. which is either non-dirty or is dirty but does
  624. not contain scratch file information. We search
  625. for the least recently used slot with the above
  626. requirements.
  627. If fn == fnScratch, we are trying to find a buffer
  628. slot for a scratch file page. We may not put it in
  629. the beginning cbpMustKeep slots.
  630. Returns: ibp (slot #).
  631. */
  632. int ibpOuterLoop;
  633. int ibpNextTry;
  634. int ibpStart;
  635. typeTS ts, tsLastTry = 0;
  636. int ibp;
  637. #ifdef DEBUG
  638. Assert(vfSysFull);
  639. #endif
  640. if (fn == fnScratch) ibpStart = cbpMustKeep;
  641. else ibpStart = 0;
  642. /* In LRU timestamp order, we are looking for any slot */
  643. /* which is non dirty or is dirty but is not part of the */
  644. /* scratch file. */
  645. for (ibpOuterLoop = ibpStart; ibpOuterLoop < ibpMax; ibpOuterLoop++)
  646. {
  647. struct BPS *pbps = &mpibpbps[ibpStart];
  648. typeTS tsNextTry = -1;/* largest possible timestamp */
  649. for(ibp = ibpStart; ibp < ibpMax; ibp++, pbps++)
  650. {
  651. ts = pbps->ts - (tsMruBps + 1);
  652. if ((ts <= tsNextTry) && (ts > tsLastTry))
  653. {
  654. tsNextTry = ts;
  655. ibpNextTry = ibp;
  656. }
  657. }
  658. if (mpibpbps[ibpNextTry].fDirty == fFalse) break;
  659. if (mpibpbps[ibpNextTry].fn != fnScratch)
  660. {
  661. FFlushFn(mpibpbps[ibpNextTry].fn);
  662. /* We need not check a return value.
  663. If the flush failed, vfDiskFull
  664. will get set */
  665. break;
  666. }
  667. else tsLastTry = tsNextTry;
  668. }
  669. if (ibpOuterLoop < ibpMax)
  670. {
  671. if (fn == vfnWriting) vibpWriting = ibpNextTry;
  672. return(ibpNextTry);
  673. }
  674. #ifdef DEBUG
  675. Assert(FALSE); /* there just had to be some slot available */
  676. /* not used by the scratch file */
  677. #endif
  678. } /* end IbpFindSlot */
  679. NEAR WaitBeforePostMsg(errlevel)
  680. int errlevel;
  681. {
  682. extern int flashID;
  683. extern HWND hwndWait;
  684. BOOL fParentEnable = IsWindowEnabled(hParentWw) || hwndWait;
  685. MessageBeep(errlevel);
  686. Diag(CommSzNum("WAITBEFOREPOSTMSG: vfDeactByOtherApp==",vfDeactByOtherApp));
  687. if (!fParentEnable)
  688. EnableWindow(hParentWw, TRUE); /* make sure parent window is enabled
  689. to let the user click in it */
  690. flashID = SetTimer(hParentWw, NULL, 500, (FARPROC)NULL);
  691. while (vfDeactByOtherApp)
  692. {
  693. if (PeekMessage((LPMSG)&vmsgLast, (HWND)NULL, NULL, NULL, PM_REMOVE))
  694. {
  695. if (vfDeactByOtherApp)
  696. {
  697. TranslateMessage( (LPMSG)&vmsgLast);
  698. DispatchMessage((LPMSG)&vmsgLast);
  699. }
  700. }
  701. }
  702. if (!fParentEnable)
  703. EnableWindow(hParentWw, FALSE); /* reset */
  704. }
  705. EnableExcept(hWnd, fEnable)
  706. HWND hWnd;
  707. BOOL fEnable;
  708. { /* Enable hParentWw and all modeless except hWnd according to fEnable */
  709. extern HWND vhDlgChange;
  710. extern HWND vhDlgFind;
  711. extern HWND vhDlgRunningHead;
  712. extern HWND hParentWw;
  713. if (hWnd != vhDlgChange && IsWindow(vhDlgChange))
  714. {
  715. EnableWindow(vhDlgChange, fEnable);
  716. }
  717. if (hWnd != vhDlgFind && IsWindow(vhDlgFind))
  718. {
  719. EnableWindow(vhDlgFind, fEnable);
  720. }
  721. if (hWnd != vhDlgRunningHead && IsWindow(vhDlgRunningHead))
  722. {
  723. EnableWindow(vhDlgRunningHead, fEnable);
  724. }
  725. EnableWindow(hParentWw, fEnable);
  726. }