aboutsummaryrefslogtreecommitdiffstats
path: root/apps/windoze/swdisprtfchap.cpp
blob: 9c7cb722bd07b00c942269389add8729049be5c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "biblecsmgr.h"
#include "swdisprtfchap.h"
#include <winbase.h>


//---------------------------------------------------------------------------
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;
	System::AnsiString newtext, tmptext, tmptext2;
	VerseKey *key = (VerseKey *)(SWKey *)Module;
	testmt = key->Testament();
	chap   = key->Chapter();
	book   = key->Book();
	verse  = key->Verse();
	key->Verse(1);

	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(), "ar", 2)))) {
	   newtext = newtext + "\\rtlpar ";
	}

	Module.Error(); // clear error;
	string lastEntry = "something the first entry will never be";
	while ((key->Book() == book) && (key->Chapter() == chap) && (Module.Error() == 0)) {
		if (lastEntry == (string)Module.getRawEntry()) {
			Module++;
			continue;
		}
		newtext = newtext + "{";

		tmptext = "";
		lastEntry = Module.getRawEntry();
		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
			if (Module.Direction() == DIRECTION_RTL && (platformID == VER_PLATFORM_WIN32_WINDOWS	 || (Module.Lang() && strnicmp(Module.Lang(), "he", 2) && strnicmp(Module.Lang(), "ar", 2)))) {
				newtext = newtext + RTFVersePre;
				if ((key->Verse() == verse) && (dispAttribs.markCurrentVerse)) {
					newtext = newtext + "\\cf2 "; // \cf2 = second color in color table
				}
				newtext += tmptext + RTFVersePost;
				newtext = newtext + RTFVerseMarkPre + IntToStr(key->Verse()) + RTFVerseMarkPost;
				newtext = newtext + "\\par ";
			}
			else {
				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;
			}
		}
		if (key->Verse() == verse) {
			tmptext = newtext + RTFTrailer + "}";
			RTFStream->Clear();
			RTFStream->WriteBuffer(tmptext.c_str(), tmptext.Length());
			RTFStream->Position = 0;
			Lines->LoadFromStream(RTFStream);
			versepos =  GetTextLen() - 3;
		}
		newtext = newtext + "}";
		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->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());
	RTFStream->Position = 0;
	Lines->LoadFromStream(RTFStream);

	//{ Position control text at current verse }
	this->SetFocus();
	SelStart = versepos;
	SendMessage(Handle, EM_SCROLLCARET, 0, 0);
	return 0;
}


//---------------------------------------------------------------------------
namespace Swdisprtfchap
{
	void __fastcall Register()
	{
		TComponentClass classes[1] = {__classid(SWDispRTFChap)};
		RegisterComponents("SWORD", classes, 0);
	}
}
//---------------------------------------------------------------------------