LibreOffice Module sw (master) 1
pagenumberdlg.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <pagenumberdlg.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>
27
29 : SfxDialogController(pParent, "modules/swriter/ui/pagenumberdlg.ui", "PageNumberDialog")
30 , m_xOk(m_xBuilder->weld_button("ok"))
31 , m_xCancel(m_xBuilder->weld_button("cancel"))
32 , m_xPageNumberPosition(m_xBuilder->weld_combo_box("positionCombo"))
33 , m_xPageNumberAlignment(m_xBuilder->weld_combo_box("alignmentCombo"))
34 , m_xMirrorOnEvenPages(m_xBuilder->weld_check_button("mirrorCheckbox"))
35 , m_xIncludePageTotal(m_xBuilder->weld_check_button("pagetotalCheckbox"))
36 , m_xPageNumberTypeLB(new SvxPageNumberListBox(m_xBuilder->weld_combo_box("numfmtlb")))
37 , m_xPreviewImage(m_xBuilder->weld_image("previewImage"))
38 , m_aPageNumberPosition(1) // bottom
39 , m_aPageNumberAlignment(1) // center
40 , m_nPageNumberType(SVX_NUM_CHARS_UPPER_LETTER)
41{
42 m_xOk->connect_clicked(LINK(this, SwPageNumberDlg, OkHdl));
43 m_xPageNumberPosition->connect_changed(LINK(this, SwPageNumberDlg, PositionSelectHdl));
44 m_xPageNumberAlignment->connect_changed(LINK(this, SwPageNumberDlg, AlignmentSelectHdl));
47 m_xMirrorOnEvenPages->set_sensitive(false);
51 ::std::numeric_limits<sal_uInt16>::max());
52 m_xPageNumberTypeLB->connect_changed(LINK(this, SwPageNumberDlg, NumberTypeSelectHdl));
53 m_xIncludePageTotal->connect_toggled(LINK(this, SwPageNumberDlg, IncludePageTotalChangeHdl));
55}
56
58
60{
61 m_aPageNumberPosition = m_xPageNumberPosition->get_active();
62 updateImage();
63}
64
66{
67 m_aPageNumberAlignment = m_xPageNumberAlignment->get_active();
68 updateImage();
69
70 if (m_aPageNumberAlignment == 1) // centered
71 m_xMirrorOnEvenPages->set_sensitive(false);
72 else
73 m_xMirrorOnEvenPages->set_sensitive(true);
74}
75
76IMPL_LINK_NOARG(SwPageNumberDlg, NumberTypeSelectHdl, weld::ComboBox&, void)
77{
78 m_nPageNumberType = m_xPageNumberTypeLB->get_active_id();
79}
80
81IMPL_LINK_NOARG(SwPageNumberDlg, IncludePageTotalChangeHdl, weld::Toggleable&, void)
82{
83 updateImage();
84}
85
87{
88 return m_xMirrorOnEvenPages->get_sensitive()
89 && m_xMirrorOnEvenPages->get_state() == TRISTATE_TRUE;
90}
91
93{
94 return m_xIncludePageTotal->get_state() == TRISTATE_TRUE;
95}
96
98{
99 m_nPageNumberType = nSet;
100 m_xPageNumberTypeLB->set_active_id(nSet);
101}
102
104{
105 int nBackgroundWidth = 75;
106 int nBackgroundHeight = 105;
107
108 int nMargin = 7;
109
111 Size aVDSize(nBackgroundWidth, nBackgroundHeight);
112 pVirtualDev->SetOutputSizePixel(aVDSize);
113 pVirtualDev->SetBackground(Color(0xF0, 0xF0, 0xF0));
114 pVirtualDev->Erase();
115
116 OUString sText = "#";
117
118 if (m_xIncludePageTotal->get_state() == TRISTATE_TRUE)
119 {
120 sText += " / #";
121 }
122
123 DrawTextFlags eFlags = DrawTextFlags::Left;
124
125 if (m_aPageNumberAlignment == 1)
126 {
127 eFlags = DrawTextFlags::Center;
128 }
129 else if (m_aPageNumberAlignment == 2)
130 {
131 eFlags = DrawTextFlags::Right;
132 }
133
134 eFlags |= m_aPageNumberPosition ? DrawTextFlags::Bottom : DrawTextFlags::Top;
135
136 pVirtualDev->DrawText(
137 tools::Rectangle(nMargin, nMargin, nBackgroundWidth - nMargin, nBackgroundHeight - nMargin),
138 sText, eFlags);
139
140 m_xPreviewImage->set_image(pVirtualDev);
141}
142
143/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DrawTextFlags
Reference< XExecutableDialog > m_xDialog
static void GetI18nNumbering(weld::ComboBox &rFmtLB, sal_uInt16 nDoNotRemove)
Page number wizard for easy header/footer page number insertion.
std::unique_ptr< weld::CheckButton > m_xIncludePageTotal
std::unique_ptr< weld::ComboBox > m_xPageNumberPosition
void SetPageNumberType(SvxNumType nSet)
bool GetIncludePageTotal()
std::unique_ptr< weld::Image > m_xPreviewImage
bool GetMirrorOnEvenPages()
std::unique_ptr< SvxPageNumberListBox > m_xPageNumberTypeLB
SwPageNumberDlg(weld::Window *pParent)
std::unique_ptr< weld::CheckButton > m_xMirrorOnEvenPages
std::unique_ptr< weld::Button > m_xOk
SvxNumType m_nPageNumberType
std::unique_ptr< weld::ComboBox > m_xPageNumberAlignment
TRISTATE_FALSE
TRISTATE_TRUE
IMPL_LINK_NOARG(SwPageNumberDlg, OkHdl, weld::Button &, void)
SvxNumType
SVX_NUM_CHARS_UPPER_LETTER
RET_OK