[sword-svn] r124 - in trunk/src/SwordReader_GUI: . SRFramework

dtrotzjr at www.crosswire.org dtrotzjr at www.crosswire.org
Fri Apr 25 16:23:00 MST 2008


Author: dtrotzjr
Date: 2008-04-25 16:22:59 -0700 (Fri, 25 Apr 2008)
New Revision: 124

Modified:
   trunk/src/SwordReader_GUI/SRFramework/SRWnd.cpp
   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
Log:
SRNumberChooser works now.

Modified: trunk/src/SwordReader_GUI/SRFramework/SRWnd.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRFramework/SRWnd.cpp	2008-04-24 03:35:00 UTC (rev 123)
+++ trunk/src/SwordReader_GUI/SRFramework/SRWnd.cpp	2008-04-25 23:22:59 UTC (rev 124)
@@ -1,6 +1,7 @@
 #include "SRWnd.h"
 using namespace SRFramework;
 
+
 SRWnd::SRWnd()
 {
     m_dwStyle = 0;

Modified: trunk/src/SwordReader_GUI/SRMainFrame.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.cpp	2008-04-24 03:35:00 UTC (rev 123)
+++ trunk/src/SwordReader_GUI/SRMainFrame.cpp	2008-04-25 23:22:59 UTC (rev 124)
@@ -4,6 +4,8 @@
 
 using namespace sword;
 
+BOOL SRMainFrame::m_fRegistered = false;
+
 namespace sword {
 	char *SWBuf::nullStr = "";
 }
@@ -23,6 +25,8 @@
 ,m_nTotalOpts(0)
 ,m_swmgr(NULL)
 ,m_viewText(NULL)
+,m_viewChapter(NULL)
+,m_viewVerse(NULL)
 {
     // Create a general options file for storing options 
 	// and navigaiton history
@@ -37,7 +41,6 @@
     m_hInstance = SRFramework::SRApp::GetInstanceHandle();
     m_swmgr = new SWMgr(new sword::MarkupFilterMgr(sword::FMT_HTMLHREF, sword::ENC_UTF16));
 
-    
 }
 
 SRMainFrame::~SRMainFrame()
@@ -51,6 +54,8 @@
 BOOL SRMainFrame::Register()
 {
     WNDCLASS wc;
+    if(m_fRegistered)
+        return TRUE;
 
     wc.style = CS_HREDRAW | CS_VREDRAW;
     wc.lpfnWndProc = MessageRoute;
@@ -65,6 +70,9 @@
 
     if(RegisterClass(&wc) == 0) 
         return FALSE;
+    
+    m_fRegistered = TRUE;
+
     return TRUE;
 }
 
@@ -94,16 +102,28 @@
     m_viewText = new SRTextView();
     if(!m_viewText->Create(this, view_rect))
         return FALSE;
-    //m_viewText->Show();
-    m_viewText->Hide();
+    m_viewText->Show();
+    
+    /* The following should be removed... */
     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();
+
+    m_viewVerse = new SRNumberChooser("Select a Verse:",MENU_TEXT);
     if(!m_viewVerse->Create(this, view_rect))
         return FALSE;
-    m_viewVerse->Show();
 
+    m_viewChapter = new SRNumberChooser("Select a Chapter:",MENU_VERSE);
+    if(!m_viewChapter->Create(this, view_rect))
+        return FALSE;
+
+    m_viewText->Show();
+    m_viewChapter->Hide();
+    m_viewVerse->Hide();
+
+    m_viewChapter->SetEndNumber(130);
+    m_viewVerse->SetEndNumber(13);
+    
     return TRUE;
 }
 
@@ -196,8 +216,31 @@
                 break;
             }else if((nOptsID >= 0) && (nOptsID < m_menuBar->GetTotalOptions())){
                 ToggleOption(wID);
-            }else
-                return FALSE;
+            }else{
+                switch(wID)
+                {
+                case MENU_TEXT:
+                    m_viewText->Show();
+                    m_viewChapter->Hide();
+                    m_viewVerse->Hide();
+                    break;
+                case MENU_CHAP:
+                    m_viewChapter->SetEndNumber(m_keyCurVerse->books[m_keyCurVerse->Book()]->chapmax);
+                    m_viewChapter->Show();
+                    m_viewText->Hide();
+                    m_viewVerse->Hide();
+                    break;
+                case MENU_VERSE:
+                    m_keyCurVerse->Verse(MAXVERSE);
+                    m_viewVerse->SetEndNumber(m_keyCurVerse->Verse());
+                    m_viewVerse->Show();
+                    m_viewChapter->Hide();
+                    m_viewText->Hide();
+                    break;
+                default:
+                    return FALSE;
+                }
+            }
     }
     return TRUE;
 }

Modified: trunk/src/SwordReader_GUI/SRMainFrame.h
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.h	2008-04-24 03:35:00 UTC (rev 123)
+++ trunk/src/SwordReader_GUI/SRMainFrame.h	2008-04-25 23:22:59 UTC (rev 124)
@@ -40,7 +40,6 @@
     SWBuf        *m_bufModOptions;
     SRMenuBar    *m_menuBar;
     SRTextView   *m_viewText;
-    SRNumberChooser *m_viewVerse;
 	SWMgr        *m_swmgr;
     ModuleMap    *m_modTexts;
     SWModule     *m_modCurText;
@@ -49,4 +48,7 @@
     SWModule     *m_modHebrewLex;
     SWModule     *m_modHebrewMorph;
     VerseKey     *m_keyCurVerse;
+    SRNumberChooser *m_viewVerse;
+    SRNumberChooser *m_viewChapter;
+    static BOOL m_fRegistered;
 };

Modified: trunk/src/SwordReader_GUI/SRNumberChooser.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.cpp	2008-04-24 03:35:00 UTC (rev 123)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.cpp	2008-04-25 23:22:59 UTC (rev 124)
@@ -1,21 +1,22 @@
 #include "SRNumberChooser.h"
 #include "SwordReaderResource.h"
 
+BOOL SRNumberChooser::m_fRegistered = false;
 
 #define MAXNUMBERS (getMaxRows()*MAXHORIZONTAL)
 
 #define ROW0 5
 #define LASTROW ROW0+getMaxRows()*(BUTTON_HEIGHT+PADDING_HEIGHT)
 
-SRNumberChooser::SRNumberChooser()
+SRNumberChooser::SRNumberChooser(WCString wcsPrompt, WORD wNextMenuID)
 :m_nEndNumber(0)
 ,m_nSelectedNumber(0)
 ,m_nStartAt(1)
+,m_wcsPrompt(wcsPrompt)
+,m_wNextMenuID(wNextMenuID)
 {   
-    m_nEndNumber = 120; // REMOVE ME!!!!!!
     m_wcsClassName = "SRNumberChooser";
     m_wcsWindowName = "Number Chooser";
-    m_wcsPrompt = "Choose a number:";
 }
 
 BOOL SRNumberChooser::Create(SRWnd *pParentWnd, RECT bounds)
@@ -37,6 +38,9 @@
 {
     // Register window class...
     WNDCLASS    wc;
+    if(m_fRegistered)
+        return TRUE;
+
     wc.style            = CS_HREDRAW | CS_VREDRAW | CS_PARENTDC;
     wc.lpfnWndProc      = (WNDPROC) MessageRoute;
     wc.cbClsExtra       = 0;
@@ -50,40 +54,47 @@
 
     if(RegisterClass(&wc) == 0) 
         return FALSE;
-    
+    m_fRegistered = TRUE;
+
     return TRUE;
 }
 
-INT SRNumberChooser::GetMaxCols()
+INT SRNumberChooser::MaxCols()
 {
     RECT clientRect;
     ::GetClientRect(m_hWnd,&clientRect);
     return ( ((clientRect.right  - BUTTON_PADDING_WIDTH) - clientRect.left)/(BUTTON_PADDING_WIDTH + BUTTON_WIDTH_NUMBER) );
 }
 
-INT SRNumberChooser::GetMaxRows()
+INT SRNumberChooser::MaxRows()
 {
     RECT clientRect;
+    INT nMaxNumbers = 0; 
+    INT nMaxRows = 0;
     ::GetClientRect(m_hWnd,&clientRect);
+    
     // 2 less rows due to the Prompt and the More Prev buttons.
-    return ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT) ) - 2;
+    nMaxRows =  ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT) ) - 2;
+    nMaxNumbers =  MaxCols() * nMaxRows;
+
+    if(m_nStartAt == 1 && m_nEndNumber <= nMaxNumbers + MaxCols())
+        nMaxRows++; // We can fit another row since there is no need for a More or Prev button.
+    return nMaxRows;
+
 }
 
-INT SRNumberChooser::GetMaxNumbersPerScreen()
+INT SRNumberChooser::MaxNumbersPerScreen()
 {
-    INT nMaxNumbers =  GetMaxCols() * GetMaxRows();
-    if(m_nEndNumber <= nMaxNumbers + GetMaxCols())
-        nMaxNumbers += GetMaxCols(); // We can fit another row since there is no More button.
-    return nMaxNumbers;
+    return MaxCols() * MaxRows();
 }
 
 // Tries to center the buttons by calculating a left edge
-INT SRNumberChooser::GetLeftEdge()
+INT SRNumberChooser::LeftEdge()
 {
     RECT clientRect;
     GetClientRect(m_hWnd, &clientRect);
     return ((clientRect.right - clientRect.left)/2) - 
-        ((GetMaxCols()*BUTTON_WIDTH_NUMBER + (GetMaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
+        ((MaxCols()*BUTTON_WIDTH_NUMBER + (MaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
 }
 BOOL SRNumberChooser::OnPaint() {
 	TCHAR buttonText[4];
@@ -94,8 +105,8 @@
     PAINTSTRUCT ps;
     INT nRow;
     INT nCol;
-    INT nMaxCols = GetMaxCols();
-    INT nMaxRows = GetMaxRows();
+    INT nMaxCols = MaxCols();
+    INT nMaxRows = MaxRows();
 
     HDC hdc = BeginPaint(m_hWnd, &ps);
     
@@ -105,15 +116,15 @@
     
     // Draw the prompt.
     buttonRect.top = BUTTON_PADDING_HEIGHT;
-    buttonRect.left = GetLeftEdge();
-    buttonRect.right = clientRect.right - GetLeftEdge();
+    buttonRect.left = LeftEdge();
+    buttonRect.right = clientRect.right - LeftEdge();
     buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
     DrawText(hdc, m_wcsPrompt.w_str(), -1, &buttonRect, DT_CENTER | DT_VCENTER);
 
     // Init the first button's bounds
     buttonRect.top = 2*BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT;
     buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
-    buttonRect.left = GetLeftEdge();
+    buttonRect.left = LeftEdge();
     buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
     
     SetBkColor(hdc, BUTTON_BACKGROUND);
@@ -132,7 +143,7 @@
 
         }
         // Move the bounds down and all the way back to the left.
-        buttonRect.left = GetLeftEdge();
+        buttonRect.left = LeftEdge();
         buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
         buttonRect.top += BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT;
         buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
@@ -142,7 +153,7 @@
     
     // If we didn't reach the end we need to draw the More button...
     if(nCurrent < m_nEndNumber){
-        buttonRect.left = clientRect.right - (BUTTON_WIDTH_MORE + GetLeftEdge());
+        buttonRect.left = clientRect.right - (BUTTON_WIDTH_MORE + LeftEdge());
         buttonRect.right = buttonRect.left + BUTTON_WIDTH_MORE;
         buttonRect.top = clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
         buttonRect.bottom = clientRect.bottom - BUTTON_PADDING_HEIGHT;
@@ -152,7 +163,7 @@
     }
     // We are not on the first page of numbers we need to draw a Prev button...
     if(m_nStartAt != 1){
-        buttonRect.left = GetLeftEdge();
+        buttonRect.left = LeftEdge();
         buttonRect.right = buttonRect.left + BUTTON_WIDTH_MORE;
         buttonRect.top = clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
         buttonRect.bottom = clientRect.bottom - BUTTON_PADDING_HEIGHT;
@@ -178,7 +189,7 @@
     INT nRows = (y - BUTTON_PADDING_HEIGHT)/ (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT) - 1;
     GetClientRect(m_hWnd, &clientRect);
     // I ignore the minimal amount of white space between the buttons.
-    INT nNumber = m_nStartAt + (nRows * GetMaxCols()) + nCols; 
+    INT nNumber = m_nStartAt + (nRows * MaxCols()) + nCols; 
     
     if(y < BUTTON_HEIGHT + 2*BUTTON_PADDING_HEIGHT)
         return -2; // Tapped the title area.
@@ -187,13 +198,13 @@
     if(y > clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT) ){
         if(x > BUTTON_PADDING_WIDTH && x < BUTTON_PADDING_WIDTH + BUTTON_WIDTH_MORE){
             return -1;
-        }else if( (x > (GetMaxCols()*(BUTTON_WIDTH_NUMBER+BUTTON_PADDING_WIDTH) - BUTTON_WIDTH_MORE)) &&
-                  (x < (GetMaxCols()*(BUTTON_WIDTH_NUMBER+BUTTON_PADDING_WIDTH))) ){
+        }else if( (x > (MaxCols()*(BUTTON_WIDTH_NUMBER+BUTTON_PADDING_WIDTH) - BUTTON_WIDTH_MORE)) &&
+                  (x < (MaxCols()*(BUTTON_WIDTH_NUMBER+BUTTON_PADDING_WIDTH))) ){
             return 0;
         }else
             return -2;
     }
-    if(nNumber > m_nEndNumber || nNumber >= m_nStartAt + GetMaxNumbersPerScreen())
+    if(nNumber > m_nEndNumber || nNumber >= m_nStartAt + MaxNumbersPerScreen())
         return -2;
 
     return nNumber;
@@ -203,17 +214,17 @@
 {
     TCHAR buf[16] = {0};
     INT found = NumberAt(xPos, yPos);
-    if(found == 0 && (m_nStartAt + GetMaxNumbersPerScreen() <= m_nEndNumber) ){
-        m_nStartAt += GetMaxNumbersPerScreen();
+    if(found == 0 && (m_nStartAt + MaxNumbersPerScreen() <= m_nEndNumber) ){
+        m_nStartAt += MaxNumbersPerScreen();
         RefreshWindow();
     }else if(found == -1 && m_nStartAt != 1){
-        m_nStartAt -= GetMaxNumbersPerScreen();
+        m_nStartAt -= MaxNumbersPerScreen();
         RefreshWindow();
     }else if(found == -2){
         return TRUE;
     }else if(found != 0 && found != -1){
-        _itow(found, buf, 10);
-        MessageBox(m_hWnd, buf, L"Found", MB_OK);
+        m_nSelectedNumber = found;
+        ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,m_wNextMenuID,0);
     }
     return TRUE;
 }
@@ -223,4 +234,9 @@
         m_nSelectedNumber = 0;
     else
         m_nSelectedNumber = nSelectedNumber;
+}
+
+void SRNumberChooser::SetEndNumber(INT nEndNumber)
+{
+    m_nEndNumber = nEndNumber;
 }
\ No newline at end of file

Modified: trunk/src/SwordReader_GUI/SRNumberChooser.h
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.h	2008-04-24 03:35:00 UTC (rev 123)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.h	2008-04-25 23:22:59 UTC (rev 124)
@@ -7,28 +7,30 @@
 
 class SRNumberChooser: public SRWnd {
 public:
-	SRNumberChooser();
+	SRNumberChooser(WCString wcsPrompt, WORD wNextMenuID);
 	virtual ~SRNumberChooser();
 	
 	// redraw the screen. This should use methods in ApplicationInterface.h to do the drawing
 	BOOL OnPaint();
     INT GetSelectedNumber() { return m_nSelectedNumber; }
     void SetSelectedNumber(INT nSelectedNumber);
+    void SetEndNumber(INT nEndNumber);
     BOOL Register();
     BOOL Create(SRWnd *pParentWnd, RECT bounds);
     BOOL OnLButtonUp(WORD fwKeys, INT xPos, INT yPos);
 protected:
-    INT GetLeftEdge();
-	// signals that the user has tapped somewhere. 
-	// returns: the number that the user has tapped. -1 if no number
 	INT NumberAt(int x, int y);
-	INT GetMaxRows();
-    INT GetMaxCols();
-    INT GetMaxNumbersPerScreen();
-	INT m_nEndNumber;
-    INT m_nStartAt;
-    INT m_nSelectedNumber;
+    INT LeftEdge();
+	INT MaxRows();
+    INT MaxCols();
+    INT MaxNumbersPerScreen();
+    
+	INT      m_nEndNumber;
+    INT      m_nStartAt;
+    INT      m_nSelectedNumber;
+    WORD     m_wNextMenuID;
 	WCString m_wcsPrompt;
+    static BOOL m_fRegistered;
 };
 
 #endif

Modified: trunk/src/SwordReader_GUI/SRTextView.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRTextView.cpp	2008-04-24 03:35:00 UTC (rev 123)
+++ trunk/src/SwordReader_GUI/SRTextView.cpp	2008-04-25 23:22:59 UTC (rev 124)
@@ -25,6 +25,7 @@
 #include "SRFramework/SRApp.h"
 using namespace SRFramework;
 
+BOOL SRTextView::m_fRegistered = false;
 
 VOID LOGTAG(const char *tag)
 {
@@ -89,6 +90,9 @@
 {
     // Register window class...
     WNDCLASS    wc;
+    if(m_fRegistered)
+        return TRUE;
+
     wc.style            = CS_HREDRAW | CS_VREDRAW | CS_PARENTDC;
     wc.lpfnWndProc      = (WNDPROC) MessageRoute;
     wc.cbClsExtra       = 0;
@@ -103,6 +107,8 @@
     if(RegisterClass(&wc) == 0) 
         return FALSE;
     
+    m_fRegistered = TRUE;
+
     return TRUE;
 }
 

Modified: trunk/src/SwordReader_GUI/SRTextView.h
===================================================================
--- trunk/src/SwordReader_GUI/SRTextView.h	2008-04-24 03:35:00 UTC (rev 123)
+++ trunk/src/SwordReader_GUI/SRTextView.h	2008-04-25 23:22:59 UTC (rev 124)
@@ -125,7 +125,7 @@
     features necessary to display biblical and supporting texts. Whether I have
     been successful at this or not is unfounded, only time will tell.
  */
-class SRTextView : SRWnd
+class SRTextView : public SRWnd
 {
 private:
 
@@ -684,5 +684,8 @@
     //! the current window layout.
     BOOL                        m_fPreRendered;
 
+    static BOOL                 m_fRegistered;
+
+
     HFONT                       m_hFontCache[BTEXT_FONT_CACHE_MAX];        
 };




More information about the sword-cvs mailing list