//--------------------------------------------------------------------------- #include #pragma hdrstop #include "biblecsmgr.h" #include "swdisprtfchap.h" #include #include #include #include #include #include #include #include //using namespace std; //--------------------------------------------------------------------------- static inline SWDispRTFChap *ValidCtrCheck() { return new SWDispRTFChap(NULL); } char SWDispRTFChap::platformID = 0; class SWDispRTFChap_init { public: SWDispRTFChap_init() { OSVERSIONINFO osvi; memset(&osvi, 0, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); SWDispRTFChap::platformID = osvi.dwPlatformId; } } SWDispRTFChap::_init; //--------------------------------------------------------------------------- __fastcall SWDispRTFChap::SWDispRTFChap(TWinControl *Owner) : SWDispRTF(Owner) { } __fastcall SWDispRTFChap::~SWDispRTFChap() { } void __fastcall SWDispRTFChap::Loaded(void) { SWDispRTF::Loaded(); } // Display for biblical text char SWDispRTFChap::Display(SWModule &Module) { int testmt, book, chap, verse, versepos; char buf[254]; System::AnsiString newtext, tmptext, tmptext2; VerseKey *key = (VerseKey *)(SWKey *)Module; key->Headings(1); testmt = key->Testament(); book = key->Book(); chap = key->Chapter(); verse = key->Verse(); key->AutoNormalize(0); key->Verse(0); if (chap == 1) { key->Chapter(0); if (book == 1) { key->Book(0); if (testmt == 1) key->Testament(0); } } key->AutoNormalize(0); module = &Module; type = "Default"; recalcAppearance(); newtext = RTFHeader; newtext = newtext + RTFChapterMarkPre + IntToStr(chap) + RTFChapterMarkPost; newtext = newtext + "\\pard\\f0\\nowidctlpar\\cf7 "; if (Module.Direction() == DIRECTION_RTL) { newtext = newtext + "\\qr "; } if (Module.Direction() == DIRECTION_RTL && (platformID == VER_PLATFORM_WIN32_NT && (!strnicmp(Module.Lang(), "he", 2) || (!strnicmp(Module.Lang(), "fa", 2) || !strnicmp(Module.Lang(), "ar", 2)))) { newtext = newtext + "\\rtlpar "; } Module.Error(); // clear error; SWBuf lastEntry = "something the first entry will never be"; while (((!key->Book())||(key->Book() == book)) && ((!key->Chapter())||(key->Chapter() == chap)) && (Module.Error() == 0)) { SWBuf rawText = Module.getRawEntry(); // strip off any leading and ending whitespace rawText.trim(); if (lastEntry == rawText) { Module++; continue; } newtext = newtext + "{"; tmptext = ""; lastEntry = rawText; for (const char *loop = (const char *)Module; *loop; loop++) { if (*loop == '\n') { tmptext += "\\par "; } else tmptext += *loop; } if (tmptext.Length() > 3) { // make sure we have an entry int pvHeading = 0; do { sprintf(buf, "%i", pvHeading++); SWBuf preverseHeading = module->getEntryAttributes()["Heading"]["Preverse"][buf].c_str(); preverseHeading = Module.RenderText(preverseHeading); if (preverseHeading.length()) { newtext += ((AnsiString)"\\par\\par {\\i1\\b1 ") + preverseHeading.c_str() + "\\par}"; } else break; } while (true); if (Module.Direction() == DIRECTION_RTL && (platformID == VER_PLATFORM_WIN32_WINDOWS || (Module.Lang() && strnicmp(Module.Lang(), "he", 2) && strnicmp(Module.Lang(), "ar", 2) && strnicmp(Module.Lang(), "fa", 2)))) { newtext = newtext + RTFVersePre; if ((key->Verse() == verse) && (dispAttribs.markCurrentVerse)) { newtext = newtext + "\\cf2 "; // \cf2 = second color in color table } newtext += tmptext + RTFVersePost; if (key->Verse()) newtext = newtext + RTFVerseMarkPre + /*"" +*/ IntToStr(key->Verse()) /*+ ""*/ + RTFVerseMarkPost; if (!dispAttribs.verseNewLine) newtext = newtext + "\\par "; } else { if (key->Verse()) newtext = newtext + RTFVerseMarkPre + /*"" +*/ IntToStr(key->Verse()) /*+ ""*/ + RTFVerseMarkPost; newtext = newtext + RTFVersePre; if ((key->Verse() == verse) && (dispAttribs.markCurrentVerse)) { newtext = newtext + "\\cf2 "; // \cf2 = second color in color table } newtext += tmptext + RTFVersePost; } // check for headings and add a couple new lines, if so. if ((!key->Verse()) || (!key->Chapter()) || (!key->Book()) || (!key->Testament())) { if (rawText.size()) newtext = newtext + "\\par\\par"; } // we don't want to add too many newlines if this display option is turned on, so this is in an else. else { if (dispAttribs.verseNewLine) { newtext += "\\par "; } } } if (key->Verse() == verse) { tmptext = newtext + RTFTrailer + "}"; RTFStream->Clear(); RTFStream->WriteBuffer(tmptext.c_str(), tmptext.Length()); RTFStream->Position = 0; Lines->LoadFromStream(RTFStream); makeLinks(); makeImages(); versepos = GetTextLen() - 3; } newtext = newtext + "}"; Module++; } newtext = newtext + RTFTrailer; key->Verse(1); //{ When setting chapter: if (verse !in new chapter range) don't autonormalize. (we could've just turned the autonormalize option off then back on, but this is cooler) } key->Chapter(1); key->Book(1); key->Testament(testmt); key->Book(book); key->Chapter(chap); key->Verse(verse); RTFStream->Clear(); RTFStream->WriteBuffer(newtext.c_str(), newtext.Length()); // int fd = open("rtfout.txt", O_CREAT|O_RDWR|O_TRUNC, S_IREAD|S_IWRITE); // write(fd, newtext.c_str(), newtext.Length()); // close(fd); RTFStream->Position = 0; Lines->LoadFromStream(RTFStream); makeLinks(); makeImages(); //{ Position control text at current verse } this->SetFocus(); SelStart = 1; SendMessage(Handle, EM_SCROLLCARET, 0, 0); SelStart = versepos; SendMessage(Handle, EM_SCROLLCARET, 0, 0); return 0; } //--------------------------------------------------------------------------- namespace Swdisprtfchap { void __fastcall Register() { TComponentClass classes[1] = {__classid(SWDispRTFChap)}; RegisterComponents("SWORD", classes, 0); } } //---------------------------------------------------------------------------