forked from BlastarIndia/msword
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlghyph.c
1859 lines (1637 loc) · 42.9 KB
/
dlghyph.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ****************************************************************************
**
** COPYRIGHT (C) 1987, 1988 MICROSOFT
**
** ****************************************************************************
*
* Module: dlghyph.c --- contains dialog functions for hyphenation dialog.
*
**
** REVISIONS
**
** Date Who Rel Ver Remarks
**
** ************************************************************************* */
#include "word.h"
DEBUGASSERTSZ /* WIN - bogus macro for assert string */
#include "heap.h"
#include "doc.h"
#include "props.h"
#include "sel.h"
#include "disp.h"
#include "debug.h"
#include "doslib.h"
#include "file.h"
#include "ch.h"
#include "wininfo.h"
#include "sedit.h"
#include "prm.h"
#include "screen.h"
#include "prompt.h"
#include "message.h"
#include "hyph.h"
#include "cmd.h"
#include "field.h"
#include "error.h"
#include "help.h"
#include "rareflag.h"
#include "core.h"
#include "idd.h"
#include "sdmdefs.h"
#include "sdmver.h"
#include "sdm.h"
#include "sdmtmpl.h"
#include "sdmparse.h"
#include "hyphen.hs"
#include "hyphen.sdm"
extern BOOL vfRecording;
extern char szClsStaticEdit[];
extern struct MERR vmerr;
extern struct SEL selCur;
extern int wwCur;
extern struct WWD **hwwdCur;
extern CHAR szEmpty[];
extern struct CHP vchpFetch;
extern int vccpFetch;
extern CHAR HUGE *vhpchFetch;
extern CP vcpFetch;
extern struct UAB vuab;
extern struct PREF vpref;
extern struct SCI vsci;
extern struct BPTB vbptbExt;
extern struct HYPFD vhypfd;
extern struct HYPB **vhhypb;
extern HCURSOR vhcArrow;
extern HCURSOR vhcIBeam;
extern HWND vhwndApp;
extern HWND vhwndCBT;
FARPROC lpprocBlinkCaretSEdit;
FARPROC lpprocStaticEditWndProc;
HWND hwndStaticEdit = NULL;
EXPORT PASCAL BlinkCaretSEdit(); /* DECLARATION ONLY */
#define flashIDHyph 0x1059
#define XpFromHypIch(dxp, ich) (DxpLeftSE(dxp) + ((dxp) * (ich)))
csconst CHAR szOK[] = SzSharedKey("OK",OK);
csconst CHAR szYes[] = SzSharedKey("&Yes",Yes);
#define cchPBTextMax ((sizeof(szOK) > sizeof(szYes)) ? \
sizeof(szOK) : sizeof(szYes))
#define cchUTextMax cchMaxWord*2
struct UTXD
{
int ichSelFirst;
int ichSelLim;
int ichLimEffective;
int flashID;
int fSelOn;
char stText[cchUTextMax+1];
};
#define cbUTXD (sizeof(struct UTXD))
#define cwUTXD ((cbUTXD + 1) / 2)
extern CP CpBestHypd();
#ifdef WIN23
extern CHAR *PchLastFit3();
#endif /* WIN23 */
/***************************
*
* Hyphenation functions:
* CmdHyphenate(), DlgfHyphenate() and their supporting
* functions. Main hyphenation functions are located
* in cshare\hyphenate.c
*
***************************/
/* ****
*
Function: CmdHyphenate
* Author:
* Copyright: Microsoft 1986
* Date: 12/12/86
*
* Description: Menu level command function for "Proof Hyphenate" dialog
*
** ***/
/* %%Function:CmdHyphenate %%Owner:bryanl */
CMD CmdHyphenate(pcmb)
CMB * pcmb;
{
CABHYPHEN *pcab;
CHAR *szT;
int dxaT;
struct DOP *pdop;
CMD cmdReturn=cmdOK;
TMC tmc;
BOOL fOverflow;
CHAR szNum[ichMaxNum + 1];
CPR cpr;
cmdReturn = cmdOK; /* we haven't failed yet */
if (pcmb->fDefaults)
{
CHAR *pch;
/* Get the hot zone value from the current dop. */
pdop = &PdodMother(selCur.doc)->dop;
if (pdop->dxaHotZ <= 0 || vsci.xaRightMax <= pdop->dxaHotZ)
{
pdop->dxaHotZ = dxaInch / 4;
}
pch = szNum;
CchExpZa(&pch, pdop->dxaHotZ, vpref.ut, ichMaxNum, fTrue);
*pch = '\0';
if (!FSetCabSz(pcmb->hcab, szNum, Iag(CABHYPHEN, hszHypHotZ)))
return cmdNoMemory;
pcab = (CABHYPHEN *) *pcmb->hcab;
pcab->fHypCaps = vrf.fHyphCapitals;
pcab->fHypConfirm = fTrue;
vrf.fHotZValid = fTrue;
}
if (pcmb->fDialog || pcmb->fAction)
{
char dlt [sizeof (dltHyphenate)];
if (vhhypb == NULL)
{ /* do only if not already set up */
cmdReturn = cmdError;
if (!FLoadHyph()
|| (cmdReturn = CmdHyphInit()) != cmdOK)
goto LReturnUnload;
}
#ifdef DEBUG
else
{
Assert( vhypfd.fn != fnNil );
Assert( vhypfd.hrgoutp != hNil );
}
#endif
BltDlt(dltHyphenate, dlt);
if ((tmc = TmcOurDoDlg(dlt, pcmb)) == tmcError)
{
cmdReturn = cmdNoMemory;
goto LReturnCancel;
}
if (tmc == tmcCancel)
{
cmdReturn = cmdCancelled;
goto LReturnCancel;
}
if (vfRecording)
{
FRecordCab(pcmb->hcab, IDDHyphenate, pcmb->tmc,
imiHyphenate);
}
/* Save the global hyphenation setting for the next time. */
/* First, protect ourselves from a heap movement. */
pcab = (CABHYPHEN *) *pcmb->hcab;
vrf.fHyphCapitals = pcab->fHypCaps;
GetCabSz(pcmb->hcab, szNum, ichMaxNum,
Iag(CABHYPHEN, hszHypHotZ));
if (FZaFromSs(&dxaT, szNum, CchSz(szNum) - 1,
vpref.ut, &fOverflow) &&
dxaT > 0)
{
PdodMother(selCur.doc)->dop.dxaHotZ = dxaT;
}
else if (vrf.fHotZValid)
{
/* Haven't warned the user yet about this invalid
hot zone measurement. */
ErrorEid(eidInvalidHotZ, " CmdHyphenate");
cmdReturn = cmdError;
goto LReturnCancel;
}
if (tmc == tmcHypChange)
{
HyphChangeSelection(dxaT, vrf.fHyphCapitals, &cpr);
/* Because of unmatching StartLongOp() in
HyphChangeSelection(). */
EndLongOp(fFalse /* fAll */);
}
cmdReturn = cmdOK;
LReturnCancel:
HyphCancel();
LReturnUnload:
UnloadHyph();
}
return cmdReturn;
}
/******
*
* Function: FDlgHyphenate
* Author:
* Copyright: Microsoft 1986
* Date: 12/12/86
*
* Description: Dialog box function for "Proof Hyphenate" dialog
*
******/
/* %%Function:FDlgHyphenate %%Owner:bryanl */
BOOL FDlgHyphenate(dlm, tmc, wNew, wOld, wParam)
DLM dlm;
TMC tmc;
WORD wNew, wOld, wParam;
{
int dxaT;
struct HYPD *phypd;
CHAR szT[cchPBTextMax];
struct UTXD utxd;
HWND hwnd;
struct RC rcDlg, rcApp;
int dyp;
switch (dlm)
{
case dlmIdle:
if (wNew /* cIdle */ == 0)
return fTrue; /* call FSdmDoIdle and keep idling */
if (wNew /* cIdle */ == 3)
FAbortNewestCmg (cmgUtilEdit, fTrue, fTrue);
else if (wNew /* cIdle */ == 5)
FAbortNewestCmg (cmgPromptUtilAC, fTrue, fTrue);
else if (wNew > 5)
return fTrue; /* stop idling */
return fFalse; /* keep idling */
case dlmInit:
if (FIsDlgDying())
return fTrue; /* just get out. Dlg will come down bz */
/* position the dialog out of the way */
GetClientRect(vhwndApp, (LPRECT) &rcApp);
hwnd = HwndFromDlg(HdlgGetCur());
GetWindowRect(hwnd, (LPRECT) &rcDlg);
dyp = rcDlg.ypBottom - rcDlg.ypTop;
ScreenToClient(vhwndApp, (LPPOINT) &rcDlg.ptTopLeft);
MoveDlg(rcDlg.xpLeft, rcApp.ypBottom - dyp - vsci.dypBdrCapt);
Assert( vhhypb != hNil );
SetHyphStaticEdit(NULL);
/* if selection exactly one word, do hyphenation and display it */
if ((*vhhypb)->fHyphWord)
{
FreezeHp();
FetchToHypd(selCur.doc, selCur.cpFirst, selCur.cpLim,
&(*vhhypb)->hypd);
HyphenateWord(&(*vhhypb)->hypd, vrf.fHyphCapitals);
(*vhhypb)->hypd.ichLimEffective = -1;
if ((*vhhypb)->hypd.iichMac > 0)
{
(*vhhypb)->hypd.iichBest = (*vhhypb)->hypd.iichMac-1;
if (FHypdWidow(&(*vhhypb)->hypd))
goto LNoBest;
}
else
{
LNoBest:
(*vhhypb)->hypd.iichBest = -1;
}
MeltHp();
EnableTmc(tmcHypNoChange, fFalse);
EnableTmc(tmcHypConfirm, fFalse);
vrf.fHyphHaveWord = fTrue;
goto LDispWord;
}
/* We want to hyphenate the entire document/selection. */
/* Set up push buttons to initial state. */
EnableTmc(tmcHypNoChange, fFalse);
CchCopyLpszCchMax(szOK, (CHAR FAR *) szT, cchPBTextMax);
SetTmcText(tmcHypChange, szT);
EnableTmc(tmcHypAt, fFalse);
vrf.fHyphHaveWord = fFalse;
break;
case dlmClick:
switch (tmc)
{
CP cp;
int cHyphen;
int ichLast;
CHAR *pchCur;
HCAB hcab;
case tmcHypChange:
if (!vrf.fHyphHaveWord)
goto LNextWord; /* don't have a word yet, go scan for one */
DelHyphHhypb(vhhypb);
SendMessage(hwndStaticEdit, WM_COMMAND, SEM_GETDSCRP, (LPSTR) &utxd);
Assert( utxd.ichSelFirst > 0 );
for (pchCur = &(utxd.stText[1]), cHyphen = ichLast = 0;
ichLast < utxd.ichSelFirst; ichLast++, pchCur++)
{
if (*pchCur == '-')
cHyphen++;
}
phypd = &((*vhhypb)->hypd);
#ifdef BRYANL
CommSzNum( SzShared( "Insert Hyph at cp = " ),
(int) (phypd->rgdcp[utxd.ichSelFirst - cHyphen] + phypd->cpFirst) );
#endif
HyphInsertCp( phypd->rgdcp[utxd.ichSelFirst - cHyphen]
+ phypd->cpFirst);
Debug(phypd = 0); /* can't assume no HM */
if (vmerr.fDiskFail || vmerr.fMemFail)
/* if failure, dialog will be taken down without EndDlg */
return (fTrue);
LMaybeNextWord:
if ((*vhhypb)->fHyphWord)
goto LEndTmc;
LNextWord:
if (!FGetHotZoneWidth(tmcHypHotZ, &dxaT))
{
SetTmcTxs(tmcHypHotZ, TxsAll());
break;
}
if (!ValGetTmc(tmcHypConfirm))
{
LEndTmc:
if ((hcab = HcabFromDlg(fFalse)) == hcabNotFilled)
return fFalse;
if (hcab != hcabNull)
{
Assert(PcmbDlgCur()->hcab == hcab);
EndDlg(tmc); /* ok to call EndDlg here */
}
/* if hcabNull, dialog will be taken down without EndDlg */
return (fTrue);
break;
}
if (!vrf.fHyphHaveWord)
{
vrf.fHyphHaveWord = fTrue;
EnableTmc(tmcHypNoChange, fTrue);
CchCopyLpszCchMax(szYes, (CHAR FAR *) szT, cchPBTextMax);
SetTmcText(tmcHypChange, szT);
}
vrf.fHyphCapitals = ValGetTmc(tmcHypCaps);
LRetry:
if (!FHyphFind(dxaT, fFalse, vrf.fHyphCapitals, NULL))
{
if ((hcab = HcabFromDlg(fFalse)) == hcabNotFilled)
return fFalse;
if (hcab != hcabNull)
{
Assert(PcmbDlgCur()->hcab == hcab);
EndDlg(tmcHypNoChange); /* ok to call EndDlg here */
}
/* if hcabNull, dialog will be taken down without EndDlg */
return (fTrue);
}
cp = CpBestHypd(&(*vhhypb)->hypd);
/* calculate effective hyphenation limit */
phypd = &(*vhhypb)->hypd;
if (phypd->ichLimEffective <= 0)
{
IchLimEffectiveHypd();
}
Debug(phypd = 0); /* can't assume no HM */
LDispWord:
ProposeHyph(vhhypb);
EnableTmc(tmcHypAt, fTrue);
SetHyphStaticEdit(vhhypb);
if ((*vhhypb)->hypd.iichBest < 0)
{
/* hyphenation's opinion is that we should not hyphenate this word. However,
if we just selected a word and asked hyphenate to break it down, we want
to offer the option anyway. Hence this code. */
SendMessage(hwndStaticEdit, WM_COMMAND,
SEM_GETDSCRP, (LPSTR) &utxd);
SetDefaultTmc( (*vhhypb)->fHyphWord ?
tmcCancel :
tmcHypNoChange );
if ((*vhhypb)->fHyphWord && utxd.ichSelFirst > 0)
{
EnableTmc( tmcHypChange, fTrue );
if (FEnabledTmc(tmcHypText))
SetFocusTmc(tmcHypText);
}
else
EnableTmc( tmcHypChange, fFalse );
break;
}
/* have both suggested and recommended hyphenation points for this word */
EnableTmc( tmcHypChange, fTrue );
SetDefaultTmc( tmcHypChange );
if (FEnabledTmc(tmcHypText))
SetFocusTmc(tmcHypText);
break;
case tmcHypNoChange:
Assert( vrf.fHyphHaveWord );
DelHyphHhypb(vhhypb);
goto LMaybeNextWord;
} /* end switch (tmc) */
} /* end switch (dlm) */
return fTrue;
}
/******
*
* Function: FGetHotZoneWidth
* Author:
* Copyright: Microsoft 1986
* Date: 12/12/86
*
* Description: Get a dxa value from the hot zone edit control.
* Returns fTrue iff the hot zone value is correct.
*
******/
/* %%Function:FGetHotZoneWidth %%Owner:bryanl */
FGetHotZoneWidth(tmc, pdxa)
int tmc;
int *pdxa;
{
int cch;
BOOL fOverflow;
CHAR szNum[ichMaxNum];
cch = CchGetTmcText(tmc, szNum, ichMaxNum - 1);
if (cch != 0)
{
if (FZaFromSs(pdxa, szNum, cch, vpref.ut, &fOverflow)
&& !fOverflow
&& *pdxa > dxaHotZMin && *pdxa < vsci.xaRightMax)
{
vrf.fHotZValid = fTrue;
return fTrue;
}
}
LInvalid:
ErrorEid(eidInvalidHotZ, "FGetHotZoneWidth");
vrf.fHotZValid = fFalse;
return (fFalse);
}
/* %%Function:CmdHyphInit %%Owner:bryanl */
CMD CmdHyphInit()
{
struct HYPB hypb;
BOOL fUndo = fTrue;
SetBytes(&hypb, 0, cbHYPB);
/* back up to beginning of paragraph */
hypb.cpStart = CpFirstSty(selCur.ww, selCur.doc,
selCur.cpFirst, styPara, fFalse);
hypb.fHyphWord = fFalse;
hypb.fDirty = (DiDirtyDoc(selCur.doc) != diNotDirty);
if (hypb.fWholeDocScan = selCur.fIns)
{
hypb.cpLim = CpMacDoc(selCur.doc);
PcaSetWholeDoc(&hypb.caUndo, selCur.doc);
}
else
{
CP cpWordLim;
/* if selection exactly one word, set flag */
if (selCur.cpFirst != selCur.cpLim &&
selCur.cpFirst == CpFirstSty(wwCur, selCur.doc,
selCur.cpLim - 1, styWord,
fFalse) &&
(selCur.cpLim == (cpWordLim = CpLimSty(wwCur,
selCur.doc, selCur.cpFirst,
styWord, fFalse)) ||
selCur.cpLim + 1 == cpWordLim))
{
hypb.fHyphWord = fTrue;
hypb.cpStart = selCur.cpFirst;
hypb.cpLim = selCur.cpLim;
}
else
{
/* cpStart is already set. */
Assert(hypb.cpStart ==
CpFirstSty(selCur.ww, selCur.doc,
selCur.cpFirst, styPara,
fFalse));
hypb.cpLim = CpLimSty(selCur.ww, selCur.doc,
selCur.cpLim - 1, styPara,
fFalse);
}
PcaSet(&hypb.caUndo, selCur.doc, hypb.cpStart, hypb.cpLim);
}
if ((PdodDoc(selCur.doc)->fFtn || PdodDoc(selCur.doc)->fAtn) &&
!FCheckLargeEditFtn(&hypb.caUndo, &fUndo))
return cmdCancelled;
if (fUndo)
{
if (!FSetUndoB1(imiHyphenate, uccPaste, &hypb.caUndo))
{
return cmdCancelled;
}
}
else
SetUndoNil();
hypb.cpLine = hypb.cpStart = CpFirstSty(selCur.ww, selCur.doc, selCur.cpFirst, styPara, fFalse);
Assert( vhhypb == hNil );
if ((vhhypb = HAllocateCw(CwFromCch(cbHYPB))) == hNil)
return(cmdNoMemory);
/* We only hyphenate in the show result mode, so that
we won't end up hyphenating field keywords, etc. */
{
GRPFVISI grpfvisi;
struct CA ca;
grpfvisi = PwwdWw(wwCur)->grpfvisi;
hypb.grpfvisiSave = grpfvisi.w;
grpfvisi.grpfShowResults = ~0;
grpfvisi.fForceField = fTrue;
PwwdWw(wwCur)->grpfvisi = grpfvisi;
CheckInvalCpFirst(PcaSetWholeDoc(&ca, selCur.doc));
InvalCp(&ca);
}
/* if the selection is an insertion point (meaning we will be searching
the whole doc) or the selection covers more than 500 chars then
preload the external cache with the hyphenation pattern file. */
if (selCur.fIns || selCur.cpFirst + 500 < selCur.cpLim)
{
PN cpnRead, pn;
struct FCB *pfcb = PfcbFn(vhypfd.fn);
StartLongOp();
/* external cache better exist */
Assert(vbptbExt.ibpMac);
cpnRead = min((PN) ((pfcb->cbMac + cbSector - 1) >> shftSector), 5);
for (pn = 0; pn < cpnRead; pn++)
IbpCacheFilePage(vhypfd.fn, pn);
EndLongOp(fTrue);
}
/* initialize hypd and hypb */
hypb.hypd.ichMac = 0;
hypb.hypd.ichLimEffective = -1;
hypb.hypd.ichSel = -1;
bltb(&hypb, *vhhypb, cbHYPB);
return(cmdOK);
}
/* %%Function:HyphCancel %%Owner:bryanl */
HyphCancel()
{
struct CA ca;
struct HYPB hypb;
bltb( *vhhypb, &hypb, cbHYPB);
DelHyphHhypb(vhhypb);
hypb.caUndo.cpLim += hypb.cHyph;
SetUndoAfter(&hypb.caUndo);
Select(&selCur, hypb.caUndo.cpFirst, hypb.caUndo.cpLim);
PwwdWw(wwCur)->grpfvisi.w = hypb.grpfvisiSave;
PcaSetWholeDoc(&ca, selCur.doc);
CheckInvalCpFirst(&ca);
InvalCp(&ca);
if (hypb.cHyph == 0)
{
PdodDoc(DocMother(selCur.doc))->fDirty = hypb.fDirty; /* restore the fDirty flag */
}
FreePh(&vhhypb);
}
/* U n l o a d H y p h */
/* free hyphenation data file fn and all heap variables used to store
stuff read from it */
/* %%Function:UnloadHyph %%Owner:bryanl */
UnloadHyph()
{
if (vhypfd.fn != fnNil)
{
DeleteFn(vhypfd.fn, fFalse);
vhypfd.fn = fnNil;
}
FreePh(&vhypfd.hrgoutp);
FreePh(&vhypfd.hrgbctt);
}
/* D E L H Y P H H H Y P B */
/* Delete the suggested hyphenation */
/* %%Function:DelHyphHhypb %%Owner:bryanl */
DelHyphHhypb(hhypb)
struct HYPB **hhypb;
{
struct CA ca;
/* Turn off the selection anyway even if there is no
hyphen to clear. */
TurnOffSel(&selCur);
if ((*hhypb)->fClearHyph)
{
struct HYPD *phypd;
phypd = &(*hhypb)->hypd;
FDelete( PcaSetDcp( &ca, selCur.doc, CpBestHypd(phypd), (CP) 1 ));
#ifdef BRYANL
CommSzNum( SzShared( "Delete Hyph at cp = " ), (int) CpBestHypd(phypd) );
#endif
(*hhypb)->fClearHyph = fFalse;
}
}
/* ------ Routines used in wordtech\hyph.c but sufficiently ------ */
/* -------------- different from the Mac counterpart. ------------ */
/* P r o p o s e H y p h */
/* Scrolls the suggested hyphenation point into a view complete
with a hyphen. */
/* %%Function:ProposeHyph %%Owner:bryanl */
ProposeHyph(hhypb)
struct HYPB **hhypb;
{
/* Put in a hyphen to show where the line would break. */
CP cpSuggested;
struct HYPD *phypd;
struct CA ca;
TurnOffSel(&selCur);
phypd = &(*hhypb)->hypd;
if (phypd->iichBest >= 0)
{
CHAR rgchHyphen[1];
FreezeHp();
cpSuggested = CpBestHypd(phypd);
#ifdef BRYANL
CommSzNum( SzShared( "Propose Hyph at cp = " ), (int) cpSuggested );
#endif
MeltHp();
rgchHyphen[0] = chHyphen;
/* if this fails, so what, you don't get a hyphen */
FInsertRgch(selCur.doc, cpSuggested, rgchHyphen, 1, NULL, NULL);
InvalCp(PcaSetDcp( &ca,selCur.doc, cpSuggested, (CP) 1));
AssureCpAboveDyp(cpSuggested,
((*hwwdCur)->ywMac - (*hwwdCur)->ywMin) / 3, fTrue);
Select(&selCur,cpSuggested, cpSuggested + 1);
(*hhypb)->fClearHyph = fTrue;
}
else
{
(*hhypb)->fClearHyph = fFalse;
}
TurnOnSelCur();
}
/* %%Function:FLoadHyph %%Owner:bryanl */
BOOL FLoadHyph()
{
/* read in hyphenation outputs and translation table */
int cb;
int cch;
struct HYPFH hypfh;
CHAR stFile[ichMaxFile + 2]; /* Used as stz with GetProgramDir */
if (vhypfd.fn != fnNil)
{
return fTrue;
}
if (!FFindFileSpec(StShared("HYPH.DAT"), stFile, grpfpiUtil, nfoNormal)
|| (vhypfd.fn = FnOpenSt(stFile, 0, ofcDoc, NULL)) == fnNil)
{
ErrorEid(eidHypNoDataFile, "FLoadHyph");
return(fFalse);
}
/* read in base pointers for rest of hyphenation data */
SetFnPos(vhypfd.fn, (FC) cbSectorPre35);
ReadRgchFromFn(vhypfd.fn, (CHAR *) &hypfh, cchHYPFH);
/* allocate memory for and read in hyphenation outputs */
cb = hypfh.cbCttBase - hypfh.cbOutpBase;
if ((vhypfd.hrgoutp = HAllocateCw(CwFromCch(cb))) == hNil)
{
return fFalse;
}
SetFnPos(vhypfd.fn, (FC) hypfh.cbOutpBase);
ReadRgchFromFn(vhypfd.fn, (CHAR *) &(**vhypfd.hrgoutp)[0], cb);
/* read in hyphenation translation table, if any */
vhypfd.cbTrieBase = hypfh.cbTrieBase;
if (hypfh.cbMac > hypfh.cbCttBase)
{
FC fcPrd = (FC) hypfh.cbCttBase + 2;
/* 2 is WFromStm(VHYPFD.FN), count of translation runs (not used) */
vhypfd.chHttFirst = *(char HUGE *) HpchFromFc(vhypfd.fn, fcPrd++);
vhypfd.chHttLast = *(char HUGE *) HpchFromFc(vhypfd.fn, fcPrd++);
cb = vhypfd.chHttLast - vhypfd.chHttFirst + 1;
if ((vhypfd.hrgbctt = HAllocateCw(CwFromCch(cb))) == hNil)
goto ErrRet;
SetFnPos(vhypfd.fn, (FC) hypfh.cbCttBase + 4);
ReadRgchFromFn(vhypfd.fn,
(CHAR *) &(**vhypfd.hrgbctt)[0], cb);
}
else
{ /* no translation */
vhypfd.chHttLast = vhypfd.chHttFirst = -1;
vhypfd.hrgbctt = 0;
}
return fTrue;
ErrRet:
FreePh(&vhypfd.hrgoutp);
return fFalse;
}
/* F E T C H T O H Y P D */
/* fetches the contents of a ca to hypd.
Vanished text and chNonReqHypen's will be skipped and their places indicated
in rgdcp.
No heap movement allowed.
*/
/* %%Function:FetchToHypd %%Owner:bryanl */
FetchToHypd(doc, cpFirst, cpLim, phypd)
int doc;
CP cpFirst, cpLim;
struct HYPD *phypd;
{
int ichMac = 0, ch;
CHAR *pchTo = &phypd->rgch[0], HUGE *hpch;
CP *pdcpTo = &phypd->rgdcp[0];
CP dcp = cp0, ccp;
phypd->cpFirst = cpFirst;
CachePara(doc, cpFirst);
while (cpFirst < cpLim)
{
FetchCp(doc, cpFirst, fcmChars + fcmProps);
doc = docNil;
if (vchpFetch.fVanish)
dcp += vccpFetch;
else
{
for (ccp = (int)CpMin((CP)vccpFetch, cpLim - vcpFetch),
hpch = vhpchFetch; ccp > 0;
ccp--, hpch++, dcp++)
if ((ch = *hpch) != chNonReqHyphen && ichMac < cchMaxWord - 1)
{
if (!(FUpper(ch) || FLower(ch)))
goto LEnd;
*pchTo++ = ch;
*pdcpTo++ = dcp;
ichMac++;
}
}
cpFirst += vccpFetch;
}
LEnd:
Assert( ichMac <= cchMaxWord - 1 );
phypd->ichMac = ichMac;
phypd->iichMac = 0;
phypd->iichBest = -1;
}
/* %%Function:SetHyphStaticEdit %%Owner:bryanl */
SetHyphStaticEdit(hhypb)
struct HYPB **hhypb;
{
int ichTo;
struct UTXD utxd;
ichTo = 0;
SetBytes(&utxd, 0, sizeof(struct UTXD));
if (hhypb != NULL)
{
int ichFrom, iich;
struct HYPD *phypd = &(*hhypb)->hypd;
char *rgch;
BOOL fAdjust;
rgch = &(utxd.stText[1]);
utxd.ichLimEffective = phypd->ichLimEffective;
#ifdef DBGYXY
CommSzNum(SzShared("ichLimEffective(before): "), utxd.ichLimEffective);
#endif
for (ichFrom = iich = 0; ichFrom < phypd->ichMac; ichFrom++)
{
Assert( ichTo < cchUTextMax - 1 );
rgch[ichTo++] = phypd->rgch[ichFrom];
if (ichFrom == phypd->ichSel && iich > 0 &&
ichFrom - 1 == phypd->rgich[iich - 1])
{
Assert(ichTo >= 2);
utxd.ichSelFirst = ichTo - 2;
utxd.ichSelLim = ichTo - 1;
}
if (iich < phypd->iichMac && ichFrom == phypd->rgich[iich])
{
if (ichTo <= utxd.ichLimEffective)
{
utxd.ichLimEffective++;
}
rgch[ichTo++] = '-';
iich++;
}
}
#ifdef DBGYXY
CommSzNum(SzShared("ichLimEffective(after): "), utxd.ichLimEffective);
#endif
}
if (hhypb == hNil || (*hhypb)->fHyphWord)
{
utxd.ichLimEffective = -1;
}
utxd.fSelOn = fFalse;
utxd.flashID = NULL;
utxd.stText[0] = ichTo;
Assert(hwndStaticEdit != NULL);
#ifdef DBGYXY
CommSzSt(SzShared("utxd.stText: "), utxd.stText);
#endif
SendMessage(hwndStaticEdit, WM_COMMAND, SEM_SETDSCRP, (LPSTR) &utxd);
}
/* Routines to make the hyphenation progress reporting mechanism
sharable. */
/* %%Function:InitHyphCancelPoll %%Owner:bryanl */
BOOL InitHyphCancelPoll(pcpr)
CPR *pcpr;
{
struct HYPB *phypb;
if ((*vhhypb)->fHyphWord)
return;
Assert (pcpr != NULL);
if (pcpr == NULL) /* just to avoid low memory trashing */
return;
pcpr->hppr = HpprStartProgressReport(mstHyphenate, NULL,
nIncrPercent, fTrue);
phypb = *vhhypb;
ProgressReportPercent(pcpr->hppr, phypb->cpStart, phypb->cpLim,
phypb->cpLine, &pcpr->cpRptNext);
}
/* %%Function:FHyphCancelPoll %%Owner:bryanl */
BOOL FHyphCancelPoll(pcpr, fBatch)
CPR *pcpr;
BOOL fBatch;
{
if (fBatch && (*vhhypb)->hypd.cpFirst >= pcpr->cpRptNext)
{
#ifdef DBGYXY
CommSzLong(SzShared("cpStart: "), (*vhhypb)->cpStart);
CommSzLong(SzShared("cpLim: "), (*vhhypb)->cpLim);
CommSzLong(SzShared("cpFirst: "), (*vhhypb)->hypd.cpFirst);
#endif
if (!(*vhhypb)->fHyphWord)
{
ProgressReportPercent(pcpr->hppr, (*vhhypb)->cpStart,
(*vhhypb)->cpLim, (*vhhypb)->hypd.cpFirst,
&(pcpr->cpRptNext));
if (FQueryAbortCheck())
{
TurnOffSel(&selCur);
Select(&selCur, (*vhhypb)->hypd.cpFirst,
(*vhhypb)->hypd.cpFirst);
NormCp(wwCur, selCur.doc, (*vhhypb)->hypd.cpFirst, 3,
((*hwwdCur)->ywMac - (*hwwdCur)->ywMin) / 3,
fTrue);
TurnOnSelCur();
return fTrue;
}
}
}
return fFalse;
}
/* To accomodate difference in the prompt scheme between WIN and MAC. */
/* %%Function:IAlertHyphAn %%Owner:bryanl */
int IAlertHyphAn(an, fResponse)
CHAR *an;
BOOL fResponse;
{
int wRet;
Assert( vhhypb != hNil );
if (an == anHyphContinue)
{
wRet = IdMessageBoxMstRgwMb(mstHypRepeat, NULL, MB_DEFYESQUESTION)
== IDYES;
}
else if (!(*vhhypb)->fHyphWord)
{
SetPromptMst(mstHyphComplete, pdcAdvise2);
wRet = NULL;
}
return wRet;
}
/* ---------------- Hyphenation Dialog Static Edit Stuff ----------------- */
/* %%Function:WPictureStaticEdit %%Owner:bryanl */