// Navigator.cpp: implementation of the Navigator class. // ////////////////////////////////////////////////////////////////////// #include "ApplicationInterface.h" #include "Navigator.h" #include "NavNumbers.h" #include "NavBooks.h" #include "NavRenderText.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// #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}; Navigator::Navigator(RECT* screen) { RECT_SCREEN=*screen; mode=-1; numbers=new NavNumbers(this); books=new NavBooks(this); text=new NavRenderText(this); } Navigator::~Navigator() { delete numbers; delete books; delete text; } void Navigator::refresh() { refreshScreen(); } void Navigator::setMode(int mode) { if (this->mode==MODE_TEXT) text->hide(); this->mode=mode; switch (mode) { case MODE_BOOK: selectMenu(MENU_BOOK); break; case MODE_CHAP: selectMenu(MENU_CHAP); showChap(); break; case MODE_VERSE: selectMenu(MENU_VERSE); showVerse(); break; case MODE_TEXT: selectMenu(MENU_TEXT); text->show(); break; case MODE_FIND: selectMenu(MENU_FIND); break; }; updateTitle(); refresh(); } void Navigator::paint() { if (mode==MODE_BOOK) { books->paint(); } if ((mode==MODE_CHAP)||(mode==MODE_VERSE)) { numbers->paint(); } if (mode==MODE_TEXT) { text->paint(); } if (mode==MODE_FIND) { clearRect(&RECT_SCREEN); drawText(&RECT_SELECTLABEL, UString(L"Not yet implemented.")); } } void Navigator::showChap() { numbers->show(position.chapCount(),UString(L"Select a chapter:")); } void Navigator::showVerse() { numbers->show(position.verseCount(),UString(L"Select a verse:")); } void Navigator::updateTitle() { UString title=position.toString()+L" - SwRd"; setTitle(title); } /* a menu-item is selected (one of the translations) */ void Navigator::buttonClicked(int id) { setModule(id); checkModuleMenu(id); text->show(true); } void Navigator::keyDown(WPARAM id, LPARAM lparam) { switch (mode) { case MODE_TEXT: text->keyDown(id,lparam); break; } } void Navigator::mouseDown(int x, int y) { int number; switch (mode) { case MODE_BOOK: number=books->userTap(x,y); if (number>0) { position.setBook(number); setMode(MODE_CHAP); } break; case MODE_CHAP: number=numbers->userTap(x,y); if (number>0) { position.setChap(number); setMode(MODE_VERSE); } break; case MODE_VERSE: number=numbers->userTap(x,y); if (number>0) { position.setVerse(number); setMode(MODE_TEXT); } break; } } void Navigator::fillTranslationsMenu(HMENU menuTranslations) { this->menuTranslations=menuTranslations; if (menuTranslations) { int modulenr=1; for (ModuleMap::iterator i=position.firstModule();i!=position.lastModule();i++) { addMenu(menuTranslations,modulenr,toUString(String(i->first))); modulenr++; } } checkModuleMenu(1); } void Navigator::setModule(int id) { int modulenr=1; ModuleMap::iterator i; for ( i=position.firstModule(); (i!=position.lastModule())&&(id!=modulenr); i++ ) { modulenr++; }; if (i!=position.lastModule()) { position.setModule(i->second); setMode(MODE_TEXT); } } void Navigator::checkModuleMenu(int id) { int current=1; for (ModuleMap::iterator i=position.firstModule();i!=position.lastModule();i++) { checkMenu(menuTranslations,current,(current==id)); current++; } }