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 <swmodule.hxx>
24 #include <globals.hrc>
25 #include <docsh.hxx>
26 #include <pview.hxx>
27 #include <doc.hxx>
28 #include <docstdlg.hxx>
29 #include <modcfg.hxx>
30 #include <fldmgr.hxx>
31 #include <fldbas.hxx>
32 #include <IDocumentStatistics.hxx>
33 
35 #include <vcl/settings.hxx>
36 #include <vcl/svapp.hxx>
37 
38 std::unique_ptr<SfxTabPage> SwDocStatPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
39 {
40  return std::make_unique<SwDocStatPage>(pPage, pController, *rSet);
41 }
42 
44  : SfxTabPage(pPage, pController, "modules/swriter/ui/statisticsinfopage.ui", "StatisticsInfoPage", &rSet)
45  , m_xPageNo(m_xBuilder->weld_label("nopages"))
46  , m_xTableNo(m_xBuilder->weld_label("notables"))
47  , m_xGrfNo(m_xBuilder->weld_label("nogrfs"))
48  , m_xOLENo(m_xBuilder->weld_label("nooles"))
49  , m_xParaNo(m_xBuilder->weld_label("noparas"))
50  , m_xWordNo(m_xBuilder->weld_label("nowords"))
51  , m_xCharNo(m_xBuilder->weld_label("nochars"))
52  , m_xCharExclSpacesNo(m_xBuilder->weld_label("nocharsexspaces"))
53  , m_xLineLbl(m_xBuilder->weld_label("lineft"))
54  , m_xLineNo(m_xBuilder->weld_label("nolines"))
55  , m_xUpdatePB(m_xBuilder->weld_button("update"))
56 {
57  Update();
58  m_xUpdatePB->connect_clicked(LINK(this, SwDocStatPage, UpdateHdl));
59  //#111684# is the current view a page preview no SwFEShell can be found -> hide the update button
60  SwDocShell* pDocShell = static_cast<SwDocShell*>( SfxObjectShell::Current() );
61  SwFEShell* pFEShell = pDocShell->GetFEShell();
62  if(!pFEShell)
63  {
64  m_xUpdatePB->hide();
65  m_xLineLbl->hide();
66  m_xLineNo->hide();
67  }
68 }
69 
71 {
72 }
73 
74 // Description: fill ItemSet when changed
76 {
77  return false;
78 }
79 
81 {
82 }
83 
84 // Description: update / set data
86 {
88  m_xTableNo->set_label(rLocaleData.getNum(rStat.nTable, 0));
89  m_xGrfNo->set_label(rLocaleData.getNum(rStat.nGrf, 0));
90  m_xOLENo->set_label(rLocaleData.getNum(rStat.nOLE, 0));
91  m_xPageNo->set_label(rLocaleData.getNum(rStat.nPage, 0));
92  m_xParaNo->set_label(rLocaleData.getNum(rStat.nPara, 0));
93  m_xWordNo->set_label(rLocaleData.getNum(rStat.nWord, 0));
94  m_xCharNo->set_label(rLocaleData.getNum(rStat.nChar, 0));
95  m_xCharExclSpacesNo->set_label(rLocaleData.getNum(rStat.nCharExcludingSpaces, 0));
96 }
97 
98 // Description: update statistics
100 {
102  SwViewShell *pSh = nullptr;
103  if ( dynamic_cast< const SwView *>( pVSh ) != nullptr )
104  pSh = static_cast<SwView*>(pVSh)->GetWrtShellPtr();
105  else if ( dynamic_cast< const SwPagePreview *>( pVSh ) != nullptr )
106  pSh = static_cast<SwPagePreview*>(pVSh)->GetViewShell();
107 
108  OSL_ENSURE( pSh, "Shell not found" );
109 
110  if (!pSh)
111  return;
112 
113  SwWait aWait( *pSh->GetDoc()->GetDocShell(), true );
114  pSh->StartAction();
115  aDocStat = pSh->GetDoc()->getIDocumentStatistics().GetUpdatedDocStat( false, true );
116  pSh->EndAction();
117 
118  SetData(aDocStat);
119 }
120 
122 {
123  Update();
124  SwDocShell* pDocShell = static_cast<SwDocShell*>( SfxObjectShell::Current());
125  SwFEShell* pFEShell = pDocShell->GetFEShell();
126  if (pFEShell)
127  m_xLineNo->set_label(OUString::number(pFEShell->GetLineCount()));
128 }
129 
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IDocumentStatistics const & getIDocumentStatistics() const
Definition: doc.cxx:372
sal_uInt16 GetLineCount()
Definition: editsh.cxx:848
SwDocStatPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: docstdlg.cxx:43
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:85
SwDocShell * GetDocShell()
Definition: doc.hxx:1342
IMPL_LINK_NOARG(SwDocStatPage, UpdateHdl, weld::Button &, void)
Definition: docstdlg.cxx:121
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:70
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:80
void Update()
Definition: docstdlg.cxx:99
SwFEShell * GetFEShell()
For Core - it knows the DocShell but not the WrtShell!
Definition: docsh.cxx:1250
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:38
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: docstdlg.cxx:75