// -*- c++ -*-

/*
 *  Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org>
 *
 *  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., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 */

#ifndef KJSEMBEDFACTORY_H
#define KJSEMBEDFACTORY_H

#include <qstringlist.h>

#include <kparts/part.h>
#include <kjs/interpreter.h>
#include <kjs/object.h>
#include <kjsembed/jsbinding.h>
#include <kjsembed/xmlactionclient.h>

class QWidget;

/**
 * Namespace containing the KJSEmbed library.
 */
namespace KJSEmbed {

namespace Bindings { class KJSEmbedPartImp; };
class JSObjectProxy;
class JSConsoleWidget;
class KJSEmbedPart;

/**
 * Factory class for KJSEmbed.
 */
class JSFactory
{
public:

    /** Returns a new interpreter each time it is called. */
    static KJS::Interpreter *createInterpreter();

    /**
     * Publishes 'obj' as property 'name' of object 'parent'. The binding is defined
     * using @ref JSObjectProxy, and is subject to the current default SecurityPolicy.
     */
    static KJS::Object addObject( KJS::Interpreter *js, QObject *obj, KJS::Object &parent, const char *name=0 );

    /** Returns a JS::Object that provides a binding to the specified QObject. */
    static KJS::Object bind( KJS::Interpreter *js, QObject *obj );

    static void addStdBindings( KJSEmbedPart *part, KJS::ExecState *exec, KJS::Object &object );

    static void addBuiltIn( KJSEmbedPart *part, KJS::ExecState *state, KJS::Object &parent );
    static void addFactory( KJSEmbedPart *part, KJS::ExecState *state, KJS::Object &parent );
    static void addIO( KJSEmbedPart *part, KJS::ExecState *state, KJS::Object &parent );
    static void addSystem( KJSEmbedPart *part, KJS::ExecState *state, KJS::Object &parent );
    static void addWidgets( KJSEmbedPart *part, KJS::ExecState *state, KJS::Object &parent );

    /**
     * Creates an instance of a QObject subclass. If the instance cannot be
     * created then 0 is returned.
     */
    static QObject *create( QString classname, QObject *parent=0, const char *name=0  );

    /**
     * Loads the widget defined in the specified .ui file. If the widget
     * cannot be created then 0 is returned.
     */
    static QWidget *loadUI( const QString &uiFile, QObject *connector=0, QWidget *parent=0, const char *name=0 );

private:
    /** Creates the implementation of a method. */
    static Bindings::KJSEmbedPartImp *createPartImp( KJSEmbedPart *part, int id, const QString &param=QString::null );
};


}; // namespace KJSEmbed

#endif // KJSEMBEDFACTORY_H

// Local Variables:
// c-basic-offset: 4
// End:
