📄 unit1.cpp
字号:
/*******************************************************}
{ }
{ RichViewActions }
{ Demo project. }
{ You can use it as a basis for your }
{ applications. }
{ }
{ Copyright (c) Sergey Tkachenko }
{ svt@trichview.com }
{ http://www.trichview.com }
{ }
{*******************************************************/
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "dmActions.hpp"
#include "RVALocRuler.hpp"
//---------------------------------------------------------------------------
/*
Uncomment the defines below to enable support for Gif and Png.
GifImage (by Anders Melander)
http://www.torry.net/vcl/graphics/gif/gifimage.exe (original)
http://www.trichview.com/resources/thirdparty/gifimage.zip (update)
PngObject (by Gustavo Huffenbacher Daud)
http://pngdelphi.sourceforge.net/
*/
//#define USE_GIFIMAGE
//#define USE_PNGOBJECT
#ifdef USE_GIFIMAGE
#include "GifImage.hpp"
#endif
#ifdef USE_PNGOBJECT
#include "PngImage.hpp"
#endif
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PtblRV"
#pragma link "RichView"
#pragma link "RichViewActions"
#pragma link "Ruler"
#pragma link "RVEdit"
#pragma link "RVFontCombos"
#pragma link "RVRuler"
#pragma link "RVScroll"
#pragma link "RVStyle"
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
#ifdef USE_GIFIMAGE
RegisterClass(__classid(TGIFImage));
// uncomment the line below if Gif does not appear in Insert | Image
//TPicture::RegisterFileFormat(__classid(TPicture), "gif", "Gif Image", __classid(TGIFImage));
RV_RegisterHTMLGraphicFormat(__classid(TGIFImage));
#endif
#ifdef USE_PNGOBJECT
RegisterClass(__classid(TPNGObject));
RV_RegisterHTMLGraphicFormat(__classid(TPNGObject));
RV_RegisterPngGraphic(__classid(TPNGObject));
#endif
}
//---------------------------------------------------------------------------
void __fastcall TForm3::FormCreate(TObject *Sender)
{
// Almost all these assignments could be done at design time in the Object Inspector
// But in this demo we do not want to modify rvActionsResource
// (and we recommend to use a copy of it in your applications)
rvActionsResource->rvActionSave1->OnDocumentFileChange = rvActionSave1DocumentFileChange;
// Code for making color-picking buttons stay pressed while a
// color-picker window is visible.
rvActionsResource->rvActionColor1->OnShowColorPicker = ColorPickerShow;
rvActionsResource->rvActionColor1->OnHideColorPicker = ColorPickerHide;
rvActionsResource->rvActionParaColor1->OnShowColorPicker = ColorPickerShow;
rvActionsResource->rvActionParaColor1->OnHideColorPicker = ColorPickerHide;
rvActionsResource->rvActionFontColor1->OnShowColorPicker = ColorPickerShow;
rvActionsResource->rvActionFontColor1->OnHideColorPicker = ColorPickerHide;
rvActionsResource->rvActionFontBackColor1->OnShowColorPicker = ColorPickerShow;
rvActionsResource->rvActionFontBackColor1->OnHideColorPicker = ColorPickerHide;
// C++Builder 4 and 5 do not have ActionComponent property for actions.
// Coloring actions have a substitution - CallerControl property
// It is ignored in C++Builder 6
rvActionsResource->rvActionParaColor1->CallerControl = ToolButton39;
rvActionsResource->rvActionFontBackColor1->CallerControl = ToolButton38;
rvActionsResource->rvActionFontColor1->CallerControl = ToolButton36;
#if __BORLANDC__>0x0550
// AutoComplete feature causes OnClick generation when editing combo-box's text.
// Since in OnClick we move input focus in RichViewEdit1, this effect is
// undesirable
cmbFont->AutoComplete = false;
cmbFontSize->AutoComplete = false;
#endif
Localize();
// Loading initial file via ActionOpen (allowing to update user interface)
rvActionsResource->rvActionOpen1->LoadFile(RichViewEdit1,
ExtractFilePath(Application->ExeName)+"readme.rvf", ffiRVF);
/*
// alternative way to start
rvActionsResource->rvActionNew1->ExecuteTarget(RichViewEdit1);
*/
}
//---------------------------------------------------------------------------
/* Working with document */
//---------------------------------------------------------------------------
// When document is created, saved, loaded...
void __fastcall TForm3::rvActionSave1DocumentFileChange(TObject* Sender,
TCustomRichViewEdit* Editor, const AnsiString FileName,
TrvFileSaveFilter FileFormat, bool IsNew)
{
AnsiString s = ExtractFileName(FileName);
rvActionsResource->rvActionPrint1->Title = s;
rvActionsResource->rvActionQuickPrint1->Title = s;
if (IsNew)
s += " (*)";
Caption = s + " - RichViewActionsTest";
}
//---------------------------------------------------------------------------
// Prompt for saving...
void __fastcall TForm3::FormCloseQuery(TObject *Sender, bool &CanClose)
{
CanClose = rvActionsResource->rvActionSave1->CanCloseDoc(RichViewEdit1);
}
//---------------------------------------------------------------------------
void __fastcall TForm3::mitExitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
/* Working with color-picking buttons */
//---------------------------------------------------------------------------
// Code for making color-picking buttons pressed while
// a color-picker window is visible.
void __fastcall TForm3::ColorPickerShow(TObject* Sender)
{
#if __BORLANDC__>0x0550
TComponent* ActionComponent = ((TAction*)Sender)->ActionComponent;
if (ActionComponent->InheritsFrom(__classid(TToolButton)))
((TToolButton*)ActionComponent)->Down = true;
#else
TControl* CallerControl = ((TrvActionCustomColor*)Sender)->CallerControl;
if (CallerControl)
((TToolButton*)CallerControl)->Down = true;
#endif
}
//---------------------------------------------------------------------------
void __fastcall TForm3::ColorPickerHide(TObject* Sender)
{
#if __BORLANDC__>0x0550
TComponent* ActionComponent = ((TAction*)Sender)->ActionComponent;
if (ActionComponent->InheritsFrom(__classid(TToolButton)))
((TToolButton*)ActionComponent)->Down = false;
#else
TControl* CallerControl = ((TrvActionCustomColor*)Sender)->CallerControl;
if (CallerControl)
((TToolButton*)CallerControl)->Down = false;
#endif
}
//---------------------------------------------------------------------------
/* Set of events for processing hypertext jumps */
//---------------------------------------------------------------------------
// Hyperlink click
void __fastcall TForm3::RichViewEdit1Jump(TObject *Sender, int id)
{
rvActionsResource->rvActionInsertHyperlink1->GoToLink(RichViewEdit1, id);
}
//---------------------------------------------------------------------------
// Inserting hyperlinks from files (RTF) and drag source
void __fastcall TForm3::RichViewEdit1ReadHyperlink(TCustomRichView *Sender,
const AnsiString Target, const AnsiString Extras,
TRVLoadFormat DocFormat, int &StyleNo, int &ItemTag,
AnsiString &ItemName)
{
if (DocFormat==rvlfURL)
StyleNo = rvActionsResource->rvActionInsertHyperlink1->GetHyperlinkStyleNo(RichViewEdit1);
AnsiString URL = rvActionsResource->rvActionInsertHyperlink1->EncodeTarget(Target);
ItemTag = (int)StrNew(URL.c_str());
}
//---------------------------------------------------------------------------
// Exporting hyperlink to RTF and HTML
void __fastcall TForm3::RichViewEdit1WriteHyperlink(
TCustomRichView *Sender, int id, TCustomRVData *RVData, int ItemNo,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -