[sword-svn] r144 - trunk/src/SwordReader_GUI
dtrotzjr at www.crosswire.org
dtrotzjr at www.crosswire.org
Sun Jul 6 19:44:43 MST 2008
Author: dtrotzjr
Date: 2008-07-06 19:44:42 -0700 (Sun, 06 Jul 2008)
New Revision: 144
Modified:
trunk/src/SwordReader_GUI/SRBookChooser.cpp
trunk/src/SwordReader_GUI/SRBookChooser.h
trunk/src/SwordReader_GUI/SRNumberChooser.cpp
trunk/src/SwordReader_GUI/SRNumberChooser.h
trunk/src/SwordReader_GUI/SwordReaderResource.h
trunk/src/SwordReader_GUI/SwordReader_GUI.rc
Log:
Albert Sites initial patch for Smartphone support.
Modified: trunk/src/SwordReader_GUI/SRBookChooser.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRBookChooser.cpp 2008-07-02 00:49:31 UTC (rev 143)
+++ trunk/src/SwordReader_GUI/SRBookChooser.cpp 2008-07-07 02:44:42 UTC (rev 144)
@@ -1,238 +1,293 @@
-#include "SRBookChooser.h"
-#include "SwordReaderResource.h"
-
-BOOL SRBookChooser::s_fRegistered = false;
-
-SRBookChooser::SRBookChooser(WCString *wcsBookNames, WORD wNextMenuID)
-:m_nEndBook(BIBLE_TOTAL_BOOKS)
-,m_nSelectedBook(0)
-,m_nStartAt(1)
-,m_wcsPrompt("Select a Book:")
-,m_wNextMenuID(wNextMenuID)
-,m_wcsBookNames(wcsBookNames)
-{
- m_wcsClassName = "SRBookChooser";
- m_wcsWindowName = "Book Chooser";
-}
-
-BOOL SRBookChooser::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;
-}
-
-SRBookChooser::~SRBookChooser()
-{
-}
-
-BOOL SRBookChooser::Register()
-{
- // Register window class...
- WNDCLASS wc;
- if(s_fRegistered)
- return TRUE;
-
- 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();
-
- if(RegisterClass(&wc) == 0)
- return FALSE;
- s_fRegistered = TRUE;
-
- return TRUE;
-}
-
-INT SRBookChooser::MaxCols()
-{
- RECT clientRect;
- ::GetClientRect(m_hWnd,&clientRect);
- return ( ((clientRect.right - BUTTON_PADDING_WIDTH) - clientRect.left)/(BUTTON_PADDING_WIDTH + BUTTON_WIDTH_BOOK) );
-}
-
-INT SRBookChooser::MaxRows()
-{
- RECT clientRect;
- INT nMaxBooks = 0;
- INT nMaxRows = 0;
- ::GetClientRect(m_hWnd,&clientRect);
-
- // 2 less rows due to the Prompt and the More Prev buttons.
- nMaxRows = ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT) ) - 2;
- nMaxBooks = MaxCols() * nMaxRows;
-
- if(m_nStartAt == 1 && m_nEndBook <= nMaxBooks + MaxCols())
- nMaxRows++; // We can fit another row since there is no need for a More or Prev button.
- return nMaxRows;
-
-}
-
-INT SRBookChooser::MaxBooksPerScreen()
-{
- return MaxCols() * MaxRows();
-}
-
-// Tries to center the buttons by calculating a left edge
-INT SRBookChooser::LeftEdge()
-{
- RECT clientRect;
- GetClientRect(m_hWnd, &clientRect);
- return ((clientRect.right - clientRect.left)/2) -
- ((MaxCols()*BUTTON_WIDTH_BOOK + (MaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
-}
-BOOL SRBookChooser::OnPaint() {
- RECT buttonRect;
- RECT clientRect;
- INT nCurrent = m_nStartAt;
- INT nColStart = 0;
- PAINTSTRUCT ps;
- INT nRow;
- INT nCol;
- INT nMaxCols = MaxCols();
- INT nMaxRows = MaxRows();
-
- HDC hdc = BeginPaint(m_hWnd, &ps);
-
- HBRUSH brushBG = CreateSolidBrush((COLORREF)BUTTON_BACKGROUND);
- GetClientRect(m_hWnd, &clientRect);
- FillRect(hdc, &clientRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
-
- // Draw the prompt.
- buttonRect.top = BUTTON_PADDING_HEIGHT;
- 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 = LeftEdge();
- buttonRect.right = buttonRect.left + BUTTON_WIDTH_BOOK;
-
- SetBkColor(hdc, BUTTON_BACKGROUND);
-
- for(nRow = 0; nRow < nMaxRows; nRow++){
- for(nCol = 0; nCol < nMaxCols; nCol++){
- nCurrent = m_nStartAt + (nRow * nMaxCols) + nCol;
- FillRect(hdc, &buttonRect, brushBG);
- DrawText(hdc, m_wcsBookNames[nCurrent - 1].w_str(), -1, &buttonRect, DT_CENTER | DT_VCENTER);
- if(nCurrent == m_nEndBook)
- break;
- // Move the bounds right.
- buttonRect.left += BUTTON_WIDTH_BOOK + BUTTON_PADDING_WIDTH;
- buttonRect.right = buttonRect.left + BUTTON_WIDTH_BOOK;
-
- }
- // Move the bounds down and all the way back to the left.
- buttonRect.left = LeftEdge();
- buttonRect.right = buttonRect.left + BUTTON_WIDTH_BOOK;
- buttonRect.top += BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT;
- buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
- if(nCurrent == m_nEndBook)
- break;
- }
-
- // If we didn't reach the end we need to draw the More button...
- if(nCurrent < m_nEndBook){
- 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;
-
- FillRect(hdc, &buttonRect, brushBG);
- DrawText(hdc, L"More >>", -1, &buttonRect, DT_CENTER | DT_VCENTER);
- }
- // We are not on the first page of Books we need to draw a Prev button...
- if(m_nStartAt != 1){
- 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;
-
- FillRect(hdc, &buttonRect, brushBG);
- DrawText(hdc, L"<< Prev", -1, &buttonRect, DT_CENTER | DT_VCENTER);
- }
- //Clean up.
- DeleteObject(brushBG);
- EndPaint(m_hWnd,&ps);
- return TRUE;
-}
-/* Return:
- * > 0 - the Book found.
- * 0 - More button pressed.
- * -1 - Prev button pressed.
- * -2 - White space tapped. Ignore
- */
-INT SRBookChooser::BookAt(int x, int y)
-{
- RECT clientRect;
- INT nCols = (x - BUTTON_PADDING_WIDTH) / (BUTTON_WIDTH_BOOK + BUTTON_PADDING_WIDTH);
- 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 nBook = m_nStartAt + (nRows * MaxCols()) + nCols;
-
- if(y < BUTTON_HEIGHT + 2*BUTTON_PADDING_HEIGHT)
- return -2; // Tapped the title area.
-
- // Check if the tap was on a button...
- 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 > (MaxCols()*(BUTTON_WIDTH_BOOK+BUTTON_PADDING_WIDTH) - BUTTON_WIDTH_MORE)) &&
- (x < (MaxCols()*(BUTTON_WIDTH_BOOK+BUTTON_PADDING_WIDTH))) ){
- return 0;
- }else
- return -2;
- }
- if(nBook > m_nEndBook || nBook >= m_nStartAt + MaxBooksPerScreen())
- return -2;
-
- return nBook;
-}
-
-BOOL SRBookChooser::OnLButtonUp(WORD fwKeys, INT xPos, INT yPos)
-{
- TCHAR buf[16] = {0};
- INT found = BookAt(xPos, yPos);
- if(found == 0 && (m_nStartAt + MaxBooksPerScreen() <= m_nEndBook) ){
- m_nStartAt += MaxBooksPerScreen();
- RefreshWindow();
- }else if(found == -1 && m_nStartAt != 1){
- m_nStartAt -= MaxBooksPerScreen();
- RefreshWindow();
- }else if(found == -2){
- return TRUE;
- }else if(found != 0 && found != -1){
- m_nSelectedBook = found;
- // We also send the value found, thus when this messge is recv'd the new value can be processed.
- ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,SR_SETBOOK, found);
- ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,m_wNextMenuID, found);
- }
- return TRUE;
-}
-void SRBookChooser::SetSelectedBook(INT nSelectedBook)
-{
- if(nSelectedBook < 0 || nSelectedBook > m_nEndBook)
- m_nSelectedBook = 0;
- else
- m_nSelectedBook = nSelectedBook;
-}
-
-void SRBookChooser::SetEndBook(INT nEndBook)
-{
- m_nEndBook = nEndBook;
+#include "SRBookChooser.h"
+#include "SwordReaderResource.h"
+
+BOOL SRBookChooser::s_fRegistered = false;
+
+SRBookChooser::SRBookChooser(WCString *wcsBookNames, WORD wNextMenuID)
+:m_nEndBook(BIBLE_TOTAL_BOOKS)
+,m_nSelectedBook(0)
+,m_nStartAt(1)
+,m_wcsPrompt("Select a Book:")
+,m_wNextMenuID(wNextMenuID)
+,m_wcsBookNames(wcsBookNames)
+{
+ m_wcsClassName = "SRBookChooser";
+ m_wcsWindowName = "Book Chooser";
+}
+
+BOOL SRBookChooser::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;
+}
+
+SRBookChooser::~SRBookChooser()
+{
+}
+
+BOOL SRBookChooser::Register()
+{
+ // Register window class...
+ WNDCLASS wc;
+ if(s_fRegistered)
+ return TRUE;
+
+ 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();
+
+ if(RegisterClass(&wc) == 0)
+ return FALSE;
+ s_fRegistered = TRUE;
+
+ return TRUE;
+}
+
+INT SRBookChooser::MaxCols()
+{
+ RECT clientRect;
+ ::GetClientRect(m_hWnd,&clientRect);
+ return ( ((clientRect.right - BUTTON_PADDING_WIDTH) - clientRect.left)/(BUTTON_PADDING_WIDTH + BUTTON_WIDTH_BOOK) );
+}
+
+INT SRBookChooser::MaxRows()
+{
+ RECT clientRect;
+ INT nMaxBooks = 0;
+ INT nMaxRows = 0;
+ ::GetClientRect(m_hWnd,&clientRect);
+
+ // 2 less rows due to the Prompt and the More Prev buttons.
+ nMaxRows = ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT) ) - 2;
+ nMaxBooks = MaxCols() * nMaxRows;
+
+ if(m_nStartAt == 1 && m_nEndBook <= nMaxBooks + MaxCols())
+ nMaxRows++; // We can fit another row since there is no need for a More or Prev button.
+ return nMaxRows;
+
+}
+
+INT SRBookChooser::MaxBooksPerScreen()
+{
+ return MaxCols() * MaxRows();
+}
+
+// Tries to center the buttons by calculating a left edge
+INT SRBookChooser::LeftEdge()
+{
+ RECT clientRect;
+ GetClientRect(m_hWnd, &clientRect);
+ return ((clientRect.right - clientRect.left)/2) -
+ ((MaxCols()*BUTTON_WIDTH_BOOK + (MaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
+}
+BOOL SRBookChooser::OnPaint() {
+ RECT buttonRect;
+ RECT clientRect;
+ INT nCurrent = m_nStartAt;
+ INT nColStart = 0;
+ PAINTSTRUCT ps;
+ INT nRow;
+ INT nCol;
+ INT nMaxCols = MaxCols();
+ INT nMaxRows = MaxRows();
+
+ HDC hdc = BeginPaint(m_hWnd, &ps);
+
+ if (selCol < 0 || selCol >= MaxCols())
+ selCol = 0;
+
+ if (selRow < 0 || selRow >= MaxRows())
+ selRow = 0;
+
+ HBRUSH brushBG = CreateSolidBrush((COLORREF)BUTTON_BACKGROUND);
+ GetClientRect(m_hWnd, &clientRect);
+ FillRect(hdc, &clientRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
+
+ // Draw the prompt.
+ buttonRect.top = BUTTON_PADDING_HEIGHT;
+ 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 = LeftEdge();
+ buttonRect.right = buttonRect.left + BUTTON_WIDTH_BOOK;
+
+ for(nRow = 0; nRow < nMaxRows; nRow++){
+ for(nCol = 0; nCol < nMaxCols; nCol++){
+ nCurrent = m_nStartAt + (nRow * nMaxCols) + nCol;
+
+ SetTextColor(hdc, BUTTON_FOREGROUND);
+
+ if(nCol == selCol && nRow == selRow) {
+ //if(nCurrent == nSelectedBook) {
+ SetBkColor(hdc, BUTTON_SEL_BACKGROUND);
+ FillRect(hdc, &buttonRect, brushBG);
+ Rectangle(hdc, buttonRect.left, buttonRect.top, buttonRect.right, buttonRect.bottom);
+ } else {
+ SetBkColor(hdc, BUTTON_BACKGROUND);
+ FillRect(hdc, &buttonRect, brushBG);
+ }
+
+ DrawText(hdc, m_wcsBookNames[nCurrent - 1].w_str(), -1, &buttonRect, DT_CENTER | DT_VCENTER);
+ if(nCurrent == m_nEndBook)
+ break;
+ // Move the bounds right.
+ buttonRect.left += BUTTON_WIDTH_BOOK + BUTTON_PADDING_WIDTH;
+ buttonRect.right = buttonRect.left + BUTTON_WIDTH_BOOK;
+
+ }
+ // Move the bounds down and all the way back to the left.
+ buttonRect.left = LeftEdge();
+ buttonRect.right = buttonRect.left + BUTTON_WIDTH_BOOK;
+ buttonRect.top += BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT;
+ buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
+ if(nCurrent == m_nEndBook)
+ break;
+ }
+
+ // If we didn't reach the end we need to draw the More button...
+ if(nCurrent < m_nEndBook){
+ 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;
+
+ FillRect(hdc, &buttonRect, brushBG);
+ DrawText(hdc, L"More >>", -1, &buttonRect, DT_CENTER | DT_VCENTER);
+ }
+ // We are not on the first page of Books we need to draw a Prev button...
+ if(m_nStartAt != 1){
+ 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;
+
+ FillRect(hdc, &buttonRect, brushBG);
+ DrawText(hdc, L"<< Prev", -1, &buttonRect, DT_CENTER | DT_VCENTER);
+ }
+ //Clean up.
+ DeleteObject(brushBG);
+ EndPaint(m_hWnd,&ps);
+ return TRUE;
+}
+
+/* Return:
+ * > 0 - the Book found.
+ * 0 - More button pressed.
+ * -1 - Prev button pressed.
+ * -2 - White space tapped. Ignore
+ */
+INT SRBookChooser::BookAt(int x, int y)
+{
+ RECT clientRect;
+ INT nCols = (x - BUTTON_PADDING_WIDTH) / (BUTTON_WIDTH_BOOK + BUTTON_PADDING_WIDTH);
+ 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 nBook = m_nStartAt + (nRows * MaxCols()) + nCols;
+
+ if(y < BUTTON_HEIGHT + 2*BUTTON_PADDING_HEIGHT)
+ return -2; // Tapped the title area.
+
+ // Check if the tap was on a button...
+ 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 > (MaxCols()*(BUTTON_WIDTH_BOOK+BUTTON_PADDING_WIDTH) - BUTTON_WIDTH_MORE)) &&
+ (x < (MaxCols()*(BUTTON_WIDTH_BOOK+BUTTON_PADDING_WIDTH))) ){
+ return 0;
+ }else
+ return -2;
+ }
+ if(nBook > m_nEndBook || nBook >= m_nStartAt + MaxBooksPerScreen())
+ return -2;
+
+ return nBook;
+}
+
+BOOL SRBookChooser::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags){
+ if(nChar == VK_RIGHT){
+ INT tempBook = (MaxCols() * selRow) + selCol + 1;
+ if (tempBook == m_nEndBook) {
+ selCol = 0;
+ selRow = 0;
+ } else if (selCol == (MaxCols() - 1)) {
+ selCol = 0;
+ selRow++;
+ } else {
+ selCol++;
+ }
+ RefreshWindow();
+ } else if(nChar == VK_DOWN){
+ selRow++;
+ if(selRow >= MaxRows())
+ selRow = 0;
+ RefreshWindow();
+ } else if(nChar == VK_LEFT){
+ if(selCol <= 0)
+ selCol = MaxCols() - 1;
+ else
+ selCol--;
+ RefreshWindow();
+ } else if(nChar == VK_UP){
+ if(selRow <= 0)
+ selRow = MaxRows() - 1;
+ else
+ selRow--;
+ RefreshWindow();
+ } else if(nChar == VK_RETURN){
+ INT book = (selRow * MaxCols()) + selCol + 1;
+ ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,SR_SETBOOK, book);
+ ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,m_wNextMenuID, book);
+ }
+ return true;
+}
+
+BOOL SRBookChooser::OnLButtonUp(WORD fwKeys, INT xPos, INT yPos)
+{
+ TCHAR buf[16] = {0};
+ INT found = BookAt(xPos, yPos);
+ if(found == 0 && (m_nStartAt + MaxBooksPerScreen() <= m_nEndBook) ){
+ m_nStartAt += MaxBooksPerScreen();
+ RefreshWindow();
+ }else if(found == -1 && m_nStartAt != 1){
+ m_nStartAt -= MaxBooksPerScreen();
+ RefreshWindow();
+ }else if(found == -2){
+ return TRUE;
+ }else if(found != 0 && found != -1){
+ m_nSelectedBook = found;
+ // We also send the value found, thus when this messge is recv'd the new value can be processed.
+ ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,SR_SETBOOK, found);
+ ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,m_wNextMenuID, found);
+ }
+ return TRUE;
+}
+void SRBookChooser::SetSelectedBook(INT nSelectedBook)
+{
+ if(nSelectedBook < 0 || nSelectedBook > m_nEndBook)
+ m_nSelectedBook = 0;
+ else
+ m_nSelectedBook = nSelectedBook;
+}
+
+void SRBookChooser::SetEndBook(INT nEndBook)
+{
+ m_nEndBook = nEndBook;
}
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SRBookChooser.h
===================================================================
--- trunk/src/SwordReader_GUI/SRBookChooser.h 2008-07-02 00:49:31 UTC (rev 143)
+++ trunk/src/SwordReader_GUI/SRBookChooser.h 2008-07-07 02:44:42 UTC (rev 144)
@@ -1,36 +1,39 @@
-#ifndef SRBOOKCHOOSER_H
-#define SRBOOKCHOOSER_H
-
-#include "SRFramework/SRWnd.h"
-using namespace SRFramework;
-
-class SRBookChooser: public SRWnd {
-public:
- SRBookChooser(WCString *wcsBookNames, WORD wNextMenuID);
- virtual ~SRBookChooser();
-
- // redraw the screen. This should use methods in ApplicationInterface.h to do the drawing
- BOOL OnPaint();
- INT GetSelectedBook() { return m_nSelectedBook; }
- void SetSelectedBook(INT nSelectedBook);
- void SetEndBook(INT nEndBook);
- BOOL Register();
- BOOL Create(SRWnd *pParentWnd, RECT bounds);
- BOOL OnLButtonUp(WORD fwKeys, INT xPos, INT yPos);
-protected:
- INT BookAt(int x, int y);
- INT LeftEdge();
- INT MaxRows();
- INT MaxCols();
- INT MaxBooksPerScreen();
-
- INT m_nEndBook;
- INT m_nStartAt;
- INT m_nSelectedBook;
- WORD m_wNextMenuID;
- WCString m_wcsPrompt;
- WCString *m_wcsBookNames;
- static BOOL s_fRegistered;
-};
-
-#endif
+#ifndef SRBOOKCHOOSER_H
+#define SRBOOKCHOOSER_H
+
+#include "SRFramework/SRWnd.h"
+using namespace SRFramework;
+
+class SRBookChooser: public SRWnd {
+public:
+ SRBookChooser(WCString *wcsBookNames, WORD wNextMenuID);
+ virtual ~SRBookChooser();
+
+ // redraw the screen. This should use methods in ApplicationInterface.h to do the drawing
+ BOOL OnPaint();
+ INT GetSelectedBook() { return m_nSelectedBook; }
+ void SetSelectedBook(INT nSelectedBook);
+ void SetEndBook(INT nEndBook);
+ BOOL Register();
+ BOOL Create(SRWnd *pParentWnd, RECT bounds);
+ BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
+ BOOL OnLButtonUp(WORD fwKeys, INT xPos, INT yPos);
+protected:
+ INT BookAt(int x, int y);
+ INT LeftEdge();
+ INT MaxRows();
+ INT MaxCols();
+ INT MaxBooksPerScreen();
+
+ INT m_nEndBook;
+ INT m_nStartAt;
+ INT m_nSelectedBook;
+ INT selCol;
+ INT selRow;
+ WORD m_wNextMenuID;
+ WCString m_wcsPrompt;
+ WCString *m_wcsBookNames;
+ static BOOL s_fRegistered;
+};
+
+#endif
Modified: trunk/src/SwordReader_GUI/SRNumberChooser.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.cpp 2008-07-02 00:49:31 UTC (rev 143)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.cpp 2008-07-07 02:44:42 UTC (rev 144)
@@ -1,240 +1,296 @@
-#include "SRNumberChooser.h"
-#include "SwordReaderResource.h"
-
-BOOL SRNumberChooser::s_fRegistered = false;
-
-SRNumberChooser::SRNumberChooser(ChooserType type, WCString wcsPrompt, WORD wNextMenuID)
-:m_nEndNumber(0)
-,m_nSelectedNumber(0)
-,m_nStartAt(1)
-,m_wcsPrompt(wcsPrompt)
-,m_wNextMenuID(wNextMenuID)
-,m_type(type)
-{
- m_wcsClassName = "SRNumberChooser";
- m_wcsWindowName = "Number Chooser";
-}
-
-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()
-{
-}
-
-BOOL SRNumberChooser::Register()
-{
- // Register window class...
- WNDCLASS wc;
- if(s_fRegistered)
- return TRUE;
-
- 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();
-
- if(RegisterClass(&wc) == 0)
- return FALSE;
- s_fRegistered = TRUE;
-
- return TRUE;
-}
-
-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::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.
- 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::MaxNumbersPerScreen()
-{
- return MaxCols() * MaxRows();
-}
-
-// Tries to center the buttons by calculating a left edge
-INT SRNumberChooser::LeftEdge()
-{
- RECT clientRect;
- GetClientRect(m_hWnd, &clientRect);
- return ((clientRect.right - clientRect.left)/2) -
- ((MaxCols()*BUTTON_WIDTH_NUMBER + (MaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
-}
-BOOL SRNumberChooser::OnPaint() {
- TCHAR buttonText[4];
- RECT buttonRect;
- RECT clientRect;
- INT nCurrent = m_nStartAt;
- INT nColStart = 0;
- PAINTSTRUCT ps;
- INT nRow;
- INT nCol;
- INT nMaxCols = MaxCols();
- INT nMaxRows = MaxRows();
-
- HDC hdc = BeginPaint(m_hWnd, &ps);
-
- HBRUSH brushBG = CreateSolidBrush((COLORREF)BUTTON_BACKGROUND);
- GetClientRect(m_hWnd, &clientRect);
- FillRect(hdc, &clientRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
-
- // Draw the prompt.
- buttonRect.top = BUTTON_PADDING_HEIGHT;
- 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 = LeftEdge();
- buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
-
- SetBkColor(hdc, BUTTON_BACKGROUND);
-
- 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;
-
- }
- // Move the bounds down and all the way back to the left.
- buttonRect.left = LeftEdge();
- buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
- buttonRect.top += BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT;
- buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
- if(nCurrent == m_nEndNumber)
- break;
- }
-
- // 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 + LeftEdge());
- buttonRect.right = buttonRect.left + BUTTON_WIDTH_MORE;
- buttonRect.top = clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
- buttonRect.bottom = clientRect.bottom - BUTTON_PADDING_HEIGHT;
-
- FillRect(hdc, &buttonRect, brushBG);
- DrawText(hdc, L"More >>", -1, &buttonRect, DT_CENTER | DT_VCENTER);
- }
- // We are not on the first page of numbers we need to draw a Prev button...
- if(m_nStartAt != 1){
- 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;
-
- FillRect(hdc, &buttonRect, brushBG);
- DrawText(hdc, L"<< Prev", -1, &buttonRect, DT_CENTER | DT_VCENTER);
- }
- //Clean up.
- DeleteObject(brushBG);
- EndPaint(m_hWnd,&ps);
- return TRUE;
-}
-/* Return:
- * > 0 - the number found.
- * 0 - More button pressed.
- * -1 - Prev button pressed.
- * -2 - White space tapped. Ignore
- */
-INT SRNumberChooser::NumberAt(int x, int y)
-{
- RECT clientRect;
- INT nCols = (x - BUTTON_PADDING_WIDTH) / (BUTTON_WIDTH_NUMBER + BUTTON_PADDING_WIDTH);
- 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 * MaxCols()) + nCols;
-
- if(y < BUTTON_HEIGHT + 2*BUTTON_PADDING_HEIGHT)
- return -2; // Tapped the title area.
-
- // Check if the tap was on a button...
- 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 > (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 + MaxNumbersPerScreen())
- return -2;
-
- return nNumber;
-}
-
-BOOL SRNumberChooser::OnLButtonUp(WORD fwKeys, INT xPos, INT yPos)
-{
- TCHAR buf[16] = {0};
- INT found = NumberAt(xPos, yPos);
- if(found == 0 && (m_nStartAt + MaxNumbersPerScreen() <= m_nEndNumber) ){
- m_nStartAt += MaxNumbersPerScreen();
- RefreshWindow();
- }else if(found == -1 && m_nStartAt != 1){
- m_nStartAt -= MaxNumbersPerScreen();
- RefreshWindow();
- }else if(found == -2){
- return TRUE;
- }else if(found != 0 && found != -1){
- m_nSelectedNumber = found;
- // We also send the value found, thus when this messge is recv'd the new value can be processed.
- ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,(SR_MSRC_CHOOSER << 16) | (m_type == CHAPTER ? SR_SETCHAPTER : SR_SETVERSE), found);
- ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,m_wNextMenuID, found);
- }
- return TRUE;
-}
-void SRNumberChooser::SetSelectedNumber(INT nSelectedNumber)
-{
- if(nSelectedNumber < 0 || nSelectedNumber > m_nEndNumber)
- m_nSelectedNumber = 0;
- else
- m_nSelectedNumber = nSelectedNumber;
-}
-
-void SRNumberChooser::SetEndNumber(INT nEndNumber)
-{
- m_nEndNumber = nEndNumber;
+#include "SRNumberChooser.h"
+#include "SwordReaderResource.h"
+
+BOOL SRNumberChooser::s_fRegistered = false;
+
+SRNumberChooser::SRNumberChooser(ChooserType type, WCString wcsPrompt, WORD wNextMenuID)
+:m_nEndNumber(0)
+,m_nSelectedNumber(0)
+,m_nStartAt(1)
+,m_wcsPrompt(wcsPrompt)
+,m_wNextMenuID(wNextMenuID)
+,m_type(type)
+{
+ m_wcsClassName = "SRNumberChooser";
+ m_wcsWindowName = "Number Chooser";
+}
+
+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()
+{
+}
+
+BOOL SRNumberChooser::Register()
+{
+ // Register window class...
+ WNDCLASS wc;
+ if(s_fRegistered)
+ return TRUE;
+
+ 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();
+
+ if(RegisterClass(&wc) == 0)
+ return FALSE;
+ s_fRegistered = TRUE;
+
+ return TRUE;
+}
+
+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::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.
+ 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::MaxNumbersPerScreen()
+{
+ return MaxCols() * MaxRows();
+}
+
+// Tries to center the buttons by calculating a left edge
+INT SRNumberChooser::LeftEdge()
+{
+ RECT clientRect;
+ GetClientRect(m_hWnd, &clientRect);
+ return ((clientRect.right - clientRect.left)/2) -
+ ((MaxCols()*BUTTON_WIDTH_NUMBER + (MaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
+}
+BOOL SRNumberChooser::OnPaint() {
+ TCHAR buttonText[4];
+ RECT buttonRect;
+ RECT clientRect;
+ INT nCurrent = m_nStartAt;
+ INT nColStart = 0;
+ PAINTSTRUCT ps;
+ INT nRow;
+ INT nCol;
+ INT nMaxCols = MaxCols();
+ INT nMaxRows = MaxRows();
+
+ if (selCol < 0 || selCol >= MaxCols())
+ selCol = 0;
+
+ if (selRow < 0 || selRow >= MaxRows())
+ selRow = 0;
+
+ HDC hdc = BeginPaint(m_hWnd, &ps);
+
+ HBRUSH brushBG = CreateSolidBrush((COLORREF)BUTTON_BACKGROUND);
+ GetClientRect(m_hWnd, &clientRect);
+ FillRect(hdc, &clientRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
+
+ // Draw the prompt.
+ buttonRect.top = BUTTON_PADDING_HEIGHT;
+ 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 = LeftEdge();
+ buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
+
+ SetBkColor(hdc, BUTTON_BACKGROUND);
+
+ for(nRow = 0; nRow < nMaxRows; nRow++){
+ for(nCol = 0; nCol < nMaxCols; nCol++){
+ nCurrent = m_nStartAt + (nRow * nMaxCols) + nCol;
+ _itow(nCurrent, buttonText, 10);
+
+ if(nCol == selCol && nRow == selRow) {
+ //if(nCurrent == nSelectedBook) {
+ SetBkColor(hdc, BUTTON_SEL_BACKGROUND);
+ FillRect(hdc, &buttonRect, brushBG);
+ Rectangle(hdc, buttonRect.left, buttonRect.top, buttonRect.right, buttonRect.bottom);
+ } else {
+ SetBkColor(hdc, BUTTON_BACKGROUND);
+ 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;
+
+ }
+ // Move the bounds down and all the way back to the left.
+ buttonRect.left = LeftEdge();
+ buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
+ buttonRect.top += BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT;
+ buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
+ if(nCurrent == m_nEndNumber)
+ break;
+ }
+
+ // 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 + LeftEdge());
+ buttonRect.right = buttonRect.left + BUTTON_WIDTH_MORE;
+ buttonRect.top = clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
+ buttonRect.bottom = clientRect.bottom - BUTTON_PADDING_HEIGHT;
+
+ FillRect(hdc, &buttonRect, brushBG);
+ DrawText(hdc, L"More >>", -1, &buttonRect, DT_CENTER | DT_VCENTER);
+ }
+ // We are not on the first page of numbers we need to draw a Prev button...
+ if(m_nStartAt != 1){
+ 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;
+
+ FillRect(hdc, &buttonRect, brushBG);
+ DrawText(hdc, L"<< Prev", -1, &buttonRect, DT_CENTER | DT_VCENTER);
+ }
+ //Clean up.
+ DeleteObject(brushBG);
+ EndPaint(m_hWnd,&ps);
+ return TRUE;
+}
+
+/* Return:
+ * > 0 - the number found.
+ * 0 - More button pressed.
+ * -1 - Prev button pressed.
+ * -2 - White space tapped. Ignore
+ */
+INT SRNumberChooser::NumberAt(int x, int y)
+{
+ RECT clientRect;
+ INT nCols = (x - BUTTON_PADDING_WIDTH) / (BUTTON_WIDTH_NUMBER + BUTTON_PADDING_WIDTH);
+ 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 * MaxCols()) + nCols;
+
+ if(y < BUTTON_HEIGHT + 2*BUTTON_PADDING_HEIGHT)
+ return -2; // Tapped the title area.
+
+ // Check if the tap was on a button...
+ 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 > (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 + MaxNumbersPerScreen())
+ return -2;
+
+ return nNumber;
+}
+
+BOOL SRNumberChooser::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags){
+ if(nChar == VK_RIGHT){
+ INT tempNumber = (MaxCols() * selRow) + selCol + 1;
+ if (tempNumber == m_nEndNumber) {
+ selCol = 0;
+ selRow = 0;
+ } else if (selCol == (MaxCols() - 1)) {
+ selCol = 0;
+ selRow++;
+ } else {
+ selCol++;
+ }
+ RefreshWindow();
+ } else if(nChar == VK_DOWN){
+ selRow++;
+ if(selRow >= MaxRows())
+ selRow = 0;
+ RefreshWindow();
+ } else if(nChar == VK_LEFT){
+ if(selCol <= 0)
+ selCol = MaxCols() - 1;
+ else
+ selCol--;
+ RefreshWindow();
+ } else if(nChar == VK_UP){
+ if(selRow <= 0)
+ selRow = MaxRows() - 1;
+ else
+ selRow--;
+ RefreshWindow();
+ } else if(nChar == VK_RETURN){
+ INT number = (selRow * MaxCols()) + selCol + 1;
+ ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,(SR_MSRC_CHOOSER << 16) | (m_type == CHAPTER ? SR_SETCHAPTER : SR_SETVERSE), number);
+ ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,m_wNextMenuID, number);
+ }
+ return true;
+}
+
+BOOL SRNumberChooser::OnLButtonUp(WORD fwKeys, INT xPos, INT yPos)
+{
+ TCHAR buf[16] = {0};
+ INT found = NumberAt(xPos, yPos);
+ if(found == 0 && (m_nStartAt + MaxNumbersPerScreen() <= m_nEndNumber) ){
+ m_nStartAt += MaxNumbersPerScreen();
+ RefreshWindow();
+ }else if(found == -1 && m_nStartAt != 1){
+ m_nStartAt -= MaxNumbersPerScreen();
+ RefreshWindow();
+ }else if(found == -2){
+ return TRUE;
+ }else if(found != 0 && found != -1){
+ m_nSelectedNumber = found;
+ // We also send the value found, thus when this messge is recv'd the new value can be processed.
+ ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,(SR_MSRC_CHOOSER << 16) | (m_type == CHAPTER ? SR_SETCHAPTER : SR_SETVERSE), found);
+ ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,m_wNextMenuID, found);
+ }
+ return TRUE;
+}
+
+void SRNumberChooser::SetSelectedNumber(INT nSelectedNumber)
+{
+ if(nSelectedNumber < 0 || nSelectedNumber > m_nEndNumber)
+ 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-07-02 00:49:31 UTC (rev 143)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.h 2008-07-07 02:44:42 UTC (rev 144)
@@ -1,38 +1,41 @@
-#ifndef SRNUMBERCHOOSER_H
-#define SRNUMBERCHOOSER_H
-
-#include "SRFramework/SRWnd.h"
-using namespace SRFramework;
-
-enum ChooserType { CHAPTER, VERSE };
-
-class SRNumberChooser: public SRWnd {
-public:
- SRNumberChooser(ChooserType type, 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 NumberAt(int x, int y);
- INT LeftEdge();
- INT MaxRows();
- INT MaxCols();
- INT MaxNumbersPerScreen();
-
- INT m_nEndNumber;
- INT m_nStartAt;
- INT m_nSelectedNumber;
- WORD m_wNextMenuID;
- ChooserType m_type;
- WCString m_wcsPrompt;
- static BOOL s_fRegistered;
-};
-
-#endif
+#ifndef SRNUMBERCHOOSER_H
+#define SRNUMBERCHOOSER_H
+
+#include "SRFramework/SRWnd.h"
+using namespace SRFramework;
+
+enum ChooserType { CHAPTER, VERSE };
+
+class SRNumberChooser: public SRWnd {
+public:
+ SRNumberChooser(ChooserType type, 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 OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
+ BOOL OnLButtonUp(WORD fwKeys, INT xPos, INT yPos);
+protected:
+ INT NumberAt(int x, int y);
+ INT LeftEdge();
+ INT MaxRows();
+ INT MaxCols();
+ INT MaxNumbersPerScreen();
+
+ INT m_nEndNumber;
+ INT m_nStartAt;
+ INT m_nSelectedNumber;
+ WORD m_wNextMenuID;
+ ChooserType m_type;
+ WCString m_wcsPrompt;
+ static BOOL s_fRegistered;
+ INT selCol;
+ INT selRow;
+};
+
+#endif
Modified: trunk/src/SwordReader_GUI/SwordReaderResource.h
===================================================================
--- trunk/src/SwordReader_GUI/SwordReaderResource.h 2008-07-02 00:49:31 UTC (rev 143)
+++ trunk/src/SwordReader_GUI/SwordReaderResource.h 2008-07-07 02:44:42 UTC (rev 144)
@@ -1,67 +1,69 @@
-#ifndef _SWORDREADERRESOURCE_H_
-#define _SWORDREADERRESOURCE_H_
-#include <map>
-#include <swmodule.h>
-
-/*****************************************************************************
- TODO:
- 1) Implement the Find dialog
- 2) Set the menu items to reflect current settings at startup (modules, options)
- 3) Implement actions when settings or modules are changed.
- 4) Speed up the page loads (go multi-threaded, and initially load the page
- requested then load the rest in the background)
- 5) Load the last viewed text at startup.
- 6) Separate the OT and NT Books in the Book Chooser.
- 7) Highlight the current Book/Chap/Verse in the choosers.
- 8) Allow the Choosers to respond to up/down/left/right buttons for selecting
- the items.
- 9) More to come...
-
- *****************************************************************************/
-
-struct ltstr
-{
- bool operator()(const char* s1, const char* s2) const
- {
- return strcmp(s1, s2) < 0;
- }
-};
-
-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
-#define WM_TXT_END WM_USER + 0x00F2
-
-#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
-#define SR_MSRC_CHOOSER 0x8000
-#define SR_MSRC_TEXT 0x4000
-
-#define BUTTON_BACKGROUND 0x00b9ccd5
-#define BUTTON_WIDTH_BOOK 26
-#define BUTTON_WIDTH_NUMBER 20
-#define BUTTON_WIDTH_MORE 60
-#define BUTTON_HEIGHT 17
-#define BUTTON_PADDING_WIDTH 3
-#define BUTTON_PADDING_HEIGHT 3
-
-
-
+#ifndef _SWORDREADERRESOURCE_H_
+#define _SWORDREADERRESOURCE_H_
+#include <map>
+#include <swmodule.h>
+
+/*****************************************************************************
+ TODO:
+ 1) Implement the Find dialog
+ 2) Set the menu items to reflect current settings at startup (modules, options)
+ 3) Implement actions when settings or modules are changed.
+ 4) Speed up the page loads (go multi-threaded, and initially load the page
+ requested then load the rest in the background)
+ 5) Load the last viewed text at startup.
+ 6) Separate the OT and NT Books in the Book Chooser.
+ 7) Highlight the current Book/Chap/Verse in the choosers.
+ 8) Allow the Choosers to respond to up/down/left/right buttons for selecting
+ the items.
+ 9) More to come...
+
+ *****************************************************************************/
+
+struct ltstr
+{
+ bool operator()(const char* s1, const char* s2) const
+ {
+ return strcmp(s1, s2) < 0;
+ }
+};
+
+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
+#define WM_TXT_END WM_USER + 0x00F2
+
+#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
+#define SR_MSRC_CHOOSER 0x8000
+#define SR_MSRC_TEXT 0x4000
+
+#define BUTTON_BACKGROUND 0x00b9ccd5
+#define BUTTON_SEL_BACKGROUND 0x00ffffff
+#define BUTTON_WIDTH_BOOK 28
+#define BUTTON_WIDTH_NUMBER 20
+#define BUTTON_WIDTH_MORE 60
+#define BUTTON_HEIGHT 19
+#define BUTTON_PADDING_WIDTH 2
+#define BUTTON_PADDING_HEIGHT 2
+#define BUTTON_FOREGROUND 0x00000000
+
+
+
#endif
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SwordReader_GUI.rc
===================================================================
--- trunk/src/SwordReader_GUI/SwordReader_GUI.rc 2008-07-02 00:49:31 UTC (rev 143)
+++ trunk/src/SwordReader_GUI/SwordReader_GUI.rc 2008-07-07 02:44:42 UTC (rev 144)
@@ -1,189 +1,185 @@
-//Microsoft Developer Studio generated resource script.
-//
-#include "resource.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "newres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// English (U.S.) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-#ifdef _WIN32
-LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
-#pragma code_page(1252)
-#endif //_WIN32
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Icon
-//
-
-// Icon with lowest ID value placed first to ensure application icon
-// remains consistent on all systems.
-IDI_BIBLEREADER ICON DISCARDABLE "BibleReader.ICO"
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE DISCARDABLE
-BEGIN
- "resource.h\0"
-END
-
-2 TEXTINCLUDE DISCARDABLE
-BEGIN
- "#include ""newres.h""\r\n"
- "\0"
-END
-
-3 TEXTINCLUDE DISCARDABLE
-BEGIN
- "\r\n"
- "\0"
-END
-
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Data
-//
-
-IDM_MENU SHMENUBAR MOVEABLE PURE
-BEGIN
- IDM_MENU, 6,
- I_IMAGENONE, MENU_BOOK, TBSTATE_ENABLED,
- TBSTYLE_CHECK | TBSTYLE_AUTOSIZE, IDS_CAP_BOOK, 0, NOMENU,
- I_IMAGENONE, MENU_CHAP, TBSTATE_ENABLED,
- TBSTYLE_CHECK | TBSTYLE_AUTOSIZE, IDS_CAP_CHAP, 0, NOMENU,
- I_IMAGENONE, MENU_VERSE, TBSTATE_ENABLED,
- TBSTYLE_CHECK | TBSTYLE_AUTOSIZE, IDS_CAP_VERSE, 0, NOMENU,
- I_IMAGENONE, MENU_TEXT, TBSTATE_ENABLED,
- TBSTYLE_CHECK | TBSTYLE_AUTOSIZE, IDS_CAP_TEXT, MENU_TEXT, NOMENU,
- I_IMAGENONE, MENU_FIND, TBSTATE_ENABLED,
- TBSTYLE_CHECK | TBSTYLE_AUTOSIZE, IDS_CAP_FIND, 0, NOMENU,
- I_IMAGENONE, MENU_MENU, TBSTATE_ENABLED,
- TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE, IDS_CAP_MENU, 0, 5,
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Menubar
-//
-
-IDM_MENU MENU DISCARDABLE
-BEGIN
- MENUITEM "Book", MENU_BOOK
- MENUITEM "Chap", MENU_CHAP
- MENUITEM "Verse", MENU_VERSE
- MENUITEM "Text", MENU_TEXT
- MENUITEM "Find", MENU_FIND
- POPUP "Menu"
- BEGIN
- MENUITEM "Shutdown", MENU_SHUTDOWN
- MENUITEM "About", MENU_ABOUT
- END
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Accelerator
-//
-
-IDC_BIBLEREADER ACCELERATORS DISCARDABLE
-BEGIN
- "A", IDM_HELP_ABOUT, VIRTKEY, CONTROL, NOINVERT
- "Q", IDOK, VIRTKEY, CONTROL, NOINVERT
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// DESIGNINFO
-//
-
-#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO DISCARDABLE
-BEGIN
- IDD_ERROR_NOBIBLES, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 243
- TOPMARGIN, 7
- BOTTOMMARGIN, 75
- END
-END
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Dialog
-//
-
-IDD_ERROR_NOBIBLES DIALOG DISCARDABLE 0, 0, 250, 82
-STYLE WS_POPUP
-FONT 8, "MS Sans Serif"
-BEGIN
- LTEXT "ERROR: No bibles were installed",IDC_STATIC,7,31,229,16
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_APP_TITLE "Sword Reader"
- IDC_BIBLEREADER "BIBLEREADER"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_CAP_BOOK "Book"
- IDS_CAP_CHAP "Chap"
- IDS_CAP_TEXT "Text"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_CAP_VERSE "Verse"
- IDS_CAP_BIBLE "Find"
- IDS_SELECTBOOK "Select a book:"
- IDS_SELECTCHAP "Select a chapter:"
- IDS_SELECTBIBLE "Select a bible"
- IDS_CAP_MENU "Menu"
- IDS_CAP_FIND "Find"
-END
-
-#endif // English (U.S.) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-
-
-/////////////////////////////////////////////////////////////////////////////
-#endif // not APSTUDIO_INVOKED
-
+// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "newres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+IDI_BIBLEREADER ICON "BibleReader.ICO"
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""newres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// RCDATA
+//
+
+IDM_MENU RCDATA
+BEGIN
+ 0x0066, 0x0006, 0xfffe, 0x9c44, 0x0004, 0x0012, 0x9c46, 0x0000, 0xffff,
+ 0xfffe, 0x9c47, 0x0004, 0x0012, 0x9c49, 0x0000, 0xffff, 0xfffe, 0x9c4a,
+ 0x0004, 0x0012, 0x9c50, 0x0000, 0xffff, 0xfffe, 0x9c53, 0x0004, 0x0012,
+ 0x9c4d, 0x9c53, 0xffff, 0xfffe, 0x9c5d, 0x0004, 0x0012, 0x9c5e, 0x0000,
+ 0xffff, 0xfffe, 0x9c55, 0x0004, 0x0018, 0x9c57, 0x0000, 0x0005
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Menu
+//
+
+IDM_MENU MENU
+BEGIN
+ POPUP "Navigate"
+ BEGIN
+ MENUITEM "Book", MENU_BOOK
+ MENUITEM "Chap", MENU_CHAP
+ MENUITEM "Verse", MENU_VERSE
+ MENUITEM "Text", MENU_TEXT
+ MENUITEM SEPARATOR
+ MENUITEM "Find", MENU_FIND
+ END
+ POPUP "Menu"
+ BEGIN
+ MENUITEM "About", MENU_ABOUT
+ MENUITEM "Exit", MENU_SHUTDOWN
+ END
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Accelerator
+//
+
+IDC_BIBLEREADER ACCELERATORS
+BEGIN
+ "A", IDM_HELP_ABOUT, VIRTKEY, CONTROL, NOINVERT
+ "Q", IDOK, VIRTKEY, CONTROL, NOINVERT
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_ERROR_NOBIBLES, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 243
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 75
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_ERROR_NOBIBLES DIALOG 0, 0, 250, 82
+STYLE DS_SETFONT | WS_POPUP
+FONT 8, "MS Sans Serif"
+BEGIN
+ LTEXT "ERROR: No bibles were installed",IDC_STATIC,7,31,229,16
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+STRINGTABLE
+BEGIN
+ IDS_APP_TITLE "Sword Reader"
+ IDC_BIBLEREADER "BIBLEREADER"
+END
+
+STRINGTABLE
+BEGIN
+ IDS_CAP_BOOK "Book"
+ IDS_CAP_CHAP "Chap"
+ IDS_CAP_TEXT "Text"
+END
+
+STRINGTABLE
+BEGIN
+ IDS_CAP_VERSE "Verse"
+ IDS_CAP_BIBLE "Find"
+ IDS_SELECTBOOK "Select a book:"
+ IDS_SELECTCHAP "Select a chapter:"
+ IDS_SELECTBIBLE "Select a bible"
+ IDS_CAP_MENU "Menu"
+ IDS_CAP_FIND "Find"
+END
+
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
More information about the sword-cvs
mailing list