[sword-svn] r126 - trunk/src/SwordReader_GUI
dtrotzjr at www.crosswire.org
dtrotzjr at www.crosswire.org
Sun Apr 27 18:19:19 MST 2008
Author: dtrotzjr
Date: 2008-04-27 18:19:18 -0700 (Sun, 27 Apr 2008)
New Revision: 126
Modified:
trunk/src/SwordReader_GUI/SRMainFrame.cpp
trunk/src/SwordReader_GUI/SRMainFrame.h
trunk/src/SwordReader_GUI/SRNumberChooser.cpp
trunk/src/SwordReader_GUI/SRNumberChooser.h
trunk/src/SwordReader_GUI/SRTextView.cpp
trunk/src/SwordReader_GUI/SRTextView.h
trunk/src/SwordReader_GUI/SwordReaderResource.h
trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj
Log:
Rewrite at 80% completion. Looking promising, but very buggy still...
Modified: trunk/src/SwordReader_GUI/SRMainFrame.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.cpp 2008-04-27 03:09:29 UTC (rev 125)
+++ trunk/src/SwordReader_GUI/SRMainFrame.cpp 2008-04-28 01:19:18 UTC (rev 126)
@@ -4,12 +4,25 @@
using namespace sword;
-BOOL SRMainFrame::m_fRegistered = false;
+BOOL SRMainFrame::s_fRegistered = false;
namespace sword {
char *SWBuf::nullStr = "";
}
+/*
+ * While SWORD's canon.h does have a form of these abbreviations,
+ * We need consistent 3 letter abbreviations so we define our own.
+ */
+WCString SRMainFrame::s_wcsBookNames[BIBLE_TOTAL_BOOKS] = {
+"Gen","Exo","Lev","Num","Deu","Jos","Jdg","Rut","1Sa","2Sa","1Ki","2Ki","1Ch",
+"2Ch","Ezr","Neh","Est","Job","Psa","Pro","Ecc","Son","Isa","Jer","Lam","Eze",
+"Dan","Hos","Joe","Amo","Oba","Jon","Mic","Nah","Hab","Zep","Hag","Zec","Mal",
+"Mat","Mar","Luk","Joh","Act","Rom","1Co","2Co","Gal","Eph","Phi","Col","1Th",
+"2Th","1Ti","2Ti","Tit","Phm","Heb","Jam","1Pe","2Pe","1Jo","2Jo","3Jo","Jud",
+"Rev"
+};
+
SRMainFrame::SRMainFrame()
:SRFrame()
,m_bufModOptions(NULL)
@@ -27,6 +40,7 @@
,m_viewText(NULL)
,m_viewChapter(NULL)
,m_viewVerse(NULL)
+,m_viewBook(NULL)
{
// Create a general options file for storing options
// and navigaiton history
@@ -54,7 +68,7 @@
BOOL SRMainFrame::Register()
{
WNDCLASS wc;
- if(m_fRegistered)
+ if(s_fRegistered)
return TRUE;
wc.style = CS_HREDRAW | CS_VREDRAW;
@@ -71,7 +85,7 @@
if(RegisterClass(&wc) == 0)
return FALSE;
- m_fRegistered = TRUE;
+ s_fRegistered = TRUE;
return TRUE;
}
@@ -108,21 +122,22 @@
WCString test_str = "This is a <b>test</b>. It worked?";
m_viewText->AddText(test_str.w_str(),test_str.length());
-
- m_viewVerse = new SRNumberChooser(ChooserType::VERSE, "Select a Verse:",MENU_TEXT);
+ m_viewBook = new SRBookChooser(s_wcsBookNames,MENU_CHAP);
+ if(!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))
return FALSE;
- m_viewChapter = new SRNumberChooser(ChooserType::CHAPTER, "Select a Chapter:",MENU_VERSE);
+ m_viewChapter = new SRNumberChooser(CHAPTER, "Select a Chapter:",MENU_VERSE);
if(!m_viewChapter->Create(this, view_rect))
return FALSE;
m_viewText->Show();
+ m_viewBook->Hide();
m_viewChapter->Hide();
m_viewVerse->Hide();
-
- m_viewChapter->SetEndNumber(130);
- m_viewVerse->SetEndNumber(13);
return TRUE;
}
@@ -190,6 +205,95 @@
return TRUE;
}
+void SRMainFrame::LoadTextView() {
+ /*
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_BOOK, false);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_CHAP, false);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_VERSE, false);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_TEXT, false);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_FIND, false);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_MENU, false);
+
+
+ // Suspend user interaction until this page is fully loaded.
+ PostThreadMessage(g_tMain, WM_TXT_START, NULL, NULL);
+ */
+ m_viewText->Clear();
+ //VerseKey keyCur(m_keyCurVerse);
+ m_keyCurVerse->Verse(1);
+ WCString buf = "";//"<html><head><meta name=\"MobileOptimized\" content=\"240\"><title></title></head><body>";
+
+ m_viewText->AddText(buf.w_str(), buf.length()); // a <style> section presumably gets skipped
+ WCString s;
+ WCString heading;
+ char strNum[10];
+ while (true) {
+ if(m_keyCurVerse->Verse() == 26)
+ s = "";
+ m_modCurText->SetKey(m_keyCurVerse);
+ int pvHeading = 0;
+ do {
+ sprintf(strNum, "%i", pvHeading++);
+ SWBuf preverseHeading = m_modCurText->getEntryAttributes()["Heading"]["Preverse"][strNum].c_str();
+ if (preverseHeading.length()) {
+ buf = "<br /><br /><b>";
+ buf += (TCHAR *)m_modCurText->RenderText(preverseHeading);
+ buf += "</b><br /><br />";
+ m_viewText->AddText(buf.w_str(), buf.length());
+ }
+ else break;
+ } while (true);
+ s = GetVerseHeader(*m_keyCurVerse);
+ s += (TCHAR *)m_modCurText->RenderText();
+ s += " "; // Many verses do not have a space after them.
+ if (s.length() > 0) {
+ if(m_keyCurVerse->Verse() == 31){
+ m_viewText->AddText(s.w_str(), s.length());
+ }else
+ m_viewText->AddText(s.w_str(), s.length());
+ }
+ if (m_keyCurVerse->Verse() == GetMaxVerses())
+ break;
+ else
+ m_keyCurVerse->increment(1);
+ }
+ buf = "</body></html>";
+ m_viewText->AddText(buf.w_str(), buf.length());
+
+ /*
+ // Allow user interaction since this page is now fully loaded.
+ PostThreadMessage(g_tMain, WM_TXT_END, NULL, NULL);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_BOOK, true);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_CHAP, true);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_VERSE, true);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_TEXT, true);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_FIND, true);
+ SendMessage(g_hwndCB, TB_ENABLEBUTTON, MENU_MENU, true);
+ */
+
+ m_viewText->RefreshWindow();
+}
+
+
+WCString SRMainFrame::GetVerseHeader(VerseKey key) {
+ wchar_t wverse[16] = {0};
+ wchar_t wchap[16] = {0};
+ _itow(key.Verse(), wverse, 10);
+ _itow(key.Chapter(), wchap, 10);
+
+ WCString result = "\n<b><a name=\"";
+ result += wverse;
+ result += "\">";
+ if (key.Verse() == 1) {
+ result += wchap;
+ result += ":";
+ }
+ result += wverse;
+ result += "</a></b> ";
+
+ return result;
+}
+
BOOL SRMainFrame::OnCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl)
{
INT nTransID = 0;
@@ -208,6 +312,48 @@
SendMessage(m_hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)m_hWnd);
SendMessage (m_hWnd, WM_CLOSE, 0, 0);
exit(0);
+ case MENU_TEXT:
+ m_viewText->Show();
+ m_viewBook->Hide();
+ m_viewChapter->Hide();
+ m_viewVerse->Hide();
+ LoadTextView();
+ break;
+ case MENU_BOOK:
+ m_viewBook->Show();
+ m_viewChapter->Hide();
+ m_viewVerse->Hide();
+ m_viewText->Hide();
+ break;
+ case MENU_CHAP:
+ m_viewChapter->SetEndNumber(GetMaxChapters());
+ m_viewChapter->Show();
+ m_viewBook->Hide();
+ m_viewText->Hide();
+ m_viewVerse->Hide();
+ break;
+ case MENU_VERSE:
+ m_viewVerse->SetEndNumber(GetMaxVerses());
+ m_viewVerse->Show();
+ m_viewBook->Hide();
+ m_viewChapter->Hide();
+ m_viewText->Hide();
+ break;
+ case SR_SETBOOK:
+ if(newValue > BIBLE_OT_BOOKS){
+ m_keyCurVerse->Testament(SWORD_NEW_TESTAMENT);
+ m_keyCurVerse->Book(newValue - BIBLE_OT_BOOKS);
+ }else{
+ m_keyCurVerse->Testament(SWORD_OLD_TESTAMENT);
+ m_keyCurVerse->Book(newValue);
+ }
+ break;
+ case SR_SETCHAPTER:
+ m_keyCurVerse->Chapter(newValue);
+ break;
+ case SR_SETVERSE:
+ m_keyCurVerse->Verse(newValue);
+ break;
default:
// Check the custom made menu items...
nTransID = wID - MENU_TRANS_START;
@@ -219,34 +365,7 @@
}else if((nOptsID >= 0) && (nOptsID < m_menuBar->GetTotalOptions())){
ToggleOption(wID);
}else{
- switch(wID)
- {
- case MENU_TEXT:
- m_viewText->Show();
- m_viewChapter->Hide();
- m_viewVerse->Hide();
- break;
- case MENU_CHAP:
- m_viewChapter->SetEndNumber(GetMaxChapters());
- m_viewChapter->Show();
- m_viewText->Hide();
- m_viewVerse->Hide();
- break;
- case MENU_VERSE:
- m_viewVerse->SetEndNumber(GetMaxVerses());
- m_viewVerse->Show();
- m_viewChapter->Hide();
- m_viewText->Hide();
- break;
- case SR_SETCHAPTER:
- m_keyCurVerse->Chapter(newValue);
- break;
- case SR_SETVERSE:
- m_keyCurVerse->Verse(newValue);
- break;
- default:
- return FALSE;
- }
+ return FALSE;
}
}
return TRUE;
Modified: trunk/src/SwordReader_GUI/SRMainFrame.h
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.h 2008-04-27 03:09:29 UTC (rev 125)
+++ trunk/src/SwordReader_GUI/SRMainFrame.h 2008-04-28 01:19:18 UTC (rev 126)
@@ -11,6 +11,7 @@
#include "SRTextView.h"
#include "SRMenuBar.h"
#include "SRNumberChooser.h"
+#include "SRBookChooser.h"
// The one and only command bar.
#define SR_COMMAND_BAR_ID 0x0001
@@ -38,6 +39,9 @@
BOOL InitSword();
INT GetMaxChapters();
INT GetMaxVerses();
+ static const WCString *GetBookNames() { return s_wcsBookNames; }
+ void LoadTextView();
+ WCString GetVerseHeader(VerseKey key);
private:
INT m_nTotalOpts;
SWConfig *m_confOptions;
@@ -54,5 +58,7 @@
VerseKey *m_keyCurVerse;
SRNumberChooser *m_viewVerse;
SRNumberChooser *m_viewChapter;
- static BOOL m_fRegistered;
+ SRBookChooser *m_viewBook;
+ static WCString s_wcsBookNames[BIBLE_TOTAL_BOOKS];
+ static BOOL s_fRegistered;
};
Modified: trunk/src/SwordReader_GUI/SRNumberChooser.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.cpp 2008-04-27 03:09:29 UTC (rev 125)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.cpp 2008-04-28 01:19:18 UTC (rev 126)
@@ -1,13 +1,8 @@
#include "SRNumberChooser.h"
#include "SwordReaderResource.h"
-BOOL SRNumberChooser::m_fRegistered = false;
+BOOL SRNumberChooser::s_fRegistered = false;
-#define MAXNUMBERS (getMaxRows()*MAXHORIZONTAL)
-
-#define ROW0 5
-#define LASTROW ROW0+getMaxRows()*(BUTTON_HEIGHT+PADDING_HEIGHT)
-
SRNumberChooser::SRNumberChooser(ChooserType type, WCString wcsPrompt, WORD wNextMenuID)
:m_nEndNumber(0)
,m_nSelectedNumber(0)
@@ -39,7 +34,7 @@
{
// Register window class...
WNDCLASS wc;
- if(m_fRegistered)
+ if(s_fRegistered)
return TRUE;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_PARENTDC;
@@ -55,7 +50,7 @@
if(RegisterClass(&wc) == 0)
return FALSE;
- m_fRegistered = TRUE;
+ s_fRegistered = TRUE;
return TRUE;
}
Modified: trunk/src/SwordReader_GUI/SRNumberChooser.h
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.h 2008-04-27 03:09:29 UTC (rev 125)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.h 2008-04-28 01:19:18 UTC (rev 126)
@@ -32,7 +32,7 @@
WORD m_wNextMenuID;
ChooserType m_type;
WCString m_wcsPrompt;
- static BOOL m_fRegistered;
+ static BOOL s_fRegistered;
};
#endif
Modified: trunk/src/SwordReader_GUI/SRTextView.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRTextView.cpp 2008-04-27 03:09:29 UTC (rev 125)
+++ trunk/src/SwordReader_GUI/SRTextView.cpp 2008-04-28 01:19:18 UTC (rev 126)
@@ -25,7 +25,7 @@
#include "SRFramework/SRApp.h"
using namespace SRFramework;
-BOOL SRTextView::m_fRegistered = false;
+BOOL SRTextView::s_fRegistered = false;
VOID LOGTAG(const char *tag)
{
@@ -90,7 +90,7 @@
{
// Register window class...
WNDCLASS wc;
- if(m_fRegistered)
+ if(s_fRegistered)
return TRUE;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_PARENTDC;
@@ -107,7 +107,7 @@
if(RegisterClass(&wc) == 0)
return FALSE;
- m_fRegistered = TRUE;
+ s_fRegistered = TRUE;
return TRUE;
}
@@ -117,7 +117,7 @@
ShowWindow(m_hWnd, SW_SHOW);
// FOR COMPARATIVE PERFORMANCE TESTING...
// REMOVE ONCE INTEGRATED
- m_fPreRendered = FALSE;
+ //m_fPreRendered = FALSE;
UpdateWindow();
}
@@ -392,6 +392,8 @@
}
}
dwWordEnd++;
+ if(dwWordIndex + dwWordEnd > m_dwBuffEnd)
+ break;
}
if(m_lpszBuff[dwWordIndex + dwWordEnd] == '\n')
return BTEXT_NEWLINE_ENCOUNTERED;
@@ -441,7 +443,7 @@
m_BTLines.ClearLines();
m_BTLines.InitLines(nLineH);
-
+ int tmpI = 0;
while(TRUE){
thisWord.Clear();
rsState.m_space_encountered = FALSE;
@@ -462,7 +464,8 @@
rsState.m_dwSubWordNum = 0;
}else
rsState.m_dwSubWordNum++;
-
+ if(tmpI++ == 380)
+ tmpI = tmpI + 1;
dwResult = NextWord(rsState, dwWordIndex, dwWordEnd);
if(dwWordEnd == 0){
break;
@@ -875,10 +878,13 @@
VOID SRTextView::AddText(const TCHAR *szText, DWORD dwSize)
{
DWORD i = 0;
-
+ if(!m_dwBuffSize){
+ m_dwBuffSize = BTEXT_BUFF_INC > dwSize ? BTEXT_BUFF_INC : dwSize;
+ m_lpszBuff = new TCHAR[m_dwBuffSize];
+ }
// Do we need to make room for the new szText
if((m_dwBuffEnd + dwSize) > m_dwBuffSize){
- DWORD dwNewSize = BTEXT_BUFF_INC > dwSize ? BTEXT_BUFF_INC : dwSize;
+ DWORD dwNewSize = m_dwBuffSize + (BTEXT_BUFF_INC > dwSize ? BTEXT_BUFF_INC : dwSize);
TCHAR *lpszTmp = new TCHAR[dwNewSize];
for(i = 0; i < m_dwBuffSize; i++){
lpszTmp[i] = m_lpszBuff[i];
@@ -908,11 +914,13 @@
// Copy it in, and ignore the closing tags, if any
for(; i < dwSize; i++){
+ /*
// We arbitrarily choose to start looking at the last 100 characters for the tail end
// of this HTML stream. If we fail to chop it off its not the end of the world, but
// it would be nice to get out of the way now.
if(dwSize > 100 && i > (dwSize - 100) && wcsnicmp(&szText[i], L"</body>", 7) == 0)
break;
+ */
if(szText[i] == 0x09) // Horizontal tab, replace with a single space. (for now at least.)
m_lpszBuff[m_dwBuffEnd++] = ' ';
else if(szText[i] != '\n') // Ignore new-lines
Modified: trunk/src/SwordReader_GUI/SRTextView.h
===================================================================
--- trunk/src/SwordReader_GUI/SRTextView.h 2008-04-27 03:09:29 UTC (rev 125)
+++ trunk/src/SwordReader_GUI/SRTextView.h 2008-04-28 01:19:18 UTC (rev 126)
@@ -684,7 +684,7 @@
//! the current window layout.
BOOL m_fPreRendered;
- static BOOL m_fRegistered;
+ static BOOL s_fRegistered;
HFONT m_hFontCache[BTEXT_FONT_CACHE_MAX];
Modified: trunk/src/SwordReader_GUI/SwordReaderResource.h
===================================================================
--- trunk/src/SwordReader_GUI/SwordReaderResource.h 2008-04-27 03:09:29 UTC (rev 125)
+++ trunk/src/SwordReader_GUI/SwordReaderResource.h 2008-04-28 01:19:18 UTC (rev 126)
@@ -13,6 +13,15 @@
typedef std::map<const char*, sword::SWModule*, ltstr> ModuleMap;
+#define SWORD_OLD_TESTAMENT 1
+#define SWORD_NEW_TESTAMENT 2
+
+#define BIBLE_OT_BOOKS 39
+#define BIBLE_NT_BOOKS 27
+#define BIBLE_TOTAL_BOOKS BIBLE_OT_BOOKS + BIBLE_NT_BOOKS
+
+
+
#define MENU_TRANS_START 0x1000
#define MENU_OPTS_START 0x2000
#define WM_TXT_START WM_USER + 0x00F1
@@ -30,4 +39,6 @@
#define BUTTON_PADDING_WIDTH 3
#define BUTTON_PADDING_HEIGHT 3
+
+
#endif
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj
===================================================================
--- trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj 2008-04-27 03:09:29 UTC (rev 125)
+++ trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj 2008-04-28 01:19:18 UTC (rev 126)
@@ -642,6 +642,10 @@
>
</File>
<File
+ RelativePath=".\SRBookChooser.cpp"
+ >
+ </File>
+ <File
RelativePath=".\SRMainFrame.cpp"
>
</File>
@@ -703,6 +707,10 @@
>
</File>
<File
+ RelativePath=".\SRBookChooser.h"
+ >
+ </File>
+ <File
RelativePath=".\SRMainFrame.h"
>
</File>
More information about the sword-cvs
mailing list