http://code.google.com/p/mcrux/source/detail?r=157
Modified:
/trunk/src/include/mcrux/MCrux.h
/trunk/src/lib/MCrux.cpp
/trunk/src/lib/MCruxWebView.cpp
/trunk/src/lib/MCruxWebView.h
/trunk/src/lib/abstract/MCruxWindow.h
/trunk/src/lib/window/MCruxQTWindow.cpp
/trunk/src/lib/window/MCruxQTWindow.h
/trunk/src/lib/window/MCruxWin32Window.cpp
/trunk/src/lib/window/MCruxWin32Window.h
/trunk/src/lib/window/MCruxWindowManager.cpp
/trunk/src/src.pro
=======================================
--- /trunk/src/include/mcrux/MCrux.h Sun Nov 1 05:42:59 2009
+++ /trunk/src/include/mcrux/MCrux.h Sat Nov 7 10:37:22 2009
@@ -34,13 +34,10 @@
class MCRUX_API MCrux
{
- void Initialize(
#ifndef WIN32
- int argc, char **argv
-#endif
- );
-
+ void Initialize();
void UnInitialize();
+#endif
public:
=======================================
--- /trunk/src/lib/MCrux.cpp Thu Nov 5 17:39:05 2009
+++ /trunk/src/lib/MCrux.cpp Sat Nov 7 10:37:22 2009
@@ -69,13 +69,9 @@
{
}
-void MCrux::Initialize(
-#ifndef WIN32
- int argc, char **argv
-#endif
- )
-{
#ifdef WIN32
+void MCrux::Initialize()
+{
// Initialize Common controls
INITCOMMONCONTROLSEX InitCtrlEx;
@@ -87,22 +83,17 @@
// Init COM
OleInitialize(NULL);
-#else
- //gtk_init (&argc, &argv);
- //if (!g_thread_supported ())
- //g_thread_init (NULL);
-
-#endif
-}
-
+}
+#endif
+
+#ifdef WIN32
void MCrux::UnInitialize()
{
-#ifdef WIN32
// Shut down COM.
OleUninitialize();
MCruxWin32Window::unInitWindowClass(GetModuleHandle(NULL));
-#endif
-}
+}
+#endif
@@ -156,9 +147,7 @@
}
bRet = true;
#else // for linux
- // gtk_main();
-
- return app.exec();
+ bRet = app.exec();
#endif
}
else
=======================================
--- /trunk/src/lib/MCruxWebView.cpp Sat Oct 31 19:36:03 2009
+++ /trunk/src/lib/MCruxWebView.cpp Sat Nov 7 10:37:22 2009
@@ -16,19 +16,34 @@
*
* @author: Mital Vora.
**/
+#ifdef WIN32
#include <shlwapi.h>
#include <wininet.h>
#include <WebKit/WebKitCOMAPI.h>
+#else // for linux
+
+#include <QtWebKit/QWebView>
+#include "window/MCruxQTWindow.h"
+#endif
+
#include "MCruxWebView.h"
-MCruxWebView::MCruxWebView()
-: hParentWindow(NULL),
- webView(NULL),
+MCruxWebView::MCruxWebView(
+#ifndef WIN32
+ MCruxQTWindow * _parentWindow
+#endif
+ )
+: webView(NULL)
+#ifdef WIN32
+ ,hParentWindow(NULL),
hWebViewWindow(NULL),
httpGetMethod(SysAllocString(TEXT("GET")))
+#else // for linux
+ ,parentWindow(_parentWindow)
+#endif
{
}
@@ -38,219 +53,242 @@
bool MCruxWebView::createWebView()
{
- if(webView)
- {
- webView->Release();
- webView = NULL;
- }
- hWebViewWindow = NULL;
-
- HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView,
(void**)&webView);
- if (SUCCEEDED(hr))
- {
- return true;
- }
- return false;
+#ifdef WIN32
+ if(webView)
+ {
+ webView->Release();
+ webView = NULL;
+ }
+ hWebViewWindow = NULL;
+
+ HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView,
(void**)&webView);
+ if (SUCCEEDED(hr))
+ {
+ return true;
+ }
+#else // for linux
+
+ webView = new QWebView(parentWindow);
+ parentWindow->setCentralWidget(webView);
+ //webView->show();
+#endif
+ return false;
}
+#ifdef WIN32
bool MCruxWebView::setFrameLoadDelegate(MCruxWebFrameLoadDelegate *
frameLoadDelegate)
{
- if(webView)
- {
- HRESULT hr = webView->setFrameLoadDelegate(frameLoadDelegate);
- if (SUCCEEDED(hr))
- {
- return true;
- }
- }
- return false;
+ if(webView)
+ {
+ HRESULT hr = webView->setFrameLoadDelegate(frameLoadDelegate);
+ if (SUCCEEDED(hr))
+ {
+ return true;
+ }
+ }
+ return false;
}
bool MCruxWebView::setWebUIDelegate(MCruxWebUIDelegate * webUIDelegate)
{
- if(webView)
- {
- HRESULT hr = webView->setUIDelegate(webUIDelegate);
- if(SUCCEEDED(hr))
- {
- return true;
- }
- }
- return false;
+ if(webView)
+ {
+ HRESULT hr = webView->setUIDelegate(webUIDelegate);
+ if(SUCCEEDED(hr))
+ {
+ return true;
+ }
+ }
+ return false;
}
bool MCruxWebView::initWithHostWindow(HWND hWnd)
{
- if(webView)
- {
- HRESULT hr = webView->setHostWindow((OLE_HANDLE) HandleToLong(hWnd));
- if (SUCCEEDED(hr))
- {
- RECT clientRect;
- GetClientRect(hWnd, &clientRect);
- hr = webView->initWithFrame(clientRect, 0, 0);
- if (SUCCEEDED(hr))
- {
- hParentWindow = hWnd;
- return true;
- }
- }
- }
- return false;
-}
+ if(webView)
+ {
+ HRESULT hr = webView->setHostWindow((OLE_HANDLE) HandleToLong(hWnd));
+ if (SUCCEEDED(hr))
+ {
+ RECT clientRect;
+ GetClientRect(hWnd, &clientRect);
+ hr = webView->initWithFrame(clientRect, 0, 0);
+ if (SUCCEEDED(hr))
+ {
+ hParentWindow = hWnd;
+ return true;
+ }
+ }
+ }
+ return false;
+}
+#endif
bool MCruxWebView::loadPage(const wstring & defaultPageText) const
{
- if(webView)
- {
- IWebFrame* frame;
- HRESULT hr = webView->mainFrame(&frame);
- if (SUCCEEDED(hr))
- {
- BSTR page = SysAllocString(defaultPageText.c_str());
- frame->loadHTMLString(page, 0);
- frame->Release();
- return true;
- }
- }
- return false;
+#ifdef WIN32
+ if(webView)
+ {
+ IWebFrame* frame;
+ HRESULT hr = webView->mainFrame(&frame);
+ if (SUCCEEDED(hr))
+ {
+ BSTR page = SysAllocString(defaultPageText.c_str());
+ frame->loadHTMLString(page, 0);
+ frame->Release();
+ return true;
+ }
+ }
+#endif
+ return false;
}
bool MCruxWebView::storeViewWindowHandle()
{
- if(webView)
- {
- IWebViewPrivate* viewExt;
- HRESULT hr = webView->QueryInterface(IID_IWebViewPrivate,
(void**)&viewExt);
- if (SUCCEEDED(hr))
- {
- hr = viewExt->viewWindow((OLE_HANDLE*) &hWebViewWindow);
- viewExt->Release();
- if (SUCCEEDED(hr))
- {
- return true;
- }
- }
-
- }
- return false;
-}
-
+#ifdef WIN32
+ if(webView)
+ {
+ IWebViewPrivate* viewExt;
+ HRESULT hr = webView->QueryInterface(IID_IWebViewPrivate,
(void**)&viewExt);
+ if (SUCCEEDED(hr))
+ {
+ hr = viewExt->viewWindow((OLE_HANDLE*) &hWebViewWindow);
+ viewExt->Release();
+ if (SUCCEEDED(hr))
+ {
+ return true;
+ }
+ }
+
+ }
+#endif
+ return false;
+}
+#ifdef WIN32
void MCruxWebView::resizeSubView() const
{
- RECT rcClient;
- GetClientRect(hParentWindow, &rcClient);
- MoveWindow(hWebViewWindow, 0, 0, rcClient.right, rcClient.bottom, TRUE);
-}
+ RECT rcClient;
+ GetClientRect(hParentWindow, &rcClient);
+ MoveWindow(hWebViewWindow, 0, 0, rcClient.right, rcClient.bottom, TRUE);
+}
+#endif
+
+#ifdef WIN32
bool MCruxWebView::loadPageInWindow(HWND hWnd, const wstring &
defaultPageText)
{
- if(initWithHostWindow(hWnd)
- && loadPage(defaultPageText)
- && storeViewWindowHandle())
- {
- return true;
- }
- return false;
+ if(initWithHostWindow(hWnd)
+ && loadPage(defaultPageText)
+ && storeViewWindowHandle())
+ {
+ return true;
+ }
+ return false;
}
bool MCruxWebView::loadURLInWindow(HWND hWnd, const wstring & url)
{
- if(initWithHostWindow(hWnd)
- && navigateTo(url)
- && storeViewWindowHandle())
- {
- return true;
- }
- return false;
+ if(initWithHostWindow(hWnd)
+ && navigateTo(url)
+ && storeViewWindowHandle())
+ {
+ return true;
+ }
+ return false;
}
bool MCruxWebView::loadURLRequestInWindow(HWND hWnd, IWebURLRequest
*request)
{
- if(initWithHostWindow(hWnd)
- //&& navigateTo(request)
- && storeViewWindowHandle())
- {
- return true;
- }
- return false;
-}
-
+#ifdef WIN32
+ if(initWithHostWindow(hWnd)
+ && storeViewWindowHandle())
+ {
+ return true;
+ }
+#endif
+ return false;
+}
+#endif
bool MCruxWebView::navigateTo(const wstring & url)
{
- wstring navigateURL = url;
- IWebFrame* frame = 0;
- IWebMutableURLRequest* request = 0;
-
- if ((PathFileExists(navigateURL.c_str()) ||
PathIsUNC(navigateURL.c_str())))
- {
- TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
- DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
- if (SUCCEEDED(UrlCreateFromPath(navigateURL.c_str(), fileURL,
&fileURLLength, 0)))
- {
- wstring wfileURL = fileURL;
- navigateURL = wfileURL;
- }
- }
-
- HRESULT hr = webView->mainFrame(&frame);
- if (FAILED(hr))
- goto exit;
-
- hr = WebKitCreateInstance(CLSID_WebMutableURLRequest,
- 0,
- IID_IWebMutableURLRequest,
- (void**)&request);
- if (FAILED(hr))
- goto exit;
-
- hr = request->initWithURL(::SysAllocString(navigateURL.c_str()),
WebURLRequestUseProtocolCachePolicy, 0);
- if (FAILED(hr))
- goto exit;
-
- hr = request->setHTTPMethod(httpGetMethod);
- if (FAILED(hr))
- goto exit;
-
- hr = frame->loadRequest(request);
- if (FAILED(hr))
- goto exit;
-
- SetFocus(hWebViewWindow);
+#ifdef WIN32
+ wstring navigateURL = url;
+ IWebFrame* frame = 0;
+ IWebMutableURLRequest* request = 0;
+
+ if ((PathFileExists(navigateURL.c_str()) ||
PathIsUNC(navigateURL.c_str())))
+ {
+ TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
+ DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
+ if (SUCCEEDED(UrlCreateFromPath(navigateURL.c_str(), fileURL,
&fileURLLength, 0)))
+ {
+ wstring wfileURL = fileURL;
+ navigateURL = wfileURL;
+ }
+ }
+
+ HRESULT hr = webView->mainFrame(&frame);
+ if (FAILED(hr))
+ goto exit;
+
+ hr = WebKitCreateInstance(CLSID_WebMutableURLRequest,
+ 0,
+ IID_IWebMutableURLRequest,
+ (void**)&request);
+ if (FAILED(hr))
+ goto exit;
+
+ hr = request->initWithURL(::SysAllocString(navigateURL.c_str()),
WebURLRequestUseProtocolCachePolicy, 0);
+ if (FAILED(hr))
+ goto exit;
+
+ hr = request->setHTTPMethod(httpGetMethod);
+ if (FAILED(hr))
+ goto exit;
+
+ hr = frame->loadRequest(request);
+ if (FAILED(hr))
+ goto exit;
+
+ SetFocus(hWebViewWindow);
exit:
- if (frame)
- frame->Release();
- if (request)
- request->Release();
- return true;
+ if (frame)
+ frame->Release();
+ if (request)
+ request->Release();
+#else
+ string strurl(url.begin(), url.end());
+ webView->load(QUrl(strurl.c_str()));
+#endif
+ return true;
}
+#ifdef WIN32
bool MCruxWebView::navigateTo(IWebURLRequest *request)
{
- IWebFrame* frame = 0;
- HRESULT hr = webView->mainFrame(&frame);
- if (SUCCEEDED(hr))
- {
- hr = frame->loadRequest(request);
- if (SUCCEEDED(hr))
- {
- SetFocus(hWebViewWindow);
- request->Release();
- }
- frame->Release();
- return true;
- }
- return false;
-}
-
+ IWebFrame* frame = 0;
+ HRESULT hr = webView->mainFrame(&frame);
+ if (SUCCEEDED(hr))
+ {
+ hr = frame->loadRequest(request);
+ if (SUCCEEDED(hr))
+ {
+ SetFocus(hWebViewWindow);
+ request->Release();
+ }
+ frame->Release();
+ return true;
+ }
+ return false;
+}
IWebView * MCruxWebView::getWebView()
{
- return webView;
-}
+ return webView;
+}
+#endif
=======================================
--- /trunk/src/lib/MCruxWebView.h Sun Nov 1 00:06:50 2009
+++ /trunk/src/lib/MCruxWebView.h Sat Nov 7 10:37:22 2009
@@ -24,39 +24,59 @@
using namespace std;
+#ifdef WIN32
#include <WebKit/WebKit.h>
#include "delegates/MCruxWebUIDelegate.h"
#include "delegates/MCruxWebFrameLoadDelegate.h"
+#else // for linux
+#include <QtGui>
+
+class QWebView;
+class MCruxQTWindow;
+#endif
class MCruxWebView
{
+#ifdef WIN32
HWND hParentWindow;
IWebView* webView;
HWND hWebViewWindow;
const BSTR httpGetMethod;
-
bool initWithHostWindow(HWND hWnd);
+
+#else // for linux
+ QWebView* webView;
+ MCruxQTWindow * parentWindow;
+#endif
+
bool loadPage(const wstring & defaultPageText) const;
bool storeViewWindowHandle();
public:
- MCruxWebView();
+ MCruxWebView(
+#ifndef WIN32 // for linux
+ MCruxQTWindow * _parentWindow
+#endif
+ );
~MCruxWebView();
bool createWebView();
+ bool navigateTo(const wstring & url);
+
+#ifdef WIN32
bool setFrameLoadDelegate(MCruxWebFrameLoadDelegate * frameLoadDelegate);
bool setWebUIDelegate(MCruxWebUIDelegate * webUIDelegate);
- void resizeSubView() const;
-
+
+ void resizeSubView() const;
bool loadPageInWindow(HWND hWnd, const wstring & defaultPageText);
bool loadURLInWindow(HWND hWnd, const wstring & url);
bool loadURLRequestInWindow(HWND hWnd, IWebURLRequest *request);
- bool navigateTo(const wstring & url);
bool navigateTo(IWebURLRequest *request);
IWebView * getWebView();
+#endif
};
#endif // _MCRUXWEBVIEW_H_
=======================================
--- /trunk/src/lib/abstract/MCruxWindow.h Sun Nov 1 04:45:19 2009
+++ /trunk/src/lib/abstract/MCruxWindow.h Sat Nov 7 10:37:22 2009
@@ -36,10 +36,10 @@
MCruxWindow(const MCruxWindowConfiguration * _config);
virtual ~MCruxWindow();
- virtual int ShowWindow() const=0;
- virtual int HideWindow() const=0;
- virtual int UpdateWindow() const=0;
- virtual void resize() const=0;
+ virtual int ShowWindow()=0;
+ virtual int HideWindow()=0;
+ virtual int UpdateWindow()=0;
+ virtual void resize()=0;
};
#endif // _MCRUXWINDOW_H_
=======================================
--- /trunk/src/lib/window/MCruxQTWindow.cpp Thu Nov 5 17:39:05 2009
+++ /trunk/src/lib/window/MCruxQTWindow.cpp Sat Nov 7 10:37:22 2009
@@ -24,8 +24,15 @@
MCruxQTWindow::MCruxQTWindow(const MCruxWindowConfiguration * _config)
: MCruxWindow(_config)
-{
- this->show();
+#ifndef WIN32 // for linux
+ , webView(this)
+#endif
+{
+ webView.createWebView();
+ if(!webView.navigateTo(config->getURL()))
+ {
+ cerr << "Error navigating to url:" << endl;
+ }
}
@@ -33,24 +40,25 @@
{
}
-int MCruxQTWindow::ShowWindow() const
-{
- return -1;
+int MCruxQTWindow::ShowWindow()
+{
+ this->show();
+ return 0;
}
-int MCruxQTWindow::HideWindow() const
+int MCruxQTWindow::HideWindow()
{
return -1;
}
-int MCruxQTWindow::UpdateWindow() const
+int MCruxQTWindow::UpdateWindow()
{
return -1;
}
-void MCruxQTWindow::resize() const
+void MCruxQTWindow::resize()
{
}
=======================================
--- /trunk/src/lib/window/MCruxQTWindow.h Thu Nov 5 17:39:05 2009
+++ /trunk/src/lib/window/MCruxQTWindow.h Sat Nov 7 10:37:22 2009
@@ -24,33 +24,30 @@
#include <abstract/MCruxWindow.h>
#include <window/MCruxWindowConfiguration.h>
-//#include "MCruxWebView.h"
+#include "MCruxWebView.h"
//#include "plugin/MCruxPluginManager.h"
class MCruxQTWindow
- : public QWidget,
+ : public QMainWindow,
public MCruxWindow
{
-#ifdef WIN32
-private:
- // webView
- MCruxWebView webView;
-#else
+#ifndef WIN32
Q_OBJECT
-
- // TODO: Add Qwebview class
#endif
+private:
+ MCruxWebView webView;
+
public:
MCruxQTWindow(const MCruxWindowConfiguration * _config);
virtual ~MCruxQTWindow();
- virtual int ShowWindow() const;
- virtual int HideWindow() const;
- virtual int UpdateWindow() const;
- virtual void resize() const;
+ virtual int ShowWindow();
+ virtual int HideWindow();
+ virtual int UpdateWindow();
+ virtual void resize();
};
#endif // _MCRUXQTWINDOW_H_
=======================================
--- /trunk/src/lib/window/MCruxWin32Window.cpp Sun Nov 1 04:45:19 2009
+++ /trunk/src/lib/window/MCruxWin32Window.cpp Sat Nov 7 10:37:22 2009
@@ -95,25 +95,25 @@
delete config;
}
-int MCruxWin32Window::ShowWindow() const
+int MCruxWin32Window::ShowWindow()
{
return ::ShowWindow(hWnd, SW_SHOW);
}
-int MCruxWin32Window::HideWindow() const
+int MCruxWin32Window::HideWindow()
{
return ::ShowWindow(hWnd, SW_HIDE);
}
-int MCruxWin32Window::UpdateWindow() const
+int MCruxWin32Window::UpdateWindow()
{
return ::UpdateWindow(hWnd);
}
-void MCruxWin32Window::resize() const
+void MCruxWin32Window::resize()
{
webView.resizeSubView();
}
@@ -192,8 +192,8 @@
case WM_DESTROY:
PostQuitMessage(0);
break;
- case WM_SIZE:
- if(MCruxWin32Window::mcruxWindows[hWnd])
+ case WM_SIZE:
+ if(MCruxWin32Window::mcruxWindows[hWnd]
{
MCruxWin32Window::mcruxWindows[hWnd]->resize();
}
@@ -213,4 +213,4 @@
MCruxWin32Window * MCruxWin32Window::getMCruxWindowFrom(IWebView * webView)
{
return MCruxWin32Window::mcruxWindowsFromViews[webView];
-}
+ }
=======================================
--- /trunk/src/lib/window/MCruxWin32Window.h Sun Nov 1 04:45:19 2009
+++ /trunk/src/lib/window/MCruxWin32Window.h Sat Nov 7 10:37:22 2009
@@ -52,10 +52,10 @@
MCruxWindowManager * windowManager);
~MCruxWin32Window();
- virtual int ShowWindow() const;
- virtual int HideWindow() const;
- virtual int UpdateWindow() const;
- virtual void resize() const;
+ virtual int ShowWindow();
+ virtual int HideWindow();
+ virtual int UpdateWindow();
+ virtual void resize();
MCruxWebView * getMCruxWebView();
static void initWindowClass(HINSTANCE hInstance);
=======================================
--- /trunk/src/lib/window/MCruxWindowManager.cpp Thu Nov 5 17:39:05 2009
+++ /trunk/src/lib/window/MCruxWindowManager.cpp Sat Nov 7 10:37:22 2009
@@ -39,13 +39,13 @@
oIter != _windowConfigurations.end();
oIter++)
{
- MCruxWindowConfiguration * mainWindowConfig = *oIter;
+ MCruxWindowConfiguration *windowConfig = *oIter;
MCruxWindow * newWindow = NULL;
#ifdef WIN32
- newWindow = new MCruxWin32Window(mainWindowConfig, pluginManager, this);
+ newWindow = new MCruxWin32Window(windowConfig, pluginManager, this);
#else
- newWindow = new MCruxQTWindow(mainWindowConfig);
+ newWindow = new MCruxQTWindow(windowConfig);
#endif
newWindow->ShowWindow();
=======================================
--- /trunk/src/src.pro Thu Nov 5 17:39:05 2009
+++ /trunk/src/src.pro Sat Nov 7 10:37:22 2009
@@ -5,6 +5,7 @@
TEMPLATE = app
TARGET = mcrux.bin
LIBS += -lxml2
+QT += webkit
DEPENDPATH += . \
/usr/include/libxml2 \
bin \
@@ -27,6 +28,7 @@
SOURCES += bin/mcrux_linux.cpp \
lib/MCrux.cpp \
lib/MCruxSpecParser.cpp \
+ lib/MCruxWebView.cpp \
lib/abstract/MCruxWindow.cpp \
lib/window/MCruxQTWindow.cpp \
lib/window/MCruxWindowConfiguration.cpp \