コード例 #1
0
	virtual HTMLEventStatus Event(HTMLElement *pElement, HTMLEvent *pEvent, WEBC_CHAR *pParam = 0)
	{
		HTMLEventStatus result = HTML_EVENT_STATUS_CONTINUE;

		if (mFunction)
		{
			HTMLDocument *pDoc;
			HTMLBrowser  *pBrowser;
			wcCtx _Ctx;
			char nphoney[4];

			pDoc = (pElement)? pElement->GetDocument() : 0;
			pBrowser = (pDoc)? pDoc->GetBrowser() : 0;

			wcCtxtInit(&_Ctx,  (wcBROW) pBrowser, (wcDOC) pDoc);
			char *param = webc_arg_to_char(pParam);
			if (!param)
				param = &nphoney[0];

			result = mFunction(&_Ctx, (wcEL)pElement, pEvent, param);
			wcCtxtRelease(&_Ctx);
			if (param != &nphoney[0])
				webc_arg_done(param);
		}
		return (result);
	}
コード例 #2
0
ファイル: webcsdk.hpp プロジェクト: peteratebs/webcwebbrowser
	virtual HTMLEventStatus Event(HTMLElement *pElement, HTMLEvent *pEvent, WEBC_CHAR *pParam = 0)
	{
		HTMLEventStatus result = HTML_EVENT_STATUS_CONTINUE;

		if (mFunction)
		{
			HTMLDocument *pDoc;
			HTMLBrowser  *pBrowser;

			pDoc = (pElement)? pElement->GetDocument() : 0;
			pBrowser = (pDoc)? pDoc->GetBrowser() : 0;


			char *param = webc_arg_to_char(pParam);

			if (!param)
			{
				param = nphoney;
			}

			result = mFunction((HBROWSER_HANDLE)pBrowser, (HDOC_HANDLE)pDoc, (HELEMENT_HANDLE)pElement, pEvent, param);

			if (param != nphoney)
			{
				webc_arg_done(param);
			}
		}

		return (result);
	}
コード例 #3
0
static JSBool jwindow_dialog(JSContext *cx, JSObject *obj,uintN argc, jsval *argv, jsval *rval, int which_dialogue)
{
	WebcJSDocumentContext *jsmgr = (WebcJSDocumentContext *) jhutil_GetPrivate(cx, obj);
	HTMLDocument *pDoc = (jsmgr)? jsmgr->GetDocument() : 0;

	if (argc < 1)
        return(JS_FALSE);

    char *prompt_str = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
// << EDIT 20080120 - Needs work

	// Clone the graphics abstraction layer function pointers so we know who to call
	HTMLBrowserConfig config, docConfig;
    rtp_memset(&config, 0, sizeof(config));
    rtp_memset(&docConfig, 0, sizeof(docConfig));
	pDoc->GetBrowser()->GetConfig(&docConfig);
	config.graphics = docConfig.graphics;

    switch (which_dialogue) {
        case WHICH_DIALOGUE_ALERT:
            config.WindowConfig.left =   WEBC_SKIN_ALERT_LEFT;
            config.WindowConfig.top =    WEBC_SKIN_ALERT_TOP;
            config.WindowConfig.width =  WEBC_SKIN_ALERT_WIDTH;
            config.WindowConfig.height = WEBC_SKIN_ALERT_HEIGHT;
            break;
        case WHICH_DIALOGUE_PROMPT:
            config.WindowConfig.left =   WEBC_SKIN_PROMPT_LEFT;
            config.WindowConfig.top =    WEBC_SKIN_PROMPT_TOP;
            config.WindowConfig.width =  WEBC_SKIN_PROMPT_WIDTH;
            config.WindowConfig.height = WEBC_SKIN_PROMPT_HEIGHT;
            break;
        case WHICH_DIALOGUE_CONFIRM:
        default:
            config.WindowConfig.left =   WEBC_SKIN_CONFIRM_LEFT;
            config.WindowConfig.top =    WEBC_SKIN_CONFIRM_TOP;
            config.WindowConfig.width =  WEBC_SKIN_CONFIRM_WIDTH;
            config.WindowConfig.height = WEBC_SKIN_CONFIRM_HEIGHT;
            break;
    }
	config.WindowConfig.WindowFlags |= WF_MODAL;

    HBROWSER_HANDLE Browser = webc_CreateBrowser(&config,  WEBC_TRUE,"dialog", "");
    if (Browser)
    {
     HDOC_HANDLE hDoc = webc_BrowserGetDocument(Browser);
	 wcCtx Ctx;
     char buff[128];
	  wcCtxtInit(&Ctx, (wcBROW) Browser, (wcDOC) hDoc);
     /* Experimental */
     wcDocClear(&Ctx, wcFALSE);
     wcDocOpen(&Ctx);


     // Create a link between 'C' and Javascript the Native 'C' function PromptDismiss will
     // be called with the value of the input field.
     webc_JScriptDefineFunction(hDoc, "PromptDismiss", (JSNative) PromptDismiss, 0);
     if (which_dialogue == WHICH_DIALOGUE_ALERT)
     {
         WriteDlgLine(&Ctx, WEBC_SKIN_ALERT_SOURCE_1);
         WriteDlgLine(&Ctx, prompt_str);
         WriteDlgLine(&Ctx, WEBC_SKIN_ALERT_SOURCE_2);
         WriteDlgLine(&Ctx, WEBC_SKIN_ALERT_SOURCE_3);
     }
     else if (which_dialogue == WHICH_DIALOGUE_CONFIRM)
     {
         WriteDlgLine(&Ctx, WEBC_SKIN_CONFIRM_SOURCE_1);
         WriteDlgLine(&Ctx, prompt_str);
         WriteDlgLine(&Ctx, WEBC_SKIN_CONFIRM_SOURCE_2);
         WriteDlgLine(&Ctx, WEBC_SKIN_CONFIRM_SOURCE_3);
     }
     else if (which_dialogue == WHICH_DIALOGUE_PROMPT)
     {
         char *default_str = "";
         if (argc > 1)
             default_str = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
         WriteDlgLine(&Ctx, prompt_str);
         rtp_sprintf(&buff[0],WEBC_SKIN_PROMPT_SOURCE_1,default_str);
         WriteDlgLine(&Ctx, &buff[0]);
         WriteDlgLine(&Ctx, WEBC_SKIN_PROMPT_SOURCE_2);
         WriteDlgLine(&Ctx, WEBC_SKIN_PROMPT_SOURCE_3);
     }
     wcDocClose(&Ctx);
     wcDocRefresh(&Ctx);

     /* Go modal here */
  //   HBROWSER_HANDLE Browser = webc_CreateBrowser(&config,  WEBC_TRUE, "");
     HTMLBrowser *pBrowser = (HTMLBrowser *) Browser;
     while (pBrowser->ProcessInputQueue(WEBC_TRUE) >= 0)
     {
         WebString *user_WebString;
         void* privateData = webc_BrowserGetPrivateData(Browser);
         if (privateData)
         {
             user_WebString = (WebString *) privateData;
             if (which_dialogue == WHICH_DIALOGUE_PROMPT)
             {
                 if (user_WebString && user_WebString->getLength())
 			        *rval = STRING_TO_JSVAL(WEBC_JS_NEW_STRING_COPY_Z(cx, user_WebString->getChars()));
                 else
                     *rval = JSVAL_VOID;
             }
             else if (which_dialogue == WHICH_DIALOGUE_ALERT)
                 *rval = JSVAL_VOID;
             else if (which_dialogue == WHICH_DIALOGUE_CONFIRM)
             {
                 if (user_WebString && webc_c_strcmp(user_WebString->getChars(), "OK")==0)
                     *rval = BOOLEAN_TO_JSVAL(JS_TRUE);
                 else
                     *rval = BOOLEAN_TO_JSVAL(JS_FALSE);
             }
             WEBC_DELETE(user_WebString);
             webc_JScriptExecuteSource(hDoc, "window.close();");
             break;
         }
     }
     }
     return jutils_CheckContextState(cx);
}
コード例 #4
0
ファイル: hscript.cpp プロジェクト: peteratebs/webcwebbrowser
void HTMLScript::Update(WEBC_PFBYTE o, WEBC_PFBYTE data)
{
#if (WEBC_SUPPORT_JSCRIPT)
HTMLDocument *pDoc = GetDocument();
WebcJSDocumentContext *jsMgr = (pDoc)? pDoc->GetJSMgr() : 0;

	if (mpScript || !jsMgr)
	{
		return;
	}

	WEBC_NEW_VERBOSE(mpScript, WebcJSScript(jsMgr, jsMgr->GetGlobalObject()),"WebcJSDocumentContext");

	if (mpScript)
	{
		if (Src())
		{
			LoadScript *pJob;
			if (pDoc)
			{
				HTMLBrowser *pBrowser = pDoc->GetBrowser();
				if (pBrowser)
				{
					WebcCharset charset = (mCharset == WEBC_CHARSET_UNKNOWN)? pDoc->GetCharset() : mCharset;
					WEBC_NEW_VERBOSE(pJob, LoadScript(this, pDoc, charset),"LoadScript");
					if (pJob)
					{
						pBrowser->ProcessLoadJob(pJob, pJob->GetURL(), pDoc->BaseURL(), pDoc, WEBC_TRUE /* urgent */);
					}
					webc_free_string_copy(mpSrc, __FILE__, __LINE__);
					mpSrc = 0;
				}
			}
		}
		else // compile the contents of this tag as the script to execute
		{
			HTMLElement *pChild = mpFirstChild;
			WEBC_CHAR* pStr;
			long iLen;
			for (; pChild != WEBC_NULL; pChild = pChild->mpNext)
			{
				if (pChild->Type() == HTML_STRING_ELEMENT)
				{
					pStr = ((HTMLString*)(pChild))->GetString();
					iLen = webc_strlen(pStr);
					if (mpScript->Write(pStr, iLen) < iLen)
					{
						mpScript->Destroy();
						mpScript = 0;
						break;
					}
				}
			}

			if (mpScript)
			{
				mpScript->Compile();
			}

			DeleteChildren();
		}
	}

#endif
}