merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / pagedlg / tptable.cxx
blobb33dd06bb054073bc1f7fcb007d7cdb4f7396f09
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tptable.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 //------------------------------------------------------------------
40 #include "scitems.hxx"
42 #include "tptable.hxx"
43 #include "global.hxx"
44 #include "attrib.hxx"
45 #include "scresid.hxx"
46 #include "sc.hrc"
47 #include "pagedlg.hrc"
49 // =======================================================================
51 void EmptyNumericField::Modify()
53 if( GetText().Len() )
54 NumericField::Modify();
55 else
56 SetEmptyFieldValue();
59 void EmptyNumericField::SetValue( sal_Int64 nValue )
61 if( nValue == 0 )
62 SetEmptyFieldValue();
63 else
64 NumericField::SetValue( nValue );
67 sal_Int64 EmptyNumericField::GetValue() const
69 return IsEmptyFieldValue() ? 0 : NumericField::GetValue();
72 // =======================================================================
74 // STATIC DATA -----------------------------------------------------------
76 static USHORT pPageTableRanges[] =
78 ATTR_PAGE_NOTES, ATTR_PAGE_FIRSTPAGENO,
82 BOOL lcl_PutVObjModeItem( USHORT nWhich,
83 SfxItemSet& rCoreSet,
84 const SfxItemSet& rOldSet,
85 const CheckBox& rBtn );
87 BOOL lcl_PutScaleItem( USHORT nWhich,
88 SfxItemSet& rCoreSet,
89 const SfxItemSet& rOldSet,
90 const ListBox& rListBox,
91 USHORT nLBEntry,
92 const SpinField& rEd,
93 UINT16 nValue );
95 BOOL lcl_PutScaleItem2( USHORT nWhich,
96 SfxItemSet& rCoreSet,
97 const SfxItemSet& rOldSet,
98 const ListBox& rListBox,
99 USHORT nLBEntry,
100 const NumericField& rEd1,
101 const NumericField& rEd2 );
103 BOOL lcl_PutBoolItem( USHORT nWhich,
104 SfxItemSet& rCoreSet,
105 const SfxItemSet& rOldSet,
106 BOOL bIsChecked,
107 BOOL bSavedValue );
109 //------------------------------------------------------------------------
111 #define PAGENO_HDL LINK(this,ScTablePage,PageNoHdl)
112 #define PAGEDIR_HDL LINK(this,ScTablePage,PageDirHdl)
113 #define SCALE_HDL LINK(this,ScTablePage,ScaleHdl)
115 #define WAS_DEFAULT(w,s) (SFX_ITEM_DEFAULT==(s).GetItemState((w),TRUE))
116 #define GET_BOOL(sid,set) ((const SfxBoolItem&)((set).Get(GetWhich((sid))))).GetValue()
117 #define GET_USHORT(sid,set) (USHORT)((const SfxUInt16Item&)((set).Get(GetWhich((sid))))).GetValue()
118 #define GET_SHOW(sid,set) ( ScVObjMode( ((const ScViewObjectModeItem&)((set).Get(GetWhich((sid))))).GetValue() ) \
119 == VOBJ_MODE_SHOW )
121 //========================================================================
123 ScTablePage::ScTablePage( Window* pParent, const SfxItemSet& rCoreAttrs ) :
125 SfxTabPage( pParent, ScResId( RID_SCPAGE_TABLE ), rCoreAttrs ),
127 aFlPageDir ( this, ScResId( FL_PAGEDIR ) ),
128 aBtnTopDown ( this, ScResId( BTN_TOPDOWN ) ),
129 aBtnLeftRight ( this, ScResId( BTN_LEFTRIGHT ) ),
130 aBmpPageDir ( this, ScResId( BMP_PAGEDIR ) ),
131 aImgLeftRight ( ScResId( IMG_LEFTRIGHT ) ),
132 aImgTopDown ( ScResId( IMG_TOPDOWN ) ),
133 aImgLeftRightHC ( ScResId( IMG_LEFTRIGHT_H ) ),
134 aImgTopDownHC ( ScResId( IMG_TOPDOWN_H ) ),
135 aBtnPageNo ( this, ScResId( BTN_PAGENO ) ),
136 aEdPageNo ( this, ScResId( ED_PAGENO ) ),
137 aFlPrint ( this, ScResId( FL_PRINT ) ),
138 aBtnHeaders ( this, ScResId( BTN_HEADER ) ),
139 aBtnGrid ( this, ScResId( BTN_GRID ) ),
140 aBtnNotes ( this, ScResId( BTN_NOTES ) ),
141 aBtnObjects ( this, ScResId( BTN_OBJECTS ) ),
142 aBtnCharts ( this, ScResId( BTN_CHARTS ) ),
143 aBtnDrawings ( this, ScResId( BTN_DRAWINGS ) ),
144 aBtnFormulas ( this, ScResId( BTN_FORMULAS ) ),
145 aBtnNullVals ( this, ScResId( BTN_NULLVALS ) ),
146 aFlScale ( this, ScResId( FL_SCALE ) ),
147 aFtScaleMode ( this, ScResId( FT_SCALEMODE ) ),
148 aLbScaleMode ( this, ScResId( LB_SCALEMODE ) ),
149 aFtScaleAll ( this, ScResId( FT_SCALEFACTOR ) ),
150 aEdScaleAll ( this, ScResId( ED_SCALEALL ) ),
151 aFtScalePageWidth ( this, ScResId( FT_SCALEPAGEWIDTH ) ),
152 aEdScalePageWidth ( this, ScResId( ED_SCALEPAGEWIDTH ) ),
153 aFtScalePageHeight ( this, ScResId( FT_SCALEPAGEHEIGHT ) ),
154 aEdScalePageHeight ( this, ScResId( ED_SCALEPAGEHEIGHT ) ),
155 aFtScalePageNum ( this, ScResId( FT_SCALEPAGENUM ) ),
156 aEdScalePageNum ( this, ScResId( ED_SCALEPAGENUM ) )
158 SetExchangeSupport();
159 aBtnPageNo.SetClickHdl( PAGENO_HDL );
160 aBtnTopDown.SetClickHdl( PAGEDIR_HDL );
161 aBtnLeftRight.SetClickHdl( PAGEDIR_HDL );
162 aLbScaleMode.SetSelectHdl( SCALE_HDL );
164 Size aBmpSize = Image( ScResId( IMG_LEFTRIGHT ) ).GetSizePixel();
165 aBmpPageDir.SetOutputSizePixel( aBmpSize );
167 FreeResource();
170 // -----------------------------------------------------------------------
172 void ScTablePage::ShowImage()
174 bool bDark = GetDisplayBackground().GetColor().IsDark();
175 bool bLeftRight = aBtnLeftRight.IsChecked();
176 aBmpPageDir.SetImage( bDark ?
177 (bLeftRight ? aImgLeftRightHC : aImgTopDownHC) :
178 (bLeftRight ? aImgLeftRight : aImgTopDown) );
181 // -----------------------------------------------------------------------
183 ScTablePage::~ScTablePage()
187 //------------------------------------------------------------------------
189 USHORT* ScTablePage::GetRanges()
191 return pPageTableRanges;
194 // -----------------------------------------------------------------------
196 SfxTabPage* ScTablePage::Create( Window* pParent, const SfxItemSet& rCoreSet )
198 return ( new ScTablePage( pParent, rCoreSet ) );
201 // -----------------------------------------------------------------------
203 void ScTablePage::Reset( const SfxItemSet& rCoreSet )
205 BOOL bTopDown = GET_BOOL( SID_SCATTR_PAGE_TOPDOWN, rCoreSet );
206 USHORT nWhich = 0;
208 //-----------
209 // BOOL-Flags
210 //-----------
211 aBtnNotes .Check( GET_BOOL(SID_SCATTR_PAGE_NOTES,rCoreSet) );
212 aBtnGrid .Check( GET_BOOL(SID_SCATTR_PAGE_GRID,rCoreSet) );
213 aBtnHeaders .Check( GET_BOOL(SID_SCATTR_PAGE_HEADERS,rCoreSet) );
214 aBtnFormulas .Check( GET_BOOL(SID_SCATTR_PAGE_FORMULAS,rCoreSet) );
215 aBtnNullVals .Check( GET_BOOL(SID_SCATTR_PAGE_NULLVALS,rCoreSet) );
216 aBtnTopDown .Check( bTopDown );
217 aBtnLeftRight .Check( !bTopDown );
219 //------------------
220 // Erste Druckseite:
221 //------------------
222 USHORT nPage = GET_USHORT(SID_SCATTR_PAGE_FIRSTPAGENO,rCoreSet);
223 aBtnPageNo.Check( nPage != 0 );
224 aEdPageNo.SetValue( (nPage != 0) ? nPage : 1 );
225 PageNoHdl( NULL );
227 //-------------------
228 // Objektdarstellung:
229 //-------------------
230 aBtnCharts .Check( GET_SHOW( SID_SCATTR_PAGE_CHARTS, rCoreSet ) );
231 aBtnObjects .Check( GET_SHOW( SID_SCATTR_PAGE_OBJECTS, rCoreSet ) );
232 aBtnDrawings .Check( GET_SHOW( SID_SCATTR_PAGE_DRAWINGS, rCoreSet ) );
234 //------------
235 // Skalierung:
236 //------------
238 nWhich = GetWhich(SID_SCATTR_PAGE_SCALE);
239 if ( rCoreSet.GetItemState( nWhich, TRUE ) >= SFX_ITEM_AVAILABLE )
241 USHORT nScale = ((const SfxUInt16Item&)rCoreSet.Get(nWhich)).GetValue();
242 if( nScale > 0 )
243 aLbScaleMode.SelectEntryPos( SC_TPTABLE_SCALE_PERCENT );
244 aEdScaleAll.SetValue( (nScale > 0) ? nScale : 100 );
247 nWhich = GetWhich(SID_SCATTR_PAGE_SCALETO);
248 if ( rCoreSet.GetItemState( nWhich, TRUE ) >= SFX_ITEM_AVAILABLE )
250 const ScPageScaleToItem& rItem = static_cast< const ScPageScaleToItem& >( rCoreSet.Get( nWhich ) );
251 USHORT nWidth = rItem.GetWidth();
252 USHORT nHeight = rItem.GetHeight();
254 /* width==0 and height==0 is invalid state, used as "not selected".
255 Dialog shows width=height=1 then. */
256 bool bValid = nWidth || nHeight;
257 if( bValid )
258 aLbScaleMode.SelectEntryPos( SC_TPTABLE_SCALE_TO );
259 aEdScalePageWidth.SetValue( bValid ? nWidth : 1 );
260 aEdScalePageHeight.SetValue( bValid ? nHeight : 1 );
263 nWhich = GetWhich(SID_SCATTR_PAGE_SCALETOPAGES);
264 if ( rCoreSet.GetItemState( nWhich, TRUE ) >= SFX_ITEM_AVAILABLE )
266 USHORT nPages = ((const SfxUInt16Item&)rCoreSet.Get(nWhich)).GetValue();
267 if( nPages > 0 )
268 aLbScaleMode.SelectEntryPos( SC_TPTABLE_SCALE_TO_PAGES );
269 aEdScalePageNum.SetValue( (nPages > 0) ? nPages : 1 );
272 if( aLbScaleMode.GetSelectEntryCount() == 0 )
274 // fall back to 100%
275 DBG_ERRORFILE( "ScTablePage::Reset - missing scaling item" );
276 aLbScaleMode.SelectEntryPos( SC_TPTABLE_SCALE_PERCENT );
277 aEdScaleAll.SetValue( 100 );
280 PageDirHdl( NULL );
281 ScaleHdl( NULL );
283 // merken fuer FillItemSet
284 aBtnFormulas .SaveValue();
285 aBtnNullVals .SaveValue();
286 aBtnNotes .SaveValue();
287 aBtnGrid .SaveValue();
288 aBtnHeaders .SaveValue();
289 aBtnTopDown .SaveValue();
290 aBtnLeftRight .SaveValue();
291 aLbScaleMode .SaveValue();
292 aBtnCharts .SaveValue();
293 aBtnObjects .SaveValue();
294 aBtnDrawings .SaveValue();
295 aBtnPageNo .SaveValue();
296 aEdPageNo .SaveValue();
297 aEdScaleAll .SaveValue();
298 aEdScalePageWidth.SaveValue();
299 aEdScalePageHeight.SaveValue();
300 aEdScalePageNum .SaveValue();
303 // -----------------------------------------------------------------------
305 BOOL ScTablePage::FillItemSet( SfxItemSet& rCoreSet )
307 const SfxItemSet& rOldSet = GetItemSet();
308 USHORT nWhichPageNo = GetWhich(SID_SCATTR_PAGE_FIRSTPAGENO);
309 BOOL bDataChanged = FALSE;
311 //-----------
312 // BOOL-Flags
313 //-----------
315 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_NOTES),
316 rCoreSet, rOldSet,
317 aBtnNotes.IsChecked(),
318 aBtnNotes.GetSavedValue() != STATE_NOCHECK );
320 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_GRID),
321 rCoreSet, rOldSet,
322 aBtnGrid.IsChecked(),
323 aBtnGrid.GetSavedValue() != STATE_NOCHECK );
325 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_HEADERS),
326 rCoreSet, rOldSet,
327 aBtnHeaders.IsChecked(),
328 aBtnHeaders.GetSavedValue() != STATE_NOCHECK );
330 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_TOPDOWN),
331 rCoreSet, rOldSet,
332 aBtnTopDown.IsChecked(),
333 aBtnTopDown.GetSavedValue() );
335 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_FORMULAS),
336 rCoreSet, rOldSet,
337 aBtnFormulas.IsChecked(),
338 aBtnFormulas.GetSavedValue() != STATE_NOCHECK );
340 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_NULLVALS),
341 rCoreSet, rOldSet,
342 aBtnNullVals.IsChecked(),
343 aBtnNullVals.GetSavedValue() != STATE_NOCHECK );
345 //------------------
346 // Erste Druckseite:
347 //------------------
348 BOOL bUseValue = aBtnPageNo.IsChecked();
350 if ( WAS_DEFAULT(nWhichPageNo,rOldSet)
351 && ( (!bUseValue && bUseValue == aBtnPageNo.GetSavedValue())
352 || ( bUseValue && bUseValue == aBtnPageNo.GetSavedValue()
353 && aEdPageNo.GetText() == aEdPageNo.GetSavedValue() ) ) )
355 rCoreSet.ClearItem( nWhichPageNo );
357 else
359 UINT16 nPage = (UINT16)( aBtnPageNo.IsChecked()
360 ? aEdPageNo.GetValue()
361 : 0 );
363 rCoreSet.Put( SfxUInt16Item( nWhichPageNo, nPage ) );
364 bDataChanged = TRUE;
367 //-------------------
368 // Objektdarstellung:
369 //-------------------
371 bDataChanged |= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_CHARTS),
372 rCoreSet, rOldSet, aBtnCharts );
374 bDataChanged |= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_OBJECTS),
375 rCoreSet, rOldSet, aBtnObjects );
377 bDataChanged |= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_DRAWINGS),
378 rCoreSet, rOldSet, aBtnDrawings );
380 //------------
381 // Skalierung:
382 //------------
384 if( !aEdScalePageWidth.GetValue() && !aEdScalePageHeight.GetValue() )
386 aLbScaleMode.SelectEntryPos( SC_TPTABLE_SCALE_PERCENT );
387 aEdScaleAll.SetValue( 100 );
390 bDataChanged |= lcl_PutScaleItem( GetWhich(SID_SCATTR_PAGE_SCALE),
391 rCoreSet, rOldSet,
392 aLbScaleMode, SC_TPTABLE_SCALE_PERCENT,
393 aEdScaleAll, (UINT16)aEdScaleAll.GetValue() );
395 bDataChanged |= lcl_PutScaleItem2( GetWhich(SID_SCATTR_PAGE_SCALETO),
396 rCoreSet, rOldSet,
397 aLbScaleMode, SC_TPTABLE_SCALE_TO,
398 aEdScalePageWidth, aEdScalePageHeight );
400 bDataChanged |= lcl_PutScaleItem( GetWhich(SID_SCATTR_PAGE_SCALETOPAGES),
401 rCoreSet, rOldSet,
402 aLbScaleMode, SC_TPTABLE_SCALE_TO_PAGES,
403 aEdScalePageNum, (UINT16)aEdScalePageNum.GetValue() );
405 return bDataChanged;
408 //------------------------------------------------------------------------
410 int ScTablePage::DeactivatePage( SfxItemSet* pSetP )
412 if ( pSetP )
413 FillItemSet( *pSetP );
415 return LEAVE_PAGE;
418 //------------------------------------------------------------------------
420 void ScTablePage::DataChanged( const DataChangedEvent& rDCEvt )
422 if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
423 ShowImage();
424 SfxTabPage::DataChanged( rDCEvt );
427 //------------------------------------------------------------------------
428 // Handler:
429 //------------------------------------------------------------------------
431 IMPL_LINK( ScTablePage, PageDirHdl, RadioButton*, EMPTYARG )
433 ShowImage();
434 return 0;
437 //------------------------------------------------------------------------
439 IMPL_LINK( ScTablePage, PageNoHdl, CheckBox*, pBtn )
441 if ( aBtnPageNo.IsChecked() )
443 aEdPageNo.Enable();
444 if ( pBtn )
445 aEdPageNo.GrabFocus();
447 else
448 aEdPageNo.Disable();
450 return 0;
453 //------------------------------------------------------------------------
455 IMPL_LINK( ScTablePage, ScaleHdl, ListBox*, EMPTYARG )
457 // controls for "Reduce/enlarge"
458 bool bPercent = (aLbScaleMode.GetSelectEntryPos() == SC_TPTABLE_SCALE_PERCENT);
459 aFtScaleAll.Show( bPercent );
460 aEdScaleAll.Show( bPercent );
462 // controls for "Scale to width/height"
463 bool bScaleTo = (aLbScaleMode.GetSelectEntryPos() == SC_TPTABLE_SCALE_TO);
464 aFtScalePageWidth.Show( bScaleTo );
465 aEdScalePageWidth.Show( bScaleTo );
466 aFtScalePageHeight.Show( bScaleTo );
467 aEdScalePageHeight.Show( bScaleTo );
469 // controls for "Scale to pages"
470 bool bScalePages = (aLbScaleMode.GetSelectEntryPos() == SC_TPTABLE_SCALE_TO_PAGES);
471 aFtScalePageNum.Show( bScalePages );
472 aEdScalePageNum.Show( bScalePages );
474 return 0;
477 //========================================================================
478 // Hilfsfunktionen fuer FillItemSet:
479 //========================================================================
481 BOOL lcl_PutBoolItem( USHORT nWhich,
482 SfxItemSet& rCoreSet,
483 const SfxItemSet& rOldSet,
484 BOOL bIsChecked,
485 BOOL bSavedValue )
487 BOOL bDataChanged = ( bSavedValue == bIsChecked
488 && WAS_DEFAULT(nWhich,rOldSet) );
490 if ( bDataChanged )
491 rCoreSet.ClearItem(nWhich);
492 else
493 rCoreSet.Put( SfxBoolItem( nWhich, bIsChecked ) );
495 return bDataChanged;
498 //------------------------------------------------------------------------
500 BOOL lcl_PutVObjModeItem( USHORT nWhich,
501 SfxItemSet& rCoreSet,
502 const SfxItemSet& rOldSet,
503 const CheckBox& rBtn )
505 BOOL bIsChecked = rBtn.IsChecked();
506 BOOL bDataChanged = ( rBtn.GetSavedValue() == bIsChecked
507 && WAS_DEFAULT(nWhich,rOldSet) );
509 if ( bDataChanged )
510 rCoreSet.ClearItem( nWhich );
512 else
513 rCoreSet.Put( ScViewObjectModeItem( nWhich, bIsChecked
514 ? VOBJ_MODE_SHOW
515 : VOBJ_MODE_HIDE ) );
516 return bDataChanged;
519 //------------------------------------------------------------------------
521 BOOL lcl_PutScaleItem( USHORT nWhich,
522 SfxItemSet& rCoreSet,
523 const SfxItemSet& rOldSet,
524 const ListBox& rListBox,
525 USHORT nLBEntry,
526 const SpinField& rEd,
527 UINT16 nValue )
529 BOOL bIsSel = (rListBox.GetSelectEntryPos() == nLBEntry);
530 BOOL bDataChanged = (rListBox.GetSavedValue() != nLBEntry) ||
531 (rEd.GetSavedValue() != rEd.GetText()) ||
532 !WAS_DEFAULT( nWhich, rOldSet );
534 if( bDataChanged )
535 rCoreSet.Put( SfxUInt16Item( nWhich, bIsSel ? nValue : 0 ) );
536 else
537 rCoreSet.ClearItem( nWhich );
539 return bDataChanged;
543 BOOL lcl_PutScaleItem2( USHORT nWhich,
544 SfxItemSet& rCoreSet,
545 const SfxItemSet& rOldSet,
546 const ListBox& rListBox,
547 USHORT nLBEntry,
548 const NumericField& rEd1,
549 const NumericField& rEd2 )
551 UINT16 nValue1 = (UINT16)rEd1.GetValue();
552 UINT16 nValue2 = (UINT16)rEd2.GetValue();
553 BOOL bIsSel = (rListBox.GetSelectEntryPos() == nLBEntry);
554 BOOL bDataChanged = (rListBox.GetSavedValue() != nLBEntry) ||
555 (rEd1.GetSavedValue() != rEd1.GetText()) ||
556 (rEd2.GetSavedValue() != rEd2.GetText()) ||
557 !WAS_DEFAULT( nWhich, rOldSet );
559 if( bDataChanged )
561 ScPageScaleToItem aItem;
562 if( bIsSel )
563 aItem.Set( nValue1, nValue2 );
564 rCoreSet.Put( aItem );
566 else
567 rCoreSet.ClearItem( nWhich );
569 return bDataChanged;