//--------------------------------------------------------------------------- #include #pragma hdrstop #include //--------------------------------------------------------------------------- static inline SWDispRTFChap *ValidCtrCheck() { return new SWDispRTFChap(NULL); } //--------------------------------------------------------------------------- __fastcall SWDispRTFChap::SWDispRTFChap(TComponent* Owner) : SWDispRTF(Owner) { FCurVersePos = true; FCurVerseMrk = true; FMarkCurrentVerse = true; FAutoPosition = true; } __fastcall SWDispRTFChap::~SWDispRTFChap() { } void __fastcall SWDispRTFChap::Loaded(void) { SWDispRTF::Loaded(); } char SWDispRTFChap::Display(SWModule &Module) { int book, chap, verse, versepos; System::AnsiString newtext, tmptext; VerseKey *key = (VerseKey *)(SWKey *)Module; chap = key->Chapter(); book = key->Book(); verse = key->Verse(); key->Verse(1); newtext = RTFHeader; newtext = newtext + RTFChapterMarkPre + IntToStr(chap) + RTFChapterMarkPost; Module.Error(); // clear error; while ((key->Book() == book) && (key->Chapter() == chap) && (Module.Error() == 0)) { if (key->Verse() == verse) { if (MarkCurrentVerse == true) // {This does not work for shading background of current verse, but should } newtext = newtext + "\\pard \\nowidctlpar \\shading2000 \\cf2\\f0 "; // \cf2 = second color in color table else newtext = newtext + "\\pard \\nowidctlpar \\cf0\\f0 "; } else newtext = newtext + "\\pard \\nowidctlpar \\cf0 "; tmptext = ""; for (char *loop = (char *)Module; *loop; loop++) { if (*loop == '\n') tmptext += "\\par "; else tmptext += *loop; } if (tmptext.Length() > 3) { // make sure we have an entry newtext = newtext + RTFVerseMarkPre + IntToStr(key->Verse()) + RTFVerseMarkPost; newtext = newtext + RTFVersePre + tmptext + RTFVersePost; } if ((key->Verse() == verse) && (AutoPosition == true)) { tmptext = newtext + RTFTrailer; RTFStream->Clear(); RTFStream->WriteBuffer(tmptext.c_str(), tmptext.Length()); RTFStream->Position = 0; FMarkCurrentVerse = true; Lines->LoadFromStream(RTFStream); PlainText = true; versepos = GetTextLen(); //RTFStream.Position; PlainText = false; } Module++; } newtext = newtext + RTFTrailer; key->Verse(1); //{ When setting chapter: if (verse <> new chapter range) don't autonormalize. (we could've just turned the autonormalize option off then back on, but this is cooler) } key->Book(book); key->Chapter(chap); key->Verse(verse); RTFStream->Clear(); RTFStream->WriteBuffer(newtext.c_str(), newtext.Length()); RTFStream->Position = 0; Lines->LoadFromStream(RTFStream); //{ Position control text at current verse } if (AutoPosition == true) { SelStart = versepos; SendMessage(Handle, EM_SCROLLCARET, 0, 0); } return 0; } //--------------------------------------------------------------------------- namespace Swdisprtfchap { void __fastcall Register() { TComponentClass classes[1] = {__classid(SWDispRTFChap)}; RegisterComponents("SWORD", classes, 0); } } //---------------------------------------------------------------------------