[sword-cvs] swordreader/src/gui SimpleNavigator.cpp,1.1,1.2 SimpleNavigator.h,1.1,1.2

sword@www.crosswire.org sword@www.crosswire.org
Mon, 15 Mar 2004 01:47:22 -0700


Update of /cvs/core/swordreader/src/gui
In directory www:/tmp/cvs-serv23900

Modified Files:
	SimpleNavigator.cpp SimpleNavigator.h 
Log Message:
Modified SimpleNavigator.* so it will probably not be corrupted anymore


Index: SimpleNavigator.cpp
===================================================================
RCS file: /cvs/core/swordreader/src/gui/SimpleNavigator.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- SimpleNavigator.cpp	15 Mar 2004 08:40:45 -0000	1.1
+++ SimpleNavigator.cpp	15 Mar 2004 08:47:20 -0000	1.2
@@ -1,297 +1,298 @@
-#include "ApplicationInterface.h"
-#include "SimpleNavigator.h"
-#include "NavChap.h"
-#include "NavVerse.h"
-#include "NavBooks.h"
-#include "NavRenderText.h"
-
-#include "NavFind.h"
-#include <swordce.h>
-#include <swmgr.h>
-
-using namespace sword;
-
-#define WIDTH 240
-#define HEIGHT 294
-
-RECT RECT_SCREEN;// = {0,0,240,294};
-
-RECT RECT_SELECTLABEL = {4,4,120,20};
-
-RECT RECT_POSITION = {164,4,236,20};
-
-RECT RECT_FIELD = {6,24,240,250};
-
-SimpleNavigator::SimpleNavigator(RECT* screen) {
-	RECT_SCREEN=*screen;
-	mode=-1;
-	nextID = 1;
-	chapterCache=false;
-	books=pages[MODE_BOOK]=new NavBooks(this);
-	chapters=pages[MODE_CHAP]=new NavChap(this);
-	verses=pages[MODE_VERSE]=new NavVerse(this);
-	text=pages[MODE_TEXT]=new NavRenderText(this);
-	find=pages[MODE_FIND]=new NavFind(this);
-	menus[MODE_BOOK]=MENU_BOOK;
-	menus[MODE_CHAP]=MENU_CHAP;
-	menus[MODE_VERSE]=MENU_VERSE;
-	menus[MODE_TEXT]=MENU_TEXT;
-	menus[MODE_FIND]=MENU_FIND;
-	optStartID = 0;
-	optEndID = 0;
-	transStartID = 0;
-	transEndID = 0;
-	options = 0;
-	opCount = 0;
-}
-
-SimpleNavigator::~SimpleNavigator() {
-	delete books;
-	delete chapters;
-	delete verses;
-	delete text;
-	delete find;
-	if (options)
-		delete options;
-}
-
-void SimpleNavigator::refresh() {
-	refreshScreen();
-}
-
-void SimpleNavigator::setMode(int mode) {
-	if (this->mode>=0) pages[this->mode]->hide();
-	this->mode=mode;
-	selectMenu(menus[this->mode]);
-	pages[this->mode]->show();
-	updateTitle();
-	refresh();
-}
-
-void SimpleNavigator::paint() {
-	pages[mode]->paint();
-}
-
-void SimpleNavigator::updateTitle() {
-	UString title=position.toString()+L" - SwRd";
-	setTitle(title);
-}
-
-/* a menu-item is selected (maybe one of the translations) */
-void SimpleNavigator::buttonClicked(int id) {
-	if ((id >= transStartID) && (id <= transEndID)) {
-		setModule(id);
-		checkModuleMenu(id);
-		chapterCache=false;
-		setMode(mode);
-	}
-	else if ((id >= optStartID) && (id <= optEndID)) {
-		toggleOptionMenu(id);
-		chapterCache=false;
-		setMode(mode);
-	}
-	else
-		pages[mode]->buttonClicked(id);
-}
-
-bool SimpleNavigator::menuClicked(int id) {
-	for (std::map<int,int>::iterator i=menus.begin();i!=menus.end();i++) {
-		if (i->second==id) {
-			setMode(i->first);
-			return true;
-		}
-	}
-	return false;
-}
-
-void SimpleNavigator::keyDown(WPARAM id, LPARAM lparam) {
-	pages[mode]->keyDown(id,lparam);
-}
-
-void SimpleNavigator::mouseDown(int x, int y) {
-	pages[mode]->userTap(x,y);
-}
-
-void SimpleNavigator::setBook(int number) {
-	position.setBook(number);
-	chapterCache=false;
-}
-
-void SimpleNavigator::setChap(int number) {
-	position.setChap(number);
-	chapterCache=false;
-}
-
-void SimpleNavigator::setVerse(int number) {
-	position.setVerse(number);
-}
-
-void SimpleNavigator::fillTranslationsMenu(HMENU menuTranslations) {
-	transStartID = nextID;
-	this->menuTranslations=menuTranslations;
-	if (menuTranslations) {
-		for (ModuleMap::iterator i=position.firstModule();i!=position.lastModule();i++) {
-			addMenu(menuTranslations, nextID++, toUString(String(i->first)));
-		}
-	}
-	checkModuleMenu(transStartID);
-	transEndID = nextID - 1;
-}
-
-void SimpleNavigator::fillGlobalOptionsMenu(HMENU menuOptions) {
-	if (menuOptions) {
-		if (options)
-			delete options;
-		optStartID = nextID;
-		this->menuOptions=menuOptions;
-		StringList optionNames = position.manager->getGlobalOptions();
-
-		// count options
-		opCount = 0;
-		for (StringList::iterator i = optionNames.begin(); i != optionNames.end(); i++) {
-			StringList values = position.manager->getGlobalOptionValues(*i);
-			bool supported = true;
-			for (StringList::iterator j = values.begin(); j != values.end(); j++) {
-				if ((*j != "On") && (*j != "Off"))
-					supported = false;
-			}
-			if (supported)
-				opCount++;
-		}
-
-		options = new SWBuf[opCount];
-
-		// add options;
-		for (i = optionNames.begin(); i != optionNames.end(); i++) {
-//			HMENU menuOption = CreatePopupMenu();
-//			InsertMenu(menuOptions,0,MF_POPUP,(UINT)menuOption, toUString(i->c_str()).c_str());
-			StringList values = position.manager->getGlobalOptionValues(*i);
-			bool supported = true;
-			for (StringList::iterator j = values.begin(); j != values.end(); j++) {
-//				addMenu(menuOption, nextID++, toUString(j->c_str()));
-				if ((*j != "On") && (*j != "Off"))
-					supported = false;
-			}
-			if (supported) {
-				options[nextID - optStartID] = *i;
-				addMenu(menuOptions, nextID++, toUString(i->c_str()));
-			}
-		}
-	}
-	optEndID = nextID - 1;
-	// TODO: if no options, disable options menu
-}
-
-void SimpleNavigator::setModule(int id) {
-	int modulenr = transStartID;
-	ModuleMap::iterator i;
-	for (i=position.firstModule();
-			(i!=position.lastModule())&&(id!=modulenr);
-			i++) { 
-		modulenr++; 
-	};
-	if (i!=position.lastModule()) {
-		position.setModule(i->second);
-	}
-}
-
-
-void SimpleNavigator::checkModuleMenu(int id) {
-	int current=transStartID;
-	for (ModuleMap::iterator i=position.firstModule();i!=position.lastModule();i++) {
-		checkMenu(menuTranslations,current,(current==id));
-		current++;
-	}
-}
-
-
-void SimpleNavigator::toggleOptionMenu(int id) {
-	if (options) {
-		for (int i = optStartID; i <= optEndID; i++) {
-			SWBuf val = position.manager->getGlobalOption(options[i-optStartID]);
-			if (i == id) {
-				val = (val=="On")?"Off":"On";
-				position.manager->setGlobalOption(options[i-optStartID], val);
-			}
-			checkMenu(menuOptions, i, (val == "On"));
-		}
-	}
-}
-
-void SimpleNavigator::urlClicked(const WCHAR *target) {
-	const char * t = wstrtostr(target);
-	if (strstr(t, "type=morph")) {
-		const char *val = strstr(t, "value=");
-		if ((val) && (strlen(val) > 6)) {
-			val += 6;
-			SWModule *mod = (position.verse->Testament() == 1) ? position.hebrewMorph : position.greekMorph;
-			if (mod) {
-				mod->SetKey(val);
-				MessageBox(0, strtowstr(mod->StripText()), L"Morphology", MB_OK);
-			}
-		}
-	}
-	else if (strstr(t, "type=Strongs")) {
-		const char *val = strstr(t, "value=G");
-		if ((val) && (strlen(val) > 7)) {
-			val += 7;
-			if (position.greekLex) {
-				position.greekLex->SetKey(val);
-				MessageBox(0, strtowstr(position.greekLex->StripText()), L"Greek Strong's", MB_OK);
-			}
-		}
-		val = strstr(t, "value=H");
-		if ((val) && (strlen(val) > 7)) {
-			val += 7;
-			if (position.hebrewLex) {
-				position.hebrewLex->SetKey(val);
-				MessageBox(0, strtowstr(position.hebrewLex->StripText()), L"Hebrew Strong's", MB_OK);
-			}
-		}
-	}
-	else if (strstr(t, "noteID=")) {
-		const char *val = strstr(t, "noteID=");
-		if ((val) && (strlen(val) > 7)) {
-			val += 7;
-			SWBuf buf = val;
-			const char *tmp = buf.c_str();
-			val = strstr(tmp, ".n.");
-			if (val) {
-				buf.setSize(val - tmp);
-				SWBuf saveKey = position.verse->getText();
-				position.verse->setText(buf.c_str());
-				position.bible->StripText();	// force lookup
-				const char *n = strstr(t, ".n.");
-				if (n) {
-					SWBuf body = position.bible->getEntryAttributes()["Footnote"][n+3]["body"];
-					body = position.bible->StripText(body.c_str());
-					MessageBox(0, strtowstr(body), L"Footnote", MB_OK);
-				}
-				position.verse->setText(saveKey);
-			}
-			else {
-				val = strstr(tmp, ".x.");
-				if (val) {
-					buf.setSize(val - tmp);
-					SWBuf saveKey = position.verse->getText();
-					position.verse->setText(buf.c_str());
-					position.bible->StripText();	// force lookup
-					const char *n = strstr(t, ".x.");
-					if (n) {
-						SWBuf body = position.bible->getEntryAttributes()["Footnote"][n+3]["body"];
-						body = position.bible->StripText(body.c_str());
-						MessageBox(0, strtowstr(body), L"CrossReference", MB_OK);
-					}
-					position.verse->setText(saveKey);
-				}
-			}
-		}
-	}
-	else MessageBox(0, target, L"url clicked", MB_OK);
-
-}
-int SimpleNavigator::getID() {
-
-	return nextID++;
-
-}
\ No newline at end of file
+#include "ApplicationInterface.h"
+#include "SimpleNavigator.h"
+#include "NavChap.h"
+#include "NavVerse.h"
+#include "NavBooks.h"
+#include "NavRenderText.h"
+
+#include "NavFind.h"
+#include <swordce.h>
+#include <swmgr.h>
+
+using namespace sword;
+
+#define WIDTH 240
+#define HEIGHT 294
+
+RECT RECT_SCREEN;// = {0,0,240,294};
+
+RECT RECT_SELECTLABEL = {4,4,120,20};
+
+RECT RECT_POSITION = {164,4,236,20};
+
+RECT RECT_FIELD = {6,24,240,250};
+
+SimpleNavigator::SimpleNavigator(RECT* screen) {
+	RECT_SCREEN=*screen;
+	mode=-1;
+	nextID = 1;
+	chapterCache=false;
+	books=pages[MODE_BOOK]=new NavBooks(this);
+	chapters=pages[MODE_CHAP]=new NavChap(this);
+	verses=pages[MODE_VERSE]=new NavVerse(this);
+	text=pages[MODE_TEXT]=new NavRenderText(this);
+	find=pages[MODE_FIND]=new NavFind(this);
+	menus[MODE_BOOK]=MENU_BOOK;
+	menus[MODE_CHAP]=MENU_CHAP;
+	menus[MODE_VERSE]=MENU_VERSE;
+	menus[MODE_TEXT]=MENU_TEXT;
+	menus[MODE_FIND]=MENU_FIND;
+	optStartID = 0;
+	optEndID = 0;
+	transStartID = 0;
+	transEndID = 0;
+	options = 0;
+	opCount = 0;
+}
+
+SimpleNavigator::~SimpleNavigator() {
+	delete books;
+	delete chapters;
+	delete verses;
+	delete text;
+	delete find;
+	if (options)
+		delete options;
+}
+
+void SimpleNavigator::refresh() {
+	refreshScreen();
+}
+
+void SimpleNavigator::setMode(int mode) {
+	if (this->mode>=0) pages[this->mode]->hide();
+	this->mode=mode;
+	selectMenu(menus[this->mode]);
+	pages[this->mode]->show();
+	updateTitle();
+	refresh();
+}
+
+void SimpleNavigator::paint() {
+	pages[mode]->paint();
+}
+
+void SimpleNavigator::updateTitle() {
+	UString title=position.toString()+L" - SwRd";
+	setTitle(title);
+}
+
+/* a menu-item is selected (maybe one of the translations) */
+void SimpleNavigator::buttonClicked(int id) {
+	if ((id >= transStartID) && (id <= transEndID)) {
+		setModule(id);
+		checkModuleMenu(id);
+		chapterCache=false;
+		setMode(mode);
+	}
+	else if ((id >= optStartID) && (id <= optEndID)) {
+		toggleOptionMenu(id);
+		chapterCache=false;
+		setMode(mode);
+	}
+	else
+		pages[mode]->buttonClicked(id);
+}
+
+bool SimpleNavigator::menuClicked(int id) {
+	for (std::map<int,int>::iterator i=menus.begin();i!=menus.end();i++) {
+		if (i->second==id) {
+			setMode(i->first);
+			return true;
+		}
+	}
+	return false;
+}
+
+void SimpleNavigator::keyDown(WPARAM id, LPARAM lparam) {
+	pages[mode]->keyDown(id,lparam);
+}
+
+void SimpleNavigator::mouseDown(int x, int y) {
+	pages[mode]->userTap(x,y);
+}
+
+void SimpleNavigator::setBook(int number) {
+	position.setBook(number);
+	chapterCache=false;
+}
+
+void SimpleNavigator::setChap(int number) {
+	position.setChap(number);
+	chapterCache=false;
+}
+
+void SimpleNavigator::setVerse(int number) {
+	position.setVerse(number);
+}
+
+void SimpleNavigator::fillTranslationsMenu(HMENU menuTranslations) {
+	transStartID = nextID;
+	this->menuTranslations=menuTranslations;
+	if (menuTranslations) {
+		for (ModuleMap::iterator i=position.firstModule();i!=position.lastModule();i++) {
+			addMenu(menuTranslations, nextID++, toUString(String(i->first)));
+		}
+	}
+	checkModuleMenu(transStartID);
+	transEndID = nextID - 1;
+}
+
+void SimpleNavigator::fillGlobalOptionsMenu(HMENU menuOptions) {
+	if (menuOptions) {
+		if (options)
+			delete options;
+		optStartID = nextID;
+		this->menuOptions=menuOptions;
+		StringList optionNames = position.manager->getGlobalOptions();
+
+		// count options
+		opCount = 0;
+		for (StringList::iterator i = optionNames.begin(); i != optionNames.end(); i++) {
+			StringList values = position.manager->getGlobalOptionValues(*i);
+			bool supported = true;
+			for (StringList::iterator j = values.begin(); j != values.end(); j++) {
+				if ((*j != "On") && (*j != "Off"))
+					supported = false;
+			}
+			if (supported)
+				opCount++;
+		}
+
+		options = new SWBuf[opCount];
+
+		// add options;
+		for (i = optionNames.begin(); i != optionNames.end(); i++) {
+//			HMENU menuOption = CreatePopupMenu();
+//			InsertMenu(menuOptions,0,MF_POPUP,(UINT)menuOption, toUString(i->c_str()).c_str());
+			StringList values = position.manager->getGlobalOptionValues(*i);
+			bool supported = true;
+			for (StringList::iterator j = values.begin(); j != values.end(); j++) {
+//				addMenu(menuOption, nextID++, toUString(j->c_str()));
+				if ((*j != "On") && (*j != "Off"))
+					supported = false;
+			}
+			if (supported) {
+				options[nextID - optStartID] = *i;
+				addMenu(menuOptions, nextID++, toUString(i->c_str()));
+			}
+		}
+	}
+	optEndID = nextID - 1;
+	// TODO: if no options, disable options menu
+}
+
+void SimpleNavigator::setModule(int id) {
+	int modulenr = transStartID;
+	ModuleMap::iterator i;
+	for (i=position.firstModule();
+			(i!=position.lastModule())&&(id!=modulenr);
+			i++) { 
+		modulenr++; 
+	};
+	if (i!=position.lastModule()) {
+		position.setModule(i->second);
+	}
+}
+
+
+void SimpleNavigator::checkModuleMenu(int id) {
+	int current=transStartID;
+	for (ModuleMap::iterator i=position.firstModule();i!=position.lastModule();i++) {
+		checkMenu(menuTranslations,current,(current==id));
+		current++;
+	}
+}
+
+
+void SimpleNavigator::toggleOptionMenu(int id) {
+	if (options) {
+		for (int i = optStartID; i <= optEndID; i++) {
+			SWBuf val = position.manager->getGlobalOption(options[i-optStartID]);
+			if (i == id) {
+				val = (val=="On")?"Off":"On";
+				position.manager->setGlobalOption(options[i-optStartID], val);
+			}
+			checkMenu(menuOptions, i, (val == "On"));
+		}
+	}
+}
+
+void SimpleNavigator::urlClicked(const WCHAR *target) {
+	const char * t = wstrtostr(target);
+	if (strstr(t, "type=morph")) {
+		const char *val = strstr(t, "value=");
+		if ((val) && (strlen(val) > 6)) {
+			val += 6;
+			SWModule *mod = (position.verse->Testament() == 1) ? position.hebrewMorph : position.greekMorph;
+			if (mod) {
+				mod->SetKey(val);
+				MessageBox(0, strtowstr(mod->StripText()), L"Morphology", MB_OK);
+			}
+		}
+	}
+	else if (strstr(t, "type=Strongs")) {
+		const char *val = strstr(t, "value=G");
+		if ((val) && (strlen(val) > 7)) {
+			val += 7;
+			if (position.greekLex) {
+				position.greekLex->SetKey(val);
+				MessageBox(0, strtowstr(position.greekLex->StripText()), L"Greek Strong's", MB_OK);
+			}
+		}
+		val = strstr(t, "value=H");
+		if ((val) && (strlen(val) > 7)) {
+			val += 7;
+			if (position.hebrewLex) {
+				position.hebrewLex->SetKey(val);
+				MessageBox(0, strtowstr(position.hebrewLex->StripText()), L"Hebrew Strong's", MB_OK);
+			}
+		}
+	}
+	else if (strstr(t, "noteID=")) {
+		const char *val = strstr(t, "noteID=");
+		if ((val) && (strlen(val) > 7)) {
+			val += 7;
+			SWBuf buf = val;
+			const char *tmp = buf.c_str();
+			val = strstr(tmp, ".n.");
+			if (val) {
+				buf.setSize(val - tmp);
+				SWBuf saveKey = position.verse->getText();
+				position.verse->setText(buf.c_str());
+				position.bible->StripText();	// force lookup
+				const char *n = strstr(t, ".n.");
+				if (n) {
+					SWBuf body = position.bible->getEntryAttributes()["Footnote"][n+3]["body"];
+					body = position.bible->StripText(body.c_str());
+					MessageBox(0, strtowstr(body), L"Footnote", MB_OK);
+				}
+				position.verse->setText(saveKey);
+			}
+			else {
+				val = strstr(tmp, ".x.");
+				if (val) {
+					buf.setSize(val - tmp);
+					SWBuf saveKey = position.verse->getText();
+					position.verse->setText(buf.c_str());
+					position.bible->StripText();	// force lookup
+					const char *n = strstr(t, ".x.");
+					if (n) {
+						SWBuf body = position.bible->getEntryAttributes()["Footnote"][n+3]["body"];
+						body = position.bible->StripText(body.c_str());
+						MessageBox(0, strtowstr(body), L"CrossReference", MB_OK);
+					}
+					position.verse->setText(saveKey);
+				}
+			}
+		}
+	}
+	else MessageBox(0, target, L"url clicked", MB_OK);
+
+}
+int SimpleNavigator::getID() {
+
+	return nextID++;
+
+}
+

Index: SimpleNavigator.h
===================================================================
RCS file: /cvs/core/swordreader/src/gui/SimpleNavigator.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- SimpleNavigator.h	15 Mar 2004 08:40:45 -0000	1.1
+++ SimpleNavigator.h	15 Mar 2004 08:47:20 -0000	1.2
@@ -1,5 +1,5 @@
-#ifndef SIMPLENAVIGATOR_H
-#define SIMPLENAVIGATOR_H
+#ifndef SIMPLENAVIGATOR_H
+#define SIMPLENAVIGATOR_H
 
 #if _MSC_VER > 1000
 #pragma once
@@ -7,9 +7,9 @@
 
 
 #include "utils.h"
-#include "SwordIndex.h"
+#include "SwordIndex.h"
 #include "NavPage.h"
-#include <swbuf.h>
+#include <swbuf.h>
 #include <map>
 
 using namespace sword;
@@ -28,14 +28,14 @@
 
 class NavNumbers;
 class NavBooks;
-class NavRenderText;
+class NavRenderText;
 class NavFind;
 
 class SimpleNavigator
 {
-protected:
-	std::map<int,NavPage*> pages;
-	std::map<int,int> menus;
+protected:
+	std::map<int,NavPage*> pages;
+	std::map<int,int> menus;
 	int mode;
 
 	HMENU menuTranslations;
@@ -55,48 +55,49 @@
 
 public:
 	SwordIndex position;
-	NavPage* chapters;
+	NavPage* chapters;
 	NavPage* verses;
 	NavPage* books;
-	NavPage* text;
-	NavPage* find;
-
+	NavPage* text;
+	NavPage* find;
+
 	SimpleNavigator(RECT* screen);
-	virtual ~SimpleNavigator();
-
-	//	Navigation
-	void setBook(int number);
-	void setChap(int number);
-	void setVerse(int number);
-
-	int getBook() {return position.getBook();};
-	int getChap() {return position.verse->Chapter();};
-	int getVerse() {return position.verse->Verse();};
-
-	int chapCount() {return position.chapCount();}
-	int verseCount() {return position.verseCount();}
+	virtual ~SimpleNavigator();
 
-	//	Change user interface
+	//	Navigation
+	void setBook(int number);
+	void setChap(int number);
+	void setVerse(int number);
+
+	int getBook() {return position.getBook();};
+	int getChap() {return position.verse->Chapter();};
+	int getVerse() {return position.verse->Verse();};
+
+	int chapCount() {return position.chapCount();}
+	int verseCount() {return position.verseCount();}
+
+	//	Change user interface
 	void updateTitle();
 	void fillTranslationsMenu(HMENU menuTranslations);
-	void fillGlobalOptionsMenu(HMENU menuTranslations);
+	void fillGlobalOptionsMenu(HMENU menuTranslations);
 	void toggleOptionMenu(int id);
-
+
 	//	Interface with pages
-	int getID();
-	void setMode(int mode);
-	bool chapterCache;	// to be set to false if 'text' should reload 
-						// its chapter
-	void refresh();
-
-	//	Interface with system
-	bool initialized() {return position.initialized();}
-	void buttonClicked(int id);
-	void keyDown(WPARAM id, LPARAM lparam);
-	void urlClicked(const WCHAR *target);
-	bool menuClicked(int id);
-	void mouseDown(int x, int y);
-	void paint();
+	int getID();
+	void setMode(int mode);
+	bool chapterCache;	// to be set to false if 'text' should reload 
+						// its chapter
+	void refresh();
+
+	//	Interface with system
+	bool initialized() {return position.initialized();}
+	void buttonClicked(int id);
+	void keyDown(WPARAM id, LPARAM lparam);
+	void urlClicked(const WCHAR *target);
+	bool menuClicked(int id);
+	void mouseDown(int x, int y);
+	void paint();
 };
 
-#endif
\ No newline at end of file
+#endif
+