kateview.h

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
00003    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00004    Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
00005    Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License version 2 as published by the Free Software Foundation.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef kate_view_h
00023 #define kate_view_h
00024 
00025 #include "katedocument.h"
00026 #include "kateviewinternal.h"
00027 #include "kateconfig.h"
00028 
00029 #include "../interfaces/view.h"
00030 
00031 #include <ktexteditor/sessionconfiginterface.h>
00032 #include <ktexteditor/viewstatusmsginterface.h>
00033 #include <ktexteditor/texthintinterface.h>
00034 
00035 #include <qguardedptr.h>
00036 
00037 class KateDocument;
00038 class KateBookmarks;
00039 class KateSearch;
00040 class KateCmdLine;
00041 class KateCodeCompletion;
00042 class KateViewConfig;
00043 class KateViewSchemaAction;
00044 class KateRenderer;
00045 class KateSpell;
00046 
00047 class KToggleAction;
00048 class KAction;
00049 class KRecentFilesAction;
00050 class KSelectAction;
00051 
00052 class QGridLayout;
00053 
00054 //
00055 // Kate KTextEditor::View class ;)
00056 //
00057 class KateView : public Kate::View,
00058                  public KTextEditor::SessionConfigInterface,
00059                  public KTextEditor::ViewStatusMsgInterface,
00060                  public KTextEditor::TextHintInterface,
00061                  public KTextEditor::SelectionInterface,
00062                  public KTextEditor::SelectionInterfaceExt,
00063                  public KTextEditor::BlockSelectionInterface
00064 {
00065     Q_OBJECT
00066 
00067     friend class KateViewInternal;
00068     friend class KateIconBorder;
00069     friend class KateCodeCompletion;
00070 
00071   public:
00072     KateView( KateDocument* doc, QWidget* parent = 0L, const char* name = 0 );
00073     ~KateView ();
00074 
00075   //
00076   // KTextEditor::View
00077   //
00078   public:
00079     KTextEditor::Document* document() const       { return m_doc; }
00080 
00081   //
00082   // KTextEditor::ClipboardInterface
00083   //
00084   public slots:
00085     // TODO: Factor out of m_viewInternal
00086     void paste()         {  m_doc->paste( this ); m_viewInternal->repaint(); }
00087     void cut();
00088     void copy() const;
00089 
00093     void copyHTML();
00094 
00095   // helper to export text as html stuff
00096   private:
00097     QString selectionAsHtml ();
00098     QString textAsHtml ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise);
00099     void textAsHtmlStream ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise, QTextStream *ts);
00100 
00113     void lineAsHTML (KateTextLine::Ptr line, uint startCol, uint length, QTextStream *outputStream);
00114 
00115   public slots:
00116     void exportAsHTML ();
00117 
00118   //
00119   // KTextEditor::PopupMenuInterface
00120   //
00121   public:
00122     void installPopup( QPopupMenu* menu ) { m_rmbMenu = menu; }
00123     QPopupMenu* popup() const             { return m_rmbMenu; }
00124 
00125   //
00126   // KTextEditor::ViewCursorInterface
00127   //
00128   public slots:
00129     QPoint cursorCoordinates()
00130         { return m_viewInternal->cursorCoordinates();                 }
00131     void cursorPosition( uint* l, uint* c )
00132         { if( l ) *l = cursorLine(); if( c ) *c = cursorColumn();     }
00133     void cursorPositionReal( uint* l, uint* c )
00134         { if( l ) *l = cursorLine(); if( c ) *c = cursorColumnReal(); }
00135     bool setCursorPosition( uint line, uint col )
00136         { return setCursorPositionInternal( line, col, tabWidth(), true );  }
00137     bool setCursorPositionReal( uint line, uint col)
00138         { return setCursorPositionInternal( line, col, 1, true );           }
00139     uint cursorLine()
00140         { return m_viewInternal->getCursor().line();                    }
00141     uint cursorColumn();
00142     uint cursorColumnReal()
00143         { return m_viewInternal->getCursor().col();                     }
00144 
00145   signals:
00146     void cursorPositionChanged();
00147 
00148   //
00149   // KTextEditor::CodeCompletionInterface
00150   //
00151   public slots:
00152     void showArgHint( QStringList arg1, const QString& arg2, const QString& arg3 );
00153     void showCompletionBox( QValueList<KTextEditor::CompletionEntry> arg1, int offset = 0, bool cs = true );
00154 
00155   signals:
00156     void completionAborted();
00157     void completionDone();
00158     void argHintHidden();
00159     void completionDone(KTextEditor::CompletionEntry);
00160     void filterInsertString(KTextEditor::CompletionEntry*,QString *);
00161     void aboutToShowCompletionBox();
00162 
00163   //
00164   // KTextEditor::TextHintInterface
00165   //
00166   public:
00167     void enableTextHints(int timeout);
00168     void disableTextHints();
00169 
00170   signals:
00171     void needTextHint(int line, int col, QString &text);
00172 
00173   //
00174   // KTextEditor::DynWordWrapInterface
00175   //
00176   public:
00177     void setDynWordWrap( bool b );
00178     bool dynWordWrap() const      { return m_hasWrap; }
00179 
00180   //
00181   // KTextEditor::SelectionInterface stuff
00182   //
00183   public slots:
00184     bool setSelection ( const KateTextCursor & start,
00185       const KateTextCursor & end );
00186     bool setSelection ( uint startLine, uint startCol,
00187       uint endLine, uint endCol );
00188     bool clearSelection ();
00189     bool clearSelection (bool redraw, bool finishedChangingSelection = true);
00190 
00191     bool hasSelection () const;
00192     QString selection () const ;
00193 
00194     bool removeSelectedText ();
00195 
00196     bool selectAll();
00197 
00198     //
00199     // KTextEditor::SelectionInterfaceExt
00200     //
00201     int selStartLine() { return selectStart.line(); };
00202     int selStartCol()  { return selectStart.col(); };
00203     int selEndLine()   { return selectEnd.line(); };
00204     int selEndCol()    { return selectEnd.col(); };
00205 
00206   signals:
00207     void selectionChanged ();
00208 
00209   //
00210   // internal helper stuff, for katerenderer and so on
00211   //
00212   public:
00217     inline const KateSuperCursor &selStart () const { return selectStart; }
00218 
00223     inline const KateSuperCursor &selEnd () const { return selectEnd; }
00224 
00225     // should cursor be wrapped ? take config + blockselection state in account
00226     bool wrapCursor ();
00227 
00228     // some internal functions to get selection state of a line/col
00229     bool lineColSelected (int line, int col);
00230     bool lineSelected (int line);
00231     bool lineEndSelected (int line, int endCol);
00232     bool lineHasSelected (int line);
00233     bool lineIsSelection (int line);
00234 
00235     void tagSelection (const KateTextCursor &oldSelectStart, const KateTextCursor &oldSelectEnd);
00236 
00237     void selectWord(   const KateTextCursor& cursor );
00238     void selectLine(   const KateTextCursor& cursor );
00239     void selectLength( const KateTextCursor& cursor, int length );
00240 
00241   //
00242   // KTextEditor::BlockSelectionInterface stuff
00243   //
00244   public slots:
00245     bool blockSelectionMode ();
00246     bool setBlockSelectionMode (bool on);
00247     bool toggleBlockSelectionMode ();
00248 
00249 
00250   //BEGIN EDIT STUFF
00251   public:
00252     void editStart ();
00253     void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00254 
00255     void editSetCursor (const KateTextCursor &cursor);
00256   //END
00257 
00258   //BEGIN TAG & CLEAR
00259   public:
00260     bool tagLine (const KateTextCursor& virtualCursor);
00261 
00262     bool tagLines (int start, int end, bool realLines = false );
00263     bool tagLines (KateTextCursor start, KateTextCursor end, bool realCursors = false);
00264 
00265     void tagAll ();
00266 
00267     void clear ();
00268 
00269     void repaintText (bool paintOnlyDirty = false);
00270 
00271     void updateView (bool changed = false);
00272   //END
00273 
00274   //
00275   // Kate::View
00276   //
00277   public:
00278     bool isOverwriteMode() const;
00279     void setOverwriteMode( bool b );
00280 
00281     QString currentTextLine()
00282         { return getDoc()->textLine( cursorLine() ); }
00283     QString currentWord()
00284         { return m_doc->getWord( m_viewInternal->getCursor() ); }
00285     void insertText( const QString& text )
00286         { getDoc()->insertText( cursorLine(), cursorColumnReal(), text ); }
00287     bool canDiscard();
00288     int tabWidth()                { return m_doc->config()->tabWidth(); }
00289     void setTabWidth( int w )     { m_doc->config()->setTabWidth(w);  }
00290     void setEncoding( QString e ) { m_doc->setEncoding(e);       }
00291     bool isLastView()             { return m_doc->isLastView(1); }
00292 
00293   public slots:
00294     void flush();
00295     saveResult save();
00296     saveResult saveAs();
00297 
00298     void indent()             { m_doc->indent( this, cursorLine(), 1 );  }
00299     void unIndent()           { m_doc->indent( this, cursorLine(), -1 ); }
00300     void cleanIndent()        { m_doc->indent( this, cursorLine(), 0 );  }
00301     void align()              { m_doc->align( this, cursorLine() ); }
00302     void comment()            { m_doc->comment( this, cursorLine(), cursorColumnReal(), 1 );  }
00303     void uncomment()          { m_doc->comment( this, cursorLine(), cursorColumnReal(),-1 ); }
00304     void killLine()           { m_doc->removeLine( cursorLine() ); }
00305 
00309     void uppercase() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Uppercase ); }
00313     void lowercase() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Lowercase ); }
00318     void capitalize() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Capitalize ); }
00322     void joinLines();
00323 
00324 
00325     void keyReturn()          { m_viewInternal->doReturn();          }
00326     void backspace()          { m_viewInternal->doBackspace();       }
00327     void deleteWordLeft()     { m_viewInternal->doDeleteWordLeft();  }
00328     void keyDelete()          { m_viewInternal->doDelete();          }
00329     void deleteWordRight()    { m_viewInternal->doDeleteWordRight(); }
00330     void transpose()          { m_viewInternal->doTranspose();       }
00331     void cursorLeft()         { m_viewInternal->cursorLeft();        }
00332     void shiftCursorLeft()    { m_viewInternal->cursorLeft(true);    }
00333     void cursorRight()        { m_viewInternal->cursorRight();       }
00334     void shiftCursorRight()   { m_viewInternal->cursorRight(true);   }
00335     void wordLeft()           { m_viewInternal->wordLeft();          }
00336     void shiftWordLeft()      { m_viewInternal->wordLeft(true);      }
00337     void wordRight()          { m_viewInternal->wordRight();         }
00338     void shiftWordRight()     { m_viewInternal->wordRight(true);     }
00339     void home()               { m_viewInternal->home();              }
00340     void shiftHome()          { m_viewInternal->home(true);          }
00341     void end()                { m_viewInternal->end();               }
00342     void shiftEnd()           { m_viewInternal->end(true);           }
00343     void up()                 { m_viewInternal->cursorUp();          }
00344     void shiftUp()            { m_viewInternal->cursorUp(true);      }
00345     void down()               { m_viewInternal->cursorDown();        }
00346     void shiftDown()          { m_viewInternal->cursorDown(true);    }
00347     void scrollUp()           { m_viewInternal->scrollUp();          }
00348     void scrollDown()         { m_viewInternal->scrollDown();        }
00349     void topOfView()          { m_viewInternal->topOfView();         }
00350     void shiftTopOfView()     { m_viewInternal->topOfView(true);     }
00351     void bottomOfView()       { m_viewInternal->bottomOfView();      }
00352     void shiftBottomOfView()  { m_viewInternal->bottomOfView(true);  }
00353     void pageUp()             { m_viewInternal->pageUp();            }
00354     void shiftPageUp()        { m_viewInternal->pageUp(true);        }
00355     void pageDown()           { m_viewInternal->pageDown();          }
00356     void shiftPageDown()      { m_viewInternal->pageDown(true);      }
00357     void top()                { m_viewInternal->top_home();          }
00358     void shiftTop()           { m_viewInternal->top_home(true);      }
00359     void bottom()             { m_viewInternal->bottom_end();        }
00360     void shiftBottom()        { m_viewInternal->bottom_end(true);    }
00361     void toMatchingBracket()  { m_viewInternal->cursorToMatchingBracket();}
00362     void shiftToMatchingBracket()  { m_viewInternal->cursorToMatchingBracket(true);}
00363 
00364     void gotoLine();
00365     void gotoLineNumber( int linenumber );
00366 
00367   // config file / session management functions
00368   public:
00369     void readSessionConfig(KConfig *);
00370     void writeSessionConfig(KConfig *);
00371 
00372   public slots:
00373     int getEol();
00374     void setEol( int eol );
00375     void find();
00376     void find( const QString&, long, bool add=true ); 
00377     void replace();
00378     void replace( const QString&, const QString &, long ); 
00379     void findAgain( bool back );
00380     void findAgain()              { findAgain( false );          }
00381     void findPrev()               { findAgain( true );           }
00382 
00383     void setFoldingMarkersOn( bool enable ); // Not in Kate::View, but should be
00384     void setIconBorder( bool enable );
00385     void setLineNumbersOn( bool enable );
00386     void setScrollBarMarks( bool enable );
00387     void showCmdLine ( bool enable );
00388     void toggleFoldingMarkers();
00389     void toggleIconBorder();
00390     void toggleLineNumbersOn();
00391     void toggleScrollBarMarks();
00392     void toggleDynWordWrap ();
00393     void toggleCmdLine ();
00394     void setDynWrapIndicators(int mode);
00395     
00396     void applyWordWrap ();
00397 
00398   public:
00399     KateRenderer *renderer ();
00400 
00401     bool iconBorder();
00402     bool lineNumbersOn();
00403     bool scrollBarMarks();
00404     int dynWrapIndicators();
00405     bool foldingMarkersOn();
00406     Kate::Document* getDoc()    { return m_doc; }
00407 
00408     void setActive( bool b )    { m_active = b; }
00409     bool isActive()             { return m_active; }
00410 
00411   public slots:
00412     void gotoMark( KTextEditor::Mark* mark ) { setCursorPositionInternal ( mark->line, 0, 1 ); }
00413     void slotSelectionChanged ();
00414 
00415   signals:
00416     void gotFocus( Kate::View* );
00417     void lostFocus( Kate::View* );
00418     void newStatus(); // Not in Kate::View, but should be (Kate app connects to it)
00419 
00420   //
00421   // Extras
00422   //
00423   public:
00424     // Is it really necessary to have 3 methods for this?! :)
00425     KateDocument*  doc() const       { return m_doc; }
00426 
00427     KActionCollection* editActionCollection() const { return m_editActions; }
00428 
00429   public slots:
00430     void slotNewUndo();
00431     void slotUpdate();
00432     void toggleInsert();
00433     void reloadFile();
00434     void toggleWWMarker();
00435     void toggleWriteLock();
00436     void switchToCmdLine ();
00437     void slotReadWriteChanged ();
00438 
00439   signals:
00440     void dropEventPass(QDropEvent*);
00441     void viewStatusMsg (const QString &msg);
00442 
00443   public:
00444     bool setCursorPositionInternal( uint line, uint col, uint tabwidth = 1, bool calledExternally = false );
00445 
00446   protected:
00447     void contextMenuEvent( QContextMenuEvent* );
00448     bool checkOverwrite( KURL );
00449 
00450   public slots:
00451     void slotSelectionTypeChanged();
00452 
00453   private slots:
00454     void slotGotFocus();
00455     void slotLostFocus();
00456     void slotDropEventPass( QDropEvent* ev );
00457     void slotStatusMsg();
00458     void slotSaveCanceled( const QString& error );
00459     void slotExpandToplevel();
00460     void slotCollapseLocal();
00461     void slotExpandLocal();
00462 
00463   private:
00464     void setupConnections();
00465     void setupActions();
00466     void setupEditActions();
00467     void setupCodeFolding();
00468     void setupCodeCompletion();
00469 
00470     KActionCollection*     m_editActions;
00471     KAction*               m_editUndo;
00472     KAction*               m_editRedo;
00473     KRecentFilesAction*    m_fileRecent;
00474     KToggleAction*         m_toggleFoldingMarkers;
00475     KToggleAction*         m_toggleIconBar;
00476     KToggleAction*         m_toggleLineNumbers;
00477     KToggleAction*         m_toggleScrollBarMarks;
00478     KToggleAction*         m_toggleDynWrap;
00479     KSelectAction*         m_setDynWrapIndicators;
00480     KToggleAction*         m_toggleWWMarker;
00481     KAction*               m_switchCmdLine;
00482 
00483     KSelectAction*         m_setEndOfLine;
00484 
00485     KAction *m_cut;
00486     KAction *m_copy;
00487     KAction *m_copyHTML;
00488     KAction *m_paste;
00489     KAction *m_selectAll;
00490     KAction *m_deSelect;
00491 
00492     KToggleAction *m_toggleBlockSelection;
00493     KToggleAction *m_toggleInsert;
00494     KToggleAction *m_toggleWriteLock;
00495 
00496     KateDocument*          m_doc;
00497     KateViewInternal*      m_viewInternal;
00498     KateRenderer*          m_renderer;
00499     KateSearch*            m_search;
00500     KateSpell             *m_spell;
00501     KateBookmarks*         m_bookmarks;
00502     QGuardedPtr<QPopupMenu>  m_rmbMenu;
00503     KateCodeCompletion*    m_codeCompletion;
00504 
00505     KateCmdLine *m_cmdLine;
00506     bool m_cmdLineOn;
00507 
00508     QGridLayout *m_grid;
00509 
00510     bool       m_active;
00511     bool       m_hasWrap;
00512 
00513   private slots:
00514     void slotNeedTextHint(int line, int col, QString &text);
00515     void slotHlChanged();
00516 
00520   public:
00521     inline KateViewConfig *config () { return m_config; };
00522 
00523     void updateConfig ();
00524 
00525     void updateDocumentConfig();
00526 
00527     void updateRendererConfig();
00528 
00529   private slots:
00530     void updateFoldingConfig ();
00531 
00532   private:
00533     KateViewConfig *m_config;
00534     bool m_startingUp;
00535     bool m_updatingDocumentConfig;
00536 
00537   private:
00538     // stores the current selection
00539     KateSuperCursor selectStart;
00540     KateSuperCursor selectEnd;
00541 
00542     // do we select normal or blockwise ?
00543     bool blockSelect;
00544 
00548   public:
00549     void setIMSelectionValue( uint imStartLine, uint imStart, uint imEnd,
00550                               uint imSelStart, uint imSelEnd, bool m_imComposeEvent );
00551     void getIMSelectionValue( uint *imStartLine, uint *imStart, uint *imEnd,
00552                               uint *imSelStart, uint *imSelEnd );
00553     bool isIMSelection( int _line, int _column );
00554     bool isIMEdit( int _line, int _column );
00555     bool imComposeEvent () const { return m_imComposeEvent; }
00556 
00557   private:
00558     uint m_imStartLine;
00559     uint m_imStart;
00560     uint m_imEnd;
00561     uint m_imSelStart;
00562     uint m_imSelEnd;
00563     bool m_imComposeEvent;
00564 };
00565 
00566 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys