Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / utlui / gotodlg.cxx
blob711717ee44c13a4a8614631f5c5d804808e32f05
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 <swmodule.hxx>
21 #include <view.hxx>
22 #include <wrtsh.hxx>
23 #include <gotodlg.hxx>
24 #include <sfx2/bindings.hxx>
25 #include <sfx2/viewfrm.hxx>
27 using namespace com::sun::star;
29 SwGotoPageDlg::SwGotoPageDlg(weld::Window* pParent, SfxBindings& rBindings)
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"))
37 sal_uInt16 nTotalPage = GetPageInfo();
39 if (nTotalPage)
41 OUString sStr = mxPageNumberLbl->get_label();
42 mxPageNumberLbl->set_label(sStr.replaceFirst("$1", OUString::number(nTotalPage)));
43 mnMaxPageCnt = nTotalPage;
45 mxMtrPageCtrl->connect_changed(LINK(this, SwGotoPageDlg, PageModifiedHdl));
46 mxMtrPageCtrl->set_position(-1);
47 mxMtrPageCtrl->select_region(0, -1);
50 IMPL_LINK_NOARG(SwGotoPageDlg, PageModifiedHdl, weld::Entry&, void)
52 if (mxMtrPageCtrl->get_text().isEmpty())
53 return;
55 int page_value = mxMtrPageCtrl->get_text().toInt32();
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);
64 mxMtrPageCtrl->set_position(-1);
67 SwView* SwGotoPageDlg::GetCreateView() const
69 if (!m_pCreateView)
71 SwView* pView = SwModule::GetFirstView();
72 while (pView)
74 if (&pView->GetViewFrame().GetBindings() == &m_rBindings)
76 const_cast<SwGotoPageDlg*>(this)->m_pCreateView = pView;
77 break;
79 pView = SwModule::GetNextView(pView);
83 return m_pCreateView;
86 // If the page can be set here, the maximum is set.
88 sal_uInt16 SwGotoPageDlg::GetPageInfo()
90 SwView* pView = GetCreateView();
91 SwWrtShell* pSh = pView ? &pView->GetWrtShell() : nullptr;
92 mxMtrPageCtrl->set_value(1);
93 if (pSh)
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;
102 return 0;
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */