[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice
Subject:    Page Scrolling by Paper Size Patch submitted
From:       John Califf <jcaliff () usit ! net>
Date:       2000-09-20 17:33:53
[Download RAW message or body]

Attached is a patch to kword_page.cc to handle page scrolling in page
size units as discussed, using Control-PageUp and Control-PageDown.  All
my changes are in the keyPressEvent method - in a single block of code. 
The other stuff showing up in the diff file is just spaces somebody put
in (probably me) and is meaninglesss.

I've tested this pretty throughly.  Please review and commit. 

Later I will try to get cvs read-write access from coolo but I really
need to learn more about cvs first, so I currently use anonymous cvs
access. 

If there is a deadline for next week it would help to discuss such
things here but probaby people are busy. In light of the effort to get a
release of KOffice out next week (independently of Kde 2.0 which won't
be ready until the middle of next month?) I will have to limit planned
work to:

1. setting cursor after page scrolling by paper size to allow editing
from the final page navigated to

2.  possible flow enhacements for page scrolling within frames

3.  right mouse click crash fix.  A real fix for this will involve
changes to several files, including the document and flow control stuff.
The problem is invalid frame references caused by using the cursor
position instead of mouse click location, especially when cursor is at
top or bottom of view and partially hidden by scrollbar, as calculating
of the view boundaries is inconsistent.  Sometimes width() and height()
are used and sometimes visibleWidth() and visibleHeight(). It needs to
be consistent, and I don't feel that it would be safe to make such
extensive changes now with a deadline coming up.  A tempory fix in the
mouse event handling code can at least prevent an ugly crash for code
that doesn't do anything but crash anyway...specifically right click
when in text edit mode.

The other changes I've proposed will have to wait til after next week.
Please review and commit what's here, though. Users will expect this
functionality.

John
["kword_page.diff" (text/plain)]

Index: kword_page.cc
===================================================================
RCS file: /home/kde/koffice/kword/kword_page.cc,v
retrieving revision 1.274
diff -u -3 -p -r1.274 kword_page.cc
--- kword_page.cc	2000/09/18 17:44:13	1.274
+++ kword_page.cc	2000/09/20 16:45:34
@@ -431,7 +431,7 @@ void KWPage::vmmEditFrameResize( int mx,
         if(isAHeader(frame->getFrameSet()->getFrameInfo())) move=false;
         if(isAFooter(frame->getFrameSet()->getFrameInfo())) move=false;
         if(mx-newX1 < minFrameWidth) mx=newX1+minFrameHeight+5;
-        if(mx > ptPaperWidth()) 
+        if(mx > ptPaperWidth())
             mx = ptPaperWidth();
 
         if(move) newX2=mx;
@@ -780,7 +780,7 @@ void KWPage::vmpRightButton( QMouseEvent
             if(frame->getFrameSet() && frame->getFrameSet()->getFrameInfo() != \
FI_BODY) return;  // enable delete
             frame_edit_menu->setItemEnabled(frEditDel, true);
-            // if text frame, 
+            // if text frame,
             if(frame->getFrameSet() && frame->getFrameSet()->getFrameType() == \
FT_TEXT) {  // if frameset 0 disable delete
                 if(doc->getProcessingType() == KWordDocument::WP && \
frame->getFrameSet() == doc->getFrameSet(0)) { @@ -789,7 +789,7 @@ void \
KWPage::vmpRightButton( QMouseEvent  } else {
                     frame_edit_menu->setItemEnabled(frEditReconnect, true);
                 }
-            } else 
+            } else
                 frame_edit_menu->setItemEnabled(frEditReconnect, false);
             frame_edit_menu->popup( pnt );
         } break;
@@ -906,13 +906,13 @@ void KWPage::vmrEdit()
 /*================================================================*/
 void KWPage::vmrEditFrame( int mx, int my )
 {
-    int frameset=0; 
+    int frameset=0;
     KWFrame *frame= doc->getFirstSelectedFrame(frameset);
     if(!frame) return;
     if ( doc->getProcessingType() == KWordDocument::DTP )
         setRuler2Frame( frame );
     gui->getHorzRuler()->setFrameStart( frame->x() );
-    
+
     if ( mouseMoved ) {
         doc->recalcFrames();
         doc->updateAllFrames();
@@ -2434,7 +2434,7 @@ bool KWPage::kDown( QKeyEvent *e, int, i
 
 
 /*=============================
-  kNext - Next key handler - same as PageDown. Move cursor down one 
+  kPrior - Prior key handler - same as PageUp. Move cursor up one 
   visible document area height and adjust page view accordingly
 			  ===================================*/
 
@@ -2853,9 +2853,7 @@ void KWPage::keyPressEvent( QKeyEvent *e
 
     inputTimer.stop();
     formatTimer.stop();
-
     startProcessKeyEvent();
-
     editModeChanged( e );
 
     // if we are in a table and CTRL-Return was pressed
@@ -2864,7 +2862,79 @@ void KWPage::keyPressEvent( QKeyEvent *e
         if ( !kInsertTableRow() )
             STOP;
 
-    if ( e->state() & ControlButton ) {
+    /*============================================ 
+     scroll up or down by one paper page height, aligning top of view
+     with top of page. Uses PageUp and PageDown with Alt. key.
+    
+     note that pages returned from calcVisiblePages() start with 1, not 0
+     note also that firstVisiblePage and lastVisiblePage are always different
+     even when only one page is visible - first takes floor and last takes
+     ceiling so there is always a difference of at least one!
+     I adjust by always subtracting 1 from last visible page.
+     if two or more pages are visible this will scroll up to the top of
+     higher one so such pages are not skipped, then scroll a full page 
+     on page alignments from there on.  Scrolling down does not have this
+     problem as it always goes to the start of the next page after top
+     page in view, even if the lower page is partially visible to start.
+    ===========================================*/
+    
+    if ((e->key() == Key_Prior || e->key() == Key_Next) 
+    && (e->state() & ControlButton))
+    {
+          calcVisiblePages();
+	  int ifvPage = static_cast<int>(firstVisiblePage);
+          int ilvPage = static_cast<int>(lastVisiblePage) - 1;	  
+  
+          // determine whether current view is exactly aligned 
+	  // to page boundaries or is in the middle of a page somewhere
+          unsigned int topY = (unsigned int)contentsY();
+	  unsigned int leftover = topY % ptPaperHeight();
+
+          // kdDebug() << "leftover: " << leftover << endl;
+          
+	  if(e->key() == Key_Prior)
+          {
+              stopProcessKeyEvent();	  
+              int priorPage = 0;
+
+              // kdDebug() << "ifvPage: " << ifvPage << " ilvPage: " << ilvPage << \
endl; +	      
+              // scroll to top of next page       
+              if((ifvPage == ilvPage) && (leftover < 2)) 
+              {
+                  priorPage = ifvPage - 1;
+		  if(priorPage > 0)  priorPage -= 1;
+              }
+              else // scroll to top of current page
+              { 
+                  priorPage = ifvPage;
+                  if(priorPage > 0) priorPage -= 1;		  
+              }
+
+              scrollToOffset( 0, (priorPage) * (ptPaperHeight()) + 1);
+          }
+          else if(e->key() == Key_Next)
+          {
+              stopProcessKeyEvent();
+              int nextPage = 1;
+
+              // kdDebug() << "ifvPage: " << ifvPage << " ilvPage: " << ilvPage << \
endl;	      	       +
+              if(ifvPage == ilvPage)
+                  nextPage = ifvPage + 1;
+              else
+                  nextPage =  ifvPage + 1;
+  
+              scrollToOffset( 0, (nextPage - 1) * (ptPaperHeight()) + 1);
+          }  
+          // note: vmrEdit will set cursor at offset into document !!!
+	  // risky - will test later. jwc
+	  // vmrEdit(0, (nextPage - 1) * (ptPaperHeight()) + 1);      
+          return;
+    }
+    
+    // other keys modified by ControlButton
+    else if ( e->state() & ControlButton ) {
         if ( e->key() == Key_B ) {
             stopProcessKeyEvent();
             gui->getView()->textBold();
@@ -2880,7 +2950,7 @@ void KWPage::keyPressEvent( QKeyEvent *e
         }
     }
 
-
+    
     unsigned int oldPage = fc->getPage();
     unsigned int oldFrame = fc->getFrame();
     KWParag* oldParag = fc->getParag();
@@ -2891,6 +2961,7 @@ void KWPage::keyPressEvent( QKeyEvent *e
             STOP;
 
     switch( e->key() ) {
+
     case Key_Prior: // PageUp
 	{
         if ( !kPrior( e, oldPage, oldFrame, oldParag, frameSet ) )



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic