summaryrefslogtreecommitdiff
path: root/binfilter/bf_sw/source/core/layout/sw_flylay.cxx
blob: d0470cdf6003e39f17cb7f66b4b805122c776359 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/


#ifdef _MSC_VER
#pragma hdrstop
#endif

#include <horiornt.hxx>

#include "doc.hxx"
#include "pagefrm.hxx"
#include "cntfrm.hxx"
#include "dflyobj.hxx"
#include "dcontact.hxx"
#include "ftnfrm.hxx"
#include "frmtool.hxx"
#include "frmfmt.hxx"
#include "hints.hxx"
#include "pam.hxx"
#include "sectfrm.hxx"


#include <bf_svx/svdpage.hxx>

#include <bf_svx/ulspitem.hxx>

#include <fmtanchr.hxx>
#include <fmtornt.hxx>
#include <fmtfsize.hxx>
#include "tabfrm.hxx"
#include "flyfrms.hxx"

#ifdef ACCESSIBLE_LAYOUT
#include <frmsh.hxx>
#endif
namespace binfilter {

/*************************************************************************
|*
|*	SwFlyFreeFrm::SwFlyFreeFrm(), ~SwFlyFreeFrm()
|*
|*	Ersterstellung		MA 03. Dec. 92
|*	Letzte Aenderung	MA 09. Apr. 99
|*
|*************************************************************************/

/*N*/ SwFlyFreeFrm::SwFlyFreeFrm( SwFlyFrmFmt *pFmt, SwFrm *pAnch ) :
/*N*/ 	SwFlyFrm( pFmt, pAnch ),
/*N*/ 	pPage( 0 )
/*N*/ {
/*N*/ }

/*N*/ SwFlyFreeFrm::~SwFlyFreeFrm()
/*N*/ {
/*N*/ 	//und Tschuess.
/*N*/ 	if( GetPage() )
/*N*/ 	{
/*N*/ 		if( GetFmt()->GetDoc()->IsInDtor() )
/*N*/ 		{
/*N*/ 			if ( IsFlyAtCntFrm() && GetPage()->GetSortedObjs() )
/*N*/ 				GetPage()->GetSortedObjs()->Remove( GetVirtDrawObj() );
/*N*/ 		}
/*N*/ 		else
/*N*/ 		{
/*N*/ 			SwRect aTmp( AddSpacesToFrm() );
/*N*/ 			SwFlyFreeFrm::NotifyBackground( GetPage(), aTmp, PREP_FLY_LEAVE );
/*N*/ 		}
/*N*/ 	}
/*N*/ }

/*************************************************************************
|*
|*	SwFlyFreeFrm::NotifyBackground()
|*
|*	Beschreibung		Benachrichtigt den Hintergrund (alle CntntFrms die
|*		gerade ueberlappt werden. Ausserdem wird das Window in einigen
|* 		Faellen direkt invalidiert (vor allem dort, wo keine CntntFrms
|*		ueberlappt werden.
|* 		Es werden auch die CntntFrms innerhalb von anderen Flys
|*		beruecksichtigt.
|*	Ersterstellung		MA 03. Dec. 92
|*	Letzte Aenderung	MA 26. Aug. 93
|*
|*************************************************************************/

/*N*/ void SwFlyFreeFrm::NotifyBackground( SwPageFrm *pPage,
/*N*/ 									 const SwRect& rRect, PrepareHint eHint )
/*N*/ {
/*N*/ 	::binfilter::Notify_Background( GetVirtDrawObj(), pPage, rRect, eHint, TRUE );
/*N*/ }

/*************************************************************************
|*
|*	SwFlyFreeFrm::MakeAll()
|*
|*	Ersterstellung		MA 18. Feb. 94
|*	Letzte Aenderung	MA 03. Mar. 97
|*
|*************************************************************************/

/*N*/ void SwFlyFreeFrm::MakeAll()
/*N*/ {
/*N*/     if ( !GetAnchor() || IsLocked() || IsColLocked() )
/*N*/ 		return;
/*N*/     if( !GetPage() && GetAnchor() && GetAnchor()->IsInFly() )
/*N*/     {
/*?*/         SwFlyFrm* pFly = GetAnchor()->FindFlyFrm();
/*?*/         SwPageFrm *pPage = pFly ? pFly->FindPageFrm() : NULL;
/*?*/         if( pPage )
/*?*/             pPage->SwPageFrm::AppendFly( this );
/*N*/     }
/*N*/     if( !GetPage() )
/*?*/         return;
/*N*/ 
/*N*/ 	Lock();	//Der Vorhang faellt
/*N*/ 
/*N*/ 	//uebernimmt im DTor die Benachrichtigung
/*N*/ 	const SwFlyNotify aNotify( this );
/*N*/ 
/*N*/ 	if ( IsClipped() )
/*N*/ 		bValidPos = bValidSize = bHeightClipped = bWidthClipped = FALSE;
/*N*/ 
/*N*/ 	while ( !bValidPos || !bValidSize || !bValidPrtArea || bFormatHeightOnly )
/*N*/ 	{
/*N*/ #ifdef VERTICAL_LAYOUT
/*N*/        SWRECTFN( this )
/*N*/ #endif
/*N*/ 		const SwFmtFrmSize *pSz;
/*N*/ 		{	//Zusaetzlicher Scope, damit aAccess vor dem Check zerstoert wird!
/*N*/ 
/*N*/ 			SwBorderAttrAccess aAccess( SwFrm::GetCache(), this );
/*N*/ 			const SwBorderAttrs &rAttrs = *aAccess.Get();
/*N*/ 			pSz = &rAttrs.GetAttrSet().GetFrmSize();
/*N*/ 
/*N*/ 			//Nur einstellen wenn das Flag gesetzt ist!!
/*N*/ 			if ( !bValidSize )
/*N*/ 			{
/*N*/ 				bValidPrtArea = FALSE;
/*N*/ 				const Size aTmp( CalcRel( *pSz ) );
/*N*/ 				const SwTwips nMin = MINFLY + rAttrs.CalcLeftLine()+rAttrs.CalcRightLine();
/*N*/                 long nDiff = bVert ? aTmp.Height() : aTmp.Width();
/*N*/                 if( nDiff < nMin )
/*?*/                     nDiff = nMin;
/*N*/                 nDiff -= (aFrm.*fnRect->fnGetWidth)();
/*N*/                 if( nDiff )
/*N*/                 {
/*N*/                     (aFrm.*fnRect->fnAddRight)( nDiff );
/*N*/                     bValidPos = FALSE;
/*N*/                 }
/*N*/ 			}
/*N*/ 
/*N*/ 			if ( !bValidPrtArea )
/*N*/ 				MakePrtArea( rAttrs );
/*N*/ 
/*N*/ 			if ( !bValidSize || bFormatHeightOnly )
/*N*/ 			{
/*N*/ 				bValidSize = FALSE;
/*N*/ 				Format( &rAttrs );
/*N*/ 				bFormatHeightOnly = FALSE;
/*N*/ 			}
/*N*/ 
/*N*/ 			if ( !bValidPos )
/*N*/ 			{
/*N*/ #ifdef VERTICAL_LAYOUT
/*N*/                 const Point aOldPos( (Frm().*fnRect->fnGetPos)() );
/*N*/ 				MakeFlyPos();
/*N*/                 if( aOldPos == (Frm().*fnRect->fnGetPos)() )
/*N*/ #else
/*?*/ 				const Point aOldPos( Frm().Pos() );
/*?*/ 				MakeFlyPos();
/*?*/ 				if( aOldPos == Frm().Pos() )
/*N*/ #endif
/*N*/ 				{
/*N*/ 					if( !bValidPos && GetAnchor()->IsInSct() &&
/*N*/ 						!GetAnchor()->FindSctFrm()->IsValid() )
/*?*/ 						bValidPos = TRUE;
/*N*/ 				}
/*N*/ 				else
/*N*/ 					bValidSize = FALSE;
/*N*/ 			}
/*N*/ 		}
/*N*/ 		if ( bValidPos && bValidSize )
/*N*/ 			CheckClip( *pSz );
/*N*/ 	}
/*N*/ 	Unlock();
/*N*/ 
/*N*/ #ifdef VERTICAL_LAYOUT
/*N*/ #ifdef DBG_UTIL
/*N*/     SWRECTFN( this )
/*N*/     ASSERT( bHeightClipped || ( (Frm().*fnRect->fnGetHeight)() > 0 &&
/*N*/             (Prt().*fnRect->fnGetHeight)() > 0),
/*N*/ 			"SwFlyFreeFrm::Format(), flipping Fly." );
/*N*/ 
/*N*/ #endif
/*N*/ #else
/*?*/ 	ASSERT( bHeightClipped || (Frm().Height() > 0 && Prt().Height() > 0),
/*?*/ 			"SwFlyFreeFrm::Format(), flipping Fly." );
/*N*/ #endif
/*N*/ }

/*************************************************************************
|*
|*	SwFlyFreeFrm::CheckClip()
|*
|*	Ersterstellung		MA 21. Feb. 94
|*	Letzte Aenderung	MA 03. Mar. 97
|*
|*************************************************************************/

/*N*/ void SwFlyFreeFrm::CheckClip( const SwFmtFrmSize &rSz )
/*N*/ {
/*N*/ 	//Jetzt ist es ggf. an der Zeit geignete Massnahmen zu ergreifen wenn
/*N*/ 	//der Fly nicht in seine Umgebung passt.
/*N*/     //Zuerst gibt der Fly seine Position auf. Danach wird er zunaechst
/*N*/     //formatiert. Erst wenn er auch durch die Aufgabe der Position nicht
/*N*/ 	//passt wird die Breite oder Hoehe aufgegeben - der Rahmen wird soweit
/*N*/ 	//wie notwendig zusammengequetscht.
/*N*/ 
/*N*/ 	const SwVirtFlyDrawObj *pObj = GetVirtDrawObj();
/*N*/ 	SwRect aClip, aTmpStretch;
/*N*/ 	::binfilter::CalcClipRect( pObj, aClip, TRUE );
/*N*/ 	::binfilter::CalcClipRect( pObj, aTmpStretch, FALSE );
/*N*/ 	aClip._Intersection( aTmpStretch );
/*N*/ 
/*N*/     const long nBot = Frm().Top() + Frm().Height();
/*N*/     const long nRig = Frm().Left() + Frm().Width();
/*N*/     const long nClipBot = aClip.Top() + aClip.Height();
/*N*/     const long nClipRig = aClip.Left() + aClip.Width();
/*N*/ 
/*N*/ 	const FASTBOOL bBot = nBot > nClipBot;
/*N*/ 	const FASTBOOL bRig = nRig > nClipRig;
/*N*/ 	if ( bBot || bRig )
/*N*/ 	{
/*N*/ 		FASTBOOL bAgain = FALSE;
/*N*/         if ( bBot && !GetDrawObjs() && !GetAnchor()->IsInTab() )
/*N*/ 		{
/*N*/ 			SwFrm* pHeader = FindFooterOrHeader();
/*N*/ 			// In a header, correction of the position is no good idea.
/*N*/ 			// If the fly moves, some paragraphs has to be formatted, this
/*N*/             // could cause a change of the height of the headerframe,
/*N*/ 			// now the flyframe can change its position and so on ...
/*N*/ 			if( !pHeader || !pHeader->IsHeaderFrm() )
/*N*/ 			{
/*N*/ 				const long nOld = Frm().Top();
/*N*/                 Frm().Pos().Y() = Max( aClip.Top(), nClipBot - Frm().Height() );
/*N*/                 if ( Frm().Top() != nOld )
/*N*/ 					bAgain = TRUE;
/*N*/ 				bHeightClipped = TRUE;
/*N*/ 			}
/*N*/ 		}
/*N*/ 		if ( bRig )
/*N*/ 		{
/*N*/ 			const long nOld = Frm().Left();
/*N*/             Frm().Pos().X() = Max( aClip.Left(), nClipRig - Frm().Width() );
/*N*/ 			if ( Frm().Left() != nOld )
/*N*/ 			{
/*N*/ 				const SwFmtHoriOrient &rH = GetFmt()->GetHoriOrient();
/*N*/ 				// Links ausgerichtete duerfen nicht nach links verschoben werden,
/*N*/ 				// wenn sie einem anderen ausweichen.
/*N*/ 				if( rH.GetHoriOrient() == HORI_LEFT )
/*?*/ 					Frm().Pos().X() = nOld;
/*N*/ 				else
/*N*/ 					bAgain = TRUE;
/*N*/ 			}
/*N*/ 			bWidthClipped = TRUE;
/*N*/ 		}
/*N*/ 		if ( bAgain )
/*N*/ 			bValidSize = FALSE;
/*N*/ 		else
/*N*/ 		{
/*N*/ 			//Wenn wir hier ankommen ragt der Frm in unerlaubte Bereiche
/*N*/ 			//hinein, und eine Positionskorrektur ist nicht erlaubt bzw.
/*N*/ 			//moeglich oder noetig.
/*N*/ 
/*N*/ 			//Fuer Flys mit OLE-Objekten als Lower sorgen wir dafuer, dass
/*N*/ 			//immer proportional Resized wird.
/*N*/ 			Size aOldSize( Frm().SSize() );
/*N*/ 
/*N*/ 			//Zuerst wird das FrmRect eingestellt, und dann auf den Frm
/*N*/ 			//uebertragen.
/*N*/ 			SwRect aFrmRect( Frm() );
/*N*/ 
/*N*/ 			if ( bBot )
/*N*/ 			{
/*N*/ 				long nDiff = nClipBot;
/*N*/                 nDiff -= aFrmRect.Top(); //nDiff ist die verfuegbare Strecke.
/*N*/ 				nDiff = aFrmRect.Height() - nDiff;
/*N*/ 				aFrmRect.Height( aFrmRect.Height() - nDiff );
/*N*/ 				bHeightClipped = TRUE;
/*N*/ 			}
/*N*/ 			if ( bRig )
/*N*/ 			{
/*N*/ 				long nDiff = nClipRig;
/*N*/                 nDiff -= aFrmRect.Left();//nDiff ist die verfuegbare Strecke.
/*N*/ 				nDiff = aFrmRect.Width() - nDiff;
/*N*/ 				aFrmRect.Width( aFrmRect.Width() - nDiff );
/*N*/ 				bWidthClipped = TRUE;
/*N*/ 			}
/*N*/ 
/*N*/           if ( Lower() && Lower()->IsNoTxtFrm() && !FindFooterOrHeader() )
/*N*/ 			{
/*?*/ 				//Wenn Breite und Hoehe angepasst wurden, so ist die
/*?*/ 				//groessere Veraenderung massgeblich.
/*?*/ 				if ( aFrmRect.Width() != aOldSize.Width() &&
/*?*/ 					 aFrmRect.Height()!= aOldSize.Height() )
/*?*/ 				{
/*?*/ 					if ( (aOldSize.Width() - aFrmRect.Width()) >
/*?*/ 						 (aOldSize.Height()- aFrmRect.Height())	)
/*?*/ 						aFrmRect.Height( aOldSize.Height() );
/*?*/ 					else
/*?*/ 						aFrmRect.Width( aOldSize.Width() );
/*?*/ 				}
/*?*/ 
/*?*/ 				//Breite angepasst? - Hoehe dann proportional verkleinern
/*?*/ 				if( aFrmRect.Width() != aOldSize.Width() )
/*?*/                 {
/*?*/ 					aFrmRect.Height( aFrmRect.Width() * aOldSize.Height() /
/*?*/ 									 aOldSize.Width() );
/*?*/                     bHeightClipped = TRUE;
/*?*/                 }
/*?*/ 				//Hoehe angepasst? - Breite dann proportional verkleinern
/*?*/                 else if( aFrmRect.Height() != aOldSize.Height() )
/*?*/                 {
/*?*/ 					aFrmRect.Width( aFrmRect.Height() * aOldSize.Width() /
/*?*/ 									aOldSize.Height() );
/*?*/                     bWidthClipped = TRUE;
/*?*/                 }
/*?*/ 
/*?*/ //                if( bWidthClipped || bHeightClipped )
/*?*/ //                {
/*?*/ //                    SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt();
/*?*/ //                    pFmt->LockModify();
/*?*/ //                    SwFmtFrmSize aFrmSize( rSz );
/*?*/ //                    aFrmSize.SetWidth( aFrmRect.Width() );
/*?*/ //                    aFrmSize.SetHeight( aFrmRect.Height() );
/*?*/ //                    pFmt->SetAttr( aFrmSize );
/*?*/ //                    pFmt->UnlockModify();
/*?*/ //                }
/*N*/ 			}
/*N*/ 
/*N*/ 			//Jetzt die Einstellungen am Frm vornehmen, bei Spalten werden
/*N*/ 			//die neuen Werte in die Attribute eingetragen, weil es sonst
/*N*/ 			//ziemlich fiese Oszillationen gibt.
/*N*/ 			const long nPrtHeightDiff = Frm().Height() - Prt().Height();
/*N*/ 			const long nPrtWidthDiff  = Frm().Width()  - Prt().Width();
/*N*/ 			Frm().Height( aFrmRect.Height() );
/*N*/ 			Frm().Width ( Max( long(MINLAY), aFrmRect.Width() ) );
/*N*/ 			if ( Lower() && Lower()->IsColumnFrm() )
/*N*/ 			{
/*?*/ 				ColLock();	//Grow/Shrink locken.
/*?*/ 				const Size aOldSize( Prt().SSize() );
/*?*/ 				Prt().Height( Frm().Height() - nPrtHeightDiff );
/*?*/ 				Prt().Width ( Frm().Width()  - nPrtWidthDiff );
/*?*/ 				ChgLowersProp( aOldSize );
/*?*/ 				SwFrm *pLow = Lower();
/*?*/ 				do
/*?*/ 				{	pLow->Calc();
/*?*/ 					// auch den (Column)BodyFrm mitkalkulieren
/*?*/ 					((SwLayoutFrm*)pLow)->Lower()->Calc();
/*?*/ 					pLow = pLow->GetNext();
/*?*/ 				} while ( pLow );
/*?*/ 				::binfilter::CalcCntnt( this );
/*?*/ 				ColUnlock();
/* MA 02. Sep. 96: Wenn das Attribut gesetzt wird funktionieren Flys in Flys
 * nicht  (30095 30096)
                SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt();
                pFmt->LockModify();
                SwFmtFrmSize aFrmSize( rSz );
                if ( bRig )
                    aFrmSize.SetWidth( Frm().Width() );
                if ( bBot )
                {
                    aFrmSize.SetSizeType( ATT_FIX_SIZE );
                    aFrmSize.SetHeight( Frm().Height() );
                    bFixHeight = TRUE;
                    bMinHeight = FALSE;
                }
                pFmt->SetAttr( aFrmSize );
                pFmt->UnlockModify();
*/
/*?*/ //Stattdessen:
/*?*/ 				if ( !bValidSize && !bWidthClipped )
/*?*/ 					bFormatHeightOnly = bValidSize = TRUE;
/*N*/ 			}
/*N*/ 			else
/*N*/ 			{
/*N*/ 				Prt().Height( Frm().Height() - nPrtHeightDiff );
/*N*/ 				Prt().Width ( Frm().Width()  - nPrtWidthDiff );
/*N*/ 			}
/*N*/ 		}
/*N*/ 	}
/*N*/ }

/*************************************************************************
|*
|*	SwFlyLayFrm::SwFlyLayFrm()
|*
|*	Ersterstellung		MA 25. Aug. 92
|*	Letzte Aenderung	MA 09. Apr. 99
|*
|*************************************************************************/

/*N*/ SwFlyLayFrm::SwFlyLayFrm( SwFlyFrmFmt *pFmt, SwFrm *pAnch ) :
/*N*/ 	SwFlyFreeFrm( pFmt, pAnch )
/*N*/ {
/*N*/ 	bLayout = TRUE;
/*N*/ }

/*************************************************************************
|*
|*	SwFlyLayFrm::Modify()
|*
|*	Ersterstellung		MA 08. Feb. 93
|*	Letzte Aenderung	MA 28. Aug. 93
|*
|*************************************************************************/

/*N*/ void SwFlyLayFrm::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew )
/*N*/ {
/*N*/ 	USHORT nWhich = pNew ? pNew->Which() : 0;
/*N*/ 
/*N*/ 	SwFmtAnchor *pAnch = 0;
/*N*/ 	if( RES_ATTRSET_CHG == nWhich && SFX_ITEM_SET ==
/*N*/ 		((SwAttrSetChg*)pNew)->GetChgSet()->GetItemState( RES_ANCHOR, FALSE,
/*N*/ 			(const SfxPoolItem**)&pAnch ))
/*N*/ 		;		// Beim GetItemState wird der AnkerPointer gesetzt !
/*N*/ 
/*N*/ 	else if( RES_ANCHOR == nWhich )
/*N*/ 	{
/*N*/ 		//Ankerwechsel, ich haenge mich selbst um.
/*N*/ 		//Es darf sich nicht um einen Wechsel des Ankertyps handeln,
/*N*/ 		//dies ist nur ueber die SwFEShell moeglich.
/*?*/ 		pAnch = (SwFmtAnchor*)pNew;
/*N*/ 	}
/*N*/ 
/*N*/ 	if( pAnch )
/*N*/ 	{
/*?*/ 		ASSERT( pAnch->GetAnchorId() ==
/*?*/ 				GetFmt()->GetAnchor().GetAnchorId(),
/*?*/ 				"8-) Unzulaessiger Wechsel des Ankertyps." );
/*?*/ 
/*?*/ 		//Abmelden, Seite besorgen, an den entsprechenden LayoutFrm
/*?*/ 		//haengen.
/*?*/ 		SwRect aOld( AddSpacesToFrm() );
/*?*/ 		SwPageFrm *pOldPage = GetPage();
/*?*/ 		GetAnchor()->RemoveFly( this );
/*?*/ 
/*?*/ 		if( FLY_PAGE == pAnch->GetAnchorId() )
/*?*/ 		{
/*?*/ 			USHORT nPgNum = pAnch->GetPageNum();
/*?*/ 			SwRootFrm *pRoot = FindRootFrm();
/*?*/ 			SwPageFrm *pPage = (SwPageFrm*)pRoot->Lower();
/*?*/ 			for ( USHORT i = 1; (i <= nPgNum) && pPage; ++i,
/*?*/ 								pPage = (SwPageFrm*)pPage->GetNext() )
/*?*/ 			{
/*?*/ 				if ( i == nPgNum )
/*?*/ 					pPage->PlaceFly( this, 0, pAnch );
/*?*/ 			}
/*?*/ 			if( !pPage )
/*?*/ 			{
/*?*/ 				pRoot->SetAssertFlyPages();
/*?*/ 				pRoot->AssertFlyPages();
/*?*/ 			}
/*?*/ 		}
/*?*/ 		else
/*?*/ 		{
/*?*/ 			SwNodeIndex aIdx( pAnch->GetCntntAnchor()->nNode );
/*?*/ 			SwCntntFrm *pCntnt = GetFmt()->GetDoc()->GetNodes().GoNext( &aIdx )->
/*?*/ 						 GetCntntNode()->GetFrm( 0, 0, FALSE );
/*?*/ 			if( pCntnt )
/*?*/ 			{
/*?*/ 				SwFlyFrm *pTmp = pCntnt->FindFlyFrm();
/*?*/ 				if( pTmp )
/*?*/ 					pTmp->AppendFly( this );
/*?*/ 			}
/*?*/ 		}
/*?*/ 		if ( pOldPage && pOldPage != GetPage() )
/*?*/ 			NotifyBackground( pOldPage, aOld, PREP_FLY_LEAVE );
/*?*/ 		SetCompletePaint();
/*?*/ 		InvalidateAll();
/*?*/ 		SetNotifyBack();
/*N*/ 	}
/*N*/ 	else
/*N*/ 		SwFlyFrm::Modify( pOld, pNew );
/*N*/ }

/*************************************************************************
|*
|*	SwPageFrm::AppendFly()
|*
|*	Ersterstellung		MA 10. Oct. 92
|*	Letzte Aenderung	MA 08. Jun. 96
|*
|*************************************************************************/

/*N*/ void SwPageFrm::AppendFly( SwFlyFrm *pNew )
/*N*/ {
/*N*/ 	if ( !pNew->GetVirtDrawObj()->IsInserted() )
/*N*/ 		FindRootFrm()->GetDrawPage()->InsertObject(
/*N*/ 				(SdrObject*)pNew->GetVirtDrawObj(),
/*N*/ 				pNew->GetVirtDrawObj()->GetReferencedObj().GetOrdNumDirect() );
/*N*/ 
/*N*/ 	InvalidateSpelling();
/*N*/ 	InvalidateAutoCompleteWords();
/*N*/ 
/*N*/ 	if ( GetUpper() )
/*N*/ 	{
/*N*/ 		((SwRootFrm*)GetUpper())->SetIdleFlags();
/*N*/ 		((SwRootFrm*)GetUpper())->InvalidateBrowseWidth();
/*N*/ 	}
/*N*/ 
/*N*/ 	const SdrObjectPtr pObj = pNew->GetVirtDrawObj();
/*N*/ 	ASSERT( pNew->GetAnchor(), "Fly without Anchor" );
/*N*/ 	SwFlyFrm *pFly = pNew->GetAnchor()->FindFlyFrm();
/*N*/ 	if ( pFly && pObj->GetOrdNum() < pFly->GetVirtDrawObj()->GetOrdNum() )
/*N*/ 	{
/*?*/ 		UINT32 nNewNum = pFly->GetVirtDrawObj()->GetOrdNumDirect() + 1;
/*?*/ 		if ( pObj->GetPage() )
/*?*/ 			pObj->GetPage()->SetObjectOrdNum( pObj->GetOrdNumDirect(), nNewNum);
/*?*/ 		else
/*?*/ 			pObj->SetOrdNum( nNewNum );
/*N*/ 	}
/*N*/ 
/*N*/ 	//Flys die im Cntnt sitzen beachten wir nicht weiter.
/*N*/ 	if ( pNew->IsFlyInCntFrm() )
/*N*/ 		InvalidateFlyInCnt();
/*N*/     else
/*N*/     {
/*N*/         InvalidateFlyCntnt();
/*N*/ 
/*N*/         if ( !pSortedObjs )
/*N*/             pSortedObjs = new SwSortDrawObjs();
/*N*/         if ( !pSortedObjs->Insert( pObj ) )
/*?*/             ASSERT( FALSE, "Fly nicht in Sorted eingetragen." );
/*N*/ 
/*N*/         ((SwFlyFreeFrm*)pNew)->SetPage( this );
/*N*/         pNew->InvalidatePage( this );
/*N*/ 
/*N*/ #ifdef ACCESSIBLE_LAYOUT
/*N*/ 		// Notify accessible layout. That's required at this place for
/*N*/ 		// frames only where the anchor is moved. Creation of new frames
/*N*/ 		// is additionally handled by the SwFrmNotify class.
/*N*/ 		if( GetUpper() &&
/*N*/ 			static_cast< SwRootFrm * >( GetUpper() )->IsAnyShellAccessible() &&
/*N*/ 		 	static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell() )
/*N*/ 		{
/*?*/ 			DBG_BF_ASSERT(0, "STRIP"); //STRIP001 static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell()->Imp()
/*N*/ 		}
/*N*/ #endif
/*N*/ 
/*N*/     }
/*N*/ 
/*N*/     if( pNew->GetDrawObjs() )
/*N*/     {
/*?*/         SwDrawObjs &rObjs = *pNew->GetDrawObjs();
/*?*/         for ( USHORT i = 0; i < rObjs.Count(); ++i )
/*?*/         {
/*?*/             SdrObject *pO = rObjs[i];
/*?*/             if( pO->IsWriterFlyFrame() )
/*?*/             {
/*?*/                 SwFlyFrm* pFly = ((SwVirtFlyDrawObj*)pO)->GetFlyFrm();
/*?*/                 if( pFly->IsFlyFreeFrm() && !((SwFlyFreeFrm*)pFly)->GetPage() )
/*?*/                     SwPageFrm::AppendFly( pFly );
/*?*/             }
/*?*/         }
/*N*/     }
/*N*/ 
/*N*/ 	//fix(3018): Kein pNew->Calc() oder sonstiges hier.
/*N*/ 	//Code enfernt in flylay.cxx Rev 1.51
/*N*/ }

