diff --git a/examples/kjsconsole/console.h b/examples/kjsconsole/console.h index cc242e8..faf8665 100644 --- a/examples/kjsconsole/console.h +++ b/examples/kjsconsole/console.h @@ -1,55 +1,55 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CONSOLE_H #define CONSOLE_H #include #include #include "kjsembed.h" class KJSObjectModel; class Console : public QMainWindow { Q_OBJECT public: - Console(QWidget *parent = 0); + Console(QWidget *parent = nullptr); ~Console(); public Q_SLOTS: void on_mExecute_clicked(); void on_actionOpenScript_activated(); void on_actionCloseScript_activated(); void on_actionQuit_activated(); void on_actionRun_activated(); void on_actionRunTo_activated(); void on_actionStep_activated(); void on_actionStop_activated(); private: void updateModel(const QModelIndex &parent, KJS::Object &obj); KJSEmbed::Engine mKernel; KJSObjectModel *m_model; QModelIndex m_root; }; #endif diff --git a/examples/kjsconsole/kjs_object_model.cpp b/examples/kjsconsole/kjs_object_model.cpp index eb1f6d5..ab809de 100644 --- a/examples/kjsconsole/kjs_object_model.cpp +++ b/examples/kjsconsole/kjs_object_model.cpp @@ -1,181 +1,181 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kjs_object_model.h" #include #include #include #include #include struct Node { QByteArray name; KJS::JSObject *instance; Node *parent; }; KJSObjectModel::KJSObjectModel(KJS::Interpreter *js, QObject *parent): QAbstractItemModel(parent), m_js(js) { } void KJSObjectModel::updateModel(KJS::JSObject *root) { m_root = root; reset(); } KJSObjectModel::~KJSObjectModel() { } Qt::ItemFlags KJSObjectModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return Qt::ItemIsEnabled; } return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } int KJSObjectModel::rowCount(const QModelIndex &parent) const { KJS::ExecState *exec = m_js->globalExec(); KJS::PropertyNameArray props; if (!parent.isValid()) { m_root->getPropertyNames(exec, props); } else { Node *item = static_cast(parent.internalPointer()); item->instance->getPropertyNames(exec, props); } return props.size(); } int KJSObjectModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); return 1; } QVariant KJSObjectModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (section == 0) { return "Object Name"; } else { return "Value"; } } return QVariant(); } QModelIndex KJSObjectModel::index(int row, int column, const QModelIndex &parent) const { - KJS::JSObject *parentInstance = 0; - Node *childItem = 0; + KJS::JSObject *parentInstance = nullptr; + Node *childItem = nullptr; KJS::ExecState *exec = m_js->globalExec(); if (!parent.isValid()) { if (m_root) { parentInstance = m_root; } else { return QModelIndex(); } } else { parentInstance = static_cast(parent.internalPointer())->instance; } int idx = 0; KJS::PropertyNameArray props; parentInstance->getPropertyNames(exec, props); for (KJS::PropertyNameArrayIterator ref = props.begin(); ref != props.end(); ref++) { if (idx == row) { childItem = new Node; childItem->name = ref->ascii(); //### M.O.: this is wrong, can be unicode. childItem->instance = parentInstance->get(exec, childItem->name.constData())->toObject(exec); childItem->parent = static_cast(parent.internalPointer()); break; } ++idx; } if (childItem) { return createIndex(row, column, childItem); } return QModelIndex(); } QModelIndex KJSObjectModel::parent(const QModelIndex &index) const { if (!index.isValid()) { Node *node = new Node; node->instance = m_root; node->name = "Objects"; - node->parent = 0; + node->parent = nullptr; return createIndex(0, index.column(), node); } Node *parentItem = static_cast(index.internalPointer())->parent; if (parentItem) { Node *node = new Node; node->instance = parentItem->instance; node->name = parentItem->name; node->parent = parentItem->parent; return createIndex(0, index.column(), node); } else { return QModelIndex(); } } QVariant KJSObjectModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } Node *item = static_cast(index.internalPointer()); KJS::JSObject *instance = item->instance; if (role == Qt::DecorationRole) { if (instance->implementsConstruct()) { return QPixmap(":/images/class.png"); } else if (instance->implementsCall()) { return QPixmap(":/images/method.png"); } else { return QPixmap(":/images/property.png"); } } if (role == Qt::TextColorRole) { if (instance->implementsConstruct()) { return QColor("blue"); } else if (instance->implementsCall()) { return QColor("green"); } else { return QColor("black"); } } if (role == Qt::DisplayRole) { return item->name; } return QVariant(); } diff --git a/examples/kjsconsole/kjs_object_model.h b/examples/kjsconsole/kjs_object_model.h index fd8fd40..003351a 100644 --- a/examples/kjsconsole/kjs_object_model.h +++ b/examples/kjsconsole/kjs_object_model.h @@ -1,57 +1,57 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KJS_OBJECT_MODEL #define KJS_OBJECT_MODEL #include #include namespace KJS { class Interpreter; class JSObject; } struct Node; class KJSObjectModel : public QAbstractItemModel { Q_OBJECT public: - explicit KJSObjectModel(KJS::Interpreter *js, QObject *parent = 0); + explicit KJSObjectModel(KJS::Interpreter *js, QObject *parent = nullptr); ~KJSObjectModel(); QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; void updateModel(KJS::JSObject *m_root); private: KJS::Interpreter *m_js; KJS::JSObject *m_root; }; #endif diff --git a/examples/kjsconsole/numberedtextview.cpp b/examples/kjsconsole/numberedtextview.cpp index a810390..e67e68d 100644 --- a/examples/kjsconsole/numberedtextview.cpp +++ b/examples/kjsconsole/numberedtextview.cpp @@ -1,284 +1,284 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "numberedtextview.h" #include #include #include #include #include #include #include #include #include NumberBar::NumberBar(QWidget *parent) - : QWidget(parent), edit(0), m_stopLine(-1), m_currentLine(-1), m_bugLine(-1) + : QWidget(parent), edit(nullptr), m_stopLine(-1), m_currentLine(-1), m_bugLine(-1) { stopMarker = QPixmap(":/images/no.png"); currentMarker = QPixmap(":/images/next.png"); bugMarker = QPixmap(":/images/bug.png"); setFixedWidth(fontMetrics().width(QStringLiteral("0000")) + bugMarker.width() + stopMarker.width() + currentMarker.width()); } NumberBar::~NumberBar() { } void NumberBar::setCurrentLine(int lineno) { m_currentLine = lineno; } void NumberBar::setStopLine(int lineno) { m_stopLine = lineno; } void NumberBar::setBugLine(int lineno) { m_bugLine = lineno; } int NumberBar::currentLine() const { return m_currentLine; } int NumberBar::stopLine() const { return m_stopLine; } int NumberBar::bugLine() const { return m_bugLine; } void NumberBar::setTextEdit(QTextEdit *edit) { this->edit = edit; connect(edit->document()->documentLayout(), SIGNAL(update(QRectF)), this, SLOT(update())); connect(edit->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(update())); } void NumberBar::paintEvent(QPaintEvent *) { QAbstractTextDocumentLayout *layout = edit->document()->documentLayout(); int contentsY = edit->verticalScrollBar()->value(); qreal pageBottom = contentsY + edit->viewport()->height(); const QFontMetrics fm = fontMetrics(); const int ascent = fontMetrics().ascent() + 1; // height = ascent + descent + 1 int lineCount = 1; QPainter p(this); bugRect = QRect(); stopRect = QRect(); currentRect = QRect(); for (QTextBlock block = edit->document()->begin(); block.isValid(); block = block.next(), ++lineCount) { const QRectF boundingRect = layout->blockBoundingRect(block); QPointF position = boundingRect.topLeft(); if (position.y() + boundingRect.height() < contentsY) { continue; } if (position.y() > pageBottom) { break; } const QString txt = QString::number(lineCount); p.drawText(width() - fm.width(txt), qRound(position.y()) - contentsY + ascent, txt); // Bug marker if (m_bugLine == lineCount) { p.drawPixmap(1, qRound(position.y()) - contentsY, bugMarker); bugRect = QRect(1, qRound(position.y()) - contentsY, bugMarker.width(), bugMarker.height()); } // Stop marker if (m_stopLine == lineCount) { p.drawPixmap(1, qRound(position.y()) - contentsY, stopMarker); stopRect = QRect(1, qRound(position.y()) - contentsY, stopMarker.width(), stopMarker.height()); } // Current line marker if (m_currentLine == lineCount) { p.drawPixmap(1, qRound(position.y()) - contentsY, currentMarker); currentRect = QRect(1, qRound(position.y()) - contentsY, currentMarker.width(), currentMarker.height()); } } } bool NumberBar::event(QEvent *event) { if (event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = static_cast(event); if (stopRect.contains(helpEvent->pos())) { QToolTip::showText(helpEvent->globalPos(), "Stop Here"); } else if (currentRect.contains(helpEvent->pos())) { QToolTip::showText(helpEvent->globalPos(), "Current Line"); } else if (bugRect.contains(helpEvent->pos())) { QToolTip::showText(helpEvent->globalPos(), "Error Line"); } } return QWidget::event(event); } NumberedTextView::NumberedTextView(QWidget *parent) : QFrame(parent) { setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); setLineWidth(2); // Setup the main view view = new QTextEdit(this); view->setFontFamily("Monospace"); view->setLineWrapMode(QTextEdit::NoWrap); view->setFrameStyle(QFrame::NoFrame); view->installEventFilter(this); connect(view->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(textChanged(int,int,int))); // Setup the line number pane numbers = new NumberBar(this); numbers->setTextEdit(view); // Testing... numbers->setStopLine(3); numbers->setBugLine(1); setCurrentLine(5); box = new QHBoxLayout(this); box->setSpacing(0); box->setMargin(0); box->addWidget(numbers); box->addWidget(view); } NumberedTextView::~NumberedTextView() { } void NumberedTextView::setCurrentLine(int lineno) { numbers->setCurrentLine(lineno); textChanged(0, 0, 1); } void NumberedTextView::setStopLine(int lineno) { numbers->setStopLine(lineno); } void NumberedTextView::setBugLine(int lineno) { numbers->setBugLine(lineno); } int NumberedTextView::currentLine() const { return numbers->currentLine(); } int NumberedTextView::stopLine() const { return numbers->stopLine(); } int NumberedTextView::bugLine() const { return numbers->bugLine(); } QString NumberedTextView::text() const { return view->toPlainText(); } void NumberedTextView::setText(const QString &text) { view->setPlainText(text); } void NumberedTextView::textChanged(int pos, int removed, int added) { Q_UNUSED(pos); if (removed == 0 && added == 0) { return; } QTextBlock block = highlight.block(); QTextBlockFormat fmt = block.blockFormat(); QColor bg = view->palette().base().color(); fmt.setBackground(bg); highlight.setBlockFormat(fmt); int lineCount = 1; for (QTextBlock block = view->document()->begin(); block.isValid(); block = block.next(), ++lineCount) { if (lineCount == numbers->currentLine()) { fmt = block.blockFormat(); QColor bg = view->palette().color(QPalette::Highlight).light(175); fmt.setBackground(bg); highlight = QTextCursor(block); highlight.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); highlight.setBlockFormat(fmt); break; } } } bool NumberedTextView::eventFilter(QObject *obj, QEvent *event) { if (obj != view) { return QFrame::eventFilter(obj, event); } if (event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = static_cast(event); QTextCursor cursor = view->cursorForPosition(helpEvent->pos()); cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); QString word = cursor.selectedText(); emit mouseHover(word); emit mouseHover(helpEvent->pos(), word); // QToolTip::showText( helpEvent->globalPos(), word ); // For testing } return false; } diff --git a/examples/kjsconsole/numberedtextview.h b/examples/kjsconsole/numberedtextview.h index b3cd4ea..f2c5ccc 100644 --- a/examples/kjsconsole/numberedtextview.h +++ b/examples/kjsconsole/numberedtextview.h @@ -1,146 +1,146 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef NUMBERED_TEXT_VIEW_H #define NUMBERED_TEXT_VIEW_H #include #include #include class QTextEdit; class QHBoxLayout; /** * @internal Used to display the numbers. */ class NumberBar : public QWidget { Q_OBJECT public: NumberBar(QWidget *parent); ~NumberBar(); void setCurrentLine(int lineno); void setStopLine(int lineno); void setBugLine(int lineno); int currentLine() const; int stopLine() const; int bugLine() const; void setTextEdit(QTextEdit *edit); void paintEvent(QPaintEvent *ev) Q_DECL_OVERRIDE; protected: bool event(QEvent *ev) Q_DECL_OVERRIDE; private: QTextEdit *edit; QPixmap stopMarker; QPixmap currentMarker; QPixmap bugMarker; int m_stopLine; int m_currentLine; int m_bugLine; QRect stopRect; QRect currentRect; QRect bugRect; }; /** * Displays a QTextEdit with line numbers. */ class NumberedTextView : public QFrame { Q_OBJECT Q_PROPERTY(QString text READ text WRITE setText) Q_PROPERTY(int currentLine READ currentLine WRITE setCurrentLine) Q_PROPERTY(int stopLine READ stopLine WRITE setStopLine) Q_PROPERTY(int bugLine READ bugLine WRITE setBugLine) public: - NumberedTextView(QWidget *parent = 0); + NumberedTextView(QWidget *parent = nullptr); ~NumberedTextView(); /** Returns the QTextEdit of the main view. */ QTextEdit *textEdit() const { return view; } /** * Sets the line that should have the current line indicator. * A value of -1 indicates no line should show the indicator. */ void setCurrentLine(int lineno); /** * Sets the line that should have the stop line indicator. * A value of -1 indicates no line should show the indicator. */ void setStopLine(int lineno); /** * Sets the line that should have the bug line indicator. * A value of -1 indicates no line should show the indicator. */ void setBugLine(int lineno); int currentLine() const; int stopLine() const; int bugLine() const; /** @internal Used to get tooltip events from the view for the hover signal. */ bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; QString text() const; void setText(const QString &text); Q_SIGNALS: /** * Emitted when the mouse is hovered over the text edit component. * @param word The word under the mouse pointer */ void mouseHover(const QString &word); /** * Emitted when the mouse is hovered over the text edit component. * @param pos The position of the mouse pointer. * @param word The word under the mouse pointer */ void mouseHover(const QPoint &pos, const QString &word); protected Q_SLOTS: /** @internal Used to update the highlight on the current line. */ void textChanged(int pos, int added, int removed); private: QTextEdit *view; NumberBar *numbers; QHBoxLayout *box; //int m_currentLine; QTextCursor highlight; }; #endif // NUMBERED_TEXT_VIEW_H diff --git a/src/kjsembed/QBrush_bind.cpp b/src/kjsembed/QBrush_bind.cpp index 5fc49dd..96b2d35 100644 --- a/src/kjsembed/QBrush_bind.cpp +++ b/src/kjsembed/QBrush_bind.cpp @@ -1,294 +1,294 @@ #include "QBrush_bind.h" #include #include #include using namespace KJSEmbed; // Temp - for building class QColorBinding { public: static const KJS::ClassInfo info; }; class QPixmapBinding { public: static const KJS::ClassInfo info; }; class QGradientBinding { public: static const KJS::ClassInfo info; }; -const KJS::ClassInfo QColorBinding::info = { "QColor", &VariantBinding::info, 0, 0 }; -const KJS::ClassInfo QPixmapBinding::info = { "QPixmap", &VariantBinding::info, 0, 0 }; -const KJS::ClassInfo QGradientBinding::info = { "QGradient", &ObjectBinding::info, 0, 0 }; +const KJS::ClassInfo QColorBinding::info = { "QColor", &VariantBinding::info, nullptr, nullptr }; +const KJS::ClassInfo QPixmapBinding::info = { "QPixmap", &VariantBinding::info, nullptr, nullptr }; +const KJS::ClassInfo QGradientBinding::info = { "QGradient", &ObjectBinding::info, nullptr, nullptr }; -const KJS::ClassInfo QBrushBinding::info = { "QBrush", &VariantBinding::info, 0, 0 }; +const KJS::ClassInfo QBrushBinding::info = { "QBrush", &VariantBinding::info, nullptr, nullptr }; QBrushBinding::QBrushBinding(KJS::ExecState *exec, const QBrush &value) : VariantBinding(exec, value) { StaticBinding::publish(exec, this, QBrushData::methods()); StaticBinding::publish(exec, this, VariantFactory::methods()); } namespace QBrushNS { // style KJS::JSValue *style(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJS::JSValue *result = KJS::jsNull(); KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (!imp) { return KJS::throwError(exec, KJS::GeneralError, "No implementation? Huh?"); } QBrush value = imp->value(); if (args.size() == 0) { Qt::BrushStyle tmp = value.style(); result = KJS::jsNumber(tmp); imp->setValue(qVariantFromValue(value)); return result; } return KJS::throwError(exec, KJS::SyntaxError, "Syntax error in parameter list for QBrush.style"); } // setStyle KJS::JSValue *setStyle(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJS::JSValue *result = KJS::jsNull(); KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (!imp) { return KJS::throwError(exec, KJS::GeneralError, "No implementation? Huh?"); } QBrush value = imp->value(); if (args.size() == 1) { KJS::JSValue *value0 = args[0]; KJS::JSObject *object0 = value0->toObject(exec); if (object0 && object0->isNumber()) { Qt::BrushStyle arg0 = KJSEmbed::extractInteger(exec, args, 0); value.setStyle(arg0); imp->setValue(qVariantFromValue(value)); return result; } } return KJS::throwError(exec, KJS::SyntaxError, "Syntax error in parameter list for QBrush.setStyle"); } // texture KJS::JSValue *texture(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJS::JSValue *result = KJS::jsNull(); KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (!imp) { return KJS::throwError(exec, KJS::GeneralError, "No implementation? Huh?"); } QBrush value = imp->value(); if (args.size() == 0) { QPixmap tmp = value.texture(); result = KJSEmbed::createVariant(exec, "QPixmap", tmp); imp->setValue(qVariantFromValue(value)); return result; } return KJS::throwError(exec, KJS::SyntaxError, "Syntax error in parameter list for QBrush.texture"); } // setTexture KJS::JSValue *setTexture(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJS::JSValue *result = KJS::jsNull(); KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (!imp) { return KJS::throwError(exec, KJS::GeneralError, "No implementation? Huh?"); } QBrush value = imp->value(); if (args.size() == 1) { KJS::JSValue *value0 = args[0]; KJS::JSObject *object0 = value0->toObject(exec); if (object0 && object0->inherits(&QPixmapBinding::info)) { QPixmap pixmap = KJSEmbed::extractVariant(exec, args, 0); value.setTexture(pixmap); imp->setValue(qVariantFromValue(value)); return result; } } return KJS::throwError(exec, KJS::SyntaxError, "Syntax error in parameter list for QBrush.setTexture"); } // color KJS::JSValue *color(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJS::JSValue *result = KJS::jsNull(); KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (!imp) { return KJS::throwError(exec, KJS::GeneralError, "No implementation? Huh?"); } QBrush value = imp->value(); if (args.size() == 0) { const QColor &tmp = value.color(); result = KJSEmbed::createVariant(exec, "QColor", tmp); imp->setValue(qVariantFromValue(value)); return result; } return KJS::throwError(exec, KJS::SyntaxError, "Syntax error in parameter list for QBrush.color"); } // setColor KJS::JSValue *setColor(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJS::JSValue *result = KJS::jsNull(); KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (!imp) { return KJS::throwError(exec, KJS::GeneralError, "No implementation? Huh?"); } QBrush value = imp->value(); if (args.size() == 1) { KJS::JSValue *value0 = args[0]; KJS::JSObject *object0 = value0->toObject(exec); if (object0 && object0->inherits(&QColorBinding::info)) { QColor color = KJSEmbed::extractVariant(exec, args, 0); value.setColor(color); imp->setValue(qVariantFromValue(value)); return result; } if (object0 && object0->isNumber()) { Qt::GlobalColor color = KJSEmbed::extractInteger(exec, args, 0); value.setColor(color); imp->setValue(qVariantFromValue(value)); return result; } } return KJS::throwError(exec, KJS::SyntaxError, "Syntax error in parameter list for QBrush.setColor"); } // gradient KJS::JSValue *gradient(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJS::JSValue *result = KJS::jsNull(); KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (!imp) { return KJS::throwError(exec, KJS::GeneralError, "No implementation? Huh?"); } QBrush value = imp->value(); if (args.size() == 0) { const QGradient *tmp = value.gradient(); result = KJSEmbed::createValue(exec, "const QGradient *", tmp); imp->setValue(qVariantFromValue(value)); return result; } return KJS::throwError(exec, KJS::SyntaxError, "Syntax error in parameter list for QBrush.gradient"); } // isOpaque KJS::JSValue *isOpaque(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJS::JSValue *result = KJS::jsNull(); KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (!imp) { return KJS::throwError(exec, KJS::GeneralError, "No implementation? Huh?"); } QBrush value = imp->value(); if (args.size() == 0) { bool tmp = value.isOpaque(); result = KJSEmbed::createVariant(exec, "bool", tmp); imp->setValue(qVariantFromValue(value)); return result; } return KJS::throwError(exec, KJS::SyntaxError, "Syntax error in parameter list for QBrush.isOpaque"); } } -const Enumerator KJSEmbed::QBrushData::p_enums[] = {{0, 0 }}; +const Enumerator KJSEmbed::QBrushData::p_enums[] = {{nullptr, 0 }}; NO_STATICS(KJSEmbed::QBrushData) const Constructor KJSEmbed::QBrushData::p_constructor = -{"QBrush", 0, KJS::DontDelete | KJS::ReadOnly, 0, &QBrushData::ctorMethod, p_statics, p_enums, KJSEmbed::QBrushData::p_methods }; +{"QBrush", 0, KJS::DontDelete | KJS::ReadOnly, nullptr, &QBrushData::ctorMethod, p_statics, p_enums, KJSEmbed::QBrushData::p_methods }; KJS::JSObject *KJSEmbed::QBrushData::ctorMethod(KJS::ExecState *exec, const KJS::List &args) { if (args.size() == 0) { return new KJSEmbed::QBrushBinding(exec, QBrush()); } if (args.size() == 1) { KJS::JSValue *value0 = args[0]; KJS::JSObject *object0 = value0->toObject(exec); if (object0 && object0->isNumber()) { Qt::BrushStyle bs = KJSEmbed::extractInteger(exec, args, 0); return new KJSEmbed::QBrushBinding(exec, QBrush(bs)); } if (object0 && object0->inherits(&QPixmapBinding::info)) { QPixmap pixmap = KJSEmbed::extractVariant(exec, args, 0); return new KJSEmbed::QBrushBinding(exec, QBrush(pixmap)); } if (object0 && object0->inherits(&QBrushBinding::info)) { QBrush brush = KJSEmbed::extractVariant(exec, args, 0); return new KJSEmbed::QBrushBinding(exec, QBrush(brush)); } if (object0 && object0->inherits(&QGradientBinding::info)) { QGradient gradient = KJSEmbed::extractValue(exec, args, 0); return new KJSEmbed::QBrushBinding(exec, QBrush(gradient)); } } if (args.size() == 2) { KJS::JSValue *value0 = args[0]; KJS::JSObject *object0 = value0->toObject(exec); KJS::JSValue *value1 = args[1]; KJS::JSObject *object1 = value1->toObject(exec); if (object0 && object0->inherits(&QColorBinding::info) && ((object1 && object1->isNumber()) || !object1)) { QColor color = KJSEmbed::extractVariant(exec, args, 0); Qt::BrushStyle bs = KJSEmbed::extractInteger(exec, args, 1, Qt::SolidPattern); return new KJSEmbed::QBrushBinding(exec, QBrush(color, bs)); } if (object0 && object0->isNumber() && ((object1 && object1->isNumber()) || !object1)) { Qt::GlobalColor color = KJSEmbed::extractInteger(exec, args, 0); Qt::BrushStyle bs = KJSEmbed::extractInteger(exec, args, 1, Qt::SolidPattern); return new KJSEmbed::QBrushBinding(exec, QBrush(color, bs)); } if (object0 && object0->inherits(&QColorBinding::info) && object1 && object1->inherits(&QPixmapBinding::info)) { QColor color = KJSEmbed::extractVariant(exec, args, 0); QPixmap pixmap = KJSEmbed::extractVariant(exec, args, 1); return new KJSEmbed::QBrushBinding(exec, QBrush(color, pixmap)); } if (object0 && object0->isNumber() && object1 && object1->inherits(&QPixmapBinding::info)) { Qt::GlobalColor color = KJSEmbed::extractInteger(exec, args, 0); QPixmap pixmap = KJSEmbed::extractVariant(exec, args, 1); return new KJSEmbed::QBrushBinding(exec, QBrush(color, pixmap)); } } return KJS::throwError(exec, KJS::SyntaxError, "Syntax error in parameter list for QBrush"); } const Method KJSEmbed::QBrushData::p_methods[] = { { "style", 0, KJS::DontDelete | KJS::ReadOnly, &QBrushNS::style }, { "setStyle", 1, KJS::DontDelete | KJS::ReadOnly, &QBrushNS::setStyle }, { "texture", 0, KJS::DontDelete | KJS::ReadOnly, &QBrushNS::texture }, { "setTexture", 1, KJS::DontDelete | KJS::ReadOnly, &QBrushNS::setTexture }, { "color", 0, KJS::DontDelete | KJS::ReadOnly, &QBrushNS::color }, { "setColor", 1, KJS::DontDelete | KJS::ReadOnly, &QBrushNS::setColor }, { "gradient", 0, KJS::DontDelete | KJS::ReadOnly, &QBrushNS::gradient }, { "isOpaque", 0, KJS::DontDelete | KJS::ReadOnly, &QBrushNS::isOpaque }, - {0, 0, 0, 0 } + {nullptr, 0, 0, nullptr } }; diff --git a/src/kjsembed/binding_support.cpp b/src/kjsembed/binding_support.cpp index dd9d3e1..dcfed11 100644 --- a/src/kjsembed/binding_support.cpp +++ b/src/kjsembed/binding_support.cpp @@ -1,228 +1,228 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "binding_support.h" #include using namespace KJSEmbed; ProxyBinding::ProxyBinding(KJS::ExecState *exec) : KJS::JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()) { } QString KJSEmbed::extractQString(KJS::ExecState *exec, const KJS::List &args, int idx, const QString defaultValue) { if (args.size() > idx) { return extractQString(exec, args[idx]); } return defaultValue; } QString KJSEmbed::extractQString(KJS::ExecState *exec, KJS::JSValue *value, const QString defaultValue) { if (!value) { return defaultValue; } return toQString(value->toString(exec)); } QByteArray KJSEmbed::extractQByteArray(KJS::ExecState *exec, const KJS::List &args, int idx, const QByteArray &defaultValue) { if (args.size() > idx) { return extractQByteArray(exec, args[idx]); } return defaultValue; } QByteArray KJSEmbed::extractQByteArray(KJS::ExecState *exec, KJS::JSValue *value, const QByteArray &defaultValue) { if (!value) { return defaultValue; } return toQString(value->toString(exec)).toLatin1(); } KJS::JSValue *KJSEmbed::createQByteArray(KJS::ExecState *exec, const QByteArray &value) { Q_UNUSED(exec); return KJS::jsString(value.data()); } int KJSEmbed::extractInt(KJS::ExecState *exec, const KJS::List &args, int idx, int defaultValue) { if (args.size() > idx) { return extractInt(exec, args[idx]); } return defaultValue; } int KJSEmbed::extractInt(KJS::ExecState *exec, KJS::JSValue *value, int defaultValue) { if (!value) { return defaultValue; } return int(value->toInteger(exec)); } KJS::JSValue *KJSEmbed::createQString(KJS::ExecState *exec, const QString &value) { Q_UNUSED(exec); return KJS::jsString(toUString(value)); } KJS::JSValue *KJSEmbed::createInt(KJS::ExecState *exec, int value) { Q_UNUSED(exec); return KJS::jsNumber(value); } double KJSEmbed::extractDouble(KJS::ExecState *exec, const KJS::List &args, int idx, double defaultValue) { if (args.size() > idx) { return extractDouble(exec, args[idx]); } return defaultValue; } double KJSEmbed::extractDouble(KJS::ExecState *exec, KJS::JSValue *value, double defaultValue) { if (!value) { return defaultValue; } return (double) value->toNumber(exec); } KJS::JSValue *KJSEmbed::createDouble(KJS::ExecState *exec, double value) { Q_UNUSED(exec); return KJS::jsNumber(value); } float KJSEmbed::extractFloat(KJS::ExecState *exec, const KJS::List &args, int idx, float defaultValue) { if (args.size() > idx) { return extractFloat(exec, args[idx]); } return defaultValue; } float KJSEmbed::extractFloat(KJS::ExecState *exec, KJS::JSValue *value, float defaultValue) { if (!value) { return defaultValue; } return (float) value->toNumber(exec); } KJS::JSValue *KJSEmbed::createFloat(KJS::ExecState *exec, float value) { Q_UNUSED(exec); return KJS::jsNumber(value); } bool KJSEmbed::extractBool(KJS::ExecState *exec, const KJS::List &args, int idx, bool defaultValue) { if (args.size() > idx) { return extractBool(exec, args[idx]); } return defaultValue; } bool KJSEmbed::extractBool(KJS::ExecState *exec, KJS::JSValue *value, bool defaultValue) { if (!value) { return defaultValue; } return value->toBoolean(exec); } KJS::JSValue *KJSEmbed::createBool(KJS::ExecState *exec, bool value) { Q_UNUSED(exec); return KJS::jsBoolean(value); } QDateTime KJSEmbed::extractQDateTime(KJS::ExecState * /* exec */, const KJS::List & /* args */, int /* idx */, const QDateTime & /* defaultValue */) { return QDateTime(); } QDateTime KJSEmbed::extractQDateTime(KJS::ExecState * /* exec */, KJS::JSValue * /* value */, const QDateTime & /* defaultValue */) { return QDateTime(); } KJS::JSValue *KJSEmbed::createQDateTime(KJS::ExecState * /* exec */, const QDateTime & /* value */) { // return new KJS::JSValue(); - return 0; + return nullptr; } QDate KJSEmbed::extractQDate(KJS::ExecState * /* exec */, const KJS::List & /* args */, int /* idx */, const QDate & /* defaultValue */) { return QDate(); } QDate KJSEmbed::extractQDate(KJS::ExecState * /*exec*/, KJS::JSValue * /*value*/, const QDate & /*defaultValue*/) { return QDate(); } KJS::JSValue *KJSEmbed::createQDate(KJS::ExecState * /*exec*/, const QDate & /*value*/) { // return new KJS::JSValue(); - return 0; + return nullptr; } QTime KJSEmbed::extractQTime(KJS::ExecState * /*exec*/, const KJS::List & /*args*/, int /*idx*/, const QTime & /*defaultValue*/) { return QTime(); } QTime KJSEmbed::extractQTime(KJS::ExecState * /*exec*/, KJS::JSValue * /*value*/, const QTime &/*defaultValue*/) { return QTime(); } KJS::JSValue *KJSEmbed::createQTime(KJS::ExecState * /*exec*/, const QTime &/*value*/) { // return new KJS::JSValue(); - return 0; + return nullptr; } QStringList KJSEmbed::extractQStringList(KJS::ExecState * /*exec*/, const KJS::List &/*args*/, int /*idx*/, const QStringList &/*defaultValue*/) { return QStringList(); } QStringList KJSEmbed::extractQStringList(KJS::ExecState * /*exec*/, KJS::JSValue * /*value*/, const QStringList &/*defaultValue*/) { return QStringList(); } KJS::JSValue *KJSEmbed::createQStringList(KJS::ExecState * /*exec*/, const QStringList &/*value*/) { // return new KJS::JSValue(); - return 0; + return nullptr; } diff --git a/src/kjsembed/brush.cpp b/src/kjsembed/brush.cpp index a87d62d..08af2c1 100644 --- a/src/kjsembed/brush.cpp +++ b/src/kjsembed/brush.cpp @@ -1,158 +1,158 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "brush.h" #include #include #include #include #include "pixmap.h" #include "color.h" #include "util.h" using namespace KJSEmbed; -const KJS::ClassInfo BrushBinding::info = { "QBrush", &VariantBinding::info, 0, 0 }; +const KJS::ClassInfo BrushBinding::info = { "QBrush", &VariantBinding::info, nullptr, nullptr }; BrushBinding::BrushBinding(KJS::ExecState *exec, const QBrush &value) : VariantBinding(exec, value) { StaticBinding::publish(exec, this, Brush::methods()); StaticBinding::publish(exec, this, VariantFactory::methods()); } namespace BrushNS { START_VARIANT_METHOD(callcolor, QBrush) QColor cppValue = value.color(); result = KJSEmbed::createVariant(exec, "QColor", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callgradient, QBrush) const QGradient *cppValue = value.gradient(); result = KJSEmbed::createObject(exec, "QGradient", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callisOpaque, QBrush) bool cppValue = value.isOpaque(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsetColor, QBrush) QColor arg0 = KJSEmbed::extractVariant(exec, args, 0); value.setColor(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetStyle, QBrush) Qt::BrushStyle arg0 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 0); value.setStyle(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetTexture, QBrush) QPixmap arg0 = KJSEmbed::extractVariant(exec, args, 0); value.setTexture(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callstyle, QBrush) Qt::BrushStyle cppValue = value.style(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calltexture, QBrush) QPixmap cppValue = value.texture(); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); END_VARIANT_METHOD } START_METHOD_LUT(Brush) {"color", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callcolor}, {"gradient", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callgradient}, {"isOpaque", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callisOpaque}, {"setColor", 1, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callsetColor}, {"setStyle", 1, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callsetStyle}, {"setTexture", 1, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callsetTexture}, {"style", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callstyle}, {"texture", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::calltexture} END_METHOD_LUT NO_ENUMS(Brush) NO_STATICS(Brush) START_CTOR(Brush, QBrush, 0) if (args.size() == 0) { return new KJSEmbed::BrushBinding(exec, QBrush()); } else if (args.size() == 1) { KJS::JSValue *value0 = args[0]; KJS::JSObject *obj0 = value0->toObject(exec); if (obj0) { if (obj0->inherits(&PixmapBinding::info)) { QPixmap arg0 = KJSEmbed::extractVariant(exec, args, 0); return new KJSEmbed::BrushBinding(exec, QBrush(arg0)); } if (obj0->inherits(&BrushBinding::info)) { QBrush arg0 = KJSEmbed::extractVariant(exec, args, 0); return new KJSEmbed::BrushBinding(exec, QBrush(arg0)); } // if(obj0->inherits(&GradientBinding::info)) // { // QGradient arg0 = KJSEmbed::extractVariant(exec, args, 0); // return new KJSEmbed::BrushBinding(exec, QBrush(arg0)); // } } else if (isBasic(value0)) { Qt::BrushStyle arg0 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 0); return new KJSEmbed::BrushBinding(exec, QBrush(arg0)); } } else if (args.size() == 2) { KJS::JSValue *value0 = args[0]; KJS::JSValue *value1 = args[1]; KJS::JSObject *obj0 = value0->toObject(exec); KJS::JSObject *obj1 = value1->toObject(exec); if (obj0 && obj1 && obj0->inherits(&ColorBinding::info) && obj1->inherits(&PixmapBinding::info)) { QColor arg0 = KJSEmbed::extractVariant(exec, args, 0); QPixmap arg1 = KJSEmbed::extractVariant(exec, args, 1); return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1)); } if (obj1 && isBasic(value0) && obj1->inherits(&PixmapBinding::info)) { Qt::GlobalColor arg0 = (Qt::GlobalColor)KJSEmbed::extractInt(exec, args, 0); QPixmap arg1 = KJSEmbed::extractVariant(exec, args, 1); return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1)); } if (obj0 && obj0->inherits(&ColorBinding::info) && isBasic(value1)) { QColor arg0 = KJSEmbed::extractVariant(exec, args, 0); Qt::BrushStyle arg1 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 1); return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1)); } if (isBasic(value0) && isBasic(value1)) { Qt::GlobalColor arg0 = (Qt::GlobalColor)KJSEmbed::extractInt(exec, args, 0); Qt::BrushStyle arg1 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 1); return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1)); } } return new KJSEmbed::BrushBinding(exec, QBrush()); END_CTOR diff --git a/src/kjsembed/builtins.cpp b/src/kjsembed/builtins.cpp index d12e214..646713a 100644 --- a/src/kjsembed/builtins.cpp +++ b/src/kjsembed/builtins.cpp @@ -1,200 +1,200 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "builtins.h" #include #include #include #include #include #include #include #include "variant_binding.h" #include "object_binding.h" #include "static_binding.h" #include "kjsembed.h" using namespace KJSEmbed; KJS::JSValue *callExec(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(exec); Q_UNUSED(self); Q_UNUSED(args); return KJS::jsBoolean(QCoreApplication::exec()); } KJS::JSValue *callDump(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(self); if (args.size() == 1) { KJS::JSObject *object = args[0]->toObject(exec); Q_UNUSED(object); } return KJS::jsNull(); } KJS::JSValue *callInclude(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(self); if (args.size() == 1) { KJS::UString filename = args[0]->toString(exec); qDebug() << "include: " << toQString(filename); KJS::Completion c = Engine::runFile(exec->dynamicInterpreter(), filename); if (c.complType() == KJS::Normal) { return KJS::jsNull(); } if (c.complType() == KJS::ReturnValue) { if (c.isValueCompletion()) { return c.value(); } return KJS::jsNull(); } if (c.complType() == KJS::Throw) { QString message = toQString(c.value()->toString(exec)); int line = c.value()->toObject(exec)->get(exec, "line")->toUInt32(exec); return throwError(exec, KJS::EvalError, toUString(i18n("Error encountered while processing include '%1' line %2: %3", toQString(filename), line, message))); } } else { return throwError(exec, KJS::URIError, toUString(i18n("include only takes 1 argument, not %1.", args.size()))); } return KJS::jsNull(); } KJS::JSValue *callLibrary(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(self); if (args.size() == 1) { KJS::UString filename = args[0]->toString(exec); QString qualifiedFilename = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "scripts/" + toQString(filename)); if (!qualifiedFilename.isEmpty()) { KJS::Completion c = Engine::runFile(exec->dynamicInterpreter(), toUString(qualifiedFilename)); if (c.complType() == KJS::Normal) { return KJS::jsNull(); } if (c.complType() == KJS::ReturnValue) { if (c.isValueCompletion()) { return c.value(); } return KJS::jsNull(); } if (c.complType() == KJS::Throw) { QString message = toQString(c.value()->toString(exec)); int line = c.value()->toObject(exec)->get(exec, "line")->toUInt32(exec); return throwError(exec, KJS::EvalError, toUString(i18n("Error encountered while processing include '%1' line %2: %3", toQString(filename), line, message))); } } else { QString msg = i18n("File %1 not found.", toQString(filename)); return throwError(exec, KJS::URIError, toUString(msg)); } } else { return throwError(exec, KJS::URIError, toUString(i18n("library only takes 1 argument, not %1.", args.size()))); } return KJS::jsNull(); } KJS::JSValue *callAlert(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(self) if (args.size() == 1) { (*KJSEmbed::conerr()) << "callAlert"; QString message = toQString(args[0]->toString(exec)); - QMessageBox::warning(0, i18n("Alert"), message, QMessageBox::Ok, QMessageBox::NoButton); + QMessageBox::warning(nullptr, i18n("Alert"), message, QMessageBox::Ok, QMessageBox::NoButton); } return KJS::jsNull(); } KJS::JSValue *callConfirm(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(self) if (args.size() == 1) { QString message = toQString(args[0]->toString(exec)); - int result = QMessageBox::question(0, i18n("Confirm"), message, QMessageBox::Yes, QMessageBox::No); + int result = QMessageBox::question(nullptr, i18n("Confirm"), message, QMessageBox::Yes, QMessageBox::No); if (result == QMessageBox::Yes) { return KJS::jsBoolean(true); } } return KJS::jsBoolean(false); } KJS::JSValue *callIsVariantType(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(self) if (args.size() == 1) { QString thetypename = toQString(args[0]->toString(exec)); return KJS::jsBoolean(QMetaType::type(thetypename.toLatin1().data())); } return KJS::jsBoolean(false); } KJS::JSValue *callIsVariant(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(self) if (args.size() == 1) { KJS::JSObject *obj = args[0]->toObject(exec); if (obj->inherits(&VariantBinding::info)) { return KJS::jsBoolean(true); } } return KJS::jsBoolean(false); } KJS::JSValue *callIsObject(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(self) if (args.size() == 1) { KJS::JSObject *obj = args[0]->toObject(exec); if (obj->inherits(&ObjectBinding::info)) { return KJS::jsBoolean(true); } } return KJS::jsBoolean(false); } const Method BuiltinsFactory::BuiltinMethods[] = { {"exec", 0, KJS::DontDelete | KJS::ReadOnly, &callExec}, {"dump", 1, KJS::DontDelete | KJS::ReadOnly, &callDump}, {"include", 1, KJS::DontDelete | KJS::ReadOnly, &callInclude}, {"library", 1, KJS::DontDelete | KJS::ReadOnly, &callLibrary}, {"alert", 1, KJS::DontDelete | KJS::ReadOnly, &callAlert}, {"confirm", 1, KJS::DontDelete | KJS::ReadOnly, &callConfirm}, {"isVariantType", 1, KJS::DontDelete | KJS::ReadOnly, &callIsVariantType}, {"isVariant", 1, KJS::DontDelete | KJS::ReadOnly, &callIsVariant}, {"isObject", 1, KJS::DontDelete | KJS::ReadOnly, &callIsObject}, - {0, 0, 0, 0 } + {nullptr, 0, 0, nullptr } }; diff --git a/src/kjsembed/color.cpp b/src/kjsembed/color.cpp index 802627c..dc18064 100644 --- a/src/kjsembed/color.cpp +++ b/src/kjsembed/color.cpp @@ -1,190 +1,190 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "color.h" #include #include using namespace KJSEmbed; -const KJS::ClassInfo ColorBinding::info = { "QColor", &VariantBinding::info, 0, 0 }; +const KJS::ClassInfo ColorBinding::info = { "QColor", &VariantBinding::info, nullptr, nullptr }; ColorBinding::ColorBinding(KJS::ExecState *exec, const QColor &value) : VariantBinding(exec, value) { StaticBinding::publish(exec, this, Color::methods()); StaticBinding::publish(exec, this, VariantFactory::methods()); } START_VARIANT_METHOD(callSetAlpha, QColor) value.setAlpha(KJSEmbed::extractInt(exec, args, 0)); END_VARIANT_METHOD START_VARIANT_METHOD(callSetBlue, QColor) value.setBlue(KJSEmbed::extractInt(exec, args, 0)); END_VARIANT_METHOD START_VARIANT_METHOD(callSetGreen, QColor) value.setGreen(KJSEmbed::extractInt(exec, args, 0)); END_VARIANT_METHOD START_VARIANT_METHOD(callSetRed, QColor) value.setRed(KJSEmbed::extractInt(exec, args, 0)); END_VARIANT_METHOD START_VARIANT_METHOD(callSetRgb, QColor) value.setRgb(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1), KJSEmbed::extractInt(exec, args, 2), KJSEmbed::extractInt(exec, args, 3, 255)); END_VARIANT_METHOD START_VARIANT_METHOD(callSetCmyk, QColor) value.setCmyk(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1), KJSEmbed::extractInt(exec, args, 2), KJSEmbed::extractInt(exec, args, 3), KJSEmbed::extractInt(exec, args, 4, 255)); END_VARIANT_METHOD START_VARIANT_METHOD(callSetHsv, QColor) value.setHsv(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1), KJSEmbed::extractInt(exec, args, 2), KJSEmbed::extractInt(exec, args, 3, 255)); END_VARIANT_METHOD START_VARIANT_METHOD(callSetNamedColor, QColor) value.setNamedColor(KJSEmbed::extractQString(exec, args, 0)); END_VARIANT_METHOD START_VARIANT_METHOD(callAlpha, QColor) value.setAlpha(KJSEmbed::extractInt(exec, args, 0)); END_VARIANT_METHOD START_VARIANT_METHOD(callBlue, QColor) result = KJSEmbed::createInt(exec, value.blue()); END_VARIANT_METHOD START_VARIANT_METHOD(callCyan, QColor) result = KJSEmbed::createInt(exec, value.cyan()); END_VARIANT_METHOD START_VARIANT_METHOD(callGreen, QColor) result = KJSEmbed::createInt(exec, value.green()); END_VARIANT_METHOD START_VARIANT_METHOD(callHue, QColor) result = KJSEmbed::createInt(exec, value.hue()); END_VARIANT_METHOD START_VARIANT_METHOD(callMagenta, QColor) result = KJSEmbed::createInt(exec, value.magenta()); END_VARIANT_METHOD START_VARIANT_METHOD(callRed, QColor) result = KJSEmbed::createInt(exec, value.red()); END_VARIANT_METHOD START_VARIANT_METHOD(callYellow, QColor) result = KJSEmbed::createInt(exec, value.yellow()); END_VARIANT_METHOD START_VARIANT_METHOD(callSaturation, QColor) result = KJSEmbed::createInt(exec, value.saturation()); END_VARIANT_METHOD START_VARIANT_METHOD(callDark, QColor) QColor darkColor = value.dark(KJSEmbed::extractInt(exec, args, 0, 200)); result = KJSEmbed::createVariant(exec, "QColor", darkColor); END_VARIANT_METHOD START_VARIANT_METHOD(callLight, QColor) QColor darkColor = value.light(KJSEmbed::extractInt(exec, args, 0, 200)); result = KJSEmbed::createVariant(exec, "QColor", darkColor); END_VARIANT_METHOD START_VARIANT_METHOD(callConvertTo, QColor) QColor otherColor = value.convertTo((QColor::Spec)KJSEmbed::extractInt(exec, args, 0)); result = KJSEmbed::createVariant(exec, "QColor", otherColor); END_VARIANT_METHOD START_VARIANT_METHOD(callSpec, QColor) result = KJS::jsNumber(value.spec()); END_VARIANT_METHOD START_METHOD_LUT(Color) {"setAlpha", 1, KJS::DontDelete | KJS::ReadOnly, &callSetAlpha}, {"setBlue", 1, KJS::DontDelete | KJS::ReadOnly, &callSetBlue}, {"setGreen", 1, KJS::DontDelete | KJS::ReadOnly, &callSetGreen}, {"setRed", 1, KJS::DontDelete | KJS::ReadOnly, &callSetRed}, {"setRgb", 4, KJS::DontDelete | KJS::ReadOnly, &callSetRgb}, {"setCmyk", 5, KJS::DontDelete | KJS::ReadOnly, &callSetCmyk}, {"setHsv", 4, KJS::DontDelete | KJS::ReadOnly, &callSetHsv}, {"setNamedColor", 1, KJS::DontDelete | KJS::ReadOnly, &callSetNamedColor}, {"alpha", 0, KJS::DontDelete | KJS::ReadOnly, &callAlpha}, {"blue", 0, KJS::DontDelete | KJS::ReadOnly, &callBlue}, {"cyan", 0, KJS::DontDelete | KJS::ReadOnly, &callCyan}, {"green", 0, KJS::DontDelete | KJS::ReadOnly, &callGreen}, {"hue", 0, KJS::DontDelete | KJS::ReadOnly, &callHue}, {"magenta", 0, KJS::DontDelete | KJS::ReadOnly, &callMagenta}, {"red", 0, KJS::DontDelete | KJS::ReadOnly, &callRed}, {"saturation", 0, KJS::DontDelete | KJS::ReadOnly, &callSaturation}, {"yellow", 0, KJS::DontDelete | KJS::ReadOnly, &callYellow}, {"light", 1, KJS::DontDelete | KJS::ReadOnly, &callLight}, {"dark", 1, KJS::DontDelete | KJS::ReadOnly, &callDark}, {"convertTo", 1, KJS::DontDelete | KJS::ReadOnly, &callConvertTo}, {"spec", 0, KJS::DontDelete | KJS::ReadOnly, &callSpec} END_METHOD_LUT START_ENUM_LUT(Color) {"Rgb", QColor::Rgb}, {"Hsv", QColor::Hsv}, {"Cmyk", QColor::Cmyk}, {"Invalid", QColor::Invalid} END_ENUM_LUT NO_STATICS(Color) START_CTOR(Color, QColor, 0) if (args.size() == 1) { return new KJSEmbed::ColorBinding(exec, QColor(KJSEmbed::extractQString(exec, args, 0))); } else if (args.size() >= 3) { return new KJSEmbed::ColorBinding(exec, QColor(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1), KJSEmbed::extractInt(exec, args, 2))); } if (args.size() == 4) { return new KJSEmbed::ColorBinding(exec, QColor(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1), KJSEmbed::extractInt(exec, args, 2), KJSEmbed::extractInt(exec, args, 3))); } return new KJSEmbed::ColorBinding(exec, QColor()); END_CTOR diff --git a/src/kjsembed/dom.cpp b/src/kjsembed/dom.cpp index 0600945..a5d646b 100644 --- a/src/kjsembed/dom.cpp +++ b/src/kjsembed/dom.cpp @@ -1,868 +1,868 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dom.h" #include #include using namespace KJSEmbed; -const KJS::ClassInfo DomNodeBinding::info = { "QDomNode", &ValueBinding::info, 0, 0 }; +const KJS::ClassInfo DomNodeBinding::info = { "QDomNode", &ValueBinding::info, nullptr, nullptr }; DomNodeBinding::DomNodeBinding(KJS::ExecState *exec, const QDomNode &value) : ValueBinding(exec, "QDomNode", value) { StaticBinding::publish(exec, this, DomNode::methods()); } namespace DomNodeNS { START_VALUE_METHOD(nodeType, QDomNode) result = KJS::jsNumber((int)value.nodeType()); END_VALUE_METHOD START_VALUE_METHOD(nodeName, QDomNode) result = KJS::jsString(value.nodeName()); END_VALUE_METHOD START_VALUE_METHOD(nodeValue, QDomNode) result = KJS::jsString(value.nodeValue()); END_VALUE_METHOD START_VALUE_METHOD(appendChild, QDomNode) QDomNode newNode = KJSEmbed::extractValue(exec, args, 0); QDomNode node = value.appendChild(newNode); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(attributes, QDomNode) QDomNamedNodeMap map = value.attributes(); result = KJSEmbed::createValue(exec, "QDomNamedNodeMap", map); END_VALUE_METHOD START_VALUE_METHOD(childNodes, QDomNode) QDomNodeList nodes = value.childNodes(); result = KJSEmbed::createValue(exec, "QDomNodeList", nodes); END_VALUE_METHOD START_VALUE_METHOD(clear, QDomNode) value.clear(); END_VALUE_METHOD START_VALUE_METHOD(cloneNode, QDomNode) bool deep = KJSEmbed::extractBool(exec, args, 0, true); QDomNode node = value.cloneNode(deep); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(firstChild, QDomNode) QDomNode node = value.firstChild(); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(firstChildElement, QDomNode) QString name = KJSEmbed::extractQString(exec, args, 0); QDomElement node = value.firstChildElement(name); result = KJSEmbed::createValue(exec, "QDomElement", node); END_VALUE_METHOD START_VALUE_METHOD(hasAttributes, QDomNode) result = KJS::jsBoolean(value.hasAttributes()); END_VALUE_METHOD START_VALUE_METHOD(hasChildNodes, QDomNode) result = KJS::jsBoolean(value.hasChildNodes()); END_VALUE_METHOD START_VALUE_METHOD(insertBefore, QDomNode) QDomNode first = KJSEmbed::extractValue(exec, args, 0); QDomNode second = KJSEmbed::extractValue(exec, args, 1); QDomNode node = value.insertBefore(first, second); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(insertAfter, QDomNode) QDomNode first = KJSEmbed::extractValue(exec, args, 0); QDomNode second = KJSEmbed::extractValue(exec, args, 1); QDomNode node = value.insertAfter(first, second); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(isAttr, QDomNode) result = KJS::jsBoolean(value.isAttr()); END_VALUE_METHOD START_VALUE_METHOD(isCDATASection, QDomNode) result = KJS::jsBoolean(value.isCDATASection()); END_VALUE_METHOD START_VALUE_METHOD(isCharacterData, QDomNode) result = KJS::jsBoolean(value.isCharacterData()); END_VALUE_METHOD START_VALUE_METHOD(isComment, QDomNode) result = KJS::jsBoolean(value.isComment()); END_VALUE_METHOD START_VALUE_METHOD(isDocument, QDomNode) result = KJS::jsBoolean(value.isDocument()); END_VALUE_METHOD START_VALUE_METHOD(isDocumentFragment, QDomNode) result = KJS::jsBoolean(value.isDocumentFragment()); END_VALUE_METHOD START_VALUE_METHOD(isDocumentType, QDomNode) result = KJS::jsBoolean(value.isDocumentType()); END_VALUE_METHOD START_VALUE_METHOD(isElement, QDomNode) result = KJS::jsBoolean(value.isElement()); END_VALUE_METHOD START_VALUE_METHOD(isEntity, QDomNode) result = KJS::jsBoolean(value.isEntity()); END_VALUE_METHOD START_VALUE_METHOD(isEntityReference, QDomNode) result = KJS::jsBoolean(value.isEntityReference()); END_VALUE_METHOD START_VALUE_METHOD(isNotation, QDomNode) result = KJS::jsBoolean(value.isNotation()); END_VALUE_METHOD START_VALUE_METHOD(isNull, QDomNode) result = KJS::jsBoolean(value.isNull()); END_VALUE_METHOD START_VALUE_METHOD(isProcessingInstruction, QDomNode) result = KJS::jsBoolean(value.isProcessingInstruction()); END_VALUE_METHOD START_VALUE_METHOD(isSupported, QDomNode) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QString arg1 = KJSEmbed::extractQString(exec, args, 1); result = KJS::jsBoolean(value.isSupported(arg0, arg1)); END_VALUE_METHOD START_VALUE_METHOD(isText, QDomNode) result = KJS::jsBoolean(value.isText()); END_VALUE_METHOD START_VALUE_METHOD(lastChild, QDomNode) QDomNode node = value.lastChild(); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(lastChildElement, QDomNode) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QDomElement node = value.lastChildElement(arg0); result = KJSEmbed::createValue(exec, "QDomElement", node); END_VALUE_METHOD START_VALUE_METHOD(localName, QDomNode) result = KJS::jsString(value.localName()); END_VALUE_METHOD START_VALUE_METHOD(namedItem, QDomNode) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QDomNode node = value.namedItem(arg0); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(namespaceURI, QDomNode) result = KJS::jsString(value.namespaceURI()); END_VALUE_METHOD START_VALUE_METHOD(nextSibling, QDomNode) QDomNode node = value.nextSibling(); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(nextSiblingElement, QDomNode) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QDomElement node = value.nextSiblingElement(arg0); result = KJSEmbed::createValue(exec, "QDomElement", node); END_VALUE_METHOD START_VALUE_METHOD(normalize, QDomNode) value.normalize(); END_VALUE_METHOD START_VALUE_METHOD(ownerDocument, QDomNode) QDomDocument doc = value.ownerDocument(); result = KJSEmbed::createValue(exec, "QDomDocument", doc); END_VALUE_METHOD START_VALUE_METHOD(parentNode, QDomNode) QDomNode parent = value.parentNode(); result = KJSEmbed::createValue(exec, "QDomNode", parent); END_VALUE_METHOD START_VALUE_METHOD(prefix, QDomNode) result = KJS::jsString(value.prefix()); END_VALUE_METHOD START_VALUE_METHOD(previousSibling, QDomNode) QDomNode node = value.previousSibling(); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(previousSiblingElement, QDomNode) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QDomNode node = value.previousSiblingElement(arg0); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(removeChild, QDomNode) QDomNode arg0 = KJSEmbed::extractValue(exec, args, 0); QDomNode node = value.removeChild(arg0); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(replaceChild, QDomNode) QDomNode arg0 = KJSEmbed::extractValue(exec, args, 0); QDomNode arg1 = KJSEmbed::extractValue(exec, args, 1); QDomNode node = value.replaceChild(arg0, arg1); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(setPrefix, QDomNode) QString arg0 = KJSEmbed::extractQString(exec, args, 0); value.setPrefix(arg0); END_VALUE_METHOD START_VALUE_METHOD(setNodeValue, QDomNode) QString arg0 = KJSEmbed::extractQString(exec, args, 0); value.setNodeValue(arg0); END_VALUE_METHOD START_VALUE_METHOD(toAttr, QDomNode) QDomAttr attr = value.toAttr(); result = KJSEmbed::createValue(exec, "QDomAttr", attr); END_VALUE_METHOD START_VALUE_METHOD(toElement, QDomNode) QDomElement elem = value.toElement(); result = KJSEmbed::createValue(exec, "QDomElement", elem); END_VALUE_METHOD } START_METHOD_LUT(DomNode) {"appendChild", 1, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::appendChild}, {"attributes", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::attributes}, {"childNodes", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::childNodes}, {"clear", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::clear}, {"cloneNode", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::cloneNode}, {"firstChild", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::firstChild}, {"firstChildElement", 1, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::firstChildElement}, {"hasAttributes", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::hasAttributes}, {"hasChildNodes", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::hasChildNodes}, {"insertBefore", 2, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::insertBefore}, {"insertAfter", 2, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::insertAfter}, {"isAttr", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isAttr}, {"isCDATASection", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isCDATASection}, {"isCharacterData", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isCharacterData}, {"isComment", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isComment}, {"isDocument", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isDocument}, {"isDocumentFragment", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isDocumentFragment}, {"isDocumentType", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isDocumentType}, {"isElement", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isElement}, {"isEntity", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isEntity}, {"isEntityReference", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isEntityReference}, {"isNotation", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isNotation}, {"isNull", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isNull}, {"isProcessingInstruction", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isProcessingInstruction}, {"isSupported", 2, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isSupported}, {"isText", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::isText}, {"lastChild", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::lastChild}, {"lastChildElement", 1, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::lastChildElement}, {"localName", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::localName}, {"namedItem", 1, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::namedItem}, {"namespaceURI", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::namespaceURI}, {"nextSibling", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::nextSibling}, {"nextSiblingElement", 1, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::nextSiblingElement}, {"nodeType", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::nodeType}, {"nodeName", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::nodeName}, {"nodeValue", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::nodeValue}, {"normalize", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::normalize}, {"ownerDocument", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::ownerDocument}, {"parentNode", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::parentNode}, {"prefix", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::prefix}, {"previousSibling", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::previousSibling}, {"previousSiblingElement", 1, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::previousSiblingElement}, {"removeChild", 1, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::removeChild}, {"replaceChild", 2, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::replaceChild}, {"setPrefix", 1, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::setPrefix}, {"setNodeValue", 2, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::setNodeValue}, {"toAttr", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::toAttr}, {"toElement", 0, KJS::DontDelete | KJS::ReadOnly, &DomNodeNS::toElement} END_METHOD_LUT START_ENUM_LUT(DomNode) {"ElementNode", QDomNode::ElementNode}, {"AttributeNode", QDomNode::AttributeNode}, {"TextNode", QDomNode::TextNode}, {"CDATASectionNode", QDomNode::CDATASectionNode}, {"EntityReferenceNode", QDomNode::EntityReferenceNode}, {"EntityNode", QDomNode::EntityNode}, {"ProcessingInstructionNode", QDomNode::ProcessingInstructionNode}, {"CommentNode", QDomNode::CommentNode}, {"DocumentNode", QDomNode::DocumentNode}, {"DocumentTypeNode", QDomNode::DocumentTypeNode}, {"DocumentFragmentNode", QDomNode::DocumentFragmentNode}, {"NotationNode", QDomNode::NotationNode}, {"BaseNode", QDomNode::BaseNode}, {"CharacterDataNode", QDomNode::CharacterDataNode} END_ENUM_LUT NO_STATICS(DomNode) START_CTOR(DomNode, QDomNode, 0) return new KJSEmbed::DomNodeBinding(exec, QDomNode()); END_CTOR -const KJS::ClassInfo DomDocumentBinding::info = { "QDomDocument", &ValueBinding::info, 0, 0 }; +const KJS::ClassInfo DomDocumentBinding::info = { "QDomDocument", &ValueBinding::info, nullptr, nullptr }; DomDocumentBinding::DomDocumentBinding(KJS::ExecState *exec, const QDomDocument &value) : ValueBinding(exec, "QDomDocument", value) { StaticBinding::publish(exec, this, DomNode::methods()); StaticBinding::publish(exec, this, DomDocument::methods()); } namespace DomDocumentNS { QString parserErrorTemplate = "XML Parse error '%1' at %2,%3"; START_VALUE_METHOD(setContent, QDomDocument) QString xml = KJSEmbed::extractQString(exec, args, 0); QString message; int row = 0; int col = 0; bool success = value.setContent(xml, &message, &row, &col); result = KJS::jsBoolean(success); if (!success) { KJS::throwError(exec, KJS::SyntaxError, parserErrorTemplate.arg(message).arg(row).arg(col)); } END_VALUE_METHOD START_VALUE_METHOD(toString, QDomDocument) int indent = KJSEmbed::extractInt(exec, args, 0, 1); result = KJS::jsString(value.toString(indent)); END_VALUE_METHOD START_VALUE_METHOD(documentElement, QDomDocument) QDomElement elem = value.documentElement(); result = KJSEmbed::createValue(exec, "QDomElement", elem); END_VALUE_METHOD START_VALUE_METHOD(elementById, QDomDocument) QString id = KJSEmbed::extractQString(exec, args, 0); QDomElement elem = value.elementById(id); result = KJSEmbed::createValue(exec, "QDomElement", elem); END_VALUE_METHOD START_VALUE_METHOD(createAttribute, QDomDocument) QString name = KJSEmbed::extractQString(exec, args, 0); QDomAttr attr = value.createAttribute(name); result = KJSEmbed::createValue(exec, "QDomAttr", attr); END_VALUE_METHOD START_VALUE_METHOD(createAttributeNS, QDomDocument) QString nsURI = KJSEmbed::extractQString(exec, args, 0); QString qName = KJSEmbed::extractQString(exec, args, 1); QDomAttr attr = value.createAttributeNS(nsURI, qName); result = KJSEmbed::createValue(exec, "QDomAttr", attr); END_VALUE_METHOD START_VALUE_METHOD(createCDATASection, QDomDocument) QString cdatatxt = KJSEmbed::extractQString(exec, args, 0); QDomCDATASection cdata = value.createCDATASection(cdatatxt); result = KJSEmbed::createValue(exec, "QDomCDATASection", cdata); END_VALUE_METHOD START_VALUE_METHOD(createComment, QDomDocument) QString commenttxt = KJSEmbed::extractQString(exec, args, 0); QDomComment comment = value.createComment(commenttxt); result = KJSEmbed::createValue(exec, "QDomComment", comment); END_VALUE_METHOD START_VALUE_METHOD(createDocumentFragment, QDomDocument) QDomDocumentFragment fragment = value.createDocumentFragment(); result = KJSEmbed::createValue(exec, "QDomDocumentFragment", fragment); END_VALUE_METHOD START_VALUE_METHOD(createElement, QDomDocument) QString tagName = KJSEmbed::extractQString(exec, args, 0); QDomElement elem = value.createElement(tagName); result = KJSEmbed::createValue(exec, "QDomElement", elem); END_VALUE_METHOD START_VALUE_METHOD(createElementNS, QDomDocument) QString nsURI = KJSEmbed::extractQString(exec, args, 0); QString qName = KJSEmbed::extractQString(exec, args, 1); QDomElement elem = value.createElementNS(nsURI, qName); result = KJSEmbed::createValue(exec, "QDomElement", elem); END_VALUE_METHOD START_VALUE_METHOD(createEntityReference, QDomDocument) QString name = KJSEmbed::extractQString(exec, args, 0); QDomEntityReference ref = value.createEntityReference(name); result = KJSEmbed::createValue(exec, "QDomEntityReference", ref); END_VALUE_METHOD START_VALUE_METHOD(createProcessingInstruction, QDomDocument) QString target = KJSEmbed::extractQString(exec, args, 0); QString data = KJSEmbed::extractQString(exec, args, 1); QDomProcessingInstruction inst = value.createProcessingInstruction(target, data); result = KJSEmbed::createValue(exec, "QDomProcessingInstruction", inst); END_VALUE_METHOD START_VALUE_METHOD(createTextNode, QDomDocument) QString texttext = KJSEmbed::extractQString(exec, args, 0); QDomText text = value.createTextNode(texttext); result = KJSEmbed::createValue(exec, "QDomText", text); END_VALUE_METHOD START_VALUE_METHOD(importNode, QDomDocument) QDomNode import = KJSEmbed::extractValue(exec, args, 0); bool deep = KJSEmbed::extractBool(exec, args, 1); QDomNode node = value.importNode(import, deep); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD } START_METHOD_LUT(DomDocument) {"setContent", 1, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::setContent}, {"toString", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::toString}, {"documentElement", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::documentElement}, {"elementById", 1, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::elementById}, {"createAttribute", 1, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::createAttribute }, {"createAttributeNS", 2, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::createAttributeNS }, {"createCDATASection", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::createCDATASection}, {"createComment", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::createComment}, {"createDocumentFragment", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::createDocumentFragment}, {"createElement", 1, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::createElement}, {"createElementNS", 2, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::createElementNS}, {"createEntityReference", 1, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::createEntityReference}, {"createProcessingInstruction", 2, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::createProcessingInstruction}, {"createTextNode", 1, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::createTextNode}, {"importNode", 2, KJS::DontDelete | KJS::ReadOnly, &DomDocumentNS::importNode} END_METHOD_LUT NO_ENUMS(DomDocument) NO_STATICS(DomDocument) START_CTOR(DomDocument, QDomDocument, 1) QString name = KJSEmbed::extractQString(exec, args, 0); return new KJSEmbed::DomDocumentBinding(exec, QDomDocument(name)); END_CTOR -const KJS::ClassInfo DomElementBinding::info = { "QDomElement", &ValueBinding::info, 0, 0 }; +const KJS::ClassInfo DomElementBinding::info = { "QDomElement", &ValueBinding::info, nullptr, nullptr }; DomElementBinding::DomElementBinding(KJS::ExecState *exec, const QDomElement &value) : ValueBinding(exec, "QDomElement", value) { StaticBinding::publish(exec, this, DomNode::methods()); StaticBinding::publish(exec, this, DomElement::methods()); } namespace DomElementNS { START_VALUE_METHOD(toString, QDomElement) result = KJS::jsString(value.text()); END_VALUE_METHOD START_VALUE_METHOD(tagName, QDomElement) result = KJS::jsString(value.tagName()); END_VALUE_METHOD START_VALUE_METHOD(setTagName, QDomElement) QString tag = KJSEmbed::extractQString(exec, args, 0); value.setTagName(tag); END_VALUE_METHOD START_VALUE_METHOD(attribute, QDomElement) QString tag = KJSEmbed::extractQString(exec, args, 0); QString defaultValue = KJSEmbed::extractQString(exec, args, 1, QString()); result = KJS::jsString(value.attribute(tag, defaultValue)); END_VALUE_METHOD START_VALUE_METHOD(setAttribute, QDomElement) QString tag = KJSEmbed::extractQString(exec, args, 0); QString newValue = KJSEmbed::extractQString(exec, args, 1); value.setAttribute(tag, newValue); END_VALUE_METHOD START_VALUE_METHOD(hasAttribute, QDomElement) QString attr = KJSEmbed::extractQString(exec, args, 0); result = KJS::jsBoolean(value.hasAttribute(attr)); END_VALUE_METHOD START_VALUE_METHOD(removeAttribute, QDomElement) QString attr = KJSEmbed::extractQString(exec, args, 0); value.removeAttribute(attr); END_VALUE_METHOD START_VALUE_METHOD(setAttributeNS, QDomElement) QString ns = KJSEmbed::extractQString(exec, args, 0); QString attr = KJSEmbed::extractQString(exec, args, 1); QString val = KJSEmbed::extractQString(exec, args, 3); value.setAttributeNS(ns, attr, val); END_VALUE_METHOD START_VALUE_METHOD(attributeNS, QDomElement) QString nsURI = KJSEmbed::extractQString(exec, args, 0); QString localName = KJSEmbed::extractQString(exec, args, 1); QString defValue = KJSEmbed::extractQString(exec, args, 1, QString()); result = KJS::jsString(value.attributeNS(nsURI, localName, defValue)); END_VALUE_METHOD START_VALUE_METHOD(hasAttributeNS, QDomElement) QString ns = KJSEmbed::extractQString(exec, args, 0); QString attr = KJSEmbed::extractQString(exec, args, 1); result = KJS::jsBoolean(value.hasAttributeNS(ns, attr)); END_VALUE_METHOD START_VALUE_METHOD(removeAttributeNS, QDomElement) QString ns = KJSEmbed::extractQString(exec, args, 0); QString attr = KJSEmbed::extractQString(exec, args, 1); value.removeAttributeNS(ns, attr); END_VALUE_METHOD START_VALUE_METHOD(elementsByTagName, QDomElement) QString name = KJSEmbed::extractQString(exec, args, 0); QDomNodeList nodes = value.elementsByTagName(name); result = KJSEmbed::createValue(exec, "QDomNodeList", nodes); END_VALUE_METHOD START_VALUE_METHOD(elementsByTagNameNS, QDomElement) QString ns = KJSEmbed::extractQString(exec, args, 0); QString name = KJSEmbed::extractQString(exec, args, 1); QDomNodeList nodes = value.elementsByTagNameNS(ns, name); result = KJSEmbed::createValue(exec, "QDomNodeList", nodes); END_VALUE_METHOD START_VALUE_METHOD(attributeNode, QDomElement) QString name = KJSEmbed::extractQString(exec, args, 0); QDomAttr attr = value.attributeNode(name); result = KJSEmbed::createValue(exec, "QDomAttr", attr); END_VALUE_METHOD START_VALUE_METHOD(attributeNodeNS, QDomElement) QString ns = KJSEmbed::extractQString(exec, args, 0); QString name = KJSEmbed::extractQString(exec, args, 1); QDomAttr attr = value.attributeNodeNS(ns, name); result = KJSEmbed::createValue(exec, "QDomAttr", attr); END_VALUE_METHOD START_VALUE_METHOD(removeAttributeNode, QDomElement) QDomAttr attr = KJSEmbed::extractValue(exec, args, 0); QDomAttr newAttr = value.removeAttributeNode(attr); result = KJSEmbed::createValue(exec, "QDomAttr", newAttr); END_VALUE_METHOD START_VALUE_METHOD(setAttributeNode, QDomElement) QDomAttr attr = KJSEmbed::extractValue(exec, args, 0); QDomAttr newAttr = value.setAttributeNode(attr); result = KJSEmbed::createValue(exec, "QDomAttr", newAttr); END_VALUE_METHOD START_VALUE_METHOD(setAttributeNodeNS, QDomElement) QDomAttr attr = KJSEmbed::extractValue(exec, args, 0); QDomAttr newAttr = value.setAttributeNodeNS(attr); result = KJSEmbed::createValue(exec, "QDomAttr", newAttr); END_VALUE_METHOD } NO_ENUMS(DomElement) NO_STATICS(DomElement) START_METHOD_LUT(DomElement) {"toString", 0, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::toString}, {"text", 0, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::toString}, {"tagName", 0, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::tagName}, {"setTagName", 1, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::setTagName}, {"setAttribute", 2, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::setAttribute}, {"attribute", 2, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::attribute}, {"hasAttribute", 1, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::hasAttribute}, {"removeAttribute", 1, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::removeAttribute}, {"setAttributeNS", 3, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::setAttributeNS}, {"attributeNS", 3, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::attributeNS}, {"hasAttributeNS", 2, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::hasAttributeNS}, {"removeAttributeNS", 2, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::removeAttributeNS}, {"elementsByTagName", 1, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::elementsByTagName}, {"elementsByTagNameNS", 2, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::elementsByTagNameNS}, {"attributeNode", 1, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::attributeNode}, {"attributeNodeNS", 2, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::attributeNodeNS}, {"removeAttributeNode", 1, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::removeAttributeNode}, {"setAttributeNode", 1, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::setAttributeNode}, {"setAttributeNodeNS", 1, KJS::DontDelete | KJS::ReadOnly, &DomElementNS::setAttributeNodeNS} END_METHOD_LUT START_CTOR(DomElement, QDomElement, 0) return new KJSEmbed::DomElementBinding(exec, QDomElement()); END_CTOR -const KJS::ClassInfo DomAttrBinding::info = { "QDomAttr", &ValueBinding::info, 0, 0 }; +const KJS::ClassInfo DomAttrBinding::info = { "QDomAttr", &ValueBinding::info, nullptr, nullptr }; DomAttrBinding::DomAttrBinding(KJS::ExecState *exec, const QDomAttr &value) : ValueBinding(exec, "QDomAttr", value) { StaticBinding::publish(exec, this, DomNode::methods()); StaticBinding::publish(exec, this, DomAttr::methods()); } namespace AttrElementNS { START_VALUE_METHOD(name, QDomAttr) result = KJS::jsString(value.value()); END_VALUE_METHOD START_VALUE_METHOD(specified, QDomAttr) result = KJS::jsBoolean(value.specified()); END_VALUE_METHOD START_VALUE_METHOD(ownerElement, QDomAttr) QDomElement owner = value.ownerElement(); result = KJSEmbed::createValue(exec, "QDomElement", owner); END_VALUE_METHOD START_VALUE_METHOD(value, QDomAttr) result = KJS::jsString(value.value()); END_VALUE_METHOD START_VALUE_METHOD(setValue, QDomAttr) QString newValue = KJSEmbed::extractQString(exec, args, 0); value.setValue(newValue); END_VALUE_METHOD } NO_ENUMS(DomAttr) NO_STATICS(DomAttr) START_METHOD_LUT(DomAttr) {"name", 0, KJS::DontDelete | KJS::ReadOnly, &AttrElementNS::name}, {"specified", 0, KJS::DontDelete | KJS::ReadOnly, &AttrElementNS::specified}, {"ownerElement", 0, KJS::DontDelete | KJS::ReadOnly, &AttrElementNS::ownerElement}, {"value", 0, KJS::DontDelete | KJS::ReadOnly, &AttrElementNS::value}, {"setValue", 1, KJS::DontDelete | KJS::ReadOnly, &AttrElementNS::setValue} END_METHOD_LUT START_CTOR(DomAttr, QDomAttr, 0) return new KJSEmbed::DomAttrBinding(exec, QDomAttr()); END_CTOR -const KJS::ClassInfo DomNodeListBinding::info = { "QDomNodeList", &ValueBinding::info, 0, 0 }; +const KJS::ClassInfo DomNodeListBinding::info = { "QDomNodeList", &ValueBinding::info, nullptr, nullptr }; DomNodeListBinding::DomNodeListBinding(KJS::ExecState *exec, const QDomNodeList &value) : ValueBinding(exec, "QDomNodeList", value) { StaticBinding::publish(exec, this, DomNodeList::methods()); } namespace NodeListNS { START_VALUE_METHOD(count, QDomNodeList) result = KJS::jsNumber(value.count()); END_VALUE_METHOD START_VALUE_METHOD(length, QDomNodeList) result = KJS::jsNumber(value.length()); END_VALUE_METHOD START_VALUE_METHOD(item, QDomNodeList) int idx = KJSEmbed::extractInt(exec, args, 0); QDomNode node = value.item(idx); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD } NO_ENUMS(DomNodeList) NO_STATICS(DomNodeList) START_METHOD_LUT(DomNodeList) {"count", 0, KJS::DontDelete | KJS::ReadOnly, &NodeListNS::count}, {"length", 0, KJS::DontDelete | KJS::ReadOnly, &NodeListNS::length}, {"item", 1, KJS::DontDelete | KJS::ReadOnly, &NodeListNS::item} END_METHOD_LUT START_CTOR(DomNodeList, QDomNodeList, 0) return new KJSEmbed::DomNodeListBinding(exec, QDomNodeList()); END_CTOR -const KJS::ClassInfo DomDocumentTypeBinding::info = { "QDomDocumentType", &ValueBinding::info, 0, 0 }; +const KJS::ClassInfo DomDocumentTypeBinding::info = { "QDomDocumentType", &ValueBinding::info, nullptr, nullptr }; DomDocumentTypeBinding::DomDocumentTypeBinding(KJS::ExecState *exec, const QDomDocumentType &value) : ValueBinding(exec, "QDomDocumentType", value) { StaticBinding::publish(exec, this, DomNode::methods()); StaticBinding::publish(exec, this, DomDocumentType::methods()); } namespace DomDocumentTypeNS { START_VALUE_METHOD(internalSubset, QDomDocumentType) result = KJS::jsString(value.internalSubset()); END_VALUE_METHOD START_VALUE_METHOD(name, QDomDocumentType) result = KJS::jsString(value.name()); END_VALUE_METHOD START_VALUE_METHOD(publicId, QDomDocumentType) result = KJS::jsString(value.publicId()); END_VALUE_METHOD START_VALUE_METHOD(systemId, QDomDocumentType) result = KJS::jsString(value.systemId()); END_VALUE_METHOD START_VALUE_METHOD(entities, QDomDocumentType) result = KJSEmbed::createValue(exec, "QDomNamedNodeMap", value.entities()); END_VALUE_METHOD START_VALUE_METHOD(notations, QDomDocumentType) result = KJSEmbed::createValue(exec, "QDomNamedNodeMap", value.notations()); END_VALUE_METHOD } NO_ENUMS(DomDocumentType) NO_STATICS(DomDocumentType) START_METHOD_LUT(DomDocumentType) {"entities", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentTypeNS::entities}, {"notations", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentTypeNS::notations}, {"internalSubset", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentTypeNS::internalSubset}, {"name", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentTypeNS::name}, {"publicId", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentTypeNS::publicId}, {"systemId", 0, KJS::DontDelete | KJS::ReadOnly, &DomDocumentTypeNS::systemId} END_METHOD_LUT START_CTOR(DomDocumentType, QDomDocumentType, 0) return new KJSEmbed::DomDocumentTypeBinding(exec, QDomDocumentType()); END_CTOR -const KJS::ClassInfo DomNamedNodeMapBinding::info = { "QDomNamedNodeMap", &ValueBinding::info, 0, 0 }; +const KJS::ClassInfo DomNamedNodeMapBinding::info = { "QDomNamedNodeMap", &ValueBinding::info, nullptr, nullptr }; DomNamedNodeMapBinding::DomNamedNodeMapBinding(KJS::ExecState *exec, const QDomNamedNodeMap &value) : ValueBinding(exec, "QDomNamedNodeMap", value) { StaticBinding::publish(exec, this, DomNamedNodeMap::methods()); } namespace NamedNodeMapNS { START_VALUE_METHOD(contains, QDomNamedNodeMap) QString name = KJSEmbed::extractQString(exec, args, 0); result = KJS::jsBoolean(value.contains(name)); END_VALUE_METHOD START_VALUE_METHOD(count, QDomNamedNodeMap) result = KJS::jsNumber(value.count()); END_VALUE_METHOD START_VALUE_METHOD(item, QDomNamedNodeMap) int idx = KJSEmbed::extractInt(exec, args, 0); QDomNode node = value.item(idx); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(length, QDomNamedNodeMap) result = KJS::jsNumber(value.length()); END_VALUE_METHOD START_VALUE_METHOD(namedItem, QDomNamedNodeMap) QString name = KJSEmbed::extractQString(exec, args, 0); QDomNode node = value.namedItem(name); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(namedItemNS, QDomNamedNodeMap) QString nsuri = KJSEmbed::extractQString(exec, args, 0); QString localName = KJSEmbed::extractQString(exec, args, 1); QDomNode node = value.namedItemNS(nsuri, localName); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(removeNamedItem, QDomNamedNodeMap) QString name = KJSEmbed::extractQString(exec, args, 0); QDomNode node = value.removeNamedItem(name); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(removeNamedItemNS, QDomNamedNodeMap) QString nsuri = KJSEmbed::extractQString(exec, args, 0); QString localName = KJSEmbed::extractQString(exec, args, 1); QDomNode node = value.removeNamedItemNS(nsuri, localName); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(setNamedItem, QDomNamedNodeMap) QDomNode newNode = KJSEmbed::extractValue(exec, args, 0); QDomNode node = value.setNamedItem(newNode); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD START_VALUE_METHOD(setNamedItemNS, QDomNamedNodeMap) QDomNode newNode = KJSEmbed::extractValue(exec, args, 0); QDomNode node = value.setNamedItemNS(newNode); result = KJSEmbed::createValue(exec, "QDomNode", node); END_VALUE_METHOD } NO_ENUMS(DomNamedNodeMap) NO_STATICS(DomNamedNodeMap) START_METHOD_LUT(DomNamedNodeMap) {"contains", 0, KJS::DontDelete | KJS::ReadOnly, &NamedNodeMapNS::contains}, {"count", 0, KJS::DontDelete | KJS::ReadOnly, &NamedNodeMapNS::count}, {"item", 1, KJS::DontDelete | KJS::ReadOnly, &NamedNodeMapNS::item}, {"length", 0, KJS::DontDelete | KJS::ReadOnly, &NamedNodeMapNS::length}, {"namedItem", 1, KJS::DontDelete | KJS::ReadOnly, &NamedNodeMapNS::namedItem}, {"namedItemNS", 2, KJS::DontDelete | KJS::ReadOnly, &NamedNodeMapNS::namedItemNS}, {"removeNamedItem", 1, KJS::DontDelete | KJS::ReadOnly, &NamedNodeMapNS::removeNamedItem}, {"removeNamedItemNS", 2, KJS::DontDelete | KJS::ReadOnly, &NamedNodeMapNS::removeNamedItemNS}, {"setNamedItem", 1, KJS::DontDelete | KJS::ReadOnly, &NamedNodeMapNS::setNamedItem}, {"setNamedItemNS", 1, KJS::DontDelete | KJS::ReadOnly, &NamedNodeMapNS::setNamedItemNS} END_METHOD_LUT START_CTOR(DomNamedNodeMap, QDomNamedNodeMap, 0) return new KJSEmbed::DomNamedNodeMapBinding(exec, QDomNamedNodeMap()); END_CTOR -const KJS::ClassInfo DomTextBinding::info = { "QDomText", &ValueBinding::info, 0, 0 }; +const KJS::ClassInfo DomTextBinding::info = { "QDomText", &ValueBinding::info, nullptr, nullptr }; DomTextBinding::DomTextBinding(KJS::ExecState *exec, const QDomText &value) : ValueBinding(exec, "QDomText", value) { StaticBinding::publish(exec, this, DomNode::methods()); StaticBinding::publish(exec, this, DomText::methods()); } NO_ENUMS(DomText) NO_STATICS(DomText) NO_METHODS(DomText) START_CTOR(DomText, QDomText, 0) return new KJSEmbed::DomTextBinding(exec, QDomText()); END_CTOR diff --git a/src/kjsembed/filedialog_binding.cpp b/src/kjsembed/filedialog_binding.cpp index 68b935a..c813432 100644 --- a/src/kjsembed/filedialog_binding.cpp +++ b/src/kjsembed/filedialog_binding.cpp @@ -1,88 +1,88 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "filedialog_binding.h" #include #include #include #include #include #include "static_binding.h" using namespace KJSEmbed; KJS::JSValue *callGetExistingDirectory(KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args) { - QWidget *parent = KJSEmbed::extractObject(exec, args, 0, 0); + QWidget *parent = KJSEmbed::extractObject(exec, args, 0, nullptr); QString caption = KJSEmbed::extractVariant(exec, args, 1, QString()); QString dir = KJSEmbed::extractVariant(exec, args, 2, QString()); QFileDialog::Options options = (QFileDialog::Options)KJSEmbed::extractVariant(exec, args, 3, QFileDialog::ShowDirsOnly); return KJS::jsString(QFileDialog::getExistingDirectory(parent, caption, dir, options)); } KJS::JSValue *callGetOpenFileName(KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args) { - QWidget *parent = KJSEmbed::extractObject(exec, args, 0, 0); + QWidget *parent = KJSEmbed::extractObject(exec, args, 0, nullptr); QString caption = KJSEmbed::extractVariant(exec, args, 1, ""); QString dir = KJSEmbed::extractVariant(exec, args, 2, ""); QString filter = KJSEmbed::extractVariant(exec, args, 3, ""); // QString *selectedFilter = KJSEmbed::extractVariant(exec, args, 4, 0); QFileDialog::Options options = (QFileDialog::Options)KJSEmbed::extractVariant(exec, args, 4, 0); - return KJS::jsString(QFileDialog::getOpenFileName(parent, caption, dir, filter, 0, options)); + return KJS::jsString(QFileDialog::getOpenFileName(parent, caption, dir, filter, nullptr, options)); } KJS::JSValue *callGetOpenFileNames(KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args) { - QWidget *parent = KJSEmbed::extractObject(exec, args, 0, 0); + QWidget *parent = KJSEmbed::extractObject(exec, args, 0, nullptr); QString caption = KJSEmbed::extractVariant(exec, args, 1, QString()); QString dir = KJSEmbed::extractVariant(exec, args, 2, QString()); QString filter = KJSEmbed::extractVariant(exec, args, 3, QString()); // QString *selectedFilter = KJSEmbed::extractVariant(exec, args, 4, 0); QFileDialog::Options options = (QFileDialog::Options)KJSEmbed::extractVariant(exec, args, 4, 0); - QStringList fileNames = QFileDialog::getOpenFileNames(parent, caption, dir, filter, 0, options); + QStringList fileNames = QFileDialog::getOpenFileNames(parent, caption, dir, filter, nullptr, options); return convertToValue(exec, fileNames); } KJS::JSValue *callGetSaveFileName(KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args) { - QWidget *parent = KJSEmbed::extractObject(exec, args, 0, 0); + QWidget *parent = KJSEmbed::extractObject(exec, args, 0, nullptr); QString caption = KJSEmbed::extractVariant(exec, args, 1, QString()); QString dir = KJSEmbed::extractVariant(exec, args, 2, QString()); QString filter = KJSEmbed::extractVariant(exec, args, 3, QString()); // QString *selectedFilter = KJSEmbed::extractVariant(exec, args, 4, 0); QFileDialog::Options options = (QFileDialog::Options)KJSEmbed::extractVariant(exec, args, 4, 0); - return KJS::jsString(QFileDialog::getSaveFileName(parent, caption, dir, filter, 0, options)); + return KJS::jsString(QFileDialog::getSaveFileName(parent, caption, dir, filter, nullptr, options)); } const Method FileDialog::FileDialogMethods[] = { {"getExistingDirectory", 1, KJS::DontDelete | KJS::ReadOnly, &callGetExistingDirectory }, {"getOpenFileName", 1, KJS::DontDelete | KJS::ReadOnly, &callGetOpenFileName }, {"getOpenFileNames", 1, KJS::DontDelete | KJS::ReadOnly, &callGetOpenFileNames }, {"getSaveFileName", 0, KJS::DontDelete | KJS::ReadOnly, &callGetSaveFileName }, - {0, 0, 0, 0 } + {nullptr, 0, 0, nullptr } }; diff --git a/src/kjsembed/font.cpp b/src/kjsembed/font.cpp index c408dca..a0fcec2 100644 --- a/src/kjsembed/font.cpp +++ b/src/kjsembed/font.cpp @@ -1,350 +1,350 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "font.h" #include #include #include using namespace KJSEmbed; -const KJS::ClassInfo FontBinding::info = { "QFont", &VariantBinding::info, 0, 0 }; +const KJS::ClassInfo FontBinding::info = { "QFont", &VariantBinding::info, nullptr, nullptr }; FontBinding::FontBinding(KJS::ExecState *exec, const QFont &value) : VariantBinding(exec, value) { StaticBinding::publish(exec, this, Font::methods()); StaticBinding::publish(exec, this, VariantFactory::methods()); } namespace FontNS { START_VARIANT_METHOD(callbold, QFont) bool cppValue = value.bold(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callexactMatch, QFont) bool cppValue = value.exactMatch(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callfamily, QFont) QString cppValue = value.family(); result = KJS::jsString(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callfixedPitch, QFont) bool cppValue = value.fixedPitch(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callfromString, QFont) QString arg0 = KJSEmbed::extractQString(exec, args, 0); bool cppValue = value.fromString(arg0); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callinsertSubstitution, QFont) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QString arg1 = KJSEmbed::extractQString(exec, args, 1); value.insertSubstitution(arg0, arg1); END_VARIANT_METHOD START_VARIANT_METHOD(callinsertSubstitutions, QFont) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QStringList arg1 = KJSEmbed::extractQStringList(exec, args, 1); value.insertSubstitutions(arg0, arg1); END_VARIANT_METHOD START_VARIANT_METHOD(callisCopyOf, QFont) QFont arg0 = KJSEmbed::extractVariant(exec, args, 0); bool cppValue = value.isCopyOf(arg0); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callitalic, QFont) bool cppValue = value.italic(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callkerning, QFont) bool cppValue = value.kerning(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callkey, QFont) QString cppValue = value.key(); result = KJS::jsString(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calllastResortFamily, QFont) QString cppValue = value.lastResortFamily(); result = KJS::jsString(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calllastResortFont, QFont) QString cppValue = value.lastResortFont(); result = KJS::jsString(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calloverline, QFont) bool cppValue = value.overline(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callpixelSize, QFont) int cppValue = value.pixelSize(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callpointSize, QFont) int cppValue = value.pointSize(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callrawMode, QFont) bool cppValue = value.rawMode(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callrawName, QFont) QString cppValue = value.rawName(); result = KJS::jsString(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callremoveSubstitution, QFont) QString arg0 = KJSEmbed::extractQString(exec, args, 0); value.removeSubstitution(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callresolve, QFont) QFont arg0 = KJSEmbed::extractVariant(exec, args, 0); QFont cppValue = value.resolve(arg0); result = KJSEmbed::createVariant(exec, "QFont", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsetBold, QFont) bool arg0 = KJSEmbed::extractBool(exec, args, 0); value.setBold(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetFamily, QFont) QString arg0 = KJSEmbed::extractQString(exec, args, 0); value.setFamily(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetFixedPitch, QFont) bool arg0 = KJSEmbed::extractBool(exec, args, 0); value.setFixedPitch(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetItalic, QFont) bool arg0 = KJSEmbed::extractBool(exec, args, 0); value.setItalic(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetKerning, QFont) bool arg0 = KJSEmbed::extractBool(exec, args, 0); value.setKerning(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetOverline, QFont) bool arg0 = KJSEmbed::extractBool(exec, args, 0); value.setOverline(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetPixelSize, QFont) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setPixelSize(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetPointSize, QFont) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setPointSize(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetRawMode, QFont) bool arg0 = KJSEmbed::extractBool(exec, args, 0); value.setRawMode(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetRawName, QFont) QString arg0 = KJSEmbed::extractQString(exec, args, 0); value.setRawName(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetStretch, QFont) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setStretch(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetStrikeOut, QFont) bool arg0 = KJSEmbed::extractBool(exec, args, 0); value.setStrikeOut(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetStyle, QFont) QFont::Style arg0 = (QFont::Style) KJSEmbed::extractInt(exec, args, 0); value.setStyle(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetStyleHint, QFont) QFont::StyleHint arg0 = (QFont::StyleHint) KJSEmbed::extractInt(exec, args, 0); QFont::StyleStrategy arg1 = (QFont::StyleStrategy) KJSEmbed::extractInt(exec, args, 1); value.setStyleHint(arg0, arg1); END_VARIANT_METHOD START_VARIANT_METHOD(callsetStyleStrategy, QFont) QFont::StyleStrategy arg0 = (QFont::StyleStrategy) KJSEmbed::extractInt(exec, args, 0); value.setStyleStrategy(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetUnderline, QFont) bool arg0 = KJSEmbed::extractBool(exec, args, 0); value.setUnderline(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetWeight, QFont) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setWeight(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callstretch, QFont) int cppValue = value.stretch(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callstrikeOut, QFont) bool cppValue = value.strikeOut(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callstyle, QFont) QFont::Style cppValue = value.style(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callstyleHint, QFont) QFont::StyleHint cppValue = value.styleHint(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callstyleStrategy, QFont) QFont::StyleStrategy cppValue = value.styleStrategy(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsubstitute, QFont) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QString cppValue = value.substitute(arg0); result = KJS::jsString(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsubstitutes, QFont) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QStringList cppValue = value.substitutes(arg0); result = KJSEmbed::createQStringList(exec, cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsubstitutions, QFont) QStringList cppValue = value.substitutions(); result = KJSEmbed::createQStringList(exec, cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calltoString, QFont) QString cppValue = value.toString(); result = KJS::jsString(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callunderline, QFont) bool cppValue = value.underline(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callweight, QFont) int cppValue = value.weight(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD } START_METHOD_LUT(Font) {"bold", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callbold}, {"exactMatch", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callexactMatch}, {"family", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callfamily}, {"fixedPitch", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callfixedPitch}, {"fromString", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callfromString}, {"insertSubstitution", 1, KJS::DontDelete | KJS::ReadOnly, &FontNS::callinsertSubstitution}, {"insertSubstitutions", 1, KJS::DontDelete | KJS::ReadOnly, &FontNS::callinsertSubstitutions}, {"isCopyOf", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callisCopyOf}, {"italic", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callitalic}, {"kerning", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callkerning}, {"key", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callkey}, {"lastResortFamily", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::calllastResortFamily}, {"lastResortFont", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::calllastResortFont}, {"overline", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::calloverline}, {"pixelSize", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callpixelSize}, {"pointSize", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callpointSize}, {"rawMode", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callrawMode}, {"rawName", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callrawName}, {"removeSubstitution", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callremoveSubstitution}, {"resolve", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callresolve}, {"setBold", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetBold}, {"setFamily", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetFamily}, {"setFixedPitch", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetFixedPitch}, {"setItalic", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetItalic}, {"setKerning", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetKerning}, {"setOverline", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetOverline}, {"setPixelSize", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetPixelSize}, {"setPointSize", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetPointSize}, {"setRawMode", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetRawMode}, {"setRawName", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetRawName}, {"setStretch", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetStretch}, {"setStrikeOut", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetStrikeOut}, {"setStyle", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetStyle}, {"setStyleHint", 1, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetStyleHint}, {"setStyleStrategy", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetStyleStrategy}, {"setUnderline", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetUnderline}, {"setWeight", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsetWeight}, {"stretch", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callstretch}, {"strikeOut", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callstrikeOut}, {"style", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callstyle}, {"styleHint", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callstyleHint}, {"styleStrategy", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callstyleStrategy}, {"substitute", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsubstitute}, {"substitutes", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsubstitutes}, {"substitutions", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callsubstitutions}, {"toString", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::calltoString}, {"underline", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callunderline}, {"weight", 0, KJS::DontDelete | KJS::ReadOnly, &FontNS::callweight} END_METHOD_LUT NO_ENUMS(Font) NO_STATICS(Font) START_CTOR(Font, QFont, 0) if (args.size() == 0) { return new KJSEmbed::FontBinding(exec, QFont()); } return new KJSEmbed::FontBinding(exec, QFont()); END_CTOR diff --git a/src/kjsembed/image.cpp b/src/kjsembed/image.cpp index b7b275a..5ea9259 100644 --- a/src/kjsembed/image.cpp +++ b/src/kjsembed/image.cpp @@ -1,346 +1,346 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "image.h" #include "variant_binding.h" #include "object_binding.h" #include #include #include #include using namespace KJSEmbed; -const KJS::ClassInfo ImageBinding::info = { "QImage", &VariantBinding::info, 0, 0 }; +const KJS::ClassInfo ImageBinding::info = { "QImage", &VariantBinding::info, nullptr, nullptr }; ImageBinding::ImageBinding(KJS::ExecState *exec, const QImage &value) : VariantBinding(exec, value) { StaticBinding::publish(exec, this, VariantFactory::methods()); StaticBinding::publish(exec, this, Image::methods()); } namespace ImageNS { START_VARIANT_METHOD(callallGray, QImage) bool cppValue = value.allGray(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callalphaChannel, QImage) QImage cppValue = value.alphaChannel(); result = KJSEmbed::createVariant(exec, "QImage", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callcopy, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); QImage cppValue = value.copy(arg0, arg1, arg2, arg3); result = KJSEmbed::createVariant(exec, "QImage", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callcreateAlphaMask, QImage) Qt::ImageConversionFlags arg0 = (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 0); QImage cppValue = value.createAlphaMask(arg0); result = KJSEmbed::createVariant(exec, "QImage", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callcreateHeuristicMask, QImage) bool arg0 = KJSEmbed::extractBool(exec, args, 0); QImage cppValue = value.createHeuristicMask(arg0); result = KJSEmbed::createVariant(exec, "QImage", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calldepth, QImage) int cppValue = value.depth(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calldevType, QImage) int cppValue = value.devType(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calldotsPerMeterX, QImage) int cppValue = value.dotsPerMeterX(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calldotsPerMeterY, QImage) int cppValue = value.dotsPerMeterY(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callfill, QImage) uint arg0 = KJSEmbed::extractVariant(exec, args, 0); value.fill(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callhasAlphaChannel, QImage) bool cppValue = value.hasAlphaChannel(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callheight, QImage) int cppValue = value.height(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callinvertPixels, QImage) QImage::InvertMode arg0 = (QImage::InvertMode)KJSEmbed::extractInt(exec, args, 0); value.invertPixels(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callisGrayscale, QImage) bool cppValue = value.isGrayscale(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callisNull, QImage) bool cppValue = value.isNull(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callload, QImage) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QByteArray arg1 = KJSEmbed::extractQString(exec, args, 1).toLatin1(); bool cppValue = value.load(arg0, arg1); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callmirrored, QImage) bool arg0 = KJSEmbed::extractBool(exec, args, 0); bool arg1 = KJSEmbed::extractBool(exec, args, 1); QImage cppValue = value.mirrored(arg0, arg1); result = KJSEmbed::createVariant(exec, "QImage", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callnumBytes, QImage) int cppValue = value.byteCount(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callnumColors, QImage) int cppValue = value.colorCount(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calloffset, QImage) QPoint cppValue = value.offset(); result = KJSEmbed::createVariant(exec, "QPoint", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callpixel, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); QRgb cppValue = value.pixel(arg0, arg1); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callpixelIndex, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int cppValue = value.pixelIndex(arg0, arg1); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callrect, QImage) QRect cppValue = value.rect(); result = KJSEmbed::createVariant(exec, "QRect", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callrgbSwapped, QImage) QImage cppValue = value.rgbSwapped(); result = KJSEmbed::createVariant(exec, "QImage", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsave, QImage) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QByteArray arg1 = KJSEmbed::extractQString(exec, args, 1).toLatin1(); int arg2 = KJSEmbed::extractInt(exec, args, 2); bool cppValue = value.save(arg0, arg1, arg2); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callscaled, QImage) if (args.size() == 3) { QSize arg0 = KJSEmbed::extractVariant(exec, args, 0); Qt::AspectRatioMode arg1 = (Qt::AspectRatioMode)KJSEmbed::extractInt(exec, args, 1); Qt::TransformationMode arg2 = (Qt::TransformationMode)KJSEmbed::extractInt(exec, args, 2); QImage cppValue = value.scaled(arg0, arg1, arg2); result = KJSEmbed::createVariant(exec, "QImage", cppValue); } else if (args.size() == 4) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); Qt::AspectRatioMode arg2 = (Qt::AspectRatioMode)KJSEmbed::extractInt(exec, args, 2); Qt::TransformationMode arg3 = (Qt::TransformationMode)KJSEmbed::extractInt(exec, args, 3); QImage cppValue = value.scaled(arg0, arg1, arg2, arg3); result = KJSEmbed::createVariant(exec, "QImage", cppValue); } END_VARIANT_METHOD START_VARIANT_METHOD(callscaledToHeight, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); Qt::TransformationMode arg1 = (Qt::TransformationMode)KJSEmbed::extractInt(exec, args, 1); QImage cppValue = value.scaledToHeight(arg0, arg1); result = KJSEmbed::createVariant(exec, "QImage", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callscaledToWidth, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); Qt::TransformationMode arg1 = (Qt::TransformationMode)KJSEmbed::extractInt(exec, args, 1); QImage cppValue = value.scaledToWidth(arg0, arg1); result = KJSEmbed::createVariant(exec, "QImage", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callserialNumber, QImage) int cppValue = value.serialNumber(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsetAlphaChannel, QImage) QImage arg0 = KJSEmbed::extractVariant(exec, args, 0); value.setAlphaChannel(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetColor, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); QRgb arg1 = (QRgb)KJSEmbed::extractInt(exec, args, 1); value.setColor(arg0, arg1); END_VARIANT_METHOD START_VARIANT_METHOD(callsetDotsPerMeterX, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setDotsPerMeterX(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetDotsPerMeterY, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setDotsPerMeterY(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetNumColors, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setColorCount(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetOffset, QImage) QPoint arg0 = KJSEmbed::extractVariant(exec, args, 0); value.setOffset(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetPixel, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); uint arg2 = KJSEmbed::extractVariant(exec, args, 2); value.setPixel(arg0, arg1, arg2); END_VARIANT_METHOD START_VARIANT_METHOD(callsize, QImage) QSize cppValue = value.size(); result = KJSEmbed::createVariant(exec, "QSize", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callvalid, QImage) int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); bool cppValue = value.valid(arg0, arg1); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callwidth, QImage) int cppValue = value.width(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD } START_METHOD_LUT(Image) {"allGray", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callallGray}, {"alphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callalphaChannel}, {"copy", 4, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callcopy}, {"createAlphaMask", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callcreateAlphaMask}, {"createHeuristicMask", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callcreateHeuristicMask}, {"depth", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::calldepth}, {"dotsPerMeterX", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::calldotsPerMeterX}, {"dotsPerMeterY", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::calldotsPerMeterY}, {"fill", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callfill}, {"hasAlphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callhasAlphaChannel}, {"height", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callheight}, {"invertPixels", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callinvertPixels}, {"isGrayscale", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callisGrayscale}, {"isNull", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callisNull}, {"load", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callload}, {"mirrored", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callmirrored}, {"numBytes", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callnumBytes}, {"numColors", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callnumColors}, {"offset", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::calloffset}, {"pixel", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callpixel}, {"pixelIndex", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callpixelIndex}, {"rect", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callrect}, {"rgbSwapped", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callrgbSwapped}, {"save", 2, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsave}, {"scaled", 3, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callscaled}, {"scaledToHeight", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callscaledToHeight}, {"scaledToWidth", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callscaledToWidth}, {"serialNumber", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callserialNumber}, {"setAlphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetAlphaChannel}, {"setColor", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetColor}, {"setDotsPerMeterX", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetDotsPerMeterX}, {"setDotsPerMeterY", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetDotsPerMeterY}, {"setNumColors", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetNumColors}, {"setOffset", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetOffset}, {"setPixel", 2, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsetPixel}, {"size", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callsize}, {"valid", 1, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callvalid}, {"width", 0, KJS::DontDelete | KJS::ReadOnly, &ImageNS::callwidth} END_METHOD_LUT NO_ENUMS(Image) NO_STATICS(Image) START_CTOR(Image, QImage, 0) if (args.size() == 0) { return new KJSEmbed::ImageBinding(exec, QImage()); } if (args.size() == 1) { return new KJSEmbed::ImageBinding(exec, QImage(KJSEmbed::extractQString(exec, args, 0))); } else if (args.size() == 2) { return new KJSEmbed::ImageBinding(exec, QImage(KJSEmbed::extractVariant(exec, args, 0), (QImage::Format)KJSEmbed::extractInt(exec, args, 1))); } else if (args.size() == 3) { return new KJSEmbed::ImageBinding(exec, QImage(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1), (QImage::Format)KJSEmbed::extractInt(exec, args, 2))); } return new KJSEmbed::ImageBinding(exec, QImage()); END_CTOR diff --git a/src/kjsembed/iosupport.cpp b/src/kjsembed/iosupport.cpp index aa036e2..2c70f22 100644 --- a/src/kjsembed/iosupport.cpp +++ b/src/kjsembed/iosupport.cpp @@ -1,86 +1,86 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "iosupport.h" #include "static_binding.h" #include "kjseglobal.h" #include #include #include #include using namespace KJSEmbed; KJS::JSValue *callPrint(KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args) { (*KJSEmbed::conout()) << toQString(args[0]->toString(exec)); return KJS::jsNull(); } KJS::JSValue *callPrintLn(KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args) { (*KJSEmbed::conout()) << toQString(args[0]->toString(exec)) << endl; return KJS::jsNull(); } KJS::JSValue *callDebug(KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args) { //(*KJSEmbed::conerr()) << "Debug: " << toQString(args[0]->toString(exec)) << endl; qDebug() << "Debug: " << toQString(args[0]->toString(exec)); return KJS::jsNull(); } KJS::JSValue *callReadLine(KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args) { Q_UNUSED(exec); Q_UNUSED(args); QString line = conin()->readLine(); return KJS::jsString(line); } KJS::JSValue *callSystem(KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args) { QProcess systemProcess; QStringList processArgs = toQString(args[0]->toString(exec)).split(' '); QString app = processArgs[0]; processArgs.pop_front(); systemProcess.start(app, processArgs); if (!systemProcess.waitForStarted()) { return KJS::throwError(exec, KJS::GeneralError, "Application could not start."); } if (!systemProcess.waitForFinished()) { return KJS::throwError(exec, KJS::GeneralError, "Application crashed."); } return KJS::jsString(systemProcess.readAll().data()); } const Method IoFactory::IoMethods[] = { {"debug", 1, KJS::DontDelete | KJS::ReadOnly, &callDebug }, {"print", 1, KJS::DontDelete | KJS::ReadOnly, &callPrint }, {"println", 1, KJS::DontDelete | KJS::ReadOnly, &callPrintLn }, {"readln", 0, KJS::DontDelete | KJS::ReadOnly, &callReadLine }, {"system", 1, KJS::DontDelete | KJS::ReadOnly, &callSystem }, - {0, 0, 0, 0 } + {nullptr, 0, 0, nullptr } }; diff --git a/src/kjsembed/jseventmapper.cpp b/src/kjsembed/jseventmapper.cpp index 0ab699c..23f0ab8 100644 --- a/src/kjsembed/jseventmapper.cpp +++ b/src/kjsembed/jseventmapper.cpp @@ -1,297 +1,297 @@ /* This file is part of the KDE libraries Copyright (C) 2001,2002,2003,2004,2005,2006 Ian Reinhart Geiser Copyright (C) 2001,2002,2003,2004,2005,2006 Matt Broadstone Copyright (C) 2001,2002,2003,2004,2005,2006 Richard J. Moore Copyright (C) 2001,2002,2003,2004,2005,2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "jseventmapper.h" #include "kjseglobal.h" namespace KJSEmbed { -JSEventMapper *JSEventMapper::m_inst = 0; +JSEventMapper *JSEventMapper::m_inst = nullptr; /** Used internally for the event handler table. */ struct EventType { EventType(KJS::Identifier _id, QEvent::Type _type) : id(_id), type(_type) { ; } const KJS::Identifier id; const QEvent::Type type; }; /* Qt4 events as of Qt 4.0 None = 0, // invalid event Timer = 1, // timer event MouseButtonPress = 2, // mouse button pressed MouseButtonRelease = 3, // mouse button released MouseButtonDblClick = 4, // mouse button double click MouseMove = 5, // mouse move KeyPress = 6, // key pressed KeyRelease = 7, // key released FocusIn = 8, // keyboard focus received FocusOut = 9, // keyboard focus lost Enter = 10, // mouse enters widget Leave = 11, // mouse leaves widget Paint = 12, // paint widget Move = 13, // move widget Resize = 14, // resize widget Create = 15, // after widget creation Destroy = 16, // during widget destruction Show = 17, // widget is shown Hide = 18, // widget is hidden Close = 19, // request to close widget Quit = 20, // request to quit application ParentChange = 21, // widget has been reparented ParentAboutToChange = 131, // sent just before the parent change is done ThreadChange = 22, // object has changed threads WindowActivate = 24, // window was activated WindowDeactivate = 25, // window was deactivated ShowToParent = 26, // widget is shown to parent HideToParent = 27, // widget is hidden to parent Wheel = 31, // wheel event WindowTitleChange = 33, // window title changed WindowIconChange = 34, // icon changed ApplicationWindowIconChange = 35, // application icon changed ApplicationFontChange = 36, // application font changed ApplicationLayoutDirectionChange = 37, // application layout direction changed ApplicationPaletteChange = 38, // application palette changed PaletteChange = 39, // widget palette changed Clipboard = 40, // internal clipboard event Speech = 42, // reserved for speech input MetaCall = 43, // meta call event SockAct = 50, // socket activation WinEventAct = 123, // win event activation DeferredDelete = 52, // deferred delete event DragEnter = 60, // drag moves into widget DragMove = 61, // drag moves in widget DragLeave = 62, // drag leaves or is canceled Drop = 63, // actual drop DragResponse = 64, // drag accepted/rejected ChildAdded = 68, // new child widget ChildPolished = 69, // polished child widget ChildRemoved = 71, // deleted child widget ShowWindowRequest = 73, // widget's window should be mapped PolishRequest = 74, // widget should be polished Polish = 75, // widget is polished LayoutRequest = 76, // widget should be relayouted UpdateRequest = 77, // widget should be repainted EmbeddingControl = 79, // ActiveX embedding ActivateControl = 80, // ActiveX activation DeactivateControl = 81, // ActiveX deactivation ContextMenu = 82, // context popup menu InputMethod = 83, // input method AccessibilityPrepare = 86, // accessibility information is requested TabletMove = 87, // Wacom tablet event LocaleChange = 88, // the system locale changed LanguageChange = 89, // the application language changed LayoutDirectionChange = 90, // the layout direction changed Style = 91, // internal style event TabletPress = 92, // tablet press TabletRelease = 93, // tablet release OkRequest = 94, // CE (Ok) button pressed HelpRequest = 95, // CE (?) button pressed IconDrag = 96, // proxy icon dragged FontChange = 97, // font has changed EnabledChange = 98, // enabled state has changed ActivationChange = 99, // window activation has changed StyleChange = 100, // style has changed IconTextChange = 101, // icon text has changed ModifiedChange = 102, // modified state has changed MouseTrackingChange = 109, // mouse tracking state has changed WindowBlocked = 103, // window is about to be blocked modally WindowUnblocked = 104, // windows modal blocking has ended WindowStateChange = 105, ToolTip = 110, WhatsThis = 111, StatusTip = 112, ActionChanged = 113, ActionAdded = 114, ActionRemoved = 115, FileOpen = 116, // file open request Shortcut = 117, // shortcut triggered ShortcutOverride = 51, // shortcut override request WhatsThisClicked = 118, ToolBarChange = 120, // toolbar visibility toggled ApplicationActivated = 121, // application has been changed to active ApplicationDeactivated = 122, // application has been changed to inactive QueryWhatsThis = 123, // query what's this widget help EnterWhatsThisMode = 124, LeaveWhatsThisMode = 125, ZOrderChange = 126, // child widget has had its z-order changed HoverEnter = 127, // mouse cursor enters a hover widget HoverLeave = 128, // mouse cursor leaves a hover widget HoverMove = 129, // mouse cursor move inside a hover widget AccessibilityHelp = 119, // accessibility help text request AccessibilityDescription = 130 */ static EventType events[] = { EventType(KJS::Identifier("onTimerEvent"), QEvent::Timer), EventType(KJS::Identifier("onMouseButtonPressEvent"), QEvent::MouseButtonPress), EventType(KJS::Identifier("onMouseButtonReleaseEvent"), QEvent::MouseButtonRelease), EventType(KJS::Identifier("onMouseButtonDblClickEvent"), QEvent::MouseButtonDblClick), EventType(KJS::Identifier("onMouseMoveEvent"), QEvent::MouseMove), EventType(KJS::Identifier("onKeyPressEvent"), QEvent::KeyPress), EventType(KJS::Identifier("onKeyReleaseEvent"), QEvent::KeyRelease), EventType(KJS::Identifier("onFocusInEvent"), QEvent::FocusIn), EventType(KJS::Identifier("onFocusOutEvent"), QEvent::FocusOut), EventType(KJS::Identifier("onEnterEvent"), QEvent::Enter), EventType(KJS::Identifier("onLeaveEvent"), QEvent::Leave), EventType(KJS::Identifier("onPaintEvent"), QEvent::Paint), EventType(KJS::Identifier("onMoveEvent"), QEvent::Move), EventType(KJS::Identifier("onResizeEvent"), QEvent::Resize), EventType(KJS::Identifier("onCreateEvent"), QEvent::Create), EventType(KJS::Identifier("onDestroyEvent"), QEvent::Destroy), EventType(KJS::Identifier("onShowEvent"), QEvent::Show), EventType(KJS::Identifier("onHideEvent"), QEvent::Hide), EventType(KJS::Identifier("onCloseEvent"), QEvent::Close), EventType(KJS::Identifier("onQuitEvent"), QEvent::Quit), EventType(KJS::Identifier("onParentChangeEvent"), QEvent::ParentChange), EventType(KJS::Identifier("onParentAboutToChangeEvent"), QEvent::ParentAboutToChange), EventType(KJS::Identifier("onThreadChangeEvent"), QEvent::ThreadChange), EventType(KJS::Identifier("onWindowActivateEvent"), QEvent::WindowActivate), EventType(KJS::Identifier("onWindowDeactivateEvent"), QEvent::WindowDeactivate), EventType(KJS::Identifier("onShowToParentEvent"), QEvent::ShowToParent), EventType(KJS::Identifier("onHideToParentEvent"), QEvent::HideToParent), EventType(KJS::Identifier("onWheelEvent"), QEvent::Wheel), EventType(KJS::Identifier("onWindowTitleChangeEvent"), QEvent::WindowTitleChange), EventType(KJS::Identifier("onWindowIconChangeEvent"), QEvent::WindowIconChange), EventType(KJS::Identifier("onApplicationWindowIconChangeEvent"), QEvent::ApplicationWindowIconChange), EventType(KJS::Identifier("onApplicationFontChangeEvent"), QEvent::ApplicationFontChange), EventType(KJS::Identifier("onApplicationLayoutDirectionChangeEvent"), QEvent::ApplicationLayoutDirectionChange), EventType(KJS::Identifier("onApplicationPaletteChangeEvent"), QEvent::ApplicationPaletteChange), EventType(KJS::Identifier("onPaletteChangeEvent"), QEvent::PaletteChange), EventType(KJS::Identifier("onClipboardEvent"), QEvent::Clipboard), EventType(KJS::Identifier("onSpeechEvent"), QEvent::Speech), EventType(KJS::Identifier("onMetaCallEvent"), QEvent::MetaCall), EventType(KJS::Identifier("onSockActEvent"), QEvent::SockAct), EventType(KJS::Identifier("onWinEventActEvent"), QEvent::WinEventAct), EventType(KJS::Identifier("onDeferredDeleteEvent"), QEvent::DeferredDelete), EventType(KJS::Identifier("onDragEnterEvent"), QEvent::DragEnter), EventType(KJS::Identifier("onDragMoveEvent"), QEvent::DragMove), EventType(KJS::Identifier("onDragLeaveEvent"), QEvent::DragLeave), EventType(KJS::Identifier("onDropEvent"), QEvent::Drop), EventType(KJS::Identifier("onDragResponseEvent"), QEvent::DragResponse), EventType(KJS::Identifier("onChildAddedEvent"), QEvent::ChildAdded), EventType(KJS::Identifier("onChildPolishedEvent"), QEvent::ChildRemoved), EventType(KJS::Identifier("onShowWindowRequestEvent"), QEvent::ShowWindowRequest), EventType(KJS::Identifier("onPolishRequestEvent"), QEvent::PolishRequest), EventType(KJS::Identifier("onPolishEvent"), QEvent::Polish), EventType(KJS::Identifier("onLayoutRequestEvent"), QEvent::LayoutRequest), EventType(KJS::Identifier("onUpdateRequestEvent"), QEvent::UpdateRequest), EventType(KJS::Identifier("onEmbeddingControlEvent"), QEvent::EmbeddingControl), EventType(KJS::Identifier("onActivateControlEvent"), QEvent::ActivateControl), EventType(KJS::Identifier("onDeactivateControlEvent"), QEvent::DeactivateControl), EventType(KJS::Identifier("onContextMenuEvent"), QEvent::ContextMenu), EventType(KJS::Identifier("onInputMethodEvent"), QEvent::InputMethod), EventType(KJS::Identifier("onTabletMoveEvent"), QEvent::TabletMove), EventType(KJS::Identifier("onLocaleChangeEvent"), QEvent::LocaleChange), EventType(KJS::Identifier("onLanguageChangeEvent"), QEvent::LanguageChange), EventType(KJS::Identifier("onLayoutDirectionChangeEvent"), QEvent::LayoutDirectionChange), EventType(KJS::Identifier("onStyleEvent"), QEvent::Style), EventType(KJS::Identifier("onTabletPressEvent"), QEvent::TabletPress), EventType(KJS::Identifier("onTabletReleaseEvent"), QEvent::TabletRelease), EventType(KJS::Identifier("onOkRequestEvent"), QEvent::OkRequest), EventType(KJS::Identifier("onHelpRequestEvent"), QEvent::HelpRequest), EventType(KJS::Identifier("onIconDragEvent"), QEvent::IconDrag), EventType(KJS::Identifier("onFontChangeEvent"), QEvent::FontChange), EventType(KJS::Identifier("onEnabledChangeEvent"), QEvent::EnabledChange), EventType(KJS::Identifier("onActivationChangeEvent"), QEvent::ActivationChange), EventType(KJS::Identifier("onStyleChangeEvent"), QEvent::StyleChange), EventType(KJS::Identifier("onIconTextChangeEvent"), QEvent::IconTextChange), EventType(KJS::Identifier("onModifiedChangeEvent"), QEvent::ModifiedChange), EventType(KJS::Identifier("onMouseTrackingChangeEvent"), QEvent::MouseTrackingChange), EventType(KJS::Identifier("onWindowBlockedEvent"), QEvent::WindowBlocked), EventType(KJS::Identifier("onWindowUnblockedEvent"), QEvent::WindowUnblocked), EventType(KJS::Identifier("onWindowStateChangeEvent"), QEvent::WindowStateChange), EventType(KJS::Identifier("onToolTipEvent"), QEvent::ToolTip), EventType(KJS::Identifier("onWhatsThisEvent"), QEvent::WhatsThis), EventType(KJS::Identifier("onStatusTipEvent"), QEvent::StatusTip), EventType(KJS::Identifier("onActionChangedEvent"), QEvent::ActionChanged), EventType(KJS::Identifier("onActionAddedEvent"), QEvent::ActionAdded), EventType(KJS::Identifier("onActionRemovedEvent"), QEvent::ActionRemoved), EventType(KJS::Identifier("onFileOpenEvent"), QEvent::FileOpen), EventType(KJS::Identifier("onShortcutEvent"), QEvent::Shortcut), EventType(KJS::Identifier("onShortcutOverrideEvent"), QEvent::ShortcutOverride), EventType(KJS::Identifier("onWhatsThisClickedEvent"), QEvent::WhatsThisClicked), EventType(KJS::Identifier("onToolBarChangeEvent"), QEvent::ToolBarChange), EventType(KJS::Identifier("onApplicationActivatedEvent"), QEvent::ApplicationActivated), EventType(KJS::Identifier("onApplicationDeactivatedEvent"), QEvent::ApplicationDeactivated), EventType(KJS::Identifier("onQueryWhatsThisEvent"), QEvent::QueryWhatsThis), EventType(KJS::Identifier("onEnterWhatsThisModeEvent"), QEvent::EnterWhatsThisMode), EventType(KJS::Identifier("onLeaveWhatsThisModeEvent"), QEvent::LeaveWhatsThisMode), EventType(KJS::Identifier("onZOrderChangeEvent"), QEvent::ZOrderChange), EventType(KJS::Identifier("onHoverEnterEvent"), QEvent::HoverEnter), EventType(KJS::Identifier("onHoverLeaveEvent"), QEvent::HoverLeave), EventType(KJS::Identifier("onHoverMoveEvent"), QEvent::HoverMove), EventType(KJS::Identifier(), QEvent::None) }; JSEventMapper::JSEventMapper() { int i = 0; do { addEvent(events[i].id, events[i].type); i++; } while (events[i].type != QEvent::None); } JSEventMapper::~JSEventMapper() { } void JSEventMapper::addEvent(const KJS::Identifier &name, QEvent::Type t) { m_handlerToEvent[ toQString(name) ] = t; m_eventToHandler[ t ] = name; } QEvent::Type JSEventMapper::findEventType(const KJS::Identifier &name) const { return m_handlerToEvent[ toQString(name) ]; } bool JSEventMapper::isEventHandler(const KJS::Identifier &name) const { return m_handlerToEvent.contains(toQString(name)); } KJS::Identifier JSEventMapper::findEventHandler(QEvent::Type t) const { return m_eventToHandler[t]; } JSEventMapper *JSEventMapper::mapper() { if (m_inst) { return m_inst; } m_inst = new JSEventMapper(); return m_inst; } } // namespace KJSEmbed // Local Variables: // End: diff --git a/src/kjsembed/kjseglobal.cpp b/src/kjsembed/kjseglobal.cpp index 03d22a1..e0dbdb1 100644 --- a/src/kjsembed/kjseglobal.cpp +++ b/src/kjsembed/kjseglobal.cpp @@ -1,152 +1,152 @@ /* This file is part of the KDE libraries Copyright (C) 2004, 2005, 2006 Ian Reinhart Geiser Copyright (C) 2004, 2005, 2006 Matt Broadstone Copyright (C) 2004, 2005, 2006 Richard J. Moore Copyright (C) 2004, 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kjseglobal.h" #ifdef QT_ONLY # include # include #endif #if defined(_WIN32) || defined(_WIN64) # include # include # include # include # include # include #endif -static QTextStream *kjsembed_err = 0L; -static QTextStream *kjsembed_in = 0L; -static QTextStream *kjsembed_out = 0L; +static QTextStream *kjsembed_err = nullptr; +static QTextStream *kjsembed_in = nullptr; +static QTextStream *kjsembed_out = nullptr; #if defined(_WIN32) || defined(_WIN64) static QFile win32_stdin; static QFile win32_stdout; static QFile win32_stderr; static const WORD MAX_CONSOLE_LINES = 500; void RedirectIOToConsole() { int hConHandle; intptr_t lStdHandle; CONSOLE_SCREEN_BUFFER_INFO coninfo; AllocConsole(); GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo); coninfo.dwSize.Y = MAX_CONSOLE_LINES; SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize); lStdHandle = (intptr_t)GetStdHandle(STD_INPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); win32_stdin.open(hConHandle, QIODevice::ReadOnly); lStdHandle = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); win32_stdout.open(hConHandle, QIODevice::WriteOnly); lStdHandle = (intptr_t)GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); win32_stderr.open(hConHandle, QIODevice::WriteOnly); std::ios::sync_with_stdio(); } #endif QTextStream &consoleOut() { return *KJSEmbed::conout(); } QTextStream &consoleError() { return *KJSEmbed::conerr(); } QTextStream &consoleIn() { return *KJSEmbed::conin(); } #ifdef QT_ONLY QTextStream &kdDebug(int area) { #ifndef QT_DEBUG return consoleError() << "DEBUG: (" << area << ") "; #else return consoleOut(); #endif } QTextStream &kdWarning(int area) { return consoleOut() << "WARNING: (" << area << ") "; } QString i18n(const char *string) { return QCoreApplication::translate("KJSEmbed", string, "qjsembed string"); } #endif QTextStream *KJSEmbed::conin() { if (!kjsembed_in) { #ifdef _WIN32 kjsembed_in = new QTextStream(&win32_stdin); #else kjsembed_in = new QTextStream(stdin, QIODevice::ReadOnly); #endif } return kjsembed_in; } QTextStream *KJSEmbed::conout() { if (!kjsembed_out) { #ifdef _WIN32 kjsembed_out = new QTextStream(&win32_stdout); #else kjsembed_out = new QTextStream(stdout, QIODevice::WriteOnly); #endif } return kjsembed_out; } QTextStream *KJSEmbed::conerr() { if (!kjsembed_err) { #ifdef _WIN32 kjsembed_err = new QTextStream(&win32_stderr); #else kjsembed_err = new QTextStream(stderr, QIODevice::WriteOnly); #endif } return kjsembed_err; } diff --git a/src/kjsembed/kjsembed.cpp b/src/kjsembed/kjsembed.cpp index cfddae7..5e02fab 100644 --- a/src/kjsembed/kjsembed.cpp +++ b/src/kjsembed/kjsembed.cpp @@ -1,312 +1,312 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kjsembed.h" #include "binding_support.h" #include "qobject_binding.h" #include "variant_binding.h" #include "static_binding.h" #include "iosupport.h" #include "quiloader_binding.h" #ifdef KJSEMBED_FORMBUILDER_BINDING #include "qformbuilder_binding.h" #endif #include "qpainter_binding.h" #include "qwidget_binding.h" #include "qaction_binding.h" #include "qlayout_binding.h" #include "svg_binding.h" #include "filedialog_binding.h" #include "settings.h" #include "fileio.h" #include "color.h" #include "rect.h" #include "size.h" #include "point.h" #include "image.h" #include "pixmap.h" #include "brush.h" #include "pen.h" #include "font.h" #include "dom.h" #include "url.h" #include "application.h" #include "builtins.h" #include #include #include #include #include #include /** * Implement QString-KJS::UString conversion methods. These methods are declared * by KJS, but libkjs doesn't actually contain their implementations. * because we link against khtml , those functions are already implemented there. * */ namespace KJS { #ifndef QTONLY_WEBKIT UString::UString(const QString &d) { uint len = d.length(); UChar *dat = static_cast(fastMalloc(sizeof(UChar) * len)); memcpy(dat, d.unicode(), len * sizeof(UChar)); m_rep = UString::Rep::create(dat, len); } QString UString::qstring() const { return QString((QChar *) data(), size()); } QString Identifier::qstring() const { return QString((QChar *) data(), size()); } #endif } namespace KJSEmbed { class EnginePrivate { public: EnginePrivate() { m_interpreter = new KJS::Interpreter(); m_interpreter->initGlobalObject(); m_interpreter->ref(); } ~EnginePrivate() { m_interpreter->deref(); } KJS::Interpreter *m_interpreter; KJS::Completion m_currentResult; bool m_bindingsEnabled; }; void setup(KJS::ExecState *exec, KJS::JSObject *parent) { StaticBinding::publish(exec, parent, IoFactory::methods()); // Global methods StaticBinding::publish(exec, parent, FileDialog::methods()); // Global methods StaticBinding::publish(exec, parent, BuiltinsFactory::methods()); // Global methods StaticConstructor::add(exec, parent, FileIO::constructor()); // Ctor StaticConstructor::add(exec, parent, DomNode::constructor()); // Ctor StaticConstructor::add(exec, parent, DomDocument::constructor()); // Ctor StaticConstructor::add(exec, parent, DomElement::constructor()); // Ctor StaticConstructor::add(exec, parent, DomAttr::constructor()); // Ctor StaticConstructor::add(exec, parent, DomDocumentType::constructor()); // Ctor StaticConstructor::add(exec, parent, DomNodeList::constructor()); // Ctor StaticConstructor::add(exec, parent, DomNamedNodeMap::constructor()); // Ctor StaticConstructor::add(exec, parent, DomText::constructor()); // Ctor StaticConstructor::add(exec, parent, Url::constructor()); // Ctor StaticConstructor::add(exec, parent, SettingsBinding::constructor()); // Ctor StaticConstructor::add(exec, parent, CoreApplicationBinding::constructor()); StaticConstructor::add(exec, parent, Point::constructor()); // Ctor StaticConstructor::add(exec, parent, Size::constructor()); // Ctor StaticConstructor::add(exec, parent, Rect::constructor()); // Ctor StaticConstructor::add(exec, parent, Color::constructor()); // Ctor // check if this is a GUI application QApplication *app = ::qobject_cast(QCoreApplication::instance()); if (app) { //qDebug("Loading GUI Bindings"); #ifdef KJSEMBED_FORMBUILDER_BINDING StaticConstructor::add(exec, parent, FormBuilder::constructor()); // Ctor #endif StaticConstructor::add(exec, parent, UiLoaderBinding::constructor()); // Ctor StaticConstructor::add(exec, parent, QWidgetBinding::constructor()); // Ctor StaticConstructor::add(exec, parent, Layout::constructor()); // Ctor StaticConstructor::add(exec, parent, Action::constructor()); // Ctor StaticConstructor::add(exec, parent, ActionGroup::constructor()); // Ctor StaticConstructor::add(exec, parent, Font::constructor()); // Ctor StaticConstructor::add(exec, parent, Pen::constructor()); // Ctor StaticConstructor::add(exec, parent, Brush::constructor()); // Ctor StaticConstructor::add(exec, parent, Image::constructor()); // Ctor StaticConstructor::add(exec, parent, Pixmap::constructor()); // Ctor StaticConstructor::add(exec, parent, Painter::constructor()); // Ctor StaticConstructor::add(exec, parent, SvgRenderer::constructor()); // Ctor StaticConstructor::add(exec, parent, SvgWidget::constructor()); // Ctor StaticConstructor::add(exec, parent, ApplicationBinding::constructor()); } } Engine::Engine(bool enableBindings) { dptr = new EnginePrivate(); if (enableBindings) { setup(dptr->m_interpreter->globalExec(), dptr->m_interpreter->globalObject()); } dptr->m_bindingsEnabled = enableBindings; } Engine::~Engine() { delete dptr; } bool Engine::isBindingsEnabled() const { return dptr->m_bindingsEnabled; } KJS::JSObject *Engine::addObject(QObject *obj, KJS::JSObject *parent, const KJS::UString &name) const { KJS::ExecState *exec = dptr->m_interpreter->globalExec(); KJS::JSObject *returnObject = KJSEmbed::createQObject(exec, obj, KJSEmbed::ObjectBinding::CPPOwned); KJS::Identifier jsName(!name.isEmpty() ? name : toUString(obj->objectName())); parent->putDirect(jsName, returnObject, KJS::DontDelete | KJS::ReadOnly); return returnObject; } KJS::JSObject *Engine::addObject(QObject *obj, const KJS::UString &name) const { return addObject(obj, dptr->m_interpreter->globalObject(), name); } KJS::Completion Engine::completion() const { return dptr->m_currentResult; } KJS::Interpreter *Engine::interpreter() const { return dptr->m_interpreter; } KJS::Completion Engine::runFile(KJS::Interpreter *interpreter, const KJS::UString &fileName) { // qDebug() << "runFile: " << toQString(fileName); KJS::UString code; QFile file(toQString(fileName)); if (file.open(QFile::ReadOnly)) { QTextStream ts(&file); QString line; while (!ts.atEnd()) { line = ts.readLine(); if (line[0] != '#') { code += toUString(line + '\n'); } } file.close(); } else { code = "println('Could not open file.');"; qWarning() << "Could not open file " << toQString(fileName); } // qDebug() << "Loaded code: " << toQString(code); - return interpreter->evaluate(fileName, 0, code, 0); + return interpreter->evaluate(fileName, 0, code, nullptr); } Engine::ExitStatus Engine::runFile(const KJS::UString &fileName) { dptr->m_currentResult = runFile(dptr->m_interpreter, fileName); if (dptr->m_currentResult.complType() == KJS::Normal) { return Engine::Success; } else if (dptr->m_currentResult.complType() == KJS::ReturnValue) { return Engine::Success; } else { return Engine::Failure; } } Engine::ExitStatus Engine::execute(const KJS::UString &code) { - dptr->m_currentResult = dptr->m_interpreter->evaluate(KJS::UString(""), 0, code, 0); + dptr->m_currentResult = dptr->m_interpreter->evaluate(KJS::UString(""), 0, code, nullptr); if (dptr->m_currentResult.complType() == KJS::Normal) { return Engine::Success; } else if (dptr->m_currentResult.complType() == KJS::ReturnValue) { return Engine::Success; } else { return Engine::Failure; } } KJS::JSObject *Engine::construct(const KJS::UString &className, const KJS::List &args) const { KJS::JSObject *global = dptr->m_interpreter->globalObject(); KJS::ExecState *exec = dptr->m_interpreter->globalExec(); return StaticConstructor::construct(exec, global, className, args); } KJS::JSValue *Engine::callMethod(const KJS::UString &methodName, const KJS::List &args) { KJS::JSObject *global = dptr->m_interpreter->globalObject(); KJS::ExecState *exec = dptr->m_interpreter->globalExec(); KJS::Identifier id = KJS::Identifier(KJS::UString(methodName)); KJS::JSObject *fun = global->get(exec, id)->toObject(exec); KJS::JSValue *retValue; if (!fun->implementsCall()) { QString msg = i18n("%1 is not a function and cannot be called.", toQString(methodName)); return throwError(exec, KJS::TypeError, msg); } retValue = fun->call(exec, global, args); if (exec->hadException()) { return exec->exception(); } return retValue; } KJS::JSValue *Engine::callMethod(KJS::JSObject *parent, const KJS::UString &methodName, const KJS::List &args) { KJS::ExecState *exec = dptr->m_interpreter->globalExec(); KJS::Identifier id = KJS::Identifier(methodName); KJS::JSObject *fun = parent->get(exec, id)->toObject(exec); KJS::JSValue *retValue; if (!fun->implementsCall()) { QString msg = i18n("%1 is not a function and cannot be called.", toQString(methodName)); return throwError(exec, KJS::TypeError, msg); } retValue = fun->call(exec, parent, args); if (exec->hadException()) { return exec->exception(); } return retValue; } } // namespace KJS diff --git a/src/kjsembed/object_binding.cpp b/src/kjsembed/object_binding.cpp index e732c35..df2ebac 100644 --- a/src/kjsembed/object_binding.cpp +++ b/src/kjsembed/object_binding.cpp @@ -1,108 +1,108 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "object_binding.h" #include #include #include "static_binding.h" #include "variant_binding.h" using namespace KJSEmbed; -const KJS::ClassInfo ObjectBinding::info = { "ObjectBinding", 0, 0, 0 }; +const KJS::ClassInfo ObjectBinding::info = { "ObjectBinding", nullptr, nullptr, nullptr }; ObjectBinding::~ObjectBinding() { if (m_owner == JSOwned) { m_value->cleanup(); } delete m_value; } const char *ObjectBinding::typeName() const { return m_name; } KJS::UString ObjectBinding::toString(KJS::ExecState * /*exec*/) const { return KJS::UString(typeName()); } KJS::UString ObjectBinding::className() const { return KJS::UString(typeName()); } KJS::JSType ObjectBinding::type() const { return KJS::ObjectType; } ObjectBinding::Ownership ObjectBinding::ownership() const { return m_owner; } void ObjectBinding::setOwnership(ObjectBinding::Ownership owner) { m_owner = owner; } KJS::JSValue *callPointerName(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &/*args*/) { KJSEmbed::ObjectBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (imp) { return KJS::jsString(imp->typeName()); } return KJS::jsNull(); } KJS::JSValue *callPointerCast(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &/*args*/) { KJSEmbed::ObjectBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (imp) { return KJS::jsBoolean(false); } return KJS::jsNull(); } KJS::JSValue *callPointerToString(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &/*args*/) { KJSEmbed::ObjectBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (imp) { qDebug("Object to string"); return KJS::jsString(imp->typeName()); } return KJS::jsNull(); } const Method ObjectFactory::ObjectMethods[] = { {"type", 0, KJS::DontDelete | KJS::ReadOnly, &callPointerName }, {"cast", 1, KJS::DontDelete | KJS::ReadOnly, &callPointerCast }, {"toString", 0, KJS::DontDelete | KJS::ReadOnly, &callPointerToString }, - {0, 0, 0, 0 } + {nullptr, 0, 0, nullptr } }; diff --git a/src/kjsembed/object_binding.h b/src/kjsembed/object_binding.h index 8a1ff53..aaead61 100644 --- a/src/kjsembed/object_binding.h +++ b/src/kjsembed/object_binding.h @@ -1,260 +1,260 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OBJECT_BINDING_H #define OBJECT_BINDING_H #include "static_binding.h" #include "variant_binding.h" #include "pointer.h" #include "kjseglobal.h" /** * A simple pointer syle method. * This will extract the pointer, cast it to the native type and place it in "value". * Any data that should be returned from this method should be placed into "result"; * */ #define START_OBJECT_METHOD( METHODNAME, TYPE) \ KJS::JSValue *METHODNAME( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args ) \ { \ Q_UNUSED(exec);\ Q_UNUSED(self);\ Q_UNUSED(args);\ KJS::JSValue *result = KJS::jsNull(); \ KJSEmbed::ObjectBinding *imp = KJSEmbed::extractBindingImp(exec, self ); \ if( imp ) \ { \ TYPE *object = imp->object(); \ if( object ) \ { /** * End a variant method started by START_OBJECT_METHOD */ #define END_OBJECT_METHOD \ } \ else \ KJS::throwError(exec, KJS::ReferenceError, QString("O: The internal object died."));\ } \ else \ KJS::throwError(exec, KJS::GeneralError, QString("Object cast failed."));\ return result; \ } #define START_STATIC_OBJECT_METHOD( METHODNAME ) \ KJS::JSValue *METHODNAME( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args ) \ {\ Q_UNUSED(exec);\ Q_UNUSED(self);\ Q_UNUSED(args);\ KJS::JSValue *result = KJS::jsNull(); \ #define END_STATIC_OBJECT_METHOD \ return result; \ } namespace KJSEmbed { class KJSEMBED_EXPORT ObjectFactory { public: static const Method ObjectMethods[]; static const Method *methods() { return ObjectMethods; } }; class KJSEMBED_EXPORT ObjectBinding : public ProxyBinding { public: enum Ownership { CPPOwned, QObjOwned, JSOwned }; static const KJS::ClassInfo info; private: const char *m_name; mutable PointerBase *m_value; Ownership m_owner; public: template ObjectBinding(KJS::ExecState *exec, const char *typeName, T *ptr) : ProxyBinding(exec), m_name(typeName) { StaticBinding::publish(exec, this, ObjectFactory::methods()); m_owner = CPPOwned; m_value = new Pointer(ptr); } virtual ~ObjectBinding(); const char *typeName() const; /** * \return the internal object as a pointer of type T */ template T *object() const { if (m_value) { return pointer_cast(m_value); } else { - return 0; + return nullptr; } } void *voidStar() const { return m_value->voidStar(); } template void setObject(T *ptr) { if (m_owner == JSOwned) { //qDebug("object cleans up"); m_value->cleanup(); } delete m_value; m_value = new Pointer(ptr); } KJS::UString toString(KJS::ExecState *exec) const Q_DECL_OVERRIDE; KJS::UString className() const Q_DECL_OVERRIDE; KJS::JSType type() const Q_DECL_OVERRIDE; Ownership ownership() const; void setOwnership(Ownership owner); }; /** * Extracts a pointer based type from an ObjectBinding object. Care should be taken that this method * is not used with KJSEmbed::ObjectBinding objects because the cast will fail. */ template< typename T> T *extractObject(KJS::ExecState *exec, KJS::JSValue *arg, T *defaultValue) { if (!arg) { return defaultValue; } else { - T *returnValue = 0; + T *returnValue = nullptr; KJSEmbed::ObjectBinding *imp = KJSEmbed::extractBindingImp(exec, arg); if (imp) { // GCC 3.3 has problems calling template functions in another class from a template class. // returnValue = imp->object(); returnValue = (T *)imp->voidStar(); } if (returnValue) { return returnValue; } else { return defaultValue; } } } /** * Extracts a pointer from a KJS::List of KJS::JSValues. If the argument is out of range the default value * is returned. */ template< typename T> -T *extractObject(KJS::ExecState *exec, const KJS::List &args, int idx, T *defaultValue = 0L) +T *extractObject(KJS::ExecState *exec, const KJS::List &args, int idx, T *defaultValue = nullptr) { if (args.size() > idx) { return extractObject(exec, args[idx], defaultValue); } else { return defaultValue; } } /** * Can create any known KJSEmbed::ObjectBinding object and set the value. * On failure a KJS::jsNull will be returned and the exception set. */ template< typename T> KJS::JSValue *createObject(KJS::ExecState *exec, const KJS::UString &className, const T *value, KJSEmbed::ObjectBinding::Ownership owner = KJSEmbed::ObjectBinding::JSOwned) { - if (0 == value) { + if (nullptr == value) { return KJS::jsNull(); } KJS::JSObject *parent = exec->dynamicInterpreter()->globalObject(); KJS::JSObject *returnValue = StaticConstructor::construct(exec, parent, className); if (returnValue) { // If it is a value type setValue KJSEmbed::ObjectBinding *imp = extractBindingImp(exec, returnValue); if (imp) { imp->setOwnership(KJSEmbed::ObjectBinding::JSOwned); imp->setObject(value); imp->setOwnership(owner); } else { throwError(exec, KJS::TypeError, i18n("%1 is not an Object type", className.ascii())); return KJS::jsNull(); } } else { throwError(exec, KJS::GeneralError, "Could not construct value"); //throwError(exec, "Could not construct value" ); return KJS::jsNull(); } return returnValue; } template< typename T > T extractParameter(KJS::ExecState *exec, KJS::JSValue *arg, const T &defaultValue) { if (!arg) { return defaultValue; } else { switch (arg->type()) { case KJS::NumberType: return extractInt(exec, arg, defaultValue); break; case KJS::BooleanType: return extractBool(exec, arg, 0); break; case KJS::UnspecifiedType: case KJS::UndefinedType: case KJS::NullType: case KJS::GetterSetterType: case KJS::StringType: return defaultValue; break; } KJS::JSObject *object = arg->toObject(exec); if (object->inherits(&VariantBinding::info)) { return extractVariant(exec, arg, defaultValue); } else if (object->inherits(&ObjectBinding::info)) { return extractObject(exec, arg, defaultValue); } else { return defaultValue; } } } } #endif diff --git a/src/kjsembed/pen.cpp b/src/kjsembed/pen.cpp index 0cb8ae3..a3f8ae0 100644 --- a/src/kjsembed/pen.cpp +++ b/src/kjsembed/pen.cpp @@ -1,148 +1,148 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "pen.h" #include #include #include #include using namespace KJSEmbed; -const KJS::ClassInfo PenBinding::info = { "QPen", &VariantBinding::info, 0, 0 }; +const KJS::ClassInfo PenBinding::info = { "QPen", &VariantBinding::info, nullptr, nullptr }; PenBinding::PenBinding(KJS::ExecState *exec, const QPen &value) : VariantBinding(exec, value) { StaticBinding::publish(exec, this, Pen::methods()); StaticBinding::publish(exec, this, VariantFactory::methods()); } namespace PenNS { START_VARIANT_METHOD(callbrush, QPen) QBrush cppValue = value.brush(); result = KJSEmbed::createVariant(exec, "QBrush", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callcapStyle, QPen) Qt::PenCapStyle cppValue = value.capStyle(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callcolor, QPen) QColor cppValue = value.color(); result = KJSEmbed::createVariant(exec, "QColor", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callisSolid, QPen) bool cppValue = value.isSolid(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calljoinStyle, QPen) Qt::PenJoinStyle cppValue = value.joinStyle(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsetBrush, QPen) QBrush arg0 = KJSEmbed::extractVariant(exec, args, 0); value.setBrush(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetCapStyle, QPen) Qt::PenCapStyle arg0 = (Qt::PenCapStyle)KJSEmbed::extractInt(exec, args, 0); value.setCapStyle(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetColor, QPen) QColor arg0 = KJSEmbed::extractVariant(exec, args, 0); value.setColor(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetJoinStyle, QPen) Qt::PenJoinStyle arg0 = (Qt::PenJoinStyle)KJSEmbed::extractInt(exec, args, 0); value.setJoinStyle(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetStyle, QPen) Qt::PenStyle arg0 = (Qt::PenStyle)KJSEmbed::extractInt(exec, args, 0); value.setStyle(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetWidth, QPen) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setWidth(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callstyle, QPen) Qt::PenStyle cppValue = value.style(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callwidth, QPen) int cppValue = value.width(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD } START_METHOD_LUT(Pen) {"brush", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callbrush}, {"capStyle", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callcapStyle}, {"color", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callcolor}, {"isSolid", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callisSolid}, {"joinStyle", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::calljoinStyle}, {"setBrush", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetBrush}, {"setCapStyle", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetCapStyle}, {"setColor", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetColor}, {"setJoinStyle", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetJoinStyle}, {"setStyle", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetStyle}, {"setWidth", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetWidth}, {"style", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callstyle}, {"width", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callwidth} END_METHOD_LUT NO_ENUMS(Pen) NO_STATICS(Pen) START_CTOR(Pen, QPen, 0) if (args.size() == 1) { return new KJSEmbed::PenBinding(exec, QPen(KJSEmbed::extractVariant(exec, args, 0) )); } else if (args.size() >= 2) { return new KJSEmbed::PenBinding(exec, QPen(KJSEmbed::extractVariant(exec, args, 0), KJSEmbed::extractInt(exec, args, 1), (Qt::PenStyle)KJSEmbed::extractInt(exec, args, 2, Qt::SolidLine), (Qt::PenCapStyle)KJSEmbed::extractInt(exec, args, 3, Qt::SquareCap), (Qt::PenJoinStyle)KJSEmbed::extractInt(exec, args, 4, Qt::BevelJoin) )); } return new KJSEmbed::PenBinding(exec, QPen()); END_CTOR diff --git a/src/kjsembed/pixmap.cpp b/src/kjsembed/pixmap.cpp index b3e904f..28abb1e 100644 --- a/src/kjsembed/pixmap.cpp +++ b/src/kjsembed/pixmap.cpp @@ -1,308 +1,308 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "pixmap.h" #include #include #include #include #include #include using namespace KJSEmbed; -const KJS::ClassInfo PixmapBinding::info = { "QPixmap", &VariantBinding::info, 0, 0 }; +const KJS::ClassInfo PixmapBinding::info = { "QPixmap", &VariantBinding::info, nullptr, nullptr }; PixmapBinding::PixmapBinding(KJS::ExecState *exec, const QPixmap &value) : VariantBinding(exec, value) { StaticBinding::publish(exec, this, Pixmap::methods()); StaticBinding::publish(exec, this, VariantFactory::methods()); } namespace PixmapNS { START_VARIANT_METHOD(callalphaChannel, QPixmap) QPixmap cppValue = value.alphaChannel(); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callcopy, QPixmap) if (args.size() == 1) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); QPixmap cppValue = value.copy(arg0); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); } else if (args.size() == 4) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); QPixmap cppValue = value.copy(arg0, arg1, arg2, arg3); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); } END_VARIANT_METHOD START_VARIANT_METHOD(callcreateHeuristicMask, QPixmap) bool arg0 = KJSEmbed::extractBool(exec, args, 0); QBitmap cppValue = value.createHeuristicMask(arg0); result = KJSEmbed::createVariant(exec, "QBitmap", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callcreateMaskFromColor, QPixmap) QColor arg0 = KJSEmbed::extractVariant(exec, args, 0); QBitmap cppValue = value.createMaskFromColor(arg0); result = KJSEmbed::createVariant(exec, "QBitmap", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calldefaultDepth, QPixmap) int cppValue = value.defaultDepth(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calldepth, QPixmap) int cppValue = value.depth(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callfill, QPixmap) if (args.size() == 3) { QWidget *arg0 = KJSEmbed::extractObject(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); value.fill(arg0, arg1, arg2); } else if (args.size() == 1) { QColor arg0 = KJSEmbed::extractVariant(exec, args, 0); value.fill(arg0); } else if (args.size() == 2) { QWidget *arg0 = KJSEmbed::extractObject(exec, args, 0); QPoint arg1 = KJSEmbed::extractVariant(exec, args, 1); value.fill(arg0, arg1); } END_VARIANT_METHOD START_VARIANT_METHOD(callfromImage, QPixmap) QImage arg0 = KJSEmbed::extractVariant(exec, args, 0); Qt::ImageConversionFlags arg1 = (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 1); QPixmap cppValue = QPixmap::fromImage(arg0, arg1); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callgrabWidget, QPixmap) if (args.size() == 2) { QWidget *arg0 = KJSEmbed::extractObject(exec, args, 0); QRect arg1 = KJSEmbed::extractVariant(exec, args, 1); QPixmap cppValue = value.grabWidget(arg0, arg1); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); } else if (args.size() == 5) { QWidget *arg0 = KJSEmbed::extractObject(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); int arg4 = KJSEmbed::extractInt(exec, args, 4); QPixmap cppValue = value.grabWidget(arg0, arg1, arg2, arg3, arg4); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); } END_VARIANT_METHOD START_VARIANT_METHOD(callhasAlpha, QPixmap) bool cppValue = value.hasAlpha(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callhasAlphaChannel, QPixmap) bool cppValue = value.hasAlphaChannel(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callheight, QPixmap) int cppValue = value.height(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callisNull, QPixmap) bool cppValue = value.isNull(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callisQBitmap, QPixmap) bool cppValue = value.isQBitmap(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callload, QPixmap) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QByteArray arg1 = KJSEmbed::extractQString(exec, args, 1).toLatin1(); Qt::ImageConversionFlags arg2 = (Qt::ImageConversionFlags) KJSEmbed::extractInt(exec, args, 2); bool cppValue = value.load(arg0, arg1, arg2); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callmask, QPixmap) QBitmap cppValue = value.mask(); result = KJSEmbed::createVariant(exec, "QBitmap", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callrect, QPixmap) QRect cppValue = value.rect(); result = KJSEmbed::createVariant(exec, "QRect", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsave, QPixmap) QString arg0 = KJSEmbed::extractQString(exec, args, 0); QByteArray arg1 = KJSEmbed::extractQString(exec, args, 1).toLatin1(); int arg2 = KJSEmbed::extractInt(exec, args, 2, -1); bool cppValue = value.save(arg0, arg1, arg2); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callscaled, QPixmap) if (args.size() == 3) { QSize arg0 = KJSEmbed::extractVariant(exec, args, 0); Qt::AspectRatioMode arg1 = (Qt::AspectRatioMode) KJSEmbed::extractInt(exec, args, 1); Qt::TransformationMode arg2 = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 3); QPixmap cppValue = value.scaled(arg0, arg1, arg2); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); } else if (args.size() == 4) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); Qt::AspectRatioMode arg2 = (Qt::AspectRatioMode) KJSEmbed::extractInt(exec, args, 2); Qt::TransformationMode arg3 = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 3); QPixmap cppValue = value.scaled(arg0, arg1, arg2, arg3); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); } END_VARIANT_METHOD START_VARIANT_METHOD(callscaledToHeight, QPixmap) int arg0 = KJSEmbed::extractInt(exec, args, 0); Qt::TransformationMode arg1 = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 1); QPixmap cppValue = value.scaledToHeight(arg0, arg1); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callscaledToWidth, QPixmap) int arg0 = KJSEmbed::extractInt(exec, args, 0); Qt::TransformationMode arg1 = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 1); QPixmap cppValue = value.scaledToWidth(arg0, arg1); result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callserialNumber, QPixmap) int cppValue = value.serialNumber(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsetAlphaChannel, QPixmap) QPixmap arg0 = KJSEmbed::extractVariant(exec, args, 0); value.setAlphaChannel(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetMask, QPixmap) QBitmap arg0 = KJSEmbed::extractVariant(exec, args, 0); value.setMask(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsize, QPixmap) QSize cppValue = value.size(); result = KJSEmbed::createVariant(exec, "QSize", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(calltoImage, QPixmap) QImage cppValue = value.toImage(); result = KJSEmbed::createVariant(exec, "QImage", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callwidth, QPixmap) int cppValue = value.width(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD } START_METHOD_LUT(Pixmap) {"alphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callalphaChannel}, {"copy", 3, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callcopy}, {"createHeuristicMask", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callcreateHeuristicMask}, {"createMaskFromColor", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callcreateMaskFromColor}, {"defaultDepth", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::calldefaultDepth}, {"depth", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::calldepth}, {"fill", 2, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callfill}, {"fromImage", 1, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callfromImage}, {"grabWidget", 4, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callgrabWidget}, {"hasAlpha", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callhasAlpha}, {"hasAlphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callhasAlphaChannel}, {"height", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callheight}, {"isNull", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callisNull}, {"isQBitmap", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callisQBitmap}, {"load", 2, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callload}, {"mask", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callmask}, {"rect", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callrect}, {"save", 2, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsave}, {"scaled", 3, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callscaled}, {"scaledToHeight", 1, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callscaledToHeight}, {"scaledToWidth", 1, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callscaledToWidth}, {"serialNumber", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callserialNumber}, {"setAlphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsetAlphaChannel}, {"setMask", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsetMask}, {"size", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsize}, {"toImage", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::calltoImage}, {"width", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callwidth} END_METHOD_LUT NO_STATICS(Pixmap) NO_ENUMS(Pixmap) START_CTOR(Pixmap, QPixmap, 0) if (args.size() == 0) { return new KJSEmbed::PixmapBinding(exec, QPixmap()); } else if (args.size() == 1) { return new KJSEmbed::PixmapBinding(exec, QPixmap(KJSEmbed::extractQString(exec, args, 0))); } else if (args.size() == 2) { return new KJSEmbed::PixmapBinding(exec, QPixmap(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1) )); } else if (args.size() == 3) { QString tmp = toQString(args[2]->toObject(exec)->className()); qDebug() << tmp; return new KJSEmbed::PixmapBinding(exec, QPixmap(KJSEmbed::extractQString(exec, args, 0), KJSEmbed::extractVariant(exec, args, 1).constData(), (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 2) )); } return new KJSEmbed::PixmapBinding(exec, QPixmap()); END_CTOR diff --git a/src/kjsembed/point.cpp b/src/kjsembed/point.cpp index 265e4e8..a0d4242 100644 --- a/src/kjsembed/point.cpp +++ b/src/kjsembed/point.cpp @@ -1,107 +1,107 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "point.h" #include #include using namespace KJSEmbed; -const KJS::ClassInfo PointBinding::info = { "QPoint", &VariantBinding::info, 0, 0 }; +const KJS::ClassInfo PointBinding::info = { "QPoint", &VariantBinding::info, nullptr, nullptr }; PointBinding::PointBinding(KJS::ExecState *exec, const QPoint &value) : VariantBinding(exec, value) { StaticBinding::publish(exec, this, Point::methods()); StaticBinding::publish(exec, this, VariantFactory::methods()); } namespace PointNS { START_VARIANT_METHOD(callisNull, QPoint) bool cppValue = value.isNull(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callmanhattanLength, QPoint) int cppValue = value.manhattanLength(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callrx, QPoint) int cppValue = value.rx(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callry, QPoint) int cppValue = value.ry(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callsetX, QPoint) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setX(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetY, QPoint) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setY(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callx, QPoint) int cppValue = value.x(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(cally, QPoint) int cppValue = value.y(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD } START_METHOD_LUT(Point) {"isNull", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callisNull}, {"manhattanLength", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callmanhattanLength}, {"rx", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callrx}, {"ry", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callry}, {"setX", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callsetX}, {"setY", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callsetY}, {"x", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callx}, {"y", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::cally} END_METHOD_LUT NO_ENUMS(Point) NO_STATICS(Point) START_CTOR(Point, QPoint, 0) if (args.size() == 2) { return new KJSEmbed::PointBinding(exec, QPoint(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1) )); } return new KJSEmbed::PointBinding(exec, QPoint()); END_CTOR diff --git a/src/kjsembed/pointer.h b/src/kjsembed/pointer.h index 0ffe2c0..cff3b81 100644 --- a/src/kjsembed/pointer.h +++ b/src/kjsembed/pointer.h @@ -1,148 +1,148 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef POINTER_H #define POINTER_H #include #include #include namespace KJSEmbed { struct PointerBase { public: virtual ~PointerBase() { ; } virtual void cleanup() = 0; virtual const std::type_info &type() const = 0; virtual void *voidStar() = 0; }; template struct Pointer : public PointerBase { public: Pointer(ValueType *value) : ptr(value) { // qDebug("new pointer %s %0x", typeid(ValueType).name(), value); } ~Pointer() { } void cleanup() Q_DECL_OVERRIDE { // qDebug("delete pointer %s %0x", typeid(ValueType).name(), ptr ); delete ptr; - ptr = 0L; + ptr = nullptr; } const std::type_info &type() const Q_DECL_OVERRIDE { return typeid(ValueType); } void *voidStar() Q_DECL_OVERRIDE { return (void *)ptr; } ValueType *ptr; }; template struct Value : public PointerBase { public: Value(ValueType val) : value(val) { //qDebug("new value %s", typeid(ValueType).name()); } ~Value() { //qDebug("delete value"); } void cleanup() Q_DECL_OVERRIDE { } const std::type_info &type() const Q_DECL_OVERRIDE { return typeid(ValueType); } void *voidStar() Q_DECL_OVERRIDE { return (void *)&value; } ValueType value; }; struct NullPtr : public PointerBase { - NullPtr() : ptr(0) + NullPtr() : ptr(nullptr) { ; } ~NullPtr() { ; } void cleanup() Q_DECL_OVERRIDE { ; } const std::type_info &type() const Q_DECL_OVERRIDE { return typeid(NullPtr); } void *voidStar() Q_DECL_OVERRIDE { return &ptr; } void *ptr; }; template ValueType *pointer_cast(PointerBase *pointer) { // qDebug("pointers %s %s", typeid(ValueType).name(), pointer->type().name() ); if (typeid(ValueType) != pointer->type()) { - return 0L; + return nullptr; } Pointer *upcast = static_cast< Pointer *>(pointer); return upcast->ptr; } } Q_DECLARE_METATYPE(KJSEmbed::PointerBase *) #endif diff --git a/src/kjsembed/qaction_binding.cpp b/src/kjsembed/qaction_binding.cpp index d83dac9..3ee6025 100644 --- a/src/kjsembed/qaction_binding.cpp +++ b/src/kjsembed/qaction_binding.cpp @@ -1,87 +1,87 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "qaction_binding.h" #include "static_binding.h" #include "kjseglobal.h" #include #include #include #include namespace KJSEmbed { QUiLoader *uiLoader(); } using namespace KJSEmbed; NO_METHODS(Action) NO_ENUMS(Action) NO_STATICS(Action) KJSO_SIMPLE_BINDING_CTOR(Action, QAction, QObjectBinding) KJSO_QOBJECT_BIND(Action, QAction) KJSO_START_CTOR(Action, QAction, 0) -QObject *parent = KJSEmbed::extractObject(exec, args, 0, 0); +QObject *parent = KJSEmbed::extractObject(exec, args, 0, nullptr); QString actionName = KJSEmbed::extractQString(exec, args, 1); QAction *action = uiLoader()->createAction(parent, actionName); if (action) { KJS::JSObject *actionObject = new Action(exec, action); return actionObject; } else { return KJS::throwError(exec, KJS::GeneralError, i18n("Action takes 2 args.")); } KJSO_END_CTOR NO_METHODS(ActionGroup) NO_ENUMS(ActionGroup) NO_STATICS(ActionGroup) KJSO_SIMPLE_BINDING_CTOR(ActionGroup, QActionGroup, QObjectBinding) KJSO_QOBJECT_BIND(ActionGroup, QActionGroup) KJSO_START_CTOR(ActionGroup, QActionGroup, 0) if (args.size() == 2) { - QObject *parent = KJSEmbed::extractObject(exec, args, 0, 0); + QObject *parent = KJSEmbed::extractObject(exec, args, 0, nullptr); QString actionName = KJSEmbed::extractQString(exec, args, 1); QActionGroup *action = uiLoader()->createActionGroup(parent, actionName); if (action) { KJS::JSObject *actionObject = new ActionGroup(exec, action); return actionObject; } else { return KJS::throwError(exec, KJS::GeneralError, i18n("ActionGroup takes 2 args.")); // return KJSEmbed::throwError(exec, i18n("ActionGroup takes 2 args.")); } } // Trow error incorrect args return KJS::throwError(exec, KJS::GeneralError, i18n("Must supply a valid parent.")); // return KJSEmbed::throwError(exec, i18n("Must supply a valid parent.")); END_CTOR diff --git a/src/kjsembed/qlayout_binding.cpp b/src/kjsembed/qlayout_binding.cpp index 9b19e84..0d77d3b 100644 --- a/src/kjsembed/qlayout_binding.cpp +++ b/src/kjsembed/qlayout_binding.cpp @@ -1,96 +1,96 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "qlayout_binding.h" #include "static_binding.h" #include "kjseglobal.h" #include #include #include #include #include #include namespace KJSEmbed { QUiLoader *uiLoader(); } using namespace KJSEmbed; namespace LayoutNS { START_QOBJECT_METHOD(addWidget, QLayout) -QWidget *w = KJSEmbed::extractObject(exec, args, 0, 0); +QWidget *w = KJSEmbed::extractObject(exec, args, 0, nullptr); object->addWidget(w); END_QOBJECT_METHOD START_QOBJECT_METHOD(removeWidget, QLayout) -QWidget *w = KJSEmbed::extractObject(exec, args, 0, 0); +QWidget *w = KJSEmbed::extractObject(exec, args, 0, nullptr); object->removeWidget(w); END_QOBJECT_METHOD START_QOBJECT_METHOD(parentWidget, QLayout) QWidget *w = object->parentWidget(); result = KJSEmbed::createQObject(exec, w); END_QOBJECT_METHOD } START_METHOD_LUT(Layout) {"addWidget", 1, KJS::DontDelete | KJS::ReadOnly, &LayoutNS::addWidget}, {"removeWidget", 1, KJS::DontDelete | KJS::ReadOnly, &LayoutNS::removeWidget}, {"parentWidget", 0, KJS::DontDelete | KJS::ReadOnly, &LayoutNS::parentWidget} END_METHOD_LUT NO_ENUMS(Layout) NO_STATICS(Layout) KJSO_SIMPLE_BINDING_CTOR(Layout, QLayout, QObjectBinding) KJSO_QOBJECT_BIND(Layout, QLayout) KJSO_START_CTOR(Layout, QLayout, 0) // qDebug("Layout::CTOR(): args.size()=%d", args.size()); if (args.size() > 0) { QString layoutName = toQString(args[0]->toString(exec)); - QObject *parentObject = 0; + QObject *parentObject = nullptr; KJSEmbed::QObjectBinding *parentImp = KJSEmbed::extractBindingImp(exec, args[1]); if (parentImp) { parentObject = parentImp->object(); } QLayout *layout = uiLoader()->createLayout(layoutName, parentObject, "QLayout"); if (layout) { KJS::JSObject *layoutObject = new Layout(exec, layout);//KJSEmbed::createQObject(exec, layout); return layoutObject; } return KJS::throwError(exec, KJS::GeneralError, i18n("'%1' is not a valid QLayout.", layoutName)); // return KJSEmbed::throwError(exec, i18n("'%1' is not a valid QLayout.").arg(layoutName)); } // should Trow error incorrect args return KJS::throwError(exec, KJS::GeneralError, i18n("Must supply a layout name.")); // return KJSEmbed::throwError(exec, i18n("Must supply a layout name.")); KJSO_END_CTOR diff --git a/src/kjsembed/qobject_binding.cpp b/src/kjsembed/qobject_binding.cpp index 050ee45..bfa253e 100644 --- a/src/kjsembed/qobject_binding.cpp +++ b/src/kjsembed/qobject_binding.cpp @@ -1,866 +1,866 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce Copyright (C) 2007, 2008 Sebastian Sauer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "qobject_binding.h" #include #include #include #include #include #include #include #include #include #include "slotproxy.h" #include "eventproxy.h" #include "jseventmapper.h" #include "pointer.h" #include "variant_binding.h" #include #include //#define CREATEQOBJ_DIAG using namespace KJSEmbed; QByteArray createSignal(const QByteArray &sig) { return '2' + sig; } QByteArray createSlot(const QByteArray &slt) { return '1' + slt; } bool validSlot(const QMetaMethod &method, QObjectBinding::AccessFlags accessflags) { switch (method.access()) { case QMetaMethod::Private: { if (!(accessflags & QObjectBinding::PrivateSlots)) { return false; } } break; case QMetaMethod::Protected: { if (!(accessflags & QObjectBinding::ProtectedSlots)) { return false; } } break; case QMetaMethod::Public: { if (!(accessflags & QObjectBinding::PublicSlots)) { return false; } } break; } if (method.attributes() & QMetaMethod::Scriptable) { if (!(accessflags & QObjectBinding::ScriptableSlots)) { return false; } } else { if (!(accessflags & QObjectBinding::NonScriptableSlots)) { return false; } } return true; } bool validSignal(const QMetaMethod &method, QObjectBinding::AccessFlags accessflags) { switch (method.access()) { case QMetaMethod::Private: { if (!(accessflags & QObjectBinding::PrivateSignals)) { return false; } } break; case QMetaMethod::Protected: { if (!(accessflags & QObjectBinding::ProtectedSignals)) { return false; } } break; case QMetaMethod::Public: { if (!(accessflags & QObjectBinding::PublicSignals)) { return false; } } break; } if (method.attributes() & QMetaMethod::Scriptable) { if (!(accessflags & QObjectBinding::ScriptableSignals)) { return false; } } else { if (!(accessflags & QObjectBinding::NonScriptableSignals)) { return false; } } return true; } bool validProperty(const QMetaProperty &property, QObjectBinding::AccessFlags accessflags) { if (property.isScriptable()) { if (!(accessflags & QObjectBinding::ScriptableProperties)) { return false; } } else { if (!(accessflags & QObjectBinding::NonScriptableProperties)) { return false; } } return true; } KJS::JSValue *callConnect(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { KJSEmbed::QObjectBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (!imp) { // No implementation, so we need to use the first argument as we are a global static invocation. imp = KJSEmbed::extractBindingImp(exec, args[0]); } if (!imp) { return KJS::throwError(exec, KJS::GeneralError, i18n("Wrong object type.")); } //return KJSEmbed::throwError(exec, i18n("Wrong object type.")); if (args.size() > 2) { KJSEmbed::QObjectBinding *senderImp = KJSEmbed::extractBindingImp(exec, args[0]); if (!senderImp) { return KJS::throwError(exec, KJS::GeneralError, i18n("First argument must be a QObject.")); //return KJSEmbed::throwError(exec, i18n("First argument must be a QObject")); } - QObject *receiver = 0; + QObject *receiver = nullptr; QObject *sender = senderImp->object(); QByteArray signal = createSignal(args[1]->toString(exec).ascii()); QByteArray slot; - KJSEmbed::QObjectBinding *receiverImp = 0; + KJSEmbed::QObjectBinding *receiverImp = nullptr; if (args.size() >= 4) { slot = createSlot(args[3]->toString(exec).ascii()); receiverImp = KJSEmbed::extractBindingImp(exec, args[2]); if (!receiverImp) { receiver = new SlotProxy(args[2]->toObject(exec), exec->dynamicInterpreter(), sender, args[3]->toString(exec).ascii()); } else { receiver = receiverImp->object(); } } else { receiverImp = imp; receiver = imp->object(); slot = createSlot(args[2]->toString(exec).ascii()); } const QMetaObject *senderMetaObject = sender->metaObject(); QMetaMethod senderMetaMethod = senderMetaObject->method(senderMetaObject->indexOfSignal(signal.constData())); const QMetaObject *receiverMetaObject = receiver->metaObject(); QMetaMethod receiverMetaMethod = receiverMetaObject->method(receiverMetaObject->indexOfSlot(slot.constData())); if (validSignal(senderMetaMethod, senderImp->access()) && (!receiverImp || validSlot(receiverMetaMethod, receiverImp->access()))) { return KJS::jsBoolean(QObject::connect(sender, signal.constData(), receiver, slot.constData())); } return KJS::jsBoolean(false); } return KJS::throwError(exec, KJS::GeneralError, i18n("Incorrect number of arguments.")); //return KJSEmbed::throwError(exec, i18n("Incorrect number of arguments.")); } QByteArray extractMemberName(const QMetaMethod &member) { QString sig = member.methodSignature(); return sig.left(sig.indexOf('(')).toLatin1(); } void QObjectBinding::publishQObject(KJS::ExecState *exec, KJS::JSObject *target, QObject *object) { KJSEmbed::QObjectBinding *imp = KJSEmbed::extractBindingImp(exec, target); Q_ASSERT(imp); // Add the children the QObject has. if (imp->access() & QObjectBinding::ChildObjects) { //TODO uh, this one is dirty cause it may eat a lot of time to publish things that may not //got accessed anyway. Better solution would be to provide access to them on demand only. That //would also allow to manipulate the QObject-tree at runtime what is currently not possible. QObjectList children = object->children(); QObjectList::Iterator child = children.begin(); for (; child != children.end(); ++child) { QString objectName = (*child)->objectName(); if (!objectName.isEmpty()) { KJS::JSObject *childObject = KJSEmbed::createQObject(exec, *child); KJSEmbed::QObjectBinding *childImp = KJSEmbed::extractBindingImp(exec, childObject); if (childImp) { childImp->setAccess(imp->access()); // inherit access from parent target->put(exec, KJS::Identifier(toUString(objectName)), childObject); } } } } // Add slots of the current object. const QMetaObject *metaObject = object->metaObject(); int methods = metaObject->methodCount(); for (int idx = 0; idx < methods; ++idx) { QMetaMethod member = metaObject->method(idx); if (validSlot(member, imp->access())) { target->put(exec, KJS::Identifier(extractMemberName(member).constData()), new SlotBinding(exec, member), KJS::DontDelete | KJS::ReadOnly | KJS::Function); } } // Add enums as read only uints. int enums = metaObject->enumeratorCount(); for (int idx = 0; idx < enums; ++idx) { QMetaEnum enumerator = metaObject->enumerator(idx); int keys = enumerator.keyCount(); for (int key = 0; key < keys; ++key) { target->put(exec, KJS::Identifier(enumerator.key(key)), KJS::jsNumber(enumerator.value(key)), KJS::DontDelete | KJS::ReadOnly); } } } QObjectBinding::QObjectBinding(KJS::ExecState *exec, QObject *object) : ObjectBinding(exec, object->metaObject()->className(), object) - , m_evproxy(0) + , m_evproxy(nullptr) , m_access(AllSlots | AllSignals | AllProperties | AllObjects) { - if (object->parent() != 0) { + if (object->parent() != nullptr) { setOwnership(ObjectBinding::QObjOwned); } else { setOwnership(ObjectBinding::JSOwned); } m_cleanupHandler = new QObjectCleanupHandler(); watchObject(object); StaticBinding::publish(exec, this, QObjectFactory::methods()); QObjectBinding::publishQObject(exec, this, object); // Make "connect" a global static method. exec->dynamicInterpreter()->globalObject()->put(exec, "connect", new StaticBinding(exec, &QObjectFactory::methods()[0])); } QObjectBinding::~QObjectBinding() { if (m_cleanupHandler->isEmpty()) { setOwnership(ObjectBinding::QObjOwned); - } else if (object()->parent() != 0) { + } else if (object()->parent() != nullptr) { setOwnership(ObjectBinding::QObjOwned); m_cleanupHandler->remove(object()); } else if (ownership() != ObjectBinding::JSOwned) { m_cleanupHandler->remove(object()); } else { m_cleanupHandler->remove(object()); } delete m_cleanupHandler; } void QObjectBinding::watchObject(QObject *object) { m_cleanupHandler->add(object); } bool QObjectBinding::getOwnPropertySlot(KJS::ExecState *exec, const KJS::Identifier &propertyName, KJS::PropertySlot &slot) { // qDebug() << "getOwnPropertySlot called"; QObject *obj = object(); const QMetaObject *meta = obj->metaObject(); int propIndex = meta->indexOfProperty(propertyName.ascii()); if (propIndex != -1) { if (! validProperty(meta->property(propIndex), m_access)) { return false; } // qDebug() << "getOwnPropertySlot found the property " << propertyName.ascii(); slot.setCustom(this, propertyGetter); return true; } return ObjectBinding::getOwnPropertySlot(exec, propertyName, slot); } KJS::JSValue *QObjectBinding::propertyGetter(KJS::ExecState *exec, KJS::JSObject *, const KJS::Identifier &propertyName, const KJS::PropertySlot &slot) { // qDebug() << "Getter was called"; QObjectBinding *self = static_cast(slot.slotBase()); QObject *obj = self->object(); QVariant val = obj->property(propertyName.ascii()); if (val.isValid()) { return convertToValue(exec, val); } qDebug() << QString("propertyGetter called but no property, name was '%1'").arg(propertyName.ascii()); - return 0; // ERROR + return nullptr; // ERROR } QObjectBinding::AccessFlags QObjectBinding::access() const { return m_access; } void QObjectBinding::setAccess(QObjectBinding::AccessFlags access) { m_access = access; } void QObjectBinding::put(KJS::ExecState *exec, const KJS::Identifier &propertyName, KJS::JSValue *value, int attr) { QObject *obj = object(); if (obj && !m_cleanupHandler->isEmpty()) { // Properties const QMetaObject *meta = obj->metaObject(); if (int propIndex = meta->indexOfProperty(propertyName.ascii()) != -1) { QMetaProperty prop = meta->property(propIndex); if (! validProperty(prop, m_access)) { return; } bool propSet = false; QVariant val = convertToVariant(exec, value); if (prop.isEnumType()) { propSet = obj->setProperty(propertyName.ascii(), val.toUInt()); } else if (val.isValid() /*&& meta->property(propIndex).isWritable() <- wtf?*/) { propSet = obj->setProperty(propertyName.ascii(), val); } /* if( !propSet ) { KJSEmbed::throwError(exec, i18n("Setting property %1 failed: property invalid, read-only or does not exist").arg(propertyName.ascii())); } */ } if (JSEventMapper::mapper()->isEventHandler(propertyName)) { if (!m_evproxy) { m_evproxy = new KJSEmbed::EventProxy(this, exec->dynamicInterpreter()); } if (value) { m_evproxy->addFilter(JSEventMapper::mapper()->findEventType(propertyName)); } else { m_evproxy->removeFilter(JSEventMapper::mapper()->findEventType(propertyName)); } } } //qDebug() << "Forward put"; // Set a property value ObjectBinding::put(exec, propertyName, value, attr); } bool QObjectBinding::canPut(KJS::ExecState *exec, const KJS::Identifier &propertyName) const { QObject *obj = object(); if (obj && !m_cleanupHandler->isEmpty()) { // Properties const QMetaObject *meta = obj->metaObject(); if (int propIndex = meta->indexOfProperty(propertyName.ascii()) != -1) { QMetaProperty prop = meta->property(propIndex); return validProperty(prop, m_access) && prop.isWritable(); } } return ObjectBinding::canPut(exec, propertyName); } KJS::UString QObjectBinding::className() const { return toUString(typeName()); } KJS::UString QObjectBinding::toString(KJS::ExecState *exec) const { Q_UNUSED(exec); QString s("%1 (%2)"); s = s.arg(object()->objectName()); s = s.arg(typeName()); return toUString(s); } PointerBase *getArg(KJS::ExecState *exec, const QList &types, const KJS::List &args, int idx, QString &errorText) { //qDebug("Index %d, args size %d, types size %d", idx, args.size(), types.size() ); if (types.size() == 0 && idx == 0) { return new NullPtr(); } if (args.size() <= idx) { return new NullPtr(); } if (types.size() <= idx) { const QString firstPart = i18np("The slot asked for %1 argument", "The slot asked for %1 arguments", idx); const QString secondPart = i18np("but there is only %1 available", "but there are only %1 available", types.size()); errorText = i18nc("%1 is 'the slot asked for foo arguments', %2 is 'but there are only bar available'", "%1, %2."); - return 0; + return nullptr; } QVariant::Type varianttype = QVariant::nameToType(types[idx].constData()); //qDebug( QString("type=%1 argtype=%2 variantType=%3 (%4)").arg(types[idx].constData()).arg(args[idx]->type()).arg(varianttype).arg(QVariant::typeToName(varianttype)).toLatin1() ); switch (varianttype) { case QVariant::Int: if (args[idx]->type() == KJS::NumberType) { return new Value(int(args[idx]->toInteger(exec))); } break; case QVariant::UInt: if (args[idx]->type() == KJS::NumberType) { return new Value(uint(args[idx]->toInteger(exec))); } break; case QVariant::LongLong: if (args[idx]->type() == KJS::NumberType) { return new Value(qlonglong(args[idx]->toInteger(exec))); } break; case QVariant::ULongLong: if (args[idx]->type() == KJS::NumberType) { return new Value(qulonglong(args[idx]->toInteger(exec))); } break; case QVariant::Double: if (args[idx]->type() == KJS::NumberType) { return new Value(args[idx]->toNumber(exec)); } //if ( types[idx] == "float" ) return new Value( args[idx]->toNumber(exec) ); //if ( types[idx] == "qreal" ) return new Value( args[idx]->toNumber(exec) ); break; case QVariant::Bool: if (args[idx]->type() == KJS::BooleanType) { return new Value(args[idx]->toBoolean(exec)); } break; case QVariant::ByteArray: if (args[idx]->type() == KJS::StringType) { return new Value(toQString(args[idx]->toString(exec)).toUtf8()); } break; case QVariant::String: if (args[idx]->type() == KJS::StringType) { return new Value(toQString(args[idx]->toString(exec))); } break; case QVariant::StringList: if (args[idx]->type() == KJS::ObjectType) { return new Value(convertArrayToStringList(exec, args[idx])); } break; case QVariant::Size: if (VariantBinding *valImp = KJSEmbed::extractBindingImp(exec, args[idx])) { return new Value(valImp->variant().value()); } break; case QVariant::SizeF: if (VariantBinding *valImp = KJSEmbed::extractBindingImp(exec, args[idx])) { return new Value(valImp->variant().value()); } break; case QVariant::Point: if (VariantBinding *valImp = KJSEmbed::extractBindingImp(exec, args[idx])) { return new Value(valImp->variant().value()); } break; case QVariant::PointF: if (VariantBinding *valImp = KJSEmbed::extractBindingImp(exec, args[idx])) { return new Value(valImp->variant().value()); } break; case QVariant::Rect: if (VariantBinding *valImp = KJSEmbed::extractBindingImp(exec, args[idx])) { return new Value(valImp->variant().value()); } break; case QVariant::RectF: if (VariantBinding *valImp = KJSEmbed::extractBindingImp(exec, args[idx])) { return new Value(valImp->variant().value()); } break; case QVariant::Color: if (args[idx]->type() == KJS::StringType) { return new Value(QColor(toQString(args[idx]->toString(exec)))); } if (VariantBinding *valImp = KJSEmbed::extractBindingImp(exec, args[idx])) { return new Value(valImp->variant().value()); } break; case QVariant::Url: if (args[idx]->type() == KJS::StringType) { return new Value(QUrl(toQString(args[idx]->toString(exec)))); } if (VariantBinding *valImp = KJSEmbed::extractBindingImp(exec, args[idx])) { return new Value(valImp->variant().value()); } break; case QVariant::List: if (args[idx]->type() == KJS::ObjectType) { return new Value(convertArrayToList(exec, args[idx])); } break; case QVariant::Map: if (args[idx]->type() == KJS::ObjectType) { return new Value(convertArrayToMap(exec, args[idx])); } break; case QVariant::UserType: // fall through default: if (args[idx]->type() == KJS::NullType) { return new NullPtr(); } if (args[idx]->type() == KJS::StringType) { if (strcmp(types[idx].constData(), "KUrl") == 0) { //downcast to QUrl return new Value(QUrl(toQString(args[idx]->toString(exec)))); } } if (args[idx]->type() == KJS::ObjectType) { if (QObjectBinding *objImp = KJSEmbed::extractBindingImp(exec, args[idx])) { //qDebug("\tQObjectBinding"); if (QObject *qObj = objImp->qobject()) { return new Value(qObj); } } else if (ObjectBinding *objImp = KJSEmbed::extractBindingImp(exec, args[idx])) { //qDebug("\tObjectBinding"); return new Value(objImp->voidStar()); } if (VariantBinding *valImp = KJSEmbed::extractBindingImp(exec, args[idx])) { //qDebug() << "\tVariantBinding typeName=" << valImp->variant().typeName() << "type=" << valImp->variant().type() << "userType=" << valImp->variant().userType() << " variant=" << valImp->variant(); QVariant var = valImp->variant(); // if the variant is the appropriate type, return its data if ((var.type() == varianttype) || ((var.type() == QVariant::UserType) && (types[idx].constData() == var.typeName()))) { return new Value(valImp->variant().data()); } else if ((var.type() != QVariant::UserType) && var.canConvert(varianttype)) { // is convertable type, so convert it, and return if successful if (var.convert(varianttype)) { return new Value(valImp->variant().data()); } } else if ((var.type() == QVariant::UserType) && var.canConvert()) { QObject *qObj = var.value(); if (!qObj) { qObj = reinterpret_cast(var.value()); } if (qObj) { QByteArray typeName = types[idx].constData(); typeName.replace("*", ""); //krazy:exclude=doublequote_chars if (qObj->inherits(typeName.constData())) { return new Value(qObj); } } } } } QVariant v = KJSEmbed::extractVariant(exec, args[idx]); if (! v.isNull()) { return new Value(v); } break; } qDebug("Cast failure %s value Type %d", types[idx].constData(), args[idx]->type()); // construct a meaningful exception message QString jsType; KJS::JSObject *jsObj = args[idx]->getObject(); if (jsObj) { const KJS::ClassInfo *ci = jsObj->classInfo(); if (ci && ci->className) { jsType = ci->className; } if (jsType.isEmpty()) { jsType = toQString(jsObj->className()); } } if (jsType.isEmpty()) { switch (args[idx]->type()) { case KJS::UnspecifiedType: jsType = "jsUnspecified"; break; case KJS::NumberType: jsType = "jsNumber"; break; case KJS::BooleanType: jsType = "jsBoolean"; break; case KJS::UndefinedType: jsType = "jsUndefined"; break; case KJS::NullType: jsType = "jsNull"; break; case KJS::StringType: jsType = "jsString"; break; case KJS::ObjectType: jsType = "jsObject"; break; case KJS::GetterSetterType: jsType = "jsGetterSetter"; break; default: jsType = QString::number(args[idx]->type()); break; } } errorText = i18n("Failure to cast to %1 value from Type %2 (%3)", types[idx].constData(), jsType, toQString(args[idx]->toString(exec))); - return 0; + return nullptr; } KJS::JSValue *SlotBinding::callAsFunction(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { QObjectBinding *imp = extractBindingImp(exec, self); - if (imp == 0) { + if (imp == nullptr) { return KJS::jsNull(); } PointerBase *qtArgs[10]; void *param[11]; QObject *object = imp->object(); int count = object->metaObject()->methodCount(); QMetaMethod metaMember; int offset = 0; bool success = false; for (; offset < count; ++offset) { metaMember = object->metaObject()->method(offset); if (extractMemberName(metaMember) == m_memberName) { if (metaMember.parameterTypes().size() == args.size() && validSlot(metaMember, imp->access())) { success = true; break; } } } if (!success) { return KJS::throwError(exec, KJS::GeneralError, i18n("No such method '%1'.", m_memberName.constData())); //return KJSEmbed::throwError(exec, i18n("Call to '%1' failed.").arg(m_memberName.constData())); } QList types = metaMember.parameterTypes(); QVariant::Type returnTypeId = QVariant::nameToType(metaMember.typeName()); int tp = QMetaType::type(metaMember.typeName()); - PointerBase *qtRet = new Value(0); + PointerBase *qtRet = new Value(nullptr); bool returnIsMetaType = ( returnTypeId == QVariant::UserType || returnTypeId == QVariant::Size || returnTypeId == QVariant::SizeF || returnTypeId == QVariant::Point || returnTypeId == QVariant::PointF || returnTypeId == QVariant::Rect || returnTypeId == QVariant::RectF || returnTypeId == QVariant::Color ); - QVariant returnValue = returnIsMetaType ? QVariant(tp, (void *)0) : QVariant(returnTypeId); + QVariant returnValue = returnIsMetaType ? QVariant(tp, (void *)nullptr) : QVariant(returnTypeId); QGenericReturnArgument returnArgument(metaMember.typeName(), &returnValue); param[0] = returnIsMetaType ? qtRet->voidStar() : returnArgument.data(); QString errorText; for (int idx = 0; idx < 10; ++idx) { qtArgs[idx] = getArg(exec, types, args, idx, errorText); if (!qtArgs[idx]) { for (int i = 0; i < idx; ++i) { delete qtArgs[i]; } delete qtRet; return KJS::throwError(exec, KJS::GeneralError, i18n("Call to method '%1' failed, unable to get argument %2: %3", m_memberName.constData(), idx, errorText)); } param[idx + 1] = qtArgs[idx]->voidStar(); } success = object->qt_metacall(QMetaObject::InvokeMetaMethod, offset, param) < 0; - KJS::JSValue *jsReturnValue = 0; + KJS::JSValue *jsReturnValue = nullptr; if (success) { switch (returnTypeId) { case QVariant::Invalid: // fall through case QVariant::UserType: { if (QMetaType::typeFlags(tp) & QMetaType::PointerToQObject) { const QVariant v(tp, param[0]); QObject *obj = v.value< QObject * >(); if (obj) { jsReturnValue = KJSEmbed::createQObject(exec, obj, KJSEmbed::ObjectBinding::CPPOwned); } } } break; default: if (returnIsMetaType) { returnValue = QVariant(tp, param[0]); } break; } if (! jsReturnValue) { jsReturnValue = KJSEmbed::convertToValue(exec, returnValue); } } for (int idx = 0; idx < 10; ++idx) { delete qtArgs[idx]; } delete qtRet; if (!success) { return KJS::throwError(exec, KJS::GeneralError, i18n("Call to '%1' failed.", m_memberName.constData())); } return jsReturnValue; } SlotBinding::SlotBinding(KJS::ExecState *exec, const QMetaMethod &member) : KJS::InternalFunctionImp(static_cast(exec->lexicalInterpreter()->builtinFunctionPrototype()), KJS::Identifier(toUString(extractMemberName(member)))) { m_memberName = extractMemberName(member); int count = member.parameterNames().count(); putDirect(exec->propertyNames().length, count, LengthFlags); } KJS::JSObject *KJSEmbed::createQObject(KJS::ExecState *exec, QObject *value, KJSEmbed::ObjectBinding::Ownership owner) { - if (0 == value) { + if (nullptr == value) { return new KJS::JSObject(); } const QMetaObject *meta = value->metaObject(); KJS::JSObject *parent = exec->dynamicInterpreter()->globalObject(); KJS::JSObject *returnValue; int pos; QString clazz; do { clazz = meta->className(); #ifdef CREATEQOBJ_DIAG qDebug() << "clazz=" << clazz; #endif // strip off namespace since they aren't included if ((pos = clazz.lastIndexOf("::")) != -1) { clazz.remove(0, pos + 2); } #ifdef CREATEQOBJ_DIAG qDebug() << "cleaned clazz=" << clazz; #endif if (parent->hasProperty(exec, KJS::Identifier(toUString(clazz)))) { #ifdef CREATEQOBJ_DIAG qDebug() << "createQObject(): clazz=" << clazz << " value=" << value; #endif Pointer pov(value); returnValue = StaticConstructor::bind(exec, clazz, pov); if (returnValue) { return returnValue; } #ifdef CREATEQOBJ_DIAG qDebug("\tresort to construct() method."); #endif returnValue = StaticConstructor::construct(exec, parent, toUString(clazz)); if (returnValue) { // If it is a value type setValue KJSEmbed::QObjectBinding *imp = extractBindingImp(exec, returnValue); if (imp) { imp->setObject(value); imp->watchObject(value); imp->setOwnership(owner); KJSEmbed::QObjectBinding::publishQObject(exec, returnValue, value); } else { KJS::throwError(exec, KJS::TypeError, i18n("%1 is not an Object type", clazz)); return new KJS::JSObject(); } } else { KJS::throwError(exec, KJS::TypeError, i18n("Could not construct value")); return new KJS::JSObject(); } return returnValue; } else { #ifdef CREATEQOBJ_DIAG qDebug("%s not a bound type, move up the chain", meta->className()); #endif meta = meta->superClass(); } } while (meta); KJSEmbed::QObjectBinding *imp = new KJSEmbed::QObjectBinding(exec, value); imp->setOwnership(owner); return imp; } START_QOBJECT_METHOD(callParent, QObject) //TODO it would be better, if each QObjectBinding remembers it's parent rather then //creating a new instance each time. That wouldn't only be more logical, but also //does prevent losing of additional information like e.g. the access-level. if (imp->access() & QObjectBinding::GetParentObject) { QObject *parent = imp->object()->parent(); KJS::JSObject *parentObject = KJSEmbed::createQObject(exec, parent); KJSEmbed::QObjectBinding *parentImp = KJSEmbed::extractBindingImp(exec, parentObject); if (parentImp) { parentImp->setAccess(imp->access()); // inherit access from child since we don't know the access-level of the parent here :-( } result = parentObject; } END_QOBJECT_METHOD START_QOBJECT_METHOD(callIsWidgetType, QObject) result = KJS::jsBoolean(object->isWidgetType()); END_QOBJECT_METHOD START_QOBJECT_METHOD(callInherits, QObject) QByteArray className = KJSEmbed::extractQString(exec, args, 0).toLatin1(); result = KJS::jsBoolean(object->inherits(className.constData())); END_QOBJECT_METHOD START_QOBJECT_METHOD(callSetParent, QObject) if (imp->access() & QObjectBinding::SetParentObject) { - QObject *parent = KJSEmbed::extractObject(exec, args, 0, 0); + QObject *parent = KJSEmbed::extractObject(exec, args, 0, nullptr); object->setParent(parent); } END_QOBJECT_METHOD START_QOBJECT_METHOD(callFindChild, QObject) if (imp->access() & QObjectBinding::ChildObjects) { QString childName = KJSEmbed::extractQString(exec, args, 0); QObject *child = object->findChild(childName); KJS::JSObject *childObject = KJSEmbed::createQObject(exec, child); KJSEmbed::QObjectBinding *childImp = KJSEmbed::extractBindingImp(exec, childObject); if (childImp) { childImp->setAccess(imp->access()); // inherit access from parent } result = childObject; } END_QOBJECT_METHOD START_METHOD_LUT(QObjectFactory) {"connect", 4, KJS::DontDelete | KJS::ReadOnly, &callConnect }, {"parent", 0, KJS::DontDelete | KJS::ReadOnly, &callParent }, {"inherits", 1, KJS::DontDelete | KJS::ReadOnly, &callInherits }, {"isWidgetType", 0, KJS::DontDelete | KJS::ReadOnly, &callIsWidgetType }, {"setParent", 1, KJS::DontDelete | KJS::ReadOnly, &callSetParent }, {"findChild", 1, KJS::DontDelete | KJS::ReadOnly, &callFindChild } END_METHOD_LUT NO_ENUMS(QObjectFactory) NO_STATICS(QObjectFactory) diff --git a/src/kjsembed/qobject_binding.h b/src/kjsembed/qobject_binding.h index 0466bab..9507954 100644 --- a/src/kjsembed/qobject_binding.h +++ b/src/kjsembed/qobject_binding.h @@ -1,242 +1,242 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce Copyright (C) 2007, 2008 Sebastian Sauer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef QOBJECT_BINDING_H #define QOBJECT_BINDING_H #include #include #include #include "binding_support.h" #include "object_binding.h" /** * A simple pointer syle method. * This will extract the pointer, cast it to the native type and place it in "value". * Any data that should be returned from this method should be placed into "result"; * */ #define START_QOBJECT_METHOD( METHODNAME, TYPE) \ KJS::JSValue *METHODNAME( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args ) \ { \ Q_UNUSED( args ); \ KJS::JSValue *result = KJS::jsNull(); \ KJSEmbed::QObjectBinding *imp = KJSEmbed::extractBindingImp(exec, self ); \ if( imp ) \ { \ TYPE *object = imp->qobject(); \ if( object ) \ { /** * End a variant method started by START_QOBJECT_METHOD */ #define END_QOBJECT_METHOD \ } \ else \ KJS::throwError(exec, KJS::ReferenceError, QString("QO: The internal object died %1:%2.").arg(__FILE__).arg(__LINE__));\ } \ else \ KJS::throwError(exec, KJS::ReferenceError, QString("QObject died."));\ return result; \ } class QObject; class QMetaMethod; namespace KJSEmbed { KJS_BINDING(QObjectFactory) class EventProxy; class KJSEMBED_EXPORT QObjectBinding : public ObjectBinding { public: QObjectBinding(KJS::ExecState *exec, QObject *object); virtual ~QObjectBinding(); static void publishQObject(KJS::ExecState *exec, KJS::JSObject *target, QObject *object); /** * Enumeration of access-flags that could be OR-combined to define * what parts of the QObject should be published. * Default is AllSlots|AllSignals|AllProperties|AllObjects what * means that everything got published, even e.g. private slots. */ enum Access { None = 0x00, ///< Don't publish anything. ScriptableSlots = 0x01, ///< Publish slots that have Q_SCRIPTABLE defined. NonScriptableSlots = 0x02, ///< Publish slots that don't have Q_SCRIPTABLE defined. PrivateSlots = 0x04, ///< Publish private slots. ProtectedSlots = 0x08, ///< Publish protected slots. PublicSlots = 0x10, ///< Publish public slots. AllSlots = ScriptableSlots | NonScriptableSlots | PrivateSlots | ProtectedSlots | PublicSlots, ScriptableSignals = 0x100, ///< Publish signals that have Q_SCRIPTABLE defined. NonScriptableSignals = 0x200, ///< Publish signals that don't have Q_SCRIPTABLE defined. PrivateSignals = 0x400, ///< Publish private signals. ProtectedSignals = 0x800, ///< Publish protected signals. PublicSignals = 0x1000, ///< Publish public signals. AllSignals = ScriptableSignals | NonScriptableSignals | PrivateSignals | ProtectedSignals | PublicSignals, ScriptableProperties = 0x10000, ///< Publish properties that have Q_SCRIPTABLE defined. NonScriptableProperties = 0x20000, ///< Publish properties that don't have Q_SCRIPTABLE defined. AllProperties = ScriptableProperties | NonScriptableProperties, GetParentObject = 0x100000, ///< Provide access to the parent QObject the QObject has. SetParentObject = 0x200000, ///< Be able to set the parent QObject the QObject has. ChildObjects = 0x400000, ///< Provide access to the child QObject's the QObject has. AllObjects = GetParentObject | SetParentObject | ChildObjects }; Q_DECLARE_FLAGS(AccessFlags, Access) /** * \return the defined \a Access flags. */ AccessFlags access() const; /** * Set the defined \a Access flags to \p access . */ void setAccess(AccessFlags access); /** * Set the value \p value of the property \p propertyName . */ void put(KJS::ExecState *exec, const KJS::Identifier &propertyName, KJS::JSValue *value, int attr = KJS::None) Q_DECL_OVERRIDE; using JSObject::put; /** * \return true if the property \p propertyName can be changed else false is returned. */ bool canPut(KJS::ExecState *exec, const KJS::Identifier &propertyName) const Q_DECL_OVERRIDE; /** * Called to ask if we have a callback for the named property. * We return the callback in the property slot. */ bool getOwnPropertySlot(KJS::ExecState *exec, const KJS::Identifier &propertyName, KJS::PropertySlot &slot) Q_DECL_OVERRIDE; using JSObject::getOwnPropertySlot; /** * Callback used to get properties. */ static KJS::JSValue *propertyGetter(KJS::ExecState *exec, KJS::JSObject *, const KJS::Identifier &name, const KJS::PropertySlot &); /** * \return a string-representation of the QObject. For example for a QWidget-instance that * has the QObject::objectName "mywidget" the string "mywidget (QWidget)" is returned. */ KJS::UString toString(KJS::ExecState *exec) const Q_DECL_OVERRIDE; /** * \return the QObject's classname. For example for a QWidget-instance the string "QWidget" * is returned. */ KJS::UString className() const Q_DECL_OVERRIDE; /** * Add the QObject \p object to the internal QObjectCleanupHandler to watch the * lifetime of the QObject to know when the QObject got deleted. */ void watchObject(QObject *object); /** * \return the internal object as a pointer to type T to the * internal object that is derived from QObject. */ template T *qobject() const { QObject *object = QObjectBinding::object(); if (object) { return qobject_cast(object); } else { - return 0; + return nullptr; } } private: EventProxy *m_evproxy; QObjectCleanupHandler *m_cleanupHandler; AccessFlags m_access; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QObjectBinding::AccessFlags) class KJSEMBED_EXPORT SlotBinding : public KJS::InternalFunctionImp { public: SlotBinding(KJS::ExecState *exec, const QMetaMethod &memberName); KJS::JSValue *callAsFunction(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) Q_DECL_OVERRIDE; bool implementsCall() const Q_DECL_OVERRIDE { return true; } bool implementsConstruct() const Q_DECL_OVERRIDE { return false; } protected: QByteArray m_memberName; }; /** * Returns a binding object for the specified QObject. This method walks * up the meta objects in order to find the most specific binding it can. * There should always be some kind of binding possible even if it is just * the QObject binding. * * \param exec Represents the current state of script execution. * \param value The QObject or from it inherited instance we should return * a binding object for. * \param owner Defines who's the owner of the QObject. This could be; * \li CPPOwned what means, that the QObject's lifetime is handled * within C++ code. So, we just provide access to it and don't * take any future actions. * \li QObjOwned means that the QObject got deleted if the parent QObject * is destroyed. If the QObject has no parent QObject, it behaves like * JSOwned. * \li JSOwned means, that the returned KJS::JSObject takes care of * deleting the QObject. This means, that the QObject got deleted * as soon as the KJS::JSObject got destroyed what happens if the * KJS::JSObject is not needed / in use any longer. * \return the binding object instance that wraps the QObject instance or * a JSObject with a prototype of jsNull (that is, the ECMAScript "null" value, * not a null object pointer) if we failed to provide any binding for it. */ KJSEMBED_EXPORT KJS::JSObject *createQObject(KJS::ExecState *exec, QObject *value, KJSEmbed::ObjectBinding::Ownership owner = KJSEmbed::ObjectBinding::JSOwned); } #endif diff --git a/src/kjsembed/qpainter_binding.cpp b/src/kjsembed/qpainter_binding.cpp index 328c97a..6cd1ef8 100644 --- a/src/kjsembed/qpainter_binding.cpp +++ b/src/kjsembed/qpainter_binding.cpp @@ -1,493 +1,493 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "qpainter_binding.h" #include "object_binding.h" #include "static_binding.h" #include "kjseglobal.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace KJSEmbed; QPaintDevice *extractPaintDevice(KJS::ExecState *exec, KJS::JSValue *arg) { - QPaintDevice *device = 0; + QPaintDevice *device = nullptr; ObjectBinding *imp = extractBindingImp(exec, arg); if (imp) { #ifdef __GNUC__ #warning There be dragons here... #endif /** * Because of something odd with multiple inheritence and qobject cast * we need to first cast it to a QObject, then cast it to a QWidget. * All other paint devices in Qt that are objects are single inheritence * so dynamic_cast will work properly. */ QObject *qobject = imp->object(); if (qobject) { device = qobject_cast(qobject); } else { device = imp->object(); } if (device) { qDebug("Height = %d Width = %d", device->height(), device->width()); } } else { VariantBinding *valueImp = extractBindingImp(exec, arg); if (valueImp && (valueImp->variant().type() == QVariant::Pixmap || valueImp->variant().type() == QVariant::Image)) { device = static_cast(valueImp->pointer()); } } return device; } START_OBJECT_METHOD(callPainterBegin, QPainter) result = KJS::jsBoolean(false); QPaintDevice *device = extractPaintDevice(exec, args[0]); if (device) { result = KJS::jsBoolean(object->begin(device)); } else { result = KJS::jsBoolean(false); } END_OBJECT_METHOD START_OBJECT_METHOD(callPainterEnd, QPainter) result = KJS::jsBoolean(object->end()); END_OBJECT_METHOD START_OBJECT_METHOD(callbackground, QPainter) QBrush cppValue = object->background(); result = KJSEmbed::createVariant(exec, "QBrush", cppValue); END_OBJECT_METHOD START_OBJECT_METHOD(callbackgroundMode, QPainter) Qt::BGMode cppValue = object->backgroundMode(); result = KJS::jsNumber(cppValue); END_OBJECT_METHOD START_OBJECT_METHOD(callboundingRect, QPainter) if (args.size() == 3) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); QString arg2 = KJSEmbed::extractQString(exec, args, 2); QRect cppValue = object->boundingRect(arg0, arg1, arg2); result = KJSEmbed::createVariant(exec, "QRect", cppValue); } else if (args.size() == 6) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); int arg4 = KJSEmbed::extractInt(exec, args, 4); QString arg5 = KJSEmbed::extractQString(exec, args, 5); QRect cppValue = object->boundingRect(arg0, arg1, arg2, arg3, arg4, arg5); result = KJSEmbed::createVariant(exec, "QRect", cppValue); } END_OBJECT_METHOD START_OBJECT_METHOD(callbrush, QPainter) QBrush cppValue = object->brush(); result = KJSEmbed::createVariant(exec, "QBrush", cppValue); END_OBJECT_METHOD START_OBJECT_METHOD(callbrushOrigin, QPainter) QPoint cppValue = object->brushOrigin(); result = KJSEmbed::createVariant(exec, "QPoint", cppValue); END_OBJECT_METHOD START_OBJECT_METHOD(calldrawArc, QPainter) if (args.size() == 3) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); object->drawArc(arg0, arg1, arg2); } else if (args.size() == 6) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); int arg4 = KJSEmbed::extractInt(exec, args, 4); int arg5 = KJSEmbed::extractInt(exec, args, 5); object->drawArc(arg0, arg1, arg2, arg3, arg4, arg5); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawChord, QPainter) if (args.size() == 3) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); object->drawChord(arg0, arg1, arg2); } else if (args.size() == 6) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); int arg4 = KJSEmbed::extractInt(exec, args, 4); int arg5 = KJSEmbed::extractInt(exec, args, 5); object->drawChord(arg0, arg1, arg2, arg3, arg4, arg5); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawConvexPolygon, QPainter) QPolygon arg0 = KJSEmbed::extractVariant(exec, args, 0); object->drawConvexPolygon(arg0); END_OBJECT_METHOD START_OBJECT_METHOD(calldrawEllipse, QPainter) if (args.size() == 4) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); object->drawEllipse(arg0, arg1, arg2, arg3); } else if (args.size() == 1) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); object->drawEllipse(arg0); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawImage, QPainter) if (args.size() == 2) { QPoint arg0 = KJSEmbed::extractVariant(exec, args, 0); QImage arg1 = KJSEmbed::extractVariant(exec, args, 1); object->drawImage(arg0, arg1); } else if (args.size() == 4) { QPoint arg0 = KJSEmbed::extractVariant(exec, args, 0); QImage arg1 = KJSEmbed::extractVariant(exec, args, 1); QRect arg2 = KJSEmbed::extractVariant(exec, args, 2); Qt::ImageConversionFlags arg3 = (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 3); object->drawImage(arg0, arg1, arg2, arg3); } else if (args.size() == 8) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); QImage arg2 = KJSEmbed::extractVariant(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); int arg4 = KJSEmbed::extractInt(exec, args, 4); int arg5 = KJSEmbed::extractInt(exec, args, 5); int arg6 = KJSEmbed::extractInt(exec, args, 6); Qt::ImageConversionFlags arg7 = (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 7); object->drawImage(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawLine, QPainter) if (args.size() == 1) { QLine arg0 = KJSEmbed::extractVariant(exec, args, 0); object->drawLine(arg0); } else if (args.size() == 2) { QPoint arg0 = KJSEmbed::extractVariant(exec, args, 0); QPoint arg1 = KJSEmbed::extractVariant(exec, args, 1); object->drawLine(arg0, arg1); } else if (args.size() == 4) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); object->drawLine(arg0, arg1, arg2, arg3); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawPie, QPainter) if (args.size() == 3) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); object->drawPie(arg0, arg1, arg2); } else if (args.size() == 6) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); int arg4 = KJSEmbed::extractInt(exec, args, 4); int arg5 = KJSEmbed::extractInt(exec, args, 5); object->drawPie(arg0, arg1, arg2, arg3, arg4, arg5); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawPixmap, QPainter) if (args.size() == 2) { QPoint arg0 = KJSEmbed::extractVariant(exec, args, 0); QPixmap arg1 = KJSEmbed::extractVariant(exec, args, 1); object->drawPixmap(arg0, arg1); } else if (args.size() == 3) { QPoint arg0 = KJSEmbed::extractVariant(exec, args, 0); QPixmap arg1 = KJSEmbed::extractVariant(exec, args, 1); QRect arg2 = KJSEmbed::extractVariant(exec, args, 2); object->drawPixmap(arg0, arg1, arg2); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawPoint, QPainter) if (args.size() == 1) { QPoint arg0 = KJSEmbed::extractVariant(exec, args, 0); object->drawPoint(arg0); } else if (args.size() == 2) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); object->drawPoint(arg0, arg1); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawPoints, QPainter) QPolygon arg0 = KJSEmbed::extractVariant(exec, args, 0); object->drawPoints(arg0); END_OBJECT_METHOD START_OBJECT_METHOD(calldrawPolygon, QPainter) QPolygon arg0 = KJSEmbed::extractVariant(exec, args, 0); Qt::FillRule arg1 = (Qt::FillRule)KJSEmbed::extractInt(exec, args, 1, Qt::OddEvenFill); object->drawPolygon(arg0, arg1); END_OBJECT_METHOD START_OBJECT_METHOD(calldrawPolyline, QPainter) QPolygon arg0 = KJSEmbed::extractVariant(exec, args, 0); object->drawPolyline(arg0); END_OBJECT_METHOD START_OBJECT_METHOD(calldrawRect, QPainter) if (args.size() == 1) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); object->drawRect(arg0); } else if (args.size() == 4) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); object->drawRect(arg0, arg1, arg2, arg3); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawRoundRect, QPainter) if (args.size() == 2) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); object->drawRoundRect(arg0, arg1, arg2); } else if (args.size() == 6) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); int arg4 = KJSEmbed::extractInt(exec, args, 4); int arg5 = KJSEmbed::extractInt(exec, args, 5); object->drawRoundRect(arg0, arg1, arg2, arg3, arg4, arg5); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawText, QPainter) if (args.size() == 2) { QPoint arg0 = KJSEmbed::extractVariant(exec, args, 0); QString arg1 = KJSEmbed::extractQString(exec, args, 1); object->drawText(arg0, arg1); } else if (args.size() == 3) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); QString arg2 = KJSEmbed::extractQString(exec, args, 2); - QRect *arg3 = 0; + QRect *arg3 = nullptr; object->drawText(arg0, arg1, arg2, arg3); } else if (args.size() == 6) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); int arg4 = KJSEmbed::extractInt(exec, args, 4); QString arg5 = KJSEmbed::extractQString(exec, args, 5); - QRect *arg6 = 0; + QRect *arg6 = nullptr; object->drawText(arg0, arg1, arg2, arg3, arg4, arg5, arg6); } END_OBJECT_METHOD START_OBJECT_METHOD(calltranslate, QPainter) if (args.size() == 2) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); object->translate(arg0, arg1); } else if (args.size() == 1) { QPoint arg0 = KJSEmbed::extractVariant(exec, args, 0); object->translate(arg0); } END_OBJECT_METHOD START_OBJECT_METHOD(calldrawTiledPixmap, QPainter) if (args.size() == 3) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); QPixmap arg1 = KJSEmbed::extractVariant(exec, args, 1); QPoint arg2 = KJSEmbed::extractVariant(exec, args, 2); object->drawTiledPixmap(arg0, arg1, arg2); } else if (args.size() == 7) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); QPixmap arg4 = KJSEmbed::extractVariant(exec, args, 4); int arg5 = KJSEmbed::extractInt(exec, args, 5); int arg6 = KJSEmbed::extractInt(exec, args, 6); object->drawTiledPixmap(arg0, arg1, arg2, arg3, arg4, arg5, arg6); } END_OBJECT_METHOD START_OBJECT_METHOD(calleraseRect, QPainter) if (args.size() == 4) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); int arg2 = KJSEmbed::extractInt(exec, args, 2); int arg3 = KJSEmbed::extractInt(exec, args, 3); object->eraseRect(arg0, arg1, arg2, arg3); } else if (args.size() == 1) { QRect arg0 = KJSEmbed::extractVariant(exec, args, 0); object->eraseRect(arg0); } END_OBJECT_METHOD START_METHOD_LUT(Painter) {"begin", 1, KJS::DontDelete | KJS::ReadOnly, &callPainterBegin }, {"end", 0, KJS::DontDelete | KJS::ReadOnly, &callPainterEnd }, {"background", 0, KJS::DontDelete | KJS::ReadOnly, &callbackground}, {"backgroundMode", 0, KJS::DontDelete | KJS::ReadOnly, &callbackgroundMode}, {"boundingRect", 6, KJS::DontDelete | KJS::ReadOnly, &callboundingRect}, {"brush", 0, KJS::DontDelete | KJS::ReadOnly, &callbrush}, {"brushOrigin", 0, KJS::DontDelete | KJS::ReadOnly, &callbrushOrigin}, {"drawArc", 6, KJS::DontDelete | KJS::ReadOnly, &calldrawArc}, {"drawChord", 6, KJS::DontDelete | KJS::ReadOnly, &calldrawChord}, {"drawConvexPolygon", 1, KJS::DontDelete | KJS::ReadOnly, &calldrawConvexPolygon}, {"drawEllipse", 3, KJS::DontDelete | KJS::ReadOnly, &calldrawEllipse}, {"drawImage", 7, KJS::DontDelete | KJS::ReadOnly, &calldrawImage}, {"drawLine", 3, KJS::DontDelete | KJS::ReadOnly, &calldrawLine}, //{drawLines", 1, KJS::DontDelete|KJS::ReadOnly, &calldrawLines}, //{"drawPath", 0, KJS::DontDelete|KJS::ReadOnly, &calldrawPath}, //{"drawPicture", 2, KJS::DontDelete|KJS::ReadOnly, &calldrawPicture}, {"drawPie", 6, KJS::DontDelete | KJS::ReadOnly, &calldrawPie}, {"drawPixmap", 8, KJS::DontDelete | KJS::ReadOnly, &calldrawPixmap}, {"drawPoint", 2, KJS::DontDelete | KJS::ReadOnly, &calldrawPoint}, {"drawPoints", 1, KJS::DontDelete | KJS::ReadOnly, &calldrawPoints}, {"drawPolygon", 2, KJS::DontDelete | KJS::ReadOnly, &calldrawPolygon}, {"drawPolyline", 1, KJS::DontDelete | KJS::ReadOnly, &calldrawPolyline}, {"drawRect", 4, KJS::DontDelete | KJS::ReadOnly, &calldrawRect}, //{"drawRects", 0, KJS::DontDelete|KJS::ReadOnly, &calldrawRects}, {"drawRoundRect", 5, KJS::DontDelete | KJS::ReadOnly, &calldrawRoundRect}, {"drawText", 7, KJS::DontDelete | KJS::ReadOnly, &calldrawText}, {"drawTiledPixmap", 3, KJS::DontDelete | KJS::ReadOnly, &calldrawTiledPixmap}, {"eraseRect", 1, KJS::DontDelete | KJS::ReadOnly, &calleraseRect}, //{"fillPath", 1, KJS::DontDelete|KJS::ReadOnly, &callfillPath}, //{"fillRect", 4, KJS::DontDelete|KJS::ReadOnly, &callfillRect}, //{"font", 0, KJS::DontDelete|KJS::ReadOnly, &callfont}, //{"hasClipping", 0, KJS::DontDelete|KJS::ReadOnly, &callhasClipping}, //{"isActive", 0, KJS::DontDelete|KJS::ReadOnly, &callisActive}, //{"pen", 0, KJS::DontDelete|KJS::ReadOnly, &callpen}, //{"renderHints", 0, KJS::DontDelete|KJS::ReadOnly, &callrenderHints}, //{"restore", 0, KJS::DontDelete|KJS::ReadOnly, &callrestore}, //{"rotate", 0, KJS::DontDelete|KJS::ReadOnly, &callrotate}, //{"save", 0, KJS::DontDelete|KJS::ReadOnly, &callsave}, //{"scale", 1, KJS::DontDelete|KJS::ReadOnly, &callscale}, //{"setBackground", 0, KJS::DontDelete|KJS::ReadOnly, &callsetBackground}, //{"setBackgroundColor", 0, KJS::DontDelete|KJS::ReadOnly, &callsetBackgroundColor}, //{"setBackgroundMode", 0, KJS::DontDelete|KJS::ReadOnly, &callsetBackgroundMode}, //{"setBrush", 0, KJS::DontDelete|KJS::ReadOnly, &callsetBrush}, //{"setBrushOrigin", 1, KJS::DontDelete|KJS::ReadOnly, &callsetBrushOrigin}, //{"setClipPath", 1, KJS::DontDelete|KJS::ReadOnly, &callsetClipPath}, //{"setClipRect", 4, KJS::DontDelete|KJS::ReadOnly, &callsetClipRect}, //{"setClipRegion", 1, KJS::DontDelete|KJS::ReadOnly, &callsetClipRegion}, //{"setClipping", 0, KJS::DontDelete|KJS::ReadOnly, &callsetClipping}, //{"setFont", 1, KJS::DontDelete|KJS::ReadOnly, &callsetFont}, //{"setPen", 1, KJS::DontDelete|KJS::ReadOnly, &callsetPen}, //{"setRenderHint", 1, KJS::DontDelete|KJS::ReadOnly, &callsetRenderHint}, //{"shear", 2, KJS::DontDelete|KJS::ReadOnly, &callshear}, //{"strokePath", 1, KJS::DontDelete|KJS::ReadOnly, &callstrokePath}, {"translate", 1, KJS::DontDelete | KJS::ReadOnly, &calltranslate} END_METHOD_LUT NO_ENUMS(Painter) NO_STATICS(Painter) START_CTOR(Painter, QPainter, 0) KJS::JSObject *object; if (args.size() == 1) { QPaintDevice *device = extractPaintDevice(exec, args[0]); if (device) { object = new KJSEmbed::ObjectBinding(exec, "Painter", new QPainter(device)); } else { KJS::throwError(exec, KJS::EvalError, QString("Cannot paint to object %1").arg(toQString(args[0]->toString(exec)))); - return 0L; + return nullptr; } } else { object = new KJSEmbed::ObjectBinding(exec, "Painter", new QPainter()); } StaticBinding::publish(exec, object, ObjectFactory::methods()); StaticBinding::publish(exec, object, Painter::methods()); return object; END_CTOR diff --git a/src/kjsembed/quiloader_binding.cpp b/src/kjsembed/quiloader_binding.cpp index f82de0d..3a60e60 100644 --- a/src/kjsembed/quiloader_binding.cpp +++ b/src/kjsembed/quiloader_binding.cpp @@ -1,165 +1,165 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "quiloader_binding.h" #include #include #include #include "qwidget_binding.h" #include "qobject_binding.h" #include "qaction_binding.h" #include "qlayout_binding.h" #include "static_binding.h" #include "kjseglobal.h" using namespace KJSEmbed; KJSO_SIMPLE_BINDING_CTOR(UiLoaderBinding, QUiLoader, QObjectBinding) KJSO_QOBJECT_BIND(UiLoaderBinding, QUiLoader) KJSO_START_CTOR(UiLoaderBinding, QUiLoader, 1) { - QUiLoader *uiLoader = 0; + QUiLoader *uiLoader = nullptr; if (args.size() == 0) { uiLoader = new QUiLoader(); } else if (args.size() == 1) { - QObject *arg0 = KJSEmbed::extractObject(exec, args, 0, 0); + QObject *arg0 = KJSEmbed::extractObject(exec, args, 0, nullptr); uiLoader = new QUiLoader(arg0); } else { return KJS::throwError(exec, KJS::GeneralError, i18n("Not enough arguments.")); } KJS::JSObject *uiLoaderBinding = new UiLoaderBinding(exec, uiLoader); // qDebug() << "UiLoaderBinding::CTOR() args.size()=" << args.size() << " uiLoader=" << uiLoader << " uiLoaderBinding=" << uiLoaderBinding; return uiLoaderBinding; } KJSO_END_CTOR namespace UiLoaderNS { START_QOBJECT_METHOD(createAction, QUiLoader) { - QObject *parent = KJSEmbed::extractObject(exec, args, 0, 0); + QObject *parent = KJSEmbed::extractObject(exec, args, 0, nullptr); QString actionName = KJSEmbed::extractQString(exec, args, 1); QAction *action = object->createAction(parent, actionName); if (action) { return KJSEmbed::createQObject(exec, action); } else { return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create Action.")); } } END_QOBJECT_METHOD START_QOBJECT_METHOD(createActionGroup, QUiLoader) -QObject *parent = KJSEmbed::extractObject(exec, args, 0, 0); +QObject *parent = KJSEmbed::extractObject(exec, args, 0, nullptr); QString actionName = KJSEmbed::extractQString(exec, args, 1); QActionGroup *actionGroup = object->createActionGroup(parent, actionName); if (actionGroup) { return KJSEmbed::createQObject(exec, actionGroup); } else { return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create ActionGroup.")); } END_QOBJECT_METHOD START_QOBJECT_METHOD(createLayout, QUiLoader) { QString className = KJSEmbed::extractQString(exec, args, 0); if (className.isEmpty()) { return KJS::throwError(exec, KJS::SyntaxError, i18n("No classname specified")); } - QObject *parent = KJSEmbed::extractObject(exec, args, 1, 0); + QObject *parent = KJSEmbed::extractObject(exec, args, 1, nullptr); QString name = KJSEmbed::extractQString(exec, args, 2); QLayout *layout = object->createLayout(className, parent, name); if (layout) { return KJSEmbed::createQObject(exec, layout); } else { return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create Layout.")); } } END_QOBJECT_METHOD START_QOBJECT_METHOD(createWidget, QUiLoader) { QString className = KJSEmbed::extractQString(exec, args, 0); if (className.isEmpty()) { return KJS::throwError(exec, KJS::SyntaxError, i18n("No classname specified.")); } - QWidget *parent = KJSEmbed::extractObject(exec, args, 1, 0); + QWidget *parent = KJSEmbed::extractObject(exec, args, 1, nullptr); QString name = KJSEmbed::extractQString(exec, args, 2); QWidget *widget = object->createWidget(className, parent, name); if (widget) { return KJSEmbed::createQObject(exec, widget); } else { return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create Widget.")); } } END_QOBJECT_METHOD START_QOBJECT_METHOD(load, QUiLoader) { QString fileName = KJSEmbed::extractQString(exec, args, 0); if (fileName.isEmpty()) { return KJS::throwError(exec, KJS::SyntaxError, i18n("Must supply a filename.")); } QFile uiFile(fileName); if (! uiFile.open(QIODevice::ReadOnly | QIODevice::Text)) { return KJS::throwError(exec, KJS::GeneralError, i18n("Could not open file '%1': %2", fileName, uiFile.errorString())); } - QWidget *parent = KJSEmbed::extractObject(exec, args, 1, 0); + QWidget *parent = KJSEmbed::extractObject(exec, args, 1, nullptr); QWidget *widget = object->load(&uiFile, parent); uiFile.close(); if (! widget) { return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to load file '%1'", fileName)); } KJS::JSObject *result = KJSEmbed::createQObject(exec, widget); // qDebug() << "UiLoaderBinding::load(): fileName=" << fileName << "widget " << widget << " result=" << result << "(" << result->toString(exec).ascii() << ")"; return result; } END_QOBJECT_METHOD START_QOBJECT_METHOD(pluginPaths, QUiLoader) // qDebug() << "UiLoader::pluginPaths(): " << object->pluginPaths(); result = KJSEmbed::convertToValue(exec, QVariant(object->pluginPaths())); END_QOBJECT_METHOD } START_METHOD_LUT(UiLoaderBinding) {"createAction", 0, KJS::DontDelete | KJS::ReadOnly, &UiLoaderNS::createAction}, {"createActionGroup", 0, KJS::DontDelete | KJS::ReadOnly, &UiLoaderNS::createActionGroup}, {"createLayout", 1, KJS::DontDelete | KJS::ReadOnly, &UiLoaderNS::createLayout}, {"createWidget", 1, KJS::DontDelete | KJS::ReadOnly, &UiLoaderNS::createWidget}, {"load", 1, KJS::DontDelete | KJS::ReadOnly, &UiLoaderNS::load}, {"load", 2, KJS::DontDelete | KJS::ReadOnly, &UiLoaderNS::load}, {"pluginPaths", 0, KJS::DontDelete | KJS::ReadOnly, &UiLoaderNS::pluginPaths} END_METHOD_LUT NO_ENUMS(UiLoaderBinding) NO_STATICS(UiLoaderBinding) diff --git a/src/kjsembed/qwidget_binding.cpp b/src/kjsembed/qwidget_binding.cpp index 30a649d..19369ec 100644 --- a/src/kjsembed/qwidget_binding.cpp +++ b/src/kjsembed/qwidget_binding.cpp @@ -1,172 +1,172 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "qwidget_binding.h" #include "static_binding.h" #include "qpainter_binding.h" #include "kjseglobal.h" #include #include #include #include #include #include #include namespace KJSEmbed { -static QUiLoader *gUiLoader = 0L; +static QUiLoader *gUiLoader = nullptr; QUiLoader *uiLoader() { - if (gUiLoader == 0) { + if (gUiLoader == nullptr) { gUiLoader = new QUiLoader(); } return gUiLoader; } } using namespace KJSEmbed; namespace WidgetNS { START_QOBJECT_METHOD(adjustSize, QWidget) object->adjustSize(); END_QOBJECT_METHOD START_QOBJECT_METHOD(grabMouse, QWidget) object->grabMouse(); END_QOBJECT_METHOD START_QOBJECT_METHOD(grabKeyboard, QWidget) object->grabKeyboard(); END_QOBJECT_METHOD START_QOBJECT_METHOD(releaseMouse, QWidget) object->releaseMouse(); END_QOBJECT_METHOD START_QOBJECT_METHOD(releaseKeyboard, QWidget) object->releaseKeyboard(); END_QOBJECT_METHOD START_QOBJECT_METHOD(childAt, QWidget) QPoint pt = KJSEmbed::extractVariant(exec, args, 0); int x, y; -QWidget *child = 0; +QWidget *child = nullptr; if (pt.isNull()) { x = KJSEmbed::extractVariant(exec, args, 0); y = KJSEmbed::extractVariant(exec, args, 1); child = object->childAt(x, y); } else { child = object->childAt(pt); } result = new QWidgetBinding(exec, child); END_QOBJECT_METHOD START_QOBJECT_METHOD(focusWidget, QWidget) result = KJSEmbed::createQObject(exec, object->focusWidget()); END_QOBJECT_METHOD START_QOBJECT_METHOD(heightForWidth, QWidget) // qDebug() << "heightForWidth() object=" << object << " imp=" << imp; int width = KJSEmbed::extractInt(exec, args, 0); result = KJS::jsNumber(object->heightForWidth(width)); END_QOBJECT_METHOD START_QOBJECT_METHOD(mapFrom, QWidget) -QWidget *w = KJSEmbed::extractObject(exec, args, 0, 0); +QWidget *w = KJSEmbed::extractObject(exec, args, 0, nullptr); QPoint pt = KJSEmbed::extractVariant(exec, args, 1); result = KJSEmbed::createVariant(exec, "QPoint", object->mapFrom(w, pt)); END_QOBJECT_METHOD START_QOBJECT_METHOD(mapFromGlobal, QWidget) QPoint pt = KJSEmbed::extractVariant(exec, args, 0); result = KJSEmbed::createVariant(exec, "QPoint", object->mapFromGlobal(pt)); END_QOBJECT_METHOD START_QOBJECT_METHOD(mapFromParent, QWidget) QPoint pt = KJSEmbed::extractVariant(exec, args, 0); result = KJSEmbed::createVariant(exec, "QPoint", object->mapFromParent(pt)); END_QOBJECT_METHOD START_QOBJECT_METHOD(mapTo, QWidget) -QWidget *w = KJSEmbed::extractObject(exec, args, 0, 0); +QWidget *w = KJSEmbed::extractObject(exec, args, 0, nullptr); QPoint pt = KJSEmbed::extractVariant(exec, args, 1); result = KJSEmbed::createVariant(exec, "QPoint", object->mapTo(w, pt)); END_QOBJECT_METHOD START_QOBJECT_METHOD(mapToParent, QWidget) QPoint pt = KJSEmbed::extractVariant(exec, args, 0); result = KJSEmbed::createVariant(exec, "QPoint", object->mapToParent(pt)); END_QOBJECT_METHOD START_QOBJECT_METHOD(mapToGlobal, QWidget) QPoint pt = KJSEmbed::extractVariant(exec, args, 0); result = KJSEmbed::createVariant(exec, "QPoint", object->mapToGlobal(pt)); END_QOBJECT_METHOD } START_METHOD_LUT(QWidgetBinding) {"adjustSize", 0, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::adjustSize}, {"grabMouse", 0, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::grabMouse}, {"grabKeyboard", 0, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::grabKeyboard}, {"releaseMouse", 0, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::releaseMouse}, {"releaseKeyboard", 0, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::releaseKeyboard}, {"childAt", 1, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::childAt}, {"focusWidget", 0, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::focusWidget}, {"heightForWidth", 1, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::heightForWidth}, {"mapFrom", 2, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::mapFrom}, {"mapFromGlobal", 1, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::mapFromGlobal}, {"mapFromParent", 1, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::mapFromParent}, {"mapTo", 2, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::mapTo}, {"mapToParent", 1, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::mapToParent}, {"mapToGlobal", 1, KJS::DontDelete | KJS::ReadOnly, &WidgetNS::mapToGlobal} END_METHOD_LUT NO_ENUMS(QWidgetBinding) NO_STATICS(QWidgetBinding) KJSO_SIMPLE_BINDING_CTOR(QWidgetBinding, QWidget, QObjectBinding) KJSO_QOBJECT_BIND(QWidgetBinding, QWidget) KJSO_START_CTOR(QWidgetBinding, QWidget, 0) //qDebug() << "QWidgetBinding::CTOR args.size()=" << args.size(); if (args.size() > 0) { QString widgetName = toQString(args[0]->toString(exec)); - QWidget *parentWidget = 0; + QWidget *parentWidget = nullptr; KJSEmbed::QObjectBinding *parentImp = KJSEmbed::extractBindingImp(exec, args[1]); if (parentImp) { parentWidget = parentImp->object(); } QWidget *widget = uiLoader()->createWidget(widgetName, parentWidget, "QWidget"); if (widget) { return new QWidgetBinding(exec, widget); } return KJS::throwError(exec, KJS::TypeError, toUString(i18n("'%1' is not a valid QWidget.", widgetName))); } else { QWidget *widget = new QWidget(); if (widget) { return new QWidgetBinding(exec, widget); } } return KJS::throwError(exec, KJS::GeneralError, toUString(i18n("Must supply a widget name."))); END_CTOR diff --git a/src/kjsembed/settings.cpp b/src/kjsembed/settings.cpp index a5bcb67..bb663eb 100644 --- a/src/kjsembed/settings.cpp +++ b/src/kjsembed/settings.cpp @@ -1,122 +1,122 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "settings.h" #include #include "kjseglobal.h" using namespace KJSEmbed; START_QOBJECT_METHOD(callAllKeys, QSettings) QStringList keys = object->allKeys(); result = KJSEmbed::convertToValue(exec, keys); END_QOBJECT_METHOD START_QOBJECT_METHOD(callSetValue, QSettings) QString key = KJSEmbed::extractQString(exec, args, 0); QVariant value = KJSEmbed::convertToVariant(exec, args[1]); object->setValue(key, value); END_QOBJECT_METHOD START_QOBJECT_METHOD(callValue, QSettings) QVariant value; QString key = KJSEmbed::extractQString(exec, args, 0); if (args.size() == 2) { value = KJSEmbed::convertToVariant(exec, args[1]); } value = object->value(key, value); result = KJSEmbed::convertToValue(exec, value); END_QOBJECT_METHOD START_QOBJECT_METHOD(callClear, QSettings) object->clear(); END_QOBJECT_METHOD START_QOBJECT_METHOD(callSync, QSettings) object->sync(); END_QOBJECT_METHOD START_QOBJECT_METHOD(callRemove, QSettings) QString key = KJSEmbed::extractQString(exec, args, 0); object->remove(key); END_QOBJECT_METHOD START_STATIC_OBJECT_METHOD(callSetPath) // QSettings::Format format = (QSettings::Format) KJSEmbed::extractVariant(exec, args, 0); // QSettings::Scope scope = (QSettings::Scope) KJSEmbed::extractVariant(exec, args, 1); QString path = KJSEmbed::extractQString(exec, args, 2); //QSettings::setSystemIniPath(format,scope,path); return KJS::jsNull(); END_STATIC_OBJECT_METHOD START_METHOD_LUT(SettingsBinding) {"allKeys", 0, KJS::DontDelete | KJS::ReadOnly, &callAllKeys }, {"setValue", 2, KJS::DontDelete | KJS::ReadOnly, &callSetValue }, {"value", 1, KJS::DontDelete | KJS::ReadOnly, &callValue }, {"clear", 0, KJS::DontDelete | KJS::ReadOnly, &callClear }, {"sync", 0, KJS::DontDelete | KJS::ReadOnly, &callSync }, {"remove", 1, KJS::DontDelete | KJS::ReadOnly, &callRemove } END_METHOD_LUT START_ENUM_LUT(SettingsBinding) {"NativeFormat", QSettings::NativeFormat}, {"IniFormat", QSettings::IniFormat}, //{"InvalidFormat", QSettings::InvalidFormat}, {"UserScope", QSettings::UserScope}, {"SystemScope", QSettings::SystemScope} END_ENUM_LUT START_STATIC_METHOD_LUT(SettingsBinding) {"setPath", 3, KJS::DontDelete | KJS::ReadOnly, &callSetPath } END_METHOD_LUT KJSO_SIMPLE_BINDING_CTOR(SettingsBinding, QSettings, QObjectBinding) KJSO_QOBJECT_BIND(SettingsBinding, QSettings) KJSO_START_CTOR(SettingsBinding, QSettings, 1) -QSettings *settings = 0; +QSettings *settings = nullptr; if (args.size() == 1) { QObject *parent = KJSEmbed::extractObject(exec, args, 0); settings = new QSettings(parent); } else if (args.size() == 3) { QString fileName = KJSEmbed::extractQString(exec, args, 0); QSettings::Format format = (QSettings::Format) KJSEmbed::extractVariant(exec, args, 1); QObject *parent = KJSEmbed::extractObject(exec, args, 2); settings = new QSettings(fileName, format, parent); } else if (args.size() == 4) { QSettings::Scope scope = (QSettings::Scope) KJSEmbed::extractVariant(exec, args, 0); QString organization = KJSEmbed::extractQString(exec, args, 1); QString application = KJSEmbed::extractQString(exec, args, 2); QObject *parent = KJSEmbed::extractObject(exec, args, 3); settings = new QSettings(scope, organization, application, parent); } else { settings = new QSettings(); } return new SettingsBinding(exec, settings); KJSO_END_CTOR diff --git a/src/kjsembed/size.cpp b/src/kjsembed/size.cpp index 91d4ccf..5e57560 100644 --- a/src/kjsembed/size.cpp +++ b/src/kjsembed/size.cpp @@ -1,150 +1,150 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "size.h" #include #include using namespace KJSEmbed; -const KJS::ClassInfo SizeBinding::info = { "QSize", &VariantBinding::info, 0, 0 }; +const KJS::ClassInfo SizeBinding::info = { "QSize", &VariantBinding::info, nullptr, nullptr }; SizeBinding::SizeBinding(KJS::ExecState *exec, const QSize &value) : VariantBinding(exec, value) { StaticBinding::publish(exec, this, Size::methods()); StaticBinding::publish(exec, this, VariantFactory::methods()); } namespace SizeNS { START_VARIANT_METHOD(callboundedTo, QSize) QSize arg0 = KJSEmbed::extractVariant(exec, args, 0); QSize cppValue = value.boundedTo(arg0); result = KJSEmbed::createVariant(exec, "QSize", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callexpandedTo, QSize) QSize arg0 = KJSEmbed::extractVariant(exec, args, 0); QSize cppValue = value.expandedTo(arg0); result = KJSEmbed::createVariant(exec, "QSize", cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callheight, QSize) int cppValue = value.height(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callisEmpty, QSize) bool cppValue = value.isEmpty(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callisNull, QSize) bool cppValue = value.isNull(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callisValid, QSize) bool cppValue = value.isValid(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callrheight, QSize) int cppValue = value.rheight(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callrwidth, QSize) int cppValue = value.rwidth(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(callscale, QSize) if (args.size() == 2) { QSize arg0 = KJSEmbed::extractVariant(exec, args, 0); Qt::AspectRatioMode arg1 = (Qt::AspectRatioMode)KJSEmbed::extractInt(exec, args, 1); value.scale(arg0, arg1); } else if (args.size() == 3) { int arg0 = KJSEmbed::extractInt(exec, args, 0); int arg1 = KJSEmbed::extractInt(exec, args, 1); Qt::AspectRatioMode arg2 = (Qt::AspectRatioMode)KJSEmbed::extractInt(exec, args, 2); value.scale(arg0, arg1, arg2); } END_VARIANT_METHOD START_VARIANT_METHOD(callsetHeight, QSize) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setHeight(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(callsetWidth, QSize) int arg0 = KJSEmbed::extractInt(exec, args, 0); value.setWidth(arg0); END_VARIANT_METHOD START_VARIANT_METHOD(calltranspose, QSize) value.transpose(); END_VARIANT_METHOD START_VARIANT_METHOD(callwidth, QSize) int cppValue = value.width(); result = KJS::jsNumber(cppValue); END_VARIANT_METHOD } START_METHOD_LUT(Size) {"boundedTo", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callboundedTo}, {"expandedTo", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callexpandedTo}, {"height", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callheight}, {"isEmpty", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callisEmpty}, {"isNull", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callisNull}, {"isValid", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callisValid}, {"rheight", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callrheight}, {"rwidth", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callrwidth}, {"scale", 2, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callscale}, {"setHeight", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callsetHeight}, {"setWidth", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callsetWidth}, {"transpose", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::calltranspose}, {"width", 0, KJS::DontDelete | KJS::ReadOnly, &SizeNS::callwidth} END_METHOD_LUT NO_ENUMS(Size) NO_STATICS(Size) START_CTOR(Size, QSize, 0) if (args.size() == 0) { return new KJSEmbed::SizeBinding(exec, QSize()); } else if (args.size() == 2) { return new KJSEmbed::SizeBinding(exec, QSize(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1) )); } return new KJSEmbed::SizeBinding(exec, QSize()); END_CTOR diff --git a/src/kjsembed/slotproxy.cpp b/src/kjsembed/slotproxy.cpp index ce941a2..3533611 100644 --- a/src/kjsembed/slotproxy.cpp +++ b/src/kjsembed/slotproxy.cpp @@ -1,297 +1,297 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "slotproxy.h" #include #include #include #include #include #include "variant_binding.h" #include "qobject_binding.h" //#define DEBUG_SLOTPROXY 1 using namespace KJSEmbed; SlotProxy::SlotProxy(KJS::JSObject *obj, KJS::Interpreter *interpreter, QObject *parent, const QByteArray &signature) : QObject(parent), m_interpreter(interpreter), m_object(obj) { m_signature = QMetaObject::normalizedSignature(signature.constData()); uint signatureSize = m_signature.size() + 1; // content: m_data[0] = 1; // revision m_data[1] = 0; // classname m_data[2] = 0; // classinfo m_data[3] = 0; // classinfo m_data[4] = 1; // methods m_data[5] = 10; // methods m_data[6] = 0; // properties m_data[7] = 0; // properties m_data[8] = 0; // enums/sets m_data[9] = 0; // enums/sets // Q_SLOTS: m_data[10] = 10; //signature start m_data[11] = 10 + signatureSize; //parameters start m_data[12] = 10 + signatureSize; //type start m_data[13] = 10 + signatureSize; //tag start m_data[14] = 0x0a;//flags m_data[15] = 0; // eod m_stringData = QByteArray("SlotProxy\0", 10); m_stringData += m_signature; m_stringData += QByteArray("\0\0", 2); staticMetaObject.d.superdata = &QObject::staticMetaObject; staticMetaObject.d.stringdata = m_stringData.data_ptr(); staticMetaObject.d.data = m_data; - staticMetaObject.d.extradata = 0; + staticMetaObject.d.extradata = nullptr; #ifdef DEBUG_SLOTPROXY qDebug() << "SlotProxy() obj=" << this << " m_signature=" << m_signature; #endif } SlotProxy::~SlotProxy() { #ifdef DEBUG_SLOTPROXY qDebug() << "??????SlotProxy::~SlotProxy() obj=" << this << " m_signature=" << m_signature; #endif } const QMetaObject *SlotProxy::metaObject() const { return &staticMetaObject; } void *SlotProxy::qt_metacast(const char *_clname) { if (!_clname) { - return 0; + return nullptr; } if (!strcmp(_clname, m_stringData.constData())) { return static_cast(const_cast(this)); } return QObject::qt_metacast(_clname); } KJS::JSValue *SlotProxy::callMethod(const QByteArray &methodName, void **_a) { #ifdef DEBUG_SLOTPROXY qDebug() << "SlotProxy::callMethod(" << methodName << ",_a) obj=" << this; #endif KJS::ExecState *exec = m_interpreter->globalExec(); exec->clearException(); // Crash // KJS::Interpreter::globalExec()->context().thisValue() KJS::List args = convertArguments(exec, _a); KJS::Identifier id = KJS::Identifier(KJS::UString(methodName.data())); KJS::JSObject *fun = m_object->get(exec, id)->toObject(exec); KJS::JSValue *retValue; if (!fun->implementsCall()) { #ifdef DEBUG_SLOTPROXY qDebug() << "SlotProxy::callMethod got bad handler"; #endif QString msg = i18n("Bad slot handler: Object %1 Identifier %2 Method %3 Signature: %4.", m_object->className().ascii(), id.ascii(), methodName.data(), QString(m_signature)); retValue = throwError(exec, KJS::TypeError, msg); } else { retValue = fun->call(exec, m_object, args); } if (exec->hadException()) { #ifdef DEBUG_SLOTPROXY qDebug() << "SlotProxy::callMethod had exception"; #endif if (m_interpreter->shouldPrintExceptions()) { KJS::JSLock lock; KJS::JSObject *exceptObj = exec->exception()->toObject(exec);//retValue->toObject(exec); QString message = toQString(exceptObj->toString(exec)); QString sourceURL = toQString(exceptObj->get(exec, "sourceURL")->toString(exec)); int sourceId = exceptObj->get(exec, "sourceId")->toUInt32(exec); // would include the line number, but it's always last line of file int line = exceptObj->get(exec, "line")->toUInt32(exec); (*KJSEmbed::conerr()) << i18n("Exception calling '%1' slot from %2:%3:%4", QString(methodName), !sourceURL.isEmpty() ? sourceURL : QString::number(sourceId), line, message) << endl; } // clear it so it doesn't stop other things exec->clearException(); return KJS::jsNull(); } else { if (retValue->type() == 1 || retValue->type() == 0) { return KJS::jsNull(); } } return retValue; } KJS::List SlotProxy::convertArguments(KJS::ExecState *exec, void **_a) { KJS::List args; int offset = metaObject()->indexOfMethod(m_signature.constData()); QMetaMethod method = metaObject()->method(offset); QList params = method.parameterTypes(); int idx = 1; #ifdef DEBUG_SLOTPROXY qDebug() << "SlotProxy::convertArguments(): obj=" << this << " m_signature=" << m_signature << " offset=" << offset << " params=" << params; #endif foreach (const QByteArray ¶m, params) { #ifdef DEBUG_SLOTPROXY int type = QMetaType::type(param.constData()); qDebug("\tGot a %d - %s - _a[%d] = %p", type, param.data(), idx, _a[idx]); qDebug("\t QMetaType::type()=%d", QMetaType::type(QByteArray("Pinya::") + param.constData())); #endif int tp = QVariant::nameToType(param.constData()); switch (tp) { case QVariant::Int: args.append(KJS::jsNumber(*(int *)_a[idx])); break; case QVariant::UInt: args.append(KJS::jsNumber(*(uint *)_a[idx])); break; case QVariant::LongLong: args.append(KJS::jsNumber(*(qlonglong *)_a[idx])); break; case QVariant::ULongLong: args.append(KJS::jsNumber(*(qulonglong *)_a[idx])); break; case QVariant::Double: args.append(KJS::jsNumber(*(double *)_a[idx])); break; case QVariant::Bool: args.append(KJS::jsBoolean(*(bool *)_a[idx])); break; case QVariant::String: args.append(KJS::jsString((*reinterpret_cast(_a[idx])))); break; case QVariant::UserType: { KJS::JSObject *returnValue; KJS::JSObject *parent = exec->dynamicInterpreter()->globalObject(); QByteArray typeName = param.constData(); bool isPtr = typeName.contains("*"); if (isPtr) { typeName.replace("*", ""); //krazy:exclude=doublequote_chars } #ifdef DEBUG_SLOTPROXY qDebug() << "\tQVariant::UserType: typeName=" << typeName << " param=" << param.constData() << " isPtr" << isPtr; #endif if (parent->hasProperty(exec, KJS::Identifier(toUString(typeName)))) { QObject *qObj; if (isPtr && - ((qObj = *reinterpret_cast(_a[idx])) != 0)) { + ((qObj = *reinterpret_cast(_a[idx])) != nullptr)) { #ifdef DEBUG_SLOTPROXY qDebug() << "qObj=" << qObj; #endif Pointer pov(*reinterpret_cast(_a[idx])); returnValue = StaticConstructor::bind(exec, typeName, pov); if (returnValue) { args.append(returnValue); break; } else { #ifdef DEBUG_SLOTPROXY qDebug("\t\tNo binding retrieved"); #endif returnValue = StaticConstructor::construct(exec, parent, toUString(typeName)); if (returnValue) { if (QObjectBinding *objImp = KJSEmbed::extractBindingImp(exec, returnValue)) { #ifdef DEBUG_SLOTPROXY qDebug() << "\t\t\tFound QObjectBinding"; #endif objImp->setOwnership(KJSEmbed::ObjectBinding::JSOwned); objImp->setObject(qObj); - if (qObj->parent() != 0) { + if (qObj->parent() != nullptr) { objImp->setOwnership(KJSEmbed::ObjectBinding::QObjOwned); } else { objImp->setOwnership(KJSEmbed::ObjectBinding::CPPOwned); } args.append(returnValue); break; } } } } } else { #ifdef DEBUG_SLOTPROXY qDebug("\t\tNo binding registered"); #endif - KJS::JSObject *returnValue = 0; + KJS::JSObject *returnValue = nullptr; const int metaTypeId = QMetaType::type(param.constData()); if (QMetaType::typeFlags(metaTypeId) & QMetaType::PointerToQObject) { QObject *obj = (*reinterpret_cast< QObject*(*)>(_a[idx])); returnValue = KJSEmbed::createQObject(exec, obj, KJSEmbed::ObjectBinding::QObjOwned); } if (returnValue) { args.append(returnValue); break; } } } case QVariant::StringList: case QVariant::List: case QVariant::Map: default: //qDebug("\t\tconverting to variant"); QVariant variant(tp, _a[idx]); args.append(KJSEmbed::convertToValue(exec, variant)); break; } ++idx; } return args; } int SlotProxy::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { #ifdef DEBUG_SLOTPROXY qDebug("SlotProxy::qt_metacall(_c=%d, _id=%d, _a=%p _a[0]=%p _a[1]=%p) obj=", _c, _id, _a, _a[0], _a[1], this); #endif _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) { return _id; } if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: { // invoke js method here QByteArray method = m_signature.left(m_signature.indexOf('(')); KJS::JSValue *result = callMethod(method, _a); m_tmpResult = convertToVariant(m_interpreter->globalExec(), result); #ifdef DEBUG_SLOTPROXY qDebug() << "SlotProxy::qt_metacall result=" << m_tmpResult.toString(); #endif _a[0] = &(m_tmpResult); } break; } _id -= 1; } return _id; } diff --git a/src/kjsembed/static_binding.cpp b/src/kjsembed/static_binding.cpp index f0b2178..eb60e7f 100644 --- a/src/kjsembed/static_binding.cpp +++ b/src/kjsembed/static_binding.cpp @@ -1,148 +1,148 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "static_binding.h" #include #include #include namespace KJSEmbed { static QHash g_ctorHash; } using namespace KJSEmbed; StaticBinding::StaticBinding(KJS::ExecState *exec, const Method *method) : KJS::InternalFunctionImp(static_cast(exec->lexicalInterpreter()->builtinFunctionPrototype()), method->name), m_method(method) { putDirect(exec->propertyNames().length, m_method->argc, LengthFlags); } KJS::JSValue *StaticBinding::callAsFunction(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { - if (m_method->call == 0) { + if (m_method->call == nullptr) { //throwError(exec, "Bad method id"); // NOTE: fix KJS::throwError(exec, KJS::GeneralError, "Bad method id"); return KJS::jsNull(); } KJS::JSValue *retValue = (*m_method->call)(exec, self, args); if (exec->hadException()) { return KJS::jsNull(); } return retValue; } void StaticBinding::publish(KJS::ExecState *exec, KJS::JSObject *object, const Method *methods) { int idx = 0; - while (methods[idx].name != 0) { + while (methods[idx].name != nullptr) { object->put(exec, methods[idx].name, new StaticBinding(exec, &methods[idx]), methods[idx].flags); idx++; } } StaticConstructor::StaticConstructor(KJS::ExecState *exec, const Constructor *constructor) : KJS::InternalFunctionImp(static_cast(exec->lexicalInterpreter()->builtinFunctionPrototype()), constructor->name), m_constructor(constructor) { putDirect(exec->propertyNames().length, m_constructor->argc, LengthFlags); m_default = KJS::jsNull(); } KJS::JSObject *StaticConstructor::construct(KJS::ExecState *exec, const KJS::List &args) { return (*m_constructor->construct)(exec, args); } void StaticConstructor::setDefaultValue(KJS::JSValue *value) { m_default = value; } KJS::JSValue *StaticConstructor::defaultValue(KJS::ExecState *exec, KJS::JSType hint) const { Q_UNUSED(exec); Q_UNUSED(hint); return m_default; } KJS::JSObject *StaticConstructor::add(KJS::ExecState *exec, KJS::JSObject *object, const Constructor *constructor) { KJS::JSObject *obj = new StaticConstructor(exec, constructor); object->put(exec, constructor->name, obj); if (constructor->staticMethods) { StaticBinding::publish(exec, obj, constructor->staticMethods); } /* crashes for some reason */ if (constructor->enumerators) { int idx = 0; - while (constructor->enumerators[idx].name != 0) { + while (constructor->enumerators[idx].name != nullptr) { obj->put(exec, constructor->enumerators[idx].name, KJS::jsNumber(constructor->enumerators[idx].value), KJS::DontDelete | KJS::ReadOnly); idx++; } } // publish methods KJSEmbed::g_ctorHash[constructor->name] = constructor; return obj; } const Method *StaticConstructor::methods(const KJS::UString &className) { return KJSEmbed::g_ctorHash[toQString(className)]->methods; } const Constructor *StaticConstructor::constructor(const KJS::UString &className) { return KJSEmbed::g_ctorHash[toQString(className)]; } KJS::JSObject *StaticConstructor::bind(KJS::ExecState *exec, const QString &className, PointerBase &objPtr) { KJSEmbed::callBind mybind = KJSEmbed::g_ctorHash[className]->bind; // qDebug() << "StaticConstructor::bind() className=" << className << " mybind=" << mybind; if (mybind) { return (*mybind)(exec, objPtr); } - return 0; + return nullptr; } KJS::JSObject *StaticConstructor::construct(KJS::ExecState *exec, KJS::JSObject *parent, const KJS::UString &className, const KJS::List &args) { // qDebug("StaticConstructor::construct('%s')", className.ascii() ); if (parent->hasProperty(exec, className.ascii())) { KJS::JSObject *ctor = parent->get(exec, className.ascii())->toObject(exec); if (ctor) { return ctor->construct(exec, args); } } qDebug("cannot create '%s'", className.ascii()); return KJS::throwError(exec, KJS::TypeError, toUString(QString("Cannot create %1 objects from javascript.").arg(toQString(className)))); } diff --git a/src/kjsembed/svg_binding.cpp b/src/kjsembed/svg_binding.cpp index 18ed5c8..b70f282 100644 --- a/src/kjsembed/svg_binding.cpp +++ b/src/kjsembed/svg_binding.cpp @@ -1,124 +1,124 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "svg_binding.h" #include #include #include #include "qwidget_binding.h" #include "static_binding.h" #include "kjseglobal.h" using namespace KJSEmbed; namespace SvgRendererNS { START_QOBJECT_METHOD(animationDuration, QSvgRenderer) result = KJS::jsNumber(object->animationDuration()); END_QOBJECT_METHOD START_QOBJECT_METHOD(defaultSize, QSvgRenderer) result = KJSEmbed::createVariant(exec, "QSize", object->defaultSize()); END_QOBJECT_METHOD START_QOBJECT_METHOD(isValid, QSvgRenderer) result = KJS::jsBoolean(object->isValid()); END_QOBJECT_METHOD START_QOBJECT_METHOD(animated, QSvgRenderer) result = KJS::jsBoolean(object->animated()); END_QOBJECT_METHOD } START_METHOD_LUT(SvgRenderer) {"animationDuration", 0, KJS::DontDelete | KJS::ReadOnly, &SvgRendererNS::animationDuration}, {"defaultSize", 0, KJS::DontDelete | KJS::ReadOnly, &SvgRendererNS::defaultSize}, {"isValid", 0, KJS::DontDelete | KJS::ReadOnly, &SvgRendererNS::isValid}, {"animated", 0, KJS::DontDelete | KJS::ReadOnly, &SvgRendererNS::animated} END_METHOD_LUT NO_ENUMS(SvgRenderer) NO_STATICS(SvgRenderer) KJSO_SIMPLE_BINDING_CTOR(SvgRenderer, QSvgRenderer, QObjectBinding) KJSO_QOBJECT_BIND(SvgRenderer, QSvgRenderer) KJSO_START_CTOR(SvgRenderer, QSvgRenderer, 0) -QSvgRenderer *renderer = 0; +QSvgRenderer *renderer = nullptr; if (args.size() == 1) { - QObject *arg0 = KJSEmbed::extractObject(exec, args, 0, 0); + QObject *arg0 = KJSEmbed::extractObject(exec, args, 0, nullptr); renderer = new QSvgRenderer(arg0); } else if (args.size() == 2) { QString arg0 = KJSEmbed::extractVariant(exec, args, 0); - QObject *arg1 = KJSEmbed::extractObject(exec, args, 1, 0); + QObject *arg1 = KJSEmbed::extractObject(exec, args, 1, nullptr); renderer = new QSvgRenderer(arg0, arg1); } else { renderer = new QSvgRenderer(); } KJS::JSObject *rendererObject = new SvgRenderer(exec, renderer); return rendererObject; KJSO_END_CTOR namespace SvgWidgetNS { START_QOBJECT_METHOD(renderer, QSvgWidget) result = KJSEmbed::createQObject(exec, object->renderer(), ObjectBinding::QObjOwned); END_QOBJECT_METHOD } START_METHOD_LUT(SvgWidget) {"renderer", 0, KJS::DontDelete | KJS::ReadOnly, &SvgWidgetNS::renderer } END_METHOD_LUT NO_ENUMS(SvgWidget) NO_STATICS(SvgWidget) KJSO_SIMPLE_BINDING_CTOR(SvgWidget, QSvgWidget, QWidgetBinding) KJSO_QOBJECT_BIND(SvgWidget, QSvgWidget) KJSO_START_CTOR(SvgWidget, QSvgWidget, 0) -QSvgWidget *widget = 0; +QSvgWidget *widget = nullptr; if (args.size() == 1) { - QWidget *arg0 = KJSEmbed::extractObject(exec, args, 0, 0); + QWidget *arg0 = KJSEmbed::extractObject(exec, args, 0, nullptr); widget = new QSvgWidget(arg0); } else if (args.size() == 2) { QString arg0 = KJSEmbed::extractVariant(exec, args, 0); - QWidget *arg1 = KJSEmbed::extractObject(exec, args, 1, 0); + QWidget *arg1 = KJSEmbed::extractObject(exec, args, 1, nullptr); widget = new QSvgWidget(arg0, arg1); } else { widget = new QSvgWidget(); } KJS::JSObject *rendererObject = new SvgWidget(exec, widget); return rendererObject; KJSO_END_CTOR diff --git a/src/kjsembed/url.cpp b/src/kjsembed/url.cpp index 29aa79b..5d60001 100644 --- a/src/kjsembed/url.cpp +++ b/src/kjsembed/url.cpp @@ -1,79 +1,79 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "url.h" #include #include using namespace KJSEmbed; -const KJS::ClassInfo UrlBinding::info = { "QUrl", &VariantBinding::info, 0, 0 }; +const KJS::ClassInfo UrlBinding::info = { "QUrl", &VariantBinding::info, nullptr, nullptr }; UrlBinding::UrlBinding(KJS::ExecState *exec, const QUrl &value) : VariantBinding(exec, value) { StaticBinding::publish(exec, this, VariantFactory::methods()); StaticBinding::publish(exec, this, Url::methods()); } namespace UrlNS { START_VARIANT_METHOD(callisValid, QUrl) bool cppValue = value.isValid(); result = KJS::jsBoolean(cppValue); END_VARIANT_METHOD START_VARIANT_METHOD(toString, QUrl) QUrl::FormattingOptions opts = (QUrl::FormattingOptions)KJSEmbed::extractInt(exec, args, 0, QUrl::None); result = KJS::jsString(value.toString(opts)); END_VARIANT_METHOD } START_METHOD_LUT(Url) {"toString", 0, KJS::DontDelete | KJS::ReadOnly, &UrlNS::toString}, {"isValid", 0, KJS::DontDelete | KJS::ReadOnly, &UrlNS::callisValid} END_METHOD_LUT START_ENUM_LUT(Url) {"None", QUrl::None}, {"RemoveScheme", QUrl::RemoveScheme}, {"RemovePassword", QUrl::RemovePassword}, {"RemoveUserInfo", QUrl::RemoveUserInfo}, {"RemovePort", QUrl::RemovePort}, {"RemoveAuthority", QUrl::RemoveAuthority}, {"RemovePath", QUrl::RemovePath}, {"RemoveQuery", QUrl::RemoveQuery}, {"RemoveFragment", QUrl::RemoveFragment}, {"StripTrailingSlash", QUrl::StripTrailingSlash} END_ENUM_LUT NO_STATICS(Url) START_CTOR(Url, QUrl, 0) if (args.size() == 1) { return new KJSEmbed::UrlBinding(exec, QUrl(KJSEmbed::extractQString(exec, args, 0))); } return new KJSEmbed::UrlBinding(exec, QUrl()); END_CTOR diff --git a/src/kjsembed/value_binding.cpp b/src/kjsembed/value_binding.cpp index cdf76c6..be0468c 100644 --- a/src/kjsembed/value_binding.cpp +++ b/src/kjsembed/value_binding.cpp @@ -1,69 +1,69 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "value_binding.h" #include "static_binding.h" using namespace KJSEmbed; -const KJS::ClassInfo ValueBinding::info = { "ValueBinding", 0, 0, 0 }; +const KJS::ClassInfo ValueBinding::info = { "ValueBinding", nullptr, nullptr, nullptr }; KJS::JSValue *callValueType(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJSEmbed::ValueBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (imp) { return KJS::jsString(imp->className().ascii()); } return KJS::jsNull(); } const Method ValueFactory::ValueMethods[] = { {"type", 0, KJS::DontDelete | KJS::ReadOnly, &callValueType }, //{"cast", 1, KJS::DontDelete|KJS::ReadOnly, &callPointerCast }, //{"toString", 0, KJS::DontDelete|KJS::ReadOnly, &callPointerToString }, - {0, 0, 0, 0 } + {nullptr, 0, 0, nullptr } }; const Method *ValueFactory::methods() { return ValueMethods; } ValueBinding::ValueBinding(KJS::ExecState *exec, const char *typeName) : ProxyBinding(exec), - m_value(0), + m_value(nullptr), m_name(typeName) { StaticBinding::publish(exec, this, ValueFactory::methods()); } ValueBinding::~ValueBinding() { delete m_value; } KJS::UString ValueBinding::toString(KJS::ExecState *exec) const { Q_UNUSED(exec); return m_value->type().name(); } diff --git a/src/kjsembed/variant_binding.cpp b/src/kjsembed/variant_binding.cpp index 4e6f466..d68c7a1 100644 --- a/src/kjsembed/variant_binding.cpp +++ b/src/kjsembed/variant_binding.cpp @@ -1,433 +1,433 @@ /* This file is part of the KDE libraries Copyright (C) 2005, 2006 Ian Reinhart Geiser Copyright (C) 2005, 2006 Matt Broadstone Copyright (C) 2005, 2006 Richard J. Moore Copyright (C) 2005, 2006 Erik L. Bunce Copyright (C) 2007, 2008 Sebastian Sauer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "variant_binding.h" #include #include #include #include #include #include #include #include #include "kjseglobal.h" #include "static_binding.h" #include "qobject_binding.h" //#define KJSEMBED_VARIANT_DEBUG using namespace KJSEmbed; -const KJS::ClassInfo VariantBinding::info = { "VariantBinding", 0, 0, 0 }; +const KJS::ClassInfo VariantBinding::info = { "VariantBinding", nullptr, nullptr, nullptr }; VariantBinding::VariantBinding(KJS::ExecState *exec, const QVariant &value) : ProxyBinding(exec), m_value(value) { StaticBinding::publish(exec, this, VariantFactory::methods()); } void *VariantBinding::pointer() { return m_value.data(); } KJS::UString VariantBinding::toString(KJS::ExecState *) const { return toUString(m_value.toString()); } KJS::UString VariantBinding::className() const { return m_value.typeName(); } QVariant VariantBinding::variant() const { return m_value; } void VariantBinding::setValue(const QVariant &val) { m_value = val; } QGenericArgument VariantBinding::arg(const char *type) const { const void *p = m_value.constData(); //qDebug("Ptr %0x", p ); //qDebug() << p; return QGenericArgument(type, p); } KJS::JSValue *callName(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); return imp ? KJS::jsString(imp->variant().typeName()) : KJS::jsNull(); } KJS::JSValue *callCast(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (imp) { QVariant val = imp->variant(); QVariant::Type type = QVariant::nameToType(args[0]->toString(exec).ascii()); KJS::JSValue *returnValue = KJS::jsBoolean(val.convert(type)); imp->setValue(val); return returnValue; } return KJS::jsNull(); } KJS::JSValue *callToString(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args) { Q_UNUSED(args); KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, self); if (imp) { //qDebug("Call value to string"); QVariant val = imp->variant(); QString stringVal = val.toString(); if (!stringVal.isEmpty()) { return KJS::jsString(val.toString()); } return KJS::jsString(val.typeName()); } return KJS::jsNull(); } const Method VariantFactory::VariantMethods[] = { {"cast", 1, KJS::DontDelete | KJS::ReadOnly | KJS::DontEnum, &callCast }, {"toString", 0, KJS::DontDelete | KJS::ReadOnly | KJS::DontEnum, &callToString }, - {0, 0, 0, 0 } + {nullptr, 0, 0, nullptr } }; enum JavaScriptArrayType { None, List, Map }; JavaScriptArrayType checkArray(KJS::ExecState *exec, KJS::JSValue *val) { KJS::JSObject *obj = val->toObject(exec); if (toQString(obj->className()) == "Array") { if (!obj->hasProperty(exec, KJS::Identifier("length"))) { return Map; } KJS::JSValue *jslen = obj->get(exec, KJS::Identifier("length")); const int len = jslen->toNumber(exec); if (len > 0) { QByteArray buff; buff.setNum(len - 1); if (!obj->hasProperty(exec, KJS::Identifier(buff.data()))) { return Map; } } return List; } else { return None; } } QMap KJSEmbed::convertArrayToMap(KJS::ExecState *exec, KJS::JSValue *value) { QMap returnMap; KJS::JSObject *obj = value->toObject(exec); KJS::PropertyNameArray lst; obj->getPropertyNames(exec, lst); KJS::PropertyNameArrayIterator idx = lst.begin(); for (; idx != lst.end(); idx++) { KJS::Identifier id = *idx; KJS::JSValue *val = obj->get(exec, id); returnMap[toQString(id)] = convertToVariant(exec, val); } return returnMap; } QList KJSEmbed::convertArrayToList(KJS::ExecState *exec, KJS::JSValue *value) { QList returnList; /* KJS::JSObject *obj = value->toObject( exec ); if ( toQString(obj->className() == "Array" ) { int length = int(obj->get( exec, KJS::Identifier( "length" ) )->toInteger( exec ) ); for ( int index = 0; index < length; ++index ) { QByteArray buff; buff.setNum(index); KJS::JSValue *val = obj->get(exec, KJS::Identifier( buff.data() ) ); if( val ) returnList += convertToVariant(exec, val ); else returnList += QVariant(); } } */ KJS::ArrayInstance *arrayImp = extractBindingImp(exec, value); if (arrayImp) { const unsigned numItems = arrayImp->getLength(); for (unsigned i = 0; i < numItems; ++i) { returnList.append(convertToVariant(exec, arrayImp->getItem(i))); } } return returnList; } QStringList KJSEmbed::convertArrayToStringList(KJS::ExecState *exec, KJS::JSValue *value) { QStringList returnList; /* KJS::JSObject *obj = value->toObject( exec ); if ( toQString(obj->className()) == "Array" ) { int length = int( obj->get( exec, KJS::Identifier( "length" ) )->toInteger( exec ) ); for ( int index = 0; index < length; ++index ) { QByteArray buff; buff.setNum(index); KJS::JSValue *val = obj->get(exec, KJS::Identifier( buff.data() ) ); if( val ) returnList += convertToVariant(exec, val ).value(); else returnList += QString(); } } */ KJS::ArrayInstance *arrayImp = extractBindingImp(exec, value); if (arrayImp) { const unsigned numItems = arrayImp->getLength(); for (unsigned i = 0; i < numItems; ++i) { returnList.append(convertToVariant(exec, arrayImp->getItem(i)).toString()); } } return returnList; } QDateTime convertDateToDateTime(KJS::ExecState *exec, KJS::JSValue *value) { KJS::List args; QDateTime returnDateTime; KJS::JSObject *obj = value->toObject(exec); if (toQString(obj->className()) == "Date") { int seconds = int(obj->get(exec, KJS::Identifier("getSeconds"))->toObject(exec)->call(exec, obj, args)->toInteger(exec)); int minutes = int(obj->get(exec, KJS::Identifier("getMinutes"))->toObject(exec)->call(exec, obj, args)->toInteger(exec)); int hours = int(obj->get(exec, KJS::Identifier("getHours"))->toObject(exec)->call(exec, obj, args)->toInteger(exec)); int month = int(obj->get(exec, KJS::Identifier("getMonth"))->toObject(exec)->call(exec, obj, args)->toInteger(exec)); int day = int(obj->get(exec, KJS::Identifier("getDate"))->toObject(exec)->call(exec, obj, args)->toInteger(exec)); int year = int(obj->get(exec, KJS::Identifier("getFullYear"))->toObject(exec)->call(exec, obj, args)->toInteger(exec)); returnDateTime.setDate(QDate(year, month + 1, day)); returnDateTime.setTime(QTime(hours, minutes, seconds)); } else { // Throw error } return returnDateTime; } QVariant KJSEmbed::convertToVariant(KJS::ExecState *exec, KJS::JSValue *value) { #ifdef KJSEMBED_VARIANT_DEBUG qDebug() << "KJSEmbed::convertToVariant"; #endif QVariant returnValue; switch (value->type()) { case KJS::UndefinedType: case KJS::NullType: break; case KJS::StringType: returnValue = toQString(value->toString(exec)); break; case KJS::NumberType: returnValue = value->toNumber(exec); break; case KJS::BooleanType: returnValue = value->toBoolean(exec); break; case KJS::ObjectType: { KJS::JSObject *obj = value->toObject(exec); //qDebug() << "Object type: " << toQString(obj->className()); if (toQString(obj->className()) == "Array") { if (checkArray(exec, value) == List) { returnValue = convertArrayToList(exec, value); } else { returnValue = convertArrayToMap(exec, value); } } else if (toQString(obj->className()) == "Date") { returnValue = convertDateToDateTime(exec, value); } else { returnValue = extractVariant(exec, value); } //if( returnValue.isNull() ) returnValue = toQString(value->toString(exec)); } break; default: returnValue = extractVariant(exec, value); //if( returnValue.isNull() ) returnValue = toQString(value->toString(exec)); break; } return returnValue; } KJS::JSValue *KJSEmbed::convertToValue(KJS::ExecState *exec, const QVariant &value) { #ifdef KJSEMBED_VARIANT_DEBUG qDebug() << "KJSEmbed::convertToValue typeid=" << value.type() << "typename=" << value.typeName() << "toString=" << value.toString(); #endif KJS::JSValue *returnValue; switch (value.type()) { case QVariant::Invalid: returnValue = KJS::jsNull(); break; case QVariant::Int: returnValue = KJS::jsNumber(value.value()); break; case QVariant::UInt: returnValue = KJS::jsNumber(value.value()); break; case QVariant::LongLong: returnValue = KJS::jsNumber(value.value()); break; case QVariant::ULongLong: returnValue = KJS::jsNumber(value.value()); break; case QVariant::Double: returnValue = KJS::jsNumber(value.value()); break; case QVariant::Bool: returnValue = KJS::jsBoolean(value.value()); break; case QVariant::ByteArray: returnValue = KJS::jsString(QString(value.value())); break; case QVariant::String: returnValue = KJS::jsString(value.value()); break; case QVariant::StringList: { KJS::List items; QStringList lst = value.value(); QStringList::Iterator idx = lst.begin(); for (; idx != lst.end(); ++idx) { items.append(KJS::jsString((*idx))); } returnValue = exec->lexicalInterpreter()->builtinArray()->construct(exec, items); break; } case QVariant::Date: // fall through case QVariant::DateTime: // fall through case QVariant::Time: { QDateTime dt = QDateTime::currentDateTime(); if (value.type() == QVariant::Date) { dt.setDate(value.toDate()); } else if (value.type() == QVariant::Time) { dt.setTime(value.toTime()); } else { dt = value.toDateTime(); } KJS::List items; items.append(KJS::jsNumber(dt.date().year())); items.append(KJS::jsNumber(dt.date().month() - 1)); items.append(KJS::jsNumber(dt.date().day())); items.append(KJS::jsNumber(dt.time().hour())); items.append(KJS::jsNumber(dt.time().minute())); items.append(KJS::jsNumber(dt.time().second())); items.append(KJS::jsNumber(dt.time().msec())); returnValue = exec->lexicalInterpreter()->builtinDate()->construct(exec, items); break; } case QVariant::List: { KJS::List items; QList lst = value.toList(); foreach (const QVariant &item, lst) { items.append(convertToValue(exec, item)); } returnValue = exec->lexicalInterpreter()->builtinArray()->construct(exec, items); break; } case QVariant::Map: { QMap map = value.toMap(); QMap::Iterator idx = map.begin(); KJS::JSObject *obj = exec->lexicalInterpreter()->builtinObject()->construct(exec, KJS::List()); for (; idx != map.end(); ++idx) { obj->put(exec, KJS::Identifier(toUString(idx.key())), convertToValue(exec, idx.value())); } returnValue = obj; break; } default: { if (value.canConvert< QWidget * >()) { QWidget *widget = qvariant_cast< QWidget * >(value); returnValue = widget ? createQObject(exec, widget, KJSEmbed::ObjectBinding::CPPOwned) : KJS::jsNull(); } else if (value.canConvert< QObject * >()) { QObject *object = qvariant_cast< QObject * >(value); returnValue = object ? createQObject(exec, object, KJSEmbed::ObjectBinding::CPPOwned) : KJS::jsNull(); } else { returnValue = createVariant(exec, value.typeName(), value); if (returnValue->isNull()) { returnValue = KJS::jsString(value.value()); } } break; } } return returnValue; } QVariant KJSEmbed::extractVariant(KJS::ExecState *exec, KJS::JSValue *value) { #ifdef KJSEMBED_VARIANT_DEBUG qDebug() << "KJSEmbed::extractVariant"; #endif KJSEmbed::VariantBinding *imp = KJSEmbed::extractBindingImp(exec, value); if (imp) { return imp->variant(); } if (value->type() == KJS::StringType) { return QVariant(toQString(value->toString(exec))); } if (value->type() == KJS::NumberType) { return QVariant(value->toNumber(exec)); } if (value->type() == KJS::BooleanType) { return QVariant(value->toBoolean(exec)); } KJS::JSObject *obj = value->toObject(exec); if (obj) { if (QObjectBinding *objImp = KJSEmbed::extractBindingImp(exec, value)) { QVariant v; if (QObject *qobj = objImp->qobject()) { v.setValue(qobj); } return v; } if (toQString(obj->className()) == "Array") { return convertArrayToList(exec, value); } } return QVariant(); }