Commit 3911418f authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov

trunk cef

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@64195 954022d7-b5bf-4e40-9824-e11837661b57
parent 4c06d217
This diff is collapsed.
QT += core gui widgets gui-private widgets-private core-private printsupport
TEMPLATE = app
CONFIG += app_bundle
CONFIG(debug, debug|release) {
DESTDIR = $$PWD/build/windows/Debug
} else {
DESTDIR = $$PWD/build/windows/Release
}
HEADERS += \
mainwindow.h \
qmainpanel.h \
qwinhost.h \
qwinwidget.h \
asctabwidget.h \
../../lib/qcefview/qcefview.h \
QAscApplicationManager.h \
../../lib/include/qascprinter.h
SOURCES += \
main.cpp \
mainwindow.cpp \
qmainpanel.cpp \
qwinhost.cpp \
qwinwidget.cpp \
../../lib/qcefview/qcefview.cpp
RESOURCES += \
Icons.qrc
LIBS += -lwininet \
-ldnsapi \
-lversion \
-lmsimg32 \
-lws2_32 \
-lusp10 \
-lpsapi \
-ldbghelp \
-lwinmm \
-lshlwapi \
-lkernel32 \
-lgdi32 \
-lwinspool \
-lcomdlg32 \
-ladvapi32 \
-lshell32 \
-lole32 \
-loleaut32 \
-luser32 \
-luuid \
-lodbc32 \
-lodbccp32 \
-ldelayimp \
-lcredui \
-lnetapi32 \
-lcomctl32 \
-lrpcrt4 \
-ldwmapi \
-lOpenGL32
win32:contains(QMAKE_TARGET.arch, x86_64):{
DEFINES += JAS_WIN_MSVC_BUILD WIN32
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.02
CONFIG(debug, debug|release) {
LIBS += -L../../cefbuilds/win64 -llibcef
LIBS += -L../../../lib/build/Debug/debug -lascdocumentscore
} else {
LIBS += -L../../cefbuilds/win64 -llibcef
LIBS += -L../../../lib/build/Release/release -lascdocumentscore
}
message(windows64)
}
win32:!contains(QMAKE_TARGET.arch, x86_64):{
DEFINES += JAS_WIN_MSVC_BUILD WIN32 _WIN32
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
CONFIG(debug, debug|release) {
LIBS += -L../../cefbuilds/win32 -llibcef
LIBS += -L../../../lib/build/Debug/debug -lascdocumentscore
} else {
LIBS += -L../../cefbuilds/win32 -llibcef
LIBS += -L../../../lib/build/Release/release -lascdocumentscore
}
message(windows32)
}
<RCC>
<qresource prefix="/">
<file>Icons/collapse_active.png</file>
<file>Icons/collapse_hover.png</file>
<file>Icons/collapse_normal.png</file>
<file>Icons/deploy_active.png</file>
<file>Icons/deploy_hover.png</file>
<file>Icons/deploy_normal.png</file>
<file>Icons/exit_active.png</file>
<file>Icons/exit_hover.png</file>
<file>Icons/exit_normal.png</file>
<file>Icons/first_tab_active.png</file>
<file>Icons/first_tab_hover.png</file>
<file>Icons/first_tab_normal.png</file>
<file>Icons/output_tab_active.png</file>
<file>Icons/output_tab_hover.png</file>
<file>Icons/output_tab_normal.png</file>
<file>Icons/tabicon_DE_active.png</file>
<file>Icons/tabicon_DE_normal.png</file>
<file>Icons/tabicon_PE_active.png</file>
<file>Icons/tabicon_PE_normal.png</file>
<file>Icons/tabicon_SE_active.png</file>
<file>Icons/tabicon_SE_normal.png</file>
<file>Icons/changetab_left_active.png</file>
<file>Icons/changetab_left_hover.png</file>
<file>Icons/changetab_left_normal.png</file>
<file>Icons/changetab_right_active.png</file>
<file>Icons/changetab_right_hover.png</file>
<file>Icons/changetab_right_normal.png</file>
<file>Icons/changetab_left_disabled.png</file>
<file>Icons/changetab_right_disabled.png</file>
<file>Icons/deploy2_active.png</file>
<file>Icons/deploy2_hover.png</file>
<file>Icons/deploy2_normal.png</file>
<file>Icons/Documents_active_hover.png</file>
<file>Icons/Documents_active_normal.png</file>
<file>Icons/Documents_disabled_hover.png</file>
<file>Icons/Documents_disabled_normal.png</file>
<file>Icons/new_collapse_normal.png</file>
<file>Icons/new_deploy_hover.png</file>
<file>Icons/new_deploy_normal.png</file>
<file>Icons/new_exit_hover.png</file>
<file>Icons/new_exit_normal.png</file>
<file>Icons/new_deploy2_hover.png</file>
<file>Icons/new_deploy2_normal.png</file>
<file>Icons/new_collapse_hover.png</file>
</qresource>
</RCC>
#ifndef QASCAPPLICATIONMANAGER
#define QASCAPPLICATIONMANAGER
#include "../../lib/include/cefapplication.h"
#include "../../lib/include/applicationmanager.h"
#include <shlwapi.h>
#include <shlobj.h>
#include <QFileDialog>
#include "qmainpanel.h"
class QAscApplicationManager : public CAscApplicationManager
{
public:
QMainPanel* m_pPanel;
public:
QAscApplicationManager()
{
m_pPanel = NULL;
}
public:
virtual void StartSaveDialog(const std::wstring& sName)
{
// сделал через QMainPanel - чтобы использовать сигналы-слоты.
// если сделать QAscApplicationManager : public QObject, то он будет прокидывать
// слоты родителю. Т.е. классу CAscApplicationManager.
// А в либе я не буду затачиваться на QT
((QMainPanel*)m_pPanel)->sendDialogSave(sName);
}
};
#endif // QASCAPPLICATIONMANAGER
This diff is collapsed.
#ifndef ASCEDITORWIDGET
#define ASCEDITORWIDGET
#include <QWidget>
#include <QTabWidget>
#include <QTabBar>
#include <QStyleOption>
#include <QPainter>
#include <QApplication>
namespace NSAscEditor
{
enum EditorType
{
etDocument = 0,
etPresentation = 1,
etSpreadsheet = 2
};
}
#if 0
class CAscEditorWidget : public QWidget
{
Q_OBJECT
public:
NSAscEditor::EditorType m_etType;
public:
CAscEditorWidget(QWidget *parent = 0, NSAscEditor::EditorType etType = NSAscEditor::etDocument) : QWidget(parent)
{
m_etType = etType;
setStyleSheet("background-color:#FF00FF");
}
~CAscEditorWidget()
{
}
void SetIcon(int nIndex, QTabWidget* pWidget)
{
int nSelectedIndex = pWidget->tabBar()->currentIndex();
QTabBar* pTabBar = pWidget->tabBar();
bool bIsActive = (nIndex == nSelectedIndex) ? true : false;
switch (m_etType)
{
case NSAscEditor::etPresentation:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_PE_active.png") : QIcon(":/Icons/tabicon_PE_normal.png"));
break;
}
case NSAscEditor::etSpreadsheet:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_SE_active.png") : QIcon(":/Icons/tabicon_SE_normal.png"));
break;
}
case NSAscEditor::etDocument:
default:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_DE_active.png") : QIcon(":/Icons/tabicon_DE_normal.png"));
break;
}
}
pTabBar->setTabTextColor(nIndex, bIsActive ? QColor(255, 255, 255) : QColor(51, 51, 51));
}
protected:
void paintEvent(QPaintEvent* e)
{
Q_UNUSED(e);
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
};
#else
#include "./cef/qcefwebview.h"
class CAscEditorWidget : public QCefWebView
{
Q_OBJECT
public:
NSAscEditor::EditorType m_etType;
public:
CAscEditorWidget(QWidget *parent = 0, NSAscEditor::EditorType etType = NSAscEditor::etDocument, std::wstring strUrl = L"") : QCefWebView(parent)
{
this->setParentTabs((QTabWidget*)parent);
m_etType = etType;
std::wstring sUrl = QApplication::applicationDirPath().toStdWString();
sUrl += L"/deploy/apps/api/documents/index.html";
if (etType == NSAscEditor::etSpreadsheet)
sUrl += L"?doctype=spreadsheet";
if (etType == NSAscEditor::etPresentation)
sUrl += L"?doctype=presentation";
if (strUrl.length() != 0)
sUrl = strUrl;
this->load(sUrl);
}
virtual ~CAscEditorWidget()
{
}
void SetIcon(int nIndex, QTabWidget* pWidget)
{
int nSelectedIndex = pWidget->tabBar()->currentIndex();
QTabBar* pTabBar = pWidget->tabBar();
bool bIsActive = (nIndex == nSelectedIndex) ? true : false;
switch (m_etType)
{
case NSAscEditor::etPresentation:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_PE_active.png") : QIcon(":/Icons/tabicon_PE_normal.png"));
break;
}
case NSAscEditor::etSpreadsheet:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_SE_active.png") : QIcon(":/Icons/tabicon_SE_normal.png"));
break;
}
case NSAscEditor::etDocument:
default:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_DE_active.png") : QIcon(":/Icons/tabicon_DE_normal.png"));
break;
}
}
//pTabBar->setTabTextColor(nIndex, bIsActive ? QColor(255, 255, 255) : QColor(51, 51, 51));
pTabBar->setTabTextColor(nIndex, QColor(51, 51, 51));
}
};
#endif
#endif // ASCEDITORWIDGET
#include <QFile>
#include "QAscApplicationManager.h"
#include "mainwindow.h"
#include <QScreen>
#include <shlwapi.h>
#include <shlobj.h>
int main( int argc, char *argv[] )
{
bool bIsChromiumSubprocess = false;
for (int i = 0; i < argc; ++i)
{
if ((0 == strcmp("--type=gpu-process", argv[i])) ||
(0 == strcmp("--type=renderer", argv[i])))
{
bIsChromiumSubprocess = true;
break;
}
}
#if 0
FILE* f = fopen("E:\\12345.txt", "a+");
fprintf(f, "-----------------------------------------------\n");
for (int i = 0; i < argc; ++i)
{
fprintf(f, argv[i]);
fprintf(f, "\n");
}
fprintf(f, "-----------------------------------------------\n");
fclose(f);
#endif
if (bIsChromiumSubprocess)
{
QApplication aa(argc, argv);
CApplicationCEF oCef;
CAscApplicationManager oManager;
WCHAR szPath[MAX_PATH];
// Get path for each computer, non-user specific and non-roaming data.
if ( SUCCEEDED( SHGetFolderPathW( NULL, CSIDL_COMMON_APPDATA, NULL, 0, szPath ) ) )
{
// Append product-specific path
std::wstring sAppData(szPath);
sAppData += L"/ONLYOFFICE";
oManager.m_oSettings.SetUserDataPath(sAppData);
}
oCef.Init_CEF(&oManager);
return aa.exec();
}
QApplication a(argc, argv);
CApplicationCEF* application_cef = new CApplicationCEF();
CAscApplicationManager* pApplicationManager = new QAscApplicationManager();
WCHAR szPath[MAX_PATH];
// Get path for each computer, non-user specific and non-roaming data.
if ( SUCCEEDED( SHGetFolderPathW( NULL, CSIDL_COMMON_APPDATA, NULL, 0, szPath ) ) )
{
// Append product-specific path
std::wstring sAppData(szPath);
sAppData += L"/ONLYOFFICE";
pApplicationManager->m_oSettings.SetUserDataPath(sAppData);
}
qreal ww = a.primaryScreen()->logicalDotsPerInch();
qreal hh = a.primaryScreen()->physicalDotsPerInch();
application_cef->Init_CEF(pApplicationManager);
pApplicationManager->CheckFonts();
a.setStyleSheet("#mainPanel { margin: 0; padding: 0; }\
#systemPanel { margin: 0; padding: 0; } \
#centralWidget { background: #fff; }");
// Font
QFont mainFont = a.font();
mainFont.setStyleStrategy( QFont::PreferAntialias );
a.setFont( mainFont );
// Background color
HBRUSH windowBackground = CreateSolidBrush( RGB( 49, 52, 55 ) );
// Create window
CMainWindow window( &a, windowBackground, 100, 100, 1024 * 2, 600 * 2, pApplicationManager );
window.setMinimumSize( 100, 100 );
((QAscApplicationManager*)pApplicationManager)->m_pPanel = window.mainPanel;
// Launch
a.exec();
// release all subprocesses
pApplicationManager->CloseApplication();
delete application_cef;
delete pApplicationManager;
}
This diff is collapsed.
#include <windows.h>
#include "../../lib/include/applicationmanager.h"
#include "qmainpanel.h"
#include "qwinwidget.h"
#include <QtWidgets/QApplication>
class CMainWindow
{
enum class Style : DWORD
{
//windowed = ( WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN | WS_SYSMENU ),
//aero_borderless = ( WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN )
windowed = ( WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN ),
aero_borderless = ( WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN )
};
public:
HWND hWnd;
HINSTANCE hInstance;
CAscApplicationManager* m_pManager;
CMainWindow( QApplication *app, HBRUSH windowBackground, const int x, const int y, const int width, const int height, CAscApplicationManager* pManager );
~CMainWindow();
static LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
void show();
void hide();
bool isVisible();
void toggleBorderless();
void toggleShadow();
void toggleResizeable();
bool isResizeable();
void setMinimumSize( const int width, const int height );
bool isSetMinimumSize();
void removeMinimumSize();
int getMinimumHeight();
int getMinimumWidth();
void setMaximumSize( const int width, const int height );
bool isSetMaximumSize();
int getMaximumHeight();
int getMaximumWidth();
void removeMaximumSize();
public:
QApplication *a;
QMainPanel *mainPanel;
private:
bool closed;
bool visible;
bool borderless;
bool aeroShadow;
bool borderlessResizeable;
struct sizeType
{
sizeType() : required( false ), width( 0 ), height( 0 ) {}
bool required;
int width;
int height;
};
sizeType minimumSize;
sizeType maximumSize;
UINT_PTR m_nTimerLanguageId;
};
This diff is collapsed.
#ifndef QMAINPANEL_H
#define QMAINPANEL_H
#include <QMouseEvent>
#include <QResizeEvent>
#include <QtWidgets/QTabWidget>
#include <QtWidgets/QPushButton>
#include "qwinwidget.h"
#include <QLabel>
#include "../../lib/include/applicationmanager.h"
class QMainPanel : public QWinWidget, public NSEditorApi::CAscMenuEventListener
{
Q_OBJECT
signals:
void downloadEvent( NSEditorApi::CAscDownloadFileInfo* );
void setModified(int, bool);
void signalPrint(int, int);
void dialogSave(std::wstring sName);
public:
QMainPanel( HWND hWnd, CAscApplicationManager* pManager );
bool nativeEvent(const QByteArray &, void *msg, long *result);
void mousePressEvent( QMouseEvent *event );
void resizeEvent(QResizeEvent* event);
public slots:
void pushButtonSaveClicked();
void pushButtonMinimizeClicked();
void pushButtonMaximizeClicked();
void pushButtonCloseClicked();
void pushButtonMainClicked();
void downloadEventSlot( NSEditorApi::CAscDownloadFileInfo* );
void onSetModified(int, bool);
void slotPrint(int, int);
void onDialogSave(std::wstring sName);
private:
HWND windowHandle;
QPushButton* m_pButtonMain;
QWidget* m_pMainWidget;
QPushButton* m_pButtonMinimize;
QPushButton* m_pButtonMaximize;
QPushButton* m_pButtonClose;
QPushButton* m_pSaveModifiedButton;
QTabWidget* m_pTabs;
QWidget* m_pSeparator;
std::wstring m_sDownloadName;
CAscApplicationManager* m_pManager;
std::map<int, NSEditorApi::CAscDownloadFileInfo*> m_mapDownloads;
QWidget* m_pDownloadBackground;
QLabel* m_pDownloadLable;
public:
HWND GetHwndForKeyboard()
{
return (HWND)((QWidget*)m_pTabs->parent())->winId();
}
public:
virtual void OnEvent(NSEditorApi::CAscMenuEvent* pEvent);
virtual bool IsSupportEvent(int nEventType)
{
return true;
}
void sendDialogSave(std::wstring sName);
private:
void RecalculatePlaces();
};
#endif // QMAINPANEL_H
// Implementation of the QWinHost classes
#include "qwinhost.h"
#include <QEvent>
#include <qt_windows.h>
/*!
\class QWinHost qwinhost.h
\brief The QWinHost class provides an API to use native Win32
windows in Qt applications.
QWinHost exists to provide a QWidget that can act as a parent for
any native Win32 control. Since QWinHost is a proper QWidget, it
can be used as a toplevel widget (e.g. 0 parent) or as a child of
any other QWidget.
QWinHost integrates the native control into the Qt user interface,
e.g. handles focus switches and laying out.
Applications moving to Qt may have custom Win32 controls that will
take time to rewrite with Qt. Such applications can use these
custom controls as children of QWinHost widgets. This allows the
application's user interface to be replaced gradually.
When the QWinHost is destroyed, and the Win32 window hasn't been
set with setWindow(), the window will also be destroyed.
*/
/*!
Creates an instance of QWinHost. \a parent and \a f are
passed on to the QWidget constructor. The widget has by default
no background.
\warning You cannot change the parent widget of the QWinHost instance
after the native window has been created, i.e. do not call
QWidget::setParent or move the QWinHost into a different layout.
*/
QWinHost::QWinHost(QWidget *parent, Qt::WindowFlags f) :
QWidget(parent, f), wndproc(0),own_hwnd(false), hwnd(0)
{
setAttribute(Qt::WA_NoBackground);
}
/*!
Destroys the QWinHost object. If the hosted Win32 window has not
been set explicitly using setWindow() the window will be
destroyed.
*/
QWinHost::~QWinHost()
{
if (wndproc)
{
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc);
}
if (hwnd && own_hwnd)
DestroyWindow(hwnd);
}
/*!
Reimplement this virtual function to create and return the native
Win32 window. \a parent is the handle to this widget, and \a
instance is the handle to the application instance. The returned HWND
must be a child of the \a parent HWND.
The default implementation returns null. The window returned by a
reimplementation of this function is owned by this QWinHost
instance and will be destroyed in the destructor.
This function is called by the implementation of polish() if no
window has been set explicitly using setWindow(). Call polish() to
force this function to be called.
\sa setWindow()
*/
HWND QWinHost::createWindow(HWND parent, HINSTANCE instance)
{
Q_UNUSED(parent);
Q_UNUSED(instance);
return 0;
}
/*!
Ensures that the window provided a child of this widget, unless
it is a WS_OVERLAPPED window.
*/
void QWinHost::fixParent()
{
if (!hwnd)
return;
if (!::IsWindow(hwnd))
{
hwnd = 0;
return;
}
if (::GetParent(hwnd) == (HWND)winId())
return;
long style = GetWindowLong(hwnd, GWL_STYLE);
if (style & WS_OVERLAPPED)
return;
::SetParent(hwnd, (HWND)winId());
}
/*!
Sets the native Win32 window to \a window. If \a window is not a child
window of this widget, then it is reparented to become one. If \a window
is not a child window (i.e. WS_OVERLAPPED is set), then this function does nothing.
The lifetime of the window handle will be managed by Windows, QWinHost does not
call DestroyWindow. To verify that the handle is destroyed when expected, handle
WM_DESTROY in the window procedure.
\sa window(), createWindow()
*/
void QWinHost::setWindow(HWND window)
{
if (hwnd && own_hwnd)
DestroyWindow(hwnd);
hwnd = window;
fixParent();
own_hwnd = false;
}
/*!
Returns the handle to the native Win32 window, or null if no
window has been set or created yet.
\sa setWindow(), createWindow()
*/
HWND QWinHost::window() const
{
return hwnd;
}
void *getWindowProc(QWinHost *host)
{
return host ? host->wndproc : 0;
}
LRESULT CALLBACK WinHostProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
QWinHost *widget = qobject_cast<QWinHost*>(QWidget::find((WId)::GetParent(hwnd)));
WNDPROC oldproc = (WNDPROC)getWindowProc(widget);
if (widget)
{
switch(msg)
{
case WM_LBUTTONDOWN:
if (::GetFocus() != hwnd && (widget->focusPolicy() & Qt::ClickFocus))
{
widget->setFocus(Qt::MouseFocusReason);
}
break;
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
SendMessage((HWND)widget->winId(), msg, wParam, lParam);
break;
case WM_KEYDOWN:
if (wParam == VK_TAB)
{
SendMessage((HWND)widget->winId(), msg, wParam, lParam);
}
break;
default:
break;
}
}
if (oldproc)
return CallWindowProc(oldproc, hwnd, msg, wParam, lParam);
return DefWindowProc(hwnd, msg, wParam, lParam);
}
/*!
\reimp
*/
bool QWinHost::event(QEvent *e)
{
switch(e->type())
{
case QEvent::Polish:
if (!hwnd)
{
hwnd = createWindow((HWND)winId(), qWinAppInst());
fixParent();
own_hwnd = hwnd != 0;
}
if (hwnd && !wndproc && GetParent(hwnd) == (HWND)winId())
{
wndproc = (void*)GetWindowLongPtr(hwnd, GWLP_WNDPROC);
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WinHostProc);
LONG style = GetWindowLong(hwnd, GWL_STYLE);
if (style & WS_TABSTOP)
setFocusPolicy(Qt::FocusPolicy(focusPolicy() | Qt::StrongFocus));
}
break;
case QEvent::WindowBlocked:
if (hwnd)
EnableWindow(hwnd, false);
break;
case QEvent::WindowUnblocked:
if (hwnd)
EnableWindow(hwnd, true);
break;
}
return QWidget::event(e);
}
/*!
\reimp
*/
void QWinHost::showEvent(QShowEvent *e)
{
QWidget::showEvent(e);
if (hwnd)
SetWindowPos(hwnd, HWND_TOP, 0, 0, width(), height(), SWP_SHOWWINDOW);
}
/*!
\reimp
*/
void QWinHost::focusInEvent(QFocusEvent *e)
{
QWidget::focusInEvent(e);
if (hwnd)
::SetFocus(hwnd);
}
/*!
\reimp
*/
void QWinHost::resizeEvent(QResizeEvent *e)
{
QWidget::resizeEvent(e);
if (hwnd)
SetWindowPos(hwnd, HWND_TOP, 0, 0, width(), height(), 0);
}
/*!
\reimp
*/
bool QWinHost::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
MSG *msg = (MSG *)message;
switch (msg->message)
{
case WM_SETFOCUS:
if (hwnd)
{
::SetFocus(hwnd);
return true;
}
default:
break;
}
return QWidget::nativeEvent(eventType, message, result);
}
#ifndef QWINHOST_H
#define QWINHOST_H
#include <QtWidgets/QWidget>
#include <Windows.h>
class QWinHost : public QWidget
{
Q_OBJECT
public:
QWinHost(QWidget *parent = 0, Qt::WindowFlags f = 0);
~QWinHost();
void setWindow(HWND);
HWND window() const;
protected:
virtual HWND createWindow(HWND parent, HINSTANCE instance);
bool event(QEvent *e);
void showEvent(QShowEvent *);
void focusInEvent(QFocusEvent*);
void resizeEvent(QResizeEvent*);
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
private:
void fixParent();
friend void* getWindowProc(QWinHost*);
void* wndproc;
bool own_hwnd;
HWND hwnd;
};
#endif // QWINHOST_H
#include <qevent.h>
#include "qwinwidget.h"
#include <qt_windows.h>
#include <QtWidgets/QApplication>
#include <QWindow>
#include <qpa/qplatformnativeinterface.h>
/*!
\class QWinWidget qwinwidget.h
\brief The QWinWidget class is a Qt widget that can be child of a
native Win32 widget.
The QWinWidget class is the bridge between an existing application
user interface developed using native Win32 APIs or toolkits like
MFC, and Qt based GUI elements.
Using QWinWidget as the parent of QDialogs will ensure that
modality, placement and stacking works properly throughout the
entire application. If the child widget is a top level window that
uses the \c WDestructiveClose flag, QWinWidget will destroy itself
when the child window closes down.
Applications moving to Qt can use QWinWidget to add new
functionality, and gradually replace the existing interface.
*/
/*!
Creates an instance of QWinWidget. \a hParentWnd is the handle to
the native Win32 parent. If a \a parent is provided the object is
owned by that QObject. \a f is passed on to the QWidget constructor.
*/
QWinWidget::QWinWidget(HWND hParentWnd, QObject *parent, Qt::WindowFlags f)
: QWidget(0, f), hParent(hParentWnd), prevFocus(0), reenable_parent(false)
{
if (parent)
QObject::setParent(parent);
init();
}
void QWinWidget::init()
{
Q_ASSERT(hParent);
if (hParent)
{
// make the widget window style be WS_CHILD so SetParent will work
LONG lStyle = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
SetWindowLong((HWND)winId(), GWL_STYLE, lStyle);
QWindow *window = windowHandle();
window->setProperty("_q_embedded_native_parent_handle", (WId)hParent);
HWND h = static_cast<HWND>(QGuiApplication::platformNativeInterface()->
nativeResourceForWindow("handle", window));
SetParent(h, hParent);
window->setFlags(Qt::FramelessWindowHint);
QEvent e(QEvent::EmbeddingControl);
QApplication::sendEvent(this, &e);
}
}
/*!
Destroys this object, freeing all allocated resources.
*/
QWinWidget::~QWinWidget()
{
}
/*!
Returns the handle of the native Win32 parent window.
*/
HWND QWinWidget::parentWindow() const
{
return hParent;
}
/*!
\reimp
*/
void QWinWidget::childEvent(QChildEvent *e)
{
QObject *obj = e->child();
if (obj->isWidgetType())
{
if (e->added())
{
if (obj->isWidgetType())
{
obj->installEventFilter(this);
}
}
else if (e->removed() && reenable_parent)
{
reenable_parent = false;
EnableWindow(hParent, true);
obj->removeEventFilter(this);
}
}
QWidget::childEvent(e);
}
/*! \internal */
void QWinWidget::saveFocus()
{
if (!prevFocus)
prevFocus = ::GetFocus();
if (!prevFocus)
prevFocus = parentWindow();
}
/*!
Shows this widget. Overrides QWidget::show().
\sa showCentered()
*/
void QWinWidget::show()
{
saveFocus();
QWidget::show();
}
/*!
Centers this widget over the native parent window. Use this
function to have Qt toplevel windows (i.e. dialogs) positioned
correctly over their native parent windows.
\code
QWinWidget qwin(hParent);
qwin.center();
QMessageBox::information(&qwin, "Caption", "Information Text");
\endcode
This will center the message box over the client area of hParent.
*/
void QWinWidget::center()
{
const QWidget *child = findChild<QWidget*>();
if (child && !child->isWindow())
{
qWarning("QWinWidget::center: Call this function only for QWinWidgets with toplevel children");
}
RECT r;
GetWindowRect(hParent, &r);
setGeometry((r.right-r.left)/2+r.left, (r.bottom-r.top)/2+r.top,0,0);
}
/*!
\obsolete
Call center() instead.
*/
void QWinWidget::showCentered()
{
center();
show();
}
/*!
Sets the focus to the window that had the focus before this widget
was shown, or if there was no previous window, sets the focus to
the parent window.
*/
void QWinWidget::resetFocus()
{
if (prevFocus)
::SetFocus(prevFocus);
else
::SetFocus(parentWindow());
}
/*! \reimp
*/
bool QWinWidget::nativeEvent(const QByteArray &, void *message, long *)
{
MSG *msg = (MSG *)message;
if (msg->message == WM_SETFOCUS)
{
Qt::FocusReason reason;
if (::GetKeyState(VK_LBUTTON) < 0 || ::GetKeyState(VK_RBUTTON) < 0)
reason = Qt::MouseFocusReason;
else if (::GetKeyState(VK_SHIFT) < 0)
reason = Qt::BacktabFocusReason;
else
reason = Qt::TabFocusReason;
QFocusEvent e(QEvent::FocusIn, reason);
QApplication::sendEvent(this, &e);
}
return false;
}
/*!
\reimp
*/
bool QWinWidget::eventFilter(QObject *o, QEvent *e)
{
QWidget *w = (QWidget*)o;
switch (e->type())
{
case QEvent::WindowDeactivate:
if (w->isModal() && w->isHidden())
BringWindowToTop(hParent);
break;
case QEvent::Hide:
if (reenable_parent)
{
EnableWindow(hParent, true);
reenable_parent = false;
}
resetFocus();
if (w->testAttribute(Qt::WA_DeleteOnClose) && w->isWindow())
deleteLater();
break;
case QEvent::Show:
if (w->isWindow())
{
saveFocus();
hide();
if (w->isModal() && !reenable_parent)
{
EnableWindow(hParent, false);
reenable_parent = true;
}
}
break;
case QEvent::Close:
::SetActiveWindow(hParent);
if (w->testAttribute(Qt::WA_DeleteOnClose))
deleteLater();
break;
default:
break;
}
return QWidget::eventFilter(o, e);
}
/*! \reimp
*/
void QWinWidget::focusInEvent(QFocusEvent *e)
{
QWidget *candidate = this;
switch (e->reason())
{
case Qt::TabFocusReason:
case Qt::BacktabFocusReason:
while (!(candidate->focusPolicy() & Qt::TabFocus))
{
candidate = candidate->nextInFocusChain();
if (candidate == this)
{
candidate = 0;
break;
}
}
if (candidate)
{
candidate->setFocus(e->reason());
if (e->reason() == Qt::BacktabFocusReason || e->reason() == Qt::TabFocusReason)
{
candidate->setAttribute(Qt::WA_KeyboardFocusChange);
candidate->window()->setAttribute(Qt::WA_KeyboardFocusChange);
}
if (e->reason() == Qt::BacktabFocusReason)
QWidget::focusNextPrevChild(false);
}
break;
default:
break;
}
}
/*! \reimp
*/
bool QWinWidget::focusNextPrevChild(bool next)
{
QWidget *curFocus = focusWidget();
if (!next)
{
if (!curFocus->isWindow())
{
QWidget *nextFocus = curFocus->nextInFocusChain();
QWidget *prevFocus = 0;
QWidget *topLevel = 0;
while (nextFocus != curFocus)
{
if (nextFocus->focusPolicy() & Qt::TabFocus)
{
prevFocus = nextFocus;
topLevel = 0;
}
else if (nextFocus->isWindow())
{
topLevel = nextFocus;
}
nextFocus = nextFocus->nextInFocusChain();
}
if (!topLevel)
{
return QWidget::focusNextPrevChild(false);
}
}
}
else
{
QWidget *nextFocus = curFocus;
while (1)
{
nextFocus = nextFocus->nextInFocusChain();
if (nextFocus->isWindow())
break;
if (nextFocus->focusPolicy() & Qt::TabFocus)
{
return QWidget::focusNextPrevChild(true);
}
}
}
::SetFocus(hParent);
return true;
}
#ifndef QWINWIDGET_H
#define QWINWIDGET_H
#include <QtWidgets/QWidget>
class QWinWidget : public QWidget
{
Q_OBJECT
public:
QWinWidget( HWND hParentWnd, QObject *parent = 0, Qt::WindowFlags f = 0 );
~QWinWidget();
void show();
void center();
void showCentered();
HWND parentWindow() const;
protected:
void childEvent( QChildEvent *e );
bool eventFilter( QObject *o, QEvent *e );
bool focusNextPrevChild(bool next);
void focusInEvent(QFocusEvent *e);
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
private:
void init();
void saveFocus();
void resetFocus();
HWND hParent;
HWND prevFocus;
bool reenable_parent;
};
#endif // QWINWIDGET_H
This diff is collapsed.
#ifndef APPLICATION_MANAGER_H
#define APPLICATION_MANAGER_H
#include <string>
#include <vector>
#include "../../../common/File.h"
#include "./applicationmanager_events.h"
#include "./keyboardchecker.h"
#include "./spellchecker.h"
#include "./cefview.h"
#include "./cefapplication.h"
namespace NSCommon
{
static void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
{
size_t posn = 0;
while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
{
text.replace(posn, replaceFrom.length(), replaceTo);
posn += replaceTo.length();
}
}
}
class CAscApplicationSettings
{
public:
std::wstring spell_dictionaries_path;
std::wstring cache_path;
std::wstring cookie_path;
bool use_system_fonts;
std::vector<std::wstring> additional_fonts_folder;
std::wstring fonts_cache_info_path;
std::wstring app_data_path;
public:
CAscApplicationSettings()
{
std::wstring sApplicationPath = NSFile::GetProcessDirectory();
NSCommon::string_replace(sApplicationPath, L"\\", L"/");
app_data_path = sApplicationPath;
spell_dictionaries_path = sApplicationPath + L"/Dictionaries";
cache_path = sApplicationPath + L"/data/cache";
cookie_path = sApplicationPath + L"/data";
use_system_fonts = true;
fonts_cache_info_path = app_data_path + L"/webdata/cloud/fonts";
}
void SetUserDataPath(std::wstring sPath)
{
app_data_path = sPath;
NSCommon::string_replace(app_data_path, L"\\", L"/");
cache_path = app_data_path + L"/data/cache";
cookie_path = app_data_path + L"/data";
use_system_fonts = true;
fonts_cache_info_path = app_data_path + L"/webdata/cloud/fonts";
}
};
class CAscPrintSettings
{
public:
enum PrintMode
{
pmFit = 0, // вписывать по аспекту
pmStretch = 1, // растягивать
pm100 = 2 // печатать как есть
};
public:
PrintMode Mode;
int WidthPix;
int HeightPix;
bool ZoomEnable;
bool RotateEnable;
bool PrintableArea;
public:
CAscPrintSettings()
{
Mode = pm100;
WidthPix = -1;
HeightPix = -1;
ZoomEnable = false;
RotateEnable = true;
PrintableArea = false;
}
};
class CAscApplicationManager_Private;
class CApplicationFonts;
class Q_DECL_EXPORT CAscApplicationManager
{
public:
CAscApplicationManager();
~CAscApplicationManager();
public:
CAscApplicationSettings m_oSettings;
CAscPrintSettings m_oPrintSettings;
public:
void StartSpellChecker();
void StopSpellChecker();
void SpellCheck(const int& nEditorId, const std::string& sTask, int nId);
void CheckKeyboard();
void SendKeyboardAttack();
void CheckFonts(bool bAsync = true);
void SetEventListener(NSEditorApi::CAscMenuEventListener* );
NSEditorApi::CAscMenuEventListener* GetEventListener();
void Apply(NSEditorApi::CAscMenuEvent* );
NSEditorApi::CAscMenuEvent* ApplySync(NSEditorApi::CAscMenuEvent* );
CCefView* CreateCefView(CCefViewWidgetImpl* parent);
CCefViewEditor* CreateCefEditor(CCefViewWidgetImpl* parent);
CCefView* GetViewById(int nId);
CCefView* GetViewByUrl(const std::wstring& url);
void Logout(std::wstring strUrl);
void CancelDownload(int nId);
void DestroyCefView(int nId);
void LockCS(int nId);
void UnlockCS(int nId);
bool IsInitFonts();
CApplicationCEF* GetApplication();
void SetApplication(CApplicationCEF* );
void SetDebugInfoSupport(bool bIsSupport);
bool GetDebugInfoSupport();
void CloseApplication();
CApplicationFonts* GetApplicationFonts();
virtual void StartSaveDialog(const std::wstring& sName);
virtual void EndSaveDialog(const std::wstring& sPath);
virtual int GetPlatformKeyboardLayout();
protected:
CAscApplicationManager_Private* m_pInternal;
};
#endif // APPLICATION_MANAGER_H
#ifndef APPLICATION_BASE_H
#define APPLICATION_BASE_H
#ifdef WIN32
#ifndef Q_DECL_EXPORT
#define Q_DECL_EXPORT __declspec(dllexport)
#include "windows.h"
#endif
#define WindowHandleId HWND
#include <wchar.h>
#endif
#endif // APPLICATION_BASE_H
#ifndef APPLICATION_CEF_H
#define APPLICATION_CEF_H
#include "base.h"
class CApplicationCEF_Private;
class CAscApplicationManager;
class Q_DECL_EXPORT CApplicationCEF
{
protected:
CApplicationCEF_Private* m_pInternal;
public:
CApplicationCEF();
void Init_CEF(CAscApplicationManager* );
virtual ~CApplicationCEF();
void Close();
};
#endif // APPLICATION_CEF_H
#ifndef CEFCLIENT_CEFWEBVIEW_H
#define CEFCLIENT_CEFWEBVIEW_H
#include "base.h"
#include "./applicationmanager_events.h"
enum CefViewWrapperType
{
cvwtSimple = 0,
cvwtEditor = 1
};
enum AscEditorType
{
etDocument = 0,
etPresentation = 1,
etSpreadsheet = 2,
etUndefined = 255
};
class CCefView_Private;
class CAscApplicationManager;
class CCefViewWidgetImpl
{
public:
virtual bool parent_window_is_empty() { return false; }
virtual int parent_x() { return 0; }
virtual int parent_y() { return 0; }
virtual int parent_width() { return 0; }
virtual int parent_height() { return 0; }
virtual WindowHandleId parent_wid() { return 0; }
virtual void child_loaded() { }
};
class Q_DECL_EXPORT CCefView
{
public:
CCefView(CCefViewWidgetImpl* parent, int nId);
virtual ~CCefView();
void load(const std::wstring& url);
std::wstring GetUrl();
void focus(bool value = true);
void resizeEvent(int width = 0, int height = 0);
bool nativeEvent(const char* data, const int& datalen, void *message, long *result);
void Apply(NSEditorApi::CAscMenuEvent* );
NSEditorApi::CAscMenuEvent* ApplySync(NSEditorApi::CAscMenuEvent* );
#if 0
virtual void dragEnterEvent(QDragEnterEvent *);
virtual void dragMoveEvent(QDragMoveEvent *);
virtual void dragLeaveEvent(QDragLeaveEvent *);
virtual void dropEvent(QDropEvent *);
#endif
CAscApplicationManager* GetAppManager();
void SetAppManager(CAscApplicationManager* );
CCefViewWidgetImpl* GetWidgetImpl();
int GetId();
CefViewWrapperType GetType();
void SetParentCef(int nId);
int GetParentCef();
void SetModified(bool bIsModified);
bool GetModified();
protected:
int m_nId;
CefViewWrapperType m_eWrapperType;
CCefView_Private* m_pInternal;
friend class CAscClientHandler;
friend class CAscApplicationManager;
};
class Q_DECL_EXPORT CCefViewEditor : public CCefView
{
protected:
AscEditorType m_eType;
public:
CCefViewEditor(CCefViewWidgetImpl* parent, int nId);
virtual ~CCefViewEditor();
void SetEditorType(AscEditorType eType);
AscEditorType GetEditorType();
};
#endif // CEFCLIENT_CEFWEBVIEW_H
#ifndef APPLICATION_KEYBOARD_CHECKER_H
#define APPLICATION_KEYBOARD_CHECKER_H
#include "base.h"
class CAscApplicationManager;
class Q_DECL_EXPORT CAscKeyboardChecker
{
public:
CAscKeyboardChecker();
~CAscKeyboardChecker();
public:
void Check(CAscApplicationManager* pManager, int nLangInput = -1);
void Send(CAscApplicationManager* pManager);
protected:
int m_nLanguage;
};
#endif // APPLICATION_KEYBOARD_CHECKER_H
#ifndef QASCPRINTER_H
#define QASCPRINTER_H
#include <QtPrintSupport/QPrinter>
#include <QtPrintSupport/QPrintDialog>
#include <QPainter>
#include <QPaintEngine>
#include "./applicationmanager_events.h"
#include <qmath.h>
class QAscPrinterContext : public NSEditorApi::CAscPrinterContextBase
{
private:
QPrinter m_oPrinter;
QPainter m_oPainter;
bool m_bIsUsePainter;
public:
QAscPrinterContext() : NSEditorApi::CAscPrinterContextBase(), m_oPrinter(QPrinter::HighResolution)
{
m_bIsUsePainter = false;
}
QAscPrinterContext(const QPrinterInfo& pi) : NSEditorApi::CAscPrinterContextBase(),
m_oPrinter(pi, QPrinter::HighResolution), m_bIsUsePainter(false)
{
}
void BeginPaint()
{
m_bIsUsePainter = true;
//m_oPrinter.setFullPage(true);
m_oPainter.begin(&m_oPrinter);
}
void EndPaint()
{
if (m_bIsUsePainter)
m_oPainter.end();
m_bIsUsePainter = false;
}
QPrinter* getPrinter()
{
return &m_oPrinter;
}
virtual ~QAscPrinterContext()
{
}
virtual void GetLogicalDPI(int& nDpiX, int& nDpiY)
{
nDpiX = m_oPrinter.logicalDpiX();
nDpiY = m_oPrinter.logicalDpiY();
}
virtual void GetPhysicalRect(int& nX, int& nY, int& nW, int& nH)
{
QRect rect1 = m_oPrinter.pageRect();
QRect rect2 = m_oPrinter.paperRect();
nX = rect1.x();
nY = rect1.y();
nW = rect2.width();
nH = rect2.height();
}
virtual void GetPrintAreaSize(int& nW, int& nH)
{
QRect rect = m_oPrinter.pageRect();
nW = rect.width();
nH = rect.height();
}
virtual void BitBlt(BYTE* pBGRA, const int& nRasterX, const int& nRasterY, const int& nRasterW, const int& nRasterH,
const double& x, const double& y, const double& w, const double& h, const double& dAngle)
{
int nPhysicalX = 0;
int nPhysicalY = 0;
int nPhysicalW = 0;
int nPhysicalH = 0;
this->GetPhysicalRect(nPhysicalX, nPhysicalY, nPhysicalW, nPhysicalH);
//m_oPrinter.setFullPage(true);
// TODO: must be faster!!! (create CBgraFrame as QPixmap???)
//QPainter painter(&m_oPrinter);
QPainter* painter = NULL;
if (m_bIsUsePainter)
painter = &m_oPainter;
else
{
painter = new QPainter();
painter->begin(&m_oPrinter);
}
painter->save();
bool bIsPrintToFile = (m_oPrinter.outputFileName().length() != 0);
bool bIsClip = painter->hasClipping();
painter->setClipping(false);
//QImage oImage(pBGRA + 4 * ((nRasterH - 1) * nRasterW), nRasterW, nRasterH, -4 * nRasterW, QImage::Format_ARGB32);
QImage oImage(pBGRA, nRasterW, nRasterH, 4 * nRasterW, QImage::Format_ARGB32);
double dAngleDeg = dAngle * 180.0 / M_PI;
if ((std::abs(dAngleDeg - 90) < 1.0) || (std::abs(dAngleDeg - 270) < 1.0))
{
//painter->translate(-nPhysicalX, -nPhysicalY);
float fCenterX = (float)(x + w / 2.0);
float fCenterY = (float)(y + h / 2.0);
painter->translate(fCenterX, fCenterY);
painter->rotate(90);
painter->translate(-fCenterX, -fCenterY);
int nWDst = nRasterW;
int nHDst = nRasterH;
int nAreaW = 0;
int nAreaH = 0;
this->GetPrintAreaSize(nAreaW, nAreaH);
int nOldX = nPhysicalX;
nPhysicalX = nPhysicalY;
nPhysicalY = nPhysicalW - nAreaW - nOldX;
if (bIsPrintToFile)
{
// обнуляем сдвиги, напечатается и в отрицательных местах
nPhysicalX = 0;
nPhysicalY = 0;
}
nWDst -= nPhysicalX;
nHDst -= nPhysicalY;
QRect rect((int)x + nPhysicalX, (int)y + nPhysicalY, nWDst, nHDst);
QRect rectSrc(nPhysicalX, nPhysicalY, nWDst, nHDst);
//QRectF rectF((float)x + nPhysicalX, (float)y, (float)w, (float)h);
//painter->drawImage(rectF, oImage);
painter->drawImage(rect, oImage, rectSrc);
}
else
{
int nWDst = nRasterW;
int nHDst = nRasterH;
if (bIsPrintToFile)
{
// обнуляем сдвиги, напечатается и в отрицательных местах
nPhysicalX = 0;
nPhysicalY = 0;
}
nWDst -= nPhysicalX;
nHDst -= nPhysicalY;
QRect rect((int)x + nPhysicalX, (int)y + nPhysicalY, nWDst, nHDst);
QRect rectSrc(nPhysicalX, nPhysicalY, nWDst, nHDst);
painter->drawImage(rect, oImage, rectSrc);
}
painter->restore();
if (!m_bIsUsePainter)
{
painter->end();
delete painter;
}
//m_oPrinter.setFullPage(false);
}
};
#endif // QASCPRINTER_H
#ifndef APPLICATION_SPELL_CHECKER_H
#define APPLICATION_SPELL_CHECKER_H
#include <string>
#include "base.h"
class CAscApplicationManager;
class CAscSpellChecker_Private;
class Q_DECL_EXPORT CAscSpellChecker
{
protected:
CAscSpellChecker_Private* m_pInternal;
public:
CAscSpellChecker();
~CAscSpellChecker();
public:
void SetApplicationManager(CAscApplicationManager* );
void AddTask(const int& nEditorId, const std::string& sTask, int nId); // utf8
void Init(std::wstring sDirectory);
void Start();
void End();
};
#endif // APPLICATION_SPELL_CHECKER_H
#include "./qcefview.h"
#include <QPainter>
QCefView::QCefView(QWidget* parent) : QWidget(parent)
{
m_pCefView = NULL;
m_pLoader = new QWidget(this);
m_pLoader->setGeometry(0, 0, width(), height());
SetBackgroundCefColor(255, 255, 255);
m_pLoader->setHidden(false);
QObject::connect(this, SIGNAL( _loaded() ) , this, SLOT( _loadedSlot() ), Qt::QueuedConnection );
}
QCefView::~QCefView()
{
// release from CApplicationManager
}
void QCefView::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
void QCefView::SetBackgroundCefColor(unsigned char r, unsigned char g, unsigned char b)
{
QString sColor = QString::number((int)r, 16) + QString::number((int)g, 16) + QString::number((int)b, 16);
QString sStyle = "background-color:#" + sColor + ";";
this->setStyleSheet(sStyle);
m_pLoader->setStyleSheet(sStyle);
}
void QCefView::focusInEvent(QFocusEvent* e)
{
if (NULL != m_pCefView)
m_pCefView->focus();
}
void QCefView::resizeEvent(QResizeEvent* e)
{
if (NULL != e)
QWidget::resizeEvent(e);
m_pLoader->setGeometry(0, 0, width(), height());
if (NULL != m_pCefView)
m_pCefView->resizeEvent();
}
bool QCefView::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
if (m_pCefView)
{
if (m_pCefView->nativeEvent(NULL, 0, message, result))
return true;
}
return QWidget::nativeEvent(eventType, message, result);
}
#if 0
void QCefView::dragEnterEvent(QDragEnterEvent *e)
{
m_pCefView->dragEnterEvent(e);
}
void QCefView::dragMoveEvent(QDragMoveEvent *e)
{
m_pCefView->dragMoveEvent(e);
}
void QCefView::dragLeaveEvent(QDragLeaveEvent *e)
{
m_pCefView->dragLeaveEvent(e);
}
void QCefView::dropEvent(QDropEvent *e)
{
m_pCefView->dropEvent(e);
}
#endif
CCefView* QCefView::GetCefView()
{
return m_pCefView;
}
void QCefView::Create(CAscApplicationManager* pManager, CefViewWrapperType eType)
{
switch (eType)
{
case cvwtSimple:
{
m_pCefView = pManager->CreateCefView(this);
break;
}
case cvwtEditor:
{
m_pCefView = pManager->CreateCefEditor(this);
break;
}
default:
break;
}
}
// CCefViewWidgetImpl
int QCefView::parent_x() { return this->pos().x(); }
int QCefView::parent_y() { return this->pos().y(); }
int QCefView::parent_width() { return this->width(); }
int QCefView::parent_height() { return this->height(); }
WindowHandleId QCefView::parent_wid()
{
#if 1
return (WindowHandleId)this->winId();
#else
return (WindowHandleId)m_pLoader->winId();
#endif
}
bool QCefView::parent_window_is_empty() { return true; }
void QCefView::child_loaded()
{
emit _loaded();
}
void QCefView::_loadedSlot()
{
if (!m_pLoader->isHidden())
m_pLoader->setHidden(true);
}
#ifndef CEFCLIENT_QCEFWEBVIEW_H
#define CEFCLIENT_QCEFWEBVIEW_H
#include "./../include/cefview.h"
#include "./../include/applicationmanager.h"
#include <QWidget>
#include <QStyleOption>
class QCefView : public QWidget, public CCefViewWidgetImpl
{
Q_OBJECT
signals:
void _loaded();
public:
QCefView(QWidget* parent);
virtual ~QCefView();
virtual void paintEvent(QPaintEvent *);
void SetBackgroundCefColor(unsigned char r, unsigned char g, unsigned char b);
virtual void focusInEvent(QFocusEvent* e);
virtual void resizeEvent(QResizeEvent* e);
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
#if 0
virtual void dragEnterEvent(QDragEnterEvent *e);
virtual void dragMoveEvent(QDragMoveEvent *e);
virtual void dragLeaveEvent(QDragLeaveEvent *e);
virtual void dropEvent(QDropEvent *e);
#endif
CCefView* GetCefView();
void Create(CAscApplicationManager* pManager, CefViewWrapperType eType);
protected:
CCefView* m_pCefView;
QWidget* m_pLoader;
public:
// CCefViewWidgetImpl
virtual int parent_x();
virtual int parent_y();
virtual int parent_width();
virtual int parent_height();
virtual WindowHandleId parent_wid();
virtual bool parent_window_is_empty();
virtual void child_loaded();
protected slots:
void _loadedSlot();
};
#endif // CEFCLIENT_QCEFWEBVIEW_H
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cefclient/browser/binding_test.h"
#include <algorithm>
#include <string>
#include "include/wrapper/cef_stream_resource_handler.h"
namespace client {
namespace binding_test {
namespace {
const char kTestUrl[] = "http://tests/binding";
const char kTestMessageName[] = "BindingTest";
// Handle messages in the browser process.
class Handler : public CefMessageRouterBrowserSide::Handler {
public:
Handler() {}
// Called due to cefQuery execution in binding.html.
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int64 query_id,
const CefString& request,
bool persistent,
CefRefPtr<Callback> callback) OVERRIDE {
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (url.find(kTestUrl) != 0)
return false;
const std::string& message_name = request;
if (message_name.find(kTestMessageName) == 0) {
// Reverse the string and return.
std::string result = message_name.substr(sizeof(kTestMessageName));
std::reverse(result.begin(), result.end());
callback->Success(result);
return true;
}
return false;
}
};
} // namespace
void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers) {
handlers.insert(new Handler());
}
} // namespace binding_test
} // namespace client
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef CEF_TESTS_CEFCLIENT_BROWSER_BINDING_TEST_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_BINDING_TEST_H_
#pragma once
#include "cefclient/browser/test_runner.h"
namespace client {
namespace binding_test {
// Create message handlers. Called from test_runner.cc.
void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers);
} // namespace binding_test
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_BINDING_TEST_H_
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cefclient/browser/client_handler_std.h"
namespace client {
ClientHandlerStd::ClientHandlerStd(Delegate* delegate,
const std::string& startup_url)
: ClientHandler(delegate, false, startup_url) {
}
} // namespace client
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment