[patch] "normal" layout

Aaron Lehmann (aaronl@vitelus.com)
Fri, 11 Jun 1999 07:38:37 +0000 ( )


Hi,

I went ahead and played arround in src/text/fmt/xp and came up with a
partially-complete patch for a "normal" layout mode. Note that this patch
forces abiword to use normal mode, since I haven't even tried playing with
menu items and etc. yet.

If someone a little more advanced than me could implement a few menu items
to switch between modes. All that would be necessary would be changing:

pView = (FV_View*) new FV_View_Normal (getApp(), this, pDocLayout);

to

if (pagelayout)
pView = new FV_View (getApp(), this, pDocLayout);

else if (normal)
pView = (FV_View*) new FV_View_Normal (getApp(), this,
pDocLayout);

else if (outline
pView = (FV_View*) new FV_View_Outline (getApp(), this,
pDocLayout); // Haven't writting this class yet, but reorganized some code
in FV_View to make it easier to derive from it. Someone could do
FV_View_Outline the way FV_View_Normal is done, overriding more functions
if neccesary.

in:
src/wp/ap/unix/ap_UnixFrame.cpp
src/wp/ap/beos/ap_BeOSFrame.cpp
src/wp/ap/win/ap_Win32Frame.cpp
(I wonder why these are in non-xp code).

Anyway, once switching between modes is worked out, there's only one more
problem (that i've noticed), being that there is still a margin between
pages. If someone knows how to fix this, please tell me.

While I was testing this patch I found a refresh bug in AbiWord. I don't
know if it's in bugzilla (probably, all that's necessary to reproduce on
unix is to put another window in front of it and scroll up and down...
gray horizontal lines appear in the text area). But this isn't my fault -
I can reproduce it with the 0.7.1 deb release.

And I must point out - Abi is one of the best organized large source trees
I had ever seen. I was able to dive into it and understand how everything
worked. Perhaps becuase it's good old C++ :).

Here's the diff, against cvs a few hours ago:

diff -urN abi.vanilla/src/text/fmt/xp/Makefile abi/src/text/fmt/xp/Makefile
--- abi.vanilla/src/text/fmt/xp/Makefile Sun May 23 15:25:56 1999
+++ abi/src/text/fmt/xp/Makefile Thu Jun 10 19:22:08 1999
@@ -24,6 +24,7 @@

CPPSRCS= fv_View.cpp \
fv_View_TestRoutines.cpp \
+ fv_View_Normal.cpp \
fb_LineBreaker.cpp \
fl_BlockLayout.cpp \
fl_DocLayout.cpp \
diff -urN abi.vanilla/src/text/fmt/xp/fl_DocLayout.cpp abi/src/text/fmt/xp/fl_DocLayout.cpp
--- abi.vanilla/src/text/fmt/xp/fl_DocLayout.cpp Tue Jun 1 21:05:33 1999
+++ abi/src/text/fmt/xp/fl_DocLayout.cpp Thu Jun 10 20:41:40 1999
@@ -128,8 +128,8 @@
if (m_pG->queryProperties(GR_Graphics::DGP_SCREEN))
{
// add page view dimensions
- iHeight += fl_PAGEVIEW_PAGE_SEP * (count - 1);
- iHeight += fl_PAGEVIEW_MARGIN_Y * 2;
+ iHeight += m_pView->fl_PAGEVIEW_PAGE_SEP * (count - 1);
+ iHeight += m_pView->fl_PAGEVIEW_MARGIN_Y * 2;
}

return iHeight;
@@ -152,7 +152,7 @@
if (m_pG->queryProperties(GR_Graphics::DGP_SCREEN))
{
// add page view dimensions
- iWidth += fl_PAGEVIEW_MARGIN_X * 2;
+ iWidth += m_pView->fl_PAGEVIEW_MARGIN_X * 2;
}

return iWidth;
diff -urN abi.vanilla/src/text/fmt/xp/fl_DocLayout.h abi/src/text/fmt/xp/fl_DocLayout.h
--- abi.vanilla/src/text/fmt/xp/fl_DocLayout.h Wed Apr 7 13:46:43 1999
+++ abi/src/text/fmt/xp/fl_DocLayout.h Thu Jun 10 20:07:16 1999
@@ -39,13 +39,6 @@
class UT_Timer;
class fl_PartOfBlock;

-
-// the following get used by view and layout code,
-// since they're private to the formatter, we stick 'em here
-#define fl_PAGEVIEW_PAGE_SEP 20 // must be <= MARGIN_Y
-#define fl_PAGEVIEW_MARGIN_X 25
-#define fl_PAGEVIEW_MARGIN_Y 25
-
// ----------------------------------------------------------------
/*
FL_DocLayout is a formatted representation of a specific PD_Document,
diff -urN abi.vanilla/src/text/fmt/xp/fv_View.cpp abi/src/text/fmt/xp/fv_View.cpp
--- abi.vanilla/src/text/fmt/xp/fv_View.cpp Wed May 26 21:45:55 1999
+++ abi/src/text/fmt/xp/fv_View.cpp Thu Jun 10 21:27:14 1999
@@ -75,6 +75,11 @@
FV_View::FV_View(XAP_App * pApp, void* pParentData, FL_DocLayout* pLayout)
: AV_View(pApp, pParentData)
{
+ fl_PAGEVIEW_MARGIN_X = 25;
+ fl_PAGEVIEW_MARGIN_Y = 25;
+ fl_PAGEVIEW_PAGE_SEP = 20;
+
+
m_pLayout = pLayout;
m_pDoc = pLayout->getDocument();
m_pG = m_pLayout->getGraphics();
@@ -3662,6 +3667,7 @@
#endif

}
+

void FV_View::cmdScroll(AV_ScrollCmd cmd, UT_uint32 iPos)
{
diff -urN abi.vanilla/src/text/fmt/xp/fv_View.h abi/src/text/fmt/xp/fv_View.h
--- abi.vanilla/src/text/fmt/xp/fv_View.h Sun May 23 15:25:56 1999
+++ abi/src/text/fmt/xp/fv_View.h Thu Jun 10 20:05:48 1999
@@ -140,6 +140,7 @@
UT_Bool setStyle(const XML_Char * style);
UT_Bool getStyle(const XML_Char ** style);

+ UT_uint16 fl_PAGEVIEW_MARGIN_X, fl_PAGEVIEW_MARGIN_Y, fl_PAGEVIEW_PAGE_SEP;
void insertParagraphBreak(void);
void insertSectionBreak(void);

@@ -207,7 +208,7 @@
protected:
void _generalUpdate(void);

- void _draw(UT_sint32, UT_sint32, UT_sint32, UT_sint32, UT_Bool bDirtyRunsOnly, UT_Bool bClip=UT_FALSE);
+ virtual void _draw(UT_sint32, UT_sint32, UT_sint32, UT_sint32, UT_Bool bDirtyRunsOnly, UT_Bool bClip=UT_FALSE);

void _drawBetweenPositions(PT_DocPosition left, PT_DocPosition right);
void _clearBetweenPositions(PT_DocPosition left, PT_DocPosition right, UT_Bool bFullLineHeightRect);
diff -urN abi.vanilla/src/text/fmt/xp/fv_View_Normal.cpp abi/src/text/fmt/xp/fv_View_Normal.cpp
--- abi.vanilla/src/text/fmt/xp/fv_View_Normal.cpp Wed Dec 31 16:00:00 1969
+++ abi/src/text/fmt/xp/fv_View_Normal.cpp Fri Jun 11 00:00:34 1999
@@ -0,0 +1,272 @@
+/* AbiWord
+ * Copyright (C) 1998 AbiSource, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "ut_assert.h"
+#include "ut_debugmsg.h"
+#include "ut_growbuf.h"
+#include "ut_misc.h"
+#include "ut_string.h"
+#include "ut_bytebuf.h"
+#include "ut_timer.h"
+
+#include "xav_View.h"
+#include "fl_DocLayout.h"
+#include "fl_BlockLayout.h"
+#include "fl_SectionLayout.h"
+#include "fp_Page.h"
+#include "fp_Column.h"
+#include "fp_Line.h"
+#include "fp_Run.h"
+#include "fg_Graphic.h"
+#include "fg_GraphicRaster.h"
+#include "pd_Document.h"
+#include "pd_Style.h"
+#include "pp_Property.h"
+#include "pp_AttrProp.h"
+#include "gr_Graphics.h"
+#include "gr_DrawArgs.h"
+#include "ie_types.h"
+#include "xap_App.h"
+
+#ifndef FV_VIEW_NORMAL_H
+#include "fv_View_Normal.h"
+#endif
+
+void FV_View_Normal::_draw(UT_sint32 x, UT_sint32 y,
+ UT_sint32 width, UT_sint32 height,
+ UT_Bool bDirtyRunsOnly, UT_Bool bClip)
+{
+ xxx_UT_DEBUGMSG(("FV_View::draw_3 [x %ld][y %ld][w %ld][h %ld][bClip %ld]\n"
+ "\t\twith [yScrollOffset %ld][windowHeight %ld]\n",
+ x,y,width,height,bClip,
+ m_yScrollOffset,m_iWindowHeight));
+
+ // this can happen when the frame size is decreased and
+ // only the toolbars show...
+ if ((m_iWindowWidth <= 0) || (m_iWindowHeight <= 0))
+ {
+ UT_DEBUGMSG(("fv_View::draw() called with zero drawing area.\n"));
+ return;
+ }
+
+ if ((width <= 0) || (height <= 0))
+ {
+ UT_DEBUGMSG(("fv_View::draw() called with zero width or height expose.\n"));
+ return;
+ }
+
+ if (bClip)
+ {
+ UT_Rect r;
+
+ r.left = x;
+ r.top = y;
+ r.width = width;
+ r.height = height;
+
+ m_pG->setClipRect(&r);
+ }
+
+ // figure out where pages go, based on current window dimensions
+ // TODO: don't calc for every draw
+ // HYP: cache calc results at scroll/size time
+ UT_sint32 iDocHeight = m_pLayout->getHeight();
+
+ // TODO: handle positioning within oversized viewport
+ // TODO: handle variable-size pages (envelope, landscape, etc.)
+
+ /*
+ In page view mode, so draw outside decorations first, then each
+ page with its decorations.
+ */
+
+ UT_RGBColor clrMargin(127,127,127); // dark gray
+
+ if (!bDirtyRunsOnly)
+ {
+ if (m_xScrollOffset < fl_PAGEVIEW_MARGIN_X)
+ {
+ // fill left margin
+ m_pG->fillRect(clrMargin, 0, 0, fl_PAGEVIEW_MARGIN_X - m_xScrollOffset, m_iWindowHeight);
+ }
+
+ if (m_yScrollOffset < fl_PAGEVIEW_MARGIN_Y)
+ {
+ // fill top margin
+ m_pG->fillRect(clrMargin, 0, 0, m_iWindowWidth, fl_PAGEVIEW_MARGIN_Y - m_yScrollOffset);
+ }
+ }
+
+ UT_sint32 curY = fl_PAGEVIEW_MARGIN_Y;
+ fp_Page* pPage = m_pLayout->getFirstPage();
+ while (pPage)
+ {
+ UT_sint32 iPageWidth = pPage->getWidth();
+ UT_sint32 iPageHeight = pPage->getHeight();
+ UT_sint32 adjustedTop = curY - m_yScrollOffset;
+ UT_sint32 adjustedBottom = adjustedTop + iPageHeight + fl_PAGEVIEW_PAGE_SEP;
+ if (adjustedTop > m_iWindowHeight)
+ {
+ // the start of this page is past the bottom
+ // of the window, so we don't need to draw it.
+
+ xxx_UT_DEBUGMSG(("not drawing page A: iPageHeight=%d curY=%d nPos=%d m_iWindowHeight=%d\n",
+ iPageHeight,
+ curY,
+ m_yScrollOffset,
+ m_iWindowHeight));
+
+ // since all other pages are below this one, we
+ // don't need to draw them either. exit loop now.
+ break;
+ }
+ else if (adjustedBottom < 0)
+ {
+ // the end of this page is above the top of
+ // the window, so we don't need to draw it.
+
+ xxx_UT_DEBUGMSG(("not drawing page B: iPageHeight=%d curY=%d nPos=%d m_iWindowHeight=%d\n",
+ iPageHeight,
+ curY,
+ m_yScrollOffset,
+ m_iWindowHeight));
+ }
+ else if (adjustedTop > y + height)
+ {
+ // the top of this page is beyond the end
+ // of the clipping region, so we don't need
+ // to draw it.
+
+ xxx_UT_DEBUGMSG(("not drawing page C: iPageHeight=%d curY=%d nPos=%d m_iWindowHeight=%d y=%d h=%d\n",
+ iPageHeight,
+ curY,
+ m_yScrollOffset,
+ m_iWindowHeight,
+ y,height));
+ }
+ else if (adjustedBottom < y)
+ {
+ // the bottom of this page is above the top
+ // of the clipping region, so we don't need
+ // to draw it.
+
+ xxx_UT_DEBUGMSG(("not drawing page D: iPageHeight=%d curY=%d nPos=%d m_iWindowHeight=%d y=%d h=%d\n",
+ iPageHeight,
+ curY,
+ m_yScrollOffset,
+ m_iWindowHeight,
+ y,height));
+ }
+ else
+ {
+ // this page is on screen and intersects the clipping region,
+ // so we *DO* draw it.
+
+ xxx_UT_DEBUGMSG(("drawing page E: iPageHeight=%d curY=%d nPos=%d m_iWindowHeight=%d y=%d h=%d\n",
+ iPageHeight,curY,m_yScrollOffset,m_iWindowHeight,y,height));
+
+ dg_DrawArgs da;
+
+ da.bDirtyRunsOnly = bDirtyRunsOnly;
+ da.pG = m_pG;
+ da.xoff = fl_PAGEVIEW_MARGIN_X - m_xScrollOffset;
+ da.yoff = adjustedTop;
+
+ UT_sint32 adjustedLeft = fl_PAGEVIEW_MARGIN_X - m_xScrollOffset;
+ UT_sint32 adjustedRight = adjustedLeft + iPageWidth;
+
+ adjustedBottom -= fl_PAGEVIEW_PAGE_SEP;
+
+ UT_RGBColor clrPaper(255,255,255);
+
+ if (!bDirtyRunsOnly || pPage->needsRedraw())
+ {
+ m_pG->fillRect(clrPaper,adjustedLeft+1,adjustedTop+1,iPageWidth-1,iPageHeight-1);
+ }
+
+ pPage->draw(&da);
+
+ // draw page decorations
+ UT_RGBColor clr(0,0,0), clrLG(211,211,211); // black
+ m_pG->setColor(clrLG);
+ // one pixel border
+ m_pG->drawLine(adjustedLeft, adjustedTop, adjustedRight, adjustedTop);
+ m_pG->drawLine(adjustedRight, adjustedTop, adjustedRight, adjustedBottom);
+ m_pG->drawLine(adjustedLeft, adjustedBottom, adjustedLeft, adjustedTop);
+ m_pG->drawLine(adjustedRight, adjustedBottom, adjustedLeft, adjustedBottom);
+ m_pG->setColor(clr);
+
+ // fill to right of page
+ m_pG->fillRect(clrPaper, adjustedRight + 1, adjustedTop, m_iWindowWidth - (adjustedRight + 1), iPageHeight + 1);
+
+ // fill separator below page
+ m_pG->fillRect(clrMargin, adjustedLeft, adjustedBottom + 1, m_iWindowWidth - adjustedLeft, fl_PAGEVIEW_PAGE_SEP);
+
+ // two pixel drop shadow
+ /*adjustedLeft += 3;
+ adjustedBottom += 1;
+ m_pG->drawLine(adjustedLeft, adjustedBottom, adjustedRight+1, adjustedBottom);
+ adjustedBottom += 1;
+ m_pG->drawLine(adjustedLeft, adjustedBottom, adjustedRight+1, adjustedBottom);
+
+ adjustedTop += 3;
+ adjustedRight += 1;
+ m_pG->drawLine(adjustedRight, adjustedTop, adjustedRight, adjustedBottom+1);
+ adjustedRight += 1;
+ m_pG->drawLine(adjustedRight, adjustedTop, adjustedRight, adjustedBottom+1);*/
+ }
+
+ curY += iPageHeight + fl_PAGEVIEW_PAGE_SEP;
+
+ pPage = pPage->getNext();
+ }
+
+ if (curY < iDocHeight)
+ {
+ // fill below bottom of document
+ UT_sint32 y = curY - m_yScrollOffset + 1;
+ UT_sint32 h = m_iWindowHeight - y;
+
+ m_pG->fillRect(clrMargin, 0, y, m_iWindowWidth, h);
+ }
+
+ if (!bDirtyRunsOnly)
+ {
+ _fixInsertionPointCoords();
+ _drawInsertionPoint();
+ }
+
+ if (bClip)
+ {
+ m_pG->setClipRect(NULL);
+ }
+
+#if 0
+ {
+ // Some test code for the graphics interface.
+ UT_RGBColor clrRed(255,0,0);
+ m_pG->setColor(clrRed);
+ m_pG->drawLine(10,10,20,10);
+ m_pG->drawLine(20,11,30,11);
+ m_pG->fillRect(clrRed,50,10,10,10);
+ m_pG->fillRect(clrRed,60,20,10,10);
+ }
+#endif
+
+}
diff -urN abi.vanilla/src/text/fmt/xp/fv_View_Normal.h abi/src/text/fmt/xp/fv_View_Normal.h
--- abi.vanilla/src/text/fmt/xp/fv_View_Normal.h Wed Dec 31 16:00:00 1969
+++ abi/src/text/fmt/xp/fv_View_Normal.h Thu Jun 10 21:49:43 1999
@@ -0,0 +1,41 @@
+/* AbiWord
+ * Copyright (C) 1998 AbiSource, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+#ifndef FV_VIEW_NORMAL_H
+#define FV_VIEW_NORMAL_H
+
+#include "fv_View.h"
+
+class FV_View_Normal : public FV_View
+{
+public:
+ FV_View_Normal(XAP_App* one1, void* two2, FL_DocLayout* three3) : FV_View (one1, two2, three3)
+ {
+ fl_PAGEVIEW_MARGIN_X = 0;
+ fl_PAGEVIEW_MARGIN_Y = 0;
+ fl_PAGEVIEW_PAGE_SEP = 0;
+ }
+ ~FV_View_Normal()
+ {
+ this -> FV_View::~FV_View ();
+ }
+protected:
+ virtual void _draw(UT_sint32, UT_sint32, UT_sint32, UT_sint32, UT_Bool, UT_Bool bClip=UT_FALSE);
+};
+
+#endif
diff -urN abi.vanilla/src/wp/ap/beos/ap_BeOSFrame.cpp abi/src/wp/ap/beos/ap_BeOSFrame.cpp
--- abi.vanilla/src/wp/ap/beos/ap_BeOSFrame.cpp Fri Jun 4 21:41:37 1999
+++ abi/src/wp/ap/beos/ap_BeOSFrame.cpp Thu Jun 10 21:46:50 1999
@@ -27,6 +27,7 @@
#include "xav_View.h"
#include "xad_Document.h"
#include "fv_View.h"
+#include "fv_View_Normal.h"
#include "fl_DocLayout.h"
#include "pd_Document.h"
#include "gr_BeOSGraphics.h"
@@ -95,7 +96,7 @@

// pDocLayout->formatAll();

- pView = new FV_View(getApp(), this, pDocLayout);
+ pView = (FV_View*) new FV_View_Normal(getApp(), this, pDocLayout);
ENSUREP(pView);

// The "AV_ScrollObj pScrollObj" receives
diff -urN abi.vanilla/src/wp/ap/unix/ap_UnixFrame.cpp abi/src/wp/ap/unix/ap_UnixFrame.cpp
--- abi.vanilla/src/wp/ap/unix/ap_UnixFrame.cpp Mon May 17 14:46:57 1999
+++ abi/src/wp/ap/unix/ap_UnixFrame.cpp Thu Jun 10 21:45:51 1999
@@ -29,6 +29,7 @@
#include "xav_View.h"
#include "xad_Document.h"
#include "fv_View.h"
+#include "fv_View_Normal.h"
#include "fl_DocLayout.h"
#include "pd_Document.h"
#include "gr_UnixGraphics.h"
@@ -99,7 +100,7 @@

// pDocLayout->formatAll();

- pView = new FV_View(getApp(), this, pDocLayout);
+ pView = (FV_View*) new FV_View_Normal (getApp(), this, pDocLayout);
ENSUREP(pView);

// The "AV_ScrollObj pScrollObj" receives
diff -urN abi.vanilla/src/wp/ap/win/ap_Win32Frame.cpp abi/src/wp/ap/win/ap_Win32Frame.cpp
--- abi.vanilla/src/wp/ap/win/ap_Win32Frame.cpp Tue May 4 12:01:28 1999
+++ abi/src/wp/ap/win/ap_Win32Frame.cpp Thu Jun 10 21:47:22 1999
@@ -30,6 +30,7 @@
#include "xav_View.h"
#include "xad_Document.h"
#include "fv_View.h"
+#include "fv_View_Normal.h"
#include "fl_DocLayout.h"
#include "pd_Document.h"
#include "gr_Win32Graphics.h"
@@ -149,7 +150,7 @@

// pDocLayout->formatAll();

- pView = new FV_View(getApp(), this, pDocLayout);
+ pView = (FV_View*) new FV_View_Normal(getApp(), this, pDocLayout);
ENSUREP(pView);

// The "AV_ScrollObj pScrollObj" receives



This archive was generated by hypermail 1.03b2.