#include "ApplicationInterface.h" #include "SimpleNavigator.h" #include "NavChap.h" #include "NavVerse.h" #include "NavBooks.h" #include "NavRenderText.h" #include "NavFind.h" #include #include #include using namespace sword; extern SWConfig *g_swordConf; #define WIDTH 240 #define HEIGHT 294 RECT RECT_SCREEN;// = {0,0,240,294}; RECT RECT_SELECTLABEL = {4,4,120,20}; RECT RECT_POSITION = {164,4,236,20}; RECT RECT_FIELD = {6,24,240,250}; SimpleNavigator::SimpleNavigator(RECT* screen) { RECT_SCREEN=*screen; mode=-1; nextID = 1; chapterCache=false; books=pages[MODE_BOOK]=new NavBooks(this); chapters=pages[MODE_CHAP]=new NavChap(this); verses=pages[MODE_VERSE]=new NavVerse(this); text=pages[MODE_TEXT]=new NavRenderText(this); find=pages[MODE_FIND]=new NavFind(this); menus[MODE_BOOK]=MENU_BOOK; menus[MODE_CHAP]=MENU_CHAP; menus[MODE_VERSE]=MENU_VERSE; menus[MODE_TEXT]=MENU_TEXT; menus[MODE_FIND]=MENU_FIND; optStartID = 0; optEndID = 0; transStartID = 0; transEndID = 0; options = 0; opCount = 0; SWModule *mod = SwordIndex::manager->getModule((*g_swordConf)["History"].getWithDefault("LastVersion", "KJV")); if (mod) { position.setModule(SwordIndex::manager->getModule((*g_swordConf)["History"].getWithDefault("LastVersion", "KJV"))); } else setModule(transStartID); // if defaults not present, start with first module found sword::VerseKey key = sword::VerseKey((*g_swordConf)["History"].getWithDefault("LastPassage", "Gen 1:1")); position.setVerseKey(&key); } SimpleNavigator::~SimpleNavigator() { delete books; delete chapters; delete verses; delete text; delete find; if (options){ delete [] options; } saveState(); } void SimpleNavigator::saveState(){ (*g_swordConf)["History"]["LastPassage"] = position.verseToString().c_str(); (*g_swordConf)["History"]["LastVersion"] = position.getModName(); } void SimpleNavigator::refresh() { refreshScreen(); } void SimpleNavigator::setModule(const char *module){ position.setModule(SwordIndex::manager->getModule(module)); } void SimpleNavigator::setMode(int mode) { if (this->mode>=0) pages[this->mode]->hide(); this->mode=mode; selectMenu(menus, mode); pages[this->mode]->show(); updateTitle(); refresh(); } void SimpleNavigator::paint() { pages[mode]->paint(); } void SimpleNavigator::updateTitle() { WCString title = position.toString() + " - SwRd"; setTitle(title); } /* a menu-item is selected (maybe one of the translations) */ void SimpleNavigator::buttonClicked(int id) { if ((id >= transStartID) && (id <= transEndID)) { setModule(id); checkModuleMenu(id); chapterCache=false; setMode(mode); } else if ((id >= optStartID) && (id <= optEndID)) { toggleOptionMenu(id); chapterCache=false; setMode(mode); } else pages[mode]->buttonClicked(id); } bool SimpleNavigator::menuClicked(int id) { for (std::map::iterator i=menus.begin();i!=menus.end();i++) { if (i->second==id) { setMode(i->first); return true; } } return false; } void SimpleNavigator::keyDown(WPARAM id, LPARAM lparam) { pages[mode]->keyDown(id,lparam); } void SimpleNavigator::mouseDown(int x, int y) { pages[mode]->userTap(x,y); } void SimpleNavigator::setBook(int number) { position.setBook(number); chapterCache=false; } void SimpleNavigator::setChap(int number) { position.setChap(number); chapterCache=false; } void SimpleNavigator::setVerse(int number) { position.setVerse(number); } void SimpleNavigator::fillTranslationsMenu(HMENU menuTranslations) { transStartID = nextID; this->menuTranslations=menuTranslations; if (menuTranslations) { for (ModuleMap::iterator i=position.firstModule();i!=position.lastModule();i++) { if(strcmp(i->first, position.getModName()) == 0) addMenu(menuTranslations, MF_CHECKED, nextID++, i->first); else addMenu(menuTranslations, 0, nextID++, i->first); } } // The following line is now handled above. -- dctrotz //checkModuleMenu(transStartID); transEndID = nextID - 1; } void SimpleNavigator::fillGlobalOptionsMenu(HMENU menuOptions) { StringList::iterator i; if (menuOptions) { if (options) delete [] options; optStartID = nextID; this->menuOptions=menuOptions; StringList optionNames = position.manager->getGlobalOptions(); // count options opCount = 0; for (i = optionNames.begin(); i != optionNames.end(); i++) { StringList values = position.manager->getGlobalOptionValues(*i); bool supported = true; for (StringList::iterator j = values.begin(); j != values.end(); j++) { if ((*j != "On") && (*j != "Off")) supported = false; } if (supported) opCount++; } options = new SWBuf[opCount]; // add options; for (i = optionNames.begin(); i != optionNames.end(); i++) { // HMENU menuOption = CreatePopupMenu(); // InsertMenu(menuOptions,0,MF_POPUP,(UINT)menuOption, toUString(i->c_str()).c_str()); StringList values = position.manager->getGlobalOptionValues(*i); bool supported = true; for (StringList::iterator j = values.begin(); j != values.end(); j++) { // addMenu(menuOption, nextID++, toUString(j->c_str())); if ((*j != "On") && (*j != "Off")) supported = false; } if (supported) { options[nextID - optStartID] = *i; addMenu(menuOptions, 0, nextID++, i->c_str()); } } } optEndID = nextID - 1; // TODO: if no options, disable options menu } void SimpleNavigator::setModule(int id) { int modulenr = transStartID; ModuleMap::iterator i; for (i=position.firstModule(); (i!=position.lastModule())&&(id!=modulenr); i++) { modulenr++; }; if (i!=position.lastModule()) { position.setModule(i->second); // added - bd 06/01/08 (*g_swordConf)["History"]["LastModule"] = position.getModName(); SWModule *mod = SwordIndex::manager->getModule((*g_swordConf)["History"]["LastModule"]); if (!strcmp(mod->Type(), "Biblical Texts")) { (*g_swordConf)["History"]["LastBible"] = position.getModName(); } else if (!strcmp(mod->Type(), "Commentaries")) { (*g_swordConf)["History"]["LastComment"] = position.getModName(); } // end added code - bd 06/01/08 } } void SimpleNavigator::checkModuleMenu(int id) { int current=transStartID; for (ModuleMap::iterator i=position.firstModule();i!=position.lastModule();i++) { checkMenu(menuTranslations,current,(current==id)); current++; } } void SimpleNavigator::toggleOptionMenu(int id) { if (options) { for (int i = optStartID; i <= optEndID; i++) { SWBuf val = position.manager->getGlobalOption(options[i-optStartID]); if (i == id) { val = (val=="On")?"Off":"On"; position.manager->setGlobalOption(options[i-optStartID], val); } checkMenu(menuOptions, i, (val == "On")); } } } void SimpleNavigator::urlClicked(const WCHAR *target) { const int BUF_SIZE = 2048; char target_cstr[BUF_SIZE]; const char * t = wstrtostr(target_cstr, target, BUF_SIZE); wchar_t buf[BUF_SIZE]; SWKey *modKey = 0; // MessageBox(0, strtowstr(t), L"This is 't'", MB_OK); // SWMgr swmanager; // don't create new manager - use SwordIndex::manager // Footnote MessageBox WCString oldPos = position.verseToString(); // information to restore the persistent key if (strstr(t, "showNote")) { URL footnote(t); // t is char* to URL string SWBuf module = footnote.getParameterValue("module"); SWBuf key = footnote.getParameterValue("passage"); SWBuf footnoteNumber = footnote.getParameterValue("value"); // Now that you have extracted all the info you need from the URL, // you can lookup the footnote... // get the module it's in SWModule *mod = SwordIndex::manager->getModule(module); // Thanks Troy for above ... Nov 2007 // set that module to the correct entry // TODO - may need to re-set this afterwards - could save int SimpleNavigator::getID(); modKey = mod->getKey(); // get the persistent key modKey->setText(key.c_str()); // set the key itself // force a parse of the entry mod->RenderText(); SWBuf body = mod->getEntryAttributes()["Footnote"][footnoteNumber]["body"]; const char *Body = mod->RenderText(body.c_str()); // RenderText not StripText used // MessageBox can't display html - need to strip out tagged stuff; but Greek works OK // FIX ME MessageBox(0, (LPCWSTR)Body, L"Footnote", MB_OK); // } // Strongs number MessageBox else if (strstr(t, "showStrongs")) { URL footnote(t); // t is char* to URL string SWBuf type = footnote.getParameterValue("type"); SWBuf number = footnote.getParameterValue("value"); SWModule *mod = 0; if(strstr(type.c_str(), "Greek")) mod = SwordIndex::greekLex; if(strstr(type.c_str(), "Hebrew")) mod = SwordIndex::hebrewLex; if (! mod) { MessageBox(0, L"No Dictionary found - install Strong's modules", L"Strong's", MB_OK); return; } modKey = mod->getKey(); modKey->setText(number.c_str()); mod->RenderText(); MessageBox(0, strtowstr(buf, mod->StripText(), BUF_SIZE), L"Strong's", MB_OK); } // Morph MessageBox else if (strstr(t, "showMorph")) { URL footnote(t); // t is char* to URL string SWBuf type = footnote.getParameterValue("type"); SWBuf number = footnote.getParameterValue("value"); SWModule *mod = 0; if(strstr(type.c_str(), "robinson")) { mod = SwordIndex::greekMorph; if (! mod) { MessageBox(0, L"No Greek parsing Dictionary found - install Morphological modules", L"Greek Morphological tags", MB_ICONWARNING); return; } } if(strstr(type.c_str(), "strongMorph")) { mod = SwordIndex::hebrewMorph; if (! mod) { MessageBox(0, L"No Hebrew parsing Dictionary found - install Morphological modules", L"Hebrew Morphological tags", MB_ICONWARNING); return; } } modKey = mod->getKey(); modKey->setText(number.c_str()); mod->RenderText(); MessageBox(0, strtowstr(buf, mod->StripText(), BUF_SIZE), L"Morph tags", MB_OK); } // X-Ref MessageBox else if (strstr(t, "scripRef")) { URL footnote(t); // t is char* to URL string SWBuf module = footnote.getParameterValue("module"); // very unlikely to have this SWBuf key = footnote.getParameterValue("value"); // get the last bible module used and get xRefs from this version SWModule *mod = SwordIndex::manager->getModule((*g_swordConf)["History"]["LastBible"]); // will fail if user has never looked at a bible - possible??? so check .... if (!mod) { MessageBox(0, L"xRef bible not found", L"Cross referencing", MB_ICONWARNING); return; } modKey = mod->getKey(); // get the persistent key modKey->setText(key.c_str()); // set the key itself mod->RenderText(); // strip out html if present SWBuf body = mod->StripText(); // not sure if MessageBox can display html - if it can, re-think this some day MessageBox(0, strtowstr(buf, body, BUF_SIZE), L"Scripture reference", MB_OK); } else //comment next line out in release version MessageBox(0, strtowstr(buf, t, BUF_SIZE), L"Raw entry unresolved", MB_OK); // catch all modKey->setText((const char *)oldPos.c_str()); // restore the key before leaving } int SimpleNavigator::getID() { return nextID++; }