LibreOffice Module sw (master)  1
docstdlg.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 <swwait.hxx>
21 #include <wrtsh.hxx>
22 #include <view.hxx>
23 #include <docsh.hxx>
24 #include <pview.hxx>
25 #include <doc.hxx>
26 #include <docstdlg.hxx>
27 #include <IDocumentStatistics.hxx>
28 
30 #include <vcl/settings.hxx>
31 #include <vcl/svapp.hxx>
32 
33 std::unique_ptr<SfxTabPage> SwDocStatPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
34 {
35  return std::make_unique<SwDocStatPage>(pPage, pController, *rSet);
36 }
37 
39  : SfxTabPage(pPage, pController, "modules/swriter/ui/statisticsinfopage.ui", "StatisticsInfoPage", &rSet)
40  , m_xPageNo(m_xBuilder->weld_label("nopages"))
41  , m_xTableNo(m_xBuilder->weld_label("notables"))
42  , m_xGrfNo(m_xBuilder->weld_label("nogrfs"))
43  , m_xOLENo(m_xBuilder->weld_label("nooles"))
44  , m_xParaNo(m_xBuilder->weld_label("noparas"))
45  , m_xWordNo(m_xBuilder->weld_label("nowords"))
46  , m_xCharNo(m_xBuilder->weld_label("nochars"))
47  , m_xCharExclSpacesNo(m_xBuilder->weld_label("nocharsexspaces"))
48  , m_xLineLbl(m_xBuilder->weld_label("lineft"))
49  , m_xLineNo(m_xBuilder->weld_label("nolines"))
50  , m_xUpdatePB(m_xBuilder->weld_button("update"))
51 {
52  Update();
53  m_xUpdatePB->connect_clicked(LINK(this, SwDocStatPage, UpdateHdl));
54  //#111684# is the current view a page preview no SwFEShell can be found -> hide the update button
55  SwDocShell* pDocShell = static_cast<SwDocShell*>( SfxObjectShell::Current() );
56  SwFEShell* pFEShell = pDocShell->GetFEShell();
57  if(!pFEShell)
58  {
59  m_xUpdatePB->hide();
60  m_xLineLbl->hide();
61  m_xLineNo->hide();
62  }
63 }
64 
66 {
67 }
68 
69 // Description: fill ItemSet when changed
71 {
72  return false;
73 }
74 
76 {
77 }
78 
79 // Description: update / set data
81 {
83  m_xTableNo->set_label(rLocaleData.getNum(rStat.nTable, 0));
84  m_xGrfNo->set_label(rLocaleData.getNum(rStat.nGrf, 0));
85  m_xOLENo->set_label(rLocaleData.getNum(rStat.nOLE, 0));
86  m_xPageNo->set_label(rLocaleData.getNum(rStat.nPage, 0));
87  m_xParaNo->set_label(rLocaleData.getNum(rStat.nPara, 0));
88  m_xWordNo->set_label(rLocaleData.getNum(rStat.nWord, 0));
89  m_xCharNo->set_label(rLocaleData.getNum(rStat.nChar, 0));
90  m_xCharExclSpacesNo->set_label(rLocaleData.getNum(rStat.nCharExcludingSpaces, 0));
91 }
92 
93 // Description: update statistics
95 {
97  SwViewShell *pSh = nullptr;
98  if ( dynamic_cast< const SwView *>( pVSh ) != nullptr )
99  pSh = static_cast<SwView*>(pVSh)->GetWrtShellPtr();
100  else if ( dynamic_cast< const SwPagePreview *>( pVSh ) != nullptr )
101  pSh = static_cast<SwPagePreview*>(pVSh)->GetViewShell();
102 
103  OSL_ENSURE( pSh, "Shell not found" );
104 
105  if (!pSh)
106  return;
107 
108  SwWait aWait( *pSh->GetDoc()->GetDocShell(), true );
109  pSh->StartAction();
110  aDocStat = pSh->GetDoc()->getIDocumentStatistics().GetUpdatedDocStat( false, true );
111  pSh->EndAction();
112 
113  SetData(aDocStat);
114 }
115 
117 {
118  Update();
119  SwDocShell* pDocShell = static_cast<SwDocShell*>( SfxObjectShell::Current());
120  SwFEShell* pFEShell = pDocShell->GetFEShell();
121  if (pFEShell)
122  m_xLineNo->set_label(OUString::number(pFEShell->GetLineCount()));
123 }
124 
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IDocumentStatistics const & getIDocumentStatistics() const
Definition: doc.cxx:372
sal_uInt16 GetLineCount()
Definition: editsh.cxx:842
SwDocStatPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: docstdlg.cxx:38
sal_uLong nPara
paragraphs for document statistic: non-empty and non-hidden ones
Definition: docstat.hxx:32
void SetData(const SwDocStat &rStat)
Definition: docstdlg.cxx:80
SwDocShell * GetDocShell()
Definition: doc.hxx:1348
IMPL_LINK_NOARG(SwDocStatPage, UpdateHdl, weld::Button &, void)
Definition: docstdlg.cxx:116
static const AllSettings & GetSettings()
std::unique_ptr< weld::Label > m_xCharExclSpacesNo
Definition: docstdlg.hxx:47
sal_uLong nChar
Definition: docstat.hxx:37
sal_uInt16 nTable
Definition: docstat.hxx:27
static SfxObjectShell * Current()
virtual const SwDocStat & GetUpdatedDocStat(bool bCompleteAsync, bool bFields)=0
Updates the document statistics if the document has been modified and returns a reference to the resu...
sal_uLong nCharExcludingSpaces
Definition: docstat.hxx:38
std::unique_ptr< weld::Label > m_xLineNo
Definition: docstdlg.hxx:49
std::unique_ptr< weld::Label > m_xWordNo
Definition: docstdlg.hxx:45
std::unique_ptr< weld::Label > m_xCharNo
Definition: docstdlg.hxx:46
virtual ~SwDocStatPage() override
Definition: docstdlg.cxx:65
SwDocStat aDocStat
Definition: docstdlg.hxx:52
static SfxViewShell * Current()
const LocaleDataWrapper & GetUILocaleDataWrapper() const
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
sal_uInt16 nOLE
Definition: docstat.hxx:29
std::unique_ptr< weld::Label > m_xOLENo
Definition: docstdlg.hxx:43
std::unique_ptr< weld::Label > m_xPageNo
Definition: docstdlg.hxx:40
std::unique_ptr< weld::Label > m_xGrfNo
Definition: docstdlg.hxx:42
void StartAction()
Definition: viewsh.hxx:592
std::unique_ptr< weld::Button > m_xUpdatePB
Definition: docstdlg.hxx:50
std::unique_ptr< weld::Label > m_xLineLbl
Definition: docstdlg.hxx:48
sal_uLong nPage
Definition: docstat.hxx:30
void EndAction(const bool bIdleEnd=false)
Definition: viewsh.hxx:597
std::unique_ptr< weld::Label > m_xParaNo
Definition: docstdlg.hxx:44
sal_uInt16 nGrf
Definition: docstat.hxx:28
std::unique_ptr< weld::Label > m_xTableNo
Definition: docstdlg.hxx:41
virtual void Reset(const SfxItemSet *rSet) override
Definition: docstdlg.cxx:75
void Update()
Definition: docstdlg.cxx:94
SwFEShell * GetFEShell()
For Core - it knows the DocShell but not the WrtShell!
Definition: docsh.cxx:1208
OUString getNum(sal_Int64 nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
sal_uLong nWord
Definition: docstat.hxx:35
Definition: view.hxx:146
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: docstdlg.cxx:33
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: docstdlg.cxx:70