[sword-cvs]
swordreader/src/gui NavFind.cpp, 1.6, 1.7 NavFind.h, 1.6,
1.7 NavRenderText.cpp, 1.12, 1.13 NavRenderText.h, 1.5,
1.6 SwordIndex.cpp, 1.11, 1.12 SwordIndex.h, 1.7,
1.8 TextControl.cpp, 1.1, 1.2 Utils.cpp, 1.2,
1.3 VerseTextControl.cpp, 1.1, 1.2
sword at www.crosswire.org
sword at www.crosswire.org
Sat Jul 24 08:28:03 MST 2004
Committed by: jgorter
Update of /cvs/core/swordreader/src/gui
In directory www:/tmp/cvs-serv21072/src/gui
Modified Files:
NavFind.cpp NavFind.h NavRenderText.cpp NavRenderText.h
SwordIndex.cpp SwordIndex.h TextControl.cpp Utils.cpp
VerseTextControl.cpp
Log Message:
- integrated HTML verseText component
- goto-button on search page works
Index: NavFind.cpp
===================================================================
RCS file: /cvs/core/swordreader/src/gui/NavFind.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- NavFind.cpp 17 Apr 2004 18:51:47 -0000 1.6
+++ NavFind.cpp 24 Jul 2004 15:28:01 -0000 1.7
@@ -141,6 +141,11 @@
if ((pos!=LB_ERR)&&(pos<verses.size())) {
previewVerse(&verses[pos]);
}
+ } else if (id==goID) {
+ int pos= SendMessage (results, LB_GETCURSEL, 0, 0);
+ if ((pos!=LB_ERR)&&(pos<verses.size())) {
+ navigateToVerse(&verses[pos]);
+ }
}
}
@@ -150,6 +155,13 @@
preview->addText(navigator->position.verseText(verse));
preview->endOfText();
}
+
+void NavFind::navigateToVerse(Verse* verse) {
+ navigator->position.setVerseKey(verse);
+ navigator->chapterCache=false;
+ navigator->setMode(MODE_TEXT);
+}
+
void NavFind::clearResults() {
SendMessage (results, LB_RESETCONTENT,0,0);
Index: NavFind.h
===================================================================
RCS file: /cvs/core/swordreader/src/gui/NavFind.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- NavFind.h 17 Apr 2004 18:51:47 -0000 1.6
+++ NavFind.h 24 Jul 2004 15:28:01 -0000 1.7
@@ -38,6 +38,7 @@
UString query;
void clearResults();
void previewVerse(Verse* verse);
+ void navigateToVerse(Verse* verse);
int rangeMode;
int methodMode;
};
Index: NavRenderText.cpp
===================================================================
RCS file: /cvs/core/swordreader/src/gui/NavRenderText.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- NavRenderText.cpp 17 Apr 2004 18:51:47 -0000 1.12
+++ NavRenderText.cpp 24 Jul 2004 15:28:01 -0000 1.13
@@ -4,118 +4,81 @@
#include <swordce.h>
-//#define NOHTML
-
-#ifndef NOHTML
-
-#include <htmlctrl.h>
-
-//#define debugfile
-
-#ifdef debugfile
- #include <stdio.h>
- FILE* file;
- #define addHtml(window,text) SendMessage(window, DTM_ADDTEXTW, FALSE, (LPARAM)text);fwprintf(file,text);
-#else
- #define addHtml(window,text) SendMessage(window, DTM_ADDTEXTW, FALSE, (LPARAM)text)
-#endif
-
-#define setZoom(window,zoom) SendMessage(window, DTM_ZOOMLEVEL, 0, zoom);
-#define clearHtml(window) SendMessage(window, DTM_CLEAR, 0, 0);
-#define endHtml(window) SendMessage(window, DTM_ENDOFSOURCE, 0, 0);
-#define controlToVerse(window,versenr) SendMessage(window, DTM_ANCHORW, FALSE, (LPARAM)(toUString(versenr).c_str()))
-
-
NavRenderText::NavRenderText(SimpleNavigator* navigator):NavPage(navigator) {
- VERIFY(InitHTMLControl(g_hInst));
- htmlControl = CreateWindowEx(WS_EX_NOACTIVATE, WC_HTML, NULL,
- WS_CHILD | HS_CLEARTYPE | HS_NOSCRIPTING |
- HS_NOIMAGES | HS_NOACTIVEX | HS_NOSOUNDS ,
- RECT_SCREEN.left, RECT_SCREEN.top, RECT_SCREEN.right, RECT_SCREEN.bottom,
- g_hWnd, NULL, g_hInst, NULL);
- setZoom(htmlControl, 1);
+ textControl = new VerseTextControl(RECT_SCREEN.left, RECT_SCREEN.top, RECT_SCREEN.right, RECT_SCREEN.bottom);
}
NavRenderText::~NavRenderText() {
+ delete textControl;
}
void NavRenderText::show() {
- ShowWindow(htmlControl,SW_SHOW);
+ textControl->show();
showText();
}
void NavRenderText::showText() {
int verse=navigator->getVerse();
if (!(navigator->chapterCache)) {
- clearHtml(htmlControl);
- ShowWindow(htmlControl,SW_HIDE);
- load();
- ShowWindow(htmlControl,SW_SHOW);
+ textControl->clearText();
+ textControl->hide();
+ __try {
+ load();
+ } __except(EXCEPTION_EXECUTE_HANDLER) { // it is not known if this still works like this
+ textControl->clearText();
+ textControl->addText(UString(L"Error: Not enough memory available"));
+ textControl->endOfText();
+ }
+ textControl->show();
if (verse!=1)
- controlToVerse(htmlControl,verse);
+ textControl->gotoAnchor(verse);
}
else
- controlToVerse(htmlControl,verse);
+ textControl->gotoAnchor(verse);
navigator->chapterCache=true;
}
void NavRenderText::load() {
-#ifdef debugfile
- file=fopen("\\chapter.html","w+");
-#endif
navigator->position.setMark();
navigator->position.setVerse(1);
- UString text = L"";
-// text += L"<?xml version=\"1.0\" encoding=\"UTF-16\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; // This is not recognized properly
- text += L"<html><head><title>c</title>"; // a <style> section presumably gets skipped
- text += L"</head><body>";
+ textControl->addText(UString(L"<html><head><title></title></head><body>")); // a <style> section presumably gets skipped
UString s;
UString heading;
char buf[10];
while (true) {
- int pvHeading = 0;
- do {
- sprintf(buf, "%i", pvHeading++);
- SWBuf preverseHeading = navigator->position.bible->getEntryAttributes()["Heading"]["Preverse"][buf].c_str();
- if (preverseHeading.length()) {
- text += L"<br><br><b>";
- text += (WCHAR *)navigator->position.bible->RenderText(preverseHeading); // do any tag conversions for our requested markup
- text += L"</b><br><br>";
- }
- else break;
- } while (true);
- s = navigator->position.verseText();
- if (s.length() > 0) {
- heading = getVerseHeader();
- text += heading;
- text += s;
+ int pvHeading = 0;
+ do {
+ sprintf(buf, "%i", pvHeading++);
+ SWBuf preverseHeading = navigator->position.bible->getEntryAttributes()["Heading"]["Preverse"][buf].c_str();
+ if (preverseHeading.length()) {
+ textControl->addText(L"<br /><br /><b>");
+ textControl->addText((WCHAR *)navigator->position.bible->RenderText(preverseHeading)); // do any tag conversions for our requested markup
+ textControl->addText(L"</b><br /><br />");
}
+ else break;
+ } while (true);
+ s = navigator->position.verseText();
+ if (s.length() > 0) {
+ textControl->addAnchoredText(getVerseHeader(),navigator->position.getVerse());
+ textControl->addText(s);
+ }
if (navigator->position.getVerse()==navigator->position.verseCount())
break;
else
navigator->position.next();
}
- text += L"</body></html>";
-
- __try {
- addHtml(htmlControl, text.c_str());
- }
- __except(EXCEPTION_EXECUTE_HANDLER) {
- addHtml(htmlControl,L"Not enough memory available");
- }
+ textControl->addText(UString(L"</body></html>"));
navigator->position.jumpBack();
- endHtml(htmlControl);
-#ifdef debugfile
- fclose(file);
-#endif
+ textControl->endOfText();
}
void NavRenderText::hide() {
- ShowWindow(htmlControl,SW_HIDE);
+ textControl->hide();
}
void NavRenderText::paint() {
+ textControl->paint();
}
UString NavRenderText::getVerseHeader() {
@@ -157,109 +120,3 @@
showText();
navigator->updateTitle();
}
-
-#else //ifndef NOHTML
-
-// A simpeler graphical representation not using the HTML component
-
-
-NavRenderText::NavRenderText(SimpleNavigator* navigator): NavPage(navigator) {
-}
-
-
-NavRenderText::~NavRenderText() {
-}
-
-
-void NavRenderText::show(bool forceRefresh) {
-}
-
-
-void NavRenderText::showText(bool forceRefresh) {
-}
-
-
-void NavRenderText::load() {
-}
-
-
-void NavRenderText::hide() {
-}
-
-
-void NavRenderText::paint() {
- clearRect(&RECT_SCREEN);
- RECT textRect=RECT_SCREEN;
- setFont(FONT_TEXT);
- navigator->position.setMark();
- verseCount=0;
- bool ready=false;
- UString s;
- UString heading;
-
- while ((textRect.top<textRect.bottom)&&(!ready)) {
- __try {
- s = noMarkup(navigator->position.verseText());
- if (s.length() > 0) {
- heading = getVerseHeader();
- textRect.top += drawVerseText(&textRect,heading+s);
- }
- }
- __except(EXCEPTION_EXECUTE_HANDLER) {
- drawVerseText(&textRect,UString(L"Not enough memory available"));
- ready=true;
- }
-
- navigator->position.next();
- verseCount++;
- }
-
- navigator->position.jumpBack();
- setFont();
-
-}
-
-
-UString NavRenderText::getVerseHeader() {
- UString result;
-
- if (navigator->position.getVerse()==1) {
- result+=toUString(navigator->position.getChap());
- result+=":";
- }
-
- result+=toUString(navigator->position.getVerse());
- result+=" ";
-
- return result;
-}
-
-
-void NavRenderText::keyDown(WPARAM id, LPARAM lparam) {
- switch (id) {
- case VK_UP:
- navigator->position--;
- navigator->refresh();
- break;
-
- case VK_DOWN:
- navigator->position++;
- navigator->refresh();
- break;
-
- case VK_LEFT:
- navigator->position-=verseCount-1;
- navigator->refresh();
- break;
-
- case VK_RIGHT:
- navigator->position+=verseCount-1;
- navigator->refresh();
- break;
-
- }
-
- navigator->updateTitle();
-}
-
-#endif
\ No newline at end of file
Index: NavRenderText.h
===================================================================
RCS file: /cvs/core/swordreader/src/gui/NavRenderText.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- NavRenderText.h 15 Mar 2004 10:44:35 -0000 1.5
+++ NavRenderText.h 24 Jul 2004 15:28:01 -0000 1.6
@@ -7,6 +7,7 @@
#include "utils.h"
#include "NavPage.h"
+#include "VerseTextControl.h"
class SimpleNavigator;
@@ -22,7 +23,8 @@
void hide();
void keyDown(WPARAM id, LPARAM lparam);
private:
- HWND htmlControl;
+// HWND htmlControl;
+ VerseTextControl* textControl;
void load();
void showText();
UString getVerseHeader();
Index: SwordIndex.cpp
===================================================================
RCS file: /cvs/core/swordreader/src/gui/SwordIndex.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- SwordIndex.cpp 17 Apr 2004 18:51:47 -0000 1.11
+++ SwordIndex.cpp 24 Jul 2004 15:28:01 -0000 1.12
@@ -159,6 +159,10 @@
return temp;
}
+void SwordIndex::setVerseKey(sword::VerseKey* anyVerse) {
+ verse->copyFrom(anyVerse);
+}
+
void SwordIndex::setMark() {
mark->copyFrom(verse);
}
Index: SwordIndex.h
===================================================================
RCS file: /cvs/core/swordreader/src/gui/SwordIndex.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- SwordIndex.h 17 Apr 2004 18:51:47 -0000 1.7
+++ SwordIndex.h 24 Jul 2004 15:28:01 -0000 1.8
@@ -87,7 +87,7 @@
TCHAR** getBookNames() {return bookNames;};
- static UString verseToString(Verse* verse);//(Verse* verse);
+ static UString verseToString(Verse* verse);
static int otBookCount() {return 39;};
static int bookCount() {return 66;};
@@ -104,6 +104,8 @@
int maxVerseCount() {return 176;};
void setVerse(int verse);
int getVerse();
+
+ void setVerseKey(sword::VerseKey* anyVerse);
void operator++(int) {verse->increment(1);};
void operator--(int) {verse->decrement(1);};
Index: TextControl.cpp
===================================================================
RCS file: /cvs/core/swordreader/src/gui/TextControl.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TextControl.cpp 17 Apr 2004 18:52:53 -0000 1.1
+++ TextControl.cpp 24 Jul 2004 15:28:01 -0000 1.2
@@ -33,7 +33,8 @@
HS_NOIMAGES | HS_NOACTIVEX | HS_NOSOUNDS ,
x, y, width, height,
g_hWnd, NULL, g_hInst, NULL);
- setZoom(htmlControl, 1);}
+ setZoom(htmlControl, 1);
+}
TextControl::~TextControl(){
}
@@ -51,6 +52,9 @@
void TextControl::clearText() {
clearHtml(htmlControl);
+#ifdef debugfile
+ file=fopen("\\chapter.html","w+");
+#endif
}
void TextControl::addText(UString text) {
@@ -59,6 +63,9 @@
void TextControl::endOfText() {
endHtml(htmlControl);
+#ifdef debugfile
+ fclose(file);
+#endif
}
#else //ifndef NOHTML
Index: Utils.cpp
===================================================================
RCS file: /cvs/core/swordreader/src/gui/Utils.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Utils.cpp 22 Feb 2004 16:12:27 -0000 1.2
+++ Utils.cpp 24 Jul 2004 15:28:01 -0000 1.3
@@ -40,12 +40,15 @@
UString noMarkup(UString in) {
bool inTag=false;
+ bool inEntity=false;
UString::iterator pos;
UString result;
for(pos=in.begin();pos!=in.end();pos++) {
if ((inTag)&&(*pos==L'>')) inTag=false;
else if ((!inTag)&&(*pos==L'<')) inTag=true;
- else if (!inTag) result+=*pos;
+ else if ((!inEntity)&&(*pos==L'&')) inEntity=true;
+ else if ((inEntity)&&(*pos==L';')) { inEntity=false; result+=L' '; } //probably
+ else if ((!inTag)&&(!inEntity)&&(*pos!=L'\n')) result+=*pos;
}
return result;
}
Index: VerseTextControl.cpp
===================================================================
RCS file: /cvs/core/swordreader/src/gui/VerseTextControl.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- VerseTextControl.cpp 17 Apr 2004 18:52:53 -0000 1.1
+++ VerseTextControl.cpp 24 Jul 2004 15:28:01 -0000 1.2
@@ -7,16 +7,20 @@
#ifndef NOHTML
+#include <htmlctrl.h>
+
+#define controlToVerse(window,versenr) SendMessage(window, DTM_ANCHORW, FALSE, (LPARAM)(toUString(versenr).c_str()))
+
VerseTextControl::VerseTextControl(int x, int y, int width, int height)
: TextControl(x,y,width,height) {}
void VerseTextControl::addAnchoredText(UString text, int anchor) {
- //TODO
+ // anchor is assumed to be embedded in the text
addText(text);
}
void VerseTextControl::gotoAnchor(int anchor) {
- //TODO
+ controlToVerse(htmlControl,anchor);
}
void VerseTextControl::paint() {}
@@ -46,14 +50,16 @@
if (current==(AnchorIterator)anchorPositions.end())
end=buffer.length();
else {
- current++;
- end=current->second;
+ current++;
+ end=(current==(AnchorIterator)anchorPositions.end())?buffer.length():current->second;
+ }
+ if (end<=start) {
+ clearRect(&textArea);
+ break; // no more text left
}
- if (end<=start) break; // no more text left
textArea.top+=drawVerseText(&textArea,buffer.substr(start, end-start));
start=end;
}
- clearRect(&textArea);
}
void VerseTextControl::clearText() {
@@ -70,6 +76,7 @@
void VerseTextControl::gotoAnchor(int anchor) {
currentAnchor=anchor;
+ refreshScreen();
}
#endif
More information about the sword-cvs
mailing list