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 
27 using namespace com::sun::star;
28 
30  : GenericDialogController(pParent, "modules/swriter/ui/gotopagedialog.ui", "GotoPageDialog")
31  , m_pCreateView(nullptr)
32  , m_rBindings(_pBindings)
33  , mnMaxPageCnt(1)
34  , mxMtrPageCtrl(m_xBuilder->weld_entry("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 
50 IMPL_LINK_NOARG(SwGotoPageDlg, PageModifiedHdl, weld::Entry&, void)
51 {
52  if (!mxMtrPageCtrl->get_text().isEmpty())
53  {
54  int page_value = mxMtrPageCtrl->get_text().toInt32();
55 
56  if (page_value <= 0)
57  mxMtrPageCtrl->set_text(OUString::number(1));
58  else if (page_value > mnMaxPageCnt)
59  mxMtrPageCtrl->set_text(OUString::number(mnMaxPageCnt));
60 
61  mxMtrPageCtrl->set_position(-1);
62  }
63 }
64 
66 {
67  if (!m_pCreateView)
68  {
69  SwView* pView = SwModule::GetFirstView();
70  while (pView)
71  {
72  if (&pView->GetViewFrame()->GetBindings() == m_rBindings)
73  {
74  const_cast<SwGotoPageDlg*>(this)->m_pCreateView = pView;
75  break;
76  }
77  pView = SwModule::GetNextView(pView);
78  }
79  }
80 
81  return m_pCreateView;
82 }
83 
84 // If the page can be set here, the maximum is set.
85 
87 {
88  SwView* pView = GetCreateView();
89  SwWrtShell* pSh = pView ? &pView->GetWrtShell() : nullptr;
90  mxMtrPageCtrl->set_text(OUString::number(1));
91  if (pSh)
92  {
93  const sal_uInt16 nPageCnt = pSh->GetPageCnt();
94  sal_uInt16 nPhyPage, nVirPage;
95  pSh->GetPageNum(nPhyPage, nVirPage);
96  mxMtrPageCtrl->set_text(OUString::number(nPhyPage));
97  return nPageCnt;
98  }
99  return 0;
100 }
101 
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
IMPL_LINK_NOARG(SwGotoPageDlg, PageModifiedHdl, weld::Entry &, void)
Definition: gotodlg.cxx:50
SwView * m_pCreateView
Definition: gotodlg.hxx:39
void GetPageNum(sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum, bool bAtCursorPos=true, const bool bCalcFrame=true)
Definition: crsrsh.cxx:1208
SwWrtShell & GetWrtShell() const
Definition: view.hxx:399
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
SwGotoPageDlg(weld::Window *parent, SfxBindings *_pBindings)
Definition: gotodlg.cxx:29
sal_uInt16 GetPageCnt()
Definition: crsrsh.cxx:1290
SfxBindings & GetBindings()
static SwView * GetFirstView()
Definition: swmodul1.cxx:122
sal_uInt16 mnMaxPageCnt
Definition: gotodlg.hxx:41
std::unique_ptr< weld::Label > mxPageNumberLbl
Definition: gotodlg.hxx:44
std::unique_ptr< weld::Entry > mxMtrPageCtrl
Definition: gotodlg.hxx:43
SwView * GetCreateView() const
Definition: gotodlg.cxx:65
sal_uInt16 GetPageInfo()
Definition: gotodlg.cxx:86
static SwView * GetNextView(SwView const *)
Definition: swmodul1.cxx:129
SfxBindings * m_rBindings
Definition: gotodlg.hxx:40
Definition: view.hxx:144