/// <summary>
        /// Copies the relevant information out of the handle and into the PageSettings.
        /// </summary>
        public void SetHdevmode(IntPtr hdevmode)
        {
            if (hdevmode == IntPtr.Zero)
            {
                throw new ArgumentException(SR.Format(SR.InvalidPrinterHandle, hdevmode));
            }

            IntPtr pointer = Interop.Kernel32.GlobalLock(hdevmode);

            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));

            if ((mode.dmFields & SafeNativeMethods.DM_COLOR) == SafeNativeMethods.DM_COLOR)
            {
                _color = (mode.dmColor == SafeNativeMethods.DMCOLOR_COLOR);
            }

            if ((mode.dmFields & SafeNativeMethods.DM_ORIENTATION) == SafeNativeMethods.DM_ORIENTATION)
            {
                _landscape = (mode.dmOrientation == SafeNativeMethods.DMORIENT_LANDSCAPE);
            }

            _paperSize         = PaperSizeFromMode(mode);
            _paperSource       = PaperSourceFromMode(mode);
            _printerResolution = PrinterResolutionFromMode(mode);

            Interop.Kernel32.GlobalUnlock(hdevmode);
        }
Beispiel #2
0
 public PageSettings(System.Drawing.Printing.PrinterSettings printerSettings)
 {
     this.color           = TriState.Default;
     this.landscape       = TriState.Default;
     this.margins         = new System.Drawing.Printing.Margins();
     this.printerSettings = printerSettings;
 }
        public void SetHdevmode(IntPtr hdevmode)
        {
            // SECREVIEW:
            // PrinterSettings.SetHdevmode demand AllPrintingANDUMC so lets be consistent here.
            IntSecurity.AllPrintingAndUnmanagedCode.Demand();
            if (hdevmode == IntPtr.Zero)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidPrinterHandle, hdevmode));
            }

            IntPtr pointer = SafeNativeMethods.GlobalLock(new HandleRef(null, hdevmode));

            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)UnsafeNativeMethods.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));

            if ((mode.dmFields & SafeNativeMethods.DM_COLOR) == SafeNativeMethods.DM_COLOR)
            {
                color = (mode.dmColor == SafeNativeMethods.DMCOLOR_COLOR);
            }

            if ((mode.dmFields & SafeNativeMethods.DM_ORIENTATION) == SafeNativeMethods.DM_ORIENTATION)
            {
                landscape = (mode.dmOrientation == SafeNativeMethods.DMORIENT_LANDSCAPE);
            }

            paperSize         = PaperSizeFromMode(mode);
            paperSource       = PaperSourceFromMode(mode);
            printerResolution = PrinterResolutionFromMode(mode);

            SafeNativeMethods.GlobalUnlock(new HandleRef(null, hdevmode));
        }
 public PageSettings(System.Drawing.Printing.PrinterSettings printerSettings)
 {
     this.color = TriState.Default;
     this.landscape = TriState.Default;
     this.margins = new System.Drawing.Printing.Margins();
     this.printerSettings = printerSettings;
 }
Beispiel #5
0
 public void SetHdevmode(IntPtr hdevmode)
 {
     IntSecurity.AllPrintingAndUnmanagedCode.Demand();
     if (hdevmode == IntPtr.Zero)
     {
         throw new ArgumentException(System.Drawing.SR.GetString("InvalidPrinterHandle", new object[] { hdevmode }));
     }
     SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)UnsafeNativeMethods.PtrToStructure(SafeNativeMethods.GlobalLock(new HandleRef(null, hdevmode)), typeof(SafeNativeMethods.DEVMODE));
     if ((mode.dmFields & 0x800) == 0x800)
     {
         this.color = mode.dmColor == 2;
     }
     if ((mode.dmFields & 1) == 1)
     {
         this.landscape = mode.dmOrientation == 2;
     }
     this.paperSize         = this.PaperSizeFromMode(mode);
     this.paperSource       = this.PaperSourceFromMode(mode);
     this.printerResolution = this.PrinterResolutionFromMode(mode);
     SafeNativeMethods.GlobalUnlock(new HandleRef(null, hdevmode));
 }
Beispiel #6
0
        /// <include file='doc\PageSettings.uex' path='docs/doc[@for="PageSettings.SetHdevmode"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Copies the relevant information out of the handle and into the PageSettings.
        ///    </para>
        /// </devdoc>
        public void SetHdevmode(IntPtr hdevmode)
        {
            IntSecurity.AllPrinting.Demand();

            if (hdevmode == IntPtr.Zero)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidPrinterHandle, hdevmode));
            }

            IntPtr pointer = SafeNativeMethods.GlobalLock(new HandleRef(null, hdevmode));

            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)UnsafeNativeMethods.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));

            color             = (mode.dmColor == SafeNativeMethods.DMCOLOR_COLOR);
            landscape         = (mode.dmOrientation == SafeNativeMethods.DMORIENT_LANDSCAPE);
            paperSize         = PaperSizeFromMode(mode);
            paperSource       = PaperSourceFromMode(mode);
            printerResolution = PrinterResolutionFromMode(mode);

            SafeNativeMethods.GlobalUnlock(new HandleRef(null, hdevmode));
        }
 public void SetHdevmode(IntPtr hdevmode)
 {
     System.Drawing.IntSecurity.AllPrintingAndUnmanagedCode.Demand();
     if (hdevmode == IntPtr.Zero)
     {
         throw new ArgumentException(System.Drawing.SR.GetString("InvalidPrinterHandle", new object[] { hdevmode }));
     }
     IntPtr lparam = SafeNativeMethods.GlobalLock(new HandleRef(null, hdevmode));
     SafeNativeMethods.DEVMODE devmode = (SafeNativeMethods.DEVMODE) UnsafeNativeMethods.PtrToStructure(lparam, typeof(SafeNativeMethods.DEVMODE));
     this.devmodebytes = devmode.dmSize;
     if (this.devmodebytes > 0)
     {
         this.cachedDevmode = new byte[this.devmodebytes];
         Marshal.Copy(lparam, this.cachedDevmode, 0, this.devmodebytes);
     }
     this.extrabytes = devmode.dmDriverExtra;
     if (this.extrabytes > 0)
     {
         this.extrainfo = new byte[this.extrabytes];
         Marshal.Copy((IntPtr) (((long) lparam) + devmode.dmSize), this.extrainfo, 0, this.extrabytes);
     }
     if ((devmode.dmFields & 0x100) == 0x100)
     {
         this.copies = devmode.dmCopies;
     }
     if ((devmode.dmFields & 0x1000) == 0x1000)
     {
         this.duplex = (System.Drawing.Printing.Duplex) devmode.dmDuplex;
     }
     if ((devmode.dmFields & 0x8000) == 0x8000)
     {
         this.collate = devmode.dmCollate == 1;
     }
     SafeNativeMethods.GlobalUnlock(new HandleRef(null, hdevmode));
 }
Beispiel #8
0
        public void SetHdevmode(IntPtr hdevmode) {
            // SECREVIEW: 
            // PrinterSettings.SetHdevmode demand AllPrintingANDUMC so lets be consistent here.
            IntSecurity.AllPrintingAndUnmanagedCode.Demand();
            if (hdevmode == IntPtr.Zero)
                throw new ArgumentException(SR.GetString(SR.InvalidPrinterHandle, hdevmode));

            IntPtr pointer = SafeNativeMethods.GlobalLock(new HandleRef(null, hdevmode));
            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE) UnsafeNativeMethods.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));

            if ((mode.dmFields & SafeNativeMethods.DM_COLOR) == SafeNativeMethods.DM_COLOR)
            {
                color = (mode.dmColor == SafeNativeMethods.DMCOLOR_COLOR);
            }

            if ((mode.dmFields & SafeNativeMethods.DM_ORIENTATION) == SafeNativeMethods.DM_ORIENTATION)
            {
                landscape = (mode.dmOrientation == SafeNativeMethods.DMORIENT_LANDSCAPE);
            }
            
            paperSize = PaperSizeFromMode(mode);
            paperSource = PaperSourceFromMode(mode);
            printerResolution = PrinterResolutionFromMode(mode);

            SafeNativeMethods.GlobalUnlock(new HandleRef(null, hdevmode));
        }
Beispiel #9
0
        public override bool Equals(object o)
        {
            TriState state = (TriState)o;

            return(this.value == state.value);
        }
        public void SetHdevmode(IntPtr hdevmode) {
            IntSecurity.AllPrintingAndUnmanagedCode.Demand();
            // Don't assert unmanaged code -- anyone using handles should have unmanaged code permission

            if (hdevmode == IntPtr.Zero)
                throw new ArgumentException(SR.GetString(SR.InvalidPrinterHandle, hdevmode));

            IntPtr pointer = SafeNativeMethods.GlobalLock(new HandleRef(null, hdevmode));
            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE) UnsafeNativeMethods.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));

            //Copy entire public devmode as a byte array...
            devmodebytes = mode.dmSize;
            if (devmodebytes > 0)  {
                cachedDevmode = new byte[devmodebytes];
                Marshal.Copy(pointer, cachedDevmode, 0, devmodebytes);
            }

            //Copy private devmode as a byte array..
            extrabytes = mode.dmDriverExtra;
            if (extrabytes > 0)  {
                extrainfo = new byte[extrabytes];
                Marshal.Copy((IntPtr)(checked((long)pointer + (long)mode.dmSize)), extrainfo, 0, extrabytes);
            }

            if ((mode.dmFields & SafeNativeMethods.DM_COPIES) == SafeNativeMethods.DM_COPIES) {
                copies = mode.dmCopies;
            }

            if ((mode.dmFields & SafeNativeMethods.DM_DUPLEX) == SafeNativeMethods.DM_DUPLEX ) {
                duplex = (Duplex) mode.dmDuplex;
            }
            
            if ((mode.dmFields & SafeNativeMethods.DM_COLLATE) == SafeNativeMethods.DM_COLLATE) {
                collate = (mode.dmCollate == SafeNativeMethods.DMCOLLATE_TRUE);
            }

            SafeNativeMethods.GlobalUnlock(new HandleRef(null, hdevmode));
        }
 public void SetHdevmode(IntPtr hdevmode)
 {
     IntSecurity.AllPrintingAndUnmanagedCode.Demand();
     if (hdevmode == IntPtr.Zero)
     {
         throw new ArgumentException(System.Drawing.SR.GetString("InvalidPrinterHandle", new object[] { hdevmode }));
     }
     SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE) UnsafeNativeMethods.PtrToStructure(SafeNativeMethods.GlobalLock(new HandleRef(null, hdevmode)), typeof(SafeNativeMethods.DEVMODE));
     if ((mode.dmFields & 0x800) == 0x800)
     {
         this.color = mode.dmColor == 2;
     }
     if ((mode.dmFields & 1) == 1)
     {
         this.landscape = mode.dmOrientation == 2;
     }
     this.paperSize = this.PaperSizeFromMode(mode);
     this.paperSource = this.PaperSourceFromMode(mode);
     this.printerResolution = this.PrinterResolutionFromMode(mode);
     SafeNativeMethods.GlobalUnlock(new HandleRef(null, hdevmode));
 }
 static TriState()
 {
     Default = new TriState(0);
     False = new TriState(1);
     True = new TriState(2);
 }
Beispiel #13
0
 static TriState()
 {
     Default = new TriState(0);
     False   = new TriState(1);
     True    = new TriState(2);
 }