예제 #1
0
        // ------------------------------
        // private
        // ------------------------------
        private void ShowPreview(Link link, Point loc)
        {
            if (link != null && UriUtil.IsMemoUri(link.Uri))
            {
                var info = UriUtil.GetMemoInfo(link.Uri);

                if (info != null)
                {
                    var bmp = default(Bitmap);
                    if (_app.IsLoadedMemo(info))
                    {
                        /// Loadされていればそのcanvasからbitmapを作る
                        var content = _app.FindPageContent(info);
                        bmp = MemoOutlineUtil.CreateOutline(content.EditorCanvas);
                    }
                    else
                    {
                        bmp = MemoOutlineUtil.LoadOrSaveAndLoadOutline(info);
                    }

                    DisposePreviewPopup();

                    var canvas  = Host.Site.EditorCanvas;
                    var bounds  = _Figure.Bounds;
                    var screen  = Screen.FromRectangle(bounds);
                    var outline = new OutlinePreviewControl(screen, info.Title, bmp, 1f);
                    _previewPopup = new Popup(outline);
                    /// AutoClose = falseにしておかないとPopupにフォーカスを取られてしまう
                    _previewPopup.AutoClose = false;
                    _previewPopup.Tag       = bmp;

                    var locDelta      = 20;
                    var locOnScreen   = canvas.PointToScreen(canvas.TranslateToControlPoint(loc));
                    var preferredSize = outline.GetPreferredSize(new Size(int.MaxValue, int.MaxValue));

                    var isEnoughLowerSpace = preferredSize.Height < screen.WorkingArea.Height - (locOnScreen.Y + locDelta) - 2;
                    var isLocUpper         = locOnScreen.Y <= screen.WorkingArea.Height / 2;
                    var y = 0;
                    if (isEnoughLowerSpace || isLocUpper)
                    {
                        outline.MaxHeight = screen.WorkingArea.Height - (locOnScreen.Y + locDelta) - 2;
                        y = locOnScreen.Y + locDelta;
                    }
                    else
                    {
                        outline.MaxHeight = locOnScreen.Y - locDelta - 2;
                        y = locOnScreen.Y - locDelta - Math.Min(preferredSize.Height, outline.MaxHeight);
                    }

                    var isEnoughRighterSpace = preferredSize.Width < screen.WorkingArea.Width - (locOnScreen.X + locDelta) - 2;
                    var isLocLefter          = locOnScreen.X <= screen.WorkingArea.Width / 2;
                    var x = 0;
                    if (isEnoughRighterSpace || isLocLefter)
                    {
                        outline.MaxWidth = screen.WorkingArea.Width - (locOnScreen.X + locDelta) - 2;
                        x = locOnScreen.X + locDelta;
                    }
                    else
                    {
                        outline.MaxWidth = locOnScreen.X - locDelta - 2;
                        x = locOnScreen.X - locDelta - Math.Min(preferredSize.Width, outline.MaxWidth);
                    }

                    _previewPopup.Show(new Point(x, y));
                }
            }
        }