AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzUIWebView.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CCZ_UI_WEB_VIEW_H_)
00015 #define _CCZ_UI_WEB_VIEW_H_
00016 
00017 #include "CzActor.h"
00018 #include "CzScene.h"
00019 #include "CzBrush.h"
00020 #include "CzInput.h"
00021 #include "CzUIBase.h"
00022 
00023 
00024 //
00025 //
00026 //
00027 //
00028 // CzUIWebView - A wrapper for the Marmalade WebView class providing access to web view display
00029 //
00030 //
00031 //
00032 //
00033 class CzUIWebView : public CzUIBase
00034 {
00035 public:
00036     // Properties
00037 protected:
00038     CzString            URI;                // Html to display
00039     CzString            CurrentURI;         // Current URI (URI last navigated to)
00040     CzString            Javascript;         // Javaxcript that was passed back from web view
00041     CzWebView           WebView;            // The created web view object
00042     bool                Modal;              // If true then takes over full screen and does not go back to app until dismissed
00043 
00044 public:
00045     void                setURI(const char* uri);
00046     bool                setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta);
00047     bool                setProperty(unsigned int property_name, const CzString& data, bool delta);
00048     bool                getProperty(unsigned int property_name, CzXomlProperty& prop);
00049     void                setHtml(const char* html);
00050     void                sendJavascript(const char* js);
00051     bool                isModal() const             { return Modal; }
00052     const CzString&     getCurrentURI() const       { return CurrentURI; }
00053     const CzString&     getJavascript() const       { return Javascript; }
00054     // Properties end
00055 protected:
00056     CzString            TempFilename;
00057     bool                PrevVisible;
00058     CzVec2              OldPosition;
00059     CzVec2              OldSize;
00060     bool                UpdateBinding(unsigned int property_name, CzXomlVariable* var);
00061 
00062     // Event notification callbacks (platform agnostic, athough you can override the event notification methods)
00063 protected:
00064     CzCallback          PageLoadedHandler;
00065     CzCallbackData      PageLoadedHandlerData;
00066     CzCallback          PageLoadingHandler;
00067     CzCallbackData      PageLoadingHandlerData;
00068     CzCallback          PageErrorHandler;
00069     CzCallbackData      PageErrorHandlerData;
00070     CzCallback          JavascriptHandler;
00071     CzCallbackData      JavascriptHandlerData;
00072 public:
00073     void                setPageLoadedHandler(CzCallback handler, CzCallbackData data)   { PageLoadedHandler = handler; PageLoadedHandlerData = data; }
00074     void                setPageLoadingHandler(CzCallback handler, CzCallbackData data)  { PageLoadingHandler = handler; PageLoadingHandlerData = data; }
00075     void                setPageErrorHandler(CzCallback handler, CzCallbackData data)    { PageErrorHandler = handler; PageErrorHandlerData = data; }
00076     void                setJavascriptHandler(CzCallback handler, CzCallbackData data)   { JavascriptHandler = handler; JavascriptHandlerData = data; }
00077 
00078 public:
00079     CzUIWebView() : CzUIBase(), WebView(NULL), Modal(false), PageLoadedHandler(NULL), PageLoadedHandlerData(NULL), PageLoadingHandler(NULL), PageLoadingHandlerData(NULL), 
00080                     PageErrorHandler(NULL), PageErrorHandlerData(NULL), JavascriptHandler(NULL), JavascriptHandlerData(NULL)  {}
00081     virtual ~CzUIWebView();
00082 
00083     bool                InitView(bool modal, bool transparent, const char* java_script);
00084     bool                UpdateVisual();
00085     void                UpdatePosSize();
00086 
00087     // Implementation of IzXomlClass interface
00088     int                 LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00089 
00090     // Implementation of IzAnimTarget interface
00091     bool                UpdateFromAnimation(CzAnimInstance *animation);
00092 
00093     // Event notification
00094     void                NotifyPageLoaded(const char* url);
00095     void                NotifyPageLoading(const char* url);
00096     void                NotifyPageError(const char* url);
00097     void                NotifyJavascript(const char* data);
00098     void                NotifyOrientationChange(CzScene::eOrientation old_orientation, CzScene::eOrientation new_orientation);
00099 
00100     // Internal (used by XOML system to setup and cleanup the XOML class properties system
00101 protected:
00102     static CzXomlClassDef*  WebViewClassDef;                                // XOML class definition
00103 public:
00104     static void             InitClass();
00105     static void             ReleaseClass();
00106     static bool             _setURI(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00107     static CzXomlProperty   _getJavascript(IzXomlResource* target);
00108     static bool             _setJavaScript(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00109     static bool             _setHtml(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00110     static CzXomlProperty   _getModal(IzXomlResource* target);
00111     static CzXomlProperty   _getCurrentURI(IzXomlResource* target);
00112     static bool             _setOnPageLoaded(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00113     static bool             _setOnPageLoading(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00114     static bool             _setOnPageError(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00115     static bool             _setOnJavascript(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00116 
00117 };
00118 
00119 //
00120 //  CzUIWebViewCreator - Creates an instance of a web view actor object
00121 //
00122 class CzUIWebViewCreator : public IzXomlClassCreator
00123 {
00124 public:
00125     CzUIWebViewCreator()
00126     {
00127         setClassName("webview");
00128     }
00129     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzUIWebView(); }
00130 };
00131 
00132 
00133 #endif  // _CCZ_UI_WEB_VIEW_H_
00134