Exemplo n.º 1
0
        public void SaveToTIF(string fileName)
        {
            XpsDocument           xd        = new XpsDocument(fileName, System.IO.FileAccess.Read);
            FixedDocumentSequence fds       = xd.GetFixedDocumentSequence();
            DocumentPaginator     paginator = fds.DocumentPaginator;

            System.Windows.Media.Visual visual = paginator.GetPage(0).Visual;

            System.Windows.FrameworkElement fe = (System.Windows.FrameworkElement)visual;

            int    multiplyFactor = 4;
            string outputPath     = fileName.Replace(".xps", ".tif");

            RenderTargetBitmap bmp = new RenderTargetBitmap(
                (int)fe.ActualWidth * multiplyFactor,
                (int)fe.ActualHeight * multiplyFactor,
                96d * multiplyFactor,
                96d * multiplyFactor,
                System.Windows.Media.PixelFormats.Default);

            bmp.Render(fe);

            TiffBitmapEncoder tff = new TiffBitmapEncoder();

            tff.Frames.Add(BitmapFrame.Create(bmp));

            using (Stream stream = File.Create(outputPath))
            {
                tff.Save(stream);
            }
        }
Exemplo n.º 2
0
        public static System.Windows.Forms.IWin32Window GetIWin32Window(this System.Windows.Media.Visual visual)
        {
            var source = System.Windows.PresentationSource.FromVisual(visual) as System.Windows.Interop.HwndSource;

            System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle);
            return(win);
        }
Exemplo n.º 3
0
        public static System.Windows.Forms.IWin32Window GetIWin32Window(this System.Windows.Media.Visual visual)
        {
            var source = (System.Windows.Interop.HwndSource)PresentationSource.FromVisual(visual) !;

            System.Windows.Forms.IWin32Window win = new Win32WindowHandleWrapper(source.Handle);
            return(win);
        }
        public static T GetDescendantByType <T>(this System.Windows.Media.Visual element) where T : class
        {
            if (element == null)
            {
                return(default(T));
            }
            if (element.GetType() == typeof(T))
            {
                return(element as T);
            }
            T foundElement = null;

            if (element is FrameworkElement)
            {
                (element as FrameworkElement).ApplyTemplate();
            }
            for (var i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(element); i++)
            {
                var visual = System.Windows.Media.VisualTreeHelper.GetChild(element, i) as System.Windows.Media.Visual;
                foundElement = visual.GetDescendantByType <T>();
                if (foundElement != null)
                {
                    break;
                }
            }
            return(foundElement);
        }
Exemplo n.º 5
0
        /*
         * private bool walk_child_nodes_for_BringIntoView(string uri, DependencyObject parent)
         * {
         *  bool found = false;
         *  try
         *  {
         *
         *      for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); i++)
         *      {
         *          System.Windows.Media.Visual child = null;
         *          try
         *          {
         *              child = (System.Windows.Media.Visual)System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
         *              if (child != null)
         *              {
         *                  string res = "";
         *                  res = child.GetValue(System.Windows.Documents.Glyphs.NameProperty).ToString();
         *                  if (res.Equals(uri))
         *                  {
         *                      ((FrameworkElement)child).BringIntoView();
         *                      found = true;
         *                  }
         *              }
         *          }
         *          catch //(System.Exception ex)
         *          {
         *              //...
         *          }
         *          if (found == false && child != null)
         *              walk_child_nodes_for_BringIntoView(uri, child);
         *      }
         *  }
         *  catch //(System.Exception ex)
         *  {
         *      //...
         *  }
         *  return found;
         * }
         */

        private bool BringIntoView_ByURI(string url_to_search, int pageIdx)
        {
            bool found = false;

            try
            {
                DocumentPaginator           pag  = documentViewer.Document.DocumentPaginator;
                FixedDocumentSequence       seq  = (FixedDocumentSequence)documentViewer.Document;
                System.Windows.Media.Visual page = pag.GetPage(pageIdx).Visual;

                FixedPage fp  = page as FixedPage;
                Canvas    can = fp.Children[0] as Canvas;
                object    obj = can.FindName(url_to_search);
                if (obj != null)
                {
                    ((FrameworkElement)obj).BringIntoView();
                    found = true;
                }
            }
            catch (Exception ex)
            {
                LogFile.Error("Error in BringIntoView_ByURI()", ex);
            }
            return(found);
        }
Exemplo n.º 6
0
        public static void Prints(System.Windows.Media.Visual visual)
        {
            PrintDialog p = new PrintDialog();

            if (p.ShowDialog() == true)
            {
                p.PrintVisual(visual, "Отчет");
            }
        }
        /// <summary>
        /// Returns the mouse cursor location.  This method is necessary during
        /// a drag-drop operation because the WPF mechanisms for retrieving the
        /// cursor coordinates are unreliable.
        /// </summary>
        /// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param>
        public static System.Windows.Point GetMousePosition(System.Windows.Media.Visual relativeTo)
        {
            GetCursorPos(out Point mouse);

            // Using PointFromScreen instead of Dan Crevier's code (commented out below)
            // is a bug fix created by William J. Roberts.  Read his comments about the fix
            // here: http://www.codeproject.com/useritems/ListViewDragDropManager.asp?msg=1911611#xx1911611xx
            return(relativeTo.PointFromScreen(new System.Windows.Point(mouse.X, mouse.Y)));
        }
Exemplo n.º 8
0
        public static Point GetScreenCursor(System.Windows.Media.Visual visual)
        {
            var w32Mouse = new Win32Point();

            GetCursorPos(ref w32Mouse);
            var transform = PresentationSource.FromVisual(visual).CompositionTarget.TransformFromDevice;

            return(transform.Transform(new Point(w32Mouse.X, w32Mouse.Y)));
        }
Exemplo n.º 9
0
        public static IntPtr getHandle(this System.Windows.Media.Visual ctrl)
        {
            IntPtr     handle     = IntPtr.Zero;
            HwndSource hwndSource = PresentationSource.FromVisual(ctrl) as HwndSource;

            if (hwndSource != null)
            {
                handle = hwndSource.Handle;
            }
            return(handle);
        }
Exemplo n.º 10
0
 public void Start(System.Windows.Media.Visual visual)
 {
     //string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
     //string p = Path.GetDirectoryName(path);
     //m_process = Process.Start(string.Format("{0}\\ImageServer.exe", p));
     m_process     = Process.GetProcessesByName("ImageServer").FirstOrDefault();
     m_mappedWrite = MemoryMappedFile.CreateOrOpen("ImageEdit", 1024);
     m_mappedRead  = MemoryMappedFile.CreateOrOpen("ImageServer", 8 * 1024 * 1024 * 100);
     Hwnd          = Process.GetCurrentProcess().MainWindowHandle.ToInt64();
     hwndSource    = HwndSource.FromHwnd(Process.GetCurrentProcess().MainWindowHandle);
     hwndSource.AddHook(Hook);
 }
Exemplo n.º 11
0
        public static Point GetNowPosition(System.Windows.Media.Visual v)
        {
            POINT p;

            GetCursorPos(out p);

            var source = HwndSource.FromVisual(v) as HwndSource;
            var hwnd   = source.Handle;

            ScreenToClient(hwnd, ref p);
            return(new Point(p.X, p.Y));
        }
Exemplo n.º 12
0
        public TargetWpfHook(Visual visual, IObserver <WpfHookResult> target, WpfHookParam param)
        {
            this.Target = target;
            var frameworkElement = (FrameworkElement)visual;

            frameworkElement.Unloaded += (_1, _2) => target.OnCompleted();

            tbTime              = (WpfTextBox)frameworkElement.FindName("tbTime");
            tbTime.TextChanged += tbTime_TextChanged;

            tbArbitrary              = (WpfTextBox)frameworkElement.FindName("tbArbitrary");
            tbArbitrary.TextChanged += tbArbitrary_TextChanged;
        }
Exemplo n.º 13
0
        public static System.Windows.Point getElementPos(System.Windows.Media.Visual element)
        {
            System.Windows.Point retVal = new System.Windows.Point(0, 0);
            bool done = false;

            element.Dispatcher.Invoke(() =>
            {
                retVal = element.PointToScreen(new System.Windows.Point(0, 0));
                done   = true;
            });
            while (!done)
            {
            }
            return(retVal);
        }
Exemplo n.º 14
0
        public static void DoPreview(string title, System.Windows.Media.Visual visual)
        {
            string fileName = System.IO.Path.GetTempFileName();

            try
            {
                // write the XPS document
                using (XpsDocument doc = new XpsDocument(fileName, FileAccess.ReadWrite))
                {
                    XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
                    writer.Write(visual);
                }

                // Read the XPS document into a dynamically generated
                // preview Window
                using (XpsDocument doc = new XpsDocument(fileName, FileAccess.Read))
                {
                    FixedDocumentSequence fds = doc.GetFixedDocumentSequence();

                    string s = _previewWindowXaml;
                    s = s.Replace("@@TITLE", title.Replace("'", "&apos;"));

                    using (var reader = new System.Xml.XmlTextReader(new StringReader(s)))
                    {
                        Window preview = System.Windows.Markup.XamlReader.Load(reader) as Window;

                        DocumentViewer dv1 = LogicalTreeHelper.FindLogicalNode(preview, "dv1") as DocumentViewer;
                        dv1.Document = fds as IDocumentPaginatorSource;


                        preview.ShowDialog();
                    }
                }
            }
            finally
            {
                if (File.Exists(fileName))
                {
                    try
                    {
                        File.Delete(fileName);
                    }
                    catch//temporary file anyway so doesn't matter if can't delete
                    {
                    }
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Forces content to scroll until the coordinate space of a <see cref="T:System.Windows.Media.Visual" /> object is visible.
        /// </summary>
        /// <param name="visual">A <see cref="T:System.Windows.Media.Visual" /> that becomes visible.</param>
        /// <param name="rectangle">A bounding rectangle that identifies the coordinate space to make visible.</param>
        /// <returns>
        /// A <see cref="T:System.Windows.Rect" /> that is visible.
        /// </returns>
        Rect IScrollInfo.MakeVisible(System.Windows.Media.Visual visual, Rect rectangle)
        {
            var topDelta    = visual.TransformToAncestor(this).Transform(rectangle.Location).Y;
            var bottomDelta = topDelta + rectangle.Height - _scrollViewport.Height;

            if (topDelta < 0)
            {
                // Top part is out of scroll
                SetVerticalOffset(_scrollOffset + topDelta, true);
            }
            else if (bottomDelta > 0)
            {
                // Bottom part is out of scroll
                SetVerticalOffset(_scrollOffset + bottomDelta, true);
            }
            return(rectangle);
        }
Exemplo n.º 16
0
        private System.Windows.FrameworkElement FindElement(System.Windows.Media.Visual v, string name)
        {
            this.has_find_e = true;

            if (v == null)
            {
                return(null);
            }

            for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(v); ++i)
            {
                System.Windows.Media.Visual child =
                    System.Windows.Media.VisualTreeHelper.GetChild(v, i) as
                    System.Windows.Media.Visual;
                if (child != null)
                {
                    System.Windows.FrameworkElement e =
                        child as System.Windows.FrameworkElement;
                    //if (e != null && e.Name == name)
                    //    return e;
                    if (e != null)
                    {
                        //Debug.WriteLine(e.Name);
                        Point position = e.PointToScreen(new Point(0d, 0d));
                        if (eWithMinY == null)
                        {
                            eWithMinY = e;
                        }
                        if (position.Y < eWithMinY.PointToScreen(new Point(0d, 0d)).Y)
                        {
                            eWithMinY = e;
                        }
                        if (e.Name == name)
                        {
                            return(e);
                        }
                    }
                }
                System.Windows.FrameworkElement result = FindElement(child, name);
                if (result != null)
                {
                    return(result);
                }
            }
            return(null);
        }
        /// <summary>
        /// Get primary screen's DPI from PresentationSource.FromVisual(visual).CompositionTarget.TransformToDevice
        /// </summary>
        public static Dpi GetDpiFromCompositionTargetTransformToDevice(System.Windows.Media.Visual visual)
        {
            Debug.Assert(visual != null);
            if (visual == null)
            {
                return(Dpi.Default);
            }
            var hwndSource = PresentationSource.FromVisual(visual) as System.Windows.Interop.HwndSource;

            if (hwndSource == null)
            {
                return(Dpi.Default);
            }
            if (hwndSource.CompositionTarget == null)
            {
                return(Dpi.Default);
            }
            return(new Dpi((int)(Dpi.Default.X * hwndSource.CompositionTarget.TransformToDevice.M11), (int)(Dpi.Default.Y * hwndSource.CompositionTarget.TransformToDevice.M22)));
        }
Exemplo n.º 18
0
 public System.Windows.Media.Visual AddControl(string name, System.Windows.Media.Visual control)
 {
     if (_controls.ContainsKey(name))
     {
         control = _controls[name].View;
     }
     else
     {
         _controls.Add(name, new ControlStateInfo()
         {
             View = control, HostDocument = Tools.GetActiveAcadDocument()
         });
         base.AddVisual(name, control, true);
     }
     if (FindVisual(name) == null)
     {
         base.AddVisual(name, control);
     }
     return(control);
 }
        /// <summary>
        /// You can get current screen's DPi (screen which has mouse cursor currently), when you set dpiType to RawDpi or AngularDpi.
        /// Refer to https://msdn.microsoft.com/en-us/library/windows/desktop/dn280510(v=vs.85).aspx
        /// </summary>
        public static Dpi GetDpiFromGetDpiForMonitor(System.Windows.Media.Visual visual, Win32.MonitorDpiType dpiType = Win32.MonitorDpiType.Default)
        {
            Debug.Assert(visual != null);
            if (visual == null)
            {
                return(Dpi.Default);
            }
            // NOTE: app.manifestに、Windows8.1対応を明記しなければならないため、このような判定は行わないことにする。
            //if (IsPerMonitorDpiServiceSupported == false) { return GetDpiFromCompositionTargetTransformToDevice(visual); }
            var hwndSource = PresentationSource.FromVisual(visual) as System.Windows.Interop.HwndSource;

            if (hwndSource == null)
            {
                return(Dpi.Default);
            }
            var  hmonitor = Win32.NativeMethods.MonitorFromWindow(hwndSource.Handle, Win32.NativeMethods.MonitorDefaultTo.MONITOR_DEFAULTTONEAREST);
            uint dpiX = 96, dpiY = 96;

            Win32.NativeMethods.GetDpiForMonitor(hmonitor, (Win32.MonitorDpiType)dpiType, ref dpiX, ref dpiY);
            return(new Dpi((int)dpiX, (int)dpiY));
        }
Exemplo n.º 20
0
        public static System.Windows.Forms.Screen GetCurrentScreen(this System.Windows.Media.Visual visual)
        {
            System.Windows.Forms.Screen currentScreen = Screens[0];

            System.Windows.Point ptOnScreen = visual.PointToScreen(new System.Windows.Point(1, 1));
            foreach (var screen in Screens)
            {
                if (
                    (ptOnScreen.X >= screen.Bounds.X) &&
                    (ptOnScreen.X <= screen.Bounds.Right) &&
                    (ptOnScreen.Y >= screen.Bounds.Y) &&
                    (ptOnScreen.Y <= screen.Bounds.Bottom)
                    )
                {
                    return(screen);
                }
            }

            // This should not happen
            return(currentScreen);
        }
        /// <summary>
        /// Transform bounds relative to FrameworkElement
        /// </summary>
        /// <param name="sibling1">base rectangle</param>
        /// <param name="sibling2">second of pair to transform</param>
        /// <returns>result of transformed rectangle</returns>
        private static WF.Rect BoundsRelativeTo(FrameworkElement sibling1, System.Windows.Media.Visual sibling2)
        {
            WF.Rect origin = default(WF.Rect);

            if (sibling1 != null)
            {
                // TransformToVisual can throw an exception if two elements don't have a common ancestor
                try
                {
                    var transform         = sibling1.TransformToVisual(sibling2);
                    var systemWindowsRect = transform.TransformBounds(
                        new Rect(0, 0, sibling1.ActualWidth, sibling1.ActualHeight));
                    origin.X      = systemWindowsRect.X;
                    origin.Y      = systemWindowsRect.Y;
                    origin.Width  = systemWindowsRect.Width;
                    origin.Height = systemWindowsRect.Height;
                }
                catch (System.InvalidOperationException)
                {
                }
            }

            return(origin);
        }
 protected void RemoveVisualChild(System.Windows.Media.Visual child)
 {
 }
 protected void AddVisualChild(System.Windows.Media.Visual child)
 {
 }
 public GeneralTransform TransformToVisual(System.Windows.Media.Visual visual)
 {
     Contract.Requires(visual != null);
     Contract.Ensures(Contract.Result <GeneralTransform>() != null);
     return(default(GeneralTransform));
 }
 public GeneralTransform TransformToDescendant(System.Windows.Media.Visual descendant)
 {
     Contract.Requires(descendant != null);
     Contract.Ensures(Contract.Result <GeneralTransform>() != null);
     return(default(GeneralTransform));
 }
 public GeneralTransform3DTo2D TransformToAncestor(System.Windows.Media.Visual ancestor)
 {
     return(default(GeneralTransform3DTo2D));
 }
 public static AdornerLayer GetAdornerLayer(System.Windows.Media.Visual visual)
 {
     return(default(AdornerLayer));
 }
Exemplo n.º 28
0
 public Rect MakeVisible(System.Windows.Media.Visual visual, Rect rectangle)
 {
     return(new Rect());
 }
 public GeneralTransform TransformToAncestor(System.Windows.Media.Visual ancestor)
 {
     Contract.Requires(ancestor != null);
     Contract.Ensures(Contract.Result <GeneralTransform>() != null);
     return(default(GeneralTransform));
 }
Exemplo n.º 30
0
 public abstract void WriteAsync(System.Windows.Media.Visual visual, System.Printing.PrintTicket printTicket, Object userState);