コード例 #1
0
        public void AwakeFromNib()
        {
            Window.Delegate = this;

            iAnimation = NSViewAnimationHelper.Create();

            ViewContent.AddSubview(iView.View);
            iView.EventClose += ViewClose;
        }
コード例 #2
0
        private void Close()
        {
            NSRect targetFrame = GetMinimalRect(Window.Frame);

            // animate
            NSViewAnimationHelper.SetFrames(iAnimation, Window, Window.Frame, targetFrame);
            iAnimation.StartAnimation();

            Window.Delegate = null;
            Window.Close();
            this.Autorelease();
        }
コード例 #3
0
        public void Show(NSPoint aAnchor, bool aAnchorOnLeft, NSSize aSize)
        {
            // calculate the rect for the window - the passed in arguments are "preferred" values
            // and will only be honoured if possible
            float x, y, w, h, anchorPos;
            bool  anchorOnTop = false;

            if (NSScreen.MainScreen == null)
            {
                Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 MainScreen null");
            }
            if (ViewBkgd == null)
            {
                Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 ViewBkgd null");
            }
            if (Window == null)
            {
                Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 Window null");
            }
            if (ViewContent == null)
            {
                Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 ViewContent null");
            }
            if (iView == null)
            {
                Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 iView null");
            }
            if (iView.View == null)
            {
                Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 iView.View null");
            }
            if (iAnimation == null)
            {
                Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 iAnimation null");
            }

            NSRect screenFrame = NSScreen.MainScreen.VisibleFrame;

            // determine the y-pos, height and anchor position
            if (aAnchor.y - aSize.height > screenFrame.MinY)
            {
                // window can fit in available screen with given coords and anchor at the top
                h           = aSize.height;
                y           = aAnchor.y - aSize.height;
                anchorOnTop = true;
            }
            else if (aAnchor.y + aSize.height < screenFrame.MaxY)
            {
                // window can fit in available screen with given coords and anchor at the bottom
                h           = aSize.height;
                y           = aAnchor.y;
                anchorOnTop = false;
            }
            else if (aAnchor.y > screenFrame.MidY)
            {
                // window height is truncated with anchor at top
                h           = aAnchor.y - screenFrame.MinY;
                y           = screenFrame.MinY;
                anchorOnTop = true;
            }
            else
            {
                // window height is truncated with anchor at bottom
                h           = screenFrame.MaxY - aAnchor.y;
                y           = aAnchor.y;
                anchorOnTop = false;
            }

            // determine x-pos and width
            const float anchorIndent = 50.0f;

            if (aAnchorOnLeft)
            {
                float left  = aAnchor.x - anchorIndent;
                float right = left + aSize.width;
                if (right < screenFrame.MaxX)
                {
                    // anchor ok on the left
                    x         = left;
                    w         = aSize.width;
                    anchorPos = anchorIndent;
                }
                else
                {
                    // move anchor to the right
                    x         = aAnchor.x + anchorIndent - aSize.width;
                    w         = aSize.width;
                    anchorPos = aSize.width - anchorIndent;
                }
            }
            else
            {
                float left = aAnchor.x + anchorIndent - aSize.width;
                if (left > screenFrame.MinX)
                {
                    // anchor ok on right
                    x         = left;
                    w         = aSize.width;
                    anchorPos = aSize.width - anchorIndent;
                }
                else
                {
                    // move anchor to the left
                    x         = aAnchor.x - anchorIndent;
                    w         = aSize.width;
                    anchorPos = anchorIndent;
                }
            }

            // set the target rect for the window
            ViewBkgd.AnchorOnTop = anchorOnTop;
            ViewBkgd.AnchorPos   = anchorPos;

            NSRect targetFrame  = new NSRect(x, y, w, h);
            NSRect initialFrame = GetMinimalRect(targetFrame);

            // initialise the content view to be the target size - this avoids adverse animation
            // effects where the view could potentially have a 0 or -ve height
            Window.SetFrameDisplay(targetFrame, false);
            iView.View.Frame = ViewContent.Bounds;

            // initialise and show the window
            Window.SetFrameDisplay(initialFrame, false);
            Window.MakeKeyAndOrderFront(this);

            // the popover closes when it resigns key window status. Normally, this would mean
            // it can no longer be seen (the main window is on top). Given that this window should
            // animate when closing, setting the window level will ensure that the popover is always
            // on top of the main window, so the closing animation can be seen
            Window.Level = NSWindowLevel.NSFloatingWindowLevel;

            // animate
            NSViewAnimationHelper.SetFrames(iAnimation, Window, initialFrame, targetFrame);
            iAnimation.Duration = 0.2;
            iAnimation.StartAnimation();
        }