📄 ribbonnotepaddemomain.cpp
字号:
TRibbonDemoMainForm *RibbonDemoMainForm;
char
*sRichEditFoundResultCaption = "Information",
*sRichEditTextNotFound = "The search text is not found.",
*sRichEditReplaceAllResult = "Replaced %d occurances.",
*sDefaultDocName = "Document1.rtf";
char
*RTFFilter = "Rich Text Files (*.RTF)|*.RTF",
*TXTFilter = "Plain text (*.TXT)|*.TXT";
//---------------------------------------------------------------------------
__fastcall TRibbonDemoMainForm::TRibbonDemoMainForm(TComponent* Owner)
: TdxCustomRibbonForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::ApplicationMenuRecentDocumentsClick(TObject *Sender, int AIndex)
{
OpenFile(ApplicationMenu->ExtraPaneItems->Items[AIndex]->Text);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonNewClick(TObject *Sender)
{
if (Editor->Modified)
switch (QuerySaveFile()) {
case ID_YES: {
if (SaveFile(false)) {
MakeNewDocument();
}
break;
}
case ID_NO: {
MakeNewDocument();
}
}
else {
MakeNewDocument();
}
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonOpenClick(TObject *Sender)
{
OpenFile("");
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonCloseClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonSaveClick(TObject *Sender)
{
SaveFile(false);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonSaveAsRTFClick(TObject *Sender)
{
SaveFile(true);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonSaveAsTextClick(TObject *Sender)
{
SaveFile(true, true);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonPrintClick(TObject *Sender)
{
if (PrintDialog->Execute()) Editor->Print(FileName);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonExitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonUndoClick(TObject *Sender)
{
Undo(1);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonCutClick(TObject *Sender)
{
Editor->CutToClipboard();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonCopyClick(TObject *Sender)
{
Editor->CopyToClipboard();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonPasteClick(TObject *Sender)
{
Editor->PasteFromClipboard();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonClearClick(TObject *Sender)
{
Editor->ClearSelection();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonSelectAllClick(TObject *Sender)
{
Editor->SelectAll();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonFindClick(TObject *Sender)
{
Editor->SelLength = 0;
FindDialog->Execute();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonReplaceClick(TObject *Sender)
{
Editor->SelLength = 0;
ReplaceDialog->Execute();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarComboFontNameChange(TObject *Sender)
{
if (!FUpdating)
Editor->SelAttributes->Name = dxBarComboFontName->Text;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarComboFontSizeChange(TObject *Sender)
{
if (!FUpdating)
Editor->SelAttributes->Size = StrToInt(dxBarComboFontSize->Text);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonBoldClick(TObject *Sender)
{
if (dxBarButtonBold->Down)
Editor->SelAttributes->Style = Editor->SelAttributes->Style << fsBold;
else
Editor->SelAttributes->Style = Editor->SelAttributes->Style >> fsBold;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonItalicClick(TObject *Sender)
{
if (dxBarButtonItalic->Down)
Editor->SelAttributes->Style = Editor->SelAttributes->Style << fsItalic;
else
Editor->SelAttributes->Style = Editor->SelAttributes->Style >> fsItalic;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonUnderlineClick(TObject *Sender)
{
if (dxBarButtonUnderline->Down)
Editor->SelAttributes->Style = Editor->SelAttributes->Style << fsUnderline;
else
Editor->SelAttributes->Style = Editor->SelAttributes->Style >> fsUnderline;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonBulletsClick(TObject *Sender)
{
Editor->Paragraph->Numbering = TNumberingStyle(dxBarButtonBullets->Down);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::btnLockedClick(TObject *Sender)
{
AnsiString AHint;
Editor->ReadOnly = ((TdxBarButton*)Sender)->Down;
if (Editor->ReadOnly) {
AHint = "Editing protection: Read only. Click for editing.";
cxStyle1->TextColor = clMaroon;
}
else
{
AHint = "Editing protection: Writable. Click for read-only mode.";
cxStyle1->TextColor = clGray;
}
((TdxBarButton*)Sender)->Hint = AHint;
EditorSelectionChange(0);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonAlignClick(TObject *Sender)
{
if (((TdxBarLargeButton*)Sender)->Down)
Editor->Paragraph->Alignment = ((TAlignment)((TdxBarLargeButton*)Sender)->Tag);
else
Editor->Paragraph->Alignment = taLeftJustify;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonProtectedClick(TObject *Sender)
{
Editor->SelAttributes->Protected = !Editor->SelAttributes->Protected;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarLargeButtonBlueSchemeClick(TObject *Sender)
{
SetColorScheme("Blue");
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarLargeButtonBlackSchemeClick(TObject *Sender)
{
SetColorScheme("Black");
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarLargeButtonSilverSchemeClick(TObject *Sender)
{
SetColorScheme("Silver");
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarLargeButton6Click(TObject *Sender)
{
Ribbon->SupportNonClientDrawing = !Ribbon->SupportNonClientDrawing;
dxBarLargeButton7->Enabled = Ribbon->SupportNonClientDrawing;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarLargeButton7Click(TObject *Sender)
{
Ribbon->ApplicationButton->Visible = !Ribbon->ApplicationButton->Visible;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarLargeButton8Click(TObject *Sender)
{
Ribbon->QuickAccessToolbar->Position = qtpAboveRibbon;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarLargeButton9Click(TObject *Sender)
{
Ribbon->QuickAccessToolbar->Position = qtpBelowRibbon;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarLargeButton10Click(TObject *Sender)
{
Ribbon->QuickAccessToolbar->Visible = !Ribbon->QuickAccessToolbar->Visible;
dxBarLargeButton8->Enabled = Ribbon->QuickAccessToolbar->Visible;
dxBarLargeButton9->Enabled = Ribbon->QuickAccessToolbar->Visible;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::EditorChange(TObject *Sender)
{
if (Editor == NULL) return;
Editor->OnSelectionChange(Editor);
SetModified(Editor->Modified);
dxBarButtonUndo->Enabled = SendMessage(Editor->Handle, EM_CANUNDO, 0, 0) != 0;
RibbonDemoMainForm->FEditorUndoController->AnalyseMessage();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::EditorSelectionChange(TObject *Sender)
{
FUpdating = true;
dxBarComboFontSize->OnChange = 0;
dxBarComboFontName->OnChange = 0;
try
{
btnLineNumber->Caption = Format(" Line: %3d ", ARRAYOFCONST((1 + EditorRow)));
btnColumnNumber->Caption = Format(" Row: %3d ", ARRAYOFCONST((1 + EditorCol)));
dxBarButtonCopy->Enabled = Editor->SelLength > 0;
dxBarButtonCut->Enabled = dxBarButtonCopy->Enabled;
dxBarButtonPaste->Enabled = SendMessage(Editor->Handle, EM_CANPASTE, 0, 0) != 0;
dxBarButtonClear->Enabled = dxBarButtonCopy->Enabled;
dxBarComboFontSize->Text = IntToStr(Editor->SelAttributes->Size);
dxBarComboFontName->Text = Editor->SelAttributes->Name;
dxBarButtonBold->Down = Editor->SelAttributes->Style.Contains(fsBold);
dxBarButtonItalic->Down = Editor->SelAttributes->Style.Contains(fsItalic);
dxBarButtonUnderline->Down = Editor->SelAttributes->Style.Contains(fsUnderline);
dxBarButtonBullets->Down = ((bool)Editor->Paragraph->Numbering);
switch (Editor->Paragraph->Alignment) {
case taLeftJustify: dxBarButtonAlignLeft->Down = true; break;
case taRightJustify: dxBarButtonAlignRight->Down = true; break;
case taCenter: dxBarButtonCenter->Down = true;
}
dxBarButtonProtected->Down = Editor->SelAttributes->Protected;
FUpdating = false;
}
__finally
{
dxBarComboFontSize->OnChange = dxBarComboFontSizeChange;
dxBarComboFontName->OnChange = dxBarComboFontNameChange;
}
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::EditorMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (Button == mbRight)
dxBarPopupMenu->PopupFromCursorPos();
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::FindOne(TObject *Sender)
{
int StartPos, FindLength, FoundAt;
TSearchTypes Flags;
TPoint P;
TRect CaretR, R, IntersectR;
TFindDialog *ADialog = ((TFindDialog*) Sender);
if (ADialog->Options.Contains(frDown))
{
if (Editor->SelLength == 0) StartPos = Editor->SelStart;
else StartPos = Editor->SelStart + Editor->SelLength;
FindLength = Editor->Text.Length() - StartPos;
}
else
{
StartPos = Editor->SelStart;
FindLength = -StartPos;
}
Flags.Clear();
if (ADialog->Options.Contains(frMatchCase)) Flags << stMatchCase;
if (ADialog->Options.Contains(frWholeWord)) Flags << stWholeWord;
Screen->Cursor = crHourGlass;
FoundAt = Editor->FindText(ADialog->FindText, StartPos, FindLength, Flags);
if (!(ADialog->Options.Contains(frReplaceAll))) Screen->Cursor = crDefault;
if (FoundAt > -1)
if (ADialog->Options.Contains(frReplaceAll))
{
Editor->SelStart = FoundAt;
Editor->SelLength = ADialog->FindText.Length();
}
else
{
Editor->SetFocus();
Editor->SelStart = FoundAt;
Editor->SelLength = ADialog->FindText.Length();
GetCaretPos(&P);
P = Editor->ClientToScreen(P);
CaretR = Rect(P.x, P.y, P.x + 2, P.y + 20);
GetWindowRect(Editor->Handle, &R);
if (IntersectRect(&IntersectR, &CaretR, &R))
if (P.y < Screen->Height / 2)
ADialog->Top = P.y + 40;
else
ADialog->Top = P.y - (R.bottom - R.top + 20);
if (ADialog->Top < 0) ADialog->Top = 0;
}
else
if (!(ADialog->Options.Contains(frReplaceAll)))
Application->MessageBox(sRichEditTextNotFound,
sRichEditFoundResultCaption, MB_ICONINFORMATION);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::FontClick(TObject *Sender)
{
FontDialog->Font->Assign(Editor->SelAttributes);
if (FontDialog->Execute())
Editor->SelAttributes->Assign(FontDialog->Font);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::FormCreate(TObject *Sender)
{
dmCommonData->AboutFormClass = __classid(TRibbonDemoAboutForm);
if (FileExists(sDefaultDocName))
OpenFile(ExpandFileName(sDefaultDocName));
else
FileName = sDefaultDocName;
OpenDialog->Filter = RTFFilter;
OpenDialog->InitialDir = ExtractFilePath(ParamStr(0));
SaveDialog->InitialDir = OpenDialog->InitialDir;
ShowItems(true);
dxBarButton7->LargeImageIndex = 18;
dxBarButton7->ImageIndex = 18;
dxBarLargeButton1->LargeImageIndex = 18;
dxBarLargeButton1->ImageIndex = 18;
dxBarButton1->LargeImageIndex = 19;
dxBarButton1->ImageIndex = 19;
dxBarButton3->LargeImageIndex = 20;
dxBarButton3->ImageIndex = 20;
dxBarButton4->LargeImageIndex = 21;
dxBarButton4->ImageIndex = 21;
dxBarButton5->LargeImageIndex = 22;
dxBarButton5->ImageIndex = 22;
FColorPickerController = new TColorPickerController(rgiFontColor, rgiColorTheme, dxRibbonDropDownGallery);
FColorPickerController->OnColorChanged = FontColorChanged;
AssignFontColorGlyph();
InitSymbolGallery();
SetColorScheme("Blue");
FEditorUndoController = new TRichEditUndoController(rgiUndo, Editor);
int ATextWidth = cxTextWidth(BarManager->Font, "Undo 9999 Actions");
rgiUndo->GalleryOptions->ItemPullHighlighting->Active = True;
rgiUndo->GalleryOptions->ColumnCount = 1;
rgiUndo->GalleryOptions->SubMenuResizing = gsrNone;
rgiUndo->GalleryOptions->ItemSize->Width = ATextWidth;
rgiUndo->GalleryOptions->ItemSize->Height = 21 * Screen->PixelsPerInch / 96;
rgiUndo->GalleryGroups->Add();
bstSelectionInfo->Width = ATextWidth;
bstSelectionInfo->Caption = "Cancel";
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::FormDestroy(TObject *Sender)
{
delete FEditorUndoController;
delete FColorPickerController;
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::FormActivate(TObject *Sender)
{
if (FCanOnChange) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -