#include "layout.h" #include #include #include #include #include #include int layoutFilter::cRef(0); QAbstractEventDispatcher::EventFilter layoutFilter::prevFilter(NULL); static LRESULT CALLBACK HTMLayoutNotifyHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID vParam); /* bool eventFilter(void *message) { LARGE_INTEGER t1; QueryPerformanceCounter(&t1); HTMLayoutTranslateMessage((MSG*)message); LARGE_INTEGER t2; QueryPerformanceCounter(&t2); LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); //qDebug()<<(qreal)(qreal(t2.QuadPart-t1.QuadPart)/freq.QuadPart); return false; }*/ Layout::Layout(QWidget *parent, Qt::WFlags flags) : QWidget(parent, flags) , htmlayout::event_handler(-1) { setWindowFlags(Qt::Window); setUpdatesEnabled(false); BOOL bHandled; HTMLayoutProcND(winId(),WM_CREATE,0,0, &bHandled); HTMLayoutSetCallback(winId(),&HTMLayoutNotifyHandler,this); // attach handler of htmlayout events htmlayout::attach_event_handler(winId(),this); // attach handler of DOM events BOOL bOk=::HTMLayoutLoadFile(winId(), L"d:\\PTShell\\release\\Layout\\temp.html"); //BOOL bOk=::HTMLayoutLoadFile(winId(), L"D:\\htmlayout\\html_samples\\grid\\sortable-grid.htm"); } Layout::~Layout() { BOOL bHandled; HTMLayoutProcND(winId(),WM_DESTROY,0,0, &bHandled); } bool Layout::winEvent( MSG * message, long * result ) { BOOL bHandled = FALSE; LRESULT lr=HTMLayoutProcND(winId(),message->message,message->wParam,message->lParam, &bHandled); if (bHandled) return lr; QRect rect=contentsRect(); QPoint pos=mapFromGlobal(QPoint(message->pt.x,message->pt.y)); if (rect.contains(pos) && (message->message >= WM_MOUSEFIRST) && (message->message <= WM_MOUSELAST)) return true; return QWidget::winEvent(message,result); } LRESULT Layout::OnAttachBehavior(LPNMHL_ATTACH_BEHAVIOR lpab ) { // attach custom behaviors htmlayout::event_handler *pb = htmlayout::behavior::find(lpab->behaviorName, lpab->element); if(pb) { lpab->elementTag = pb; lpab->elementProc = htmlayout::behavior::element_proc; lpab->elementEvents = pb->subscribed_to; } else Q_ASSERT(FALSE); // this project includes two behavior implementationsL // behavior_hyperlink.cpp // behavior_command.cpp // to connect them into the chain of available // behaviors - just include them into the project. return 0; } static LRESULT CALLBACK HTMLayoutNotifyHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID vParam) { // all HTMLayout notification are comming here. NMHDR* phdr = (NMHDR*)lParam; Layout* pView = static_cast(vParam); switch(phdr->code) { case HLN_CREATE_CONTROL: return pView->OnCreateControl((LPNMHL_CREATE_CONTROL) lParam); case HLN_CONTROL_CREATED: return pView->OnControlCreated((LPNMHL_CREATE_CONTROL) lParam); case HLN_DESTROY_CONTROL: return pView->OnDestroyControl((LPNMHL_DESTROY_CONTROL) lParam); case HLN_LOAD_DATA: return pView->OnLoadData((LPNMHL_LOAD_DATA) lParam); case HLN_DATA_LOADED: return pView->OnDataLoaded((LPNMHL_DATA_LOADED)lParam); case HLN_DOCUMENT_COMPLETE: return pView->OnDocumentComplete(); case HLN_ATTACH_BEHAVIOR: return pView->OnAttachBehavior((LPNMHL_ATTACH_BEHAVIOR)lParam ); } return 0; } BOOL Layout::on_script_call(HELEMENT he, LPCSTR name, UINT argc, json::value* argv, json::value& retval) { return FALSE; }