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 <swtypes.hxx>
21 #include <wordcountdialog.hxx>
22 #include <docstat.hxx>
25 #include <swmodule.hxx>
29 #include <comphelper/string.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <svl/cjkoptions.hxx>
32 #include <vcl/msgbox.hxx>
34 IMPL_LINK_NOARG(SwWordCountFloatDlg
, CloseHdl
)
36 SfxViewFrame
* pVFrame
= ::GetActiveView()->GetViewFrame();
39 pVFrame
->ToggleChildWindow(FN_WORDCOUNT_DIALOG
);
44 SwWordCountFloatDlg::~SwWordCountFloatDlg()
46 ViewShell::SetCareWin( 0 );
51 void setValue(FixedText
*pWidget
, sal_uLong nValue
)
53 OUString
sValue(OUString::number(nValue
));
54 pWidget
->SetText(sValue
);
58 void SwWordCountFloatDlg::SetValues(const SwDocStat
& rCurrent
, const SwDocStat
& rDoc
)
60 setValue(m_pCurrentWordFT
, rCurrent
.nWord
);
61 setValue(m_pCurrentCharacterFT
, rCurrent
.nChar
);
62 setValue(m_pCurrentCharacterExcludingSpacesFT
, rCurrent
.nCharExcludingSpaces
);
63 setValue(m_pCurrentCjkcharsFT
, rCurrent
.nAsianWord
);
64 setValue(m_pDocWordFT
, rDoc
.nWord
);
65 setValue(m_pDocCharacterFT
, rDoc
.nChar
);
66 setValue(m_pDocCharacterExcludingSpacesFT
, rDoc
.nCharExcludingSpaces
);
67 setValue(m_pDocCjkcharsFT
, rDoc
.nAsianWord
);
69 bool bShowCJK
= (SvtCJKOptions().IsAnyEnabled() || rDoc
.nAsianWord
);
70 bool bToggleCJK
= m_pCurrentCjkcharsFT
->IsVisible() != static_cast<sal_Bool
>(bShowCJK
);
74 setOptimalLayoutSize(); //force resize of dialog
78 void SwWordCountFloatDlg::showCJK(bool bShowCJK
)
80 m_pCurrentCjkcharsFT
->Show(bShowCJK
);
81 m_pDocCjkcharsFT
->Show(bShowCJK
);
82 m_pCjkcharsLabelFT
->Show(bShowCJK
);
85 SwWordCountFloatDlg::SwWordCountFloatDlg(SfxBindings
* _pBindings
,
86 SfxChildWindow
* pChild
,
88 SfxChildWinInfo
* pInfo
)
89 : SfxModelessDialog(_pBindings
, pChild
, pParent
, "WordCountDialog", "modules/swriter/ui/wordcount.ui")
91 get(m_pCurrentWordFT
, "selectwords");
92 get(m_pCurrentCharacterFT
, "selectchars");
93 get(m_pCurrentCharacterExcludingSpacesFT
, "selectcharsnospaces");
94 get(m_pCurrentCjkcharsFT
, "selectcjkchars");
96 get(m_pDocWordFT
, "docwords");
97 get(m_pDocCharacterFT
, "docchars");
98 get(m_pDocCharacterExcludingSpacesFT
, "doccharsnospaces");
99 get(m_pDocCjkcharsFT
, "doccjkchars");
101 get(m_pCjkcharsLabelFT
, "cjkcharsft");
103 get(m_pClosePB
, "close");
105 showCJK(SvtCJKOptions().IsAnyEnabled());
109 m_pClosePB
->SetClickHdl(LINK(this, SwWordCountFloatDlg
, CloseHdl
));
110 m_pClosePB
->GrabFocus();
113 void SwWordCountFloatDlg::Activate()
115 SfxModelessDialog::Activate();
118 void SwWordCountFloatDlg::UpdateCounts()
120 SwWrtShell
&rSh
= ::GetActiveView()->GetWrtShell();
124 SwWait
aWait( *::GetActiveView()->GetDocShell(), sal_True
);
126 rSh
.CountWords( aCurrCnt
);
127 aDocStat
= rSh
.GetUpdatedDocStat();
130 SetValues(aCurrCnt
, aDocStat
);
133 void SwWordCountFloatDlg::SetCounts(const SwDocStat
&rCurrCnt
, const SwDocStat
&rDocStat
)
135 SetValues(rCurrCnt
, rDocStat
);
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */