PATCH: Fix 5209

From: William Lachance (william.lachance@sympatico.ca)
Date: Sun Jul 20 2003 - 01:03:09 EDT

  • Next message: Marc Maurer: "Commit: lots of goodies & cleanup"

    Hi all,

    This updates the XP and Unix status bar code so that the encoding is
    taken into account when updating the status bar fields (instead of
    naively stuffing all the ascii-encoded info into a UCS4 buffer).

    It also changes the encoding used in the status bar internal structures
    to UTF8, and the status bar now uses string classes instead of
    fixed-length buffers. I also added a new constructor to UT_UTF8String
    which does a conversion of an arbitrarily encoded ascii string to utf8
    (using iconv). Oh, and ap_StatusBar.cpp is now formatted according to
    AbiWord coding style guidelines.

    I'm not entirely happy with the OO design of the statusbar class (we do
    some gross things) and it's debatable whether or not we should be using
    UTF8 here (vs. UCS4). But the code works (checked with Valgrind, etc.)
    and is more robust than before (and it's not really a complex enough
    beast to really get -that- worked up over).

    The reason I'm posting this patch is that the platform specific code
    (other than Unix) needs some updates. I think it should only be 1 or 2
    lines in ap_Win32Statusbar.cpp. Could Jordi or someone else do the
    necessarily legwork and commit this patch?

    -- 
    William Lachance <william.lachance@sympatico.ca>
    

    ? Untitled1.abw.CRASHED
    ? autom4te.cache
    ? out.diff
    ? statusbar.patch
    Index: src/af/util/xp/ut_string_class.cpp
    ===================================================================
    RCS file: /cvsroot/abi/src/af/util/xp/ut_string_class.cpp,v
    retrieving revision 1.48
    diff --unified -r1.48 ut_string_class.cpp
    --- src/af/util/xp/ut_string_class.cpp 16 Jul 2003 08:51:09 -0000 1.48
    +++ src/af/util/xp/ut_string_class.cpp 20 Jul 2003 01:21:33 -0000
    @@ -33,6 +33,7 @@
     #include "ut_string_class.h"
     #include "ut_stringbuf.h"
     #include "ut_debugmsg.h" // UT_DEBUGMSG
    +#include "ut_iconv.h"
     #include "ut_assert.h" // UT_ASSERT
     
     //
    @@ -733,6 +734,20 @@
             //
     }
     
    +UT_UTF8String::UT_UTF8String (const char *str, const char *encoding)
    +{
    + UT_uint32 iRead, iWritten;
    + char *pUTF8Buf = UT_convert(str,
    + strlen(str),
    + encoding,
    + "UTF-8",
    + &iRead,
    + &iWritten);
    + pimpl = new UT_UTF8Stringbuf(pUTF8Buf);
    + FREEP(pUTF8Buf);
    +}
    +
    +
     UT_UTF8String::UT_UTF8String (const UT_UTF8String & rhs) :
             pimpl(new UT_UTF8Stringbuf(*rhs.pimpl))
     {
    Index: src/af/util/xp/ut_string_class.h
    ===================================================================
    RCS file: /cvsroot/abi/src/af/util/xp/ut_string_class.h,v
    retrieving revision 1.36
    diff --unified -r1.36 ut_string_class.h
    --- src/af/util/xp/ut_string_class.h 26 Jun 2003 00:39:49 -0000 1.36
    +++ src/af/util/xp/ut_string_class.h 20 Jul 2003 01:21:33 -0000
    @@ -169,7 +169,9 @@
             virtual const char * GenericBaseID () const;
     
             UT_UTF8String ();
    - UT_UTF8String (const char * sz);
    + UT_UTF8String (const char * sz);
    + UT_UTF8String (const char *sz, const char *encoding);
    +
             UT_UTF8String (const UT_UTF8String & rhs);
             UT_UTF8String (const UT_UCS4String & rhs);
             UT_UTF8String (const UT_UCSChar * sz, size_t n = 0 /* 0 == zero-terminate */);
    @@ -194,8 +196,7 @@
             // The returned pointer is valid until the next non-const
             // operation. You will _always_ get a legal pointer back,
             // even if to an empty (0) string.
    - const char * utf8_str () const;
    -
    + const char * utf8_str () const;
             UT_UCS4String ucs4_str ();
     
             void appendUCS4 (const UT_UCS4Char * sz, size_t n = 0 /* 0 == zero-terminate */);
    Index: src/wp/ap/unix/ap_UnixStatusBar.cpp
    ===================================================================
    RCS file: /cvsroot/abi/src/wp/ap/unix/ap_UnixStatusBar.cpp,v
    retrieving revision 1.27
    diff --unified -r1.27 ap_UnixStatusBar.cpp
    --- src/wp/ap/unix/ap_UnixStatusBar.cpp 6 Jun 2003 01:57:30 -0000 1.27
    +++ src/wp/ap/unix/ap_UnixStatusBar.cpp 20 Jul 2003 01:21:36 -0000
    @@ -45,10 +45,8 @@
             UT_ASSERT(m_pLabel);
     
             AP_StatusBarField_TextInfo * textInfo = ((AP_StatusBarField_TextInfo *)m_pStatusBarField);
    - const UT_UCS4Char * buf = textInfo->getBufUCS();
    - UT_UTF8String utf8 (buf);
     
    - gtk_label_set_label(GTK_LABEL(m_pLabel), utf8.utf8_str());
    + gtk_label_set_label(GTK_LABEL(m_pLabel), textInfo->getBuf().utf8_str());
     
             // we conditionally update the size request, if the representative string (or an earlier
             // size) wasn't large enough, if the element uses the representative string method
    Index: src/wp/ap/xp/ap_StatusBar.cpp
    ===================================================================
    RCS file: /cvsroot/abi/src/wp/ap/xp/ap_StatusBar.cpp,v
    retrieving revision 1.40
    diff --unified -r1.40 ap_StatusBar.cpp
    --- src/wp/ap/xp/ap_StatusBar.cpp 18 May 2003 18:49:46 -0000 1.40
    +++ src/wp/ap/xp/ap_StatusBar.cpp 20 Jul 2003 01:21:37 -0000
    @@ -49,25 +49,23 @@
     
     AP_StatusBarField::AP_StatusBarField(AP_StatusBar * pSB)
     {
    - m_pSB = pSB;
    - m_pStatusBarFieldListener = NULL;
    - m_fillMethod = MAX_POSSIBLE;
    + m_pSB = pSB;
    + m_pStatusBarFieldListener = NULL;
    + m_fillMethod = MAX_POSSIBLE;
     }
     
     AP_StatusBarField::~AP_StatusBarField(void)
     {
    - if(m_pStatusBarFieldListener)
    - delete(m_pStatusBarFieldListener);
    + if(m_pStatusBarFieldListener)
    + delete(m_pStatusBarFieldListener);
     }
     
     //////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////
     
     AP_StatusBarField_TextInfo::AP_StatusBarField_TextInfo(AP_StatusBar *pSB)
    - : AP_StatusBarField(pSB)
    + : AP_StatusBarField(pSB)
     {
    - memset(m_bufUCS, 0, sizeof(m_bufUCS));
    - strcpy(m_sRepresentativeString, "");
     }
     
     //////////////////////////////////////////////////////////////////
    @@ -75,63 +73,57 @@
     class ap_sbf_PageInfo : public AP_StatusBarField_TextInfo
     {
     public:
    - ap_sbf_PageInfo(AP_StatusBar * pSB);
    + ap_sbf_PageInfo(AP_StatusBar * pSB);
     
    - virtual void notify(AV_View * pView, const AV_ChangeMask mask);
    + virtual void notify(AV_View * pView, const AV_ChangeMask mask);
     
     private:
    - UT_uint32 m_pageNr;
    - UT_uint32 m_nrPages;
    + UT_uint32 m_pageNr;
    + UT_uint32 m_nrPages;
     
    - const XML_Char * m_szFormat;
    + const XML_Char * m_szFormat;
     };
     
     ap_sbf_PageInfo::ap_sbf_PageInfo(AP_StatusBar * pSB)
    - : AP_StatusBarField_TextInfo(pSB)
    + : AP_StatusBarField_TextInfo(pSB)
     {
    - m_pageNr = 0;
    - m_nrPages = 0;
    + m_pageNr = 0;
    + m_nrPages = 0;
     
    - m_szFormat = pSB->getFrame()->getApp()->getStringSet()->getValue(AP_STRING_ID_PageInfoField);
    - m_fillMethod = REPRESENTATIVE_STRING;
    - m_alignmentMethod = LEFT;
    + m_szFormat = pSB->getFrame()->getApp()->getStringSet()->getValue(AP_STRING_ID_PageInfoField);
    + m_fillMethod = REPRESENTATIVE_STRING;
    + m_alignmentMethod = LEFT;
     
    - sprintf(m_sRepresentativeString,m_szFormat,AP_STATUSBAR_MAX_PAGES,AP_STATUSBAR_MAX_PAGES);
    + UT_UTF8String_sprintf(m_sRepresentativeString,m_szFormat,AP_STATUSBAR_MAX_PAGES,AP_STATUSBAR_MAX_PAGES);
     }
     
     void ap_sbf_PageInfo::notify(AV_View * pavView, const AV_ChangeMask mask)
     {
    - FV_View * pView = static_cast<FV_View *>(pavView);
    + FV_View * pView = static_cast<FV_View *>(pavView);
             
    - bool bNeedNewString = false;
    + bool bNeedNewString = false;
     
    - if (mask & (AV_CHG_MOTION | AV_CHG_PAGECOUNT))
    - {
    - UT_uint32 currentPage = pView->getCurrentPageNumForStatusBar();
    - UT_uint32 newPageCount = pView->getLayout()->countPages();
    + if (mask & (AV_CHG_MOTION | AV_CHG_PAGECOUNT))
    + {
    + UT_uint32 currentPage = pView->getCurrentPageNumForStatusBar();
    + UT_uint32 newPageCount = pView->getLayout()->countPages();
     
    - if (newPageCount != m_nrPages || m_pageNr != currentPage)
    - {
    - bNeedNewString = true;
    - m_nrPages = newPageCount;
    - m_pageNr = currentPage;
    - }
    + if (newPageCount != m_nrPages || m_pageNr != currentPage)
    + {
    + bNeedNewString = true;
    + m_nrPages = newPageCount;
    + m_pageNr = currentPage;
             }
    + }
     
    - if (bNeedNewString)
    - {
    - char buf[AP_MAX_MESSAGE_FIELD];
    - sprintf(buf,m_szFormat,m_pageNr,m_nrPages);
    -
    - // WL: Assume all incoming strings are in UTF-8
    - // FIXME: Should we be doing this in a more principled way?
    - // 23/04/2003 Jordi: The string arrives here in ANSI format not UTF-8
    - UT_UCS4_strcpy_char(m_bufUCS,buf);
    -
    - if (getListener())
    - getListener()->notify();
    + if (bNeedNewString)
    + {
    + UT_UTF8String_sprintf(m_sBuf, m_szFormat, m_pageNr, m_nrPages);
    +
    + if (getListener())
    + getListener()->notify();
     
    - }
    + }
     }
     
     //////////////////////////////////////////////////////////////////
    @@ -139,35 +131,36 @@
     
     class ap_sbf_StatusMessage : public AP_StatusBarField_TextInfo
     {
    - public:
    - ap_sbf_StatusMessage(AP_StatusBar * pSB);
    +public:
    + ap_sbf_StatusMessage(AP_StatusBar * pSB);
     
    - virtual void notify(AV_View * pView, const AV_ChangeMask mask);
    - void update(UT_UCS4Char *pMessage); // for receiving messages from the status bar itself
    + virtual void notify(AV_View * pView, const AV_ChangeMask mask);
    + void update(const UT_UTF8String &sMessage); // for receiving messages from the status bar itself
     };
     
     ap_sbf_StatusMessage::ap_sbf_StatusMessage(AP_StatusBar * pSB)
    - : AP_StatusBarField_TextInfo(pSB)
    + : AP_StatusBarField_TextInfo(pSB)
    +
     {
    - m_fillMethod = MAX_POSSIBLE;
    - m_alignmentMethod = LEFT;
    - strcpy(m_sRepresentativeString, AP_STATUSBAR_STATUSMESSAGE_REPRESENTATIVE_STRING);
    + m_fillMethod = MAX_POSSIBLE;
    + m_alignmentMethod = LEFT;
    + m_sRepresentativeString = AP_STATUSBAR_STATUSMESSAGE_REPRESENTATIVE_STRING;
     }
     
     void ap_sbf_StatusMessage::notify(AV_View * /*pView*/, const AV_ChangeMask /*mask*/)
    -{
    - UT_UCS4_strcpy(m_bufUCS, m_pSB->getStatusMessage());
    +{
    + m_sBuf = m_pSB->getStatusMessage();
     
    - if (getListener())
    - getListener()->notify();
    + if (getListener())
    + getListener()->notify();
     }
     
    -void ap_sbf_StatusMessage::update(UT_UCS4Char *pMessage)
    +void ap_sbf_StatusMessage::update(const UT_UTF8String &sMessage)
     {
    - UT_UCS4_strcpy(m_bufUCS, pMessage);
    + m_sBuf = sMessage;
     
    - if (getListener())
    - getListener()->notify();
    + if (getListener())
    + getListener()->notify();
     }
     
     //////////////////////////////////////////////////////////////////
    @@ -175,38 +168,34 @@
     
     class ap_sbf_InputMode : public AP_StatusBarField_TextInfo
     {
    - public:
    - ap_sbf_InputMode(AP_StatusBar * pSB);
    +public:
    + ap_sbf_InputMode(AP_StatusBar * pSB);
             
    - virtual void notify(AV_View * pView, const AV_ChangeMask mask);
    + virtual void notify(AV_View * pView, const AV_ChangeMask mask);
     };
     
     ap_sbf_InputMode::ap_sbf_InputMode(AP_StatusBar * pSB)
    - : AP_StatusBarField_TextInfo(pSB)
    + : AP_StatusBarField_TextInfo(pSB)
    +
     {
    - const char * szInputMode = m_pSB->getFrame()->getInputMode();
    - // WL: Assume all incoming strings are in UTF-8
    - // FIXME: Should we be doing this in a more principled way?
    - UT_UCS4_strcpy_utf8_char(m_bufUCS,szInputMode);
    -
    - m_fillMethod = REPRESENTATIVE_STRING;
    - m_alignmentMethod = LEFT;
    - strcpy(m_sRepresentativeString, AP_STATUSBAR_INPUTMODE_REP_STRING);
    + UT_UTF8String sInputMode(pSB->getFrame()->getInputMode(), pSB->getFrame()->getApp()->getDefaultEncoding());
    + m_sBuf = sInputMode;
    +
    + m_fillMethod = REPRESENTATIVE_STRING;
    + m_alignmentMethod = LEFT;
    + m_sRepresentativeString = AP_STATUSBAR_INPUTMODE_REP_STRING;
     }
     
     void ap_sbf_InputMode::notify(AV_View * /*pavView*/, const AV_ChangeMask mask)
     {
    - if (mask & (AV_CHG_INPUTMODE))
    - {
    - const char * szInputMode = m_pSB->getFrame()->getInputMode();
    -
    - // WL: Assume all incoming strings are in UTF-8
    - // FIXME: Should we be doing this in a more principled way?
    - UT_UCS4_strcpy_utf8_char(m_bufUCS,szInputMode);
    + if (mask & (AV_CHG_INPUTMODE))
    + {
    + UT_UTF8String sInputMode(m_pSB->getFrame()->getInputMode(), m_pSB->getFrame()->getApp()->getDefaultEncoding());
    + m_sBuf = sInputMode;
     
    - if (getListener())
    - getListener()->notify();
    - }
    + if (getListener())
    + getListener()->notify();
    + }
     }
     
     
    @@ -215,42 +204,47 @@
     
     class ap_sbf_InsertMode : public AP_StatusBarField_TextInfo
     {
    - public:
    - ap_sbf_InsertMode(AP_StatusBar * pSB);
    +public:
    + ap_sbf_InsertMode(AP_StatusBar * pSB);
             
    - virtual void notify(AV_View * pView, const AV_ChangeMask mask);
    + virtual void notify(AV_View * pView, const AV_ChangeMask mask);
     
    - private:
    - UT_UCSChar m_InsertMode[2][AP_MAX_MESSAGE_FIELD];
    - bool m_bInsertMode;
    +private:
    + UT_UTF8String m_sInsertMode[2];
    + bool m_bInsertMode;
     };
     
     ap_sbf_InsertMode::ap_sbf_InsertMode(AP_StatusBar * pSB)
         : AP_StatusBarField_TextInfo(pSB)
    -{
    -
    - UT_UCS4_strcpy_utf8_char(m_InsertMode[static_cast<int>(true)],pSB->getFrame()->getApp()->getStringSet()->getValue(AP_STRING_ID_InsertModeFieldINS));
    - UT_UCS4_strcpy_utf8_char(m_InsertMode[static_cast<int>(false)],pSB->getFrame()->getApp()->getStringSet()->getValue(AP_STRING_ID_InsertModeFieldOVR));
    +
     
    +{
         m_bInsertMode = true;
    +
    + UT_UTF8String s1(pSB->getFrame()->getApp()->getStringSet()->getValue(AP_STRING_ID_InsertModeFieldINS),
    + pSB->getFrame()->getApp()->getDefaultEncoding());
    + UT_UTF8String s2(pSB->getFrame()->getApp()->getStringSet()->getValue(AP_STRING_ID_InsertModeFieldOVR),
    + pSB->getFrame()->getApp()->getDefaultEncoding());
    + m_sInsertMode[0] = s1;
    + m_sInsertMode[1] = s2;
     
         m_fillMethod = REPRESENTATIVE_STRING;
         m_alignmentMethod = CENTER;
    - strcpy(m_sRepresentativeString, AP_STATUSBAR_INSERTMODE_REP_STRING);
    + m_sRepresentativeString = AP_STATUSBAR_INSERTMODE_REP_STRING;
     }
     
     void ap_sbf_InsertMode::notify(AV_View * /*pavView*/, const AV_ChangeMask mask)
     {
         if (mask & (AV_CHG_INSERTMODE))
         {
    - AP_FrameData * pData = static_cast<AP_FrameData *>(m_pSB->getFrame()->getFrameData());
    - if (pData) {
    - m_bInsertMode = pData->m_bInsertMode;
    - UT_UCS4_strcpy(m_bufUCS, m_InsertMode[m_bInsertMode]);
    - }
    + AP_FrameData * pData = static_cast<AP_FrameData *>(m_pSB->getFrame()->getFrameData());
    + if (pData) {
    + m_bInsertMode = pData->m_bInsertMode;
    + m_sBuf = m_sInsertMode[m_bInsertMode];
    + }
     
    - if (getListener())
    - getListener()->notify();
    + if (getListener())
    + getListener()->notify();
         }
     }
     
    @@ -260,39 +254,39 @@
     
     class ap_sbf_Language : public AP_StatusBarField_TextInfo
     {
    - public:
    - ap_sbf_Language(AP_StatusBar * pSB);
    +public:
    + ap_sbf_Language(AP_StatusBar * pSB);
     
    - virtual void notify(AV_View * pView, const AV_ChangeMask mask);
    + virtual void notify(AV_View * pView, const AV_ChangeMask mask);
     };
     
     ap_sbf_Language::ap_sbf_Language(AP_StatusBar * pSB)
    - : AP_StatusBarField_TextInfo(pSB)
    + : AP_StatusBarField_TextInfo(pSB)
     {
    - m_fillMethod = REPRESENTATIVE_STRING;
    - m_alignmentMethod = CENTER;
    - strcpy(m_sRepresentativeString, "mm-MM"); // this should actually be longer.. see old code for info on why
    + m_fillMethod = REPRESENTATIVE_STRING;
    + m_alignmentMethod = CENTER;
    + m_sRepresentativeString = "mm-MM";
     }
     
     void ap_sbf_Language::notify(AV_View * pavView, const AV_ChangeMask mask)
     {
    - // TODO do we want our own bit for language change?
    - //if (mask & (AV_CHG_INSERTMODE))
    - {
    - const char * szLang = NULL;
    -
    - const XML_Char ** props_in = NULL;
    - if (pavView && static_cast<FV_View *>(pavView)->getCharFormat(&props_in))
    - {
    - szLang = UT_getAttribute("lang", props_in);
    - FREEP(props_in);
    + // TODO do we want our own bit for language change?
    + //if (mask & (AV_CHG_INSERTMODE))
    + {
    + const char * szLang = NULL;
     
    - UT_UCS4_strcpy_utf8_char(m_bufUCS, szLang ? szLang : "");
    - }
    + const XML_Char ** props_in = NULL;
    + if (pavView && static_cast<FV_View *>(pavView)->getCharFormat(&props_in))
    + {
    + szLang = UT_getAttribute("lang", props_in);
    + FREEP(props_in);
     
    - if (getListener())
    - getListener()->notify();
    + m_sBuf = szLang;
             }
    +
    + if (getListener())
    + getListener()->notify();
    + }
     }
     
     //////////////////////////////////////////////////////////////////
    @@ -301,11 +295,11 @@
     // PROGRESSBAR. CURRENTLY UNUSED. MAY BE BROKEN. NEEDS TESTING.
     
     AP_StatusBarField_ProgressBar::AP_StatusBarField_ProgressBar(AP_StatusBar * pSB)
    - : AP_StatusBarField(pSB)
    + : AP_StatusBarField(pSB)
     {
    - m_ProgressStartPoint = 0;
    - m_ProgressFlags = 0;
    - m_ProgressTimer = NULL;
    + m_ProgressStartPoint = 0;
    + m_ProgressFlags = 0;
    + m_ProgressTimer = NULL;
     }
     
     AP_StatusBarField_ProgressBar::~AP_StatusBarField_ProgressBar(void)
    @@ -321,48 +315,47 @@
         UT_ASSERT(pfspb);
     
         if(pfspb->getListener())
    - pfspb->getListener()->notify();
    + pfspb->getListener()->notify();
     }
     
     void AP_StatusBarField_ProgressBar::notify(AV_View * /*pView*/, const AV_ChangeMask /*mask*/)
     {
    - // do nothing, we get our information from the status bar
    + // do nothing, we get our information from the status bar
     }
     
     void AP_StatusBarField_ProgressBar::setStatusProgressType(int start, int end, int flags)
     {
    - m_ProgressStart =
    - m_ProgressValue = start;
    - m_ProgressEnd = end;
    - m_ProgressFlags = flags;
    - m_ProgressStartPoint = 0;
    -
    - if (m_ProgressTimer) {
    - delete m_ProgressTimer;
    - m_ProgressTimer = NULL;
    - }
    + m_ProgressStart = m_ProgressValue = start;
    + m_ProgressEnd = end;
    + m_ProgressFlags = flags;
    + m_ProgressStartPoint = 0;
    +
    + if (m_ProgressTimer) {
    + delete m_ProgressTimer;
    + m_ProgressTimer = NULL;
    + }
     
    - if (m_ProgressStart == m_ProgressEnd &&
    - (m_ProgressFlags & PROGRESS_CMD_MASK) == PROGRESS_STARTBAR) {
    - m_ProgressTimer = UT_Timer::static_constructor(updateProgress, this);
    - m_ProgressTimer->stop();
    - m_ProgressTimer->set(50); //Milliseconds
    - }
    + if (m_ProgressStart == m_ProgressEnd &&
    + (m_ProgressFlags & PROGRESS_CMD_MASK) == PROGRESS_STARTBAR) {
    + m_ProgressTimer = UT_Timer::static_constructor(updateProgress, this);
    + m_ProgressTimer->stop();
    + m_ProgressTimer->set(50); //Milliseconds
    + }
     }
     
     void AP_StatusBarField_ProgressBar::setStatusProgressValue(int value)
     {
    - m_ProgressValue = value;
    + m_ProgressValue = value;
     }
     
     //////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////
     
     AP_StatusBar::AP_StatusBar(XAP_Frame * pFrame)
    -: m_pFrame(pFrame),
    - m_pView(0),
    - m_bInitFields(false),
    - m_pStatusMessageField(0)
    + : m_pFrame(pFrame),
    + m_pView(0),
    + m_bInitFields(false),
    + m_pStatusMessageField(0)
     {
     
     #define DclField(type,var) \
    @@ -370,168 +363,130 @@
                     UT_ASSERT((var)); \
                     m_vecFields.addItem((var)); \
                     
    - DclField(ap_sbf_PageInfo, pf1);
    - DclField(ap_sbf_StatusMessage, pf2);
    + DclField(ap_sbf_PageInfo, pf1);
    + DclField(ap_sbf_StatusMessage, pf2);
     
    - m_pStatusMessageField = pf2; // its in the vector, but we remember it explicitly
    - // so that setStatusMessage() can do its thing.
    + m_pStatusMessageField = pf2; // its in the vector, but we remember it explicitly
    + // so that setStatusMessage() can do its thing.
     
    - DclField(ap_sbf_InsertMode, pf4);
    - DclField(ap_sbf_InputMode, pf3);
    + DclField(ap_sbf_InsertMode, pf4);
    + DclField(ap_sbf_InputMode, pf3);
                     
    - DclField(ap_sbf_Language, pf5);
    + DclField(ap_sbf_Language, pf5);
     
    - // TODO add other fields
    + // TODO add other fields
     
     #undef DclField
    -
    -
    - m_bufUCS[0] = 0;
     }
     
     AP_StatusBar::~AP_StatusBar(void)
     {
    - UT_VECTOR_PURGEALL(AP_StatusBarField *, m_vecFields);
    + UT_VECTOR_PURGEALL(AP_StatusBarField *, m_vecFields);
     }
     
     XAP_Frame * AP_StatusBar::getFrame(void) const
     {
    - return m_pFrame;
    + return m_pFrame;
     }
     
     void AP_StatusBar::setView(AV_View * pView)
     {
    - m_pView = pView;
    + m_pView = pView;
     
    - // Register the StatusBar as a ViewListener on the View.
    - // This lets us receive notify events as the user interacts
    - // with the document (cmdCharMotion, etc). This will let
    - // us update the display as we move from block to block and
    - // from column to column.
    + // Register the StatusBar as a ViewListener on the View.
    + // This lets us receive notify events as the user interacts
    + // with the document (cmdCharMotion, etc). This will let
    + // us update the display as we move from block to block and
    + // from column to column.
     
    - AV_ListenerId lidTopRuler;
    - m_pView->addListener(static_cast<AV_Listener *>(this),&lidTopRuler);
    + AV_ListenerId lidTopRuler;
    + m_pView->addListener(static_cast<AV_Listener *>(this),&lidTopRuler);
     
    - if (!m_bInitFields)
    - {
    + if (!m_bInitFields)
    + {
                     
    - m_bInitFields = true;
    - }
    + m_bInitFields = true;
    + }
     
    - // force a full notify of all fields so that they all
    - // completely update themselves.
    + // force a full notify of all fields so that they all
    + // completely update themselves.
             
    - notify(pView,AV_CHG_ALL);
    + notify(pView,AV_CHG_ALL);
             
    - return;
    + return;
     }
     
     bool AP_StatusBar::notify(AV_View * pView, const AV_ChangeMask mask)
     {
    - // Handle AV_Listener events on the view.
    + // Handle AV_Listener events on the view.
     
    - // We choose to clear any status message we may have,
    - // since it's a pain for the code which set the message
    - // to hang around and clear it at some point in the future.
    - // This way, message will get cleared any time the user does
    - // something with the window.
    - if(getFrame()->getFrameMode() != XAP_NormalFrame)
    - {
    - return true;
    - }
    + // We choose to clear any status message we may have,
    + // since it's a pain for the code which set the message
    + // to hang around and clear it at some point in the future.
    + // This way, message will get cleared any time the user does
    + // something with the window.
    + if(getFrame()->getFrameMode() != XAP_NormalFrame)
    + {
    + return true;
    + }
     
    - if (*m_bufUCS)
    - setStatusMessage(static_cast<UT_UCSChar *>(NULL));
    + setStatusMessage(static_cast<UT_UCSChar *>(NULL));
             
    - // Let each field on the status bar update itself accordingly.
    + // Let each field on the status bar update itself accordingly.
             
    - UT_ASSERT(pView==m_pView);
    - UT_uint32 kLimit = m_vecFields.getItemCount();
    - UT_uint32 k;
    + UT_ASSERT(pView==m_pView);
    + UT_uint32 kLimit = m_vecFields.getItemCount();
    + UT_uint32 k;
     
    - for (k=0; k<kLimit; k++)
    + for (k=0; k<kLimit; k++)
    + {
    + AP_StatusBarField * pf = static_cast<AP_StatusBarField *>(m_vecFields.getNthItem(k));
    + if(pf)
             {
    - AP_StatusBarField * pf = static_cast<AP_StatusBarField *>(m_vecFields.getNthItem(k));
    - if(pf)
    - {
    - pf->notify(pView,mask);
    - }
    + pf->notify(pView,mask);
             }
    + }
     
    - return true;
    + return true;
     }
     
     void AP_StatusBar::setStatusMessage(UT_UCSChar * pBufUCS, int redraw)
     {
    - if(getFrame()->getFrameMode() != XAP_NormalFrame)
    - {
    - return;
    - }
    -
    - memset(m_bufUCS, 0, sizeof(m_bufUCS));
    + if(getFrame()->getFrameMode() != XAP_NormalFrame)
    + {
    + return;
    + }
    + m_sStatusMessage.clear();
     
    - if (pBufUCS && *pBufUCS)
    - {
    - UT_UCS4_strncpy(m_bufUCS, pBufUCS, AP_MAX_MESSAGE_FIELD);
    - m_bufUCS[AP_MAX_MESSAGE_FIELD] = 0;
    - }
    + if (pBufUCS && *pBufUCS)
    + m_sStatusMessage.appendUCS4(pBufUCS);
             
    - ap_sbf_StatusMessage * pf = static_cast<ap_sbf_StatusMessage *>(m_pStatusMessageField);
    - if(pf)
    - pf->update(pBufUCS);
    + ap_sbf_StatusMessage * pf = static_cast<ap_sbf_StatusMessage *>(m_pStatusMessageField);
    + if(pf)
    + pf->update(m_sStatusMessage);
     }
     
     void AP_StatusBar::setStatusMessage(const char * pBuf, int redraw)
     {
    - if(getFrame()->getFrameMode() != XAP_NormalFrame)
    - {
    - return;
    - }
    -
    - UT_uint32 len = ((pBuf && *pBuf) ? strlen(pBuf) : 0);
    -
    - // This is the kind of a bad assert that creates segfaults and
    - // unnecessary work!!!
    - // UT_ASSERT(len*MB_LEN_MAX < AP_MAX_MESSAGE_FIELD);
    -
    - char * t = NULL;
    - if(len*MB_LEN_MAX >= AP_MAX_MESSAGE_FIELD)
    - {
    - t = new char[AP_MAX_MESSAGE_FIELD/MB_LEN_MAX + 1];
    - // leave 4 empty spaces at the end
    - // this might leave a broken char at the end, but it will not
    - // crash ...
    - strncpy(t,pBuf,AP_MAX_MESSAGE_FIELD/MB_LEN_MAX - 4);
    - t[AP_MAX_MESSAGE_FIELD/MB_LEN_MAX - 4] = ' ';
    - t[AP_MAX_MESSAGE_FIELD/MB_LEN_MAX - 3] = '.';
    - t[AP_MAX_MESSAGE_FIELD/MB_LEN_MAX - 2] = '.';
    - t[AP_MAX_MESSAGE_FIELD/MB_LEN_MAX - 1] = '.';
    - t[AP_MAX_MESSAGE_FIELD/MB_LEN_MAX] = 0;
    - }
    -
    - UT_UCSChar bufUCS[AP_MAX_MESSAGE_FIELD+1];
    + if(getFrame()->getFrameMode() != XAP_NormalFrame)
    + {
    + return;
    + }
     
    - if (len && !t)
    - UT_UCS4_strcpy_utf8_char(bufUCS,pBuf);
    - else if(len && t)
    - UT_UCS4_strcpy_utf8_char(bufUCS,t);
    - else
    - memset(bufUCS,0,sizeof(bufUCS));
    -
    - ap_sbf_StatusMessage * pf = static_cast<ap_sbf_StatusMessage *>(m_pStatusMessageField);
    - if(pf) {
    - pf->update(bufUCS);
    - }
    + if (pBuf && *pBuf)
    + {
    + UT_UTF8String sBuf(pBuf, XAP_App::getApp()->getDefaultEncoding());
    + m_sStatusMessage = sBuf;
    + }
     
    - if(t)
    - {
    - delete [] t;
    - }
    + ap_sbf_StatusMessage * pf = static_cast<ap_sbf_StatusMessage *>(m_pStatusMessageField);
    + if(pf)
    + pf->update(m_sStatusMessage);
     }
     
    -const UT_UCSChar * AP_StatusBar::getStatusMessage(void) const
    +const UT_UTF8String & AP_StatusBar::getStatusMessage(void) const
     {
    - return m_bufUCS;
    + return m_sStatusMessage;
     }
     
     void AP_StatusBar::setStatusProgressType(int start, int end, int flags) {
    Index: src/wp/ap/xp/ap_StatusBar.h
    ===================================================================
    RCS file: /cvsroot/abi/src/wp/ap/xp/ap_StatusBar.h,v
    retrieving revision 1.18
    diff --unified -r1.18 ap_StatusBar.h
    --- src/wp/ap/xp/ap_StatusBar.h 19 Nov 2002 00:13:14 -0000 1.18
    +++ src/wp/ap/xp/ap_StatusBar.h 20 Jul 2003 01:21:37 -0000
    @@ -31,6 +31,7 @@
     #include "ap_Prefs.h"
     #include "ap_Prefs_SchemeIds.h"
     #include "xav_Listener.h"
    +#include "ut_string_class.h"
     
     class XAP_Frame;
     class GR_Graphics;
    @@ -42,13 +43,13 @@
     
     #define PROGRESS_CMD_MASK 0x3 /* 0,1,2,3 Operational values */
     enum _progress_flags {
    - PROGRESS_RESERVED1 = 0x0,
    - PROGRESS_STARTBAR = 0x1, /* Start using the progress bar */
    - PROGRESS_STOPBAR = 0x2, /* Stop using the progress bar */
    - PROGRESS_RESERVED2 = 0x3,
    - PROGRESS_SHOW_MSG = 0x4, /* Allow message to be displayed */
    - PROGRESS_SHOW_RAW = 0x8, /* Allow raw value to be displayed */
    - PROGRESS_SHOW_PERCENT = 0x10 /* Allow calculation of percent value */
    + PROGRESS_RESERVED1 = 0x0,
    + PROGRESS_STARTBAR = 0x1, /* Start using the progress bar */
    + PROGRESS_STOPBAR = 0x2, /* Stop using the progress bar */
    + PROGRESS_RESERVED2 = 0x3,
    + PROGRESS_SHOW_MSG = 0x4, /* Allow message to be displayed */
    + PROGRESS_SHOW_RAW = 0x8, /* Allow raw value to be displayed */
    + PROGRESS_SHOW_PERCENT = 0x10 /* Allow calculation of percent value */
     };
     
     #include "ut_timer.h"
    @@ -61,37 +62,38 @@
     class AP_StatusBar : public AV_Listener
     {
     public:
    - AP_StatusBar(XAP_Frame * pFrame);
    - virtual ~AP_StatusBar(void);
    + AP_StatusBar(XAP_Frame * pFrame);
    + virtual ~AP_StatusBar(void);
     
    - XAP_Frame * getFrame(void) const;
    - virtual void setView(AV_View * pView);
    - void setStatusMessage(UT_UCSChar * pbufUCS, int redraw = true);
    - void setStatusMessage(const char * pbuf, int redraw = true);
    - const UT_UCS4Char * getStatusMessage(void) const;
    + XAP_Frame * getFrame(void) const;
    + virtual void setView(AV_View * pView);
    + void setStatusMessage(UT_UCSChar * pbufUCS, int redraw = true);
    + void setStatusMessage(const char * pbuf, int redraw = true);
    + const UT_UTF8String & getStatusMessage(void) const;
     
    - void setStatusProgressType(int start, int end, int flags);
    - void setStatusProgressValue(int value);
    + void setStatusProgressType(int start, int end, int flags);
    + void setStatusProgressValue(int value);
     
    - virtual void show(void) {} // It must be abstract, but I don't want to screw
    - virtual void hide(void) {} // the platforms that don't implement show/hide
    + virtual void show(void) {} // It must be abstract, but I don't want to screw
    + virtual void hide(void) {} // the platforms that don't implement show/hide
             
    - /* used with AV_Listener */
    - virtual bool notify(AV_View * pView, const AV_ChangeMask mask);
    - virtual AV_ListenerType getType(void) { return AV_LISTENER_STATUSBAR;}
    + /* used with AV_Listener */
    + virtual bool notify(AV_View * pView, const AV_ChangeMask mask);
    + virtual AV_ListenerType getType(void) { return AV_LISTENER_STATUSBAR;}
     
    - UT_Vector * getFields() { return &m_vecFields; }
    + UT_Vector * getFields() { return &m_vecFields; }
     protected:
     
    - XAP_Frame * m_pFrame;
    - AV_View * m_pView;
    + XAP_Frame * m_pFrame;
    + AV_View * m_pView;
     
    - bool m_bInitFields;
    - UT_Vector m_vecFields; /* vector of 'ap_sb_Field *' */
    - void * m_pStatusMessageField; /* actually 'AP_StatusBarField_StatusMessage *' */
    - void * m_pStatusProgressField; /* actually 'AP_StatusBarField_ProgressBar *' */
    + bool m_bInitFields;
    + UT_Vector m_vecFields; /* vector of 'ap_sb_Field *' */
    + void * m_pStatusMessageField; /* actually 'AP_StatusBarField_StatusMessage *' */
    + void * m_pStatusProgressField; /* actually 'AP_StatusBarField_ProgressBar *' */
     
    - UT_UCS4Char m_bufUCS[AP_MAX_MESSAGE_FIELD];
    +
    + UT_UTF8String m_sStatusMessage;
     };
     
     // abstract class which "listens" for changes in the status bar fields in the base classes
    @@ -100,79 +102,80 @@
     
     class AP_StatusBarFieldListener
     {
    - public:
    - AP_StatusBarFieldListener(AP_StatusBarField *pStatusBarField) { m_pStatusBarField = pStatusBarField; }
    - virtual ~AP_StatusBarFieldListener() {}
    - virtual void notify() = 0;
    +public:
    + AP_StatusBarFieldListener(AP_StatusBarField *pStatusBarField) { m_pStatusBarField = pStatusBarField; }
    + virtual ~AP_StatusBarFieldListener() {}
    + virtual void notify() = 0;
     
    - protected:
    - AP_StatusBarField *m_pStatusBarField;
    +protected:
    + AP_StatusBarField *m_pStatusBarField;
     };
     
     // alignment/fill properties for the upper level gui
     enum _statusbar_element_fill_method {
    - REPRESENTATIVE_STRING,
    - MAX_POSSIBLE
    + REPRESENTATIVE_STRING,
    + MAX_POSSIBLE
     };
     
     enum _statusbar_textelement_alignment_method {
    - LEFT,
    - CENTER
    + LEFT,
    + CENTER
     };
     
     // AP_StatusBarField: abstract base class for a status bar field
     class AP_StatusBarField
     {
    - public:
    - AP_StatusBarField(AP_StatusBar * pSB);
    - virtual ~AP_StatusBarField(void);
    +public:
    + AP_StatusBarField(AP_StatusBar * pSB);
    + virtual ~AP_StatusBarField(void);
                     
    - virtual void notify(AV_View * pView, const AV_ChangeMask mask) = 0;
    - void setListener(AP_StatusBarFieldListener *pStatusBarFieldListener) { m_pStatusBarFieldListener = pStatusBarFieldListener; }
    - AP_StatusBarFieldListener * getListener() { return m_pStatusBarFieldListener; }
    -
    - _statusbar_element_fill_method getFillMethod() { return m_fillMethod; }
    -
    - protected:
    - AP_StatusBar * m_pSB;
    - AP_StatusBarFieldListener *m_pStatusBarFieldListener;
    - _statusbar_element_fill_method m_fillMethod;
    + virtual void notify(AV_View * pView, const AV_ChangeMask mask) = 0;
    + void setListener(AP_StatusBarFieldListener *pStatusBarFieldListener) { m_pStatusBarFieldListener = pStatusBarFieldListener; }
    + AP_StatusBarFieldListener * getListener() { return m_pStatusBarFieldListener; }
    +
    + _statusbar_element_fill_method getFillMethod() { return m_fillMethod; }
    +
    +protected:
    + AP_StatusBar * m_pSB;
    + AP_StatusBarFieldListener *m_pStatusBarFieldListener;
    + _statusbar_element_fill_method m_fillMethod;
     };
     
     class AP_StatusBarField_TextInfo : public AP_StatusBarField
     {
    - public:
    - AP_StatusBarField_TextInfo(AP_StatusBar * pSB);
    - //virtual ~AP_StatusBarField_TextInfo(void) {}
    - const UT_UCS4Char * getBufUCS() { return m_bufUCS; }
    - // getRepresentativeString: give a "guess" as to how long the string will be. it's not a big deal
    - // if it's wrong; we should resize fixed-length status bar elements in platform specific code
    - // if they're not big enough to show the string correctly
    - const char * getRepresentativeString(void) { return m_sRepresentativeString; }
    - _statusbar_textelement_alignment_method getAlignmentMethod() { return m_alignmentMethod; }
    - protected:
    - UT_UCS4Char m_bufUCS[AP_MAX_MESSAGE_FIELD];
    - char m_sRepresentativeString[AP_MAX_MESSAGE_FIELD];
    - _statusbar_textelement_alignment_method m_alignmentMethod;
    +public:
    + AP_StatusBarField_TextInfo(AP_StatusBar * pSB);
    + //virtual ~AP_StatusBarField_TextInfo(void) {}
    + const UT_UTF8String & getBuf() { return m_sBuf; }
    + // getRepresentativeString: give a "guess" as to how long the string will be. it's not a big deal
    + // if it's wrong; we should resize fixed-length status bar elements in platform specific code
    + // if they're not big enough to show the string correctly
    + const char * getRepresentativeString(void) { return m_sRepresentativeString.utf8_str(); }
    + _statusbar_textelement_alignment_method getAlignmentMethod() { return m_alignmentMethod; }
    +
    +protected:
    + UT_UTF8String m_sBuf;
    + UT_UTF8String m_sRepresentativeString;
    + _statusbar_textelement_alignment_method m_alignmentMethod;
     };
     
     // PROGRESSBAR. CURRENTLY UNUSED. MAY BE BROKEN. NEEDS TESTING.
     class AP_StatusBarField_ProgressBar : public AP_StatusBarField
     {
    - public:
    - AP_StatusBarField_ProgressBar(AP_StatusBar * pSB);
    - virtual ~AP_StatusBarField_ProgressBar(void);
    -
    - virtual void notify(AV_View * pView, const AV_ChangeMask mask);
    - void setStatusProgressType(int start, int end, int flags);
    - void setStatusProgressValue(int value);
    -
    - protected:
    - UT_sint32 m_ProgressStart;
    - UT_sint32 m_ProgressEnd;
    - UT_sint32 m_ProgressValue;
    - UT_sint32 m_ProgressStartPoint;
    - UT_uint32 m_ProgressFlags;
    - UT_Timer *m_ProgressTimer;
    +public:
    + AP_StatusBarField_ProgressBar(AP_StatusBar * pSB);
    + virtual ~AP_StatusBarField_ProgressBar(void);
    +
    + virtual void notify(AV_View * pView, const AV_ChangeMask mask);
    + void setStatusProgressType(int start, int end, int flags);
    + void setStatusProgressValue(int value);
    +
    +protected:
    + UT_sint32 m_ProgressStart;
    + UT_sint32 m_ProgressEnd;
    + UT_sint32 m_ProgressValue;
    + UT_sint32 m_ProgressStartPoint;
    + UT_uint32 m_ProgressFlags;
    + UT_Timer *m_ProgressTimer;
     };
     #endif /* AP_STATUSBAR_H */



    This archive was generated by hypermail 2.1.4 : Sun Jul 20 2003 - 01:17:21 EDT