/*************************************************************************
|*
|*	SwPageFrm::RemoveFly()
|*
|*	Ersterstellung		MA 10. Oct. 92
|*	Letzte Aenderung	MA 26. Aug. 96
|*
|*************************************************************************/

/*N*/ void SwPageFrm::RemoveFly( SwFlyFrm *pToRemove )
/*N*/ {
/*N*/ 	const UINT32 nOrdNum = pToRemove->GetVirtDrawObj()->GetOrdNum();
/*N*/ 	FindRootFrm()->GetDrawPage()->RemoveObject( nOrdNum );
/*N*/ 	pToRemove->GetVirtDrawObj()->ReferencedObj().SetOrdNum( nOrdNum );
/*N*/ 
/*N*/ 	if ( GetUpper() )
/*N*/ 	{
/*N*/ 		if ( !pToRemove->IsFlyInCntFrm() )
/*N*/ 			((SwRootFrm*)GetUpper())->SetSuperfluous();
/*N*/ 		((SwRootFrm*)GetUpper())->InvalidateBrowseWidth();
/*N*/ 	}
/*N*/ 
/*N*/ 	//Flys die im Cntnt sitzen beachten wir nicht weiter.
/*N*/ 	if ( pToRemove->IsFlyInCntFrm() )
/*?*/ 		return;
/*N*/ 
/*N*/ #ifdef ACCESSIBLE_LAYOUT
/*N*/ 	// Notify accessible layout. That's required at this place for
/*N*/ 	// frames only where the anchor is moved. Creation of new frames
/*N*/ 	// is additionally handled by the SwFrmNotify class.
/*N*/ 	if( GetUpper() &&
/*N*/ 		static_cast< SwRootFrm * >( GetUpper() )->IsAnyShellAccessible() &&
/*N*/ 		static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell() )
/*N*/ 	{
/*?*/ 		DBG_BF_ASSERT(0, "STRIP"); //STRIP001 static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell()->Imp()
/*N*/ 	}
/*N*/ #endif
/*N*/ 
/*N*/ 	//Collections noch nicht loeschen. Das passiert am Ende
/*N*/ 	//der Action im RemoveSuperfluous der Seite - angestossen von gleich-
/*N*/ 	//namiger Methode der Root.
/*N*/ 	//Die FlyColl kann bereits weg sein, weil der DTor der Seite
/*N*/ 	//gerade 'laeuft'
/*N*/ 	if ( pSortedObjs )
/*N*/ 	{
/*N*/ 		pSortedObjs->Remove( pToRemove->GetVirtDrawObj() );
/*N*/ 		if ( !pSortedObjs->Count() )
/*N*/ 		{	DELETEZ( pSortedObjs );
/*N*/ 		}
/*N*/ 	}
/*N*/ 	((SwFlyFreeFrm*)pToRemove)->SetPage( 0 );
/*N*/ }

/*************************************************************************
|*
|*	SwPageFrm::MoveFly
|*
|*	Ersterstellung		MA 25. Jan. 97
|*	Letzte Aenderung	MA 25. Jan. 97
|*
|*************************************************************************/

/*N*/ void SwPageFrm::MoveFly( SwFlyFrm *pToMove, SwPageFrm *pDest )
/*N*/ {
/*N*/ 	//Invalidierungen
/*N*/ 	if ( GetUpper() )
/*N*/ 	{
/*N*/ 		((SwRootFrm*)GetUpper())->SetIdleFlags();
/*N*/ 		if ( !pToMove->IsFlyInCntFrm() && pDest->GetPhyPageNum() < GetPhyPageNum() )
/*N*/ 			((SwRootFrm*)GetUpper())->SetSuperfluous();
/*N*/ 	}
/*N*/ 	pDest->InvalidateSpelling();
/*N*/ 	pDest->InvalidateAutoCompleteWords();
/*N*/ 
/*N*/ 	if ( pToMove->IsFlyInCntFrm() )
/*N*/ 	{
/*?*/ 		pDest->InvalidateFlyInCnt();
/*?*/ 		return;
/*N*/ 	}
/*N*/ 
/*N*/ #ifdef ACCESSIBLE_LAYOUT
/*N*/ 	// Notify accessible layout. That's required at this place for
/*N*/ 	// frames only where the anchor is moved. Creation of new frames
/*N*/ 	// is additionally handled by the SwFrmNotify class.
/*N*/ 	if( GetUpper() &&
/*N*/ 		static_cast< SwRootFrm * >( GetUpper() )->IsAnyShellAccessible() &&
/*N*/ 		static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell() )
/*N*/ 	{
/*?*/ 		DBG_BF_ASSERT(0, "STRIP"); //STRIP001 static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell()->Imp()
/*N*/ 	}
/*N*/ #endif
/*N*/ 
/*N*/ 	//Die FlyColl kann bereits weg sein, weil der DTor der Seite
/*N*/ 	//gerade 'laeuft'
/*N*/ 	const SdrObjectPtr pObj = pToMove->GetVirtDrawObj();
/*N*/ 	if ( pSortedObjs )
/*N*/ 	{
/*N*/ 		pSortedObjs->Remove( pObj );
/*N*/ 		if ( !pSortedObjs->Count() )
/*N*/ 		{	DELETEZ( pSortedObjs );
/*N*/ 		}
/*N*/ 	}
/*N*/ 
/*N*/ 	//Anmelden
/*N*/ 	if ( !pDest->GetSortedObjs() )
/*N*/ 		pDest->pSortedObjs = new SwSortDrawObjs();
/*N*/ 	if ( !pDest->GetSortedObjs()->Insert( pObj ) )
/*?*/ 		ASSERT( FALSE, "Fly nicht in Sorted eingetragen." );
/*N*/ 
/*N*/ 	((SwFlyFreeFrm*)pToMove)->SetPage( pDest );
/*N*/ 	pToMove->InvalidatePage( pDest );
/*N*/ 	pToMove->SetNotifyBack();
/*N*/ 	pDest->InvalidateFlyCntnt();
/*N*/ 
/*N*/ #ifdef ACCESSIBLE_LAYOUT
/*N*/ 	// Notify accessible layout. That's required at this place for
/*N*/ 	// frames only where the anchor is moved. Creation of new frames
/*N*/ 	// is additionally handled by the SwFrmNotify class.
/*N*/ 	if( GetUpper() &&
/*N*/ 		static_cast< SwRootFrm * >( GetUpper() )->IsAnyShellAccessible() &&
/*N*/ 		static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell() )
/*N*/ 	{
/*?*/ 		DBG_BF_ASSERT(0, "STRIP"); //STRIP001 static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell()->Imp()
/*N*/ 	}
/*N*/ #endif
/*N*/ }

