示例#1
0
            /// <summary>
            /// Adds a <see cref="Control"/> to the end of the <see cref="ControlCollection"/>.
            /// </summary>
            /// <param name="label">The text beside the child <see cref="Control"/>.</param>
            /// <param name="child">The <see cref="Control"/> to be added to the end of the <see cref="ControlCollection"/>.</param>
            /// <param name="stretches">Whether or not <paramref name="child"/> stretches the area of the parent <see cref="Control"/></param>
            public void Add(string label, Control child, bool stretches = false)
            {
                if (string.IsNullOrEmpty(label))
                {
                    throw new ArgumentNullException(nameof(label));
                }
                if (child == null)
                {
                    throw new ArgumentNullException(nameof(child));
                }
                if (child.IsInvalid)
                {
                    throw new InvalidHandleException();
                }
                if (Owner.IsInvalid)
                {
                    throw new InvalidHandleException();
                }
                if (Contains(child))
                {
                    throw new InvalidOperationException("Cannot add the same control more than once.");
                }
                if (child.TopLevel)
                {
                    throw new ArgumentException("Cannot add a top-level control to a ControlCollectionBase.");
                }

                Libui.Call <Libui.uiFormAppend>()(Owner.Handle, label, child.Handle, stretches);
                base.Add(child);
            }
示例#2
0
文件: Window.cs 项目: zhongzf/tcdfx
        /// <summary>
        /// Initializes this <see cref="Window"/> object's events.
        /// </summary>
        protected sealed override void InitializeEvents()
        {
            if (IsInvalid)
            {
                throw new InvalidHandleException();
            }

            Libui.Call <Libui.uiWindowOnClosing>()(Handle, (window, data) =>
            {
                CloseEventArgs e = new CloseEventArgs();
                OnClosing(this, e);
                if (e.Close)
                {
                    if (this != Application.MainWindow)
                    {
                        Close();
                    }
                    else
                    {
                        Application.Current.Shutdown();
                    }
                }
                return(e.Close);
            }, IntPtr.Zero);

            Libui.Call <Libui.uiWindowOnContentSizeChanged>()(Handle, (window, data) => OnSizeChanged(this, EventArgs.Empty), IntPtr.Zero);
        }
示例#3
0
 /// <summary>
 /// Performs prerendering operations.
 /// </summary>
 protected internal override void DelayRender()
 {
     if (!initialized && isMargined)
     {
         Libui.Call <Libui.uiTabSetMargined>()(Parent.Handle, Index, isMargined);
     }
 }
示例#4
0
文件: Surface.cs 项目: zhongzf/tcdfx
        private static SafeControlHandle GetHandle(SurfaceHandler handler, bool scrollable, int width, int height, out Libui.uiAreaHandler outHandler)
        {
            outHandler = new Libui.uiAreaHandler
            {
                Draw = (nativeHandler, surface, args) =>
                {
                    DrawEventArgs e = new DrawEventArgs(args);
                    handler.Draw(surfaceCache[surface], ref e);
                },
                MouseEvent = (nativeHandler, surface, args) =>
                {
                    MouseEventArgs e = new MouseEventArgs(args);
                    handler.MouseEvent(surfaceCache[surface], ref e);
                },
                MouseCrossed = (nativeHandler, surface, left) =>
                {
                    handler.MouseCrossed(surfaceCache[surface], left);
                },
                DragBroken = (nativeHandler, surface) => handler.DragBroken(surfaceCache[surface]),
                KeyEvent   = (nativeHandler, surface, args) =>
                {
                    KeyEventArgs e = new KeyEventArgs(args);
                    return(handler.KeyEvent(surfaceCache[surface], ref e));
                }
            };

            return(!scrollable
                ? new SafeControlHandle(Libui.Call <Libui.uiNewArea>()(outHandler))
                : new SafeControlHandle(Libui.Call <Libui.uiNewScrollingArea>()(outHandler, width, height)));
        }
示例#5
0
            /// <summary>
            /// Adds a <see cref="CheckableMenuItem"/> to the end of the <see cref="MenuItemCollection"/>.
            /// </summary>
            /// <param name="name">The name of the <see cref="Control"/> to be added to the end of the <see cref="MenuItemCollection"/>.</param>
            /// <param name="click">The action invoked when the child is clicked.</param>
            public void AddCheckable(string name, Action <IntPtr> click = null)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentNullException(nameof(name));
                }
                if (Owner.IsInvalid)
                {
                    throw new InvalidHandleException();
                }

                CheckableMenuItem item = new CheckableMenuItem(new SafeControlHandle(Libui.Call <Libui.uiMenuAppendCheckItem>()(Owner.Handle, name)), name);

                if (click != null)
                {
                    item.Clicked += (data) =>
                    {
                        if (data != null)
                        {
                            click(data);
                        }
                    };
                }
                base.Add(item);
            }
