xref: /aoo41x/main/sw/source/ui/frmdlg/wrap.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #ifdef SW_DLLIMPLEMENTATION
32 #undef SW_DLLIMPLEMENTATION
33 #endif
34 
35 
36 #include "hintids.hxx"
37 #include <vcl/graph.hxx>
38 #include <svx/htmlmode.hxx>
39 #include <sfx2/objsh.hxx>
40 #include <svl/intitem.hxx>
41 #include <editeng/opaqitem.hxx>
42 #include <editeng/ulspitem.hxx>
43 #include <editeng/lrspitem.hxx>
44 // OD 18.09.2003 #i18732#
45 #include <fmtfollowtextflow.hxx>
46 #include <svx/swframevalidation.hxx>
47 
48 
49 #include "cmdid.h"
50 #include "uitool.hxx"
51 #include "wrtsh.hxx"
52 #include "swmodule.hxx"
53 #include "viewopt.hxx"
54 #include "frmatr.hxx"
55 #include "frmmgr.hxx"
56 #include "globals.hrc"
57 #include "frmui.hrc"
58 #include "wrap.hrc"
59 #include "wrap.hxx"
60 
61 using namespace ::com::sun::star;
62 
63 
64 /*--------------------------------------------------------------------
65 	Beschreibung:
66  --------------------------------------------------------------------*/
67 
68 static sal_uInt16 __FAR_DATA aWrapPageRg[] = {
69 	RES_LR_SPACE, RES_UL_SPACE,
70 	RES_PROTECT, RES_SURROUND,
71 	RES_PRINT, RES_PRINT,
72 	0
73 };
74 
75 
76 /*--------------------------------------------------------------------
77 	Beschreibung:
78  --------------------------------------------------------------------*/
79 
80 
81 
82 SwWrapDlg::SwWrapDlg(Window* pParent, SfxItemSet& rSet, SwWrtShell* pSh, sal_Bool bDrawMode) :
83 	SfxSingleTabDialog(pParent, rSet, 0),
84 	pWrtShell(pSh)
85 
86 {
87 	// TabPage erzeugen
88     SwWrapTabPage* pNewPage = (SwWrapTabPage*) SwWrapTabPage::Create(this, rSet);
89     pNewPage->SetFormatUsed(sal_False, bDrawMode);
90     pNewPage->SetShell(pWrtShell);
91     SetTabPage(pNewPage);
92 
93 	String sTitle(SW_RES(STR_FRMUI_WRAP));
94 	SetText(sTitle);
95 }
96 
97 
98 
99 SwWrapDlg::~SwWrapDlg()
100 {
101 }
102 
103 /*--------------------------------------------------------------------
104 	Beschreibung:
105  --------------------------------------------------------------------*/
106 
107 
108 
109 SwWrapTabPage::SwWrapTabPage(Window *pParent, const SfxItemSet &rSet) :
110 	SfxTabPage(pParent, SW_RES(TP_FRM_WRAP), rSet),
111 
112     aWrapFLC           (this, SW_RES(C_WRAP_FL)),
113 	aNoWrapRB			(this, SW_RES(RB_NO_WRAP)),
114 	aWrapLeftRB			(this, SW_RES(RB_WRAP_LEFT)),
115 	aWrapRightRB		(this, SW_RES(RB_WRAP_RIGHT)),
116 	aWrapParallelRB		(this, SW_RES(RB_WRAP_PARALLEL)),
117 	aWrapThroughRB		(this, SW_RES(RB_WRAP_THROUGH)),
118 	aIdealWrapRB		(this, SW_RES(RB_WRAP_IDEAL)),
119 
120     aMarginFL           (this, SW_RES(FL_MARGIN)),
121     aLeftMarginFT       (this, SW_RES(FT_LEFT_MARGIN)),
122     aLeftMarginED       (this, SW_RES(ED_LEFT_MARGIN)),
123     aRightMarginFT      (this, SW_RES(FT_RIGHT_MARGIN)),
124     aRightMarginED      (this, SW_RES(ED_RIGHT_MARGIN)),
125     aTopMarginFT        (this, SW_RES(FT_TOP_MARGIN)),
126     aTopMarginED        (this, SW_RES(ED_TOP_MARGIN)),
127     aBottomMarginFT     (this, SW_RES(FT_BOTTOM_MARGIN)),
128     aBottomMarginED     (this, SW_RES(ED_BOTTOM_MARGIN)),
129 
130     aOptionsSepFL       (this, SW_RES(FL_OPTION_SEP)),
131     aOptionsFL          (this, SW_RES(FL_OPTION)),
132     aWrapAnchorOnlyCB   (this, SW_RES(CB_ANCHOR_ONLY)),
133 	aWrapTransparentCB	(this, SW_RES(CB_TRANSPARENT)),
134 	aWrapOutlineCB		(this, SW_RES(CB_OUTLINE)),
135 	aWrapOutsideCB		(this, SW_RES(CB_ONLYOUTSIDE)),
136 
137     aWrapIL             (SW_RES(IL_WRAP)),
138     aWrapILH            (SW_RES(ILH_WRAP)),
139 
140     nAnchorId(FLY_AT_PARA),
141     nHtmlMode(0),
142 
143     pWrtSh(0),
144 
145     bFormat(sal_False),
146 	bNew(sal_True),
147 	bHtmlMode(sal_False),
148     bContourImage(sal_False)
149 
150 {
151 	FreeResource();
152 	SetExchangeSupport();
153 
154 	Link aLk = LINK(this, SwWrapTabPage, RangeModifyHdl);
155 	aLeftMarginED.SetUpHdl(aLk);
156 	aLeftMarginED.SetDownHdl(aLk);
157 	aLeftMarginED.SetFirstHdl(aLk);
158 	aLeftMarginED.SetLastHdl(aLk);
159 	aLeftMarginED.SetLoseFocusHdl(aLk);
160 
161 	aRightMarginED.SetUpHdl(aLk);
162 	aRightMarginED.SetDownHdl(aLk);
163 	aRightMarginED.SetFirstHdl(aLk);
164 	aRightMarginED.SetLastHdl(aLk);
165 	aRightMarginED.SetLoseFocusHdl(aLk);
166 
167 	aTopMarginED.SetUpHdl(aLk);
168 	aTopMarginED.SetDownHdl(aLk);
169 	aTopMarginED.SetFirstHdl(aLk);
170 	aTopMarginED.SetLastHdl(aLk);
171 	aTopMarginED.SetLoseFocusHdl(aLk);
172 
173 	aBottomMarginED.SetUpHdl(aLk);
174 	aBottomMarginED.SetDownHdl(aLk);
175 	aBottomMarginED.SetFirstHdl(aLk);
176 	aBottomMarginED.SetLastHdl(aLk);
177 	aBottomMarginED.SetLoseFocusHdl(aLk);
178 
179 	aLk = LINK(this, SwWrapTabPage, WrapTypeHdl);
180 	aNoWrapRB.SetClickHdl(aLk);
181 	aWrapLeftRB.SetClickHdl(aLk);
182 	aWrapRightRB.SetClickHdl(aLk);
183 	aWrapParallelRB.SetClickHdl(aLk);
184 	aWrapThroughRB.SetClickHdl(aLk);
185 	aIdealWrapRB.SetClickHdl(aLk);
186     ApplyImageList();
187 	aWrapOutlineCB.SetClickHdl(LINK(this, SwWrapTabPage, ContourHdl));
188 }
189 
190 
191 
192 SwWrapTabPage::~SwWrapTabPage()
193 {
194 }
195 
196 
197 
198 SfxTabPage* SwWrapTabPage::Create(Window *pParent, const SfxItemSet &rSet)
199 {
200 	return new SwWrapTabPage(pParent, rSet);
201 }
202 /*--------------------------------------------------------------------
203 	Beschreibung:
204  --------------------------------------------------------------------*/
205 
206 
207 
208 void SwWrapTabPage::Reset(const SfxItemSet &rSet)
209 {
210 	//Contour fuer Draw, Grafik und OLE (Einfuegen/Grafik/Eigenschaften fehlt noch!)
211 	if( bDrawMode )
212 	{
213 		aWrapOutlineCB.Show();
214 		aWrapOutsideCB.Show();
215 
216 		aWrapTransparentCB.Check( 0 == ((const SfxInt16Item&)rSet.Get(
217 										FN_DRAW_WRAP_DLG)).GetValue() );
218 		aWrapTransparentCB.SaveValue();
219 	}
220 	else
221 	{
222 		sal_Bool bShowCB = bFormat;
223 		if( !bFormat )
224 		{
225 			int nSelType = pWrtSh->GetSelectionType();
226 			if( ( nSelType & nsSelectionType::SEL_GRF ) ||
227 			    ( nSelType & nsSelectionType::SEL_OLE && GRAPHIC_NONE !=
228 				            pWrtSh->GetIMapGraphic().GetType() ))
229 				bShowCB = sal_True;
230 		}
231 		if( bShowCB )
232 		{
233 			aWrapOutlineCB.Show();
234 			aWrapOutsideCB.Show();
235 		}
236 	}
237 
238 	nHtmlMode = ::GetHtmlMode((const SwDocShell*)SfxObjectShell::Current());
239 	bHtmlMode = nHtmlMode & HTMLMODE_ON ? sal_True : sal_False;
240 
241 	FieldUnit aMetric = ::GetDfltMetric(bHtmlMode);
242 	SetMetric( aLeftMarginED  , aMetric );
243 	SetMetric( aRightMarginED , aMetric );
244 	SetMetric( aTopMarginED   , aMetric );
245 	SetMetric( aBottomMarginED, aMetric );
246 
247 	const SwFmtSurround& rSurround = (const SwFmtSurround&)rSet.Get(RES_SURROUND);
248 
249     SwSurround nSur = rSurround.GetSurround();
250 	const SwFmtAnchor &rAnch = (const SwFmtAnchor&)rSet.Get(RES_ANCHOR);
251 	nAnchorId = rAnch.GetAnchorId();
252 
253     if (((nAnchorId == FLY_AT_PARA) || (nAnchorId == FLY_AT_CHAR))
254         && (nSur != SURROUND_NONE))
255     {
256 		aWrapAnchorOnlyCB.Check( rSurround.IsAnchorOnly() );
257     }
258 	else
259     {
260 		aWrapAnchorOnlyCB.Enable( sal_False );
261     }
262 
263 	sal_Bool bContour = rSurround.IsContour();
264 	aWrapOutlineCB.Check( bContour );
265 	aWrapOutsideCB.Check( rSurround.IsOutside() );
266 	aWrapThroughRB.Enable(!aWrapOutlineCB.IsChecked());
267 	bContourImage = !bContour;
268 
269 	ImageRadioButton* pBtn = NULL;
270 
271 	switch (nSur)
272 	{
273 		case SURROUND_NONE:
274 		{
275 			pBtn = &aNoWrapRB;
276 			break;
277 		}
278 
279 		case SURROUND_THROUGHT:
280 		{
281 			// transparent ?
282 			pBtn = &aWrapThroughRB;
283 
284 			if (!bDrawMode)
285 			{
286 				const SvxOpaqueItem& rOpaque = (const SvxOpaqueItem&)rSet.Get(RES_OPAQUE);
287 				aWrapTransparentCB.Check(!rOpaque.GetValue());
288 			}
289 			break;
290 		}
291 
292 		case SURROUND_PARALLEL:
293 		{
294 			pBtn = &aWrapParallelRB;
295 			break;
296 		}
297 
298 		case SURROUND_IDEAL:
299 		{
300 			pBtn = &aIdealWrapRB;
301 			break;
302 		}
303 
304 		default:
305 		{
306 			if (nSur == SURROUND_LEFT)
307 				pBtn = &aWrapLeftRB;
308 			else if (nSur == SURROUND_RIGHT)
309 				pBtn = &aWrapRightRB;
310 		}
311 	}
312 	if (pBtn)
313 	{
314 		pBtn->Check();
315 		WrapTypeHdl(pBtn);
316 		// Hier wird fuer Zeichenobjekte, die im Moment auf Durchlauf stehen,
317 		// schon mal der Default "Kontur an" vorbereitet, falls man spaeter auf
318 		// irgendeinen Umlauf umschaltet.
319 		if (bDrawMode && !aWrapOutlineCB.IsEnabled())
320 			aWrapOutlineCB.Check();
321 	}
322 	aWrapTransparentCB.Enable( pBtn == &aWrapThroughRB && !bHtmlMode );
323 
324 	const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)rSet.Get(RES_UL_SPACE);
325 	const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)rSet.Get(RES_LR_SPACE);
326 
327 	// Abstand zum Text
328 	aLeftMarginED.SetValue(aLeftMarginED.Normalize(rLR.GetLeft()), FUNIT_TWIP);
329 	aRightMarginED.SetValue(aRightMarginED.Normalize(rLR.GetRight()), FUNIT_TWIP);
330 	aTopMarginED.SetValue(aTopMarginED.Normalize(rUL.GetUpper()), FUNIT_TWIP);
331 	aBottomMarginED.SetValue(aBottomMarginED.Normalize(rUL.GetLower()), FUNIT_TWIP);
332 
333 	ContourHdl(0);
334 	ActivatePage( rSet );
335 }
336 
337 /*--------------------------------------------------------------------
338 	Beschreibung:	Attribute in den Set stopfen bei OK
339  --------------------------------------------------------------------*/
340 
341 
342 
343 sal_Bool SwWrapTabPage::FillItemSet(SfxItemSet &rSet)
344 {
345 	sal_Bool bModified = sal_False;
346 	const SfxPoolItem* pOldItem;
347 
348 	const SwFmtSurround& rOldSur = (const SwFmtSurround&)GetItemSet().Get(RES_SURROUND);
349 	SwFmtSurround aSur( rOldSur );
350 
351     SvxOpaqueItem aOp( RES_OPAQUE);
352 
353 	if (!bDrawMode)
354 	{
355 		const SvxOpaqueItem& rOpaque = (const SvxOpaqueItem&)GetItemSet().Get(RES_OPAQUE);
356         aOp = rOpaque;
357 		aOp.SetValue(sal_True);
358 	}
359 
360 	if (aNoWrapRB.IsChecked())
361 		aSur.SetSurround(SURROUND_NONE);
362 	else if (aWrapLeftRB.IsChecked())
363 		aSur.SetSurround(SURROUND_LEFT);
364 	else if (aWrapRightRB.IsChecked())
365 		aSur.SetSurround(SURROUND_RIGHT);
366 	else if (aWrapParallelRB.IsChecked())
367 		aSur.SetSurround(SURROUND_PARALLEL);
368 	else if (aWrapThroughRB.IsChecked())
369 	{
370 		aSur.SetSurround(SURROUND_THROUGHT);
371 		if (aWrapTransparentCB.IsChecked() && !bDrawMode)
372 			aOp.SetValue(sal_False);
373 	}
374 	else if (aIdealWrapRB.IsChecked())
375 		aSur.SetSurround(SURROUND_IDEAL);
376 
377 	aSur.SetAnchorOnly( aWrapAnchorOnlyCB.IsChecked() );
378 	sal_Bool bContour = aWrapOutlineCB.IsChecked() && aWrapOutlineCB.IsEnabled();
379 	aSur.SetContour( bContour );
380 
381 	if ( bContour )
382 		aSur.SetOutside(aWrapOutsideCB.IsChecked());
383 
384 	if(0 == (pOldItem = GetOldItem( rSet, RES_SURROUND )) ||
385 				aSur != *pOldItem )
386 	{
387 		rSet.Put(aSur);
388 		bModified = sal_True;
389 	}
390 
391 	if (!bDrawMode)
392 	{
393 		if(0 == (pOldItem = GetOldItem( rSet, FN_OPAQUE )) ||
394 					aOp != *pOldItem )
395 		{
396 			rSet.Put(aOp);
397 			bModified = sal_True;
398 		}
399 	}
400 
401 	sal_Bool bTopMod = aTopMarginED.IsValueModified();
402 	sal_Bool bBottomMod = aBottomMarginED.IsValueModified();
403 
404     SvxULSpaceItem aUL( RES_UL_SPACE );
405 	aUL.SetUpper((sal_uInt16)aTopMarginED.Denormalize(aTopMarginED.GetValue(FUNIT_TWIP)));
406 	aUL.SetLower((sal_uInt16)aBottomMarginED.Denormalize(aBottomMarginED.GetValue(FUNIT_TWIP)));
407 
408 	if ( bTopMod || bBottomMod )
409 	{
410 		if(0 == (pOldItem = GetOldItem(rSet, RES_UL_SPACE)) ||
411 				aUL != *pOldItem )
412 		{
413 			rSet.Put( aUL, RES_UL_SPACE );
414 			bModified = sal_True;
415 		}
416 	}
417 
418 	sal_Bool bLeftMod = aLeftMarginED.IsValueModified();
419 	sal_Bool bRightMod = aRightMarginED.IsValueModified();
420 
421     SvxLRSpaceItem aLR( RES_LR_SPACE );
422 	aLR.SetLeft((sal_uInt16)aLeftMarginED.Denormalize(aLeftMarginED.GetValue(FUNIT_TWIP)));
423 	aLR.SetRight((sal_uInt16)aRightMarginED.Denormalize(aRightMarginED.GetValue(FUNIT_TWIP)));
424 
425 	if ( bLeftMod || bRightMod )
426 	{
427 		if( 0 == (pOldItem = GetOldItem(rSet, RES_LR_SPACE)) ||
428 				aLR != *pOldItem )
429 		{
430 			rSet.Put(aLR, RES_LR_SPACE);
431 			bModified = sal_True;
432 		}
433 	}
434 
435 	if ( bDrawMode )
436 	{
437 		sal_Bool bChecked = aWrapTransparentCB.IsChecked() & aWrapTransparentCB.IsEnabled();
438 		if (aWrapTransparentCB.GetSavedValue() != bChecked)
439 			bModified |= 0 != rSet.Put(SfxInt16Item(FN_DRAW_WRAP_DLG, bChecked ? 0 : 1));
440 	}
441 
442 	return bModified;
443 }
444 
445 /*--------------------------------------------------------------------
446 	Beschreibung:	Bsp - Update
447  --------------------------------------------------------------------*/
448 
449 
450 
451 void SwWrapTabPage::ActivatePage(const SfxItemSet& rSet)
452 {
453 	// Anchor
454 	const SwFmtAnchor &rAnch = (const SwFmtAnchor&)rSet.Get(RES_ANCHOR);
455 	nAnchorId = rAnch.GetAnchorId();
456     sal_Bool bEnable = (nAnchorId != FLY_AS_CHAR);
457 
458 	if (!bDrawMode)
459 	{
460 		SwWrtShell* pSh = bFormat ? ::GetActiveWrtShell() : pWrtSh;
461 		SwFlyFrmAttrMgr aMgr( bNew, pSh, (const SwAttrSet&)GetItemSet() );
462         SvxSwFrameValidation aVal;
463 
464 		// Size
465 		const SwFmtFrmSize& rFrmSize = (const SwFmtFrmSize&)rSet.Get(RES_FRM_SIZE);
466 		Size aSize = rFrmSize.GetSize();
467 
468 		// Rand
469 		const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)rSet.Get(RES_UL_SPACE);
470 		const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)rSet.Get(RES_LR_SPACE);
471         nOldLeftMargin  = static_cast< sal_uInt16 >(rLR.GetLeft());
472         nOldRightMargin = static_cast< sal_uInt16 >(rLR.GetRight());
473         nOldUpperMargin = static_cast< sal_uInt16 >(rUL.GetUpper());
474         nOldLowerMargin = static_cast< sal_uInt16 >(rUL.GetLower());
475 
476 		// Position
477 		const SwFmtHoriOrient& rHori = (const SwFmtHoriOrient&)rSet.Get(RES_HORI_ORIENT);
478 		const SwFmtVertOrient& rVert = (const SwFmtVertOrient&)rSet.Get(RES_VERT_ORIENT);
479 
480         aVal.nAnchorType = static_cast< sal_Int16 >(nAnchorId);
481 		aVal.bAutoHeight = rFrmSize.GetHeightSizeType() == ATT_MIN_SIZE;
482 		aVal.bAutoWidth = rFrmSize.GetWidthSizeType() == ATT_MIN_SIZE;
483 		aVal.bMirror = rHori.IsPosToggle();
484         // OD 18.09.2003 #i18732#
485         aVal.bFollowTextFlow =
486             static_cast<const SwFmtFollowTextFlow&>(rSet.Get(RES_FOLLOW_TEXT_FLOW)).GetValue();
487 
488         aVal.nHoriOrient = (short)rHori.GetHoriOrient();
489         aVal.nVertOrient = (short)rVert.GetVertOrient();
490 
491 		aVal.nHPos = rHori.GetPos();
492         aVal.nHRelOrient = rHori.GetRelationOrient();
493 		aVal.nVPos = rVert.GetPos();
494         aVal.nVRelOrient = rVert.GetRelationOrient();
495 
496 		if (rFrmSize.GetWidthPercent() && rFrmSize.GetWidthPercent() != 0xff)
497 			aSize.Width() = aSize.Width() * rFrmSize.GetWidthPercent() / 100;
498 
499 		if (rFrmSize.GetHeightPercent() && rFrmSize.GetHeightPercent() != 0xff)
500 			aSize.Height() = aSize.Height() * rFrmSize.GetHeightPercent() / 100;
501 
502 		aVal.nWidth  = aSize.Width();
503 		aVal.nHeight = aSize.Height();
504 		aFrmSize = aSize;
505 
506         aMgr.ValidateMetrics(aVal, 0);
507 
508 		SwTwips nLeft;
509 		SwTwips nRight;
510 		SwTwips nTop;
511 		SwTwips nBottom;
512 
513 		nLeft	= aVal.nHPos - aVal.nMinHPos;
514 		nRight	= aVal.nMaxWidth - aVal.nWidth;
515 		nTop	= aVal.nVPos - aVal.nMinVPos;
516 		nBottom	= aVal.nMaxHeight - aVal.nHeight;
517 
518 		if (bHtmlMode && 0 == (nHtmlMode & HTMLMODE_FULL_ABS_POS))
519 		{
520 			nLeft = nRight = ( nLeft + nRight ) / 2;
521 			nTop = nBottom = ( nTop + nBottom ) / 2;
522 		}
523 		else
524 		{
525             if (aVal.nAnchorType == FLY_AS_CHAR)
526 			{
527 				nLeft = nRight;
528 
529 				if (aVal.nVPos < 0)
530 				{
531 					if (aVal.nVPos <= aVal.nMaxHeight)
532 						nTop = aVal.nMaxVPos - aVal.nHeight;
533 					else
534 						nTop = nBottom = 0;	// Kein Umlauf
535 				}
536 				else
537 					nTop = aVal.nMaxVPos - aVal.nHeight - aVal.nVPos;
538 			}
539 			else
540 			{
541 				nLeft += nRight;
542 				nTop += nBottom;
543 			}
544 
545 			nBottom	= nTop;
546 			nRight = nLeft;
547 		}
548 
549 		aLeftMarginED.SetMax(aLeftMarginED.Normalize(nLeft), FUNIT_TWIP);
550 		aRightMarginED.SetMax(aRightMarginED.Normalize(nRight), FUNIT_TWIP);
551 
552 		aTopMarginED.SetMax(aTopMarginED.Normalize(nTop), FUNIT_TWIP);
553 		aBottomMarginED.SetMax(aBottomMarginED.Normalize(nBottom), FUNIT_TWIP);
554 
555 		RangeModifyHdl(&aLeftMarginED);
556 		RangeModifyHdl(&aTopMarginED);
557 	}
558 
559 	const SwFmtSurround& rSurround = (const SwFmtSurround&)rSet.Get(RES_SURROUND);
560     SwSurround nSur = rSurround.GetSurround();
561 
562 	aWrapTransparentCB.Enable( bEnable && !bHtmlMode && nSur == SURROUND_THROUGHT );
563 	if(bHtmlMode)
564 	{
565 		sal_Bool bSomeAbsPos = 0 != (nHtmlMode & HTMLMODE_SOME_ABS_POS);
566 		const SwFmtHoriOrient& rHori = (const SwFmtHoriOrient&)rSet.Get(RES_HORI_ORIENT);
567         sal_Int16 eHOrient = rHori.GetHoriOrient();
568         sal_Int16 eHRelOrient = rHori.GetRelationOrient();
569 		aWrapOutlineCB.Hide();
570         const bool bAllHtmlModes =
571             ((nAnchorId == FLY_AT_PARA) || (nAnchorId == FLY_AT_CHAR)) &&
572                             (eHOrient == text::HoriOrientation::RIGHT || eHOrient == text::HoriOrientation::LEFT);
573 		aWrapAnchorOnlyCB.Enable( bAllHtmlModes && nSur != SURROUND_NONE );
574 		aWrapOutsideCB.Hide();
575 		aIdealWrapRB.Enable( sal_False );
576 
577 
578 		aWrapTransparentCB.Enable( sal_False );
579         aNoWrapRB.Enable( FLY_AT_PARA == nAnchorId );
580 		aWrapParallelRB.Enable( sal_False  );
581         aWrapLeftRB       .Enable
582                     (  (FLY_AT_PARA == nAnchorId)
583                     || (   (FLY_AT_CHAR == nAnchorId)
584                         && (eHOrient == text::HoriOrientation::RIGHT)
585                         && (eHRelOrient == text::RelOrientation::PRINT_AREA)));
586         aWrapRightRB      .Enable
587                     (  (FLY_AT_PARA == nAnchorId)
588                     || (   (FLY_AT_CHAR == nAnchorId)
589                         && (eHOrient == text::HoriOrientation::LEFT)
590                         && (eHRelOrient == text::RelOrientation::PRINT_AREA)));
591 
592         aWrapThroughRB.Enable
593                 (   (  (FLY_AT_PAGE == nAnchorId)
594                     || (   (FLY_AT_CHAR == nAnchorId)
595                         && (eHRelOrient != text::RelOrientation::PRINT_AREA))
596                     || (FLY_AT_PARA == nAnchorId))
597                 && bSomeAbsPos
598                 && (eHOrient != text::HoriOrientation::RIGHT));
599 		if(aNoWrapRB.IsChecked() && !aNoWrapRB.IsEnabled())
600 		{
601 			if(aWrapThroughRB.IsEnabled())
602 				aWrapThroughRB.Check(sal_True);
603 			else if(aWrapLeftRB.IsEnabled())
604 				aWrapLeftRB.Check();
605 			else if(aWrapRightRB.IsEnabled())
606 				aWrapRightRB.Check();
607 
608 		}
609 		if(aWrapLeftRB.IsChecked() && !aWrapLeftRB.IsEnabled())
610 		{
611 			if(aWrapRightRB.IsEnabled())
612 				aWrapRightRB.Check();
613 			else if(aWrapThroughRB.IsEnabled())
614 				aWrapThroughRB.Check();
615 		}
616 		if(aWrapRightRB.IsChecked() && !aWrapRightRB.IsEnabled())
617 		{
618 			if(aWrapLeftRB.IsEnabled())
619 				aWrapLeftRB.Check();
620 			else if(aWrapThroughRB.IsEnabled())
621 				aWrapThroughRB.Check();
622 		}
623 		if(aWrapThroughRB.IsChecked() && !aWrapThroughRB.IsEnabled())
624 			if(aNoWrapRB.IsEnabled())
625 				aNoWrapRB.Check();
626 
627 		if(aWrapParallelRB.IsChecked() && !aWrapParallelRB.IsEnabled())
628 			aWrapThroughRB.Check();
629 	}
630 	else
631 	{
632 		aNoWrapRB.Enable( bEnable );
633 		aWrapLeftRB.Enable( bEnable );
634 		aWrapRightRB.Enable( bEnable );
635 		aIdealWrapRB.Enable( bEnable );
636 		aWrapThroughRB.Enable( bEnable );
637 		aWrapParallelRB.Enable( bEnable );
638         aWrapAnchorOnlyCB.Enable(
639                 ((nAnchorId == FLY_AT_PARA) || (nAnchorId == FLY_AT_CHAR))
640 				&& nSur != SURROUND_NONE );
641 	}
642 	ContourHdl(0);
643 }
644 
645 
646 
647 int SwWrapTabPage::DeactivatePage(SfxItemSet* _pSet)
648 {
649     if(_pSet)
650         FillItemSet(*_pSet);
651 
652 	return sal_True;
653 }
654 
655 /*--------------------------------------------------------------------
656 	Beschreibung:	Bereichspruefung
657  --------------------------------------------------------------------*/
658 
659 
660 
661 IMPL_LINK( SwWrapTabPage, RangeModifyHdl, MetricField *, pEdit )
662 {
663 	if(bHtmlMode && 0 == (nHtmlMode & HTMLMODE_FULL_ABS_POS))
664 	{
665         sal_Int64 nValue = pEdit->GetValue();
666 		if (pEdit == &aLeftMarginED)
667 			aRightMarginED.SetUserValue(nValue, FUNIT_NONE);
668 		else if (pEdit == &aRightMarginED)
669 			aLeftMarginED.SetUserValue(nValue, FUNIT_NONE);
670 		else if (pEdit == &aTopMarginED)
671 			aBottomMarginED.SetUserValue(nValue, FUNIT_NONE);
672 		else if (pEdit == &aBottomMarginED)
673 			aTopMarginED.SetUserValue(nValue, FUNIT_NONE);
674 	}
675 	else
676 	{
677         sal_Int64 nValue = pEdit->GetValue();
678         MetricField *pOpposite = 0;
679 
680 		if (pEdit == &aLeftMarginED)
681 			pOpposite = &aRightMarginED;
682 		else if (pEdit == &aRightMarginED)
683 			pOpposite = &aLeftMarginED;
684 		else if (pEdit == &aTopMarginED)
685 			pOpposite = &aBottomMarginED;
686 		else if (pEdit == &aBottomMarginED)
687 			pOpposite = &aTopMarginED;
688 
689         sal_Int64 nOpposite = pOpposite->GetValue();
690 
691 		if (nValue + nOpposite > Max(pEdit->GetMax(), pOpposite->GetMax()))
692 			pOpposite->SetValue(pOpposite->GetMax() - nValue);
693 	}
694 
695 	return 0;
696 }
697 
698 /*--------------------------------------------------------------------
699 	Beschreibung:
700  --------------------------------------------------------------------*/
701 
702 
703 
704 IMPL_LINK( SwWrapTabPage, WrapTypeHdl, ImageRadioButton *, pBtn )
705 {
706 	sal_Bool bWrapThrough = (pBtn == &aWrapThroughRB);
707 	aWrapTransparentCB.Enable( bWrapThrough && !bHtmlMode );
708     bWrapThrough |= ( nAnchorId == FLY_AS_CHAR );
709 	aWrapOutlineCB.Enable( !bWrapThrough && pBtn != &aNoWrapRB);
710 	aWrapOutsideCB.Enable( !bWrapThrough && aWrapOutlineCB.IsChecked() );
711     aWrapAnchorOnlyCB.Enable(
712         ((nAnchorId == FLY_AT_PARA) || (nAnchorId == FLY_AT_CHAR)) &&
713 		(pBtn != &aNoWrapRB) );
714 
715 	ContourHdl(0);
716 	return 0;
717 }
718 
719 /*--------------------------------------------------------------------
720 	Beschreibung:
721  --------------------------------------------------------------------*/
722 
723 
724 
725 IMPL_LINK( SwWrapTabPage, ContourHdl, CheckBox *, EMPTYARG )
726 {
727 	sal_Bool bEnable = !(aWrapOutlineCB.IsChecked() && aWrapOutlineCB.IsEnabled());
728 
729 	aWrapOutsideCB.Enable(!bEnable);
730 
731 	bEnable =  !aWrapOutlineCB.IsChecked();
732 	if (bEnable == bContourImage) // damit es nicht immer flackert
733 	{
734         bContourImage = !bEnable;
735         ApplyImageList();
736     }
737 
738 	return 0;
739 }
740 
741 /*--------------------------------------------------------------------
742 	Beschreibung:
743  --------------------------------------------------------------------*/
744 sal_uInt16* SwWrapTabPage::GetRanges()
745 {
746 	return aWrapPageRg;
747 }
748 /* -----------------------------08.05.2002 14:28------------------------------
749 
750  ---------------------------------------------------------------------------*/
751 void SwWrapTabPage::DataChanged( const DataChangedEvent& rDCEvt )
752 {
753 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
754          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
755             ApplyImageList();
756 
757     SfxTabPage::DataChanged( rDCEvt );
758 }
759 /* -----------------------------08.05.2002 14:28------------------------------
760 
761  ---------------------------------------------------------------------------*/
762 void SwWrapTabPage::ApplyImageList()
763 {
764     ImageList& rImgLst = GetSettings().GetStyleSettings().GetHighContrastMode() ?
765         aWrapILH : aWrapIL;
766 
767     aWrapThroughRB.SetModeRadioImage(rImgLst.GetImage(IMG_THROUGH));
768     sal_Bool bWrapOutline =  !aWrapOutlineCB.IsChecked();
769     if(bWrapOutline)
770     {
771         aNoWrapRB.SetModeRadioImage(rImgLst.GetImage(IMG_NONE));
772         aWrapLeftRB.SetModeRadioImage(rImgLst.GetImage(IMG_LEFT));
773         aWrapRightRB.SetModeRadioImage(rImgLst.GetImage(IMG_RIGHT));
774         aWrapParallelRB.SetModeRadioImage(rImgLst.GetImage(IMG_PARALLEL));
775         aIdealWrapRB.SetModeRadioImage(rImgLst.GetImage(IMG_IDEAL));
776     }
777     else
778     {
779         aNoWrapRB.SetModeRadioImage(rImgLst.GetImage( IMG_KON_NONE ));
780         aWrapLeftRB.SetModeRadioImage(rImgLst.GetImage( IMG_KON_LEFT ));
781         aWrapRightRB.SetModeRadioImage(rImgLst.GetImage( IMG_KON_RIGHT ));
782         aWrapParallelRB.SetModeRadioImage(rImgLst.GetImage(IMG_KON_PARALLEL ));
783         aIdealWrapRB.SetModeRadioImage(rImgLst.GetImage( IMG_KON_IDEAL ));
784     }
785 }
786