// NavRenderText.cpp: implementation of the NavRenderText class. // ////////////////////////////////////////////////////////////////////// #include "ApplicationInterface.h" #include "NavRenderText.h" #include "Navigator.h" #include #define scrollTick 1 //#define debugfile #ifdef debugfile #include FILE* file; #define addHtml(window,text) SendMessage(window, DTM_ADDTEXT, FALSE, (LPARAM)text);fwprintf(file,text); #else #define addHtml(window,text) SendMessage(window, DTM_ADDTEXT, FALSE, (LPARAM)text) #endif #define setZoom(window,zoom) SendMessage(window, DTM_ZOOMLEVEL, 0, zoom); #define clearHtml(window) SendMessage(window, DTM_CLEAR, 0, 0); #define endHtml(window) SendMessage(window, DTM_ENDOFSOURCE, 0, 0); #define controlToVerse(window,versenr) SendMessage(window, DTM_ANCHORW, FALSE, (LPARAM)(toUString(versenr).c_str())) NavRenderText::NavRenderText(Navigator* navigator) { this->navigator=navigator; currentBook=-1; verseCount=5; VERIFY(InitHTMLControl(g_hInst)); htmlControl = CreateWindowEx(WS_EX_NOACTIVATE, WC_HTML, NULL, WS_CHILD | HS_CLEARTYPE | HS_NOSCRIPTING | HS_NOIMAGES | HS_NOACTIVEX | HS_NOSOUNDS , RECT_SCREEN.left, RECT_SCREEN.top, RECT_SCREEN.right, RECT_SCREEN.bottom, g_hWnd, NULL, g_hInst, NULL); setZoom(htmlControl, 1); } NavRenderText::~NavRenderText() { } void NavRenderText::show(bool forceRefresh) { ShowWindow(htmlControl,SW_SHOW); showText(forceRefresh); } void NavRenderText::showText(bool forceRefresh) { int verse=navigator->position.getVerse(); if ((currentBook!=navigator->position.getBook()) ||(currentChapter!=navigator->position.getChap()) || forceRefresh) { clearHtml(htmlControl); ShowWindow(htmlControl,SW_HIDE); load(); ShowWindow(htmlControl,SW_SHOW); if (verse!=1) controlToVerse(htmlControl,verse); } else controlToVerse(htmlControl,verse); } void NavRenderText::load() { #ifdef debugfile file=_fopen("\\chapter.html","w+"); #endif navigator->position.setMark(); navigator->position.setVerse(1); currentBook=navigator->position.getBook(); currentChapter=navigator->position.getChap(); #ifdef debugfile addHtml(htmlControl,""); #endif addHtml(htmlControl,"c"); String* s=new String(); String* heading=new String();//If not a pointer, warnings will occur while (true) { __try { *s=navigator->position.verseText(); if (s->length()>0) { *heading=getVerseHeader(); addHtml(htmlControl,((*heading)+(*s)).c_str()); } } __except(EXCEPTION_EXECUTE_HANDLER) { addHtml(htmlControl,"Not enough memory available"); break; } if (navigator->position.getVerse()==navigator->position.verseCount()) break; else navigator->position.next(); } delete s;delete heading; navigator->position.jumpBack(); addHtml(htmlControl,""); endHtml(htmlControl); #ifdef debugfile fclose(file); #endif } void NavRenderText::hide() { ShowWindow(htmlControl,SW_HIDE); } void NavRenderText::paint() { } String NavRenderText::getVerseHeader() { String result="\nposition.getVerse()); result+="\">"; if (navigator->position.getVerse()==1) { result+=toCString(navigator->position.getChap()); result+=":"; } result+=toCString(navigator->position.getVerse()); result+=" "; return result; } void NavRenderText::keyDown(WPARAM id, LPARAM lparam) { switch (id) { case VK_UP: navigator->position--; break; case VK_DOWN: navigator->position++; break; case VK_LEFT: navigator->position.setVerse(1); navigator->position--; break; case VK_RIGHT: navigator->position.setVerse(navigator->position.verseCount()); navigator->position++; break; } showText(); navigator->updateTitle(); }