aboutsummaryrefslogtreecommitdiffstats
path: root/apps/windoze/CBuilder5/BibleCS/editentryfrm.cpp
diff options
context:
space:
mode:
authordanglassey <danglassey>2002-08-14 09:57:17 +0000
committerdanglassey <danglassey>2002-08-14 09:57:17 +0000
commitdaa67ff1f728c07f2a116ee9a9f4505479ca6808 (patch)
treec224a537d30480002ae0560cc9104b543b4d1b5e /apps/windoze/CBuilder5/BibleCS/editentryfrm.cpp
parent6d6973e035aac5ec1676efccd5b8ada70c40b639 (diff)
downloadsword-sf-cvs-import-1.1.1.tar.gz
Initial import from crosswire CVS for syncingimport-1.1.1
Diffstat (limited to 'apps/windoze/CBuilder5/BibleCS/editentryfrm.cpp')
-rw-r--r--apps/windoze/CBuilder5/BibleCS/editentryfrm.cpp352
1 files changed, 352 insertions, 0 deletions
diff --git a/apps/windoze/CBuilder5/BibleCS/editentryfrm.cpp b/apps/windoze/CBuilder5/BibleCS/editentryfrm.cpp
new file mode 100644
index 0000000..01935e0
--- /dev/null
+++ b/apps/windoze/CBuilder5/BibleCS/editentryfrm.cpp
@@ -0,0 +1,352 @@
+#include <vcl.h>
+#pragma hdrstop
+#include <windows.hpp>
+#include <stdlib.h>
+#include <stdio.h>
+#include "editentryfrm.h"
+#include <swdisprtf.h>
+#include "rxricheditx.h"
+
+const float RulerAdj = 4.0/3.0;
+const int GutterWid = 6;
+//----------------------------------------------------------------------------
+#pragma resource "*.dfm"
+TEditEntryForm *EditEntryForm;
+//----------------------------------------------------------------------------
+__fastcall TEditEntryForm::TEditEntryForm(TComponent *Owner) : TForm(Owner) {
+ ResultBuf = 0;
+ RichEdit1 = new TRxRichEditX(this);
+
+ RichEdit1->Parent = pnlRichEdit;
+ RichEdit1->Align = alClient;
+ RichEdit1->ScrollBars = ssVertical;
+}
+
+
+__fastcall TEditEntryForm::~TEditEntryForm() {
+ if (ResultBuf)
+ delete [] ResultBuf;
+}
+
+
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::SelectionChange(TObject */*Sender*/) {
+ char sizebuf[6];
+
+ try {
+ FUpdating = True;
+ FirstInd->Left = int(RichEdit1->Paragraph->FirstIndent*RulerAdj)-
+ 4+GutterWid;
+ LeftInd->Left = int((RichEdit1->Paragraph->LeftIndent+
+ RichEdit1->Paragraph->FirstIndent)*RulerAdj)-
+ 4+GutterWid;
+ RightInd->Left = Ruler->ClientWidth-6-int(
+ (RichEdit1->Paragraph->RightIndent+GutterWid)*RulerAdj);
+
+ BoldButton->Down = RichEdit1->SelAttributes->Style.Contains(fsBold);
+ ItalicButton->Down = RichEdit1->SelAttributes->Style.Contains(fsItalic);
+ UnderlineButton->Down = RichEdit1->SelAttributes->Style.Contains(fsUnderline);
+
+ BulletsButton->Down = bool(RichEdit1->Paragraph->Numbering);
+
+ FontSize->Text = itoa(RichEdit1->SelAttributes->Size, sizebuf, 10);
+
+ switch((int)RichEdit1->Paragraph->Alignment)
+ { case 0: LeftAlign->Down = True; break;
+ case 1: RightAlign->Down = True; break;
+ case 2: CenterAlign->Down = True; break;
+ }
+ }
+ catch (...) {
+ FUpdating = False;
+ }
+ FUpdating = False;
+}
+
+
+//----------------------------------------------------------------------------
+TRxTextAttributes *__fastcall TEditEntryForm::CurrText(void)
+{
+ return RichEdit1->SelAttributes;
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::CheckFileSave(void)
+{
+ if ( RichEdit1->Modified ) {
+ switch(MessageBox(Handle, "Save Changes?","Modify Comment",MB_YESNOCANCEL | MB_ICONQUESTION)) {
+ case ID_YES : ExtractRTF(); break;
+ case ID_CANCEL : Abort(); break;
+ default:
+ if (ResultBuf)
+ delete [] ResultBuf;
+ ResultBuf = 0;
+ break;
+ };
+ }
+}
+
+
+void __fastcall TEditEntryForm::SetupRuler(void)
+{ int iCtr = 1;
+ char sTmp[201];
+ while (iCtr < 200) {
+ sTmp[iCtr] = 9;
+ iCtr++;
+ sTmp[iCtr] = '|';
+ iCtr++;
+ }
+ Ruler->Caption = (AnsiString)sTmp;
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::SetEditRect(void)
+{ TRect Rct = Rect(GutterWid, 0, RichEdit1->ClientWidth-GutterWid,
+ ClientHeight);
+ SendMessage(RichEdit1->Handle, EM_SETRECT, 0, long(&Rct));
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::FormCreate(TObject* /*Sender*/)
+{ Application->OnHint = &ShowHint;
+ SetupRuler();
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::ShowHint(TObject* /*Sender*/)
+{ StatusBar->SimpleText = Application->Hint;
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::EditUndoClick(TObject* /*Sender*/)
+{ if ( RichEdit1->HandleAllocated() )
+ SendMessage(RichEdit1->Handle, EM_UNDO, 0, 0);
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::EditCutClick(TObject* /*Sender*/)
+{ RichEdit1->CutToClipboard();
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::EditCopyClick(TObject* /*Sender*/)
+{ RichEdit1->CopyToClipboard();
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::EditPasteClick(TObject* /*Sender*/)
+{ RichEdit1->PasteFromClipboard();
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::RulerResize(TObject* /*Sender*/)
+{ RulerLine->Width = (int)Ruler->ClientWidth - (RulerLine->Left*2);
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::FormResize(TObject* Sender)
+{ SetEditRect();
+ SelectionChange(Sender);
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::FormPaint(TObject* /*Sender*/)
+{ SetEditRect();
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::BoldButtonClick(TObject* /*Sender*/)
+{ if ( !FUpdating )
+ { if ( BoldButton->Down )
+ CurrText()->Style = CurrText()->Style << fsBold;
+ else
+ CurrText()->Style = CurrText()->Style >> fsBold;
+ }
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::ItalicButtonClick(TObject* /*Sender*/)
+{ if ( !FUpdating )
+ {
+ if ( ItalicButton->Down )
+ CurrText()->Style = CurrText()->Style << fsItalic;
+ else
+ CurrText()->Style = CurrText()->Style >> fsItalic;
+ }
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::UnderlineButtonClick(TObject* /*Sender*/)
+{
+ if ( !FUpdating ) {
+ if ( UnderlineButton->Down )
+ CurrText()->Style = CurrText()->Style << fsUnderline;
+ else CurrText()->Style = CurrText()->Style >> fsUnderline;
+ }
+}
+
+
+void __fastcall TEditEntryForm::FontSizeChange(TObject* /*Sender*/)
+{
+ int fontsize = atoi(FontSize->Text.c_str());
+
+ if ((!FUpdating) && (fontsize)) {
+ if (fontsize < 1) {
+ ShowMessage("Please Enter a Number betweek 1 and 1638");
+ FontSize->Text = 1;
+ }
+ else if (fontsize > 1638) {
+ ShowMessage("Please Enter a Number betweek 1 and 1638");
+ FontSize->Text = 1638;
+ }
+ CurrText()->Size = atoi(FontSize->Text.c_str());
+ }
+}
+
+
+void __fastcall TEditEntryForm::AlignClick(TObject* Sender)
+{
+ if ( !FUpdating ) {
+ TControl *oAliBtn = (TControl*)(Sender);
+ RichEdit1->Paragraph->Alignment = (TAlignment)oAliBtn->Tag;
+ }
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::BulletsButtonClick(TObject* /*Sender*/)
+{ if ( !FUpdating )
+ RichEdit1->Paragraph->Numbering = (TNumberingStyle)BulletsButton->Down;
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::FormCloseQuery(TObject* /*Sender*/,
+ bool & CanClose)
+{ try {
+ CheckFileSave();
+ }
+ catch (...) {
+ CanClose = False;
+ }
+}
+//----------------------------------------------------------------------------
+
+//***************************
+//***Ruler Indent Dragging***
+//***************************
+
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::RulerItemMouseDown(TObject * Sender,
+ TMouseButton Button, TShiftState Shift, int X, int Y)
+{ TLabel * oTmpLabel = (TLabel *)Sender;
+ FDragOfs = oTmpLabel->Width / 2;
+ oTmpLabel->Left = oTmpLabel->Left+X-FDragOfs;
+ FDragging = True;
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::RulerItemMouseMove(TObject *Sender, TShiftState Shift, int X, int /*Y*/) {
+ if (FDragging) {
+ TLabel *oTmpLabel = (TLabel *)Sender;
+ oTmpLabel->Left = oTmpLabel->Left+X-FDragOfs;
+ oTmpLabel->Left -= oTmpLabel->Left % 10;
+ }
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::FirstIndMouseUp(TObject *Sender, TMouseButton
+ Button, TShiftState Shift, int X, int Y)
+{ FDragging = False;
+ RichEdit1->Paragraph->FirstIndent = int((FirstInd->Left+FDragOfs-GutterWid) / RulerAdj);
+ LeftIndMouseUp(Sender, Button, Shift, X, Y);
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::LeftIndMouseUp(TObject *Sender, TMouseButton
+ /*Button*/, TShiftState /*Shift*/, int /*X*/, int /*Y*/)
+{ FDragging = False;
+ RichEdit1->Paragraph->LeftIndent = int((LeftInd->Left+FDragOfs-GutterWid)/
+ RulerAdj)-RichEdit1->Paragraph->FirstIndent;
+ SelectionChange(Sender);
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::RightIndMouseUp(TObject *Sender, TMouseButton
+ /*Button*/, TShiftState /*Shift*/, int /*X*/, int /*Y*/)
+{ FDragging = False;
+ RichEdit1->Paragraph->RightIndent =
+ int((Ruler->ClientWidth-RightInd->Left+FDragOfs-2) /
+ RulerAdj)-2*GutterWid;
+ SelectionChange(Sender);
+}
+//----------------------------------------------------------------------------
+void __fastcall TEditEntryForm::FormActivate(TObject *Sender)
+{
+ System::AnsiString newtext, tmptext;
+
+ if (Module) {
+ TMemoryStream *RTFStream = new TMemoryStream();
+ newtext = RTFDisplay->RTFHeader;
+ Module->Error(); // clear error;
+ newtext = newtext + "\\pard \\nowidctlpar \\cf0 ";
+ (const char *)*Module; // force key to snap to entry before pulling out the text of the key
+ tmptext = Module->getRawEntry();
+
+ newtext = newtext + RTFDisplay->RTFVersePre + " " + tmptext + RTFDisplay->RTFVersePost;
+ newtext = newtext + RTFDisplay->RTFTrailer;
+ RTFStream->Clear();
+ RTFStream->WriteBuffer(newtext.c_str(), newtext.Length());
+ RTFStream->Position = 0;
+ RichEdit1->Lines->LoadFromStream(RTFStream);
+ delete RTFStream;
+ }
+ SelectionChange(this);
+ RichEdit1->SetFocus();
+ if (ResultBuf)
+ delete [] ResultBuf;
+ ResultBuf = 0;
+}
+//---------------------------------------------------------------------
+
+void TEditEntryForm::ExtractRTF()
+{
+ System::AnsiString newtext, tmptext;
+ TMemoryStream *RTFStream = new TMemoryStream();
+ char *tmpbuf, *datastart;
+
+ RTFStream->Clear();
+ RichEdit1->Lines->SaveToStream(RTFStream);
+ RTFStream->Position = 0;
+ if (ResultBuf)
+ delete [] ResultBuf;
+ tmpbuf = new char [ RTFStream->Size + 1];
+ RTFStream->ReadBuffer(tmpbuf, RTFStream->Size);
+ tmpbuf[RTFStream->Size] = 0;
+ char *tbl = strstr(tmpbuf, "colortbl");
+ if (!tbl)
+ tbl = strstr(tmpbuf, "fonttbl");
+ if (tbl) {
+ strtok(tbl, "}");
+// strtok(NULL, "}");
+ datastart = strtok(NULL, "");
+ ResultBuf = new char [ strlen(datastart) + 2 ];
+ ResultBuf[0] = '{';
+ strcpy(ResultBuf+1, datastart);
+ delete [] tmpbuf;
+ delete RTFStream;
+ //-------- Change all fonts to \f1
+ for (int i = 0; i < strlen(ResultBuf)-4; i++) {
+ if (ResultBuf[i] == '\\') {
+ if (ResultBuf[i+1] == '\\') { // skip a real '\' character
+ i += 1;
+ continue;
+ }
+ if (ResultBuf[i+1] == 'f') {
+ if (isdigit(ResultBuf[i+2])) {
+ ResultBuf[i+2] = '1';
+ if (isdigit(ResultBuf[i+3])) {
+ memmove(&ResultBuf[i+3], &ResultBuf[i+4], strlen(&ResultBuf[i+3]));
+ }
+ }
+ }
+ if (ResultBuf[i+1] == 'c') {
+ if (ResultBuf[i+2] == 'f') {
+ if (isdigit(ResultBuf[i+3])) {
+ ResultBuf[i+3] = '7';
+ if (isdigit(ResultBuf[i+4])) {
+ memmove(&ResultBuf[i+4], &ResultBuf[i+5], strlen(&ResultBuf[i+4]));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+
+__fastcall TCharsetObject::TCharsetObject(int FCharset)
+ : TObject()
+{
+ Charset = FCharset;
+}
+//---------------------------------------------------------------------------