xref: /aoo42x/main/sw/source/ui/table/tabledlg.cxx (revision 4d7c9de0)
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
DbgTblRep(SwTableRep * pRep)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 
SwFormatTablePage(Window * pParent,const SfxItemSet & rSet)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 ------------------------------------------------------------------------*/
Init()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 
IMPL_LINK(SwFormatTablePage,RelWidthClickHdl,CheckBox *,pBtn)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 ------------------------------------------------------------------------*/
IMPL_LINK(SwFormatTablePage,AutoClickHdl,CheckBox *,pBox)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 /*----------------------------------------------------------------------*/
IMPL_LINK(SwFormatTablePage,RightModifyHdl,MetricField *,EMPTYARG)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 ------------------------------------------------------------------------*/
IMPL_LINK_INLINE_START(SwFormatTablePage,UpDownLoseFocusHdl,MetricField *,pEdit)348 IMPL_LINK_INLINE_START( SwFormatTablePage, UpDownLoseFocusHdl, MetricField *, pEdit )
349 {
350     if( &aRightMF == pEdit)
351         RightModifyHdl(pEdit);
352     ModifyHdl( pEdit );
353 	return 0;
354 }
IMPL_LINK_INLINE_END(SwFormatTablePage,UpDownLoseFocusHdl,MetricField *,pEdit)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 ------------------------------------------------------------------------*/
Create(Window * pParent,const SfxItemSet & rAttrSet)461 SfxTabPage*  SwFormatTablePage::Create( Window* pParent,
462 								   const SfxItemSet& rAttrSet)
463 {
464 	return new SwFormatTablePage( pParent, rAttrSet );
465 }
466 
467 /*------------------------------------------------------------------------
468 -------------------------------------------------------------------------*/
FillItemSet(SfxItemSet & rCoreSet)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 ------------------------------------------------------------------------*/
Reset(const SfxItemSet &)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 ------------------------------------------------------------------------*/
ActivatePage(const SfxItemSet & rSet)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 ------------------------------------------------------------------------*/
DeactivatePage(SfxItemSet * _pSet)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 ------------------------------------------------------------------------*/
SwTableColumnPage(Window * pParent,const SfxItemSet & rSet)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 ------------------------------------------------------------------------*/
~SwTableColumnPage()878  SwTableColumnPage::~SwTableColumnPage()
879 {
880 };
881 
882 /*------------------------------------------------------------------------
883 ------------------------------------------------------------------------*/
Create(Window * pParent,const SfxItemSet & rAttrSet)884 SfxTabPage*   SwTableColumnPage::Create( Window* pParent,
885 								const SfxItemSet& rAttrSet)
886 {
887 	return new SwTableColumnPage( pParent, rAttrSet );
888 };
889 
890 /*------------------------------------------------------------------------
891 ------------------------------------------------------------------------*/
Reset(const SfxItemSet &)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 ------------------------------------------------------------------------*/
Init(sal_Bool bWeb)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 ------------------------------------------------------------------------*/
IMPL_LINK(SwTableColumnPage,AutoClickHdl,CheckBox *,pBox)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 		String sColumnWidth = SW_RESSTR( STR_ACCESS_COLUMN_WIDTH);
994 		sColumnWidth.SearchAndReplace( DEFINE_CONST_UNICODE("%1"), sIndex );
995 		pFieldArr[i]->SetAccessibleName( sColumnWidth );
996 	}
997 
998 	aDownBtn.Enable(aValueTbl[0] > 0);
999 	aUpBtn.Enable(aValueTbl[ MET_FIELDS -1 ] < nNoOfVisibleCols -1 );
1000 	UpdateCols(0);
1001 	return 0;
1002 };
1003 
1004 /*------------------------------------------------------------------------
1005 ------------------------------------------------------------------------*/
IMPL_LINK_INLINE_START(SwTableColumnPage,UpHdl,PercentField *,pEdit)1006 IMPL_LINK_INLINE_START( SwTableColumnPage, UpHdl, PercentField *, pEdit )
1007 {
1008 	bModified = sal_True;
1009 	ModifyHdl( pEdit );
1010 	return 0;
1011 };
IMPL_LINK_INLINE_END(SwTableColumnPage,UpHdl,PercentField *,pEdit)1012 IMPL_LINK_INLINE_END( SwTableColumnPage, UpHdl, PercentField *, pEdit )
1013 
1014 /*------------------------------------------------------------------------
1015 ------------------------------------------------------------------------*/
1016 IMPL_LINK_INLINE_START( SwTableColumnPage, DownHdl, PercentField *, pEdit )
1017 {
1018 	bModified = sal_True;
1019 	ModifyHdl( pEdit );
1020 	return 0;
1021 };
IMPL_LINK_INLINE_END(SwTableColumnPage,DownHdl,PercentField *,pEdit)1022 IMPL_LINK_INLINE_END( SwTableColumnPage, DownHdl, PercentField *, pEdit )
1023 
1024 /*------------------------------------------------------------------------
1025 ------------------------------------------------------------------------*/
1026 IMPL_LINK_INLINE_START( SwTableColumnPage, LoseFocusHdl, PercentField *, pEdit )
1027 {
1028 	if(pEdit->IsModified())
1029 	{
1030 		bModified = sal_True;
1031 		ModifyHdl( pEdit );
1032 	}
1033 	return 0;
1034 };
IMPL_LINK_INLINE_END(SwTableColumnPage,LoseFocusHdl,PercentField *,pEdit)1035 IMPL_LINK_INLINE_END( SwTableColumnPage, LoseFocusHdl, PercentField *, pEdit )
1036 
1037 /*------------------------------------------------------------------------
1038 ------------------------------------------------------------------------*/
1039 IMPL_LINK( SwTableColumnPage, ModeHdl, CheckBox*, pBox )
1040 {
1041 	sal_Bool bCheck = pBox->IsChecked();
1042 	if(pBox == &aProportionalCB)
1043 	{
1044 		if(bCheck)
1045 			aModifyTableCB.Check();
1046 		aModifyTableCB.Enable(!bCheck && bModifyTbl);
1047 	}
1048 	return 0;
1049 };
1050 
1051 /*------------------------------------------------------------------------
1052 ------------------------------------------------------------------------*/
FillItemSet(SfxItemSet &)1053 sal_Bool  SwTableColumnPage::FillItemSet( SfxItemSet& )
1054 {
1055 	for( sal_uInt16 i = 0; i < MET_FIELDS; i++ )
1056 	{
1057 		if(pFieldArr[i]->HasFocus())
1058 		{
1059 			LoseFocusHdl(pFieldArr[i]);
1060 			break;
1061 		}
1062 	}
1063 
1064 	if(bModified)
1065 	{
1066 		pTblData->SetColsChanged();
1067 	}
1068 	return bModified;
1069 };
1070 
1071 /*------------------------------------------------------------------------
1072 ------------------------------------------------------------------------*/
ModifyHdl(PercentField * pEdit)1073 void   SwTableColumnPage::ModifyHdl( PercentField* pEdit )
1074 {
1075 		sal_uInt16 nAktPos;
1076 		sal_uInt16 i;
1077 
1078 		for( i = 0; i < MET_FIELDS; i++)
1079 			if(pEdit == pFieldArr[i])
1080 				break;
1081 
1082         if (MET_FIELDS <= i)
1083         {
1084             OSL_ENSURE(false, "cannot happen.");
1085             return;
1086         }
1087 
1088         SetVisibleWidth(aValueTbl[i], static_cast< SwTwips >(pEdit->DenormalizePercent(pEdit->GetValue( FUNIT_TWIP ))) );
1089 		nAktPos = aValueTbl[i];
1090 
1091 		UpdateCols( nAktPos );
1092 };
1093 
1094 /*------------------------------------------------------------------------
1095 ------------------------------------------------------------------------*/
UpdateCols(sal_uInt16 nAktPos)1096 void   SwTableColumnPage::UpdateCols( sal_uInt16 nAktPos )
1097 {
1098 	SwTwips nSum = 0;
1099 	sal_uInt16 i;
1100 
1101 	for( i = 0; i < nNoOfCols; i++ )
1102 	{
1103 		nSum += (pTblData->GetColumns())[i].nWidth;
1104 	}
1105 	SwTwips nDiff = nSum - nTableWidth;
1106 
1107     sal_Bool bModifyTable = aModifyTableCB.IsChecked();
1108 	sal_Bool bProp =    aProportionalCB.IsChecked();
1109 
1110     if(!bModifyTable && !bProp )
1111 	{
1112 //		the table width is constant, the difference is balanced with the other columns
1113 		sal_uInt16 nLoopCount = 0;
1114 		while( nDiff )
1115 		{
1116 			if( ++nAktPos == nNoOfVisibleCols)
1117 			{
1118 				nAktPos = 0;
1119 				++nLoopCount;
1120 				//#i101353# in small tables it might not be possible to balance column width
1121 				if( nLoopCount > 1 )
1122 					break;
1123 			}
1124 			if( nDiff < 0 )
1125 			{
1126 				SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
1127 				nDiff = 0;
1128 			}
1129 			else if( GetVisibleWidth(nAktPos) >= nDiff + nMinWidth )
1130 			{
1131 				SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
1132 				nDiff = 0;
1133 			}
1134 			if( nDiff > 0 && GetVisibleWidth(nAktPos) > nMinWidth )
1135 			{
1136 				if( nDiff >= (GetVisibleWidth(nAktPos) - nMinWidth) )
1137 				{
1138 					nDiff -= (GetVisibleWidth(nAktPos) - nMinWidth);
1139 					SetVisibleWidth(nAktPos, nMinWidth);
1140 				}
1141 				else
1142 				{
1143 					nDiff = 0;
1144 					SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
1145 				}
1146 				DBG_ASSERT(nDiff >= 0, "nDiff < 0 kann hier nicht sein!");
1147 			}
1148 		}
1149 	}
1150     else if(bModifyTable && !bProp)
1151 	{
1152 //		Differenz wird ueber die Tabellenbreite ausgeglichen,
1153 //		andere Spalten bleiben unveraendert
1154 		DBG_ASSERT(nDiff <= pTblData->GetSpace() - nTableWidth, "Maximum falsch eingestellt" );
1155 		SwTwips nActSpace = pTblData->GetSpace() - nTableWidth;
1156 		if(nDiff > nActSpace)
1157 		{
1158 			nTableWidth = pTblData->GetSpace();
1159 			SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) - nDiff + nActSpace );
1160 		}
1161 		else
1162 		{
1163 			nTableWidth += nDiff;
1164 		}
1165 	}
1166     else if(bModifyTable & bProp)
1167 	{
1168 //		Alle Spalten werden proportional mitveraendert, die Tabellenbreite wird
1169 //  	entsprechend angepasst
1170 		DBG_ASSERT(nDiff * nNoOfVisibleCols <= pTblData->GetSpace() - nTableWidth, "Maximum falsch eingestellt" );
1171 		long nAdd = nDiff;
1172 		if(nDiff * nNoOfVisibleCols > pTblData->GetSpace() - nTableWidth)
1173 		{
1174 			nAdd = (pTblData->GetSpace() - nTableWidth) / nNoOfVisibleCols;
1175 			SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) - nDiff + nAdd );
1176 			nDiff = nAdd;
1177 		}
1178 		if(nAdd)
1179             for(i = 0; i < nNoOfVisibleCols; i++ )
1180 			{
1181 				if(i == nAktPos)
1182 					continue;
1183 				SwTwips nVisWidth;
1184 				if((nVisWidth = GetVisibleWidth(i)) + nDiff < MINLAY)
1185 				{
1186 					nAdd += nVisWidth - MINLAY;
1187 					SetVisibleWidth(i, MINLAY);
1188 				}
1189 				else
1190 				{
1191 					SetVisibleWidth(i, nVisWidth + nDiff);
1192 					nAdd += nDiff;
1193 				}
1194 
1195 			}
1196 		nTableWidth += nAdd;
1197 
1198 	}
1199 	else
1200 	{
1201 //		Die Differenz wird gleichmaessig auf alle anderen Spalten aufgeteilt
1202 // 		die Tabellenbreite bleibt konstant
1203 /*
1204 		SwTwips nDiffn = nDiff/(nNoOfVisibleCols - 1);
1205 		if(nDiff < 0 && (nNoOfVisibleCols - 1) * nDiffn != nDiff)
1206 			nDiffn-- ;
1207 		sal_uInt16 nStart = nAktPos++;
1208 		if(nAktPos == nNoOfVisibleCols)
1209 			nStart = 0;
1210 		for(sal_uInt16 i = 0; i < nNoOfVisibleCols; i++ )
1211 		{
1212 			if((nVisWidth = GetVisibleWidth(i)) + nDiff < MINLAY)
1213 			{
1214 				nAdd += nVisWidth - MINLAY;
1215 				SetVisibleWidth(i, MINLAY);
1216 			}
1217 		}
1218 */
1219 
1220 	}
1221 
1222 #ifdef DEBUG_TBLDLG
1223 DbgTblRep(pTblData)
1224 #endif
1225 
1226 	if(!bPercentMode)
1227 		aSpaceED.SetValue(aSpaceED.Normalize( pTblData->GetSpace() - nTableWidth) , FUNIT_TWIP);
1228 
1229 	for( i = 0; ( i < nNoOfVisibleCols ) && ( i < MET_FIELDS ); i++)
1230 	{
1231         pFieldArr[i]->SetPrcntValue(pFieldArr[i]->NormalizePercent(
1232 						GetVisibleWidth(aValueTbl[i]) ), FUNIT_TWIP);
1233 		pFieldArr[i]->ClearModifyFlag();
1234 	}
1235 
1236 }
1237 
1238 /*------------------------------------------------------------------------
1239 ------------------------------------------------------------------------*/
ActivatePage(const SfxItemSet &)1240 void    SwTableColumnPage::ActivatePage( const SfxItemSet& )
1241 {
1242 	bPercentMode = pTblData->GetWidthPercent() != 0;
1243 	for( sal_uInt16 i = 0; (i < MET_FIELDS) && (i < nNoOfVisibleCols); i++ )
1244 	{
1245 		pFieldArr[i]->SetRefValue(pTblData->GetWidth());
1246 		pFieldArr[i]->ShowPercent( bPercentMode );
1247 	}
1248 
1249 	sal_uInt16 nTblAlign = pTblData->GetAlign();
1250     if((text::HoriOrientation::FULL != nTblAlign && nTableWidth != pTblData->GetWidth()) ||
1251     (text::HoriOrientation::FULL == nTblAlign && nTableWidth != pTblData->GetSpace()))
1252 	{
1253         nTableWidth = text::HoriOrientation::FULL == nTblAlign ?
1254 									pTblData->GetSpace() :
1255 										pTblData->GetWidth();
1256 		UpdateCols(0);
1257 	}
1258 	bModifyTbl = sal_True;
1259 	if(pTblData->GetWidthPercent() ||
1260                 text::HoriOrientation::FULL == nTblAlign ||
1261 						pTblData->IsLineSelected()  )
1262 		bModifyTbl = sal_False;
1263 	if(bPercentMode)
1264 	{
1265 		aModifyTableCB	.Check(sal_False);
1266 		aProportionalCB .Check(sal_False);
1267 	}
1268 	else if( !bModifyTbl )
1269 	{
1270 		aProportionalCB.Check(sal_False);
1271 		aModifyTableCB.Check(sal_False);
1272 	}
1273 	aSpaceFT.Enable(!bPercentMode);
1274 	aSpaceED.Enable(!bPercentMode);
1275 	aModifyTableCB.Enable( !bPercentMode && bModifyTbl );
1276 	aProportionalCB.Enable(!bPercentMode && bModifyTbl );
1277 
1278 /*	if(pTblData->IsLineSelected() && pTblData->IsComplex())
1279 	{
1280 
1281 	}*/
1282 	aSpaceED.SetValue(aSpaceED.Normalize(
1283 				pTblData->GetSpace() - nTableWidth) , FUNIT_TWIP);
1284 
1285 }
1286 
1287 /*------------------------------------------------------------------------
1288 ------------------------------------------------------------------------*/
DeactivatePage(SfxItemSet * _pSet)1289 int  SwTableColumnPage::DeactivatePage( SfxItemSet* _pSet )
1290 {
1291     if(_pSet)
1292 	{
1293         FillItemSet(*_pSet);
1294         if(text::HoriOrientation::FULL != pTblData->GetAlign() && pTblData->GetWidth() != nTableWidth)
1295 		{
1296 			pTblData->SetWidth(nTableWidth);
1297 			SwTwips nDiff = pTblData->GetSpace() - pTblData->GetWidth() -
1298 							pTblData->GetLeftSpace() - pTblData->GetRightSpace();
1299 			switch( pTblData->GetAlign()  )
1300 			{
1301                 case text::HoriOrientation::RIGHT:
1302 					pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff);
1303 				break;
1304                 case text::HoriOrientation::LEFT:
1305 					pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff);
1306 				break;
1307                 case text::HoriOrientation::NONE:
1308 				{
1309 					SwTwips nDiff2 = nDiff/2;
1310 					if( nDiff > 0 ||
1311 						(-nDiff2 < pTblData->GetRightSpace() && - nDiff2 < pTblData->GetLeftSpace()))
1312 					{
1313 						pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff2);
1314 						pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff2);
1315 					}
1316 					else
1317 					{
1318 						if(pTblData->GetRightSpace() > pTblData->GetLeftSpace())
1319 						{
1320 							pTblData->SetLeftSpace(0);
1321 							pTblData->SetRightSpace(pTblData->GetSpace() - pTblData->GetWidth());
1322 						}
1323 						else
1324 						{
1325 							pTblData->SetRightSpace(0);
1326 							pTblData->SetLeftSpace(pTblData->GetSpace() - pTblData->GetWidth());
1327 						}
1328 					}
1329 				}
1330 				break;
1331                 case text::HoriOrientation::CENTER:
1332 					pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff/2);
1333 					pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff/2);
1334 				break;
1335                 case text::HoriOrientation::LEFT_AND_WIDTH :
1336 					if(nDiff > pTblData->GetRightSpace())
1337 					{
1338 						pTblData->SetLeftSpace(pTblData->GetSpace() - pTblData->GetWidth());
1339 					}
1340 					pTblData->SetRightSpace(
1341 						pTblData->GetSpace() - pTblData->GetWidth() - pTblData->GetLeftSpace());
1342 				break;
1343 			}
1344 			pTblData->SetWidthChanged();
1345 		}
1346 #ifdef DEBUG_TBLDLG
1347 DbgTblRep(pTblData)
1348 #endif
1349         _pSet->Put(SwPtrItem( FN_TABLE_REP, pTblData ));
1350 	}
1351 	return sal_True;
1352 }
1353 
1354 /*------------------------------------------------------------------------
1355 ------------------------------------------------------------------------*/
GetVisibleWidth(sal_uInt16 nPos)1356 SwTwips  SwTableColumnPage::GetVisibleWidth(sal_uInt16 nPos)
1357 {
1358 	sal_uInt16 i=0;
1359 
1360 	while( nPos )
1361 	{
1362 		if(pTblData->GetColumns()[i].bVisible && nPos)
1363 			nPos--;
1364 		i++;
1365 	}
1366 	SwTwips nReturn = pTblData->GetColumns()[i].nWidth;
1367 	DBG_ASSERT(i < nNoOfCols, "Array index out of range");
1368 	while(!pTblData->GetColumns()[i].bVisible && (i + 1) < nNoOfCols)
1369 		nReturn += pTblData->GetColumns()[++i].nWidth;
1370 
1371 //	return (*ppTableColumns)[i].nWidth;
1372 	return nReturn;
1373 }
1374 
1375 /*------------------------------------------------------------------------
1376 ------------------------------------------------------------------------*/
SetVisibleWidth(sal_uInt16 nPos,SwTwips nNewWidth)1377 void SwTableColumnPage::SetVisibleWidth(sal_uInt16 nPos, SwTwips nNewWidth)
1378 {
1379 	sal_uInt16 i=0;
1380 	while( nPos )
1381 	{
1382 		if(pTblData->GetColumns()[i].bVisible && nPos)
1383 			nPos--;
1384 		i++;
1385 	}
1386 	DBG_ASSERT(i < nNoOfCols, "Array index out of range");
1387 	pTblData->GetColumns()[i].nWidth = nNewWidth;
1388 	while(!pTblData->GetColumns()[i].bVisible && (i + 1) < nNoOfCols)
1389 		pTblData->GetColumns()[++i].nWidth = 0;
1390 
1391 }
1392 
1393 /*------------------------------------------------------------------------
1394 ------------------------------------------------------------------------*/
SwTableTabDlg(Window * pParent,SfxItemPool &,const SfxItemSet * pItemSet,SwWrtShell * pSh)1395 SwTableTabDlg::SwTableTabDlg(Window* pParent, SfxItemPool& ,
1396 					const SfxItemSet* pItemSet, SwWrtShell* pSh ) :
1397 		SfxTabDialog(pParent, SW_RES(DLG_FORMAT_TABLE), pItemSet,0),
1398         pShell(pSh),
1399         nHtmlMode(::GetHtmlMode(pSh->GetView().GetDocShell()))
1400 {
1401 	FreeResource();
1402     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1403     DBG_ASSERT(pFact, "Dialogdiet fail!");
1404 	AddTabPage(TP_FORMAT_TABLE, &SwFormatTablePage::Create, 0 );
1405 	AddTabPage(TP_TABLE_TEXTFLOW, &SwTextFlowPage::Create, 0 );
1406 	AddTabPage(TP_TABLE_COLUMN, &SwTableColumnPage::Create, 0 );
1407     AddTabPage(TP_BACKGROUND, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0 );
1408     AddTabPage(TP_BORDER, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), 0 );
1409 }
1410 
1411 
1412 /*------------------------------------------------------------------------
1413 ------------------------------------------------------------------------*/
PageCreated(sal_uInt16 nId,SfxTabPage & rPage)1414 void  SwTableTabDlg::PageCreated(sal_uInt16 nId, SfxTabPage& rPage)
1415 {
1416     SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
1417 	if( TP_BACKGROUND == nId )
1418 	{
1419         sal_Int32 nFlagType = SVX_SHOW_TBLCTL;
1420         if(!( nHtmlMode & HTMLMODE_ON ) ||
1421 			nHtmlMode & HTMLMODE_SOME_STYLES)
1422             nFlagType |= SVX_SHOW_SELECTOR;
1423         aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, nFlagType));
1424 		rPage.PageCreated(aSet);
1425 	}
1426 	else if(TP_BORDER == nId)
1427 	{
1428 		aSet.Put (SfxUInt16Item(SID_SWMODE_TYPE,SW_BORDER_MODE_TABLE));
1429 		rPage.PageCreated(aSet);
1430 	}
1431 	else if(TP_TABLE_TEXTFLOW == nId)
1432 	{
1433 		((SwTextFlowPage&)rPage).SetShell(pShell);
1434 		const sal_uInt16 eType = pShell->GetFrmType(0,sal_True);
1435 		if( !(FRMTYPE_BODY & eType) )
1436 			((SwTextFlowPage&)rPage).DisablePageBreak();
1437 	}
1438 }
1439 
1440 /*-----------------12.12.96 12.22-------------------
1441 --------------------------------------------------*/
SwTextFlowPage(Window * pParent,const SfxItemSet & rSet)1442 SwTextFlowPage::SwTextFlowPage( Window* pParent,
1443 								const SfxItemSet& rSet ) :
1444 	SfxTabPage(pParent, SW_RES( TP_TABLE_TEXTFLOW ), rSet ),
1445     aFlowFL         (this, SW_RES(FL_FLOW            )),
1446 	aPgBrkCB        (this, SW_RES(CB_PAGEBREAK      )),
1447 	aPgBrkRB        (this, SW_RES(RB_BREAKPAGE      )),
1448 	aColBrkRB       (this, SW_RES(RB_BREAKCOLUMN    )),
1449 	aPgBrkBeforeRB  (this, SW_RES(RB_PAGEBREAKBEFORE)),
1450 	aPgBrkAfterRB   (this, SW_RES(RB_PAGEBREAKAFTER )),
1451 	aPageCollCB     (this, SW_RES(CB_PAGECOLL       )),
1452 	aPageCollLB     (this, SW_RES(LB_PAGECOLL       )),
1453 	aPageNoFT       (this, SW_RES(FT_PAGENUM        )),
1454 	aPageNoNF       (this, SW_RES(NF_PAGENUM        )),
1455     aSplitCB        (this, SW_RES(CB_SPLIT          )),
1456     aSplitRowCB     (this, SW_RES(CB_SPLIT_ROW      )),
1457 	aKeepCB			(this, SW_RES(CB_KEEP			)),
1458     aHeadLineCB     (this, SW_RES(CB_HEADLINE       )),
1459     aRepeatHeaderFT         (this, SW_RES(FT_REPEAT_HEADER  )),
1460     aRepeatHeaderBeforeFT   (this),
1461     aRepeatHeaderNF         (this, SW_RES(NF_REPEAT_HEADER  )),
1462     aRepeatHeaderAfterFT    (this),
1463     aRepeatHeaderCombo      (this, SW_RES(WIN_REPEAT_HEADER), aRepeatHeaderNF, aRepeatHeaderBeforeFT, aRepeatHeaderAfterFT),
1464     aTextDirectionFT(this, SW_RES(FT_TEXTDIRECTION  )),
1465     aTextDirectionLB(this, SW_RES(LB_TEXTDIRECTION  )),
1466 
1467     aVertOrientFL   (this, SW_RES(FL_VERT_ORIENT    )),
1468     aVertOrientFT(this,  SW_RES(FT_VERTORIENT       )),
1469     aVertOrientLB(this,  SW_RES(LB_VERTORIENT       )),
1470 
1471     pShell(0),
1472 
1473 	bPageBreak(sal_True),
1474 	bHtmlMode(sal_False)
1475 {
1476 	FreeResource();
1477 
1478 	aPgBrkRB.SetAccessibleRelationMemberOf(&aPgBrkCB);
1479 	aColBrkRB.SetAccessibleRelationMemberOf(&aPgBrkCB);
1480 	aPgBrkBeforeRB.SetAccessibleRelationMemberOf(&aPgBrkCB);
1481 	aPgBrkAfterRB.SetAccessibleRelationMemberOf(&aPgBrkCB);
1482 	aPageCollLB.SetAccessibleRelationLabeledBy(&aPageCollCB);
1483 	aPageCollLB.SetAccessibleName(aPageCollCB.GetText());
1484 
1485 	aPgBrkCB.SetClickHdl(LINK(this, SwTextFlowPage, PageBreakHdl_Impl));
1486 	aPgBrkBeforeRB.SetClickHdl(
1487 		LINK( this, SwTextFlowPage, PageBreakPosHdl_Impl ) );
1488 	aPgBrkAfterRB.SetClickHdl(
1489 		LINK( this, SwTextFlowPage, PageBreakPosHdl_Impl ) );
1490 	aPageCollCB.SetClickHdl(
1491 		LINK( this, SwTextFlowPage, ApplyCollClickHdl_Impl ) );
1492 	aColBrkRB.SetClickHdl(
1493 		LINK( this, SwTextFlowPage, PageBreakTypeHdl_Impl ) );
1494 	aPgBrkRB.SetClickHdl(
1495 		LINK( this, SwTextFlowPage, PageBreakTypeHdl_Impl ) );
1496     aSplitCB.SetClickHdl(
1497         LINK( this, SwTextFlowPage, SplitHdl_Impl));
1498     aSplitRowCB.SetClickHdl(
1499         LINK( this, SwTextFlowPage, SplitRowHdl_Impl));
1500 	aHeadLineCB.SetClickHdl( LINK( this, SwTextFlowPage, HeadLineCBClickHdl ) );
1501 
1502 #ifndef SW_FILEFORMAT_40
1503 	const SfxPoolItem *pItem;
1504 	if(SFX_ITEM_SET == rSet.GetItemState( SID_HTML_MODE, sal_False,&pItem )
1505 		&& ((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON)
1506 #endif
1507 	{
1508 		aKeepCB.Hide();
1509 		aSplitCB.Hide();
1510         aSplitRowCB.Hide();
1511 	}
1512 
1513 	aRepeatHeaderCombo.Arrange( aRepeatHeaderFT );
1514 
1515 	HeadLineCBClickHdl();
1516 }
1517 
1518 /*-----------------12.12.96 12.22-------------------
1519 --------------------------------------------------*/
~SwTextFlowPage()1520  SwTextFlowPage::~SwTextFlowPage()
1521 {
1522 }
1523 
1524 /*-----------------12.12.96 12.22-------------------
1525 --------------------------------------------------*/
Create(Window * pParent,const SfxItemSet & rAttrSet)1526 SfxTabPage*   SwTextFlowPage::Create( Window* pParent,
1527 								const SfxItemSet& rAttrSet)
1528 {
1529 	return new SwTextFlowPage(pParent, rAttrSet);
1530 }
1531 
1532 /*-----------------12.12.96 12.22-------------------
1533 --------------------------------------------------*/
FillItemSet(SfxItemSet & rSet)1534 sal_Bool  SwTextFlowPage::FillItemSet( SfxItemSet& rSet )
1535 {
1536 	sal_Bool bModified = sal_False;
1537 
1538 	//Ueberschrift wiederholen
1539 	if(aHeadLineCB.IsChecked() != aHeadLineCB.GetSavedValue() ||
1540         String::CreateFromInt32( static_cast< sal_Int32 >(aRepeatHeaderNF.GetValue()) ) != aRepeatHeaderNF.GetSavedValue() )
1541 	{
1542 		bModified |= 0 != rSet.Put(
1543 			SfxUInt16Item(FN_PARAM_TABLE_HEADLINE, aHeadLineCB.IsChecked()? sal_uInt16(aRepeatHeaderNF.GetValue()) : 0 ));
1544 	}
1545 	if(aKeepCB.IsChecked() != aKeepCB.GetSavedValue())
1546         bModified |= 0 != rSet.Put( SvxFmtKeepItem( aKeepCB.IsChecked(), RES_KEEP));
1547 
1548 	if(aSplitCB.IsChecked() != aSplitCB.GetSavedValue())
1549         bModified |= 0 != rSet.Put( SwFmtLayoutSplit( aSplitCB.IsChecked()));
1550 
1551     if(aSplitRowCB.IsChecked() != aSplitRowCB.GetSavedValue())
1552         bModified |= 0 != rSet.Put( SwFmtRowSplit( aSplitRowCB.IsChecked()));
1553 
1554 
1555 	const SvxFmtBreakItem* pBreak = (const SvxFmtBreakItem*)GetOldItem( rSet, RES_BREAK );
1556 	const SwFmtPageDesc* pDesc = (const SwFmtPageDesc*) GetOldItem( rSet, RES_PAGEDESC );
1557 
1558 
1559 	sal_Bool bState = aPageCollCB.IsChecked();
1560 
1561 	//Wenn Seitenvorlage, dann kein Break
1562 	sal_Bool bPageItemPut = sal_False;
1563 	if ( bState != aPageCollCB.GetSavedValue() ||
1564 		 ( bState &&
1565 		   aPageCollLB.GetSelectEntryPos() != aPageCollLB.GetSavedValue() )
1566 		   || (aPageNoNF.IsEnabled() && aPageNoNF.IsValueModified()) )
1567 	{
1568 		String sPage;
1569 
1570 		if ( bState )
1571 		{
1572 			sPage = aPageCollLB.GetSelectEntry();
1573 		}
1574         sal_uInt16 nPgNum = static_cast< sal_uInt16 >(aPageNoNF.GetValue());
1575 		if ( !pDesc || !pDesc->GetPageDesc() ||
1576 			( pDesc->GetPageDesc() && ((pDesc->GetPageDesc()->GetName() != sPage) ||
1577 					aPageNoNF.GetSavedValue() != (String)nPgNum)))
1578 		{
1579 			SwFmtPageDesc aFmt( pShell->FindPageDescByName( sPage, sal_True ) );
1580 			aFmt.SetNumOffset(bState ? nPgNum : 0);
1581 			bModified |= 0 != rSet.Put( aFmt );
1582 			bPageItemPut = bState;
1583 		}
1584 	}
1585 	sal_Bool bIsChecked = aPgBrkCB.IsChecked();
1586 	if ( !bPageItemPut &&
1587 		(	bState != aPageCollCB.GetSavedValue() ||
1588 			bIsChecked != aPgBrkCB.GetSavedValue()				||
1589 			aPgBrkBeforeRB.IsChecked() != aPgBrkBeforeRB.GetSavedValue()	||
1590 			aPgBrkRB.IsChecked() != aPgBrkRB.GetSavedValue() ))
1591 	{
1592 		SvxFmtBreakItem aBreak(
1593 			(const SvxFmtBreakItem&)GetItemSet().Get( RES_BREAK ) );
1594 
1595 		if(bIsChecked)
1596 		{
1597 			sal_Bool bBefore = aPgBrkBeforeRB.IsChecked();
1598 
1599 			if ( aPgBrkRB.IsChecked() )
1600 			{
1601 				if ( bBefore )
1602 					aBreak.SetValue( SVX_BREAK_PAGE_BEFORE );
1603 				else
1604 					aBreak.SetValue( SVX_BREAK_PAGE_AFTER );
1605 			}
1606 			else
1607 			{
1608 				if ( bBefore )
1609 					aBreak.SetValue( SVX_BREAK_COLUMN_BEFORE );
1610 				else
1611 					aBreak.SetValue( SVX_BREAK_COLUMN_AFTER );
1612 			}
1613 		}
1614 		else
1615 		{
1616 				aBreak.SetValue( SVX_BREAK_NONE );
1617 		}
1618 
1619 		if ( !pBreak || !( *(const SvxFmtBreakItem*)pBreak == aBreak ) )
1620 		{
1621 			bModified |= 0 != rSet.Put( aBreak );
1622 		}
1623 	}
1624 
1625     if(aTextDirectionLB.GetSelectEntryPos() != aTextDirectionLB.GetSavedValue())
1626     {
1627           bModified |= 0 != rSet.Put(
1628                     SvxFrameDirectionItem(
1629                         (SvxFrameDirection)(sal_uLong)aTextDirectionLB.GetEntryData(aTextDirectionLB.GetSelectEntryPos())
1630                         , FN_TABLE_BOX_TEXTDIRECTION));
1631     }
1632 
1633     if(aVertOrientLB.GetSelectEntryPos() != aVertOrientLB.GetSavedValue())
1634     {
1635         sal_uInt16 nOrient = USHRT_MAX;
1636         switch(aVertOrientLB.GetSelectEntryPos())
1637         {
1638             case 0 : nOrient = text::VertOrientation::NONE; break;
1639             case 1 : nOrient = text::VertOrientation::CENTER; break;
1640             case 2 : nOrient = text::VertOrientation::BOTTOM; break;
1641         }
1642         if(nOrient != USHRT_MAX)
1643             bModified |= 0 != rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, nOrient));
1644     }
1645 
1646 	return bModified;
1647 
1648 }
1649 
1650 /*-----------------12.12.96 12.22-------------------
1651 --------------------------------------------------*/
Reset(const SfxItemSet & rSet)1652 void   SwTextFlowPage::Reset( const SfxItemSet& rSet )
1653 {
1654 	const SfxPoolItem* pItem;
1655 	SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get();
1656 	sal_Bool bFlowAllowed = !bHtmlMode || pHtmlOpt->IsPrintLayoutExtension();
1657 	if(bFlowAllowed)
1658 	{
1659 		// Einfuegen der vorhandenen Seitenvorlagen in die Listbox
1660 		const sal_uInt16 nCount = pShell->GetPageDescCnt();
1661 		sal_uInt16 i;
1662 
1663 		for( i = 0; i < nCount; ++i)
1664 		{
1665 			const SwPageDesc &rPageDesc = pShell->GetPageDesc(i);
1666 			aPageCollLB.InsertEntry(rPageDesc.GetName());
1667 		}
1668 
1669 		String aFmtName;
1670 		for(i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
1671 			if( LISTBOX_ENTRY_NOTFOUND == aPageCollLB.GetEntryPos(
1672 					aFmtName = SwStyleNameMapper::GetUIName( i, aFmtName ) ))
1673 				aPageCollLB.InsertEntry( aFmtName );
1674 
1675 		if(SFX_ITEM_SET == rSet.GetItemState( RES_KEEP, sal_False, &pItem ))
1676 		{
1677 			aKeepCB.Check( ((const SvxFmtKeepItem*)pItem)->GetValue() );
1678 			aKeepCB.SaveValue();
1679 		}
1680 		if(SFX_ITEM_SET == rSet.GetItemState( RES_LAYOUT_SPLIT, sal_False, &pItem ))
1681 		{
1682             aSplitCB.Check( ((const SwFmtLayoutSplit*)pItem)->GetValue() );
1683 		}
1684         else
1685             aSplitCB.Check();
1686 
1687 	    aSplitCB.SaveValue();
1688         SplitHdl_Impl(&aSplitCB);
1689 
1690         if(SFX_ITEM_SET == rSet.GetItemState( RES_ROW_SPLIT, sal_False, &pItem ))
1691         {
1692             aSplitRowCB.Check( ((const SwFmtRowSplit*)pItem)->GetValue() );
1693         }
1694         else
1695             aSplitRowCB.SetState(STATE_DONTKNOW);
1696         aSplitRowCB.SaveValue();
1697 
1698         if(bPageBreak)
1699 		{
1700 			if(SFX_ITEM_SET == rSet.GetItemState( RES_PAGEDESC, sal_False, &pItem ))
1701 			{
1702 				String sPageDesc;
1703 				const SwPageDesc* pDesc = ((const SwFmtPageDesc*)pItem)->GetPageDesc();
1704 				aPageNoNF.SetValue(((const SwFmtPageDesc*)pItem)->GetNumOffset());
1705 				if(pDesc)
1706 					sPageDesc = pDesc->GetName();
1707 				if ( sPageDesc.Len() &&
1708 						aPageCollLB.GetEntryPos( sPageDesc ) != LISTBOX_ENTRY_NOTFOUND )
1709 				{
1710 					aPageCollLB.SelectEntry( sPageDesc );
1711 					aPageCollCB.Check();
1712 
1713 					aPgBrkCB.Enable();
1714 					aPgBrkRB.Enable();
1715 					aColBrkRB.Enable();
1716 					aPgBrkBeforeRB.Enable();
1717 					aPgBrkAfterRB.Enable();
1718 					aPageCollCB.Enable();
1719 					aPgBrkCB.Check();
1720 
1721 					aPgBrkCB.Check( sal_True );
1722 					aColBrkRB.Check( sal_False );
1723 					aPgBrkBeforeRB.Check( sal_True );
1724 					aPgBrkAfterRB.Check( sal_False );
1725 				}
1726 				else
1727 				{
1728 					aPageCollLB.SetNoSelection();
1729 					aPageCollCB.Check(sal_False);
1730 				}
1731 			}
1732 
1733 			if(SFX_ITEM_SET == rSet.GetItemState( RES_BREAK, sal_False, &pItem ))
1734 			{
1735 				const SvxFmtBreakItem* pPageBreak = (const SvxFmtBreakItem*)pItem;
1736 				SvxBreak eBreak = (SvxBreak)pPageBreak->GetValue();
1737 
1738 				if ( eBreak != SVX_BREAK_NONE )
1739 				{
1740 					aPgBrkCB.Check();
1741 					aPageCollCB.Enable(sal_False);
1742 					aPageCollLB.Enable(sal_False);
1743 					aPageNoFT.Enable(sal_False);
1744 					aPageNoNF.Enable(sal_False);
1745 				}
1746 				switch ( eBreak )
1747 				{
1748 					case SVX_BREAK_PAGE_BEFORE:
1749 						aPgBrkRB.Check( sal_True );
1750 						aColBrkRB.Check( sal_False );
1751 						aPgBrkBeforeRB.Check( sal_True );
1752 						aPgBrkAfterRB.Check( sal_False );
1753 						break;
1754 					case SVX_BREAK_PAGE_AFTER:
1755 						aPgBrkRB.Check( sal_True );
1756 						aColBrkRB.Check( sal_False );
1757 						aPgBrkBeforeRB.Check( sal_False );
1758 						aPgBrkAfterRB.Check( sal_True );
1759 						break;
1760 					case SVX_BREAK_COLUMN_BEFORE:
1761 						aPgBrkRB.Check( sal_False );
1762 						aColBrkRB.Check( sal_True );
1763 						aPgBrkBeforeRB.Check( sal_True );
1764 						aPgBrkAfterRB.Check( sal_False );
1765 						break;
1766 					case SVX_BREAK_COLUMN_AFTER:
1767 						aPgBrkRB.Check( sal_False );
1768 						aColBrkRB.Check( sal_True );
1769 						aPgBrkBeforeRB.Check( sal_False );
1770 						aPgBrkAfterRB.Check( sal_True );
1771 						break;
1772                     default:; //prevent warning
1773 				}
1774 
1775 			}
1776 			if ( aPgBrkBeforeRB.IsChecked() )
1777 				PageBreakPosHdl_Impl( &aPgBrkBeforeRB );
1778 			else if ( aPgBrkAfterRB.IsChecked() )
1779 				PageBreakPosHdl_Impl( &aPgBrkAfterRB );
1780 			PageBreakHdl_Impl( &aPgBrkCB );
1781 		}
1782 	}
1783 	else
1784 	{
1785 		aPgBrkRB.Enable(sal_False);
1786 		aColBrkRB.Enable(sal_False);
1787 		aPgBrkBeforeRB.Enable(sal_False);
1788 		aPgBrkAfterRB.Enable(sal_False);
1789 		aKeepCB	.Enable(sal_False);
1790 		aSplitCB.Enable(sal_False);
1791 		aPgBrkCB.Enable(sal_False);
1792 		aPageCollCB.Enable(sal_False);
1793 		aPageCollLB.Enable(sal_False);
1794 	}
1795 
1796 	if(SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, sal_False, &pItem ))
1797 	{
1798 		sal_uInt16 nRep = ((const SfxUInt16Item*)pItem)->GetValue();
1799 		aHeadLineCB.Check( nRep > 0 );
1800 		aHeadLineCB.SaveValue();
1801 		aRepeatHeaderNF.SetValue( nRep );
1802 		aRepeatHeaderNF.SaveValue();
1803 	}
1804     if ( rSet.GetItemState(FN_TABLE_BOX_TEXTDIRECTION) > SFX_ITEM_AVAILABLE )
1805     {
1806         sal_uLong nDirection = ((const SvxFrameDirectionItem&)rSet.Get(FN_TABLE_BOX_TEXTDIRECTION)).GetValue();
1807         aTextDirectionLB.SelectEntryPos(aTextDirectionLB.GetEntryPos( (const void*)nDirection ));
1808     }
1809 
1810     if ( rSet.GetItemState(FN_TABLE_SET_VERT_ALIGN) > SFX_ITEM_AVAILABLE )
1811 	{
1812 		sal_uInt16 nVert = ((const SfxUInt16Item&)rSet.Get(FN_TABLE_SET_VERT_ALIGN)).GetValue();
1813         sal_uInt16 nPos = 0;
1814 		switch(nVert)
1815 		{
1816             case text::VertOrientation::NONE:     nPos = 0;   break;
1817             case text::VertOrientation::CENTER:   nPos = 1;   break;
1818             case text::VertOrientation::BOTTOM:   nPos = 2;   break;
1819 		}
1820         aVertOrientLB.SelectEntryPos(nPos);
1821 	}
1822 
1823 	aPageCollCB.SaveValue();
1824 	aPageCollLB.SaveValue();
1825 	aPgBrkCB.SaveValue();
1826 	aPgBrkRB.SaveValue();
1827 	aColBrkRB.SaveValue();
1828 	aPgBrkBeforeRB.SaveValue();
1829 	aPgBrkAfterRB.SaveValue();
1830 	aPageNoNF.SaveValue();
1831     aTextDirectionLB.SaveValue();
1832     aVertOrientLB.SaveValue();
1833 
1834 	HeadLineCBClickHdl();
1835 }
1836 /*-----------------16.04.98 14:48-------------------
1837 
1838 --------------------------------------------------*/
1839 
SetShell(SwWrtShell * pSh)1840 void SwTextFlowPage::SetShell(SwWrtShell* pSh)
1841 {
1842 	pShell = pSh;
1843 	bHtmlMode = 0 != (::GetHtmlMode(pShell->GetView().GetDocShell()) & HTMLMODE_ON);
1844 	if(bHtmlMode)
1845 	{
1846 		aPageNoNF.Enable(sal_False);
1847 		aPageNoFT.Enable(sal_False);
1848 	}
1849 }
1850 
1851 /*-----------------12.12.96 16.18-------------------
1852 --------------------------------------------------*/
IMPL_LINK(SwTextFlowPage,PageBreakHdl_Impl,CheckBox *,EMPTYARG)1853 IMPL_LINK( SwTextFlowPage, PageBreakHdl_Impl, CheckBox*, EMPTYARG )
1854 {
1855 	if( aPgBrkCB.IsChecked() )
1856 	{
1857 			aPgBrkRB.		Enable();
1858 			aColBrkRB.		Enable();
1859 			aPgBrkBeforeRB.	Enable();
1860 			aPgBrkAfterRB.	Enable();
1861 
1862 			if ( aPgBrkRB.IsChecked() && aPgBrkBeforeRB.IsChecked() )
1863 			{
1864 				aPageCollCB.Enable();
1865 
1866 				sal_Bool bEnable = aPageCollCB.IsChecked() &&
1867 											aPageCollLB.GetEntryCount();
1868 				aPageCollLB.Enable(bEnable);
1869 				if(!bHtmlMode)
1870 				{
1871 					aPageNoFT.Enable(bEnable);
1872 					aPageNoNF.Enable(bEnable);
1873 				}
1874 			}
1875 	}
1876 	else
1877 	{
1878 			aPageCollCB.Check( sal_False );
1879 			aPageCollCB.Enable(sal_False);
1880 			aPageCollLB.Enable(sal_False);
1881 			aPageNoFT.Enable(sal_False);
1882 			aPageNoNF.Enable(sal_False);
1883 			aPgBrkRB.		Enable(sal_False);
1884 			aColBrkRB.		Enable(sal_False);
1885 			aPgBrkBeforeRB.	Enable(sal_False);
1886 			aPgBrkAfterRB.	Enable(sal_False);
1887 	}
1888 	return 0;
1889 }
1890 
1891 /*-----------------12.12.96 16.18-------------------
1892 --------------------------------------------------*/
IMPL_LINK(SwTextFlowPage,ApplyCollClickHdl_Impl,CheckBox *,EMPTYARG)1893 IMPL_LINK( SwTextFlowPage, ApplyCollClickHdl_Impl, CheckBox*, EMPTYARG )
1894 {
1895 	sal_Bool bEnable = sal_False;
1896 	if ( aPageCollCB.IsChecked() &&
1897 		 aPageCollLB.GetEntryCount() )
1898 	{
1899 		bEnable = sal_True;
1900 		aPageCollLB.SelectEntryPos( 0 );
1901 	}
1902 	else
1903 	{
1904 		aPageCollLB.SetNoSelection();
1905 	}
1906 	aPageCollLB.Enable(bEnable);
1907 	if(!bHtmlMode)
1908 	{
1909 		aPageNoFT.Enable(bEnable);
1910 		aPageNoNF.Enable(bEnable);
1911 	}
1912 	return 0;
1913 }
1914 
1915 /*-----------------12.12.96 16.18-------------------
1916 --------------------------------------------------*/
IMPL_LINK(SwTextFlowPage,PageBreakPosHdl_Impl,RadioButton *,pBtn)1917 IMPL_LINK( SwTextFlowPage, PageBreakPosHdl_Impl, RadioButton*, pBtn )
1918 {
1919 	if ( aPgBrkCB.IsChecked() )
1920 	{
1921         if ( pBtn == &aPgBrkBeforeRB && aPgBrkRB.IsChecked() )
1922 		{
1923 			aPageCollCB.Enable();
1924 
1925 			sal_Bool bEnable = aPageCollCB.IsChecked()  &&
1926 										aPageCollLB.GetEntryCount();
1927 
1928 			aPageCollLB.Enable(bEnable);
1929 			if(!bHtmlMode)
1930 			{
1931 				aPageNoFT.Enable(bEnable);
1932 				aPageNoNF.Enable(bEnable);
1933 			}
1934 		}
1935 		else if ( pBtn == &aPgBrkAfterRB )
1936 		{
1937 			aPageCollCB	.Check( sal_False );
1938 			aPageCollCB	.Enable(sal_False);
1939 			aPageCollLB	.Enable(sal_False);
1940 			aPageNoFT 	.Enable(sal_False);
1941 			aPageNoNF	.Enable(sal_False);
1942 		}
1943 	}
1944 	return 0;
1945 }
1946 
1947 /*-----------------12.12.96 16.18-------------------
1948 --------------------------------------------------*/
IMPL_LINK(SwTextFlowPage,PageBreakTypeHdl_Impl,RadioButton *,pBtn)1949 IMPL_LINK( SwTextFlowPage, PageBreakTypeHdl_Impl, RadioButton*, pBtn )
1950 {
1951 	if ( pBtn == &aColBrkRB || aPgBrkAfterRB.IsChecked() )
1952 	{
1953 		aPageCollCB	.Check(sal_False);
1954 		aPageCollCB	.Enable(sal_False);
1955 		aPageCollLB	.Enable(sal_False);
1956 		aPageNoFT	.Enable(sal_False);
1957 		aPageNoNF	.Enable(sal_False);
1958 	}
1959 	else if ( aPgBrkBeforeRB.IsChecked() )
1960 		PageBreakPosHdl_Impl( &aPgBrkBeforeRB );
1961 	return 0;
1962 }
1963 /*-----------------17.11.2003 11:30-----------------
1964  *
1965  * --------------------------------------------------*/
IMPL_LINK(SwTextFlowPage,SplitHdl_Impl,CheckBox *,pBox)1966 IMPL_LINK( SwTextFlowPage, SplitHdl_Impl, CheckBox*, pBox )
1967 {
1968     aSplitRowCB.Enable(pBox->IsChecked());
1969     return 0;
1970 }
1971 /*-----------------17.11.2003 11:30-----------------
1972  *
1973  * --------------------------------------------------*/
IMPL_LINK(SwTextFlowPage,SplitRowHdl_Impl,TriStateBox *,pBox)1974 IMPL_LINK( SwTextFlowPage, SplitRowHdl_Impl, TriStateBox*, pBox )
1975 {
1976     pBox->EnableTriState(sal_False);
1977     return 0;
1978 }
1979 
IMPL_LINK(SwTextFlowPage,HeadLineCBClickHdl,void *,EMPTYARG)1980 IMPL_LINK( SwTextFlowPage, HeadLineCBClickHdl, void*, EMPTYARG )
1981 {
1982 	aRepeatHeaderCombo.Enable(aHeadLineCB.IsChecked());
1983 
1984 	return 0;
1985 }
1986 
1987 /*-----------------30.05.97 07:37-------------------
1988 
1989 --------------------------------------------------*/
DisablePageBreak()1990 void SwTextFlowPage::DisablePageBreak()
1991 {
1992 	bPageBreak = sal_False;
1993 	aPgBrkCB       .Disable();
1994 	aPgBrkRB       .Disable();
1995 	aColBrkRB      .Disable();
1996 	aPgBrkBeforeRB .Disable();
1997 	aPgBrkAfterRB  .Disable();
1998 	aPageCollCB    .Disable();
1999 	aPageCollLB    .Disable();
2000 	aPageNoFT      .Disable();
2001 	aPageNoNF      .Disable();
2002 }
2003 
2004 
2005 
2006