-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This patch adds character and paragraph counting.  It assumes that you
haven't applied my previous word count patch.  If anyone has, I can
probably created a diff for that too.  If you have any problems with it,
let me know.  

           
                                sam th               
                                [EMAIL PROTECTED]
                                        
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE4sN0kt+kM0Mq9M/wRAjiBAJ0bI/DfD796XI4T6b5IWVQSekUzoACg2T8K
S1FPDuQSFM4fAi/QUEi5MJs=
=RcML
-----END PGP SIGNATURE-----
Index: src/af/util/xp/ut_types.h
===================================================================
RCS file: /cvsroot/abi/src/af/util/xp/ut_types.h,v
retrieving revision 1.30
diff -u -r1.30 ut_types.h
--- src/af/util/xp/ut_types.h   2000/01/27 06:15:43     1.30
+++ src/af/util/xp/ut_types.h   2000/02/21 06:30:02
@@ -42,6 +42,13 @@
 typedef                unsigned int            UT_uint32;
 typedef                signed int                      UT_sint32;
 
+typedef struct { 
+  UT_uint32 word;  
+  UT_uint32 para; 
+  UT_uint32 ch;
+} UT_wordCount;
+
+
 /*
        TODO we currently use plain old C 'int' all over the place.
        For many applications, this is inappropriate, and we should change
Index: src/text/fmt/xp/fv_View.cpp
===================================================================
RCS file: /cvsroot/abi/src/text/fmt/xp/fv_View.cpp,v
retrieving revision 1.242
diff -u -r1.242 fv_View.cpp
--- src/text/fmt/xp/fv_View.cpp 2000/02/10 21:32:08     1.242
+++ src/text/fmt/xp/fv_View.cpp 2000/02/21 06:30:03
@@ -4848,4 +4920,82 @@
 
                pView->_updateInsertionPoint();
        }
+}
+
+/******************************************************
+ *****************************************************/
+UT_Bool notChar(UT_UCSChar c)
+{
+  UT_Bool res = UT_FALSE;
+
+  switch (c)
+    {
+    case UCS_TAB:
+    case UCS_LF:
+    case UCS_VTAB:
+    case UCS_FF:
+    case UCS_CR:
+      {
+      res = UT_TRUE;
+      break;
+      }
+    default:
+      break;
+    }
+  return res;
+}
+
+
+UT_wordCount FV_View::countWords(void)
+{
+  UT_wordCount wCount;
+  UT_Bool isPara = UT_FALSE;
+  wCount.word = 0;
+  wCount.para = 0;
+  wCount.ch = 0;
+
+  fl_SectionLayout * pSL = m_pLayout->getFirstSection();
+  while (pSL)
+    {
+      fl_BlockLayout * pBL = pSL->getFirstBlock();
+      while (pBL)
+       {
+         UT_GrowBuf gb(1024);
+         pBL->getBlockBuf(&gb);
+         const UT_UCSChar * pSpan = gb.getPointer(0);
+         UT_uint32 len = gb.getLength();
+         
+         // count words in pSpan[0..len]
+         UT_uint32 i;
+         UT_Bool newWord = UT_FALSE;
+         UT_Bool delim = UT_TRUE;
+         for (i = 0; i < len; i++)
+           {
+             UT_DEBUGMSG(("%c", i));
+             if (!notChar(pSpan[i]))
+               {
+                 wCount.ch++;
+                 isPara = UT_TRUE;
+               }
+             newWord = (delim && !UT_isWordDelimiter(pSpan[i]));
+
+             delim = UT_isWordDelimiter(pSpan[i]);
+             
+             if (newWord)
+               wCount.word++;
+
+           }
+               
+         pBL = pBL->getNext();
+         if (isPara)
+           {
+             wCount.para++;
+             isPara = UT_FALSE;
+           }
+       }
+      pSL = pSL->getNext();
+    }
+  
+
+  return (wCount);
 }
Index: src/text/fmt/xp/fv_View.h
===================================================================
RCS file: /cvsroot/abi/src/text/fmt/xp/fv_View.h,v
retrieving revision 1.108
diff -u -r1.108 fv_View.h
--- src/text/fmt/xp/fv_View.h   2000/02/10 21:32:08     1.108
+++ src/text/fmt/xp/fv_View.h   2000/02/21 06:30:03
@@ -228,6 +228,8 @@
 
 // ----------------------
 
+       UT_wordCount     countWords(void);
+
 protected:
        void                            _generalUpdate(void);
        
@@ -287,6 +289,8 @@
        void                            _clearIfAtFmtMark(PT_DocPosition dpos);
 
        void                            _checkPendingWord(void);
+
+
 
        PT_DocPosition          m_iInsPoint;
        UT_sint32                       m_xPoint;
