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

dtrotzjr at www.crosswire.org dtrotzjr at www.crosswire.org
Sun Apr 20 18:35:13 MST 2008


Author: dtrotzjr
Date: 2008-04-20 18:35:12 -0700 (Sun, 20 Apr 2008)
New Revision: 121

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/SRReaderApp.cpp
   trunk/src/SwordReader_GUI/SwordReaderResource.h
Log:
More work on the SRNumberChooser class. This class replaces the NavPage class.

Modified: trunk/src/SwordReader_GUI/SRMainFrame.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.cpp	2008-04-19 23:34:39 UTC (rev 120)
+++ trunk/src/SwordReader_GUI/SRMainFrame.cpp	2008-04-21 01:35:12 UTC (rev 121)
@@ -94,9 +94,16 @@
     m_viewText = new SRTextView();
     if(!m_viewText->Create(this, view_rect))
         return FALSE;
-    m_viewText->Show();
+    //m_viewText->Show();
+    m_viewText->Hide();
     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();
+    if(!m_viewVerse->Create(this, view_rect))
+        return FALSE;
+    m_viewVerse->Show();
+
     return TRUE;
 }
 

Modified: trunk/src/SwordReader_GUI/SRMainFrame.h
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.h	2008-04-19 23:34:39 UTC (rev 120)
+++ trunk/src/SwordReader_GUI/SRMainFrame.h	2008-04-21 01:35:12 UTC (rev 121)
@@ -10,6 +10,7 @@
 #include "SRFramework/SRMenu.h"
 #include "SRTextView.h"
 #include "SRMenuBar.h"
+#include "SRNumberChooser.h"
 
 // The one and only command bar.
 #define SR_COMMAND_BAR_ID 0x0001
@@ -39,6 +40,7 @@
     SWBuf        *m_bufModOptions;
     SRMenuBar    *m_menuBar;
     SRTextView   *m_viewText;
+    SRNumberChooser *m_viewVerse;
 	SWMgr        *m_swmgr;
     ModuleMap    *m_modTexts;
     SWModule     *m_modCurText;

Modified: trunk/src/SwordReader_GUI/SRNumberChooser.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.cpp	2008-04-19 23:34:39 UTC (rev 120)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.cpp	2008-04-21 01:35:12 UTC (rev 121)
@@ -1,9 +1,7 @@
 #include "SRNumberChooser.h"
+#include "SwordReaderResource.h"
 
 
-
-#define MAXHORIZONTAL 10
-#define BUTTON_BACKGROUND 0x00A0A0A0
 #define MAXNUMBERS (getMaxRows()*MAXHORIZONTAL)
 
 #define ROW0 5
@@ -12,115 +10,140 @@
 SRNumberChooser::SRNumberChooser()
 :m_nEndNumber(0)
 ,m_nSelectedNumber(0)
+,m_nStartAt(1)
+{   
+    m_nEndNumber = 0xFFFF; // REMOVE ME!!!!!!
+    m_wcsClassName = "SRNumberChooser";
+    m_wcsWindowName = "Number Chooser";
+    m_wcsPrompt = "Choose a number:";
+}
+
+BOOL SRNumberChooser::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;
 }
 
 SRNumberChooser::~SRNumberChooser() 
 {
 }
 
-INT SRNumberChooser::getMaxRows()
+BOOL SRNumberChooser::Register()
 {
-		return (GetSystemMetrics(SM_CYSCREEN) - 2*MENU_HEIGHT) / (BUTTON_HEIGHT + PADDING_HEIGHT) - 1; 
-};
+    // Register window class...
+    WNDCLASS    wc;
+    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();
 
-BOOL SRNumberChooser::OnPaint() {
-	RECT rt;
-	memset(&rt,0,sizeof(rt));
+    if(RegisterClass(&wc) == 0) 
+        return FALSE;
+    
+    return TRUE;
+}
 
-	RECT_SCREEN.bottom = GetSystemMetrics(SM_CYSCREEN) - 2*MENU_HEIGHT;
-	RECT_SCREEN.right = GetSystemMetrics(SM_CXSCREEN);
+INT SRNumberChooser::GetMaxCols()
+{
+    RECT clientRect;
+    ::GetClientRect(m_hWnd,&clientRect);
+    return ( ((clientRect.right  - BUTTON_PADDING_WIDTH) - clientRect.left)/(BUTTON_PADDING_WIDTH + BUTTON_WIDTH_NUMBER) );
+}
 
-	rt.right=RECT_SCREEN.right;
+INT SRNumberChooser::GetMaxRows()
+{
+    RECT clientRect;
+    ::GetClientRect(m_hWnd,&clientRect);
+    return ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT) ) - 1;
+}
 
