예제 #1
0
        private void WireUpEvents()
        {
            tree.MouseDown += (s, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    ContextNode = tree.GetNodeAt(e.X, e.Y) as TestSuiteTreeNode;
                }
            };

            tree.AfterSelect += (s, e) =>
            {
                if (_propertiesDialog != null)
                {
                    if (_propertiesDialog.Pinned)
                    {
                        _propertiesDialog.DisplayProperties((TestSuiteTreeNode)e.Node);
                    }
                    else
                    {
                        _propertiesDialog.Close();
                    }
                }
            };

            tree.DragDrop += (s, e) =>
            {
                if (IsValidFileDrop(e.Data))
                {
                    FileDrop?.Invoke((string[])e.Data.GetData(DataFormats.FileDrop));
                }
            };

            tree.DragEnter += (s, e) =>
            {
                e.Effect = IsValidFileDrop(e.Data)
                    ? DragDropEffects.Copy
                    : DragDropEffects.None;
            };

            treeMenu.Popup += (s, e) =>
            {
                TestSuiteTreeNode targetNode = ContextNode ?? (TestSuiteTreeNode)tree.SelectedNode;
                TestSuiteTreeNode theoryNode = targetNode?.GetTheoryNode();


                runMenuItem.DefaultItem = runMenuItem.Enabled && targetNode != null && targetNode.Included &&
                                          (targetNode.Test.RunState == RunState.Runnable || targetNode.Test.RunState == RunState.Explicit);

                showCheckBoxesMenuItem.Checked = tree.CheckBoxes;

                //failedAssumptionsMenuItem.Visible =
                failedAssumptionsMenuItem.Enabled = theoryNode != null;
                failedAssumptionsMenuItem.Checked = theoryNode?.ShowFailedAssumptions ?? false;

                propertiesMenuItem.Enabled = targetNode != null;
            };

            treeMenu.Collapse += (s, e) => ContextNode = null;
        }
        private void UserControl_Drop(object sender, DragEventArgs e)
        {
            if (!e.Handled && e.Data.GetDataPresent(DataFormats.FileDrop, true))
            {
                // Note that you can have more than one file.
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

                // simply pass over to upper layer to decide, how to finally handle
                e.Handled = true;
                FileDrop?.Invoke(null, null, files);
            }
        }
예제 #3
0
        private void WireUpEvents()
        {
            tree.MouseDoubleClick += (s, e) =>
            {
                ContextNode = tree.GetNodeAt(e.X, e.Y) as TestSuiteTreeNode;
                if (ContextNode.TestType == "TestCase")
                {
                    Delegate eventDelegate = (Delegate)RunCommand.GetType().GetField("Execute", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(RunCommand);
                    eventDelegate.Method.Invoke(eventDelegate.Target, null);
                }
            };

            tree.MouseDown += (s, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    ContextNode = tree.GetNodeAt(e.X, e.Y) as TestSuiteTreeNode;
                }
            };

            tree.AfterSelect += (s, e) =>
            {
                if (_propertiesDialog != null)
                {
                    if (_propertiesDialog.Pinned)
                    {
                        _propertiesDialog.DisplayProperties((TestSuiteTreeNode)e.Node);
                    }
                    else
                    {
                        _propertiesDialog.Close();
                    }
                }
            };

            tree.DragDrop += (s, e) =>
            {
                if (IsValidFileDrop(e.Data))
                {
                    FileDrop?.Invoke((string[])e.Data.GetData(DataFormats.FileDrop));
                }
            };

            tree.DragEnter += (s, e) =>
            {
                e.Effect = IsValidFileDrop(e.Data)
                    ? DragDropEffects.Copy
                    : DragDropEffects.None;
            };

            treeMenu.Collapse += (s, e) => ContextNode = null;
        }
예제 #4
0
        private void RepoControl_Drop(object sender, DragEventArgs e)
        {
            // Appearantly you need to figure out if OriginalSource would have handled the Drop?
            if (!e.Handled && e.Data.GetDataPresent(DataFormats.FileDrop, true))
            {
                // Note that you can have more than one file.
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

                // simply pass over to upper layer to decide, how to finally handle
                e.Handled = true;
                FileDrop?.Invoke(FileRepository, files);
            }
        }
 private void PackageContainerListControl_FileDrop(
     Control senderList,
     PackageContainerListBase fr, string[] files)
 {
     FileDrop?.Invoke(senderList, fr, files);
 }
예제 #6
0
        public Window(string title, int width, int height)
        {
            _title = title;
            Width  = width;
            Height = height;

            glfw.WindowHint(WindowHintBool.Visible, false);

            pWindowHandle = glfw.CreateWindow(width, height, _title, (Monitor *)IntPtr.Zero.ToPointer(), null);

            Load?.Invoke();

            _onMove = (window, x, y) =>
            {
                Move?.Invoke((x, y));
            };

            _onResize = (window, width, height) =>
            {
                Resize?.Invoke((width, height));
            };

            _onFramebufferResize = (window, width, height) =>
            {
                FramebufferResize?.Invoke((width, height));
            };

            _onClosing = window => Closing?.Invoke();

            _onFocusChanged = (window, isFocused) => FocusChanged?.Invoke(isFocused);

            _onMinimized = (window, isMinimized) =>
            {
                WindowState state;
                // If minimized, we immediately know what value the new WindowState is.
                if (isMinimized)
                {
                    state = WindowState.Minimized;
                }
                else
                {
                    // Otherwise, we have to query a few things to figure out out.
                    if (glfw.GetWindowAttrib(pWindowHandle, WindowAttributeGetter.Maximized))
                    {
                        state = WindowState.Maximized;
                    }
                    else if (glfw.GetWindowMonitor(pWindowHandle) != null)
                    {
                        state = WindowState.Fullscreen;
                    }
                    else
                    {
                        state = WindowState.Normal;
                    }
                }

                StateChanged?.Invoke(state);
            };

            _onMaximized = (window, isMaximized) =>
            {
                // Same here as in onMinimized.
                WindowState state;
                if (isMaximized)
                {
                    state = WindowState.Maximized;
                }
                else
                {
                    if (glfw.GetWindowAttrib(pWindowHandle, WindowAttributeGetter.Iconified))
                    {
                        state = WindowState.Minimized;
                    }
                    else if (glfw.GetWindowMonitor(pWindowHandle) != null)
                    {
                        state = WindowState.Fullscreen;
                    }
                    else
                    {
                        state = WindowState.Normal;
                    }
                }

                StateChanged?.Invoke(state);
            };

            _onFileDrop = (window, count, paths) =>
            {
                var arrayOfPaths = new string[count];

                if (count == 0 || paths == IntPtr.Zero)
                {
                    return;
                }

                for (var i = 0; i < count; i++)
                {
                    var p = Marshal.ReadIntPtr(paths, i * IntPtr.Size);
                    arrayOfPaths[i] = Marshal.PtrToStringAnsi(p);
                }

                FileDrop?.Invoke(arrayOfPaths);
            };


            glfw.SetWindowPosCallback(pWindowHandle, _onMove);
            glfw.SetWindowSizeCallback(pWindowHandle, _onResize);
            glfw.SetWindowCloseCallback(pWindowHandle, _onClosing);
            glfw.SetWindowFocusCallback(pWindowHandle, _onFocusChanged);
            glfw.SetWindowIconifyCallback(pWindowHandle, _onMinimized);
            glfw.SetWindowMaximizeCallback(pWindowHandle, _onMaximized);
            glfw.SetFramebufferSizeCallback(pWindowHandle, _onFramebufferResize);
            glfw.SetDropCallback(pWindowHandle, _onFileDrop);
        }
예제 #7
0
        private void RegisterWindowCallbacks()
        {
            if (_callbackRegistered)
            {
                return;
            }
            _callbackRegistered = true;

            // [NOTE]
            // Do not register callback to GLFW as lambda or method. (That cannot work)
            // Put delegate on a field and register it to GLFW.

            _posCallback = (wnd, x, y) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                _location = new Vector2i(x, y);
                Move?.Invoke(this, new WindowPositionEventArgs(x, y));
            };
            GLFW.SetWindowPosCallback(_window, _posCallback);

            _sizeCallback = (wnd, width, height) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                GLFW.GetWindowFrameSize(_window, out var left, out var top, out var right, out var bottom);
                _clientSize = new Vector2i(width, height);
                _size       = new Vector2i(_clientSize.X + left + right, _clientSize.Y + top + bottom);
                Resize?.Invoke(this, new ResizeEventArgs(width, height));
            };
            GLFW.SetWindowSizeCallback(_window, _sizeCallback);

            _frameBufferSizeCallback = (wnd, width, height) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                _frameBufferSize = new Vector2i(width, height);
                FrameBufferSizeChanged?.Invoke(this, _frameBufferSize);
            };
            GLFW.SetFramebufferSizeCallback(_window, _frameBufferSizeCallback);

            _closeCallback = wnd =>
            {
                if (wnd != _window)
                {
                    return;
                }
                var cancel = false;
                var e      = new CancelEventArgs(&cancel);
                Closing?.Invoke(this, e);
                if (e.Cancel)
                {
                    GLFW.SetWindowShouldClose(_window, false);
                }
            };
            GLFW.SetWindowCloseCallback(_window, _closeCallback);


            _iconifyCallback = (wnd, minimized) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                Minimized?.Invoke(this, new MinimizedEventArgs(minimized));
            };
            GLFW.SetWindowIconifyCallback(_window, _iconifyCallback);

            _focusCallback = (wnd, focused) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                FocusedChanged?.Invoke(this, new FocusedChangedEventArgs(focused));
            };
            GLFW.SetWindowFocusCallback(_window, _focusCallback);

            _charCallback = (wnd, unicode) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                CharInput?.Invoke(this, new CharInputEventArgs(unicode));
            };
            GLFW.SetCharCallback(_window, _charCallback);

            _keyCallback = (wnd, glfwKey, scanCode, action, glfwMods) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                var e = new KeyboardKeyEventArgs(glfwKey, scanCode, glfwMods, action == GlfwInputAction.Repeat);

                if (action == GlfwInputAction.Release)
                {
                    KeyUp?.Invoke(this, e);
                }
                else
                {
                    KeyDown?.Invoke(this, e);
                }
            };
            GLFW.SetKeyCallback(_window, _keyCallback);

            _cursorEnterCallback = (wnd, entered) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                if (entered)
                {
                    MouseEnter?.Invoke(this);
                }
                else
                {
                    MouseLeave?.Invoke(this);
                }
            };
            GLFW.SetCursorEnterCallback(_window, _cursorEnterCallback);

            _mouseButtonCallback = (wnd, button, action, mods) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                var e = new MouseButtonEventArgs(button, action, mods);

                if (action == GlfwInputAction.Release)
                {
                    MouseUp?.Invoke(this, e);
                }
                else
                {
                    MouseDown?.Invoke(this, e);
                }
            };
            GLFW.SetMouseButtonCallback(_window, _mouseButtonCallback);

            _cursorPosCallback = (wnd, posX, posY) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                var e = new MouseMoveEventArgs(new Vector2((int)posX, (int)posY));
                MouseMove?.Invoke(this, e);
            };
            GLFW.SetCursorPosCallback(_window, _cursorPosCallback);

            _scrollCallback = (wnd, offsetX, offsetY) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                var e = new MouseWheelEventArgs((float)offsetX, (float)offsetY);
                MouseWheel?.Invoke(this, e);
            };
            GLFW.SetScrollCallback(_window, _scrollCallback);

            _dropCallback = (wnd, count, paths) =>
            {
                if (wnd != _window)
                {
                    return;
                }
                var e = new FileDropEventArgs(count, paths);
                FileDrop?.Invoke(this, e);
            };
            GLFW.SetDropCallback(_window, _dropCallback);

            _joystickCallback = (joystick, state) =>
            {
                var e = new JoystickConnectionEventArgs(joystick, state == GlfwConnectedState.Connected);
                JoystickConnectionChanged?.Invoke(this, e);
            };
            GLFW.SetJoystickCallback(_joystickCallback);

            _monitorCallback = (monitor, state) =>
            {
                var e = new MonitorConnectionEventArgs(monitor, state == GlfwConnectedState.Connected);
                MonitorConnectionChanged?.Invoke(this, e);
            };
            GLFW.SetMonitorCallback(_monitorCallback);

            _refreshCallback = wnd =>
            {
                if (wnd != _window)
                {
                    return;
                }
                Refresh?.Invoke(this);
            };
            GLFW.SetWindowRefreshCallback(_window, _refreshCallback);
        }