diff options
Diffstat (limited to 'apps/windoze/CBuilder5/prototype/TextPanel.cpp')
-rw-r--r-- | apps/windoze/CBuilder5/prototype/TextPanel.cpp | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/apps/windoze/CBuilder5/prototype/TextPanel.cpp b/apps/windoze/CBuilder5/prototype/TextPanel.cpp new file mode 100644 index 0000000..a534e12 --- /dev/null +++ b/apps/windoze/CBuilder5/prototype/TextPanel.cpp @@ -0,0 +1,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(); +} |