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/dispatch.hxx>
26 #include <sfx2/viewfrm.hxx>
27 #include <cmdid.h>
28 
29 using namespace com::sun::star;
30 
32  : GenericDialogController(pParent, "modules/swriter/ui/gotopagedialog.ui", "GotoPageDialog")
33  , m_pCreateView(nullptr)
34  , m_rBindings(_pBindings)
35  , mnMaxPageCnt(1)
36  , mxMtrPageCtrl(m_xBuilder->weld_entry("page"))
37  , mxPageNumberLbl(m_xBuilder->weld_label("page_count"))
38 {
39  sal_uInt16 nTotalPage = GetPageInfo();
40 
41  if(nTotalPage)
42  {
43  OUString sStr = mxPageNumberLbl->get_label();
44  mxPageNumberLbl->set_label(sStr.replaceFirst("$1", OUString::number(nTotalPage)));
45  mnMaxPageCnt = nTotalPage;
46  }
47  mxMtrPageCtrl->connect_changed(LINK(this, SwGotoPageDlg, PageModifiedHdl));
48  mxMtrPageCtrl->set_position(-1);
49  mxMtrPageCtrl->select_region(0, -1);
50 }
51 
52 IMPL_LINK_NOARG(SwGotoPageDlg, PageModifiedHdl, weld::Entry&, void)
53 {
54  if (!mxMtrPageCtrl->get_text().isEmpty())
55  {
56  int page_value = mxMtrPageCtrl->get_text().toInt32();
57 
58  if (page_value <= 0)
59  mxMtrPageCtrl->set_text(OUString::number(1));
60  else if(page_value > mnMaxPageCnt)
61  mxMtrPageCtrl->set_text(OUString::number(mnMaxPageCnt));
62 
63  mxMtrPageCtrl->set_position(-1);
64  }
65 }
66 
68 {
69  if(!m_pCreateView)
70  {
71  SwView* pView = SwModule::GetFirstView();
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_text(OUString::number(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_text(OUString::number(nPhyPage));
99  return nPageCnt;
100  }
101  return 0;
102 }
103 
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
IMPL_LINK_NOARG(SwGotoPageDlg, PageModifiedHdl, weld::Entry &, void)
Definition: gotodlg.cxx:52
SwView * m_pCreateView
Definition: gotodlg.hxx:38
void GetPageNum(sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum, bool bAtCursorPos=true, const bool bCalcFrame=true)
Definition: crsrsh.cxx:1197
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
Used by the UI to modify the document model.
Definition: wrtsh.hxx:86
SwGotoPageDlg(weld::Window *parent, SfxBindings *_pBindings)
Definition: gotodlg.cxx:31
sal_uInt16 GetPageCnt()
Definition: crsrsh.cxx:1279
SfxBindings & GetBindings()
static SwView * GetFirstView()
Definition: swmodul1.cxx:129
SfxBindings *const m_rBindings
Definition: gotodlg.hxx:39
sal_uInt16 mnMaxPageCnt
Definition: gotodlg.hxx:40
std::unique_ptr< weld::Label > mxPageNumberLbl
Definition: gotodlg.hxx:43
std::unique_ptr< weld::Entry > mxMtrPageCtrl
Definition: gotodlg.hxx:42
SwView * GetCreateView() const
Definition: gotodlg.cxx:67
sal_uInt16 GetPageInfo()
Definition: gotodlg.cxx:88
static SwView * GetNextView(SwView const *)
Definition: swmodul1.cxx:136
Definition: view.hxx:146