From ce14342c4292628a641a72d4f63d9c048e030c6a Mon Sep 17 00:00:00 2001 From: Muhammad Haggag Date: Tue, 22 May 2012 16:59:37 +0200 Subject: fdo#34772 Add word count to the status bar in writer This change adds a new status bar control, "SwWordCountStatusBarControl". The control shows the number of words selected as well as the number of words in the whole document. Double-clicking the control launches the modeless word count dialog. Change-Id: I756183ab1aaf4d059e782dfb05508370178cfbe3 --- sw/Library_sw.mk | 1 + sw/inc/cmdid.h | 1 + sw/sdi/_viewsh.sdi | 5 +++++ sw/sdi/swriter.sdi | 25 ++++++++++++++++++++++ sw/sdi/viewsh.sdi | 23 +++++++++++++-------- sw/source/ui/app/swmodule.cxx | 2 ++ sw/source/ui/inc/wordcountctrl.hxx | 32 +++++++++++++++++++++++++++++ sw/source/ui/uiview/view2.cxx | 27 ++++++++++++++++++++++++ sw/source/ui/utlui/wordcountctrl.cxx | 26 +++++++++++++++++++++++ sw/uiconfig/swriter/statusbar/statusbar.xml | 1 + 10 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 sw/source/ui/inc/wordcountctrl.hxx create mode 100644 sw/source/ui/utlui/wordcountctrl.cxx (limited to 'sw') diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk index 45975a0f800a..1ddc142c108c 100644 --- a/sw/Library_sw.mk +++ b/sw/Library_sw.mk @@ -708,6 +708,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\ sw/source/ui/utlui/uitool \ sw/source/ui/utlui/unotools \ sw/source/ui/utlui/viewlayoutctrl \ + sw/source/ui/utlui/wordcountctrl \ sw/source/ui/utlui/zoomctrl \ sw/source/ui/web/wdocsh \ sw/source/ui/web/wformsh \ diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h index 7802db719670..ca5a87296f86 100644 --- a/sw/inc/cmdid.h +++ b/sw/inc/cmdid.h @@ -1165,6 +1165,7 @@ included in c-context files, so c++ style stuff will cause problems. #define FN_STAT_SELMODE (FN_STAT + 5) #define FN_STAT_CONTEXT (FN_STAT + 7) #define FN_STAT_BOOKMARK (FN_STAT + 8) /* For Popup Bookmarks*/ +#define FN_STAT_WORDCOUNT (FN_STAT + 9) /*-------------------------------------------------------------------- Region: Page preview diff --git a/sw/sdi/_viewsh.sdi b/sw/sdi/_viewsh.sdi index a17fbb8f5742..d4486af83a36 100644 --- a/sw/sdi/_viewsh.sdi +++ b/sw/sdi/_viewsh.sdi @@ -317,6 +317,11 @@ interface BaseTextEditView ExecMethod = ExecuteStatusLine ; StateMethod = StateStatusLine ; ] + FN_STAT_WORDCOUNT // status() + [ + ExecMethod = ExecuteStatusLine ; + StateMethod = StateStatusLine ; + ] FN_STAT_BOOKMARK // status() [ ExecMethod = ExecuteStatusLine ; diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi index edb780916471..89e1530ca803 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -8026,6 +8026,31 @@ SfxStringItem StateZoom FN_STAT_ZOOM GroupId = GID_EDIT; ] +//-------------------------------------------------------------------------- +SfxStringItem StateWordCount FN_STAT_WORDCOUNT +() +[ + /* flags: */ + AutoUpdate = FALSE, + Cachable = Cachable, + FastCall = FALSE, + HasCoreId = FALSE, + HasDialog = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + Synchron; + + /* config: */ + AccelConfig = FALSE, + MenuConfig = FALSE, + StatusBarConfig = TRUE, + ToolBoxConfig = FALSE, + GroupId = GID_VIEW; +] + //-------------------------------------------------------------------------- SfxBoolItem SubScript FN_SET_SUB_SCRIPT diff --git a/sw/sdi/viewsh.sdi b/sw/sdi/viewsh.sdi index 1005c96040a1..d5d8380d29c9 100644 --- a/sw/sdi/viewsh.sdi +++ b/sw/sdi/viewsh.sdi @@ -275,8 +275,8 @@ interface TextPrintPreview [ StateMethod = StateUndo ; ] - //--------------------------------------------------------------------- - //Ab hier Statusleiste + //--------------------------------------------------------------------- + // Begin StatusBar FN_STAT_ZOOM // status() [ ExecMethod = Execute ; @@ -307,13 +307,18 @@ interface TextPrintPreview ExecMethod = Execute ; StateMethod = GetState ; ] - SID_ATTR_ZOOMSLIDER // status() - [ - ExecMethod = Execute ; - StateMethod = GetState ; - ] - //---------------------------------------------- - //End mit Statusleiste + SID_ATTR_ZOOMSLIDER // status() + [ + ExecMethod = Execute ; + StateMethod = GetState ; + ] + FN_STAT_WORDCOUNT // status() + [ + ExecMethod = Execute ; + StateMethod = GetState ; + ] + //---------------------------------------------- + // End StatusBar } //========================================================================= diff --git a/sw/source/ui/app/swmodule.cxx b/sw/source/ui/app/swmodule.cxx index 03bb5a2bb5e7..4c975246d1b3 100644 --- a/sw/source/ui/app/swmodule.cxx +++ b/sw/source/ui/app/swmodule.cxx @@ -107,6 +107,7 @@ #include #include #include +#include #include #include #include @@ -372,6 +373,7 @@ void SwDLL::RegisterControls() SvxInsertStatusBarControl::RegisterControl(SID_ATTR_INSERT, pMod ); SvxSelectionModeControl::RegisterControl(FN_STAT_SELMODE, pMod ); XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE, pMod ); + SwWordCountStatusBarControl::RegisterControl(FN_STAT_WORDCOUNT, pMod); SwBookmarkControl::RegisterControl(FN_STAT_PAGE, pMod ); SwTemplateControl::RegisterControl(FN_STAT_TEMPLATE, pMod ); diff --git a/sw/source/ui/inc/wordcountctrl.hxx b/sw/source/ui/inc/wordcountctrl.hxx new file mode 100644 index 000000000000..d62652f13723 --- /dev/null +++ b/sw/source/ui/inc/wordcountctrl.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright 2012 LibreOffice contributors. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef _WORDCOUNTCTRL_HXX +#define _WORDCOUNTCTRL_HXX + +#include + +/** +Word count status bar control for Writer. + +@remarks This is a simple status bar control of type SfxStringItem, and it has no custom +logic whatsoever. The actual updating of the word count string happens in +SwView::StateStatusLine (see sw/source/ui/uiview/view2.cxx). +*/ +class SwWordCountStatusBarControl : public SfxStatusBarControl +{ +public: + SFX_DECL_STATUSBAR_CONTROL(); + + SwWordCountStatusBarControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar& rStb); + ~SwWordCountStatusBarControl(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/uiview/view2.cxx b/sw/source/ui/uiview/view2.cxx index febc0764ba2d..9292185b5c96 100644 --- a/sw/source/ui/uiview/view2.cxx +++ b/sw/source/ui/uiview/view2.cxx @@ -140,6 +140,7 @@ #include #include #include +#include const char sStatusDelim[] = " : "; const char sStatusComma[] = " , ";//#outlinelevel, define a Variable for "," add by zhaojianwei @@ -1197,6 +1198,25 @@ void SwView::StateStatusLine(SfxItemSet &rSet) } } break; + + case FN_STAT_WORDCOUNT: + { + SwDocStat selectionStats; + SwDocStat documentStats; + { + SwWait aWait( *GetDocShell(), sal_True ); + rShell.StartAction(); + rShell.CountWords(selectionStats); + documentStats = rShell.GetUpdatedDocStat(); + rShell.EndAction(); + } + rSet.Put(SfxStringItem(FN_STAT_WORDCOUNT, rtl::OUStringBuffer("Words: ") + .append(rtl::OUString::valueOf(static_cast(selectionStats.nWord))) + .append('/') + .append(rtl::OUString::valueOf(static_cast(documentStats.nWord))).makeStringAndClear())); + } + break; + case FN_STAT_TEMPLATE: { rSet.Put(SfxStringItem( FN_STAT_TEMPLATE, @@ -1471,6 +1491,13 @@ void SwView::ExecuteStatusLine(SfxRequest &rReq) } break; + case FN_STAT_WORDCOUNT: + { + GetViewFrame()->GetDispatcher()->Execute(FN_WORDCOUNT_DIALOG, + SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD ); + } + break; + case FN_STAT_BOOKMARK: if ( pArgs ) { diff --git a/sw/source/ui/utlui/wordcountctrl.cxx b/sw/source/ui/utlui/wordcountctrl.cxx new file mode 100644 index 000000000000..a0146d0e1579 --- /dev/null +++ b/sw/source/ui/utlui/wordcountctrl.cxx @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright 2012 LibreOffice contributors. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include "wordcountctrl.hxx" +#include + +SFX_IMPL_STATUSBAR_CONTROL(SwWordCountStatusBarControl, SfxStringItem); + +SwWordCountStatusBarControl::SwWordCountStatusBarControl( + sal_uInt16 _nSlotId, + sal_uInt16 _nId, + StatusBar& rStb) : + SfxStatusBarControl(_nSlotId, _nId, rStb) +{ +} + +SwWordCountStatusBarControl::~SwWordCountStatusBarControl() +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/uiconfig/swriter/statusbar/statusbar.xml b/sw/uiconfig/swriter/statusbar/statusbar.xml index 87b3edda2d82..d5e2271952a7 100644 --- a/sw/uiconfig/swriter/statusbar/statusbar.xml +++ b/sw/uiconfig/swriter/statusbar/statusbar.xml @@ -2,6 +2,7 @@ + -- cgit v1.2.3