1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #undef SC_DLLIMPLEMENTATION
25 //------------------------------------------------------------------
27 #include "scitems.hxx"
29 #include "tptable.hxx"
32 #include "scresid.hxx"
34 #include "pagedlg.hrc"
36 // =======================================================================
38 void EmptyNumericField::Modify()
40 if( !GetText().isEmpty() )
41 NumericField::Modify();
46 void EmptyNumericField::SetValue( sal_Int64 nValue
)
51 NumericField::SetValue( nValue
);
54 sal_Int64
EmptyNumericField::GetValue() const
56 return IsEmptyFieldValue() ? 0 : NumericField::GetValue();
59 // =======================================================================
61 // STATIC DATA -----------------------------------------------------------
63 static sal_uInt16 pPageTableRanges
[] =
65 ATTR_PAGE_NOTES
, ATTR_PAGE_FIRSTPAGENO
,
69 static sal_Bool
lcl_PutVObjModeItem( sal_uInt16 nWhich
,
71 const SfxItemSet
& rOldSet
,
72 const CheckBox
& rBtn
);
74 static sal_Bool
lcl_PutScaleItem( sal_uInt16 nWhich
,
76 const SfxItemSet
& rOldSet
,
77 const ListBox
& rListBox
,
82 static sal_Bool
lcl_PutScaleItem2( sal_uInt16 nWhich
,
84 const SfxItemSet
& rOldSet
,
85 const ListBox
& rListBox
,
87 const NumericField
& rEd1
,
88 const NumericField
& rEd2
);
90 static sal_Bool
lcl_PutBoolItem( sal_uInt16 nWhich
,
92 const SfxItemSet
& rOldSet
,
94 sal_Bool bSavedValue
);
96 //------------------------------------------------------------------------
98 #define PAGENO_HDL LINK(this,ScTablePage,PageNoHdl)
99 #define PAGEDIR_HDL LINK(this,ScTablePage,PageDirHdl)
100 #define SCALE_HDL LINK(this,ScTablePage,ScaleHdl)
102 #define WAS_DEFAULT(w,s) (SFX_ITEM_DEFAULT==(s).GetItemState((w),sal_True))
103 #define GET_BOOL(sid,set) ((const SfxBoolItem&)((set).Get(GetWhich((sid))))).GetValue()
104 #define GET_USHORT(sid,set) (sal_uInt16)((const SfxUInt16Item&)((set).Get(GetWhich((sid))))).GetValue()
105 #define GET_SHOW(sid,set) ( ScVObjMode( ((const ScViewObjectModeItem&)((set).Get(GetWhich((sid))))).GetValue() ) \
107 // List box entries "Scaling mode"
108 #define SC_TPTABLE_SCALE_PERCENT 0
109 #define SC_TPTABLE_SCALE_TO 1
110 #define SC_TPTABLE_SCALE_TO_PAGES 2
112 //========================================================================
114 ScTablePage::ScTablePage( Window
* pParent
, const SfxItemSet
& rCoreAttrs
) :
116 SfxTabPage( pParent
, "SheetPrintPage","modules/scalc/ui/sheetprintpage.ui", rCoreAttrs
)
118 get(m_pBtnTopDown
,"radioBTN_TOPDOWN");
119 get(m_pBtnLeftRight
,"radioBTN_LEFTRIGHT");
120 get(m_pBmpPageDir
,"imageBMP_PAGEDIR");
121 get(m_pBtnPageNo
,"checkBTN_PAGENO");
122 get(m_pEdPageNo
,"spinED_PAGENO");
124 get(m_pBtnHeaders
,"checkBTN_HEADER");
125 get(m_pBtnGrid
,"checkBTN_GRID");
126 get(m_pBtnNotes
,"checkBTN_NOTES");
127 get(m_pBtnObjects
,"checkBTN_OBJECTS");
128 get(m_pBtnCharts
,"checkBTN_CHARTS");
129 get(m_pBtnDrawings
,"checkBTN_DRAWINGS");
130 get(m_pBtnFormulas
,"checkBTN_FORMULAS");
131 get(m_pBtnNullVals
,"checkBTN_NULLVALS");
133 get(m_pLbScaleMode
,"comboLB_SCALEMODE");
134 get(m_pBxScaleAll
,"boxSCALEALL");
135 get(m_pEdScaleAll
,"spinED_SCALEALL");
136 get(m_pGrHeightWidth
,"gridWH");
137 get(m_pEdScalePageWidth
,"spinED_SCALEPAGEWIDTH");
138 get(m_pEdScalePageHeight
,"spinED_SCALEPAGEHEIGHT");
139 get(m_pBxScalePageNum
,"boxNP");
140 get(m_pEdScalePageNum
,"spinED_SCALEPAGENUM");
142 SetExchangeSupport();
144 m_pBtnPageNo
->SetClickHdl( PAGENO_HDL
);
145 m_pBtnTopDown
->SetClickHdl( PAGEDIR_HDL
);
146 m_pBtnLeftRight
->SetClickHdl( PAGEDIR_HDL
);
147 m_pLbScaleMode
->SetSelectHdl( SCALE_HDL
);
151 // -----------------------------------------------------------------------
153 void ScTablePage::ShowImage()
155 Image aImg
= Image( ScResId( (m_pBtnLeftRight
->IsChecked()) ? IMG_LEFTRIGHT
: IMG_TOPDOWN
) );
156 m_pBmpPageDir
->SetImage( aImg
);
157 m_pBmpPageDir
->SetOutputSizePixel( aImg
.GetSizePixel() );
160 // -----------------------------------------------------------------------
162 ScTablePage::~ScTablePage()
166 //------------------------------------------------------------------------
168 sal_uInt16
* ScTablePage::GetRanges()
170 return pPageTableRanges
;
173 // -----------------------------------------------------------------------
175 SfxTabPage
* ScTablePage::Create( Window
* pParent
, const SfxItemSet
& rCoreSet
)
177 return ( new ScTablePage( pParent
, rCoreSet
) );
180 // -----------------------------------------------------------------------
182 void ScTablePage::Reset( const SfxItemSet
& rCoreSet
)
184 sal_Bool bTopDown
= GET_BOOL( SID_SCATTR_PAGE_TOPDOWN
, rCoreSet
);
185 sal_uInt16 nWhich
= 0;
190 m_pBtnNotes
->Check( GET_BOOL(SID_SCATTR_PAGE_NOTES
,rCoreSet
) );
191 m_pBtnGrid
->Check( GET_BOOL(SID_SCATTR_PAGE_GRID
,rCoreSet
) );
192 m_pBtnHeaders
->Check( GET_BOOL(SID_SCATTR_PAGE_HEADERS
,rCoreSet
) );
193 m_pBtnFormulas
->Check( GET_BOOL(SID_SCATTR_PAGE_FORMULAS
,rCoreSet
) );
194 m_pBtnNullVals
->Check( GET_BOOL(SID_SCATTR_PAGE_NULLVALS
,rCoreSet
) );
195 m_pBtnTopDown
->Check( bTopDown
);
196 m_pBtnLeftRight
->Check( !bTopDown
);
201 sal_uInt16 nPage
= GET_USHORT(SID_SCATTR_PAGE_FIRSTPAGENO
,rCoreSet
);
202 m_pBtnPageNo
->Check( nPage
!= 0 );
203 m_pEdPageNo
->SetValue( (nPage
!= 0) ? nPage
: 1 );
206 //-------------------
207 // Objektdarstellung:
208 //-------------------
209 m_pBtnCharts
->Check( GET_SHOW( SID_SCATTR_PAGE_CHARTS
, rCoreSet
) );
210 m_pBtnObjects
->Check( GET_SHOW( SID_SCATTR_PAGE_OBJECTS
, rCoreSet
) );
211 m_pBtnDrawings
->Check( GET_SHOW( SID_SCATTR_PAGE_DRAWINGS
, rCoreSet
) );
217 nWhich
= GetWhich(SID_SCATTR_PAGE_SCALE
);
218 if ( rCoreSet
.GetItemState( nWhich
, sal_True
) >= SFX_ITEM_AVAILABLE
)
220 sal_uInt16 nScale
= ((const SfxUInt16Item
&)rCoreSet
.Get(nWhich
)).GetValue();
222 m_pLbScaleMode
->SelectEntryPos( SC_TPTABLE_SCALE_PERCENT
);
223 m_pEdScaleAll
->SetValue( (nScale
> 0) ? nScale
: 100 );
226 nWhich
= GetWhich(SID_SCATTR_PAGE_SCALETO
);
227 if ( rCoreSet
.GetItemState( nWhich
, sal_True
) >= SFX_ITEM_AVAILABLE
)
229 const ScPageScaleToItem
& rItem
= static_cast< const ScPageScaleToItem
& >( rCoreSet
.Get( nWhich
) );
230 sal_uInt16 nWidth
= rItem
.GetWidth();
231 sal_uInt16 nHeight
= rItem
.GetHeight();
233 /* width==0 and height==0 is invalid state, used as "not selected".
234 Dialog shows width=height=1 then. */
235 bool bValid
= nWidth
|| nHeight
;
237 m_pLbScaleMode
->SelectEntryPos( SC_TPTABLE_SCALE_TO
);
238 m_pEdScalePageWidth
->SetValue( bValid
? nWidth
: 1 );
239 m_pEdScalePageHeight
->SetValue( bValid
? nHeight
: 1 );
242 nWhich
= GetWhich(SID_SCATTR_PAGE_SCALETOPAGES
);
243 if ( rCoreSet
.GetItemState( nWhich
, sal_True
) >= SFX_ITEM_AVAILABLE
)
245 sal_uInt16 nPages
= ((const SfxUInt16Item
&)rCoreSet
.Get(nWhich
)).GetValue();
247 m_pLbScaleMode
->SelectEntryPos( SC_TPTABLE_SCALE_TO_PAGES
);
248 m_pEdScalePageNum
->SetValue( (nPages
> 0) ? nPages
: 1 );
251 if( m_pLbScaleMode
->GetSelectEntryCount() == 0 )
254 OSL_FAIL( "ScTablePage::Reset - missing scaling item" );
255 m_pLbScaleMode
->SelectEntryPos( SC_TPTABLE_SCALE_PERCENT
);
256 m_pEdScaleAll
->SetValue( 100 );
262 // merken fuer FillItemSet
263 m_pBtnFormulas
->SaveValue();
264 m_pBtnNullVals
->SaveValue();
265 m_pBtnNotes
->SaveValue();
266 m_pBtnGrid
->SaveValue();
267 m_pBtnHeaders
->SaveValue();
268 m_pBtnTopDown
->SaveValue();
269 m_pBtnLeftRight
->SaveValue();
270 m_pLbScaleMode
->SaveValue();
271 m_pBtnCharts
->SaveValue();
272 m_pBtnObjects
->SaveValue();
273 m_pBtnDrawings
->SaveValue();
274 m_pBtnPageNo
->SaveValue();
275 m_pEdPageNo
->SaveValue();
276 m_pEdScaleAll
->SaveValue();
277 m_pEdScalePageWidth
->SaveValue();
278 m_pEdScalePageHeight
->SaveValue();
279 m_pEdScalePageNum
->SaveValue();
282 // -----------------------------------------------------------------------
284 sal_Bool
ScTablePage::FillItemSet( SfxItemSet
& rCoreSet
)
286 const SfxItemSet
& rOldSet
= GetItemSet();
287 sal_uInt16 nWhichPageNo
= GetWhich(SID_SCATTR_PAGE_FIRSTPAGENO
);
288 sal_Bool bDataChanged
= false;
294 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_NOTES
),
296 m_pBtnNotes
->IsChecked(),
297 m_pBtnNotes
->GetSavedValue() != STATE_NOCHECK
);
299 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_GRID
),
301 m_pBtnGrid
->IsChecked(),
302 m_pBtnGrid
->GetSavedValue() != STATE_NOCHECK
);
304 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_HEADERS
),
306 m_pBtnHeaders
->IsChecked(),
307 m_pBtnHeaders
->GetSavedValue() != STATE_NOCHECK
);
309 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_TOPDOWN
),
311 m_pBtnTopDown
->IsChecked(),
312 m_pBtnTopDown
->GetSavedValue() );
314 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_FORMULAS
),
316 m_pBtnFormulas
->IsChecked(),
317 m_pBtnFormulas
->GetSavedValue() != STATE_NOCHECK
);
319 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_NULLVALS
),
321 m_pBtnNullVals
->IsChecked(),
322 m_pBtnNullVals
->GetSavedValue() != STATE_NOCHECK
);
327 sal_Bool bUseValue
= m_pBtnPageNo
->IsChecked();
329 if ( WAS_DEFAULT(nWhichPageNo
,rOldSet
)
330 && ( (!bUseValue
&& bUseValue
== m_pBtnPageNo
->GetSavedValue())
331 || ( bUseValue
&& bUseValue
== m_pBtnPageNo
->GetSavedValue()
332 && m_pEdPageNo
->GetText() == m_pEdPageNo
->GetSavedValue() ) ) )
334 rCoreSet
.ClearItem( nWhichPageNo
);
338 sal_uInt16 nPage
= (sal_uInt16
)( m_pBtnPageNo
->IsChecked()
339 ? m_pEdPageNo
->GetValue()
342 rCoreSet
.Put( SfxUInt16Item( nWhichPageNo
, nPage
) );
343 bDataChanged
= sal_True
;
346 //-------------------
347 // Objektdarstellung:
348 //-------------------
350 bDataChanged
|= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_CHARTS
),
351 rCoreSet
, rOldSet
, *m_pBtnCharts
);
353 bDataChanged
|= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_OBJECTS
),
354 rCoreSet
, rOldSet
, *m_pBtnObjects
);
356 bDataChanged
|= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_DRAWINGS
),
357 rCoreSet
, rOldSet
, *m_pBtnDrawings
);
363 if( !m_pEdScalePageWidth
->GetValue() && !m_pEdScalePageHeight
->GetValue() )
365 m_pLbScaleMode
->SelectEntryPos( SC_TPTABLE_SCALE_PERCENT
);
366 m_pEdScaleAll
->SetValue( 100 );
369 bDataChanged
|= lcl_PutScaleItem( GetWhich(SID_SCATTR_PAGE_SCALE
),
371 *m_pLbScaleMode
, SC_TPTABLE_SCALE_PERCENT
,
372 *m_pEdScaleAll
, (sal_uInt16
)m_pEdScaleAll
->GetValue() );
374 bDataChanged
|= lcl_PutScaleItem2( GetWhich(SID_SCATTR_PAGE_SCALETO
),
376 *m_pLbScaleMode
, SC_TPTABLE_SCALE_TO
,
377 *m_pEdScalePageWidth
, *m_pEdScalePageHeight
);
379 bDataChanged
|= lcl_PutScaleItem( GetWhich(SID_SCATTR_PAGE_SCALETOPAGES
),
381 *m_pLbScaleMode
, SC_TPTABLE_SCALE_TO_PAGES
,
382 *m_pEdScalePageNum
, (sal_uInt16
)m_pEdScalePageNum
->GetValue() );
387 //------------------------------------------------------------------------
389 int ScTablePage::DeactivatePage( SfxItemSet
* pSetP
)
392 FillItemSet( *pSetP
);
397 //------------------------------------------------------------------------
399 void ScTablePage::DataChanged( const DataChangedEvent
& rDCEvt
)
401 if( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
403 SfxTabPage::DataChanged( rDCEvt
);
406 //------------------------------------------------------------------------
408 //------------------------------------------------------------------------
410 IMPL_LINK_NOARG(ScTablePage
, PageDirHdl
)
416 //------------------------------------------------------------------------
418 IMPL_LINK( ScTablePage
, PageNoHdl
, CheckBox
*, pBtn
)
420 if ( m_pBtnPageNo
->IsChecked() )
422 m_pEdPageNo
->Enable();
424 m_pEdPageNo
->GrabFocus();
427 m_pEdPageNo
->Disable();
432 //------------------------------------------------------------------------
434 IMPL_LINK_NOARG(ScTablePage
, ScaleHdl
)
436 // controls for Box "Reduce/enlarge"
437 m_pBxScaleAll
->Show(m_pLbScaleMode
->GetSelectEntryPos() == SC_TPTABLE_SCALE_PERCENT
);
439 // controls for Grid "Scale to width/height"
440 m_pGrHeightWidth
->Show(m_pLbScaleMode
->GetSelectEntryPos() == SC_TPTABLE_SCALE_TO
);
442 // controls for Box "Scale to pages"
443 m_pBxScalePageNum
->Show(m_pLbScaleMode
->GetSelectEntryPos() == SC_TPTABLE_SCALE_TO_PAGES
);
448 //========================================================================
449 // Hilfsfunktionen fuer FillItemSet:
450 //========================================================================
452 static sal_Bool
lcl_PutBoolItem( sal_uInt16 nWhich
,
453 SfxItemSet
& rCoreSet
,
454 const SfxItemSet
& rOldSet
,
456 sal_Bool bSavedValue
)
458 sal_Bool bDataChanged
= ( bSavedValue
== bIsChecked
459 && WAS_DEFAULT(nWhich
,rOldSet
) );
462 rCoreSet
.ClearItem(nWhich
);
464 rCoreSet
.Put( SfxBoolItem( nWhich
, bIsChecked
) );
469 //------------------------------------------------------------------------
471 static sal_Bool
lcl_PutVObjModeItem( sal_uInt16 nWhich
,
472 SfxItemSet
& rCoreSet
,
473 const SfxItemSet
& rOldSet
,
474 const CheckBox
& rBtn
)
476 sal_Bool bIsChecked
= rBtn
.IsChecked();
477 sal_Bool bDataChanged
= ( rBtn
.GetSavedValue() == bIsChecked
478 && WAS_DEFAULT(nWhich
,rOldSet
) );
481 rCoreSet
.ClearItem( nWhich
);
484 rCoreSet
.Put( ScViewObjectModeItem( nWhich
, bIsChecked
486 : VOBJ_MODE_HIDE
) );
490 //------------------------------------------------------------------------
492 static sal_Bool
lcl_PutScaleItem( sal_uInt16 nWhich
,
493 SfxItemSet
& rCoreSet
,
494 const SfxItemSet
& rOldSet
,
495 const ListBox
& rListBox
,
497 const SpinField
& rEd
,
500 sal_Bool bIsSel
= (rListBox
.GetSelectEntryPos() == nLBEntry
);
501 sal_Bool bDataChanged
= (rListBox
.GetSavedValue() != nLBEntry
) ||
502 (rEd
.GetSavedValue() != rEd
.GetText()) ||
503 !WAS_DEFAULT( nWhich
, rOldSet
);
506 rCoreSet
.Put( SfxUInt16Item( nWhich
, bIsSel
? nValue
: 0 ) );
508 rCoreSet
.ClearItem( nWhich
);
514 static sal_Bool
lcl_PutScaleItem2( sal_uInt16 nWhich
,
515 SfxItemSet
& rCoreSet
,
516 const SfxItemSet
& rOldSet
,
517 const ListBox
& rListBox
,
519 const NumericField
& rEd1
,
520 const NumericField
& rEd2
)
522 sal_uInt16 nValue1
= (sal_uInt16
)rEd1
.GetValue();
523 sal_uInt16 nValue2
= (sal_uInt16
)rEd2
.GetValue();
524 sal_Bool bIsSel
= (rListBox
.GetSelectEntryPos() == nLBEntry
);
525 sal_Bool bDataChanged
= (rListBox
.GetSavedValue() != nLBEntry
) ||
526 (rEd1
.GetSavedValue() != rEd1
.GetText()) ||
527 (rEd2
.GetSavedValue() != rEd2
.GetText()) ||
528 !WAS_DEFAULT( nWhich
, rOldSet
);
532 ScPageScaleToItem aItem
;
534 aItem
.Set( nValue1
, nValue2
);
535 rCoreSet
.Put( aItem
);
538 rCoreSet
.ClearItem( nWhich
);
545 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */