aboutsummaryrefslogtreecommitdiffstats
path: root/apps/windoze/CBuilder5/prototype/CommentPanel.cpp
blob: a7214ea8a1c882718a59e9c7b2f6012334734fe9 (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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//---------------------------------------------------------------------------
#include <vcl.h>
#include <vcl/clipbrd.hpp>
#pragma hdrstop

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

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

class DispExternal : public SWDisplay {
public:
	DispExternal() {}
	char Display(SWModule &imodule) {
		SHELLEXECUTEINFO info;
		info.cbSize = sizeof(SHELLEXECUTEINFO);
		info.fMask = SEE_MASK_NOCLOSEPROCESS; //SEE_MASK_CLASSNAME;
		info.hwnd = GetFocus();
		info.lpVerb = "open";
		info.lpFile = (const char *)imodule;
		info.lpParameters = NULL;
		info.lpDirectory = NULL;
		info.nShow = 0;
//		info.lpClass = ".html";
		ShellExecuteEx(&info);
//		ShellExecute(edit->Handle, "open", (char *)imodule, NULL, NULL, SW_SHOWNORMAL);
	}
};

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

static inline void ValidCtrCheck(TCommentPanel *)
{
	new TCommentPanel(NULL);
}
//---------------------------------------------------------------------------
__fastcall TCommentPanel::TCommentPanel(TComponent* Owner, SWModule *mod, SWMgr *imgr)
	: TPanel(Owner)
{
	module = mod;
	mgr = imgr;
	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 TCommentPanel::CreateWnd() {
	TPanel::CreateWnd();

	TWinControl *newrtf;

	if (mgr->config->Sections[module->Name()]["ModDrv"] == "HREFCom") {
//		if (mainmgr->config->Sections[mod->Name()]["External"] == "1") {
			newrtf = new TPanel(this);
			((TPanel *)newrtf)->Caption = "Syncronizing to External Viewer";
			display = new DispExternal();
			module->Disp(display);
/*
		}
		else {
	//		newrtf = new THTML(this->Handle);
	//		newrtf = new SWDispRTF(this);
			newrtf = HTML1;
			newrtf->Visible = true;
			mod->Disp(*displays.insert(displays.begin(), new HREFDisp((THTML *)newrtf)));
	//		mod->Disp(*displays.insert(displays.begin(), new RTFDisp((SWDispRTF *)newrtf)));
		}
*/
	}
	else {
		newrtf = new SWDispRTF(this);
		display = new RTFDisp((SWDispRTF *)newrtf);
		module->Disp(display);
		((SWDispRTF *)newrtf)->ScrollBars = ssVertical;
		((SWDispRTF *)newrtf)->ReadOnly = true;
		if (mgr->config->Sections[module->Name()]["ModDrv"] == "RawFiles") {
//			((SWDispRTF *)newrtf)->PopupMenu = PopupMenu3;
			((SWDispRTF *)newrtf)->ExpandNewLine = false;
		}
//		else	((SWDispRTF *)newrtf)->PopupMenu = PopupMenu2;
		((SWDispRTF *)newrtf)->OnMouseDown = RTFMouseDown;
	}

	newrtf->Parent = this;
	newrtf->Align = alClient;

//	mod->SetKey(DefaultVSKey);
//	return 0;


}
__fastcall TCommentPanel::~TCommentPanel() {
	delete display;
	if (font)
		delete font;
}
//---------------------------------------------------------------------------
namespace Commentpanel
{
	void __fastcall PACKAGE Register()
	{
		TComponentClass classes[1] = {__classid(TCommentPanel)};
		RegisterComponents("Samples", classes, 0);
	}
}
//---------------------------------------------------------------------------
void __fastcall TCommentPanel::PopupMenuPopup(TObject *Sender)
{
}
void TCommentPanel::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 TCommentPanel::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 TCommentPanel::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 TCommentPanel::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 TCommentPanel::RTFMouseDown(TObject *Sender, TMouseButton Button,
	 TShiftState Shift, int X, int Y)
{
	((TWinControl *)Sender)->SetFocus();
}