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 <wordcountdialog.hxx>
22#include <docsh.hxx>
23#include <docstat.hxx>
24#include <swmodule.hxx>
25#include <view.hxx>
26#include <swwait.hxx>
27#include <wrtsh.hxx>
28#include <rtl/math.hxx>
29#include <svl/cjkoptions.hxx>
31#include <vcl/settings.hxx>
32#include <vcl/svapp.hxx>
33#include <comphelper/lok.hxx>
34#include <PostItMgr.hxx>
35
36#define IS_MOBILE_PHONE (comphelper::LibreOfficeKit::isActive() && SfxViewShell::Current() && SfxViewShell::Current()->isLOKMobilePhone())
37
39{
41}
42
43namespace
44{
45 void setValue(weld::Label& rWidget, sal_uLong nValue, const LocaleDataWrapper& rLocaleData)
46 {
47 rWidget.set_label(rLocaleData.getNum(nValue, 0));
48 }
49
50 void setDoubleValue(weld::Label& rWidget, double fValue)
51 {
52 OUString sValue(OUString::number(::rtl::math::round(fValue, 1)));
53 rWidget.set_label(sValue);
54 }
55}
56
57void SwWordCountFloatDlg::SetValues(const SwDocStat& rCurrent, const SwDocStat& rDoc)
58{
60 setValue(*m_xCurrentWordFT, rCurrent.nWord, rLocaleData);
61 setValue(*m_xCurrentCharacterFT, rCurrent.nChar, rLocaleData);
63 setValue(*m_xCurrentCjkcharsFT, rCurrent.nAsianWord, rLocaleData);
64 setValue(*m_xDocWordFT, rDoc.nWord, rLocaleData);
65 setValue(*m_xDocCharacterFT, rDoc.nChar, rLocaleData);
67 setValue(*m_xDocCjkcharsFT, rDoc.nAsianWord, rLocaleData);
68 setValue(*m_xDocComments, rCurrent.nComments, rLocaleData);
69
70 if (m_xStandardizedPagesLabelFT->get_visible())
71 {
72 sal_Int64 nCharsPerStandardizedPage = officecfg::Office::Writer::WordCount::StandardizedPageSize::get();
73 setDoubleValue(*m_xCurrentStandardizedPagesFT,
74 static_cast<double>(rCurrent.nChar) / nCharsPerStandardizedPage);
75 setDoubleValue(*m_xDocStandardizedPagesFT,
76 static_cast<double>(rDoc.nChar) / nCharsPerStandardizedPage);
77 }
78
79 bool bShowCJK = (SvtCJKOptions::IsAnyEnabled() || rDoc.nAsianWord);
80 bool bToggleCJK = m_xCurrentCjkcharsFT->get_visible() != bShowCJK;
81 if (bToggleCJK)
82 {
83 showCJK(bShowCJK);
84 m_xDialog->resize_to_request(); //force resize of dialog
85 }
86}
87
89{
90 m_xCurrentCjkcharsFT->set_visible(bShowCJK);
91 m_xDocCjkcharsFT->set_visible(bShowCJK);
93 m_xCjkcharsLabelFT2->set_visible(bShowCJK);
94 m_xCjkcharsLabelFT->set_visible(bShowCJK);
95}
96
97void SwWordCountFloatDlg::showStandardizedPages(bool bShowStandardizedPages)
98{
99 m_xCurrentStandardizedPagesFT->set_visible(bShowStandardizedPages);
100 m_xDocStandardizedPagesFT->set_visible(bShowStandardizedPages);
102 m_xStandardizedPagesLabelFT2->set_visible(bShowStandardizedPages);
103 m_xStandardizedPagesLabelFT->set_visible(bShowStandardizedPages);
104}
105
107 SfxChildWindow* pChild,
108 weld::Window *pParent,
109 SfxChildWinInfo const * pInfo)
110 : SfxModelessDialogController(_pBindings, pChild, pParent, IS_MOBILE_PHONE ? OUString("modules/swriter/ui/wordcount-mobile.ui") : OUString("modules/swriter/ui/wordcount.ui"), "WordCountDialog")
111 , m_xCurrentWordFT(m_xBuilder->weld_label("selectwords"))
112 , m_xCurrentCharacterFT(m_xBuilder->weld_label("selectchars"))
113 , m_xCurrentCharacterExcludingSpacesFT(m_xBuilder->weld_label("selectcharsnospaces"))
114 , m_xCurrentCjkcharsFT(m_xBuilder->weld_label("selectcjkchars"))
115 , m_xCurrentStandardizedPagesFT(m_xBuilder->weld_label("selectstandardizedpages"))
116 , m_xDocWordFT(m_xBuilder->weld_label("docwords"))
117 , m_xDocCharacterFT(m_xBuilder->weld_label("docchars"))
118 , m_xDocCharacterExcludingSpacesFT(m_xBuilder->weld_label("doccharsnospaces"))
119 , m_xDocCjkcharsFT(m_xBuilder->weld_label("doccjkchars"))
120 , m_xDocStandardizedPagesFT(m_xBuilder->weld_label("docstandardizedpages"))
121 , m_xCjkcharsLabelFT(m_xBuilder->weld_label("cjkcharsft"))
122 , m_xCjkcharsLabelFT2(m_xBuilder->weld_label("cjkcharsft2"))
123 , m_xStandardizedPagesLabelFT(m_xBuilder->weld_label("standardizedpages"))
124 , m_xStandardizedPagesLabelFT2(m_xBuilder->weld_label("standardizedpages2"))
125 , m_xDocComments(m_xBuilder->weld_label("docComments"))
126{
129
130 Initialize(pInfo);
131}
132
134{
135 if (SwView* pView = GetActiveView())
136 {
137 SwWrtShell &rSh = pView->GetWrtShell();
138 SwDocStat aCurrCnt;
139 SwDocStat aDocStat;
140 {
141 auto& rDocShell(*pView->GetDocShell());
142 SwWait aWait(rDocShell, true);
143 auto aLock = rDocShell.LockAllViews();
144 rSh.StartAction();
145 rSh.CountWords( aCurrCnt );
146 aDocStat = rSh.GetUpdatedDocStat();
147 rSh.EndAction();
148 }
149 SwPostItMgr* pPostItMgr = rSh.GetPostItMgr();
150 aCurrCnt.nComments = pPostItMgr->end() - pPostItMgr->begin();
151 SetValues(aCurrCnt, aDocStat);
152 }
153}
154
155void SwWordCountFloatDlg::SetCounts(const SwDocStat &rCurrCnt, const SwDocStat &rDocStat)
156{
157 SetValues(rCurrCnt, rDocStat);
158}
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
const LocaleDataWrapper & GetUILocaleDataWrapper() const
static const AllSettings & GetSettings()
OUString getNum(sal_Int64 nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
void Initialize(SfxChildWinInfo const *pInfo)
void StartAction()
Definition: crsrsh.cxx:226
void EndAction(const bool bIdleEnd=false)
Definition: crsrsh.cxx:243
void CountWords(SwDocStat &rStat) const
Count words in current selection.
Definition: editsh.cxx:1081
const SwDocStat & GetUpdatedDocStat()
Definition: editsh.cxx:432
const_iterator begin() const
Definition: PostItMgr.hxx:180
const_iterator end() const
Definition: PostItMgr.hxx:181
static void SetCareDialog(const std::shared_ptr< weld::Window > &rNew)
Definition: viewsh.cxx:2669
const SwPostItMgr * GetPostItMgr() const
Definition: viewsh.hxx:583
Definition: view.hxx:146
void SetValues(const SwDocStat &rCurrent, const SwDocStat &rDoc)
void SetCounts(const SwDocStat &rCurrCnt, const SwDocStat &rDocStat)
std::unique_ptr< weld::Label > m_xDocComments
std::unique_ptr< weld::Label > m_xCjkcharsLabelFT
std::unique_ptr< weld::Label > m_xDocCjkcharsFT
std::unique_ptr< weld::Label > m_xDocCharacterFT
std::unique_ptr< weld::Label > m_xCjkcharsLabelFT2
std::unique_ptr< weld::Label > m_xDocCharacterExcludingSpacesFT
std::unique_ptr< weld::Label > m_xCurrentCjkcharsFT
std::unique_ptr< weld::Label > m_xCurrentStandardizedPagesFT
std::unique_ptr< weld::Label > m_xDocStandardizedPagesFT
std::unique_ptr< weld::Label > m_xDocWordFT
std::unique_ptr< weld::Label > m_xCurrentCharacterFT
virtual ~SwWordCountFloatDlg() override
std::unique_ptr< weld::Label > m_xCurrentWordFT
SwWordCountFloatDlg(SfxBindings *pBindings, SfxChildWindow *pChild, weld::Window *pParent, SfxChildWinInfo const *pInfo)
std::unique_ptr< weld::Label > m_xStandardizedPagesLabelFT2
void showCJK(bool bShowCJK)
void showStandardizedPages(bool bShowStandardizedPages)
std::unique_ptr< weld::Label > m_xCurrentCharacterExcludingSpacesFT
std::unique_ptr< weld::Label > m_xStandardizedPagesLabelFT
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
virtual void set_label(const OUString &rText)=0
bool IsAnyEnabled()
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)
sal_uIntPtr sal_uLong
sal_uLong nWord
Definition: docstat.hxx:35
sal_uLong nComments
Definition: docstat.hxx:39
sal_uLong nCharExcludingSpaces
Definition: docstat.hxx:38
sal_uLong nAsianWord
Definition: docstat.hxx:36
sal_uLong nChar
Definition: docstat.hxx:37
SwView * GetActiveView()
Definition: swmodul1.cxx:115
#define IS_MOBILE_PHONE