#include "SRFramework\SRApp.h" #include "SRModuleWidget.h" #include "SRModuleView.h" #include "SRSubWindow.h" #include #include BOOL SRModuleWidget::s_fRegistered = false; SRModuleWidget::SRModuleWidget() :m_viewModule(NULL) { m_wcsClassName = "SRModuleWidget"; m_wcsWindowName = ""; m_hInstance = SRFramework::SRApp::GetInstanceHandle(); } SRModuleWidget::~SRModuleWidget() { if(m_viewModule) delete m_viewModule; } BOOL SRModuleWidget::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 SRModuleWidget::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; } VOID SRModuleWidget::SetSwordReady() { if(m_viewModule) m_viewModule->SetSwordReady(); } BOOL SRModuleWidget::OnCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl) { if(m_pParentWnd) return m_pParentWnd->OnCommand(wNotifyCode, wID, hWndCtl); return FALSE; } VOID SRModuleWidget::SetModule(SWModule *pModule) { if(m_viewModule) m_viewModule->SetModule(pModule); } VOID SRModuleWidget::SetKey(const VerseKey &verse) { if(m_viewModule) m_viewModule->SetKey(verse); } VOID SRModuleWidget::SetBook(INT nBook) { if(m_viewModule) m_viewModule->SetBook(nBook); } VOID SRModuleWidget::SetChapter(INT nChapter) { if(m_viewModule) m_viewModule->SetChapter(nChapter); } VOID SRModuleWidget::SetVerse(INT nVerse, BOOL fScroll) { if(m_viewModule) m_viewModule->SetVerse(nVerse, fScroll); } WCString SRModuleWidget::GetWindowTitle() { if(m_viewModule) return m_viewModule->GetWindowTitle(); return ""; } const SWModule* SRModuleWidget::GetModule() { if(m_viewModule) return m_viewModule->GetModule(); return NULL; } INT SRModuleWidget::GetBook() { if(m_viewModule) return m_viewModule->GetBook(); return -1; } INT SRModuleWidget::GetChapter() { if(m_viewModule) return m_viewModule->GetChapter(); return -1; } INT SRModuleWidget::GetVerse() { if(m_viewModule) return m_viewModule->GetVerse(); return -1; } const VerseKey& SRModuleWidget::GetVerseKey() const { if(m_viewModule) return m_viewModule->GetVerseKey(); return m_keyDummy; } INT SRModuleWidget::GetTestament() { if(m_viewModule) return m_viewModule->GetTestament(); return -1; } INT SRModuleWidget::GetChapterMax() { if(m_viewModule) return m_viewModule->GetChapterMax(); return -1; } INT SRModuleWidget::GetVerseMax() { if(m_viewModule) return m_viewModule->GetVerseMax(); return -1; } VOID SRModuleWidget::ShowSubWindow(SRSubWindow *pSubWnd) { RECT clientRect = GetBounds(); INT nBottomMax = GetSplitPoint(); RECT mainRect, subRect; int i,j,tmp; if(!pSubWnd || !m_viewModule) return; mainRect = clientRect; subRect = clientRect; subRect.top = mainRect.bottom; pSubWnd->MoveWindow(&subRect); pSubWnd->Show(); for(i = 0, j = 1; i < nBottomMax;){ tmp = 20 - j++; i += tmp; mainRect.bottom -= tmp; if(mainRect.bottom < nBottomMax) mainRect.bottom = nBottomMax; subRect.top = mainRect.bottom; m_viewModule->MoveWindow(&mainRect); pSubWnd->MoveWindow(&subRect); m_viewModule->RefreshWindow(); pSubWnd->RefreshWindow(); } } VOID SRModuleWidget::HideSubWindow(SRSubWindow *pSubWnd) { RECT mainRect, subRect; int i,j,tmp; if(!pSubWnd || !m_viewModule) return; mainRect = m_viewModule->GetBounds(); INT nBottomMax = GetBounds().bottom; subRect = pSubWnd->GetBounds(); subRect.top += mainRect.bottom; subRect.bottom += mainRect.bottom; for(i = 0, j = 1; i < nBottomMax;){ tmp = 20 - j++; i += tmp; mainRect.bottom += tmp; if(mainRect.bottom > nBottomMax){ mainRect.bottom = nBottomMax; i = nBottomMax; } subRect.top = mainRect.bottom; m_viewModule->MoveWindow(&mainRect); m_viewModule->RefreshWindow(); pSubWnd->MoveWindow(&subRect); pSubWnd->RefreshWindow(); } pSubWnd->Hide(); } VOID SRModuleWidget::MoveWindow(LPCRECT lpRect,BOOL bRepaint) { SRWnd::MoveWindow(lpRect, bRepaint); RECT clientRect = GetBounds(); m_viewModule->MoveWindow(&clientRect, bRepaint); } INT SRModuleWidget::GetSplitPoint() { RECT clientRect = GetBounds(); return (INT)(((float)(clientRect.bottom - clientRect.top))*0.65f); } VOID SRModuleWidget::RefreshScreen(BOOL fReloadText) { m_viewModule->RefreshScreen(fReloadText); }