/// <summary>
 /// Init.
 /// </summary>
 /// <param name="link">the context menu</param>
 public HtmlContextMenuEventArgs(RContextMenu contextMenu)
 {
     _contextMenu = contextMenu;
 }
        /// <summary>
        /// Show context menu clicked on given rectangle.
        /// </summary>
        /// <param name="parent">the parent control to show the context menu on</param>
        /// <param name="rect">the rectangle that was clicked to show context menu</param>
        /// <param name="link">the link that was clicked to show context menu on</param>
        public void ShowContextMenu(RControl parent, CssRect rect, CssBox link)
        {
            try
            {
                DisposeContextMenu();

                _parentControl = parent;
                _currentRect = rect;
                _currentLink = link;
                _contextMenu = _htmlContainer.Adapter.GetContextMenu();

                if (rect != null)
                {
                    bool isVideo = false;
                    if (link != null)
                    {
                        isVideo = link is CssBoxFrame && ((CssBoxFrame)link).IsVideo;
                        var linkExist = !string.IsNullOrEmpty(link.HrefLink);
                        _contextMenu.AddItem(isVideo ? _openVideo : _openLink, linkExist, OnOpenLinkClick);
                        if (_htmlContainer.IsSelectionEnabled)
                        {
                            _contextMenu.AddItem(isVideo ? _copyVideoUrl : _copyLink, linkExist, OnCopyLinkClick);
                        }
                        _contextMenu.AddDivider();
                    }

                    if (rect.IsImage && !isVideo)
                    {
                        _contextMenu.AddItem(_saveImage, rect.Image != null, OnSaveImageClick);
                        if (_htmlContainer.IsSelectionEnabled)
                        {
                            _contextMenu.AddItem(_copyImageLink, !string.IsNullOrEmpty(_currentRect.OwnerBox.GetAttribute("src")), OnCopyImageLinkClick);
                            _contextMenu.AddItem(_copyImage, rect.Image != null, OnCopyImageClick);
                        }
                        _contextMenu.AddDivider();
                    }

                    if (_htmlContainer.IsSelectionEnabled)
                    {
                        _contextMenu.AddItem(_copy, rect.Selected, OnCopyClick);
                    }
                }

                if (_htmlContainer.IsSelectionEnabled)
                {
                    _contextMenu.AddItem(_selectAll, true, OnSelectAllClick);
                }

                if (_contextMenu.ItemsCount > 0)
                {
                    _contextMenu.RemoveLastDivider();
                    _contextMenu.Show(parent, parent.MouseLocation);
                }
            }
            catch (Exception ex)
            {
                _htmlContainer.ReportError(HtmlRenderErrorType.ContextMenu, "Failed to show context menu", ex);
            }
        }
 /// <summary>
 /// Dispose of the last used context menu.
 /// </summary>
 private void DisposeContextMenu()
 {
     try
     {
         if (_contextMenu != null)
             _contextMenu.Dispose();
         _contextMenu = null;
         _parentControl = null;
         _currentRect = null;
         _currentLink = null;
     }
     catch
     { }
 }
示例#4
0
 /// <summary>
 /// Handle context menu customisation by the caller
 /// </summary>
 /// <param name="contextMenu">the context menu to customise</param>
 internal void HandleContextMenuInvoked(RContextMenu contextMenu)
 {
     EventHandler<HtmlContextMenuEventArgs> contextMenuHandler = ContextMenuInvoked;
     if (contextMenuHandler != null)
     {
         var args = new HtmlContextMenuEventArgs(contextMenu);
         try
         {
             contextMenuHandler(this, args);
         }
         catch (Exception ex)
         {
             throw new Exception("Error in context menu intercept", ex);
         }
     }
 }