Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

kateview.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           kateview.cpp  -  description
00003                              -------------------
00004     begin                : Mon Jan 15 2001
00005     copyright            : (C) 2001 by Christoph "Crossfire" Cullmann
00006          (C) 2002 by Joseph Wenninger
00007     email                : crossfire@babylon2k.de
00008          jowenn@kde.org
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
00017  *                                                                         *
00018  ***************************************************************************/
00019 
00020 /*
00021    Copyright (C) 1998, 1999 Jochen Wilhelmy
00022                             digisnap@cs.tu-berlin.de
00023 
00024     This library is free software; you can redistribute it and/or
00025     modify it under the terms of the GNU Library General Public
00026     License as published by the Free Software Foundation; either
00027     version 2 of the License, or (at your option) any later version.
00028 
00029     This library is distributed in the hope that it will be useful,
00030     but WITHOUT ANY WARRANTY; without even the implied warranty of
00031     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00032     Library General Public License for more details.
00033 
00034     You should have received a copy of the GNU Library General Public License
00035     along with this library; see the file COPYING.LIB.  If not, write to
00036     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00037     Boston, MA 02111-1307, USA.
00038 */
00039 
00040 
00041 
00042 #include "kateview.h"
00043 
00044 #include "../document/katedocument.h"
00045 #include "../document/katecmd.h"
00046 #include "../document/katehighlight.h"
00047 #include "../document/katedialogs.h"
00048 #include "kateviewdialog.h"
00049 #include <kateconfig.h>
00050 
00051 #include <kapplication.h>
00052 #include <qscrollbar.h>
00053 #include <qpopupmenu.h>
00054 #include <kpopupmenu.h>
00055 #include <qkeycode.h>
00056 #include <qintdict.h>
00057 #include <qfont.h>
00058 #include <qpainter.h>
00059 #include <qpixmap.h>
00060 #include <qfileinfo.h>
00061 #include <qfile.h>
00062 #include <qevent.h>
00063 #include <qdir.h>
00064 #include <qvbox.h>
00065 #include <qprintdialog.h>
00066 #include <qpaintdevicemetrics.h>
00067 #include <qbuffer.h>
00068 #include <klocale.h>
00069 #include <kglobal.h>
00070 #include <kmessagebox.h>
00071 #include <qregexp.h>
00072 #include <kdialogbase.h>
00073 #include <klineeditdlg.h>
00074 #include <qapplication.h>
00075 #include <kfiledialog.h>
00076 #include <kiconloader.h>
00077 #include "../document/katetextline.h"
00078 #include "kateundohistory.h"
00079 #include <qlayout.h>
00080 #include <qpe/qpeapplication.h>
00081 
00082 KateViewInternal::KateViewInternal(KateView *view, KateDocument *doc) : QWidget(view)
00083 {
00084   waitForPreHighlight=-1;
00085   myView = view;
00086   myDoc = doc;
00087 
00088   iconBorderWidth  = 16;
00089   iconBorderHeight = 800;
00090 
00091   QWidget::setCursor(ibeamCursor);
00092   setBackgroundMode(NoBackground);
00093 
00094   setFocusPolicy(StrongFocus);
00095 
00096   xScroll = new QScrollBar(QScrollBar::Horizontal,myView);
00097   yScroll = new QScrollBar(QScrollBar::Vertical,myView);
00098   connect(xScroll,SIGNAL(valueChanged(int)),SLOT(changeXPos(int)));
00099   connect(yScroll,SIGNAL(valueChanged(int)),SLOT(changeYPos(int)));
00100   connect(yScroll,SIGNAL(valueChanged(int)),myView,SIGNAL(scrollValueChanged(int)));
00101   connect( doc, SIGNAL (preHighlightChanged(long)),this,SLOT(slotPreHighlightUpdate(long)));
00102 
00103   xPos = 0;
00104   yPos = 0;
00105 
00106   scrollTimer = 0;
00107 
00108   cursor.x = 0;
00109   cursor.y = 0;
00110   cursorOn = false;
00111   cursorTimer = 0;
00112   cXPos = 0;
00113   cOldXPos = 0;
00114 
00115   startLine = 0;
00116   endLine = -1;
00117 
00118   exposeCursor = false;
00119   updateState = 0;
00120   numLines = 0;
00121   lineRanges = 0L;
00122   newXPos = -1;
00123   newYPos = -1;
00124 
00125   drawBuffer = new QPixmap ();
00126   drawBuffer->setOptimization (QPixmap::BestOptim);
00127 
00128   bm.sXPos = 0;
00129   bm.eXPos = -1;
00130 
00131 }
00132 
00133 
00134 KateViewInternal::~KateViewInternal()
00135 {
00136   delete [] lineRanges;
00137   delete drawBuffer;
00138 }
00139 
00140 
00141 void KateViewInternal::slotPreHighlightUpdate(long line)
00142 {
00143   //kdDebug()<<QString("slotPreHighlightUpdate - Wait for: %1, line:  %2").arg(waitForPreHighlight).arg(line)<<endl;
00144   if (waitForPreHighlight!=-1)
00145     {
00146        if (line>=waitForPreHighlight)
00147          {
00148            waitForPreHighlight=-1;
00149            repaint();
00150          }
00151     }
00152 }
00153 
00154 void KateViewInternal::doCursorCommand(VConfig &c, int cmdNum) {
00155 
00156   switch (cmdNum) {
00157     case KateView::cmLeft:
00158       cursorLeft(c);
00159       break;
00160     case KateView::cmRight:
00161       cursorRight(c);
00162       break;
00163     case KateView::cmWordLeft:
00164       wordLeft(c);
00165       break;
00166     case KateView::cmWordRight:
00167       wordRight(c);
00168       break;
00169     case KateView::cmHome:
00170       home(c);
00171       break;
00172     case KateView::cmEnd:
00173       end(c);
00174       break;
00175     case KateView::cmUp:
00176       cursorUp(c);
00177       break;
00178     case KateView::cmDown:
00179       cursorDown(c);
00180       break;
00181     case KateView::cmScrollUp:
00182       scrollUp(c);
00183       break;
00184     case KateView::cmScrollDown:
00185       scrollDown(c);
00186       break;
00187     case KateView::cmTopOfView:
00188       topOfView(c);
00189       break;
00190     case KateView::cmBottomOfView:
00191       bottomOfView(c);
00192       break;
00193     case KateView::cmPageUp:
00194       pageUp(c);
00195       break;
00196     case KateView::cmPageDown:
00197       pageDown(c);
00198       break;
00199     case KateView::cmTop:
00200       top_home(c);
00201       break;
00202     case KateView::cmBottom:
00203       bottom_end(c);
00204       break;
00205   }
00206 }
00207 
00208 void KateViewInternal::doEditCommand(VConfig &c, int cmdNum) {
00209 
00210   switch (cmdNum) {
00211     case KateView::cmCopy:
00212       myDoc->copy(c.flags);
00213       return;
00214     case KateView::cmSelectAll:
00215       myDoc->selectAll();
00216       return;
00217     case KateView::cmDeselectAll:
00218       myDoc->deselectAll();
00219       return;
00220     case KateView::cmInvertSelection:
00221       myDoc->invertSelection();
00222       return;
00223   }
00224   if (myView->isReadOnly()) return;
00225   switch (cmdNum) {
00226     case KateView::cmReturn:
00227       if (c.flags & KateView::cfDelOnInput) myDoc->delMarkedText(c);
00228       myDoc->newLine(c);
00229       //emit returnPressed();
00230       //e->ignore();
00231       return;
00232     case KateView::cmDelete:
00233       if ((c.flags & KateView::cfDelOnInput) && myDoc->hasMarkedText())
00234         myDoc->delMarkedText(c);
00235       else myDoc->del(c);
00236       return;
00237     case KateView::cmBackspace:
00238       if ((c.flags & KateView::cfDelOnInput) && myDoc->hasMarkedText())
00239         myDoc->delMarkedText(c);
00240       else myDoc->backspace(c);
00241       return;
00242     case KateView::cmKillLine:
00243       myDoc->killLine(c);
00244       return;
00245     case KateView::cmCut:
00246       myDoc->cut(c);
00247       return;
00248     case KateView::cmPaste:
00249       if (c.flags & KateView::cfDelOnInput) myDoc->delMarkedText(c);
00250       myDoc->paste(c);
00251       return;
00252     case KateView::cmUndo:
00253       myDoc->undo(c);
00254       return;
00255     case KateView::cmRedo:
00256       myDoc->redo(c);
00257       return;
00258     case KateView::cmIndent:
00259       myDoc->indent(c);
00260       return;
00261     case KateView::cmUnindent:
00262       myDoc->unIndent(c);
00263       return;
00264     case KateView::cmCleanIndent:
00265       myDoc->cleanIndent(c);
00266       return;
00267     case KateView::cmComment:
00268       myDoc->comment(c);
00269       return;
00270     case KateView::cmUncomment:
00271       myDoc->unComment(c);
00272       return;
00273   }
00274 }
00275 
00276 void KateViewInternal::cursorLeft(VConfig &c) {
00277 
00278   cursor.x--;
00279   if (c.flags & KateView::cfWrapCursor && cursor.x < 0 && cursor.y > 0) {
00280     cursor.y--;
00281     cursor.x = myDoc->textLength(cursor.y);
00282   }
00283   cOldXPos = cXPos = myDoc->textWidth(cursor);
00284   changeState(c);
00285 }
00286 
00287 void KateViewInternal::cursorRight(VConfig &c) {
00288 
00289   if (c.flags & KateView::cfWrapCursor) {
00290     if (cursor.x >= myDoc->textLength(cursor.y)) {
00291       if (cursor.y == myDoc->lastLine()) return;
00292       cursor.y++;
00293       cursor.x = -1;
00294     }
00295   }
00296   cursor.x++;
00297   cOldXPos = cXPos = myDoc->textWidth(cursor);
00298   changeState(c);
00299 }
00300 
00301 void KateViewInternal::wordLeft(VConfig &c) {
00302   Highlight *highlight;
00303 
00304   highlight = myDoc->highlight();
00305   TextLine::Ptr textLine = myDoc->getTextLine(cursor.y);
00306 
00307   if (cursor.x > 0) {
00308     do {
00309       cursor.x--;
00310     } while (cursor.x > 0 && !highlight->isInWord(textLine->getChar(cursor.x)));
00311     while (cursor.x > 0 && highlight->isInWord(textLine->getChar(cursor.x -1)))
00312       cursor.x--;
00313   } else {
00314     if (cursor.y > 0) {
00315       cursor.y--;
00316       textLine = myDoc->getTextLine(cursor.y);
00317       cursor.x = textLine->length();
00318     }
00319   }
00320 
00321   cOldXPos = cXPos = myDoc->textWidth(cursor);
00322   changeState(c);
00323 }
00324 
00325 void KateViewInternal::wordRight(VConfig &c) {
00326   Highlight *highlight;
00327   int len;
00328 
00329   highlight = myDoc->highlight();
00330   TextLine::Ptr textLine = myDoc->getTextLine(cursor.y);
00331   len = textLine->length();
00332 
00333   if (cursor.x < len) {
00334     do {
00335       cursor.x++;
00336     } while (cursor.x < len && highlight->isInWord(textLine->getChar(cursor.x)));
00337     while (cursor.x < len && !highlight->isInWord(textLine->getChar(cursor.x)))
00338       cursor.x++;
00339   } else {
00340     if (cursor.y < myDoc->lastLine()) {
00341       cursor.y++;
00342       textLine = myDoc->getTextLine(cursor.y);
00343       cursor.x = 0;
00344     }
00345   }
00346 
00347   cOldXPos = cXPos = myDoc->textWidth(cursor);
00348   changeState(c);
00349 }
00350 
00351 void KateViewInternal::home(VConfig &c) {
00352   int lc;
00353 
00354   lc = (c.flags & KateView::cfSmartHome) ? myDoc->getTextLine(cursor.y)->firstChar() : 0;
00355   if (lc <= 0 || cursor.x == lc) {
00356     cursor.x = 0;
00357     cOldXPos = cXPos = 0;
00358   } else {
00359     cursor.x = lc;
00360     cOldXPos = cXPos = myDoc->textWidth(cursor);
00361   }
00362 
00363   changeState(c);
00364 }
00365 
00366 void KateViewInternal::end(VConfig &c) {
00367   cursor.x = myDoc->textLength(cursor.y);
00368   cOldXPos = cXPos = myDoc->textWidth(cursor);
00369   changeState(c);
00370 }
00371 
00372 
00373 void KateViewInternal::cursorUp(VConfig &c) {
00374 
00375   cursor.y--;
00376   cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos);
00377   changeState(c);
00378 }
00379 
00380 
00381 void KateViewInternal::cursorDown(VConfig &c) {
00382   int x;
00383 
00384   if (cursor.y == myDoc->lastLine()) {
00385     x = myDoc->textLength(cursor.y);
00386     if (cursor.x >= x) return;
00387     cursor.x = x;
00388     cXPos = myDoc->textWidth(cursor);
00389   } else {
00390     cursor.y++;
00391     cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor, cOldXPos);
00392   }
00393   changeState(c);
00394 }
00395 
00396 void KateViewInternal::scrollUp(VConfig &c) {
00397 
00398   if (! yPos) return;
00399 
00400   newYPos = yPos - myDoc->fontHeight;
00401   if (cursor.y == (yPos + height())/myDoc->fontHeight -1) {
00402     cursor.y--;
00403     cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos);
00404 
00405     changeState(c);
00406   }
00407 }
00408 
00409 void KateViewInternal::scrollDown(VConfig &c) {
00410 
00411   if (endLine >= myDoc->lastLine()) return;
00412 
00413   newYPos = yPos + myDoc->fontHeight;
00414   if (cursor.y == (yPos + myDoc->fontHeight -1)/myDoc->fontHeight) {
00415     cursor.y++;
00416     cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos);
00417     changeState(c);
00418   }
00419 }
00420 
00421 void KateViewInternal::topOfView(VConfig &c) {
00422 
00423   cursor.y = (yPos + myDoc->fontHeight -1)/myDoc->fontHeight;
00424   cursor.x = 0;
00425   cOldXPos = cXPos = 0;
00426   changeState(c);
00427 }
00428 
00429 void KateViewInternal::bottomOfView(VConfig &c) {
00430 
00431   cursor.y = (yPos + height())/myDoc->fontHeight -1;
00432   if (cursor.y < 0) cursor.y = 0;
00433   if (cursor.y > myDoc->lastLine()) cursor.y = myDoc->lastLine();
00434   cursor.x = 0;
00435   cOldXPos = cXPos = 0;
00436   changeState(c);
00437 }
00438 
00439 void KateViewInternal::pageUp(VConfig &c) {
00440   int lines = (endLine - startLine - 1);
00441 
00442   if (lines <= 0) lines = 1;
00443 
00444   if (!(c.flags & KateView::cfPageUDMovesCursor) && yPos > 0) {
00445     newYPos = yPos - lines * myDoc->fontHeight;
00446     if (newYPos < 0) newYPos = 0;
00447   }
00448   cursor.y -= lines;
00449   cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor, cOldXPos);
00450   changeState(c);
00451 //  cursorPageUp(c);
00452 }
00453 
00454 void KateViewInternal::pageDown(VConfig &c) {
00455 
00456   int lines = (endLine - startLine - 1);
00457 
00458   if (!(c.flags & KateView::cfPageUDMovesCursor) && endLine < myDoc->lastLine()) {
00459     if (lines < myDoc->lastLine() - endLine)
00460       newYPos = yPos + lines * myDoc->fontHeight;
00461     else
00462       newYPos = yPos + (myDoc->lastLine() - endLine) * myDoc->fontHeight;
00463   }
00464   cursor.y += lines;
00465   cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos);
00466   changeState(c);
00467 //  cursorPageDown(c);
00468 }
00469 
00470 // go to the top, same X position
00471 void KateViewInternal::top(VConfig &c) {
00472 
00473 //  cursor.x = 0;
00474   cursor.y = 0;
00475   cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos);
00476 //  cOldXPos = cXPos = 0;
00477   changeState(c);
00478 }
00479 
00480 // go to the bottom, same X position
00481 void KateViewInternal::bottom(VConfig &c) {
00482 
00483 //  cursor.x = 0;
00484   cursor.y = myDoc->lastLine();
00485   cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos);
00486 //  cOldXPos = cXPos = 0;
00487   changeState(c);
00488 }
00489 
00490 // go to the top left corner
00491 void KateViewInternal::top_home(VConfig &c)
00492 {
00493   cursor.y = 0;
00494   cursor.x = 0;
00495   cOldXPos = cXPos = 0;
00496   changeState(c);
00497 }
00498 
00499 // go to the bottom right corner
00500 void KateViewInternal::bottom_end(VConfig &c) {
00501 
00502   cursor.y = myDoc->lastLine();
00503   cursor.x = myDoc->textLength(cursor.y);
00504   cOldXPos = cXPos = myDoc->textWidth(cursor);
00505   changeState(c);
00506 }
00507 
00508 
00509 void KateViewInternal::changeXPos(int p) {
00510   int dx;
00511 
00512   dx = xPos - p;
00513   xPos = p;
00514   if (QABS(dx) < width()) scroll(dx, 0); else update();
00515 }
00516 
00517 void KateViewInternal::changeYPos(int p) {
00518   int dy;
00519 
00520   dy = yPos - p;
00521   yPos = p;
00522   clearDirtyCache(height());
00523 
00524   if (QABS(dy) < height())
00525   {
00526     scroll(0, dy);
00527     leftBorder->scroll(0, dy);
00528   }
00529   else
00530     update();
00531 }
00532 
00533 
00534 void KateViewInternal::getVConfig(VConfig &c) {
00535 
00536   c.view = myView;
00537   c.cursor = cursor;
00538   c.cXPos = cXPos;
00539   c.flags = myView->configFlags;
00540 }
00541 
00542 void KateViewInternal::changeState(VConfig &c) {
00543   /*
00544    * we need to be sure to kill the selection on an attempted cursor
00545    * movement even if the cursor doesn't physically move,
00546    * but we need to be careful not to do some other things in this case,
00547    * like we don't want to expose the cursor
00548    */
00549 
00550 //  if (cursor.x == c.cursor.x && cursor.y == c.cursor.y) return;
00551   bool nullMove = (cursor.x == c.cursor.x && cursor.y == c.cursor.y);
00552 
00553 //  if (cursor.y != c.cursor.y || c.flags & KateView::cfMark) myDoc->recordReset();
00554 
00555   if (! nullMove) {
00556 
00557     exposeCursor = true;
00558 
00559     // mark old position of cursor as dirty
00560     if (cursorOn) {
00561       tagLines(c.cursor.y, c.cursor.y, c.cXPos -2, c.cXPos +3);
00562       cursorOn = false;
00563     }
00564 
00565     // mark old bracket mark position as dirty
00566     if (bm.sXPos < bm.eXPos) {
00567       tagLines(bm.cursor.y, bm.cursor.y, bm.sXPos, bm.eXPos);
00568     }
00569     // make new bracket mark
00570     myDoc->newBracketMark(cursor, bm);
00571 
00572     // remove trailing spaces when leaving a line
00573     if (c.flags & KateView::cfRemoveSpaces && cursor.y != c.cursor.y) {
00574       TextLine::Ptr textLine = myDoc->getTextLine(c.cursor.y);
00575       int newLen = textLine->lastChar();
00576       if (newLen != textLine->length()) {
00577         textLine->truncate(newLen);
00578         // if some spaces are removed, tag the line as dirty
00579         myDoc->tagLines(c.cursor.y, c.cursor.y);
00580       }
00581     }
00582   }
00583 
00584   if (c.flags & KateView::cfMark) {
00585     if (! nullMove)
00586       myDoc->selectTo(c, cursor, cXPos);
00587   } else {
00588     if (!(c.flags & KateView::cfPersistent))
00589       myDoc->deselectAll();
00590   }
00591 }
00592 
00593 void KateViewInternal::insLine(int line) {
00594 
00595   if (line <= cursor.y) {
00596     cursor.y++;
00597   }
00598   if (line < startLine) {
00599     startLine++;
00600     endLine++;
00601     yPos += myDoc->fontHeight;
00602   } else if (line <= endLine) {
00603     tagAll();
00604   }
00605 }
00606 
00607 void KateViewInternal::delLine(int line) {
00608 
00609   if (line <= cursor.y && cursor.y > 0) {
00610     cursor.y--;
00611   }
00612   if (line < startLine) {
00613     startLine--;
00614     endLine--;
00615     yPos -= myDoc->fontHeight;
00616   } else if (line <= endLine) {
00617     tagAll();
00618   }
00619 }
00620 
00621 void KateViewInternal::updateCursor() {
00622   cOldXPos = cXPos = myDoc->textWidth(cursor);
00623 }
00624 
00625 
00626 void KateViewInternal::updateCursor(PointStruc &newCursor) {
00627   updateCursor(newCursor, myView->config());
00628 }
00629 
00630 void KateViewInternal::updateCursor(PointStruc &newCursor, int flags) {
00631 
00632   if (!(flags & KateView::cfPersistent)) myDoc->deselectAll();
00633 
00634   exposeCursor = true;
00635   if (cursorOn) {
00636     tagLines(cursor.y, cursor.y, cXPos -2, cXPos +3);
00637     cursorOn = false;
00638   }
00639 
00640   if (bm.sXPos < bm.eXPos) {
00641     tagLines(bm.cursor.y, bm.cursor.y, bm.sXPos, bm.eXPos);
00642   }
00643   myDoc->newBracketMark(newCursor, bm);
00644 
00645   cursor = newCursor;
00646   cOldXPos = cXPos = myDoc->textWidth(cursor);
00647 }
00648 
00649 // init the line dirty cache
00650 void KateViewInternal::clearDirtyCache(int height) {
00651   int lines, z;
00652 
00653   // calc start and end line of visible part
00654   startLine = yPos/myDoc->fontHeight;
00655   endLine = (yPos + height -1)/myDoc->fontHeight;
00656 
00657   updateState = 0;
00658 
00659   lines = endLine - startLine +1;
00660   if (lines > numLines) { // resize the dirty cache
00661     numLines = lines*2;
00662     delete [] lineRanges;
00663     lineRanges = new LineRange[numLines];
00664   }
00665 
00666   for (z = 0; z < lines; z++) { // clear all lines
00667     lineRanges[z].start = 0xffffff;
00668     lineRanges[z].end = -2;
00669   }
00670   newXPos = newYPos = -1;
00671 }
00672 
00673 void KateViewInternal::tagLines(int start, int end, int x1, int x2) {
00674   LineRange *r;
00675   int z;
00676 
00677   start -= startLine;
00678   if (start < 0) start = 0;
00679   end -= startLine;
00680   if (end > endLine - startLine) end = endLine - startLine;
00681 
00682   if (x1 <= 0) x1 = -2;
00683   if (x1 < xPos-2) x1 = xPos-2;
00684   if (x2 > width() + xPos-2) x2 = width() + xPos-2;
00685   if (x1 >= x2) return;
00686 
00687   r = &lineRanges[start];
00688   for (z = start; z <= end; z++) {
00689     if (x1 < r->start) r->start = x1;
00690     if (x2 > r->end) r->end = x2;
00691     r++;
00692     updateState |= 1;
00693   }
00694 }
00695 
00696 void KateViewInternal::tagAll() {
00697   updateState = 3;
00698 }
00699 
00700 void KateViewInternal::setPos(int x, int y) {
00701   newXPos = x;
00702   newYPos = y;
00703 }
00704 
00705 void KateViewInternal::center() {
00706   newXPos = 0;
00707   newYPos = cursor.y*myDoc->fontHeight - height()/2;
00708   if (newYPos < 0) newYPos = 0;
00709 }
00710 
00711 void KateViewInternal::updateView(int flags) {
00712   int fontHeight;
00713   int oldXPos, oldYPos;
00714   int w, h;
00715   int z;
00716   bool b;
00717   int xMax, yMax;
00718   int cYPos;
00719   int cXPosMin, cXPosMax, cYPosMin, cYPosMax;
00720   int dx, dy;
00721   int pageScroll;
00722   int scrollbarWidth = style().scrollBarExtent().width();
00723 
00724 //debug("upView %d %d %d %d %d", exposeCursor, updateState, flags, newXPos, newYPos);
00725   if (exposeCursor || flags & KateView::ufDocGeometry) {
00726     emit myView->newCurPos();
00727   } else {
00728     if (updateState == 0 && newXPos < 0 && newYPos < 0) return;
00729   }
00730 
00731   if (cursorTimer) {
00732     killTimer(cursorTimer);
00733     cursorTimer = startTimer(KApplication::cursorFlashTime() / 2);
00734     cursorOn = true;
00735   }
00736 
00737   oldXPos = xPos;
00738   oldYPos = yPos;
00739 /*  if (flags & ufPos) {
00740     xPos = newXPos;
00741     yPos = newYPos;
00742     exposeCursor = true;
00743   }*/
00744   if (newXPos >= 0) xPos = newXPos;
00745   if (newYPos >= 0) yPos = newYPos;
00746 
00747   fontHeight = myDoc->fontHeight;
00748   cYPos = cursor.y*fontHeight;
00749 
00750   z = 0;
00751   do {
00752     w = myView->width() - 4;
00753     h = myView->height() - 4;
00754 
00755     xMax = myDoc->textWidth() - w;
00756     b = (xPos > 0 || xMax > 0);
00757     if (b) h -= scrollbarWidth;
00758     yMax = myDoc->textHeight() - h;
00759     if (yPos > 0 || yMax > 0) {
00760       w -= scrollbarWidth;
00761       xMax += scrollbarWidth;
00762       if (!b && xMax > 0) {
00763         h -= scrollbarWidth;
00764         yMax += scrollbarWidth;
00765       }
00766     }
00767 
00768     if (!exposeCursor) break;
00769 //    if (flags & KateView::ufNoScroll) break;
00770 /*
00771     if (flags & KateView::ufCenter) {
00772       cXPosMin = xPos + w/3;
00773       cXPosMax = xPos + (w*2)/3;
00774       cYPosMin = yPos + h/3;
00775       cYPosMax = yPos + ((h - fontHeight)*2)/3;
00776     } else {*/
00777       cXPosMin = xPos + 4;
00778       cXPosMax = xPos + w - 8;
00779       cYPosMin = yPos;
00780       cYPosMax = yPos + (h - fontHeight);
00781 //    }
00782 
00783     if (cXPos < cXPosMin) {
00784       xPos -= cXPosMin - cXPos;
00785     }
00786     if (xPos < 0) xPos = 0;
00787     if (cXPos > cXPosMax) {
00788       xPos += cXPos - cXPosMax;
00789     }
00790     if (cYPos < cYPosMin) {
00791       yPos -= cYPosMin - cYPos;
00792     }
00793     if (yPos < 0) yPos = 0;
00794     if (cYPos > cYPosMax) {
00795       yPos += cYPos - cYPosMax;
00796     }
00797 
00798     z++;
00799   } while (z < 2);
00800 
00801   if (xMax < xPos) xMax = xPos;
00802   if (yMax < yPos) yMax = yPos;
00803 
00804   if (xMax > 0) {
00805     pageScroll = w - (w % fontHeight) - fontHeight;
00806     if (pageScroll <= 0)
00807       pageScroll = fontHeight;
00808 
00809     xScroll->blockSignals(true);
00810     xScroll->setGeometry(2,h + 2,w,scrollbarWidth);
00811     xScroll->setRange(0,xMax);
00812     xScroll->setValue(xPos);
00813     xScroll->setSteps(fontHeight,pageScroll);
00814     xScroll->blockSignals(false);
00815     xScroll->show();
00816   } else xScroll->hide();
00817 
00818   if (yMax > 0) {
00819     pageScroll = h - (h % fontHeight) - fontHeight;
00820     if (pageScroll <= 0)
00821       pageScroll = fontHeight;
00822 
00823     yScroll->blockSignals(true);
00824     yScroll->setGeometry(w + 2,2,scrollbarWidth,h);
00825     yScroll->setRange(0,yMax);
00826     yScroll->setValue(yPos);
00827     yScroll->setSteps(fontHeight,pageScroll);
00828     yScroll->blockSignals(false);
00829     yScroll->show();
00830   } else yScroll->hide();
00831 
00832   if (w != width() || h != height()) {
00833     clearDirtyCache(h);
00834     resize(w,h);
00835   } else {
00836     dx = oldXPos - xPos;
00837     dy = oldYPos - yPos;
00838 
00839     b = updateState == 3;
00840     if (flags & KateView::ufUpdateOnScroll) {
00841       b |= dx || dy;
00842     } else {
00843       b |= QABS(dx)*3 > w*2 || QABS(dy)*3 > h*2;
00844     }
00845 
00846     if (b) {
00847       clearDirtyCache(h);
00848       update();
00849     } else {
00850       if (dy)
00851         leftBorder->scroll(0, dy);
00852       if (updateState > 0) paintTextLines(oldXPos, oldYPos);
00853       clearDirtyCache(h);
00854 
00855       if (dx || dy) {
00856         scroll(dx,dy);
00857 //        kapp->syncX();
00858 //        scroll2(dx - dx/2,dy - dy/2);
00859 //      } else {
00860       }
00861       if (cursorOn) paintCursor();
00862       if (bm.eXPos > bm.sXPos) paintBracketMark();
00863     }
00864   }
00865   exposeCursor = false;
00866 //  updateState = 0;
00867 }
00868 
00869 
00870 void KateViewInternal::paintTextLines(int xPos, int yPos) {
00871 //  int xStart, xEnd;
00872   int line;//, z;
00873   int h;
00874   LineRange *r;
00875 
00876   if (!drawBuffer) return;
00877   if (drawBuffer->isNull()) return;
00878 
00879   QPainter paint;
00880   paint.begin(drawBuffer);
00881 
00882   h = myDoc->fontHeight;
00883   r = lineRanges;
00884   for (line = startLine; line <= endLine; line++) {
00885     if (r->start < r->end) {
00886 //debug("painttextline %d %d %d", line, r->start, r->end);
00887       myDoc->paintTextLine(paint, line, r->start, r->end, myView->configFlags & KateView::cfShowTabs);
00888       bitBlt(this, r->start - (xPos-2), line*h - yPos, drawBuffer, 0, 0,
00889         r->end - r->start, h);
00890         leftBorder->paintLine(line);
00891     }
00892     r++;
00893   }
00894 
00895   paint.end();
00896 }
00897 
00898 void KateViewInternal::paintCursor() {
00899   int h, y, x;
00900   static int cx = 0, cy = 0, ch = 0;
00901 
00902   h = myDoc->fontHeight;
00903   y = h*cursor.y - yPos;
00904   x = cXPos - (xPos-2);
00905 
00906   if(myDoc->myFont != font()) setFont(myDoc->myFont);
00907   if(cx != x || cy != y || ch != h){
00908     cx = x;
00909     cy = y;
00910     ch = h;
00911     setMicroFocusHint(cx, cy, 0, ch - 2);
00912   }
00913 
00914   QPainter paint;
00915   if (cursorOn) {
00916     paint.begin(this);
00917     paint.setClipping(false);
00918     paint.setPen(myDoc->cursorCol(cursor.x,cursor.y));
00919 
00920     h += y - 1;
00921     paint.drawLine(x, y, x, h);
00922 
00923  paint.end();
00924   } else { if (drawBuffer && !drawBuffer->isNull()) {
00925     paint.begin(drawBuffer);
00926     myDoc->paintTextLine(paint, cursor.y, cXPos - 2, cXPos + 3, myView->configFlags & KateView::cfShowTabs);
00927     bitBlt(this,x - 2,y, drawBuffer, 0, 0, 5, h);
00928  paint.end(); }
00929   }
00930 
00931 }
00932 
00933 void KateViewInternal::paintBracketMark() {
00934   int y;
00935 
00936   y = myDoc->fontHeight*(bm.cursor.y +1) - yPos -1;
00937 
00938   QPainter paint;
00939   paint.begin(this);
00940   paint.setPen(myDoc->cursorCol(bm.cursor.x, bm.cursor.y));
00941 
00942   paint.drawLine(bm.sXPos - (xPos-2), y, bm.eXPos - (xPos-2) -1, y);
00943   paint.end();
00944 }
00945 
00946 void KateViewInternal::placeCursor(int x, int y, int flags) {
00947   VConfig c;
00948 
00949   getVConfig(c);
00950   c.flags |= flags;
00951   cursor.y = (yPos + y)/myDoc->fontHeight;
00952   cXPos = cOldXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor,xPos-2 + x);
00953   changeState(c);
00954 }
00955 
00956 // given physical coordinates, report whether the text there is selected
00957 bool KateViewInternal::isTargetSelected(int x, int y) {
00958 
00959   y = (yPos + y) / myDoc->fontHeight;
00960 
00961   TextLine::Ptr line = myDoc->getTextLine(y);
00962   if (!line)
00963     return false;
00964 
00965   x = myDoc->textPos(line, x);
00966 
00967   return line->isSelected(x);
00968 }
00969 
00970 void KateViewInternal::focusInEvent(QFocusEvent *) {
00971 //  debug("got focus %d",cursorTimer);
00972 
00973   if (!cursorTimer) {
00974     cursorTimer = startTimer(KApplication::cursorFlashTime() / 2);
00975     cursorOn = true;
00976     paintCursor();
00977   }
00978 }
00979 
00980 void KateViewInternal::focusOutEvent(QFocusEvent *) {
00981 //  debug("lost focus %d", cursorTimer);
00982 
00983   if (cursorTimer) {
00984     killTimer(cursorTimer);
00985     cursorTimer = 0;
00986   }
00987 
00988   if (cursorOn) {
00989     cursorOn = false;
00990     paintCursor();
00991   }
00992 }
00993 
00994 void KateViewInternal::keyPressEvent(QKeyEvent *e) {
00995   VConfig c;
00996 //  int ascii;
00997 
00998 /*  if (e->state() & AltButton) {
00999     e->ignore();
01000     return;
01001   }*/
01002 //  debug("ascii %i, key %i, state %i",e->ascii(), e->key(), e->state());
01003 
01004   getVConfig(c);
01005 //  ascii = e->ascii();
01006 
01007   if (!myView->isReadOnly()) {
01008     if (c.flags & KateView::cfTabIndents && myDoc->hasMarkedText()) {
01009       if (e->key() == Qt::Key_Tab) {
01010         myDoc->indent(c);
01011         myDoc->updateViews();
01012         return;
01013       }
01014       if (e->key() == Qt::Key_Backtab) {
01015         myDoc->unIndent(c);
01016         myDoc->updateViews();
01017         return;
01018       }
01019     }
01020     if ( !(e->state() & ControlButton ) && myDoc->insertChars(c, e->text())) {
01021       myDoc->updateViews();
01022       e->accept();
01023       return;
01024     }
01025   }
01026   e->ignore();
01027 }
01028 
01029 void KateViewInternal::mousePressEvent(QMouseEvent *e) {
01030 
01031   if (e->button() == LeftButton) {
01032 
01033       int flags;
01034 
01035       flags = 0;
01036       if (e->state() & ShiftButton) {
01037         flags |= KateView::cfMark;
01038         if (e->state() & ControlButton) flags |= KateView::cfMark | KateView::cfKeepSelection;
01039       }
01040       placeCursor(e->x(), e->y(), flags);
01041       scrollX = 0;
01042       scrollY = 0;
01043       if (!scrollTimer) scrollTimer = startTimer(50);
01044       myDoc->updateViews();
01045   }
01046   if (e->button() == MidButton) {
01047     placeCursor(e->x(), e->y());
01048     if (! myView->isReadOnly())
01049       myView->paste();
01050   }
01051   if (myView->rmbMenu && e->button() == RightButton) {
01052     myView->rmbMenu->popup(mapToGlobal(e->pos()));
01053   }
01054   myView->mousePressEvent(e); // this doesn't do anything, does it?
01055   // it does :-), we need this for KDevelop, so please don't uncomment it again -Sandy
01056 }
01057 
01058 void KateViewInternal::mouseDoubleClickEvent(QMouseEvent *e) {
01059 
01060   if (e->button() == LeftButton) {
01061     VConfig c;
01062     getVConfig(c);
01063     myDoc->selectWord(c.cursor, c.flags);
01064     myDoc->updateViews();
01065   }
01066 }
01067 
01068 void KateViewInternal::mouseReleaseEvent(QMouseEvent *e) {
01069 
01070   if (e->button() == LeftButton) {
01071       if (myView->config() & KateView::cfMouseAutoCopy) myView->copy();
01072       killTimer(scrollTimer);
01073       scrollTimer = 0;
01074   }
01075 }
01076 
01077 void KateViewInternal::mouseMoveEvent(QMouseEvent *e) {
01078 
01079   if (e->state() & LeftButton) {
01080     int flags;
01081     int d;
01082     int x = e->x(),
01083         y = e->y();
01084 
01085     mouseX = e->x();
01086     mouseY = e->y();
01087     scrollX = 0;
01088     scrollY = 0;
01089     d = myDoc->fontHeight;
01090     if (mouseX < 0) {
01091       mouseX = 0;
01092       scrollX = -d;
01093     }
01094     if (mouseX > width()) {
01095       mouseX = width();
01096       scrollX = d;
01097     }
01098     if (mouseY < 0) {
01099       mouseY = 0;
01100       scrollY = -d;
01101     }
01102     if (mouseY > height()) {
01103       mouseY = height();
01104       scrollY = d;
01105     }
01106 //debug("modifiers %d", ((KGuiCmdApp *) kapp)->getModifiers());
01107     flags = KateView::cfMark;
01108     if (e->state() & ControlButton) flags |= KateView::cfKeepSelection;
01109     placeCursor(mouseX, mouseY, flags);
01110     myDoc->updateViews(/*ufNoScroll*/);
01111   }
01112 }
01113 
01114 
01115 
01116 void KateViewInternal::wheelEvent( QWheelEvent *e )
01117 {
01118   if( yScroll->isVisible() == true )
01119   {
01120     QApplication::sendEvent( yScroll, e );
01121   }
01122 }
01123 
01124 
01125 
01126 void KateViewInternal::paintEvent(QPaintEvent *e) {
01127   int xStart, xEnd;
01128   int h;
01129   int line, y, yEnd;
01130 
01131   QRect updateR = e->rect();
01132 
01133   if (!drawBuffer) return;
01134   if (drawBuffer->isNull()) return;
01135 
01136   QPainter paint;
01137   paint.begin(drawBuffer);
01138 
01139   xStart = xPos-2 + updateR.x();
01140   xEnd = xStart + updateR.width();
01141 
01142   h = myDoc->fontHeight;
01143   line = (yPos + updateR.y()) / h;
01144   y = line*h - yPos;
01145   yEnd = updateR.y() + updateR.height();
01146   waitForPreHighlight=myDoc->needPreHighlight(waitForPreHighlight=line+((long)(yEnd-y)/h)+5);
01147 
01148   while (y < yEnd)
01149   {
01150     TextLine *textLine;
01151     int ctxNum = 0;
01152     myDoc->paintTextLine(paint, line, xStart, xEnd, myView->configFlags & KateView::cfShowTabs);
01153     bitBlt(this, updateR.x(), y, drawBuffer, 0, 0, updateR.width(), h);
01154     leftBorder->paintLine(line);
01155     line++;
01156     y += h;
01157   }
01158   paint.end();
01159 
01160   if (cursorOn) paintCursor();
01161   if (bm.eXPos > bm.sXPos) paintBracketMark();
01162 }
01163 
01164 void KateViewInternal::resizeEvent(QResizeEvent *)
01165 {
01166   drawBuffer->resize (width(), myDoc->fontHeight);
01167   leftBorder->resize(iconBorderWidth, height());
01168 }
01169 
01170 void KateViewInternal::timerEvent(QTimerEvent *e) {
01171   if (e->timerId() == cursorTimer) {
01172     cursorOn = !cursorOn;
01173     paintCursor();
01174   }
01175   if (e->timerId() == scrollTimer && (scrollX | scrollY)) {
01176     xScroll->setValue(xPos + scrollX);
01177     yScroll->setValue(yPos + scrollY);
01178 
01179     placeCursor(mouseX, mouseY, KateView::cfMark);
01180     myDoc->updateViews(/*ufNoScroll*/);
01181   }
01182 }
01183 
01184 uint KateView::uniqueID = 0;
01185 
01186 KateView::KateView(KateDocument *doc, QWidget *parent, const char * name) : Kate::View (doc, parent, name)
01187 {
01188 
01189   myViewID = uniqueID;
01190   uniqueID++;
01191 
01192   active = false;
01193   myIconBorder = false;
01194 
01195   myDoc = doc;
01196   myViewInternal = new KateViewInternal (this,doc);
01197   myViewInternal->move(2, 2);
01198   myViewInternal->leftBorder = new KateIconBorder(this, myViewInternal);
01199   myViewInternal->leftBorder->setGeometry(2, 2, myViewInternal->iconBorderWidth, myViewInternal->iconBorderHeight);
01200   myViewInternal->leftBorder->hide();
01201 
01202   doc->addView( this );
01203 
01204 
01205   // some defaults
01206   configFlags = KateView::cfAutoIndent | KateView::cfBackspaceIndents
01207     | KateView::cfTabIndents | KateView::cfKeepIndentProfile
01208     | KateView::cfRemoveSpaces
01209     | KateView::cfDelOnInput | KateView::cfMouseAutoCopy | KateView::cfWrapCursor
01210     | KateView::cfGroupUndo | KateView::cfShowTabs | KateView::cfSmartHome;
01211 
01212   searchFlags = 0;
01213   replacePrompt = 0L;
01214   rmbMenu = 0L;
01215 
01216 
01217   setFocusProxy( myViewInternal );
01218   myViewInternal->setFocus();
01219   resize(parent->width() -4, parent->height() -4);
01220 
01221 
01222   myViewInternal->installEventFilter( this );
01223 
01224   //setupActions();
01225 
01226   connect( this, SIGNAL( newStatus() ), this, SLOT( slotUpdate() ) );
01227   connect( this, SIGNAL( newUndo() ), this, SLOT( slotNewUndo() ) );
01228   connect( doc, SIGNAL( fileNameChanged() ), this, SLOT( slotFileStatusChanged() ) );
01229   connect( doc, SIGNAL( highlightChanged() ), this, SLOT( slotHighlightChanged() ) );
01230 
01231   readConfig();
01232 //  setHighlight->setCurrentItem(getHl());
01233   slotUpdate();
01234 }
01235 
01236 KateView::~KateView()
01237 {
01238   writeConfig();
01239 
01240   if (myDoc && !myDoc->m_bSingleViewMode)
01241     myDoc->removeView( this );
01242 
01243   delete myViewInternal;
01244 }
01245 
01246 #if 0
01247 void KateView::setupActions()
01248 {
01249 #if 0
01250     KStdAction::close( this, SLOT(flush()), actionCollection(), "file_close" );
01251 
01252     KStdAction::save(this, SLOT(save()), actionCollection());
01253 
01254     // setup edit menu
01255     editUndo = KStdAction::undo(this, SLOT(undo()), actionCollection());
01256     editRedo = KStdAction::redo(this, SLOT(redo()), actionCollection());
01257     editUndoHist = new KAction(i18n("Undo/Redo &History..."), 0, this, SLOT(undoHistory()),
01258                                actionCollection(), "edit_undoHistory");
01259     KStdAction::cut(this, SLOT(cut()), actionCollection());
01260     KStdAction::copy(this, SLOT(copy()), actionCollection());
01261     KStdAction::paste(this, SLOT(paste()), actionCollection());
01262 
01263     if ( myDoc->hasBrowserExtension() )
01264     {
01265       KStdAction::saveAs(this, SLOT(saveAs()), myDoc->actionCollection());
01266       KStdAction::find(this, SLOT(find()), myDoc->actionCollection(), "find");
01267       KStdAction::findNext(this, SLOT(findAgain()), myDoc->actionCollection(), "find_again");
01268       KStdAction::findPrev(this, SLOT(findPrev()), myDoc->actionCollection(), "find_prev");
01269       KStdAction::gotoLine(this, SLOT(gotoLine()), myDoc->actionCollection(), "goto_line" );
01270       new KAction(i18n("&Configure Editor..."), 0, this, SLOT(configDialog()),myDoc->actionCollection(), "set_confdlg");
01271       setHighlight = new KSelectAction(i18n("&Highlight Mode"), 0, myDoc->actionCollection(), "set_highlight");
01272       KStdAction::selectAll(this, SLOT(selectAll()), myDoc->actionCollection(), "select_all");
01273       new KAction(i18n("&Deselect All"), 0, this, SLOT(deselectAll()),
01274                 myDoc->actionCollection(), "unselect_all");
01275       new KAction(i18n("Invert &Selection"), 0, this, SLOT(invertSelection()),
01276                 myDoc->actionCollection(), "invert_select");
01277 
01278       new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, this, SLOT(slotIncFontSizes()),
01279                 myDoc->actionCollection(), "incFontSizes");
01280       new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, this, SLOT(slotDecFontSizes()),
01281                 myDoc->actionCollection(), "decFontSizes");
01282     }
01283     else
01284     {
01285       KStdAction::saveAs(this, SLOT(saveAs()), actionCollection());
01286       KStdAction::find(this, SLOT(find()), actionCollection());
01287       KStdAction::findNext(this, SLOT(findAgain()), actionCollection());
01288       KStdAction::findPrev(this, SLOT(findPrev()), actionCollection(), "edit_find_prev");
01289       KStdAction::gotoLine(this, SLOT(gotoLine()), actionCollection());
01290       new KAction(i18n("&Configure Editor..."), 0, this, SLOT(configDialog()),actionCollection(), "set_confdlg");
01291       setHighlight = new KSelectAction(i18n("&Highlight Mode"), 0, actionCollection(), "set_highlight");
01292       KStdAction::selectAll(this, SLOT(selectAll()), actionCollection());
01293       new KAction(i18n("&Deselect All"), 0, this, SLOT(deselectAll()),
01294                 actionCollection(), "edit_deselectAll");
01295       new KAction(i18n("Invert &Selection"), 0, this, SLOT(invertSelection()),
01296                 actionCollection(), "edit_invertSelection");
01297 
01298       new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, this, SLOT(slotIncFontSizes()),
01299                 actionCollection(), "incFontSizes");
01300       new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, this, SLOT(slotDecFontSizes()),
01301                 actionCollection(), "decFontSizes");
01302     }
01303 
01304   new KAction(i18n("Apply Word Wrap"), 0, myDoc, SLOT(applyWordWrap()), actionCollection(), "edit_apply_wordwrap");
01305 
01306   KStdAction::replace(this, SLOT(replace()), actionCollection());
01307 
01308   new KAction(i18n("Editing Co&mmand"), Qt::CTRL+Qt::Key_M, this, SLOT(slotEditCommand()),
01309                                   actionCollection(), "edit_cmd");
01310 
01311     // setup bookmark menu
01312     bookmarkToggle = new KAction(i18n("Toggle &Bookmark"), Qt::CTRL+Qt::Key_B, this, SLOT(toggleBookmark()), actionCollection(), "edit_bookmarkToggle");
01313     bookmarkClear = new KAction(i18n("Clear Bookmarks"), 0, this, SLOT(clearBookmarks()), actionCollection(), "edit_bookmarksClear");
01314 
01315     // connect settings menu aboutToshow
01316     bookmarkMenu = new KActionMenu(i18n("&Bookmarks"), actionCollection(), "bookmarks");
01317     connect(bookmarkMenu->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(bookmarkMenuAboutToShow()));
01318 
01319     new KToggleAction(i18n("Show &IconBorder"), Key_F6, this, SLOT(toggleIconBorder()), actionCollection(), "view_border");
01320 
01321     // setup Tools menu
01322     KStdAction::spelling(this, SLOT(spellcheck()), actionCollection());
01323     new KAction(i18n("&Indent"), "indent", Qt::CTRL+Qt::Key_I, this, SLOT(indent()),
01324                               actionCollection(), "tools_indent");
01325     new KAction(i18n("&Unindent"), "unindent", Qt::CTRL+Qt::Key_U, this, SLOT(unIndent()),
01326                                 actionCollection(), "tools_unindent");
01327     new KAction(i18n("&Clean Indentation"), 0, this, SLOT(cleanIndent()),
01328                                    actionCollection(), "tools_cleanIndent");
01329     new KAction(i18n("C&omment"), CTRL+Qt::Key_NumberSign, this, SLOT(comment()),
01330                                actionCollection(), "tools_comment");
01331     new KAction(i18n("Unco&mment"), CTRL+SHIFT+Qt::Key_NumberSign, this, SLOT(uncomment()),
01332                                  actionCollection(), "tools_uncomment");
01333 
01334     setVerticalSelection = new KToggleAction(i18n("&Vertical Selection"), Key_F4, this, SLOT(toggleVertical()),
01335                                              actionCollection(), "set_verticalSelect");
01336 
01337     connect(setHighlight, SIGNAL(activated(int)), this, SLOT(setHl(int)));
01338     QStringList list;
01339     for (int z = 0; z < HlManager::self()->highlights(); z++)
01340         list.append(HlManager::self()->hlName(z));
01341     setHighlight->setItems(list);
01342 
01343     setEndOfLine = new KSelectAction(i18n("&End Of Line"), 0, actionCollection(), "set_eol");
01344     connect(setEndOfLine, SIGNAL(activated(int)), this, SLOT(setEol(int)));
01345     list.clear();
01346     list.append("&Unix");
01347     list.append("&Windows/Dos");
01348     list.append("&Macintosh");
01349     setEndOfLine->setItems(list);
01350 #endif 
01351 }
01352 #endif
01353 
01354 void KateView::slotUpdate()
01355 {
01356     int cfg = config();
01357 
01358 #warning fixme    setVerticalSelection->setChecked(cfg & KateView::cfVerticalSelect);
01359 
01360     slotNewUndo();
01361 }
01362 void KateView::slotFileStatusChanged()
01363 {
01364   int eol = getEol();
01365   eol = eol>=1 ? eol : 0;
01366 
01367 #warning fixme    setEndOfLine->setCurrentItem(eol);
01368 }
01369 void KateView::slotNewUndo()
01370 {
01371 #if 0
01372     int state = undoState();
01373 
01374     editUndoHist->setEnabled(state & 1 || state & 2);
01375 
01376     QString t = i18n("Und&o");   // it would be nicer to fetch the original string
01377     if (state & 1) {
01378         editUndo->setEnabled(true);
01379         t += ' ';
01380         t += i18n(undoTypeName(nextUndoType()));
01381     } else {
01382         editUndo->setEnabled(false);
01383     }
01384     editUndo->setText(t);
01385 
01386     t = i18n("Re&do");   // it would be nicer to fetch the original string
01387     if (state & 2) {
01388         editRedo->setEnabled(true);
01389         t += ' ';
01390         t += i18n(undoTypeName(nextRedoType()));
01391     } else {
01392         editRedo->setEnabled(false);
01393     }
01394     editRedo->setText(t);
01395 #endif
01396 }
01397 
01398 void KateView::slotHighlightChanged()
01399 {
01400 //    setHighlight->setCurrentItem(getHl());
01401 }
01402 
01403 
01404 void KateView::keyPressEvent( QKeyEvent *ev )
01405 {
01406     switch ( ev->key() )
01407     {
01408         case Key_Left:
01409             if ( ev->state() & ShiftButton )
01410             {
01411                 if ( ev->state() & ControlButton )
01412                     shiftWordLeft();
01413                 else
01414                     shiftCursorLeft();
01415             }
01416             else if ( ev->state() & ControlButton )
01417                 wordLeft();
01418             else
01419                 cursorLeft();
01420             break;
01421         case Key_Right:
01422             if ( ev->state() & ShiftButton )
01423             {
01424                 if ( ev->state() & ControlButton )
01425                     shiftWordRight();
01426                 else
01427                     shiftCursorRight();
01428             }
01429             else if ( ev->state() & ControlButton )
01430                 wordRight();
01431             else
01432                 cursorRight();
01433             break;
01434         case Key_Home:
01435             if ( ev->state() & ShiftButton )
01436             {
01437                 if ( ev->state() & ControlButton )
01438                     shiftTop();
01439                 else
01440                     shiftHome();
01441             }
01442             else if ( ev->state() & ControlButton )
01443                 top();
01444             else
01445                 home();
01446             break;
01447         case Key_End:
01448             if ( ev->state() & ShiftButton )
01449             {
01450                 if ( ev->state() & ControlButton )
01451                     shiftBottom();
01452                 else
01453                     shiftEnd();
01454             }
01455             else if ( ev->state() & ControlButton )
01456                 bottom();
01457             else
01458                 end();
01459             break;
01460         case Key_Up:
01461             if ( ev->state() & ShiftButton )
01462                 shiftUp();
01463             else if ( ev->state() & ControlButton )
01464                 scrollUp();
01465             else
01466                 up();
01467             break;
01468         case Key_Down:
01469             if ( ev->state() & ShiftButton )
01470                 shiftDown();
01471             else if ( ev->state() & ControlButton )
01472                 scrollDown();
01473             else
01474                 down();
01475             break;
01476         case Key_PageUp:
01477             if ( ev->state() & ShiftButton )
01478                 shiftPageUp();
01479             else if ( ev->state() & ControlButton )
01480                 topOfView();
01481             else
01482                 pageUp();
01483             break;
01484         case Key_PageDown:
01485             if ( ev->state() & ShiftButton )
01486                 shiftPageDown();
01487             else if ( ev->state() & ControlButton )
01488                 bottomOfView();
01489             else
01490                 pageDown();
01491             break;
01492         case Key_Return:
01493         case Key_Enter:
01494             keyReturn();
01495             break;
01496         case Key_Delete:
01497             if ( ev->state() & ControlButton )
01498             {
01499                VConfig c;
01500                shiftWordRight();
01501                myViewInternal->getVConfig(c);
01502                myDoc->delMarkedText(c);
01503                myViewInternal->update();
01504             }
01505             else keyDelete();
01506             break;
01507         case Key_Backspace:
01508             if ( ev->state() & ControlButton )
01509             {
01510                VConfig c;
01511                shiftWordLeft();
01512                myViewInternal->getVConfig(c);
01513                myDoc->delMarkedText(c);
01514                myViewInternal->update();
01515             }
01516             else backspace();
01517             break;
01518         case Key_Insert:
01519             toggleInsert();
01520             break;
01521         case Key_K:
01522             if ( ev->state() & ControlButton )
01523             {
01524                 killLine();
01525                 break;
01526             }
01527         default:
01528             KTextEditor::View::keyPressEvent( ev );
01529             return;
01530             break;
01531     }
01532     ev->accept();
01533 }
01534 
01535 
01536 void KateView::setCursorPosition( int line, int col, bool /*mark*/ )
01537 {
01538   setCursorPositionInternal( line, col );
01539 }
01540 
01541 void KateView::getCursorPosition( int *line, int *col )
01542 {
01543   if ( line )
01544     *line = currentLine();
01545 
01546   if ( col )
01547     *col = currentColumn();
01548 }
01549 
01550 
01551 int KateView::currentLine() {
01552   return myViewInternal->cursor.y;
01553 }
01554 
01555 int KateView::currentColumn() {
01556   return myDoc->currentColumn(myViewInternal->cursor);
01557 }
01558 
01559 int KateView::currentCharNum() {
01560   return myViewInternal->cursor.x;
01561 }
01562 
01563 void KateView::setCursorPositionInternal(int line, int col) {
01564   PointStruc cursor;
01565 
01566   cursor.x = col;
01567   cursor.y = line;
01568   myViewInternal->updateCursor(cursor);
01569   myViewInternal->center();
01570 //  myViewInternal->updateView(ufPos, 0, line*myDoc->fontHeight - height()/2);
01571 //  myDoc->updateViews(myViewInternal); //uptade all other views except this one
01572   myDoc->updateViews();
01573 }
01574 
01575 int KateView::config() {
01576   int flags;
01577 
01578   flags = configFlags;
01579   if (myDoc->singleSelection()) flags |= KateView::cfSingleSelection;
01580   return flags;
01581 }
01582 
01583 void KateView::setConfig(int flags) {
01584   bool updateView;
01585 
01586   // cfSingleSelection is a doc-property
01587   myDoc->setSingleSelection(flags & KateView::cfSingleSelection);
01588   flags &= ~KateView::cfSingleSelection;
01589 
01590   if (flags != configFlags) {
01591     // update the view if visibility of tabs has changed
01592     updateView = (flags ^ configFlags) & KateView::cfShowTabs;
01593     configFlags = flags;
01594     emit newStatus();
01595     if (updateView) myViewInternal->update();
01596   }
01597 }
01598 
01599 int KateView::tabWidth() {
01600   return myDoc->tabChars;
01601 }
01602 
01603 void KateView::setTabWidth(int w) {
01604   myDoc->setTabWidth(w);
01605   myDoc->updateViews();
01606 }
01607 
01608 void KateView::setEncoding (QString e) {
01609   myDoc->setEncoding (e);
01610   myDoc->updateViews();
01611 }
01612 
01613 int KateView::undoSteps() {
01614   return myDoc->undoSteps;
01615 }
01616 
01617 void KateView::setUndoSteps(int s) {
01618   myDoc->setUndoSteps(s);
01619 }
01620 
01621 bool KateView::isReadOnly() {
01622   return myDoc->readOnly;
01623 }
01624 
01625 bool KateView::isModified() {
01626   return myDoc->modified;
01627 }
01628 
01629 void KateView::setReadOnly(bool m) {
01630   myDoc->setReadOnly(m);
01631 }
01632 
01633 void KateView::setModified(bool m) {
01634   myDoc->setModified(m);
01635 }
01636 
01637 bool KateView::isLastView() {
01638   return myDoc->isLastView(1);
01639 }
01640 
01641 KateDocument *KateView::doc() {
01642   return myDoc;
01643 }
01644 
01645 int KateView::undoState() {
01646   if (isReadOnly())
01647     return 0;
01648   else
01649     return myDoc->undoState;
01650 }
01651 
01652 int KateView::nextUndoType() {
01653   return myDoc->nextUndoType();
01654 }
01655 
01656 int KateView::nextRedoType() {
01657   return myDoc->nextRedoType();
01658 }
01659 
01660 void KateView::undoTypeList(QValueList<int> &lst)
01661 {
01662   myDoc->undoTypeList(lst);
01663 }
01664 
01665 void KateView::redoTypeList(QValueList<int> &lst)
01666 {
01667   myDoc->redoTypeList(lst);
01668 }
01669 
01670 const char * KateView::undoTypeName(int type) {
01671   return KateActionGroup::typeName(type);
01672 }
01673 
01674 QColor* KateView::getColors()
01675 {
01676   return myDoc->colors;
01677 }
01678 
01679 void KateView::applyColors()
01680 {
01681    myDoc->tagAll();
01682    myDoc->updateViews();
01683 }
01684 
01685 bool KateView::isOverwriteMode() const
01686 {
01687   return ( configFlags & KateView::cfOvr );
01688 }
01689 
01690 void KateView::setOverwriteMode( bool b )
01691 {
01692   if ( isOverwriteMode() && !b )
01693     setConfig( configFlags ^ KateView::cfOvr );
01694   else
01695     setConfig( configFlags | KateView::cfOvr );
01696 }
01697 
01698 void KateView::toggleInsert() {
01699   setConfig(configFlags ^ KateView::cfOvr);
01700 }
01701 
01702 void KateView::toggleVertical()
01703 {
01704   setConfig(configFlags ^ KateView::cfVerticalSelect);
01705 }
01706 
01707 
01708 int KateView::numLines() {
01709   return myDoc->numLines();
01710 }
01711 
01712 QString KateView::text() {
01713   return myDoc->text();
01714 }
01715 
01716 QString KateView::currentTextLine() {
01717   TextLine::Ptr textLine = myDoc->getTextLine(myViewInternal->cursor.y);
01718   return QString(textLine->getText(), textLine->length());
01719 }
01720 
01721 QString KateView::textLine(int num) {
01722   TextLine::Ptr textLine = myDoc->getTextLine(num);
01723   return QString(textLine->getText(), textLine->length());
01724 }
01725 
01726 QString KateView::currentWord() {
01727   return myDoc->getWord(myViewInternal->cursor);
01728 }
01729 
01730 QString KateView::word(int x, int y) {
01731   PointStruc cursor;
01732   cursor.y = (myViewInternal->yPos + y)/myDoc->fontHeight;
01733   if (cursor.y < 0 || cursor.y > myDoc->lastLine()) return QString();
01734   cursor.x = myDoc->textPos(myDoc->getTextLine(cursor.y), myViewInternal->xPos-2 + x);
01735   return myDoc->getWord(cursor);
01736 }
01737 
01738 void KateView::setText(const QString &s) {
01739   myDoc->setText(s);
01740   myDoc->updateViews();
01741 }
01742 
01743 void KateView::insertText(const QString &s, bool /*mark*/) {
01744   VConfig c;
01745   myViewInternal->getVConfig(c);
01746   myDoc->insert(c, s);
01747   myDoc->updateViews();
01748 }
01749 
01750 bool KateView::hasMarkedText() {
01751   return myDoc->hasMarkedText();
01752 }
01753 
01754 QString KateView::markedText() {
01755   return myDoc->markedText(configFlags);
01756 }
01757 
01758 bool KateView::canDiscard() {
01759   int query;
01760 
01761   if (isModified()) {
01762     query = KMessageBox::warningYesNoCancel(this,
01763       i18n("The current Document has been modified.\nWould you like to save it?"));
01764     switch (query) {
01765       case KMessageBox::Yes: //yes
01766         if (save() == CANCEL) return false;
01767         if (isModified()) {
01768             query = KMessageBox::warningContinueCancel(this,
01769                i18n("Could not save the document.\nDiscard it and continue?"),
01770          QString::null, i18n("&Discard"));
01771           if (query == KMessageBox::Cancel) return false;
01772         }
01773         break;
01774       case KMessageBox::Cancel: //cancel
01775         return false;
01776     }
01777   }
01778   return true;
01779 }
01780 
01781 void KateView::flush()
01782 {
01783   if (canDiscard()) myDoc->flush();
01784 }
01785 
01786 KateView::fileResult KateView::save() {
01787   int query = KMessageBox::Yes;
01788   if (isModified()) {
01789       return saveAs();
01790   }
01791   return OK;
01792 }
01793 
01794 KateView::fileResult KateView::saveAs() {
01795  return OK;
01796 }
01797 
01798 void KateView::doCursorCommand(int cmdNum) {
01799   VConfig c;
01800   myViewInternal->getVConfig(c);
01801   if (cmdNum & selectFlag) c.flags |= KateView::cfMark;
01802   if (cmdNum & multiSelectFlag) c.flags |= KateView::cfMark | KateView::cfKeepSelection;
01803   cmdNum &= ~(selectFlag | multiSelectFlag);
01804   myViewInternal->doCursorCommand(c, cmdNum);
01805   myDoc->updateViews();
01806 }
01807 
01808 void KateView::doEditCommand(int cmdNum) {
01809   VConfig c;
01810   myViewInternal->getVConfig(c);
01811   myViewInternal->doEditCommand(c, cmdNum);
01812   myDoc->updateViews();
01813 }
01814 
01815 void KateView::undoMultiple(int count) {
01816   if (isReadOnly())
01817     return;
01818 
01819   VConfig c;
01820   myViewInternal->getVConfig(c);
01821   myDoc->undo(c, count);
01822   myDoc->updateViews();
01823 }
01824 
01825 void KateView::redoMultiple(int count) {
01826   if (isReadOnly())
01827     return;
01828 
01829   VConfig c;
01830   myViewInternal->getVConfig(c);
01831   myDoc->redo(c, count);
01832   myDoc->updateViews();
01833 }
01834 
01835 void KateView::undoHistory()
01836 {
01837   UndoHistory   *undoH;
01838 
01839   undoH = new UndoHistory(this, this, "UndoHistory", true);
01840 
01841   undoH->setCaption(i18n("Undo/Redo History"));
01842 
01843   connect(this,SIGNAL(newUndo()),undoH,SLOT(newUndo()));
01844   connect(undoH,SIGNAL(undo(int)),this,SLOT(undoMultiple(int)));
01845   connect(undoH,SIGNAL(redo(int)),this,SLOT(redoMultiple(int)));
01846 
01847   undoH->exec();
01848 
01849   delete undoH;
01850 }
01851 
01852 static void kwview_addToStrList(QStringList &list, const QString &str) {
01853   if (list.count() > 0) {
01854     if (list.first() == str) return;
01855     QStringList::Iterator it;
01856     it = list.find(str);
01857     if (*it != 0L) list.remove(it);
01858     if (list.count() >= 16) list.remove(list.fromLast());
01859   }
01860   list.prepend(str);
01861 }
01862 
01863 void KateView::find() {
01864   SearchDialog *searchDialog;
01865 
01866   if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected;
01867 
01868   searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList,
01869   searchFlags & ~KateView::sfReplace);
01870 
01871   // If the user has marked some text we use that otherwise
01872   // use the word under the cursor.
01873    QString str;
01874    if (myDoc->hasMarkedText())
01875      str = markedText();
01876 
01877    if (str.isEmpty())
01878      str = currentWord();
01879 
01880    if (!str.isEmpty())
01881    {
01882      str.replace(QRegExp("^\n"), "");
01883      int pos=str.find("\n");
01884      if (pos>-1)
01885        str=str.left(pos);
01886      searchDialog->setSearchText( str );
01887    }
01888 
01889   myViewInternal->focusOutEvent(0L);// QT bug ?
01890   if (searchDialog->exec() == QDialog::Accepted) {
01891     kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor());
01892     searchFlags = searchDialog->getFlags() | (searchFlags & KateView::sfPrompt);
01893     initSearch(s, searchFlags);
01894     findAgain(s);
01895   }
01896   delete searchDialog;
01897 }
01898 
01899 void KateView::replace() {
01900   SearchDialog *searchDialog;
01901 
01902   if (isReadOnly()) return;
01903 
01904   if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected;
01905   searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList,
01906     searchFlags | KateView::sfReplace);
01907 
01908   // If the user has marked some text we use that otherwise
01909   // use the word under the cursor.
01910    QString str;
01911    if (myDoc->hasMarkedText())
01912      str = markedText();
01913 
01914    if (str.isEmpty())
01915      str = currentWord();
01916 
01917    if (!str.isEmpty())
01918    {
01919      str.replace(QRegExp("^\n"), "");
01920      int pos=str.find("\n");
01921      if (pos>-1)
01922        str=str.left(pos);
01923      searchDialog->setSearchText( str );
01924    }
01925 
01926   myViewInternal->focusOutEvent(0L);// QT bug ?
01927   if (searchDialog->exec() == QDialog::Accepted) {
01928 //    myDoc->recordReset();
01929     kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor());
01930     kwview_addToStrList(myDoc->replaceWithList, searchDialog->getReplaceWith());
01931     searchFlags = searchDialog->getFlags();
01932     initSearch(s, searchFlags);
01933     replaceAgain();
01934   }
01935   delete searchDialog;
01936 }
01937 
01938 void KateView::gotoLine() {
01939   GotoLineDialog *dlg;
01940   PointStruc cursor;
01941 
01942   dlg = new GotoLineDialog(this, myViewInternal->cursor.y + 1, myDoc->numLines());
01943 //  dlg = new GotoLineDialog(myViewInternal->cursor.y + 1, this);
01944 
01945   if (dlg->exec() == QDialog::Accepted) {
01946 //    myDoc->recordReset();
01947     cursor.x = 0;
01948     cursor.y = dlg->getLine() - 1;
01949     myDoc->needPreHighlight(cursor.y);
01950     myViewInternal->updateCursor(cursor);
01951     myViewInternal->center();
01952     myViewInternal->updateView(KateView::ufUpdateOnScroll);
01953     myDoc->updateViews(this); //uptade all other views except this one
01954   }
01955   delete dlg;
01956 }
01957 
01958 
01959 void KateView::initSearch(SConfig &s, int flags) {
01960 
01961   s.flags = flags;
01962   s.setPattern(myDoc->searchForList.first());
01963 
01964   if (!(s.flags & KateView::sfFromBeginning)) {
01965     // If we are continuing a backward search, make sure we do not get stuck
01966     // at an existing match.
01967     s.cursor = myViewInternal->cursor;
01968     TextLine::Ptr textLine = myDoc->getTextLine(s.cursor.y);
01969     QString const txt(textLine->getText(),textLine->length());
01970     const QString searchFor= myDoc->searchForList.first();
01971     int pos = s.cursor.x-searchFor.length()-1;
01972     if ( pos < 0 ) pos = 0;
01973     pos= txt.find(searchFor, pos, s.flags & KateView::sfCaseSensitive);
01974     if ( s.flags & KateView::sfBackward )
01975     {
01976       if ( pos <= s.cursor.x )  s.cursor.x= pos-1;
01977     }
01978     else
01979       if ( pos == s.cursor.x )  s.cursor.x++;
01980   } else {
01981     if (!(s.flags & KateView::sfBackward)) {
01982       s.cursor.x = 0;
01983       s.cursor.y = 0;
01984     } else {
01985       s.cursor.x = -1;
01986       s.cursor.y = myDoc->lastLine();
01987     }
01988     s.flags |= KateView::sfFinished;
01989   }
01990   if (!(s.flags & KateView::sfBackward)) {
01991     if (!(s.cursor.x || s.cursor.y))
01992       s.flags |= KateView::sfFinished;
01993   }
01994   s.startCursor = s.cursor;
01995 }
01996 
01997 void KateView::continueSearch(SConfig &s) {
01998 
01999   if (!(s.flags & KateView::sfBackward)) {
02000     s.cursor.x = 0;
02001     s.cursor.y = 0;
02002   } else {
02003     s.cursor.x = -1;
02004     s.cursor.y = myDoc->lastLine();
02005   }
02006   s.flags |= KateView::sfFinished;
02007   s.flags &= ~KateView::sfAgain;
02008 }
02009 
02010 void KateView::findAgain(SConfig &s) {
02011   int query;
02012   PointStruc cursor;
02013   QString str;
02014 
02015   QString searchFor = myDoc->searchForList.first();
02016 
02017   if( searchFor.isEmpty() ) {
02018     find();
02019     return;
02020   }
02021 
02022   do {
02023     query = KMessageBox::Cancel;
02024     if (myDoc->doSearch(s,searchFor)) {
02025       cursor = s.cursor;
02026       if (!(s.flags & KateView::sfBackward))
02027         s.cursor.x += s.matchedLength;
02028       myViewInternal->updateCursor(s.cursor); //does deselectAll()
02029       exposeFound(cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,false);
02030     } else {
02031       if (!(s.flags & KateView::sfFinished)) {
02032         // ask for continue
02033         if (!(s.flags & KateView::sfBackward)) {
02034           // forward search
02035           str = i18n("End of document reached.\n"
02036                 "Continue from the beginning?");
02037           query = KMessageBox::warningContinueCancel(this,
02038                            str, i18n("Find"), i18n("Continue"));
02039         } else {
02040           // backward search
02041           str = i18n("Beginning of document reached.\n"
02042                 "Continue from the end?");
02043           query = KMessageBox::warningContinueCancel(this,
02044                            str, i18n("Find"), i18n("Continue"));
02045         }
02046         continueSearch(s);
02047       } else {
02048         // wrapped
02049         KMessageBox::sorry(this,
02050           i18n("Search string '%1' not found!").arg(searchFor),
02051           i18n("Find"));
02052       }
02053     }
02054   } while (query == KMessageBox::Continue);
02055 }
02056 
02057 void KateView::replaceAgain() {
02058   if (isReadOnly())
02059     return;
02060 
02061   replaces = 0;
02062   if (s.flags & KateView::sfPrompt) {
02063     doReplaceAction(-1);
02064   } else {
02065     doReplaceAction(KateView::srAll);
02066   }
02067 }
02068 
02069 void KateView::doReplaceAction(int result, bool found) {
02070   int rlen;
02071   PointStruc cursor;
02072   bool started;
02073 
02074   QString searchFor = myDoc->searchForList.first();
02075   QString replaceWith = myDoc->replaceWithList.first();
02076   rlen = replaceWith.length();
02077 
02078   switch (result) {
02079     case KateView::srYes: //yes
02080       myDoc->recordStart(this, s.cursor, configFlags,
02081         KateActionGroup::ugReplace, true);
02082       myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith);
02083       replaces++;
02084       if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x)
02085         s.startCursor.x += rlen - s.matchedLength;
02086       if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen;
02087       myDoc->recordEnd(this, s.cursor, configFlags | KateView::cfPersistent);
02088       break;
02089     case KateView::srNo: //no
02090       if (!(s.flags & KateView::sfBackward)) s.cursor.x += s.matchedLength;
02091       break;
02092     case KateView::srAll: //replace all
02093       deleteReplacePrompt();
02094       do {
02095         started = false;
02096         while (found || myDoc->doSearch(s,searchFor)) {
02097           if (!started) {
02098             found = false;
02099             myDoc->recordStart(this, s.cursor, configFlags,
02100               KateActionGroup::ugReplace);
02101             started = true;
02102           }
02103           myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith);
02104           replaces++;
02105           if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x)
02106             s.startCursor.x += rlen - s.matchedLength;
02107           if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen;
02108         }
02109         if (started) myDoc->recordEnd(this, s.cursor,
02110           configFlags | KateView::cfPersistent);
02111       } while (!askReplaceEnd());
02112       return;
02113     case KateView::srCancel: //cancel
02114       deleteReplacePrompt();
02115       return;
02116     default:
02117       replacePrompt = 0L;
02118   }
02119 
02120   do {
02121     if (myDoc->doSearch(s,searchFor)) {
02122       //text found: highlight it, show replace prompt if needed and exit
02123       cursor = s.cursor;
02124       if (!(s.flags & KateView::sfBackward)) cursor.x += s.matchedLength;
02125       myViewInternal->updateCursor(cursor); //does deselectAll()
02126       exposeFound(s.cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,true);
02127       if (replacePrompt == 0L) {
02128         replacePrompt = new ReplacePrompt(this);
02129         myDoc->setPseudoModal(replacePrompt);//disable();
02130         connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot()));
02131         replacePrompt->show(); //this is not modal
02132       }
02133       return; //exit if text found
02134     }
02135     //nothing found: repeat until user cancels "repeat from beginning" dialog
02136   } while (!askReplaceEnd());
02137   deleteReplacePrompt();
02138 }
02139 
02140 void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) {
02141   int x1, x2, y1, y2, xPos, yPos;
02142 
02143   VConfig c;
02144   myViewInternal->getVConfig(c);
02145   myDoc->selectLength(cursor,slen,c.flags);
02146 
02147   TextLine::Ptr textLine = myDoc->getTextLine(cursor.y);
02148   x1 = myDoc->textWidth(textLine,cursor.x)        -10;
02149   x2 = myDoc->textWidth(textLine,cursor.x + slen) +20;
02150   y1 = myDoc->fontHeight*cursor.y                 -10;
02151   y2 = y1 + myDoc->fontHeight                     +30;
02152 
02153   xPos = myViewInternal->xPos;
02154   yPos = myViewInternal->yPos;
02155 
02156   if (x1 < 0) x1 = 0;
02157   if (replace) y2 += 90;
02158 
02159   if (x1 < xPos || x2 > xPos + myViewInternal->width()) {
02160     xPos = x2 - myViewInternal->width();
02161   }
02162   if (y1 < yPos || y2 > yPos + myViewInternal->height()) {
02163     xPos = x2 - myViewInternal->width();
02164     yPos = myDoc->fontHeight*cursor.y - height()/3;
02165   }
02166   myViewInternal->setPos(xPos, yPos);
02167   myViewInternal->updateView(flags);// | ufPos,xPos,yPos);
02168   myDoc->updateViews(this);
02169 }
02170 
02171 void KateView::deleteReplacePrompt() {
02172   myDoc->setPseudoModal(0L);
02173 }
02174 
02175 bool KateView::askReplaceEnd() {
02176   QString str;
02177   int query;
02178 
02179   myDoc->updateViews();
02180   if (s.flags & KateView::sfFinished) {
02181     // replace finished
02182     str = i18n("%1 replacement(s) made").arg(replaces);
02183     KMessageBox::information(this, str, i18n("Replace"));
02184     return true;
02185   }
02186 
02187   // ask for continue
02188   if (!(s.flags & KateView::sfBackward)) {
02189     // forward search
02190     str = i18n("%1 replacement(s) made.\n"
02191                "End of document reached.\n"
02192                "Continue from the beginning?").arg(replaces);
02193     query = KMessageBox::questionYesNo(this, str, i18n("Replace"),
02194     i18n("Continue"), i18n("Stop"));
02195   } else {
02196     // backward search
02197     str = i18n("%1 replacement(s) made.\n"
02198                 "Beginning of document reached.\n"
02199                 "Continue from the end?").arg(replaces);
02200     query = KMessageBox::questionYesNo(this, str, i18n("Replace"),
02201                 i18n("Continue"), i18n("Stop"));
02202   }
02203   replaces = 0;
02204   continueSearch(s);
02205   return (query == KMessageBox::No);
02206 }
02207 
02208 void KateView::replaceSlot() {
02209   doReplaceAction(replacePrompt->result(),true);
02210 }
02211 
02212 void KateView::installPopup(QPopupMenu *rmb_Menu)
02213 {
02214   rmbMenu = rmb_Menu;
02215 }
02216 
02217 void KateView::readConfig()
02218 {
02219   KateConfig *config = KGlobal::config();
02220   config->setGroup("Kate View");
02221 
02222   searchFlags = config->readNumEntry("SearchFlags", KateView::sfPrompt);
02223   configFlags = config->readNumEntry("ConfigFlags", configFlags) & ~KateView::cfMark;
02224 
02225 //  config->sync();
02226 }
02227 
02228 void KateView::writeConfig()
02229 {
02230   KateConfig *config = KGlobal::config();
02231   config->setGroup("Kate View");
02232 
02233   config->writeEntry("SearchFlags",searchFlags);
02234   config->writeEntry("ConfigFlags",configFlags);
02235 
02236 //  config->sync();
02237 }
02238 
02239 void KateView::readSessionConfig(KateConfig *config)
02240 {
02241   PointStruc cursor;
02242 
02243   myViewInternal->xPos = config->readNumEntry("XPos");
02244   myViewInternal->yPos = config->readNumEntry("YPos");
02245   cursor.x = config->readNumEntry("CursorX");
02246   cursor.y = config->readNumEntry("CursorY");
02247   myViewInternal->updateCursor(cursor);
02248   myIconBorder = config->readBoolEntry("IconBorder on");
02249   setIconBorder(myIconBorder);
02250 }
02251 
02252 void KateView::writeSessionConfig(KateConfig *config)
02253 {
02254   config->writeEntry("XPos",myViewInternal->xPos);
02255   config->writeEntry("YPos",myViewInternal->yPos);
02256   config->writeEntry("CursorX",myViewInternal->cursor.x);
02257   config->writeEntry("CursorY",myViewInternal->cursor.y);
02258   config->writeEntry("IconBorder on", myIconBorder);
02259 }
02260 
02261 void KateView::configDialog()
02262 {
02263 
02264 #warning fixme
02265 
02266 #if 1 
02267   KDialogBase *kd = new KDialogBase(KDialogBase::IconList,
02268                                     i18n("Configure Editor"),
02269                                     KDialogBase::Ok | KDialogBase::Cancel |
02270                                     KDialogBase::Help ,
02271                                     KDialogBase::Ok, this, "tabdialog");
02272 
02273   // color options
02274   QFrame *page=kd->addPage(i18n("Colors"));
02275   (new QVBoxLayout(page))->setAutoAdd(true);
02276   ColorConfig *colorConfig = new ColorConfig(page);
02277   QColor* colors = getColors();
02278   colorConfig->setColors(colors);
02279 
02280  page = kd->addPage(i18n("Fonts"));
02281   (new QVBoxLayout(page))->setAutoAdd(true);
02282 
02283   FontConfig *fontConfig = new FontConfig(page);
02284   fontConfig->setFont (myDoc->getFont());
02285 
02286   // indent options
02287   page=kd->addPage(i18n("Indent"));
02288   (new QVBoxLayout(page))->setAutoAdd(true);
02289 
02290   IndentConfigTab *indentConfig = new IndentConfigTab(page, this);
02291 
02292   // select options
02293   page=kd->addPage(i18n("Select"));
02294   (new QVBoxLayout(page))->setAutoAdd(true);
02295 
02296   SelectConfigTab *selectConfig = new SelectConfigTab(page, this);
02297 
02298   // edit options
02299   page=kd->addPage(i18n("Edit"));
02300   (new QVBoxLayout(page))->setAutoAdd(true);
02301 
02302   EditConfigTab *editConfig = new EditConfigTab(page, this);
02303 
02304 
02305 
02306   HighlightDialogPage *hlPage;
02307   HlManager *hlManager;
02308   HlDataList hlDataList;
02309   ItemStyleList defaultStyleList;
02310 
02311   hlManager = HlManager::self();
02312 
02313   defaultStyleList.setAutoDelete(true);
02314   hlManager->getDefaults(defaultStyleList);
02315 
02316   hlDataList.setAutoDelete(true);
02317   //this gets the data from the KateConfig object
02318   hlManager->getHlDataList(hlDataList);
02319 
02320   page=kd->addPage(i18n("Highlighting"));
02321   (new QVBoxLayout(page))->setAutoAdd(true);
02322 
02323   hlPage = new HighlightDialogPage(hlManager, &defaultStyleList, &hlDataList, 0, page);
02324  if ( QPEApplication::execDialog( kd )) {
02325     // color options
02326     colorConfig->getColors(colors);
02327     myDoc->setFont (fontConfig->getFont());
02328 
02329     applyColors();
02330     // indent options
02331     indentConfig->getData(this);
02332     // select options
02333     selectConfig->getData(this);
02334     // edit options
02335     editConfig->getData(this);
02336     // spell checker
02337     hlManager->setHlDataList(hlDataList);
02338     hlManager->setDefaults(defaultStyleList);
02339     hlPage->saveData();
02340   }
02341 
02342 //  delete kd;
02343 
02344 #endif
02345 }
02346 
02347 int KateView::getHl() {
02348   return myDoc->highlightNum();
02349 }
02350 
02351 void KateView::setDontChangeHlOnSave()
02352 {
02353     myDoc->setDontChangeHlOnSave();
02354 }
02355 
02356 void KateView::setHl(int n) {
02357   myDoc->setHighlight(n);
02358   myDoc->setDontChangeHlOnSave();
02359   myDoc->updateViews();
02360 }
02361 
02362 int KateView::getEol() {
02363   return myDoc->eolMode;
02364 }
02365 
02366 void KateView::setEol(int eol) {
02367   if (isReadOnly())
02368     return;
02369 
02370   myDoc->eolMode = eol;
02371   myDoc->setModified(true);
02372 }
02373 
02374 
02375 
02376 void KateView::paintEvent(QPaintEvent *e) {
02377   int x, y;
02378 
02379   QRect updateR = e->rect();                    // update rectangle
02380 //  debug("Update rect = ( %i, %i, %i, %i )",
02381 //    updateR.x(),updateR.y(), updateR.width(), updateR.height() );
02382 
02383   int ux1 = updateR.x();
02384   int uy1 = updateR.y();
02385   int ux2 = ux1 + updateR.width();
02386   int uy2 = uy1 + updateR.height();
02387 
02388   QPainter paint;
02389   paint.begin(this);
02390 
02391   QColorGroup g = colorGroup();
02392   x = width();
02393   y = height();
02394 
02395   paint.setPen(g.dark());
02396   if (uy1 <= 0) paint.drawLine(0,0,x-2,0);
02397   if (ux1 <= 0) paint.drawLine(0,1,0,y-2);
02398 
02399   paint.setPen(black);
02400   if (uy1 <= 1) paint.drawLine(1,1,x-3,1);
02401   if (ux1 <= 1) paint.drawLine(1,2,1,y-3);
02402 
02403   paint.setPen(g.midlight());
02404   if (uy2 >= y-1) paint.drawLine(1,y-2,x-3,y-2);
02405   if (ux2 >= x-1) paint.drawLine(x-2,1,x-2,y-2);
02406 
02407   paint.setPen(g.light());
02408   if (uy2 >= y) paint.drawLine(0,y-1,x-2,y-1);
02409   if (ux2 >= x) paint.drawLine(x-1,0,x-1,y-1);
02410 
02411   x -= 2 + 16;
02412   y -= 2 + 16;
02413   if (ux2 > x && uy2 > y) {
02414     paint.fillRect(x,y,16,16,g.background());
02415   }
02416   paint.end();
02417 }
02418 
02419 void KateView::resizeEvent(QResizeEvent *) {
02420 
02421 //  debug("Resize %d, %d",e->size().width(),e->size().height());
02422 
02423 //myViewInternal->resize(width() -20, height() -20);
02424   myViewInternal->tagAll();
02425   myViewInternal->updateView(0/*ufNoScroll*/);
02426 }
02427 
02428 
02429 // Applies a new pattern to the search context.
02430 void SConfig::setPattern(QString &newPattern) {
02431   bool regExp = (flags & KateView::sfRegularExpression);
02432 
02433   m_pattern = newPattern;
02434   if (regExp) {
02435     m_regExp.setCaseSensitive(flags & KateView::sfCaseSensitive);
02436     m_regExp.setPattern(m_pattern);
02437   }
02438 }
02439 
02440 // Applies the search context to the given string, and returns whether a match was found. If one is,
02441 // the length of the string matched is also returned.
02442 int SConfig::search(QString &text, int index) {
02443   bool regExp = (flags & KateView::sfRegularExpression);
02444   bool caseSensitive = (flags & KateView::sfCaseSensitive);
02445 
02446   if (flags & KateView::sfBackward) {
02447     if (regExp) {
02448       index = text.findRev(m_regExp, index);
02449     }
02450     else {
02451       index = text.findRev(m_pattern, index, caseSensitive);
02452     }
02453   }
02454   else {
02455     if (regExp) {
02456       index = text.find(m_regExp, index);
02457     }
02458     else {
02459       index = text.find(m_pattern, index, caseSensitive);
02460     }
02461   }
02462 
02463   // Work out the matched length.
02464   if (index != -1)
02465   {
02466     if (regExp) {
02467       m_regExp.match(text, index, &matchedLength, false);
02468     }
02469     else {
02470       matchedLength = m_pattern.length();
02471     }
02472   }
02473   return index;
02474 }
02475 
02476 void KateView::setActive (bool b)
02477 {
02478   active = b;
02479 }
02480 
02481 bool KateView::isActive ()
02482 {
02483   return active;
02484 }
02485 
02486 void KateView::setFocus ()
02487 {
02488   QWidget::setFocus ();
02489 
02490   emit gotFocus (this);
02491 }
02492 
02493 bool KateView::eventFilter (QObject *object, QEvent *event)
02494 {
02495 
02496   if ( (event->type() == QEvent::FocusIn) )
02497     emit gotFocus (this);
02498 
02499   if ( (event->type() == QEvent::KeyPress) )
02500     {
02501         QKeyEvent * ke=(QKeyEvent *)event;
02502 
02503         if ((ke->key()==Qt::Key_Tab) || (ke->key()==Qt::Key_BackTab))
02504           {
02505             myViewInternal->keyPressEvent(ke);
02506             return true;
02507           }
02508     }
02509   return QWidget::eventFilter (object, event);
02510 }
02511 
02512 void KateView::findAgain (bool back)
02513 {
02514   bool b= (searchFlags & sfBackward) > 0;
02515   initSearch(s, (searchFlags & ((b==back)?~sfBackward:~0) & ~sfFromBeginning)  // clear flag for forward searching
02516                 | sfPrompt | sfAgain | ((b!=back)?sfBackward:0) );
02517   if (s.flags & sfReplace)
02518     replaceAgain();
02519   else
02520     KateView::findAgain(s);
02521 }
02522 
02523 void KateView::slotEditCommand ()
02524 {
02525 #warning fixme
02526 /*
02527   bool ok;
02528   QString cmd = KLineEditDlg::getText("Editing Command", "", &ok, this);
02529 
02530   if (ok)
02531     myDoc->cmd()->execCmd (cmd, this);*/
02532 }
02533 
02534 void KateView::setIconBorder (bool enable)
02535 {
02536   myIconBorder = enable;
02537 
02538   if (myIconBorder)
02539   {
02540     myViewInternal->move(myViewInternal->iconBorderWidth+2, 2);
02541     myViewInternal->leftBorder->show();
02542   }
02543   else
02544   {
02545     myViewInternal->leftBorder->hide();
02546     myViewInternal->move(2, 2);
02547   }
02548 }
02549 
02550 void KateView::toggleIconBorder ()
02551 {
02552   setIconBorder (!myIconBorder);
02553 }
02554 
02555 void KateView::gotoMark (Kate::Mark *mark)
02556 {
02557   PointStruc cursor;
02558 
02559   cursor.x = 0;
02560   cursor.y = mark->line;
02561   myDoc->needPreHighlight(cursor.y);
02562   myViewInternal->updateCursor(cursor);
02563   myViewInternal->center();
02564   myViewInternal->updateView(KateView::ufUpdateOnScroll);
02565   myDoc->updateViews(this);
02566 }
02567 
02568 void KateView::toggleBookmark ()
02569 {
02570   TextLine::Ptr line = myDoc->getTextLine (currentLine());
02571 
02572   if (line->mark()&KateDocument::Bookmark)
02573     line->delMark(KateDocument::Bookmark);
02574   else
02575     line->addMark(KateDocument::Bookmark);
02576 
02577   myDoc->tagLines (currentLine(), currentLine());
02578   myDoc->updateViews();
02579 }
02580 
02581 void KateView::clearBookmarks()
02582 {
02583   QList<Kate::Mark> list = myDoc->marks();
02584   for (int i=0; (uint) i < list.count(); i++)
02585   {
02586     if (list.at(i)->type&KateDocument::Bookmark)
02587     {
02588       myDoc->getTextLine(list.at(i)->line)->delMark(KateDocument::Bookmark);
02589       myDoc->tagLines(list.at(i)->line, list.at(i)->line);
02590     }
02591   }
02592 
02593   myDoc->updateViews();
02594 }
02595 
02596 void KateView::bookmarkMenuAboutToShow()
02597 {
02598 #warning fixme
02599 #if 0
02600   bookmarkMenu->popupMenu()->clear ();
02601   bookmarkToggle->plug (bookmarkMenu->popupMenu());
02602   bookmarkClear->plug (bookmarkMenu->popupMenu());
02603   bookmarkMenu->popupMenu()->insertSeparator ();
02604 
02605   list = myDoc->marks();
02606   for (int i=0; (uint) i < list.count(); i++)
02607   {
02608     if (list.at(i)->type&KateDocument::Bookmark)
02609     {
02610       QString bText = textLine(list.at(i)->line);
02611       bText.truncate(32);
02612       bText.append ("...");
02613       bookmarkMenu->popupMenu()->insertItem ( QString("%1 - \"%2\"").arg(list.at(i)->line).arg(bText), this, SLOT (gotoBookmark(int)), 0, i );
02614     }
02615   }
02616 #endif
02617 }
02618 
02619 void KateView::gotoBookmark (int n)
02620 {
02621   gotoMark (list.at(n));
02622 }
02623 
02624 int KateView::getHlCount ()
02625 {
02626   return HlManager::self()->highlights();
02627 }
02628 
02629 QString KateView::getHlName (int z)
02630 {
02631   return HlManager::self()->hlName(z);
02632 }
02633 
02634 QString KateView::getHlSection (int z)
02635 {
02636   return HlManager::self()->hlSection (z);
02637 }
02638 
02639 void KateView::slotIncFontSizes ()
02640 {
02641   QFont font = myDoc->getFont();
02642   font.setPointSize (font.pointSize()+2);
02643   myDoc->setFont (font);
02644 }
02645 
02646 void KateView::slotDecFontSizes ()
02647 {
02648   QFont font = myDoc->getFont();
02649   font.setPointSize (font.pointSize()-2);
02650   myDoc->setFont (font);
02651 }
02652 
02653 const char*bookmark_xpm[]={
02654 "12 16 4 1",
02655 "b c #808080",
02656 "a c #000080",
02657 "# c #0000ff",
02658 ". c None",
02659 "............",
02660 "............",
02661 "........###.",
02662 ".......#...a",
02663 "......#.##.a",
02664 ".....#.#..aa",
02665 "....#.#...a.",
02666 "...#.#.a.a..",
02667 "..#.#.a.a...",
02668 ".#.#.a.a....",
02669 "#.#.a.a.....",
02670 "#.#a.a...bbb",
02671 "#...a..bbb..",
02672 ".aaa.bbb....",
02673 "............",
02674 "............"};
02675 
02676 const char* breakpoint_xpm[]={
02677 "11 16 6 1",
02678 "c c #c6c6c6",
02679 ". c None",
02680 "# c #000000",
02681 "d c #840000",
02682 "a c #ffffff",
02683 "b c #ff0000",
02684 "...........",
02685 "...........",
02686 "...#####...",
02687 "..#aaaaa#..",
02688 ".#abbbbbb#.",
02689 "#abbbbbbbb#",
02690 "#abcacacbd#",
02691 "#abbbbbbbb#",
02692 "#abcacacbd#",
02693 "#abbbbbbbb#",
02694 ".#bbbbbbb#.",
02695 "..#bdbdb#..",
02696 "...#####...",
02697 "...........",
02698 "...........",
02699 "..........."};
02700 
02701 const char*breakpoint_bl_xpm[]={
02702 "11 16 7 1",
02703 "a c #c0c0ff",
02704 "# c #000000",
02705 "c c #0000c0",
02706 "e c #0000ff",
02707 "b c #dcdcdc",
02708 "d c #ffffff",
02709 ". c None",
02710 "...........",
02711 "...........",
02712 "...#####...",
02713 "..#ababa#..",
02714 ".#bcccccc#.",
02715 "#acccccccc#",
02716 "#bcadadace#",
02717 "#acccccccc#",
02718 "#bcadadace#",
02719 "#acccccccc#",
02720 ".#ccccccc#.",
02721 "..#cecec#..",
02722 "...#####...",
02723 "...........",
02724 "...........",
02725 "..........."};
02726 
02727 const char*breakpoint_gr_xpm[]={
02728 "11 16 6 1",
02729 "c c #c6c6c6",
02730 "d c #2c2c2c",
02731 "# c #000000",
02732 ". c None",
02733 "a c #ffffff",
02734 "b c #555555",
02735 "...........",
02736 "...........",
02737 "...#####...",
02738 "..#aaaaa#..",
02739 ".#abbbbbb#.",
02740 "#abbbbbbbb#",
02741 "#abcacacbd#",
02742 "#abbbbbbbb#",
02743 "#abcacacbd#",
02744 "#abbbbbbbb#",
02745 ".#bbbbbbb#.",
02746 "..#bdbdb#..",
02747 "...#####...",
02748 "...........",
02749 "...........",
02750 "..........."};
02751 
02752 const char*ddd_xpm[]={
02753 "11 16 4 1",
02754 "a c #00ff00",
02755 "b c #000000",
02756 ". c None",
02757 "# c #00c000",
02758 "...........",
02759 "...........",
02760 "...........",
02761 "#a.........",
02762 "#aaa.......",
02763 "#aaaaa.....",
02764 "#aaaaaaa...",
02765 "#aaaaaaaaa.",
02766 "#aaaaaaa#b.",
02767 "#aaaaa#b...",
02768 "#aaa#b.....",
02769 "#a#b.......",
02770 "#b.........",
02771 "...........",
02772 "...........",
02773 "..........."};
02774 
02775 
02776 
02777 KateIconBorder::KateIconBorder(KateView *view, KateViewInternal *internalView)
02778     : QWidget(view), myView(view), myInternalView(internalView)
02779 {
02780   lmbSetsBreakpoints = true;
02781 }
02782 
02783 KateIconBorder::~KateIconBorder()
02784 {
02785 }
02786 
02787 void KateIconBorder::paintLine(int i)
02788 {
02789   if (!myView->myIconBorder) return;
02790 
02791   QPainter p(this);
02792 
02793     int fontHeight = myView->doc()->fontHeight;
02794     int y = i*fontHeight - myInternalView->yPos;
02795     p.fillRect(0, y, myInternalView->iconBorderWidth-2, fontHeight, colorGroup().background());
02796     p.setPen(white);
02797     p.drawLine(myInternalView->iconBorderWidth-2, y, myInternalView->iconBorderWidth-2, y + fontHeight);
02798     p.setPen(QColor(colorGroup().background()).dark());
02799     p.drawLine(myInternalView->iconBorderWidth-1, y, myInternalView->iconBorderWidth-1, y + fontHeight);
02800 
02801     TextLine *line = myView->doc()->getTextLine(i);
02802     if (!line)
02803         return;
02804 
02805     if (line->mark()&KateDocument::Bookmark)
02806         p.drawPixmap(2, y, QPixmap(bookmark_xpm));      /*
02807     if (line && (line->breakpointId() != -1)) {
02808         if (!line->breakpointEnabled())
02809             p.drawPixmap(2, y, QPixmap(breakpoint_gr_xpm));
02810         else if (line->breakpointPending())
02811             p.drawPixmap(2, y, QPixmap(breakpoint_bl_xpm));
02812         else
02813             p.drawPixmap(2, y, QPixmap(breakpoint_xpm));
02814     }
02815     if (line->isExecutionPoint())
02816         p.drawPixmap(2, y, QPixmap(ddd_xpm));    */
02817 }
02818 
02819 
02820 void KateIconBorder::paintEvent(QPaintEvent* e)
02821 {
02822   if (!myView->myIconBorder) return;
02823 
02824     int lineStart = 0;
02825     int lineEnd = 0;
02826 
02827     QRect updateR = e->rect();
02828 
02829     KateDocument *doc = myView->doc();
02830     int h = doc->fontHeight;
02831     int yPos = myInternalView->yPos;
02832     if (h) {
02833     lineStart = (yPos + updateR.y()) / h;
02834         lineEnd = QMAX((yPos + updateR.y() + updateR.height()) / h, (int)doc->numLines());
02835     }
02836 
02837     for(int i = lineStart; i <= lineEnd; ++i)
02838         paintLine(i);
02839 }
02840 
02841 
02842 void KateIconBorder::mousePressEvent(QMouseEvent* e)
02843 {
02844     myInternalView->placeCursor( 0, e->y(), 0 );
02845 
02846     KateDocument *doc = myView->doc();
02847     int cursorOnLine = (e->y() + myInternalView->yPos) / doc->fontHeight;
02848     TextLine *line = doc->getTextLine(cursorOnLine);
02849 
02850     switch (e->button()) {
02851     case LeftButton:
02852         if (!line)
02853             break;
02854         else
02855         {
02856             if (line->mark()&KateDocument::Bookmark)
02857               line->delMark (KateDocument::Bookmark);
02858             else
02859               line->addMark (KateDocument::Bookmark);
02860 
02861             doc->tagLines(cursorOnLine, cursorOnLine);
02862             doc->updateViews();
02863         }
02864         break;
02865  /*   case RightButton:
02866         {
02867             if (!line)
02868                 break;
02869             KPopupMenu popup;
02870             popup.setCheckable(true);
02871             popup.insertTitle(i18n("Breakpoints/Bookmarks"));
02872             int idToggleBookmark =     popup.insertItem(i18n("Toggle bookmark"));
02873             popup.insertSeparator();
02874             int idToggleBreakpoint =   popup.insertItem(i18n("Toggle breakpoint"));
02875             int idEditBreakpoint   =   popup.insertItem(i18n("Edit breakpoint"));
02876             int idEnableBreakpoint =   popup.insertItem(i18n("Disable breakpoint"));
02877             popup.insertSeparator();
02878             popup.insertSeparator();
02879             int idLmbSetsBreakpoints = popup.insertItem(i18n("LMB sets breakpoints"));
02880             int idLmbSetsBookmarks   = popup.insertItem(i18n("LMB sets bookmarks"));
02881 
02882             popup.setItemChecked(idLmbSetsBreakpoints, lmbSetsBreakpoints);
02883             popup.setItemChecked(idLmbSetsBookmarks, !lmbSetsBreakpoints);
02884 
02885             if (line->breakpointId() == -1) {
02886                 popup.setItemEnabled(idEditBreakpoint, false);
02887                 popup.setItemEnabled(idEnableBreakpoint, false);
02888                 popup.changeItem(idEnableBreakpoint, i18n("Enable breakpoint"));
02889             }
02890             int res = popup.exec(mapToGlobal(e->pos()));
02891             if (res == idToggleBookmark) {
02892                 line->toggleBookmark();
02893                 doc->tagLines(cursorOnLine, cursorOnLine);
02894                 doc->updateViews();
02895             } else if (res == idToggleBreakpoint)
02896                 emit myView->toggledBreakpoint(cursorOnLine);
02897             else if (res == idEditBreakpoint)
02898                 emit myView->editedBreakpoint(cursorOnLine);
02899             else if (res == idEnableBreakpoint)
02900                 emit myView->toggledBreakpointEnabled(cursorOnLine+1);
02901             else if (res == idLmbSetsBreakpoints || res == idLmbSetsBookmarks)
02902                 lmbSetsBreakpoints = !lmbSetsBreakpoints;
02903             break;
02904         }
02905     case MidButton:
02906         line->toggleBookmark();
02907         doc->tagLines(cursorOnLine, cursorOnLine);
02908         doc->updateViews();
02909         break;      */
02910     default:
02911         break;
02912     }
02913 }
02914 
02915 
02916 

Generated on Sat Nov 5 16:17:13 2005 for OPIE by  doxygen 1.4.2