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 <pagenumberdlg.hxx>
21 #include <svx/SvxNumOptionsTabPageHelper.hxx>
22 #include <vcl/bitmap.hxx>
23 #include <vcl/graph.hxx>
24 #include <vcl/BitmapTools.hxx>
25 #include <vcl/virdev.hxx>
26 #include <tools/gen.hxx>
28 SwPageNumberDlg::SwPageNumberDlg(weld::Window
* pParent
)
29 : SfxDialogController(pParent
, u
"modules/swriter/ui/pagenumberdlg.ui"_ustr
,
30 u
"PageNumberDialog"_ustr
)
31 , m_xOk(m_xBuilder
->weld_button(u
"ok"_ustr
))
32 , m_xCancel(m_xBuilder
->weld_button(u
"cancel"_ustr
))
33 , m_xPageNumberPosition(m_xBuilder
->weld_combo_box(u
"positionCombo"_ustr
))
34 , m_xPageNumberAlignment(m_xBuilder
->weld_combo_box(u
"alignmentCombo"_ustr
))
35 , m_xMirrorOnEvenPages(m_xBuilder
->weld_check_button(u
"mirrorCheckbox"_ustr
))
36 , m_xIncludePageTotal(m_xBuilder
->weld_check_button(u
"pagetotalCheckbox"_ustr
))
37 , m_xFitIntoExistingMargins(
38 m_xBuilder
->weld_check_button(u
"fitintoexistingmarginsCheckbox"_ustr
))
39 , m_xPageNumberTypeLB(new SvxPageNumberListBox(m_xBuilder
->weld_combo_box(u
"numfmtlb"_ustr
)))
40 , m_xPreviewImage(m_xBuilder
->weld_image(u
"previewImage"_ustr
))
41 , m_aPageNumberPosition(1) // bottom
42 , m_aPageNumberAlignment(1) // center
43 , m_nPageNumberType(SVX_NUM_CHARS_UPPER_LETTER
)
45 m_xOk
->connect_clicked(LINK(this, SwPageNumberDlg
, OkHdl
));
46 m_xPageNumberPosition
->connect_changed(LINK(this, SwPageNumberDlg
, PositionSelectHdl
));
47 m_xPageNumberAlignment
->connect_changed(LINK(this, SwPageNumberDlg
, AlignmentSelectHdl
));
48 m_xPageNumberPosition
->set_active(m_aPageNumberPosition
);
49 m_xPageNumberAlignment
->set_active(m_aPageNumberAlignment
);
50 m_xMirrorOnEvenPages
->set_sensitive(false);
51 m_xMirrorOnEvenPages
->set_state(TRISTATE_TRUE
);
52 m_xIncludePageTotal
->set_state(TRISTATE_FALSE
);
53 m_xFitIntoExistingMargins
->set_state(TRISTATE_FALSE
);
54 SvxNumOptionsTabPageHelper::GetI18nNumbering(m_xPageNumberTypeLB
->get_widget(),
55 ::std::numeric_limits
<sal_uInt16
>::max());
56 m_xPageNumberTypeLB
->connect_changed(LINK(this, SwPageNumberDlg
, NumberTypeSelectHdl
));
57 m_xIncludePageTotal
->connect_toggled(LINK(this, SwPageNumberDlg
, IncludePageTotalChangeHdl
));
61 IMPL_LINK_NOARG(SwPageNumberDlg
, OkHdl
, weld::Button
&, void) { m_xDialog
->response(RET_OK
); }
63 IMPL_LINK_NOARG(SwPageNumberDlg
, PositionSelectHdl
, weld::ComboBox
&, void)
65 m_aPageNumberPosition
= m_xPageNumberPosition
->get_active();
69 IMPL_LINK_NOARG(SwPageNumberDlg
, AlignmentSelectHdl
, weld::ComboBox
&, void)
71 m_aPageNumberAlignment
= m_xPageNumberAlignment
->get_active();
74 if (m_aPageNumberAlignment
== 1) // centered
75 m_xMirrorOnEvenPages
->set_sensitive(false);
77 m_xMirrorOnEvenPages
->set_sensitive(true);
80 IMPL_LINK_NOARG(SwPageNumberDlg
, NumberTypeSelectHdl
, weld::ComboBox
&, void)
82 m_nPageNumberType
= m_xPageNumberTypeLB
->get_active_id();
85 IMPL_LINK_NOARG(SwPageNumberDlg
, IncludePageTotalChangeHdl
, weld::Toggleable
&, void)
90 bool SwPageNumberDlg::GetMirrorOnEvenPages() const
92 return m_xMirrorOnEvenPages
->get_sensitive()
93 && m_xMirrorOnEvenPages
->get_state() == TRISTATE_TRUE
;
96 bool SwPageNumberDlg::GetIncludePageTotal() const
98 return m_xIncludePageTotal
->get_state() == TRISTATE_TRUE
;
101 bool SwPageNumberDlg::GetFitIntoExistingMargins() const
103 return m_xFitIntoExistingMargins
->get_state() == TRISTATE_TRUE
;
106 void SwPageNumberDlg::SetPageNumberType(SvxNumType nSet
)
108 m_nPageNumberType
= nSet
;
109 m_xPageNumberTypeLB
->set_active_id(nSet
);
112 void SwPageNumberDlg::updateImage()
114 int nBackgroundWidth
= 75;
115 int nBackgroundHeight
= 105;
119 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
120 Size
aVDSize(nBackgroundWidth
, nBackgroundHeight
);
121 pVirtualDev
->SetOutputSizePixel(aVDSize
);
122 pVirtualDev
->SetBackground(Color(0xF0, 0xF0, 0xF0));
123 pVirtualDev
->Erase();
125 OUString sText
= u
"#"_ustr
;
127 if (m_xIncludePageTotal
->get_state() == TRISTATE_TRUE
)
132 DrawTextFlags eFlags
= DrawTextFlags::Left
;
134 if (m_aPageNumberAlignment
== 1)
136 eFlags
= DrawTextFlags::Center
;
138 else if (m_aPageNumberAlignment
== 2)
140 eFlags
= DrawTextFlags::Right
;
143 eFlags
|= m_aPageNumberPosition
? DrawTextFlags::Bottom
: DrawTextFlags::Top
;
145 pVirtualDev
->DrawText(
146 tools::Rectangle(nMargin
, nMargin
, nBackgroundWidth
- nMargin
, nBackgroundHeight
- nMargin
),
149 m_xPreviewImage
->set_image(pVirtualDev
);
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */