xref: /aoo42x/main/cui/source/tabpages/border.cxx (revision 2ee96f1c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <sfx2/app.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <sfx2/module.hxx>
31 #include <svx/dialogs.hrc>
32 #include <svx/dialmgr.hxx>
33 #define _SVX_BORDER_CXX
34 
35 #include <cuires.hrc>
36 #include "border.hrc"
37 #include "helpid.hrc"
38 
39 #define LINESTYLE_HTML_MAX 5
40 
41 #include <svx/xtable.hxx>				// XColorTable
42 #include <svx/drawitem.hxx>
43 #include <editeng/boxitem.hxx>
44 #include <editeng/shaditem.hxx>
45 #include "border.hxx"
46 #include <svx/dlgutil.hxx>
47 #include <dialmgr.hxx>
48 #include "svx/htmlmode.hxx"
49 #include <vcl/msgbox.hxx>
50 #include "svx/flagsdef.hxx"	//CHINA001
51 #include <sfx2/request.hxx>
52 #include <svl/intitem.hxx> //CHINA001
53 #include <sfx2/itemconnect.hxx>
54 #include "borderconn.hxx"
55 
56 // -----------------------------------------------------------------------
57 
58 /*
59  * [Beschreibung:]
60  * TabPage zum Einstellen der Rahmen-Attribute.
61  * Benoetigt
62  *		ein SvxShadowItem: Schatten
63  *		ein SvxBoxItem:    Linien links,rechts,oben,unten ),
64  *		ein SvxBoxInfo:    Linien vertikal,horizontal, Abstaende, Flags )
65  *
66  * Linien koennen drei Zustaende haben.
67  *		1. Show		( -> gueltige Werte )
68  *		2. Hide		( -> NULL-Pointer )
69  *		3. DontCare ( -> gesonderte Valid-Flags im InfoItem )
70  */
71 
72 // static ----------------------------------------------------------------
73 
74 static sal_uInt16 pRanges[] =
75 {
76     SID_ATTR_BORDER_INNER,      SID_ATTR_BORDER_SHADOW,
77     SID_ATTR_ALIGN_MARGIN,      SID_ATTR_ALIGN_MARGIN,
78     SID_ATTR_BORDER_CONNECT,    SID_ATTR_BORDER_CONNECT,
79     SID_SW_COLLAPSING_BORDERS,  SID_SW_COLLAPSING_BORDERS,
80     SID_ATTR_BORDER_DIAG_TLBR,  SID_ATTR_BORDER_DIAG_BLTR,
81 	0
82 };
83 
84 sal_Bool SvxBorderTabPage::bSync = sal_True;
85 
86 
87 //------------------------------------------------------------------------
88 
89 #define LINE_WIDTH0		(DEF_LINE_WIDTH_0 *100)
90 #define LINE_WIDTH1		(DEF_LINE_WIDTH_1 *100)
91 #define LINE_WIDTH2		(DEF_LINE_WIDTH_2 *100)
92 #define LINE_WIDTH3		(DEF_LINE_WIDTH_3 *100)
93 #define LINE_WIDTH4		(DEF_LINE_WIDTH_4 *100)
94 #define LINE_WIDTH5     (DEF_LINE_WIDTH_5 *100)
95 
96 #define DLINE0_OUT		(DEF_DOUBLE_LINE0_OUT  *100)
97 #define DLINE0_IN		(DEF_DOUBLE_LINE0_IN   *100)
98 #define DLINE0_DIST		(DEF_DOUBLE_LINE0_DIST *100)
99 
100 #define DLINE1_OUT		(DEF_DOUBLE_LINE1_OUT  *100)
101 #define DLINE1_IN		(DEF_DOUBLE_LINE1_IN   *100)
102 #define DLINE1_DIST		(DEF_DOUBLE_LINE1_DIST *100)
103 
104 #define DLINE2_OUT		(DEF_DOUBLE_LINE2_OUT  *100)
105 #define DLINE2_IN		(DEF_DOUBLE_LINE2_IN   *100)
106 #define DLINE2_DIST		(DEF_DOUBLE_LINE2_DIST *100)
107 
108 #define DLINE3_OUT		(DEF_DOUBLE_LINE3_OUT  *100)
109 #define DLINE3_IN		(DEF_DOUBLE_LINE3_IN   *100)
110 #define DLINE3_DIST		(DEF_DOUBLE_LINE3_DIST *100)
111 
112 #define DLINE4_OUT		(DEF_DOUBLE_LINE4_OUT  *100)
113 #define DLINE4_IN		(DEF_DOUBLE_LINE4_IN   *100)
114 #define DLINE4_DIST		(DEF_DOUBLE_LINE4_DIST *100)
115 
116 #define DLINE5_OUT		(DEF_DOUBLE_LINE5_OUT  *100)
117 #define DLINE5_IN		(DEF_DOUBLE_LINE5_IN   *100)
118 #define DLINE5_DIST		(DEF_DOUBLE_LINE5_DIST *100)
119 
120 #define DLINE6_OUT		(DEF_DOUBLE_LINE6_OUT  *100)
121 #define DLINE6_IN		(DEF_DOUBLE_LINE6_IN   *100)
122 #define DLINE6_DIST		(DEF_DOUBLE_LINE6_DIST *100)
123 
124 #define DLINE7_OUT		(DEF_DOUBLE_LINE7_OUT  *100)
125 #define DLINE7_IN		(DEF_DOUBLE_LINE7_IN   *100)
126 #define DLINE7_DIST		(DEF_DOUBLE_LINE7_DIST *100)
127 
128 #define DLINE8_OUT		(DEF_DOUBLE_LINE8_OUT  *100)
129 #define DLINE8_IN		(DEF_DOUBLE_LINE8_IN   *100)
130 #define DLINE8_DIST		(DEF_DOUBLE_LINE8_DIST *100)
131 
132 #define DLINE9_OUT		(DEF_DOUBLE_LINE9_OUT  *100)
133 #define DLINE9_IN		(DEF_DOUBLE_LINE9_IN   *100)
134 #define DLINE9_DIST		(DEF_DOUBLE_LINE9_DIST *100)
135 
136 #define DLINE10_OUT		(DEF_DOUBLE_LINE10_OUT *100)
137 #define DLINE10_IN		(DEF_DOUBLE_LINE10_IN  *100)
138 #define DLINE10_DIST	(DEF_DOUBLE_LINE10_DIST*100)
139 
140 #define RGBCOL(eColorName) (TpBorderRGBColor(eColorName))
141 
142 // LOKALE FUNKTION
143 // Konvertiert in echte RGB-Farben, damit in den Listboxen
144 // endlich mal richtig selektiert werden kann.
145 
146 Color TpBorderRGBColor( ColorData aColorData )
147 {
148 	Color aRGBColor( aColorData );
149 
150 	return( aRGBColor );
151 }
152 
153 // -----------------------------------------------------------------------
154 void lcl_SetDecimalDigitsTo1(MetricField& rField)
155 {
156     sal_Int64 nMin = rField.Denormalize( rField.GetMin( FUNIT_TWIP ) );
157     rField.SetDecimalDigits(1);
158     rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
159 }
160 // -----------------------------------------------------------------------
161 
162 SvxBorderTabPage::SvxBorderTabPage( Window* pParent,
163 									const SfxItemSet& rCoreAttrs )
164 
165 	:	SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_BORDER ), rCoreAttrs ),
166 
167 		aFlBorder       ( this, CUI_RES( FL_BORDER ) ),
168         aDefaultFT      ( this, CUI_RES( FT_DEFAULT ) ),
169         aWndPresets     ( this, CUI_RES( WIN_PRESETS ) ),
170         aUserDefFT      ( this, CUI_RES( FT_USERDEF ) ),
171         aFrameSel       ( this, CUI_RES( WIN_FRAMESEL ) ),
172 
173         aFlSep1         ( this, CUI_RES( FL_SEPARATOR1 ) ),
174         aFlLine         ( this, CUI_RES( FL_LINE ) ),
175         aStyleFT        ( this, CUI_RES( FT_STYLE ) ),
176         aLbLineStyle    ( this, CUI_RES( LB_LINESTYLE ) ),
177         aColorFT        ( this, CUI_RES( FT_COLOR ) ),
178         aLbLineColor    ( this, CUI_RES( LB_LINECOLOR ) ),
179 
180         aFlSep2         ( this, CUI_RES( FL_SEPARATOR2 ) ),
181         aDistanceFL     ( this, CUI_RES( FL_DISTANCE ) ),
182         aLeftFT         ( this, CUI_RES( FT_LEFT ) ),
183         aLeftMF         ( this, CUI_RES( MF_LEFT ) ),
184         aRightFT        ( this, CUI_RES( FT_RIGHT ) ),
185         aRightMF        ( this, CUI_RES( MF_RIGHT ) ),
186         aTopFT          ( this, CUI_RES( FT_TOP ) ),
187         aTopMF          ( this, CUI_RES( MF_TOP ) ),
188         aBottomFT       ( this, CUI_RES( FT_BOTTOM ) ),
189         aBottomMF       ( this, CUI_RES( MF_BOTTOM ) ),
190         aSynchronizeCB  ( this, CUI_RES( CB_SYNC ) ),
191 
192 		aFlShadow       ( this, CUI_RES( FL_SHADOW ) ),
193 		aFtShadowPos    ( this, CUI_RES( FT_SHADOWPOS ) ),
194 		aWndShadows     ( this, CUI_RES( WIN_SHADOWS ) ),
195 		aFtShadowSize   ( this, CUI_RES( FT_SHADOWSIZE ) ),
196 		aEdShadowSize   ( this, CUI_RES( ED_SHADOWSIZE ) ),
197 		aFtShadowColor  ( this, CUI_RES( FT_SHADOWCOLOR ) ),
198 		aLbShadowColor  ( this, CUI_RES( LB_SHADOWCOLOR ) ),
199         aPropertiesFL   ( this, CUI_RES( FL_PROPERTIES ) ),
200         aMergeWithNextCB( this, CUI_RES( CB_MERGEWITHNEXT ) ),
201         aMergeAdjacentBordersCB( this, CUI_RES( CB_MERGEADJACENTBORDERS ) ),
202         aShadowImgLstH( CUI_RES(ILH_SDW_BITMAPS)),
203         aShadowImgLst( CUI_RES(IL_SDW_BITMAPS)),
204         aBorderImgLstH( CUI_RES(ILH_PRE_BITMAPS)),
205         aBorderImgLst( CUI_RES(IL_PRE_BITMAPS)),
206         nMinValue(0),
207         nSWMode(0),
208         mbHorEnabled( false ),
209         mbVerEnabled( false ),
210         mbTLBREnabled( false ),
211         mbBLTREnabled( false ),
212         mbUseMarginItem( false )
213 
214 {
215 	// diese Page braucht ExchangeSupport
216 	SetExchangeSupport();
217 
218     /*  Use SvxMarginItem instead of margins from SvxBoxItem, if present.
219         ->  Remember this state in mbUseMarginItem, because other special handling
220             is needed across various functions... */
221     mbUseMarginItem = rCoreAttrs.GetItemState(GetWhich(SID_ATTR_ALIGN_MARGIN),sal_True) != SFX_ITEM_UNKNOWN;
222 
223 	// Metrik einstellen
224 	FieldUnit eFUnit = GetModuleFieldUnit( rCoreAttrs );
225 
226     if( mbUseMarginItem )
227     {
228         // copied from SvxAlignmentTabPage
229         switch ( eFUnit )
230         {
231             //  #103396# the default value (1pt) can't be accurately represented in
232             //  inches or pica with two decimals, so point is used instead.
233             case FUNIT_PICA:
234             case FUNIT_INCH:
235             case FUNIT_FOOT:
236             case FUNIT_MILE:
237                 eFUnit = FUNIT_POINT;
238                 break;
239 
240             case FUNIT_CM:
241             case FUNIT_M:
242             case FUNIT_KM:
243                 eFUnit = FUNIT_MM;
244                 break;
245             default: ;//prevent warning
246         }
247     }
248     else
249     {
250         switch ( eFUnit )
251         {
252             case FUNIT_M:
253             case FUNIT_KM:
254                 eFUnit = FUNIT_MM;
255                 break;
256             default: ; //prevent warning
257         }
258     }
259 
260 	SetFieldUnit( aEdShadowSize, eFUnit );
261 
262 	sal_uInt16 nWhich = GetWhich( SID_ATTR_BORDER_INNER, sal_False );
263 	sal_Bool bIsDontCare = sal_True;
264 
265 	if ( rCoreAttrs.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
266 	{
267 		// Absatz oder Tabelle
268 		const SvxBoxInfoItem* pBoxInfo =
269 			(const SvxBoxInfoItem*)&( rCoreAttrs.Get( nWhich ) );
270 
271         mbHorEnabled = pBoxInfo->IsHorEnabled();
272         mbVerEnabled = pBoxInfo->IsVerEnabled();
273         mbTLBREnabled = sfx::ItemWrapperHelper::IsKnownItem( rCoreAttrs, SID_ATTR_BORDER_DIAG_TLBR );
274         mbBLTREnabled = sfx::ItemWrapperHelper::IsKnownItem( rCoreAttrs, SID_ATTR_BORDER_DIAG_BLTR );
275 
276 		if(pBoxInfo->IsDist())
277 		{
278 			SetFieldUnit(aLeftMF, eFUnit);
279 			SetFieldUnit(aRightMF, eFUnit);
280 			SetFieldUnit(aTopMF, eFUnit);
281 			SetFieldUnit(aBottomMF, eFUnit);
282 			aSynchronizeCB.Check(bSync);
283 			aSynchronizeCB.SetClickHdl(LINK(this, SvxBorderTabPage, SyncHdl_Impl));
284 			aLeftMF.SetModifyHdl(LINK(this, SvxBorderTabPage, ModifyDistanceHdl_Impl));
285 			aRightMF.SetModifyHdl(LINK(this, SvxBorderTabPage, ModifyDistanceHdl_Impl));
286 			aTopMF.SetModifyHdl(LINK(this, SvxBorderTabPage, ModifyDistanceHdl_Impl));
287 			aBottomMF.SetModifyHdl(LINK(this, SvxBorderTabPage, ModifyDistanceHdl_Impl));
288 		}
289 		else
290 		{
291             aFlSep2.Hide();
292             aDistanceFL.Hide();
293 			aLeftFT.Hide();
294 			aLeftMF.Hide();
295 			aRightFT.Hide();
296 			aRightMF.Hide();
297 			aTopFT.Hide();
298 			aTopMF.Hide();
299 			aBottomFT.Hide();
300 			aBottomMF.Hide();
301 			aSynchronizeCB.Hide();
302 		}
303 		bIsDontCare = !pBoxInfo->IsValid( VALID_DISABLE );
304 	}
305     if(!mbUseMarginItem && eFUnit == FUNIT_MM && SFX_MAPUNIT_TWIP == rCoreAttrs.GetPool()->GetMetric( GetWhich( SID_ATTR_BORDER_INNER ) ))
306 	{
307         //#i91548# changing the number of decimal digits changes the minimum values, too
308         lcl_SetDecimalDigitsTo1(aLeftMF);
309         lcl_SetDecimalDigitsTo1(aRightMF);
310         lcl_SetDecimalDigitsTo1(aTopMF);
311         lcl_SetDecimalDigitsTo1(aBottomMF);
312         lcl_SetDecimalDigitsTo1(aEdShadowSize);
313 	}
314 
315     svx::FrameSelFlags nFlags = svx::FRAMESEL_OUTER;
316     if( mbHorEnabled )
317         nFlags |= svx::FRAMESEL_INNER_HOR;
318     if( mbVerEnabled )
319         nFlags |= svx::FRAMESEL_INNER_VER;
320     if( mbTLBREnabled )
321         nFlags |= svx::FRAMESEL_DIAG_TLBR;
322     if( mbBLTREnabled )
323         nFlags |= svx::FRAMESEL_DIAG_BLTR;
324     if( bIsDontCare )
325         nFlags |= svx::FRAMESEL_DONTCARE;
326     aFrameSel.Initialize( nFlags );
327 
328     aFrameSel.SetSelectHdl(LINK(this, SvxBorderTabPage, LinesChanged_Impl));
329 	aLbLineStyle.SetSelectHdl( LINK( this, SvxBorderTabPage, SelStyleHdl_Impl ) );
330 	aLbLineColor.SetSelectHdl( LINK( this, SvxBorderTabPage, SelColHdl_Impl ) );
331 	aLbShadowColor.SetSelectHdl( LINK( this, SvxBorderTabPage, SelColHdl_Impl ) );
332 	aWndPresets.SetSelectHdl( LINK( this, SvxBorderTabPage, SelPreHdl_Impl ) );
333 	aWndShadows.SetSelectHdl( LINK( this, SvxBorderTabPage, SelSdwHdl_Impl ) );
334 
335     FillValueSets();
336 	FillLineListBox_Impl();
337 
338 	// ColorBox aus der XColorTable fuellen.
339 	SfxObjectShell*		pDocSh		= SfxObjectShell::Current();
340 	const SfxPoolItem*	pItem 		= NULL;
341 	XColorTable*		pColorTable = NULL;
342 
343 	DBG_ASSERT( pDocSh, "DocShell not found!" );
344 
345 	if ( pDocSh )
346     {
347         pItem = pDocSh->GetItem( SID_COLOR_TABLE );
348         if ( pItem != NULL )
349             pColorTable = ( (SvxColorTableItem*)pItem )->GetColorTable();
350     }
351 
352 	DBG_ASSERT( pColorTable, "ColorTable not found!" );
353 
354 	if ( pColorTable )
355 	{
356 		// fuellen der Linienfarben-Box
357 		aLbLineColor.SetUpdateMode( sal_False );
358 
359 		for ( long i = 0; i < pColorTable->Count(); ++i )
360 		{
361             XColorEntry* pEntry = pColorTable->GetColor(i);
362 			aLbLineColor.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
363 		}
364 		aLbLineColor.SetUpdateMode( sal_True );
365 		// dann nur noch in die Schattenfarben-Box kopieren
366 		aLbShadowColor.CopyEntries( aLbLineColor );
367 	}
368 	FreeResource();
369 
370     // connections
371 
372 	bool bSupportsShadow = !SfxItemPool::IsSlot( GetWhich( SID_ATTR_BORDER_SHADOW ) );
373 	if( bSupportsShadow )
374 		AddItemConnection( svx::CreateShadowConnection( rCoreAttrs, aWndShadows, aEdShadowSize, aLbShadowColor ) );
375 	else
376 		HideShadowControls();
377 
378     if( mbUseMarginItem )
379         AddItemConnection( svx::CreateMarginConnection( rCoreAttrs, aLeftMF, aRightMF, aTopMF, aBottomMF ) );
380     if( aFrameSel.IsBorderEnabled( svx::FRAMEBORDER_TLBR ) )
381         AddItemConnection( svx::CreateFrameLineConnection( SID_ATTR_BORDER_DIAG_TLBR, aFrameSel, svx::FRAMEBORDER_TLBR ) );
382     if( aFrameSel.IsBorderEnabled( svx::FRAMEBORDER_BLTR ) )
383         AddItemConnection( svx::CreateFrameLineConnection( SID_ATTR_BORDER_DIAG_BLTR, aFrameSel, svx::FRAMEBORDER_BLTR ) );
384     // --> OD 2005-03-01 #i43593# - item connection doesn't work for Writer,
385     // because the Writer item sets contain these items
386     // checkbox "Merge with next paragraph" only visible for Writer dialog format.paragraph
387     AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_BORDER_CONNECT, aMergeWithNextCB, sfx::ITEMCONN_DEFAULT ) );
388     aMergeWithNextCB.Hide();
389     // checkbox "Merge adjacent line styles" only visible for Writer dialog format.table
390     AddItemConnection( new sfx::CheckBoxConnection( SID_SW_COLLAPSING_BORDERS, aMergeAdjacentBordersCB, sfx::ITEMCONN_DEFAULT ) );
391     aMergeAdjacentBordersCB.Hide();
392     // <--
393 }
394 
395 // -----------------------------------------------------------------------
396 
397 SvxBorderTabPage::~SvxBorderTabPage()
398 {
399 }
400 
401 // -----------------------------------------------------------------------
402 
403 sal_uInt16* SvxBorderTabPage::GetRanges()
404 {
405 	return pRanges;
406 }
407 
408 // -----------------------------------------------------------------------
409 
410 SfxTabPage* SvxBorderTabPage::Create( Window* pParent,
411 									  const SfxItemSet& rAttrSet )
412 {
413 	return ( new SvxBorderTabPage( pParent, rAttrSet ) );
414 }
415 
416 // -----------------------------------------------------------------------
417 
418 void SvxBorderTabPage::ResetFrameLine_Impl( svx::FrameBorderType eBorder, const SvxBorderLine* pCoreLine, bool bValid )
419 {
420     if( aFrameSel.IsBorderEnabled( eBorder ) )
421     {
422         if( bValid )
423             aFrameSel.ShowBorder( eBorder, pCoreLine );
424         else
425             aFrameSel.SetBorderDontCare( eBorder );
426     }
427 }
428 
429 // -----------------------------------------------------------------------
430 
431 void SvxBorderTabPage::Reset( const SfxItemSet& rSet )
432 {
433     SfxTabPage::Reset( rSet );
434 
435 	const SvxBoxItem*       pBoxItem;
436 	const SvxBoxInfoItem*   pBoxInfoItem;
437 	sal_uInt16					nWhichBox		= GetWhich(SID_ATTR_BORDER_OUTER);
438 	SfxMapUnit 				eCoreUnit;
439 	const Color				aColBlack		= RGBCOL(COL_BLACK);
440 
441 	pBoxItem  = (const SvxBoxItem*)GetItem( rSet, SID_ATTR_BORDER_OUTER );
442 
443 
444 	pBoxInfoItem = (const SvxBoxInfoItem*)GetItem( rSet, SID_ATTR_BORDER_INNER, sal_False );
445 
446 	eCoreUnit = rSet.GetPool()->GetMetric( nWhichBox );
447 
448 	if ( pBoxItem && pBoxInfoItem ) // -> Don't Care
449 	{
450         ResetFrameLine_Impl( svx::FRAMEBORDER_LEFT,   pBoxItem->GetLeft(),     pBoxInfoItem->IsValid( VALID_LEFT ) );
451         ResetFrameLine_Impl( svx::FRAMEBORDER_RIGHT,  pBoxItem->GetRight(),    pBoxInfoItem->IsValid( VALID_RIGHT ) );
452         ResetFrameLine_Impl( svx::FRAMEBORDER_TOP,    pBoxItem->GetTop(),      pBoxInfoItem->IsValid( VALID_TOP ) );
453         ResetFrameLine_Impl( svx::FRAMEBORDER_BOTTOM, pBoxItem->GetBottom(),   pBoxInfoItem->IsValid( VALID_BOTTOM ) );
454         ResetFrameLine_Impl( svx::FRAMEBORDER_VER,    pBoxInfoItem->GetVert(), pBoxInfoItem->IsValid( VALID_VERT ) );
455         ResetFrameLine_Impl( svx::FRAMEBORDER_HOR,    pBoxInfoItem->GetHori(), pBoxInfoItem->IsValid( VALID_HORI ) );
456 
457 		//-------------------
458 		// Abstand nach innen
459 		//-------------------
460         if( !mbUseMarginItem )
461         {
462             if ( aLeftMF.IsVisible() )
463             {
464                 SetMetricValue( aLeftMF,    pBoxInfoItem->GetDefDist(), eCoreUnit );
465                 SetMetricValue( aRightMF,   pBoxInfoItem->GetDefDist(), eCoreUnit );
466                 SetMetricValue( aTopMF,     pBoxInfoItem->GetDefDist(), eCoreUnit );
467                 SetMetricValue( aBottomMF,  pBoxInfoItem->GetDefDist(), eCoreUnit );
468 
469                 nMinValue = static_cast<long>(aLeftMF.GetValue());
470 
471                 if ( pBoxInfoItem->IsMinDist() )
472                 {
473                     aLeftMF.SetFirst( nMinValue );
474                     aRightMF.SetFirst( nMinValue );
475                     aTopMF.SetFirst( nMinValue );
476                     aBottomMF.SetFirst( nMinValue );
477                 }
478 
479                 if ( pBoxInfoItem->IsDist() )
480                 {
481                     if( rSet.GetItemState( nWhichBox, sal_True ) >= SFX_ITEM_DEFAULT )
482                     {
483                         sal_Bool bIsAnyBorderVisible = aFrameSel.IsAnyBorderVisible();
484                         if( !bIsAnyBorderVisible || !pBoxInfoItem->IsMinDist() )
485                         {
486                             aLeftMF.SetMin( 0 );
487                             aLeftMF.SetFirst( 0 );
488                             aRightMF.SetMin( 0 );
489                             aRightMF.SetFirst( 0 );
490                             aTopMF.SetMin( 0 );
491                             aTopMF.SetFirst( 0 );
492                             aBottomMF.SetMin( 0 );
493                             aBottomMF.SetFirst( 0 );
494                         }
495                         long nLeftDist = pBoxItem->GetDistance( BOX_LINE_LEFT);
496                         SetMetricValue( aLeftMF, nLeftDist, eCoreUnit );
497                         long nRightDist = pBoxItem->GetDistance( BOX_LINE_RIGHT);
498                         SetMetricValue( aRightMF, nRightDist, eCoreUnit );
499                         long nTopDist = pBoxItem->GetDistance( BOX_LINE_TOP);
500                         SetMetricValue( aTopMF, nTopDist, eCoreUnit );
501                         long nBottomDist = pBoxItem->GetDistance( BOX_LINE_BOTTOM);
502                         SetMetricValue( aBottomMF, nBottomDist, eCoreUnit );
503 
504                         // ist der Abstand auf nicht-default gesetzt,
505                         // dann soll der Wert auch nicht
506                         // mehr autom. veraendert werden
507 
508                         // if the distance is set with no active border line
509                         // or it is null with an active border line
510                         // no automatic changes should be made
511                         const long nDefDist = bIsAnyBorderVisible ? pBoxInfoItem->GetDefDist() : 0;
512                         sal_Bool bDiffDist = (nDefDist != nLeftDist ||
513                                     nDefDist != nRightDist ||
514                                     nDefDist != nTopDist   ||
515                                     nDefDist != nBottomDist);
516                         if((pBoxItem->GetDistance() ||
517                                 bIsAnyBorderVisible) && bDiffDist )
518                         {
519                             aLeftMF.SetModifyFlag();
520                             aRightMF.SetModifyFlag();
521                             aTopMF.SetModifyFlag();
522                             aBottomMF.SetModifyFlag();
523                         }
524                     }
525                     else
526                     {
527                         // #106224# different margins -> do not fill the edits
528                         aLeftMF.SetText( String() );
529                         aRightMF.SetText( String() );
530                         aTopMF.SetText( String() );
531                         aBottomMF.SetText( String() );
532                     }
533                 }
534                 aLeftMF.SaveValue();
535                 aRightMF.SaveValue();
536                 aTopMF.SaveValue();
537                 aBottomMF.SaveValue();
538             }
539         }
540 	}
541 	else
542 	{
543 		// ResetFrameLine-Aufrufe einsparen:
544         aFrameSel.HideAllBorders();
545 	}
546 
547 	//-------------------------------------------------------------
548 	// Linie/Linienfarbe in Controllern darstellen, wenn eindeutig:
549 	//-------------------------------------------------------------
550 	{
551         // Do all visible lines show the same line widths?
552         sal_uInt16 nPrim, nDist, nSecn;
553         bool bWidthEq = aFrameSel.GetVisibleWidth( nPrim, nDist, nSecn );
554         if( bWidthEq )
555             aLbLineStyle.SelectEntry( nPrim * 100, nSecn * 100, nDist * 100 );
556         else
557             aLbLineStyle.SelectEntryPos( 1 );
558 
559         // Do all visible lines show the same line color?
560         Color aColor;
561         bool bColorEq = aFrameSel.GetVisibleColor( aColor );
562         if( !bColorEq )
563             aColor.SetColor( COL_BLACK );
564 
565         sal_uInt16 nSelPos = aLbLineColor.GetEntryPos( aColor );
566         if( nSelPos == LISTBOX_ENTRY_NOTFOUND )
567             nSelPos = aLbLineColor.InsertEntry( aColor, SVX_RESSTR( RID_SVXSTR_COLOR_USER ) );
568 
569         aLbLineColor.SelectEntryPos( nSelPos );
570         aLbLineStyle.SetColor( aColor );
571 
572         // Select all visible lines, if they are all equal.
573         if( bWidthEq && bColorEq )
574             aFrameSel.SelectAllVisibleBorders();
575 
576         // set the current style and color (caches style in control even if nothing is selected)
577         SelStyleHdl_Impl( &aLbLineStyle );
578         SelColHdl_Impl( &aLbLineColor );
579 	}
580 
581 	sal_Bool bEnable = aWndShadows.GetSelectItemId() > 1 ;
582 	aFtShadowSize.Enable(bEnable);
583 	aEdShadowSize.Enable(bEnable);
584     aFtShadowColor.Enable(bEnable);
585     aLbShadowColor.Enable(bEnable);
586 
587 	aWndPresets.SetNoSelection();
588 
589 	// - keine Line - sollte nicht selektiert sein
590 
591 	if ( aLbLineStyle.GetSelectEntryPos() == 0 )
592 	{
593 		aLbLineStyle.SelectEntryPos( 1 );
594 		SelStyleHdl_Impl( &aLbLineStyle );
595 	}
596 
597 	const SfxPoolItem* pItem;
598 	SfxObjectShell* pShell;
599 	if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, sal_False, &pItem) ||
600 		( 0 != (pShell = SfxObjectShell::Current()) &&
601 					0 != (pItem = pShell->GetItem(SID_HTML_MODE))))
602 	{
603 		sal_uInt16 nHtmlMode = ((SfxUInt16Item*)pItem)->GetValue();
604 		if(nHtmlMode & HTMLMODE_ON)
605 		{
606 			//Im Html-Mode gibt es keinen Schatten und nur komplette Umrandungen
607             aFtShadowPos  .Disable();
608             aWndShadows   .Disable();
609             aFtShadowSize .Disable();
610             aEdShadowSize .Disable();
611             aFtShadowColor.Disable();
612             aLbShadowColor.Disable();
613             aFlShadow     .Disable();
614 
615 			sal_uInt16 nLBCount = aLbLineStyle.GetEntryCount();
616 			// ist es ein Absatzdialog, dann alle Linien fuer
617 			// Sw-Export, sonst ist die Page nicht da
618             if(!(mbHorEnabled || mbVerEnabled)
619                  && 0 == (nHtmlMode & HTMLMODE_FULL_ABS_POS) &&
620 				SFX_ITEM_AVAILABLE > rSet.GetItemState(GetWhich( SID_ATTR_PARA_LINESPACE )))
621 			{
622 				for( sal_uInt16 i = nLBCount - 1; i > LINESTYLE_HTML_MAX; --i)
623 					aLbLineStyle.RemoveEntry(i);
624 			}
625 
626             if( !(nSWMode & SW_BORDER_MODE_TABLE) )
627 			{
628                 aUserDefFT.Disable();
629                 aFrameSel.Disable();
630 				aWndPresets.RemoveItem(3);
631 				aWndPresets.RemoveItem(4);
632 				aWndPresets.RemoveItem(5);
633 			}
634 		}
635 	}
636 
637     LinesChanged_Impl( 0 );
638 }
639 
640 // -----------------------------------------------------------------------
641 
642 int SvxBorderTabPage::DeactivatePage( SfxItemSet* _pSet )
643 {
644 	if ( _pSet )
645 		FillItemSet( *_pSet );
646 
647 	return LEAVE_PAGE;
648 }
649 
650 // -----------------------------------------------------------------------
651 
652 #define IS_DONT_CARE(a) ((a).GetState() == svx::FRAMESTATE_DONTCARE )
653 
654 sal_Bool SvxBorderTabPage::FillItemSet( SfxItemSet& rCoreAttrs )
655 {
656     bool bAttrsChanged = SfxTabPage::FillItemSet( rCoreAttrs );
657 
658 	sal_Bool				  bPut		   	= sal_True;
659 	sal_uInt16				  nBoxWhich		= GetWhich( SID_ATTR_BORDER_OUTER );
660 	sal_uInt16				  nBoxInfoWhich = rCoreAttrs.GetPool()->GetWhich( SID_ATTR_BORDER_INNER, sal_False );
661 	const SfxItemSet&	  rOldSet		= GetItemSet();
662 	SvxBoxItem		      aBoxItem 	    ( nBoxWhich );
663 	SvxBoxInfoItem        aBoxInfoItem  ( nBoxInfoWhich );
664 	SvxBoxItem* pOldBoxItem = (SvxBoxItem*)GetOldItem( rCoreAttrs, SID_ATTR_BORDER_OUTER );
665 
666     SfxMapUnit eCoreUnit = rOldSet.GetPool()->GetMetric( nBoxWhich );
667 	const SfxPoolItem* pOld = 0;
668 
669 	//------------------
670 	// Umrandung aussen:
671 	//------------------
672     typedef ::std::pair<svx::FrameBorderType,sal_uInt16> TBorderPair;
673 	TBorderPair eTypes1[] = {
674                                 TBorderPair(svx::FRAMEBORDER_TOP,BOX_LINE_TOP),
675                                 TBorderPair(svx::FRAMEBORDER_BOTTOM,BOX_LINE_BOTTOM),
676                                 TBorderPair(svx::FRAMEBORDER_LEFT,BOX_LINE_LEFT),
677                                 TBorderPair(svx::FRAMEBORDER_RIGHT,BOX_LINE_RIGHT),
678 							};
679 
680 	for (sal_uInt32 i=0; i < sizeof(eTypes1)/sizeof(TBorderPair); ++i)
681         aBoxItem.SetLine( aFrameSel.GetFrameBorderStyle( eTypes1[i].first ), eTypes1[i].second );
682 
683 	//--------------------------------
684 	// Umrandung hor/ver und TableFlag
685 	//--------------------------------
686 	TBorderPair eTypes2[] = {
687                                 TBorderPair(svx::FRAMEBORDER_HOR,BOXINFO_LINE_HORI),
688                                 TBorderPair(svx::FRAMEBORDER_VER,BOXINFO_LINE_VERT)
689 							};
690 	for (sal_uInt32 j=0; j < sizeof(eTypes2)/sizeof(TBorderPair); ++j)
691         aBoxInfoItem.SetLine( aFrameSel.GetFrameBorderStyle( eTypes2[j].first ), eTypes2[j].second );
692 
693     aBoxInfoItem.EnableHor( mbHorEnabled );
694     aBoxInfoItem.EnableVer( mbVerEnabled );
695 
696 	//-------------------
697 	// Abstand nach Innen
698 	//-------------------
699     if( aLeftMF.IsVisible() )
700     {
701         // #i40405# enable distance controls for next dialog call
702         aBoxInfoItem.SetDist( sal_True );
703 
704         if( !mbUseMarginItem )
705         {
706             // #106224# all edits empty: do nothing
707             if( aLeftMF.GetText().Len() || aRightMF.GetText().Len() ||
708                 aTopMF.GetText().Len() || aBottomMF.GetText().Len() )
709             {
710                 if ( ((mbHorEnabled || mbVerEnabled || (nSWMode & SW_BORDER_MODE_TABLE)) &&
711                         (aLeftMF.IsModified()||aRightMF.IsModified()||
712                             aTopMF.IsModified()||aBottomMF.IsModified()) )||
713                      aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_TOP ) != svx::FRAMESTATE_HIDE
714                      || aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_BOTTOM ) != svx::FRAMESTATE_HIDE
715                      || aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_LEFT ) != svx::FRAMESTATE_HIDE
716                      || aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_RIGHT ) != svx::FRAMESTATE_HIDE )
717                 {
718                     SvxBoxInfoItem* pOldBoxInfoItem = (SvxBoxInfoItem*)GetOldItem(
719                                                         rCoreAttrs, SID_ATTR_BORDER_INNER );
720                     if (
721                         !pOldBoxItem ||
722                         aLeftMF  .GetText() != aLeftMF  .GetSavedValue() ||
723                         aRightMF .GetText() != aRightMF .GetSavedValue() ||
724                         aTopMF   .GetText() != aTopMF   .GetSavedValue() ||
725                         aBottomMF.GetText() != aBottomMF.GetSavedValue() ||
726                         nMinValue == aLeftMF  .GetValue() ||
727                         nMinValue == aRightMF .GetValue() ||
728                         nMinValue == aTopMF   .GetValue() ||
729                         nMinValue == aBottomMF.GetValue() ||
730                         (pOldBoxInfoItem && !pOldBoxInfoItem->IsValid(VALID_DISTANCE))
731                        )
732                     {
733                         aBoxItem.SetDistance( (sal_uInt16)GetCoreValue( aLeftMF, eCoreUnit ), BOX_LINE_LEFT  );
734                         aBoxItem.SetDistance( (sal_uInt16)GetCoreValue( aRightMF, eCoreUnit ), BOX_LINE_RIGHT );
735                         aBoxItem.SetDistance( (sal_uInt16)GetCoreValue( aTopMF, eCoreUnit ), BOX_LINE_TOP   );
736                         aBoxItem.SetDistance( (sal_uInt16)GetCoreValue( aBottomMF, eCoreUnit ), BOX_LINE_BOTTOM);
737                     }
738                     else
739                     {
740                         aBoxItem.SetDistance(pOldBoxItem->GetDistance(BOX_LINE_LEFT ), BOX_LINE_LEFT);
741                         aBoxItem.SetDistance(pOldBoxItem->GetDistance(BOX_LINE_RIGHT),  BOX_LINE_RIGHT);
742                         aBoxItem.SetDistance(pOldBoxItem->GetDistance(BOX_LINE_TOP  ), BOX_LINE_TOP);
743                         aBoxItem.SetDistance(pOldBoxItem->GetDistance(BOX_LINE_BOTTOM), BOX_LINE_BOTTOM);
744                     }
745                     aBoxInfoItem.SetValid( VALID_DISTANCE, sal_True );
746                 }
747                 else
748                     aBoxInfoItem.SetValid( VALID_DISTANCE, sal_False );
749             }
750         }
751     }
752 
753 	//------------------------------------------
754 	// Don't Care Status im Info-Item vermerken:
755 	//------------------------------------------
756     aBoxInfoItem.SetValid( VALID_TOP,    aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_TOP )    != svx::FRAMESTATE_DONTCARE );
757     aBoxInfoItem.SetValid( VALID_BOTTOM, aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_BOTTOM ) != svx::FRAMESTATE_DONTCARE );
758     aBoxInfoItem.SetValid( VALID_LEFT,   aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_LEFT )   != svx::FRAMESTATE_DONTCARE );
759     aBoxInfoItem.SetValid( VALID_RIGHT,  aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_RIGHT )  != svx::FRAMESTATE_DONTCARE );
760     aBoxInfoItem.SetValid( VALID_HORI,   aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_HOR )    != svx::FRAMESTATE_DONTCARE );
761     aBoxInfoItem.SetValid( VALID_VERT,   aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_VER )    != svx::FRAMESTATE_DONTCARE );
762 
763 	//
764 	// Put oder Clear der Umrandung?
765 	//
766 	bPut = sal_True;
767 
768     if (   SFX_ITEM_DEFAULT == rOldSet.GetItemState( nBoxWhich,     sal_False ))
769     {
770         bPut = aBoxItem != (const SvxBoxItem&)(rOldSet.Get(nBoxWhich)) ? sal_True : sal_False;
771     }
772     if(  SFX_ITEM_DEFAULT == rOldSet.GetItemState( nBoxInfoWhich, sal_False ) )
773     {
774         const SvxBoxInfoItem& rOldBoxInfo = (const SvxBoxInfoItem&)
775                                 rOldSet.Get(nBoxInfoWhich);
776 
777         aBoxInfoItem.SetMinDist( rOldBoxInfo.IsMinDist() );
778         aBoxInfoItem.SetDefDist( rOldBoxInfo.GetDefDist() );
779         bPut |= (aBoxInfoItem != rOldBoxInfo );
780     }
781 
782 	if ( bPut )
783 	{
784 		if ( !pOldBoxItem || !( *pOldBoxItem == aBoxItem ) )
785 		{
786 			rCoreAttrs.Put( aBoxItem );
787 			bAttrsChanged |= sal_True;
788 		}
789 		pOld = GetOldItem( rCoreAttrs, SID_ATTR_BORDER_INNER, sal_False );
790 
791 		if ( !pOld || !( *(const SvxBoxInfoItem*)pOld == aBoxInfoItem ) )
792 		{
793 			rCoreAttrs.Put( aBoxInfoItem );
794 			bAttrsChanged |= sal_True;
795 		}
796 	}
797 	else
798 	{
799 		rCoreAttrs.ClearItem( nBoxWhich );
800 		rCoreAttrs.ClearItem( nBoxInfoWhich );
801 	}
802 
803 	return bAttrsChanged;
804 }
805 
806 // -----------------------------------------------------------------------
807 
808 void SvxBorderTabPage::HideShadowControls()
809 {
810 	aFtShadowPos.Hide();
811 	aWndShadows.Hide();
812 	aFtShadowSize.Hide();
813 	aEdShadowSize.Hide();
814 	aFtShadowColor.Hide();
815 	aLbShadowColor.Hide();
816 	aFlShadow.Hide();
817 }
818 
819 // -----------------------------------------------------------------------
820 
821 IMPL_LINK( SvxBorderTabPage, SelPreHdl_Impl, void *, EMPTYARG )
822 {
823     const svx::FrameBorderState SHOW = svx::FRAMESTATE_SHOW;
824     const svx::FrameBorderState HIDE = svx::FRAMESTATE_HIDE;
825     const svx::FrameBorderState DONT = svx::FRAMESTATE_DONTCARE;
826 
827     static const svx::FrameBorderState ppeStates[][ svx::FRAMEBORDERTYPE_COUNT ] =
828     {                   /*    Left  Right Top   Bot   Hor   Ver   TLBR  BLTR */
829 /* ---------------------+--------------------------------------------------- */
830 /* IID_PRE_CELL_NONE    */  { HIDE, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE },
831 /* IID_PRE_CELL_ALL     */  { SHOW, SHOW, SHOW, SHOW, HIDE, HIDE, HIDE, HIDE },
832 /* IID_PRE_CELL_LR      */  { SHOW, SHOW, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE },
833 /* IID_PRE_CELL_TB      */  { HIDE, HIDE, SHOW, SHOW, HIDE, HIDE, HIDE, HIDE },
834 /* IID_PRE_CELL_L       */  { SHOW, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE },
835 /* IID_PRE_CELL_DIAG    */  { HIDE, HIDE, HIDE, HIDE, HIDE, HIDE, SHOW, SHOW },
836 /* IID_PRE_HOR_NONE     */  { HIDE, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE },
837 /* IID_PRE_HOR_OUTER    */  { SHOW, SHOW, SHOW, SHOW, HIDE, HIDE, HIDE, HIDE },
838 /* IID_PRE_HOR_HOR      */  { HIDE, HIDE, SHOW, SHOW, SHOW, HIDE, HIDE, HIDE },
839 /* IID_PRE_HOR_ALL      */  { SHOW, SHOW, SHOW, SHOW, SHOW, HIDE, HIDE, HIDE },
840 /* IID_PRE_HOR_OUTER2   */  { SHOW, SHOW, SHOW, SHOW, DONT, HIDE, HIDE, HIDE },
841 /* IID_PRE_VER_NONE     */  { HIDE, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE },
842 /* IID_PRE_VER_OUTER    */  { SHOW, SHOW, SHOW, SHOW, HIDE, HIDE, HIDE, HIDE },
843 /* IID_PRE_VER_VER      */  { SHOW, SHOW, HIDE, HIDE, HIDE, SHOW, HIDE, HIDE },
844 /* IID_PRE_VER_ALL      */  { SHOW, SHOW, SHOW, SHOW, HIDE, SHOW, HIDE, HIDE },
845 /* IID_PRE_VER_OUTER2   */  { SHOW, SHOW, SHOW, SHOW, HIDE, DONT, HIDE, HIDE },
846 /* IID_PRE_TABLE_NONE   */  { HIDE, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE, HIDE },
847 /* IID_PRE_TABLE_OUTER  */  { SHOW, SHOW, SHOW, SHOW, HIDE, HIDE, HIDE, HIDE },
848 /* IID_PRE_TABLE_OUTERH */  { SHOW, SHOW, SHOW, SHOW, SHOW, HIDE, HIDE, HIDE },
849 /* IID_PRE_TABLE_ALL    */  { SHOW, SHOW, SHOW, SHOW, SHOW, SHOW, HIDE, HIDE },
850 /* IID_PRE_TABLE_OUTER2 */  { SHOW, SHOW, SHOW, SHOW, DONT, DONT, HIDE, HIDE }
851     };
852 
853     // first hide and deselect all frame borders
854     aFrameSel.HideAllBorders();
855     aFrameSel.DeselectAllBorders();
856 
857     // Using image ID to find correct line in table above.
858     sal_uInt16 nLine = GetPresetImageId( aWndPresets.GetSelectItemId() ) - 1;
859 
860     // Apply all styles from the table
861     for( int nBorder = 0; nBorder < svx::FRAMEBORDERTYPE_COUNT; ++nBorder )
862     {
863         svx::FrameBorderType eBorder = svx::GetFrameBorderTypeFromIndex( nBorder );
864         switch( ppeStates[ nLine ][ nBorder ] )
865         {
866             case SHOW:  aFrameSel.SelectBorder( eBorder );      break;
867             case HIDE:  /* nothing to do */                     break;
868             case DONT:  aFrameSel.SetBorderDontCare( eBorder ); break;
869         }
870     }
871 
872     // Show all lines that have been selected above
873     if( aFrameSel.IsAnyBorderSelected() )
874     {
875         // any visible style, but "no-line" in line list box? -> use hair-line
876         if( (aLbLineStyle.GetSelectEntryPos() == 0) || (aLbLineStyle.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND) )
877             aLbLineStyle.SelectEntryPos( 1 );
878 
879         // set current style to all previously selected lines
880         SelStyleHdl_Impl( &aLbLineStyle );
881         SelColHdl_Impl( &aLbLineColor );
882     }
883 
884     // Presets ValueSet does not show a selection (used as push buttons).
885     aWndPresets.SetNoSelection();
886 
887     LinesChanged_Impl( 0 );
888 	return 0;
889 }
890 
891 // -----------------------------------------------------------------------
892 
893 IMPL_LINK( SvxBorderTabPage, SelSdwHdl_Impl, void *, EMPTYARG )
894 {
895 	sal_Bool bEnable = aWndShadows.GetSelectItemId() > 1;
896 	aFtShadowSize.Enable(bEnable);
897 	aEdShadowSize.Enable(bEnable);
898     aFtShadowColor.Enable(bEnable);
899     aLbShadowColor.Enable(bEnable);
900 	return 0;
901 }
902 
903 // -----------------------------------------------------------------------
904 
905 IMPL_LINK( SvxBorderTabPage, SelColHdl_Impl, ListBox *, pLb )
906 {
907 	ColorListBox* pColLb = (ColorListBox*)pLb;
908 
909 	if ( pLb == &aLbLineColor )
910 	{
911         aFrameSel.SetColorToSelection( pColLb->GetSelectEntryColor() );
912 		aLbLineStyle.SetColor( pColLb->GetSelectEntryColor() );
913 	}
914 
915 	return 0;
916 }
917 
918 // -----------------------------------------------------------------------
919 
920 IMPL_LINK( SvxBorderTabPage, SelStyleHdl_Impl, ListBox *, pLb )
921 {
922 	if ( pLb == &aLbLineStyle )
923         aFrameSel.SetStyleToSelection(
924             static_cast< sal_uInt16 >( aLbLineStyle.GetSelectEntryLine1() / 100 ),
925             static_cast< sal_uInt16 >( aLbLineStyle.GetSelectEntryDistance() / 100 ),
926             static_cast< sal_uInt16 >( aLbLineStyle.GetSelectEntryLine2() / 100 ) );
927 
928 	return 0;
929 }
930 
931 // ============================================================================
932 // ValueSet handling
933 // ============================================================================
934 
935 // number of preset images to show
936 const sal_uInt16 SVX_BORDER_PRESET_COUNT = 5;
937 
938 // number of shadow images to show
939 const sal_uInt16 SVX_BORDER_SHADOW_COUNT = 5;
940 
941 // ----------------------------------------------------------------------------
942 
943 sal_uInt16 SvxBorderTabPage::GetPresetImageId( sal_uInt16 nValueSetIdx ) const
944 {
945     // table with all sets of predefined border styles
946     static const sal_uInt16 ppnImgIds[][ SVX_BORDER_PRESET_COUNT ] =
947     {
948         // simple cell without diagonal frame borders
949         {   IID_PRE_CELL_NONE,  IID_PRE_CELL_ALL,       IID_PRE_CELL_LR,        IID_PRE_CELL_TB,    IID_PRE_CELL_L          },
950         // simple cell with diagonal frame borders
951         {   IID_PRE_CELL_NONE,  IID_PRE_CELL_ALL,       IID_PRE_CELL_LR,        IID_PRE_CELL_TB,    IID_PRE_CELL_DIAG       },
952         // with horizontal inner frame border
953         {   IID_PRE_HOR_NONE,   IID_PRE_HOR_OUTER,      IID_PRE_HOR_HOR,        IID_PRE_HOR_ALL,    IID_PRE_HOR_OUTER2      },
954         // with vertical inner frame border
955         {   IID_PRE_VER_NONE,   IID_PRE_VER_OUTER,      IID_PRE_VER_VER,        IID_PRE_VER_ALL,    IID_PRE_VER_OUTER2      },
956         // with horizontal and vertical inner frame borders
957         {   IID_PRE_TABLE_NONE, IID_PRE_TABLE_OUTER,    IID_PRE_TABLE_OUTERH,   IID_PRE_TABLE_ALL,  IID_PRE_TABLE_OUTER2    }
958     };
959 
960     // find correct set of presets
961     int nLine = 0;
962     if( !mbHorEnabled && !mbVerEnabled )
963         nLine = (mbTLBREnabled || mbBLTREnabled) ? 1 : 0;
964     else if( mbHorEnabled && !mbVerEnabled )
965         nLine = 2;
966     else if( !mbHorEnabled && mbVerEnabled )
967         nLine = 3;
968     else
969         nLine = 4;
970 
971     DBG_ASSERT( (1 <= nValueSetIdx) && (nValueSetIdx <= SVX_BORDER_PRESET_COUNT),
972         "SvxBorderTabPage::GetPresetImageId - wrong index" );
973     return ppnImgIds[ nLine ][ nValueSetIdx - 1 ];
974 }
975 
976 sal_uInt16 SvxBorderTabPage::GetPresetStringId( sal_uInt16 nValueSetIdx ) const
977 {
978     // string resource IDs for each image (in order of the IID_PRE_* image IDs)
979     static const sal_uInt16 pnStrIds[] =
980     {
981         RID_SVXSTR_TABLE_PRESET_NONE,
982         RID_SVXSTR_PARA_PRESET_ALL,
983         RID_SVXSTR_PARA_PRESET_LEFTRIGHT,
984         RID_SVXSTR_PARA_PRESET_TOPBOTTOM,
985         RID_SVXSTR_PARA_PRESET_ONLYLEFT,
986         RID_SVXSTR_PARA_PRESET_DIAGONAL,
987 
988         RID_SVXSTR_TABLE_PRESET_NONE,
989         RID_SVXSTR_TABLE_PRESET_ONLYOUTER,
990         RID_SVXSTR_HOR_PRESET_ONLYHOR,
991         RID_SVXSTR_TABLE_PRESET_OUTERALL,
992         RID_SVXSTR_TABLE_PRESET_OUTERINNER,
993 
994         RID_SVXSTR_TABLE_PRESET_NONE,
995         RID_SVXSTR_TABLE_PRESET_ONLYOUTER,
996         RID_SVXSTR_VER_PRESET_ONLYVER,
997         RID_SVXSTR_TABLE_PRESET_OUTERALL,
998         RID_SVXSTR_TABLE_PRESET_OUTERINNER,
999 
1000         RID_SVXSTR_TABLE_PRESET_NONE,
1001         RID_SVXSTR_TABLE_PRESET_ONLYOUTER,
1002         RID_SVXSTR_TABLE_PRESET_OUTERHORI,
1003         RID_SVXSTR_TABLE_PRESET_OUTERALL,
1004         RID_SVXSTR_TABLE_PRESET_OUTERINNER
1005     };
1006     return pnStrIds[ GetPresetImageId( nValueSetIdx ) - 1 ];
1007 }
1008 
1009 // ----------------------------------------------------------------------------
1010 
1011 void SvxBorderTabPage::FillPresetVS()
1012 {
1013     // find correct image list
1014     bool bHC = aWndPresets.GetSettings().GetStyleSettings().GetHighContrastMode();
1015     ImageList& rImgList = bHC ? aBorderImgLstH : aBorderImgLst;
1016     Size aImgSize( rImgList.GetImage( IID_PRE_CELL_NONE ).GetSizePixel() );
1017 
1018     // basic initialization of the ValueSet
1019     aWndPresets.SetColCount( SVX_BORDER_PRESET_COUNT );
1020     aWndPresets.SetStyle( aWndPresets.GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER );
1021     aWndPresets.SetSizePixel( aWndPresets.CalcWindowSizePixel( aImgSize ) );
1022 
1023     // insert images and help texts
1024     for( sal_uInt16 nVSIdx = 1; nVSIdx <= SVX_BORDER_PRESET_COUNT; ++nVSIdx )
1025     {
1026         aWndPresets.InsertItem( nVSIdx );
1027         aWndPresets.SetItemImage( nVSIdx, rImgList.GetImage( GetPresetImageId( nVSIdx ) ) );
1028         aWndPresets.SetItemText( nVSIdx, CUI_RESSTR( GetPresetStringId( nVSIdx ) ) );
1029     }
1030 
1031     // show the control
1032     aWndPresets.SetNoSelection();
1033     aWndPresets.Show();
1034 }
1035 
1036 // ----------------------------------------------------------------------------
1037 
1038 void SvxBorderTabPage::FillShadowVS()
1039 {
1040     // find correct image list
1041     bool bHC = aWndPresets.GetSettings().GetStyleSettings().GetHighContrastMode();
1042     ImageList& rImgList = bHC ? aShadowImgLstH : aShadowImgLst;
1043     Size aImgSize( rImgList.GetImage( IID_SHADOWNONE ).GetSizePixel() );
1044 
1045     // basic initialization of the ValueSet
1046     aWndShadows.SetColCount( SVX_BORDER_SHADOW_COUNT );
1047     aWndShadows.SetStyle( aWndShadows.GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER );
1048     aWndShadows.SetSizePixel( aWndShadows.CalcWindowSizePixel( aImgSize ) );
1049 
1050     // image resource IDs
1051     static const sal_uInt16 pnImgIds[ SVX_BORDER_SHADOW_COUNT ] =
1052         { IID_SHADOWNONE, IID_SHADOW_BOT_RIGHT, IID_SHADOW_TOP_RIGHT, IID_SHADOW_BOT_LEFT, IID_SHADOW_TOP_LEFT };
1053     // string resource IDs for each image
1054     static const sal_uInt16 pnStrIds[ SVX_BORDER_SHADOW_COUNT ] =
1055         { RID_SVXSTR_SHADOW_STYLE_NONE, RID_SVXSTR_SHADOW_STYLE_BOTTOMRIGHT, RID_SVXSTR_SHADOW_STYLE_TOPRIGHT, RID_SVXSTR_SHADOW_STYLE_BOTTOMLEFT, RID_SVXSTR_SHADOW_STYLE_TOPLEFT };
1056 
1057     // insert images and help texts
1058     for( sal_uInt16 nVSIdx = 1; nVSIdx <= SVX_BORDER_SHADOW_COUNT; ++nVSIdx )
1059     {
1060         aWndShadows.InsertItem( nVSIdx );
1061         aWndShadows.SetItemImage( nVSIdx, rImgList.GetImage( pnImgIds[ nVSIdx - 1 ] ) );
1062         aWndShadows.SetItemText( nVSIdx, CUI_RESSTR( pnStrIds[ nVSIdx - 1 ] ) );
1063     }
1064 
1065     // show the control
1066     aWndShadows.SelectItem( 1 );
1067     aWndShadows.Show();
1068 }
1069 
1070 // ----------------------------------------------------------------------------
1071 
1072 void SvxBorderTabPage::FillValueSets()
1073 {
1074     FillPresetVS();
1075     FillShadowVS();
1076 }
1077 
1078 // ============================================================================
1079 
1080 void SvxBorderTabPage::FillLineListBox_Impl()
1081 {
1082 	aLbLineStyle.SetUnit( FUNIT_POINT );
1083 	aLbLineStyle.SetSourceUnit( FUNIT_TWIP );
1084 
1085 	// Writer 2.0 Defaults:
1086 	aLbLineStyle.InsertEntry( SVX_RESSTR( RID_SVXSTR_NONE ) );
1087 
1088 	aLbLineStyle.InsertEntry( LINE_WIDTH0 );
1089     aLbLineStyle.InsertEntry( LINE_WIDTH5 );
1090     aLbLineStyle.InsertEntry( LINE_WIDTH1 );
1091 	aLbLineStyle.InsertEntry( LINE_WIDTH2 );
1092 	aLbLineStyle.InsertEntry( LINE_WIDTH3 );
1093 	aLbLineStyle.InsertEntry( LINE_WIDTH4 );
1094 
1095 	// OS: wenn hier neue Linienstaerken zugfuegt werden, dann
1096 	// LINESTYLE_HTML_MAX anpassen
1097 
1098 	aLbLineStyle.InsertEntry( DLINE0_OUT, DLINE0_IN, DLINE0_DIST );
1099 	aLbLineStyle.InsertEntry( DLINE7_OUT, DLINE7_IN, DLINE7_DIST );
1100 	aLbLineStyle.InsertEntry( DLINE1_OUT, DLINE1_IN, DLINE1_DIST );
1101 	aLbLineStyle.InsertEntry( DLINE2_OUT, DLINE2_IN, DLINE2_DIST );
1102 	aLbLineStyle.InsertEntry( DLINE8_OUT, DLINE8_IN, DLINE8_DIST );
1103 	aLbLineStyle.InsertEntry( DLINE9_OUT, DLINE9_IN, DLINE9_DIST );
1104 	aLbLineStyle.InsertEntry( DLINE10_OUT,DLINE10_IN,DLINE10_DIST);
1105 	aLbLineStyle.InsertEntry( DLINE3_OUT, DLINE3_IN, DLINE3_DIST );
1106 	aLbLineStyle.InsertEntry( DLINE4_OUT, DLINE4_IN, DLINE4_DIST );
1107 	aLbLineStyle.InsertEntry( DLINE5_OUT, DLINE5_IN, DLINE5_DIST );
1108 	aLbLineStyle.InsertEntry( DLINE6_OUT, DLINE6_IN, DLINE6_DIST );
1109 }
1110 
1111 // -----------------------------------------------------------------------
1112 IMPL_LINK( SvxBorderTabPage, LinesChanged_Impl, void*, EMPTYARG )
1113 {
1114     if(!mbUseMarginItem && aLeftMF.IsVisible())
1115 	{
1116         sal_Bool bLineSet = aFrameSel.IsAnyBorderVisible();
1117         sal_Bool bMinAllowed = 0 != (nSWMode & (SW_BORDER_MODE_FRAME|SW_BORDER_MODE_TABLE));
1118 		sal_Bool bSpaceModified = 	aLeftMF  .IsModified()||
1119 								aRightMF .IsModified()||
1120 								aTopMF   .IsModified()||
1121 								aBottomMF.IsModified();
1122 
1123 		if(bLineSet)
1124 		{
1125 			if(!bMinAllowed)
1126 			{
1127 				aLeftMF  .SetFirst(nMinValue);
1128 				aRightMF .SetFirst(nMinValue);
1129 				aTopMF   .SetFirst(nMinValue);
1130 				aBottomMF.SetFirst(nMinValue);
1131 			}
1132 			if(!bSpaceModified)
1133 			{
1134 				aLeftMF  .SetValue(nMinValue);
1135 				aRightMF .SetValue(nMinValue);
1136 				aTopMF   .SetValue(nMinValue);
1137 				aBottomMF.SetValue(nMinValue);
1138 			}
1139 		}
1140 		else
1141 		{
1142 			aLeftMF  .SetMin(0);
1143 			aRightMF .SetMin(0);
1144 			aTopMF   .SetMin(0);
1145 			aBottomMF.SetMin(0);
1146 			aLeftMF  .SetFirst(0);
1147 			aRightMF .SetFirst(0);
1148 			aTopMF   .SetFirst(0);
1149 			aBottomMF.SetFirst(0);
1150 			if(!bSpaceModified)
1151 			{
1152 				aLeftMF  .SetValue(0);
1153 				aRightMF .SetValue(0);
1154 				aTopMF   .SetValue(0);
1155 				aBottomMF.SetValue(0);
1156 			}
1157 		}
1158 		//fuer Tabellen ist alles erlaubt
1159 		sal_uInt16 nValid = VALID_TOP|VALID_BOTTOM|VALID_LEFT|VALID_RIGHT;
1160 
1161 		//fuer Rahmen und  Absatz wird das Edit disabled, wenn keine Border gesetzt ist
1162 		if(nSWMode & (SW_BORDER_MODE_FRAME|SW_BORDER_MODE_PARA))
1163 		{
1164             if(bLineSet)
1165             {
1166                 nValid  = (aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_TOP)    == svx::FRAMESTATE_SHOW) ? VALID_TOP : 0;
1167                 nValid |= (aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_BOTTOM) == svx::FRAMESTATE_SHOW) ? VALID_BOTTOM : 0;
1168                 nValid |= (aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_LEFT)   == svx::FRAMESTATE_SHOW) ? VALID_LEFT : 0;
1169                 nValid |= (aFrameSel.GetFrameBorderState( svx::FRAMEBORDER_RIGHT ) == svx::FRAMESTATE_SHOW) ? VALID_RIGHT : 0;
1170             }
1171             else
1172                 nValid = 0;
1173 		}
1174         aLeftFT.Enable(0 != (nValid&VALID_LEFT));
1175         aRightFT.Enable(0 != (nValid&VALID_RIGHT));
1176         aTopFT.Enable(0 != (nValid&VALID_TOP));
1177         aBottomFT.Enable(0 != (nValid&VALID_BOTTOM));
1178         aLeftMF.Enable(0 != (nValid&VALID_LEFT));
1179         aRightMF.Enable(0 != (nValid&VALID_RIGHT));
1180         aTopMF.Enable(0 != (nValid&VALID_TOP));
1181         aBottomMF.Enable(0 != (nValid&VALID_BOTTOM));
1182         aSynchronizeCB.Enable( aRightMF.IsEnabled() || aTopMF.IsEnabled() ||
1183                                aBottomMF.IsEnabled() || aLeftMF.IsEnabled() );
1184 	}
1185 	return 0;
1186 }
1187 
1188 // -----------------------------------------------------------------------
1189 
1190 IMPL_LINK( SvxBorderTabPage, ModifyDistanceHdl_Impl, MetricField*, pField)
1191 {
1192 	if ( bSync )
1193 	{
1194 		sal_Int64 nVal = pField->GetValue();
1195 		if(pField != &aLeftMF)
1196 			aLeftMF.SetValue(nVal);
1197 		if(pField != &aRightMF)
1198 			aRightMF.SetValue(nVal);
1199 		if(pField != &aTopMF)
1200 			aTopMF.SetValue(nVal);
1201 		if(pField != &aBottomMF)
1202 			aBottomMF.SetValue(nVal);
1203 	}
1204 	return 0;
1205 }
1206 
1207 IMPL_LINK( SvxBorderTabPage, SyncHdl_Impl, CheckBox*, pBox)
1208 {
1209 	bSync = pBox->IsChecked();
1210 	return 0;
1211 }
1212 
1213 /* -----------------------------03.06.2002 10:15------------------------------
1214 
1215  ---------------------------------------------------------------------------*/
1216 void SvxBorderTabPage::DataChanged( const DataChangedEvent& rDCEvt )
1217 {
1218     if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1219         FillValueSets();
1220 
1221     SfxTabPage::DataChanged( rDCEvt );
1222 }
1223 
1224 void SvxBorderTabPage::PageCreated (SfxAllItemSet aSet) //add CHINA001
1225 {
1226 	SFX_ITEMSET_ARG (&aSet,pSWModeItem,SfxUInt16Item,SID_SWMODE_TYPE,sal_False);
1227 	SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_FLAG_TYPE,sal_False);
1228 	if (pSWModeItem)
1229     {
1230 		nSWMode = pSWModeItem->GetValue();
1231         // --> OD 2005-03-01 #i43593#
1232         // show checkbox <aMergeWithNextCB> for format.paragraph
1233         if ( nSWMode == SW_BORDER_MODE_PARA )
1234         {
1235             aMergeWithNextCB.Show();
1236             aPropertiesFL.Show();
1237         }
1238         // show checkbox <aMergeAdjacentBordersCB> for format.paragraph
1239         else if ( nSWMode == SW_BORDER_MODE_TABLE )
1240         {
1241 			aMergeAdjacentBordersCB.Show();
1242             aPropertiesFL.Show();
1243         }
1244         // <--
1245     }
1246 	if (pFlagItem)
1247 		if ( ( pFlagItem->GetValue() & SVX_HIDESHADOWCTL ) == SVX_HIDESHADOWCTL )
1248 			HideShadowControls();
1249 }
1250 
1251 // ============================================================================
1252 
1253