/*************************************************************************
|*
|*	SwPageFrm::AppendDrawObject(), RemoveDrawObject()
|*
|*	Ersterstellung		MA 09. Jan. 95
|*	Letzte Aenderung	MA 31. Jul. 96
|*
|*************************************************************************/

/*N*/ void SwPageFrm::AppendDrawObj( SwDrawContact *pNew )
/*N*/ {
/*N*/ 	if ( GetUpper() )
/*N*/ 		((SwRootFrm*)GetUpper())->InvalidateBrowseWidth();
/*N*/ 
/*N*/ 	const SdrObjectPtr pObj = pNew->GetMaster();
/*N*/ 	ASSERT( pNew->GetAnchor(), "Contact without Anchor" );
/*N*/ 	SwFlyFrm *pFly = pNew->GetAnchor()->FindFlyFrm();
/*N*/ 	if ( pFly && pObj->GetOrdNum() < pFly->GetVirtDrawObj()->GetOrdNum() )
/*N*/ 	{
/*?*/ 		UINT32 nNewNum = pFly->GetVirtDrawObj()->GetOrdNumDirect() + 1;
/*?*/ 		if ( pObj->GetPage() )
/*?*/ 			pObj->GetPage()->SetObjectOrdNum( pObj->GetOrdNumDirect(), nNewNum);
/*?*/ 		else
/*?*/ 			pObj->SetOrdNum( nNewNum );
/*N*/ 	}
/*N*/ 
/*N*/ 	if ( FLY_IN_CNTNT == pNew->GetFmt()->GetAnchor().GetAnchorId() )
/*N*/ 		return;
/*N*/ 
/*N*/ 	if ( !pSortedObjs )
/*N*/ 		pSortedObjs = new SwSortDrawObjs();
/*N*/ 	if ( !pSortedObjs->Insert( pObj ) )
/*N*/ 	{
/*N*/ #ifdef DBG_UTIL
/*N*/ 		USHORT nIdx;
/*N*/ 		ASSERT( pSortedObjs->Seek_Entry( pObj, &nIdx ),
/*N*/ 				"Fly nicht in Sorted eingetragen." );
/*N*/ #endif
/*N*/ 	}
/*N*/ 	pNew->ChgPage( this );
/*N*/ }

// OD 20.05.2003 #108784# - adding 'virtual' drawing object to page frame
void SwPageFrm::AppendVirtDrawObj( SwDrawContact* _pDrawContact,
                                   SwDrawVirtObj* _pDrawVirtObj )
{
    if ( GetUpper() )
    {
        ((SwRootFrm*)GetUpper())->InvalidateBrowseWidth();
    }

    ASSERT( _pDrawVirtObj->GetAnchorFrm(), "virtual draw contact without anchor" );
    SwFlyFrm *pFly = _pDrawVirtObj->GetAnchorFrm()->FindFlyFrm();
    if ( pFly && _pDrawVirtObj->GetOrdNum() < pFly->GetVirtDrawObj()->GetOrdNum() )
    {
        UINT32 nNewNum = pFly->GetVirtDrawObj()->GetOrdNumDirect() + 1;
        if ( _pDrawVirtObj->GetPage() )
            _pDrawVirtObj->GetPage()->SetObjectOrdNum( _pDrawVirtObj->GetOrdNumDirect(), nNewNum);
        else
            _pDrawVirtObj->SetOrdNum( nNewNum );
    }

    if ( FLY_IN_CNTNT == _pDrawContact->GetFmt()->GetAnchor().GetAnchorId() )
    {
        return;
    }

    if ( !pSortedObjs )
    {
        pSortedObjs = new SwSortDrawObjs();
    }
    if ( !pSortedObjs->Insert( _pDrawVirtObj ) )
    {
#ifdef DBG_UTIL
        USHORT nIdx;
        ASSERT( pSortedObjs->Seek_Entry( _pDrawVirtObj, &nIdx ),
                "Fly nicht in Sorted eingetragen." );
#endif
    }
    _pDrawVirtObj->SetPageFrm( this );
}

/*N*/ void SwPageFrm::RemoveDrawObj( SwDrawContact *pToRemove )
/*N*/ {
/*N*/ 	//Auch Zeichengebundene muessen hier leider durchlaufen, weil beim
/*N*/ 	//setzen des Attributes zuerst das Attribut gesetzt und dann das Modify
/*N*/ 	//versendet wird.
/*N*/ 
/*N*/ 	//Die FlyColl kann bereits weg sein, weil der DTor der Seite
/*N*/ 	//gerade 'laeuft'
/*N*/ 	if ( pSortedObjs )
/*N*/ 	{
/*N*/ 		const SdrObjectPtr *pDel = pSortedObjs->GetData();
/*N*/ 		pSortedObjs->Remove( pToRemove->GetMaster() );
/*N*/ 		if ( !pSortedObjs->Count() )
/*N*/ 		{
/*N*/ 			DELETEZ( pSortedObjs );
/*N*/ 		}
/*N*/ 		if ( GetUpper() )
/*N*/ 		{
/*N*/ 			if ( FLY_IN_CNTNT != pToRemove->GetFmt()->GetAnchor().GetAnchorId() )
/*N*/ 			{
/*N*/ 				((SwRootFrm*)GetUpper())->SetSuperfluous();
/*N*/ 				InvalidatePage();
/*N*/ 			}
/*N*/ 			((SwRootFrm*)GetUpper())->InvalidateBrowseWidth();
/*N*/ 		}
/*N*/ 	}
/*N*/ 	pToRemove->ChgPage( 0 );
/*N*/ }

// OD 20.05.2003 #108784# - remove 'virtual' drawing object from page frame.
void SwPageFrm::RemoveVirtDrawObj( SwDrawContact* _pDrawContact,
                                   SwDrawVirtObj* _pDrawVirtObj )
{
    if ( pSortedObjs )
    {
        pSortedObjs->Remove( _pDrawVirtObj );
        if ( !pSortedObjs->Count() )
        {
            DELETEZ( pSortedObjs );
        }
        if ( GetUpper() )
        {
            if ( FLY_IN_CNTNT != _pDrawContact->GetFmt()->GetAnchor().GetAnchorId() )
            {
                ((SwRootFrm*)GetUpper())->SetSuperfluous();
                InvalidatePage();
            }
            ((SwRootFrm*)GetUpper())->InvalidateBrowseWidth();
        }
    }
    _pDrawVirtObj->SetPageFrm( 0 );
}

/*************************************************************************
|*
|*	SwPageFrm::PlaceFly
|*
|*	Ersterstellung		MA 08. Feb. 93
|*	Letzte Aenderung	MA 27. Feb. 93
|*
|*************************************************************************/

/*N*/ SwFrm *SwPageFrm::PlaceFly( SwFlyFrm *pFly, SwFrmFmt *pFmt,
/*N*/ 							const SwFmtAnchor *pAnch )
/*N*/ {
/*N*/ 	//Der Fly will immer an der Seite direkt haengen.
/*N*/ 	ASSERT( pAnch->GetAnchorId() == FLY_PAGE, "Unerwartete AnchorId." );
/*N*/ 
/*N*/ 	//Wenn ein Fly uebergeben wurde, so benutzen wir diesen, ansonsten wird
/*N*/ 	//mit dem Format einer erzeugt.
/*N*/ 	if ( pFly )
/*?*/ 		SwFrm::AppendFly( pFly );
/*N*/ 	else
/*N*/ 	{	ASSERT( pFmt, ":-( kein Format fuer Fly uebergeben." );
/*N*/ 		pFly = new SwFlyLayFrm( (SwFlyFrmFmt*)pFmt, this );
/*N*/ 		SwFrm::AppendFly( pFly );
/*N*/ 		::binfilter::RegistFlys( this, pFly );
/*N*/ 	}
/*N*/ 	return pFly;
/*N*/ }

/*************************************************************************
|*
|*	::CalcClipRect
|*
|*	Ersterstellung		AMA 24. Sep. 96
|*	Letzte Aenderung	MA  18. Dec. 96
|*
|*************************************************************************/

BOOL CalcClipRect( const SdrObject *pSdrObj, SwRect &rRect, BOOL bMove )
{
    BOOL bRet = TRUE;
    if ( pSdrObj->IsWriterFlyFrame() )
    {
        const SwFlyFrm *pFly = ((const SwVirtFlyDrawObj*)pSdrObj)->GetFlyFrm();
        if( pFly->IsFlyLayFrm() )
        {
#ifdef AMA_OUT_OF_FLY
            const SwFrm *pClip = pFly->GetAnchor()->FindPageFrm();
#else
            const SwFrm *pClip = pFly->GetAnchor();
#endif
            pClip->Calc();

            rRect = pClip->Frm();
            SWRECTFN( pClip )

            //Vertikales clipping: Top und Bottom, ggf. an PrtArea
            const SwFmtVertOrient &rV = pFly->GetFmt()->GetVertOrient();
            if( rV.GetVertOrient() != VERT_NONE &&
                rV.GetRelationOrient() == PRTAREA )
            {
                (rRect.*fnRect->fnSetTop)( (pClip->*fnRect->fnGetPrtTop)() );
                (rRect.*fnRect->fnSetBottom)( (pClip->*fnRect->fnGetPrtBottom)() );
            }
            //Horizontales clipping: Left und Right, ggf. an PrtArea
            const SwFmtHoriOrient &rH = pFly->GetFmt()->GetHoriOrient();
            if( rH.GetHoriOrient() != HORI_NONE &&
                rH.GetRelationOrient() == PRTAREA )
            {
                (rRect.*fnRect->fnSetLeft)( (pClip->*fnRect->fnGetPrtLeft)() );
                (rRect.*fnRect->fnSetRight)((pClip->*fnRect->fnGetPrtRight)());
            }
        }
        else if( pFly->IsFlyAtCntFrm() )
        {
            const SwFrm *pClip = pFly->GetAnchor();
            SWRECTFN( pClip )
            const SwLayoutFrm *pUp = pClip->GetUpper();
            const SwFrm *pCell = pUp->IsCellFrm() ? pUp : 0;
            USHORT nType = bMove ? FRM_ROOT   | FRM_FLY | FRM_HEADER |
                                   FRM_FOOTER | FRM_FTN
                                 : FRM_BODY   | FRM_FLY | FRM_HEADER |
                                   FRM_FOOTER | FRM_CELL| FRM_FTN;

            while ( !(pUp->GetType() & nType) || pUp->IsColBodyFrm() )
            {
                pUp = pUp->GetUpper();
                if ( !pCell && pUp->IsCellFrm() )
                    pCell = pUp;
            }
            if ( bMove )
            {
                if ( pUp->IsRootFrm() )
                {
                    rRect  = pUp->Prt();
                    rRect += pUp->Frm().Pos();
                    pUp = 0;
                }
            }
            if ( pUp )
            {
                if ( !pUp->IsFooterFrm() && ( !pUp->IsFlyFrm() ||
                     (!pUp->Lower() || !pUp->Lower()->IsColumnFrm()) ) )
                    pUp->Calc();
                if ( pUp->GetType() & FRM_BODY )
                {
                    const SwPageFrm *pPg;
                    if ( pUp->GetUpper() != (pPg = pFly->FindPageFrm()) )
                        pUp = pPg->FindBodyCont();
                    rRect = pUp->GetUpper()->Frm();
                    (rRect.*fnRect->fnSetTop)( (pUp->*fnRect->fnGetPrtTop)() );
                    (rRect.*fnRect->fnSetBottom)((pUp->*fnRect->fnGetPrtBottom)());
                }
                else
                {
                    if( ( pUp->GetType() & (FRM_FLY | FRM_FTN ) ) &&
                        !pUp->Frm().IsInside( pFly->Frm().Pos() ) )
                    {
                        if( pUp->IsFlyFrm() )
                        {
                            SwFlyFrm *pTmpFly = (SwFlyFrm*)pUp;
                            while( pTmpFly->GetNextLink() )
                            {
                                pTmpFly = pTmpFly->GetNextLink();
                                if( pTmpFly->Frm().IsInside( pFly->Frm().Pos() ) )
                                    break;
                            }
                            pUp = pTmpFly;
                        }
                        else if( pUp->IsInFtn() )
                        {
                            const SwFtnFrm *pTmp = pUp->FindFtnFrm();
                            while( pTmp->GetFollow() )
                            {
                                pTmp = pTmp->GetFollow();
                                if( pTmp->Frm().IsInside( pFly->Frm().Pos() ) )
                                    break;
                            }
                            pUp = pTmp;
                        }
                    }
                    rRect = pUp->Prt();
                    rRect.Pos() += pUp->Frm().Pos();
                    if ( pUp->GetType() & (FRM_HEADER | FRM_FOOTER) )
                    {
                        rRect.Left ( pUp->GetUpper()->Frm().Left() );
                        rRect.Width( pUp->GetUpper()->Frm().Width());
                    }
                    else if ( pUp->IsCellFrm() )				//MA_FLY_HEIGHT
                    {
                        const SwFrm *pTab = pUp->FindTabFrm();
                        (rRect.*fnRect->fnSetBottom)(
                                    (pTab->GetUpper()->*fnRect->fnGetPrtBottom)() );
                    }
                }
            }
            if ( pCell )
            {
                //CellFrms koennen auch in 'unerlaubten' Bereichen stehen, dann
                //darf der Fly das auch.
                SwRect aTmp( pCell->Prt() );
                aTmp += pCell->Frm().Pos();
                rRect.Union( aTmp );
            }
        }
        else
        {
            const SwFrm *pUp = pFly->GetAnchor()->GetUpper();
            if( !pUp->IsFooterFrm() )
                pUp->Calc();
            SWRECTFN( pFly->GetAnchor() )
            while( pUp->IsColumnFrm() || pUp->IsSctFrm() || pUp->IsColBodyFrm())
                pUp = pUp->GetUpper();
            rRect = pUp->Frm();
            if( !pUp->IsBodyFrm() )
            {
                rRect += pUp->Prt().Pos();
                rRect.SSize( pUp->Prt().SSize() );
                if ( pUp->IsCellFrm() )
                {
                    const SwFrm *pTab = pUp->FindTabFrm();
                    (rRect.*fnRect->fnSetBottom)(
                                    (pTab->GetUpper()->*fnRect->fnGetPrtBottom)() );
                }
            }
            long nHeight = (9*(rRect.*fnRect->fnGetHeight)())/10;
            long nTop;
            const SwFmt *pFmt = ((SwContact*)GetUserCall(pSdrObj))->GetFmt();
            const SvxULSpaceItem &rUL = pFmt->GetULSpace();
            if( bMove )
            {
                nTop = bVert ? ((SwFlyInCntFrm*)pFly)->GetRefPoint().X() :
                               ((SwFlyInCntFrm*)pFly)->GetRefPoint().Y();
                nTop = (*fnRect->fnYInc)( nTop, -nHeight );
                long nWidth = (pFly->Frm().*fnRect->fnGetWidth)();
                (rRect.*fnRect->fnSetLeftAndWidth)( bVert ?
                            ((SwFlyInCntFrm*)pFly)->GetRefPoint().Y() :
                            ((SwFlyInCntFrm*)pFly)->GetRefPoint().X(), nWidth );
                nHeight = 2*nHeight - rUL.GetLower() - rUL.GetUpper();
            }
            else
            {
                nTop = (*fnRect->fnYInc)( (pFly->Frm().*fnRect->fnGetBottom)(),
                                           rUL.GetLower() - nHeight );
                nHeight = 2*nHeight - (pFly->Frm().*fnRect->fnGetHeight)()
                          - rUL.GetLower() - rUL.GetUpper();
            }
            (rRect.*fnRect->fnSetTopAndHeight)( nTop, nHeight );
        }
    }
    else
    {
        const SwDrawContact *pC = (const SwDrawContact*)GetUserCall(pSdrObj);
        const SwFrmFmt  *pFmt = (const SwFrmFmt*)pC->GetFmt();
        const SwFmtAnchor &rAnch = pFmt->GetAnchor();
        if ( FLY_IN_CNTNT == rAnch.GetAnchorId() )
        {
            const SwFrm *pFrm = pC->GetAnchor();
            if( !pFrm )
            {
                ((SwDrawContact*)pC)->ConnectToLayout();
                pFrm = pC->GetAnchor();
            }
            const SwFrm *pUp = pFrm->GetUpper();
            if( !pUp->IsFooterFrm() )
                pUp->Calc();
            rRect = pUp->Prt();
            rRect += pUp->Frm().Pos();
            SWRECTFN( pFrm )
            long nHeight = (9*(rRect.*fnRect->fnGetHeight)())/10;
            long nTop;
            const SvxULSpaceItem &rUL = pFmt->GetULSpace();
            SwRect aSnapRect( pSdrObj->GetSnapRect() );
            long nTmpH = 0;
            if( bMove )
            {
                nTop = (*fnRect->fnYInc)( bVert ? pSdrObj->GetAnchorPos().X() :
                                       pSdrObj->GetAnchorPos().Y(), -nHeight );
                long nWidth = (aSnapRect.*fnRect->fnGetWidth)();
                (rRect.*fnRect->fnSetLeftAndWidth)( bVert ?
                            pSdrObj->GetAnchorPos().Y() :
                            pSdrObj->GetAnchorPos().X(), nWidth );
            }
            else
            {
                nTop = (*fnRect->fnYInc)( (aSnapRect.*fnRect->fnGetTop)(),
                                          rUL.GetLower() + nTmpH - nHeight );
                nTmpH = bVert ? pSdrObj->GetBoundRect().GetWidth() :
                                pSdrObj->GetBoundRect().GetHeight();
            }
            nHeight = 2*nHeight - nTmpH - rUL.GetLower() - rUL.GetUpper();
            (rRect.*fnRect->fnSetTopAndHeight)( nTop, nHeight );
        }
        else
        {
            // OD 23.06.2003 #108784# - restrict clip rectangle for drawing
            // objects in header/footer to the page frame.
            const SwFrm* pAnchorFrm = 0L;
            if ( pSdrObj->ISA(SwDrawVirtObj) )
            {
                pAnchorFrm = static_cast<const SwDrawVirtObj*>(pSdrObj)->GetAnchorFrm();
            }
            else
            {
                pAnchorFrm = pC->GetAnchor();
            }
            if ( pAnchorFrm && pAnchorFrm->FindFooterOrHeader() )
            {
                // clip frame is the page frame the header/footer is on.
                const SwFrm* pClipFrm = pAnchorFrm->FindPageFrm();
                rRect = pClipFrm->Frm();
            }
            else
            {
                bRet = FALSE;
            }
        }
    }
    return bRet;
}


}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */