RenderedBitmap *ChmEngineImpl::CreateThumbnail(SizeI size) { RenderedBitmap *bmp = NULL; // We render twice the size of thumbnail and scale it down RectI area(0, 0, size.dx * 2, size.dy * 2); // reusing WC_STATIC. I don't think exact class matters (WndProc // will be taken over by HtmlWindow anyway) but it can't be NULL. int winDx = area.dx + GetSystemMetrics(SM_CXVSCROLL); int winDy = area.dy + GetSystemMetrics(SM_CYHSCROLL); HWND hwnd = CreateWindow(WC_STATIC, L"BrowserCapture", WS_POPUP, 0, 0, winDx, winDy, NULL, NULL, NULL, NULL); if (!hwnd) return NULL; #if 0 // when debugging set to 1 to see the window ShowWindow(hwnd, SW_SHOW); #endif SetParentHwnd(hwnd); DisplayPage(1); if (!htmlWindow || !htmlWindow->WaitUntilLoaded(5 * 1000)) goto Exit; HBITMAP hbmp = htmlWindow->TakeScreenshot(area, size); if (!hbmp) goto Exit; bmp = new RenderedBitmap(hbmp, size); Exit: DestroyWindow(hwnd); return bmp; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); HtmlWindow window; window.show(); return app.exec(); }
// Returns a localized string representing the value for the object // or child. wxAccStatus HtmlWindowAx::GetValue(int WXUNUSED(childId), wxString* strValue) { HtmlWindow *hw = wxDynamicCast( GetWindow(), HtmlWindow ); *strValue = hw->ToText(); return wxACC_OK; }
// Returns the rectangle for this object (id = 0) or a child element (id > 0). // rect is in screen coordinates. wxAccStatus HtmlWindowAx::GetLocation( wxRect& rect, int WXUNUSED(elementId) ) { HtmlWindow *hw = wxDynamicCast( GetWindow(), HtmlWindow ); rect = hw->GetRect(); rect.SetPosition( hw->GetParent()->ClientToScreen( rect.GetPosition() ) ); return wxACC_OK; }
void ChmEngineImpl::Navigate(int dir) { if (!htmlWindow) return; if (dir < 0) { for (; dir < 0 && CanNavigate(dir); dir++) htmlWindow->GoBack(); } else { for (; dir > 0 && CanNavigate(dir); dir--) htmlWindow->GoForward(); } }
// Gets the name of the specified object. wxAccStatus HtmlWindowAx::GetName(int WXUNUSED(childId), wxString* name) { HtmlWindow *hw = wxDynamicCast( GetWindow(), HtmlWindow ); *name = hw->GetName(); if( name->IsEmpty() ) { *name = hw->GetLabel(); } return wxACC_OK; }
void ChmEngineImpl::DisplayPage(const WCHAR *pageUrl) { if (IsExternalUrl(pageUrl)) { // open external links in an external browser // (same as for PDF, XPS, etc. documents) if (navCb) navCb->LaunchBrowser(pageUrl); return; } int pageNo = pages.Find(ScopedMem<WCHAR>(str::ToPlainUrl(pageUrl))) + 1; if (pageNo) currentPageNo = pageNo; // This is a hack that seems to be needed for some chm files where // url starts with "..\" even though it's not accepted by ie as // a correct its: url. There's a possibility it breaks some other // chm files (I don't know such cases, though). // A more robust solution would try to match with the actual // names of files inside chm package. if (str::StartsWith(pageUrl, L"..\\")) pageUrl += 3; if (str::StartsWith(pageUrl, L"/")) pageUrl++; assert(htmlWindow); if (htmlWindow) htmlWindow->NavigateToDataUrl(pageUrl); }
void CreateThumbnail(HtmlWindow *hw) { this->hw = hw; homeUrl.Set(str::conv::FromAnsi(doc->GetHomePath())); if (*homeUrl == '/') homeUrl.Set(str::Dup(homeUrl + 1)); hw->NavigateToDataUrl(homeUrl); }
virtual void OnDocumentComplete(const WCHAR *url) { if (url && *url == '/') url++; if (str::Eq(url, homeUrl)) { RectI area(0, 0, size.dx * 2, size.dy * 2); HBITMAP hbmp = hw->TakeScreenshot(area, size); if (hbmp) { RenderedBitmap *bmp = new RenderedBitmap(hbmp, size); tnCb->SaveThumbnail(bmp); tnCb = NULL; } uitask::Post(this); } }
virtual void OnDocumentComplete(const WCHAR *url) { if (url && *url == '/') url++; if (str::Eq(url, homeUrl)) { RectI area(0, 0, size.dx * 2, size.dy * 2); HBITMAP hbmp = hw->TakeScreenshot(area, size); if (hbmp) { RenderedBitmap *bmp = new RenderedBitmap(hbmp, size); saveThumbnail(bmp); } // TODO: why is destruction on the UI thread necessary? uitask::Post([=] { delete this; }); } }
void ShowExtraDialog() { int k=42; wxDialog Dlg(NULL, wxID_ANY, wxString(wxT("Experimental Extra Dialog"))); ShuttleGui S(&Dlg, eIsCreating); S.StartNotebook(); { S.StartNotebookPage( _("Panel 1") ); S.StartVerticalLay(1); { HtmlWindow *html = new LinkingHtmlWindow(S.GetParent(), -1, wxDefaultPosition, wxSize(600, 359), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER); html->SetFocus(); html->SetPage(wxT("<h1><font color=\"blue\">An Html Window</font></h1>Replace with whatever you like.")); S.Prop(1).AddWindow( html, wxEXPAND ); } S.EndVerticalLay(); S.EndNotebookPage(); S.StartNotebookPage( _("Diagnostics") ); S.StartVerticalLay(1); { HtmlWindow *html = new LinkingHtmlWindow(S.GetParent(), -1, wxDefaultPosition, wxSize(600, 359), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER); html->SetFocus(); html->SetPage(wxT("<h1>Diagnostics</h1>This is an html diagnostics page")); S.Prop(1).AddWindow( html, wxEXPAND ); } S.EndVerticalLay(); S.EndNotebookPage(); } S.EndNotebook(); wxButton *ok = new wxButton(S.GetParent(), wxID_OK, _("OK... Audacious!")); ok->SetDefault(); S.Prop(0).AddWindow( ok ); Dlg.Fit(); Dlg.ShowModal(); }
void ChmEngineImpl::ZoomTo(float zoomLevel) { if (htmlWindow) htmlWindow->SetZoomPercent((int)zoomLevel); }