+INT SRNumberChooser::GetMaxNumbersPerScreen()
+{
+    return GetMaxCols() * GetMaxRows();
+}
+
+BOOL SRNumberChooser::OnPaint() {
 	TCHAR buttonText[4];
-	setBackground(BUTTON_BACKGROUND);
-	setFont(FONT_NAVIGATION);
-	int current=start;
-	// left of first buttons
-	rt.right=rt.left+PADDING_WIDTH;
-	rt.top=rt.bottom; rt.bottom=LASTROW;
-	clearRect(&rt);
+    RECT buttonRect;
+    RECT clientRect;
+    INT nCurrent = m_nStartAt;
+    INT nColStart = 0;
+    PAINTSTRUCT ps;
+    INT nRow;
+    INT nCol;
+    INT nMaxCols = GetMaxCols();
+    INT nMaxRows = GetMaxRows();
 
-	while ((current<=maxNumber)&&(current<start+MAXNUMBERS)) {
-		int colStart=current;
-		rt.left=rt.right; rt.right=rt.left+BUTTON_WIDTH_NM; rt.bottom=ROW0;
-		while ((current<=maxNumber)&&(current-colStart<getMaxRows())) {
-			//padding above button
-			rt.top=rt.bottom;rt.bottom=rt.top+PADDING_HEIGHT;
-			clearRect(&rt);
-			//button
-			rt.top=rt.bottom;rt.bottom=rt.top+BUTTON_HEIGHT;
-			_itow(current,buttonText,10);
-			drawRText(&rt,buttonText,wcslen(buttonText));
-			current++;
-		}
-		//padding below buttons
-		rt.top=rt.bottom;rt.bottom=LASTROW;
-		clearRect(&rt);
-		//padding right of buttons
-		rt.top=ROW0; rt.left=rt.right; rt.right=rt.left+PADDING_WIDTH;
-		clearRect(&rt);
-	}
-	//area right of buttons
-	rt.left=rt.right; rt.right=RECT_SCREEN.right;
-	clearRect(&rt);
-	rt.left=RECT_SCREEN.left;rt.right=RECT_SCREEN.right; //rt.bottom is still LASTROW
-	//optional 'more' button
-	if ((start!=1)||(current<maxNumber)) {
-		rt.top=rt.bottom;rt.bottom=rt.top+PADDING_HEIGHT;
-		clearRect(&rt);
-		rt.top=rt.bottom; rt.bottom=rt.top+BUTTON_HEIGHT;
-		rt.right=(RECT_SCREEN.right/3);
-		clearRect(&rt);
-		rt.left=rt.right;rt.right=RECT_SCREEN.right-rt.left;
-		drawText(&rt,"More...");
-		rt.left=rt.right;rt.right=RECT_SCREEN.right;
-		clearRect(&rt);
-		rt.left=RECT_SCREEN.left;
-	}
-	//space below the buttons
-	rt.top=rt.bottom; rt.bottom=RECT_SCREEN.bottom;
-	clearRect(&rt);
+    HDC hdc = BeginPaint(m_hWnd, &ps);
+    
+    HBRUSH brushBG =  CreateSolidBrush((COLORREF)BUTTON_BACKGROUND);
+    GetClientRect(m_hWnd, &clientRect);
+    FillRect(hdc, &clientRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
+    SetBkColor(hdc, BUTTON_BACKGROUND);
+    // Init the first button's bounds
+    buttonRect.top = BUTTON_PADDING_HEIGHT;
+    buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
+    buttonRect.left = BUTTON_PADDING_WIDTH;
+    buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
 
-	setBackground();
-	setFont();
+    for(nRow = 0; nRow < nMaxRows; nRow++){
+        for(nCol = 0; nCol < nMaxCols; nCol++){
+            nCurrent = m_nStartAt + (nRow * nMaxCols) + nCol;
+            _itow(nCurrent, buttonText, 10);
+            FillRect(hdc, &buttonRect, brushBG); 
+            DrawText(hdc, buttonText, -1, &buttonRect, DT_CENTER | DT_VCENTER);
+            if(nCurrent == m_nEndNumber)
+                break;
+            // Move the bounds right.
+            buttonRect.left += BUTTON_WIDTH_NUMBER + BUTTON_PADDING_WIDTH;
+            buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
+
+        }
+        if(nCurrent == m_nEndNumber)
+           break;
+        // Move the bounds down and all the way back to the left.
+        buttonRect.left = BUTTON_PADDING_WIDTH;
+        buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
+        buttonRect.top += BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT;
+        buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
+    }
+    //Clean up.
+    DeleteObject(brushBG);
+    EndPaint(m_hWnd,&ps);
+    return TRUE;
 }
 
-int SRNumberChooser::numberAt(int x, int y) {
-	// y=y-ROW2;
-	y=y-ROW0;
-	if (x>0) {
-		int horizontal=(x/(PADDING_WIDTH+BUTTON_WIDTH_NM));
-		if (horizontal<MAXHORIZONTAL) {
-			x=x-horizontal*(PADDING_HEIGHT+BUTTON_HEIGHT);
-			int vertical=(y/(PADDING_HEIGHT+BUTTON_HEIGHT));
-			if (vertical<getMaxRows()) {
-				y=y-vertical*(PADDING_HEIGHT+BUTTON_HEIGHT);
-				//button is in bottom right corner
-				if ((x>=PADDING_WIDTH)&&(y>=PADDING_HEIGHT)) {
-					int current=horizontal*getMaxRows()+vertical+start;
-					if (current<=maxNumber) return current;
-				}
-			}
-			else if (vertical==getMaxRows()) { // The 'more' button is here
-				y=y-vertical*(PADDING_HEIGHT+BUTTON_HEIGHT);
-				if (y>=PADDING_HEIGHT) {
-					x=x+horizontal*(PADDING_HEIGHT+BUTTON_HEIGHT); //undo
-					if (((2*x)>=(RECT_SCREEN.right-x))&&((2*(RECT_SCREEN.right-x))>=x)) {
-						if ((start+MAXNUMBERS)>maxNumber)
-							start=1;
-						else
-							start=start+MAXNUMBERS;
-						refreshScreen();
-					}
-				}
-			}
-		}
-	}
-	return -1;
+INT SRNumberChooser::NumberAt(int x, int y) 
+{
+    INT nCol = (x - BUTTON_PADDING_WIDTH) / (BUTTON_WIDTH_NUMBER + BUTTON_PADDING_WIDTH);
+    INT nRow = (y - BUTTON_PADDING_HEIGHT)/ (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
+    INT nNumber = m_nStartAt + (nRow * GetMaxCols()) + nCol;
+    if( (nNumber > m_nEndNumber) || (nNumber >= (m_nStartAt + GetMaxNumbersPerScreen())) )
+        return -1;
+    return nNumber;
 }
 
+BOOL SRNumberChooser::OnLButtonUp(WORD fwKeys, INT xPos, INT yPos)
+{
+    TCHAR buf[16] = {0};
+    INT found = NumberAt(xPos, yPos);
+    if(found < 0)
+        return TRUE;
+    _itow(found, buf, 10);
+    MessageBox(m_hWnd, buf, L"Found", MB_OK);
+    return TRUE;
+}
 void SRNumberChooser::SetSelectedNumber(INT nSelectedNumber)
 {
     if(nSelectedNumber < 0 || nSelectedNumber > m_nEndNumber)

Modified: trunk/src/SwordReader_GUI/SRNumberChooser.h
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.h	2008-04-19 23:34:39 UTC (rev 120)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.h	2008-04-21 01:35:12 UTC (rev 121)
@@ -3,6 +3,8 @@
 
 #include "SRFramework/SRWnd.h"
 
+using namespace SRFramework;
+
 class SRNumberChooser: public SRWnd {
 public:
 	SRNumberChooser();
@@ -12,13 +14,18 @@
 	BOOL OnPaint();
     INT GetSelectedNumber() { return m_nSelectedNumber; }
     void SetSelectedNumber(INT nSelectedNumber);
+    BOOL Register();
+    BOOL Create(SRWnd *pParentWnd, RECT bounds);
+    BOOL OnLButtonUp(WORD fwKeys, INT xPos, INT yPos);
 protected:
 	// 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;
 	WCString m_wcsPrompt;
 };

Modified: trunk/src/SwordReader_GUI/SRReaderApp.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRReaderApp.cpp	2008-04-19 23:34:39 UTC (rev 120)
+++ trunk/src/SwordReader_GUI/SRReaderApp.cpp	2008-04-21 01:35:12 UTC (rev 121)
@@ -46,10 +46,11 @@
 BOOL SRReaderApp::InitApp(int nCmdShow)
 {
     m_pMainFrame = new SRMainFrame();
-    m_pMainFrame->Create();
-    m_pMainFrame->Init();
+    if(!m_pMainFrame->Create())
+        return FALSE;
+    if(!m_pMainFrame->Init())
+        return FALSE;
 
-
 	return TRUE;
 }
 

Modified: trunk/src/SwordReader_GUI/SwordReaderResource.h
===================================================================
--- trunk/src/SwordReader_GUI/SwordReaderResource.h	2008-04-19 23:34:39 UTC (rev 120)
+++ trunk/src/SwordReader_GUI/SwordReaderResource.h	2008-04-21 01:35:12 UTC (rev 121)
@@ -18,4 +18,11 @@
 #define WM_TXT_START WM_USER + 0x00F1
 #define WM_TXT_END   WM_USER + 0x00F2
 
+#define BUTTON_BACKGROUND 0x00b9ccd5
+#define BUTTON_WIDTH_BOOK 26
+#define BUTTON_WIDTH_NUMBER 20
+#define BUTTON_HEIGHT 17
+#define BUTTON_PADDING_WIDTH 3
+#define BUTTON_PADDING_HEIGHT 3
+
 #endif
\ No newline at end of file




More information about the sword-cvs mailing list