LibreOffice Module sw (master)  1
wordcountdialog.cxx
Go to the documentation of this file.
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 <cmdid.h>
25 #include <swmodule.hxx>
26 #include <wview.hxx>
27 #include <swwait.hxx>
28 #include <wrtsh.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <svl/cjkoptions.hxx>
32 #include <vcl/settings.hxx>
33 #include <vcl/svapp.hxx>
34 
36 {
38 }
39 
40 namespace
41 {
42  void setValue(weld::Label& rWidget, sal_uLong nValue, const LocaleDataWrapper& rLocaleData)
43  {
44  rWidget.set_label(rLocaleData.getNum(nValue, 0));
45  }
46 
47  void setDoubleValue(weld::Label& rWidget, double fValue)
48  {
49  OUString sValue(OUString::number(::rtl::math::round(fValue, 1)));
50  rWidget.set_label(sValue);
51  }
52 }
53 
54 void SwWordCountFloatDlg::SetValues(const SwDocStat& rCurrent, const SwDocStat& rDoc)
55 {
57  setValue(*m_xCurrentWordFT, rCurrent.nWord, rLocaleData);
58  setValue(*m_xCurrentCharacterFT, rCurrent.nChar, rLocaleData);
60  setValue(*m_xCurrentCjkcharsFT, rCurrent.nAsianWord, rLocaleData);
61  setValue(*m_xDocWordFT, rDoc.nWord, rLocaleData);
62  setValue(*m_xDocCharacterFT, rDoc.nChar, rLocaleData);
64  setValue(*m_xDocCjkcharsFT, rDoc.nAsianWord, rLocaleData);
65 
66  if (m_xStandardizedPagesLabelFT->get_visible())
67  {
68  sal_Int64 nCharsPerStandardizedPage = officecfg::Office::Writer::WordCount::StandardizedPageSize::get();
69  setDoubleValue(*m_xCurrentStandardizedPagesFT,
70  static_cast<double>(rCurrent.nChar) / nCharsPerStandardizedPage);
71  setDoubleValue(*m_xDocStandardizedPagesFT,
72  static_cast<double>(rDoc.nChar) / nCharsPerStandardizedPage);
73  }
74 
75  bool bShowCJK = (SvtCJKOptions().IsAnyEnabled() || rDoc.nAsianWord);
76  bool bToggleCJK = m_xCurrentCjkcharsFT->get_visible() != bShowCJK;
77  if (bToggleCJK)
78  {
79  showCJK(bShowCJK);
80  m_xDialog->resize_to_request(); //force resize of dialog
81  }
82 }
83 
84 void SwWordCountFloatDlg::showCJK(bool bShowCJK)
85 {
86  m_xCurrentCjkcharsFT->set_visible(bShowCJK);
87  m_xDocCjkcharsFT->set_visible(bShowCJK);
88  m_xCjkcharsLabelFT->set_visible(bShowCJK);
89 }
90 
91 void SwWordCountFloatDlg::showStandardizedPages(bool bShowStandardizedPages)
92 {
93  m_xCurrentStandardizedPagesFT->set_visible(bShowStandardizedPages);
94  m_xDocStandardizedPagesFT->set_visible(bShowStandardizedPages);
95  m_xStandardizedPagesLabelFT->set_visible(bShowStandardizedPages);
96 }
97 
99  SfxChildWindow* pChild,
100  weld::Window *pParent,
101  SfxChildWinInfo const * pInfo)
102  : SfxModelessDialogController(_pBindings, pChild, pParent, "modules/swriter/ui/wordcount.ui", "WordCountDialog")
103  , m_xCurrentWordFT(m_xBuilder->weld_label("selectwords"))
104  , m_xCurrentCharacterFT(m_xBuilder->weld_label("selectchars"))
105  , m_xCurrentCharacterExcludingSpacesFT(m_xBuilder->weld_label("selectcharsnospaces"))
106  , m_xCurrentCjkcharsFT(m_xBuilder->weld_label("selectcjkchars"))
107  , m_xCurrentStandardizedPagesFT(m_xBuilder->weld_label("selectstandardizedpages"))
108  , m_xDocWordFT(m_xBuilder->weld_label("docwords"))
109  , m_xDocCharacterFT(m_xBuilder->weld_label("docchars"))
110  , m_xDocCharacterExcludingSpacesFT(m_xBuilder->weld_label("doccharsnospaces"))
111  , m_xDocCjkcharsFT(m_xBuilder->weld_label("doccjkchars"))
112  , m_xDocStandardizedPagesFT(m_xBuilder->weld_label("docstandardizedpages"))
113  , m_xCjkcharsLabelFT(m_xBuilder->weld_label("cjkcharsft"))
114  , m_xStandardizedPagesLabelFT(m_xBuilder->weld_label("standardizedpages"))
115 {
116  showCJK(SvtCJKOptions().IsAnyEnabled());
118 
119  Initialize(pInfo);
120 }
121 
123 {
125  SwDocStat aCurrCnt;
126  SwDocStat aDocStat;
127  {
128  SwWait aWait( *::GetActiveView()->GetDocShell(), true );
129  rSh.StartAction();
130  rSh.CountWords( aCurrCnt );
131  aDocStat = rSh.GetUpdatedDocStat();
132  rSh.EndAction();
133  }
134  SetValues(aCurrCnt, aDocStat);
135 }
136 
137 void SwWordCountFloatDlg::SetCounts(const SwDocStat &rCurrCnt, const SwDocStat &rDocStat)
138 {
139  SetValues(rCurrCnt, rDocStat);
140 }
141 
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
RegError REGISTRY_CALLTYPE setValue(RegKeyHandle hKey, rtl_uString *keyName, RegValueType valueType, RegValue pData, sal_uInt32 valueSize)
void showStandardizedPages(bool bShowStandardizedPages)
bool IsAnyEnabled() const
void Initialize(SfxChildWinInfo const *pInfo)
SwView * GetActiveView()
Definition: swmodul1.cxx:123
sal_uIntPtr sal_uLong
static const AllSettings & GetSettings()
void CountWords(SwDocStat &rStat) const
Count words in current selection.
Definition: editsh.cxx:1045
std::unique_ptr< weld::Label > m_xDocCharacterExcludingSpacesFT
sal_uLong nChar
Definition: docstat.hxx:37
std::unique_ptr< weld::Label > m_xCurrentWordFT
std::unique_ptr< weld::Label > m_xDocCjkcharsFT
sal_uLong nCharExcludingSpaces
Definition: docstat.hxx:38
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
Used by the UI to modify the document model.
Definition: wrtsh.hxx:88
SwWordCountFloatDlg(SfxBindings *pBindings, SfxChildWindow *pChild, weld::Window *pParent, SfxChildWinInfo const *pInfo)
std::unique_ptr< weld::Label > m_xCurrentStandardizedPagesFT
const LocaleDataWrapper & GetUILocaleDataWrapper() const
std::unique_ptr< weld::Label > m_xStandardizedPagesLabelFT
const SwDocStat & GetUpdatedDocStat()
Definition: editsh.cxx:438
sal_uLong nAsianWord
Definition: docstat.hxx:36
void SetValues(const SwDocStat &rCurrent, const SwDocStat &rDoc)
void EndAction(const bool bIdleEnd=false, const bool DoSetPosX=false)
Definition: crsrsh.cxx:228
virtual void set_label(const OUString &rText)=0
void StartAction()
Definition: crsrsh.cxx:211
void SetCounts(const SwDocStat &rCurrCnt, const SwDocStat &rDocStat)
std::unique_ptr< weld::Label > m_xCurrentCjkcharsFT
static void SetCareDialog(const std::shared_ptr< weld::Window > &rNew)
Definition: viewsh.cxx:2494
std::unique_ptr< weld::Label > m_xDocStandardizedPagesFT
std::unique_ptr< weld::Label > m_xCurrentCharacterFT
virtual ~SwWordCountFloatDlg() override
std::unique_ptr< weld::Label > m_xDocWordFT
OUString getNum(sal_Int64 nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
std::unique_ptr< weld::Label > m_xCjkcharsLabelFT
sal_uLong nWord
Definition: docstat.hxx:35
std::unique_ptr< weld::Label > m_xDocCharacterFT
void showCJK(bool bShowCJK)
std::unique_ptr< weld::Label > m_xCurrentCharacterExcludingSpacesFT