示例#6
0
 /// <summary>
 /// Adds a drop-down item to this <see cref="EditableComboBox"/>.
 /// </summary>
 /// <param name="item">The item to add to this control.</param>
 public void Add(string item)
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiEditableComboboxAppend>()(Handle, item);
 }
示例#7
0
 /// <summary>
 /// Initializes this <see cref="CheckBox"/> object's events.
 /// </summary>
 protected sealed override void InitializeEvents()
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiCheckboxOnToggled>()(Handle, (checkbox, data) => OnToggled(this, EventArgs.Empty), IntPtr.Zero);
 }
示例#8
0
 /// <summary>
 /// Initializes this <see cref="DateTimePicker"/> object's events.
 /// </summary>
 protected sealed override void InitializeEvents()
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiDateTimePickerOnChanged>()(Handle, (d, data) => OnDateTimeChanged(this, EventArgs.Empty), IntPtr.Zero);
 }
示例#9
0
文件: Surface.cs 项目: zhongzf/tcdfx
 public void BeginUserWindowResize(WindowEdge edge)
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiAreaBeginUserWindowResize>()(Handle, (Libui.uiWindowResizeEdge)edge);
 }
示例#10
0
文件: Surface.cs 项目: zhongzf/tcdfx
 public void BeginUserWindowMove()
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiAreaBeginUserWindowMove>()(Handle);
 }
示例#11
0
文件: Surface.cs 项目: zhongzf/tcdfx
 /// <summary>
 /// Scrolls the surface view to the specified location and size.
 /// </summary>
 /// <param name="x">The x-coordinate of the view.</param>
 /// <param name="y">The y-coordinate of the view.</param>
 /// <param name="width">The width of the view.</param>
 /// <param name="height">The height of the view.</param>
 public void ScrollTo(double x, double y, double width, double height)
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiAreaScrollTo>()(Handle, x, y, width, height);
 }
示例#12
0
 /// <summary>
 /// Adds a separator to the end of the <see cref="MenuItemCollection"/>.
 /// </summary>
 public void AddSeparator()
 {
     if (Owner.IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiMenuAppendSeparator>()(Owner.Handle);
 }
示例#13
0
 /// <summary>
 /// Initializes this <see cref="EditableComboBox"/> object's events.
 /// </summary>
 protected sealed override void InitializeEvents()
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiEditableComboboxOnChanged>()(Handle, (box, data) => OnTextChanged(this, EventArgs.Empty), IntPtr.Zero);
 }
示例#14
0
 /// <summary>
 /// Performs tasks associated with releasing unmanaged resources.
 /// </summary>
 protected override void ReleaseUnmanagedResources()
 {
     if (!IsInvalid)
     {
         Libui.Call <Libui.uiUnInit>()();
     }
     base.ReleaseUnmanagedResources();
 }
示例#15
0
 /// <summary>
 /// Initializes this <see cref="RadioButtonList"/> object's events.
 /// </summary>
 protected sealed override void InitializeEvents()
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiRadioButtonsOnSelected>()(Handle, (btn, data) => OnSelectedIndexChanged(this, EventArgs.Empty), IntPtr.Zero);
 }
示例#16
0
文件: SpinBox.cs 项目: zhongzf/tcdfx
 /// <summary>
 /// Initializes this <see cref="SpinBox"/> object's events.
 /// </summary>
 protected sealed override void InitializeEvents()
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiSpinboxOnChanged>()(Handle, (slider, data) => OnValueChanged(this, EventArgs.Empty), IntPtr.Zero);
 }
示例#17
0
文件: Button.cs 项目: zhongzf/tcdfx
 /// <summary>
 /// Initializes this <see cref="Button"/> object's events.
 /// </summary>
 protected sealed override void InitializeEvents()
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiButtonOnClicked>()(Handle, (button, data) => OnClick(this, EventArgs.Empty), IntPtr.Zero);
 }
示例#18
0
 /// <summary>
 /// Initializes this <see cref="TextBlockBase"/> object's events.
 /// </summary>
 protected override void InitializeEvents()
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiMultilineEntryOnChanged>()(Handle, (entry, data) => OnTextChanged(this, EventArgs.Empty), IntPtr.Zero);
 }
示例#19
0
 /// <summary>
 /// Adds a radio button to the end of the list.
 /// </summary>
 /// <param name="item">The text of the radio button to be added to the end of the list.</param>
 public void Add(string item)
 {
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiRadioButtonsAppend>()(Handle, item);
 }
示例#20
0
 /// <summary>
 /// Removes the first occurrence of a specific <see cref="Control"/> from the <see cref="ControlCollection"/>.
 /// </summary>
 /// <param name="child">The <see cref="Control"/> to remove from the <see cref="ControlCollection"/>.</param>
 /// <returns>true if child is successfully removed; otherwise, false. This method also returns false if child was not found in the <see cref="ControlCollection"/>.</returns>
 public new bool Remove(Control child)
 {
     if (base.Remove(child))
     {
         Libui.Call <Libui.uiBoxDelete>()(Owner.Handle, child.Index);
         return(true);
     }
     return(false);
 }
示例#21
0
文件: Surface.cs 项目: zhongzf/tcdfx
 /// <summary>
 /// Queues a redraw of the surface.
 /// </summary>
 public void QueueRedrawAll()
 {
     Thread.Sleep(200); // Must sleep for 200ms or else crashes
     if (IsInvalid)
     {
         throw new InvalidHandleException();
     }
     Libui.Call <Libui.uiAreaQueueRedrawAll>()(Handle);
 }
示例#22
0
 protected sealed override void ReleaseUnmanagedResources()
 {
     if (Font != null)
     {
         Libui.Call <Libui.uiFreeFontButtonFont>()(uiFontDescriptor);
         uiFontDescriptor = new Libui.uiFontDescriptor();
     }
     base.ReleaseUnmanagedResources();
 }
示例#23
0
 /// <summary>
 /// Removes the first occurrence of a specific <see cref="TabPage"/> from the <see cref="TabPageCollection"/>.
 /// </summary>
 /// <param name="child">The <see cref="TabPage"/> to remove from the <see cref="TabPageCollection"/>.</param>
 /// <returns>true if child is successfully removed; otherwise, false. This method also returns false if child was not found in the <see cref="TabPageCollection"/>.</returns>
 public new bool Remove(TabPage child)
 {
     if (base.Remove(child))
     {
         Libui.Call <Libui.uiTabDelete>()(Owner.Handle, child.Index);
         return(true);
     }
     return(false);
 }
示例#24
0
            /// <summary>
            /// Adds a <see cref="QuitMenuItem"/> to the end of the <see cref="MenuItemCollection"/>.
            /// </summary>
            public void AddQuit()
            {
                if (Owner.IsInvalid)
                {
                    throw new InvalidHandleException();
                }
                QuitMenuItem item = new QuitMenuItem(new SafeControlHandle(Libui.Call <Libui.uiMenuAppendQuitItem>()(Owner.Handle)));

                base.Add(item);
            }
示例#25
0
 /// <summary>
 /// Queues the specified action to run when possible on the UI thread.
 /// </summary>
 /// <param name="action">The <see cref="Action"/> to run.</param>
 public static void QueueMain(Action action)
 {
     queue.Enqueue(action);
     Libui.Call <Libui.uiQueueMain>()(data =>
     {
         lock (sync)
         {
             queue.Dequeue().Invoke();
         }
     }, new IntPtr(queue.Count));
 }
示例#26
0
        /// <summary>
        /// Initializes this <see cref="Application"/>.
        /// </summary>
        protected override void InitializeComponent()
        {
            string error = Libui.Call <Libui.uiInit>()(ref options);

            if (!string.IsNullOrEmpty(error))
            {
                Console.WriteLine(error);
                Libui.Call <Libui.uiFreeInitError>()(error);
                throw new ApplicationInitializationException(error);
            }
        }
示例#27
0
 private int Run(Action action)
 {
     try
     {
         QueueMain(action);
         Libui.Call <Libui.uiMain>()();
     }
     catch (Exception)
     {
         return(-1);
     }
     return(0);
 }
示例#28
0
文件: Window.cs 项目: zhongzf/tcdfx
        /// <summary>
        /// Displays a dialog allowing a user to select a file to open.
        /// </summary>
        /// <param name="path">The file's path selected by the user.</param>
        /// <param name="w">The dialog's parent window.</param>
        /// <returns><see langword="true"/> if the file exists, else <see langword="false"/>.</returns>
        public static bool ShowOpenFileDialog(Window w, out string path)
        {
            if (w == null)
            {
                w = Application.MainWindow;
            }
            if (w.IsInvalid)
            {
                throw new InvalidHandleException();
            }

            path = Libui.Call <Libui.uiOpenFile>()(w.Handle);
            return(string.IsNullOrEmpty(path) ? false : true);
        }
示例#29
0
        /// <summary>
        /// Executes the code required to free the handle.
        /// </summary>
        /// <returns><see langword="true"/> if the handle is released successfully; otherwise, in the event of a catastrophic failure, <see langword="false"/>.</returns>
        protected override bool ReleaseHandle()
        {
            bool released;

            try
            {
                Libui.Call <Libui.uiControlDestroy>()(this);
                handle   = IntPtr.Zero;
                released = true;
            }
            catch
            {
                released = false;
            }
            return(released);
        }
示例#30
0
        /// <summary>
        /// Executes the code required to free the handle.
        /// </summary>
        /// <returns><see langword="true"/> if the handle is released successfully; otherwise, in the event of a catastrophic failure, <see langword="false"/>.</returns>
        protected override bool ReleaseHandle()
        {
            bool released;

            try
            {
                Libui.Call <Libui.uiFreeAttribute>()(handle);
                handle   = IntPtr.Zero;
                released = true;
            }
            catch
            {
                released = false;
            }
            return(released);
        }