git-svn-id: https://192.168.0.254/svn/Componentes.Terceros.DevExpressVCL@8 05c56307-c608-d34a-929d-697000501d7a
678 lines
22 KiB
C++
678 lines
22 KiB
C++
//---------------------------------------------------------------------------
|
|
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#include "RibbonNotepadDemoMain.h"
|
|
#include "RibbonNotepadDemoOptions.h"
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
#pragma link "cxClasses"
|
|
#pragma link "cxGraphics"
|
|
#pragma link "dxBar"
|
|
#pragma resource "*.dfm"
|
|
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)
|
|
{
|
|
SendMessage(Editor->Handle, EM_UNDO, 0, 0);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
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::dxBarComboFontColorChange(TObject *Sender)
|
|
{
|
|
Editor->SelAttributes->Color = dxBarComboFontColor->Color;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
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;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::EditorSelectionChange(TObject *Sender)
|
|
{
|
|
FUpdating = true;
|
|
dxBarComboFontSize->OnChange = 0;
|
|
dxBarComboFontName->OnChange = 0;
|
|
dxBarComboFontColor->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;
|
|
dxBarComboFontColor->Color = Editor->SelAttributes->Color;
|
|
|
|
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;
|
|
dxBarComboFontColor->OnChange = dxBarComboFontColorChange;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
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;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::FormActivate(TObject *Sender)
|
|
{
|
|
Editor->OnChange(Editor);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
|
|
{
|
|
if (Editor->Modified)
|
|
switch (QuerySaveFile()) {
|
|
case ID_YES: CanClose = SaveFile(false); return;
|
|
case ID_NO: CanClose = true; return;
|
|
case ID_CANCEL: CanClose = false;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int __fastcall TRibbonDemoMainForm::GetEditorCol()
|
|
{
|
|
return (Editor->SelStart - SendMessage(Handle, EM_LINEINDEX, EditorRow, 0));
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int __fastcall TRibbonDemoMainForm::GetEditorRow()
|
|
{
|
|
return (SendMessage(Handle, EM_LINEFROMCHAR, Editor->SelStart, 0));
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::MakeNewDocument()
|
|
{
|
|
Editor->Clear();
|
|
SetModified(False);
|
|
FileName = sDefaultDocName;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::OpenFile(AnsiString AFileName)
|
|
{
|
|
if (Editor->Modified)
|
|
{
|
|
switch (QuerySaveFile()) {
|
|
case mrYes : if (! SaveFile(false)) return; break;
|
|
case mrCancel : return;
|
|
}
|
|
|
|
}
|
|
OpenDialog->FileName = AFileName;
|
|
if ((AFileName != "") || OpenDialog->Execute()) {
|
|
FileName = OpenDialog->FileName;
|
|
Editor->Lines->LoadFromFile(FileName);
|
|
SetModified(false);
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int __fastcall TRibbonDemoMainForm::QuerySaveFile()
|
|
{
|
|
String S = "Do you want to save the changes you made to " + Ribbon->DocumentName + "?";
|
|
String Title = Application->Title;
|
|
return (Application->MessageBox(S.c_str(), Title.c_str(), /*MB_ICONQUESTION ||*/ MB_YESNOCANCEL));
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::ReplaceOne(TObject *Sender)
|
|
{
|
|
TReplaceDialog *ADialog = ((TReplaceDialog*) Sender);
|
|
int ReplacedCount, OldSelStart, PrevSelStart;
|
|
AnsiString S;
|
|
|
|
ReplacedCount = 0;
|
|
OldSelStart = Editor->SelStart;
|
|
if (ADialog->Options.Contains(frReplaceAll)) Screen->Cursor = crHourGlass;
|
|
do
|
|
{
|
|
if ((Editor->SelLength > 0) && ((Editor->SelText == ADialog->FindText) ||
|
|
(!(ADialog->Options.Contains(frMatchCase)) &&
|
|
(AnsiUpperCase(Editor->SelText) == AnsiUpperCase(ADialog->FindText)))))
|
|
{
|
|
Editor->SelText = ADialog->ReplaceText;
|
|
ReplacedCount++;
|
|
}
|
|
PrevSelStart = Editor->SelStart;
|
|
FindOne(Sender);
|
|
}
|
|
while (ADialog->Options.Contains(frReplaceAll) && (Editor->SelStart != PrevSelStart));
|
|
if (ADialog->Options.Contains(frReplaceAll))
|
|
{
|
|
Screen->Cursor = crDefault;
|
|
if (ReplacedCount == 0)
|
|
S = sRichEditTextNotFound;
|
|
else
|
|
{
|
|
Editor->SelStart = OldSelStart;
|
|
S = Format(sRichEditReplaceAllResult, ARRAYOFCONST((ReplacedCount)));
|
|
}
|
|
Application->MessageBox(S.c_str(), sRichEditFoundResultCaption,
|
|
MB_ICONINFORMATION);
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::RibbonResize(TObject *Sender)
|
|
{
|
|
const Space = 8;
|
|
|
|
Editor->SetBounds(Space, Ribbon->Height + Space, ClientWidth - Space * 2,
|
|
ClientHeight - (Ribbon->Height + dxStatusBar->Height + Space * 2));
|
|
if (Ribbon->QuickAccessToolbar->Position == qtpAboveRibbon)
|
|
dxBarLargeButton8->Down = true;
|
|
else
|
|
dxBarLargeButton9->Down = true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool __fastcall TRibbonDemoMainForm::SaveFile(bool ASaveAs, bool APlainText)
|
|
{
|
|
bool Result;
|
|
|
|
SaveDialog->FileName = ChangeFileExt(ExtractFileName(FileName), "");
|
|
|
|
if (APlainText)
|
|
SaveDialog->Filter = TXTFilter;
|
|
else
|
|
SaveDialog->Filter = RTFFilter;
|
|
|
|
ASaveAs = ASaveAs || (FileName == "") || (FileName == sDefaultDocName);
|
|
Result = !ASaveAs || SaveDialog->Execute();
|
|
if (Result)
|
|
{
|
|
Editor->PlainText = APlainText;
|
|
Editor->Lines->SaveToFile(SaveDialog->FileName);
|
|
if (!APlainText)
|
|
{
|
|
SetModified(false);
|
|
if (ASaveAs)
|
|
FileName = SaveDialog->FileName;
|
|
};
|
|
}
|
|
return Result;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::SetColorScheme(AnsiString AName)
|
|
{
|
|
Ribbon->ColorSchemeName = AName;
|
|
dxBarLargeButtonBlueScheme->Down = (AName == "Blue");
|
|
dxBarLargeButtonBlackScheme->Down = (AName == "Black");
|
|
dxBarLargeButtonSilverScheme->Down = (AName == "Silver");
|
|
dxStatusBar->Invalidate();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::SetFileName(AnsiString Value)
|
|
{
|
|
int AIndex;
|
|
|
|
Ribbon->DocumentName = ExtractFileName(Value);
|
|
FFileName = Value;
|
|
|
|
if (FileExists(FFileName))
|
|
{
|
|
AIndex = ApplicationMenu->ExtraPaneItems->IndexOf(FFileName);
|
|
if (AIndex > -1)
|
|
ApplicationMenu->ExtraPaneItems->Delete(AIndex);
|
|
ApplicationMenu->ExtraPaneItems->Insert(0)->Text = FFileName;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::SetModified(bool Value)
|
|
{
|
|
Editor->Modified = Value;
|
|
if (Value)
|
|
{
|
|
stModified->ImageIndex = 2;
|
|
stModified->Caption = "Modified";
|
|
}
|
|
else
|
|
{
|
|
stModified->ImageIndex = -1;
|
|
stModified->Caption = "";
|
|
}
|
|
dxBarButtonSave->Enabled = Value;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::ShowItems(bool AShow)
|
|
{
|
|
BarManager->LockUpdate = true;
|
|
try
|
|
{
|
|
if (!AShow)
|
|
{
|
|
btnLineNumber->Caption = "";
|
|
btnColumnNumber->Caption = "";
|
|
stModified->Caption = "";
|
|
}
|
|
BarManager->Groups[0]->Enabled = AShow;
|
|
}
|
|
__finally
|
|
{
|
|
BarManager->LockUpdate = false;
|
|
}
|
|
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::RibbonHelpButtonClick(TdxCustomRibbon *Sender)
|
|
{
|
|
ShowMessage("Clicked!");
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TRibbonDemoMainForm::RibbonHideMinimizedByClick(
|
|
TdxCustomRibbon *Sender, DWORD AWnd, TShiftState AShift,
|
|
const TPoint &APos, bool &AAllowProcessing)
|
|
{
|
|
AAllowProcessing = ((HWND *)AWnd != Editor->Handle);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TRibbonDemoMainForm::dxBarButtonOptionsClick(
|
|
TObject *Sender)
|
|
{
|
|
String AColorSchemeName;
|
|
TScreenTipOptions AScreenTipOptions;
|
|
AColorSchemeName = Ribbon->ColorSchemeName;
|
|
AScreenTipOptions.ShowScreenTips = BarManager->ShowHint;
|
|
AScreenTipOptions.ShowDescripitons = dxBarScreenTipRepository1->ShowDescription;
|
|
if (RibbonDemoOptionsForm->GetOptions(AColorSchemeName, AScreenTipOptions))
|
|
{
|
|
SetColorScheme(AColorSchemeName);
|
|
BarManager->ShowHint = AScreenTipOptions.ShowScreenTips;
|
|
dxBarScreenTipRepository1->ShowDescription = AScreenTipOptions.ShowDescripitons;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|