android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / misc / pagenumberdlg.cxx
blob1b5084c5e94b2dd4d399564477989ba82d370b00
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 SwPageNumberDlg::SwPageNumberDlg(weld::Window* pParent)
28 : SfxDialogController(pParent, "modules/swriter/ui/pagenumberdlg.ui", "PageNumberDialog")
29 , m_xOk(m_xBuilder->weld_button("ok"))
30 , m_xCancel(m_xBuilder->weld_button("cancel"))
31 , m_xPageNumberPosition(m_xBuilder->weld_combo_box("positionCombo"))
32 , m_xPageNumberAlignment(m_xBuilder->weld_combo_box("alignmentCombo"))
33 , m_xMirrorOnEvenPages(m_xBuilder->weld_check_button("mirrorCheckbox"))
34 , m_xIncludePageTotal(m_xBuilder->weld_check_button("pagetotalCheckbox"))
35 , m_xPageNumberTypeLB(new SvxPageNumberListBox(m_xBuilder->weld_combo_box("numfmtlb")))
36 , m_xPreviewImage(m_xBuilder->weld_image("previewImage"))
37 , m_aPageNumberPosition(1) // bottom
38 , m_aPageNumberAlignment(1) // center
39 , m_nPageNumberType(SVX_NUM_CHARS_UPPER_LETTER)
41 m_xOk->connect_clicked(LINK(this, SwPageNumberDlg, OkHdl));
42 m_xPageNumberPosition->connect_changed(LINK(this, SwPageNumberDlg, PositionSelectHdl));
43 m_xPageNumberAlignment->connect_changed(LINK(this, SwPageNumberDlg, AlignmentSelectHdl));
44 m_xPageNumberPosition->set_active(m_aPageNumberPosition);
45 m_xPageNumberAlignment->set_active(m_aPageNumberAlignment);
46 m_xMirrorOnEvenPages->set_sensitive(false);
47 m_xMirrorOnEvenPages->set_state(TRISTATE_TRUE);
48 m_xIncludePageTotal->set_state(TRISTATE_FALSE);
49 SvxNumOptionsTabPageHelper::GetI18nNumbering(m_xPageNumberTypeLB->get_widget(),
50 ::std::numeric_limits<sal_uInt16>::max());
51 m_xPageNumberTypeLB->connect_changed(LINK(this, SwPageNumberDlg, NumberTypeSelectHdl));
52 updateImage();
55 IMPL_LINK_NOARG(SwPageNumberDlg, OkHdl, weld::Button&, void) { m_xDialog->response(RET_OK); }
57 IMPL_LINK_NOARG(SwPageNumberDlg, PositionSelectHdl, weld::ComboBox&, void)
59 m_aPageNumberPosition = m_xPageNumberPosition->get_active();
60 updateImage();
63 IMPL_LINK_NOARG(SwPageNumberDlg, AlignmentSelectHdl, weld::ComboBox&, void)
65 m_aPageNumberAlignment = m_xPageNumberAlignment->get_active();
66 updateImage();
68 if (m_aPageNumberAlignment == 1) // centered
69 m_xMirrorOnEvenPages->set_sensitive(false);
70 else
71 m_xMirrorOnEvenPages->set_sensitive(true);
74 IMPL_LINK_NOARG(SwPageNumberDlg, NumberTypeSelectHdl, weld::ComboBox&, void)
76 m_nPageNumberType = m_xPageNumberTypeLB->get_active_id();
79 bool SwPageNumberDlg::GetMirrorOnEvenPages()
81 return m_xMirrorOnEvenPages->get_sensitive()
82 && m_xMirrorOnEvenPages->get_state() == TRISTATE_TRUE;
85 bool SwPageNumberDlg::GetIncludePageTotal()
87 return m_xIncludePageTotal->get_state() == TRISTATE_TRUE;
90 void SwPageNumberDlg::SetPageNumberType(SvxNumType nSet)
92 m_nPageNumberType = nSet;
93 m_xPageNumberTypeLB->set_active_id(nSet);
96 void SwPageNumberDlg::updateImage()
98 int nBackgroundWidth = 75;
99 int nBackgroundHeight = 105;
101 int nSpriteWidth = 10;
102 int nSpriteHeight = 14;
104 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
105 Size aVDSize(nBackgroundWidth, nBackgroundHeight);
106 pVirtualDev->SetOutputSizePixel(aVDSize);
107 pVirtualDev->SetBackground(Color(0xF0, 0xF0, 0xF0));
108 pVirtualDev->Erase();
110 int y = m_aPageNumberPosition ? (nBackgroundHeight - nSpriteHeight - 5) : 5;
111 int x = 5;
112 if (m_aPageNumberAlignment == 1)
114 x = (nBackgroundWidth - nSpriteWidth) / 2;
116 else if (m_aPageNumberAlignment == 2)
118 x = nBackgroundWidth - nSpriteWidth - 5;
120 pVirtualDev->DrawText(Point(x, y), "#");
122 m_xPreviewImage->set_image(pVirtualDev);
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */