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 <swtypes.hxx>
21 : #include <wordcountdialog.hxx>
22 : #include <docstat.hxx>
23 : #include <dialog.hrc>
24 : #include <cmdid.h>
25 : #include <swmodule.hxx>
26 : #include <wview.hxx>
27 : #include <swwait.hxx>
28 : #include <wrtsh.hxx>
29 : #include <comphelper/string.hxx>
30 : #include <sfx2/viewfrm.hxx>
31 : #include <svl/cjkoptions.hxx>
32 : #include <unotools/localedatawrapper.hxx>
33 : #include <vcl/msgbox.hxx>
34 : #include <vcl/settings.hxx>
35 :
36 0 : IMPL_LINK_NOARG(SwWordCountFloatDlg, CloseHdl)
37 : {
38 0 : SfxViewFrame* pVFrame = ::GetActiveView()->GetViewFrame();
39 0 : if (pVFrame != NULL)
40 : {
41 0 : pVFrame->ToggleChildWindow(FN_WORDCOUNT_DIALOG);
42 : }
43 0 : return 0;
44 : }
45 :
46 0 : SwWordCountFloatDlg::~SwWordCountFloatDlg()
47 : {
48 0 : SwViewShell::SetCareWin( 0 );
49 0 : }
50 :
51 : namespace
52 : {
53 0 : void setValue(FixedText *pWidget, sal_uLong nValue, const LocaleDataWrapper& rLocaleData)
54 : {
55 0 : pWidget->SetText(rLocaleData.getNum(nValue, 0));
56 0 : }
57 : }
58 :
59 0 : void SwWordCountFloatDlg::SetValues(const SwDocStat& rCurrent, const SwDocStat& rDoc)
60 : {
61 0 : const LocaleDataWrapper& rLocaleData = GetSettings().GetUILocaleDataWrapper();
62 0 : setValue(m_pCurrentWordFT, rCurrent.nWord, rLocaleData);
63 0 : setValue(m_pCurrentCharacterFT, rCurrent.nChar, rLocaleData);
64 0 : setValue(m_pCurrentCharacterExcludingSpacesFT, rCurrent.nCharExcludingSpaces, rLocaleData);
65 0 : setValue(m_pCurrentCjkcharsFT, rCurrent.nAsianWord, rLocaleData);
66 0 : setValue(m_pDocWordFT, rDoc.nWord, rLocaleData);
67 0 : setValue(m_pDocCharacterFT, rDoc.nChar, rLocaleData);
68 0 : setValue(m_pDocCharacterExcludingSpacesFT, rDoc.nCharExcludingSpaces, rLocaleData);
69 0 : setValue(m_pDocCjkcharsFT, rDoc.nAsianWord, rLocaleData);
70 :
71 0 : bool bShowCJK = (SvtCJKOptions().IsAnyEnabled() || rDoc.nAsianWord);
72 0 : bool bToggleCJK = m_pCurrentCjkcharsFT->IsVisible() != bShowCJK;
73 0 : if (bToggleCJK)
74 : {
75 0 : showCJK(bShowCJK);
76 0 : setOptimalLayoutSize(); //force resize of dialog
77 : }
78 0 : }
79 :
80 0 : void SwWordCountFloatDlg::showCJK(bool bShowCJK)
81 : {
82 0 : m_pCurrentCjkcharsFT->Show(bShowCJK);
83 0 : m_pDocCjkcharsFT->Show(bShowCJK);
84 0 : m_pCjkcharsLabelFT->Show(bShowCJK);
85 0 : }
86 :
87 0 : SwWordCountFloatDlg::SwWordCountFloatDlg(SfxBindings* _pBindings,
88 : SfxChildWindow* pChild,
89 : Window *pParent,
90 : SfxChildWinInfo* pInfo)
91 0 : : SfxModelessDialog(_pBindings, pChild, pParent, "WordCountDialog", "modules/swriter/ui/wordcount.ui")
92 : {
93 0 : get(m_pCurrentWordFT, "selectwords");
94 0 : get(m_pCurrentCharacterFT, "selectchars");
95 0 : get(m_pCurrentCharacterExcludingSpacesFT, "selectcharsnospaces");
96 0 : get(m_pCurrentCjkcharsFT, "selectcjkchars");
97 :
98 0 : get(m_pDocWordFT, "docwords");
99 0 : get(m_pDocCharacterFT, "docchars");
100 0 : get(m_pDocCharacterExcludingSpacesFT, "doccharsnospaces");
101 0 : get(m_pDocCjkcharsFT, "doccjkchars");
102 :
103 0 : get(m_pCjkcharsLabelFT, "cjkcharsft");
104 :
105 0 : get(m_pClosePB, "close");
106 :
107 0 : showCJK(SvtCJKOptions().IsAnyEnabled());
108 :
109 0 : Initialize(pInfo);
110 :
111 0 : m_pClosePB->SetClickHdl(LINK(this, SwWordCountFloatDlg, CloseHdl));
112 0 : m_pClosePB->GrabFocus();
113 0 : }
114 :
115 0 : void SwWordCountFloatDlg::Activate()
116 : {
117 0 : SfxModelessDialog::Activate();
118 0 : }
119 :
120 0 : void SwWordCountFloatDlg::UpdateCounts()
121 : {
122 0 : SwWrtShell &rSh = ::GetActiveView()->GetWrtShell();
123 0 : SwDocStat aCurrCnt;
124 0 : SwDocStat aDocStat;
125 : {
126 0 : SwWait aWait( *::GetActiveView()->GetDocShell(), true );
127 0 : rSh.StartAction();
128 0 : rSh.CountWords( aCurrCnt );
129 0 : aDocStat = rSh.GetUpdatedDocStat();
130 0 : rSh.EndAction();
131 : }
132 0 : SetValues(aCurrCnt, aDocStat);
133 0 : }
134 :
135 0 : void SwWordCountFloatDlg::SetCounts(const SwDocStat &rCurrCnt, const SwDocStat &rDocStat)
136 : {
137 0 : SetValues(rCurrCnt, rDocStat);
138 0 : }
139 :
140 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|