[sword-svn] r136 - in trunk/src/SwordReader_GUI: . SRFramework
dtrotzjr at www.crosswire.org
dtrotzjr at www.crosswire.org
Thu May 22 20:40:03 MST 2008
Author: dtrotzjr
Date: 2008-05-22 20:40:02 -0700 (Thu, 22 May 2008)
New Revision: 136
Modified:
trunk/src/SwordReader_GUI/SRFind.cpp
trunk/src/SwordReader_GUI/SRFind.h
trunk/src/SwordReader_GUI/SRFramework/SRCommandBar.cpp
trunk/src/SwordReader_GUI/SRMainFrame.cpp
trunk/src/SwordReader_GUI/SRTextView.cpp
trunk/src/SwordReader_GUI/SwordReaderResource.h
Log:
Find now works. Overall rewrite progress 95%...
Modified: trunk/src/SwordReader_GUI/SRFind.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRFind.cpp 2008-05-21 05:00:46 UTC (rev 135)
+++ trunk/src/SwordReader_GUI/SRFind.cpp 2008-05-23 03:40:02 UTC (rev 136)
@@ -1,6 +1,7 @@
#include "SRFind.h"
#include "SRFramework/SRApp.h"
#include "SwordReaderResource.h"
+#include "SRMainFrame.h"
using namespace SRFramework;
using namespace sword;
@@ -14,7 +15,7 @@
caller->SetProgress((int)percent);
}
-SRFind::SRFind()
+SRFind::SRFind(const VerseKey *keyReference, SWModule **modCurText)
:m_hEdtQuery(NULL)
,m_hBtnSearch(NULL)
,m_hRadRangeBible(NULL)
@@ -28,6 +29,8 @@
,m_textPreview(NULL)
,m_wMethodMode(SR_FIND_METHOD_MWORD)
,m_wRangeMode(SR_FIND_RANGE_BIBLE)
+,m_keyReference(keyReference)
+,m_modCurText(modCurText)
{
m_wcsClassName = "SRFind";
m_wcsWindowName = "Sword Search Window";
@@ -41,16 +44,28 @@
VOID SRFind::SetProgress(INT nPercent)
{
- SendMessage(m_hProgressBar, PBM_SETPOS, nPercent, 0);
+ ::SendMessage(m_hProgressBar, PBM_SETPOS, nPercent, 0);
}
-VOID SRFind::AddResult(WCString &wcsVerse, SWModule *text)
+VOID SRFind::AddResult(WCString &wcsVerse)
{
+ wchar_t wverse[16] = {0};
+ wchar_t wchapt[16] = {0};
VerseKey* verse = new VerseKey(wcsVerse.c_str());
+
+ WCString wcsReference =
+ SRMainFrame::GetBookNames()[(verse->Book() - 1) + BIBLE_OT_BOOKS*(verse->Testament() - 1)];
+ wcsReference +=
+ WCString(" ")
+ + WCString(_itow(verse->Chapter(),wchapt, 10))
+ + WCString(":")
+ + WCString(_itow(verse->Verse(), wverse, 10));
+
+
m_verseResults.push_back(*verse);
- text->SetKey(verse);
- WCString verseString = text->StripText();
- SendMessage (m_hLstResults, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)verseString.w_str());
+ //(*m_modCurText)->SetKey(verse);
+ //WCString verseString = (*m_modCurText)->StripText();
+ ::SendMessage (m_hLstResults, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)wcsReference.w_str());
delete verse;
}
@@ -59,6 +74,7 @@
switch(wID)
{
case IDC_BTN_SEARCH:
+ Search();
break;
case IDC_RAD_BIBLE:
::SendMessage(m_hRadRangeBible,BM_SETCHECK,BST_CHECKED,0);
@@ -89,8 +105,10 @@
m_wMethodMode = SR_FIND_METHOD_EPHRASE;
break;
case IDC_LST_RESULTS:
+ ShowPreview();
break;
case IDC_BTN_GOTO:
+ GoToVerse();
break;
default:
return FALSE;
@@ -98,6 +116,29 @@
return TRUE;
}
+VOID SRFind::ShowPreview()
+{
+ int pos = ::SendMessage(m_hLstResults, LB_GETCURSEL, 0, 0);
+ if(pos == LB_ERR)
+ return;
+ VerseKey keyPreview = m_verseResults[pos];
+ (*m_modCurText)->SetKey(keyPreview);
+ m_textPreview->Clear();
+ WCString wcsPreview = (*m_modCurText)->StripText();
+ m_textPreview->AddText(wcsPreview.w_str(), wcsPreview.length());
+ m_textPreview->UpdateWindow();
+
+}
+
+VOID SRFind::GoToVerse()
+{
+ int pos = ::SendMessage(m_hLstResults, LB_GETCURSEL, 0, 0);
+ if(pos == LB_ERR)
+ return;
+ ::SendMessage(m_pParentWnd->GetWindowHandle(), WM_COMMAND, SR_SETVERSEKEY,(LPARAM)&m_verseResults[pos]);
+ ::SendMessage(m_pParentWnd->GetWindowHandle(), WM_COMMAND, MENU_TEXT,0);
+}
+
BOOL SRFind::OnPaint()
{
RECT clientRect;
@@ -290,4 +331,65 @@
return FALSE;
return TRUE;
+}
+
+VOID SRFind::Search()
+{
+ TCHAR *strQuery = NULL;
+ INT nQueryLen = ::SendMessage(m_hEdtQuery, WM_GETTEXTLENGTH, NULL, NULL) + 1;
+ strQuery = new TCHAR[nQueryLen];
+ ::SendMessage(m_hEdtQuery,WM_GETTEXT,(WPARAM)nQueryLen,(LPARAM)strQuery);
+ strQuery[nQueryLen - 1] = 0; // in case the buffer was exceeded
+
+ // Clone is a bit dangerous, it creates a new SWKey which has to be deleted
+ // thus you cannot simply pass the cloned object to the constructor of
+ // a VerseKey object.
+ SWKey *tmp = m_keyReference->clone();
+ VerseKey from(tmp);
+ VerseKey to(tmp);
+ delete tmp;
+
+ ClearForm();
+
+ if (m_wRangeMode == SR_FIND_RANGE_BIBLE)
+ from.Testament(1);
+ if ((m_wRangeMode == SR_FIND_RANGE_TESTAMENT)||(m_wRangeMode == SR_FIND_RANGE_BIBLE))
+ from.Book(1);
+
+ from.Chapter(1);
+ from.Verse(1);
+ if (m_wRangeMode == SR_FIND_RANGE_BIBLE)
+ to.Testament(2);
+ if ((m_wRangeMode == SR_FIND_RANGE_TESTAMENT)||(m_wRangeMode == SR_FIND_RANGE_BIBLE))
+ to.Book((to.Testament() == 2) ?
+ BIBLE_NT_BOOKS :
+ BIBLE_OT_BOOKS);
+
+ to.Chapter(to.books[to.Testament() - 1][to.Book() - 1].chapmax);
+ to.Verse(to.books[to.Testament() - 1][to.Book() - 1].versemax[to.Chapter() - 1]);
+
+ VerseKey verses(from,to);
+ sword::ListKey results;
+
+ results = (*m_modCurText)->search(WCString(strQuery).c_str(),
+ (m_wMethodMode == SR_FIND_METHOD_MWORD) ? -2: -1,
+ 2, &verses, 0, setPercentCB, (void*)this);
+ SetProgress(100);
+
+ results = TOP;
+ for (int i = 0; !results.Error() && i < results.Count(); i++, results++) {
+ AddResult(WCString(results.getText()));
+ }
+
+ delete [] strQuery;
+}
+
+VOID SRFind::ClearForm()
+{
+ WCString wcsPreview = "preview";
+ SetProgress(0);
+ ::SendMessage (m_hLstResults, LB_RESETCONTENT,0,0);
+ m_textPreview->Clear();
+ m_textPreview->AddText(wcsPreview.w_str(), wcsPreview.length());
+ m_verseResults.clear();
}
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SRFind.h
===================================================================
--- trunk/src/SwordReader_GUI/SRFind.h 2008-05-21 05:00:46 UTC (rev 135)
+++ trunk/src/SwordReader_GUI/SRFind.h 2008-05-23 03:40:02 UTC (rev 136)
@@ -39,7 +39,7 @@
public SRFramework::SRWnd
{
public:
- SRFind();
+ SRFind(const sword::VerseKey *keyReference, sword::SWModule **modCurText);
~SRFind();
BOOL Register();
BOOL Create(SRWnd *pParentWnd, RECT bounds);
@@ -48,7 +48,11 @@
VOID PlaceWidgets();
BOOL OnCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl);
VOID SetProgress(INT nPercent);
- VOID AddResult(WCString &wcsVerse, sword::SWModule *text);
+ VOID AddResult(WCString &wcsVerse);
+ VOID Search();
+ VOID ClearForm();
+ VOID ShowPreview();
+ VOID GoToVerse();
private:
static BOOL s_fRegistered;
HWND m_hEdtQuery;
@@ -64,6 +68,8 @@
SRTextView *m_textPreview;
WORD m_wRangeMode;
WORD m_wMethodMode;
+ const sword::VerseKey *m_keyReference;
+ sword::SWModule **m_modCurText;
std::vector<sword::VerseKey> m_verseResults;
};
Modified: trunk/src/SwordReader_GUI/SRFramework/SRCommandBar.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRFramework/SRCommandBar.cpp 2008-05-21 05:00:46 UTC (rev 135)
+++ trunk/src/SwordReader_GUI/SRFramework/SRCommandBar.cpp 2008-05-23 03:40:02 UTC (rev 136)
@@ -54,9 +54,9 @@
HMENU SRCommandBar::GetSubMenu(UINT nPos)
{
TBBUTTON tb = {0};
- SendMessage(m_hWndCB, TB_GETBUTTON, nPos, (LPARAM)&tb);
+ ::SendMessage(m_hWndCB, TB_GETBUTTON, nPos, (LPARAM)&tb);
- return (HMENU)SendMessage(m_hWndCB,SHCMBM_GETSUBMENU, 0, tb.idCommand);
+ return (HMENU)::SendMessage(m_hWndCB,SHCMBM_GETSUBMENU, 0, tb.idCommand);
}
Modified: trunk/src/SwordReader_GUI/SRMainFrame.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.cpp 2008-05-21 05:00:46 UTC (rev 135)
+++ trunk/src/SwordReader_GUI/SRMainFrame.cpp 2008-05-23 03:40:02 UTC (rev 136)
@@ -136,7 +136,7 @@
if(!m_viewChapter->Create(this, view_rect))
return FALSE;
- m_viewFind = new SRFind();
+ m_viewFind = new SRFind(this->m_keyCurVerse, &(this->m_modCurText));
if(!m_viewFind->Create(this, view_rect))
return FALSE;
@@ -221,16 +221,16 @@
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);
+ ::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);
+ ::PostThreadMessage(g_tMain, WM_TXT_START, NULL, NULL);
*/
m_viewText->Clear();
VerseKey keyCur(m_keyCurVerse);
@@ -285,13 +285,13 @@
/*
// 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);
+ ::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();
@@ -327,15 +327,15 @@
switch(wID) {
case IDOK:
- SendMessage(m_hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)m_hWnd);
- SendMessage (m_hWnd, WM_CLOSE, 0, 0);
+ ::SendMessage(m_hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)m_hWnd);
+ ::SendMessage (m_hWnd, WM_CLOSE, 0, 0);
break;
case MENU_ABOUT:
- MessageBox(0, L"Sword reader program for Pocket PC ver. 1.0.1\n\nsee: http://www.crosswire.org/sword/swordreader/\n\nGUI by Johan Gorter, 2004\nNow being maintained by B. Drake, Robin Randall and David Trotz\nProverbs 16:3", L"About", MB_OK);
+ ::MessageBox(0, L"Sword reader program for Pocket PC ver. 1.0.1\n\nsee: http://www.crosswire.org/sword/swordreader/\n\nGUI by Johan Gorter, 2004\nNow being maintained by B. Drake, Robin Randall and David Trotz\nProverbs 16:3", L"About", MB_OK);
break;
case MENU_SHUTDOWN:
- SendMessage(m_hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)m_hWnd);
- SendMessage (m_hWnd, WM_CLOSE, 0, 0);
+ ::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();
@@ -343,7 +343,7 @@
m_viewChapter->Hide();
m_viewVerse->Hide();
m_viewFind->Hide();
- //LoadTextView();
+ LoadTextView();
break;
case MENU_BOOK:
m_viewBook->Show();
@@ -377,16 +377,31 @@
break;
case SR_SETBOOK:
if(newValue > BIBLE_OT_BOOKS){
- m_keyCurVerse->Testament(SWORD_NEW_TESTAMENT);
- m_keyCurVerse->Book(newValue - BIBLE_OT_BOOKS);
+ if( m_keyCurVerse->Testament() != 2 ||
+ m_keyCurVerse->Book() + BIBLE_OT_BOOKS != newValue){
+ m_keyCurVerse->Testament(SWORD_NEW_TESTAMENT);
+ m_keyCurVerse->Book(newValue - BIBLE_OT_BOOKS);
+ m_keyCurVerse->Chapter(1);
+ m_keyCurVerse->Verse(1);
+ }
+
}else{
- m_keyCurVerse->Testament(SWORD_OLD_TESTAMENT);
- m_keyCurVerse->Book(newValue);
+ if( m_keyCurVerse->Testament() != 1 ||
+ m_keyCurVerse->Book != newValue){
+ m_keyCurVerse->Testament(SWORD_OLD_TESTAMENT);
+ m_keyCurVerse->Book(newValue);
+ m_keyCurVerse->Chapter(1);
+ m_keyCurVerse->Verse(1);
+ }
}
+ UpdateWindowTitle();
break;
case SR_SETCHAPTER:
- m_keyCurVerse->Chapter(newValue);
- UpdateWindowTitle();
+ if(m_keyCurVerse->Chapter() != newValue){
+ m_keyCurVerse->Chapter(newValue);
+ m_keyCurVerse->Verse(1);
+ UpdateWindowTitle();
+ }
break;
case SR_SETVERSE:
m_keyCurVerse->Verse(newValue);
@@ -394,6 +409,11 @@
m_viewText->ScrollToVerse(m_keyCurVerse->Verse());
UpdateWindowTitle();
break;
+ case SR_SETVERSEKEY:
+ m_keyCurVerse->copyFrom(reinterpret_cast<VerseKey*>(hWndCtl));
+ UpdateWindowTitle();
+ LoadTextView();
+ break;
default:
// Check the custom made menu items...
nTransID = wID - MENU_TRANS_START;
Modified: trunk/src/SwordReader_GUI/SRTextView.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRTextView.cpp 2008-05-21 05:00:46 UTC (rev 135)
+++ trunk/src/SwordReader_GUI/SRTextView.cpp 2008-05-23 03:40:02 UTC (rev 136)
@@ -143,6 +143,10 @@
VOID SRTextView::MoveWindow(INT x, INT y, INT w, INT h)
{
+ m_rect.top = x;
+ m_rect.bottom = x + h;
+ m_rect.left = y;
+ m_rect.right = y + w;
::MoveWindow(m_hWnd, x, y, w, h, FALSE);
}
@@ -434,7 +438,7 @@
DWORD dwWordIndex = 0;
DWORD dwWordEnd = 0;
INT nSpaceWidth = rectDims.right - rectDims.left;
- INT nScreenWidth= GetSystemMetrics(SM_CXSCREEN) - BTEXT_MARGIN;
+ INT nScreenWidth= (m_rect.right - m_rect.left) - BTEXT_MARGIN;
DWORD dwResult = 0;
INT nAddLines = 0;
DWORDLONG dwlFontState= 0;
Modified: trunk/src/SwordReader_GUI/SwordReaderResource.h
===================================================================
--- trunk/src/SwordReader_GUI/SwordReaderResource.h 2008-05-21 05:00:46 UTC (rev 135)
+++ trunk/src/SwordReader_GUI/SwordReaderResource.h 2008-05-23 03:40:02 UTC (rev 136)
@@ -47,6 +47,7 @@
#define SR_SETBOOK 0x00FB
#define SR_SETCHAPTER 0x00FC
#define SR_SETVERSE 0x00FD
+#define SR_SETVERSEKEY 0x00FE
// These help determine the source of the
// SR_SETVERSE OnCommand Message
More information about the sword-cvs
mailing list