[sword-svn] r120 - trunk/src/SwordReader_GUI
dtrotzjr at www.crosswire.org
dtrotzjr at www.crosswire.org
Sat Apr 19 16:34:40 MST 2008
Author: dtrotzjr
Date: 2008-04-19 16:34:39 -0700 (Sat, 19 Apr 2008)
New Revision: 120
Added:
trunk/src/SwordReader_GUI/SRNumberChooser.cpp
trunk/src/SwordReader_GUI/SRNumberChooser.h
Modified:
trunk/src/SwordReader_GUI/SRMainFrame.cpp
trunk/src/SwordReader_GUI/SRMainFrame.h
trunk/src/SwordReader_GUI/SRMenuBar.cpp
trunk/src/SwordReader_GUI/SRMenuBar.h
trunk/src/SwordReader_GUI/SRReaderApp.cpp
trunk/src/SwordReader_GUI/SRReaderApp.h
trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj
Log:
More restructuring. Up to this point I have the menubar in place. The translations and options menus are in place and as functional as can be at this point. I have started to implement the Book/Chapter/Verse menu and dialogs.
Modified: trunk/src/SwordReader_GUI/SRMainFrame.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.cpp 2008-04-17 03:32:22 UTC (rev 119)
+++ trunk/src/SwordReader_GUI/SRMainFrame.cpp 2008-04-19 23:34:39 UTC (rev 120)
@@ -1,5 +1,6 @@
#include "SRMainFrame.h"
#include <markupfiltmgr.h>
+#include <swordce.h>
using namespace sword;
@@ -8,11 +9,34 @@
}
SRMainFrame::SRMainFrame()
+:SRFrame()
+,m_bufModOptions(NULL)
+,m_confOptions(NULL)
+,m_keyCurVerse(NULL)
+,m_menuBar(NULL)
+,m_modCurText(NULL)
+,m_modGreekLex(NULL)
+,m_modGreekMorph(NULL)
+,m_modHebrewLex(NULL)
+,m_modHebrewMorph(NULL)
+,m_modTexts(NULL)
+,m_nTotalOpts(0)
+,m_swmgr(NULL)
+,m_viewText(NULL)
{
+ // Create a general options file for storing options
+ // and navigaiton history
+ const char *cwd = getWorkingDirectory();
+ char confFName[MAX_PATH];
+ _snprintf(confFName, MAX_PATH, "%s\\options.conf", cwd);
+ m_confOptions = new SWConfig(confFName);
+ m_confOptions->Load();
+
m_wcsClassName = "SRMainFrame";
m_wcsWindowName = "SwordReader";
m_hInstance = SRFramework::SRApp::GetInstanceHandle();
m_swmgr = new SWMgr(new sword::MarkupFilterMgr(sword::FMT_HTMLHREF, sword::ENC_UTF16));
+
}
@@ -20,6 +44,8 @@
{
if(m_swmgr)
delete m_swmgr;
+ if(m_bufModOptions)
+ delete [] m_bufModOptions;
}
BOOL SRMainFrame::Register()
@@ -120,10 +146,18 @@
}
}
+ m_modCurText = m_swmgr->getModule((*m_confOptions)["History"].getWithDefault("LastVersion", "KJV"));
+ if(!m_modCurText){
+ m_modCurText = m_modTexts->begin()->second;
+ }
+
+ m_keyCurVerse = new VerseKey((*m_confOptions)["History"].getWithDefault("LastPassage", "Gen 1:1"));
+
if(!m_menuBar || !m_menuBar->FillTranslationsSubMenu(m_modTexts,MENU_TRANS_START))
return FALSE;
- if(!m_menuBar->FillOptionsSubMenu(m_swmgr,MENU_OPTS_START))
+ GetSupportedOptions();
+ if(!m_menuBar->FillOptionsSubMenu(m_bufModOptions,MENU_OPTS_START, m_nTotalOpts))
return FALSE;
return TRUE;
@@ -131,6 +165,8 @@
BOOL SRMainFrame::OnCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl)
{
+ INT nTransID = 0;
+ INT nOptsID = 0;
switch(wID) {
case IDOK:
SendMessage(m_hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)m_hWnd);
@@ -144,14 +180,80 @@
SendMessage (m_hWnd, WM_CLOSE, 0, 0);
exit(0);
default:
- /*
- if ((wID >= USERBUTTONS)&&(wmId<USERBUTTONS+1000)) {
- g_navigator->buttonClicked(wmId - USERBUTTONS);
+ // Check the custom made menu items...
+ nTransID = wID - MENU_TRANS_START;
+ nOptsID = wID - MENU_OPTS_START;
+ if ((nTransID >= 0) && (nTransID < m_menuBar->GetTotalTranslations())) {
+ SelectModule(nTransID);
+ m_menuBar->CheckTranslationsMenuItem(wID);
break;
- }
- else */if (m_menuBar->MenuItemClicked(wID)) {
+ }else if((nOptsID >= 0) && (nOptsID < m_menuBar->GetTotalOptions())){
+ ToggleOption(wID);
}else
return FALSE;
}
return TRUE;
+}
+
+void SRMainFrame::SelectModule(INT nModIndex)
+{
+ ModuleMap::iterator it = m_modTexts->begin();
+ for(int i = 0; i < nModIndex; i++)
+ it++;
+ m_modCurText = it->second;
+
+}
+
+void SRMainFrame::GetSupportedOptions()
+{
+ StringList optionNames = m_swmgr->getGlobalOptions();
+ StringList::iterator i;
+ bool fSupported = true;
+ StringList optionValues;
+ INT optionIndex = 0;
+
+ m_nTotalOpts = 0;
+ if (m_bufModOptions)
+ delete [] m_bufModOptions;
+
+ // count the supported options
+ for (i = optionNames.begin(); i != optionNames.end(); i++) {
+ optionValues = m_swmgr->getGlobalOptionValues(*i);
+ fSupported = true;
+ for (StringList::iterator j = optionValues.begin(); j != optionValues.end(); j++) {
+ if ((*j != "On") && (*j != "Off"))
+ fSupported = false;
+ }
+ if (fSupported)
+ m_nTotalOpts++;
+ }
+
+ m_bufModOptions = new SWBuf[m_nTotalOpts];
+
+ // place the options
+ for (i = optionNames.begin(); i != optionNames.end(); i++) {
+ optionValues = m_swmgr->getGlobalOptionValues(*i);
+ fSupported = true;
+ for (StringList::iterator j = optionValues.begin(); j != optionValues.end(); j++) {
+ if ((*j != "On") && (*j != "Off"))
+ fSupported = false;
+ }
+ if (fSupported) {
+ m_bufModOptions[optionIndex++] = *i;
+ }
+ }
+}
+
+void SRMainFrame::ToggleOption(WORD wID)
+{
+ if (m_bufModOptions) {
+ for (int i = 0; i < m_nTotalOpts; i++) {
+ SWBuf val = m_swmgr->getGlobalOption(m_bufModOptions[i]);
+ if ((i + MENU_OPTS_START) == wID) {
+ val = (val == "On") ? "Off" : "On";
+ m_swmgr->setGlobalOption(m_bufModOptions[i], val);
+ m_menuBar->CheckOptionsMenuItem(wID, (val == "On"));
+ }
+ }
+ }
}
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SRMainFrame.h
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.h 2008-04-17 03:32:22 UTC (rev 119)
+++ trunk/src/SwordReader_GUI/SRMainFrame.h 2008-04-19 23:34:39 UTC (rev 120)
@@ -1,6 +1,7 @@
#pragma once
#include <swmgr.h>
#include <swmodule.h>
+#include <versekey.h>
#include "resource.h"
#include "SwordReaderResource.h"
#include "SRFramework/SRFrame.h"
@@ -28,13 +29,22 @@
BOOL CreateCommandBar();
BOOL InitSword();
BOOL OnCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl);
+
+ void SelectModule(INT nModIndex);
+ void GetSupportedOptions();
+ void ToggleOption(WORD wID);
private:
+ INT m_nTotalOpts;
+ SWConfig *m_confOptions;
+ SWBuf *m_bufModOptions;
SRMenuBar *m_menuBar;
SRTextView *m_viewText;
SWMgr *m_swmgr;
ModuleMap *m_modTexts;
+ SWModule *m_modCurText;
SWModule *m_modGreekLex;
SWModule *m_modGreekMorph;
SWModule *m_modHebrewLex;
SWModule *m_modHebrewMorph;
+ VerseKey *m_keyCurVerse;
};
Modified: trunk/src/SwordReader_GUI/SRMenuBar.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRMenuBar.cpp 2008-04-17 03:32:22 UTC (rev 119)
+++ trunk/src/SwordReader_GUI/SRMenuBar.cpp 2008-04-19 23:34:39 UTC (rev 120)
@@ -5,7 +5,6 @@
:m_menuMain(NULL)
,m_menuTrans(NULL)
,m_menuOpts(NULL)
-,m_sbufOpts(NULL)
,m_nTotalOpts(0)
{
@@ -19,8 +18,6 @@
delete m_menuTrans;
if(m_menuOpts)
delete m_menuOpts;
- if(m_sbufOpts)
- delete [] m_sbufOpts;
}
@@ -50,71 +47,40 @@
BOOL SRMenuBar::FillTranslationsSubMenu(ModuleMap *texts, int nStartID)
{
int nCurID = nStartID;
+ m_nTotalTrans = 0;
for (ModuleMap::iterator i = texts->begin(); i != texts->end(); i++) {
m_menuTrans->AppendMenu(0, nCurID++, i->first);
+ m_nTotalTrans++;
}
return TRUE;
}
-BOOL SRMenuBar::FillOptionsSubMenu(SWMgr *swmgr, int nStartID)
+BOOL SRMenuBar::FillOptionsSubMenu(SWBuf *bufOpts, int nStartID, int nTotalOpts)
{
- StringList optionNames = swmgr->getGlobalOptions();
- StringList::iterator i;
int nCurID = nStartID;
- bool fSupported = true;
- StringList optionValues;
if (m_menuOpts) {
- m_nTotalOpts = 0;
- if (m_sbufOpts)
- delete [] m_sbufOpts;
-
+ m_nTotalOpts = nTotalOpts;
// count the supported options
- for (i = optionNames.begin(); i != optionNames.end(); i++) {
- optionValues = swmgr->getGlobalOptionValues(*i);
- fSupported = true;
- for (StringList::iterator j = optionValues.begin(); j != optionValues.end(); j++) {
- if ((*j != "On") && (*j != "Off"))
- fSupported = false;
- }
- if (fSupported)
- m_nTotalOpts++;
- }
-
- m_sbufOpts = new SWBuf[m_nTotalOpts];
-
- // add options;
- for (i = optionNames.begin(); i != optionNames.end(); i++) {
- optionValues = swmgr->getGlobalOptionValues(*i);
- fSupported = true;
- for (StringList::iterator j = optionValues.begin(); j != optionValues.end(); j++) {
- if ((*j != "On") && (*j != "Off"))
- fSupported = false;
- }
- if (fSupported) {
- m_sbufOpts[nCurID - nStartID] = *i;
- m_menuOpts->AppendMenu(0, nCurID++, i->c_str());
- }
- }
+ for (int i = 0; i < m_nTotalOpts; i++){
+ m_menuOpts->AppendMenu(0,nCurID++, (bufOpts[i]).c_str());
+ }
}
// TODO: if no options, disable options menu
return TRUE;
}
-BOOL SRMenuBar::CheckTranslationsMenuItem(ModuleMap *texts, UINT nIDCheckItem)
+BOOL SRMenuBar::CheckTranslationsMenuItem(UINT nIDCheckItem)
{
- int nCurTrans = MENU_OPTS_START;
-
- for (ModuleMap::iterator i = texts->begin(); i != texts->end(); i++) {
+ for (int nCurTrans = MENU_TRANS_START; nCurTrans < MENU_TRANS_START + m_nTotalTrans; nCurTrans++) {
m_menuTrans->CheckMenuItem(nCurTrans, (nIDCheckItem == nCurTrans ? MF_CHECKED : MF_UNCHECKED) );
- nCurTrans++;
}
-
return TRUE;
}
-BOOL SRMenuBar::MenuItemClicked(WORD wID)
+
+BOOL SRMenuBar::CheckOptionsMenuItem(UINT nIDCheckItem, BOOL fChecked)
{
- return FALSE;
+ return m_menuOpts->CheckMenuItem(nIDCheckItem, (fChecked ? MF_CHECKED : MF_UNCHECKED));
}
Modified: trunk/src/SwordReader_GUI/SRMenuBar.h
===================================================================
--- trunk/src/SwordReader_GUI/SRMenuBar.h 2008-04-17 03:32:22 UTC (rev 119)
+++ trunk/src/SwordReader_GUI/SRMenuBar.h 2008-04-19 23:34:39 UTC (rev 120)
@@ -15,15 +15,17 @@
public:
BOOL Create(SRWnd* pWndParent, UINT nBarID);
BOOL FillTranslationsSubMenu(ModuleMap *texts, int nStartID);
- BOOL FillOptionsSubMenu(SWMgr *swmgr, int nStartID);
- BOOL CheckTranslationsMenuItem(ModuleMap *texts, UINT nIDCheckItem);
- BOOL MenuItemClicked(WORD wID);
+ BOOL FillOptionsSubMenu(SWBuf *bufOpts, int nStartID, int nTotalOpts);
+ BOOL CheckTranslationsMenuItem(UINT nIDCheckItem);
+ BOOL CheckOptionsMenuItem(UINT nIDCheckItem, BOOL fChecked);
+ INT GetTotalTranslations() { return m_nTotalTrans; }
+ INT GetTotalOptions() { return m_nTotalOpts; }
SRMenuBar(void);
virtual ~SRMenuBar(void);
private:
SRMenu *m_menuMain;
SRMenu *m_menuTrans;
SRMenu *m_menuOpts;
- SWBuf *m_sbufOpts;
INT m_nTotalOpts;
+ INT m_nTotalTrans;
};
Added: trunk/src/SwordReader_GUI/SRNumberChooser.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.cpp (rev 0)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.cpp 2008-04-19 23:34:39 UTC (rev 120)
@@ -0,0 +1,130 @@
+#include "SRNumberChooser.h"
+
+
+
+#define MAXHORIZONTAL 10
+#define BUTTON_BACKGROUND 0x00A0A0A0
+#define MAXNUMBERS (getMaxRows()*MAXHORIZONTAL)
+
+#define ROW0 5
+#define LASTROW ROW0+getMaxRows()*(BUTTON_HEIGHT+PADDING_HEIGHT)
+
+SRNumberChooser::SRNumberChooser()
+:m_nEndNumber(0)
+,m_nSelectedNumber(0)
+{
+}
+
+SRNumberChooser::~SRNumberChooser()
+{
+}
+
+INT SRNumberChooser::getMaxRows()
+{
+ return (GetSystemMetrics(SM_CYSCREEN) - 2*MENU_HEIGHT) / (BUTTON_HEIGHT + PADDING_HEIGHT) - 1;
+};
+
+BOOL SRNumberChooser::OnPaint() {
+ RECT rt;
+ memset(&rt,0,sizeof(rt));
+
+ RECT_SCREEN.bottom = GetSystemMetrics(SM_CYSCREEN) - 2*MENU_HEIGHT;
+ RECT_SCREEN.right = GetSystemMetrics(SM_CXSCREEN);
+
+ rt.right=RECT_SCREEN.right;
+
+ 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);
+
+ 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);
+
+ setBackground();
+ setFont();
+}
+
+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;
+}
+
+void SRNumberChooser::SetSelectedNumber(INT nSelectedNumber)
+{
+ if(nSelectedNumber < 0 || nSelectedNumber > m_nEndNumber)
+ m_nSelectedNumber = 0;
+ else
+ m_nSelectedNumber = nSelectedNumber;
+}
\ No newline at end of file
Added: trunk/src/SwordReader_GUI/SRNumberChooser.h
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.h (rev 0)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.h 2008-04-19 23:34:39 UTC (rev 120)
@@ -0,0 +1,26 @@
+#ifndef SRNUMBERCHOOSER_H
+#define SRNUMBERCHOOSER_H
+
+#include "SRFramework/SRWnd.h"
+
+class SRNumberChooser: public SRWnd {
+public:
+ SRNumberChooser();
+ 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);
+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 m_nEndNumber;
+ INT m_nSelectedNumber;
+ WCString m_wcsPrompt;
+};
+
+#endif
Modified: trunk/src/SwordReader_GUI/SRReaderApp.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRReaderApp.cpp 2008-04-17 03:32:22 UTC (rev 119)
+++ trunk/src/SwordReader_GUI/SRReaderApp.cpp 2008-04-19 23:34:39 UTC (rev 120)
@@ -1,12 +1,10 @@
#include "SRReaderApp.h"
#include "SwordReaderResource.h"
-#include <swordce.h>
SRReaderApp::SRReaderApp(HINSTANCE hInstance)
: SRFramework::SRApp(hInstance)
-, m_confOptions(NULL)
, m_pMainFrame(NULL)
{
m_hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_BIBLEREADER);
@@ -47,15 +45,6 @@
BOOL SRReaderApp::InitApp(int nCmdShow)
{
- // Create a general options file for storing options
- // and navigaiton history
- const char *cwd = getWorkingDirectory();
- char confFName[MAX_PATH];
- _snprintf(confFName, MAX_PATH, "%s\\options.conf", cwd);
-
- m_confOptions = new SWConfig(confFName);
- m_confOptions->Load();
-
m_pMainFrame = new SRMainFrame();
m_pMainFrame->Create();
m_pMainFrame->Init();
Modified: trunk/src/SwordReader_GUI/SRReaderApp.h
===================================================================
--- trunk/src/SwordReader_GUI/SRReaderApp.h 2008-04-17 03:32:22 UTC (rev 119)
+++ trunk/src/SwordReader_GUI/SRReaderApp.h 2008-04-19 23:34:39 UTC (rev 120)
@@ -15,7 +15,5 @@
WPARAM Run();
BOOL RefreshWindows();
private:
-
- SWConfig *m_confOptions ;
SRMainFrame *m_pMainFrame;
};
Modified: trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj
===================================================================
--- trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj 2008-04-17 03:32:22 UTC (rev 119)
+++ trunk/src/SwordReader_GUI/SwordReader_GUI.vcproj 2008-04-19 23:34:39 UTC (rev 120)
@@ -650,6 +650,10 @@
>
</File>
<File
+ RelativePath=".\SRNumberChooser.cpp"
+ >
+ </File>
+ <File
RelativePath=".\SRReaderApp.cpp"
>
</File>
@@ -707,6 +711,10 @@
>
</File>
<File
+ RelativePath=".\SRNumberChooser.h"
+ >
+ </File>
+ <File
RelativePath=".\SRReaderApp.h"
>
</File>
More information about the sword-cvs
mailing list