#include "HtmlView.h" #include #include #include #include #include "wmuser.h" #include "utf8.hpp" #include "basetypes.h" #include "TabCtrl.h" extern HINSTANCE g_hInst; extern int tabHeight; extern ImgListRef skin; extern HCURSOR cursorWait; ATOM HtmlView::RegisterWindowClass() { WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = HtmlView::WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = g_hInst; wc.hIcon = NULL; wc.hCursor = 0; wc.hbrBackground = (HBRUSH)COLOR_BACKGROUND; wc.lpszMenuName = 0; wc.lpszClassName = _T("BombusHTV"); return RegisterClass(&wc); } LRESULT CALLBACK HtmlView::WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { HtmlView *p=(HtmlView *) GetWindowLong(hWnd, GWL_USERDATA); switch (message) { case WM_CREATE: { p=(HtmlView *) (((CREATESTRUCT *)lParam)->lpCreateParams); SetWindowLong(hWnd, GWL_USERDATA, (LONG) p ); RECT rc; GetClientRect (hWnd, &rc); p->htmlHWnd = CreateWindow ( DISPLAYCLASS, NULL, WS_CHILD | WS_VISIBLE | /*WS_VSCROLL |*/ WS_CLIPSIBLINGS, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hWnd, 0, //(HMENU)IDC_HTMLVIEW, g_hInst, NULL); SetFocus(p->htmlHWnd); HWND hwndHTML=p->htmlHWnd; bool fFitToPage = TRUE; PostMessage(hwndHTML, DTM_ENABLESHRINK, 0, fFitToPage); SendMessage(hwndHTML, WM_SETTEXT, 0, (LPARAM)""); SendMessage(hwndHTML, DTM_ADDTEXT, FALSE, (LPARAM)"Test

Loading...
"); SendMessage(hwndHTML, DTM_ENDOFSOURCE, 0, (LPARAM)NULL); /*SendMessage(hwndHTML, WM_SETTEXT, 0, (LPARAM)""); SendMessage(hwndHTML, DTM_ADDTEXTW, FALSE, (LPARAM)TEXT("Test")); SendMessage(hwndHTML, DTM_ADDTEXTW, FALSE, (LPARAM)TEXT("

")); SendMessage(hwndHTML, DTM_ADDTEXTW, FALSE, (LPARAM)TEXT("

Heading

