#include "ApplicationInterface.h" #include "NavFind.h" #include "SimpleNavigator.h" #include #define check(checkButtonHWND) SendMessage(checkButtonHWND,BM_SETCHECK,BST_CHECKED,0); #define uncheck(checkButtonHWND) SendMessage(checkButtonHWND,BM_SETCHECK,BST_UNCHECKED,0); // added Nov 2007 to check mode before painting 'find' listbox - BD // this was written as a separate function in case we want to call it from elsewhere int IsPortrait() { if (GetSystemMetrics(SM_CYSCREEN) > GetSystemMetrics(SM_CXSCREEN)) return(100); return(0); } NavFind::NavFind(SimpleNavigator* navigator) : NavPage(navigator) { // register ID's so we get feedback searchID=navigator->getID(); rangeBibleID=navigator->getID(); rangeTestamentID=navigator->getID(); rangeBookID=navigator->getID(); methodMultiwordID=navigator->getID(); methodExactphraseID=navigator->getID(); goID=navigator->getID(); resultsID=navigator->getID(); // create windows ce managed controls queryEdit = CreateWindow(_T("edit"), NULL, WS_CHILD | ES_AUTOHSCROLL | ES_LEFT | WS_TABSTOP | WS_BORDER, 0,0,0,0, g_hWnd, NULL, g_hInst, NULL); search = CreateWindow(_T("button"), L"Search", WS_CHILD | BS_PUSHBUTTON, 0,0,0,0, g_hWnd, registerID(searchID), g_hInst, NULL); // Radio Buttons rangeBible = CreateWindow(_T("button"), L"Whole bible", WS_CHILD | BS_RADIOBUTTON, 0,0,0,0, g_hWnd, registerID(rangeBibleID),g_hInst, NULL); rangeTestament = CreateWindow(_T("button"), L"This testament", WS_CHILD | BS_RADIOBUTTON, 0,0,0,0, g_hWnd, registerID(rangeTestamentID),g_hInst, NULL); rangeBook = CreateWindow(_T("button"), L"This book", WS_CHILD | BS_RADIOBUTTON, 0,0,0,0, g_hWnd, registerID(rangeBookID),g_hInst, NULL); methodMultiword = CreateWindow(_T("button"), L"Multi-word", WS_CHILD | BS_RADIOBUTTON, 0,0,0,0, g_hWnd, registerID(methodMultiwordID),g_hInst, NULL); methodExactphrase = CreateWindow(_T("button"), L"Exact phrase", WS_CHILD | BS_RADIOBUTTON, 0,0,0,0, g_hWnd, registerID(methodExactphraseID),g_hInst, NULL); check(rangeBook); rangeMode=RANGEBOOK; check(methodMultiword); methodMode=METHODMULTIWORD; results = CreateWindow(_T("listbox"),NULL, WS_CHILD | WS_VSCROLL | LBS_DISABLENOSCROLL | LBS_NOTIFY | WS_BORDER | LBS_NOINTEGRALHEIGHT, 0,0,0,0, g_hWnd, registerID(resultsID), g_hInst, NULL); //bottom row of screen // the last figure in above line needs to be 100 for landscape or 173 for portrait (scrHeight) progressBar = CreateWindow(PROGRESS_CLASS, L"", WS_CHILD | WS_BORDER | PBS_SMOOTH, 0,0,0,0, g_hWnd, NULL, g_hInst, NULL); go = CreateWindow(_T("button"), L"Go to", WS_CHILD | BS_PUSHBUTTON, 0,0,0,0, g_hWnd, registerID(goID), g_hInst, NULL); // HTML control // preview=new TextControl(80,120,160,148); // this is OK for portrait // we now change the preview size for landscape. Note, however that // preview window does not have scroll bars. Are long verses going to // become a problem? Maybe it's not that important. If it is, then add scrollbars. preview=new TextControl(0,0,0,0, true); // the last figure is the height // I haven't bothered changing the height - what is off-screen simply doesn't show. // There is no test and no error. preview->clearText(); preview->addText(L"preview"); preview->endOfText(); placeWidgets(); } NavFind::~NavFind() { delete preview; } void NavFind::show() { // set our controls to visible ShowWindow(queryEdit,SW_SHOW); ShowWindow(search,SW_SHOW); ShowWindow(rangeBible,SW_SHOW); ShowWindow(rangeTestament,SW_SHOW); ShowWindow(rangeBook,SW_SHOW); ShowWindow(methodMultiword,SW_SHOW); ShowWindow(methodExactphrase,SW_SHOW); //ShowWindow(title,SW_SHOW); ShowWindow(results,SW_SHOW); ShowWindow(progressBar,SW_SHOW); ShowWindow(go,SW_SHOW); // propagate to HTML control preview->show(); } void NavFind::hide() { // set our controls to visible ShowWindow(queryEdit,SW_HIDE); ShowWindow(search,SW_HIDE); ShowWindow(rangeBible,SW_HIDE); ShowWindow(rangeTestament,SW_HIDE); ShowWindow(rangeBook,SW_HIDE); ShowWindow(methodMultiword,SW_HIDE); ShowWindow(methodExactphrase,SW_HIDE); //ShowWindow(title,SW_HIDE); ShowWindow(results,SW_HIDE); ShowWindow(progressBar,SW_HIDE); ShowWindow(go,SW_HIDE); // propagate to HTML control preview->hide(); } void NavFind::paint() { placeWidgets(); // this method can be used to do custom painting, for an example, see NavBooks::paint() // propagate to HTML control preview->paint(); } void NavFind::placeWidgets(){ int width = GetSystemMetrics(SM_CXSCREEN); int height = GetSystemMetrics(SM_CYSCREEN); int searchBtnW = 60; int pad = 2; int btnH = 24; int margin = 2; int row0 = margin; int row1 = row0 + pad + btnH; int row2 = row1 + pad + btnH; int row3 = row2 + pad + btnH; int row4 = row3 + pad + btnH; int row5 = row4 + pad + btnH; int col0 = margin; int textW = (width - (2*margin + pad))/2; int col1 = margin + textW + pad; int gotoBtnW = 60; int queryW = width - (margin + searchBtnW + pad + margin); int listH = height - (row4 + margin + 2*MENU_HEIGHT); int listW = 80; int prevH = height - (row5 + margin); int prevW = width - (margin + listW + pad + margin); int progW = width - (margin + listW + pad + pad + gotoBtnW + margin); MoveWindow(queryEdit,col0, row0, queryW, btnH,TRUE); MoveWindow(search,col0 + queryW + pad, row0, searchBtnW, btnH,TRUE); MoveWindow(rangeBible,col0,row1,textW,btnH,TRUE); MoveWindow(rangeTestament,col0,row2,textW,btnH,TRUE); MoveWindow(rangeBook,col0,row3,textW,btnH,TRUE); MoveWindow(methodMultiword,col1,row1,textW,btnH,TRUE); MoveWindow(methodExactphrase,col1,row2,textW,btnH,TRUE); MoveWindow(results,margin,row4,listW,listH,TRUE); MoveWindow(progressBar,col0 + listW + pad,row4,progW,btnH,TRUE); MoveWindow(go,col0 + listW + pad + progW + pad,row4, gotoBtnW,btnH,TRUE); preview->moveTo(margin + listW + pad,row5,prevW,prevH); } void NavFind::buttonClicked(int id) { // is it one of our registered ID's? if (id==searchID) { searchFor(getText(queryEdit)); refreshScreen(); } else if (id==rangeBibleID) { check(rangeBible); uncheck(rangeTestament); uncheck(rangeBook); rangeMode=RANGEBIBLE; } else if (id==rangeTestamentID) { uncheck(rangeBible); check(rangeTestament); uncheck(rangeBook); rangeMode=RANGETESTAMENT; } else if (id==rangeBookID) { uncheck(rangeBible); uncheck(rangeTestament); check(rangeBook); rangeMode=RANGEBOOK; } else if (id==methodMultiwordID) { check(methodMultiword); uncheck(methodExactphrase); methodMode=METHODMULTIWORD; } else if (id==methodExactphraseID) { check(methodExactphrase); uncheck(methodMultiword); methodMode=METHODEXACTPHRASE; } else if (id==resultsID) { unsigned int pos= SendMessage (results, LB_GETCURSEL, 0, 0); if ((pos!=LB_ERR)&&(posclearText(); // next line was commented out // preview->addText(SwordIndex::verseToString(verse)); // and the line below left in preview->addText(navigator->position.verseText(verse)); preview->endOfText(); } void NavFind::navigateToVerse(Verse* verse) { navigator->position.setVerseKey(verse); navigator->chapterCache=false; navigator->setMode(MODE_TEXT); } void NavFind::clearResults() { SendMessage (results, LB_RESETCONTENT,0,0); preview->clearText(); preview->addText(L"preview"); preview->endOfText(); verses.clear(); } void NavFind::setProgress(int percent) { SendMessage(progressBar,PBM_SETPOS, percent, 0); } void NavFind::addResult(const WCString &verseStr) { Verse* verse=new Verse(verseStr.c_str()); verses.push_back(*verse); WCString verseString = SwordIndex::verseToString(verse); SendMessage (results, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)verseString.w_str()); delete verse; } void NavFind::searchFor(const WCString &query) { clearResults(); setProgress(5); navigator->position.search(query,rangeMode,methodMode,this); }