1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
26 #include <docstdlg.hxx>
27 #include <IDocumentStatistics.hxx>
29 #include <unotools/localedatawrapper.hxx>
30 #include <vcl/settings.hxx>
31 #include <vcl/svapp.hxx>
32 #include <osl/diagnose.h>
34 std::unique_ptr
<SfxTabPage
> SwDocStatPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
*rSet
)
36 return std::make_unique
<SwDocStatPage
>(pPage
, pController
, *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"))
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
? pDocShell
->GetFEShell() : nullptr;
66 SwDocStatPage::~SwDocStatPage()
70 // Description: fill ItemSet when changed
71 bool SwDocStatPage::FillItemSet(SfxItemSet
* /*rSet*/)
76 void SwDocStatPage::Reset(const SfxItemSet
*)
80 // Description: update / set data
81 void SwDocStatPage::SetData(const SwDocStat
&rStat
)
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));
94 // Description: update statistics
95 void SwDocStatPage::Update()
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();
104 OSL_ENSURE( pSh
, "Shell not found" );
109 SwWait
aWait( *pSh
->GetDoc()->GetDocShell(), true );
111 m_aDocStat
= pSh
->GetDoc()->getIDocumentStatistics().GetUpdatedDocStat( false, true );
117 IMPL_LINK_NOARG(SwDocStatPage
, UpdateHdl
, weld::Button
&, void)
120 SwDocShell
* pDocShell
= static_cast<SwDocShell
*>( SfxObjectShell::Current());
121 SwFEShell
* pFEShell
= pDocShell
? pDocShell
->GetFEShell() : nullptr;
123 m_xLineNo
->set_label(OUString::number(pFEShell
->GetLineCount()));
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */