LibreOffice Module sw (master) 1
gotodlg.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 <swmodule.hxx>
21#include <view.hxx>
22#include <wrtsh.hxx>
23#include <gotodlg.hxx>
24#include <sfx2/bindings.hxx>
25#include <sfx2/viewfrm.hxx>
26
27using namespace com::sun::star;
28
30 : GenericDialogController(pParent, "modules/swriter/ui/gotopagedialog.ui", "GotoPageDialog")
31 , m_pCreateView(nullptr)
32 , m_rBindings(rBindings)
33 , mnMaxPageCnt(1)
34 , mxMtrPageCtrl(m_xBuilder->weld_spin_button("page"))
35 , mxPageNumberLbl(m_xBuilder->weld_label("page_count"))
36{
37 sal_uInt16 nTotalPage = GetPageInfo();
38
39 if (nTotalPage)
40 {
41 OUString sStr = mxPageNumberLbl->get_label();
42 mxPageNumberLbl->set_label(sStr.replaceFirst("$1", OUString::number(nTotalPage)));
43 mnMaxPageCnt = nTotalPage;
44 }
45 mxMtrPageCtrl->connect_changed(LINK(this, SwGotoPageDlg, PageModifiedHdl));
46 mxMtrPageCtrl->set_position(-1);
47 mxMtrPageCtrl->select_region(0, -1);
48}
49
50IMPL_LINK_NOARG(SwGotoPageDlg, PageModifiedHdl, weld::Entry&, void)
51{
52 if (mxMtrPageCtrl->get_text().isEmpty())
53 return;
54
55 int page_value = mxMtrPageCtrl->get_text().toInt32();
56
57 if (page_value <= 0)
58 mxMtrPageCtrl->set_value(1);
59 else if (page_value > mnMaxPageCnt)
60 mxMtrPageCtrl->set_value(mnMaxPageCnt);
61 else
62 mxMtrPageCtrl->set_value(page_value);
63
64 mxMtrPageCtrl->set_position(-1);
65}
66
68{
69 if (!m_pCreateView)
70 {
72 while (pView)
73 {
74 if (&pView->GetViewFrame().GetBindings() == &m_rBindings)
75 {
76 const_cast<SwGotoPageDlg*>(this)->m_pCreateView = pView;
77 break;
78 }
79 pView = SwModule::GetNextView(pView);
80 }
81 }
82
83 return m_pCreateView;
84}
85
86// If the page can be set here, the maximum is set.
87
89{
90 SwView* pView = GetCreateView();
91 SwWrtShell* pSh = pView ? &pView->GetWrtShell() : nullptr;
92 mxMtrPageCtrl->set_value(1);
93 if (pSh)
94 {
95 const sal_uInt16 nPageCnt = pSh->GetPageCnt();
96 sal_uInt16 nPhyPage, nVirPage;
97 pSh->GetPageNum(nPhyPage, nVirPage);
98 mxMtrPageCtrl->set_max(nPageCnt);
99 mxMtrPageCtrl->set_value(nPhyPage);
100 return nPageCnt;
101 }
102 return 0;
103}
104
105/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxBindings & GetBindings()
SfxViewFrame & GetViewFrame() const
void GetPageNum(sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum, bool bAtCursorPos=true, const bool bCalcFrame=true)
Definition: crsrsh.cxx:1509
sal_uInt16 GetPageCnt()
Definition: crsrsh.cxx:1591
SfxBindings & m_rBindings
Definition: gotodlg.hxx:40
sal_uInt16 mnMaxPageCnt
Definition: gotodlg.hxx:41
SwView * m_pCreateView
Definition: gotodlg.hxx:39
SwGotoPageDlg(weld::Window *parent, SfxBindings &rBindings)
Definition: gotodlg.cxx:29
SwView * GetCreateView() const
Definition: gotodlg.cxx:67
std::unique_ptr< weld::SpinButton > mxMtrPageCtrl
Definition: gotodlg.hxx:43
sal_uInt16 GetPageInfo()
Definition: gotodlg.cxx:88
std::unique_ptr< weld::Label > mxPageNumberLbl
Definition: gotodlg.hxx:44
static SwView * GetNextView(SwView const *)
Definition: swmodul1.cxx:128
static SwView * GetFirstView()
Definition: swmodul1.cxx:121
Definition: view.hxx:146
SwWrtShell & GetWrtShell() const
Definition: view.hxx:423
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
IMPL_LINK_NOARG(SwGotoPageDlg, PageModifiedHdl, weld::Entry &, void)
Definition: gotodlg.cxx:50