Beispiel #1
0
        /*public override void Remove()
         * {
         *  foreach (WindowObject obj in m_children.List)
         *      if (obj is NativeButtonObject) // TODO: remove all!
         *          obj.Remove();
         *
         *  base.Remove();
         * }*/

        public static bool FindChildren(IWindowContainer container, Func <WindowObject, bool> checker, IList <WindowObject> result, bool one = false)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            foreach (WindowObject obj in container.Children)
            {
                if (!obj.Visible)
                {
                    continue;
                }

                if (checker(obj))
                {
                    result.Add(obj);
                    if (one)
                    {
                        return(true);
                    }
                }

                if (obj is IWindowContainer)
                {
                    if (FindChildren((IWindowContainer)obj, checker, result, one))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        protected override void OnAttached()
        {
            base.OnAttached();

            this.AssociatedObject.Loaded += delegate
            {
                IWindowContainer container = AssociatedObject.DataContext as IWindowContainer;
                if (container != null)
                {
                    container.ShowWindow += (sender, args) =>
                    {
                        var window = new DialogChildWindow {
                            DataContext = args.Context
                        };
                        window.Owner = this.AssociatedObject;

                        window.Loaded += (o, eventArgs) => Application.Current.Dispatcher.BeginInvoke(new Action(() => window.SetWindowCloseStatus(false)));

                        if (args.IsDialog)
                        {
                            window.ShowDialog();
                        }
                        else
                        {
                            window.Show();
                        }
                    }
                }
                ;
            };
        }
    }
Beispiel #3
0
 public void Init(IOutput logObj, IWindowContainer windowContainer)
 {
     //string configPath = System.Reflection.Assembly.GetExecutingAssembly().Location.ToString() + ".config";
     //ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap()
     //{
     //    ExeConfigFilename = configPath
     //}, ConfigurationUserLevel.None);
 }
Beispiel #4
0
        internal static void UpdateFocus(IFocusableWidget widget, bool focus)
        {
            IWindowContainer window = ((WindowObject)widget).Window;

            if (window == null)
            {
                return; // no window, no crime
            }
            int windowHash = window.GetHashCode();

            IFocusableWidget focusedWidget;

            s_focusedWidgets.TryGetValue(windowHash, out focusedWidget);

            // Nomad: PVS analyzer indicated some amount of fuzzy logic here.
            // I think that whole focusing and unfocusing logic should be refactored

            if (widget == focusedWidget)
            {
                if (!focus && focusedWidget != null)
                {
                    focusedWidget.SetFocused(false);
                    s_focusedWidgets.Remove(windowHash);
                    WindowController.Instance.ShowKeyboard(false);
                }

                return;
            }

            if (focusedWidget != null)
            {
                IFocusableWidget oldWidget = focusedWidget;
                s_focusedWidgets.Remove(windowHash);
                oldWidget.SetFocused(false);
            }

            focusedWidget = widget;

            WindowController.Instance.ShowKeyboard(focus && (focusedWidget is WidgetTextEdit || focusedWidget is WidgetTextField));

            if (focusedWidget == null)
            {
                s_focusedWidgets.Remove(windowHash);
            }
            else
            {
                if (focus)
                {
                    focusedWidget.SetFocused(true);
                }
                s_focusedWidgets[windowHash] = focusedWidget;
            }
        }
Beispiel #5
0
        public void BringToFront()
        {
            IWindowContainer windowParent = this.Parent as IWindowContainer;

            if (windowParent != null)
            {
                int max = windowParent.MaximumZIndex;
                if (max == 0 || this.ZIndex != max)
                {
                    this.ZIndex = max + 1;
                }
            }
        }
        internal static void UpdateFocus(IFocusableWidget widget, bool focus)
        {
            IWindowContainer window = ((WindowObject)widget).Window;

            if (window == null)
            {
                return; // no window, no crime
            }
            int windowHash = window.GetHashCode();

            IFocusableWidget focusedWidget = null;

            s_focusedWidgets.TryGetValue(windowHash, out focusedWidget);

            if (!focus)
            {
                if (widget == focusedWidget)
                {
                    s_focusedWidgets.Remove(windowHash);
                }
                return;
            }

            if (focus && widget == focusedWidget)
            {
                return;
            }

            if (focusedWidget != null && focus)
            {
                IFocusableWidget oldWidget = focusedWidget;
                s_focusedWidgets.Remove(windowHash);
                oldWidget.SetFocused(false);
            }

            if (focus)
            {
                focusedWidget = widget;
                focusedWidget.SetFocused(true);
            }

            if (focusedWidget == null)
            {
                s_focusedWidgets.Remove(windowHash);
            }
            else
            {
                s_focusedWidgets[windowHash] = focusedWidget;
            }
        }
        public static bool HasFocus(IWindowContainer window)
        {
            if (window == null)
            {
                return(false); // no window, no crime
            }
            int windowHash = window.GetHashCode();

            IFocusableWidget focusedWidget = null;

            if (s_focusedWidgets.TryGetValue(windowHash, out focusedWidget))
            {
                return(focusedWidget != null);
            }

            return(false);
        }
Beispiel #8
0
        public GraphicsDevice(IGameWindow window, IWindowContainer container, GraphicsContext context, DeviceCreationFlags creationFlags)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (context.IsDisposed)
            {
                throw new ArgumentException("context is disposed.", "context");
            }

            this.DefaultWindow = window;
            this.container     = container;
            this.Context       = context;
            this.CreationFlags = creationFlags;

            Log.Debug("Got context: [ColorFormat: {0}, Depth: {1}, Stencil: {2}, FSAA Samples: {3}, AccumulatorFormat: {4}, Buffers: {5}, Stereo: {6}]",
                      Context.GraphicsMode.ColorFormat,
                      Context.GraphicsMode.Depth,
                      Context.GraphicsMode.Stencil,
                      Context.GraphicsMode.Samples,
                      Context.GraphicsMode.AccumulatorFormat,
                      Context.GraphicsMode.Buffers,
                      Context.GraphicsMode.Stereo);

            Context.LoadAll();

            capabilities = new GraphicsCapabilities();

            CheckGraphicsCapabilities(LogLevel.Verbose);

            Factory            = new GraphicsFactory(this);
            BindManager        = new OpenGL4.BindManager(this);
            this.RenderContext = new RenderContext(this);

            Context.MakeCurrent(null);
        }
Beispiel #9
0
        public static void RemoveFocus(IWindowContainer window)
        {
            int windowHash = window.GetHashCode();

            List <WindowObject> focusables = new List <WindowObject>();

            Window.FindChildren(window, (WindowObject arg) => arg is IFocusableWidget, focusables);

            for (int i = 0; i < focusables.Count; i++)
            {
                if (((IFocusableWidget)focusables[i]).IsFocusable)
                {
                    ((IFocusableWidget)focusables[i]).SetFocused(false);
                }
            }

            s_focusedWidgets.Remove(windowHash);
            WindowController.Instance.ShowKeyboard(false);
        }
        internal static bool FocusNext(IFocusableWidget widget)
        {
            WindowObject obj = widget as WindowObject;

            if (obj == null)
            {
                throw new ArgumentException(nameof(widget) + " is not a WindowObject!");
            }

            IWindowContainer window = obj.Window;

            if (window == null)
            {
                return(false);
            }

            List <WindowObject> focusables = new List <WindowObject>();

            Window.FindChildren(window, (WindowObject arg) => arg is IFocusableWidget, focusables);

            WindowObject nextFocusable = null;

            for (int i = 0; i < focusables.Count; i++)
            {
                if (focusables[i] == widget)
                {
                    nextFocusable = focusables[(i + 1) % focusables.Count];
                    break;
                }
            }

            if (nextFocusable == null || nextFocusable == widget)
            {
                return(false); // do nothing
            }
            UpdateFocus((IFocusableWidget)nextFocusable, true);

            return(true);
        }
Beispiel #11
0
        /// <summary>
        /// 初始化
        /// </summary>
        public static void Init(IOutput logObj, IWindowContainer windowContainer)
        {
            var dal        = new ModuleInfoDAL();
            var moduleList = dal.FindAll();

            foreach (var item in moduleList)
            {
                try
                {
                    if (item.ModuleType == ModuleTypeEnum.DllModule)
                    {
                        LoadDllModule(item, logObj, windowContainer);
                    }
                    else if (item.ModuleType == ModuleTypeEnum.ExeModule)
                    {
                        LoadExeModule(item, item.GroupTitle, logObj, windowContainer);
                    }
                }
                catch (Exception e1)
                {
                    logObj.PrintLine($"模块加载出错 ModuleName:{item.Name} ModulePath:{item.ModulePath} Message:{e1.Message}");
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// 加载可执行程序
        /// </summary>
        /// <param name="moduleInfo">模块对象</param>
        /// <param name="logObj">日志对象</param>
        /// <param name="windowContainer">容器对象</param>
        /// <returns></returns>
        private static List <FormInfo> LoadExeModule(ModuleInfo moduleInfo, String groupName, IOutput logObj, IWindowContainer windowContainer)
        {
            var result = new List <FormInfo>();

            result.Add(new FormInfo()
            {
                AssemblyInfo = null, AttributeInfo = new FormAttribute(groupName, moduleInfo.Name), ModuleInfo = moduleInfo
            });

            // 添加到程序集中
            lock (lockObj)
            {
                moduleInfos.Add(new AssemblyInfo()
                {
                    AssemblyObj  = null,
                    FormInfoList = result,
                    ModuleInfo   = moduleInfo,
                });
            }

            return(result);
        }
Beispiel #13
0
        /// <summary>
        /// 注册一个新模块
        /// </summary>
        /// <param name="name">模块名</param>
        /// <param name="filePath">需要注册的文件名</param>
        /// <param name="description">描述信息</param>
        /// <param name="moduleType">模块类型</param>
        /// <param name="groupTitle">组名</param>
        /// <param name="logObj">日志对象</param>
        /// <param name="windowContainer">窗口容器</param>
        /// <returns></returns>
        public static List <FormInfo> RegisterExe(String name, String filePath, String description, ModuleTypeEnum moduleType, String groupTitle, IOutput logObj, IWindowContainer windowContainer)
        {
            try
            {
                if (ExistName(name))
                {
                    throw new Exception($"存在重复的模块名:{name}");
                }

                if (ExistPath(filePath))
                {
                    throw new Exception($"存在重复的模块加载:{filePath}");
                }

                var moduleInfo = new ModuleInfo()
                {
                    Name = name, ModulePath = filePath, ModuleType = moduleType, Description = description, GroupTitle = groupTitle
                };
                var result = LoadExeModule(moduleInfo, groupTitle, logObj, windowContainer);

                // 添加到数据库
                var dal = new ModuleInfoDAL();
                dal.Insert(moduleInfo);

                return(result);
            }
            catch (Exception e1)
            {
                throw e1;
            }
        }
Beispiel #14
0
        /// <summary>
        /// 加载一个模块
        /// </summary>
        /// <param name="moduleInfo">模块信息</param>
        /// <returns></returns>
        private static List <FormInfo> LoadDllModule(ModuleInfo moduleInfo, IOutput logObj, IWindowContainer windowContainer)
        {
            var result = new List <FormInfo>();

            // 寻找模块中的所有窗口和模块初始化类型
            var  moduleInterfaceType = typeof(IModule);
            Type moduleInitType      = null;
            var  assemblyObj         = Assembly.LoadFrom(moduleInfo.ModulePath);

            foreach (var typeItem in assemblyObj.ExportedTypes)
            {
                // 找到所有的窗口
                var attrItem = typeItem.GetCustomAttribute <FormAttribute>();
                if (attrItem != null)
                {
                    result.Add(new FormInfo()
                    {
                        AttributeInfo = attrItem, FormType = typeItem, ModuleInfo = moduleInfo
                    });
                }

                // 寻找模块初始化类
                if (moduleInitType == null)
                {
                    var tmpBaseModule = typeItem.FindInterfaces((tmp, a) => tmp == moduleInterfaceType, null);
                    if (tmpBaseModule != null && tmpBaseModule.Length > 0)
                    {
                        moduleInitType = typeItem;
                    }
                }
            }

            if (moduleInitType == null && result.Count <= 0)
            {
                throw new Exception("这不是一个有效的插件:没有IModule的实现,也没有任何窗口");
            }

            // 调用初始化函数
            if (moduleInitType != null)
            {
                var initObj = (IModule)Activator.CreateInstance(moduleInitType);
                initObj.Init(logObj, windowContainer);
            }

            // 添加到程序集中
            lock (lockObj)
            {
                moduleInfos.Add(new AssemblyInfo()
                {
                    AssemblyObj  = assemblyObj,
                    FormInfoList = new List <FormInfo>(result),
                    ModuleInfo   = moduleInfo,
                });
            }

            return(result);
        }