1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <officecfg/Office/Writer.hxx>
21 #include <wordcountdialog.hxx>
23 #include <docstat.hxx>
24 #include <swmodule.hxx>
28 #include <rtl/math.hxx>
29 #include <svl/cjkoptions.hxx>
30 #include <unotools/localedatawrapper.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/svapp.hxx>
33 #include <comphelper/lok.hxx>
35 #define IS_MOBILE_PHONE (comphelper::LibreOfficeKit::isActive() && SfxViewShell::Current() && SfxViewShell::Current()->isLOKMobilePhone())
37 SwWordCountFloatDlg::~SwWordCountFloatDlg()
39 SwViewShell::SetCareDialog(nullptr);
44 void setValue(weld::Label
& rWidget
, sal_uLong nValue
, const LocaleDataWrapper
& rLocaleData
)
46 rWidget
.set_label(rLocaleData
.getNum(nValue
, 0));
49 void setDoubleValue(weld::Label
& rWidget
, double fValue
)
51 OUString
sValue(OUString::number(::rtl::math::round(fValue
, 1)));
52 rWidget
.set_label(sValue
);
56 void SwWordCountFloatDlg::SetValues(const SwDocStat
& rCurrent
, const SwDocStat
& rDoc
)
58 const LocaleDataWrapper
& rLocaleData
= Application::GetSettings().GetUILocaleDataWrapper();
59 setValue(*m_xCurrentWordFT
, rCurrent
.nWord
, rLocaleData
);
60 setValue(*m_xCurrentCharacterFT
, rCurrent
.nChar
, rLocaleData
);
61 setValue(*m_xCurrentCharacterExcludingSpacesFT
, rCurrent
.nCharExcludingSpaces
, rLocaleData
);
62 setValue(*m_xCurrentCjkcharsFT
, rCurrent
.nAsianWord
, rLocaleData
);
63 setValue(*m_xDocWordFT
, rDoc
.nWord
, rLocaleData
);
64 setValue(*m_xDocCharacterFT
, rDoc
.nChar
, rLocaleData
);
65 setValue(*m_xDocCharacterExcludingSpacesFT
, rDoc
.nCharExcludingSpaces
, rLocaleData
);
66 setValue(*m_xDocCjkcharsFT
, rDoc
.nAsianWord
, rLocaleData
);
68 if (m_xStandardizedPagesLabelFT
->get_visible())
70 sal_Int64 nCharsPerStandardizedPage
= officecfg::Office::Writer::WordCount::StandardizedPageSize::get();
71 setDoubleValue(*m_xCurrentStandardizedPagesFT
,
72 static_cast<double>(rCurrent
.nChar
) / nCharsPerStandardizedPage
);
73 setDoubleValue(*m_xDocStandardizedPagesFT
,
74 static_cast<double>(rDoc
.nChar
) / nCharsPerStandardizedPage
);
77 bool bShowCJK
= (SvtCJKOptions::IsAnyEnabled() || rDoc
.nAsianWord
);
78 bool bToggleCJK
= m_xCurrentCjkcharsFT
->get_visible() != bShowCJK
;
82 m_xDialog
->resize_to_request(); //force resize of dialog
86 void SwWordCountFloatDlg::showCJK(bool bShowCJK
)
88 m_xCurrentCjkcharsFT
->set_visible(bShowCJK
);
89 m_xDocCjkcharsFT
->set_visible(bShowCJK
);
90 if (IS_MOBILE_PHONE
&& m_xCjkcharsLabelFT2
)
91 m_xCjkcharsLabelFT2
->set_visible(bShowCJK
);
92 m_xCjkcharsLabelFT
->set_visible(bShowCJK
);
95 void SwWordCountFloatDlg::showStandardizedPages(bool bShowStandardizedPages
)
97 m_xCurrentStandardizedPagesFT
->set_visible(bShowStandardizedPages
);
98 m_xDocStandardizedPagesFT
->set_visible(bShowStandardizedPages
);
99 if (IS_MOBILE_PHONE
&& m_xStandardizedPagesLabelFT2
)
100 m_xStandardizedPagesLabelFT2
->set_visible(bShowStandardizedPages
);
101 m_xStandardizedPagesLabelFT
->set_visible(bShowStandardizedPages
);
104 SwWordCountFloatDlg::SwWordCountFloatDlg(SfxBindings
* _pBindings
,
105 SfxChildWindow
* pChild
,
106 weld::Window
*pParent
,
107 SfxChildWinInfo
const * pInfo
)
108 : SfxModelessDialogController(_pBindings
, pChild
, pParent
, IS_MOBILE_PHONE
? OUString("modules/swriter/ui/wordcount-mobile.ui") : OUString("modules/swriter/ui/wordcount.ui"), "WordCountDialog")
109 , m_xCurrentWordFT(m_xBuilder
->weld_label("selectwords"))
110 , m_xCurrentCharacterFT(m_xBuilder
->weld_label("selectchars"))
111 , m_xCurrentCharacterExcludingSpacesFT(m_xBuilder
->weld_label("selectcharsnospaces"))
112 , m_xCurrentCjkcharsFT(m_xBuilder
->weld_label("selectcjkchars"))
113 , m_xCurrentStandardizedPagesFT(m_xBuilder
->weld_label("selectstandardizedpages"))
114 , m_xDocWordFT(m_xBuilder
->weld_label("docwords"))
115 , m_xDocCharacterFT(m_xBuilder
->weld_label("docchars"))
116 , m_xDocCharacterExcludingSpacesFT(m_xBuilder
->weld_label("doccharsnospaces"))
117 , m_xDocCjkcharsFT(m_xBuilder
->weld_label("doccjkchars"))
118 , m_xDocStandardizedPagesFT(m_xBuilder
->weld_label("docstandardizedpages"))
119 , m_xCjkcharsLabelFT(m_xBuilder
->weld_label("cjkcharsft"))
120 , m_xCjkcharsLabelFT2(m_xBuilder
->weld_label("cjkcharsft2"))
121 , m_xStandardizedPagesLabelFT(m_xBuilder
->weld_label("standardizedpages"))
122 , m_xStandardizedPagesLabelFT2(m_xBuilder
->weld_label("standardizedpages2"))
124 showCJK(SvtCJKOptions::IsAnyEnabled());
125 showStandardizedPages(officecfg::Office::Writer::WordCount::ShowStandardizedPageCount::get());
130 void SwWordCountFloatDlg::UpdateCounts()
132 if (SwView
* pView
= GetActiveView())
134 SwWrtShell
&rSh
= pView
->GetWrtShell();
138 auto& rDocShell(*pView
->GetDocShell());
139 SwWait
aWait(rDocShell
, true);
140 auto aLock
= rDocShell
.LockAllViews();
142 rSh
.CountWords( aCurrCnt
);
143 aDocStat
= rSh
.GetUpdatedDocStat();
146 SetValues(aCurrCnt
, aDocStat
);
150 void SwWordCountFloatDlg::SetCounts(const SwDocStat
&rCurrCnt
, const SwDocStat
&rDocStat
)
152 SetValues(rCurrCnt
, rDocStat
);
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */