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.

328 lines
11 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* This routine sets up the screen position used by Word relative to the
  5. current device. */
  6. #define NOGDICAPMASKS
  7. #define NOVIRTUALKEYCODES
  8. #define NOWINSTYLES
  9. #define NOCLIPBOARD
  10. #define NOCTLMGR
  11. #define NOMENUS
  12. #define NOICON
  13. #define NOKEYSTATE
  14. #define NOSYSCOMMANDS
  15. #define NOSHOWWINDOW
  16. #define NOATOM
  17. #define NODRAWTEXT
  18. #define NOMSG
  19. #define NOOPENFILE
  20. #define NOSCROLL
  21. #define NOSOUND
  22. #define NOWH
  23. #define NOWINOFFSETS
  24. #define NOCOMM
  25. #include <windows.h>
  26. #include "mw.h"
  27. #include "cmddefs.h"
  28. #include "scrndefs.h"
  29. #include "dispdefs.h"
  30. #include "wwdefs.h"
  31. #include "printdef.h"
  32. #include "str.h"
  33. #include "docdefs.h"
  34. #include "propdefs.h"
  35. #include "machdefs.h"
  36. #include "fontdefs.h"
  37. #include "winddefs.h"
  38. #include <commdlg.h>
  39. MmwWinSysChange(wm)
  40. int wm;
  41. {
  42. /* This routine processes the WM_SYSCOLORCHANGE, WM_WININICHANGE,
  43. WM_DEVMODECHANGE, and WM_FONTCHANGE messages. */
  44. extern HDC vhDCRuler;
  45. extern HBRUSH hbrBkgrnd;
  46. extern long rgbBkgrnd;
  47. extern long rgbText;
  48. extern struct WWD rgwwd[];
  49. extern HDC vhMDC;
  50. extern BOOL vfMonochrome;
  51. extern HWND hParentWw;
  52. extern HWND vhWndPageInfo;
  53. extern HBITMAP vhbmBitmapCache;
  54. extern BOOL vfBMBitmapCache;
  55. extern int vfPrinterValid;
  56. extern CHAR szWindows[];
  57. extern CHAR szDevices[];
  58. extern CHAR (**hszPrinter)[];
  59. extern CHAR (**hszPrDriver)[];
  60. extern CHAR (**hszPrPort)[];
  61. extern CHAR (**hszDevmodeChangeParam)[];
  62. extern CHAR (**hszWininiChangeParam)[];
  63. extern HFONT vhfPageInfo;
  64. extern int docMode;
  65. extern HWND vhWndCancelPrint;
  66. extern BOOL vfIconic;
  67. extern BOOL vfWarnMargins;
  68. extern int wWininiChange;
  69. BOOL FSetWindowColors(void);
  70. CHAR szPrinter[cchMaxProfileSz];
  71. CHAR (**hszPrinterSave)[];
  72. CHAR (**hszPrDriverSave)[];
  73. CHAR (**hszPrPortSave)[];
  74. BOOL fNotPrinting = (vhWndCancelPrint == NULL);
  75. RECT rc;
  76. switch (wm)
  77. {
  78. case WM_SYSCOLORCHANGE:
  79. /* Someone is changing the system colors. */
  80. if (FSetWindowColors())
  81. {
  82. /* Change the colors of the ruler. */
  83. if (vhDCRuler != NULL)
  84. {
  85. HPEN hpen;
  86. /* Set the background and foreground colors of the ruler. */
  87. SetBkColor(vhDCRuler, rgbBkgrnd);
  88. SetTextColor(vhDCRuler, rgbText);
  89. /* Set the pen for the ruler. */
  90. if ((hpen = CreatePen(0, 0, rgbText)) == NULL)
  91. {
  92. hpen = GetStockObject(BLACK_PEN);
  93. }
  94. DeleteObject(SelectObject(vhDCRuler, hpen));
  95. /* Set the background brush for the ruler. */
  96. SelectObject(vhDCRuler, hbrBkgrnd);
  97. }
  98. if (wwdCurrentDoc.hDC != NULL)
  99. {
  100. /* Set the background and foreground colors. */
  101. SetBkColor(wwdCurrentDoc.hDC, rgbBkgrnd);
  102. SetTextColor(wwdCurrentDoc.hDC, rgbText);
  103. /* Set the background brush. */
  104. SelectObject(wwdCurrentDoc.hDC, hbrBkgrnd);
  105. if (vhMDC != NULL && vfMonochrome)
  106. {
  107. /* If the display is a monochrome device, then set the text
  108. color for the memory DC. Monochrome bitmaps will not be
  109. converted to the foreground and background colors in this
  110. case, we must do the conversion. */
  111. SetTextColor(vhMDC, rgbText);
  112. }
  113. }
  114. if (hParentWw != NULL)
  115. {
  116. /* Set the background brush for the parent window. */
  117. DeleteObject(SelectObject(GetDC(hParentWw), hbrBkgrnd));
  118. }
  119. }
  120. if (vhWndPageInfo != NULL)
  121. {
  122. HBRUSH hbr;
  123. HDC hDC = GetDC(vhWndPageInfo);
  124. /* Set the colors for the page info window. */
  125. if ((hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOWFRAME))) ==
  126. NULL)
  127. {
  128. hbr = GetStockObject(BLACK_BRUSH);
  129. }
  130. DeleteObject(SelectObject(hDC, hbr));
  131. #ifdef WIN30
  132. /* If the user has their colors set with a TextCaption color of
  133. black then this becomes hard to read! We just hardcode this
  134. to be white since the background defaults to being black */
  135. SetTextColor(hDC, (DWORD) -1);
  136. #else
  137. SetTextColor(hDC, GetSysColor(COLOR_CAPTIONTEXT));
  138. #endif
  139. }
  140. #if defined(JAPAN) & defined(IME_HIDDEN) //IME3.1J
  141. GetImeHiddenTextColors();
  142. #endif
  143. /* If the bitmap cache is holding a resized metafile, then free the
  144. cache because the bitmap might contain part of the background that might
  145. have changed. */
  146. if (vhbmBitmapCache != NULL && !vfBMBitmapCache)
  147. {
  148. FreeBitmapCache();
  149. }
  150. break;
  151. case WM_WININICHANGE:
  152. /* We only care if the "windows", "devices", or "intl" fields have
  153. changed -- this has been taken care of already, see mmw.c */
  154. if (wWininiChange & wWininiChangeToIntl)
  155. {
  156. extern HWND vhDlgRunning;
  157. extern int utCur;
  158. extern CHAR vchDecimal; /* decimal point character */
  159. CHAR bufT[3]; /* to hold decimal point string */
  160. extern CHAR szsDecimal[];
  161. extern CHAR szsDecimalDefault[];
  162. extern CHAR szIntl[];
  163. extern HWND vhWndRuler;
  164. extern int viDigits;
  165. extern BOOL vbLZero;
  166. if (GetProfileInt((LPSTR)szIntl, (LPSTR)"iMeasure", 1) == 1)
  167. utCur = utInch;
  168. else
  169. utCur = utCm;
  170. viDigits = GetProfileInt((LPSTR)szIntl, (LPSTR)"iDigits", 2);
  171. vbLZero = GetProfileInt((LPSTR)szIntl, (LPSTR)"iLZero", 0);
  172. /* Get the decimal point character from the user profile. */
  173. GetProfileString((LPSTR)szIntl, (LPSTR)szsDecimal, (LPSTR)szsDecimalDefault,
  174. (LPSTR)bufT, 2);
  175. vchDecimal = *bufT;
  176. InvalidateRect(vhWndRuler, (LPRECT)NULL, FALSE);
  177. UpdateRuler();
  178. }
  179. if ((wWininiChange & wWininiChangeToDevices) ||
  180. (wWininiChange & wWininiChangeToWindows))
  181. {
  182. /* Reestablish the printer from the profile in case it was the
  183. printer that was changed. */
  184. hszPrinterSave = hszPrinter;
  185. hszPrDriverSave = hszPrDriver;
  186. hszPrPortSave = hszPrPort;
  187. if (FGetPrinterFromProfile())
  188. {
  189. BOOL fPrChange = FALSE;
  190. if (hszPrinterSave == NULL || hszPrDriverSave == NULL ||
  191. hszPrPortSave == NULL || hszPrinter == NULL || hszPrDriver ==
  192. NULL || hszPrPort == NULL || WCompSz(&(**hszPrinter)[0],
  193. &(**hszPrinterSave)[0]) != 0 || WCompSz(&(**hszPrDriver)[0],
  194. &(**hszPrDriverSave)[0]) != 0 || WCompSz(&(**hszPrPort)[0],
  195. &(**hszPrPortSave)[0]) != 0)
  196. {
  197. /* If we are not printing, then we can reflect the change of
  198. the printer on the screen. */
  199. if (!(fPrChange = fNotPrinting))
  200. {
  201. /* We are printing while the printer has changed, set
  202. the flags so that the next time we get a printer DC we
  203. will assume that it is valid. */
  204. Assert(vfPrinterValid);
  205. vfWarnMargins = TRUE;
  206. }
  207. }
  208. /* Delete the saved copies of the printer strings. */
  209. if (hszPrinterSave != NULL)
  210. {
  211. FreeH(hszPrinterSave);
  212. }
  213. if (hszPrDriverSave != NULL)
  214. {
  215. FreeH(hszPrDriverSave);
  216. }
  217. if (hszPrPortSave != NULL)
  218. {
  219. FreeH(hszPrPortSave);
  220. }
  221. if (fPrChange)
  222. {
  223. /* Get the new printer DC and update the world. */
  224. goto GetNewPrinter;
  225. }
  226. }
  227. else
  228. {
  229. Error(IDPMTNoMemory);
  230. hszPrinter = hszPrinterSave;
  231. hszPrDriver = hszPrDriverSave;
  232. hszPrPort = hszPrPortSave;
  233. }
  234. }
  235. break;
  236. case WM_DEVMODECHANGE:
  237. /* The device mode for some printer has changed; check to see if it was
  238. our printer. */
  239. if (fNotPrinting && hszPrinter != NULL &&
  240. (hszDevmodeChangeParam == NULL ||
  241. (bltszx(*hszDevmodeChangeParam, (LPSTR)szPrinter ),
  242. WCompSz(szPrinter, &(**hszPrinter)[0]) == 0)))
  243. {
  244. extern PRINTDLG PD; /* Common print dlg structure, initialized in the init code */
  245. GetNewPrinter:
  246. if (PD.hDevMode)
  247. GlobalFree(PD.hDevMode);
  248. if (PD.hDevNames)
  249. GlobalFree(PD.hDevNames);
  250. PD.hDevMode = PD.hDevNames = NULL;
  251. /* The printer has changed, so get rid of the old one. */
  252. FreePrinterDC();
  253. fnPrGetDevmode();
  254. #if defined(OLE)
  255. ObjSetTargetDevice(TRUE);
  256. #endif
  257. /* The printer description has changed; assume the new printer is
  258. valid. */
  259. vfPrinterValid = vfWarnMargins = TRUE;
  260. GetPrinterDC(FALSE);
  261. ResetFontTables();
  262. RedrawWindow:
  263. /* Everything must be redisplayed because the world may have
  264. changed. */
  265. if (!vfIconic)
  266. {
  267. InvalidateRect(wwdCurrentDoc.wwptr, (LPRECT)NULL, FALSE);
  268. }
  269. }
  270. if (hszDevmodeChangeParam != NULL)
  271. FreeH(hszDevmodeChangeParam);
  272. hszDevmodeChangeParam = NULL;
  273. break;
  274. case WM_FONTCHANGE:
  275. /* The font used to display the page number may have changed. */
  276. if (vhfPageInfo != NULL)
  277. {
  278. DeleteObject(SelectObject(GetDC(vhWndPageInfo),
  279. GetStockObject(SYSTEM_FONT)));
  280. vhfPageInfo = NULL;
  281. }
  282. docMode = docNil;
  283. DrawMode();
  284. ResetFontTables();
  285. goto RedrawWindow;
  286. } /* end switch */
  287. }
  288.