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 #include <svl/itemset.hxx>
21 #include <svl/itempool.hxx>
22 #include <sfx2/objsh.hxx>
23 #include <vcl/layout.hxx>
24 #include <vcl/msgbox.hxx>
29 #include <sfx2/zoomitem.hxx>
30 #include <svx/viewlayoutitem.hxx>
31 #include <dialmgr.hxx>
32 #include <svx/zoom_def.hxx>
37 const sal_uInt16 SPECIAL_FACTOR
= 0xFFFF;
39 } // anonymous namespace
41 sal_uInt16
SvxZoomDialog::GetFactor() const
43 if (m_p100Btn
->IsChecked())
46 if (m_pUserBtn
->IsChecked())
47 return static_cast<sal_uInt16
>(m_pUserEdit
->GetValue());
49 return SPECIAL_FACTOR
;
52 void SvxZoomDialog::SetFactor(sal_uInt16 nNewFactor
, ZoomButtonId nButtonId
)
54 m_pUserEdit
->Disable();
56 if (nButtonId
== ZoomButtonId::NONE
)
58 if ( nNewFactor
== 100 )
61 m_p100Btn
->GrabFocus();
66 m_pUserEdit
->Enable();
67 m_pUserEdit
->SetValue(static_cast<long>(nNewFactor
));
68 m_pUserEdit
->GrabFocus();
73 m_pUserEdit
->SetValue(static_cast<long>(nNewFactor
));
76 case ZoomButtonId::OPTIMAL
:
78 m_pOptimalBtn
->Check();
79 m_pOptimalBtn
->GrabFocus();
82 case ZoomButtonId::PAGEWIDTH
:
84 m_pPageWidthBtn
->Check();
85 m_pPageWidthBtn
->GrabFocus();
88 case ZoomButtonId::WHOLEPAGE
:
90 m_pWholePageBtn
->Check();
91 m_pWholePageBtn
->GrabFocus();
99 void SvxZoomDialog::HideButton(ZoomButtonId nButtonId
)
103 case ZoomButtonId::OPTIMAL
:
104 m_pOptimalBtn
->Hide();
107 case ZoomButtonId::PAGEWIDTH
:
108 m_pPageWidthBtn
->Hide();
111 case ZoomButtonId::WHOLEPAGE
:
112 m_pWholePageBtn
->Hide();
116 OSL_FAIL("Wrong button number!" );
120 void SvxZoomDialog::SetLimits(sal_uInt16 nMin
, sal_uInt16 nMax
)
122 DBG_ASSERT(nMin
< nMax
, "invalid limits");
123 m_pUserEdit
->SetMin(nMin
);
124 m_pUserEdit
->SetFirst(nMin
);
125 m_pUserEdit
->SetMax(nMax
);
126 m_pUserEdit
->SetLast(nMax
);
129 const SfxItemSet
* SvxZoomDialog::GetOutputItemSet() const
131 return mpOutSet
.get();
134 SvxZoomDialog::SvxZoomDialog( vcl::Window
* pParent
, const SfxItemSet
& rCoreSet
)
135 : SfxModalDialog(pParent
, "ZoomDialog", "cui/ui/zoomdialog.ui")
141 get(m_pOptimalBtn
, "optimal");
142 get(m_pWholePageBtn
, "fitwandh");
143 get(m_pPageWidthBtn
, "fitw");
144 get(m_p100Btn
, "100pc");
145 get(m_pUserBtn
, "variable");
146 get(m_pUserEdit
, "zoomsb");
147 get(m_pViewFrame
, "viewframe");
148 get(m_pAutomaticBtn
, "automatic");
149 get(m_pSingleBtn
, "singlepage");
150 get(m_pColumnsBtn
, "columns");
151 get(m_pColumnsEdit
, "columnssb");
152 get(m_pBookModeChk
, "bookmode");
154 Link
<> aLink
= LINK(this, SvxZoomDialog
, UserHdl
);
155 m_p100Btn
->SetClickHdl(aLink
);
156 m_pOptimalBtn
->SetClickHdl(aLink
);
157 m_pPageWidthBtn
->SetClickHdl(aLink
);
158 m_pWholePageBtn
->SetClickHdl(aLink
);
159 m_pUserBtn
->SetClickHdl(aLink
);
161 Link
<> aViewLayoutLink
= LINK(this, SvxZoomDialog
, ViewLayoutUserHdl
);
162 m_pAutomaticBtn
->SetClickHdl(aViewLayoutLink
);
163 m_pSingleBtn
->SetClickHdl(aViewLayoutLink
);
164 m_pColumnsBtn
->SetClickHdl(aViewLayoutLink
);
166 Link
<> aViewLayoutSpinLink
= LINK(this, SvxZoomDialog
, ViewLayoutSpinHdl
);
167 m_pColumnsEdit
->SetModifyHdl(aViewLayoutSpinLink
);
169 Link
<> aViewLayoutCheckLink
= LINK(this, SvxZoomDialog
, ViewLayoutCheckHdl
);
170 m_pBookModeChk
->SetClickHdl(aViewLayoutCheckLink
);
172 m_pOKBtn
->SetClickHdl(LINK(this, SvxZoomDialog
, OKHdl
));
173 m_pUserEdit
->SetModifyHdl(LINK(this, SvxZoomDialog
, SpinHdl
));
176 sal_uInt16 nValue
= 100;
177 sal_uInt16 nMin
= 10;
178 sal_uInt16 nMax
= 1000;
180 // maybe get the old value first
181 const SfxUInt16Item
* pOldUserItem
= 0;
182 SfxObjectShell
* pShell
= SfxObjectShell::Current();
185 pOldUserItem
= static_cast<const SfxUInt16Item
*>(pShell
->GetItem(SID_ATTR_ZOOM_USER
));
188 nValue
= pOldUserItem
->GetValue();
190 // initialize UserEdit
196 SetLimits(nMin
, nMax
);
197 m_pUserEdit
->SetValue(nValue
);
199 m_pUserEdit
->SetAccessibleName(m_pUserBtn
->GetText());
200 m_pColumnsEdit
->SetAccessibleName(m_pColumnsBtn
->GetText());
201 m_pColumnsEdit
->SetAccessibleRelationMemberOf(m_pColumnsBtn
);
202 m_pBookModeChk
->SetAccessibleRelationMemberOf(m_pColumnsBtn
);
204 const SfxPoolItem
& rItem
= mrSet
.Get(mrSet
.GetPool()->GetWhich(SID_ATTR_ZOOM
));
206 if (rItem
.ISA(SvxZoomItem
))
208 const SvxZoomItem
& rZoomItem
= static_cast<const SvxZoomItem
&>(rItem
);
209 const sal_uInt16 nZoom
= rZoomItem
.GetValue();
210 const SvxZoomType eType
= rZoomItem
.GetType();
211 const SvxZoomEnableFlags nValSet
= rZoomItem
.GetValueSet();
212 ZoomButtonId nButtonId
= ZoomButtonId::NONE
;
216 case SvxZoomType::OPTIMAL
:
217 nButtonId
= ZoomButtonId::OPTIMAL
;
219 case SvxZoomType::PAGEWIDTH
:
220 nButtonId
= ZoomButtonId::PAGEWIDTH
;
222 case SvxZoomType::WHOLEPAGE
:
223 nButtonId
= ZoomButtonId::WHOLEPAGE
;
225 case SvxZoomType::PERCENT
:
227 case SvxZoomType::PAGEWIDTH_NOBORDER
:
231 if (!(SvxZoomEnableFlags::N100
& nValSet
))
232 m_p100Btn
->Disable();
233 if (!(SvxZoomEnableFlags::OPTIMAL
& nValSet
))
234 m_pOptimalBtn
->Disable();
235 if (!(SvxZoomEnableFlags::PAGEWIDTH
& nValSet
))
236 m_pPageWidthBtn
->Disable();
237 if (!(SvxZoomEnableFlags::WHOLEPAGE
& nValSet
))
238 m_pWholePageBtn
->Disable();
240 SetFactor(nZoom
, nButtonId
);
244 const sal_uInt16 nZoom
= static_cast<const SfxUInt16Item
&>(rItem
).GetValue();
248 const SfxPoolItem
* pPoolViewLayoutItem
= NULL
;
249 if (SfxItemState::SET
== mrSet
.GetItemState(SID_ATTR_VIEWLAYOUT
, false, &pPoolViewLayoutItem
))
251 const SvxViewLayoutItem
* pViewLayoutItem
= static_cast<const SvxViewLayoutItem
*>(pPoolViewLayoutItem
);
252 const sal_uInt16 nColumns
= pViewLayoutItem
->GetValue();
253 const bool bBookMode
= pViewLayoutItem
->IsBookMode();
257 m_pAutomaticBtn
->Check();
258 m_pColumnsEdit
->SetValue(2);
259 m_pColumnsEdit
->Disable();
260 m_pBookModeChk
->Disable();
262 else if (1 == nColumns
)
264 m_pSingleBtn
->Check();
265 m_pColumnsEdit
->SetValue(2);
266 m_pColumnsEdit
->Disable();
267 m_pBookModeChk
->Disable();
271 m_pColumnsBtn
->Check();
274 m_pColumnsEdit
->SetValue(nColumns
);
275 if (nColumns
% 2 != 0)
276 m_pBookModeChk
->Disable();
280 m_pColumnsEdit
->SetValue(nColumns
);
281 m_pBookModeChk
->Check();
287 // hide view layout related controls:
288 m_pViewFrame
->Disable();
292 SvxZoomDialog::~SvxZoomDialog()
297 void SvxZoomDialog::dispose()
300 m_pOptimalBtn
.clear();
301 m_pWholePageBtn
.clear();
302 m_pPageWidthBtn
.clear();
306 m_pViewFrame
.clear();
307 m_pAutomaticBtn
.clear();
308 m_pSingleBtn
.clear();
309 m_pColumnsBtn
.clear();
310 m_pColumnsEdit
.clear();
311 m_pBookModeChk
.clear();
313 SfxModalDialog::dispose();
316 IMPL_LINK(SvxZoomDialog
, UserHdl
, RadioButton
*, pButton
)
320 if (pButton
== m_pUserBtn
)
322 m_pUserEdit
->Enable();
323 m_pUserEdit
->GrabFocus();
327 m_pUserEdit
->Disable();
332 IMPL_LINK_NOARG(SvxZoomDialog
, SpinHdl
)
334 if (!m_pUserBtn
->IsChecked())
341 IMPL_LINK(SvxZoomDialog
, ViewLayoutUserHdl
, RadioButton
*, pButton
)
345 if (pButton
== m_pAutomaticBtn
)
347 m_pColumnsEdit
->Disable();
348 m_pBookModeChk
->Disable();
350 else if (pButton
== m_pSingleBtn
)
352 m_pColumnsEdit
->Disable();
353 m_pBookModeChk
->Disable();
355 else if (pButton
== m_pColumnsBtn
)
357 m_pColumnsEdit
->Enable();
358 m_pColumnsEdit
->GrabFocus();
359 if (m_pColumnsEdit
->GetValue() % 2 == 0)
360 m_pBookModeChk
->Enable();
364 OSL_FAIL("Wrong Button");
371 IMPL_LINK(SvxZoomDialog
, ViewLayoutSpinHdl
, NumericField
*, pEdit
)
373 if (pEdit
== m_pColumnsEdit
&& !m_pColumnsBtn
->IsChecked())
376 if (m_pColumnsEdit
->GetValue() % 2 == 0)
378 m_pBookModeChk
->Enable();
382 m_pBookModeChk
->Check(false);
383 m_pBookModeChk
->Disable();
391 IMPL_LINK(SvxZoomDialog
, ViewLayoutCheckHdl
, CheckBox
*, pCheckBox
)
393 if (pCheckBox
== m_pBookModeChk
&& !m_pColumnsBtn
->IsChecked())
401 IMPL_LINK(SvxZoomDialog
, OKHdl
, Button
*, pButton
)
403 if (mbModified
|| m_pOKBtn
!= pButton
)
405 SvxZoomItem
aZoomItem(SvxZoomType::PERCENT
, 0, mrSet
.GetPool()->GetWhich(SID_ATTR_ZOOM
));
406 SvxViewLayoutItem
aViewLayoutItem(0, false, mrSet
.GetPool()->GetWhich(SID_ATTR_VIEWLAYOUT
));
408 if (m_pOKBtn
== pButton
)
410 sal_uInt16 nFactor
= GetFactor();
412 if (SPECIAL_FACTOR
== nFactor
)
414 if (m_pOptimalBtn
->IsChecked())
415 aZoomItem
.SetType(SvxZoomType::OPTIMAL
);
416 else if (m_pPageWidthBtn
->IsChecked())
417 aZoomItem
.SetType(SvxZoomType::PAGEWIDTH
);
418 else if (m_pWholePageBtn
->IsChecked())
419 aZoomItem
.SetType(SvxZoomType::WHOLEPAGE
);
423 aZoomItem
.SetValue(nFactor
);
426 if (m_pAutomaticBtn
->IsChecked())
428 aViewLayoutItem
.SetValue(0);
429 aViewLayoutItem
.SetBookMode(false);
431 if (m_pSingleBtn
->IsChecked())
433 aViewLayoutItem
.SetValue(1);
434 aViewLayoutItem
.SetBookMode(false);
436 else if (m_pColumnsBtn
->IsChecked())
438 aViewLayoutItem
.SetValue(static_cast<sal_uInt16
>(m_pColumnsEdit
->GetValue()));
439 aViewLayoutItem
.SetBookMode(m_pBookModeChk
->IsChecked());
444 OSL_FAIL("Wrong Button");
447 mpOutSet
.reset(new SfxItemSet(mrSet
));
448 mpOutSet
->Put(aZoomItem
);
450 // don't set attribute in case the whole viewlayout stuff is disabled:
451 if (m_pViewFrame
->IsEnabled())
452 mpOutSet
->Put(aViewLayoutItem
);
454 // memorize value from the UserEdit beyond the dialog
455 SfxObjectShell
* pShell
= SfxObjectShell::Current();
459 sal_uInt16 nZoomValue
= static_cast<sal_uInt16
>(m_pUserEdit
->GetValue());
460 pShell
->PutItem(SfxUInt16Item(SID_ATTR_ZOOM_USER
, nZoomValue
));
466 EndDialog( RET_CANCEL
);
471 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */