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