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.

1089 lines
29 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* CreateWw.c -- WRITE window & document creation */
  5. #define NOCLIPBOARD
  6. #define NOGDICAPMASKS
  7. #define NOVIRTUALKEYCODES
  8. #define NOWINMESSAGES
  9. #define NOSYSMETRICS
  10. #define NOMENUS
  11. #define NOICON
  12. #define NOKEYSTATE
  13. #define NOSYSCOMMANDS
  14. #define NORASTEROPS
  15. //#define NOATOM
  16. #define NOBITMAP
  17. #define NOPEN
  18. #define NODRAWTEXT
  19. #define NOCOLOR
  20. #define NOCREATESTRUCT
  21. #define NOHDC
  22. #define NOMB
  23. #define NOMETAFILE
  24. #define NOMSG
  25. #define NOPOINT
  26. #define NORECT
  27. #define NOREGION
  28. #define NOSCROLL
  29. #define NOWH
  30. #define NOWINOFFSETS
  31. #define NOSOUND
  32. #define NOCOMM
  33. #define NOOPENFILE
  34. #define NORESOURCE
  35. #include <windows.h>
  36. #include "mw.h"
  37. #include "dispdefs.h"
  38. #define NOUAC
  39. #include "cmddefs.h"
  40. #include "wwdefs.h"
  41. #include "docdefs.h"
  42. #include "fontdefs.h"
  43. #include "editdefs.h"
  44. #include "filedefs.h"
  45. #include "propdefs.h"
  46. #include "fkpdefs.h"
  47. #define NOSTRUNDO
  48. #define NOSTRMERGE
  49. #include "str.h"
  50. #include "code.h"
  51. #include "prmdefs.h"
  52. #if defined(OLE)
  53. #include "obj.h"
  54. #endif
  55. #define PAGEONLY
  56. #include "printdef.h" /* printdefs.h */
  57. /*
  58. #include "dlgdefs.h"
  59. */
  60. #ifdef KOREA
  61. #include <ime.h>
  62. #endif
  63. #ifndef JAPAN // added 10 Jun. 1992 by Hiraisi
  64. /*
  65. * These defines are not referrenced, and "dlgdefs.h" is included
  66. * at the bottom of this file using JAPAN flag. by Hiraisi
  67. */
  68. /* These defines replace dlgdefs.h to combat compiler heap overflows */
  69. #define idiYes IDOK
  70. #define idiNo 3
  71. #define idiCancel IDCANCEL
  72. #endif //JAPAN
  73. /* These defines replace heapdefs.h and heapdata.h for the same
  74. irritating reason */
  75. #define cwSaveAlloc (128)
  76. #define cwHeapMinPerWindow (50)
  77. #define cwHeapSpaceMin (60)
  78. /* E X T E R N A L S */
  79. extern CHAR (**vhrgbSave)[];
  80. extern HANDLE hParentWw;
  81. extern HANDLE hMmwModInstance;
  82. extern struct WWD rgwwd[];
  83. extern int wwMac;
  84. extern struct FCB (**hpfnfcb)[];
  85. extern struct DOD (**hpdocdod)[];
  86. extern int docMac;
  87. extern struct WWD *pwwdCur;
  88. extern int fnMac;
  89. extern CHAR stBuf[];
  90. /* *** Following declarations used by ValidateHeaderFooter */
  91. /* Min, Max cp's for header, footer */
  92. extern typeCP cpMinHeader;
  93. extern typeCP cpMacHeader;
  94. extern typeCP cpMinFooter;
  95. extern typeCP cpMacFooter;
  96. extern typeCP cpMinDocument;
  97. extern typeCP vcpLimParaCache;
  98. extern struct PAP vpapAbs;
  99. /* Current allowable cp range for display/edit/scroll */
  100. extern typeCP cpMinCur;
  101. extern typeCP cpMacCur;
  102. /* cpFirst and selection are saved in these during header/footer edit */
  103. extern typeCP cpFirstDocSave;
  104. extern struct SEL selDocSave;
  105. short WCompSzC();
  106. CHAR (**HszCreate())[];
  107. struct FNTB **HfntbCreate();
  108. #ifdef CASHMERE
  109. struct SETB **HsetbCreate();
  110. #else
  111. struct SEP **HsepCreate();
  112. #endif
  113. struct PGTB **HpgtbCreate();
  114. CHAR *PchFromFc( int, typeFC, CHAR * );
  115. CHAR *PchGetPn( int, typePN, int *, int );
  116. typeFC FcMacFromUnformattedFn( int );
  117. int CchReadAtPage( int, typePN, CHAR *, int, int );
  118. /* W W N E W */
  119. /* allocates and initializes a new wwd structure at wwMac.
  120. ypMin, ypMax are estimates of the height of window used to allocate dl's.
  121. wwMac++ is returned.
  122. Errors: message is made and wwNil is returned.
  123. remains to be initialized: xp, yp. Many fields must be reset if lower pane.
  124. */
  125. WwNew(doc, ypMin, ypMax)
  126. int doc, ypMin, ypMax;
  127. {
  128. extern CHAR szDocClass[];
  129. struct EDL (**hdndl)[];
  130. register struct WWD *pwwd = &rgwwd[wwMac];
  131. int dlMax = (ypMax - ypMin) / dypAveInit;
  132. int cwDndl = dlMax * cwEDL;
  133. #ifdef CASHMERE /* WwNew is only called once in MEMO */
  134. if (wwMac >= wwMax)
  135. {
  136. Error(IDPMT2ManyWws);
  137. return wwNil;
  138. }
  139. #endif
  140. bltc(pwwd, 0, cwWWDclr);
  141. if (!FChngSizeH( vhrgbSave,
  142. cwSaveAlloc + wwMac * cwHeapMinPerWindow, false ) ||
  143. FNoHeap( pwwd->hdndl = (struct EDL (**)[]) HAllocate( cwDndl )) )
  144. { /* Could not alloc addtl save space or dl array */
  145. return wwNil;
  146. }
  147. else
  148. bltc( *pwwd->hdndl, 0, cwDndl );
  149. #ifdef SPLITTERS
  150. pwwd->ww = wwNil;
  151. #endif /* SPLITTERS */
  152. /* contents of hdndl are init to 0 when allocated */
  153. pwwd->dlMac = pwwd->dlMax = dlMax;
  154. pwwd->ypMin = ypMin;
  155. pwwd->doc = doc;
  156. pwwd->wwptr = CreateWindow(
  157. (LPSTR)szDocClass,
  158. (LPSTR)"",
  159. (WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE),
  160. 0, 0, 0, 0,
  161. (HWND)hParentWw,
  162. (HMENU)NULL, /* use class menu */
  163. (HANDLE)hMmwModInstance, /* handle to window instance */
  164. (LPSTR)NULL); /* no params to pass on */
  165. if (pwwd->wwptr == NULL)
  166. return wwNil;
  167. /* inefficient
  168. pwwd->cpFirst = cp0;
  169. pwwd->ichCpFirst = 0;
  170. pwwd->dcpDepend = 0;
  171. pwwd->fCpBad = false;
  172. pwwd->xpMin = 0;
  173. pwwd->xpMac = 0;
  174. pwwd->ypMac = 0;
  175. pwwd->fFtn = false;
  176. pwwd->fSplit= false;
  177. pwwd->fLower = false;
  178. pwwd->cpMin = cp0;
  179. pwwd->drElevator = 0;
  180. pwwd->fRuler = false;
  181. pwwd->sel.CpFirst = cp0;
  182. pwwd->sel.CpFirst = cp0;
  183. */
  184. pwwd->sel.fForward = true;
  185. pwwd->fDirty = true;
  186. pwwd->fActive = true;
  187. pwwd->cpMac = CpMacText(doc);
  188. /* this is to compensate for the "min" in InvalBand */
  189. pwwd->ypFirstInval = ypMaxAll;
  190. #ifdef JAPAN /*May 26,92 t-Yosho*/
  191. {
  192. HDC hdc;
  193. hdc = GetDC(pwwd->wwptr);
  194. SelectObject(hdc,GetStocKObject(ANSI_VAR_FONT));
  195. ReleaseDC(pwwd->wwptr,hdc);
  196. }
  197. #endif
  198. #ifdef KOREA /* for level 3, 90.12.12 by Sangl */
  199. { HANDLE hKs;
  200. LPIMESTRUCT lpKs;
  201. hKs = GlobalAlloc (GMEM_MOVEABLE|GMEM_DDESHARE,(LONG)sizeof(IMESTRUCT));
  202. lpKs = (LPIMESTRUCT)GlobalLock(hKs);
  203. lpKs->fnc = IME_SETLEVEL;
  204. lpKs->wParam = 3;
  205. GlobalUnlock(hKs);
  206. SendIMEMessage (pwwd->wwptr, MAKELONG(hKs,0));
  207. GlobalFree(hKs);
  208. }
  209. #endif
  210. return wwMac++;
  211. } /* end of W w N e w */
  212. ChangeWwDoc( szDoc )
  213. CHAR szDoc[];
  214. { /* Set up wwd fields for a new document to be held in wwdCurrentDoc.
  215. docCur is used as the document */
  216. extern HANDLE hParentWw;
  217. extern int docCur;
  218. extern struct SEL selCur;
  219. extern typeCP cpMinDocument;
  220. extern int vfInsEnd;
  221. extern int vfPrPages;
  222. extern int vfDidSearch;
  223. extern typeCP cpWall;
  224. register struct WWD *pwwd = &rgwwd[wwDocument];
  225. pwwd->fDirty = true;
  226. ValidateHeaderFooter( docCur );
  227. pwwd->doc = docCur;
  228. pwwd->drElevator = 0;
  229. pwwd->ichCpFirst = 0;
  230. pwwd->dcpDepend = 0;
  231. pwwd->cpMin = pwwd->cpFirst = selCur.cpLim = selCur.cpFirst = cpMinDocument;
  232. selCur.fForward = TRUE;
  233. selCur.fEndOfLine = vfInsEnd = FALSE;
  234. pwwd->cpMac = CpMacText(docCur);
  235. TrashWw( wwDocument );
  236. SetScrollPos( pwwd->hVScrBar, pwwd->sbVbar,
  237. pwwd->drElevator = 0, TRUE);
  238. SetScrollPos( pwwd->hHScrBar, pwwd->sbHbar,
  239. pwwd->xpMin = 0, TRUE);
  240. NewCurWw(0, true);
  241. TrashCache(); /* Invalidate Scrolling cache */
  242. vfPrPages = FALSE;
  243. if (pwwd->fRuler)
  244. {
  245. ResetTabBtn();
  246. }
  247. SetTitle(szDoc);
  248. /* Since we are changing document, ensure that we don't use parameters
  249. set by a search in a previous window by setting flag false */
  250. vfDidSearch = FALSE;
  251. cpWall = selCur.cpLim;
  252. }
  253. /* F N C R E A T E S Z */
  254. int FnCreateSz(szT, cpMac, dty )
  255. CHAR *szT;
  256. typeCP cpMac;
  257. int dty;
  258. { /* Create & Open a new file of the specified type. */
  259. /* If cpMac != cpNil, write an FIB to the file */
  260. /* if dty==dtyNetwork, generate a unique name in the current
  261. directory and copy it to szT */
  262. /* WARNING: dty != dtyNetwork SUPPORT HAS BEEN REMOVED */
  263. int fn;
  264. struct FCB *pfcb; /* Be VERY careful of heap movement when using pfcb */
  265. struct FIB fib;
  266. CHAR (**hsz)[];
  267. CHAR sz[cchMaxFile];
  268. bltsz(szT, sz);
  269. sz[cchMaxFile - 1] = 0;
  270. if ((fn = FnAlloc()) == fnNil)
  271. return fnNil;
  272. pfcb = &(**hpfnfcb)[fn];
  273. pfcb->mdExt = pfcb->dty = dtyNormal;
  274. pfcb->mdFile = mdBinary;
  275. Assert( dty == dtyNetwork );
  276. if (!FCreateFile( sz, fn )) /* Sets pfcb->hszFile, pfcb->rfn */
  277. return fnNil;
  278. FreezeHp();
  279. pfcb = &(**hpfnfcb)[fn];
  280. /* Copy unique filename to parm */
  281. bltsz( **pfcb->hszFile, szT );
  282. #ifdef INEFFICIENT
  283. pfcb->fcMac = fc0;
  284. pfcb->pnMac = pn0;
  285. #endif
  286. if (cpMac == cpNil)
  287. { /* Unformatted file */
  288. #ifdef INEFFICIENT
  289. pfcb->fFormatted = false;
  290. #endif
  291. MeltHp();
  292. }
  293. else
  294. { /* Formatted file; write FIB */
  295. bltbc(&fib, 0, cchFIB);
  296. pfcb->fFormatted = true;
  297. #ifdef INEFFICIENT
  298. pfcb->pnChar = pfcb->pnPara = pfcb->pnFntb =
  299. pfcb->pnSep = pfcb->pnSetb = pfcb->pnBftb = pn0;
  300. #endif
  301. MeltHp();
  302. fib.wIdent = wMagic;
  303. fib.dty = dtyNormal;
  304. fib.wTool = wMagicTool;
  305. fib.fcMac = cpMac + cfcPage;
  306. WriteRgch(fn, &fib, (int)cfcPage);
  307. }
  308. return fn;
  309. } /* end of F n C r e a t e S z */
  310. int DocCreate(fn, hszFile, dty)
  311. int fn, dty;
  312. CHAR (**hszFile)[];
  313. { /* Create a document */
  314. extern int vfTextOnlySave;
  315. struct FNTB **HfntbCreate();
  316. struct TBD (**HgtbdCreate())[];
  317. int doc;
  318. int fFormatted, fOldWord;
  319. struct DOD *pdod;
  320. struct SEP **hsep = (struct SEP **)0; /* MEMO only; for CASHMERE, use hsetb */
  321. struct PGTB **hpgtb=(struct PGTB **)0;
  322. struct FFNTB **hffntb=(struct FFNTB **)0;
  323. struct TBD (**hgtbd)[]=(struct TBD (**)[])0;
  324. struct FNTB **hfntb = (struct FNTB **) 0;
  325. CHAR (**hszSsht)[];
  326. fFormatted = (fn == fnNil) || (**hpfnfcb)[fn].fFormatted;
  327. fOldWord = FALSE;
  328. if ((doc = DocAlloc()) == docNil || /* HEAP MOVEMENT */
  329. !FInitPctb(doc, fn)) /* HEAP MOVEMENT */
  330. return docNil;
  331. pdod = &(**hpdocdod)[doc];
  332. pdod->fReadOnly = (fn != fnNil) && ((**hpfnfcb)[fn].mdFile == mdBinRO);
  333. pdod->cref = 1;
  334. pdod->fFormatted = fFormatted;
  335. pdod->dty = dty;
  336. pdod->fBackup = false; /* Default: don't automatically make backup */
  337. pdod->fDisplayable = TRUE;
  338. switch(dty)
  339. { /* HEAP MOVEMENT */
  340. case dtyHlp:
  341. if (FNoHeap(hpgtb = HpgtbCreate(fn)))
  342. goto ErrFree;
  343. if (FNoHeap(hffntb = HffntbCreateForFn(fn, &fOldWord)))
  344. goto ErrFree;
  345. break;
  346. case dtyNormal:
  347. if (fn != fnNil && fFormatted)
  348. {
  349. #ifdef FOOTNOTES
  350. if (FNoHeap(hfntb = HfntbCreate(fn)))
  351. goto ErrFree;
  352. #endif
  353. if (FNoHeap(hsep = HsepCreate(fn)))
  354. goto ErrFree;
  355. if (FNoHeap(hpgtb = HpgtbCreate(fn)))
  356. goto ErrFree;
  357. if (FNoHeap(hgtbd = HgtbdCreate(fn)))
  358. goto ErrFree;
  359. }
  360. if (FNoHeap(hffntb = HffntbCreateForFn(fn, &fOldWord)))
  361. goto ErrFree;
  362. #ifdef JAPAN // added 10 Jun. 1992 by Hiraisi
  363. {
  364. int fnCheckFacename(CHAR *, struct FFNTB **);
  365. int fontChg; // This specifies whether facenames are changed or not.
  366. if( fn != fnNil && fFormatted ){
  367. fontChg = fnCheckFacename( *hszFile[0], hffntb );
  368. if( fontChg == docNil ){ // Changing facenames was cancelled.
  369. goto ErrFree;
  370. }
  371. else{
  372. if( fontChg == TRUE ){ // Facenames were changed.
  373. /* Flag wheter doc has been edited. 30 Jul. */
  374. (**hpdocdod)[doc].fDirty = TRUE;
  375. }
  376. }
  377. }
  378. }
  379. #endif //JAPAN
  380. break;
  381. case dtySsht:
  382. goto DtyCommon;
  383. case dtyBuffer:
  384. if (fn != fnNil)
  385. {
  386. #ifdef FOOTNOTES
  387. if (FNoHeap(hfntb = HfntbCreate(fn)))
  388. goto ErrFree;
  389. #endif
  390. if (FNoHeap(hsep = HsepCreate(fn)))
  391. goto ErrFree;
  392. if (FNoHeap(hgtbd = HgtbdCreate(fn)))
  393. goto ErrFree;
  394. }
  395. DtyCommon:
  396. hpgtb = 0;
  397. }
  398. pdod = &(**hpdocdod)[doc];
  399. pdod->hszFile = hszFile;
  400. pdod->docSsht = docNil;
  401. pdod->hfntb = hfntb;
  402. pdod->hsep = hsep;
  403. pdod->hpgtb = hpgtb;
  404. pdod->hffntb = hffntb;
  405. pdod->hgtbd = hgtbd;
  406. if (fOldWord)
  407. if (!FApplyOldWordSprm(doc))
  408. goto ErrFree;
  409. ApplyRHMarginSprm( doc );
  410. vfTextOnlySave = !fFormatted;
  411. return doc;
  412. ErrFree:
  413. FreeH( hsep );
  414. FreeFfntb( hffntb );
  415. FreeH(hgtbd);
  416. FreeH(hpgtb);
  417. #ifdef FOOTNOTES
  418. FreeH(hfntb);
  419. #endif
  420. FreeH((**hpdocdod)[doc].hpctb);
  421. (**hpdocdod)[doc].hpctb = 0;
  422. return docNil;
  423. } /* end of D o c C r e a t e */
  424. ApplyRHMarginSprm( doc )
  425. int doc;
  426. { /* Apply a sprm to adjust paper-relative running head indents to
  427. be margin-relative */
  428. extern typeCP cpMinDocument;
  429. extern struct SEP vsepNormal;
  430. ValidateHeaderFooter( doc );
  431. if (cpMinDocument != cp0)
  432. { /* Doc has running head/foot, apply sprm */
  433. CHAR rgb[ 2 + (2 * sizeof( int )) ];
  434. struct SEP **hsep = (**hpdocdod) [doc].hsep;
  435. struct SEP *psep = (hsep == NULL) ? &vsepNormal : *hsep;
  436. rgb[0] = sprmPRhcNorm;
  437. rgb[1] = 4;
  438. *((int *) (&rgb[2])) = psep->xaLeft;
  439. *((int *) (&rgb[2 + sizeof(int)])) = psep->xaMac -
  440. (psep->xaLeft + psep->dxaText);
  441. AddSprmCps( rgb, doc, cp0, cpMinDocument );
  442. }
  443. }
  444. int DocAlloc()
  445. {
  446. int doc;
  447. struct DOD *pdod = &(**hpdocdod)[0];
  448. struct DOD *pdodMac = pdod + docMac;
  449. for (doc = 0; pdod < pdodMac; ++pdod, ++doc)
  450. if (pdod->hpctb == 0)
  451. return doc;
  452. if (!FChngSizeH((int **)hpdocdod, cwDOD * ++docMac, false))
  453. {
  454. --docMac;
  455. return docNil;
  456. }
  457. return docMac - 1;
  458. } /* end of D o c A l l o c */
  459. FInitPctb(doc, fn)
  460. int doc, fn;
  461. { /* Initialize the piece table for a doc, given its initial fn */
  462. struct PCTB **hpctb;
  463. struct DOD *pdod;
  464. struct PCTB *ppctb;
  465. struct PCD *ppcd;
  466. typeFC dfc;
  467. typeCP cpMac;
  468. hpctb = (struct PCTB **)HAllocate(cwPCTBInit); /* HM */
  469. if (FNoHeap(hpctb))
  470. return false;
  471. pdod = &(**hpdocdod)[doc];
  472. ppctb = *(pdod->hpctb = hpctb); /* Beware hp mvmt above */
  473. ppcd = ppctb->rgpcd;
  474. dfc = (fn != fnNil && (**hpfnfcb)[fn].fFormatted ? cfcPage : fc0);
  475. cpMac = (fn == fnNil ? cp0 : (**hpfnfcb)[fn].fcMac - dfc);
  476. ppctb->ipcdMax = cpcdInit;
  477. ppctb->ipcdMac = (cpMac == cp0 ) ? 1 : 2; /* One real piece and one end piece */
  478. ppcd->cpMin = cp0;
  479. if ((pdod->cpMac = cpMac) != cp0)
  480. {
  481. ppcd->fn = fn;
  482. ppcd->fc = dfc;
  483. SETPRMNIL(ppcd->prm);
  484. ppcd->fNoParaLast = false;
  485. (++ppcd)->cpMin = cpMac;
  486. }
  487. ppcd->fn = fnNil;
  488. SETPRMNIL(ppcd->prm);
  489. ppcd->fNoParaLast = true;
  490. pdod->fDirty = false;
  491. return true;
  492. } /* end of F I n i t P c t b */
  493. int FnAlloc()
  494. { /* Allocate an fn number */
  495. int fn;
  496. struct FCB *pfcb;
  497. for (fn = 0 ; fn < fnMac ; fn++)
  498. if ((**hpfnfcb)[fn].rfn == rfnFree)
  499. goto DoAlloc;
  500. if (!FChngSizeH(hpfnfcb, (fnMac + 1) * cwFCB, false))
  501. return fnNil;
  502. fn = fnMac++;
  503. DoAlloc:
  504. bltc(pfcb = &(**hpfnfcb)[fn], 0, cwFCB);
  505. pfcb->rfn = rfnFree;
  506. return fn;
  507. } /* end of F n A l l o c */
  508. fnNewFile()
  509. { /* Open a new, fresh, untitled document in our MEMO window */
  510. /* Offer confirmation if the current doc is dirty & permit save */
  511. extern HANDLE hMmwModInstance;
  512. extern HANDLE hParentWw;
  513. extern int docCur;
  514. extern struct SEL selCur;
  515. extern typeCP cpMinDocument;
  516. extern int vfTextOnlySave, vfBackupSave;
  517. extern CHAR szUntitled[];
  518. if (FConfirmSave()) /* Allow the user to save if docCur is dirty */
  519. {
  520. #if defined(OLE)
  521. if (ObjClosingDoc(docCur,szUntitled))
  522. return;
  523. #endif
  524. KillDoc( docCur );
  525. docCur = DocCreate( fnNil, HszCreate( "" ), dtyNormal );
  526. Assert( docCur != docNil );
  527. ChangeWwDoc( "" );
  528. #if defined(OLE)
  529. ObjOpenedDoc(docCur); // very unlikely to fail, not fatal if it does
  530. #endif
  531. #ifdef WIN30
  532. FreeUnreferencedFns();
  533. #endif
  534. }
  535. } /* end of f n N e w F i l e */
  536. struct FFNTB **HffntbCreateForFn(fn, pfOldWord)
  537. /* returns heap copy of ffntb (font names) for fn */
  538. int fn, *pfOldWord;
  539. {
  540. struct FFNTB **hffntb;
  541. typePN pn;
  542. struct FCB *pfcb;
  543. typePN pnMac;
  544. #ifdef NEWFONTENUM
  545. BOOL fCloseAfterward;
  546. #endif
  547. if (FNoHeap(hffntb = HffntbAlloc()))
  548. return(hffntb);
  549. pfcb = &(**hpfnfcb)[fn];
  550. pn = pfcb->pnFfntb;
  551. if (fn == fnNil || !pfcb->fFormatted)
  552. {
  553. #if WINVER >= 0x300
  554. /* WINBUG 8992: Clean up so don't lose alloc'd memory! ..pault 2/12/90 */
  555. FreeFfntb(hffntb);
  556. #endif
  557. hffntb = HffntbNewDoc(FALSE);
  558. }
  559. else if (pn != (pnMac=pfcb->pnMac))
  560. { /* "normal" memo file - has a font table */
  561. CHAR *pch;
  562. int cch;
  563. int iffn;
  564. int iffnMac;
  565. /* Read the first page:
  566. bytes 0..1 iffnMac
  567. 0..n sections of:
  568. bytes 0..1 cbFfn
  569. bytes 2..cbFfn+2 Ffn
  570. bytes x..x+1 0xFFFF (end of page)
  571. OR bytes x..x+1 0x0000 (end of font table) */
  572. pch = PchGetPn( fn, pn, &cch, FALSE );
  573. if (cch != cbSector)
  574. goto Error;
  575. iffnMac = *( (int *) pch);
  576. pch += sizeof (int);
  577. #ifdef NEWFONTENUM
  578. /* Since we now support multiple charsets, but write 2 and write 1
  579. documents did not save these in their ffntb's, we have to do an
  580. extra step now in order to "infer" the proper charset values. We
  581. enumerate all the possible fonts, and then as we read in each new
  582. document font we try to match it up with what the system knows
  583. about ..pault 10/18/89 */
  584. fCloseAfterward = FInitFontEnum(docNil, 32767, FALSE);
  585. #endif
  586. for ( iffn = 0; ; )
  587. {
  588. /* Add ffn entries from one disk page to the font table */
  589. while ( TRUE )
  590. {
  591. int cb = *((int *) pch);
  592. if (cb == 0)
  593. goto LRet; /* Reached end of table */
  594. else if (cb == -1)
  595. break; /* Reached end of disk page */
  596. else
  597. {
  598. #ifdef NEWFONTENUM
  599. /* Having added the chs field to the (RAM) FFN structure,
  600. we now have trouble reading FFN's from the document
  601. directly. And because Write was designed very early
  602. without regard to variable charsets, we can't store
  603. the charset value along with the fontname, so we have
  604. to infer it! ..pault */
  605. CHAR rgbFfn[ibFfnMax];
  606. struct FFN *pffn = (struct FFN *)rgbFfn;
  607. pch += sizeof(int);
  608. bltsz(pch + sizeof(BYTE), pffn->szFfn);
  609. pffn->ffid = *((FFID *) pch);
  610. pffn->chs = ChsInferred(pffn);
  611. if (FtcAddFfn(hffntb, pffn) == ftcNil)
  612. #else
  613. if (FtcAddFfn( hffntb, pch += sizeof(int) ) == ftcNil)
  614. #endif
  615. {
  616. Error:
  617. #ifdef NEWFONTENUM
  618. if (fCloseAfterward)
  619. EndFontEnum();
  620. #endif
  621. FreeFfntb( hffntb );
  622. return (struct FFNTB **) hOverflow;
  623. }
  624. iffn++;
  625. if (iffn >= iffnMac)
  626. /* Reached last item in table, by count */
  627. /* This is so we can read old WRITE files, */
  628. /* in which the table was not terminated by 0 */
  629. goto LRet;
  630. pch += cb;
  631. }
  632. } /* end while */
  633. /* Read the next page from the file. Page format is like the first
  634. ffntb page (see above) but without the iffnMac */
  635. if (++pn >= pnMac)
  636. break;
  637. pch = PchGetPn( fn, pn, &cch, FALSE );
  638. if (cch != cbSector)
  639. goto Error;
  640. } /* end for */
  641. }
  642. else
  643. {
  644. /* word file - create a simple font table that we can map word's
  645. fonts onto */
  646. /* temporarily we map them all onto one font - soon we'll have a set */
  647. #if WINVER >= 0x300
  648. /* WINBUG 8992: Clean up so don't lose alloc'd memory! ..pault 2/12/90 */
  649. FreeFfntb(hffntb);
  650. #endif
  651. hffntb = HffntbNewDoc(TRUE);
  652. *pfOldWord = TRUE;
  653. }
  654. LRet:
  655. #ifdef NEWFONTENUM
  656. if (fCloseAfterward)
  657. EndFontEnum();
  658. #endif
  659. return(hffntb);
  660. }
  661. struct FFNTB **HffntbNewDoc(fFullSet)
  662. /* creates a font table with the default font for this doc */
  663. int fFullSet;
  664. {
  665. struct FFNTB **hffntb;
  666. hffntb = HffntbAlloc();
  667. if (FNoHeap(hffntb))
  668. return(hffntb);
  669. /* make sure we at least have a "standard" font */
  670. #ifdef KOREA /* ROMAN as family of standard font(myoungjo). sangl 91.4.17 */
  671. if (!FEnsurePffn(hffntb, PffnDefault(FF_ROMAN)))
  672. #else
  673. if (!FEnsurePffn(hffntb, PffnDefault(FF_DONTCARE)))
  674. #endif
  675. {
  676. goto BadAdd;
  677. }
  678. if (fFullSet)
  679. /* we need a full set of fonts for word ftc mapping */
  680. if (!FEnsurePffn(hffntb, PffnDefault(FF_MODERN)) ||
  681. #ifdef KOREA
  682. !FEnsurePffn(hffntb, PffnDefault(FF_DONTCARE)) ||
  683. #else
  684. !FEnsurePffn(hffntb, PffnDefault(FF_ROMAN)) ||
  685. #endif
  686. !FEnsurePffn(hffntb, PffnDefault(FF_SWISS)) ||
  687. !FEnsurePffn(hffntb, PffnDefault(FF_SCRIPT)) ||
  688. !FEnsurePffn(hffntb, PffnDefault(FF_DECORATIVE)))
  689. BadAdd:
  690. {
  691. FreeFfntb(hffntb);
  692. hffntb = (struct FFNTB **)hOverflow;
  693. }
  694. return(hffntb);
  695. }
  696. CHAR * PchBaseNameInUpper(szName)
  697. CHAR *szName;
  698. {
  699. CHAR * pchStart = szName;
  700. #ifdef DBCS
  701. CHAR * pchEnd = AnsiPrev( pchStart, pchStart + CchSz(szName) );
  702. #else
  703. CHAR * pchEnd = pchStart + CchSz(szName) - 1;
  704. #endif
  705. while (pchEnd >= pchStart)
  706. {
  707. #ifdef DBCS
  708. if (*pchEnd == '\\' || *pchEnd == ':') {
  709. // T-HIROYN 1992.07.31 bug fix
  710. pchEnd++;
  711. break;
  712. }
  713. else if (!IsDBCSLeadByte(*pchEnd))
  714. *pchEnd = ChUpper(*pchEnd);
  715. {
  716. LPSTR lpstr = AnsiPrev( pchStart, pchEnd );
  717. if( pchEnd == lpstr )
  718. break;
  719. pchEnd = lpstr;
  720. }
  721. #else
  722. if (*pchEnd == '\\' || *pchEnd == ':')
  723. break;
  724. else
  725. *pchEnd = ChUpper(*pchEnd);
  726. pchEnd--;
  727. #endif
  728. }
  729. #ifdef DBCS
  730. return(AnsiUpper(pchEnd));
  731. #else
  732. return(pchEnd+1);
  733. #endif
  734. }
  735. SetTitle(szSource)
  736. CHAR *szSource;
  737. {
  738. extern CHAR szUntitled[];
  739. extern int vfIconic;
  740. extern CHAR szAppName[];
  741. extern CHAR szSepName[];
  742. CHAR *pch = stBuf;
  743. CHAR szDocName[cchMaxFile];
  744. pch += CchCopySz((PCH)szAppName, stBuf);
  745. pch += CchCopySz((PCH)szSepName, pch);
  746. if (szSource[0] == '\0')
  747. {
  748. CchCopySz( szUntitled, pch );
  749. }
  750. else
  751. { /* get the pointer to the base file name and convert to upper case */
  752. CchCopySz(szSource, szDocName);
  753. CchCopySz(PchBaseNameInUpper(szDocName), pch);
  754. }
  755. SetWindowText(hParentWw, (LPSTR)stBuf);
  756. }
  757. ValidateHeaderFooter( doc )
  758. { /* Look for a MEMO-style running header and/or footer in the document.
  759. We scan from the beginning of the document, taking the first
  760. contiguous sequence of running head paragraphs as the running
  761. head region, and the first contiguous sequence of running foot
  762. paragraphs as the running foot region. We break the process
  763. at the first non-running paragraph or when we have both runs
  764. Update values of cpMinDocument, cpMinFooter, cpMacFooter,
  765. cpMinHeader, cpMacHeader.
  766. These ranges INCLUDE the EOL (and Return, if CRLF) at the end of the
  767. header/footer
  768. If we are currently editing a header or footer in the passed doc,
  769. adjust the values of cpFirstDocSave, selDocSave to reflect the
  770. change */
  771. extern int docScrap;
  772. extern typeCP vcpFirstParaCache;
  773. extern typeCP vcpLimParaCache;
  774. #define fGot 0
  775. #define fGetting 1
  776. #define fNotGot 2
  777. int fGotHeader=fNotGot;
  778. int fGotFooter=fNotGot;
  779. typeCP cpMinDocT=cpMinDocument;
  780. typeCP cpMinCurT = cpMinCur;
  781. typeCP cpMacCurT = cpMacCur;
  782. typeCP cp;
  783. if (doc == docNil || doc == docScrap)
  784. return;
  785. /* Want access to the entire doc cp range for this operation */
  786. cpMinCur = cp0;
  787. cpMacCur = (**hpdocdod) [doc].cpMac;
  788. cpMinDocument = cpMinFooter = cpMacFooter = cpMinHeader = cpMacHeader = cp0;
  789. for ( cp = cp0;
  790. (cp < cpMacCur) && (CachePara( doc, cp ), vpapAbs.rhc);
  791. cp = vcpLimParaCache )
  792. {
  793. int fBottom=vpapAbs.rhc & RHC_fBottom;
  794. if (fBottom)
  795. {
  796. if (fGotHeader == fGetting)
  797. fGotHeader = fGot;
  798. switch (fGotFooter) {
  799. case fGot:
  800. /* Already have footer from earlier footer run */
  801. return;
  802. case fNotGot:
  803. cpMinFooter = vcpFirstParaCache;
  804. fGotFooter = fGetting;
  805. /* FALL THROUGH */
  806. case fGetting:
  807. cpMacFooter = cpMinDocument = vcpLimParaCache;
  808. break;
  809. }
  810. }
  811. else
  812. {
  813. if (fGotFooter == fGetting)
  814. fGotFooter = fGot;
  815. switch (fGotHeader) {
  816. case fGot:
  817. /* Already have header from earlier header run */
  818. return;
  819. case fNotGot:
  820. cpMinHeader = vcpFirstParaCache;
  821. fGotHeader = fGetting;
  822. /* FALL THROUGH */
  823. case fGetting:
  824. cpMacHeader = cpMinDocument = vcpLimParaCache;
  825. break;
  826. }
  827. }
  828. } /* end of for loop through paras */
  829. /* Restore saved cpMacCur, cpMinCur */
  830. cpMinCur = cpMinCurT;
  831. cpMacCur = cpMacCurT;
  832. /* Adjust saved cp's that refer to the document to reflect
  833. header/footer changes */
  834. if ((wwdCurrentDoc.fEditHeader || wwdCurrentDoc.fEditFooter) &&
  835. wwdCurrentDoc.doc == doc )
  836. {
  837. typeCP dcpAdjust=cpMinDocument - cpMinDocT;
  838. if (dcpAdjust != (typeCP) 0)
  839. {
  840. selDocSave.cpFirst += dcpAdjust;
  841. selDocSave.cpLim += dcpAdjust;
  842. cpFirstDocSave += dcpAdjust;
  843. }
  844. }
  845. }
  846. #ifdef JAPAN // added 10 Jun. 1992 by Hiraisi
  847. #include "dlgdefs.h"
  848. BOOL FAR PASCAL _export DialogCvtFont( HWND, UINT, WPARAM, LPARAM );
  849. BOOL FAR PASCAL _export DialogCvtFont( hDlg, uMsg, wParam, lParam )
  850. HWND hDlg;
  851. UINT uMsg;
  852. WPARAM wParam;
  853. LPARAM lParam;
  854. {
  855. switch (uMsg){
  856. case WM_INITDIALOG:
  857. {
  858. char szPrompt[cchMaxSz];
  859. CHAR *pch = stBuf;
  860. if( *pch == '\\' )
  861. pch++;
  862. MergeStrings(IDPMTFontChange, pch, szPrompt);
  863. SetDlgItemText(hDlg, idiChangeFont, (LPSTR)szPrompt);
  864. }
  865. break;
  866. case WM_COMMAND:
  867. switch (wParam){
  868. case IDOK:
  869. EndDialog(hDlg, FALSE);
  870. break;
  871. case IDCANCEL:
  872. EndDialog(hDlg, TRUE);
  873. break;
  874. default:
  875. return(FALSE);
  876. }
  877. break;
  878. default:
  879. return(FALSE);
  880. }
  881. return(TRUE);
  882. }
  883. /*
  884. * This function checks facenames and removes '@' from "@facename"(s)
  885. * if facenames with '@' are found in doc of WRITE.
  886. * Return : TRUE=deleted ,FALSE=not found ,docNil(-1)=cancelled
  887. */
  888. int fnCheckFacename( sz, hffntb )
  889. CHAR *sz;
  890. struct FFNTB **hffntb;
  891. {
  892. struct FFNTB *pffntb;
  893. struct FFN *pffn;
  894. int ix, len;
  895. BOOL bChange, bRet;
  896. CHAR *szFfn;
  897. CHAR *pch = stBuf;
  898. FARPROC lpDialogCvtFont;
  899. pffntb = *hffntb;
  900. bChange = FALSE;
  901. for( ix = 0; ix < pffntb->iffnMac; ix++ ){
  902. pffn = *pffntb->mpftchffn[ix];
  903. szFfn = pffn->szFfn;
  904. if( *szFfn == '@' ){
  905. if( !bChange ){
  906. lpDialogCvtFont = MakeProcInstance(DialogCvtFont,
  907. hMmwModInstance);
  908. CchCopySz(PchBaseNameInUpper(sz), pch);
  909. bRet = DialogBox( hMmwModInstance,
  910. MAKEINTRESOURCE(dlgChangeFont),
  911. hParentWw, lpDialogCvtFont);
  912. FreeProcInstance(lpDialogCvtFont);
  913. if( bRet )
  914. return(docNil);
  915. bChange = TRUE;
  916. }
  917. len = CchCopySz( szFfn+1, pffn->szFfn);
  918. *(pffn->szFfn+len) = '\0';
  919. }
  920. }
  921. return(bChange);
  922. }
  923. #endif