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 <officecfg/Office/Writer.hxx>
21 : #include <swtypes.hxx>
22 : #include <wordcountdialog.hxx>
23 : #include <docstat.hxx>
24 : #include <dialog.hrc>
25 : #include <cmdid.h>
26 : #include <swmodule.hxx>
27 : #include <wview.hxx>
28 : #include <swwait.hxx>
29 : #include <wrtsh.hxx>
30 : #include <comphelper/string.hxx>
31 : #include <sfx2/viewfrm.hxx>
32 : #include <svl/cjkoptions.hxx>
33 : #include <unotools/localedatawrapper.hxx>
34 : #include <vcl/msgbox.hxx>
35 : #include <vcl/settings.hxx>
36 :
37 0 : IMPL_STATIC_LINK_NOARG(SwWordCountFloatDlg, CloseHdl)
38 : {
39 0 : SfxViewFrame* pVFrame = ::GetActiveView()->GetViewFrame();
40 0 : if (pVFrame != NULL)
41 : {
42 0 : pVFrame->ToggleChildWindow(FN_WORDCOUNT_DIALOG);
43 : }
44 0 : return 0;
45 : }
46 :
47 0 : SwWordCountFloatDlg::~SwWordCountFloatDlg()
48 : {
49 0 : disposeOnce();
50 0 : }
51 :
52 0 : void SwWordCountFloatDlg::dispose()
53 : {
54 0 : SwViewShell::SetCareWin( 0 );
55 0 : m_pCurrentWordFT.clear();
56 0 : m_pCurrentCharacterFT.clear();
57 0 : m_pCurrentCharacterExcludingSpacesFT.clear();
58 0 : m_pCurrentCjkcharsFT.clear();
59 0 : m_pCurrentStandardizedPagesFT.clear();
60 0 : m_pDocWordFT.clear();
61 0 : m_pDocCharacterFT.clear();
62 0 : m_pDocCharacterExcludingSpacesFT.clear();
63 0 : m_pDocCjkcharsFT.clear();
64 0 : m_pDocStandardizedPagesFT.clear();
65 0 : m_pCjkcharsLabelFT.clear();
66 0 : m_pStandardizedPagesLabelFT.clear();
67 0 : m_pClosePB.clear();
68 0 : SfxModelessDialog::dispose();
69 0 : }
70 :
71 : namespace
72 : {
73 0 : void setValue(FixedText *pWidget, sal_uLong nValue, const LocaleDataWrapper& rLocaleData)
74 : {
75 0 : pWidget->SetText(rLocaleData.getNum(nValue, 0));
76 0 : }
77 :
78 0 : void setDoubleValue(FixedText *pWidget, double fValue)
79 : {
80 0 : OUString sValue(OUString::number(::rtl::math::round(fValue, 1)));
81 0 : pWidget->SetText(sValue);
82 0 : }
83 : }
84 :
85 0 : void SwWordCountFloatDlg::SetValues(const SwDocStat& rCurrent, const SwDocStat& rDoc)
86 : {
87 0 : const LocaleDataWrapper& rLocaleData = GetSettings().GetUILocaleDataWrapper();
88 0 : setValue(m_pCurrentWordFT, rCurrent.nWord, rLocaleData);
89 0 : setValue(m_pCurrentCharacterFT, rCurrent.nChar, rLocaleData);
90 0 : setValue(m_pCurrentCharacterExcludingSpacesFT, rCurrent.nCharExcludingSpaces, rLocaleData);
91 0 : setValue(m_pCurrentCjkcharsFT, rCurrent.nAsianWord, rLocaleData);
92 0 : setValue(m_pDocWordFT, rDoc.nWord, rLocaleData);
93 0 : setValue(m_pDocCharacterFT, rDoc.nChar, rLocaleData);
94 0 : setValue(m_pDocCharacterExcludingSpacesFT, rDoc.nCharExcludingSpaces, rLocaleData);
95 0 : setValue(m_pDocCjkcharsFT, rDoc.nAsianWord, rLocaleData);
96 :
97 0 : if (m_pStandardizedPagesLabelFT->IsVisible())
98 : {
99 0 : sal_Int64 nCharsPerStandardizedPage = officecfg::Office::Writer::WordCount::StandardizedPageSize::get();
100 : setDoubleValue(m_pCurrentStandardizedPagesFT,
101 0 : (double)rCurrent.nChar / nCharsPerStandardizedPage);
102 : setDoubleValue(m_pDocStandardizedPagesFT,
103 0 : (double)rDoc.nChar / nCharsPerStandardizedPage);
104 : }
105 :
106 0 : bool bShowCJK = (SvtCJKOptions().IsAnyEnabled() || rDoc.nAsianWord);
107 0 : bool bToggleCJK = m_pCurrentCjkcharsFT->IsVisible() != bShowCJK;
108 0 : if (bToggleCJK)
109 : {
110 0 : showCJK(bShowCJK);
111 0 : setOptimalLayoutSize(); //force resize of dialog
112 : }
113 0 : }
114 :
115 0 : void SwWordCountFloatDlg::showCJK(bool bShowCJK)
116 : {
117 0 : m_pCurrentCjkcharsFT->Show(bShowCJK);
118 0 : m_pDocCjkcharsFT->Show(bShowCJK);
119 0 : m_pCjkcharsLabelFT->Show(bShowCJK);
120 0 : }
121 :
122 0 : void SwWordCountFloatDlg::showStandardizedPages(bool bShowStandardizedPages)
123 : {
124 0 : m_pCurrentStandardizedPagesFT->Show(bShowStandardizedPages);
125 0 : m_pDocStandardizedPagesFT->Show(bShowStandardizedPages);
126 0 : m_pStandardizedPagesLabelFT->Show(bShowStandardizedPages);
127 0 : }
128 :
129 0 : SwWordCountFloatDlg::SwWordCountFloatDlg(SfxBindings* _pBindings,
130 : SfxChildWindow* pChild,
131 : vcl::Window *pParent,
132 : SfxChildWinInfo* pInfo)
133 0 : : SfxModelessDialog(_pBindings, pChild, pParent, "WordCountDialog", "modules/swriter/ui/wordcount.ui")
134 : {
135 0 : get(m_pCurrentWordFT, "selectwords");
136 0 : get(m_pCurrentCharacterFT, "selectchars");
137 0 : get(m_pCurrentCharacterExcludingSpacesFT, "selectcharsnospaces");
138 0 : get(m_pCurrentCjkcharsFT, "selectcjkchars");
139 0 : get(m_pCurrentStandardizedPagesFT, "selectstandardizedpages");
140 :
141 0 : get(m_pDocWordFT, "docwords");
142 0 : get(m_pDocCharacterFT, "docchars");
143 0 : get(m_pDocCharacterExcludingSpacesFT, "doccharsnospaces");
144 0 : get(m_pDocCjkcharsFT, "doccjkchars");
145 0 : get(m_pDocStandardizedPagesFT, "docstandardizedpages");
146 :
147 0 : get(m_pCjkcharsLabelFT, "cjkcharsft");
148 0 : get(m_pStandardizedPagesLabelFT, "standardizedpages");
149 :
150 0 : get(m_pClosePB, "close");
151 :
152 0 : showCJK(SvtCJKOptions().IsAnyEnabled());
153 0 : showStandardizedPages(officecfg::Office::Writer::WordCount::ShowStandardizedPageCount::get());
154 :
155 0 : Initialize(pInfo);
156 :
157 0 : m_pClosePB->SetClickHdl(LINK(this, SwWordCountFloatDlg, CloseHdl));
158 0 : m_pClosePB->GrabFocus();
159 0 : }
160 :
161 0 : void SwWordCountFloatDlg::Activate()
162 : {
163 0 : SfxModelessDialog::Activate();
164 0 : }
165 :
166 0 : void SwWordCountFloatDlg::UpdateCounts()
167 : {
168 0 : SwWrtShell &rSh = ::GetActiveView()->GetWrtShell();
169 0 : SwDocStat aCurrCnt;
170 0 : SwDocStat aDocStat;
171 : {
172 0 : SwWait aWait( *::GetActiveView()->GetDocShell(), true );
173 0 : rSh.StartAction();
174 0 : rSh.CountWords( aCurrCnt );
175 0 : aDocStat = rSh.GetUpdatedDocStat();
176 0 : rSh.EndAction();
177 : }
178 0 : SetValues(aCurrCnt, aDocStat);
179 0 : }
180 :
181 0 : void SwWordCountFloatDlg::SetCounts(const SwDocStat &rCurrCnt, const SwDocStat &rDocStat)
182 : {
183 0 : SetValues(rCurrCnt, rDocStat);
184 0 : }
185 :
186 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|