summaryrefslogtreecommitdiff
path: root/apps/windoze/CBuilder5/prototype/TextPanel.cpp
blob: a534e125c237fed28a18856f0f46b1fcf03de528 (plain)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//---------------------------------------------------------------------------
#include <vcl.h>
#include <vcl/clipbrd.hpp>
#pragma hdrstop

#include "TextPanel.h"
#pragma package(smart_init)
#include "swdisprtfchap.h"
#include <swconfig.h>
#include <swmodule.h>
#include "Greek2Greek.h"
#include <utilfuns.h>

class RTFDisp : public SWDisplay {
	SWDispRTF *edit;
public:
	RTFDisp(SWDispRTF *iedit) { edit = iedit; }
	RTFDisp() {}
	char Display(SWModule &imodule) {
		edit->Display(imodule);
	}
};


//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(TTextPanel *)
{
	new TTextPanel(NULL);
}
//---------------------------------------------------------------------------
__fastcall TTextPanel::TTextPanel(TComponent* Owner, SWModule *mod, char *font)
	: TPanel(Owner)
{
	module = mod;
	this->font = 0;
	stdstr(&(this->font), font);
	menu = new TPopupMenu(this);
	menu->OnPopup = PopupMenuPopup;
	
	TMenuItem * newitem;
	newitem = new TMenuItem(menu);
	newitem->Caption = "&Copy";
	newitem->Hint = "Copy text to clipboard";
	newitem->Default = false;
	newitem->OnClick = Copy1Click;
	menu->Items->Add(newitem);
	if (!strcmp(mod->Name(), "N27U4")) {
		newitem = new TMenuItem(menu);
		newitem->Caption = "Copy as &B-Greek Transliteration";
		newitem->Hint = "Copy text to clipboard as B-Greek Transliteration";
		newitem->Default = false;
		newitem->OnClick = CopyasBGreekTransliteration1Click;
		menu->Items->Add(newitem);
	}
	newitem = new TMenuItem(menu);
	newitem->Caption = "Dictionary Lookup";
	newitem->Hint = "Send text to dictionary key for lookup";
	newitem->Default = false;
	newitem->OnClick = DictionaryLookup1Click;
	menu->Items->Add(newitem);
}


void __fastcall TTextPanel::CreateWnd() {
	TPanel::CreateWnd();
	SWDispRTFChap *newrtf = new SWDispRTFChap(this);
	char buf[512];
	SectionMap::iterator sit;
	
//	newtab->Caption = mod->Name();
//	newtab->Hint = mod->Description();
//	newtab->PageControl = PageControl1;
	newrtf->Parent = this;
	newrtf->Align = alClient;
	newrtf->ScrollBars = ssVertical;
	newrtf->ReadOnly = true;
	newrtf->PopupMenu = menu;
	newrtf->OnMouseDown = RTFMouseDown;

	BuildRTFHeader(buf, font, 512);
	newrtf->RTFHeader = buf;

//	if ((sit = optionsconf->Sections.find("Appearance")) != optionsconf->Sections.end()) {
//		newrtf->MarkCurrentVerse = (atoi((*sit).second["AutoVSColor"].c_str())) ? true:false;
//	}
	display = new RTFDisp(newrtf);
	module->Disp(display);
//	mod->SetKey(DefaultVSKey);

}
__fastcall TTextPanel::~TTextPanel() {
	delete display;
	if (font)
		delete font;
}
//---------------------------------------------------------------------------
namespace Textpanel
{
	void __fastcall PACKAGE Register()
	{
		TComponentClass classes[1] = {__classid(TTextPanel)};
		RegisterComponents("Samples", classes, 0);
	}
}
//---------------------------------------------------------------------------
void __fastcall TTextPanel::PopupMenuPopup(TObject *Sender)
{
}
void TTextPanel::BuildRTFHeader(char *buf, char *font, int max)
{
	char buf1[1024], buf2[1024];
	SectionMap::iterator sit;
	
	sprintf(buf1, "{\\rtf1\\ansi");
	if (font)
		sprintf(buf2, "{\\fonttbl{\\f0\\fdecor\\fprq2 %s;}{\\f1\\froman\\fcharset0\\fprq2 Times New Roman;}{\\f2\\froman\\fcharset0\\fprq2 Times New Roman;}{\\f3\\froman\\fcharset0\\fprq2 Times New Roman;}{\\f4\\froman\\fcharset0\\fprq2 Times New Roman;}{\\f7\\froman\\fcharset2\\fprq2 Symbol;}{\\f8\\froman\\fcharset2\\fprq2 Symbol;}}", font);
	else sprintf(buf2, "{\\fonttbl{\\f0\\fdecor\\fprq2 Times New Roman;}{\\f1\\froman\\fcharset0\\fprq2 Times New Roman;}{\\f7\\froman\\fcharset2\\fprq2 Symbol;}{\\f8\\froman\\fcharset2\\fprq2 Symbol;}}");
	strcat(buf1, buf2);

//	if ((sit = optionsconf->Sections.find("Appearance")) != optionsconf->Sections.end()) {
//		sprintf(buf2, "{\\colortbl;\\red0\\green0\\blue255;\\red%d\\green%d\\blue%d;\\red0\\green0\\blue255;\\red0\\green200\\blue50;\\red0\\green0\\blue255;\\red255\\green0\\blue0;}",
//			atoi((*sit).second["CurrentVSColorRed"].c_str()),
//			atoi((*sit).second["CurrentVSColorGreen"].c_str()),
//			atoi((*sit).second["CurrentVSColorBlue"].c_str()));
//	}
//	else	
	sprintf(buf2, "{\\colortbl;\\red0\\green0\\blue255;\\red0\\green200\\blue50;\\red0\\green0\\blue255;\\red0\\green200\\blue50;\\red0\\green0\\blue255;\\red255\\green0\\blue0;}");
	strcat(buf1, buf2);
	memset(buf, 0, max);
	strncpy(buf, buf1, max);
}


void __fastcall TTextPanel::CopyasBGreekTransliteration1Click(TObject *Sender)
{
	char *retbuf;
	int len;
	TClipboard *clip = new TClipboard();
	
	SWDispRTF *rtf = (SWDispRTF *)Screen->ActiveControl;
	len = rtf->SelText.Length() * 2;
	retbuf = new char [ len ];
	if (!Greek2bGreek(retbuf, rtf->SelText.c_str(), len)) {
		clip->SetTextBuf(retbuf);
	}
	delete clip;
}

void __fastcall TTextPanel::Copy1Click(TObject *Sender)
{
	int wordstart;
	
	SWDispRTF *rtf = (SWDispRTF *)Screen->ActiveControl;
	if (!rtf->SelLength) {
		for (wordstart = rtf->SelStart; (wordstart > -1)&&(isdigit(rtf->Text[wordstart])||isalpha(rtf->Text[wordstart])); wordstart--);
		rtf->SelStart = (wordstart > -1) ? wordstart: 0;
		for (wordstart = rtf->SelStart + 1; (wordstart < rtf->Text.Length())&&(isdigit(rtf->Text[wordstart])||isalpha(rtf->Text[wordstart])); wordstart++);
		rtf->SelLength = ((wordstart < rtf->Text.Length()) ? wordstart : rtf->Text.Length() - 1) - rtf->SelStart - 1;
	}
	rtf->CopyToClipboard();
}
void __fastcall TTextPanel::DictionaryLookup1Click(TObject *Sender)
{
	int wordstart;
	
	SWDispRTF *rtf = (SWDispRTF *)Screen->ActiveControl;
	if (!rtf->SelLength) {
		for (wordstart = rtf->SelStart; (wordstart > -1)&&(isdigit(rtf->Text[wordstart])||isalpha(rtf->Text[wordstart])); wordstart--);
		rtf->SelStart = (wordstart > -1) ? wordstart: 0;
		for (wordstart = rtf->SelStart + 1; (wordstart < rtf->Text.Length())&&(isdigit(rtf->Text[wordstart])||isalpha(rtf->Text[wordstart])); wordstart++);
		rtf->SelLength = ((wordstart < rtf->Text.Length()) ? wordstart : rtf->Text.Length() - 1) - rtf->SelStart - 1;
	}
//	DictKeyEdit->Text = Trim(rtf->SelText);
}
void __fastcall TTextPanel::RTFMouseDown(TObject *Sender, TMouseButton Button,
	 TShiftState Shift, int X, int Y)
{
	((TWinControl *)Sender)->SetFocus();
}