xref: /trunk/main/sw/source/ui/table/tabledlg.cxx (revision 205b6fc7)
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_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 
32 #include <hintids.hxx>
33 #include <tools/list.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <svl/stritem.hxx>
36 #include <svl/intitem.hxx>
37 #include <svx/htmlmode.hxx>
38 #include <editeng/keepitem.hxx>
39 #include <editeng/brkitem.hxx>
40 #include <editeng/ulspitem.hxx>
41 #include <editeng/frmdiritem.hxx>
42 #include <svl/ctloptions.hxx>
43 #include <swmodule.hxx>
44 #include <fmtornt.hxx>
45 #include <fmtpdsc.hxx>
46 #include <fmtlsplt.hxx>
47 
48 #include <svtools/htmlcfg.hxx>
49 #include <fmtrowsplt.hxx>
50 #include <svx/htmlmode.hxx>
51 
52 #include "access.hrc"
53 
54 #ifndef _DOCSH_HXX
55 #include <docsh.hxx>
56 #endif
57 #include <wrtsh.hxx>
58 #ifndef _VIEW_HXX
59 #include <view.hxx>
60 #endif
61 #include <viewopt.hxx>
62 #include <uitool.hxx>
63 #include <frmatr.hxx>
64 #include <tabledlg.hxx>
65 #ifndef _TABLEPG_HXX
66 #include <tablepg.hxx>
67 #endif
68 #include <tablemgr.hxx>
69 #include <pagedesc.hxx>
70 #include <uiitems.hxx>
71 #include <poolfmt.hxx>
72 #include <SwStyleNameMapper.hxx>
73 
74 #ifndef _CMDID_H
75 #include <cmdid.h>
76 #endif
77 #ifndef _TABLEDLG_HRC
78 #include <tabledlg.hrc>
79 #endif
80 #ifndef _TABLE_HRC
81 #include <table.hrc>
82 #endif
83 #include <svx/svxids.hrc>
84 #include <svx/dialogs.hrc>
85 #include <svx/flagsdef.hxx>
86 #include <svx/svxdlg.hxx>
87 
88 using namespace ::com::sun::star;
89 
90 
91 #ifdef DEBUG_TBLDLG
92 void DbgTblRep(SwTableRep* pRep)
93 {
94 	DBG_ERROR(String(pRep->GetColCount()))
95 	DBG_ERROR(String(pRep->GetAllColCount()))
96 	SwTwips nSum = 0;
97 	for(sal_uInt16 i = 0; i < pRep->GetAllColCount(); i++)
98 	{
99 		String sMsg(i);
100 		sMsg += pRep->GetColumns()[i].bVisible ? " v " : " h ";
101 		sMsg += pRep->GetColumns()[i].nWidth;
102 		nSum +=pRep->GetColumns()[i].nWidth;
103 		DBG_ERROR(sMsg)
104 	}
105 	String sMsg("Spaltensumme: ");
106 	sMsg += nSum;
107 	sMsg += " Tblbreite: ";
108 	sMsg += pRep->GetWidth();
109 	DBG_ERROR(sMsg)
110 	sMsg = "Gesamt/Links/Rechts: ";
111 	sMsg += pRep->GetSpace();
112 	sMsg += '/';
113 	sMsg += pRep->GetLeftSpace();
114 	sMsg += '/';
115 	sMsg += pRep->GetRightSpace();
116 	DBG_ERROR(sMsg)
117 	sMsg = "Align: ";
118 	sMsg += pRep->GetAlign();
119 	DBG_ERROR(sMsg)
120 
121 };
122 
123 #endif
124 
125 
126 SwFormatTablePage::SwFormatTablePage( Window* pParent, const SfxItemSet& rSet ) :
127 	SfxTabPage(pParent, SW_RES( TP_FORMAT_TABLE ), rSet ),
128     aOptionsFL(this,    SW_RES( FL_OPTIONS )),
129 	aNameFT(this,		SW_RES( FT_NAME )),
130 	aNameED(this,		SW_RES( ED_NAME )),
131 	aWidthFT(this,		SW_RES( FT_WIDTH )),
132 	aWidthMF(this,		SW_RES( ED_WIDTH )),
133 	aRelWidthCB(this, 	SW_RES( CB_REL_WIDTH )),
134 
135     aPosFL(this,       SW_RES( FL_POS )),
136     aFullBtn(this,      SW_RES( RB_FULL )),
137     aLeftBtn(this,      SW_RES( RB_LEFT )),
138     aFromLeftBtn(this,  SW_RES( RB_FROM_LEFT )),
139     aRightBtn(this,     SW_RES( RB_RIGHT )),
140     aCenterBtn(this,    SW_RES( RB_CENTER )),
141     aFreeBtn(this,      SW_RES( RB_FREE )),
142 
143     aDistFL(this,       SW_RES( FL_DIST )),
144     aLeftFT(this,       SW_RES( FT_LEFT_DIST )),
145 	aLeftMF(this,		SW_RES( ED_LEFT_DIST )),
146 	aRightFT(this,		SW_RES( FT_RIGHT_DIST )),
147 	aRightMF(this,		SW_RES( ED_RIGHT_DIST )),
148 	aTopFT (this,		SW_RES( FT_TOP_DIST )),
149 	aTopMF(this,		SW_RES( ED_TOP_DIST )),
150 	aBottomFT(this,		SW_RES( FT_BOTTOM_DIST )),
151 	aBottomMF(this,		SW_RES( ED_BOTTOM_DIST )),
152 
153     aPropertiesFL(this,     SW_RES( FL_PROPERTIES    )),
154     aTextDirectionFT(this,  SW_RES( FT_TEXTDIRECTION )),
155     aTextDirectionLB(this,  SW_RES( LB_TEXTDIRECTION )),
156 
157     pTblData(0),
158 	nSaveWidth(0),
159 	nMinTableWidth(MINLAY),
160 	bModified(sal_False),
161     bFull(0),
162     bHtmlMode(sal_False)
163 {
164 	FreeResource();
165 	SetExchangeSupport();
166 
167     const SfxPoolItem* pItem;
168     if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, sal_False, &pItem))
169         bHtmlMode = 0 != (((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON);
170 
171     sal_Bool bCTL = SW_MOD()->GetCTLOptions().IsCTLFontEnabled();
172     if( !bHtmlMode && bCTL )
173     {
174         aPropertiesFL.Show();
175         aTextDirectionFT.Show();
176         aTextDirectionLB.Show();
177     }
178 
179     Init();
180 }
181 
182 /*------------------------------------------------------------------------
183 ------------------------------------------------------------------------*/
184 void  SwFormatTablePage::Init()
185 {
186 	aLeftMF.MetricField::SetMin(-999999);
187 	aRightMF.MetricField::SetMin(-999999);
188 
189 	// handler
190 	Link aLk = LINK( this, SwFormatTablePage, AutoClickHdl );
191 	aFullBtn.SetClickHdl( aLk );
192 	aFreeBtn.SetClickHdl( aLk );
193 	aLeftBtn.SetClickHdl( aLk );
194 	aFromLeftBtn.SetClickHdl( aLk );
195 	aRightBtn.SetClickHdl( aLk );
196 	aCenterBtn.SetClickHdl( aLk );
197 
198     aLk = LINK( this, SwFormatTablePage, UpDownLoseFocusHdl );
199 	aTopMF.SetUpHdl( aLk );
200 	aBottomMF.SetUpHdl( aLk );
201 	aRightMF.SetUpHdl( aLk );
202 	aLeftMF.SetUpHdl( aLk );
203 	aWidthMF.SetUpHdl( aLk );
204 
205     aTopMF.SetDownHdl( aLk );
206 	aBottomMF.SetDownHdl( aLk );
207 	aRightMF.SetDownHdl( aLk );
208 	aLeftMF.SetDownHdl( aLk );
209 	aWidthMF.SetDownHdl( aLk );
210 
211 	aTopMF.SetLoseFocusHdl( aLk );
212 	aBottomMF.SetLoseFocusHdl( aLk );
213 	aRightMF.SetLoseFocusHdl( aLk );
214 	aLeftMF.SetLoseFocusHdl( aLk );
215 	aWidthMF.SetLoseFocusHdl( aLk );
216 
217 	aRelWidthCB.SetClickHdl(LINK( this, SwFormatTablePage, RelWidthClickHdl ));
218 }
219 
220 /*------------------------------------------------------------------------*/
221 
222 IMPL_LINK( SwFormatTablePage, RelWidthClickHdl, CheckBox *, pBtn )
223 {
224 	DBG_ASSERT(pTblData, "Tabellendaten nicht da?");
225 	sal_Bool bIsChecked = pBtn->IsChecked();
226     sal_Int64 nLeft  = aLeftMF.DenormalizePercent(aLeftMF.GetValue(FUNIT_TWIP ));
227     sal_Int64 nRight = aRightMF.DenormalizePercent(aRightMF.GetValue(FUNIT_TWIP ));
228 	aWidthMF.ShowPercent(bIsChecked);
229 	aLeftMF.ShowPercent(bIsChecked);
230 	aRightMF.ShowPercent(bIsChecked);
231 
232 	if (bIsChecked)
233 	{
234 		aWidthMF.SetRefValue(pTblData->GetSpace());
235 		aLeftMF.SetRefValue(pTblData->GetSpace());
236 		aRightMF.SetRefValue(pTblData->GetSpace());
237 		aLeftMF.MetricField::SetMin(0); // wird vom Percentfield ueberschrieben
238 		aRightMF.MetricField::SetMin(0);//                 -""-
239         aLeftMF.MetricField::SetMax(99); //
240         aRightMF.MetricField::SetMax(99);//
241         aLeftMF.SetPrcntValue(aLeftMF.NormalizePercent(nLeft ), FUNIT_TWIP );
242         aRightMF.SetPrcntValue(aRightMF.NormalizePercent(nRight ), FUNIT_TWIP );
243 	}
244 	else
245 		ModifyHdl(&aLeftMF);	// Werte wieder korrigieren
246 
247 	if(aFreeBtn.IsChecked())
248 	{
249 		sal_Bool bEnable = !pBtn->IsChecked();
250 		aRightMF.Enable(bEnable);
251 		aRightFT.Enable(bEnable);
252 	}
253 	bModified = sal_True;
254 
255 	return 0;
256 }
257 
258 /*------------------------------------------------------------------------
259 ------------------------------------------------------------------------*/
260 IMPL_LINK( SwFormatTablePage, AutoClickHdl, CheckBox *, pBox )
261 {
262 	sal_Bool bRestore = sal_True,
263 		 bLeftEnable = sal_False,
264 		 bRightEnable= sal_False,
265 		 bWidthEnable= sal_False,
266 		 bOthers = sal_True;
267 	if( (RadioButton *) pBox == &aFullBtn )
268 	{
269         aLeftMF.SetPrcntValue(0);
270         aRightMF.SetPrcntValue(0);
271         nSaveWidth = static_cast< SwTwips >(aWidthMF.DenormalizePercent(aWidthMF.GetValue(FUNIT_TWIP )));
272         aWidthMF.SetPrcntValue(aWidthMF.NormalizePercent(pTblData->GetSpace() ), FUNIT_TWIP );
273 		bFull = sal_True;
274 		bRestore = sal_False;
275 	}
276 	else if( (RadioButton *) pBox == &aLeftBtn )
277 	{
278 		bRightEnable = bWidthEnable = sal_True;
279         aLeftMF.SetPrcntValue(0);
280 	}
281 	else if( (RadioButton *) pBox == &aFromLeftBtn )
282 	{
283 		bLeftEnable = bWidthEnable = sal_True;
284         aRightMF.SetPrcntValue(0);
285 	}
286 	else if( (RadioButton *) pBox == &aRightBtn )
287 	{
288 		bLeftEnable = bWidthEnable = sal_True;
289         aRightMF.SetPrcntValue(0);
290 	}
291 	else if( ( RadioButton * ) pBox == &aCenterBtn )
292 	{
293 		bLeftEnable = bWidthEnable = sal_True;
294 	}
295 	else if( ( RadioButton * ) pBox == &aFreeBtn )
296 	{
297 		RightModifyHdl(&aRightMF);
298 		bLeftEnable = sal_True;
299 		bWidthEnable = sal_True;
300 		bOthers = sal_False;
301 	}
302 	aLeftMF.Enable(bLeftEnable);
303 	aLeftFT.Enable(bLeftEnable);
304 	aWidthMF.Enable(bWidthEnable);
305 	aWidthFT.Enable(bWidthEnable);
306 	if ( bOthers )
307 	{
308 		aRightMF.Enable(bRightEnable);
309 		aRightFT.Enable(bRightEnable);
310 		aRelWidthCB.Enable(bWidthEnable);
311 	}
312 
313 	if(bFull && bRestore)
314 	{
315 		// nachdem auf autom. geschaltet wurde, wurde die Breite gemerkt,
316 		// um sie beim Zurueckschalten restaurieren zu koennen
317 		bFull = sal_False;
318         aWidthMF.SetPrcntValue(aWidthMF.NormalizePercent(nSaveWidth ), FUNIT_TWIP );
319 	}
320 	ModifyHdl(&aWidthMF);
321 	bModified = sal_True;
322 	return 0;
323 }
324 
325 /*----------------------------------------------------------------------*/
326 IMPL_LINK( SwFormatTablePage, RightModifyHdl, MetricField *, EMPTYARG )
327 {
328 	if(aFreeBtn.IsChecked())
329 	{
330 		sal_Bool bEnable = aRightMF.GetValue() == 0;
331 //		aWidthMF.Enable(bEnable);
332 		aRelWidthCB.Enable(bEnable);
333 //		aWidthFT.Enable(bEnable);
334 		if ( !bEnable )
335 		{
336 			aRelWidthCB.Check(sal_False);
337 			RelWidthClickHdl(&aRelWidthCB);
338 		}
339 		bEnable = aRelWidthCB.IsChecked();
340 		aRightMF.Enable(!bEnable);
341 		aRightFT.Enable(!bEnable);
342 	}
343 	return 0;
344 }
345 
346 /*------------------------------------------------------------------------
347 ------------------------------------------------------------------------*/
348 IMPL_LINK_INLINE_START( SwFormatTablePage, UpDownLoseFocusHdl, MetricField *, pEdit )
349 {
350     if( &aRightMF == pEdit)
351         RightModifyHdl(pEdit);
352     ModifyHdl( pEdit );
353 	return 0;
354 }
355 IMPL_LINK_INLINE_END( SwFormatTablePage, UpDownLoseFocusHdl, MetricField *, pEdit )
356 
357 void  SwFormatTablePage::ModifyHdl( Edit* pEdit )
358 {
359 
360     SwTwips nCurWidth  = static_cast< SwTwips >(aWidthMF.DenormalizePercent(aWidthMF.GetValue( FUNIT_TWIP )));
361 	SwTwips nPrevWidth = nCurWidth;
362     SwTwips nRight = static_cast< SwTwips >(aRightMF.DenormalizePercent(aRightMF.GetValue( FUNIT_TWIP )));
363     SwTwips nLeft  = static_cast< SwTwips >(aLeftMF.DenormalizePercent(aLeftMF.GetValue( FUNIT_TWIP )));
364 	SwTwips nDiff;
365 
366 	if( pEdit == &aWidthMF )
367 	{
368 		if( nCurWidth < MINLAY )
369 			nCurWidth = MINLAY;
370 		nDiff = nRight + nLeft + nCurWidth - pTblData->GetSpace() ;
371 		//rechtsbuendig nur linken Rand veraendern
372 		if(aRightBtn.IsChecked())
373 			nLeft -= nDiff;
374 		//linksbuendig nur rechten Rand veraendern
375 		else if(aLeftBtn.IsChecked())
376 			nRight -= nDiff;
377 		//linker Rand und Breite erlaubt - erst rechts - dann links
378 		else if(aFromLeftBtn.IsChecked())
379 		{
380 			if( nRight >= nDiff )
381 				nRight -= nDiff;
382 			else
383 			{
384 				nDiff -= nRight;
385 				nRight = 0;
386 				if(nLeft >= nDiff)
387 					nLeft -= nDiff;
388 				else
389 				{
390 					nRight += nLeft - nDiff;
391 					nLeft = 0;
392 					nCurWidth = pTblData->GetSpace();
393 				}
394 
395 			}
396 		}
397 		//zentriert beide Seiten gleichmaessig veraendern
398 		else if(aCenterBtn.IsChecked())
399 		{
400 			if((nLeft != nRight))
401 			{
402 				nDiff += nLeft + nRight;
403 				nLeft = nDiff/2;
404 				nRight = nDiff/2;
405 			}
406 			else
407 			{
408 					nLeft -= nDiff/2;
409 					nRight -= nDiff/2;
410 			}
411 		}
412 		//freie Ausrichtung: beide Raender verkleinern
413 		else if(aFreeBtn.IsChecked())
414 		{
415 			nLeft -= nDiff/2;
416 			nRight -= nDiff/2;
417 		}
418 	}
419 	if( pEdit == &aRightMF	)
420 	{
421 
422 		if( nRight + nLeft > pTblData->GetSpace() - MINLAY )
423 			nRight = pTblData->GetSpace() -nLeft - MINLAY;
424 
425 		nCurWidth = pTblData->GetSpace() - nLeft - nRight;
426 	}
427 	if( pEdit == &aLeftMF )
428 	{
429 		if(!aFromLeftBtn.IsChecked())
430 		{
431 			sal_Bool bCenter = aCenterBtn.IsChecked();
432 			if( bCenter )
433 				nRight = nLeft;
434 			if(nRight + nLeft > pTblData->GetSpace() - MINLAY )
435 			{
436 				nLeft  = bCenter ? 	(pTblData->GetSpace() - MINLAY) /2 :
437 									(pTblData->GetSpace() - MINLAY) - nRight;
438 				nRight = bCenter ? 	(pTblData->GetSpace() - MINLAY) /2 : nRight;
439 			}
440 			nCurWidth = pTblData->GetSpace() - nLeft - nRight;
441 		}
442 		else
443 		{
444 			//hier wird bei Aenderung an der linken Seite zuerst der
445 			//rechte Rand veraendert, dann die Breite
446 			nDiff = nRight + nLeft + nCurWidth - pTblData->GetSpace() ;
447 
448 			nRight -= nDiff;
449 			nCurWidth = pTblData->GetSpace() - nLeft - nRight;
450 		}
451 	}
452 	if (nCurWidth != nPrevWidth )
453         aWidthMF.SetPrcntValue( aWidthMF.NormalizePercent( nCurWidth ), FUNIT_TWIP );
454     aRightMF.SetPrcntValue( aRightMF.NormalizePercent( nRight ), FUNIT_TWIP );
455     aLeftMF.SetPrcntValue( aLeftMF.NormalizePercent( nLeft ), FUNIT_TWIP );
456 	bModified = sal_True;
457 }
458 
459 /*------------------------------------------------------------------------
460 ------------------------------------------------------------------------*/
461 SfxTabPage*  SwFormatTablePage::Create( Window* pParent,
462 								   const SfxItemSet& rAttrSet)
463 {
464 	return new SwFormatTablePage( pParent, rAttrSet );
465 }
466 
467 /*------------------------------------------------------------------------
468 -------------------------------------------------------------------------*/
469 sal_Bool  SwFormatTablePage::FillItemSet( SfxItemSet& rCoreSet )
470 {
471 	// Testen, ob eins der Control noch den Focus hat
472 	if(aWidthMF.HasFocus())
473 		ModifyHdl(&aWidthMF);
474 	else if(aLeftMF.HasFocus())
475 		ModifyHdl(&aLeftMF);
476 	else if(aRightMF.HasFocus())
477 		ModifyHdl(&aRightMF);
478 	else if(aTopMF.HasFocus())
479 		ModifyHdl(&aTopMF);
480 	else if(aBottomMF.HasFocus())
481 		ModifyHdl(&aBottomMF);
482 
483 	if(bModified)
484 	{
485 		if( aBottomMF.GetText() != aBottomMF.GetSavedValue() ||
486 									aTopMF.GetText() != aTopMF.GetSavedValue() )
487 		{
488 			SvxULSpaceItem aULSpace(RES_UL_SPACE);
489 			aULSpace.SetUpper( (sal_uInt16) aTopMF.Denormalize(
490 										aTopMF.GetValue( FUNIT_TWIP )));
491 			aULSpace.SetLower( (sal_uInt16) aBottomMF.Denormalize(
492 										aBottomMF.GetValue( FUNIT_TWIP )));
493 			rCoreSet.Put(aULSpace);
494 		}
495 
496 	}
497 	if(aNameED.GetText() != aNameED.GetSavedValue())
498 	{
499 		rCoreSet.Put(SfxStringItem(	FN_PARAM_TABLE_NAME, aNameED.GetText()));
500 		bModified = sal_True;
501 	}
502 
503     sal_uInt16 nPos;
504     if( aTextDirectionLB.IsVisible() &&
505         ( nPos = aTextDirectionLB.GetSelectEntryPos() ) !=
506                                             aTextDirectionLB.GetSavedValue() )
507 	{
508         sal_uInt32 nDirection = (sal_uInt32)(sal_uIntPtr)aTextDirectionLB.GetEntryData( nPos );
509         rCoreSet.Put( SvxFrameDirectionItem( (SvxFrameDirection)nDirection, RES_FRAMEDIR));
510 		bModified = sal_True;
511 	}
512 
513     return bModified;
514 }
515 
516 /*------------------------------------------------------------------------
517 ------------------------------------------------------------------------*/
518 void  SwFormatTablePage::Reset( const SfxItemSet& )
519 {
520 	const SfxItemSet& rSet = GetItemSet();
521 	const SfxPoolItem*	pItem;
522 
523     if(bHtmlMode)
524 	{
525 		aNameED	.Disable();
526 		aTopFT	.Hide();
527 		aTopMF	.Hide();
528 		aBottomFT.Hide();
529 		aBottomMF.Hide();
530 		aFreeBtn.Enable(sal_False);
531 	}
532 	FieldUnit aMetric = ::GetDfltMetric(bHtmlMode);
533 	SetMetric( aWidthMF, aMetric );
534 	SetMetric( aRightMF, aMetric );
535 	SetMetric( aLeftMF, aMetric );
536 	SetMetric( aTopMF, aMetric );
537 	SetMetric( aBottomMF, aMetric );
538 
539 	//Name
540 	if(SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_NAME, sal_False, &pItem ))
541 	{
542 		aNameED.SetText(((const SfxStringItem*)pItem)->GetValue());
543 		aNameED.SaveValue();
544 	}
545 
546 	if(SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_REP, sal_False, &pItem ))
547 	{
548 		pTblData = (SwTableRep*)((const SwPtrItem*) pItem)->GetValue();
549 		nMinTableWidth = pTblData->GetColCount() * MINLAY;
550 
551 		if(pTblData->GetWidthPercent())
552 		{
553 			aRelWidthCB.Check(sal_True);
554 			RelWidthClickHdl(&aRelWidthCB);
555             aWidthMF.SetPrcntValue(pTblData->GetWidthPercent(), FUNIT_CUSTOM);
556 
557 			aWidthMF.SaveValue();
558             nSaveWidth = static_cast< SwTwips >(aWidthMF.GetValue(FUNIT_CUSTOM));
559 		}
560 		else
561 		{
562             aWidthMF.SetPrcntValue(aWidthMF.NormalizePercent(
563 					pTblData->GetWidth()), FUNIT_TWIP);
564 			aWidthMF.SaveValue();
565 			nSaveWidth = pTblData->GetWidth();
566 			nMinTableWidth = Min( nSaveWidth, nMinTableWidth );
567 		}
568 
569 		aWidthMF.SetRefValue(pTblData->GetSpace());
570 		aWidthMF.SetLast(aWidthMF.NormalizePercent( pTblData->GetSpace() ));
571 		aLeftMF.SetLast(aLeftMF.NormalizePercent( pTblData->GetSpace() ));
572 		aRightMF.SetLast(aRightMF.NormalizePercent( pTblData->GetSpace() ));
573 
574         aLeftMF.SetPrcntValue(aLeftMF.NormalizePercent(
575 					pTblData->GetLeftSpace()), FUNIT_TWIP);
576         aRightMF.SetPrcntValue(aRightMF.NormalizePercent(
577 					pTblData->GetRightSpace()), FUNIT_TWIP);
578 		aLeftMF.SaveValue();
579 		aRightMF.SaveValue();
580 
581 		nOldAlign = pTblData->GetAlign();
582 
583 		sal_Bool bSetRight = sal_False, bRightEnable = sal_False,
584 			 bSetLeft  = sal_False, bLeftEnable  = sal_False;
585 		switch( nOldAlign )
586 		{
587             case text::HoriOrientation::NONE:
588 				aFreeBtn.Check();
589 				if(aRelWidthCB.IsChecked())
590 					bSetRight = sal_True;
591 			break;
592             case text::HoriOrientation::FULL:
593 			{
594 				bSetRight = bSetLeft = sal_True;
595 				aFullBtn.Check();
596 				aWidthMF.Enable(sal_False);
597 				aRelWidthCB.Enable(sal_False);
598 				aWidthFT.Enable(sal_False);
599 			}
600 			break;
601             case text::HoriOrientation::LEFT:
602 			{
603 				bSetLeft = sal_True;
604 				aLeftBtn.Check();
605 			}
606 			break;
607             case text::HoriOrientation::LEFT_AND_WIDTH :
608 			{
609 				bSetRight = sal_True;
610 				aFromLeftBtn.Check();
611 			}
612 			break;
613             case text::HoriOrientation::RIGHT:
614 			{
615 				bSetRight = sal_True;
616 				aRightBtn.Check();
617 			}
618 			break;
619             case text::HoriOrientation::CENTER:
620 			{
621 				bSetRight = sal_True;
622 				aCenterBtn.Check();
623 			}
624 			break;
625 		}
626 		if ( bSetRight )
627 		{
628 			aRightMF.Enable(bRightEnable);
629 			aRightFT.Enable(bRightEnable);
630 		}
631 		if ( bSetLeft )
632 		{
633 			aLeftMF.Enable(bLeftEnable);
634 			aLeftFT.Enable(bLeftEnable);
635 		}
636 
637 	}
638 
639 	//Raender
640 	if(SFX_ITEM_SET == rSet.GetItemState( RES_UL_SPACE, sal_False,&pItem ))
641 	{
642 		aTopMF.SetValue(aTopMF.Normalize(
643 						((const SvxULSpaceItem*)pItem)->GetUpper()), FUNIT_TWIP);
644 		aBottomMF.SetValue(aBottomMF.Normalize(
645 						((const SvxULSpaceItem*)pItem)->GetLower()), FUNIT_TWIP);
646 		aTopMF.SaveValue();
647 		aBottomMF.SaveValue();
648 	}
649 
650     //text direction
651     if( SFX_ITEM_SET == rSet.GetItemState( RES_FRAMEDIR, sal_True, &pItem ) )
652 	{
653         sal_uInt32 nVal  = ((SvxFrameDirectionItem*)pItem)->GetValue();
654         sal_uInt16 nPos = aTextDirectionLB.GetEntryPos( (void*) nVal );
655         aTextDirectionLB.SelectEntryPos( nPos );
656         aTextDirectionLB.SaveValue();
657 	}
658 
659     aWidthMF.SetMax( 2*aWidthMF.NormalizePercent( pTblData->GetSpace() ), FUNIT_TWIP );
660 	aRightMF.SetMax( aRightMF.NormalizePercent( pTblData->GetSpace() ), FUNIT_TWIP );
661 	aLeftMF.SetMax( aLeftMF.NormalizePercent( pTblData->GetSpace() ), FUNIT_TWIP );
662 	aWidthMF.SetMin( aWidthMF.NormalizePercent( nMinTableWidth ), FUNIT_TWIP );
663 
664 }
665 
666 /*------------------------------------------------------------------------
667 ------------------------------------------------------------------------*/
668 void  	SwFormatTablePage::ActivatePage( const SfxItemSet& rSet )
669 {
670 	DBG_ASSERT(pTblData, "Tabellendaten nicht da?");
671 	if(SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_REP ))
672 	{
673         SwTwips nCurWidth = text::HoriOrientation::FULL != pTblData->GetAlign() ?
674 										pTblData->GetWidth() :
675 											pTblData->GetSpace();
676 		if(pTblData->GetWidthPercent() == 0 &&
677 				nCurWidth != aWidthMF.DenormalizePercent(aWidthMF.GetValue(FUNIT_TWIP )))
678 		{
679             aWidthMF.SetPrcntValue(aWidthMF.NormalizePercent(
680 							nCurWidth), FUNIT_TWIP);
681 			aWidthMF.SaveValue();
682 			nSaveWidth = nCurWidth;
683             aLeftMF.SetPrcntValue(aLeftMF.NormalizePercent(
684 							pTblData->GetLeftSpace()), FUNIT_TWIP);
685 			aLeftMF.SaveValue();
686             aRightMF.SetPrcntValue(aRightMF.NormalizePercent(
687 							pTblData->GetRightSpace()), FUNIT_TWIP);
688 			aRightMF.SaveValue();
689 		}
690 	}
691 
692 }
693 /*------------------------------------------------------------------------
694 ------------------------------------------------------------------------*/
695 int  SwFormatTablePage::DeactivatePage( SfxItemSet* _pSet )
696 {
697 	// os: VCL sorgt nicht dafuer, dass das aktive Control im
698 	// dialog bei OK den focus verliert
699 	aNameED.GrabFocus();
700 	// Test des Tabellennamens auf Leerzeichen
701 	String sTblName = aNameED.GetText();
702 	if(sTblName.Search(' ') != STRING_NOTFOUND)
703 	{
704 		InfoBox(this, SW_RES(MSG_WRONG_TABLENAME)).Execute();
705 		aNameED.GrabFocus();
706 		return KEEP_PAGE;
707 	}
708     if(_pSet)
709 	{
710         FillItemSet(*_pSet);
711 		if(bModified)
712 		{
713             SwTwips lLeft  = static_cast< SwTwips >(aLeftMF.DenormalizePercent(aLeftMF.GetValue( FUNIT_TWIP )));
714             SwTwips lRight = static_cast< SwTwips >(aRightMF.DenormalizePercent(aRightMF.GetValue( FUNIT_TWIP )));
715 
716 
717 			if( aLeftMF.GetText() != aLeftMF.GetSavedValue() ||
718 									aRightMF.GetText() != aRightMF.GetSavedValue() )
719 			{
720 				pTblData->SetWidthChanged();
721 				pTblData->SetLeftSpace( lLeft);
722 				pTblData->SetRightSpace( lRight);
723 			}
724 
725 			SwTwips lWidth;
726 			if (aRelWidthCB.IsChecked() && aRelWidthCB.IsEnabled())
727 			{
728 				lWidth = pTblData->GetSpace() - lRight - lLeft;
729 				sal_uInt16 nPercentWidth = (sal_uInt16)aWidthMF.GetValue(FUNIT_CUSTOM);
730 				if(pTblData->GetWidthPercent() != nPercentWidth)
731 				{
732 					pTblData->SetWidthPercent(nPercentWidth);
733 					pTblData->SetWidthChanged();
734 				}
735 			}
736 			else
737 			{
738 				pTblData->SetWidthPercent(0);
739                 lWidth = static_cast< SwTwips >(aWidthMF.DenormalizePercent(aWidthMF.GetValue( FUNIT_TWIP )));
740 			}
741 			pTblData->SetWidth(lWidth);
742 
743 			SwTwips nColSum = 0;
744 			sal_uInt16 i;
745 
746 			for( i = 0; i < pTblData->GetColCount(); i++)
747 			{
748 				nColSum += pTblData->GetColumns()[i].nWidth;
749 			}
750 			if(nColSum != pTblData->GetWidth())
751 			{
752 				SwTwips nMinWidth = Min( (long)MINLAY,
753 									(long) (pTblData->GetWidth() /
754 											pTblData->GetColCount() - 1));
755 				SwTwips nDiff = nColSum - pTblData->GetWidth();
756 				while ( Abs(nDiff) > pTblData->GetColCount() + 1 )
757 				{
758 					SwTwips nSub = nDiff / pTblData->GetColCount();
759 					for( i = 0; i < pTblData->GetColCount(); i++)
760 					{
761 						if(pTblData->GetColumns()[i].nWidth - nMinWidth > nSub)
762 						{
763 							pTblData->GetColumns()[i].nWidth -= nSub;
764 							nDiff -= nSub;
765 						}
766 						else
767 						{
768 							nDiff -= pTblData->GetColumns()[i].nWidth - nMinWidth;
769 							pTblData->GetColumns()[i].nWidth = nMinWidth;
770 						}
771 
772 					}
773 				}
774 			}
775 
776             sal_Int16 nAlign = 0;
777 			if(aRightBtn.IsChecked())
778                 nAlign = text::HoriOrientation::RIGHT;
779 			else if(aLeftBtn.IsChecked())
780                 nAlign = text::HoriOrientation::LEFT;
781 			else if(aFromLeftBtn.IsChecked())
782                 nAlign = text::HoriOrientation::LEFT_AND_WIDTH;
783 			else if(aCenterBtn.IsChecked())
784                 nAlign = text::HoriOrientation::CENTER;
785 			else if(aFreeBtn.IsChecked())
786                 nAlign = text::HoriOrientation::NONE;
787 			else if(aFullBtn.IsChecked())
788 			{
789                 nAlign = text::HoriOrientation::FULL;
790 				lWidth = lAutoWidth;
791 			}
792 			if(nAlign != pTblData->GetAlign())
793 			{
794 				pTblData->SetWidthChanged();
795 				pTblData->SetAlign(nAlign);
796 			}
797 
798 
799     //      if(  text::HoriOrientation::CENTER && lWidth != (SwTwips)aWidthMF.GetSavedValue())
800 			if(pTblData->GetWidth() != lWidth )
801 			{
802 				pTblData->SetWidthChanged();
803 				pTblData->SetWidth(
804                     nAlign == text::HoriOrientation::FULL ? pTblData->GetSpace() : lWidth );
805 			}
806 			if(pTblData->HasWidthChanged())
807                 _pSet->Put(SwPtrItem(FN_TABLE_REP, pTblData));
808 		}
809 #ifdef DEBUG_TBLDLG
810 DbgTblRep(pTblData)
811 #endif
812 	}
813 	return sal_True;
814 }
815 /*------------------------------------------------------------------------
816 	Beschreibung: Seite Spaltenkonfiguration
817 ------------------------------------------------------------------------*/
818 SwTableColumnPage::SwTableColumnPage( Window* pParent,
819 			const SfxItemSet& rSet ) :
820 	SfxTabPage(pParent, SW_RES( TP_TABLE_COLUMN ), rSet ),
821 	aModifyTableCB(this,	SW_RES(CB_MOD_TBL)),
822 	aProportionalCB(this,	SW_RES(CB_PROP)),
823 	aSpaceFT(this,			SW_RES(FT_SPACE)),
824 	aSpaceED(this,			SW_RES(ED_SPACE)),
825 
826     aColFL(this,            SW_RES(COL_FL_LAYOUT)),
827     aUpBtn(this,            SW_RES(COL_BTN_UP)),
828     aFT1(this,              SW_RES(COL_FT_1)),
829 	aMF1(this,				SW_RES(COL_MF_1)),
830 	aFT2(this,				SW_RES(COL_FT_2)),
831 	aMF2(this,				SW_RES(COL_MF_2)),
832 	aFT3(this,				SW_RES(COL_FT_3)),
833 	aMF3(this,				SW_RES(COL_MF_3)),
834 	aFT4(this,				SW_RES(COL_FT_4)),
835 	aMF4(this,				SW_RES(COL_MF_4)),
836 	aFT5(this,				SW_RES(COL_FT_5)),
837 	aMF5(this,				SW_RES(COL_MF_5)),
838 	aFT6(this,				SW_RES(COL_FT_6)),
839 	aMF6(this,				SW_RES(COL_MF_6)),
840     aDownBtn(this,          SW_RES(COL_BTN_DOWN)),
841 
842     nTableWidth(0),
843     nMinWidth( MINLAY ),
844     nNoOfCols( 0 ),
845 	nNoOfVisibleCols( 0 ),
846 	bModified(sal_False),
847 	bModifyTbl(sal_False),
848     bPercentMode(sal_False)
849 {
850 	FreeResource();
851 	SetExchangeSupport();
852 
853 	aDownBtn.SetAccessibleRelationMemberOf(&aColFL);
854 	aUpBtn.SetAccessibleRelationMemberOf(&aColFL);
855 
856 	pFieldArr[0] = &aMF1;
857 	pFieldArr[1] = &aMF2;
858 	pFieldArr[2] = &aMF3;
859 	pFieldArr[3] = &aMF4;
860 	pFieldArr[4] = &aMF5;
861 	pFieldArr[5] = &aMF6;
862 
863 	pTextArr[0] = &aFT1;
864 	pTextArr[1] = &aFT2;
865 	pTextArr[2] = &aFT3;
866 	pTextArr[3] = &aFT4;
867 	pTextArr[4] = &aFT5;
868 	pTextArr[5] = &aFT6;
869 
870 	const SfxPoolItem* pItem;
871 	Init((SFX_ITEM_SET == rSet.GetItemState( SID_HTML_MODE, sal_False,&pItem )
872 		&& ((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON));
873 
874 };
875 /*------------------------------------------------------------------------
876 	Beschreibung: Seite Spaltenkonfiguration
877 ------------------------------------------------------------------------*/
878  SwTableColumnPage::~SwTableColumnPage()
879 {
880 };
881 
882 /*------------------------------------------------------------------------
883 ------------------------------------------------------------------------*/
884 SfxTabPage*   SwTableColumnPage::Create( Window* pParent,
885 								const SfxItemSet& rAttrSet)
886 {
887 	return new SwTableColumnPage( pParent, rAttrSet );
888 };
889 
890 /*------------------------------------------------------------------------
891 ------------------------------------------------------------------------*/
892 void  SwTableColumnPage::Reset( const SfxItemSet& )
893 {
894 	const SfxItemSet& rSet = GetItemSet();
895 
896 	const SfxPoolItem* pItem;
897 	if(SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_REP, sal_False, &pItem ))
898 	{
899 		pTblData = (SwTableRep*)((const SwPtrItem*) pItem)->GetValue();
900 		nNoOfVisibleCols = pTblData->GetColCount();
901 		nNoOfCols = pTblData->GetAllColCount();
902         nTableWidth = pTblData->GetAlign() != text::HoriOrientation::FULL &&
903                             pTblData->GetAlign() != text::HoriOrientation::LEFT_AND_WIDTH?
904 						pTblData->GetWidth() : pTblData->GetSpace();
905 
906 		sal_uInt16 i;
907 		for( i = 0; i < nNoOfCols; i++ )
908 		{
909 			if( pTblData->GetColumns()[i].nWidth  < nMinWidth )
910 					nMinWidth = pTblData->GetColumns()[i].nWidth;
911 		}
912         sal_Int64 nMinTwips = pFieldArr[0]->NormalizePercent( nMinWidth );
913         sal_Int64 nMaxTwips = pFieldArr[0]->NormalizePercent( nTableWidth );
914 		for( i = 0; (i < MET_FIELDS) && (i < nNoOfVisibleCols); i++ )
915 		{
916             pFieldArr[i]->SetPrcntValue( pFieldArr[i]->NormalizePercent(
917 												GetVisibleWidth(i) ), FUNIT_TWIP );
918 			pFieldArr[i]->SetMin( nMinTwips , FUNIT_TWIP );
919 			pFieldArr[i]->SetMax( nMaxTwips , FUNIT_TWIP );
920 			pFieldArr[i]->Enable();
921 			pTextArr[i]->Enable();
922 		}
923 
924 		if( nNoOfVisibleCols > MET_FIELDS )
925 			aUpBtn.Enable();
926 		i = nNoOfVisibleCols;
927 		while( i < MET_FIELDS )
928 		{
929 			pFieldArr[i]->SetText( aEmptyStr );
930 			pTextArr[i]->Hide();
931 			i++;
932 		}
933 	}
934 	ActivatePage(rSet);
935 
936 };
937 
938 /*------------------------------------------------------------------------
939 ------------------------------------------------------------------------*/
940 void  SwTableColumnPage::Init(sal_Bool bWeb)
941 {
942 	FieldUnit aMetric = ::GetDfltMetric(bWeb);
943 	Link aLkUp = LINK( this, SwTableColumnPage, UpHdl );
944 	Link aLkDown = LINK( this, SwTableColumnPage, DownHdl );
945 	Link aLkLF = LINK( this, SwTableColumnPage, LoseFocusHdl );
946 	for( sal_uInt16 i = 0; i < MET_FIELDS; i++ )
947 	{
948 		aValueTbl[i] = i;
949 		SetMetric(*pFieldArr[i], aMetric);
950 		pFieldArr[i]->SetUpHdl( aLkUp );
951 		pFieldArr[i]->SetDownHdl( aLkDown );
952 		pFieldArr[i]->SetLoseFocusHdl( aLkLF );
953 
954 	}
955 	SetMetric(aSpaceED, aMetric);
956 
957 	Link aLk = LINK( this, SwTableColumnPage, AutoClickHdl );
958 	aUpBtn.SetClickHdl( aLk );
959 	aDownBtn.SetClickHdl( aLk );
960 
961 	aLk = LINK( this, SwTableColumnPage, ModeHdl );
962 	aModifyTableCB .SetClickHdl( aLk );
963 	aProportionalCB.SetClickHdl( aLk );
964 };
965 
966 /*------------------------------------------------------------------------
967 ------------------------------------------------------------------------*/
968 IMPL_LINK( SwTableColumnPage, AutoClickHdl, CheckBox *, pBox )
969 {
970 	//Anzeigefenster verschieben
971 	if(pBox == (CheckBox *)&aDownBtn)
972 	{
973 		if(aValueTbl[0] > 0)
974 		{
975 			for( sal_uInt16 i=0; i < MET_FIELDS; i++ )
976 				aValueTbl[i] -= 1;
977 		}
978 	}
979 	if(pBox == (CheckBox *)&aUpBtn)
980 	{
981 		if( aValueTbl[ MET_FIELDS -1 ] < nNoOfVisibleCols -1  )
982 		{
983 			for(sal_uInt16 i=0;i < MET_FIELDS;i++)
984 				aValueTbl[i] += 1;
985 		}
986 	}
987 	for( sal_uInt16 i = 0; (i < nNoOfVisibleCols ) && ( i < MET_FIELDS); i++ )
988 	{
989 		String sEntry('~');
990 		String sIndex = String::CreateFromInt32( aValueTbl[i] + 1 );
991 		sEntry += sIndex;
992 		pTextArr[i]->SetText( sEntry );
993 //IAccessibility2 Impplementaton 2009-----
994 		//added by menghu for SODC_5143,12/12/2006
995 		String sColumnWidth = SW_RESSTR( STR_ACCESS_COLUMN_WIDTH);
996 		sColumnWidth.SearchAndReplace( DEFINE_CONST_UNICODE("%1"), sIndex );
997 		pFieldArr[i]->SetAccessibleName( sColumnWidth );
998 		//end of SODC_5143
999 //-----IAccessibility2 Impplementaton 2009
1000 	}
1001 
1002 	aDownBtn.Enable(aValueTbl[0] > 0);
1003 	aUpBtn.Enable(aValueTbl[ MET_FIELDS -1 ] < nNoOfVisibleCols -1 );
1004 	UpdateCols(0);
1005 	return 0;
1006 };
1007 
1008 /*------------------------------------------------------------------------
1009 ------------------------------------------------------------------------*/
1010 IMPL_LINK_INLINE_START( SwTableColumnPage, UpHdl, PercentField *, pEdit )
1011 {
1012 	bModified = sal_True;
1013 	ModifyHdl( pEdit );
1014 	return 0;
1015 };
1016 IMPL_LINK_INLINE_END( SwTableColumnPage, UpHdl, PercentField *, pEdit )
1017 
1018 /*------------------------------------------------------------------------
1019 ------------------------------------------------------------------------*/
1020 IMPL_LINK_INLINE_START( SwTableColumnPage, DownHdl, PercentField *, pEdit )
1021 {
1022 	bModified = sal_True;
1023 	ModifyHdl( pEdit );
1024 	return 0;
1025 };
1026 IMPL_LINK_INLINE_END( SwTableColumnPage, DownHdl, PercentField *, pEdit )
1027 
1028 /*------------------------------------------------------------------------
1029 ------------------------------------------------------------------------*/
1030 IMPL_LINK_INLINE_START( SwTableColumnPage, LoseFocusHdl, PercentField *, pEdit )
1031 {
1032 	if(pEdit->IsModified())
1033 	{
1034 		bModified = sal_True;
1035 		ModifyHdl( pEdit );
1036 	}
1037 	return 0;
1038 };
1039 IMPL_LINK_INLINE_END( SwTableColumnPage, LoseFocusHdl, PercentField *, pEdit )
1040 
1041 /*------------------------------------------------------------------------
1042 ------------------------------------------------------------------------*/
1043 IMPL_LINK( SwTableColumnPage, ModeHdl, CheckBox*, pBox )
1044 {
1045 	sal_Bool bCheck = pBox->IsChecked();
1046 	if(pBox == &aProportionalCB)
1047 	{
1048 		if(bCheck)
1049 			aModifyTableCB.Check();
1050 		aModifyTableCB.Enable(!bCheck && bModifyTbl);
1051 	}
1052 	return 0;
1053 };
1054 
1055 /*------------------------------------------------------------------------
1056 ------------------------------------------------------------------------*/
1057 sal_Bool  SwTableColumnPage::FillItemSet( SfxItemSet& )
1058 {
1059 	for( sal_uInt16 i = 0; i < MET_FIELDS; i++ )
1060 	{
1061 		if(pFieldArr[i]->HasFocus())
1062 		{
1063 			LoseFocusHdl(pFieldArr[i]);
1064 			break;
1065 		}
1066 	}
1067 
1068 	if(bModified)
1069 	{
1070 		pTblData->SetColsChanged();
1071 	}
1072 	return bModified;
1073 };
1074 
1075 /*------------------------------------------------------------------------
1076 ------------------------------------------------------------------------*/
1077 void   SwTableColumnPage::ModifyHdl( PercentField* pEdit )
1078 {
1079 		sal_uInt16 nAktPos;
1080 		sal_uInt16 i;
1081 
1082 		for( i = 0; i < MET_FIELDS; i++)
1083 			if(pEdit == pFieldArr[i])
1084 				break;
1085 
1086         if (MET_FIELDS <= i)
1087         {
1088             OSL_ENSURE(false, "cannot happen.");
1089             return;
1090         }
1091 
1092         SetVisibleWidth(aValueTbl[i], static_cast< SwTwips >(pEdit->DenormalizePercent(pEdit->GetValue( FUNIT_TWIP ))) );
1093 		nAktPos = aValueTbl[i];
1094 
1095 		UpdateCols( nAktPos );
1096 };
1097 
1098 /*------------------------------------------------------------------------
1099 ------------------------------------------------------------------------*/
1100 void   SwTableColumnPage::UpdateCols( sal_uInt16 nAktPos )
1101 {
1102 	SwTwips nSum = 0;
1103 	sal_uInt16 i;
1104 
1105 	for( i = 0; i < nNoOfCols; i++ )
1106 	{
1107 		nSum += (pTblData->GetColumns())[i].nWidth;
1108 	}
1109 	SwTwips nDiff = nSum - nTableWidth;
1110 
1111     sal_Bool bModifyTable = aModifyTableCB.IsChecked();
1112 	sal_Bool bProp =    aProportionalCB.IsChecked();
1113 
1114     if(!bModifyTable && !bProp )
1115 	{
1116 //		the table width is constant, the difference is balanced with the other columns
1117 		sal_uInt16 nLoopCount = 0;
1118 		while( nDiff )
1119 		{
1120 			if( ++nAktPos == nNoOfVisibleCols)
1121 			{
1122 				nAktPos = 0;
1123 				++nLoopCount;
1124 				//#i101353# in small tables it might not be possible to balance column width
1125 				if( nLoopCount > 1 )
1126 					break;
1127 			}
1128 			if( nDiff < 0 )
1129 			{
1130 				SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
1131 				nDiff = 0;
1132 			}
1133 			else if( GetVisibleWidth(nAktPos) >= nDiff + nMinWidth )
1134 			{
1135 				SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
1136 				nDiff = 0;
1137 			}
1138 			if( nDiff > 0 && GetVisibleWidth(nAktPos) > nMinWidth )
1139 			{
1140 				if( nDiff >= (GetVisibleWidth(nAktPos) - nMinWidth) )
1141 				{
1142 					nDiff -= (GetVisibleWidth(nAktPos) - nMinWidth);
1143 					SetVisibleWidth(nAktPos, nMinWidth);
1144 				}
1145 				else
1146 				{
1147 					nDiff = 0;
1148 					SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
1149 				}
1150 				DBG_ASSERT(nDiff >= 0, "nDiff < 0 kann hier nicht sein!");
1151 			}
1152 		}
1153 	}
1154     else if(bModifyTable && !bProp)
1155 	{
1156 //		Differenz wird ueber die Tabellenbreite ausgeglichen,
1157 //		andere Spalten bleiben unveraendert
1158 		DBG_ASSERT(nDiff <= pTblData->GetSpace() - nTableWidth, "Maximum falsch eingestellt" );
1159 		SwTwips nActSpace = pTblData->GetSpace() - nTableWidth;
1160 		if(nDiff > nActSpace)
1161 		{
1162 			nTableWidth = pTblData->GetSpace();
1163 			SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) - nDiff + nActSpace );
1164 		}
1165 		else
1166 		{
1167 			nTableWidth += nDiff;
1168 		}
1169 	}
1170     else if(bModifyTable & bProp)
1171 	{
1172 //		Alle Spalten werden proportional mitveraendert, die Tabellenbreite wird
1173 //  	entsprechend angepasst
1174 		DBG_ASSERT(nDiff * nNoOfVisibleCols <= pTblData->GetSpace() - nTableWidth, "Maximum falsch eingestellt" );
1175 		long nAdd = nDiff;
1176 		if(nDiff * nNoOfVisibleCols > pTblData->GetSpace() - nTableWidth)
1177 		{
1178 			nAdd = (pTblData->GetSpace() - nTableWidth) / nNoOfVisibleCols;
1179 			SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) - nDiff + nAdd );
1180 			nDiff = nAdd;
1181 		}
1182 		if(nAdd)
1183             for(i = 0; i < nNoOfVisibleCols; i++ )
1184 			{
1185 				if(i == nAktPos)
1186 					continue;
1187 				SwTwips nVisWidth;
1188 				if((nVisWidth = GetVisibleWidth(i)) + nDiff < MINLAY)
1189 				{
1190 					nAdd += nVisWidth - MINLAY;
1191 					SetVisibleWidth(i, MINLAY);
1192 				}
1193 				else
1194 				{
1195 					SetVisibleWidth(i, nVisWidth + nDiff);
1196 					nAdd += nDiff;
1197 				}
1198 
1199 			}
1200 		nTableWidth += nAdd;
1201 
1202 	}
1203 	else
1204 	{
1205 //		Die Differenz wird gleichmaessig auf alle anderen Spalten aufgeteilt
1206 // 		die Tabellenbreite bleibt konstant
1207 /*
1208 		SwTwips nDiffn = nDiff/(nNoOfVisibleCols - 1);
1209 		if(nDiff < 0 && (nNoOfVisibleCols - 1) * nDiffn != nDiff)
1210 			nDiffn-- ;
1211 		sal_uInt16 nStart = nAktPos++;
1212 		if(nAktPos == nNoOfVisibleCols)
1213 			nStart = 0;
1214 		for(sal_uInt16 i = 0; i < nNoOfVisibleCols; i++ )
1215 		{
1216 			if((nVisWidth = GetVisibleWidth(i)) + nDiff < MINLAY)
1217 			{
1218 				nAdd += nVisWidth - MINLAY;
1219 				SetVisibleWidth(i, MINLAY);
1220 			}
1221 		}
1222 */
1223 
1224 	}
1225 
1226 #ifdef DEBUG_TBLDLG
1227 DbgTblRep(pTblData)
1228 #endif
1229 
1230 	if(!bPercentMode)
1231 		aSpaceED.SetValue(aSpaceED.Normalize( pTblData->GetSpace() - nTableWidth) , FUNIT_TWIP);
1232 
1233 	for( i = 0; ( i < nNoOfVisibleCols ) && ( i < MET_FIELDS ); i++)
1234 	{
1235         pFieldArr[i]->SetPrcntValue(pFieldArr[i]->NormalizePercent(
1236 						GetVisibleWidth(aValueTbl[i]) ), FUNIT_TWIP);
1237 		pFieldArr[i]->ClearModifyFlag();
1238 	}
1239 
1240 }
1241 
1242 /*------------------------------------------------------------------------
1243 ------------------------------------------------------------------------*/
1244 void    SwTableColumnPage::ActivatePage( const SfxItemSet& )
1245 {
1246 	bPercentMode = pTblData->GetWidthPercent() != 0;
1247 	for( sal_uInt16 i = 0; (i < MET_FIELDS) && (i < nNoOfVisibleCols); i++ )
1248 	{
1249 		pFieldArr[i]->SetRefValue(pTblData->GetWidth());
1250 		pFieldArr[i]->ShowPercent( bPercentMode );
1251 	}
1252 
1253 	sal_uInt16 nTblAlign = pTblData->GetAlign();
1254     if((text::HoriOrientation::FULL != nTblAlign && nTableWidth != pTblData->GetWidth()) ||
1255     (text::HoriOrientation::FULL == nTblAlign && nTableWidth != pTblData->GetSpace()))
1256 	{
1257         nTableWidth = text::HoriOrientation::FULL == nTblAlign ?
1258 									pTblData->GetSpace() :
1259 										pTblData->GetWidth();
1260 		UpdateCols(0);
1261 	}
1262 	bModifyTbl = sal_True;
1263 	if(pTblData->GetWidthPercent() ||
1264                 text::HoriOrientation::FULL == nTblAlign ||
1265 						pTblData->IsLineSelected()  )
1266 		bModifyTbl = sal_False;
1267 	if(bPercentMode)
1268 	{
1269 		aModifyTableCB	.Check(sal_False);
1270 		aProportionalCB .Check(sal_False);
1271 	}
1272 	else if( !bModifyTbl )
1273 	{
1274 		aProportionalCB.Check(sal_False);
1275 		aModifyTableCB.Check(sal_False);
1276 	}
1277 	aSpaceFT.Enable(!bPercentMode);
1278 	aSpaceED.Enable(!bPercentMode);
1279 	aModifyTableCB.Enable( !bPercentMode && bModifyTbl );
1280 	aProportionalCB.Enable(!bPercentMode && bModifyTbl );
1281 
1282 /*	if(pTblData->IsLineSelected() && pTblData->IsComplex())
1283 	{
1284 
1285 	}*/
1286 	aSpaceED.SetValue(aSpaceED.Normalize(
1287 				pTblData->GetSpace() - nTableWidth) , FUNIT_TWIP);
1288 
1289 }
1290 
1291 /*------------------------------------------------------------------------
1292 ------------------------------------------------------------------------*/
1293 int  SwTableColumnPage::DeactivatePage( SfxItemSet* _pSet )
1294 {
1295     if(_pSet)
1296 	{
1297         FillItemSet(*_pSet);
1298         if(text::HoriOrientation::FULL != pTblData->GetAlign() && pTblData->GetWidth() != nTableWidth)
1299 		{
1300 			pTblData->SetWidth(nTableWidth);
1301 			SwTwips nDiff = pTblData->GetSpace() - pTblData->GetWidth() -
1302 							pTblData->GetLeftSpace() - pTblData->GetRightSpace();
1303 			switch( pTblData->GetAlign()  )
1304 			{
1305                 case text::HoriOrientation::RIGHT:
1306 					pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff);
1307 				break;
1308                 case text::HoriOrientation::LEFT:
1309 					pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff);
1310 				break;
1311                 case text::HoriOrientation::NONE:
1312 				{
1313 					SwTwips nDiff2 = nDiff/2;
1314 					if( nDiff > 0 ||
1315 						(-nDiff2 < pTblData->GetRightSpace() && - nDiff2 < pTblData->GetLeftSpace()))
1316 					{
1317 						pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff2);
1318 						pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff2);
1319 					}
1320 					else
1321 					{
1322 						if(pTblData->GetRightSpace() > pTblData->GetLeftSpace())
1323 						{
1324 							pTblData->SetLeftSpace(0);
1325 							pTblData->SetRightSpace(pTblData->GetSpace() - pTblData->GetWidth());
1326 						}
1327 						else
1328 						{
1329 							pTblData->SetRightSpace(0);
1330 							pTblData->SetLeftSpace(pTblData->GetSpace() - pTblData->GetWidth());
1331 						}
1332 					}
1333 				}
1334 				break;
1335                 case text::HoriOrientation::CENTER:
1336 					pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff/2);
1337 					pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff/2);
1338 				break;
1339                 case text::HoriOrientation::LEFT_AND_WIDTH :
1340 					if(nDiff > pTblData->GetRightSpace())
1341 					{
1342 						pTblData->SetLeftSpace(pTblData->GetSpace() - pTblData->GetWidth());
1343 					}
1344 					pTblData->SetRightSpace(
1345 						pTblData->GetSpace() - pTblData->GetWidth() - pTblData->GetLeftSpace());
1346 				break;
1347 			}
1348 			pTblData->SetWidthChanged();
1349 		}
1350 #ifdef DEBUG_TBLDLG
1351 DbgTblRep(pTblData)
1352 #endif
1353         _pSet->Put(SwPtrItem( FN_TABLE_REP, pTblData ));
1354 	}
1355 	return sal_True;
1356 }
1357 
1358 /*------------------------------------------------------------------------
1359 ------------------------------------------------------------------------*/
1360 SwTwips  SwTableColumnPage::GetVisibleWidth(sal_uInt16 nPos)
1361 {
1362 	sal_uInt16 i=0;
1363 
1364 	while( nPos )
1365 	{
1366 		if(pTblData->GetColumns()[i].bVisible && nPos)
1367 			nPos--;
1368 		i++;
1369 	}
1370 	SwTwips nReturn = pTblData->GetColumns()[i].nWidth;
1371 	DBG_ASSERT(i < nNoOfCols, "Array index out of range");
1372 	while(!pTblData->GetColumns()[i].bVisible && (i + 1) < nNoOfCols)
1373 		nReturn += pTblData->GetColumns()[++i].nWidth;
1374 
1375 //	return (*ppTableColumns)[i].nWidth;
1376 	return nReturn;
1377 }
1378 
1379 /*------------------------------------------------------------------------
1380 ------------------------------------------------------------------------*/
1381 void SwTableColumnPage::SetVisibleWidth(sal_uInt16 nPos, SwTwips nNewWidth)
1382 {
1383 	sal_uInt16 i=0;
1384 	while( nPos )
1385 	{
1386 		if(pTblData->GetColumns()[i].bVisible && nPos)
1387 			nPos--;
1388 		i++;
1389 	}
1390 	DBG_ASSERT(i < nNoOfCols, "Array index out of range");
1391 	pTblData->GetColumns()[i].nWidth = nNewWidth;
1392 	while(!pTblData->GetColumns()[i].bVisible && (i + 1) < nNoOfCols)
1393 		pTblData->GetColumns()[++i].nWidth = 0;
1394 
1395 }
1396 
1397 /*------------------------------------------------------------------------
1398 ------------------------------------------------------------------------*/
1399 SwTableTabDlg::SwTableTabDlg(Window* pParent, SfxItemPool& ,
1400 					const SfxItemSet* pItemSet, SwWrtShell* pSh ) :
1401 		SfxTabDialog(pParent, SW_RES(DLG_FORMAT_TABLE), pItemSet,0),
1402         pShell(pSh),
1403         nHtmlMode(::GetHtmlMode(pSh->GetView().GetDocShell()))
1404 {
1405 	FreeResource();
1406     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1407     DBG_ASSERT(pFact, "Dialogdiet fail!");
1408 	AddTabPage(TP_FORMAT_TABLE, &SwFormatTablePage::Create, 0 );
1409 	AddTabPage(TP_TABLE_TEXTFLOW, &SwTextFlowPage::Create, 0 );
1410 	AddTabPage(TP_TABLE_COLUMN, &SwTableColumnPage::Create, 0 );
1411     AddTabPage(TP_BACKGROUND, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0 );
1412     AddTabPage(TP_BORDER, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), 0 );
1413 }
1414 
1415 
1416 /*------------------------------------------------------------------------
1417 ------------------------------------------------------------------------*/
1418 void  SwTableTabDlg::PageCreated(sal_uInt16 nId, SfxTabPage& rPage)
1419 {
1420     SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
1421 	if( TP_BACKGROUND == nId )
1422 	{
1423         sal_Int32 nFlagType = SVX_SHOW_TBLCTL;
1424         if(!( nHtmlMode & HTMLMODE_ON ) ||
1425 			nHtmlMode & HTMLMODE_SOME_STYLES)
1426             nFlagType |= SVX_SHOW_SELECTOR;
1427         aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, nFlagType));
1428 		rPage.PageCreated(aSet);
1429 	}
1430 	else if(TP_BORDER == nId)
1431 	{
1432 		aSet.Put (SfxUInt16Item(SID_SWMODE_TYPE,SW_BORDER_MODE_TABLE));
1433 		rPage.PageCreated(aSet);
1434 	}
1435 	else if(TP_TABLE_TEXTFLOW == nId)
1436 	{
1437 		((SwTextFlowPage&)rPage).SetShell(pShell);
1438 		const sal_uInt16 eType = pShell->GetFrmType(0,sal_True);
1439 		if( !(FRMTYPE_BODY & eType) )
1440 			((SwTextFlowPage&)rPage).DisablePageBreak();
1441 	}
1442 }
1443 
1444 /*-----------------12.12.96 12.22-------------------
1445 --------------------------------------------------*/
1446 SwTextFlowPage::SwTextFlowPage( Window* pParent,
1447 								const SfxItemSet& rSet ) :
1448 	SfxTabPage(pParent, SW_RES( TP_TABLE_TEXTFLOW ), rSet ),
1449     aFlowFL         (this, SW_RES(FL_FLOW            )),
1450 	aPgBrkCB        (this, SW_RES(CB_PAGEBREAK      )),
1451 	aPgBrkRB        (this, SW_RES(RB_BREAKPAGE      )),
1452 	aColBrkRB       (this, SW_RES(RB_BREAKCOLUMN    )),
1453 	aPgBrkBeforeRB  (this, SW_RES(RB_PAGEBREAKBEFORE)),
1454 	aPgBrkAfterRB   (this, SW_RES(RB_PAGEBREAKAFTER )),
1455 	aPageCollCB     (this, SW_RES(CB_PAGECOLL       )),
1456 	aPageCollLB     (this, SW_RES(LB_PAGECOLL       )),
1457 	aPageNoFT       (this, SW_RES(FT_PAGENUM        )),
1458 	aPageNoNF       (this, SW_RES(NF_PAGENUM        )),
1459     aSplitCB        (this, SW_RES(CB_SPLIT          )),
1460     aSplitRowCB     (this, SW_RES(CB_SPLIT_ROW      )),
1461 	aKeepCB			(this, SW_RES(CB_KEEP			)),
1462     aHeadLineCB     (this, SW_RES(CB_HEADLINE       )),
1463     aRepeatHeaderFT         (this, SW_RES(FT_REPEAT_HEADER  )),
1464     aRepeatHeaderBeforeFT   (this),
1465     aRepeatHeaderNF         (this, SW_RES(NF_REPEAT_HEADER  )),
1466     aRepeatHeaderAfterFT    (this),
1467     aRepeatHeaderCombo      (this, SW_RES(WIN_REPEAT_HEADER), aRepeatHeaderNF, aRepeatHeaderBeforeFT, aRepeatHeaderAfterFT),
1468     aTextDirectionFT(this, SW_RES(FT_TEXTDIRECTION  )),
1469     aTextDirectionLB(this, SW_RES(LB_TEXTDIRECTION  )),
1470 
1471     aVertOrientFL   (this, SW_RES(FL_VERT_ORIENT    )),
1472     aVertOrientFT(this,  SW_RES(FT_VERTORIENT       )),
1473     aVertOrientLB(this,  SW_RES(LB_VERTORIENT       )),
1474 
1475     pShell(0),
1476 
1477 	bPageBreak(sal_True),
1478 	bHtmlMode(sal_False)
1479 {
1480 	FreeResource();
1481 
1482 	aPgBrkRB.SetAccessibleRelationMemberOf(&aPgBrkCB);
1483 	aColBrkRB.SetAccessibleRelationMemberOf(&aPgBrkCB);
1484 	aPgBrkBeforeRB.SetAccessibleRelationMemberOf(&aPgBrkCB);
1485 	aPgBrkAfterRB.SetAccessibleRelationMemberOf(&aPgBrkCB);
1486 	aPageCollLB.SetAccessibleRelationLabeledBy(&aPageCollCB);
1487 	aPageCollLB.SetAccessibleName(aPageCollCB.GetText());
1488 
1489 	aPgBrkCB.SetClickHdl(LINK(this, SwTextFlowPage, PageBreakHdl_Impl));
1490 	aPgBrkBeforeRB.SetClickHdl(
1491 		LINK( this, SwTextFlowPage, PageBreakPosHdl_Impl ) );
1492 	aPgBrkAfterRB.SetClickHdl(
1493 		LINK( this, SwTextFlowPage, PageBreakPosHdl_Impl ) );
1494 	aPageCollCB.SetClickHdl(
1495 		LINK( this, SwTextFlowPage, ApplyCollClickHdl_Impl ) );
1496 	aColBrkRB.SetClickHdl(
1497 		LINK( this, SwTextFlowPage, PageBreakTypeHdl_Impl ) );
1498 	aPgBrkRB.SetClickHdl(
1499 		LINK( this, SwTextFlowPage, PageBreakTypeHdl_Impl ) );
1500     aSplitCB.SetClickHdl(
1501         LINK( this, SwTextFlowPage, SplitHdl_Impl));
1502     aSplitRowCB.SetClickHdl(
1503         LINK( this, SwTextFlowPage, SplitRowHdl_Impl));
1504 	aHeadLineCB.SetClickHdl( LINK( this, SwTextFlowPage, HeadLineCBClickHdl ) );
1505 
1506 #ifndef SW_FILEFORMAT_40
1507 	const SfxPoolItem *pItem;
1508 	if(SFX_ITEM_SET == rSet.GetItemState( SID_HTML_MODE, sal_False,&pItem )
1509 		&& ((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON)
1510 #endif
1511 	{
1512 		aKeepCB.Hide();
1513 		aSplitCB.Hide();
1514         aSplitRowCB.Hide();
1515 	}
1516 
1517 	aRepeatHeaderCombo.Arrange( aRepeatHeaderFT );
1518 
1519 	HeadLineCBClickHdl();
1520 }
1521 
1522 /*-----------------12.12.96 12.22-------------------
1523 --------------------------------------------------*/
1524  SwTextFlowPage::~SwTextFlowPage()
1525 {
1526 }
1527 
1528 /*-----------------12.12.96 12.22-------------------
1529 --------------------------------------------------*/
1530 SfxTabPage*   SwTextFlowPage::Create( Window* pParent,
1531 								const SfxItemSet& rAttrSet)
1532 {
1533 	return new SwTextFlowPage(pParent, rAttrSet);
1534 }
1535 
1536 /*-----------------12.12.96 12.22-------------------
1537 --------------------------------------------------*/
1538 sal_Bool  SwTextFlowPage::FillItemSet( SfxItemSet& rSet )
1539 {
1540 	sal_Bool bModified = sal_False;
1541 
1542 	//Ueberschrift wiederholen
1543 	if(aHeadLineCB.IsChecked() != aHeadLineCB.GetSavedValue() ||
1544         String::CreateFromInt32( static_cast< sal_Int32 >(aRepeatHeaderNF.GetValue()) ) != aRepeatHeaderNF.GetSavedValue() )
1545 	{
1546 		bModified |= 0 != rSet.Put(
1547 			SfxUInt16Item(FN_PARAM_TABLE_HEADLINE, aHeadLineCB.IsChecked()? sal_uInt16(aRepeatHeaderNF.GetValue()) : 0 ));
1548 	}
1549 	if(aKeepCB.IsChecked() != aKeepCB.GetSavedValue())
1550         bModified |= 0 != rSet.Put( SvxFmtKeepItem( aKeepCB.IsChecked(), RES_KEEP));
1551 
1552 	if(aSplitCB.IsChecked() != aSplitCB.GetSavedValue())
1553         bModified |= 0 != rSet.Put( SwFmtLayoutSplit( aSplitCB.IsChecked()));
1554 
1555     if(aSplitRowCB.IsChecked() != aSplitRowCB.GetSavedValue())
1556         bModified |= 0 != rSet.Put( SwFmtRowSplit( aSplitRowCB.IsChecked()));
1557 
1558 
1559 	const SvxFmtBreakItem* pBreak = (const SvxFmtBreakItem*)GetOldItem( rSet, RES_BREAK );
1560 	const SwFmtPageDesc* pDesc = (const SwFmtPageDesc*) GetOldItem( rSet, RES_PAGEDESC );
1561 
1562 
1563 	sal_Bool bState = aPageCollCB.IsChecked();
1564 
1565 	//Wenn Seitenvorlage, dann kein Break
1566 	sal_Bool bPageItemPut = sal_False;
1567 	if ( bState != aPageCollCB.GetSavedValue() ||
1568 		 ( bState &&
1569 		   aPageCollLB.GetSelectEntryPos() != aPageCollLB.GetSavedValue() )
1570 		   || (aPageNoNF.IsEnabled() && aPageNoNF.IsValueModified()) )
1571 	{
1572 		String sPage;
1573 
1574 		if ( bState )
1575 		{
1576 			sPage = aPageCollLB.GetSelectEntry();
1577 		}
1578         sal_uInt16 nPgNum = static_cast< sal_uInt16 >(aPageNoNF.GetValue());
1579 		if ( !pDesc || !pDesc->GetPageDesc() ||
1580 			( pDesc->GetPageDesc() && ((pDesc->GetPageDesc()->GetName() != sPage) ||
1581 					aPageNoNF.GetSavedValue() != (String)nPgNum)))
1582 		{
1583 			SwFmtPageDesc aFmt( pShell->FindPageDescByName( sPage, sal_True ) );
1584 			aFmt.SetNumOffset(bState ? nPgNum : 0);
1585 			bModified |= 0 != rSet.Put( aFmt );
1586 			bPageItemPut = bState;
1587 		}
1588 	}
1589 	sal_Bool bIsChecked = aPgBrkCB.IsChecked();
1590 	if ( !bPageItemPut &&
1591 		(	bState != aPageCollCB.GetSavedValue() ||
1592 			bIsChecked != aPgBrkCB.GetSavedValue()				||
1593 			aPgBrkBeforeRB.IsChecked() != aPgBrkBeforeRB.GetSavedValue()	||
1594 			aPgBrkRB.IsChecked() != aPgBrkRB.GetSavedValue() ))
1595 	{
1596 		SvxFmtBreakItem aBreak(
1597 			(const SvxFmtBreakItem&)GetItemSet().Get( RES_BREAK ) );
1598 
1599 		if(bIsChecked)
1600 		{
1601 			sal_Bool bBefore = aPgBrkBeforeRB.IsChecked();
1602 
1603 			if ( aPgBrkRB.IsChecked() )
1604 			{
1605 				if ( bBefore )
1606 					aBreak.SetValue( SVX_BREAK_PAGE_BEFORE );
1607 				else
1608 					aBreak.SetValue( SVX_BREAK_PAGE_AFTER );
1609 			}
1610 			else
1611 			{
1612 				if ( bBefore )
1613 					aBreak.SetValue( SVX_BREAK_COLUMN_BEFORE );
1614 				else
1615 					aBreak.SetValue( SVX_BREAK_COLUMN_AFTER );
1616 			}
1617 		}
1618 		else
1619 		{
1620 				aBreak.SetValue( SVX_BREAK_NONE );
1621 		}
1622 
1623 		if ( !pBreak || !( *(const SvxFmtBreakItem*)pBreak == aBreak ) )
1624 		{
1625 			bModified |= 0 != rSet.Put( aBreak );
1626 		}
1627 	}
1628 
1629     if(aTextDirectionLB.GetSelectEntryPos() != aTextDirectionLB.GetSavedValue())
1630     {
1631           bModified |= 0 != rSet.Put(
1632                     SvxFrameDirectionItem(
1633                         (SvxFrameDirection)(sal_uLong)aTextDirectionLB.GetEntryData(aTextDirectionLB.GetSelectEntryPos())
1634                         , FN_TABLE_BOX_TEXTDIRECTION));
1635     }
1636 
1637     if(aVertOrientLB.GetSelectEntryPos() != aVertOrientLB.GetSavedValue())
1638     {
1639         sal_uInt16 nOrient = USHRT_MAX;
1640         switch(aVertOrientLB.GetSelectEntryPos())
1641         {
1642             case 0 : nOrient = text::VertOrientation::NONE; break;
1643             case 1 : nOrient = text::VertOrientation::CENTER; break;
1644             case 2 : nOrient = text::VertOrientation::BOTTOM; break;
1645         }
1646         if(nOrient != USHRT_MAX)
1647             bModified |= 0 != rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, nOrient));
1648     }
1649 
1650 	return bModified;
1651 
1652 }
1653 
1654 /*-----------------12.12.96 12.22-------------------
1655 --------------------------------------------------*/
1656 void   SwTextFlowPage::Reset( const SfxItemSet& rSet )
1657 {
1658 	const SfxPoolItem* pItem;
1659 	SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get();
1660 	sal_Bool bFlowAllowed = !bHtmlMode || pHtmlOpt->IsPrintLayoutExtension();
1661 	if(bFlowAllowed)
1662 	{
1663 		// Einfuegen der vorhandenen Seitenvorlagen in die Listbox
1664 		const sal_uInt16 nCount = pShell->GetPageDescCnt();
1665 		sal_uInt16 i;
1666 
1667 		for( i = 0; i < nCount; ++i)
1668 		{
1669 			const SwPageDesc &rPageDesc = pShell->GetPageDesc(i);
1670 			aPageCollLB.InsertEntry(rPageDesc.GetName());
1671 		}
1672 
1673 		String aFmtName;
1674 		for(i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
1675 			if( LISTBOX_ENTRY_NOTFOUND == aPageCollLB.GetEntryPos(
1676 					aFmtName = SwStyleNameMapper::GetUIName( i, aFmtName ) ))
1677 				aPageCollLB.InsertEntry( aFmtName );
1678 
1679 		if(SFX_ITEM_SET == rSet.GetItemState( RES_KEEP, sal_False, &pItem ))
1680 		{
1681 			aKeepCB.Check( ((const SvxFmtKeepItem*)pItem)->GetValue() );
1682 			aKeepCB.SaveValue();
1683 		}
1684 		if(SFX_ITEM_SET == rSet.GetItemState( RES_LAYOUT_SPLIT, sal_False, &pItem ))
1685 		{
1686             aSplitCB.Check( ((const SwFmtLayoutSplit*)pItem)->GetValue() );
1687 		}
1688         else
1689             aSplitCB.Check();
1690 
1691 	    aSplitCB.SaveValue();
1692         SplitHdl_Impl(&aSplitCB);
1693 
1694         if(SFX_ITEM_SET == rSet.GetItemState( RES_ROW_SPLIT, sal_False, &pItem ))
1695         {
1696             aSplitRowCB.Check( ((const SwFmtRowSplit*)pItem)->GetValue() );
1697         }
1698         else
1699             aSplitRowCB.SetState(STATE_DONTKNOW);
1700         aSplitRowCB.SaveValue();
1701 
1702         if(bPageBreak)
1703 		{
1704 			if(SFX_ITEM_SET == rSet.GetItemState( RES_PAGEDESC, sal_False, &pItem ))
1705 			{
1706 				String sPageDesc;
1707 				const SwPageDesc* pDesc = ((const SwFmtPageDesc*)pItem)->GetPageDesc();
1708 				aPageNoNF.SetValue(((const SwFmtPageDesc*)pItem)->GetNumOffset());
1709 				if(pDesc)
1710 					sPageDesc = pDesc->GetName();
1711 				if ( sPageDesc.Len() &&
1712 						aPageCollLB.GetEntryPos( sPageDesc ) != LISTBOX_ENTRY_NOTFOUND )
1713 				{
1714 					aPageCollLB.SelectEntry( sPageDesc );
1715 					aPageCollCB.Check();
1716 
1717 					aPgBrkCB.Enable();
1718 					aPgBrkRB.Enable();
1719 					aColBrkRB.Enable();
1720 					aPgBrkBeforeRB.Enable();
1721 					aPgBrkAfterRB.Enable();
1722 					aPageCollCB.Enable();
1723 					aPgBrkCB.Check();
1724 
1725 					aPgBrkCB.Check( sal_True );
1726 					aColBrkRB.Check( sal_False );
1727 					aPgBrkBeforeRB.Check( sal_True );
1728 					aPgBrkAfterRB.Check( sal_False );
1729 				}
1730 				else
1731 				{
1732 					aPageCollLB.SetNoSelection();
1733 					aPageCollCB.Check(sal_False);
1734 				}
1735 			}
1736 
1737 			if(SFX_ITEM_SET == rSet.GetItemState( RES_BREAK, sal_False, &pItem ))
1738 			{
1739 				const SvxFmtBreakItem* pPageBreak = (const SvxFmtBreakItem*)pItem;
1740 				SvxBreak eBreak = (SvxBreak)pPageBreak->GetValue();
1741 
1742 				if ( eBreak != SVX_BREAK_NONE )
1743 				{
1744 					aPgBrkCB.Check();
1745 					aPageCollCB.Enable(sal_False);
1746 					aPageCollLB.Enable(sal_False);
1747 					aPageNoFT.Enable(sal_False);
1748 					aPageNoNF.Enable(sal_False);
1749 				}
1750 				switch ( eBreak )
1751 				{
1752 					case SVX_BREAK_PAGE_BEFORE:
1753 						aPgBrkRB.Check( sal_True );
1754 						aColBrkRB.Check( sal_False );
1755 						aPgBrkBeforeRB.Check( sal_True );
1756 						aPgBrkAfterRB.Check( sal_False );
1757 						break;
1758 					case SVX_BREAK_PAGE_AFTER:
1759 						aPgBrkRB.Check( sal_True );
1760 						aColBrkRB.Check( sal_False );
1761 						aPgBrkBeforeRB.Check( sal_False );
1762 						aPgBrkAfterRB.Check( sal_True );
1763 						break;
1764 					case SVX_BREAK_COLUMN_BEFORE:
1765 						aPgBrkRB.Check( sal_False );
1766 						aColBrkRB.Check( sal_True );
1767 						aPgBrkBeforeRB.Check( sal_True );
1768 						aPgBrkAfterRB.Check( sal_False );
1769 						break;
1770 					case SVX_BREAK_COLUMN_AFTER:
1771 						aPgBrkRB.Check( sal_False );
1772 						aColBrkRB.Check( sal_True );
1773 						aPgBrkBeforeRB.Check( sal_False );
1774 						aPgBrkAfterRB.Check( sal_True );
1775 						break;
1776                     default:; //prevent warning
1777 				}
1778 
1779 			}
1780 			if ( aPgBrkBeforeRB.IsChecked() )
1781 				PageBreakPosHdl_Impl( &aPgBrkBeforeRB );
1782 			else if ( aPgBrkAfterRB.IsChecked() )
1783 				PageBreakPosHdl_Impl( &aPgBrkAfterRB );
1784 			PageBreakHdl_Impl( &aPgBrkCB );
1785 		}
1786 	}
1787 	else
1788 	{
1789 		aPgBrkRB.Enable(sal_False);
1790 		aColBrkRB.Enable(sal_False);
1791 		aPgBrkBeforeRB.Enable(sal_False);
1792 		aPgBrkAfterRB.Enable(sal_False);
1793 		aKeepCB	.Enable(sal_False);
1794 		aSplitCB.Enable(sal_False);
1795 		aPgBrkCB.Enable(sal_False);
1796 		aPageCollCB.Enable(sal_False);
1797 		aPageCollLB.Enable(sal_False);
1798 	}
1799 
1800 	if(SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, sal_False, &pItem ))
1801 	{
1802 		sal_uInt16 nRep = ((const SfxUInt16Item*)pItem)->GetValue();
1803 		aHeadLineCB.Check( nRep > 0 );
1804 		aHeadLineCB.SaveValue();
1805 		aRepeatHeaderNF.SetValue( nRep );
1806 		aRepeatHeaderNF.SaveValue();
1807 	}
1808     if ( rSet.GetItemState(FN_TABLE_BOX_TEXTDIRECTION) > SFX_ITEM_AVAILABLE )
1809     {
1810         sal_uLong nDirection = ((const SvxFrameDirectionItem&)rSet.Get(FN_TABLE_BOX_TEXTDIRECTION)).GetValue();
1811         aTextDirectionLB.SelectEntryPos(aTextDirectionLB.GetEntryPos( (const void*)nDirection ));
1812     }
1813 
1814     if ( rSet.GetItemState(FN_TABLE_SET_VERT_ALIGN) > SFX_ITEM_AVAILABLE )
1815 	{
1816 		sal_uInt16 nVert = ((const SfxUInt16Item&)rSet.Get(FN_TABLE_SET_VERT_ALIGN)).GetValue();
1817         sal_uInt16 nPos = 0;
1818 		switch(nVert)
1819 		{
1820             case text::VertOrientation::NONE:     nPos = 0;   break;
1821             case text::VertOrientation::CENTER:   nPos = 1;   break;
1822             case text::VertOrientation::BOTTOM:   nPos = 2;   break;
1823 		}
1824         aVertOrientLB.SelectEntryPos(nPos);
1825 	}
1826 
1827 	aPageCollCB.SaveValue();
1828 	aPageCollLB.SaveValue();
1829 	aPgBrkCB.SaveValue();
1830 	aPgBrkRB.SaveValue();
1831 	aColBrkRB.SaveValue();
1832 	aPgBrkBeforeRB.SaveValue();
1833 	aPgBrkAfterRB.SaveValue();
1834 	aPageNoNF.SaveValue();
1835     aTextDirectionLB.SaveValue();
1836     aVertOrientLB.SaveValue();
1837 
1838 	HeadLineCBClickHdl();
1839 }
1840 /*-----------------16.04.98 14:48-------------------
1841 
1842 --------------------------------------------------*/
1843 
1844 void SwTextFlowPage::SetShell(SwWrtShell* pSh)
1845 {
1846 	pShell = pSh;
1847 	bHtmlMode = 0 != (::GetHtmlMode(pShell->GetView().GetDocShell()) & HTMLMODE_ON);
1848 	if(bHtmlMode)
1849 	{
1850 		aPageNoNF.Enable(sal_False);
1851 		aPageNoFT.Enable(sal_False);
1852 	}
1853 }
1854 
1855 /*-----------------12.12.96 16.18-------------------
1856 --------------------------------------------------*/
1857 IMPL_LINK( SwTextFlowPage, PageBreakHdl_Impl, CheckBox*, EMPTYARG )
1858 {
1859 	if( aPgBrkCB.IsChecked() )
1860 	{
1861 			aPgBrkRB.		Enable();
1862 			aColBrkRB.		Enable();
1863 			aPgBrkBeforeRB.	Enable();
1864 			aPgBrkAfterRB.	Enable();
1865 
1866 			if ( aPgBrkRB.IsChecked() && aPgBrkBeforeRB.IsChecked() )
1867 			{
1868 				aPageCollCB.Enable();
1869 
1870 				sal_Bool bEnable = aPageCollCB.IsChecked() &&
1871 											aPageCollLB.GetEntryCount();
1872 				aPageCollLB.Enable(bEnable);
1873 				if(!bHtmlMode)
1874 				{
1875 					aPageNoFT.Enable(bEnable);
1876 					aPageNoNF.Enable(bEnable);
1877 				}
1878 			}
1879 	}
1880 	else
1881 	{
1882 			aPageCollCB.Check( sal_False );
1883 			aPageCollCB.Enable(sal_False);
1884 			aPageCollLB.Enable(sal_False);
1885 			aPageNoFT.Enable(sal_False);
1886 			aPageNoNF.Enable(sal_False);
1887 			aPgBrkRB.		Enable(sal_False);
1888 			aColBrkRB.		Enable(sal_False);
1889 			aPgBrkBeforeRB.	Enable(sal_False);
1890 			aPgBrkAfterRB.	Enable(sal_False);
1891 	}
1892 	return 0;
1893 }
1894 
1895 /*-----------------12.12.96 16.18-------------------
1896 --------------------------------------------------*/
1897 IMPL_LINK( SwTextFlowPage, ApplyCollClickHdl_Impl, CheckBox*, EMPTYARG )
1898 {
1899 	sal_Bool bEnable = sal_False;
1900 	if ( aPageCollCB.IsChecked() &&
1901 		 aPageCollLB.GetEntryCount() )
1902 	{
1903 		bEnable = sal_True;
1904 		aPageCollLB.SelectEntryPos( 0 );
1905 	}
1906 	else
1907 	{
1908 		aPageCollLB.SetNoSelection();
1909 	}
1910 	aPageCollLB.Enable(bEnable);
1911 	if(!bHtmlMode)
1912 	{
1913 		aPageNoFT.Enable(bEnable);
1914 		aPageNoNF.Enable(bEnable);
1915 	}
1916 	return 0;
1917 }
1918 
1919 /*-----------------12.12.96 16.18-------------------
1920 --------------------------------------------------*/
1921 IMPL_LINK( SwTextFlowPage, PageBreakPosHdl_Impl, RadioButton*, pBtn )
1922 {
1923 	if ( aPgBrkCB.IsChecked() )
1924 	{
1925         if ( pBtn == &aPgBrkBeforeRB && aPgBrkRB.IsChecked() )
1926 		{
1927 			aPageCollCB.Enable();
1928 
1929 			sal_Bool bEnable = aPageCollCB.IsChecked()  &&
1930 										aPageCollLB.GetEntryCount();
1931 
1932 			aPageCollLB.Enable(bEnable);
1933 			if(!bHtmlMode)
1934 			{
1935 				aPageNoFT.Enable(bEnable);
1936 				aPageNoNF.Enable(bEnable);
1937 			}
1938 		}
1939 		else if ( pBtn == &aPgBrkAfterRB )
1940 		{
1941 			aPageCollCB	.Check( sal_False );
1942 			aPageCollCB	.Enable(sal_False);
1943 			aPageCollLB	.Enable(sal_False);
1944 			aPageNoFT 	.Enable(sal_False);
1945 			aPageNoNF	.Enable(sal_False);
1946 		}
1947 	}
1948 	return 0;
1949 }
1950 
1951 /*-----------------12.12.96 16.18-------------------
1952 --------------------------------------------------*/
1953 IMPL_LINK( SwTextFlowPage, PageBreakTypeHdl_Impl, RadioButton*, pBtn )
1954 {
1955 	if ( pBtn == &aColBrkRB || aPgBrkAfterRB.IsChecked() )
1956 	{
1957 		aPageCollCB	.Check(sal_False);
1958 		aPageCollCB	.Enable(sal_False);
1959 		aPageCollLB	.Enable(sal_False);
1960 		aPageNoFT	.Enable(sal_False);
1961 		aPageNoNF	.Enable(sal_False);
1962 	}
1963 	else if ( aPgBrkBeforeRB.IsChecked() )
1964 		PageBreakPosHdl_Impl( &aPgBrkBeforeRB );
1965 	return 0;
1966 }
1967 /*-----------------17.11.2003 11:30-----------------
1968  *
1969  * --------------------------------------------------*/
1970 IMPL_LINK( SwTextFlowPage, SplitHdl_Impl, CheckBox*, pBox )
1971 {
1972     aSplitRowCB.Enable(pBox->IsChecked());
1973     return 0;
1974 }
1975 /*-----------------17.11.2003 11:30-----------------
1976  *
1977  * --------------------------------------------------*/
1978 IMPL_LINK( SwTextFlowPage, SplitRowHdl_Impl, TriStateBox*, pBox )
1979 {
1980     pBox->EnableTriState(sal_False);
1981     return 0;
1982 }
1983 
1984 IMPL_LINK( SwTextFlowPage, HeadLineCBClickHdl, void*, EMPTYARG )
1985 {
1986 	aRepeatHeaderCombo.Enable(aHeadLineCB.IsChecked());
1987 
1988 	return 0;
1989 }
1990 
1991 /*-----------------30.05.97 07:37-------------------
1992 
1993 --------------------------------------------------*/
1994 void SwTextFlowPage::DisablePageBreak()
1995 {
1996 	bPageBreak = sal_False;
1997 	aPgBrkCB       .Disable();
1998 	aPgBrkRB       .Disable();
1999 	aColBrkRB      .Disable();
2000 	aPgBrkBeforeRB .Disable();
2001 	aPgBrkAfterRB  .Disable();
2002 	aPageCollCB    .Disable();
2003 	aPageCollLB    .Disable();
2004 	aPageNoFT      .Disable();
2005 	aPageNoNF      .Disable();
2006 }
2007 
2008 
2009 
2010