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.

336 lines
9.0 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. #define NOGDICAPMASKS
  5. #define NOCLIPBOARD
  6. #define NOMENUS
  7. #define NOSOUND
  8. #define NOCOMM
  9. #define NOOPENFILE
  10. #define NORESOURCE
  11. #define NODRAWTEXT
  12. #define NOSOUND
  13. #define NOCOMM
  14. #include <windows.h>
  15. #include "mw.h"
  16. #include "winddefs.h"
  17. #include "cmddefs.h"
  18. #include "wwdefs.h"
  19. #include "dispdefs.h"
  20. #include "docdefs.h"
  21. #include "debug.h"
  22. extern HWND vhWnd;
  23. extern HWND vhWndSizeBox;
  24. extern HWND vhWndRuler;
  25. extern HWND vhWndPageInfo;
  26. extern HWND vhWndCancelPrint;
  27. extern HDC vhDCPrinter;
  28. extern HFONT vhfPageInfo;
  29. extern HCURSOR vhcArrow;
  30. extern HCURSOR vhcIBeam;
  31. extern HCURSOR vhcBarCur;
  32. extern struct WWD rgwwd[];
  33. extern struct WWD *pwwdCur;
  34. extern HANDLE hMmwModInstance; /* handle to own module instance */
  35. extern int vfShiftKey;
  36. extern int vfCommandKey;
  37. extern int vfOptionKey;
  38. extern int vfDoubleClick;
  39. extern struct SEL selCur;
  40. extern long rgbBkgrnd;
  41. extern long rgbText;
  42. extern HBRUSH hbrBkgrnd;
  43. extern long ropErase;
  44. extern int vfIconic;
  45. extern int vfLargeSys;
  46. extern int dxpRuler;
  47. extern HMENU vhMenu;
  48. #ifdef JAPAN // Indicate whether to show IME convert window
  49. extern BOOL ConvertEnable;
  50. #endif
  51. void MmwSize(hWnd, cxpNew, cypNew, code)
  52. HWND hWnd;
  53. int cxpNew;
  54. int cypNew;
  55. WORD code;
  56. {
  57. if (code == SIZEICONIC)
  58. {
  59. #ifdef NOT_RECOMMENDED
  60. /* This should already be done by Windows itself!
  61. Moving here could cause confusion */
  62. /* Resize the document window. */
  63. if (wwdCurrentDoc.wwptr != NULL)
  64. MoveWindow(wwdCurrentDoc.wwptr, 0, 0, 0, 0, FALSE);
  65. #endif
  66. /* Deselect our fonts so that they can move if necessary. */
  67. ResetFont(FALSE);
  68. if (vhWndCancelPrint == NULL)
  69. {
  70. /* Reset the printer font iff we are not printing or repaginating.
  71. */
  72. ResetFont(TRUE);
  73. }
  74. if (!vfLargeSys && vhfPageInfo != NULL)
  75. {
  76. DeleteObject(SelectObject(GetDC(vhWndPageInfo),
  77. GetStockObject(SYSTEM_FONT)));
  78. vhfPageInfo = NULL;
  79. }
  80. vfIconic = TRUE;
  81. }
  82. else
  83. {
  84. int dxpBorder = GetSystemMetrics(SM_CXBORDER);
  85. int dypBorder = GetSystemMetrics(SM_CYBORDER);
  86. int xpMac = cxpNew - dxpScrlBar + dxpBorder;
  87. int ypMac = cypNew - dypScrlBar + dypBorder;
  88. int dypOverlap = 0;
  89. /* If we are coming back from being iconic, then reestablish the printer
  90. DC. */
  91. if (vfIconic && vhDCPrinter == NULL)
  92. {
  93. GetPrinterDC(FALSE);
  94. }
  95. /* Reposition all of the windows. */
  96. MoveWindow(wwdCurrentDoc.hVScrBar, xpMac, -dypBorder, dxpScrlBar, ypMac
  97. + (dypBorder << 1), TRUE);
  98. MoveWindow(wwdCurrentDoc.hHScrBar, dxpInfoSize, ypMac, cxpNew -
  99. dxpInfoSize - dxpScrlBar + (dxpBorder << 1), dypScrlBar, TRUE);
  100. #ifndef NOMORESIZEBOX
  101. MoveWindow(vhWndSizeBox, xpMac, ypMac, dxpScrlBar, dypScrlBar, TRUE);
  102. #endif
  103. MoveWindow(vhWndPageInfo, 0, ypMac, dxpInfoSize, dypScrlBar, TRUE);
  104. if (vhWndRuler != NULL)
  105. {
  106. dypOverlap = dypRuler - (wwdCurrentDoc.ypMin - 1);
  107. MoveWindow(vhWndRuler, 0, 0, xpMac, dypRuler, TRUE);
  108. }
  109. /* Resize the document window. */
  110. if (wwdCurrentDoc.wwptr != NULL)
  111. {
  112. MoveWindow(wwdCurrentDoc.wwptr, 0, dypOverlap, xpMac, ypMac -
  113. dypOverlap, FALSE);
  114. /* Validate the area of the document window that is overlapped by
  115. the ruler if necessary. */
  116. if (vhWndRuler != (HWND)NULL)
  117. {
  118. RECT rc;
  119. rc.left = rc.top = 0;
  120. rc.right = dxpRuler;
  121. rc.bottom = wwdCurrentDoc.ypMin;
  122. ValidateRect(wwdCurrentDoc.wwptr, (LPRECT)&rc);
  123. }
  124. }
  125. vhMenu = GetMenu(hWnd); // kludge patch cause Write does its own
  126. // accelerator handling (6.24.91) v-dougk
  127. vfIconic = FALSE;
  128. }
  129. }
  130. void MdocSize(hWnd, cxpNew, cypNew, code)
  131. HWND hWnd;
  132. int cxpNew;
  133. int cypNew;
  134. WORD code;
  135. {
  136. extern int wwCur;
  137. extern int vfSeeSel;
  138. extern int vfInitializing;
  139. typeCP cp;
  140. struct EDL *pedl;
  141. /* Let's start thing off with a couple of assumptions. */
  142. Assert( code == SIZENORMAL || code == SIZEFULLSCREEN );
  143. Assert( wwdCurrentDoc.wwptr == hWnd );
  144. #ifdef ENABLE /* We repaint completely on resize */
  145. if (cypNew > wwdCurrentDoc.ypMac)
  146. /* We are growing vertically, mark exposed area invalid
  147. so UpdateWw does not try to recycle a partial line
  148. at the bottom of the window. */
  149. InvalBand( &wwdCurrentDoc, wwdCurrentDoc.ypMac, cypNew );
  150. #endif
  151. if (wwCur != wwNil)
  152. TrashWw( wwCur );
  153. /* Mark the window dirty so that dlMac gets reset according to the new
  154. window size */
  155. wwdCurrentDoc.fDirty = TRUE;
  156. wwdCurrentDoc.xpMac = cxpNew;
  157. wwdCurrentDoc.ypMac = cypNew;
  158. /* If minimizing the window, we are done */
  159. if ((cxpNew == 0) && (cypNew == 0))
  160. return;
  161. /* If the selection was visible before, so shall it be hereafter */
  162. if ( ((cp = CpEdge()) >= wwdCurrentDoc.cpFirst) &&
  163. (wwdCurrentDoc.dlMac > 0) &&
  164. (cp < (pedl =
  165. &(**wwdCurrentDoc.hdndl)[wwdCurrentDoc.dlMac - 1])->cpMin +
  166. pedl->dcpMac))
  167. {
  168. /* Normally, we would just set vfSeeSel and wait for Idle to
  169. put the selection in view. However, we can be resized even
  170. when we are not the current app, and in that case Idle will not
  171. get called soon enough. So, we scroll the selection into view here */
  172. if (!vfInitializing)
  173. { /* Avoid the peril of trying to do this operation too early */
  174. extern int wwCur;
  175. UpdateWw( wwCur, FALSE ); /* To lock in the new dlMac */
  176. PutCpInWwVert( cp );
  177. UpdateWw( wwCur, FALSE );
  178. }
  179. }
  180. }
  181. FreeMemoryDC( fPrinterToo )
  182. BOOL fPrinterToo;
  183. {
  184. extern HDC vhMDC;
  185. extern int dxpbmMDC;
  186. extern int dypbmMDC;
  187. extern HBITMAP hbmNull;
  188. /* Delete the memory DC if necessary. */
  189. if ( vhMDC != NULL )
  190. {
  191. /* Delete the old bitmap if necessary. */
  192. if (dxpbmMDC != 0 || dypbmMDC != 0)
  193. {
  194. DeleteObject( SelectObject( vhMDC, hbmNull ) );
  195. dxpbmMDC = dypbmMDC = 0;
  196. }
  197. /* Discard the screen fonts. */
  198. FreeFonts( TRUE, FALSE );
  199. /* Delete the memory DC. */
  200. DeleteDC( vhMDC );
  201. vhMDC = NULL;
  202. }
  203. /* Also, delete the DC for the printer width, if necessary. */
  204. if ( fPrinterToo )
  205. {
  206. FreePrinterDC();
  207. }
  208. }
  209. FreePrinterDC()
  210. {
  211. extern int vdocBitmapCache;
  212. extern HDC vhDCPrinter;
  213. extern BOOL vfPrinterValid;
  214. extern HWND hParentWw;
  215. /* Delete the printer DC if necessary. */
  216. if ( vhDCPrinter != NULL )
  217. {
  218. /* Discard the printer fonts. */
  219. FreeFonts( FALSE, TRUE );
  220. if ( vfPrinterValid )
  221. {
  222. /* This is a real printer DC; delete it. */
  223. DeleteDC( vhDCPrinter );
  224. }
  225. else
  226. {
  227. /* This is really the screen DC; it must be released. */
  228. ReleaseDC( hParentWw, vhDCPrinter );
  229. }
  230. vhDCPrinter = NULL;
  231. /* Free the cached bitmap because it was stretched for the display to
  232. reflect its appearance on the printer. */
  233. if (vdocBitmapCache != docNil)
  234. FreeBitmapCache();
  235. }
  236. }
  237. void MdocGetFocus(hWnd, hWndPrevFocus)
  238. HWND hWnd;
  239. HWND hWndPrevFocus;
  240. {
  241. extern int vfInsertOn;
  242. extern int vfFocus;
  243. if (!vfFocus)
  244. {
  245. vfFocus = TRUE;
  246. /* Start up a timer event to blink the caret */
  247. /* MdocWndProc gets notified with a message of WM_TIMER */
  248. /* every wCaretBlinkTime milliseconds */
  249. SetTimer( hWnd, tidCaret, GetCaretBlinkTime(), (FARPROC)NULL );
  250. /* Set the caret on right away, for looks */
  251. if (!vfInsertOn)
  252. MdocTimer( hWnd, tidCaret );
  253. /* Update globals that tell us the state of the lock/shift keys */
  254. SetShiftFlags();
  255. }
  256. #ifdef JAPAN
  257. ConvertEnable = TRUE;
  258. IMEManage( FALSE );
  259. #endif
  260. }
  261. void MdocLoseFocus(hWnd, hWndNewFocus)
  262. HWND hWnd;
  263. HWND hWndNewFocus;
  264. {
  265. extern int vfFocus;
  266. if (vfFocus)
  267. {
  268. extern int vfGotoKeyMode;
  269. /* Cancel caret blink timer event & clear the caret */
  270. KillTimer( hWnd, tidCaret );
  271. ClearInsertLine();
  272. /* Free up the memory DC */
  273. /* We interpret the loss of focus as a signal that */
  274. /* some other app will be using resources */
  275. vfFocus = FALSE;
  276. vfGotoKeyMode = FALSE; /* Cancel GOTO key modifier */
  277. /* Close all files on removable media in case the guy swaps disks */
  278. CloseEveryRfn( FALSE );
  279. }
  280. #ifdef JAPAN
  281. ConvertEnable = FALSE;
  282. IMEManage( TRUE );
  283. #endif
  284. }
  285.