#if !(DO_NOT_USE_MAP) #if !(USE_WEBVIEW2) #include "rm_widget_map.h" #include #include #include #include #include #include #include "../rm_include.h" #if (USE_HTML_MAP) #include #include #include #endif #define DEBUG_MAP_HTML 0 RMWidgetMap::RMWidgetMap(QWidget *parent, Qt::WindowFlags f) : QWidget(parent) // QAxWidget(parent, f) { _ax = new QAxWidget(this, f); QBoxLayout* layout = new QBoxLayout(QBoxLayout::LeftToRight,this); layout->setMargin(0); layout->setSpacing(0); layout->addWidget(_ax); //connect(_ax, SIGNAL(signal(const QString&, int, void*)),SLOT(activexEventHandler(const QString&, int, void*))); //connect(_ax,SIGNAL(NavigateComplete(QString)),this, SLOT(onNavigateComplete(QString))); #if (USE_HTML_MAP) tempFile = NULL; #endif _ax->setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}"); _ax->setProperty("Visible", true); #if (DEBUG_MAP_HTML) _ax->setProperty("Silent",false); #else _ax->setProperty("Silent",true); #endif _ax->setProperty("Resizable",false); // FEATURE_AJAX_CONNECTIONEVENTS //connect(_ax,SIGNAL(NavigateComplete(QString)),this, SLOT(onNavigateComplete(QString))); //connect(_ax,SIGNAL(BeforeNavigate()),this, SLOT(onBeforeNavigate())); // void onBeforeNavigate(); _ax->setObjectName(QString::fromUtf8("webWidget")); #if (DEBUG_MAP_HTML) _ax->setProperty("DisplayAlerts",true); #else _ax->setProperty("DisplayAlerts",false); #endif _ax->setProperty("DisplayScrollBars",false); // User-Agent: char userAgent[] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.53"; ::UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, userAgent, strlen(userAgent)+1, 0); } void RMWidgetMap::navigate(const QString &url) { /* QString userAgent = "User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.53\r\n"; IWebBrowser *webBrowser = 0; _ax->queryInterface( IID_IWebBrowser, (void**)&webBrowser ); if ( webBrowser ) { std::wstring str_ = QString("https://www.whatismybrowser.com/detect/what-is-my-user-agent/").toStdWString(); //std::wstring str_ = url.toStdWString(); BSTR bstr_ = SysAllocString(str_.c_str()); VARIANT vAgent; VariantInit(&vAgent); vAgent.vt = VT_BSTR; std::wstring agent = userAgent.toStdWString(); vAgent.bstrVal = SysAllocString(agent.c_str()); //VT_BSTR agent_bstr = SysAllocString(str_.c_str()); webBrowser->Navigate(bstr_,NULL,NULL,NULL,NULL); //webBrowser->Navigate(bstr_,NULL,NULL,NULL,&vAgent); //do_something_with( webBrowser ); webBrowser->Release(); VariantClear(&vAgent); } */ _ax->dynamicCall("Navigate(const QString&)", url); //_ax->dynamicCall("Navigate(const QString&)", "https://www.whatismybrowser.com/detect/what-is-my-user-agent/"); } #if (USE_HTML_MAP) void RMWidgetMap::removePage() { if(tempFile != NULL) { delete tempFile; tempFile = NULL; } } void RMWidgetMap::loadFirstPage() { #if (USE_GOOGLE_MAP) #if (RM_MODEL == RM_MODEL_TYPE_FC_DR232W || RM_MODEL == RM_MODEL_TYPE_NX_DRW22) QString mapSrc = ":/html/gmap_nx.html"; #else QString mapSrc = ":/html/gmap.html"; #endif #else QString mapSrc = ":/html/map.html"; #endif // navigate("https://www.whatismybrowser.com/"); // return; QFile htmlFile(mapSrc); if(htmlFile.open(QIODevice::ReadOnly) == false){ return; } QUuid uuid = QUuid::createUuid(); QString tempFileFullPath = QDir::tempPath() + "/" + uuid.toString().replace("{","").replace("}",""); tempFile = new QTemporaryFile(tempFileFullPath); //temp.setAutoRemove(false); if(!tempFile->open()) { qWarning() << "LOAD MAP HTML ERROR:" << tempFileFullPath << __FUNCTION__; return; } tempFile->write(htmlFile.readAll()); tempFile->close(); //qInfo() << "LOAD MAP HTML:" << tempFile->fileName() << __FUNCTION__; navigate(tempFile->fileName()); } #else void RMWidgetMap::load() { //navigate("C:\\home\\roadmovie\\project\\fm_viewer\\res\\keiyo\\gmap.html"); return; #if (USE_GOOGLE_MAP) QString mapFileName = ":/html/gmap.html"; #else QString mapFileName = ":/html/map.html"; #endif QFile htmlFile(mapFileName); if(htmlFile.open(QIODevice::ReadOnly) == false){ return; } QTextStream in(&htmlFile); QString html = in.readAll(); QAxObject* document = querySubObject("Document"); if(document != NULL) { IHTMLDocument2 *doc2 = nullptr; QUuid uid = QUuid(IID_IHTMLDocument2); document->queryInterface(uid, (void**)&doc2); if(doc2) { std::wstring str_ = html.toStdWString(); BSTR bstr = SysAllocString(str_.c_str()); SAFEARRAY *psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1); if (psaStrings == NULL) { return; } VARIANT *param; HRESULT hr = SafeArrayAccessData(psaStrings, (LPVOID*)¶m); param->vt = VT_BSTR; param->bstrVal = bstr; hr = SafeArrayUnaccessData(psaStrings); hr = doc2->write(psaStrings); doc2->close(); SafeArrayDestroy(psaStrings); SysFreeString(bstr); doc2->Release(); } } htmlFile.close(); //dynamicCall("Refresh()"); } #endif // USE_HTML_MAP void RMWidgetMap::runScript(QString script) { //Q_UNUSED(script); QAxObject* document = _ax->querySubObject("Document"); if(document != NULL) { IHTMLDocument2 *doc2 = nullptr; QUuid uid = QUuid(IID_IHTMLDocument2); document->queryInterface(uid, (void**)&doc2); IHTMLWindow2* wnd = nullptr; doc2->get_parentWindow(&wnd); // QString("moveTest()") std::wstring str_ = script.toStdWString(); BSTR bstr_ = SysAllocString(str_.c_str()); std::wstring str_2 = QString("JavaScript").toStdWString(); BSTR bstr_2 = SysAllocString(str_2.c_str()); VARIANT varRet; HRESULT hr = wnd->execScript(bstr_, bstr_2, &varRet); if (SUCCEEDED(hr)) { //qInfo() << "OK"; } SysFreeString(bstr_); SysFreeString(bstr_2); } } #endif // #if !(USE_WEBVIEW2) #endif // #if !(DO_NOT_USE_MAP)