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.

436 lines
11 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* The routines in this file roughly correspond to the routines in the original
  5. Mac Word file, sand.c. But since that name is confusing, and most of these
  6. routine deal with the mouse, the name was changed to protect the innocent. */
  7. #define NOGDICAPMASKS
  8. #define NOWINSTYLES
  9. #define NOCLIPBOARD
  10. #define NOCTLMGR
  11. #define NOSYSMETRICS
  12. #define NOMENUS
  13. #define NOSOUND
  14. #define NOCOMM
  15. //#define NOMETAFILE
  16. #include <windows.h>
  17. #include "mw.h"
  18. #include "dispdefs.h"
  19. #define NOUAC
  20. #include "cmddefs.h"
  21. #include "wwdefs.h"
  22. #include "fmtdefs.h"
  23. #include "propdefs.h"
  24. #if defined(OLE)
  25. #include "obj.h"
  26. #include "winddefs.h"
  27. #include "str.h"
  28. #endif
  29. /* cpNil is defined in docdefs.h, but to include the whole file will cause the
  30. symbol table to overflow, so it is redefined here. */
  31. #define cpNil ((typeCP) -1)
  32. extern struct WWD rgwwd[];
  33. extern struct WWD *pwwdCur;
  34. extern int wwCur;
  35. extern struct SEL selCur;
  36. extern int docCur;
  37. extern int vfShiftKey;
  38. extern int vfOptionKey;
  39. extern int vfCommandKey;
  40. extern int vfDoubleClick;
  41. extern typeCP vcpFirstParaCache;
  42. extern typeCP vcpLimParaCache;
  43. extern struct PAP vpapAbs;
  44. extern typeCP cpWall;
  45. extern int vfDidSearch;
  46. extern typeCP vcpSelect;
  47. extern int vfSelAtPara;
  48. extern int vfPictSel;
  49. extern long tickOld;
  50. #ifdef PENWIN
  51. extern int vcFakeMessage;
  52. extern LONG FAR PASCAL GetMessageExtraInfo( void ); // Defined in Win 3.1
  53. #endif
  54. /* G L O B A L S */
  55. int vfSelecting = false;
  56. int vstyCur;
  57. int vpsmCur;
  58. int vfObjOpen=0,vfObjProps=0,vfObjSel=0;
  59. int vfAwfulNoise = false;
  60. struct SEL selPend;
  61. /* MB_STANDARD is the same as in diaalert.c */
  62. #define MB_STANDARD (MB_OK | MB_SYSTEMMODAL | MB_ICONEXCLAMATION)
  63. /* _ B E E P */
  64. _beep()
  65. {
  66. /* Beeps once */
  67. if (!vfAwfulNoise)
  68. {
  69. beep();
  70. vfAwfulNoise = true;
  71. }
  72. }
  73. beep()
  74. {
  75. MessageBeep(MB_STANDARD);
  76. }
  77. /* D O C O N T E N T H I T */
  78. DoContentHit(pt)
  79. POINT pt;
  80. {
  81. /* This routine process everything from a mouse-down click to the
  82. corresponding mouse-up click. */
  83. int dlMouse;
  84. /* Ignore mouse hits in the page area & above the first line*/
  85. if ( (pt.y >= wwdCurrentDoc.ypMac) ||
  86. (pt.y < wwdCurrentDoc.ypMin) )
  87. return;
  88. /* Check for a special selection, i.e. move, copy or format text. */
  89. if (FSetPsm())
  90. {
  91. blt(&selCur, &selPend, cwSEL);
  92. vfDoubleClick = vfCommandKey = vfShiftKey = false;
  93. vstyCur = vpsmCur != psmLooks ? StyFromPt(pt) : styChar;
  94. }
  95. else
  96. {
  97. vstyCur = StyFromPt(pt);
  98. }
  99. dlMouse = DlFromYp(pt.y, pwwdCur);
  100. vcpSelect = cpNil;
  101. vfSelAtPara = false;
  102. #ifdef ENABLE
  103. if (vfPictSel)
  104. {
  105. /* Check for a picture modification (moving, sizing). */
  106. if (FHitPictFrame(dlMouse, pt))
  107. {
  108. return;
  109. }
  110. /* Remove the picture frame */
  111. ToggleSel(selCur.cpFirst, selCur.cpLim, false);
  112. vfPictSel = false;
  113. ToggleSel(selCur.cpFirst, selCur.cpLim, true);
  114. }
  115. #endif
  116. vfSelecting = true;
  117. SelectDlXp(dlMouse, pt.x, vstyCur, vfShiftKey);
  118. /* Now we sit in a loop processing all mouse events in all windows until a
  119. mouse-up click. */
  120. SetCapture(wwdCurrentDoc.wwptr);
  121. while( FStillDown( &pt ) )
  122. {
  123. /* If the mouse is above or below the window, then scroll the window and
  124. pretend the mouse is in the window. */
  125. if (pt.y > (int)wwdCurrentDoc.ypMac)
  126. {
  127. ScrollDownCtr( 1 );
  128. goto DoCont1;
  129. }
  130. else if (pt.y < (int)wwdCurrentDoc.ypMin)
  131. {
  132. ScrollUpCtr( 1 );
  133. DoCont1: UpdateWw(wwCur, false);
  134. }
  135. /* Get a valid dl and xp. */
  136. dlMouse = DlFromYp(pt.y, pwwdCur);
  137. if (pt.x < 0)
  138. pt.x = 0;
  139. else if (pt.x > wwdCurrentDoc.xpMac)
  140. pt.x = wwdCurrentDoc.xpMac;
  141. /* Update the selection. */
  142. if (vfOptionKey)
  143. {
  144. vcpSelect = cpNil;
  145. }
  146. SelectDlXp(dlMouse, pt.x, vstyCur, !vfOptionKey);
  147. } /* End of for ( ; ; ) */
  148. /* Release all of the mouse events. */
  149. ReleaseCapture();
  150. /* Process Mouse Up */
  151. DoContentHitEnd( pt );
  152. SetFocus( wwdCurrentDoc.wwptr );
  153. /* If the selection is an insertion bar, start it flashing. */
  154. if (selCur.cpFirst == selCur.cpLim)
  155. {
  156. extern int vfSkipNextBlink;
  157. vfSkipNextBlink = true;
  158. }
  159. #if defined(OLE)
  160. if (ObjQueryCpIsObject(docCur,selCur.cpFirst) && (vfObjProps || vfObjOpen))
  161. /* doubleclick and maybe alt key */
  162. {
  163. /* set whether link or emb selected */
  164. ObjSetSelectionType(docCur,selCur.cpFirst,selCur.cpLim);
  165. if (vfObjProps)
  166. /* alt + double click */
  167. {
  168. switch(OBJ_SELECTIONTYPE)
  169. {
  170. #if 0 // do nothing if embedded
  171. case EMBEDDED:
  172. {
  173. struct PICINFOX picInfo;
  174. GetPicInfo(selCur.cpFirst,selCur.cpLim, docCur, &picInfo);
  175. ObjEditObjectInDoc(&picInfo, docCur, vcpFirstParaCache);
  176. }
  177. break;
  178. #endif
  179. case LINK:
  180. /* bring up properties dlg */
  181. fnObjProperties();
  182. break;
  183. }
  184. CachePara(docCur,selCur.cpFirst);
  185. }
  186. else if (vfObjOpen) // edit object
  187. /* double click */
  188. {
  189. if (OBJ_SELECTIONTYPE == STATIC)
  190. Error(IDPMTStatic);
  191. else
  192. {
  193. struct PICINFOX picInfo;
  194. GetPicInfo(selCur.cpFirst,selCur.cpLim, docCur, &picInfo);
  195. ObjPlayObjectInDoc(&picInfo, docCur, vcpFirstParaCache);
  196. }
  197. }
  198. }
  199. #endif
  200. }
  201. /* D O C O N T E N T H I T E N D */
  202. DoContentHitEnd(pt)
  203. POINT pt;
  204. {
  205. int dlMouse;
  206. int cch;
  207. dlMouse = DlFromYp(min(pt.y, wwdCurrentDoc.ypMac), pwwdCur);
  208. SelectDlXp(dlMouse, pt.x, vstyCur, vpsmCur == psmNil);
  209. switch (vpsmCur)
  210. {
  211. default:
  212. case psmNil:
  213. break;
  214. case psmLooks:
  215. LooksMouse();
  216. break;
  217. case psmCopy:
  218. #if defined(OLE)
  219. /* we'll disable CopyMouse if any objects are in dest */
  220. vfObjSel = ObjQueryCpIsObject(docCur,selCur.cpFirst);
  221. if (!vfObjSel)
  222. // !!! disable because for objects this
  223. // interferes with Alt-DoubleClick (2.20.91) D. Kent
  224. #endif
  225. CopyMouse();
  226. break;
  227. case psmMove:
  228. MoveMouse();
  229. break;
  230. }
  231. #ifdef ENABLE
  232. CachePara(docCur, selCur.cpFirst);
  233. if (vpapAbs.fGraphics && selCur.cpLim == vcpLimParaCache)
  234. {
  235. /* Selected a picture, do special selection stuff. */
  236. Assert(selCur.cpFirst == vcpFirstParaCache);
  237. /* Turn off the selection, indicate that it is a picture, then turn it
  238. back on. */
  239. ToggleSel(selCur.cpFirst, selCur.cpLim, false);
  240. vfPictSel = true;
  241. ToggleSel(selCur.cpFirst, selCur.cpLim, true);
  242. }
  243. else
  244. {
  245. vfPictSel = false;
  246. }
  247. #endif
  248. vfDidSearch = false;
  249. cpWall = selCur.cpLim;
  250. vfSelecting = false;
  251. }
  252. /* S T Y F R O M P T */
  253. int StyFromPt(pt)
  254. POINT pt;
  255. {
  256. /* Return the style code associated with the selection made at point pt. */
  257. if (pt.x > xpSelBar)
  258. {
  259. return vfCommandKey ? stySent : (vfDoubleClick ? styWord : styChar);
  260. }
  261. else
  262. {
  263. return vfCommandKey ? styDoc : (vfDoubleClick ? styPara : styLine);
  264. }
  265. }
  266. /* F S E T P S M */
  267. int FSetPsm()
  268. {
  269. /* Sets vpsmCur according to the states of the shift, commad, and option
  270. keys. True is returned if vpsmCur is not nil; false otherwise. */
  271. vpsmCur = psmNil;
  272. if (vfOptionKey)
  273. {
  274. if (vfShiftKey && !vfCommandKey)
  275. {
  276. vpsmCur = psmMove;
  277. }
  278. else if (vfCommandKey && !vfShiftKey)
  279. {
  280. vpsmCur = psmLooks;
  281. }
  282. else if (!vfCommandKey && !vfShiftKey)
  283. {
  284. vfObjProps = vfDoubleClick;
  285. vfObjOpen = FALSE;
  286. vpsmCur = psmCopy;
  287. }
  288. }
  289. else
  290. {
  291. vfObjOpen = vfDoubleClick;
  292. vfObjProps = FALSE;
  293. }
  294. return (vpsmCur != psmNil);
  295. }
  296. /* D L F R O M Y P */
  297. int DlFromYp(yp, pwwd)
  298. int yp;
  299. struct WWD *pwwd;
  300. {
  301. /* Return the dl that contains yp */
  302. int dlT;
  303. int ypSum;
  304. struct EDL *pedl;
  305. int dlMac;
  306. /* Clean up a dirty window. */
  307. if (pwwd->fDirty)
  308. {
  309. UpdateWw(pwwd - &rgwwd[0] /* = ww; grr.. */, false);
  310. }
  311. /* Loop throught the EDLs summing up the heights utill the sum is greater
  312. than yp. */
  313. ypSum = pwwd->ypMin;
  314. pedl = &(**(pwwd->hdndl))[0];
  315. dlMac = pwwd->dlMac;
  316. for (dlT = 0; dlT < dlMac; ++dlT, pedl++)
  317. {
  318. ypSum += pedl->dyp;
  319. if (ypSum > yp)
  320. {
  321. return dlT;
  322. }
  323. }
  324. return dlMac - 1;
  325. }
  326. FStillDown( ppt )
  327. POINT *ppt;
  328. { /* This is roughly equivalent to a Mac routine that returns whether
  329. the mouse button is down. We look for one mouse message from our
  330. window's queue, and return FALSE if it is a BUTTONUP. We return the
  331. point at which the mouse event occurred through a pointer. If no
  332. message occurred, we return TRUE and do not store into the pointer */
  333. MSG msg;
  334. retry_peek:
  335. if ( PeekMessage( (LPMSG)&msg, (HWND)NULL, NULL, NULL, PM_REMOVE ) )
  336. {
  337. extern WORD wWinVer;
  338. switch (msg.message) {
  339. default:
  340. TranslateMessage( (LPMSG)&msg );
  341. DispatchMessage( (LPMSG)&msg );
  342. return TRUE;
  343. case WM_MOUSEMOVE:
  344. case WM_LBUTTONUP:
  345. case WM_LBUTTONDOWN:
  346. #ifdef PENWIN
  347. if (((wWinVer & 0xFF) >= 3) && ((wWinVer & 0xFF00) >= 0x0A00))
  348. /* Windows Version >= 3.10 */
  349. if( vcFakeMessage > 0 )
  350. {
  351. static FARPROC MessageExtraInfo = NULL;
  352. if (MessageExtraInfo == NULL)
  353. MessageExtraInfo = GetProcAddress(GetModuleHandle((LPSTR)"USER"),(LPSTR)288L);
  354. if( MessageExtraInfo() != 0 )
  355. goto retry_peek;
  356. vcFakeMessage--;
  357. }
  358. #endif
  359. /* A Mouse Move, Mouse Down, or Mouse Up is waiting */
  360. ppt->x = MAKEPOINT(msg.lParam).x;
  361. ppt->y = MAKEPOINT(msg.lParam).y;
  362. return (msg.message != WM_LBUTTONUP);
  363. }
  364. }
  365. else
  366. return GetKeyState( VK_LBUTTON ) < 0;
  367. return TRUE;
  368. }
  369. 
  370.