Proposed Bugfix for 2591 - units always inches


Subject: Proposed Bugfix for 2591 - units always inches
From: Robert Altenburg (rca@xlation.com)
Date: Sat Jan 26 2002 - 23:10:58 CST


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

What this does:
Whenever the columns dialog box is opened this
code looks at what units are set in the layout
preference and matches those units.

Other notes:

This bug is listed for linux, but it looks to me
like the same thing will happen on all platforms.
The attached diff fixes the problem on my (Linux)
system and may very well fix it for all the other
systems as well, but I don't have anything to test
it on.

Since this sort of thing is going to be needed in
a lot of other places, This code should be
moved to a "convert_to_preferred_units" function. I
can do that, but I would like to know where
the most logical place to put it (under ap/xp/) would be.
(Prefs, subclass of ut_units, ect.)

One thing I noticed was that the columns dialog sets
the value for m_HeightString back to zero every time
it is opened. When I comment out the code I wrote I
get the same behavior, so I am assuming that that
is a separate bug. It looks like m_HeightString is
handled exactly the same way as m_SpaceAfterString,
and m_SpaceAfterString gets saved OK - curious.

-
Rob Altenburg

Index: abi/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
--- abi/src/af/util/xp/ut_units.cpp 2002/01/21 12:33:27 1.42
+++ abi/src/af/util/xp/ut_units.cpp 2002/01/27 03:46:07
@@ -271,6 +271,7 @@
 
 const char * UT_reformatDimensionString(UT_Dimension dim, const char *sz, const char * szPrecision)
 {
+ if (!sz) sz = "0.0in"; //catch NULLs and make them 0
         double d = UT_convertDimensionless(sz);
 
         // if needed, switch unit systems and round off
Index: abi/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
--- abi/src/wp/ap/unix/ap_UnixDialog_Columns.cpp 2001/12/19 08:12:48 1.17
+++ abi/src/wp/ap/unix/ap_UnixDialog_Columns.cpp 2002/01/27 03:46:18
@@ -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: abi/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
--- abi/src/wp/ap/xp/ap_Dialog_Columns.cpp 2002/01/02 19:45:03 1.11
+++ abi/src/wp/ap/xp/ap_Dialog_Columns.cpp 2002/01/27 03:46:21
@@ -158,12 +158,26 @@
 */
 void AP_Dialog_Columns::setViewAndDoc(XAP_Frame * pFrame)
 {
+ const XML_Char * pszRulerUnits = NULL;
+ XML_Char pszAfter[25];
+ XML_Char pszMaxHeight[25];
+
+ XAP_PrefsScheme *pPrefsScheme = pFrame->getApp()->getPrefs()->getCurrentScheme();
+ UT_ASSERT(pPrefsScheme);
+ pPrefsScheme->getValue((XML_Char*)AP_PREF_KEY_RulerUnits, &pszRulerUnits);
+ UT_Dimension dim = UT_determineDimension((char *)pszRulerUnits);
+
         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);
+
+ //the old way:
+ //const XML_Char * pszAfter = UT_getAttribute("section-space-after",pszSecProps);
+ //const XML_Char * pszMaxHeight = UT_getAttribute("section-max-column-height",pszSecProps);
+ UT_XML_strncpy(pszAfter, 25, (const XML_Char *) UT_reformatDimensionString(dim,UT_getAttribute("section-space-after",pszSecProps)));
+ UT_XML_strncpy(pszMaxHeight, 25, (const XML_Char *) UT_reformatDimensionString(dim,UT_getAttribute("section-max-column-height",pszSecProps)));
+
         if(pszAfter && *pszAfter)
         {
                 m_SpaceAfterString = (const char *) pszAfter;
Index: abi/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
--- abi/src/wp/ap/xp/ap_Dialog_Columns.h 2001/10/03 07:42:58 1.5
+++ abi/src/wp/ap/xp/ap_Dialog_Columns.h 2002/01/27 03:46:22
@@ -31,6 +31,9 @@
 
 #include "xap_Preview.h"
 
+// this is needed to get the ruler units.
+#include "ap_Prefs_SchemeIds.h"
+
 class AP_Columns_preview_drawer
 {
 public:
@@ -100,7 +103,7 @@
                                                         UT_uint32 width,
                                                         UT_uint32 height);
         void _drawColumnButton(GR_Graphics *gc, UT_Rect rect, UT_uint32 iColumns);
-
+
         AP_Dialog_Columns::tAnswer m_answer;
         AP_Columns_preview * m_pColumnsPreview;
         AP_Columns_preview_drawer m_previewDrawer;



This archive was generated by hypermail 2b25 : Sat Jan 26 2002 - 23:05:20 CST