#include "SRTabbedViews.h" #include "SRFramework\SRApp.h" using namespace SRFramework; BOOL SRTabbedViews::s_fRegistered = false; SRTabbedViews::SRTabbedViews(void) :m_viewBible(NULL) ,m_viewComm(NULL) ,m_viewDict(NULL) ,m_viewAbout(NULL) { m_wcsClassName = "SRTabbedViews"; m_wcsWindowName = ""; m_hInstance = SRFramework::SRApp::GetInstanceHandle(); m_verseDummy.setText("Gen 1:1", true); m_dictDummy.setText(""); } SRTabbedViews::~SRTabbedViews(void) { if(m_viewBible) delete m_viewBible; if(m_viewComm) delete m_viewComm; if(m_viewDict) delete m_viewDict; if(m_viewAbout) delete m_viewAbout; } BOOL SRTabbedViews::Create(SRWnd *pParentWnd, RECT bounds) { if(!Register()) return FALSE; if(!SRWnd::Create(m_wcsClassName,m_wcsWindowName,WS_CHILD | WS_VISIBLE, bounds, pParentWnd, NULL, m_hInstance)) return FALSE; return TRUE; } BOOL SRTabbedViews::Register() { // Register window class... WNDCLASS wc; if(s_fRegistered) return TRUE; wc.style = CS_HREDRAW | CS_VREDRAW | CS_PARENTDC; wc.lpfnWndProc = (WNDPROC) MessageRoute; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = m_hInstance; wc.hIcon = NULL; wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = m_wcsClassName.w_str(); if(RegisterClass(&wc) == 0) return FALSE; s_fRegistered = TRUE; return TRUE; } BOOL SRTabbedViews::OnCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl) { if(m_pParentWnd) return m_pParentWnd->OnCommand(wNotifyCode, wID, hWndCtl); return FALSE; } BOOL SRTabbedViews::InitTabs() { INT i = 0; if(m_tabs.InsertItem(SR_TAB_BIBLE, "Bible") == -1) return FALSE; if(m_tabs.InsertItem(SR_TAB_COMM, "Comm") == -1) return FALSE; if(m_tabs.InsertItem(SR_TAB_DICT, "Dict") == -1) return FALSE; if(m_tabs.InsertItem(SR_TAB_ABOUT, "About") == -1) return FALSE; return TRUE; } BOOL SRTabbedViews::InitViews() { RECT clientRect = GetBounds(); m_viewBible = new SRBibleWidget(); if(!m_viewBible || !m_viewBible->Create(this, clientRect)) return FALSE; m_viewBible->Show(); m_viewBible->Init(); m_viewComm = new SRCommWidget(); if(!m_viewComm || !m_viewComm->Create(this, clientRect)) return FALSE; m_viewComm->Init(); m_viewComm->Hide(); m_viewDict = new SRLexiWidget(); if(!m_viewDict || !m_viewDict->Create(this, clientRect)) return FALSE; m_viewDict->Init(); m_viewDict->Hide(); m_viewAbout = new SRAboutView(); if(!m_viewAbout || !m_viewAbout->Create(this, clientRect)) return FALSE; m_viewAbout->Hide(); // Create the tab control if(!m_tabs.Create(this, clientRect, WS_CHILD | WS_VISIBLE | TCS_BOTTOM | TCS_FOCUSNEVER)) return FALSE; if(!InitTabs()) return FALSE; MoveWindow(&clientRect, TRUE); return TRUE; } BOOL SRTabbedViews::Init() { return (InitViews()); } BOOL SRTabbedViews::UpdateWindow() { SRTextView *view = dynamic_cast(GetCurrentView()); if(view) return view->UpdateWindow(); return FALSE; } const SWModule *SRTabbedViews::GetBibleModule() { if(!m_viewBible) return NULL; return m_viewBible->GetModule(); } const VerseKey &SRTabbedViews::GetBibleVerseKey() { if(!m_viewBible) return m_verseDummy; return m_viewBible->GetVerseKey(); } const SWKey &SRTabbedViews::GetDictKey() { if(!m_viewDict) return m_dictDummy; return m_viewDict->GetKey(); } VOID SRTabbedViews::SetBibleModule(SWModule *pModule) { if(m_viewBible) m_viewBible->SetModule(pModule); if(m_viewComm) m_viewComm->SetScripRefModule(pModule); } const SWModule *SRTabbedViews::GetCommModule() { if(!m_viewComm) return NULL; return m_viewComm->GetModule(); } const SWModule *SRTabbedViews::GetDictModule() { if(!m_viewDict) return NULL; return m_viewDict->GetModule(); } const VerseKey &SRTabbedViews::GetCommVerseKey() { if(!m_viewComm) return m_verseDummy; return m_viewComm->GetVerseKey(); } VOID SRTabbedViews::SetCommModule(SWModule *pModule) { if(m_viewComm) m_viewComm->SetModule(pModule); } VOID SRTabbedViews::SetDictModule(SWModule *pModule) { if(m_viewDict) m_viewDict->SetModule(pModule); } VOID SRTabbedViews::SetSwordReady() { if(m_viewBible) m_viewBible->SetSwordReady(); if(m_viewComm) m_viewComm->SetSwordReady(); if(m_viewDict) m_viewDict->SetSwordReady(); } SRWnd *SRTabbedViews::GetCurrentView() { switch(m_tabs.GetCurSel()) { case SR_TAB_BIBLE: return m_viewBible; case SR_TAB_COMM: return m_viewComm; case SR_TAB_DICT: return m_viewDict; default: return NULL; } return NULL; } VOID SRTabbedViews::RefreshScreen(BOOL fReloadText) { SRModuleWidget *mview = dynamic_cast(GetCurrentView()); if(mview){ mview->RefreshScreen(fReloadText); return; } SRLexiWidget *lview = dynamic_cast(GetCurrentView()); if(lview){ lview->RefreshScreen(fReloadText); return; } } INT SRTabbedViews::GetCurrentBookNum() { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return -1; return mod->GetBook(); } INT SRTabbedViews::GetCurrentChapter() { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return -1; return mod->GetChapter(); } INT SRTabbedViews::GetCurrentChapterMax() { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return -1; return mod->GetChapterMax(); } INT SRTabbedViews::GetCurrentVerse() { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return -1; return mod->GetVerse(); } INT SRTabbedViews::GetCurrentVerseMax() { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return -1; return mod->GetVerseMax(); } INT SRTabbedViews::GetCurrentTestament() { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return -1; return mod->GetTestament(); } const VerseKey &SRTabbedViews::GetCurrentVerseKey() { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(mod) return mod->GetVerseKey(); return m_verseDummy; // ??? Not a good way to return from this error. } void SRTabbedViews::MoveWindow(LPCRECT lpRect,BOOL bRepaint) { RECT tab_rect; RECT views_rect = *lpRect; RECT clientRect = *lpRect; SRWnd::MoveWindow(&clientRect, bRepaint); // Adjust the windows for the tabs... m_tabs.GetItemRect(0, &tab_rect); tab_rect.bottom += 2; if(0){ // Tabs on top... soon to be an option... m_tabs.MoveWindow(clientRect.left,clientRect.top,clientRect.right - clientRect.left, tab_rect.bottom - tab_rect.top, bRepaint); }else{ m_tabs.MoveWindow(clientRect.left,clientRect.bottom - (tab_rect.bottom - tab_rect.top),clientRect.right - clientRect.left, tab_rect.bottom - tab_rect.top, bRepaint); } if(0){ // Same as above views_rect.top += (tab_rect.bottom - tab_rect.top); }else{ views_rect.bottom -= (tab_rect.bottom - tab_rect.top); } if(m_viewBible) m_viewBible->MoveWindow(&views_rect, bRepaint); if(m_viewComm) m_viewComm->MoveWindow(&views_rect, bRepaint); if(m_viewDict) m_viewDict->MoveWindow(&views_rect, bRepaint); if(m_viewAbout) m_viewAbout->MoveWindow(&views_rect, bRepaint); /* ... */ } VOID SRTabbedViews::SetCurrentBookNum(INT nBook) { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return; return mod->SetBook(nBook); } VOID SRTabbedViews::SetCurrentChapter(INT nChapter) { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return; return mod->SetChapter(nChapter); } VOID SRTabbedViews::SetCurrentVerse(INT nVerse, BOOL fScroll) { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return; return mod->SetVerse(nVerse, fScroll); } BOOL SRTabbedViews::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { SRWnd *view = GetCurrentView(); if(!view) return FALSE; return view->OnKeyDown(nChar, nRepCnt, nFlags); } VOID SRTabbedViews::SetCurrentModule(sword::SWModule *pModule) { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return; mod->SetModule(pModule); } WCString SRTabbedViews::GetCurrentWindowTitle() { SRWnd *view = GetCurrentView(); if(!view) return ""; return view->GetWindowTitle(); } WCString SRTabbedViews::GetWindowTitle() { SRWnd *view = GetCurrentView(); if(!view) return ""; return view->GetWindowTitle(); } const SWModule *SRTabbedViews::GetCurrentModule() { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return NULL; return mod->GetModule(); } VOID SRTabbedViews::SetCurrentKey(const VerseKey &verse) { SRModuleHolder *mod = dynamic_cast(GetCurrentView()); if(!mod) return; mod->SetKey(verse); } VOID SRTabbedViews::SetBibleKey(const VerseKey &verse) { if(m_viewBible) m_viewBible->SetKey(verse); } VOID SRTabbedViews::SetCommKey(const VerseKey &verse) { if(m_viewComm) m_viewComm->SetKey(verse); } VOID SRTabbedViews::SetDictKey(const StrKey &entry) { if(m_viewDict) m_viewDict->SetKey(entry); } BOOL SRTabbedViews::OnNotify(int idCtrl, LPNMHDR pnmh) { UINT test = TCN_SELCHANGE; switch(pnmh->code) { case TCN_SELCHANGING: if(m_tabs.GetCurSel() < 2) // i.e. this was a tab with a versekey m_keyLinked = GetCurrentVerseKey(); return FALSE; // If we return TRUE we stop the change case TCN_SELCHANGE: SwitchToCurrentView(); if(m_pParentWnd) m_pParentWnd->SetFocus(); // Give focus back to the parent. m_tabs.RefreshWindow(); // Make sure the tabs reflect the current switch. break; default: return FALSE; } return TRUE; } INT SRTabbedViews::SwitchToCurrentView() { switch(m_tabs.GetCurSel()) { case SR_TAB_BIBLE: if(m_viewComm){ m_viewComm->Hide(); } if(m_viewDict) m_viewDict->Hide(); if(m_viewAbout) m_viewAbout->Hide(); if(m_viewBible){ m_viewBible->SetKey(m_keyLinked); m_viewBible->Show(); } return SR_TAB_BIBLE; case SR_TAB_COMM: if(m_viewBible){ m_viewBible->Hide(); } if(m_viewDict) m_viewDict->Hide(); if(m_viewAbout) m_viewAbout->Hide(); if(m_viewComm){ m_viewComm->SetKey(m_keyLinked); m_viewComm->Show(); } return SR_TAB_COMM; case SR_TAB_DICT: if(m_viewBible) m_viewBible->Hide(); if(m_viewComm) m_viewComm->Hide(); if(m_viewAbout) m_viewAbout->Hide(); if(m_viewDict) m_viewDict->Show(); return SR_TAB_DICT; case SR_TAB_ABOUT: if(m_viewBible) m_viewBible->Hide(); if(m_viewComm) m_viewComm->Hide(); if(m_viewDict) m_viewDict->Hide(); if(m_viewAbout) m_viewAbout->Show(); return SR_TAB_ABOUT; } return -1; } VOID SRTabbedViews::ManualChangeCurrentTab(INT nNewTab) { m_tabs.SetCurSel(nNewTab); SwitchToCurrentView(); } INT SRTabbedViews::GetCurTabSel() { return m_tabs.GetCurSel(); } VOID SRTabbedViews::SetGreekDefModule(SWModule *pModule) { if(m_viewBible) m_viewBible->SetGreekDefModule(pModule); } VOID SRTabbedViews::SetGreekMorphModule(SWModule *pModule) { if(m_viewBible) m_viewBible->SetGreekMorphModule(pModule); } VOID SRTabbedViews::SetHebrewDefModule(SWModule *pModule) { if(m_viewBible) m_viewBible->SetHebrewDefModule(pModule); } VOID SRTabbedViews::SetHebrewMorphModule(SWModule *pModule) { if(m_viewBible) m_viewBible->SetHebrewMorphModule(pModule); } /*VOID SRTabbedViews::HyperLinkClicked() { if(m_viewBible) m_viewBible->ShowSubWindow(); }*/ VOID SRTabbedViews::ShowGreekDef(const WCString &key) { if(m_viewBible) m_viewBible->ShowGreekDef(key); } VOID SRTabbedViews::ShowHebrewDef(const WCString &key) { if(m_viewBible) m_viewBible->ShowHebrewDef(key); } VOID SRTabbedViews::ShowGreekMorph(const WCString &key) { if(m_viewBible) m_viewBible->ShowGreekMorph(key); } VOID SRTabbedViews::ShowHebrewMorph(const WCString &key) { if(m_viewBible) m_viewBible->ShowHebrewMorph(key); } VOID SRTabbedViews::ShowBibleNote(const WCString ¬e) { if(m_viewBible) m_viewBible->ShowBibleNote(note); } VOID SRTabbedViews::ShowScriptRef(const WCString &ref) { if(m_viewComm) m_viewComm->ShowScripRef(ref); }