# khtml Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kjs_debugwin.h

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (C) 2000-2001 Harri Porten (porten@kde.org)
    00004  *  Copyright (C) 2001,2003 Peter Kelly (pmk@post.com)
    00005  *
    00006  *  This library is free software; you can redistribute it and/or
    00007  *  modify it under the terms of the GNU Library General Public
    00008  *  License as published by the Free Software Foundation; either
    00009  *  version 2 of the License, or (at your option) any later version.
    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
    00017  *  License along with this library; if not, write to the Free Software
    00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00019  */
    00020
    00021 #ifndef _KJS_DEBUGGER_H_
    00022 #define _KJS_DEBUGGER_H_
    00023
    00024 #include <qglobal.h>
    00025
    00026 #define KJS_DEBUGGER
    00027
    00028 #ifdef KJS_DEBUGGER
    00029
    00030 #include <qwidget.h>
    00031 #include <qmultilineedit.h>
    00032 #include <qpixmap.h>
    00033 #include <qptrlist.h>
    00034 #include <qptrstack.h>
    00035 #include <qcheckbox.h>
    00036 #include <kdialogbase.h>
    00037 #include <kmainwindow.h>
    00038 #include <qscrollview.h>
    00039
    00040 #include <kjs/debugger.h>
    00041
    00042 #include "dom/dom_misc.h"
    00043
    00044 class QListBox;
    00045 class QComboBox;
    00046 class KActionCollection;
    00047 class KAction;
    00048
    00049 namespace KJS {
    00050   class FunctionImp;
    00051   class List;
    00052   class Interpreter;
    00053   class KJSDebugWin;
    00054
    00055   class SourceFile : public DOM::DomShared
    00056   {
    00057    public:
    00058     SourceFile(QString u, QString c, Interpreter *interp)
    00059     : url(u), code(c), interpreter(interp) {}
    00060     QString getCode();
    00061     QString url;
    00062     QString code;
    00063     Interpreter *interpreter;
    00064   };
    00065
    00081   class SourceFragment
    00082   {
    00083   public:
    00084     SourceFragment(int sid, int bl, int el, SourceFile *sf);
    00085     ~SourceFragment();
    00086
    00087     int sourceId;
    00088     int baseLine;
    00089     int errorLine;
    00090     SourceFile *sourceFile;
    00091   };
    00092
    00093   class KJSErrorDialog : public KDialogBase {
    00094     Q_OBJECT
    00095   public:
    00096     KJSErrorDialog(QWidget *parent, const QString& errorMessage, bool showDebug);
    00097     virtual ~KJSErrorDialog();
    00098
    00099     bool debugSelected() const { return m_debugSelected; }
    00100     bool dontShowAgain() const { return m_dontShowAgainCb->isChecked(); }
    00101
    00102   protected slots:
    00103     virtual void slotUser1();
    00104
    00105   private:
    00106     QCheckBox *m_dontShowAgainCb;
    00107     bool m_debugSelected;
    00108   };
    00109
    00110   class EvalMultiLineEdit : public QMultiLineEdit {
    00111     Q_OBJECT
    00112   public:
    00113       EvalMultiLineEdit(QWidget *parent);
    00114       const QString & code() const { return m_code; }
    00115   protected:
    00116       void keyPressEvent(QKeyEvent * e);
    00117   private:
    00118       QString m_code;
    00119   };
    00120
    00121   class SourceDisplay : public QScrollView {
    00122     Q_OBJECT
    00123   public:
    00124     SourceDisplay(KJSDebugWin *debugWin, QWidget *parent, const char *name = 0);
    00125     ~SourceDisplay();
    00126
    00127     void setSource(SourceFile *sourceFile);
    00128     void setCurrentLine(int lineno, bool doCenter = true);
    00129
    00130   signals:
    00131     void lineDoubleClicked(int lineno);
    00132
    00133   protected:
    00134     virtual void contentsMousePressEvent(QMouseEvent *e);
    00135     virtual void showEvent(QShowEvent *);
    00136     virtual void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph);
    00137
    00138     QString m_source;
    00139     int m_currentLine;
    00140     SourceFile *m_sourceFile;
    00141     QStringList m_lines;
    00142
    00143     KJSDebugWin *m_debugWin;
    00144     QFont m_font;
    00145     QPixmap m_breakpointIcon;
    00146   };
    00147
    00157   class KJSDebugWin : public KMainWindow, public Debugger, public KInstance
    00158   {
    00159     Q_OBJECT
    00160     friend class SourceDisplay;
    00161   public:
    00162     KJSDebugWin(QWidget *parent=0, const char *name=0);
    00163     virtual ~KJSDebugWin();
    00164
    00165     static KJSDebugWin *createInstance();
    00166     static void destroyInstance();
    00167     static KJSDebugWin *debugWindow() { return kjs_html_debugger; }
    00168
    00169     enum Mode { Disabled = 0, // No break on any statements
    00170         Next     = 1, // Will break on next statement in current context
    00171         Step     = 2, // Will break on next statement in current or deeper context
    00172         Continue = 3, // Will continue until next breakpoint
    00173         Stop     = 4  // The script will stop execution completely,
    00174                   // as soon as possible
    00175     };
    00176
    00177     void setSourceLine(int sourceId, int lineno);
    00178     void setNextSourceInfo(QString url, int baseLine);
    00179     void sourceChanged(Interpreter *interpreter, QString url);
    00180     bool inSession() const { return !m_execStates.isEmpty(); }
    00181     void setMode(Mode m) { m_mode = m; }
    00182     void clearInterpreter(Interpreter *interpreter);
    00183     ExecState *getExecState() const { return m_execStates.top(); }
    00184
    00185     // functions overridden from KJS:Debugger
    00186     bool sourceParsed(ExecState *exec, int sourceId,
    00187               const UString &source, int errorLine);
    00188     bool sourceUnused(ExecState * exec, int sourceId);
    00189     bool exception(ExecState *exec, const Value &value, bool inTryCatch);
    00190     bool atStatement(ExecState *exec);
    00191     bool enterContext(ExecState *exec);
    00192     bool exitContext(ExecState *exec, const Completion &completion);
    00193
    00194   public slots:
    00195     void slotNext();
    00196     void slotStep();
    00197     void slotContinue();
    00198     void slotStop();
    00199     void slotBreakNext();
    00200     void slotToggleBreakpoint(int lineno);
    00201     void slotShowFrame(int frameno);
    00202     void slotSourceSelected(int sourceSelIndex);
    00203     void slotEval();
    00204
    00205   protected:
    00206
    00207     void closeEvent(QCloseEvent *e);
    00208     bool eventFilter(QObject *obj, QEvent *evt);
    00209     void disableOtherWindows();
    00210     void enableOtherWindows();
    00211
    00212   private:
    00213
    00214     SourceFile *getSourceFile(Interpreter *interpreter, QString url);
    00215     void setSourceFile(Interpreter *interpreter, QString url, SourceFile *sourceFile);
    00216     void removeSourceFile(Interpreter *interpreter, QString url);
    00217
    00218     void checkBreak(ExecState *exec);
    00219     void enterSession(ExecState *exec);
    00220     void leaveSession();
    00221     void displaySourceFile(SourceFile *sourceFile, bool forceRefresh);
    00222     void updateContextList();
    00223
    00224     QString contextStr(const Context &ctx);
    00225
    00226     struct Breakpoint {
    00227       int sourceId;
    00228       int lineno;
    00229     };
    00230     Breakpoint *m_breakpoints;
    00231     int m_breakpointCount;
    00232     bool setBreakpoint(int sourceId, int lineno);
    00233     bool deleteBreakpoint(int sourceId, int lineno);
    00234     bool haveBreakpoint(SourceFile *sourceFile, int line0, int line1);
    00235     bool haveBreakpoint(int sourceId, int line0, int line1) const {
    00236       for (int i = 0; i < m_breakpointCount; i++) {
    00237     if (m_breakpoints[i].sourceId == sourceId &&
    00238         m_breakpoints[i].lineno >= line0 &&
    00239         m_breakpoints[i].lineno <= line1)
    00240       return true;
    00241       }
    00242       return false;
    00243     }
    00244
    00245     SourceFile *m_curSourceFile;
    00246     Mode m_mode;
    00247     QString m_nextSourceUrl;
    00248     int m_nextSourceBaseLine;
    00249     QPtrStack<ExecState> m_execStates;
    00250     ExecState **m_execs;
    00251     int m_execsCount;
    00252     int m_execsAlloc;
    00253     int m_steppingDepth;
    00254
    00255     QMap<QString,SourceFile*> m_sourceFiles; /* maps url->SourceFile */
    00256     QMap<int,SourceFragment*> m_sourceFragments; /* maps SourceId->SourceFragment */
    00257     QPtrList<SourceFile> m_sourceSelFiles; /* maps combobox index->SourceFile */
    00258
    00259     KActionCollection *m_actionCollection;
    00260     QPixmap m_stopIcon;
    00261     QPixmap m_emptyIcon;
    00262     SourceDisplay *m_sourceDisplay;
    00263     QListBox *m_contextList;
    00264
    00265     KAction *m_stepAction;
    00266     KAction *m_nextAction;
    00267     KAction *m_continueAction;
    00268     KAction *m_stopAction;
    00269     KAction *m_breakAction;
    00270
    00271     QComboBox *m_sourceSel;
    00272     EvalMultiLineEdit *m_evalEdit;
    00273     int m_evalDepth;
    00274
    00275     static KJSDebugWin *kjs_html_debugger;
    00276   };
    00277
    00278 } // namespace
    00279
    00280 #endif // KJS_DEBUGGER
    00281
    00282 #endif // _KJS_DEBUGGER_H_

This file is part of the documentation for khtml Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:33:17 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003