Source code of Windows XP (NT5)
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.

395 lines
9.2 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* Quit.c -- MW quit commands (non-resident) */
  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 NOCTLMGR
  22. #define NODRAWTEXT
  23. #define NOFONT
  24. #define NOHDC
  25. #define NOMB
  26. #define NOMEMMGR
  27. #define NOMENUS
  28. #define NOMETAFILE
  29. #define NOMINMAX
  30. //#define NOMSG
  31. #define NOOPENFILE
  32. #define NOPEN
  33. #define NOPOINT
  34. #define NORECT
  35. #define NOREGION
  36. #define NOSCROLL
  37. #define NOSOUND
  38. #define NOWH
  39. #define NOWINOFFSETS
  40. #define NOWNDCLASS
  41. #define NOCOMM
  42. #include <windows.h>
  43. #include "mw.h"
  44. #include "str.h"
  45. #include "cmddefs.h"
  46. #define NOKCCODES
  47. #include "ch.h"
  48. #include "docdefs.h"
  49. #include "editdefs.h"
  50. #include "filedefs.h"
  51. #include "wwdefs.h"
  52. #include "propdefs.h"
  53. #include "dlgdefs.h"
  54. #include "commdlg.h"
  55. #if defined(OLE)
  56. #include "obj.h"
  57. #endif
  58. #include "debug.h"
  59. extern PRINTDLG PD; /* Common print dlg structure, initialized in the init code */
  60. extern struct FCB (**hpfnfcb)[];
  61. extern int fnMac;
  62. extern struct WWD rgwwd[];
  63. extern int wwMac;
  64. extern struct DOD (**hpdocdod)[];
  65. extern int docCur; /* Document in current ww */
  66. extern int vfExtScrap;
  67. extern int rgval[];
  68. extern int docMac;
  69. extern int vfBuffersDirty;
  70. extern int vdxaPaper;
  71. extern int vdyaPaper;
  72. extern int ferror;
  73. extern int docScrap;
  74. extern struct PAP vpapAbs;
  75. extern int vccpFetch;
  76. extern CHAR *vpchFetch;
  77. extern int vfScrapIsPic;
  78. extern typeCP vcpLimParaCache;
  79. FMmwClose( hwnd )
  80. HWND hwnd;
  81. { /* Handle WM_CLOSE message sent to parent window. Return FALSE if
  82. the CLOSE should be aborted, TRUE if it is OK to go ahead
  83. and CLOSE (DestroyWindow is called in this case). */
  84. extern int vfDead;
  85. extern VOID (FAR PASCAL *lpfnRegisterPenApp)(WORD, BOOL);
  86. extern WORD fPrintOnly;
  87. if (fPrintOnly || FConfirmSave())
  88. {
  89. extern int vfOwnClipboard;
  90. FreeMemoryDC( FALSE ); /* To give FRenderAll max memory */
  91. /* Render Data BEFORE the world collapses around our ears */
  92. if (vfOwnClipboard)
  93. { /* We are the clipboard owner -- render the clipboard contents in
  94. all datatypes that we know about */
  95. if (!FRenderAll())
  96. /* Render failed; abort close */
  97. return FALSE;
  98. }
  99. #if defined(OLE)
  100. if (ObjClosingDoc(docCur,NULL)) // do this *after* call to RenderAll!
  101. return FALSE;
  102. #endif
  103. /* pen windows */
  104. if (lpfnRegisterPenApp) // global
  105. (*lpfnRegisterPenApp)((WORD)1, fFalse); // deregister
  106. if (PD.hDevMode)
  107. {
  108. /* We'd opened a Win3 printer driver before, now discard */
  109. GlobalFree(PD.hDevMode);
  110. PD.hDevMode = NULL;
  111. }
  112. vfDead = TRUE; /* So we don't repaint or idle anymore */
  113. DestroyWindow( hwnd );
  114. KillTempFiles( FALSE );
  115. return TRUE; /* OK to close window */
  116. }
  117. return FALSE; /* ABort the close */
  118. }
  119. MmwDestroy()
  120. { /* Parent window is being destroyed */
  121. extern HWND hParentWw;
  122. extern HWND vhWndPageInfo;
  123. extern HDC vhDCRuler;
  124. extern HBRUSH hbrBkgrnd;
  125. extern HFONT vhfPageInfo;
  126. extern HBITMAP hbmBtn;
  127. extern HBITMAP hbmMark;
  128. #ifdef JAPAN //01/21/93
  129. extern HANDLE hszNoMemorySel;
  130. #endif
  131. extern HANDLE hszNoMemory;
  132. extern HANDLE hszDirtyDoc;
  133. extern HANDLE hszCantPrint;
  134. extern HANDLE hszPRFAIL;
  135. HBRUSH hbr = GetStockObject( WHITE_BRUSH );
  136. HDC hDC = GetDC( vhWndPageInfo );
  137. #ifdef WIN30
  138. {
  139. /* We use the help engine so advise it we're going far far away */
  140. CHAR sz[cchMaxFile];
  141. PchFillPchId(sz, IDSTRHELPF, sizeof(sz));
  142. WinHelp(hParentWw, (LPSTR)sz, HELP_QUIT, NULL);
  143. }
  144. #endif
  145. FreeMemoryDC( TRUE );
  146. SelectObject( GetDC( hParentWw ), hbr );
  147. SelectObject( wwdCurrentDoc.hDC, hbr );
  148. if (vhDCRuler != NULL)
  149. {
  150. SelectObject( vhDCRuler, hbr );
  151. }
  152. DeleteObject( hbrBkgrnd );
  153. DeleteObject( SelectObject( hDC, hbr ) );
  154. if (vhfPageInfo != NULL)
  155. {
  156. DeleteObject( SelectObject( hDC, GetStockObject( SYSTEM_FONT ) ) );
  157. }
  158. if (hbmBtn != NULL)
  159. {
  160. DeleteObject( hbmBtn );
  161. }
  162. if (hbmMark != NULL)
  163. {
  164. DeleteObject( hbmMark );
  165. }
  166. #ifdef JAPAN //01/21/93
  167. if (hszNoMemorySel != NULL)
  168. {
  169. GlobalFree( hszNoMemorySel );
  170. }
  171. #endif
  172. if (hszNoMemory != NULL)
  173. {
  174. GlobalFree( hszNoMemory );
  175. }
  176. if (hszDirtyDoc != NULL)
  177. {
  178. GlobalFree( hszDirtyDoc );
  179. }
  180. if (hszCantPrint != NULL)
  181. {
  182. GlobalFree( hszCantPrint );
  183. }
  184. if (hszPRFAIL != NULL)
  185. {
  186. GlobalFree( hszPRFAIL );
  187. }
  188. #if defined(JAPAN) & defined(DBCS_IME)
  189. /* Release Ime communication memory */
  190. {
  191. extern HANDLE hImeMem;
  192. extern HANDLE hImeSetFont;
  193. if (hImeMem)
  194. GlobalFree(hImeMem);
  195. if(hImeSetFont != NULL) {
  196. HDC hdc;
  197. HANDLE oldhfont;
  198. hdc = GetDC(NULL);
  199. oldhfont = SelectObject(hdc,hImeSetFont);
  200. SelectObject(hdc,oldhfont);
  201. DeleteObject(hImeSetFont);
  202. ReleaseDC(NULL, hdc);
  203. }
  204. }
  205. #endif
  206. #if defined(JAPAN) & defined(IME_HIDDEN) //IME3.1J
  207. //IR_UNDETERMINE
  208. /* Release Ime Undetermin string & attrib memory */
  209. {
  210. extern HANDLE hImeUnAttrib;
  211. extern HANDLE hImeUnString;
  212. extern CHAR szWriteProduct[];
  213. extern CHAR szImeHidden[];
  214. extern int vfImeHidden; /*T-HIROYN ImeHidden Mode flag*/
  215. if (hImeUnAttrib)
  216. GlobalFree(hImeUnAttrib);
  217. if (hImeUnString)
  218. GlobalFree(hImeUnString);
  219. WriteProfileString((LPSTR)szWriteProduct, (LPSTR)szImeHidden,
  220. vfImeHidden ? (LPSTR)"1" : (LPSTR)"0" );
  221. }
  222. #endif
  223. #ifdef FONT_KLUDGE
  224. RemoveFontResource( (LPSTR)"helv.fon" );
  225. #endif /* FONT_KLUDGE */
  226. #if defined(OLE)
  227. ObjShutDown();
  228. #endif
  229. PostQuitMessage( 0 );
  230. }
  231. KillTempFiles( fEndSession )
  232. int fEndSession;
  233. { /* Kill off all of the temp files. MEMO cannot run after this is done */
  234. int f;
  235. int fn, fnT;
  236. CloseEveryRfn( TRUE );
  237. /* Delete all temp files */
  238. /* loop thru the FCB table looking for files that should be deleted before
  239. we quit. */
  240. for (fn = 0; fn < fnMac; fn++)
  241. {
  242. int fpe;
  243. struct FCB *pfcb = &(**hpfnfcb)[fn];
  244. if (pfcb->rfn != rfnFree && pfcb->fDelete)
  245. /* Having found a file that must be deleted, delete it */
  246. {
  247. /* This should be FDeleteFile all of the time, but we don't
  248. want to add a window enumeration during End Session
  249. at this very late stage of the project */
  250. if (fEndSession)
  251. FpeDeleteSzFfname( **pfcb->hszFile );
  252. else
  253. FDeleteFile( **pfcb->hszFile );
  254. (**hpfnfcb) [fn].rfn = rfnFree;
  255. }
  256. }
  257. }
  258. #ifdef ENABLE /* Part of "Save All", not needed */
  259. int CnfrmSz(sz)
  260. CHAR *sz;
  261. {
  262. extern AlertBoxSz2();
  263. int cch;
  264. cch = CchFillSzId(&stBuf[1], IDPMTSaveChanges);
  265. stBuf[++cch] = chSpace;
  266. cch += CchCopySz(sz, &stBuf[cch+1]);
  267. stBuf[++cch] = chQMark;
  268. stBuf[0] = cch;
  269. return(AlertBoxSz2(stBuf));
  270. }
  271. #endif /* ENABLE */
  272. #ifdef ENABLE /* Not needed, only 1 document in MEMO */
  273. int
  274. FAllDocsClean()
  275. {
  276. int fAllClean = true;
  277. int dty;
  278. int doc;
  279. if (vfBuffersDirty)
  280. return false;
  281. for (doc = 0; doc < docMac; ++doc)
  282. {
  283. dty = (**hpdocdod)[doc].dty;
  284. if ((dty != dtyNormal && dty != dtySsht) ||
  285. (**hpdocdod)[doc].hpctb == 0 || !(**hpdocdod)[doc].fDirty)
  286. continue;
  287. fAllClean = false;
  288. }
  289. return fAllClean;
  290. }
  291. #endif
  292. #ifdef ENABLE /* We don't support saving between-session state info */
  293. WriteStateInfo()
  294. { /* Write out state information into Word resource file */
  295. struct STATEINFO stiTemp;
  296. HANDLE hRes, hData;
  297. UseResFile(vresSystem);
  298. SetWords(&stiTemp,0,cwSTATEINFO);
  299. stiTemp.sf.fScrnDraftStor = vfScrnDraft;
  300. stiTemp.sf.fPrintModeStor = vfPrintMode;
  301. stiTemp.sf.fDriverDefaultOK = vfDriverDefaultOK;
  302. stiTemp.utCurStor = utCur;
  303. stiTemp.vcDaisyPitchStor = vcDaisyPitch;
  304. stiTemp.vBaudRateStor =vBaudRate;
  305. stiTemp.vPortNumStor = vPortNum;
  306. if (hszPrdFile != 0)
  307. {/* User has a Word printer driver selected currently */
  308. int cch = CchCopySz(**hszPrdFile,stiTemp.rgchPrd);
  309. stiTemp.vdxaPaperStor = vdxaPaper;
  310. stiTemp.vdyaPaperStor = vdyaPaper;
  311. stiTemp.sf.fPrintStateOK = true;
  312. }
  313. else
  314. stiTemp.sf.fPrintStateOK = false;
  315. hRes = GetResource(WINF, 1);
  316. if (hRes != 0L)
  317. RmveResource(hRes);
  318. hData = NewHandle(0);
  319. if (HandleAppendQ(hData,&stiTemp,sizeof(stiTemp)))
  320. AddResource(hData, WINF, 1, "");
  321. }
  322. #endif /* ENABLE */
  323. fnQuit(hWnd)
  324. /* user has selected Quit menu item... */
  325. HWND hWnd;
  326. {
  327. SendMessage(hWnd, WM_CLOSE, 0, 0L);
  328. }
  329.