Line data Source code
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 <ctype.h>
21 : #include <swwait.hxx>
22 : #include <wrtsh.hxx>
23 : #include <view.hxx>
24 : #include <swmodule.hxx>
25 : #include <globals.hrc>
26 : #include <docsh.hxx>
27 : #include <pview.hxx>
28 : #include <doc.hxx>
29 : #include <docstdlg.hxx>
30 : #include <modcfg.hxx>
31 : #include <fldmgr.hxx>
32 : #include <fldbas.hxx>
33 : #include <IDocumentStatistics.hxx>
34 :
35 : #include <unotools/localedatawrapper.hxx>
36 : #include <vcl/settings.hxx>
37 :
38 0 : VclPtr<SfxTabPage> SwDocStatPage::Create(vcl::Window *pParent, const SfxItemSet *rSet)
39 : {
40 0 : return VclPtr<SwDocStatPage>::Create(pParent, *rSet);
41 : }
42 :
43 0 : SwDocStatPage::SwDocStatPage(vcl::Window *pParent, const SfxItemSet &rSet)
44 :
45 0 : : SfxTabPage(pParent, "StatisticsInfoPage", "modules/swriter/ui/statisticsinfopage.ui", &rSet)
46 :
47 : {
48 0 : get(m_pPageNo, "nopages");
49 0 : get(m_pTableNo, "notables");
50 0 : get(m_pGrfNo, "nogrfs");
51 0 : get(m_pOLENo, "nooles");
52 0 : get(m_pParaNo, "noparas");
53 0 : get(m_pWordNo, "nowords");
54 0 : get(m_pCharNo, "nochars");
55 0 : get(m_pCharExclSpacesNo, "nocharsexspaces");
56 :
57 0 : get(m_pLineLbl, "lineft");
58 0 : get(m_pLineNo, "nolines");
59 0 : get(m_pUpdatePB, "update");
60 :
61 0 : Update();
62 0 : m_pUpdatePB->SetClickHdl(LINK(this, SwDocStatPage, UpdateHdl));
63 : //#111684# is the current view a page preview no SwFEShell can be found -> hide the update button
64 0 : SwDocShell* pDocShell = static_cast<SwDocShell*>( SfxObjectShell::Current() );
65 0 : SwFEShell* pFEShell = pDocShell->GetFEShell();
66 0 : if(!pFEShell)
67 : {
68 0 : m_pUpdatePB->Show(false);
69 0 : m_pLineLbl->Show(false);
70 0 : m_pLineNo->Show(false);
71 : }
72 :
73 0 : }
74 :
75 0 : SwDocStatPage::~SwDocStatPage()
76 : {
77 0 : disposeOnce();
78 0 : }
79 :
80 0 : void SwDocStatPage::dispose()
81 : {
82 0 : m_pPageNo.clear();
83 0 : m_pTableNo.clear();
84 0 : m_pGrfNo.clear();
85 0 : m_pOLENo.clear();
86 0 : m_pParaNo.clear();
87 0 : m_pWordNo.clear();
88 0 : m_pCharNo.clear();
89 0 : m_pCharExclSpacesNo.clear();
90 0 : m_pLineLbl.clear();
91 0 : m_pLineNo.clear();
92 0 : m_pUpdatePB.clear();
93 0 : SfxTabPage::dispose();
94 0 : }
95 :
96 : // Description: fill ItemSet when changed
97 0 : bool SwDocStatPage::FillItemSet(SfxItemSet * /*rSet*/)
98 : {
99 0 : return false;
100 : }
101 :
102 0 : void SwDocStatPage::Reset(const SfxItemSet *)
103 : {
104 0 : }
105 :
106 : // Description: update / set data
107 0 : void SwDocStatPage::SetData(const SwDocStat &rStat)
108 : {
109 0 : const LocaleDataWrapper& rLocaleData = GetSettings().GetUILocaleDataWrapper();
110 0 : m_pTableNo->SetText(rLocaleData.getNum(rStat.nTable, 0));
111 0 : m_pGrfNo->SetText(rLocaleData.getNum(rStat.nGrf, 0));
112 0 : m_pOLENo->SetText(rLocaleData.getNum(rStat.nOLE, 0));
113 0 : m_pPageNo->SetText(rLocaleData.getNum(rStat.nPage, 0));
114 0 : m_pParaNo->SetText(rLocaleData.getNum(rStat.nPara, 0));
115 0 : m_pWordNo->SetText(rLocaleData.getNum(rStat.nWord, 0));
116 0 : m_pCharNo->SetText(rLocaleData.getNum(rStat.nChar, 0));
117 0 : m_pCharExclSpacesNo->SetText(rLocaleData.getNum(rStat.nCharExcludingSpaces, 0));
118 0 : }
119 :
120 : // Description: update statistics
121 0 : void SwDocStatPage::Update()
122 : {
123 0 : SfxViewShell *pVSh = SfxViewShell::Current();
124 0 : SwViewShell *pSh = 0;
125 0 : if ( pVSh->ISA(SwView) )
126 0 : pSh = static_cast<SwView*>(pVSh)->GetWrtShellPtr();
127 0 : else if ( pVSh->ISA(SwPagePreview) )
128 0 : pSh = static_cast<SwPagePreview*>(pVSh)->GetViewShell();
129 :
130 : OSL_ENSURE( pSh, "Shell not found" );
131 :
132 0 : if (!pSh)
133 0 : return;
134 :
135 0 : SwWait aWait( *pSh->GetDoc()->GetDocShell(), true );
136 0 : pSh->StartAction();
137 0 : aDocStat = pSh->GetDoc()->getIDocumentStatistics().GetUpdatedDocStat( false, true );
138 0 : pSh->EndAction();
139 :
140 0 : SetData(aDocStat);
141 : }
142 :
143 0 : IMPL_LINK_NOARG(SwDocStatPage, UpdateHdl)
144 : {
145 0 : Update();
146 0 : SwDocShell* pDocShell = static_cast<SwDocShell*>( SfxObjectShell::Current());
147 0 : SwFEShell* pFEShell = pDocShell->GetFEShell();
148 0 : if(pFEShell)
149 0 : m_pLineNo->SetText( OUString::number( pFEShell->GetLineCount(false)));
150 : //pButton->Disable();
151 0 : return 0;
152 0 : }
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|