예제 #1
0
        public ContentEditor(IMainFrameWindow mainFrameWindow, Control editorContainer, IBlogPostEditingSite postEditingSite, IInternetSecurityManager internetSecurityManager, BlogPostHtmlEditorControl.TemplateStrategy templateStrategy, int dlControlFlags)
        {
            // create a docked panel to host the editor
            Panel panel = new Panel();
            panel.Dock = DockStyle.Fill;

            if (!BidiHelper.IsRightToLeft)
                panel.DockPadding.Right = 0;
            else
                panel.DockPadding.Left = 0;

            editorContainer.Controls.Add(panel);
            panel.Resize += new EventHandler(panel_Resize);
            if (BidiHelper.IsRightToLeft)
                editorContainer.RightToLeft = RightToLeft.Yes;

            // save references
            _mainFrameWindow = mainFrameWindow;
            _editorContainer = panel;
            _postEditingSite = postEditingSite;

            _commandManager = new CommandManager();

            _userPreferencesMonitor = new UserPreferencesMonitor();

            // To be high-contrast-aware we need to respond to changes in the high contrast mode
            // by invalidating commands, forcing the ribbon to ask us for new high contrast images.
            _userPreferencesMonitor.AccessibilityUserPreferencesChanged +=
                new EventHandler(delegate (object sender, EventArgs args)
                                     {
                                         _commandManager.InvalidateAllImages();
                                     });

            _imageDecoratorsManager = new LazyLoader<ImageDecoratorsManager>(() => new ImageDecoratorsManager(components, CommandManager, GlobalEditorOptions.SupportsFeature(ContentEditorFeature.ImageBorderInherit)));
            _emoticonsManager = new EmoticonsManager(this, this);

            // initialize commands
            InitializeCommands();

            // initialize normal editor
            InitializeNormalEditor(postEditingSite, internetSecurityManager, templateStrategy, dlControlFlags);

            // initialize source editor
            if (GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SourceEditor))
                InitializeSourceEditor();

            InitializeViewCommands();

            // initialize custom content
            InitializeContentSources();

            // bring main editor panel to front (this must be here for the sidebar to work!!!!)
            panel.BringToFront();
        }
        public PostEditorKeyboardHandler(BlogPostHtmlEditorControl blogPostHtmlEditorControl, IBlogPostImageEditingContext imageEditingContext, IEditingMode editingModeContext)
        {
            _blogPostHtmlEditorControl = blogPostHtmlEditorControl;
            _blogPostHtmlEditorControl.PostEditorEvent += _blogPostHtmlEditorControl_PostEditorEvent;
            _blogPostHtmlEditorControl.KeyPress += _blogPostHtmlEditorControl_KeyPress;
            _blogPostHtmlEditorControl.KeyDown += _blogPostHtmlEditorControl_KeyDown;
            _blogPostHtmlEditorControl.SelectionChanged += _blogPostHtmlEditorControl_SelectionChanged;

            _imageEditingContext = imageEditingContext;
            _editingModeContext = editingModeContext;

            _autoreplaceManager = new AutoreplaceManager();
            AutoreplaceSettings.SettingsChanged += AutoreplaceSettings_SettingsChanged;

            LastChanceKeyboardHook.BeforeKeyHandled += _keyHandled;
        }
예제 #3
0
        /// <summary>
        /// Initializes the IContentEditor.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="contentEditorSite"></param>
        /// <param name="internetSecurityManager"></param>
        /// <param name="wysiwygHTML"></param>
        /// <param name="previewHTML"></param>
        /// <param name="newEditingContext"></param>
        /// <param name="templateStrategy"></param>
        /// <param name="dlControlFlags">
        /// For Mail, these flags should always include DLCTL_DLIMAGES | DLCTL_VIDEOS | DLCTL_BGSOUNDS so that local
        /// images, videos and sounds are loaded. To block external content, it should also include
        /// DLCTL_PRAGMA_NO_CACHE | DLCTL_FORCEOFFLINE | DLCTL_NO_CLIENTPULL so that external images are not loaded
        /// and are displayed as a red X instead.
        /// </param>
        /// <param name="color"></param>
        private void ContentEditorProxyCore(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, string wysiwygHTML, string previewHTML, IBlogPostEditingContext newEditingContext, BlogPostHtmlEditorControl.TemplateStrategy templateStrategy, int dlControlFlags, string color)
        {
            try
            {
                Debug.Assert(contentEditorSite is IUIFramework, "IContentEditorSite must also implement IUIFramework");
                Debug.Assert(contentEditorSite is IDropTarget, "IContentEditorSite must also implement IDropTarget");

                ApplyInstalledCulture();

                this.factory = factory;

                _wysiwygHTML = wysiwygHTML;
                _previewHTML = previewHTML;
                _contentEditorSite = contentEditorSite;

                IntPtr p = _contentEditorSite.GetWindowHandle();
                WINDOWINFO info = new WINDOWINFO();
                User32.GetWindowInfo(p, ref info);
                panel = new Panel();
                panel.Top = 0;
                panel.Left = 0;
                panel.Width = Math.Max(info.rcWindow.Width, 200);
                panel.Height = Math.Max(info.rcWindow.Height, 200);
                panel.CreateControl();
                User32.SetParent(panel.Handle, p);

                accountAdapter = new ContentEditorAccountAdapter();
                mainFrame = new MainFrameWindowAdapter(p, panel, _contentEditorSite, accountAdapter.Id);
                context = newEditingContext;
                contentEditor = new ContentEditor(mainFrame, panel, mainFrame, internetSecurityManager, templateStrategy, dlControlFlags);

                // Prevents asserts
                contentEditor.DisableSpelling();

                contentEditor.OnEditorAccountChanged(accountAdapter);
                contentEditor.DocumentComplete += new EventHandler(blogPostHtmlEditor_DocumentComplete);
                contentEditor.GotFocus += new EventHandler(contentEditor_GotFocus);
                contentEditor.LostFocus += new EventHandler(contentEditor_LostFocus);
                contentEditor.Initialize(context, accountAdapter, wysiwygHTML, previewHTML, false);

                if (!string.IsNullOrEmpty(color))
                {
                    contentEditor.IndentColor = color;
                }
            }
            catch (Exception ex)
            {
                // Something went wrong, make sure we don't reuse a cached editor
                HtmlEditorControl.DisposeCachedEditor();
                Trace.Fail(ex.ToString());
                Trace.Flush();
                throw;
            }
        }
 public PostBodyEditingElementBehavior(BlogPostHtmlEditorControl editor, IHtmlEditorComponentContext editorContext, IHTMLElement prevEditableRegion, IHTMLElement nextEditableRegion)
     : base(editorContext, prevEditableRegion, nextEditableRegion)
 {
     _editor = editor;
 }
 public SpellCheckingDamageCommitStrategy(BlogPostHtmlEditorControl editor)
 {
     _wordBasedCommitStrategy = new WordBasedDamageCommitStrategy(editor);
     _realtimeCommitStrategy = new RealtimeDamageCommitStrategy();
     _realtimeCommitStrategy.CommitDamage += new EventHandler(_currentCommitStrategy_CommitDamage);
     _wordBasedCommitStrategy.CommitDamage += new EventHandler(_currentCommitStrategy_CommitDamage);
     CurrentCommitStrategy = _wordBasedCommitStrategy;
     _editor = editor;
 }
 public AutoReplaceAction(BlogPostHtmlEditorControl editor, char key, string replacement, MarkupRange range)
 {
     this.editor = editor;
     this.key = key;
     this.replacement = replacement;
     this.range = range;
 }
        public void Dispose()
        {
            if (_blogPostHtmlEditorControl != null)
            {
                _blogPostHtmlEditorControl.PostEditorEvent -= _blogPostHtmlEditorControl_PostEditorEvent;
                _blogPostHtmlEditorControl.KeyPress -= _blogPostHtmlEditorControl_KeyPress;
                _blogPostHtmlEditorControl.KeyDown -= _blogPostHtmlEditorControl_KeyDown;
                _blogPostHtmlEditorControl.SelectionChanged -= _blogPostHtmlEditorControl_SelectionChanged;
                _blogPostHtmlEditorControl = null;
            }
            LastChanceKeyboardHook.BeforeKeyHandled -= _keyHandled;

            AutoreplaceSettings.SettingsChanged -= AutoreplaceSettings_SettingsChanged;
        }
예제 #8
0
        private void InitializeNormalEditor(IBlogPostEditingSite postEditingSite, IInternetSecurityManager internetSecurityManager, BlogPostHtmlEditorControl.TemplateStrategy templateStrategy, int dlControlFlags)
        {
            // configure editing options
            _mshtmlOptions = new MshtmlOptions();
            _mshtmlOptions.UseDivForCarriageReturn = GlobalEditorOptions.SupportsFeature(ContentEditorFeature.DivNewLine);
            // Commented out for now to prevent first chance exception
            //_mshtmlOptions.EditingOptions.Add(IDM.RESPECTVISIBILITY_INDESIGN, GlobalEditorOptions.SupportsFeature(ContentEditorFeature.HideNonVisibleElements));
            _mshtmlOptions.EditingOptions.Add(IDM.AUTOURLDETECT_MODE, false);
            _mshtmlOptions.EditingOptions.Add(IDM.MULTIPLESELECTION, false);
            _mshtmlOptions.EditingOptions.Add(IDM.LIVERESIZE, true);
            _mshtmlOptions.EditingOptions.Add(IDM.KEEPSELECTION, true);
            _mshtmlOptions.EditingOptions.Add(IDM.DISABLE_EDITFOCUS_UI, true);
            _mshtmlOptions.DLCTLOptions = dlControlFlags;
            _mshtmlOptions.DocHostUIOptionKeyPath = GlobalEditorOptions.GetSetting<string>(ContentEditorSetting.MshtmlOptionKeyPath);

            // create the editor
            _normalHtmlContentEditor = new BlogPostHtmlEditorControl(_mainFrameWindow, StatusBar, _mshtmlOptions, this, this, this, new SmartContentResizedListener(ResizedListener), new SharedCanvasImageReferenceFixer(ReferenceFixer), internetSecurityManager, CommandManager, templateStrategy, this);
            _normalHtmlContentEditor.PostBodyInlineStyle = GetPostBodyInlineStyleOverrides();
            // hookup services and events
            _normalHtmlContentEditor.HtmlGenerationService = new HtmlGenerator(this);
            _normalHtmlContentEditor.DataFormatHandlerFactory = new ExtendedHtmlEditorMashallingHandler(_normalHtmlContentEditor, this, this, postEditingSite as IDropTarget);
            _normalHtmlContentEditor.DocumentComplete += new EventHandler(htmlEditor_DocumentComplete);
            _normalHtmlContentEditor.GotFocus += htmlEditor_GotFocus;
            _normalHtmlContentEditor.LostFocus += htmlEditor_LostFocus;

            _normalHtmlContentEditor.SelectedImageResized += new SelectedImageResizedHandler(_normalHtmlContentEditor_SelectedImageResized);
            _normalHtmlContentEditor.UpdateImageLink += new UpdateImageLinkHandler(_normalHtmlContentEditor_UpdateImageLink);
            _normalHtmlContentEditor.HtmlInserted += new EventHandler(_normalHtmlContentEditor_HtmlInserted);
            _normalHtmlContentEditor.HelpRequest += new EventHandler(_normalHtmlContentEditor_HelpRequest);
            _normalHtmlContentEditor.EditorControl.AccessibleName = "Editor";

            _normalHtmlContentEditor.KeyboardLanguageChanged += new EventHandler(_normalHtmlContentEditor_KeyboardLanguageChanged);
            _normalHtmlContentEditor.TrackKeyboardLanguageChanges = true;

            // initialize the sidebar
            _htmlEditorSidebarHost = new HtmlEditorSidebarHost(_normalHtmlContentEditor);
            _htmlEditorSidebarHost.Dock = !BidiHelper.IsRightToLeft ? DockStyle.Right : DockStyle.Left;
            _htmlEditorSidebarHost.Width = Res.SidebarWidth;
            if (BidiHelper.IsRightToLeft)
            {
                _htmlEditorSidebarHost.RightToLeft = RightToLeft.Yes;
                BidiHelper.RtlLayoutFixup(_htmlEditorSidebarHost);
            }
            _editorContainer.Controls.Add(_htmlEditorSidebarHost);
            _htmlEditorSidebarHost.BringToFront();
            _htmlEditorSidebarHost.VisibleChanged += _htmlEditorSidebarHost_VisibleChanged;

            // register sidebars
            _htmlEditorSidebarHost.RegisterSidebar(new DisabledContentSourceSidebar(this));
            _htmlEditorSidebarHost.RegisterSidebar(new BrokenContentSourceSidebar(this));
            _htmlEditorSidebarHost.RegisterSidebar(new ContentSourceSidebar(this));
            _htmlEditorSidebarHost.RegisterSidebar(new ImagePropertiesSidebar(_normalHtmlContentEditor, this, new CreateFileCallback(CreateFileHandler)));
            _htmlEditorSidebarHost.AccessibleName = "Sidebar";

            // register the normal editor
            RegisterEditor(_normalHtmlContentEditor);
        }
        private static void HandleNewImage(BlogPostHtmlEditorControl currentEditor, Control owner, IHTMLElement imageElement, bool select)
        {
            // If the selection has changed since we first inserted the img tag, don't force a new selection.
            currentEditor.SelectionChanged -= blogPostEditor_SelectionChanged;
            if (selectionChanged || !select)
                return;

            try
            {
                currentEditor.EmptySelection();
                // programmatically select the image
                currentEditor.SelectImage(imageElement);
                currentEditor.Focus();
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected error while attempting to select newly inserted image: " + ex.ToString());
            }
        }