[Amis-vcs] SF.net SVN: amis: [2152] branches/amis3
Brought to you by:
julienq,
marisademeglio
From: <mar...@us...> - 2007-09-17 07:21:45
|
Revision: 2152 http://amis.svn.sourceforge.net/amis/?rev=2152&view=rev Author: marisademeglio Date: 2007-09-17 00:21:46 -0700 (Mon, 17 Sep 2007) Log Message: ----------- New mostly untested, un-hooked-up code to do contrast and font changes entirely with CSS. Did a bit of code cleanup here and there to improve stylistic consistency. Modified Paths: -------------- branches/amis3/AmisGuiMFC2/include/gui/AmisGuiMFC2.h branches/amis3/AmisGuiMFC2/include/gui/HtmlView.h branches/amis3/AmisGuiMFC2/include/gui/TextRenderBrain.h branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp branches/amis3/AmisGuiMFC2/src/gui/HtmlView.cpp branches/amis3/AmisGuiMFC2/src/gui/TextRenderBrain.cpp Added Paths: ----------- branches/amis3/bin/settings/amis-contrast.css branches/amis3/bin/settings/amis-default.css branches/amis3/bin/settings/font1.css branches/amis3/bin/settings/font2.css branches/amis3/bin/settings/font3.css branches/amis3/bin/settings/font4.css Modified: branches/amis3/AmisGuiMFC2/include/gui/AmisGuiMFC2.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/AmisGuiMFC2.h 2007-09-15 21:03:11 UTC (rev 2151) +++ branches/amis3/AmisGuiMFC2/include/gui/AmisGuiMFC2.h 2007-09-17 07:21:46 UTC (rev 2152) @@ -77,6 +77,9 @@ afx_msg void OnAddBookmark(); afx_msg void OnSelectBookmark(UINT); afx_msg void OnGoToPage(); + afx_msg void OnIncreaseFontSize(); + afx_msg void OnResetFontSize(); + afx_msg void OnToggleContrast(); protected: HMENU m_hMDIMenu; HACCEL m_hMDIAccel; Modified: branches/amis3/AmisGuiMFC2/include/gui/HtmlView.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/HtmlView.h 2007-09-15 21:03:11 UTC (rev 2151) +++ branches/amis3/AmisGuiMFC2/include/gui/HtmlView.h 2007-09-17 07:21:46 UTC (rev 2152) @@ -19,13 +19,9 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#if !defined(AFX_AMISHTMLVIEW_H__8577ADA1_DCD3_499C_AB49_312286B915F4__INCLUDED_) -#define AFX_AMISHTMLVIEW_H__8577ADA1_DCD3_499C_AB49_312286B915F4__INCLUDED_ +#ifndef HTMLVIEW_H +#define HTMLVIEW_H -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - #include <afxhtml.h> #include "HtmlDoc.h" #include "ambulant/gui/dx/html_bridge.h" @@ -47,64 +43,45 @@ { class CAmisHtmlView : public CHtmlView { -protected: // create from serialization only - +protected: CAmisHtmlView(); - DECLARE_DYNCREATE(CAmisHtmlView) public: - CAmisHtmlView(const RECT& rect, CWnd* parent); + CAmisHtmlView(const RECT&, CWnd*); + virtual ~CAmisHtmlView(); -// Attributes -public: CAmisHtmlDoc* GetDocument(); + //returns a pointer to the stylesheet + IHTMLStyleSheet* applyStylesheet(ambulant::net::url*); + void removeStylesheet(IHTMLStyleSheet*); -// Operations -public: - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CAmisHtmlView) - public: - virtual void OnDraw(CDC* pDC); // overridden to draw this view - virtual BOOL PreCreateWindow(CREATESTRUCT& cs); + virtual void OnDraw(CDC*); // overridden to draw this view + virtual BOOL PreCreateWindow(CREATESTRUCT&); virtual void OnInitialUpdate(); - virtual void OnDocumentComplete(LPCTSTR lpszURL); - virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); - virtual BOOL PreTranslateMessage(MSG* pMsg); - virtual void OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel); - protected: - virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView); - virtual HRESULT OnFilterDataObject(LPDATAOBJECT pDataObject, LPDATAOBJECT* ppDataObject); - virtual HRESULT OnShowContextMenu(DWORD dwID, LPPOINT ppt,LPUNKNOWN pcmdtReserved, LPDISPATCH pdispReserved); + virtual void OnDocumentComplete(LPCTSTR); + virtual BOOL Create(LPCTSTR, LPCTSTR, DWORD, const RECT&, CWnd*, UINT, CCreateContext* pContext = NULL); + virtual BOOL PreTranslateMessage(MSG*); + virtual void OnBeforeNavigate2(LPCTSTR, DWORD, LPCTSTR, CByteArray&, LPCTSTR, BOOL*); + virtual void OnNavigateComplete2(LPCTSTR); + virtual void CAmisHtmlView::OnNavigateError(LPCTSTR, LPCTSTR, DWORD, BOOL*); +protected: + virtual void OnActivateView(BOOL, CView*, CView*); + virtual HRESULT OnFilterDataObject(LPDATAOBJECT, LPDATAOBJECT*); + virtual HRESULT OnShowContextMenu(DWORD, LPPOINT, LPUNKNOWN, LPDISPATCH); virtual void OnEditCopy(); - //}}AFX_VIRTUAL + afx_msg int OnCreate(LPCREATESTRUCT); + DECLARE_MESSAGE_MAP() -// Implementation -public: - virtual ~CAmisHtmlView(); #ifdef _DEBUG virtual void AssertValid() const; - virtual void Dump(CDumpContext& dc) const; + virtual void Dump(CDumpContext&) const; #endif -// Generated message map functions -protected: - //{{AFX_MSG(CAmisHtmlView) - afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); - //}}AFX_MSG - - DECLARE_MESSAGE_MAP() + public: - virtual void OnNavigateComplete2(LPCTSTR strURL); - virtual void CAmisHtmlView::OnNavigateError( - LPCTSTR lpszURL, - LPCTSTR lpszFrame, - DWORD dwError, - BOOL *pbCancel - ); + //from: http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q241750 //new code // Operations @@ -165,9 +142,4 @@ } } } -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_AMISHTMLVIEW_H__8577ADA1_DCD3_499C_AB49_312286B915F4__INCLUDED_) +#endif Modified: branches/amis3/AmisGuiMFC2/include/gui/TextRenderBrain.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/TextRenderBrain.h 2007-09-15 21:03:11 UTC (rev 2151) +++ branches/amis3/AmisGuiMFC2/include/gui/TextRenderBrain.h 2007-09-17 07:21:46 UTC (rev 2152) @@ -51,15 +51,11 @@ void increaseFontSize(); void toggleContrast(); - void loadBlankDocument(); - void highlightUriTarget(amis::TextNode*); void highlightUriTarget(std::string url); void redoPageColors(bool bDisableContrast=false); - wstring getCurrentText(); - void webDocumentComplete(); @@ -69,26 +65,28 @@ void highlightElementAtId(string); void pageContrastOn(); void pageContrastOff(); - void setPageContrast(string, string); void redoHighlightColors(); bool isElementInView(IHTMLElement*); IHTMLElement* GetElementFromId(string id, const GUID *iid); IHTMLDocument2* GetDoc(); -private: int mFontSize; - bool mb_flagWebDocWait; - bool mb_flagContrast; + bool mbWaitForDocumentLoad; + bool mbContrastOn; ambulant::net::url mCurrentUrl; string mTextElmId; wstring mCurrentElmText; - + vector<ambulant::net::url> mFontSizeCssFiles; IHTMLElement* pLastElm; + VARIANT mUnhighlightedBG; + VARIANT mUnhighlightedFG; + IHTMLStyleSheet* mpFontCss; + IHTMLStyleSheet* mpContrastCss; + IHTMLStyleSheet* mpDefaultCss; + ambulant::net::url mContrastCssUri; + ambulant::net::url mDefaultCssUri; - VARIANT mLastBG; - VARIANT mLastFG; - private: static TextRenderBrain* pinstance; Modified: branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp 2007-09-15 21:03:11 UTC (rev 2151) +++ branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp 2007-09-17 07:21:46 UTC (rev 2152) @@ -74,6 +74,7 @@ ON_COMMAND(ID_MENU_BMK_ADD, OnAddBookmark) ON_COMMAND_RANGE(BOOKMARKS_BASE_ID, BOOKMARKS_BASE_ID + MAX_ANYTHING, OnSelectBookmark) ON_COMMAND(ID_MENU_NAV_GOTOPAGE, OnGoToPage) + END_MESSAGE_MAP() Modified: branches/amis3/AmisGuiMFC2/src/gui/HtmlView.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/HtmlView.cpp 2007-09-15 21:03:11 UTC (rev 2151) +++ branches/amis3/AmisGuiMFC2/src/gui/HtmlView.cpp 2007-09-17 07:21:46 UTC (rev 2152) @@ -528,12 +528,10 @@ LPCTSTR lpszURL, LPCTSTR lpszFrame, DWORD dwError, - BOOL *pbCancel -) + BOOL *pbCancel) { } -//new code CString CAmisHtmlView::GetFullName() const { ASSERT(m_pBrowserApp != NULL); @@ -621,13 +619,56 @@ strResourceURL.Format(_T("res://%s/%s"), lpszModule, lpszResource); Navigate(strResourceURL, 0, 0, 0); } - else - bRetVal = FALSE; + else + bRetVal = FALSE; delete [] lpszModule; return bRetVal; } +IHTMLStyleSheet* CAmisHtmlView::applyStylesheet(ambulant::net::url* stylesheet) +{ + USES_CONVERSION; + + //copied this pDoc-getting code from another function in this file + HRESULT res; + // Check that we are indeed in threading mode +#ifdef _DEBUG + assert(CoInitialize(NULL) == S_FALSE); +#endif + if (stylesheet == NULL) return NULL; + + // First we need to get a pointer to the DOM + IDispatch *pDisp = GetHtmlDocument(); + if (pDisp == NULL) return NULL; + IHTMLDocument2 *pDoc; + res = pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc); + if (!SUCCEEDED(res)) return NULL; + + BSTR css_path_bstr; + CString css_path_cstr = A2T(stylesheet->get_url().c_str()); + css_path_bstr = css_path_cstr.AllocSysString(); + + IHTMLStyleSheet* pStyleSheet; + //i'm really not sure of the best value for the 2nd parameter + //i tried 0 and 1, and neither makes a difference in how the + //stylesheet doesn't override the default styling (i would like it to override this) + res = pDoc->createStyleSheet(css_path_bstr, 0, &pStyleSheet); + SysFreeString(css_path_bstr); + + return pStyleSheet; +} + +void CAmisHtmlView::removeStylesheet(IHTMLStyleSheet* pStyleSheet) +{ + if (!pStyleSheet) return; + pStyleSheet->put_disabled(VARIANT_TRUE); + pStyleSheet->Release(); + pStyleSheet = NULL; +} + + + BOOL CAmisHtmlView::LoadFromResource(UINT nRes) { HINSTANCE hInstance = AfxGetResourceHandle(); @@ -648,9 +689,7 @@ delete [] lpszModule; return bRetVal; } -//end new code -//#ifdef AMIS_WITH_AMBULANT CAmisHtmlView *html_browser_imp::s_browser = NULL; html_browser_imp::html_browser_imp(int left, int top, int width, int height) @@ -662,20 +701,23 @@ rect.bottom = top + height; - if ( ! s_browser) { + if ( ! s_browser) + { // No browser yet. Create one with the right size and position. HtmlView* browser = new HtmlView(rect, topView); assert (browser != NULL); s_browser = browser; - } else { + } else + { // The browser was created earlier. Move and resize it, if needed. s_browser->MoveWindow(&rect, 1); } //AM_DBG lib::logger::get_logger()->debug("html_browser_imp::html_browser_imp(0x%x): LTWH=(%d,%d,%d,%d) m_browser=0x%x", this, left, top, width, height, m_browser); } -html_browser_imp::~html_browser_imp() { +html_browser_imp::~html_browser_imp() +{ //AM_DBG lib::logger::get_logger()->debug("html_browser_imp::~html_browser_imp(0x%x)", this); #if 0 ShowWindow(s_browser->m_hWnd, SW_HIDE); @@ -687,8 +729,8 @@ //KB s_browser = NULL; } -void -html_browser_imp::goto_url(std::string urlstr, ambulant::net::datasource_factory *df) { +void html_browser_imp::goto_url(std::string urlstr, ambulant::net::datasource_factory *df) +{ #ifdef HTML_LOAD_MANUALLY // First get the URL for the document (strip the fragment id) ambulant::net::url url = ambulant::net::url::from_url(urlstr); @@ -697,11 +739,13 @@ // Now check whether we've already loaded this document. If we have not // loaded it yet PrepareNavigateString will also remember the URL for - if (MainWndParts::Instance()->mpHtmlView->PrepareNavigateString(lpUrl)) { + if (MainWndParts::Instance()->mpHtmlView->PrepareNavigateString(lpUrl)) + { // We haven't got this document yet. Load it, and send the data to the widget. char *data = NULL; size_t datasize = 0; - if (!ambulant::net::read_data_from_url(url, df, &data, &datasize)) { + if (!ambulant::net::read_data_from_url(url, df, &data, &datasize)) + { MainWndParts::Instance()->mpHtmlView->PrepareNavigateString("about:blank"); return; } @@ -710,7 +754,8 @@ int titlepos = datastr.find("<title>"); if (titlepos == std::string::npos) titlepos = datastr.find("<TITLE>"); - if (titlepos != std::string::npos) { + if (titlepos != std::string::npos) + { std::string basetag = "<base href=\""; basetag += docurl; basetag += "\">"; @@ -728,8 +773,8 @@ MainWndParts::Instance()->mpHtmlView->PostMessage(WM_MY_HIGHLIGHTURITARGET, 0, (LPARAM)strcopy); } -void -html_browser_imp::hide() { +void html_browser_imp::hide() +{ // AM_DBG lib::logger::get_logger()->debug("html_browser_imp::hide(0x%x)", this); #if 0 // JACK hack was to comment this line out: it causes a deadlock between the main @@ -742,8 +787,8 @@ } -void -html_browser_imp::show() { +void html_browser_imp::show() +{ // AM_DBG lib::logger::get_logger()->debug("html_browser_imp::show(0x%x)", this); #if 0 ShowWindow(s_browser->m_hWnd, SW_SHOW); @@ -752,16 +797,15 @@ #endif } -void -html_browser_imp::redraw() { +void html_browser_imp::redraw() +{ // AM_DBG lib::logger::get_logger()->debug("html_browser_imp::redraw(0x%x)", this); ShowWindow(s_browser->m_hWnd, SW_SHOWNA); } -bool -html_browser_imp::uses_screen_reader() +bool html_browser_imp::uses_screen_reader() { return false; //return !MainWndParts::Instance()->mpMmView->expectingAudio(); } -//#endif + Modified: branches/amis3/AmisGuiMFC2/src/gui/TextRenderBrain.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/TextRenderBrain.cpp 2007-09-15 21:03:11 UTC (rev 2151) +++ branches/amis3/AmisGuiMFC2/src/gui/TextRenderBrain.cpp 2007-09-17 07:21:46 UTC (rev 2152) @@ -24,6 +24,9 @@ #include "Preferences.h" #include "gui/TextRenderBrain.h" #include "gui/MainWndParts.h" +#include "util/FilePathTools.h" +#include "gui/AmisGuiMFC2.h" + #include <algorithm> #include <fstream> @@ -51,14 +54,30 @@ TextRenderBrain::TextRenderBrain() { mFontSize = 0; - mb_flagWebDocWait = false; - mb_flagContrast = false; + mbWaitForDocumentLoad = false; + mbContrastOn = false; pLastElm = NULL; - VariantInit(&mLastFG); - VariantInit(&mLastBG); + VariantInit(&mUnhighlightedFG); + VariantInit(&mUnhighlightedBG); mCurrentUrl = ambulant::net::url(); + + //TODO: replace with preferences CSS file list + string app_path = theApp.getAppPath(); + app_path += "/"; + + mFontSizeCssFiles.push_back(ambulant::net::url::from_filename(amis::util::FilePathTools::goRelativePath(app_path, "../settings/font1.css"))); + mFontSizeCssFiles.push_back(ambulant::net::url::from_filename(amis::util::FilePathTools::goRelativePath(app_path, "../settings/font2.css"))); + mFontSizeCssFiles.push_back(ambulant::net::url::from_filename(amis::util::FilePathTools::goRelativePath(app_path, "../settings/font3.css"))); + mFontSizeCssFiles.push_back(ambulant::net::url::from_filename(amis::util::FilePathTools::goRelativePath(app_path, "../settings/font4.css"))); + + mContrastCssUri = ambulant::net::url::from_filename(amis::util::FilePathTools::goRelativePath(app_path, "../settings/amis-contrast.css")); + mDefaultCssUri = ambulant::net::url::from_filename(amis::util::FilePathTools::goRelativePath(app_path, "../settings/amis-default.css")); + + mpFontCss = NULL; + mpContrastCss = NULL; + mpDefaultCss = NULL; } TextRenderBrain::~TextRenderBrain() @@ -70,11 +89,11 @@ highlightUriTarget(pText->getSrc()); } +//TODO: make sure this path comparison works for Japanese too void TextRenderBrain::highlightUriTarget(std::string urlstr) { USES_CONVERSION; ambulant::net::url url = ambulant::net::url::from_url(urlstr); - string text_elm_id = url.get_ref(); //make sure our document still exists; otherwise force a reload by @@ -85,8 +104,7 @@ bool sameDoc = url.same_document(mCurrentUrl); // If it's identical ignore it (the previous call may still be waiting // for the webDocumentComplete callback) - if (sameDoc && url.get_ref() == mCurrentUrl.get_ref()) - return; + if (sameDoc && url.get_ref() == mCurrentUrl.get_ref()) return; // If it's a different document: load it. if (!sameDoc) @@ -97,7 +115,7 @@ CString load_url(url.get_url().c_str()); mCurrentUrl = url; - mb_flagWebDocWait = true; + mbWaitForDocumentLoad = true; MainWndParts::Instance()->mpHtmlView->Navigate2(load_url, NULL, NULL); //now wait for webDocumentComplete @@ -114,41 +132,27 @@ // <audio src="clip1.wav"/> // <audio src="clip2.wav"/> //</seq></par> - if (text_elm_id == mTextElmId) - { -// AmisBrain::Instance()->textRenderDone(); - return; - } + if (text_elm_id == mTextElmId) return; //save the current ID mTextElmId = text_elm_id; - highlightElementAtId(mTextElmId); } - } void TextRenderBrain::webDocumentComplete() { - if (mb_flagWebDocWait == true) + if (mbWaitForDocumentLoad) { + mpDefaultCss = MainWndParts::Instance()->mpHtmlView->applyStylesheet(&mDefaultCssUri); MainWndParts::Instance()->mpHtmlView->RedrawWindow(); + mbWaitForDocumentLoad = false; - mb_flagWebDocWait = false; - //refresh font size and contrast settings for the newly loaded page + if (mFontSize > 0) setFontSize(mFontSize); + if (mbContrastOn) pageContrastOn(); - if (mFontSize > 0) - { - setFontSize(mFontSize); - } - - if (mb_flagContrast == true) - { - pageContrastOn(); - } - highlightElementAtId(mCurrentUrl.get_ref()); } } @@ -157,12 +161,10 @@ { USES_CONVERSION; - if (pElm == NULL) - return; + if (!pElm) return; BSTR tag_name; pElm->get_tagName(&tag_name); - string str_tag_name = OLE2A(tag_name); //convert the string to lower case before doing a comparison @@ -183,7 +185,6 @@ CString temp_cstr(OLE2CW(attr_val.bstrVal)); LPCTSTR tmp; tmp = (LPCTSTR)temp_cstr; - mCurrentElmText.assign ((LPCTSTR)temp_cstr); } else @@ -192,28 +193,20 @@ BSTR inner_text; pElm->get_innerText(&inner_text); - CString temp_cstr(OLE2CW(inner_text)); LPCTSTR tmp; tmp = (LPCTSTR)temp_cstr; - mCurrentElmText.assign ((LPCTSTR)temp_cstr); } - } void TextRenderBrain::highlightElementAtId(string elm_id) { USES_CONVERSION; - if (elm_id.size() == 0) - { -// AmisBrain::Instance()->textRenderDone(); - return; - } + if (elm_id.size() == 0) return; IHTMLElement* pElm = NULL; - pElm = GetElementFromId(elm_id, 0); //save last-style data since we'll be replacing it before using it @@ -225,17 +218,17 @@ copy_last_bg.vt = VT_BSTR; copy_last_fg.vt = VT_BSTR; - copy_last_bg.bstrVal = mLastBG.bstrVal; - copy_last_fg.bstrVal = mLastFG.bstrVal; + copy_last_bg.bstrVal = mUnhighlightedBG.bstrVal; + copy_last_fg.bstrVal = mUnhighlightedFG.bstrVal; - if (pElm != NULL) + if (pElm) { IHTMLStyle* pStyle = NULL; //save the current style info before changing it pElm->get_style(&pStyle); - pStyle->get_backgroundColor(&mLastBG); - pStyle->get_color(&mLastFG); + pStyle->get_backgroundColor(&mUnhighlightedBG); + pStyle->get_color(&mUnhighlightedFG); //save the element text //this is just a convenient place for this function call, since it @@ -271,14 +264,11 @@ pStyle->put_color(var_fg); //reset the last highlighted element's style - if (pLastElm != NULL) + if (pLastElm) { IHTMLStyle* pLastStyle = NULL; - pLastElm->get_style(&pLastStyle); - //set the properties - //marisa, test removing border entirely pLastStyle->put_backgroundColor(copy_last_bg); pLastStyle->put_color(copy_last_fg); } @@ -291,13 +281,8 @@ pElm->scrollIntoView(v_bool); } - pLastElm = pElm; } - -// AmisBrain::Instance()->textRenderDone(); - - } void TextRenderBrain::toggleContrast() @@ -320,82 +305,41 @@ } */ - if (mb_flagContrast == true) pageContrastOff(); + if (mbContrastOn) pageContrastOff(); else pageContrastOn(); } void TextRenderBrain::pageContrastOn() { - mb_flagContrast = true; +/* mb_flagContrast = true; string fg, bg; fg = amis::Preferences::Instance()->mpPageFG->getAsHtmlColor(); bg = amis::Preferences::Instance()->mpPageBG->getAsHtmlColor(); setPageContrast(fg, bg); - +*/ + mbContrastOn = true; + mpContrastCss = MainWndParts::Instance()->mpHtmlView->applyStylesheet(&mContrastCssUri); } void TextRenderBrain::pageContrastOff() { - mb_flagContrast = false; +/* mb_flagContrast = false; string fg, bg; fg = ""; bg = ""; setPageContrast(fg, bg); +*/ + mbContrastOn = false; + MainWndParts::Instance()->mpHtmlView->removeStylesheet(mpContrastCss); } -void TextRenderBrain::setPageContrast(string fg, string bg) -{ - //variants - VARIANT var_pagefg_color; - VARIANT var_pagebg_color; - - VariantInit(&var_pagefg_color); - VariantInit(&var_pagebg_color); - - //get the colors as chars - const char* pagefg_color = fg.c_str(); - const char* pagebg_color = bg.c_str(); - - //convert to variants - var_pagefg_color.vt = VT_BSTR; - var_pagefg_color.bstrVal = A2BSTR(pagefg_color); - - var_pagebg_color.vt = VT_BSTR; - var_pagebg_color.bstrVal = A2BSTR(pagebg_color); - - IHTMLElement* pBody = NULL; - IHTMLStyle* pStyle = NULL; - - IHTMLDocument2* doc = GetDoc(); - - if (doc != NULL) - { - //get the body document element - HRESULT hr = doc->get_body(&pBody); - - if (hr == S_OK && pBody != NULL) - { - //get the body's style - pBody->get_style(&pStyle); - - //set properties of style - pStyle->put_backgroundColor(var_pagebg_color); - pStyle->put_color(var_pagefg_color); - } - } -} - void TextRenderBrain::increaseFontSize() { //MainWndParts::Instance()->mpSidebar->m_wndDlg.increaseFontSize(); - - if (mFontSize >= 0 && mFontSize < 4) - { - setFontSize(mFontSize + 1); - } + if (mFontSize >= 0 && mFontSize < 4) setFontSize(mFontSize + 1); } void TextRenderBrain::resetFontSize() @@ -403,152 +347,79 @@ //MainWndParts::Instance()->mpSidebar->m_wndDlg.resetFontSize(); setFontSize(0); } - -//set the font size -//0 = small -//1 = medium -//2 = large -//3 = x-large -//4 = xx-large -/* -@todo -if the document default is not "small", this doesn't behave perfectly -and the reset goes to "small", not "default -*/ -void TextRenderBrain::setFontSize(int fontsz) -{ - IHTMLDocument2 *doc = NULL; - HRESULT hr; - IHTMLElement* pBody = NULL; - IHTMLStyle* pStyle = NULL; - - VARIANT new_font_size; - VariantInit(&new_font_size); - new_font_size.vt = VT_BSTR; - - - if (fontsz == 0) - { - new_font_size.bstrVal = L"small"; - } - else if(fontsz == 1) - { - new_font_size.bstrVal = L"medium"; - } - else if(fontsz == 2) - { - new_font_size.bstrVal = L"large"; - } - else if(fontsz == 3) - { - new_font_size.bstrVal = L"x-large"; - } - else if(fontsz == 4) - { - new_font_size.bstrVal = L"xx-large"; - } - else - { - fontsz = 0; - new_font_size.bstrVal = L"small"; - } - - mFontSize = fontsz; - - doc = GetDoc(); - - if (doc != NULL) - { - hr = doc->get_body(&pBody); - - if (hr == S_OK && pBody != NULL) - { - pBody->get_style(&pStyle); - pStyle->put_fontSize(new_font_size); - } - } +//set the font size +//0 = reset +//1...4 = increasingly bigger +void TextRenderBrain::setFontSize(int fontsz) +{ + if (fontsz > mFontSizeCssFiles.size() || fontsz < 1) fontsz = 0; + mFontSize = fontsz; + + //remove the old stylesheet + MainWndParts::Instance()->mpHtmlView->removeStylesheet(mpFontCss); + + if (fontsz) + MainWndParts::Instance()->mpHtmlView->applyStylesheet(&mFontSizeCssFiles[fontsz-1]); + + if (isElementInView(pLastElm) == false) + { + VARIANT v_bool; + v_bool.vt = VT_BOOL; + v_bool.boolVal = TRUE; + pLastElm->scrollIntoView(v_bool); + } } //taken from http://www.wischik.com/lu/programmer/webform.html IHTMLElement* TextRenderBrain::GetElementFromId(string id_str, const GUID *iid) { - - const char* id; + const char* id = NULL; IHTMLElement *ret=0; IHTMLElementCollection* doc_all = NULL; IHTMLDocument2 *doc = NULL; HRESULT hr; - if (id_str.size() == 0) - { - return 0; - } - + if (id_str.size() == 0) return 0; + id = id_str.c_str(); - doc = GetDoc(); - if (doc==0) - { - return 0; - } - + if (doc==0) return 0; hr = doc->get_all(&doc_all); // this is like doing document.all if (hr == S_OK) { IDispatch* disp = NULL; - VARIANT vid; VARIANT v0; - unsigned int len; wchar_t* ws = NULL; VariantInit(&v0); - len=strlen(id); vid.vt=VT_BSTR; ws = new wchar_t[len+1]; - MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED, id, -1, ws, len+1); - - // AfxMessageBox(ws); - vid.bstrVal=ws; hr = doc_all->item(vid,v0,&disp); // this is like doing document.all["messages"] - delete[] ws; if (hr == S_OK && disp != 0) { IHTMLElement* element = NULL; - if (iid == 0) - { - hr = disp->QueryInterface(IID_IHTMLElement,(void **)&element); - } - else - { - hr = disp->QueryInterface(*iid,(void**)&element); - } + if (iid == 0) hr = disp->QueryInterface(IID_IHTMLElement,(void **)&element); + else hr = disp->QueryInterface(*iid,(void**)&element); - if (hr == S_OK) - { - ret = element; // it's the caller's responsibility to release it - } - + if (hr == S_OK) ret = element; // it's the caller's responsibility to release it disp->Release(); } - doc_all->Release(); } - doc->Release(); - return ret; } @@ -556,17 +427,14 @@ IHTMLDocument2* TextRenderBrain::GetDoc() { IDispatch *dispatch = NULL; - dispatch = MainWndParts::Instance()->mpHtmlView->GetHtmlDocument(); - IHTMLDocument2 *doc = NULL; - if (dispatch != NULL) + + if (dispatch) { dispatch->QueryInterface(IID_IHTMLDocument2,(void**)&doc); dispatch->Release(); } - - return doc; } @@ -586,10 +454,7 @@ // MainWndParts::Instance()->mpSidebar->m_wndDlg.repaintContrast(); //repaint the html view contrast if it had been enabled - if (this->mb_flagContrast == true) - { - this->pageContrastOn(); - } + if (mbContrastOn) this->pageContrastOn(); } //otherwise turn the contrast off everywhere else @@ -642,11 +507,12 @@ pStyle->put_backgroundColor(var_bg); pStyle->put_color(var_fg); } - } //this function looks at the element's coordinates and the coordinates of the section of the //document which is being displayed, and decides if the element is visible or not +//however, stupid IE 7 broke it and it doesn't work anymore +//TODO fix this bool TextRenderBrain::isElementInView(IHTMLElement* pElm) { //the IHTMLELEMENT measurements @@ -656,18 +522,11 @@ long elm_left = 0; //if any measurements go wrong, return false - if (pElm->get_offsetWidth(&elm_width) != S_OK) - return false; + if (pElm->get_offsetWidth(&elm_width) != S_OK) return false; + if (pElm->get_offsetHeight(&elm_height) != S_OK) return false; + if (pElm->get_offsetTop(&elm_top) != S_OK) return false; + if (pElm->get_offsetLeft(&elm_left) != S_OK) return false; - if (pElm->get_offsetHeight(&elm_height) != S_OK) - return false; - - if (pElm->get_offsetTop(&elm_top) != S_OK) - return false; - - if (pElm->get_offsetLeft(&elm_left) != S_OK) - return false; - HRESULT hr; // get the document dispatch from browser @@ -695,17 +554,14 @@ pContainer->get_scrollTop(&scroll_pos.y); pContainer->get_scrollLeft(&scroll_pos.x); - pDisp->Release(); //get the html view's width and height long view_width = 0; long view_height = 0; - view_width = MainWndParts::Instance()->mpHtmlView->GetWidth(); view_height = MainWndParts::Instance()->mpHtmlView->GetHeight(); - int top_visible = scroll_pos.y; int bottom_visible = scroll_pos.y + view_height; int left_visible = scroll_pos.x; @@ -722,25 +578,14 @@ screen_data.Format(_T("******\nScreen \ttop = %d \tbottom = %d \tleft = %d \tright = %d \n****\n"), top_visible, bottom_visible, left_visible, right_visible); - TRACE(screen_data); - TRACE(element_data); +// TRACE(screen_data); +// TRACE(element_data); - if (elm_top < top_visible || elm_bottom > bottom_visible) - return false; + if (elm_top < top_visible || elm_bottom > bottom_visible) return false; + if (elm_left < left_visible || elm_right > right_visible) return false; - if (elm_left < left_visible || elm_right > right_visible) - return false; - //otherwise we assume it's in view return true; } -void TextRenderBrain::loadBlankDocument() -{ -#ifdef AMIS_WITH_AMBULANT - return; -#else - MainWndParts::Instance()->mpHtmlView->Navigate2(_T("about:blank"), NULL, NULL); -#endif -} Added: branches/amis3/bin/settings/amis-contrast.css =================================================================== --- branches/amis3/bin/settings/amis-contrast.css (rev 0) +++ branches/amis3/bin/settings/amis-contrast.css 2007-09-17 07:21:46 UTC (rev 2152) @@ -0,0 +1,3 @@ +/*contrast CSS sheet*/ +body{ background-color: blue; color: white;} + Added: branches/amis3/bin/settings/amis-default.css =================================================================== --- branches/amis3/bin/settings/amis-default.css (rev 0) +++ branches/amis3/bin/settings/amis-default.css 2007-09-17 07:21:46 UTC (rev 2152) @@ -0,0 +1,2 @@ +/*default CSS sheet*/ + Added: branches/amis3/bin/settings/font1.css =================================================================== --- branches/amis3/bin/settings/font1.css (rev 0) +++ branches/amis3/bin/settings/font1.css 2007-09-17 07:21:46 UTC (rev 2152) @@ -0,0 +1,9 @@ +/*whole document body*/ +body { + font-size: 150%; + line-spacing: 125% +} + +h1, h2, h3, h4, h5, h6{ + font-size: 150%; +} Added: branches/amis3/bin/settings/font2.css =================================================================== --- branches/amis3/bin/settings/font2.css (rev 0) +++ branches/amis3/bin/settings/font2.css 2007-09-17 07:21:46 UTC (rev 2152) @@ -0,0 +1,9 @@ +/*whole document body*/ +body { + font-size: 175%; + line-spacing: 150% +} + +h1, h2, h3, h4, h5, h6{ + font-size: 175%; +} Added: branches/amis3/bin/settings/font3.css =================================================================== --- branches/amis3/bin/settings/font3.css (rev 0) +++ branches/amis3/bin/settings/font3.css 2007-09-17 07:21:46 UTC (rev 2152) @@ -0,0 +1,9 @@ +/*whole document body*/ +body { + font-size: 200%; + line-spacing: 175% +} + +h1, h2, h3, h4, h5, h6{ + font-size: 200%; +} Added: branches/amis3/bin/settings/font4.css =================================================================== --- branches/amis3/bin/settings/font4.css (rev 0) +++ branches/amis3/bin/settings/font4.css 2007-09-17 07:21:46 UTC (rev 2152) @@ -0,0 +1,9 @@ +/*whole document body*/ +body { + font-size: 225%; + line-spacing: 175% +} + +h1, h2, h3, h4, h5, h6{ + font-size: 225%; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |