"Fossies" - the Fresh Open Source Software Archive

Member "google-gadgets-for-linux-0.11.2/extensions/qt_script_runtime/js_native_wrapper.h" (15 Mar 2009, 2213 Bytes) of package /linux/misc/old/google-gadgets-for-linux-0.11.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2   Copyright 2008 Google Inc.
    3 
    4   Licensed under the Apache License, Version 2.0 (the "License");
    5   you may not use this file except in compliance with the License.
    6   You may obtain a copy of the License at
    7 
    8        http://www.apache.org/licenses/LICENSE-2.0
    9 
   10   Unless required by applicable law or agreed to in writing, software
   11   distributed under the License is distributed on an "AS IS" BASIS,
   12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13   See the License for the specific language governing permissions and
   14   limitations under the License.
   15 */
   16 
   17 #ifndef GGADGET_QT_JS_NATIVE_WRAPPER_H__
   18 #define GGADGET_QT_JS_NATIVE_WRAPPER_H__
   19 
   20 #include <string>
   21 #include <ggadget/common.h>
   22 #include <ggadget/scriptable_helper.h>
   23 #include "js_script_context.h"
   24 
   25 namespace ggadget {
   26 namespace qt {
   27 
   28 /**
   29  * Wraps a JavaScript object into a native @c ScriptableInterface.
   30  */
   31 class JSNativeWrapper : public ScriptableHelperDefault {
   32  public:
   33   DEFINE_CLASS_ID(0x65f4d888b7b749ed, ScriptableInterface);
   34   JSNativeWrapper(JSScriptContext *context, const QScriptValue& qval);
   35 
   36  protected:
   37   virtual ~JSNativeWrapper();
   38 
   39  public:
   40   virtual void Ref() const;
   41   virtual void Unref(bool transient = false) const;
   42   virtual PropertyType GetPropertyInfo(const char *name,
   43                                        Variant *prototype);
   44   virtual ResultVariant GetProperty(const char *name);
   45   virtual bool SetProperty(const char *name, const Variant &value);
   46   virtual ResultVariant GetPropertyByIndex(int index);
   47   virtual bool SetPropertyByIndex(int index, const Variant &value);
   48   virtual bool EnumerateProperties(EnumeratePropertiesCallback *callback);
   49   virtual bool EnumerateElements(EnumerateElementsCallback *callback);
   50 
   51   QScriptValue js_object() { return qval_; }
   52   JSScriptContext *context() { return context_; }
   53 
   54   static ScriptableInterface* UnwrapJSObject(const QScriptValue& qval);
   55 
   56  private:
   57   DISALLOW_EVIL_CONSTRUCTORS(JSNativeWrapper);
   58 
   59   JSScriptContext *context_;
   60   QScriptValue qval_;
   61   class JSObjectData : public QObject {
   62    public:
   63     JSNativeWrapper *wrapper;
   64   };
   65   JSObjectData object_data_;
   66 };
   67 
   68 } // namespace qt
   69 } // namespace ggadget
   70 
   71 #endif // GGADGET_QT_JS_NATIVE_WRAPPER_H__