Index: src/wp/ap/Makefile
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/Makefile,v
retrieving revision 1.57
diff -u -r1.57 Makefile
--- src/wp/ap/Makefile  2000/02/10 21:36:09     1.57
+++ src/wp/ap/Makefile  2000/02/21 06:30:03
@@ -30,6 +30,7 @@
                $(OBJDIR)/ap_$(ABI_FE)Clipboard.$(OBJ_SUFFIX)           \
                $(OBJDIR)/ap_$(ABI_FE)DialogFactory.$(OBJ_SUFFIX)       \
                $(OBJDIR)/ap_$(ABI_FE)Dialog_Break.$(OBJ_SUFFIX)        \
+                $(OBJDIR)/ap_$(ABI_FE)Dialog_WordCount.$(OBJ_SUFFIX)        \
                $(OBJDIR)/ap_$(ABI_FE)Dialog_Field.$(OBJ_SUFFIX)        \
                $(OBJDIR)/ap_$(ABI_FE)Dialog_Insert_DateTime.$(OBJ_SUFFIX)      \
                $(OBJDIR)/ap_$(ABI_FE)Dialog_Options.$(OBJ_SUFFIX)      \
@@ -73,7 +74,9 @@
 endif
 
 OBJS=          $(PLATFORM_OBJS)                                \
+               $(OBJDIR)/ap_Convert.$(OBJ_SUFFIX)              \
                $(OBJDIR)/ap_Dialog_Break.$(OBJ_SUFFIX)         \
+                $(OBJDIR)/ap_Dialog_WordCount.$(OBJ_SUFFIX)        \
                $(OBJDIR)/ap_Dialog_Field.$(OBJ_SUFFIX)         \
                $(OBJDIR)/ap_Dialog_Insert_DateTime.$(OBJ_SUFFIX)               \
                $(OBJDIR)/ap_Dialog_Options.$(OBJ_SUFFIX)       \
Index: src/wp/ap/unix/Makefile
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/unix/Makefile,v
retrieving revision 1.34
diff -u -r1.34 Makefile
--- src/wp/ap/unix/Makefile     2000/02/11 04:20:54     1.34
+++ src/wp/ap/unix/Makefile     2000/02/21 06:30:03
@@ -38,6 +38,7 @@
                        ap_$(ABI_FE)Dialog_Paragraph.cpp        \
                        ap_$(ABI_FE)Dialog_Replace.cpp          \
                        ap_$(ABI_FE)Dialog_Spell.cpp            \
+                       ap_$(ABI_FE)Dialog_WordCount.cpp        \
                        ap_$(ABI_FE)Frame.cpp                   \
                        ap_$(ABI_FE)LeftRuler.cpp               \
                        ap_$(ABI_FE)Prefs.cpp                   \
Index: src/wp/ap/unix/ap_UnixDialog_All.h
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/unix/ap_UnixDialog_All.h,v
retrieving revision 1.23
diff -u -r1.23 ap_UnixDialog_All.h
--- src/wp/ap/unix/ap_UnixDialog_All.h  2000/02/08 01:23:18     1.23
+++ src/wp/ap/unix/ap_UnixDialog_All.h  2000/02/21 06:30:03
@@ -48,6 +48,7 @@
 #      include "ap_UnixDialog_Options.h"
 #      include "ap_UnixDialog_Spell.h"
 #      include "ap_UnixDialog_Insert_DateTime.h"
+#      include "ap_UnixDialog_WordCount.h"
 
 #ifdef HAVE_GNOME
 #   include "xap_UnixGnomeDlg_MessageBox.h"
@@ -78,6 +79,7 @@
        DeclareDialog(AP_DIALOG_ID_SPELL,                       AP_UnixDialog_Spell)
        DeclareDialog(AP_DIALOG_ID_PARAGRAPH,           AP_UnixDialog_Paragraph)       
 
        DeclareDialog(AP_DIALOG_ID_OPTIONS,                     AP_UnixDialog_Options) 
 
+        DeclareDialog(AP_DIALOG_ID_WORDCOUNT,                   
+AP_UnixDialog_WordCount)
 
        // ... also add new dialogs here ...
 #   else
@@ -98,7 +100,7 @@
        DeclareDialog(AP_DIALOG_ID_PARAGRAPH,           AP_UnixDialog_Paragraph)       
 
        DeclareDialog(AP_DIALOG_ID_OPTIONS,                     AP_UnixDialog_Options)
        DeclareDialog(AP_DIALOG_ID_INSERT_DATETIME,     AP_UnixDialog_Insert_DateTime) 
         
-
+        DeclareDialog(AP_DIALOG_ID_WORDCOUNT,                   
+AP_UnixDialog_WordCount)
        // ... also add new dialogs here ...
 #   endif
 
Index: src/wp/ap/xp/Makefile
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/xp/Makefile,v
retrieving revision 1.48
diff -u -r1.48 Makefile
--- src/wp/ap/xp/Makefile       2000/02/10 21:36:10     1.48
+++ src/wp/ap/xp/Makefile       2000/02/21 06:30:03
@@ -32,6 +34,7 @@
                ap_Dialog_Paragraph.cpp         \
                ap_Dialog_Replace.cpp           \
                ap_Dialog_Spell.cpp             \
+               ap_Dialog_WordCount.cpp         \
                ap_EditMethods.cpp              \
                ap_FrameData.cpp                \
                ap_LeftRuler.cpp                \
Index: src/wp/ap/xp/ap_Dialog_Id.h
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/xp/ap_Dialog_Id.h,v
retrieving revision 1.14
diff -u -r1.14 ap_Dialog_Id.h
--- src/wp/ap/xp/ap_Dialog_Id.h 2000/02/10 21:36:10     1.14
+++ src/wp/ap/xp/ap_Dialog_Id.h 2000/02/21 06:30:03
@@ -39,6 +39,7 @@
        AP_DIALOG_ID_OPTIONS,                           /* edit|options settings 
dialog */
        AP_DIALOG_ID_INSERT_DATETIME,           /* insert date and time dialog */
        AP_DIALOG_ID_FIELD,                                     /* insert field dialog 
*/
+       AP_DIALOG_ID_WORDCOUNT,                                 /* word count dialog 
+*/
        /* ... add others here ... */
 
        AP_DIALOG_ID__LAST__                            /* must be last */
Index: src/wp/ap/xp/ap_EditMethods.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/xp/ap_EditMethods.cpp,v
retrieving revision 1.181
diff -u -r1.181 ap_EditMethods.cpp
--- src/wp/ap/xp/ap_EditMethods.cpp     2000/02/17 18:38:07     1.181
+++ src/wp/ap/xp/ap_EditMethods.cpp     2000/02/21 06:30:04
@@ -50,6 +50,7 @@
 #include "ap_Dialog_Spell.h"
 #include "ap_Dialog_Insert_DateTime.h"
 #include "ap_Dialog_Field.h"
+#include "ap_Dialog_WordCount.h"
 
 #include "xap_DialogFactory.h"
 #include "xap_Dlg_About.h"
@@ -4100,15 +4095,38 @@
        return UT_TRUE;
 }
 
-Defun1(dlgWordCount)
+static UT_Bool s_doWordCountDlg(FV_View * pView)
 {
-       XAP_Frame * pFrame = (XAP_Frame *) pAV_View->getParentData();
+       XAP_Frame * pFrame = (XAP_Frame *) pView->getParentData();
        UT_ASSERT(pFrame);
 
-       s_TellNotImplemented(pFrame, "Word Count dialog", __LINE__);
-       return UT_TRUE;
+       pFrame->raise();
+
+       XAP_DialogFactory * pDialogFactory
+               = (XAP_DialogFactory *)(pFrame->getDialogFactory());
+
+       AP_Dialog_WordCount * pDialog
+               = (AP_Dialog_WordCount 
+*)(pDialogFactory->requestDialog(AP_DIALOG_ID_WORDCOUNT));
+       UT_ASSERT(pDialog);
+
+       pDialog->setCount(pView->countWords());
+
+       pDialog->runModal(pFrame);
+       
+       UT_Bool bOK = UT_TRUE;
+
+       pDialogFactory->releaseDialog(pDialog);
+
+       return bOK;
 }
 
+
+Defun1(dlgWordCount)
+{
+        ABIWORD_VIEW;
+       
+       return s_doWordCountDlg(pView);
+}
 
 /****************************************************************/
 /****************************************************************/
Index: src/wp/ap/xp/ap_String_Id.h
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/xp/ap_String_Id.h,v
retrieving revision 1.30
diff -u -r1.30 ap_String_Id.h
--- src/wp/ap/xp/ap_String_Id.h 2000/02/15 07:28:05     1.30
+++ src/wp/ap/xp/ap_String_Id.h 2000/02/21 06:30:04
@@ -66,6 +67,12 @@
 dcl(DLG_Break_Continuous,              "Con&tinuous")
 dcl(DLG_Break_EvenPage,                        "&Even page")
 dcl(DLG_Break_OddPage,                 "&Odd page")
+
+/* Word Count dialog */
+dcl(DLG_WordCount_WordCountTitle,       "Word Count")
+dcl(DLG_WordCount_Words,                "Words")
+dcl(DLG_WordCount_Paragraphs,           "Paragraphs")
+dcl(DLG_WordCount_Characters,           "Characters")
        
 /* Spell dialog */
 dcl(DLG_Spell_SpellTitle,              "Spelling")

Reply via email to