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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include <scitems.hxx>
24 #include <vcl/event.hxx>
25 #include <vcl/settings.hxx>
26 #include <osl/diagnose.h>
28 #include <tptable.hxx>
31 #include <bitmaps.hlst>
35 const sal_uInt16
ScTablePage::pPageTableRanges
[] =
37 ATTR_PAGE_NOTES
, ATTR_PAGE_FIRSTPAGENO
,
41 static bool lcl_PutVObjModeItem(sal_uInt16 nWhich
,
43 const SfxItemSet
& rOldSet
,
44 const weld::ToggleButton
& rBtn
);
46 static bool lcl_PutScaleItem( sal_uInt16 nWhich
,
48 const SfxItemSet
& rOldSet
,
49 const weld::ComboBox
& rListBox
,
51 const weld::MetricSpinButton
& rEd
,
54 static bool lcl_PutScaleItem2( sal_uInt16 nWhich
,
56 const SfxItemSet
& rOldSet
,
57 const weld::ComboBox
& rListBox
,
59 const weld::SpinButton
& rEd1
,
60 sal_uInt16 nOrigScalePageWidth
,
61 const weld::SpinButton
& rEd2
,
62 sal_uInt16 nOrigScalePageHeight
);
64 static bool lcl_PutScaleItem3( sal_uInt16 nWhich
,
66 const SfxItemSet
& rOldSet
,
67 const weld::ComboBox
& rListBox
,
69 const weld::SpinButton
& rEd
,
72 static bool lcl_PutBoolItem( sal_uInt16 nWhich
,
74 const SfxItemSet
& rOldSet
,
78 #define PAGENO_HDL LINK(this,ScTablePage,PageNoHdl)
79 #define PAGEDIR_HDL LINK(this,ScTablePage,PageDirHdl)
83 bool WAS_DEFAULT(sal_uInt16 w
, SfxItemSet
const & s
)
84 { return SfxItemState::DEFAULT
==s
.GetItemState(w
); }
88 #define GET_BOOL(sid,set) static_cast<const SfxBoolItem&>((set).Get(GetWhich((sid)))).GetValue()
89 #define GET_USHORT(sid,set) static_cast<const SfxUInt16Item&>((set).Get(GetWhich((sid)))).GetValue()
90 #define GET_SHOW(sid,set) ( static_cast<const ScViewObjectModeItem&>((set).Get(GetWhich((sid)))).GetValue() \
92 // List box entries "Scaling mode"
93 #define SC_TPTABLE_SCALE_PERCENT 0
94 #define SC_TPTABLE_SCALE_TO 1
95 #define SC_TPTABLE_SCALE_TO_PAGES 2
97 ScTablePage::ScTablePage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rCoreAttrs
)
98 : SfxTabPage(pPage
, pController
, "modules/scalc/ui/sheetprintpage.ui", "SheetPrintPage", &rCoreAttrs
)
99 , m_nOrigScalePageWidth(0)
100 , m_nOrigScalePageHeight(0)
101 , m_xBtnTopDown(m_xBuilder
->weld_radio_button("radioBTN_TOPDOWN"))
102 , m_xBtnLeftRight(m_xBuilder
->weld_radio_button("radioBTN_LEFTRIGHT"))
103 , m_xBmpPageDir(m_xBuilder
->weld_image("imageBMP_PAGEDIR"))
104 , m_xBtnPageNo(m_xBuilder
->weld_check_button("checkBTN_PAGENO"))
105 , m_xEdPageNo(m_xBuilder
->weld_spin_button("spinED_PAGENO"))
106 , m_xBtnHeaders(m_xBuilder
->weld_check_button("checkBTN_HEADER"))
107 , m_xBtnGrid(m_xBuilder
->weld_check_button("checkBTN_GRID"))
108 , m_xBtnNotes(m_xBuilder
->weld_check_button("checkBTN_NOTES"))
109 , m_xBtnObjects(m_xBuilder
->weld_check_button("checkBTN_OBJECTS"))
110 , m_xBtnCharts(m_xBuilder
->weld_check_button("checkBTN_CHARTS"))
111 , m_xBtnDrawings(m_xBuilder
->weld_check_button("checkBTN_DRAWINGS"))
112 , m_xBtnFormulas(m_xBuilder
->weld_check_button("checkBTN_FORMULAS"))
113 , m_xBtnNullVals(m_xBuilder
->weld_check_button("checkBTN_NULLVALS"))
114 , m_xLbScaleMode(m_xBuilder
->weld_combo_box("comboLB_SCALEMODE"))
115 , m_xBxScaleAll(m_xBuilder
->weld_widget("boxSCALEALL"))
116 , m_xEdScaleAll(m_xBuilder
->weld_metric_spin_button("spinED_SCALEALL", FieldUnit::PERCENT
))
117 , m_xGrHeightWidth(m_xBuilder
->weld_widget("gridWH"))
118 , m_xEdScalePageWidth(m_xBuilder
->weld_spin_button("spinED_SCALEPAGEWIDTH"))
119 , m_xCbScalePageWidth(m_xBuilder
->weld_check_button("labelWP"))
120 , m_xEdScalePageHeight(m_xBuilder
->weld_spin_button("spinED_SCALEPAGEHEIGHT"))
121 , m_xCbScalePageHeight(m_xBuilder
->weld_check_button("labelHP"))
122 , m_xBxScalePageNum(m_xBuilder
->weld_widget("boxNP"))
123 , m_xEdScalePageNum(m_xBuilder
->weld_spin_button("spinED_SCALEPAGENUM"))
125 SetExchangeSupport();
127 m_xBtnPageNo
->connect_toggled(PAGENO_HDL
);
128 m_xBtnTopDown
->connect_toggled(PAGEDIR_HDL
);
129 m_xBtnLeftRight
->connect_toggled(PAGEDIR_HDL
);
130 m_xLbScaleMode
->connect_changed(LINK(this,ScTablePage
,ScaleHdl
));
131 m_xCbScalePageWidth
->connect_toggled(LINK(this, ScTablePage
, ToggleHdl
));
132 m_xCbScalePageHeight
->connect_toggled(LINK(this, ScTablePage
, ToggleHdl
));
135 void ScTablePage::ShowImage()
137 OUString
aImg(m_xBtnLeftRight
->get_active() ? OUString(BMP_LEFTRIGHT
) : OUString(BMP_TOPDOWN
));
138 m_xBmpPageDir
->set_from_icon_name(aImg
);
141 ScTablePage::~ScTablePage()
145 std::unique_ptr
<SfxTabPage
> ScTablePage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rCoreSet
)
147 return std::make_unique
<ScTablePage
>(pPage
, pController
, *rCoreSet
);
150 void ScTablePage::Reset( const SfxItemSet
* rCoreSet
)
152 bool bTopDown
= GET_BOOL( SID_SCATTR_PAGE_TOPDOWN
, *rCoreSet
);
153 sal_uInt16 nWhich
= 0;
156 m_xBtnNotes
->set_active( GET_BOOL(SID_SCATTR_PAGE_NOTES
,*rCoreSet
) );
157 m_xBtnGrid
->set_active( GET_BOOL(SID_SCATTR_PAGE_GRID
,*rCoreSet
) );
158 m_xBtnHeaders
->set_active( GET_BOOL(SID_SCATTR_PAGE_HEADERS
,*rCoreSet
) );
159 m_xBtnFormulas
->set_active( GET_BOOL(SID_SCATTR_PAGE_FORMULAS
,*rCoreSet
) );
160 m_xBtnNullVals
->set_active( GET_BOOL(SID_SCATTR_PAGE_NULLVALS
,*rCoreSet
) );
161 m_xBtnTopDown
->set_active( bTopDown
);
162 m_xBtnLeftRight
->set_active( !bTopDown
);
164 // first printed page:
165 sal_uInt16 nPage
= GET_USHORT(SID_SCATTR_PAGE_FIRSTPAGENO
,*rCoreSet
);
166 m_xBtnPageNo
->set_active( nPage
!= 0 );
167 m_xEdPageNo
->set_value( (nPage
!= 0) ? nPage
: 1 );
170 // object representation:
171 m_xBtnCharts
->set_active( GET_SHOW( SID_SCATTR_PAGE_CHARTS
, *rCoreSet
) );
172 m_xBtnObjects
->set_active( GET_SHOW( SID_SCATTR_PAGE_OBJECTS
, *rCoreSet
) );
173 m_xBtnDrawings
->set_active( GET_SHOW( SID_SCATTR_PAGE_DRAWINGS
, *rCoreSet
) );
176 nWhich
= GetWhich(SID_SCATTR_PAGE_SCALE
);
177 if ( rCoreSet
->GetItemState( nWhich
) >= SfxItemState::DEFAULT
)
179 sal_uInt16 nScale
= static_cast<const SfxUInt16Item
&>(rCoreSet
->Get(nWhich
)).GetValue();
181 m_xLbScaleMode
->set_active(SC_TPTABLE_SCALE_PERCENT
);
182 m_xEdScaleAll
->set_value((nScale
> 0) ? nScale
: 100, FieldUnit::PERCENT
);
185 nWhich
= GetWhich(SID_SCATTR_PAGE_SCALETO
);
186 if ( rCoreSet
->GetItemState( nWhich
) >= SfxItemState::DEFAULT
)
188 const ScPageScaleToItem
& rItem
= static_cast< const ScPageScaleToItem
& >( rCoreSet
->Get( nWhich
) );
189 sal_uInt16 nWidth
= rItem
.GetWidth();
190 sal_uInt16 nHeight
= rItem
.GetHeight();
192 /* width==0 and height==0 is invalid state, used as "not selected".
193 Dialog shows width=height=1 then. */
194 if (nWidth
|| nHeight
)
195 m_xLbScaleMode
->set_active(SC_TPTABLE_SCALE_TO
);
197 nWidth
= nHeight
= 1;
200 m_xEdScalePageWidth
->set_value(nWidth
);
202 m_xEdScalePageWidth
->set_text(OUString());
204 m_xEdScalePageWidth
->set_sensitive(nWidth
!= 0);
205 m_xCbScalePageWidth
->set_active(nWidth
!= 0);
208 m_xEdScalePageHeight
->set_value(nHeight
);
210 m_xEdScalePageHeight
->set_text(OUString());
212 m_xEdScalePageHeight
->set_sensitive(nHeight
!= 0);
213 m_xCbScalePageHeight
->set_active(nHeight
!= 0);
216 nWhich
= GetWhich(SID_SCATTR_PAGE_SCALETOPAGES
);
217 if ( rCoreSet
->GetItemState( nWhich
) >= SfxItemState::DEFAULT
)
219 sal_uInt16 nPages
= static_cast<const SfxUInt16Item
&>(rCoreSet
->Get(nWhich
)).GetValue();
221 m_xLbScaleMode
->set_active(SC_TPTABLE_SCALE_TO_PAGES
);
222 m_xEdScalePageNum
->set_value( (nPages
> 0) ? nPages
: 1 );
225 if (m_xLbScaleMode
->get_active() == -1)
228 OSL_FAIL( "ScTablePage::Reset - missing scaling item" );
229 m_xLbScaleMode
->set_active(SC_TPTABLE_SCALE_PERCENT
);
230 m_xEdScaleAll
->set_value(100, FieldUnit::PERCENT
);
233 PageDirHdl(*m_xBtnTopDown
);
234 ScaleHdl(*m_xLbScaleMode
);
236 // remember for FillItemSet
237 m_xBtnFormulas
->save_state();
238 m_xBtnNullVals
->save_state();
239 m_xBtnNotes
->save_state();
240 m_xBtnGrid
->save_state();
241 m_xBtnHeaders
->save_state();
242 m_xBtnTopDown
->save_state();
243 m_xBtnLeftRight
->save_state();
244 m_xLbScaleMode
->save_value();
245 m_xBtnCharts
->save_state();
246 m_xBtnObjects
->save_state();
247 m_xBtnDrawings
->save_state();
248 m_xBtnPageNo
->save_state();
249 m_xEdPageNo
->save_value();
250 m_xEdScaleAll
->save_value();
251 m_nOrigScalePageWidth
= m_xEdScalePageWidth
->get_sensitive() ? m_xEdScalePageWidth
->get_value() : 0;
252 m_nOrigScalePageHeight
= m_xEdScalePageHeight
->get_sensitive() ? m_xEdScalePageHeight
->get_value() : 0;
253 m_xEdScalePageNum
->save_value();
256 bool ScTablePage::FillItemSet( SfxItemSet
* rCoreSet
)
258 const SfxItemSet
& rOldSet
= GetItemSet();
259 sal_uInt16 nWhichPageNo
= GetWhich(SID_SCATTR_PAGE_FIRSTPAGENO
);
260 bool bDataChanged
= false;
263 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_NOTES
),
265 m_xBtnNotes
->get_active(),
266 m_xBtnNotes
->get_saved_state() != TRISTATE_FALSE
);
268 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_GRID
),
270 m_xBtnGrid
->get_active(),
271 m_xBtnGrid
->get_saved_state() != TRISTATE_FALSE
);
273 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_HEADERS
),
275 m_xBtnHeaders
->get_active(),
276 m_xBtnHeaders
->get_saved_state() != TRISTATE_FALSE
);
278 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_TOPDOWN
),
280 m_xBtnTopDown
->get_active(),
281 m_xBtnTopDown
->get_saved_state() != TRISTATE_FALSE
);
283 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_FORMULAS
),
285 m_xBtnFormulas
->get_active(),
286 m_xBtnFormulas
->get_saved_state() != TRISTATE_FALSE
);
288 bDataChanged
|= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_NULLVALS
),
290 m_xBtnNullVals
->get_active(),
291 m_xBtnNullVals
->get_saved_state() != TRISTATE_FALSE
);
293 // first printed page:
294 bool bUseValue
= m_xBtnPageNo
->get_active();
296 if ( WAS_DEFAULT(nWhichPageNo
,rOldSet
)
297 && ( (!bUseValue
&& 0 == m_xBtnPageNo
->get_saved_state())
298 || ( bUseValue
&& 1 == m_xBtnPageNo
->get_saved_state()
299 && ! m_xEdPageNo
->get_value_changed_from_saved() ) ) )
301 rCoreSet
->ClearItem( nWhichPageNo
);
305 sal_uInt16 nPage
= static_cast<sal_uInt16
>( m_xBtnPageNo
->get_active()
306 ? m_xEdPageNo
->get_value()
309 rCoreSet
->Put( SfxUInt16Item( nWhichPageNo
, nPage
) );
313 // object representation:
314 bDataChanged
|= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_CHARTS
),
315 *rCoreSet
, rOldSet
, *m_xBtnCharts
);
317 bDataChanged
|= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_OBJECTS
),
318 *rCoreSet
, rOldSet
, *m_xBtnObjects
);
320 bDataChanged
|= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_DRAWINGS
),
321 *rCoreSet
, rOldSet
, *m_xBtnDrawings
);
324 if( !m_xEdScalePageWidth
->get_sensitive() && !m_xEdScalePageHeight
->get_sensitive() )
326 m_xLbScaleMode
->set_active(SC_TPTABLE_SCALE_PERCENT
);
327 m_xEdScaleAll
->set_value(100, FieldUnit::PERCENT
);
330 bDataChanged
|= lcl_PutScaleItem( GetWhich(SID_SCATTR_PAGE_SCALE
),
332 *m_xLbScaleMode
, SC_TPTABLE_SCALE_PERCENT
,
333 *m_xEdScaleAll
, static_cast<sal_uInt16
>(m_xEdScaleAll
->get_value(FieldUnit::PERCENT
)) );
335 bDataChanged
|= lcl_PutScaleItem2( GetWhich(SID_SCATTR_PAGE_SCALETO
),
337 *m_xLbScaleMode
, SC_TPTABLE_SCALE_TO
,
338 *m_xEdScalePageWidth
, m_nOrigScalePageWidth
,
339 *m_xEdScalePageHeight
, m_nOrigScalePageHeight
);
341 bDataChanged
|= lcl_PutScaleItem3( GetWhich(SID_SCATTR_PAGE_SCALETOPAGES
),
343 *m_xLbScaleMode
, SC_TPTABLE_SCALE_TO_PAGES
,
344 *m_xEdScalePageNum
, static_cast<sal_uInt16
>(m_xEdScalePageNum
->get_value()) );
349 DeactivateRC
ScTablePage::DeactivatePage( SfxItemSet
* pSetP
)
352 FillItemSet( pSetP
);
354 return DeactivateRC::LeavePage
;
359 IMPL_LINK_NOARG(ScTablePage
, PageDirHdl
, weld::ToggleButton
&, void)
364 IMPL_LINK(ScTablePage
, PageNoHdl
, weld::ToggleButton
&, rBtn
, void)
369 void ScTablePage::PageNoHdl(const weld::ToggleButton
* pBtn
)
371 if (m_xBtnPageNo
->get_active())
373 m_xEdPageNo
->set_sensitive(true);
375 m_xEdPageNo
->grab_focus();
378 m_xEdPageNo
->set_sensitive(false);
381 IMPL_LINK_NOARG(ScTablePage
, ScaleHdl
, weld::ComboBox
&, void)
383 // controls for Box "Reduce/enlarge"
384 m_xBxScaleAll
->set_visible(m_xLbScaleMode
->get_active() == SC_TPTABLE_SCALE_PERCENT
);
386 // controls for Grid "Scale to width/height"
387 m_xGrHeightWidth
->set_visible(m_xLbScaleMode
->get_active() == SC_TPTABLE_SCALE_TO
);
389 // controls for Box "Scale to pages"
390 m_xBxScalePageNum
->set_visible(m_xLbScaleMode
->get_active() == SC_TPTABLE_SCALE_TO_PAGES
);
393 IMPL_LINK(ScTablePage
, ToggleHdl
, weld::ToggleButton
&, rBox
, void)
395 if (&rBox
== m_xCbScalePageWidth
.get())
397 if (!rBox
.get_active())
399 m_xEdScalePageWidth
->set_text(OUString());
400 m_xEdScalePageWidth
->set_sensitive(false);
404 m_xEdScalePageWidth
->set_value(1);
405 m_xEdScalePageWidth
->set_sensitive(true);
410 if (!rBox
.get_active())
412 m_xEdScalePageHeight
->set_text(OUString());
413 m_xEdScalePageHeight
->set_sensitive(false);
417 m_xEdScalePageHeight
->set_value(1);
418 m_xEdScalePageHeight
->set_sensitive(true);
423 // Helper functions for FillItemSet:
425 static bool lcl_PutBoolItem( sal_uInt16 nWhich
,
426 SfxItemSet
& rCoreSet
,
427 const SfxItemSet
& rOldSet
,
431 bool bDataChanged
= ( bSavedValue
== bIsChecked
432 && WAS_DEFAULT(nWhich
,rOldSet
) );
435 rCoreSet
.ClearItem(nWhich
);
437 rCoreSet
.Put( SfxBoolItem( nWhich
, bIsChecked
) );
442 static bool lcl_PutVObjModeItem( sal_uInt16 nWhich
,
443 SfxItemSet
& rCoreSet
,
444 const SfxItemSet
& rOldSet
,
445 const weld::ToggleButton
& rBtn
)
447 bool bIsChecked
= rBtn
.get_active();
448 bool bDataChanged
= rBtn
.get_saved_state() == (bIsChecked
? 1 : 0)
449 && WAS_DEFAULT(nWhich
,rOldSet
);
452 rCoreSet
.ClearItem( nWhich
);
455 rCoreSet
.Put( ScViewObjectModeItem( nWhich
, bIsChecked
457 : VOBJ_MODE_HIDE
) );
461 static bool lcl_PutScaleItem( sal_uInt16 nWhich
,
462 SfxItemSet
& rCoreSet
,
463 const SfxItemSet
& rOldSet
,
464 const weld::ComboBox
& rListBox
,
466 const weld::MetricSpinButton
& rEd
,
469 bool bIsSel
= (rListBox
.get_active() == nLBEntry
);
470 bool bDataChanged
= (rListBox
.get_value_changed_from_saved()) ||
471 rEd
.get_value_changed_from_saved() ||
472 !WAS_DEFAULT( nWhich
, rOldSet
);
475 rCoreSet
.Put( SfxUInt16Item( nWhich
, bIsSel
? nValue
: 0 ) );
477 rCoreSet
.ClearItem( nWhich
);
482 static bool lcl_PutScaleItem2( sal_uInt16 nWhich
,
483 SfxItemSet
& rCoreSet
,
484 const SfxItemSet
& rOldSet
,
485 const weld::ComboBox
& rListBox
,
487 const weld::SpinButton
& rEd1
,
488 sal_uInt16 nOrigScalePageWidth
,
489 const weld::SpinButton
& rEd2
,
490 sal_uInt16 nOrigScalePageHeight
)
492 sal_uInt16 nValue1
= rEd1
.get_sensitive() ? rEd1
.get_value() : 0;
493 sal_uInt16 nValue2
= rEd2
.get_sensitive() ? rEd2
.get_value() : 0;
494 bool bIsSel
= (rListBox
.get_active() == nLBEntry
);
495 bool bDataChanged
= (rListBox
.get_value_changed_from_saved()) ||
496 nValue1
!= nOrigScalePageWidth
||
497 nValue1
!= nOrigScalePageHeight
||
498 !WAS_DEFAULT( nWhich
, rOldSet
);
502 ScPageScaleToItem aItem
;
504 aItem
.Set( nValue1
, nValue2
);
505 rCoreSet
.Put( aItem
);
508 rCoreSet
.ClearItem( nWhich
);
513 static bool lcl_PutScaleItem3( sal_uInt16 nWhich
,
514 SfxItemSet
& rCoreSet
,
515 const SfxItemSet
& rOldSet
,
516 const weld::ComboBox
& rListBox
,
518 const weld::SpinButton
& rEd
,
521 bool bIsSel
= (rListBox
.get_active() == nLBEntry
);
522 bool bDataChanged
= (rListBox
.get_value_changed_from_saved()) ||
523 rEd
.get_value_changed_from_saved() ||
524 !WAS_DEFAULT( nWhich
, rOldSet
);
527 rCoreSet
.Put( SfxUInt16Item( nWhich
, bIsSel
? nValue
: 0 ) );
529 rCoreSet
.ClearItem( nWhich
);
535 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */