Bugfix 2591 please commit


Subject: Bugfix 2591 please commit
From: Robert Altenburg (rca@xlation.com)
Date: Thu Jan 31 2002 - 18:03:37 CST


Fix for Bugzilla Bug 2591
(Columns setup measure unit is always inches)

What this does:

in ut_units.cpp
        UT_reformatDimensionString
        Catch nulls, convert them to 0.0in, print debug msg.
        This prevents a segfault.
        
in ap_UnixDialog_Columns.cpp
        Just changed the code formatting.
        
in ap_Dialog_Columns.cpp
        add function _convertToPreferedUnits
        uses function to convert units to the same
        units set in the prefs.
        
        Note:
        This calls UT_reformatDimensionString which
        returns a pointer to a local string. Because
        the convert function gets called back to back
        in this file, you need to copy the data out
        of that local before hitting it again, hence
        the UT_XML_strncpy and setting of the parameter
        pRet.
        
in ap_Dialog_Columns.h
        modifications necessary to support changes to
        the .cpp file.
                

-
Rob Altenburg

Index: src/af/util/xp/ut_units.cpp
===================================================================
RCS file: /cvsroot/abi/src/af/util/xp/ut_units.cpp,v
retrieving revision 1.42
diff -u -r1.42 ut_units.cpp
--- src/af/util/xp/ut_units.cpp 2002/01/21 12:33:27 1.42
+++ src/af/util/xp/ut_units.cpp 2002/01/31 23:34:02
@@ -271,6 +271,13 @@
 
 const char * UT_reformatDimensionString(UT_Dimension dim, const char *sz, const char * szPrecision)
 {
+ if (!sz)
+ {
+ //catch NULLs and make them 0
+ sz = "0.0in";
+ UT_DEBUGMSG(("UT_reformatDimensionString just made the assumption null =
+ 0.0in\n"));
+ }
         double d = UT_convertDimensionless(sz);
 
         // if needed, switch unit systems and round off
Index: src/wp/ap/unix/ap_UnixDialog_Columns.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/unix/ap_UnixDialog_Columns.cpp,v
retrieving revision 1.17
diff -u -r1.17 ap_UnixDialog_Columns.cpp
--- src/wp/ap/unix/ap_UnixDialog_Columns.cpp 2001/12/19 08:12:48 1.17
+++ src/wp/ap/unix/ap_UnixDialog_Columns.cpp 2002/01/31 23:34:14
@@ -43,15 +43,13 @@
 
 /*****************************************************************/
 
-XAP_Dialog * AP_UnixDialog_Columns::static_constructor(XAP_DialogFactory * pFactory,
- XAP_Dialog_Id id)
+XAP_Dialog * AP_UnixDialog_Columns::static_constructor(XAP_DialogFactory * pFactory, XAP_Dialog_Id id)
 {
         AP_UnixDialog_Columns * p = new AP_UnixDialog_Columns(pFactory,id);
         return p;
 }
 
-AP_UnixDialog_Columns::AP_UnixDialog_Columns(XAP_DialogFactory * pDlgFactory,
- XAP_Dialog_Id id)
+AP_UnixDialog_Columns::AP_UnixDialog_Columns(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id)
         : AP_Dialog_Columns(pDlgFactory,id)
 {
         m_windowMain = NULL;
Index: src/wp/ap/xp/ap_Dialog_Columns.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/xp/ap_Dialog_Columns.cpp,v
retrieving revision 1.11
diff -u -r1.11 ap_Dialog_Columns.cpp
--- src/wp/ap/xp/ap_Dialog_Columns.cpp 2002/01/02 19:45:03 1.11
+++ src/wp/ap/xp/ap_Dialog_Columns.cpp 2002/01/31 23:34:17
@@ -158,12 +158,19 @@
 */
 void AP_Dialog_Columns::setViewAndDoc(XAP_Frame * pFrame)
 {
+ XML_Char pszAfter[25];
+ XML_Char pszMaxHeight[25];
+
         m_pView = (FV_View *) pFrame->getCurrentView();
         m_pDoc = m_pView->getDocument();
         const XML_Char ** pszSecProps = NULL;
         m_pView->getSectionFormat(&pszSecProps);
- const XML_Char * pszAfter = UT_getAttribute("section-space-after",pszSecProps);
- const XML_Char * pszMaxHeight = UT_getAttribute("section-max-column-height",pszSecProps);
+
+ _convertToPreferedUnits( pFrame, (const XML_Char *)
+ UT_getAttribute("section-space-after",pszSecProps), (const XML_Char *)pszAfter);
+ _convertToPreferedUnits( pFrame, (const XML_Char *)
+ UT_getAttribute("section-max-column-height",pszSecProps), (const XML_Char *)pszMaxHeight);
+
         if(pszAfter && *pszAfter)
         {
                 m_SpaceAfterString = (const char *) pszAfter;
@@ -350,6 +357,24 @@
         rect.top += 2;
         rect.height -= 4;
         m_previewDrawer.draw(gc, rect, iColumns, false, 0.0, 0.0);
+}
+
+/*!
+ * Converts the string sz into the units seleced for the ruler.
+\params XAP_Frame * pFrame defined the frame of the application
+\params const char * sz is the string containing the old value
+\params const XML_Char * pRet is the string to which the new value is copied.
+*/
+void AP_Dialog_Columns::_convertToPreferedUnits(XAP_Frame * pFrame,const char *sz, const XML_Char *pRet)
+{
+ UT_Dimension PreferedUnits = DIM_none;
+ const XML_Char * pszRulerUnits = NULL;
+
+ if (pFrame->getApp()->getPrefsValue(AP_PREF_KEY_RulerUnits, &pszRulerUnits))
+ {
+ PreferedUnits = UT_determineDimension((char *)pszRulerUnits);
+ };
+ UT_XML_strncpy((XML_Char *) pRet, 25, (const XML_Char *) UT_reformatDimensionString(PreferedUnits,sz));
 }
 
         
Index: src/wp/ap/xp/ap_Dialog_Columns.h
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/xp/ap_Dialog_Columns.h,v
retrieving revision 1.5
diff -u -r1.5 ap_Dialog_Columns.h
--- src/wp/ap/xp/ap_Dialog_Columns.h 2001/10/03 07:42:58 1.5
+++ src/wp/ap/xp/ap_Dialog_Columns.h 2002/01/31 23:34:17
@@ -31,6 +31,11 @@
 
 #include "xap_Preview.h"
 
+// this is needed to get the ruler units.
+#include "ap_StatusBar.h"
+#include "ut_units.h"
+
+
 class AP_Columns_preview_drawer
 {
 public:
@@ -100,7 +105,8 @@
                                                         UT_uint32 width,
                                                         UT_uint32 height);
         void _drawColumnButton(GR_Graphics *gc, UT_Rect rect, UT_uint32 iColumns);
-
+ void _convertToPreferedUnits(XAP_Frame * pFrame,const
+ char *sz, const XML_Char *pRet);
         AP_Dialog_Columns::tAnswer m_answer;
         AP_Columns_preview * m_pColumnsPreview;
         AP_Columns_preview_drawer m_previewDrawer;



This archive was generated by hypermail 2b25 : Thu Jan 31 2002 - 17:57:54 CST