[sword-svn] r142 - trunk/src/SwordReader_GUI

dtrotzjr at www.crosswire.org dtrotzjr at www.crosswire.org
Sun Jun 22 19:00:14 MST 2008


Author: dtrotzjr
Date: 2008-06-22 19:00:13 -0700 (Sun, 22 Jun 2008)
New Revision: 142

Modified:
   trunk/src/SwordReader_GUI/SRMainFrame.cpp
   trunk/src/SwordReader_GUI/SRMainFrame.h
   trunk/src/SwordReader_GUI/SRTextView.cpp
   trunk/src/SwordReader_GUI/SRTextView.h
Log:
Fixed several navigation issues.

Modified: trunk/src/SwordReader_GUI/SRMainFrame.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.cpp	2008-05-31 15:30:57 UTC (rev 141)
+++ trunk/src/SwordReader_GUI/SRMainFrame.cpp	2008-06-23 02:00:13 UTC (rev 142)
@@ -42,6 +42,7 @@
 ,m_viewVerse(NULL)
 ,m_viewBook(NULL)
 ,m_viewFind(NULL)
+,m_fChapterChanged(TRUE)
 {
     // Create a general options file for storing options 
 	// and navigaiton history
@@ -232,6 +233,11 @@
 	// Suspend user interaction until this page is fully loaded.
 	::PostThreadMessage(g_tMain, WM_TXT_START, NULL, NULL);
     */
+    if(!m_fChapterChanged) // This text should still be valid...
+        return;
+    else
+        m_fChapterChanged = false;
+
     m_viewText->Clear();
     VerseKey keyCur(m_keyCurVerse);
     //m_keyCurVerse->Verse(1);
@@ -372,38 +378,13 @@
             m_viewText->Hide();
             break;
         case SR_SETBOOK:
-            if(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{
-                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();
+            SetBook(newValue);
             break;
         case SR_SETCHAPTER:
-            if(m_keyCurVerse->Chapter() != newValue){
-                m_keyCurVerse->Chapter(newValue);
-                m_keyCurVerse->Verse(1);
-                UpdateWindowTitle();
-            }
+            SetChapter(newValue); 
             break;
         case SR_SETVERSE:
-            m_keyCurVerse->Verse(newValue);
-            if(wNotifyCode == SR_MSRC_CHOOSER)
-                m_viewText->ScrollToVerse(m_keyCurVerse->Verse());
-            UpdateWindowTitle();
+            SetVerse(newValue, wNotifyCode == SR_MSRC_CHOOSER);
             break;
         case SR_SETVERSEKEY:
             m_keyCurVerse->copyFrom(reinterpret_cast<VerseKey*>(hWndCtl));
@@ -427,6 +408,52 @@
     return TRUE;
 }
 
+
+VOID SRMainFrame::SetBook(INT nBook)
+{
+    if(nBook > BIBLE_OT_BOOKS){
+        if( m_keyCurVerse->Testament() != 2 ||
+                m_keyCurVerse->Book() + BIBLE_OT_BOOKS != nBook){
+            m_keyCurVerse->Testament(SWORD_NEW_TESTAMENT);
+            m_keyCurVerse->Book(nBook - BIBLE_OT_BOOKS);
+            m_keyCurVerse->Chapter(1);
+            m_keyCurVerse->Verse(1);
+        }
+    }else{
+        if( m_keyCurVerse->Testament() != 1 ||
+                m_keyCurVerse->Book != nBook){
+            m_keyCurVerse->Testament(SWORD_OLD_TESTAMENT);
+            m_keyCurVerse->Book(nBook);
+            m_keyCurVerse->Chapter(1);
+            m_keyCurVerse->Verse(1);
+        }
+    }
+    m_fChapterChanged = true;
+    UpdateWindowTitle();
+}
+
+
+VOID SRMainFrame::SetChapter(INT nChapter)
+{
+    if(m_keyCurVerse->Chapter() != nChapter){
+        m_keyCurVerse->Chapter(nChapter);
+        m_keyCurVerse->Verse(1);
+        m_fChapterChanged = true;
+        UpdateWindowTitle();
+    }
+}
+
+
+VOID SRMainFrame::SetVerse(INT nVerse, BOOL fScroll)
+{
+    if(nVerse < 0)
+        return; // This isn't a valid verse.
+    m_keyCurVerse->Verse(nVerse);
+    if(fScroll)
+        m_viewText->ScrollToVerse(m_keyCurVerse->Verse());
+    UpdateWindowTitle();
+}
+
 BOOL SRMainFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
 {
     INT a = 0;
@@ -434,23 +461,31 @@
     {
     case VK_UP:
         m_viewText->ScrollFullPage(1);
-        m_keyCurVerse->Verse(m_viewText->GetVerseNum());
+        if(m_viewText->GetVerseNum() > -1)
+            m_keyCurVerse->Verse(m_viewText->GetVerseNum());
         UpdateWindowTitle();
         break;
     case VK_DOWN:
         m_viewText->ScrollFullPage(-1);
-        m_keyCurVerse->Verse(m_viewText->GetVerseNum());
+        if(m_viewText->GetVerseNum() > -1)
+            m_keyCurVerse->Verse(m_viewText->GetVerseNum());
         UpdateWindowTitle();
         break;
     case VK_LEFT:
-        if(m_keyCurVerse->Verse() > 1)
+        if(m_keyCurVerse->Verse() > 1){
             m_keyCurVerse->Verse(1);
-        else
-            m_keyCurVerse->Chapter(m_keyCurVerse->Chapter() - 1);
-        LoadTextView();
+            m_viewText->ScrollToVerse(1);
+        }else{
+            m_keyCurVerse->decrement(1);
+            m_keyCurVerse->Verse(1);
+            m_fChapterChanged = true;
+            LoadTextView();
+        }
+        UpdateWindowTitle();
         break;
     case VK_RIGHT:
         m_keyCurVerse->Chapter(m_keyCurVerse->Chapter() + 1);
+        m_fChapterChanged = true;
         LoadTextView();
         break;
     default:
@@ -466,8 +501,10 @@
     for(int i = 0; i < nModIndex; i++)
         it++;
     m_modCurText = it->second;
-    if(tmp != m_modCurText)
+    if(tmp != m_modCurText){
+        m_fChapterChanged = true;
         LoadTextView();
+    }
 }
 
 BOOL SRMainFrame::GetSupportedOptions()
@@ -529,9 +566,11 @@
                 val = (val == "On") ? "Off" : "On";
                 m_swmgr->setGlobalOption(m_bufModOptions[i], val);
                 m_menuBar->CheckOptionsMenuItem(wID, (val == "On"));
+                m_fChapterChanged = true;
             }
         }
     }
+    LoadTextView();
 }
 
 void SRMainFrame::UpdateWindowTitle()
@@ -559,4 +598,4 @@
     VerseKey ref(m_keyCurVerse);
     ref = MAXVERSE;
     return ref.Verse();
-}
\ No newline at end of file
+}

Modified: trunk/src/SwordReader_GUI/SRMainFrame.h
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.h	2008-05-31 15:30:57 UTC (rev 141)
+++ trunk/src/SwordReader_GUI/SRMainFrame.h	2008-06-23 02:00:13 UTC (rev 142)
@@ -44,6 +44,9 @@
     void LoadTextView();
     WCString GetVerseHeader(VerseKey key);
     BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
+    VOID SetBook(INT nBook);
+    VOID SetChapter(INT nChapter);
+    VOID SetVerse(INT nVerse, BOOL fScroll);
 private:
     INT           m_nTotalOpts;
     SWConfig     *m_confOptions;
@@ -62,6 +65,7 @@
     SRNumberChooser *m_viewChapter;
     SRBookChooser   *m_viewBook;
     SRFind          *m_viewFind;
+    BOOL          m_fChapterChanged;
     static WCString s_wcsBookNames[BIBLE_TOTAL_BOOKS];
     static BOOL s_fRegistered;
 };

Modified: trunk/src/SwordReader_GUI/SRTextView.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRTextView.cpp	2008-05-31 15:30:57 UTC (rev 141)
+++ trunk/src/SwordReader_GUI/SRTextView.cpp	2008-06-23 02:00:13 UTC (rev 142)
@@ -917,7 +917,7 @@
 }
 
 
-WORD SRTextView::GetVerseNum()
+INT SRTextView::GetVerseNum()
 {
     return m_BTLines.GetVerseAt(m_nTop);
 }
@@ -1147,13 +1147,15 @@
 INT SRTextView::SRTextLines::GetVersePosition(WORD wVerseNum)
 {
     for(DWORD i = 0; i < m_dwLastLine; i++){
+        if(!m_lppLinesLastWord[i]->m_lpPrevWord)
+            continue; // We hit a blank line (not neccesarrily the end).
         if(m_lppLinesLastWord[i]->m_lpPrevWord->m_wVerseNum == wVerseNum)
             return m_lppLinesLastWord[i]->m_lpPrevWord->m_rect.top;
     }
     return -1;
 }
 
-WORD SRTextView::SRTextLines::GetVerseAt(INT yPos)
+INT SRTextView::SRTextLines::GetVerseAt(INT yPos)
 {
     for(DWORD i = 0; i < m_dwLastLine; i++){
         if(!m_lppLinesLastWord[i]->m_lpPrevWord)

Modified: trunk/src/SwordReader_GUI/SRTextView.h
===================================================================
--- trunk/src/SwordReader_GUI/SRTextView.h	2008-05-31 15:30:57 UTC (rev 141)
+++ trunk/src/SwordReader_GUI/SRTextView.h	2008-06-23 02:00:13 UTC (rev 142)
@@ -295,7 +295,7 @@
         /*! @param yPos the y coordinate of the line we want the verse number for.
             @return the verse number correpsonding to the y coordinate.
         */
-        WORD    GetVerseAt(INT yPos);
+        INT    GetVerseAt(INT yPos);
         //! Indicates the total number of lines currently allocated.
         DWORD           m_dwLines;
         //! Indicates the last line actually being used,
@@ -467,7 +467,7 @@
     /*! @return the verse number of the word at the end of the top line 
         visible in the window.
     */
-    WORD GetVerseNum();
+    INT GetVerseNum();
 	
     // Friend classes, not needed in Visual Studio 2005
 	// but needed in eVC 3




More information about the sword-cvs mailing list