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.

382 lines
9.8 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* chlook.c -- modify format from the keyboard or directly from dropdown */
  5. #define NOCLIPBOARD
  6. #define NOCTLMGR
  7. #define NOGDICAPMASKS
  8. #define NOWINSTYLES
  9. #define NOWINMESSAGES
  10. #define NOVIRTUALKEYCODES
  11. #include <windows.h>
  12. #include "mw.h"
  13. #include "cmddefs.h"
  14. #include "editdefs.h"
  15. #include "str.h"
  16. #include "prmdefs.h"
  17. #include "propdefs.h"
  18. #include "filedefs.h"
  19. #include "dispdefs.h"
  20. #include "menudefs.h"
  21. /* E X T E R N A L S */
  22. extern HMENU vhMenu;
  23. extern int vfVisiMode;
  24. extern int vfInsLast;
  25. extern int vfSeeSel;
  26. extern int fGrayChar;
  27. extern struct UAB vuab;
  28. #ifdef ENABLE /* myMenus and mpifntfont not used */
  29. extern MENUHANDLE myMenus[];
  30. extern int mpifntfont[];
  31. #endif
  32. extern int vifntMac;
  33. extern int vifntApplication;
  34. #define keyDownMask 8
  35. CHAR rgbAgain[1 + cchINT]; /* holds last sprm with value for Again key */
  36. /* D O C H L O O K */
  37. /* decode ch and apply looks to pchp (or to current sel if pchp == 0) */
  38. DoChLook(ch, pchp)
  39. int ch;
  40. struct CHP *pchp;
  41. {
  42. #ifdef ENABLE /* DoChLook not implemented yet */
  43. typeCP cpFirst, cpLim;
  44. int val;
  45. int sprm;
  46. int enbSave;
  47. vfSeeSel = vfInsLast = fTrue;
  48. if (ch == chAgain)
  49. {
  50. AddOneSprm(rgbAgain, fTrue);
  51. vuab.uac = uacChLook;
  52. SetUndoMenuStr(IDSTRUndoLook);
  53. return;
  54. }
  55. val = fTrue;
  56. switch(ChUpper(ch & 0377))
  57. {
  58. default:
  59. /*---- Error(IDPMTBadLook);----*/
  60. beep();
  61. return;
  62. case chLookStd & 0377:
  63. sprm = sprmCPlain;
  64. val = stcNormal;
  65. goto LApplyCLook;
  66. case chLookItalic & 0377:
  67. sprm = sprmCItalic;
  68. goto LApplyCLook;
  69. case chLookBold & 0377:
  70. sprm = sprmCBold;
  71. goto LApplyCLook;
  72. case chLookUline & 0377:
  73. sprm = sprmCUline;
  74. goto LApplyCLook;
  75. case chLookShadow & 0377:
  76. sprm = sprmCShadow;
  77. goto LApplyCLook;
  78. case chLookOutline & 0377:
  79. sprm = sprmCOutline;
  80. goto LApplyCLook;
  81. case chLookSuper & 0377:
  82. sprm = sprmCPos;
  83. val = ypSubSuper;
  84. goto LApplyCLook;
  85. case chLookSub & 0377:
  86. sprm = sprmCPos;
  87. val = -ypSubSuper;
  88. goto LApplyCLook;
  89. case chLookSmCaps & 0377:
  90. sprm = sprmCCsm;
  91. val = csmSmallCaps;
  92. goto LApplyCLook;
  93. case chLookHpsBig & 0377:
  94. sprm = sprmCChgHps;
  95. val = 1;
  96. goto LApplyCLook;
  97. case chLookHpsSmall & 0377:
  98. sprm = sprmCChgHps;
  99. val = -1;
  100. goto LApplyCLook;
  101. case chLookFont & 0377:
  102. /* Disable eject disk/ print image key handlers */
  103. #define SCRDMPENB (0x2f8L)
  104. enbSave = LDBI(SCRDMPENB);
  105. STBI(0, SCRDMPENB);
  106. ch = ChInpWait();
  107. STBI(enbSave, SCRDMPENB);
  108. if (ch < '0' || ch > '9')
  109. {
  110. /*---- Error(IDPMTBadLook);----*/
  111. beep();
  112. return;
  113. }
  114. sprm = sprmCChgFtc;
  115. val = ch - '0';
  116. /* Map from font index to system font code */
  117. val = val >= vifntMac ? vifntApplication & 0377: mpifntfont[val];
  118. goto LApplyCLook;
  119. /* Paragraph looks */
  120. case chLookGeneral & 0377:
  121. sprm = sprmPNormal;
  122. /*val = 0;*/
  123. break;
  124. case chLookLeft & 0377:
  125. sprm = sprmPJc;
  126. val = jcLeft;
  127. break;
  128. case chLookRight & 0377:
  129. sprm = sprmPJc;
  130. val = jcRight;
  131. break;
  132. case chLookJust & 0377:
  133. sprm = sprmPJc;
  134. val = jcBoth;
  135. break;
  136. case chLookCenter & 0377:
  137. sprm = sprmPJc;
  138. val = jcCenter;
  139. break;
  140. case chLookIndent & 0377:
  141. val = czaInch/2;
  142. sprm = sprmPFIndent;
  143. goto LApplyPLook;
  144. case chLookDouble & 0377:
  145. val = czaLine * 2;
  146. sprm = sprmPDyaLine;
  147. goto LApplyPLook;
  148. case chLookOpen & 0377:
  149. val = czaLine;
  150. sprm = sprmPDyaBefore;
  151. goto LApplyPLook;
  152. case chLookNest & 0377:
  153. sprm = sprmPNest;
  154. /*val = 0;*/
  155. break;
  156. case chLookUnNest & 0377:
  157. sprm = sprmPUnNest;
  158. /*val = 0;*/
  159. break;
  160. case chLookHang & 0377:
  161. sprm = sprmPHang;
  162. /*val = 0;*/
  163. break;
  164. }
  165. /* apply look with 1 char value */
  166. ApplyLooksParaS(pchp, sprm, val);
  167. return;
  168. /* apply look with cchInt char value */
  169. LApplyPLook:
  170. ApplyLooksPara(pchp, sprm, val);
  171. return;
  172. LApplyCLook:
  173. ApplyCLooks(pchp, sprm, val);
  174. return;
  175. #endif /* ENABLE */
  176. }
  177. /* A P P L Y C L O O K S */
  178. /* character looks. val is a 1 char value */
  179. ApplyCLooks(pchp, sprm, val)
  180. struct CHP *pchp;
  181. int sprm, val;
  182. {
  183. /* Assemble sprm */
  184. CHAR *pch = rgbAgain;
  185. *pch++ = sprm;
  186. *pch = val;
  187. if (pchp == 0)
  188. {
  189. /* apply looks to current selection */
  190. AddOneSprm(rgbAgain, fTrue);
  191. vuab.uac = uacChLook;
  192. SetUndoMenuStr(IDSTRUndoLook);
  193. }
  194. else
  195. /* apply looks to pchp */
  196. DoSprm(pchp, 0, sprm, pch);
  197. }
  198. /* A P P L Y L O O K S P A R A S */
  199. /* val is a char value */
  200. ApplyLooksParaS(pchp, sprm, val)
  201. struct CHP *pchp;
  202. int sprm, val;
  203. {
  204. int valT = 0;
  205. CHAR *pch = (CHAR *)&valT;
  206. *pch = val;
  207. /* all the above is just to prepare bltbyte later gets the right byte order */
  208. ApplyLooksPara(pchp, sprm, valT);
  209. }
  210. /* A P P L Y L O O K S P A R A */
  211. /* val is an integer value. Char val's must have been bltbyte'd into val */
  212. ApplyLooksPara(pchp, sprm, val)
  213. struct CHP *pchp;
  214. int sprm, val;
  215. {
  216. #ifdef ENABLE /* related to footnote */
  217. if (FWriteCk(fwcNil)) /* Just check for illegal action in footnote */
  218. #endif
  219. {
  220. /* set Again stuff since we may have been called from the menu */
  221. CHAR *pch = rgbAgain;
  222. *pch++ = sprm;
  223. bltbyte(&val, pch, cchINT);
  224. AddOneSprm(rgbAgain, fTrue);
  225. vuab.uac = uacChLook;
  226. SetUndoMenuStr(IDSTRUndoLook);
  227. }
  228. return;
  229. }
  230. #ifdef ENABLE /* fnChar/fnPara */
  231. /* F N C H A R P L A I N */
  232. void fnCharPlain()
  233. {
  234. ApplyCLooks(0, sprmCPlain, 0);
  235. }
  236. /* F N C H A R B O L D */
  237. void fnCharBold()
  238. {
  239. ApplyCLooks(0, sprmCBold, FMenuUnchecked(imiBold));
  240. }
  241. void fnCharItalic()
  242. {
  243. ApplyCLooks(0, sprmCItalic, FMenuUnchecked(imiItalic));
  244. }
  245. void fnCharUnderline()
  246. {
  247. ApplyCLooks(0, sprmCUline, FMenuUnchecked(imiUnderline));
  248. }
  249. void fnCharSuperscript()
  250. {
  251. ApplyCLooks(0, sprmCPos, FMenuUnchecked(imiSuper) ? ypSubSuper : 0);
  252. }
  253. void fnCharSubscript()
  254. {
  255. ApplyCLooks(0, sprmCPos, FMenuUnchecked(imiSub) ? -ypSubSuper : 0);
  256. }
  257. void fnParaNormal()
  258. {
  259. extern int vfPictSel;
  260. ApplyLooksParaS(0, sprmPNormal, 0);
  261. if (vfPictSel)
  262. CmdUnscalePic();
  263. }
  264. void fnParaLeft()
  265. {
  266. ApplyLooksParaS(0, sprmPJc, jcLeft);
  267. }
  268. void fnParaCentered()
  269. {
  270. ApplyLooksParaS(0, sprmPJc, jcCenter);
  271. }
  272. void fnParaRight()
  273. {
  274. ApplyLooksParaS(0, sprmPJc, jcRight);
  275. }
  276. void fnParaJustified()
  277. {
  278. ApplyLooksParaS(0, sprmPJc, jcBoth);
  279. }
  280. void fnParaOneandhalfspace()
  281. {
  282. ApplyLooksPara(0, sprmPDyaLine, czaLine * 3 / 2);
  283. }
  284. void fnParaDoublespace()
  285. {
  286. ApplyLooksPara(0, sprmPDyaLine, czaLine * 2);
  287. }
  288. void fnParaSinglespace()
  289. {
  290. ApplyLooksPara(0, sprmPDyaLine, czaLine);
  291. }
  292. int
  293. FMenuUnchecked(imi)
  294. int imi;
  295. { /* Return true if there is NO check mark in front of menu */
  296. int flag;
  297. if (fGrayChar)
  298. return true;
  299. flag = CheckMenuItem(vhMenu, imi, MF_CHECKED);
  300. CheckMenuItem(vhMenu, imi, flag); /* back to original status */
  301. return(flag == MF_UNCHECKED ? true : false);
  302. #ifdef SAND
  303. GetItemMark(myMenus[CHARACTER - 1], imi, &ch);
  304. /***** WRONG COMMENT BELOW! *****/
  305. return (ch != 18); /* Return true is there is a check mark in front of menu */
  306. #endif /* SAND */
  307. }
  308. #endif
  309. int ChInpWait()
  310. {
  311. #ifdef ENABLE /* CpInpWait not implemented yet */
  312. EVENT event;
  313. int i;
  314. for (i = 0; i < 15000; i++)
  315. {
  316. if(GetNextEvent(keyDownMask, &event))
  317. return (event.message.wl & 0x007f);
  318. }
  319. return -1; /* Will cause a beep if the user times out */
  320. #endif /* ENABLE */
  321. }
  322. #ifdef CASHMERE /* smcap, overstrike, dbline, open para, visible mode */
  323. fnCharSmallcaps()
  324. {
  325. ApplyCLooks(0, sprmCCsm, FMenuUnchecked(7) ? csmSmallCaps : csmNormal);
  326. }
  327. fnCharOutline()
  328. {
  329. ApplyCLooks(0, sprmCOutline, FMenuUnchecked(5));
  330. }
  331. fnCharShadow()
  332. {
  333. ApplyCLooks(0, sprmCShadow, FMenuUnchecked(6));
  334. }
  335. fnParaOpenspace()
  336. {
  337. ApplyLooksPara(0, sprmPDyaBefore, czaLine);
  338. }
  339. fnVisiMode()
  340. {
  341. vfVisiMode = !vfVisiMode;
  342. TrashAllWws();
  343. }
  344. #endif /* CASHMERE */
  345.