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.

680 lines
20 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. //#define NOATOM
  5. #define NOBITMAP
  6. #define NOBRUSH
  7. #define NOCLIPBOARD
  8. #define NOCOMM
  9. #define NOCREATESTRUCT
  10. #define NODRAWTEXT
  11. #define NOGDICAPMASKS
  12. #define NOICON
  13. #define NOKEYSTATE
  14. #define NOMB
  15. #define NOMEMMGR
  16. //#define NOMENUS
  17. #define NOMETAFILE
  18. #define NOMINMAX
  19. #define NOOPENFILE
  20. #define NOPEN
  21. #define NOREGION
  22. //#define NOSHOWWINDOW
  23. #define NOSOUND
  24. #define NOSYSCOMMANDS
  25. #define NOSYSMETRICS
  26. #define NOVIRTUALKEYCODES
  27. #define NOWH
  28. #define NOWINOFFSETS
  29. #define NOWINSTYLES
  30. #define NOWNDCLASS
  31. #include <windows.h>
  32. #include "mw.h"
  33. #define NOUAC
  34. #include "cmddefs.h"
  35. #include "dispdefs.h"
  36. #include "wwdefs.h"
  37. #define NOSTRUNDO
  38. #include "str.h"
  39. #include "menudefs.h"
  40. #include "prmdefs.h"
  41. #include "propdefs.h"
  42. #include "debug.h"
  43. #include "fontdefs.h"
  44. #include "preload.h"
  45. #include "winddefs.h"
  46. #define NOIDISAVEPRINT
  47. #define NOIDIFORMATS
  48. #include "dlgdefs.h"
  49. #if defined(OLE)
  50. #include "obj.h"
  51. #endif
  52. static void DrawResizeHole(HWND hWnd, HDC hDC);
  53. extern HANDLE hMmwModInstance; /* handle to it's own module instance */
  54. extern HWND hParentWw; /* handle to parent's window */
  55. extern HWND vhWndMsgBoxParent;
  56. extern HCURSOR vhcHourGlass;
  57. extern HCURSOR vhcIBeam;
  58. extern HCURSOR vhcArrow;
  59. extern HMENU vhMenu;
  60. extern MSG vmsgLast;
  61. extern FARPROC lpDialogHelp;
  62. extern struct WWD rgwwd[];
  63. extern struct WWD *pwwdCur;
  64. extern int wwCur;
  65. extern int vfInitializing;
  66. extern int vfInsertOn;
  67. extern int vfSeeSel;
  68. extern int vfSelHidden;
  69. extern int vfDeactByOtherApp;
  70. extern int vfDownClick;
  71. extern int vfCursorVisible;
  72. extern int vfMouseExist;
  73. extern int flashID;
  74. extern int ferror;
  75. extern typeCP cpMacCur;
  76. extern struct SEL selCur;
  77. extern CHAR stBuf[];
  78. extern HBITMAP hbmNull;
  79. extern CHAR szWindows[];
  80. extern CHAR szDevices[];
  81. extern CHAR szIntl[];
  82. extern WORD fPrintOnly;
  83. #ifdef RULERALSO
  84. extern BOOL vfDisableMenus;
  85. #endif /* RULERALSO */
  86. #ifdef DEBUG
  87. #define STATIC
  88. #else /* not DEBUG */
  89. #define STATIC static
  90. #endif /* not DEBUG */
  91. CHAR **hszDevmodeChangeParam = NULL;
  92. BOOL vfDevmodeChange = fFalse;
  93. int wWininiChange = 0;
  94. BOOL vfDead = FALSE;
  95. BOOL vfIconic = FALSE;
  96. /*int vcActiveCount = 0; 0 or 1 for active/deactive count */
  97. void MmwCreate(HWND, LONG);
  98. void NEAR MmwPaint(HWND);
  99. void MmwSize(HWND, int, int, WORD);
  100. void MmwCommand(HWND, WORD, HWND, WORD);
  101. void MmwVertScroll(HWND, WORD, int);
  102. void NEAR MmwHorzScroll(HWND, WORD, int);
  103. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  104. HANDLE hInstance, hPrevInstance;
  105. LPSTR lpszCmdLine;
  106. int cmdShow;
  107. {
  108. /* Set up all manner of windows-related data; create parent (menu)
  109. window and child (document) window */
  110. if (!FInitWinInfo( hInstance, hPrevInstance, lpszCmdLine, cmdShow ))
  111. /* Could not initialize; WRITE fails */
  112. {
  113. return FALSE;
  114. }
  115. if (fPrintOnly)
  116. {
  117. UpdateDisplay(FALSE);
  118. fnPrPrinter();
  119. FMmwClose( hParentWw );
  120. DeleteObject( hbmNull );
  121. _exit( vmsgLast.wParam );
  122. }
  123. else
  124. MainLoop();
  125. DeleteObject( hbmNull );
  126. _exit( vmsgLast.wParam );
  127. }
  128. long FAR PASCAL MmwWndProc(hWnd, message, wParam, lParam)
  129. HWND hWnd;
  130. unsigned message;
  131. WORD wParam;
  132. LONG lParam;
  133. {
  134. extern int vfCloseFilesInDialog;
  135. extern long ropErase;
  136. extern int vfLargeSys;
  137. extern HDC vhDCPrinter;
  138. extern HWND vhWndCancelPrint;
  139. extern HWND vhWndPageInfo;
  140. extern HFONT vhfPageInfo;
  141. extern BOOL vfWinFailure;
  142. CHAR szT[cchMaxSz];
  143. long lReturn = 0L;
  144. #if defined(JAPAN) & defined(IME_HIDDEN) //IME3.1J
  145. //IR_UNDETERMINE
  146. extern HWND vhWnd; /* WINDOWS: Handle of the current document display window*/
  147. extern typeCP selUncpFirst;
  148. extern typeCP selUncpLim;
  149. if(selUncpFirst < selUncpLim) {
  150. switch (message) {
  151. case WM_INITMENU:
  152. case WM_VSCROLL:
  153. case WM_HSCROLL:
  154. UndetermineToDetermine(vhWnd);
  155. break;
  156. case WM_SIZE:
  157. if(SIZEICONIC == wParam )
  158. UndetermineToDetermine(vhWnd);
  159. default:
  160. break; //Fall
  161. }
  162. }
  163. #endif
  164. switch (message)
  165. {
  166. case WM_MENUSELECT:
  167. SetShiftFlags();
  168. break;
  169. case WM_CREATE:
  170. /* Window's being created; lParam contains lpParam field
  171. ** passed to CreateWindow */
  172. MmwCreate(hWnd, lParam);
  173. break;
  174. case WM_PAINT:
  175. /* Time to repaint this window. */
  176. MmwPaint(hWnd);
  177. break;
  178. #if defined(OLE)
  179. case WM_DROPFILES:
  180. /* We got dropped on, so bring ourselves to the top */
  181. BringWindowToTop(hWnd);
  182. #ifdef DEBUG
  183. OutputDebugString("Dropping on main window\r\n");
  184. #endif
  185. ObjGetDrop(wParam,TRUE);
  186. break;
  187. #endif
  188. case WM_INITMENU:
  189. /* setup the pull down menu before being drawn */
  190. /* wParam is the top level menu handle */
  191. vhMenu = (HMENU)wParam;
  192. break;
  193. case WM_INITMENUPOPUP:
  194. /* setup the pull down menu before being drawn */
  195. /* wParam is the popup menu handle */
  196. /* LOWORD(lParam) = index of popup in main menu */
  197. /* HIWORD(lParam) = 1 if system menu, 0 if application main menu */
  198. EndLongOp(vhcArrow);
  199. if (HIWORD(lParam) == 0)
  200. { /* we care for the application main menu only */
  201. #ifdef CYCLESTOBURN
  202. switch (LOWORD(lParam)) {
  203. default:
  204. break;
  205. case EDIT:
  206. PreloadCodeTsk( tskScrap );
  207. case CHARACTER:
  208. PreloadCodeTsk( tskFormat );
  209. break;
  210. }
  211. #endif
  212. SetAppMenu((HMENU)wParam, LOWORD(lParam));
  213. }
  214. /* Turn on the cursor so we can see where it is */
  215. if (!vfInsertOn && selCur.cpFirst == selCur.cpLim)
  216. ToggleSel( selCur.cpFirst, selCur.cpFirst, TRUE );
  217. break;
  218. case WM_ACTIVATE:
  219. /* We are becoming the active window iff wParam is non-0 */
  220. /* HIWORD( lParam ) is true iff the window is iconic */
  221. if (wParam && !HIWORD(lParam)
  222. #if 0
  223. #if defined(OLE)
  224. && !nBlocking
  225. #endif
  226. #endif
  227. && IsWindowEnabled(wwdCurrentDoc.wwptr))
  228. {
  229. SetFocus( wwdCurrentDoc.wwptr );
  230. vhWndMsgBoxParent = hParentWw;
  231. }
  232. if (wParam)
  233. {
  234. vfDeactByOtherApp = FALSE; /* this is to conquer a windows' bug */
  235. }
  236. /* did we receive a devmode/winini change that we should process now? */
  237. if (wWininiChange != 0)
  238. {
  239. Assert(wWininiChange > 0 && wWininiChange < wWininiChangeMax);
  240. PostMessage( hWnd, wWndMsgSysChange, WM_WININICHANGE, (LONG) wWininiChange );
  241. }
  242. if (vfDevmodeChange)
  243. {
  244. Assert(hszDevmodeChangeParam != NULL);
  245. PostMessage( hWnd, wWndMsgSysChange, WM_DEVMODECHANGE, (LONG) 0 );
  246. vfDevmodeChange = fFalse;
  247. }
  248. if (!vfInitializing && vfCursorVisible)
  249. ShowCursor(wParam);
  250. break;
  251. case WM_ACTIVATEAPP:
  252. /* We are activated or deactivated by another application */
  253. if (wParam == 0) /* being deactivated */
  254. {
  255. vfDeactByOtherApp = TRUE;
  256. vfDownClick = FALSE;
  257. /* hide selection if needed */
  258. if (!vfSelHidden)
  259. {
  260. UpdateWindow(hParentWw);
  261. ToggleSel(selCur.cpFirst, selCur.cpLim, FALSE);
  262. vfSelHidden = TRUE;
  263. }
  264. /* Deselect our fonts so that they can move if necessary. */
  265. ResetFont(FALSE);
  266. if (vhWndCancelPrint == NULL)
  267. {
  268. /* Reset the printer font iff we are not printing or
  269. repaginating. */
  270. ResetFont(TRUE);
  271. }
  272. if (!vfLargeSys && vhfPageInfo != NULL)
  273. {
  274. DeleteObject(SelectObject(GetDC(vhWndPageInfo),
  275. GetStockObject(SYSTEM_FONT)));
  276. vhfPageInfo = NULL;
  277. }
  278. }
  279. else /* being activated */
  280. {
  281. vfDeactByOtherApp = vfWinFailure = FALSE;
  282. #ifndef WIN30
  283. /* We get into a recursive loop in the situation where we
  284. have a bad/invalid/nonexistent printer driver because
  285. GetPrinterDC() calls CreateIC() which will end up sending
  286. another WM_ACTIVATEAPP! I think the machinery in Write
  287. work just fine with a null vhDCPrinter, and will retry
  288. again when it needs to do so ..pault 9/28/89 */
  289. /* get a DC for the current printer if necessary */
  290. if (vhDCPrinter == NULL)
  291. {
  292. GetPrinterDC(FALSE);
  293. }
  294. #endif
  295. /* hilight selection if needed */
  296. if (vfSelHidden)
  297. {
  298. UpdateWindow(hParentWw);
  299. /* Turn on selection highlight
  300. vfInsEnd = selCur.fEndOfLine;*/
  301. vfSelHidden = FALSE;
  302. ToggleSel(selCur.cpFirst, selCur.cpLim, TRUE);
  303. }
  304. }
  305. break;
  306. case WM_TIMER:
  307. /* the only timer event for the parent window is flashID */
  308. /* the blinking insertion point is for the doc window */
  309. if (vfDeactByOtherApp)
  310. {
  311. FlashWindow(hParentWw, TRUE);
  312. }
  313. else
  314. {
  315. KillTimer(hParentWw, flashID);
  316. flashID = 0;
  317. FlashWindow(hParentWw, FALSE);
  318. }
  319. break;
  320. case WM_CLOSE:
  321. /* The user has selected "Close" on the system menu */
  322. /* Failure to process this message means that DefWindowProc */
  323. /* Will send us a Destroy message */
  324. /* A return value of TRUE says "don't close" */
  325. /* Calling DestroyWindow means "Go ahead and close" */
  326. lReturn = (LONG) !FMmwClose( hWnd );
  327. break;
  328. case WM_QUERYENDSESSION:
  329. /* User has selected "End Session" from the MS-DOS window */
  330. /* Return TRUE if willing to quit, else return FALSE */
  331. lReturn = (LONG) FConfirmSave();
  332. break;
  333. case WM_ENDSESSION:
  334. /* if wParam is TRUE, Windows is shutting down and we should */
  335. /* delete temp files */
  336. /* if wParam is FALSE, then an "End session" has been aborted */
  337. if (wParam)
  338. {
  339. KillTempFiles( TRUE );
  340. }
  341. break;
  342. case WM_DESTROY:
  343. /* Window's being destroyed. */
  344. MmwDestroy();
  345. lReturn = (LONG) TRUE;
  346. break;
  347. case WM_SIZE:
  348. /* Window's size is changing. lParam contains the height
  349. ** and width, in the low and high words, respectively.
  350. ** wParam contains SIZENORMAL for "normal" size changes,
  351. ** SIZEICONIC when the window is being made iconic, and
  352. ** SIZEFULLSCREEN when the window is being made full screen. */
  353. MmwSize(hWnd, MAKEPOINT(lParam).x, MAKEPOINT(lParam).y, wParam);
  354. //if (wParam == SIZEICONIC)
  355. lReturn = DefWindowProc(hWnd, message, wParam, lParam);
  356. break;
  357. case WM_COMMAND:
  358. /* A menu item has been selected, or a control is notifying
  359. ** its parent. wParam is the menu item value (for menus),
  360. ** or control ID (for controls). For controls, the low word
  361. ** of lParam has the window handle of the control, and the hi
  362. ** word has the notification code. For menus, lParam contains
  363. ** 0L. */
  364. #ifdef RULERALSO
  365. if (!vfDisableMenus)
  366. #endif /* RULERALSO */
  367. {
  368. MmwCommand(hWnd, wParam, (HWND)LOWORD(lParam), HIWORD(lParam));
  369. }
  370. break;
  371. case WM_SYSCOMMAND:
  372. /* system command */
  373. #ifdef RULERALSO
  374. if (!vfDisableMenus)
  375. #endif /* RULERALSO */
  376. {
  377. lReturn = DefWindowProc(hWnd, message, wParam, lParam);
  378. }
  379. break;
  380. case WM_VSCROLL:
  381. /* Vertical scroll bar input. wParam contains the
  382. ** scroll code. For the thumb movement codes, the low
  383. ** word of lParam contain the new scroll position.
  384. ** Possible values for wParam are: SB_LINEUP, SB_LINEDOWN,
  385. ** SB_PAGEUP, SB_PAGEDOWN, SB_THUMBPOSITION, SB_THUMBTRACK */
  386. MmwVertScroll(hWnd, wParam, (int)lParam);
  387. break;
  388. case WM_HSCROLL:
  389. /* Horizontal scroll bar input. Parameters same as for
  390. ** WM_HSCROLL. UP and DOWN should be interpreted as LEFT
  391. ** and RIGHT, respectively. */
  392. MmwHorzScroll(hWnd, wParam, (int)lParam);
  393. break;
  394. case WM_WININICHANGE:
  395. /* We first save away the string passed in lParam,
  396. then return because WM_ACTIVATE will cause our
  397. wWndMsgSysChange message to get posted ..pault */
  398. if (lParam != NULL)
  399. {
  400. bltszx((LPSTR) lParam, (LPSTR) szT);
  401. /* Here we only care about [devices], [windows] or [intl] changes */
  402. if (WCompSz(szT, szWindows) == 0)
  403. wWininiChange |= wWininiChangeToWindows;
  404. #ifdef DBCS /* was in JAPAN */
  405. // We have to respond WININICHANGE immediately to deal with
  406. // dispatch driver. For deleting printer DC, dispatch driver
  407. // must be available. If do not so, syserr box comes up from
  408. // GDI module.
  409. if (WCompSz(szT, szDevices) == 0) {
  410. if( vhWndCancelPrint == NULL ) {
  411. MmwWinSysChange(WM_WININICHANGE);
  412. wWininiChange = 0; // reset
  413. }
  414. else
  415. wWininiChange |= wWininiChangeToDevices;
  416. }
  417. #else
  418. if (WCompSz(szT, szDevices) == 0)
  419. wWininiChange |= wWininiChangeToDevices;
  420. #endif
  421. if (WCompSz(szT, szIntl) == 0)
  422. wWininiChange |= wWininiChangeToIntl;
  423. lReturn = TRUE;
  424. }
  425. break;
  426. case WM_DEVMODECHANGE:
  427. /* See WM_WININICHANGE above */
  428. if (lParam != NULL)
  429. {
  430. CHAR (**HszCreate())[];
  431. bltszx((LPSTR) lParam, (LPSTR) szT);
  432. /* was there another change before this? */
  433. if (hszDevmodeChangeParam != NULL)
  434. FreeH(hszDevmodeChangeParam);
  435. hszDevmodeChangeParam = HszCreate(szT);
  436. vfDevmodeChange = fTrue;
  437. lReturn = TRUE;
  438. }
  439. break;
  440. case WM_SYSCOLORCHANGE:
  441. case WM_FONTCHANGE:
  442. /* Post this message to handle soon */
  443. PostMessage( hWnd, wWndMsgSysChange, message, (LONG) 0 );
  444. lReturn = TRUE;
  445. break;
  446. case wWndMsgSysChange:
  447. /* Handle postponed message from windows */
  448. #ifdef DEBUG
  449. if (wWininiChange != 0)
  450. Assert(wWininiChange > 0 && wWininiChange < wWininiChangeMax);
  451. #endif
  452. MmwWinSysChange( wParam );
  453. wWininiChange = 0; /* reset */
  454. lReturn = TRUE;
  455. break;
  456. default:
  457. /* Everything else comes here. This call MUST exist
  458. ** in your window proc. */
  459. lReturn = DefWindowProc(hWnd, message, wParam, lParam);
  460. break;
  461. }
  462. if (vfCloseFilesInDialog)
  463. CloseEveryRfn( FALSE );
  464. return lReturn;
  465. }
  466. void NEAR MmwPaint(hWnd)
  467. HWND hWnd;
  468. {
  469. /* This window is completely covered by it's children; so, there is
  470. no painting of this window to do. */
  471. extern HWND vhWndRuler;
  472. extern HWND vhWndSizeBox;
  473. extern HWND vhWndPageInfo;
  474. PAINTSTRUCT ps;
  475. HDC hDC;
  476. hDC = BeginPaint(hWnd, &ps); // this is causing nested BeginPaint calls,
  477. DrawResizeHole(hWnd,hDC);
  478. /* Paint the ruler if necessary. */
  479. if (vhWndRuler != NULL)
  480. {
  481. UpdateWindow(vhWndRuler);
  482. }
  483. /* Paint the scroll bar controls. */
  484. UpdateWindow(wwdCurrentDoc.hVScrBar);
  485. UpdateWindow(wwdCurrentDoc.hHScrBar);
  486. UpdateWindow(vhWndPageInfo);
  487. /* Paint the document window. */
  488. if (wwdCurrentDoc.wwptr != NULL)
  489. {
  490. UpdateWindow(wwdCurrentDoc.wwptr);
  491. }
  492. EndPaint(hWnd, &ps);
  493. }
  494. void MmwVertScroll(hWnd, code, posNew)
  495. HWND hWnd;
  496. WORD code;
  497. int posNew;
  498. {
  499. extern int vfSeeSel;
  500. extern int vfSeeEdgeSel;
  501. /* There's nothing to do if we are just tracking the thumb. */
  502. if (code == SB_THUMBTRACK)
  503. {
  504. return;
  505. }
  506. vfSeeSel = vfSeeEdgeSel = FALSE; /* So Idle doesn't override the scroll */
  507. if (code == SB_THUMBPOSITION)
  508. {
  509. /* Position to posNew; we rely upon Idle() to redraw the screen. */
  510. if (posNew != pwwdCur->drElevator)
  511. {
  512. ClearInsertLine();
  513. DirtyCache(pwwdCur->cpFirst = (cpMacCur - pwwdCur->cpMin) * posNew
  514. / (drMax - 1) + pwwdCur->cpMin);
  515. pwwdCur->ichCpFirst = 0;
  516. pwwdCur->fCpBad = TRUE;
  517. TrashWw(wwCur);
  518. }
  519. }
  520. else
  521. {
  522. switch (code)
  523. {
  524. case SB_LINEUP:
  525. ScrollUpCtr( 1 );
  526. break;
  527. case SB_LINEDOWN:
  528. ScrollDownCtr( 1 );
  529. break;
  530. case SB_PAGEUP:
  531. ScrollUpDypWw();
  532. break;
  533. case SB_PAGEDOWN:
  534. ScrollDownCtr( 100 ); /* 100 > tr's in a page */
  535. break;
  536. }
  537. UpdateWw(wwDocument, fFalse);
  538. }
  539. }
  540. void near MmwHorzScroll(hWnd, code, posNew)
  541. HWND hWnd;
  542. WORD code;
  543. int posNew;
  544. {
  545. extern int vfSeeSel;
  546. extern int vfSeeEdgeSel;
  547. /* There's nothing to do if we are just tracking the thumb. */
  548. if (code == SB_THUMBTRACK)
  549. {
  550. return;
  551. }
  552. vfSeeSel = vfSeeEdgeSel = FALSE; /* So Idle doesn't override the scroll */
  553. switch (code)
  554. {
  555. case SB_LINEUP: /* line left */
  556. ScrollRight(xpMinScroll);
  557. break;
  558. case SB_LINEDOWN: /* line right */
  559. ScrollLeft(xpMinScroll);
  560. break;
  561. case SB_PAGEUP: /* page left */
  562. ScrollRight(wwdCurrentDoc.xpMac - xpSelBar);
  563. break;
  564. case SB_PAGEDOWN: /* page right */
  565. ScrollLeft(wwdCurrentDoc.xpMac - xpSelBar);
  566. break;
  567. case SB_THUMBPOSITION:
  568. /* position to posNew */
  569. AdjWwHoriz(posNew - wwdCurrentDoc.xpMin);
  570. break;
  571. }
  572. }
  573. static void DrawResizeHole(HWND hWnd, HDC hDC)
  574. /* There's now a hole in the bottom right corner where
  575. the size box used to be, so need to fill it in! */
  576. {
  577. RECT rcSB,rcClient;
  578. HBRUSH hbr, hbrPrev;
  579. GetClientRect(hWnd,&rcClient);
  580. rcSB.left = rcClient.right - dxpScrlBar;
  581. rcSB.right = rcClient.right;
  582. rcSB.top = rcClient.bottom - dypScrlBar;
  583. rcSB.bottom = rcClient.bottom;
  584. if ((hbr = CreateSolidBrush(GetSysColor(COLOR_SCROLLBAR))) == NULL)
  585. hbr = GetStockObject(GRAY_BRUSH);
  586. hbrPrev = SelectObject(hDC, hbr);
  587. FillRect(hDC, (LPRECT)&rcSB, hbr);
  588. SelectObject(hDC, hbrPrev);
  589. DeleteObject(hbr);
  590. }
  591.