public NativeStructs.WINDOWPLACEMENT? Load(Window rpWindow)
        {
            var rPlacement = Preference.Instance.Windows.LoadPlacement(rpWindow.GetType().FullName);
            if (rPlacement == null)
                return null;

            var rResult = new NativeStructs.WINDOWPLACEMENT()
            {
                rcNormalPosition = new NativeStructs.RECT(rPlacement.Left, rPlacement.Top, rPlacement.Left+rPlacement.Width,rPlacement.Top+rPlacement.Height),
            };

            switch (rPlacement.State)
            {
                case WindowState.Normal:
                    rResult.showCmd = NativeConstants.ShowCommand.SW_SHOWNORMAL;
                    break;

                case WindowState.Minimized:
                    rResult.showCmd = NativeConstants.ShowCommand.SW_SHOWMINIMIZED;
                    break;

                case WindowState.Maximized:
                    rResult.showCmd = NativeConstants.ShowCommand.SW_SHOWMAXIMIZED;
                    break;
            }

            return rResult;
        }
 private static void PickleWindow(Window window, Dictionary<string, object> data)
 {
     foreach (var propName in new[] { "Top", "Left", "Width", "Height", "WindowState" })
     {
         data[propName] = window.GetType().GetProperty(propName).GetGetMethod().Invoke(window, new object[] { });
     }
 }
 public WindowSettings(Window window, bool isSavingPosition, bool isSavingSize, string keyExtensionValue)
 {
     _window = window;
     _isSavingPosition = isSavingPosition;
     _isSavingSize = isSavingSize;
     // Use the class-name of the given Window, minus the namespace prefix, as the instance-key.
     // This is so that we have a distinct setting for different windows.
     string sWindowType = window.GetType().ToString();
     int iPos = sWindowType.LastIndexOf('.');
     string sKey;
     if (iPos > 0)
     {
         sKey = sWindowType.Substring(iPos + 1);
     }
     else
     {
         sKey = sWindowType;
     }
     if (keyExtensionValue == null)
     {
         _sInstanceSettingsKey = sKey;
     }
     else
     {
         _sInstanceSettingsKey = sKey + keyExtensionValue;
     }
 }
Example #4
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="mWindow"></param>
 public Service(System.Windows.Window mWindow)
 {
     if (mWindow.GetType() == typeof(MainWindow))
     {
         WinMainWindow = (MainWindow)mWindow;
     }
     updatePbDelegate = new UpdateProgressBarDelegate(WinMainWindow.pb1.SetValue);
 }
        public MoveCommandBindingProxy(Window window)
        {
            this.window = window;
            MoveCommand = new RoutedCommand("Move", window.GetType());

            _CommandBinding = new CommandBinding(MoveCommand,
                CommandExecuted,
                CommandCanExecute);
        }
Example #6
0
 public Service(System.Windows.Window mWindow)
 {
     modelDB = new Model1();
     modelDB.Employee.Load();
     modelDB.Department.Load();
     if (mWindow.GetType() == typeof(MainWindow))
     {
         WinMainWindow = (MainWindow)mWindow;
     }
 }
        private static void InitWindow(Window window, Dictionary<string, object> data)
        {
            foreach (var property in data)
            {
                window.GetType().GetProperty(property.Key).GetSetMethod().Invoke(window, new[] { property.Value });
            }

            if (!Double.IsNaN(window.Top))
                window.WindowStartupLocation = WindowStartupLocation.Manual;
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="mWindow"></param>
 /// <param name="adapterEmp"></param>
 /// <param name="dtEmp"></param>
 /// <param name="adapterDep"></param>
 /// <param name="dtDep"></param>
 public Service(System.Windows.Window mWindow, SqlDataAdapter adapterEmp, DataTable dtEmp, SqlDataAdapter adapterDep, DataTable dtDep)
 {
     if (mWindow.GetType() == typeof(MainWindow))
     {
         WinMainWindow = (MainWindow)mWindow;
     }
     dtE      = dtEmp;
     dtD      = dtDep;
     adapterE = adapterEmp;
     adapterD = adapterDep;
 }
        public WindowTreeManager(Window window, WindowTreeManager parent, bool autoClosing = true)
        {
            Parent = parent;
            _window = window;
            _autoClosing = autoClosing;

            var windowName = window.GetType().Name;
            _windowBoundsPersistor = new Settings.WindowBoundsPersistor(window, windowName);
            _windowBoundsPersistor.Load();

            window.Closing += SelfClosing;
        }
        public void Save(Window rpWindow, NativeStructs.WINDOWPLACEMENT rpData)
        {
            var rPreference = new WindowPreference()
            {
                Name = rpWindow.GetType().FullName,
                Left = rpData.rcNormalPosition.Left,
                Top = rpData.rcNormalPosition.Top,
                Width = rpData.rcNormalPosition.Right - rpData.rcNormalPosition.Left,
                Height = rpData.rcNormalPosition.Bottom - rpData.rcNormalPosition.Top,
                State = rpWindow.WindowState,
            };

            Preference.Current.Windows.Landscape[rPreference.Name] = rPreference;
        }
Example #11
0
		public static void OuvrirEcran(Window parent,string nom,bool modal,bool fermeParent)
        {
            Type type = parent.GetType();
            Assembly assembly = type.Assembly;
            Window win = (Window)assembly.CreateInstance(type.Namespace + "." + nom);

            if (fermeParent)
                parent.Close();

            if (modal)
                win.ShowDialog();
            else
                win.Show();

        }
        /// <summary>
        ///     Opens a window and returns without waiting for the newly opened window to close.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <param name="owner">The owner.</param>
        /// <param name="singleton">if set to <c>true</c> only once instance of the window will be shown.</param>
        public static void Show(this Window window, IntPtr owner, bool singleton)
        {
            if (singleton)
            {
                if (!Windows.ContainsKey(window.GetType().Name))
                {
                    window.Show(owner);
                    window.Closed += (sender, args) =>
                    {
                        Windows.Remove(window.GetType().Name);
                    };

                    Windows.Add(window.GetType().Name, window);
                }
                else
                {
                    Windows[window.GetType().Name].Show(owner);
                }
            }
            else
            {
                window.Show(owner);
            }
        }
        public void Save(Window rpWindow, NativeStructs.WINDOWPLACEMENT rpData)
        {
            var rPreference = new WindowPreference()
            {
                Name = rpWindow.GetType().FullName,

                Left = rpData.rcNormalPosition.Left,
                Top = rpData.rcNormalPosition.Top,
                Width = rpData.rcNormalPosition.Right - rpData.rcNormalPosition.Left,
                Height = rpData.rcNormalPosition.Bottom - rpData.rcNormalPosition.Top,
                State = rpWindow.WindowState,
            };

            Preference.Instance.Windows.SavePlacement(rPreference);
        }
        public void ManageWindowSettings(Window window)
        {
            string typeName = window.GetType().Name;

            window.Initialized += (sender, e) =>
            {
                WindowSettings settings = this.Settings.WindowsSettings.Where(w => w.Name == typeName).FirstOrDefault();
                if (settings != null)
                {
                    window.Left = settings.X;
                    window.Top = settings.Y;
                    window.Width = settings.Width;
                    window.Height = settings.Height;
                    window.WindowState = settings.State;
                    window.WindowStartupLocation = WindowStartupLocation.Manual;
                }
            };

            window.Closing += WindowClosing;
        }
Example #15
0
 public static void SavePreferences(Window win)
 {
     WindowPreference wp = new WindowPreference();
     wp.Width = win.Width;
     wp.Height = win.Height;
     wp.Top = win.Top;
     wp.Left = win.Left;
     preferences[win.GetType().Name] = wp;
 }
Example #16
0
        /// <summary>
        /// Sets the owner window of a specific window. It will first try to set the owner via
        /// the <paramref name="ownerWindow"/>. If the <paramref name="ownerWindow"/> is not available,
        /// this method will use the <paramref name="ownerHandle"/> to set the parent.
        /// </summary>
        /// <param name="window">Reference to the current window.</param>
        /// <param name="ownerWindow">New owner window.</param>
        /// <param name="ownerHandle">The owner handle.</param>
        /// <param name="forceNewOwner">If true, the new owner will be forced. Otherwise, if the
        /// window currently has an owner, that owner will be respected (and thus not changed).</param>
        /// <param name="focusFirstControl">If true, the first control will automatically be focused.</param>
        private static void SetOwnerWindow(SystemWindow window, SystemWindow ownerWindow, IntPtr ownerHandle, bool forceNewOwner, bool focusFirstControl)
        {
            if (focusFirstControl)
            {
                window.FocusFirstControl();
            }

            if (!forceNewOwner && HasOwner(window))
            {
                return;
            }

            try
            {
                if (ownerWindow != null)
                {
                    if (ReferenceEquals(ownerWindow, window))
                    {
                        Log.Warning("Cannot set owner window to itself, no owner window set");
                        return;
                    }

                    if (window.Dispatcher.GetThreadId() != ownerWindow.Dispatcher.GetThreadId())
                    {
                        Log.Warning("The owner window '{0}' is not created on the same thread as the current window '{1}', cannot set owner window",
                                    ownerWindow.GetType().GetSafeFullName(false), window.GetType().GetSafeFullName(false));
                        return;
                    }

                    window.Owner = ownerWindow;
                }
                else
                {
                    // Set owner via interop helper
                    var interopHelper = new WindowInteropHelper(window);
                    interopHelper.Owner = ownerHandle;

                    // Get handler (so we can nicely unsubscribe)
                    RoutedEventHandler onWindowLoaded = null;
                    onWindowLoaded = delegate(object sender, RoutedEventArgs e)
                    {
                        // Since this owner type doesn't support WindowStartupLocation.CenterOwner, do
                        // it manually
                        if (window.WindowStartupLocation == WindowStartupLocation.CenterOwner)
                        {
                            // Get the parent window rect
                            RECT ownerRect;
                            if (GetWindowRect(ownerHandle, out ownerRect))
                            {
                                // Get some additional information
                                int ownerWidth            = ownerRect.Right - ownerRect.Left;
                                int ownerHeight           = ownerRect.Bottom - ownerRect.Top;
                                int ownerHorizontalCenter = (ownerWidth / 2) + ownerRect.Left;
                                int ownerVerticalCenter   = (ownerHeight / 2) + ownerRect.Top;

                                // Set the location to manual
                                window.WindowStartupLocation = WindowStartupLocation.Manual;

                                // Now we know the location of the parent, center the window
                                window.Left = ownerHorizontalCenter - (window.ActualWidth / 2);
                                window.Top  = ownerVerticalCenter - (window.ActualHeight / 2);
                            }
                        }

                        ((SystemWindow)sender).Loaded -= onWindowLoaded;
                    };

                    window.Loaded += onWindowLoaded;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to set the owner window");
            }
        }
 private bool WindowIsNotWorkbench(Window w)
 {
     return !w.GetType().Equals(typeof(WorkbenchWindow));
 }
        // Various dialogs perform a bulk edit, after which the current file's data needs to be refreshed.
        private async Task ShowBulkFileEditDialogAsync(Window dialog)
        {
            Debug.Assert((dialog.GetType() == typeof(PopulateFieldWithMetadata)) ||
                         (dialog.GetType() == typeof(DateTimeFixedCorrection)) ||
                         (dialog.GetType() == typeof(DateTimeLinearCorrection)) ||
                         (dialog.GetType() == typeof(DateDaylightSavingsTimeCorrection)) ||
                         (dialog.GetType() == typeof(DateCorrectAmbiguous)) ||
                         (dialog.GetType() == typeof(DateTimeSetTimeZone)) ||
                         (dialog.GetType() == typeof(DateTimeRereadFromFiles)),
                         String.Format("Unexpected dialog {0}.", dialog.GetType()));

            bool? result = dialog.ShowDialog();
            if (result == true)
            {
                // load the changes made through the current dialog
                long currentFileID = this.dataHandler.ImageCache.Current.ID;
                this.dataHandler.FileDatabase.SelectFiles(this.dataHandler.FileDatabase.ImageSet.FileSelection);

                // show updated data for file
                // Delete isn't considered a bulk edit so none of the bulk edit dialogs can result in a change in the image which needs to be displayed.
                // Hence the image cache doesn't need to be invalidated.  However, SelectFiles() may mean the currently displayed file is no longer selected.
                await this.ShowFileAsync(this.dataHandler.FileDatabase.GetFileOrNextFileIndex(currentFileID));
            }
        }
Example #19
0
 public static void LoadPreferences(Window win)
 {
     string name = win.GetType().Name;
     WindowPreference wp = preferences[name];
     win.Width = wp.Width;
     win.Height = wp.Height;
     win.Top = wp.Top;
     win.Left = wp.Left;
 }
Example #20
0
        internal int RunInternal(Window window)
        {
            VerifyAccess();

#if DEBUG_CLR_MEM
            if (CLRProfilerControl.ProcessIsUnderCLRProfiler &&
               (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance))
            {
                CLRProfilerControl.CLRLogWriteLine("Application_Run");
            }
#endif // DEBUG_CLR_MEM

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordGeneral | EventTrace.Keyword.KeywordPerf, EventTrace.Event.WClientAppRun);

            //
            // NOTE: hamidm 08/06/04
            // PS Windows OS Bug # 901085 (Can't create app and do run/shutdown followed
            // by run/shutdown)
            //
            // Devs could write the following code
            //
            // Application app = new Application();
            // app.Run();
            // app.Run();
            //
            // In this case, we should throw an exception when Run is called for the second time.
            // When app is shutdown, _appIsShutdown is set to true.  If it is true here, then we
            // throw an exception
            if (_appIsShutdown == true)
            {
                throw new InvalidOperationException(SR.Get(SRID.CannotCallRunMultipleTimes, this.GetType().FullName));
            }

            if (window != null)
            {
                if (window.CheckAccess() == false)
                {
                    throw new ArgumentException(SR.Get(SRID.WindowPassedShouldBeOnApplicationThread, window.GetType().FullName, this.GetType().FullName));
                }

                if (WindowsInternal.HasItem(window) == false)
                {
                    WindowsInternal.Add(window);
                }

                if (MainWindow == null)
                {
                    MainWindow = window;
                }

                if (window.Visibility != Visibility.Visible)
                {
                    Dispatcher.BeginInvoke(
                        DispatcherPriority.Send,
                        (DispatcherOperationCallback) delegate(object obj)
                        {
                            Window win = obj as Window;
                            win.Show();
                            return null;
                        },
                        window);
                }
            }

            EnsureHwndSource();

            //Even if the subclass app cancels the event we still want to create and run the dispatcher
            //so that when the app explicitly calls Shutdown, we have a dispatcher to service the posted
            //Shutdown DispatcherOperationCallback

            // Invoke the Dispatcher synchronously if we are not in the browser
            if (!BrowserInteropHelper.IsBrowserHosted)
            {
                RunDispatcher(null);
            }

            return _exitCode;
        }
 /// <summary>
 /// Sets/gets the active window for the tray manager.
 /// This will be expanded to multiple windows in the future
 /// </summary>
 public void addActiveWindow(Window value)
 {        
         if (!TrayFlags.containsType(value.GetType())) return;
         activeWindow.Add(value);
 }
Example #22
0
 public WindowApplicationSettings(Window window)
     : base(window.GetType().FullName)
 {
 }
Example #23
0
 public WindowSettings(Window window)
     : base(window.GetType().FullName)
 {
 }
Example #24
0
        public void ShowWindow(Window window)
        {
            var containsLayoutStores = window as IContainsLayoutStores;
            IList<ILayoutDataStore> layoutDataStores = new List<ILayoutDataStore>();

            if (containsLayoutStores != null)
                layoutDataStores = containsLayoutStores.GetLayoutStores();

            if (string.IsNullOrEmpty(window.Name))
            {
                var type = window.GetType();
                //???? ??????? ???????????, ? Name ?? ????? - ?? ??????????? ??? ????
                window.Name = type.Namespace.StartsWith("System.") ? null : type.Name;
            }

            if (string.IsNullOrEmpty(window.Name))
                throw new ArgumentException(Resources.ControlNameCanNotBeEmpty);

            var worker = new LayoutStoreWorker(layoutDataStorePathFactory, window.Name, layoutDataStores);
            LayoutStoreSupportUtils.Load(worker);
            window.Closing += (s, e) => LayoutStoreSupportUtils.Close(worker);

            window.Show();
        }
Example #25
0
 // ----------------------------------------------------------------------
 public WindowSettings(Window window) :
     this(window, window.GetType().Name)
 {
 } // WindowSettings
Example #26
0
        private Point ConfigureNewHostSizeAndGetDragStartWindowOffset(Window currentWindow, INewTabHost<Window> newTabHost, DragablzItem dragablzItem)
        {
            var layout = this.VisualTreeAncestory().OfType<Layout>().FirstOrDefault();
            Point dragStartWindowOffset;
            if (layout != null)
            {
                newTabHost.Container.Width = ActualWidth + Math.Max(0, currentWindow.RestoreBounds.Width - layout.ActualWidth);
                newTabHost.Container.Height = ActualHeight + Math.Max(0, currentWindow.RestoreBounds.Height - layout.ActualHeight);
                dragStartWindowOffset = dragablzItem.TranslatePoint(new Point(), this);
                //dragStartWindowOffset.Offset(currentWindow.RestoreBounds.Width - layout.ActualWidth, currentWindow.RestoreBounds.Height - layout.ActualHeight);
            }
            else
            {
                if (newTabHost.Container.GetType() == currentWindow.GetType())
                {
                    newTabHost.Container.Width = currentWindow.RestoreBounds.Width;
                    newTabHost.Container.Height = currentWindow.RestoreBounds.Height;
                    dragStartWindowOffset = dragablzItem.TranslatePoint(new Point(), currentWindow);
                }
                else
                {
                    newTabHost.Container.Width = ActualWidth;
                    newTabHost.Container.Height = ActualHeight;
                    dragStartWindowOffset = dragablzItem.TranslatePoint(new Point(), this);
                    dragStartWindowOffset.Offset(dragablzItem.MouseAtDragStart.X, dragablzItem.MouseAtDragStart.Y);
                    return dragStartWindowOffset;
                }
            }

            dragStartWindowOffset.Offset(dragablzItem.MouseAtDragStart.X, dragablzItem.MouseAtDragStart.Y);
            var borderVector = currentWindow.WindowState == WindowState.Maximized
                ? currentWindow.PointToScreen(new Point()).ToWpf() - new Point()
                : currentWindow.PointToScreen(new Point()).ToWpf() - new Point(currentWindow.Left, currentWindow.Top);
            dragStartWindowOffset.Offset(borderVector.X, borderVector.Y);
            return dragStartWindowOffset;
        }
Example #27
0
        /// <summary>
        /// Sets the owner window of a specific window. It will first try to set the owner via
        /// the <paramref name="ownerWindow"/>. If the <paramref name="ownerWindow"/> is not available,
        /// this method will use the <paramref name="ownerHandle"/> to set the parent.
        /// </summary>
        /// <param name="window">Reference to the current window.</param>
        /// <param name="ownerWindow">New owner window.</param>
        /// <param name="ownerHandle">The owner handle.</param>
        /// <param name="forceNewOwner">If true, the new owner will be forced. Otherwise, if the
        /// window currently has an owner, that owner will be respected (and thus not changed).</param>
        /// <param name="focusFirstControl">If true, the first control will automatically be focused.</param>
        private static void SetOwnerWindow(SystemWindow window, SystemWindow ownerWindow, IntPtr ownerHandle, bool forceNewOwner, bool focusFirstControl)
        {
            if (focusFirstControl)
            {
                window.FocusFirstControl();
            }

            if (!forceNewOwner && HasOwner(window))
            {
                return;
            }

            try
            {
                if (ownerWindow != null)
                {
                    if (ReferenceEquals(ownerWindow, window))
                    {
                        Log.Warning("Cannot set owner window to itself, no owner window set");
                        return;
                    }

                    if (window.Dispatcher.GetThreadId() != ownerWindow.Dispatcher.GetThreadId())
                    {
                        Log.Warning("The owner window '{0}' is not created on the same thread as the current window '{1}', cannot set owner window",
                            ownerWindow.GetType().GetSafeFullName(false), window.GetType().GetSafeFullName(false));
                        return;
                    }

                    window.Owner = ownerWindow;
                }
                else
                {
                    // Set owner via interop helper
                    var interopHelper = new WindowInteropHelper(window);
                    interopHelper.Owner = ownerHandle;

                    // Get handler (so we can nicely unsubscribe)
                    RoutedEventHandler onWindowLoaded = null;
                    onWindowLoaded = delegate(object sender, RoutedEventArgs e)
                    {
                        // Since this owner type doesn't support WindowStartupLocation.CenterOwner, do
                        // it manually
                        if (window.WindowStartupLocation == WindowStartupLocation.CenterOwner)
                        {
                            // Get the parent window rect
                            RECT ownerRect;
                            if (GetWindowRect(ownerHandle, out ownerRect))
                            {
                                // Get some additional information
                                int ownerWidth = ownerRect.Right - ownerRect.Left;
                                int ownerHeight = ownerRect.Bottom - ownerRect.Top;
                                int ownerHorizontalCenter = (ownerWidth / 2) + ownerRect.Left;
                                int ownerVerticalCenter = (ownerHeight / 2) + ownerRect.Top;

                                // Set the location to manual
                                window.WindowStartupLocation = WindowStartupLocation.Manual;

                                // Now we know the location of the parent, center the window
                                window.Left = ownerHorizontalCenter - (window.ActualWidth / 2);
                                window.Top = ownerVerticalCenter - (window.ActualHeight / 2);
                            }
                        }

                        ((SystemWindow)sender).Loaded -= onWindowLoaded;
                    };

                    window.Loaded += onWindowLoaded;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to set the owner window");
            }
        }