//--------------------------------------------------------------------------- #include #pragma hdrstop #include "swdisprtf.h" //--------------------------------------------------------------------------- static inline SWDispRTF *ValidCtrCheck() { return new SWDispRTF(NULL); } //--------------------------------------------------------------------------- __fastcall SWDispRTF::SWDispRTF(TComponent* Owner) #ifndef USEOLDRTF : TRxRichEdit(Owner) #else : TRichEdit(Owner) #endif { char buf[4096]; RTFHeader = defRTFHeader; RTFHeadMargin = defRTFHeadMargin; sprintf(buf, defRTFTrailer, 24); RTFTrailer = buf; sprintf(buf, defRTFChapterMarkPre, 30); RTFChapterMarkPre = buf; sprintf(buf, defRTFChapterMarkPost, 10); RTFChapterMarkPost = buf; sprintf(buf, defRTFVerseMarkPre, 20); RTFVerseMarkPre = buf; RTFVerseMarkPost = defRTFVerseMarkPost; sprintf(buf, defRTFVersePre, 24); RTFVersePre = buf; RTFVersePost = defRTFVersePost; RTFStream = new TMemoryStream(); ExpandNewLine = true; } __fastcall SWDispRTF::~SWDispRTF() { if (RTFStream) delete RTFStream; } void __fastcall SWDispRTF::Loaded(void) { #ifndef USEOLDRTF TRxRichEdit::Loaded(); #else TRichEdit::Loaded(); #endif /* if (RTFHeader == "") RTFHeader = defRTFHeader; if (RTFTrailer == "") RTFTrailer = defRTFTrailer; if (RTFChapterMarkPre == "") RTFChapterMarkPre = defRTFChapterMarkPre; if (RTFChapterMarkPost == "") RTFChapterMarkPost = defRTFChapterMarkPost; if (RTFVerseMarkPre == "") RTFVerseMarkPre = defRTFVerseMarkPre; if (RTFVerseMarkPost == "") RTFVerseMarkPost = defRTFVerseMarkPost; if (RTFVersePre == "") RTFVersePre = defRTFVersePre; if (RTFVersePost == "") RTFVersePost = defRTFVersePost; */ } int __fastcall SWDispRTF::GetMySelStart() { CHARRANGE cr; SendMessage(Handle, EM_EXGETSEL, 0, (long)&cr); return cr.cpMin; } void __fastcall SWDispRTF::SetMySelStart(int iselstart) { CHARRANGE cr; cr.cpMin = iselstart; cr.cpMax = iselstart; SendMessage(Handle, EM_EXSETSEL, 0, (long)&cr); } char SWDispRTF::Display(SWModule &Module) { System::AnsiString newtext, tmptext; newtext = RTFHeader; newtext = newtext + RTFHeadMargin; Module.Error(); // clear error; newtext = newtext + "\\pard \\nowidctlpar \\cf7\\f0 "; (const char *)Module; // force key to snap to entry before pulling out the text of the key newtext = newtext + RTFVerseMarkPre + Module.KeyText() + RTFVerseMarkPost; tmptext = ""; /* for (char *loop = (char *)Module; *loop; loop++) { if ((*loop == '\n') && (ExpandNewLine)) tmptext += "\\par "; else tmptext += *loop; } */ tmptext = (const char *)Module; newtext = newtext + RTFVersePre + " " + tmptext + RTFVersePost; newtext = newtext + RTFTrailer; RTFStream->Clear(); RTFStream->WriteBuffer(newtext.c_str(), newtext.Length()); RTFStream->Position = 0; Lines->LoadFromStream(RTFStream); return 0; } /* void SWDispRTF::SetModule(SWText *imodule) { FModule = imodule; } SWText *SWDispRTF::GetModule() { return FModule; } */ int __fastcall SWDispRTF::getFontSize() { return fontSize; } void __fastcall SWDispRTF::setFontSize(int iFontSize) { fontSize = iFontSize; recalcHeaders(); } void SWDispRTF::recalcHeaders() { char buf[4096]; sprintf(buf, defRTFTrailer, 24 + FontSize); RTFTrailer = buf; sprintf(buf, defRTFChapterMarkPre, 30 + FontSize); RTFChapterMarkPre = buf; sprintf(buf, defRTFChapterMarkPost, 10 + FontSize); RTFChapterMarkPost = buf; sprintf(buf, defRTFVerseMarkPre, 20 + FontSize); RTFVerseMarkPre = buf; sprintf(buf, defRTFVersePre, 24 + FontSize); RTFVersePre = buf; fontSize = 0; // (+/-) } //--------------------------------------------------------------------------- namespace Swdisprtf { void __fastcall Register() { TComponentClass classes[1] = {__classid(SWDispRTF)}; RegisterComponents("SWORD", classes, 0); } } //---------------------------------------------------------------------------