#include "ApplicationInterface.h" #include "TextControl.h" #include //#define NOHTML #ifndef NOHTML // The sophisticated graphical representation, using an HTML component #include //#define debugfile #ifdef debugfile #include FILE* file; #define addHtml(window,text) SendMessage(window, DTM_ADDTEXTW, FALSE, (LPARAM)text);fwprintf(file,text); #else #define addHtml(window,text) SendMessage(window, DTM_ADDTEXTW, 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())) TextControl::TextControl(int x, int y, int width, int height, bool preview){ this->preview = preview; primed = false; if(width < height) portrait = true; VERIFY(InitHTMLControl(g_hInst)); htmlPrimed = CreateWindowEx(WS_EX_NOACTIVATE, WC_HTML, NULL, WS_CHILD | HS_CLEARTYPE | HS_NOSCRIPTING | HS_NOIMAGES | HS_NOACTIVEX | HS_NOSOUNDS , x, y, width, height, g_hWnd, NULL, g_hInst, NULL); htmlFull = CreateWindowEx(WS_EX_NOACTIVATE, WC_HTML, NULL, WS_CHILD | HS_CLEARTYPE | HS_NOSCRIPTING | HS_NOIMAGES | HS_NOACTIVEX | HS_NOSOUNDS , x, y, width, height, g_hWnd, NULL, g_hInst, NULL); setZoom(htmlPrimed, 1); setZoom(htmlFull, 1); i = 0; ShowWindow(htmlFull,SW_HIDE); } TextControl::~TextControl(){ } void TextControl::show() { if(preview) ShowWindow(htmlPrimed,SW_SHOW); else if(primed){ ShowWindow(htmlFull,SW_SHOW); ShowWindow(htmlPrimed,SW_HIDE); }else{ ShowWindow(htmlPrimed,SW_SHOW); ShowWindow(htmlFull,SW_HIDE); } } void TextControl::focus() { if(primed) SetFocus(htmlFull); else SetFocus(htmlPrimed); } void TextControl::hide() { ShowWindow(htmlPrimed,SW_HIDE); ShowWindow(htmlFull,SW_HIDE); } void TextControl::paint() { if(preview) return; // Detect if we switched from portrait to landscape. If so lets resize the window appropiately. int width = GetSystemMetrics(SM_CXSCREEN); int height = GetSystemMetrics(SM_CYSCREEN); if(width < height && !portrait){ portrait = true; MoveWindow(htmlPrimed,0,0,width,height - 2*MENU_HEIGHT, TRUE); MoveWindow(htmlFull,0,0,width,height - 2*MENU_HEIGHT, TRUE); }else if(width > height && portrait){ portrait = false; MoveWindow(htmlPrimed,0,0,width,height - 2*MENU_HEIGHT, TRUE); MoveWindow(htmlFull,0,0,width,height - 2*MENU_HEIGHT, TRUE); } } void TextControl::moveTo(int x, int y, int width, int height){ MoveWindow(htmlPrimed, x, y, width, height, TRUE); MoveWindow(htmlFull, x, y, width, height, TRUE); } void TextControl::clearText() { clearHtml(htmlPrimed); clearHtml(htmlFull); primed = false; i = 0; buffer.clear(); } void TextControl::addText(const WCString &text) { buffer+=text; if(!preview && !primed && buffer.length() > 1500){ clearHtml(htmlPrimed); addHtml(htmlPrimed,buffer.w_str()); addHtml(htmlPrimed, L""); endHtml(htmlPrimed); ShowWindow(htmlPrimed,SW_SHOW); ShowWindow(htmlFull,SW_HIDE); UpdateWindow(g_hWnd); primed = true; } } void TextControl::endOfText() { if(preview){ addHtml(htmlPrimed,buffer.w_str()); endHtml(htmlPrimed); }else{ addHtml(htmlFull,buffer.w_str()); endHtml(htmlFull); ShowWindow(htmlPrimed,SW_HIDE); ShowWindow(htmlFull,SW_SHOW); // In some cases this is still false due to very short chapters primed = true; } #ifdef LOG_TEXT_TO_FILE FILE *fp = fopen("\\Storage Card\\Program Files\\sword\\text.txt", "w"); fwrite(buffer.c_str(), buffer.length(), 2, fp); fclose(fp); #endif } #else //ifndef NOHTML // A simpeler graphical representation not using the HTML component TextControl::TextControl(int x, int y, int width, int height){ area.left=x; area.top=y; area.right=x+width; area.bottom=y+height; } TextControl::~TextControl(){ } void TextControl::show() { } void TextControl::hide() { } void TextControl::paint() { RECT textArea=area; textArea.top+=drawVerseText(&textArea,buffer); clearRect(&textArea); } void TextControl::clearText() { buffer=L""; } void TextControl::addText(UString text) { buffer+=noMarkup(text); } void TextControl::endOfText() { refreshScreen(); } #endif