Index: src/af/util/xp/ut_units.cpp =================================================================== RCS file: /cvsroot/abi/src/af/util/xp/ut_units.cpp,v retrieving revision 1.35 diff -u -r1.35 ut_units.cpp --- src/af/util/xp/ut_units.cpp 2001/02/06 22:54:11 1.35 +++ src/af/util/xp/ut_units.cpp 2001/04/15 09:36:43 @@ -449,6 +449,25 @@ return (UT_sint32)(dInches * dResolution); } +double UT_inchesFromPaperUnits(UT_sint32 iPaperUnits) +{ + // convert inches into "paper" units. + // paper units are a relatively low-resolution (say + // 1/100 inch) but are suitable for specifying margins, + // etc. -- stuff relative to the actual paper. + + double dResolution = UT_PAPER_UNITS_PER_INCH; + + return ((double)iPaperUnits / dResolution); +} + +UT_sint32 UT_paperUnitsFromInches(double dInches) +{ + double dResolution = UT_PAPER_UNITS_PER_INCH; + + return (UT_sint32)(dInches * dResolution); +} + UT_sint32 UT_docUnitsFromPaperUnits(GR_Graphics * pG, UT_sint32 iPaperUnits) { // convert number in paper units (see above) into Index: src/af/util/xp/ut_units.h =================================================================== RCS file: /cvsroot/abi/src/af/util/xp/ut_units.h,v retrieving revision 1.25 diff -u -r1.25 ut_units.h --- src/af/util/xp/ut_units.h 2001/03/09 23:31:57 1.25 +++ src/af/util/xp/ut_units.h 2001/04/15 09:36:43 @@ -51,6 +51,8 @@ double UT_convertInchesToDimension(double inches, UT_Dimension dim); UT_sint32 UT_paperUnits(const char * sz); +double UT_inchesFromPaperUnits(UT_sint32 iPaperUnits); +UT_sint32 UT_paperUnitsFromInches(double dInches); UT_sint32 UT_docUnitsFromPaperUnits(GR_Graphics * pG, UT_sint32 iPaperUnits); UT_sint32 UT_layoutUnitsFromPaperUnits(UT_sint32 iPaperUnits); UT_sint32 UT_paperUnitsFromLayoutUnits(UT_sint32 iLayoutUnits); Index: src/wp/ap/xp/ap_Dialog_Paragraph.cpp =================================================================== RCS file: /cvsroot/abi/src/wp/ap/xp/ap_Dialog_Paragraph.cpp,v retrieving revision 1.37 diff -u -r1.37 ap_Dialog_Paragraph.cpp --- src/wp/ap/xp/ap_Dialog_Paragraph.cpp 2001/02/22 06:55:50 1.37 +++ src/wp/ap/xp/ap_Dialog_Paragraph.cpp 2001/04/15 09:36:43 @@ -36,10 +36,13 @@ #include "fl_DocLayout.h" #include "fl_BlockLayout.h" +#include "fp_PageSize.h" + #include "ap_Preview_Paragraph.h" #include "ap_Dialog_Paragraph.h" #include "ap_Prefs_SchemeIds.h" +#include "pp_Property.h" AP_Dialog_Paragraph::AP_Dialog_Paragraph(XAP_DialogFactory* pDlgFactory, XAP_Dialog_Id id) : XAP_Dialog_NonPersistent(pDlgFactory,id) @@ -266,7 +269,9 @@ // NOTE : of lines to consider an orphaned or widowed piece of text. // NOTE : If they're both 0 they're off. If either is greater than // NOTE : 0, then some form of control is in effect. If the property - // NOTE : is not set, they're indeterminate. + // NOTE : is not set, they're indeterminate (e.g. because we're setting + // NOTE : properties for text with multiple "orphans" values), or because + // NOTE : the block has no value for orphans/widows here. bool bNoOrphans = false; bool bNoWidows = false; @@ -315,17 +320,28 @@ else _setCheckItemValue(id_CHECK_KEEP_NEXT, check_INDETERMINATE, op_INIT); + // these are not like the others, they set fields on this, not dialogData. sz = UT_getAttribute("page-margin-left", pProps); if (sz) { UT_XML_cloneString(m_pageLeftMargin, sz); } + else + { + UT_XML_cloneString(m_pageLeftMargin, + PP_lookupProperty("page-margin-left")->getInitial()); + } sz = UT_getAttribute("page-margin-right", pProps); if (sz) { UT_XML_cloneString(m_pageRightMargin, sz); } + else + { + UT_XML_cloneString(m_pageRightMargin, + PP_lookupProperty("page-margin-right")->getInitial()); + } // TODO : add these to PP_Property (pp_Property.cpp) !!! // TODO : and to FV_View::getBlockFormat (or else they won't come in) @@ -802,11 +818,8 @@ break; case id_SPIN_SPECIAL_INDENT: - // NOTE : special indent doesn't mean anything as a negative number. - // NOTE : we flip the sign and apply the resultant magnitude to - // NOTE : the current indent type - UT_XML_strncpy((XML_Char *) pItem->pData, SPIN_BUF_TEXT_SIZE, UT_reformatDimensionString(m_dim, _makeAbsolute(value))); + UT_XML_strncpy((XML_Char *) pItem->pData, SPIN_BUF_TEXT_SIZE, UT_reformatDimensionString(m_dim, value)); break; case id_SPIN_BEFORE_SPACING: @@ -983,8 +996,10 @@ { // need to check the limits // cannot go past left page margin. + // TODO : is there a minimum text width? double leftPageMargin = UT_convertToDimension(m_pageLeftMargin, m_dim); + double rightIndent = UT_convertToDimension(_getSpinItemValue(id_SPIN_RIGHT_INDENT), m_dim); if(-UT_convertToDimension(_getSpinItemValue(id_SPIN_LEFT_INDENT), m_dim) > leftPageMargin) @@ -993,6 +1008,15 @@ (const XML_Char *)UT_formatDimensionString(m_dim, -leftPageMargin), op_SYNC); } + + // nor past pagesize - rightIndent on right. + if(UT_convertDimensionless(_getSpinItemValue(id_SPIN_LEFT_INDENT)) > + UT_convertInchesToDimension(m_iMaxWidth, m_dim) - rightIndent) + { + _setSpinItemValue(id_SPIN_LEFT_INDENT, + (const XML_Char *)UT_convertInchesToDimensionString(m_dim, m_iMaxWidth - rightIndent), + op_SYNC); + } } if(changed == id_SPIN_RIGHT_INDENT) @@ -1001,6 +1025,7 @@ // cannot go past right page margin. double rightPageMargin = UT_convertToDimension(m_pageRightMargin, m_dim); + double leftIndent = UT_convertToDimension(_getSpinItemValue(id_SPIN_LEFT_INDENT), m_dim); if(-UT_convertToDimension(_getSpinItemValue(id_SPIN_RIGHT_INDENT), m_dim) > rightPageMargin) @@ -1009,60 +1034,114 @@ (const XML_Char *)UT_formatDimensionString(m_dim, -rightPageMargin), op_SYNC); } - } - - if (changed == id_SPIN_SPECIAL_INDENT) - { - switch(_getMenuItemValue(id_MENU_SPECIAL_INDENT)) - { - case indent_NONE: - _setMenuItemValue(id_MENU_SPECIAL_INDENT, indent_FIRSTLINE, op_SYNC); - break; - default: - break; - } + // nor can we force text left past pagesize, minus left margin + if(UT_convertDimensionless(_getSpinItemValue(id_SPIN_RIGHT_INDENT)) > + UT_convertInchesToDimension(m_iMaxWidth, m_dim) - leftIndent) + { + _setSpinItemValue(id_SPIN_RIGHT_INDENT, + (const XML_Char *)UT_convertInchesToDimensionString(m_dim, m_iMaxWidth - leftIndent), + op_SYNC); + } } - if (changed == id_MENU_SPECIAL_INDENT) + if (changed == id_MENU_SPECIAL_INDENT || changed == id_SPIN_SPECIAL_INDENT) { double dDefault = 0.0; bool bDefault = true; + + double sign = -1.0; + if (_getMenuItemValue(id_MENU_SPECIAL_INDENT) == indent_FIRSTLINE) + sign = +1.0; - switch(_getMenuItemValue(id_MENU_SPECIAL_INDENT)) + if (changed == id_MENU_SPECIAL_INDENT) { - case indent_NONE: - dDefault = 0.0; - break; + switch(_getMenuItemValue(id_MENU_SPECIAL_INDENT)) + { + case indent_NONE: + dDefault = 0.0; + break; + + case indent_FIRSTLINE: + case indent_HANGING: + // only change to default if existing value is zero + dDefault = UT_convertDimensionless(_getSpinItemValue(id_SPIN_SPECIAL_INDENT)); + if (dDefault == 0) + { + bDefault = false; + } + else + { + dDefault = 0.5; + } + break; - case indent_FIRSTLINE: - case indent_HANGING: - // only change to default if existing value is zero - dDefault = UT_convertDimensionless(_getSpinItemValue(id_SPIN_SPECIAL_INDENT)); - if (dDefault > 0) + default: + UT_ASSERT(UT_SHOULD_NOT_HAPPEN); + break; + } + + if (bDefault) { - bDefault = false; + if (m_dim != DIM_IN) + dDefault = UT_convertInchesToDimension(dDefault, m_dim); + + const XML_Char* szNew = UT_convertInchesToDimensionString(m_dim, dDefault, ".1"); + + _setSpinItemValue(id_SPIN_SPECIAL_INDENT, szNew, op_SYNC); } - else + } + else /* (changed == id_SPIN_SPECIAL_INDENT) */ + { + switch(_getMenuItemValue(id_MENU_SPECIAL_INDENT)) { - dDefault = 0.5; + case indent_NONE: + _setMenuItemValue(id_MENU_SPECIAL_INDENT, indent_FIRSTLINE, op_SYNC); + break; + + default: + break; } - break; + } - default: - UT_ASSERT(UT_SHOULD_NOT_HAPPEN); - break; + // if spin contains a negative number, we flip the direction of the indent. + double val = UT_convertDimensionless(_getSpinItemValue(id_SPIN_SPECIAL_INDENT)); + if (val < 0) + { + sign = -sign; + + // sometimes this appears to have no effect. why? + if (_getMenuItemValue(id_MENU_SPECIAL_INDENT) == indent_FIRSTLINE) + _setMenuItemValue(id_MENU_SPECIAL_INDENT, indent_HANGING, op_SYNC); + else if (_getMenuItemValue(id_MENU_SPECIAL_INDENT) == indent_HANGING) + _setMenuItemValue(id_MENU_SPECIAL_INDENT, indent_FIRSTLINE, op_SYNC); + + const XML_Char* szNew = UT_convertInchesToDimensionString(m_dim, -val, ".1"); + _setSpinItemValue(id_SPIN_SPECIAL_INDENT, szNew, op_SYNC); } - if (bDefault) - { - if (m_dim != DIM_IN) - dDefault = UT_convertInchesToDimension(dDefault, m_dim); + // sanity check. - const XML_Char* szNew = UT_convertInchesToDimensionString(m_dim, dDefault, ".1"); + double effectiveLeftMargin = UT_convertToDimension + (_getSpinItemValue(id_SPIN_SPECIAL_INDENT), m_dim) * sign; - _setSpinItemValue(id_SPIN_SPECIAL_INDENT, szNew, op_SYNC); + double leftPageMargin = UT_convertToDimension(m_pageLeftMargin, m_dim); + double rightIndent = UT_convertToDimension(_getSpinItemValue(id_SPIN_RIGHT_INDENT), m_dim); + + if(-effectiveLeftMargin > leftPageMargin) + { + _setSpinItemValue(id_SPIN_SPECIAL_INDENT, + (const XML_Char *)UT_formatDimensionString(m_dim, -leftPageMargin), + op_SYNC); } + + if(effectiveLeftMargin > + UT_convertInchesToDimension(m_iMaxWidth, m_dim) - rightIndent) + { + _setSpinItemValue(id_SPIN_SPECIAL_INDENT, + (const XML_Char *)UT_convertInchesToDimensionString(m_dim, m_iMaxWidth - rightIndent), + op_SYNC); + } } if (changed == id_SPIN_SPECIAL_SPACING) Index: src/wp/ap/xp/ap_Dialog_Paragraph.h =================================================================== RCS file: /cvsroot/abi/src/wp/ap/xp/ap_Dialog_Paragraph.h,v retrieving revision 1.15 diff -u -r1.15 ap_Dialog_Paragraph.h --- src/wp/ap/xp/ap_Dialog_Paragraph.h 2001/03/29 00:22:47 1.15 +++ src/wp/ap/xp/ap_Dialog_Paragraph.h 2001/04/15 09:36:43 @@ -54,6 +54,9 @@ bool setDialogData(const XML_Char ** pProps); bool getDialogData(const XML_Char **& pProps); + // expects a width in paper units. + void setMaxWidth(UT_sint32 width) { m_iMaxWidth = UT_inchesFromPaperUnits(width); } + AP_Dialog_Paragraph::tAnswer getAnswer(void) const; protected: @@ -122,6 +125,9 @@ // which dimension system we're using as "native" for this document UT_Dimension m_dim; + + // current column width, in inches. + double m_iMaxWidth; private: void _addPropertyItem(UT_uint32 index, void* pValue); Index: src/wp/ap/xp/ap_EditMethods.cpp =================================================================== RCS file: /cvsroot/abi/src/wp/ap/xp/ap_EditMethods.cpp,v retrieving revision 1.324 diff -u -r1.324 ap_EditMethods.cpp --- src/wp/ap/xp/ap_EditMethods.cpp 2001/04/14 20:16:13 1.324 +++ src/wp/ap/xp/ap_EditMethods.cpp 2001/04/15 09:36:44 @@ -42,6 +42,7 @@ #include "ap_LoadBindings.h" #include "ap_FrameData.h" #include "ap_LeftRuler.h" +#include "ap_TopRuler.h" #include "ap_Prefs.h" #include "ut_string_class.h" @@ -3961,7 +3962,14 @@ return false; FREEP(props); - + + // let's steal the width from getTopRulerInfo. + AP_TopRulerInfo info; + pView->getTopRulerInfo(&info); + + // TODO tables + pDialog->setMaxWidth (info.u.c.m_xColumnWidth); + // run the dialog pDialog->runModal(pFrame); Index: src/wp/ap/xp/ap_Preview_Paragraph.cpp =================================================================== RCS file: /cvsroot/abi/src/wp/ap/xp/ap_Preview_Paragraph.cpp,v retrieving revision 1.23 diff -u -r1.23 ap_Preview_Paragraph.cpp --- src/wp/ap/xp/ap_Preview_Paragraph.cpp 2001/03/29 00:22:47 1.23 +++ src/wp/ap/xp/ap_Preview_Paragraph.cpp 2001/04/15 09:36:44 @@ -183,7 +183,7 @@ } else { - m_rightStop = DEFAULT_LEFT_STOP; + m_rightStop = DEFAULT_RIGHT_STOP; } // right margins are in or out from the default stop @@ -625,17 +625,22 @@ y += ypost; // handle all other lines until out of words - while (wordCounter < wordCount) + UT_uint32 newWords = 1; + while (wordCounter < wordCount && newWords > 0) { // handle any spacing before this line y += ypre; - wordCounter += _appendLine(&block->m_words, - &block->m_widths, - wordCounter, - block->m_leftStop, - block->m_rightStop, - block->m_align, - y); + + newWords = _appendLine(&block->m_words, + &block->m_widths, + wordCounter, + block->m_leftStop, + block->m_rightStop, + block->m_align, + y); + + wordCounter += newWords; + y += block->m_fontHeight; // handle any spacing after this line y += ypost; @@ -672,8 +677,9 @@ // left stop and the (normal) right stop UT_sint32 maxPixelsForThisLine = getWindowWidth() - left - right; - // negative or zero makes no sense - UT_ASSERT(maxPixelsForThisLine > 0); + // negative or zero makes no sense; bail in that case (callers can deal) + if (maxPixelsForThisLine <= 0) + return 0; i = startWithWord; @@ -689,7 +695,7 @@ if(i == startWithWord) { - // HACK: Make sure we have at least one word. + // HACK: Make sure we have at least one word. (no longer true, because of above) pixelsForThisLine += (UT_uint32) widths->getNthItem(i) + spaceCharWidth; i++;