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