[sword-svn] r174 - in trunk/src/SwordReader_GUI: . SRFramework
dtrotzjr at www.crosswire.org
dtrotzjr at www.crosswire.org
Sat Sep 6 21:46:07 MST 2008
Author: dtrotzjr
Date: 2008-09-06 21:46:06 -0700 (Sat, 06 Sep 2008)
New Revision: 174
Added:
trunk/src/SwordReader_GUI/SRTabbedViews.cpp
trunk/src/SwordReader_GUI/SRTabbedViews.h
Modified:
trunk/src/SwordReader_GUI/SRFind.cpp
trunk/src/SwordReader_GUI/SRFind.h
trunk/src/SwordReader_GUI/SRFramework/SRTabCtrl.cpp
trunk/src/SwordReader_GUI/SRFramework/SRTabCtrl.h
trunk/src/SwordReader_GUI/SRMainFrame.cpp
trunk/src/SwordReader_GUI/SRMainFrame.h
trunk/src/SwordReader_GUI/SRModuleView.cpp
trunk/src/SwordReader_GUI/SRModuleView.h
trunk/src/SwordReader_GUI/SRTextView.cpp
trunk/src/SwordReader_GUI/SRTextView.h
trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj
Log:
Tabs have been integrated into the main viewer, but don't do much yet.
Added some robustness to the overall thread safety of the viewer classes.
Fixed several minor bugs.
Modified: trunk/src/SwordReader_GUI/SRFind.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRFind.cpp 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SRFind.cpp 2008-09-07 04:46:06 UTC (rev 174)
@@ -394,8 +394,9 @@
}
-VOID SRFind::SetContext(VerseKey verse, SWModule *pModule)
+VOID SRFind::SetContext(VerseKey verse, const SWModule *pModule)
{
m_keyReference = verse;
- m_modCurText = pModule;
+ //TODO BROKEN DUE TO CONSTNESS OF pModule!!!
+ m_modCurText = const_cast<sword::SWModule *>(pModule);
}
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SRFind.h
===================================================================
--- trunk/src/SwordReader_GUI/SRFind.h 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SRFind.h 2008-09-07 04:46:06 UTC (rev 174)
@@ -54,7 +54,7 @@
VOID ClearForm();
VOID ShowPreview();
VOID GoToVerse();
- VOID SetContext(VerseKey verse, SWModule *pModule);
+ VOID SetContext(VerseKey verse, const SWModule *pModule);
private:
static BOOL s_fRegistered;
HWND m_hEdtQuery;
Modified: trunk/src/SwordReader_GUI/SRFramework/SRTabCtrl.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRFramework/SRTabCtrl.cpp 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SRFramework/SRTabCtrl.cpp 2008-09-07 04:46:06 UTC (rev 174)
@@ -26,7 +26,7 @@
if(!Register())
return FALSE;
- if(!SRWnd::Create(m_wcsClassName,m_wcsWindowName,WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, bounds, pParentWnd, NULL, m_hInstance))
+ if(!SRWnd::Create(m_wcsClassName,m_wcsWindowName,WS_CHILD | WS_VISIBLE, bounds, pParentWnd, NULL, m_hInstance))
return FALSE;
return TRUE;
@@ -75,9 +75,9 @@
LONG SRTabCtrl::InsertItem(int nItem, WCString wcsItem, int nImage, LPARAM lParam)
{
- BOOL retval = FALSE;
+ BOOL retval = 0;
TC_ITEM item;
- LPWSTR pszText = (LPWSTR)calloc(wcsItem.length(), sizeof(WCHAR));
+ LPWSTR pszText = (LPWSTR)calloc(wcsItem.length() + 1, sizeof(WCHAR));
wcscpy(pszText, wcsItem.w_str());
memset(&item, 0, sizeof(TC_ITEM));
Modified: trunk/src/SwordReader_GUI/SRFramework/SRTabCtrl.h
===================================================================
--- trunk/src/SwordReader_GUI/SRFramework/SRTabCtrl.h 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SRFramework/SRTabCtrl.h 2008-09-07 04:46:06 UTC (rev 174)
@@ -1,5 +1,5 @@
#pragma once
-#include "srwnd.h"
+#include "SRWnd.h"
#include <commctrl.h>
namespace SRFramework{
@@ -10,6 +10,9 @@
SRTabCtrl(VOID);
virtual ~SRTabCtrl(VOID);
BOOL Create(SRWnd *pParentWnd, RECT bounds);
+ // Does not need to be registered the call to InitCommonControlsEx
+ // does that for us.
+ BOOL Register() { return TRUE; }
BOOL DeleteAllItems(VOID);
BOOL DeleteItem(int nItem);
BOOL DeselectAll(BOOL fExcludeFocus);
Modified: trunk/src/SwordReader_GUI/SRMainFrame.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.cpp 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SRMainFrame.cpp 2008-09-07 04:46:06 UTC (rev 174)
@@ -31,7 +31,9 @@
,m_modGreekMorph(NULL)
,m_modHebrewLex(NULL)
,m_modHebrewMorph(NULL)
-,m_modTexts(NULL)
+,m_modBibles(NULL)
+,m_modComms(NULL)
+,m_modDicts(NULL)
,m_nTotalOpts(0)
,m_swmgr(NULL)
,m_viewChapter(NULL)
@@ -41,9 +43,6 @@
,m_fChapterChanged(TRUE)
,m_nCurrentModule(0)
{
- for(int i = 0; i < SR_MAX_MODULE_PAGES; i++)
- m_viewModules[0] = NULL;
-
// Create a general options file for storing options
// and navigaiton history
const char *cwd = getWorkingDirectory();
@@ -75,12 +74,14 @@
delete m_viewVerse;
if(m_viewFind)
delete m_viewFind;
- if(m_viewModules[m_nCurrentModule])
- delete m_viewModules[m_nCurrentModule];
if(m_confOptions)
delete m_confOptions;
- if(m_modTexts)
- delete m_modTexts;
+ if(m_modBibles)
+ delete m_modBibles;
+ if(m_modComms)
+ delete m_modComms;
+ if(m_modDicts)
+ delete m_modDicts;
if(m_menuBar)
delete m_menuBar;
}
@@ -143,35 +144,38 @@
CreateCommandBar();
view_rect.bottom -= m_menuBar->Height();
- m_viewModules[m_nCurrentModule] = new SRModuleView();
- if(!m_viewModules[m_nCurrentModule]->Create(this, view_rect))
+
+ m_tabViews = new SRTabbedViews();
+ if(!m_tabViews || !m_tabViews->Create(this, view_rect))
return FALSE;
+ m_tabViews->Init();
InitSword();
LoadOptions();
-
+
m_viewBook = new SRBookChooser(s_wcsBookNames,MENU_CHAP);
- if(!m_viewBook->Create(this, view_rect))
+ if(!m_viewBook || !m_viewBook->Create(this, view_rect))
return FALSE;
m_viewVerse = new SRNumberChooser(VERSE, "Select a Verse:",MENU_TEXT);
- if(!m_viewVerse->Create(this, view_rect))
+ if(!m_viewVerse || !m_viewVerse->Create(this, view_rect))
return FALSE;
m_viewChapter = new SRNumberChooser(CHAPTER, "Select a Chapter:",MENU_VERSE);
- if(!m_viewChapter->Create(this, view_rect))
+ if(!m_viewChapter || !m_viewChapter->Create(this, view_rect))
return FALSE;
m_viewFind = new SRFind();
- if(!m_viewFind->Create(this, view_rect))
+ if(!m_viewFind || !m_viewFind->Create(this, view_rect))
return FALSE;
-
+
+
m_viewBook->Hide();
m_viewChapter->Hide();
m_viewVerse->Hide();
m_viewFind->Hide();
- m_viewModules[m_nCurrentModule]->Show();
+ m_tabViews->Show();
UpdateWindowTitle();
@@ -193,12 +197,14 @@
BOOL SRMainFrame::UpdateWindow()
{
UpdateWindowTitle();
- return m_viewModules[m_nCurrentModule]->UpdateWindow();
+ return m_tabViews->UpdateWindow();
}
BOOL SRMainFrame::InitSword()
{
- m_modTexts = new ModuleMap();
+ m_modBibles = new ModuleMap();
+ m_modComms = new ModuleMap();
+ m_modDicts = new ModuleMap();
sword::ModMap::iterator it;
sword::SWModule* curMod = NULL;
@@ -206,10 +212,10 @@
for (it = m_swmgr->Modules.begin(); it != m_swmgr->Modules.end(); it++) {
curMod = (*it).second;
if (!strcmp(curMod->Type(), "Biblical Texts")) {
- (*m_modTexts)[curMod->Name()] = curMod;
+ (*m_modBibles)[curMod->Name()] = curMod;
}
if (!strcmp(curMod->Type(), "Commentaries")) {
- (*m_modTexts)[curMod->Name()] = curMod;
+ (*m_modComms)[curMod->Name()] = curMod;
}
if (curMod->getConfig().has("Feature", "GreekDef")) {
m_modGreekLex = curMod;
@@ -226,16 +232,15 @@
}
-
- if(!m_menuBar || !m_menuBar->FillTranslationsSubMenu(m_modTexts, this->m_viewModules[m_nCurrentModule]->GetModule(), MENU_TRANS_START))
+ // TODO We need to deal with commentaries, dict, devos, etc...
+ if(!m_menuBar || !m_menuBar->FillTranslationsSubMenu(m_modBibles, m_tabViews->GetBibleModule(), MENU_TRANS_START))
return FALSE;
// Gets the supported global options and fills the options sub menu.
if(!GetSupportedOptions())
return FALSE;
-
- m_viewModules[m_nCurrentModule]->SetSwordReady();
+ m_tabViews->SetSwordReady();
return TRUE;
}
@@ -261,47 +266,47 @@
::PostQuitMessage(0);
break;
case MENU_TEXT:
- m_viewModules[m_nCurrentModule]->Show();
+ m_tabViews->Show();
m_viewBook->Hide();
m_viewChapter->Hide();
m_viewVerse->Hide();
m_viewFind->Hide();
- m_viewModules[m_nCurrentModule]->RefreshScreen();
+ m_tabViews->RefreshScreen(FALSE);
SetFocus();
break;
case MENU_BOOK:
- m_viewBook->SetSelectedBook(m_viewModules[m_nCurrentModule]->GetBook() + (m_viewModules[m_nCurrentModule]->GetTestament() == 1 ? 0 : BIBLE_OT_BOOKS) );
+ m_viewBook->SetSelectedBook(m_tabViews->GetCurrentBookNum() + (m_tabViews->GetCurrentTestament() == 1 ? 0 : BIBLE_OT_BOOKS) );
m_viewBook->Show();
m_viewChapter->Hide();
m_viewVerse->Hide();
- m_viewModules[m_nCurrentModule]->Hide();
+ m_tabViews->Hide();
m_viewFind->Hide();
break;
case MENU_CHAP:
- m_viewChapter->SetEndNumber(m_viewModules[m_nCurrentModule]->GetChapterMax());
- m_viewChapter->SetSelectedNumber(m_viewModules[m_nCurrentModule]->GetChapter());
+ m_viewChapter->SetEndNumber(m_tabViews->GetCurrentChapterMax());
+ m_viewChapter->SetSelectedNumber(m_tabViews->GetCurrentChapter());
m_viewChapter->Show();
m_viewBook->Hide();
- m_viewModules[m_nCurrentModule]->Hide();
+ m_tabViews->Hide();
m_viewVerse->Hide();
m_viewFind->Hide();
break;
case MENU_VERSE:
- m_viewVerse->SetEndNumber(m_viewModules[m_nCurrentModule]->GetVerseMax());
- m_viewVerse->SetSelectedNumber(m_viewModules[m_nCurrentModule]->GetVerse());
+ m_viewVerse->SetEndNumber(m_tabViews->GetCurrentVerseMax());
+ m_viewVerse->SetSelectedNumber(m_tabViews->GetCurrentVerse());
m_viewVerse->Show();
m_viewBook->Hide();
m_viewChapter->Hide();
- m_viewModules[m_nCurrentModule]->Hide();
+ m_tabViews->Hide();
m_viewFind->Hide();
break;
case MENU_FIND:
- m_viewFind->SetContext(m_viewModules[m_nCurrentModule]->GetVerseKey(), m_viewModules[m_nCurrentModule]->GetModule());
+ m_viewFind->SetContext(m_tabViews->GetCurrentVerseKey(), m_tabViews->GetCurrentModule());
m_viewFind->Show();
m_viewVerse->Hide();
m_viewBook->Hide();
m_viewChapter->Hide();
- m_viewModules[m_nCurrentModule]->Hide();
+ m_tabViews->Hide();
break;
case SR_SETBOOK:
SetBook(newValue);
@@ -313,7 +318,9 @@
SetVerse(newValue, wNotifyCode == SR_MSRC_CHOOSER);
break;
case SR_SETVERSEKEY:
+ /*REM
m_viewModules[m_nCurrentModule]->SetKey(*reinterpret_cast<VerseKey*>(hWndCtl));
+ */
UpdateWindowTitle();
break;
default:
@@ -336,8 +343,10 @@
VOID SRMainFrame::SaveOptions()
{
+ /*REM
(*m_confOptions)["History"]["LastVersion"] = m_viewModules[m_nCurrentModule]->GetModule()->Name();
(*m_confOptions)["History"]["LastPassage"] = m_viewModules[m_nCurrentModule]->GetVerseKey().getText();
+ */
for(int i = 0; i < m_nTotalOpts; i++){
(*m_confOptions)["GlobalOptions"][m_bufModOptions[i].c_str()] = m_swmgr->getGlobalOption(m_bufModOptions[i]);
}
@@ -353,13 +362,13 @@
m_viewBook->MoveWindow(&newSize, TRUE);
m_viewChapter->MoveWindow(&newSize, TRUE);
m_viewVerse->MoveWindow(&newSize, TRUE);
- m_viewModules[m_nCurrentModule]->MoveWindow(&newSize, TRUE);
+ m_tabViews->MoveWindow(&newSize, TRUE);
return TRUE;
}
VOID SRMainFrame::SetBook(INT nBook)
{
- m_viewModules[m_nCurrentModule]->SetBook(nBook);
+ m_tabViews->SetCurrentBookNum(nBook);
SaveOptions();
UpdateWindowTitle();
}
@@ -367,7 +376,7 @@
VOID SRMainFrame::SetChapter(INT nChapter)
{
- m_viewModules[m_nCurrentModule]->SetChapter(nChapter);
+ m_tabViews->SetCurrentChapter(nChapter);
SaveOptions();
UpdateWindowTitle();
}
@@ -375,14 +384,15 @@
VOID SRMainFrame::SetVerse(INT nVerse, BOOL fScroll)
{
- m_viewModules[m_nCurrentModule]->SetVerse(nVerse, fScroll);
+ m_tabViews->SetCurrentVerse(nVerse, fScroll);
SaveOptions();
UpdateWindowTitle();
}
BOOL SRMainFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
- BOOL fRetVal = m_viewModules[m_nCurrentModule]->OnKeyDown(nChar, nRepCnt, nFlags);
+ BOOL fRetVal = m_tabViews->OnKeyDown(nChar, nRepCnt, nFlags);
+
SaveOptions();
UpdateWindowTitle();
return fRetVal;
@@ -390,10 +400,11 @@
void SRMainFrame::SelectModule(INT nModIndex)
{
- ModuleMap::iterator it = m_modTexts->begin();
+ /* TODO This needs to be reworked!!!! */
+ ModuleMap::iterator it = m_modBibles->begin();
for(int i = 0; i < nModIndex; i++)
it++;
- m_viewModules[m_nCurrentModule]->SetModule(it->second);
+ m_tabViews->SetCurrentModule(it->second);
SaveOptions();
UpdateWindowTitle();
}
@@ -461,7 +472,7 @@
}
}
}
- m_viewModules[m_nCurrentModule]->RefreshScreen(TRUE);
+ m_tabViews->RefreshScreen(TRUE);
}
VOID SRMainFrame::LoadOptions()
@@ -479,9 +490,10 @@
textMod = m_swmgr->getModule((*m_confOptions)["History"].getWithDefault("LastVersion", "KJV"));
if(!textMod){
- textMod = m_modTexts->begin()->second;
+ textMod = m_modBibles->begin()->second;
}
- m_viewModules[m_nCurrentModule]->SetModule(textMod);
+ m_tabViews->SetBibleModule(textMod);
+ /*REM
nCurID = MENU_TRANS_START;
for (ModuleMap::iterator it = m_modTexts->begin(); it != m_modTexts->end(); it++) {
if(it->second == m_viewModules[m_nCurrentModule]->GetModule()){
@@ -490,9 +502,10 @@
}
nCurID++;
}
+ */
verse = new VerseKey((*m_confOptions)["History"].getWithDefault("LastPassage", "Gen 1:1"));
- m_viewModules[m_nCurrentModule]->SetKey(*verse);
+ m_tabViews->SetCurrentKey(*verse);
delete verse;
}
@@ -504,5 +517,5 @@
void SRMainFrame::UpdateWindowTitle()
{
- SetWindowText(m_hWnd,m_viewModules[m_nCurrentModule]->GetWindowTitle().w_str());
+ SetWindowText(m_hWnd,m_tabViews->GetCurrentWindowTitle().w_str());
}
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SRMainFrame.h
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.h 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SRMainFrame.h 2008-09-07 04:46:06 UTC (rev 174)
@@ -9,11 +9,11 @@
#include "SRFramework/SRCommandBar.h"
#include "SRFramework/SRCommandBar.h"
#include "SRFramework/SRMenu.h"
-#include "SRModuleView.h"
#include "SRMenuBar.h"
#include "SRNumberChooser.h"
#include "SRBookChooser.h"
#include "SRFind.h"
+#include "SRTabbedViews.h"
using namespace SRFramework;
@@ -59,9 +59,12 @@
// The following two variables will allow for multiple views (commentary, bible, parallel, etc.)
// For now we only have one.
INT m_nCurrentModule;
- SRModuleView *m_viewModules[SR_MAX_MODULE_PAGES];
+ /*REM
+ */
SWMgr *m_swmgr;
- ModuleMap *m_modTexts;
+ ModuleMap *m_modBibles;
+ ModuleMap *m_modDicts;
+ ModuleMap *m_modComms;
SWModule *m_modGreekLex;
SWModule *m_modGreekMorph;
SWModule *m_modHebrewLex;
@@ -70,7 +73,9 @@
SRNumberChooser *m_viewChapter;
SRBookChooser *m_viewBook;
SRFind *m_viewFind;
+ SRTabbedViews *m_tabViews;
BOOL m_fChapterChanged;
+
static WCString s_wcsBookNames[BIBLE_TOTAL_BOOKS];
static BOOL s_fRegistered;
};
Modified: trunk/src/SwordReader_GUI/SRModuleView.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRModuleView.cpp 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SRModuleView.cpp 2008-09-07 04:46:06 UTC (rev 174)
@@ -17,6 +17,7 @@
view->m_fThreadRunning = FALSE;
view->m_fAbortThread = FALSE;
+
return 0;
}
@@ -28,7 +29,6 @@
, m_fThreadRunning(FALSE)
, m_fAbortThread(FALSE)
{
-
}
SRModuleView::~SRModuleView(void)
@@ -39,11 +39,13 @@
VOID SRModuleView::SetModule(SWModule *pModule)
{
+ EnterCriticalSection(&m_csLoadText);
if(m_pModule == pModule)
return;
AbortThread();
m_pModule = pModule;
m_fChapterChanged = TRUE;
+ LeaveCriticalSection(&m_csLoadText);
LoadTextView();
}
@@ -53,8 +55,8 @@
if(m_fThreadRunning){
m_fAbortThread = TRUE;
rc = WaitForSingleObject(m_hLoadTextThread, INFINITE);
- if(rc != WAIT_FAILED){
- ::Sleep(200);// Let's sleep for a bit and give the thread a chance to spawn.
+ while(rc == WAIT_FAILED){
+ ::Sleep(20);// Let's sleep for a bit and give the thread a chance to spawn.
rc = WaitForSingleObject(m_hLoadTextThread, INFINITE);
}
}
@@ -127,24 +129,31 @@
if(!fInThread){
AbortThread();
}
- if(!fInThread && !m_fChapterChanged) // This text should still be valid...
- return;
- else
- m_fChapterChanged = false;
-
- if(!fInThread)
+
+ EnterCriticalSection(&m_csLoadText);
+ VerseKey keyCur(m_verse);
+
+ if(!fInThread){ // This text should still be valid...
+ if(!m_fChapterChanged)
+ return;
Clear();
-
- VerseKey keyCur(m_verse);
- if(!fInThread)
keyCur.Verse(1);
- else
+ }else{
+ m_fChapterChanged = false;
keyCur.Verse(m_nLoadedTill + 1);
+ }
buf = "<html><body>";
AddText(buf.w_str(), buf.length()); // a <style> section presumably gets skipped
-
+
+ int i = 0;
+ if(fInThread)
+ i++;
+
while (!done && (!fInThread || !m_fAbortThread)) {
+ if(fInThread)
+ i++;
+
m_pModule->SetKey(keyCur);
int pvHeading = 0;
text = (TCHAR *)m_pModule->RenderText();
@@ -180,12 +189,15 @@
}
keyCur.increment(1);
}
+
buf = "</body></html>";
AddText(buf.w_str(), buf.length());
if(!fInThread || !m_fAbortThread)
RefreshWindow();
+ LeaveCriticalSection(&m_csLoadText);
+
if(done){
ScrollToVerse(m_verse.Verse());
}else if(!fInThread){ // Overkill but, I am a paranoid guy.
@@ -339,11 +351,16 @@
wchar_t wverse[16] = {0};
wchar_t wchapt[16] = {0};
+ EnterCriticalSection(&m_csLoadText);
+
WCString title =
WCString(m_pModule->Name()) + " " +
SRMainFrame::GetBookNames()[(m_verse.Book() - 1) + BIBLE_OT_BOOKS*(m_verse.Testament() - 1)] + WCString(" ") +
WCString(_itow(m_verse.Chapter(),wchapt, 10)) + WCString(":") +
WCString(_itow(m_verse.Verse(), wverse, 10));
+
+ LeaveCriticalSection(&m_csLoadText);
+
return title;
}
Modified: trunk/src/SwordReader_GUI/SRModuleView.h
===================================================================
--- trunk/src/SwordReader_GUI/SRModuleView.h 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SRModuleView.h 2008-09-07 04:46:06 UTC (rev 174)
@@ -21,8 +21,8 @@
VOID RefreshScreen(BOOL fReloadText = FALSE);
BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
const VerseKey& GetVerseKey() const;
- WCString SRModuleView::GetWindowTitle();
- SWModule* GetModule() { return m_pModule; }
+ WCString GetWindowTitle();
+ const SWModule* GetModule() { return m_pModule; }
INT GetBook() { return m_verse.Book(); }
INT GetChapter() { return m_verse.Chapter(); }
INT GetVerse() { return m_verse.Verse(); }
Added: trunk/src/SwordReader_GUI/SRTabbedViews.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRTabbedViews.cpp (rev 0)
+++ trunk/src/SwordReader_GUI/SRTabbedViews.cpp 2008-09-07 04:46:06 UTC (rev 174)
@@ -0,0 +1,280 @@
+#include "SRTabbedViews.h"
+#include "SRFramework\SRApp.h"
+using namespace SRFramework;
+
+BOOL SRTabbedViews::s_fRegistered = false;
+
+SRTabbedViews::SRTabbedViews(void)
+{
+ m_wcsClassName = "SRTabbedViews";
+ m_wcsWindowName = "";
+ m_hInstance = SRFramework::SRApp::GetInstanceHandle();
+}
+
+SRTabbedViews::~SRTabbedViews(void)
+{
+ if(m_viewBible)
+ delete m_viewBible;
+}
+
+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::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;
+ return TRUE;
+}
+
+BOOL SRTabbedViews::InitViews()
+{
+ RECT tab_rect;
+ RECT views_rect = m_rect;
+ m_viewBible = new SRModuleView();
+ if(!m_viewBible || !m_viewBible->Create(this, m_rect))
+ return FALSE;
+
+ // Create the tab control
+ if(!m_tabs.Create(this, m_rect))
+ return FALSE;
+ if(!InitTabs())
+ return FALSE;
+ // Adjust the windows for the tabs...
+ m_tabs.GetItemRect(0, &tab_rect);
+ m_tabs.MoveWindow(m_rect.left,m_rect.top,m_rect.right - m_rect.left, tab_rect.bottom - tab_rect.top, TRUE);
+
+ views_rect.top += tab_rect.bottom - tab_rect.top;
+ //views_rect.bottom -= tab_rect.bottom - tab_rect.top;
+ m_viewBible->MoveWindow(&views_rect, TRUE);
+
+ m_viewBible->Show();
+
+ return TRUE;
+}
+
+BOOL SRTabbedViews::Init()
+{
+ return (InitViews());
+}
+
+BOOL SRTabbedViews::UpdateWindow()
+{
+ SRTextView *view = GetCurrentView();
+ if(!view)
+ return FALSE;
+ return view->UpdateWindow();
+}
+
+const SWModule *SRTabbedViews::GetBibleModule()
+{
+ return m_viewBible->GetModule();
+}
+
+VOID SRTabbedViews::SetBibleModule(SWModule *pModule)
+{
+ m_viewBible->SetModule(pModule);
+}
+
+VOID SRTabbedViews::SetSwordReady()
+{
+ m_viewBible->SetSwordReady();
+ /* ... */
+}
+
+
+SRTextView *SRTabbedViews::GetCurrentView()
+{
+ switch(m_tabs.GetCurSel())
+ {
+ case SR_TAB_BIBLE:
+ return m_viewBible;
+ case SR_TAB_COMM:
+ return NULL;
+ case SR_TAB_DICT:
+ return NULL;
+ default:
+ return NULL;
+ }
+ return NULL;
+}
+
+VOID SRTabbedViews::RefreshScreen(BOOL fReloadText)
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return;
+ view->RefreshScreen(fReloadText);
+}
+
+
+INT SRTabbedViews::GetCurrentBookNum()
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return -1;
+ return view->GetBook();
+}
+
+INT SRTabbedViews::GetCurrentChapter()
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return -1;
+ return view->GetChapter();
+}
+
+INT SRTabbedViews::GetCurrentChapterMax()
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return -1;
+ return view->GetChapterMax();
+}
+
+INT SRTabbedViews::GetCurrentVerse()
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return -1;
+ return view->GetVerse();
+}
+
+INT SRTabbedViews::GetCurrentVerseMax()
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return -1;
+ return view->GetVerseMax();
+}
+
+INT SRTabbedViews::GetCurrentTestament()
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return -1;
+ return view->GetTestament();
+}
+
+const VerseKey &SRTabbedViews::GetCurrentVerseKey()
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return m_keyDummy; // ??? Not a good way to return from this error.
+ return view->GetVerseKey();
+}
+
+
+void SRTabbedViews::MoveWindow(LPCRECT lpRect,BOOL bRepaint)
+{
+ SRWnd::MoveWindow(lpRect, bRepaint);
+ m_viewBible->MoveWindow(lpRect, bRepaint);
+ /* ... */
+}
+
+
+VOID SRTabbedViews::SetCurrentBookNum(INT nBook)
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return;
+ return view->SetBook(nBook);
+}
+
+VOID SRTabbedViews::SetCurrentChapter(INT nChapter)
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return;
+ return view->SetChapter(nChapter);
+}
+
+VOID SRTabbedViews::SetCurrentVerse(INT nVerse, BOOL fScroll)
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return;
+ return view->SetVerse(nVerse, fScroll);
+}
+
+
+BOOL SRTabbedViews::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return FALSE;
+ return view->OnKeyDown(nChar, nRepCnt, nFlags);
+}
+
+VOID SRTabbedViews::SetCurrentModule(sword::SWModule *pModule)
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return;
+ view->SetModule(pModule);
+}
+
+WCString SRTabbedViews::GetCurrentWindowTitle()
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return "";
+ return view->GetWindowTitle();
+}
+
+const SWModule *SRTabbedViews::GetCurrentModule()
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return NULL;
+ return view->GetModule();
+}
+
+VOID SRTabbedViews::SetCurrentKey(const VerseKey &verse)
+{
+ SRModuleView *view = dynamic_cast<SRModuleView *>(GetCurrentView());
+ if(!view)
+ return;
+ view->SetKey(verse);
+}
\ No newline at end of file
Added: trunk/src/SwordReader_GUI/SRTabbedViews.h
===================================================================
--- trunk/src/SwordReader_GUI/SRTabbedViews.h (rev 0)
+++ trunk/src/SwordReader_GUI/SRTabbedViews.h 2008-09-07 04:46:06 UTC (rev 174)
@@ -0,0 +1,54 @@
+#pragma once
+#include "SRFramework/SRWnd.h"
+#include "SRFramework/SRTabCtrl.h"
+#include "SRModuleView.h"
+
+#define SR_TAB_BIBLE 0
+#define SR_TAB_COMM 1
+#define SR_TAB_DICT 2
+
+using namespace SRFramework;
+using namespace sword;
+
+class SRTabbedViews :
+ public SRFramework::SRWnd
+{
+public:
+ SRTabbedViews(void);
+ virtual ~SRTabbedViews(void);
+ SRTabCtrl m_tabs;
+ BOOL Create(SRWnd *pParentWnd, RECT bounds);
+ BOOL Register();
+ BOOL Init();
+ BOOL UpdateWindow();
+ const SWModule *GetBibleModule();
+ VOID SetBibleModule(SWModule *pModule);
+ const SWModule *GetCurrentModule();
+ VOID SetSwordReady();
+ VOID RefreshScreen(BOOL fReloadText);
+ INT GetCurrentBookNum();
+ INT GetCurrentChapter();
+ INT GetCurrentChapterMax();
+ INT GetCurrentVerse();
+ INT GetCurrentVerseMax();
+ INT GetCurrentTestament();
+ WCString GetCurrentWindowTitle();
+ const VerseKey &GetCurrentVerseKey();
+ VOID SetCurrentBookNum(INT nBook);
+ VOID SetCurrentChapter(INT nChapter);
+ VOID SetCurrentVerse(INT nVerse, BOOL fScroll);
+ VOID SetCurrentModule(SWModule *pModule);
+ VOID SetCurrentKey(const VerseKey &verse);
+
+ void MoveWindow(LPCRECT lpRect,BOOL bRepaint = TRUE);
+ BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
+
+private:
+ BOOL InitTabs();
+ BOOL InitViews();
+ SRTextView *GetCurrentView();
+ VerseKey m_keyDummy;
+ static BOOL s_fRegistered;
+
+ SRModuleView *m_viewBible;
+};
Modified: trunk/src/SwordReader_GUI/SRTextView.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRTextView.cpp 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SRTextView.cpp 2008-09-07 04:46:06 UTC (rev 174)
@@ -79,6 +79,8 @@
for(DWORD i = 0; i < BTEXT_FONT_CACHE_MAX; i++)
m_hFontCache[i] = 0;
+
+ InitializeCriticalSection(&m_csLoadText);
}
SRTextView::~SRTextView()
@@ -86,6 +88,7 @@
if(m_lpszBuff)
delete [] m_lpszBuff;
+ DeleteCriticalSection(&m_csLoadText);
DestroyWindow(m_hWnd);
}
@@ -481,6 +484,7 @@
if(m_dwBuffEnd == 0)
return;
+ EnterCriticalSection(&m_csLoadText);
if(!m_fAppended){
memset(&m_rsState, 0, sizeof(m_rsState));
m_nLineX = BTEXT_MARGIN;
@@ -605,6 +609,7 @@
m_dwWordIndex = m_dwWordIndex;
m_fAppended = FALSE;
m_fPreRendered = TRUE;
+ DeleteCriticalSection(&m_csLoadText);
}
// I wanted to use the same font setter for both prerendering and rendering
Modified: trunk/src/SwordReader_GUI/SRTextView.h
===================================================================
--- trunk/src/SwordReader_GUI/SRTextView.h 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SRTextView.h 2008-09-07 04:46:06 UTC (rev 174)
@@ -761,5 +761,7 @@
we can redraw over it while scrolling.
*/
WORD m_wStatusBarHeight;
+
+ CRITICAL_SECTION m_csLoadText;
};
Modified: trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj
===================================================================
--- trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj 2008-09-06 05:38:44 UTC (rev 173)
+++ trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj 2008-09-07 04:46:06 UTC (rev 174)
@@ -168,6 +168,7 @@
RuntimeLibrary="0"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="true"
+ RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
PrecompiledHeaderFile="$(PlatformName)\$(ConfigurationName)/SwordReader_GUI.pch"
AssemblerListingLocation="$(PlatformName)\$(ConfigurationName)/"
@@ -579,6 +580,7 @@
PreprocessorDefinitions="DEBUG;ARM;_ARM_;UNDER_CE=$(CEVER);_WIN32_WCE=$(CEVER);$(CePlatform);UNICODE;SIMPLE"
RuntimeLibrary="1"
BufferSecurityCheck="false"
+ RuntimeTypeInfo="true"
PrecompiledHeaderFile="$(PlatformName)\$(ConfigurationName)/SwordReader_GUI.pch"
AssemblerListingLocation="$(PlatformName)\$(ConfigurationName)/"
ObjectFile="$(PlatformName)\$(ConfigurationName)/"
@@ -885,6 +887,10 @@
>
</File>
<File
+ RelativePath=".\SRTabbedViews.cpp"
+ >
+ </File>
+ <File
RelativePath=".\SRTextView.cpp"
>
</File>
@@ -962,6 +968,10 @@
>
</File>
<File
+ RelativePath=".\SRTabbedViews.h"
+ >
+ </File>
+ <File
RelativePath=".\SRTextView.h"
>
</File>
More information about the sword-cvs
mailing list