openoffice-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ariel Constenla-Haile <>
Subject Re: Help finding word count bug in source
Date Thu, 26 Mar 2015 09:58:52 GMT
Hi Erik,

On Mon, Mar 23, 2015 at 10:55:00PM -0400, Erik Engstrom wrote:
> Hey developers,
> I'd like to work on a fix for issue #121672, but I'm not sure where to look
> in the source code for the word count function. Could anyone give me a hint
> as to where to look?

I only know a little about application framework, not Writer code; but
this is what I'd do to find the code. There are different approaches,
but I will search the UNO command (you could also search the dialog
title in src files):

- Start from the UI. The menu that triggers the Word Count dialog has
  the text "Word Count". All commands in toolbars and menus are
  identified by a single string named the UNO command; this command is
  bound to a string describing the feature in the UI, this binding is made
  in configuration files under
  Let's find the UNO command for this string:
  Full Search: "Word Count"
  File Path: xcu
  In Project(s): aoo-trunk
  The string is here:
  The command is ".uno:WordCountDialog"

- the UNO command represents a feature that has states (can be
  enabled/disabled, checked/unchecked, etc.) and can be executed
  ("dispatched"). Every item in a toolbar/menu/statusbar is managed in
  the application framework by a controller that listens for status
  updates at a dispatch object, which is also responsible of execute the
  Once you have the UNO command, find where is the code that dispatches
  the command and/or provides its state.
  In applications based on the application framework (chart2, dbaccess,
  reportdesign), this would be rather straight-forward. The other
  applications are based on the old SFX2 framework, and is more
  complicated to understand. You can find a technical explanation here
  and some examples in this message

  In the sfx2 world you need to find the slot definition and the shell
  interface(s) that has(have) the methods that provide the state and execution.
  We search the UNO command without the protocol part:
  Full Search: WordCountDialog
  File Path: sdi
  The slot is defined in main/sw/sdi/swriter.sdi
  SfxVoidItem WordCountDialog FN_WORDCOUNT_DIALOG

  With the ID, FN_WORDCOUNT_DIALOG you can search the shell interfaces:
  and the implementation:

The code does basically the same in the different shells:

You can set a break point in any of them, they lead you to:

void SwDoc::CountWords( const SwPaM& rPaM, SwDocStat& rStat ) const

void SwTxtNode::CountWords( SwDocStat& rStat, xub_StrLen nStt, xub_StrLen nEnd ) const

It seams that

a) word counting is done on a text node basis; this
information is cached on the text node, that is, when you insert a new
word the whole document isn't counted again and again (look for
SetWordCountDirty, it will tell you when this information is

b) in the end, Writer uses the break iterator API. I do the same in this
I get the word count for the whole document from the document
statistics, so the bug is there too. But for the selection I use the
break iterator manually, and you'll see that the bug isn't reproducible
in the statusbar control (unfortunately there is no way to cache word
count using the API, so the selection word count is limited to a certain
amount of text). In short, I guess that the bug is not in the break iterator
code but in Writer.


If you wanted to take the other approach, search the dialog title:

- dialogs are defined in .src files, so search the following:
  the result is

- Get the ID of the dialog and search it in the source:

-  SwWordCountDialog will lead you to the dialog factory:
  which creates a AbstractSwWordCountDialog

- search that dialog, you'll get the shells:


Hope this helps you getting started.

Ariel Constenla-Haile
La Plata, Argentina

View raw message