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