Normal Text
")); SendMessage(hwndHTML, DTM_ADDTEXTW, FALSE, (LPARAM)TEXT("")); SendMessage(hwndHTML, DTM_ADDTEXTW, FALSE, (LPARAM)TEXT("")); SendMessage(hwndHTML, DTM_ENDOFSOURCE, 0, (LPARAM)NULL);*/ break; } case WM_PAINT: { PAINTSTRUCT ps; HDC hdc; hdc = BeginPaint(hWnd, &ps); RECT rc = {0, 0, p->width, p->wt->getHeight()}; SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, p->wt->getColor()); p->wt->draw(hdc, rc); skin->drawElement(hdc, icons::ICON_CLOSE, p->width-2-skin->getElementWidth(), 0); EndPaint(hWnd, &ps); break; } case WM_SIZE: { //HDWP hdwp; int height=GET_Y_LPARAM(lParam); int width=GET_X_LPARAM(lParam); p->width=width; int xHeight=tabHeight;/*p->wt->getHeight();*/ // Calculate the display rectangle, assuming the // tab control is the size of the client area. SetRect(&(p->clientRect), 0, 0, width, height ); if(IsWindow(p->htmlHWnd)) SetWindowPos(p->htmlHWnd, 0, 0, xHeight, width, height-xHeight, SWP_NOZORDER ); /*hdwp = BeginDeferWindowPos(1); DeferWindowPos(hdwp, p->listScrollHWND, HWND_TOP, width-SCROLLWIDTH, tabHeight, SCROLLWIDTH, height-tabHeight, SWP_NOZORDER ); EndDeferWindowPos(hdwp); */ break; } case WM_NOTIFY: //if (wParam!=IDC_HTMLVIEW) break; { NM_HTMLVIEW* pnm = (NM_HTMLVIEW*)lParam; switch(pnm->hdr.code) { case NM_INLINE_IMAGE: { DWORD cookie=pnm->dwCookie; HBITMAP bmp=p->getImage(pnm->szTarget, pnm->dwCookie); p->setImage(bmp, cookie); return TRUE; } // end case NM_INLINE_IMAGE: case NM_HOTSPOT: { if (pnm->szTarget!=NULL) p->onHotSpot((LPCSTR)pnm->szTarget, (LPCSTR)pnm->szData); return TRUE; } } // end switch(pnm->hdr.code) } // End case IDC_HTMLVIEW: break; case WM_LBUTTONDOWN: SetFocus(hWnd); if ((GET_Y_LPARAM(lParam))>tabHeight) break; if (GET_X_LPARAM(lParam) > p->width-2-skin->getElementWidth()) { PostMessage(GetParent(hWnd), WM_COMMAND, TabsCtrl::CLOSETAB, 0); } break; case WM_HTML_UPDATE: { p->onWmUserUpdate(); break; } case WM_DESTROY: //TODO: Destroy all child data associated eith this window //WARNING! do not place virtual member calls here - object is already destructed return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } HtmlView::HtmlView() { /*init(); - MUST NOT be called before setting up parentHWnd */ } void HtmlView::init() { BOOST_ASSERT(parentHWnd); SetCursor(cursorWait); if (htmlViewInstance==0) htmlViewInstance=LoadLibrary(L"htmlview.dll"); if (htmlViewInstance==0) throw std::exception("Unable to initialize HTML control"); if(!InitHTMLControl( g_hInst )) throw std::exception("Unable to initialize HTML control"); if (windowClass==0) windowClass=RegisterWindowClass(); if (windowClass==0) throw std::exception("Can't create window class"); thisHWnd=CreateWindow((LPCTSTR)windowClass, _T("HtmlView"), WS_CHILD | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parentHWnd, NULL, g_hInst, (LPVOID)this); SetCursor(NULL); } HtmlView::HtmlView( HWND parent, const std::string & title ) { parentHWnd=parent; init(); SetParent(thisHWnd, parent); this->title=utf8::utf8_wchar(title); wt=WndTitleRef(new WndTitle(this, 0)); } const wchar_t * HtmlView::getWindowTitle() const{ return title.c_str(); } HtmlView::~HtmlView() { SetCursor(cursorWait); DestroyWindow(htmlHWnd); SetCursor(NULL); } const ODR * HtmlView::getODR() const { return wt.get(); } void HtmlView::onWmUserUpdate() {} HBITMAP HtmlView::getImage( LPCTSTR url, DWORD cookie ) { return NULL; } StringMapRef HtmlView::splitHREFtext( LPCSTR ht ) { std::string key; std::string buf; StringMap *m=new StringMap(); char c; if (ht){ while ((c=(char)(*ht++))) { switch (c) { case '+': buf+=' '; break; case '=': key=buf; buf.clear(); break; case '&': { std::string & val=m->operator [](key); if (val.length()) val+=(char)0x0a; val+=buf; //m->operator [](key)=buf; buf.clear(); break; } case '%': { char c1=(char)(*ht++)-'0'; if (c1>9) c1+='0'-'A'+10; char c2=(char)(*ht++)-'0'; if (c2>9) c2+='0'-'A'+10; char c=c1<<4 | c2; if (c!=0x0d) buf+=c; break; } default: buf+=c; } } std::string & val=m->operator [](key); if (val.length()) val+=(char)0x0a; val+=buf; //m->operator [](key)=buf; } return StringMapRef(m); } void HtmlView::addText( const char *text ) { SendMessage(htmlHWnd, DTM_ADDTEXT, FALSE, (LPARAM) text); } void HtmlView::addText( const std::string &text ) { addText( (text.c_str()) ); } void HtmlView::addText( const wchar_t *text ) { SendMessage(htmlHWnd, DTM_ADDTEXT, FALSE, (LPARAM) (utf8::wchar_utf8(std::wstring(text))).c_str()); } void HtmlView::startHtml() { SendMessage(htmlHWnd, DTM_CLEAR, 0, 0); addText("" "" "form

"); } void HtmlView::addImg( const wchar_t *src ) { addText("
"); } void HtmlView::endForm() { addText(""); } void HtmlView::endHtml() { addText(""); SendMessage(htmlHWnd, DTM_ENDOFSOURCE, 0, (LPARAM)NULL); SetCursor(NULL); } void HtmlView::button( const std::string &label ) { addText(""); } void HtmlView::button( const char *name, const std::string &label ) { addText(""); } void HtmlView::selectList(const char *name, const std::string &label, bool multiple){ addText(label); addText(":
"); addText("
"); } void HtmlView::option( const char *name, const std::string &label, bool checked ) { addText("
"); } void HtmlView::checkBox( const char *name, const std::string &label, bool checked ) { addText(""); addText(label); addText("
"); } void HtmlView::textBox( const char *name, const std::string &label, const std::string &value ) { addText(label); addText(":

"); } void HtmlView::passBox( const char *name, const std::string &label, const std::string &value ) { addText(label); addText(":

"); } void HtmlView::url( const std::string &label, const std::string &url ) { addText(label); addText(": "); addText(url); addText("
"); } void HtmlView::textConst( const std::string &label, const std::string &value ) { addText(label); addText(": "); addText(value); addText("
"); } void HtmlView::textML( const char *name, const std::string &label, const std::string &value ) { addText(label); addText(":

"); } void HtmlView::beginForm( const char *name, const char *action ) { addText("

"); } void HtmlView::setImage( HBITMAP bmp, DWORD cookie ) { if (!bmp) { SendMessage(htmlHWnd, DTM_IMAGEFAIL, 0, cookie); return; } BITMAP bm; GetObject(bmp, sizeof(bm), &bm); INLINEIMAGEINFO imgInfo; imgInfo.dwCookie = cookie; imgInfo.iOrigHeight = bm.bmHeight; imgInfo.iOrigWidth = bm.bmWidth; imgInfo.hbm = bmp; imgInfo.bOwnBitmap = FALSE; SendMessage(htmlHWnd, DTM_SETIMAGE, 0, (LPARAM)&imgInfo); } ATOM HtmlView::windowClass=0; HINSTANCE HtmlView::htmlViewInstance=0;