RibbonNotepadDemoMain.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:16k
源码类别:
Email服务器
开发平台:
Delphi
- unit RibbonNotepadDemoMain;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, ComCtrls, dxBar, StdCtrls, dxBarExtItems, cxControls,
- ImgList, ActnList, cxLookAndFeels, dxStatusBar, cxGraphics, EBarsUtils,
- dxRibbonForm, dxRibbon, cxClasses, Menus, dxRibbonStatusBar, cxStyles,
- OleCtrls, SHDocVw, uHtmlEdit, ExtDlgs;
- type
- TRibbonDemoMainForm = class(TdxRibbonForm)
- BarManager: TdxBarManager;
- dxBarButtonNew: TdxBarLargeButton;
- dxBarButtonOpen: TdxBarLargeButton;
- dxBarButtonSave: TdxBarLargeButton;
- dxBarSubItemSaveAs: TdxBarSubItem;
- dxBarButtonSaveAsRTF: TdxBarButton;
- dxBarButtonSaveAsText: TdxBarButton;
- dxBarButtonPrint: TdxBarLargeButton;
- dxBarButtonExit: TdxBarLargeButton;
- dxBarButtonUndo: TdxBarLargeButton;
- dxBarButtonCut: TdxBarLargeButton;
- dxBarButtonCopy: TdxBarLargeButton;
- dxBarButtonPaste: TdxBarLargeButton;
- dxBarButtonClear: TdxBarLargeButton;
- dxBarButtonSelectAll: TdxBarLargeButton;
- dxBarButtonFind: TdxBarLargeButton;
- dxBarButtonReplace: TdxBarLargeButton;
- dxBarComboFontSize: TdxBarCombo;
- dxBarButtonBold: TdxBarLargeButton;
- dxBarButtonItalic: TdxBarLargeButton;
- dxBarButtonUnderline: TdxBarLargeButton;
- dxBarButtonBullets: TdxBarLargeButton;
- dxBarButtonProtected: TdxBarLargeButton;
- dxBarButtonAlignLeft: TdxBarLargeButton;
- dxBarButtonCenter: TdxBarLargeButton;
- dxBarButtonAlignRight: TdxBarLargeButton;
- dxBarButtonFont: TdxBarLargeButton;
- dxBarSeparator: TdxBarSeparator;
- OpenDialog: TOpenDialog;
- SaveDialog: TSaveDialog;
- PrintDialog: TPrintDialog;
- FontDialog: TFontDialog;
- dxBarPopupMenu: TdxRibbonPopupMenu;
- dxBarComboFontColor: TdxBarColorCombo;
- dxBarGroup1: TdxBarGroup;
- dxBarButton1: TdxBarLargeButton;
- dxBarComboFontName: TdxBarFontNameCombo;
- ilStatusBarImages: TImageList;
- dxStatusBar: TdxRibbonStatusBar;
- FindDialog: TFindDialog;
- ReplaceDialog: TReplaceDialog;
- tabHome: TdxRibbonTab;
- Ribbon: TdxRibbon;
- tabAppearance: TdxRibbonTab;
- BarManagerBar5: TdxBar;
- BarManagerBar7: TdxBar;
- ApplicationMenu: TdxBarApplicationMenu;
- BarManagerBar8: TdxBar;
- BarManagerBar1: TdxBar;
- dxBarLargeButton3: TdxBarLargeButton;
- dxBarLargeButton4: TdxBarLargeButton;
- dxBarLargeButton5: TdxBarLargeButton;
- dxBarLargeButton6: TdxBarLargeButton;
- dxBarLargeButton7: TdxBarLargeButton;
- BarManagerBar10: TdxBar;
- dxBarLargeButton8: TdxBarLargeButton;
- dxBarLargeButton9: TdxBarLargeButton;
- dxBarLargeButton10: TdxBarLargeButton;
- BarManagerBar12: TdxBar;
- dxBarScreenTipRepository1: TdxBarScreenTipRepository;
- cxLargeImages: TcxImageList;
- cxSmallImages: TcxImageList;
- BarManagerBar6: TdxBar;
- BarManagerBar13: TdxBar;
- btnLineNumber: TdxBarButton;
- btnColumnNumber: TdxBarButton;
- btnLocked: TdxBarButton;
- stModified: TdxBarStatic;
- stFontDialog: TdxBarScreenTip;
- stHelpButton: TdxBarScreenTip;
- HtmlEdit: THtmlEdit;
- ActionListButton: TActionList;
- Act_New: TAction;
- Act_Open: TAction;
- Act_Save: TAction;
- Act_SaveAs: TAction;
- Act_SaveTo: TAction;
- Act_Clear: TAction;
- Act_Redo: TAction;
- Act_Undo: TAction;
- Act_SelectAll: TAction;
- Act_Print: TAction;
- Act_PageSetup: TAction;
- Act_PrintPreview: TAction;
- Act_Write: TAction;
- Act_Copy: TAction;
- Act_Cut: TAction;
- Act_Paste: TAction;
- Act_Insert: TAction;
- Act_Append: TAction;
- Act_ViewSource: TAction;
- Act_ViewText: TAction;
- Act_Edit_BackColoer: TAction;
- Act_Edit_Bold: TAction;
- Act_Edit_CreateLink: TAction;
- Act_Edit_ForeColor: TAction;
- Act_Edit_HorizontalRule: TAction;
- Act_Edit_InsertImage: TAction;
- Act_Edit_InsertLineBreak: TAction;
- Act_Edit_InsertOrderedlist: TAction;
- Act_Edit_InsertTable: TAction;
- Act_Edit_InsertUnOrderedList: TAction;
- Act_Edit_JustifyCenter: TAction;
- Act_Edit_JustifyFull: TAction;
- Act_Edit_JustifyLeft: TAction;
- Act_Edit_JustifyRight: TAction;
- Act_Edit_Italic: TAction;
- Act_Edit_RemoveFormat: TAction;
- Act_Edit_ScrollToBottom: TAction;
- Act_Edit_ScrollToTop: TAction;
- Act_Edit_OutDent: TAction;
- Act_Edit_InDent: TAction;
- Act_Edit_SuperScript: TAction;
- Act_Edit_SubScript: TAction;
- Act_Edit_UnderLine: TAction;
- Act_Edit_StrikeThrough: TAction;
- Act_Exit: TAction;
- Act_Help: TAction;
- Act_About: TAction;
- Act_M_ExampleWindow: TAction;
- Act_M_ExampleButton: TAction;
- dlgOpenPic: TOpenPictureDialog;
- tabInsert: TdxRibbonTab;
- tabTable: TdxRibbonTab;
- dxBarButton2: TdxBarButton;
- procedure FormCreate(Sender: TObject);
- procedure dxBarLargeButton8Click(Sender: TObject);
- procedure dxBarLargeButton9Click(Sender: TObject);
- procedure dxBarLargeButton7Click(Sender: TObject);
- procedure RibbonResize(Sender: TObject);
- procedure RibbonHelpButtonClick(Sender: TdxCustomRibbon);
- procedure Act_NewExecute(Sender: TObject);
- procedure Act_OpenExecute(Sender: TObject);
- procedure Act_SaveExecute(Sender: TObject);
- procedure Act_SaveAsExecute(Sender: TObject);
- procedure Act_SaveToExecute(Sender: TObject);
- procedure Act_ClearExecute(Sender: TObject);
- procedure Act_RedoExecute(Sender: TObject);
- procedure Act_UndoExecute(Sender: TObject);
- procedure Act_SelectAllExecute(Sender: TObject);
- procedure Act_PrintExecute(Sender: TObject);
- procedure Act_PageSetupExecute(Sender: TObject);
- procedure Act_PrintPreviewExecute(Sender: TObject);
- procedure Act_WriteExecute(Sender: TObject);
- procedure Act_CopyExecute(Sender: TObject);
- procedure Act_CutExecute(Sender: TObject);
- procedure Act_PasteExecute(Sender: TObject);
- procedure Act_Edit_BoldExecute(Sender: TObject);
- procedure Act_Edit_CreateLinkExecute(Sender: TObject);
- procedure Act_Edit_ForeColorExecute(Sender: TObject);
- procedure Act_Edit_HorizontalRuleExecute(Sender: TObject);
- procedure Act_Edit_InsertImageExecute(Sender: TObject);
- procedure Act_Edit_InsertLineBreakExecute(Sender: TObject);
- procedure Act_Edit_InsertOrderedlistExecute(Sender: TObject);
- procedure Act_Edit_InsertTableExecute(Sender: TObject);
- procedure Act_Edit_InsertUnOrderedListExecute(Sender: TObject);
- procedure Act_Edit_JustifyCenterExecute(Sender: TObject);
- procedure Act_Edit_JustifyFullExecute(Sender: TObject);
- procedure Act_Edit_JustifyLeftExecute(Sender: TObject);
- procedure Act_Edit_JustifyRightExecute(Sender: TObject);
- procedure Act_Edit_ItalicExecute(Sender: TObject);
- procedure Act_Edit_RemoveFormatExecute(Sender: TObject);
- procedure Act_Edit_ScrollToBottomExecute(Sender: TObject);
- procedure Act_Edit_ScrollToTopExecute(Sender: TObject);
- procedure Act_Edit_OutDentExecute(Sender: TObject);
- procedure Act_Edit_InDentExecute(Sender: TObject);
- procedure Act_Edit_SuperScriptExecute(Sender: TObject);
- procedure Act_Edit_SubScriptExecute(Sender: TObject);
- procedure Act_Edit_UnderLineExecute(Sender: TObject);
- procedure Act_Edit_StrikeThroughExecute(Sender: TObject);
- procedure Act_ExitExecute(Sender: TObject);
- procedure Act_FontNameExecute(Sender: TObject);
- procedure Act_FontSizeExecute(Sender: TObject);
- procedure dxBarLargeButton3Click(Sender: TObject);
- procedure dxBarLargeButton4Click(Sender: TObject);
- procedure dxBarLargeButton5Click(Sender: TObject);
- private
- FFileName: string;
- procedure SetFileName(Value: string);
- public
- procedure SetColorScheme(const AName: string);
- procedure ShowItems(AShow: Boolean);
- property FileName: string read FFileName write SetFileName;
- end;
- var
- RibbonDemoMainForm: TRibbonDemoMainForm;
- implementation
- {$R *.DFM}
- {$R windowsxp.res}
- uses
- RichEdit, RibbonDemoAbout;
- const
- sRichEditFoundResultCaption = 'Information';
- sRichEditTextNotFound = 'The search text is not found.';
- sRichEditReplaceAllResult = 'Replaced %d occurances.';
- sDefaultDocName = 'Document1.rtf';
- RTFFilter = 'Rich Text Files (*.RTF)|*.RTF';
- TXTFilter = 'Plain text (*.TXT)|*.TXT';
- function EnumFontsProc(var LogFont: TLogFont; var TextMetric: TTextMetric;
- FontType: Integer; Data: Pointer): Integer; stdcall;
- begin
- TStrings(Data).Add(LogFont.lfFaceName);
- Result := 1;
- end;
- procedure TRibbonDemoMainForm.SetFileName(Value: string);
- var
- AIndex: Integer;
- begin
- Ribbon.DocumentName := ExtractFileName(Value);
- FFileName := Value;
- if FileExists(FFileName) then
- begin
- AIndex := ApplicationMenu.ExtraPaneItems.IndexOf(FFileName);
- if AIndex > -1 then
- ApplicationMenu.ExtraPaneItems.Delete(AIndex);
- ApplicationMenu.ExtraPaneItems.Insert(0).Text := FFileName;
- end;
- end;
- procedure TRibbonDemoMainForm.RibbonResize(Sender: TObject);
- const
- Space = 8;
- begin
- if Ribbon.QuickAccessToolbar.Position = qtpAboveRibbon then
- dxBarLargeButton8.Down := True
- else
- dxBarLargeButton9.Down := True;
- end;
- procedure TRibbonDemoMainForm.SetColorScheme(const AName: string);
- begin
- Ribbon.ColorSchemeName := AName;
- dxStatusBar.Invalidate;
- end;
- procedure TRibbonDemoMainForm.ShowItems(AShow: Boolean);
- begin
- BarManager.LockUpdate := True;
- try
- if not AShow then
- begin
- btnLineNumber.Caption := '';
- btnColumnNumber.Caption := '';
- stModified.Caption := '';
- end;
- BarManager.Groups[0].Enabled := AShow;
- finally
- BarManager.LockUpdate := False;
- end;
- end;
- procedure TRibbonDemoMainForm.FormCreate(Sender: TObject);
- begin
- dmCommonData.AboutFormClass := TRibbonDemoAboutForm;
- HtmlEdit.Align := alClient;
- // OpenDialog.Filter := RTFFilter;
- OpenDialog.InitialDir := ExtractFilePath(ParamStr(0));
- SaveDialog.InitialDir := OpenDialog.InitialDir;
- HtmlEdit.ImageFolder := ExtractFilePath(ParamStr(0)) + 'Images';
- ShowItems(True);
- end;
- procedure TRibbonDemoMainForm.dxBarLargeButton7Click(Sender: TObject);
- begin
- Ribbon.ApplicationButton.Visible := not Ribbon.ApplicationButton.Visible;
- end;
- procedure TRibbonDemoMainForm.dxBarLargeButton8Click(Sender: TObject);
- begin
- Ribbon.QuickAccessToolbar.Position := qtpAboveRibbon;
- end;
- procedure TRibbonDemoMainForm.dxBarLargeButton9Click(Sender: TObject);
- begin
- Ribbon.QuickAccessToolbar.Position := qtpBelowRibbon;
- end;
- procedure TRibbonDemoMainForm.RibbonHelpButtonClick(
- Sender: TdxCustomRibbon);
- begin
- ShowMessage('Clicked!');
- end;
- procedure TRibbonDemoMainForm.Act_NewExecute(Sender: TObject);
- begin
- HtmlEdit.New;
- end;
- procedure TRibbonDemoMainForm.Act_ExitExecute(Sender: TObject);
- begin
- Close;
- end;
- procedure TRibbonDemoMainForm.Act_FontNameExecute(Sender: TObject);
- begin
- if dxBarComboFontName.Text <> '' then
- HtmlEdit.Edit.FontName(dxBarComboFontName.Text);
- end;
- procedure TRibbonDemoMainForm.Act_FontSizeExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.FontSize(dxBarComboFontSize.ItemIndex + 1);
- end;
- procedure TRibbonDemoMainForm.Act_OpenExecute(Sender: TObject);
- begin
- if OpenDialog.Execute then
- HtmlEdit.Open(OpenDialog.FileName);
- end;
- procedure TRibbonDemoMainForm.Act_PasteExecute(Sender: TObject);
- begin
- HtmlEdit.Paste;
- end;
- procedure TRibbonDemoMainForm.Act_PrintExecute(Sender: TObject);
- begin
- HtmlEdit.Print;
- end;
- procedure TRibbonDemoMainForm.Act_PrintPreviewExecute(Sender: TObject);
- begin
- HtmlEdit.PrintPreview;
- end;
- procedure TRibbonDemoMainForm.Act_RedoExecute(Sender: TObject);
- begin
- HtmlEdit.Redo;
- end;
- procedure TRibbonDemoMainForm.Act_SaveExecute(Sender: TObject);
- begin
- HtmlEdit.Save;
- end;
- procedure TRibbonDemoMainForm.Act_SelectAllExecute(Sender: TObject);
- begin
- HtmlEdit.SelectAll;
- end;
- procedure TRibbonDemoMainForm.Act_UndoExecute(Sender: TObject);
- begin
- HtmlEdit.Undo;
- end;
- procedure TRibbonDemoMainForm.Act_SaveAsExecute(Sender: TObject);
- begin
- HtmlEdit.SaveAs;
- end;
- procedure TRibbonDemoMainForm.Act_SaveToExecute(Sender: TObject);
- begin
- if SaveDialog.Execute then
- HtmlEdit.SaveToFile(SaveDialog.FileName);
- end;
- procedure TRibbonDemoMainForm.Act_PageSetupExecute(Sender: TObject);
- begin
- HtmlEdit.PrintPageSetup;
- end;
- procedure TRibbonDemoMainForm.Act_ClearExecute(Sender: TObject);
- begin
- HtmlEdit.Clear;
- end;
- procedure TRibbonDemoMainForm.Act_WriteExecute(Sender: TObject);
- var
- strTable: string;
- RowCnt, ColCnt: integer;
- begin
- strTable := '<TABLE border=1 >';
- for RowCnt := 1 to 3 do
- begin
- strTable := strTable + '<TR>';
- for ColCnt := 1 to 5 do
- strTable := strTable + '<TD> </TD>';
- strTable := strTable + '</TR>';
- end;
- strTable := strTable + '</TABLE>';
- HtmlEdit.Write(strTable);
- end;
- procedure TRibbonDemoMainForm.Act_CopyExecute(Sender: TObject);
- begin
- HtmlEdit.Copy;
- end;
- procedure TRibbonDemoMainForm.Act_CutExecute(Sender: TObject);
- begin
- HtmlEdit.Cut;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_BoldExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.Bold;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_CreateLinkExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.CreateLink;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_HorizontalRuleExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.InsertHorizontalRule;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_ForeColorExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.ForeColor(dxBarComboFontColor.Color);
- end;
- procedure TRibbonDemoMainForm.Act_Edit_InsertImageExecute(Sender: TObject);
- begin
- if dlgOpenPic.Execute then
- HtmlEdit.Edit.InsertImage(dlgOpenPic.FileName);
- end;
- procedure TRibbonDemoMainForm.Act_Edit_InsertLineBreakExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.InsertLineBreak;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_InsertOrderedlistExecute(Sender:
- TObject);
- begin
- HtmlEdit.Edit.InsertOrderedList;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_InsertTableExecute(Sender: TObject);
- begin
- //HtmlEdit.Edit.InsertTable(StrToInt(edt2.Text), StrToInt(edt3.Text));
- end;
- procedure TRibbonDemoMainForm.Act_Edit_InsertUnOrderedListExecute(
- Sender: TObject);
- begin
- HtmlEdit.Edit.InsertUnOrderedList;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_JustifyCenterExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.JustifyCenter;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_JustifyFullExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.JustifyFull;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_JustifyLeftExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.JustifyLeft;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_JustifyRightExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.JustifyRight;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_ItalicExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.Italic;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_RemoveFormatExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.RemoveFormat;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_ScrollToBottomExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.ScrollToBottom;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_ScrollToTopExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.ScrollToTop;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_OutDentExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.OutDent;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_InDentExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.InDent;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_SuperScriptExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.SuperScript;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_SubScriptExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.SubScript;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_UnderLineExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.UnderLine;
- end;
- procedure TRibbonDemoMainForm.Act_Edit_StrikeThroughExecute(Sender: TObject);
- begin
- HtmlEdit.Edit.StrikeThrough;
- end;
- procedure TRibbonDemoMainForm.dxBarLargeButton3Click(Sender: TObject);
- begin
- SetColorScheme('Blue');
- end;
- procedure TRibbonDemoMainForm.dxBarLargeButton4Click(Sender: TObject);
- begin
- SetColorScheme('Black');
- end;
- procedure TRibbonDemoMainForm.dxBarLargeButton5Click(Sender: TObject);
- begin
- SetColorScheme('Silver');
- end;
- end.