aboutsummaryrefslogtreecommitdiffstats
path: root/apps/windoze/CBuilder5/BibleCS/vrslstfrm.cpp
blob: 02479361db13423225c050d80b6d364c0cffe1e0 (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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "vrslstfrm.h"
#include "rtfhintfrm.h"
#include "PrintFrm.h"
#include <io.h>
#include <localemgr.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TVerseListForm *VerseListForm;
//---------------------------------------------------------------------------

//TODO:  add toolbar
//TODO:  add print to toolbar that will call up print form and populate print range
//TODO:  add const char *ListKey::rangeToString() to ListKey to allow easy implementation of above
//TODO:  add const char *VerseKey::rangeToString() to VerseKey to allow easy implementation of above
//TODO:  add save to toolbar
//TODO:  add add current verse to toolbar
//TODO:  add edit entry to toolbar
//TODO:  add new verse list to mainfrm
//TODO:  add open verse list to mainfrm

__fastcall TVerseListForm::TVerseListForm(TComponent* Owner, ListKey &iVerseList)
	: TForm(Owner), verseList(iVerseList) {
	pvrtf = new TRxRichEditX(this);

	pvrtf->Parent = plPreview;
	pvrtf->Align = alClient;
	pvrtf->ScrollBars = ssVertical;
	pvrtf->ReadOnly = true;
}
//---------------------------------------------------------------------------

void __fastcall TVerseListForm::ListBox1Click(TObject *Sender) {
	ModMap::iterator target;
	target = Form1->mainmgr->Modules.find(Form1->TextPageControl->ActivePage->Caption.c_str());
	if (target != Form1->mainmgr->Modules.end()) {
		ListKey key;
		SWKey *tkey = target->second->CreateKey();
		*tkey = ListBox1->Items->Strings[ListBox1->ItemIndex].c_str();
		key << *tkey;
		delete tkey;
		pvrtf->fillWithVerses(target->second, &key, true, false);
	}
}
//---------------------------------------------------------------------------

void __fastcall TVerseListForm::ListBox1DblClick(TObject *Sender)
{
	*(Form1->DefaultVSKey) = ListBox1->Items->Strings[ListBox1->ItemIndex].c_str();
	Form1->TextKeyChanged();
}
//---------------------------------------------------------------------------
void __fastcall TVerseListForm::FormShow(TObject *Sender)
{
	Caption = _tr("Verse List");
	SpeedButton1->Hint = _tr("Add Current Verse To List");
	SpeedButton2->Hint = _tr("Remove Highlighted Entry From List");
	SpeedButton3->Hint = _tr("Copy All Entries To Clipboard");
	SpeedButton4->Hint = _tr("Print All Entries");
	SpeedButton5->Hint = _tr("Save Verse List To File");
	SpeedButton6->Hint = _tr("Load Verse List From File");
	fillWithVerseList(verseList);
}
//---------------------------------------------------------------------------


void TVerseListForm::fillWithVerseList(ListKey &verseList) {



	ListBox1->Items->Clear();
	for (verseList = TOP; (!verseList.Error()); verseList++)
		ListBox1->Items->Add((const char *)verseList);
}


void __fastcall TVerseListForm::SpeedButton1Click(TObject *Sender)
{
	ListBox1->Items->Add((const char *)*(Form1->DefaultVSKey));
}
//---------------------------------------------------------------------------

void __fastcall TVerseListForm::SpeedButton2Click(TObject *Sender)
{
	int item = ListBox1->ItemIndex;
	if (item >=0) {
		ListBox1->Items->Delete(item);
	}	
}
//---------------------------------------------------------------------------

void __fastcall TVerseListForm::SpeedButton3Click(TObject *Sender)
{
	ListKey verses;
	for (int i = 0; i < ListBox1->Items->Count; i++) {
		verses << ListBox1->Items->Strings[i].c_str();
	}

	TPageControl *targetpc = Form1->TextPageControl;
	
	if ((Form1->ActiveControl == Form1->CommentaryPageControl) || (IsChild(Form1->CommentaryPageControl->Handle, Form1->ActiveControl->Handle)))
		targetpc = Form1->CommentaryPageControl;
	if ((Form1->ActiveControl == Form1->LexDictPageControl) || (IsChild(Form1->LexDictPageControl->Handle, Form1->ActiveControl->Handle)))
		targetpc = Form1->LexDictPageControl;

	ModMap::iterator it = Form1->mainmgr->Modules.find(targetpc->ActivePage->Caption.c_str());
	if (it != Form1->mainmgr->Modules.end()) {
		RTFHintForm->rtfDrawer->fillWithVerses(it->second, &verses, true, true);
		RTFHintForm->rtfDrawer->SelectAll();
		RTFHintForm->rtfDrawer->CopyToClipboard();
	}
}
//---------------------------------------------------------------------------

void __fastcall TVerseListForm::SpeedButton4Click(TObject *Sender)
{
	ListKey verses;
	for (int i = 0; i < ListBox1->Items->Count; i++) {
		verses << ListBox1->Items->Strings[i].c_str();
	}
	PrintForm->print(&verses);	
}
//---------------------------------------------------------------------------

void __fastcall TVerseListForm::SpeedButton5Click(TObject *Sender)
{
	int result = VLSaveDialog->Execute();
	SetCurrentDir(ExtractFilePath(Application->ExeName));
	if (result) {
		if (FileMgr::existsFile(VLSaveDialog->FileName.c_str())) {
			string message = _tr("File exists.  Overwrite?");
			string header = _tr("Overwrite File");
			if (MessageBox(Handle, message.c_str(), header.c_str(), MB_YESNO) != IDYES) {
				return;
			}
		}
		FileDesc *fd;
		unlink(VLSaveDialog->FileName.c_str());
		fd = FileMgr::systemFileMgr.open(VLSaveDialog->FileName.c_str(), O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
		ListKey verses;
		for (int i = 0; i < ListBox1->Items->Count; i++) {
			VerseKey toEn;
			toEn = ListBox1->Items->Strings[i].c_str();
			toEn.getText();
			toEn.setLocale("en_us");
			verses << toEn.getText();
		}
		const char *rangeText = verses.getRangeText();
		write(fd->getFd(), rangeText, strlen(rangeText));
		FileMgr::systemFileMgr.close(fd);
	}
}
//---------------------------------------------------------------------------

void __fastcall TVerseListForm::SpeedButton6Click(TObject *Sender)
{
	int result = VLOpenDialog->Execute();
	SetCurrentDir(ExtractFilePath(Application->ExeName));
	if (result) {
		if (!FileMgr::existsFile(VLOpenDialog->FileName.c_str())) {
			return;
		}
		FileDesc *fd;
		fd = FileMgr::systemFileMgr.open(VLOpenDialog->FileName.c_str(), O_RDONLY|O_BINARY);
		ListKey verses;
		VerseKey parser;
		long size = lseek(fd->getFd(), 0, SEEK_END);
		lseek(fd->getFd(), 0, SEEK_SET);
		char *buf = new char[size+5];
		memset(buf, 0, size+5);
		read(fd->getFd(), buf, size);
		FileMgr::systemFileMgr.close(fd);
		verses = parser.ParseVerseList(buf, parser, false);
		fillWithVerseList(verses);
		delete [] buf;
	}
}
//---------------------------------------------------------------------------