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.

690 lines
18 KiB

  1. #include "lsidefs.h"
  2. #include "autonum.h"
  3. #include "lscbk.h"
  4. #include <limits.h>
  5. #include "lsmem.h" /* memset() */
  6. #include "lsesc.h"
  7. #include "fmti.h"
  8. #include "objdim.h"
  9. #include "lscrsubl.h"
  10. #include "lssubset.h"
  11. #include "lsdnfin.h"
  12. #include "lsdssubl.h"
  13. #include "dispi.h"
  14. #include "lsdnode.h"
  15. #include "tabutils.h"
  16. #include "lscaltbd.h"
  17. #include "lstbcon.h"
  18. #include "lsdnset.h"
  19. #include "lsensubl.h"
  20. #include "dninfo.h"
  21. struct ilsobj
  22. {
  23. POLS pols;
  24. LSCBK lscbk;
  25. PLSC plsc;
  26. DWORD idObj;
  27. LSESC lsescautonum;
  28. };
  29. struct dobj
  30. {
  31. PILSOBJ pilsobj; /* ILS object */
  32. PLSSUBL plssubl; /* Handle to subline for autonumbering text */
  33. };
  34. #define ZeroMemory(a, b) memset(a, 0, b);
  35. /* M A X */
  36. /*----------------------------------------------------------------------------
  37. %%Macro: Max
  38. %%Contact: igorzv
  39. Returns the maximum of two values a and b.
  40. ----------------------------------------------------------------------------*/
  41. #define Max(a,b) ((a) < (b) ? (b) : (a))
  42. /* A U T O N U M C R E A T E I L S O B J */
  43. /*----------------------------------------------------------------------------
  44. %%Function: autonumCreateILSObj
  45. %%Contact: igorzv
  46. Parameters
  47. pols - (IN) client application context
  48. plsc - (IN) ls context
  49. pclscbk - (IN) callbacks to client application
  50. idObj - (IN) id of the object
  51. ppilsobj- (OUT)object ilsobj
  52. Create the ILS object for all autonumbering objects.
  53. ----------------------------------------------------------------------------*/
  54. LSERR WINAPI AutonumCreateILSObj(POLS pols, PLSC plsc,
  55. PCLSCBK pclscbk, DWORD idObj, PILSOBJ *ppilsobj)
  56. {
  57. PILSOBJ pilsobj;
  58. pilsobj = pclscbk->pfnNewPtr(pols, sizeof(*pilsobj));
  59. if (NULL == pilsobj)
  60. {
  61. return lserrOutOfMemory;
  62. }
  63. pilsobj->pols = pols;
  64. pilsobj->lscbk = *pclscbk;
  65. pilsobj->plsc = plsc;
  66. pilsobj->idObj = idObj;
  67. *ppilsobj = pilsobj;
  68. return lserrNone;
  69. }
  70. /* S E T A U T O N U M C O N F I G */
  71. /*----------------------------------------------------------------------------
  72. %%Function: SetAutonumConfig
  73. %%Contact: igorzv
  74. Parameters
  75. pilsobj - (IN) object ilsobj
  76. plstxtconfig - (IN) definition of special characters
  77. Set ecs character for autonumbering sequence
  78. ----------------------------------------------------------------------------*/
  79. LSERR SetAutonumConfig(PILSOBJ pilsobj, const LSTXTCFG* plstxtconfig)
  80. {
  81. pilsobj->lsescautonum.wchFirst = plstxtconfig->wchEscAnmRun;
  82. pilsobj->lsescautonum.wchLast = plstxtconfig->wchEscAnmRun;
  83. return lserrNone;
  84. }
  85. /* A U T O N U M D E S T R O Y I L S O B J */
  86. /*----------------------------------------------------------------------------
  87. %%Function: AutonumDestroyILSObj
  88. %%Contact: igorzv
  89. Parameters
  90. pilsobj - (IN) object ilsobj
  91. Free all resources assocaiated with autonum ILS object.
  92. ----------------------------------------------------------------------------*/
  93. LSERR WINAPI AutonumDestroyILSObj(PILSOBJ pilsobj)
  94. {
  95. pilsobj->lscbk.pfnDisposePtr(pilsobj->pols, pilsobj);
  96. return lserrNone;
  97. }
  98. /* A U T O N U M S E T D O C */
  99. /*----------------------------------------------------------------------------
  100. %%Function: AutonumSetDoc
  101. %%Contact: igorzv
  102. Parameters
  103. pilsobj - (IN) object ilsobj
  104. pclsdocinf - (IN) initialization data of the document level
  105. Empty function
  106. ----------------------------------------------------------------------------*/
  107. LSERR WINAPI AutonumSetDoc(PILSOBJ pilsobj, PCLSDOCINF pclsdocinf)
  108. {
  109. Unreferenced(pilsobj);
  110. Unreferenced(pclsdocinf);
  111. return lserrNone;
  112. }
  113. /* A U T O N U M C R E A T E L N O B J */
  114. /*----------------------------------------------------------------------------
  115. %%Function: AutonumCreateLNObj
  116. %%Contact: igorzv
  117. Parameters
  118. pilsobj - (IN) object ilsobj
  119. pplnobj - (OUT)object lnobj
  120. Create the Line Object for the autonum. No real need for a line
  121. object so don't allocated it.
  122. ----------------------------------------------------------------------------*/
  123. LSERR WINAPI AutonumCreateLNObj( PCILSOBJ pcilsobj, PLNOBJ *pplnobj)
  124. {
  125. *pplnobj = (PLNOBJ) pcilsobj;
  126. return lserrNone;
  127. }
  128. /* A U T O N U M D E S T R O Y L N O B J */
  129. /*----------------------------------------------------------------------------
  130. %%Function: AautonumDestroyLNObj
  131. %%Contact: igorzv
  132. Parameters
  133. pplnobj - (IN) object lnobj
  134. Frees resources associated with the autonum line object. Since
  135. there isn't any this is a no-op.
  136. ----------------------------------------------------------------------------*/
  137. LSERR WINAPI AutonumDestroyLNObj(PLNOBJ plnobj)
  138. {
  139. Unreferenced(plnobj);
  140. return lserrNone;
  141. }
  142. /* A U T O N U M F M T */
  143. /*----------------------------------------------------------------------------
  144. %%Function: AutonumFmt
  145. %%Contact: igorzv
  146. Parameters
  147. pplnobj - (IN) object lnobj
  148. pcfmtin - (IN) formatting input
  149. pfmtres - (OUT)formatting result
  150. Format the autonum object.
  151. ----------------------------------------------------------------------------*/
  152. LSERR WINAPI AutonumFmt(PLNOBJ plnobj, PCFMTIN pcfmtin, FMTRES *pfmtres)
  153. {
  154. PDOBJ pdobj;
  155. LSERR lserr;
  156. PILSOBJ pilsobj = (PILSOBJ) plnobj;
  157. LSCP cpStartMain = pcfmtin->lsfgi.cpFirst;
  158. LSCP cpOut;
  159. LSTFLOW lstflow = pcfmtin->lsfgi.lstflow;
  160. FMTRES fmtres;
  161. OBJDIM objdimAll;
  162. LSDCP dcp;
  163. PLSDNODE plsdnFirst;
  164. PLSDNODE plsdnLast;
  165. BOOL fSuccessful;
  166. /*
  167. * Allocate the DOBJ
  168. */
  169. pdobj = pilsobj->lscbk.pfnNewPtr(pilsobj->pols, sizeof(*pdobj));
  170. if (NULL == pdobj)
  171. {
  172. return lserrOutOfMemory;
  173. }
  174. ZeroMemory(pdobj, sizeof(*pdobj));
  175. pdobj->pilsobj = pilsobj;
  176. /*
  177. * Build main line of text
  178. */
  179. lserr = LsCreateSubline(pilsobj->plsc, cpStartMain, uLsInfiniteRM,
  180. lstflow, fFalse); /* because fContiguous is false
  181. all tabs will be skipped*/
  182. if (lserr != lserrNone)
  183. {
  184. AutonumDestroyDobj(pdobj);
  185. return lserr;
  186. }
  187. lserr = LsFetchAppendToCurrentSubline(pilsobj->plsc, 0, &(pilsobj->lsescautonum),
  188. 1, &fSuccessful, &fmtres, &cpOut, &plsdnFirst, &plsdnLast);
  189. /* because we formatting with uLsInfiniteRM margin result should be successful */
  190. if (lserr != lserrNone)
  191. {
  192. AutonumDestroyDobj(pdobj);
  193. return lserr;
  194. }
  195. if (fmtres != fmtrCompletedRun)
  196. {
  197. AutonumDestroyDobj(pdobj);
  198. return lserrInvalidAutonumRun;
  199. }
  200. lserr = LsFinishCurrentSubline(pilsobj->plsc, &(pdobj->plssubl));
  201. if (lserr != lserrNone)
  202. {
  203. AutonumDestroyDobj(pdobj);
  204. return lserr;
  205. }
  206. // submit subline for display
  207. lserr = LsdnSubmitSublines(pilsobj->plsc, pcfmtin->plsdnTop,
  208. 1, &(pdobj->plssubl),
  209. fFalse, fFalse, fTrue, fFalse, fFalse);
  210. if (lserr != lserrNone)
  211. {
  212. AutonumDestroyDobj(pdobj);
  213. return lserr;
  214. }
  215. /*
  216. * Calculate the object dimensions.
  217. */
  218. lserr = LssbGetObjDimSubline(pdobj->plssubl, &lstflow, &objdimAll);
  219. if (lserr != lserrNone)
  220. {
  221. AutonumDestroyDobj(pdobj);
  222. return lserr;
  223. }
  224. /* for multiline heights use ascent */
  225. objdimAll.heightsRef.dvMultiLineHeight = objdimAll.heightsRef.dvAscent;
  226. objdimAll.heightsPres.dvMultiLineHeight = objdimAll.heightsPres.dvAscent;
  227. dcp = cpOut - cpStartMain + 1; /* additional is esc character */
  228. lserr = LsdnFinishRegular(pilsobj->plsc, dcp,
  229. pcfmtin->lsfrun.plsrun, pcfmtin->lsfrun.plschp, pdobj,
  230. &objdimAll);
  231. if (lserr != lserrNone)
  232. {
  233. AutonumDestroyDobj(pdobj);
  234. return lserr;
  235. }
  236. *pfmtres = fmtrCompletedRun;
  237. return lserrNone;
  238. }
  239. /* A U T O N U M G E T S P E C I A L E F F E C T S I N S I D E */
  240. /*----------------------------------------------------------------------------
  241. %%Function: AutonumGetSpecialEffectsInside
  242. %%Contact: igorzv
  243. Parameters
  244. pdobj - (IN) structure describes object
  245. *pEffectsFlags - (OUT)Special effects for this object
  246. ----------------------------------------------------------------------------*/
  247. LSERR WINAPI AutonumGetSpecialEffectsInside(PDOBJ pdobj, UINT *pEffectsFlags)
  248. {
  249. return LsGetSpecialEffectsSubline(pdobj->plssubl, pEffectsFlags);
  250. }
  251. /* A U T O N U M C A L C P R E S E N T A T I O N */
  252. /*----------------------------------------------------------------------------
  253. %%Function: AutonumCalcPresentation
  254. %%Contact: igorzv
  255. Parameters
  256. pdobj - (IN) structure describes object
  257. dup - (IN) is not used
  258. lskj - (IN) current justification mode
  259. This just makes the line match the calculated presentation of the line.
  260. ----------------------------------------------------------------------------*/
  261. LSERR WINAPI AutonumCalcPresentation(PDOBJ pdobj, long dup, LSKJUST lskjust, BOOL fLastOnLine)
  262. {
  263. Unreferenced(dup);
  264. Unreferenced(lskjust);
  265. Unreferenced(fLastOnLine);
  266. return LsMatchPresSubline(pdobj->plssubl);
  267. }
  268. /* A U T O N U M Q U E R Y P O I N T P C P */
  269. /*----------------------------------------------------------------------------
  270. %%Function: AutonumQueryPointPcp
  271. %%Contact: igorzv
  272. Should never be called
  273. ----------------------------------------------------------------------------*/
  274. LSERR WINAPI AutonumQueryPointPcp(PDOBJ pdobj, PCPOINTUV ppointuvQuery,
  275. PCLSQIN plsqin, PLSQOUT plsqout)
  276. {
  277. Unreferenced(pdobj);
  278. Unreferenced(ppointuvQuery);
  279. Unreferenced(plsqin);
  280. Unreferenced(plsqout);
  281. NotReached();
  282. return lserrInvalidParameter;
  283. }
  284. /* A U T O N U M Q U E R Y C P P P O I N T */
  285. /*----------------------------------------------------------------------------
  286. %%Function: AutonumQueryCpPpoint
  287. %%Contact: igorzv
  288. Should never be called
  289. ----------------------------------------------------------------------------*/
  290. LSERR WINAPI AutonumQueryCpPpoint(PDOBJ pdobj, LSDCP dcp,
  291. PCLSQIN plsqin, PLSQOUT plsqout)
  292. {
  293. Unreferenced(pdobj);
  294. Unreferenced(dcp);
  295. Unreferenced(plsqin);
  296. Unreferenced(plsqout);
  297. NotReached();
  298. return lserrInvalidParameter;
  299. }
  300. /* A U T O N U M T R U N C A T E C H U N K */
  301. /*----------------------------------------------------------------------------
  302. %%Function: AutonumTruncateChunk
  303. %%Contact: igorzv
  304. Should never be called
  305. ----------------------------------------------------------------------------*/
  306. LSERR WINAPI AutonumTruncateChunk(PCLOCCHNK pclocchnk, PPOSICHNK pposichnk)
  307. {
  308. Unreferenced(pclocchnk);
  309. Unreferenced(pposichnk);
  310. NotReached();
  311. return lserrInvalidParameter;
  312. }
  313. /* A U T O N U M F I N D P R E V B R E A K C H U N K */
  314. /*----------------------------------------------------------------------------
  315. %%Function: AutonumFindPrevBreakChunk
  316. %%Contact: igorzv
  317. Should never be called
  318. ----------------------------------------------------------------------------*/
  319. LSERR WINAPI AutonumFindPrevBreakChunk(PCLOCCHNK pclocchnk, PCPOSICHNK pposichnk,
  320. BRKCOND brkcond, PBRKOUT pbrkout)
  321. {
  322. Unreferenced(pclocchnk);
  323. Unreferenced(pposichnk);
  324. Unreferenced(brkcond);
  325. Unreferenced(pbrkout);
  326. NotReached();
  327. return lserrInvalidParameter;
  328. }
  329. /* A U T O N U M F I N D N E X T B R E A K C H U N K */
  330. /*----------------------------------------------------------------------------
  331. %%Function: AutonumFindNextBreakChunk
  332. %%Contact: igorzv
  333. Should never be called
  334. ----------------------------------------------------------------------------*/
  335. LSERR WINAPI AutonumFindNextBreakChunk(PCLOCCHNK pclocchnk, PCPOSICHNK pposichnk,
  336. BRKCOND brkcond, PBRKOUT pbrkout)
  337. {
  338. Unreferenced(pclocchnk);
  339. Unreferenced(pposichnk);
  340. Unreferenced(brkcond);
  341. Unreferenced(pbrkout);
  342. NotReached();
  343. return lserrInvalidParameter;
  344. }
  345. /* A U T O N U M F O R C E B R E A K C H U N K */
  346. /*----------------------------------------------------------------------------
  347. %%Function: AutonumForceBreakChunk
  348. %%Contact: igorzv
  349. Should never be called
  350. ----------------------------------------------------------------------------*/
  351. LSERR WINAPI AutonumForceBreakChunk(PCLOCCHNK pclocchnk, PCPOSICHNK pposichnk,
  352. PBRKOUT pbrkout)
  353. {
  354. Unreferenced(pclocchnk);
  355. Unreferenced(pposichnk);
  356. Unreferenced(pbrkout);
  357. NotReached();
  358. return lserrInvalidParameter;
  359. }
  360. /* A U T O N U M S E T B R E A K */
  361. /*----------------------------------------------------------------------------
  362. %%Function: AutonumSetBreak
  363. %%Contact: igorzv
  364. Should never be called
  365. ----------------------------------------------------------------------------*/
  366. LSERR WINAPI AutonumSetBreak(PDOBJ pdobj, BRKKIND brkkind, DWORD nbreakrecord,
  367. BREAKREC* rgbreakrec, DWORD* pnactualbreakrecord)
  368. {
  369. Unreferenced(pdobj);
  370. Unreferenced(brkkind);
  371. Unreferenced(rgbreakrec);
  372. Unreferenced(nbreakrecord);
  373. Unreferenced(pnactualbreakrecord);
  374. NotReached();
  375. return lserrInvalidParameter;
  376. }
  377. /* A U T O N U M D I S P L A Y */
  378. /*----------------------------------------------------------------------------
  379. %%Function: AutonumDisplay
  380. %%Contact: igorzv
  381. Parameters
  382. pdobj - (IN) structure describes object
  383. pcdispin - (IN) info for display
  384. Displays subline
  385. ----------------------------------------------------------------------------*/
  386. LSERR WINAPI AutonumDisplay(PDOBJ pdobj, PCDISPIN pcdispin)
  387. {
  388. BOOL fDisplayed;
  389. LSERR lserr = LssbFDoneDisplay(pdobj->plssubl, &fDisplayed);
  390. if (lserr != lserrNone)
  391. {
  392. return lserr;
  393. }
  394. if (fDisplayed)
  395. {
  396. return lserrNone;
  397. }
  398. else
  399. {
  400. /* display the autonum line */
  401. return LsDisplaySubline(pdobj->plssubl, &(pcdispin->ptPen), pcdispin->kDispMode,
  402. pcdispin->prcClip);
  403. }
  404. }
  405. /* A U T O N U M D E S T R O Y D O B J */
  406. /*----------------------------------------------------------------------------
  407. %%Function: AutonumDestroyDobj
  408. %%Contact: igorzv
  409. Parameters
  410. pdobj - (IN) structure describes object
  411. Free all resources connected with the input dobj.
  412. ----------------------------------------------------------------------------*/
  413. LSERR WINAPI AutonumDestroyDobj(PDOBJ pdobj)
  414. {
  415. LSERR lserr = lserrNone;
  416. PILSOBJ pilsobj = pdobj->pilsobj;
  417. if (pdobj->plssubl != NULL)
  418. {
  419. lserr = LsDestroySubline(pdobj->plssubl);
  420. }
  421. pilsobj->lscbk.pfnDisposePtr(pilsobj->pols, pdobj);
  422. return lserr;
  423. }
  424. /* A L L I G N A U T O N U M 95 */
  425. /*----------------------------------------------------------------------------
  426. %%Function: AllignAutonum95
  427. %%Contact: igorzv
  428. Parameters
  429. durSpaceAnm - (IN) space after autonumber
  430. durWidthAnm - (IN) distance from indent to main text
  431. lskalignAnM - (IN) allignment for autonumber
  432. plsdnAnmAfter - (IN) tab dnode to put durAfter
  433. durUsed - (IN) width of autonumbering text
  434. pdurBefore - (OUT)calculated distance from indent to autonumber
  435. pdurAfter - (OUT)calculated distance from autonumber to main text
  436. Calculates space before and after autonumber for the case Word95 model.
  437. ----------------------------------------------------------------------------*/
  438. void AllignAutonum95(long durSpaceAnm, long durWidthAnm, LSKALIGN lskalignAnm,
  439. long durUsed, PLSDNODE plsdnAnmAfter, long* pdurBefore, long* pdurAfter)
  440. {
  441. long durExtra;
  442. long durJust;
  443. long durRemain;
  444. durExtra = Max(0, durWidthAnm - durUsed);
  445. durRemain = Max(0, durExtra - durSpaceAnm);
  446. *pdurBefore = 0;
  447. switch (lskalignAnm)
  448. {
  449. case lskalLeft:
  450. *pdurAfter = Max(durSpaceAnm,durExtra);
  451. break;
  452. case lskalCentered:
  453. durJust = ((DWORD)durExtra) / 2;
  454. if (durJust >= durSpaceAnm)
  455. {
  456. *pdurBefore = durJust;
  457. *pdurAfter = durJust;
  458. }
  459. else
  460. {
  461. /* Justified will not fit -- treat as flushleft */
  462. *pdurBefore = durRemain;
  463. *pdurAfter = durSpaceAnm;
  464. }
  465. break;
  466. case lskalRight:
  467. *pdurBefore = durRemain;
  468. *pdurAfter = durSpaceAnm;
  469. break;
  470. default:
  471. NotReached();
  472. }
  473. Assert(FIsDnodeReal(plsdnAnmAfter));
  474. Assert(plsdnAnmAfter->fTab);
  475. SetDnodeDurFmt(plsdnAnmAfter, *pdurAfter);
  476. plsdnAnmAfter->icaltbd = 0xFF; /* spoil icaltbd */
  477. }
  478. /* A L L I G N A U T O N U M */
  479. /*----------------------------------------------------------------------------
  480. %%Function: AllignAutonum
  481. %%Contact: igorzv
  482. Parameters
  483. plstabscontext - (IN) tabs context
  484. lskalignAnm - (IN) allignment for autonumber
  485. fAllignmentAfter- (IN) is there tab after autonumber
  486. plsdnAnmAfter - (IN) tab dnode to put durAfter
  487. urAfterAnm - (IN) pen position after autonumber
  488. durUsed - (IN) width of autonumbering text
  489. pdurBefore - (OUT)calculated distance from indent to autonumber
  490. pdurAfter - (OUT)calculated distance from autonumber to main text
  491. Calculates space before and after autonumber for the case Word95 model.
  492. ----------------------------------------------------------------------------*/
  493. LSERR AllignAutonum(PLSTABSCONTEXT plstabscontext, LSKALIGN lskalignAnm,
  494. BOOL fAllignmentAfter, PLSDNODE plsdnAnmAfter,
  495. long urAfterAnm, long durUsed,
  496. long* pdurBefore, long* pdurAfter)
  497. {
  498. LSERR lserr;
  499. LSKTAB lsktab;
  500. BOOL fBreakThroughTab;
  501. LSCALTBD* plscaltbd;
  502. /* resolving durBefore */
  503. switch (lskalignAnm)
  504. {
  505. case lskalLeft:
  506. *pdurBefore = 0;
  507. break;
  508. case lskalCentered:
  509. *pdurBefore = -durUsed/2;
  510. break;
  511. case lskalRight:
  512. *pdurBefore = -durUsed;
  513. break;
  514. default:
  515. NotReached();
  516. }
  517. /* resolving durAfter */
  518. *pdurAfter = 0;
  519. if (fAllignmentAfter)
  520. {
  521. Assert(FIsDnodeReal(plsdnAnmAfter));
  522. Assert(plsdnAnmAfter->fTab);
  523. plsdnAnmAfter->fTabForAutonumber = fTrue;
  524. urAfterAnm += *pdurBefore;
  525. lserr = GetCurTabInfoCore(plstabscontext, plsdnAnmAfter,
  526. urAfterAnm, fTrue, &lsktab, &fBreakThroughTab);
  527. if (lserr != lserrNone)
  528. return lserr;
  529. plscaltbd = &(plstabscontext->pcaltbd[plsdnAnmAfter->icaltbd]);
  530. *pdurAfter = plsdnAnmAfter->u.real.objdim.dur;
  531. }
  532. return lserrNone;
  533. }
  534. LSERR WINAPI AutonumEnumerate(PDOBJ pdobj, PLSRUN plsrun, PCLSCHP plschp, LSCP cpFirst, LSDCP dcp,
  535. LSTFLOW lstflow, BOOL fReverseOrder, BOOL fGeometryProvided,
  536. const POINT* pptStart, PCHEIGHTS pheightsPres, long dupRun)
  537. {
  538. Unreferenced(plschp);
  539. Unreferenced(plsrun);
  540. Unreferenced(cpFirst);
  541. Unreferenced(dcp);
  542. Unreferenced(lstflow);
  543. Unreferenced(fGeometryProvided);
  544. Unreferenced(pheightsPres);
  545. Unreferenced(dupRun);
  546. return LsEnumSubline(pdobj->plssubl, fReverseOrder, fGeometryProvided,
  547. pptStart);
  548. }