/// <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); }
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)); }
// used by PrinterSettings.DefaultPageSettings internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution) { PrinterSettings = printerSettings; this.color = color; this.landscape = landscape; this.paperSize = paperSize; this.paperSource = paperSource; this.printerResolution = printerResolution; }
public PageSettings(PrinterSettings printerSettings) { PrinterSettings = printerSettings; this.color = printerSettings.DefaultPageSettings.color; this.landscape = printerSettings.DefaultPageSettings.landscape; this.paperSize = printerSettings.DefaultPageSettings.paperSize; this.paperSource = printerSettings.DefaultPageSettings.paperSource; this.printerResolution = printerSettings.DefaultPageSettings.printerResolution; }
public void KindTest () { PaperSource ps = new PaperSource (); // // Set Custom ps.RawKind = (int)PaperSourceKind.Custom; Assert.AreEqual (PaperSourceKind.Custom, ps.Kind, "Kind #8"); Assert.AreEqual (257, ps.RawKind, "RawKind #8"); // // An integer value of 256 and above returns Custom (0x257) ps.RawKind = 256; Assert.AreEqual (256, ps.RawKind, "out: #" + 256); Assert.AreEqual (PaperSourceKind.Custom, ps.Kind, "kind is custom: #" + 256); // // Zero ps.RawKind = 0; Assert.AreEqual ((PaperSourceKind)0, ps.Kind, "Kind #1"); Assert.AreEqual (0, ps.RawKind, "RawKind #1"); // // Well-known ps.RawKind = (int)PaperSourceKind.Upper; Assert.AreEqual (PaperSourceKind.Upper, ps.Kind, "Kind #2"); Assert.AreEqual ((int)PaperSourceKind.Upper, ps.RawKind, "RawKind #2"); // ps.RawKind = (int)PaperSourceKind.FormSource; Assert.AreEqual (PaperSourceKind.FormSource, ps.Kind, "Kind #3"); Assert.AreEqual ((int)PaperSourceKind.FormSource, ps.RawKind, "RawKind #3"); // // Too Big ps.RawKind = 999999; Assert.AreEqual (PaperSourceKind.Custom, ps.Kind, "Kind #4"); Assert.AreEqual (999999, ps.RawKind, "RawKind #4"); // ps.RawKind = int.MaxValue; Assert.AreEqual (PaperSourceKind.Custom, ps.Kind, "Kind #5"); Assert.AreEqual (int.MaxValue, ps.RawKind, "RawKind #5"); // // Negative -- Looks as if MSFT forgot to check for negative! ps.RawKind = -1; Assert.AreEqual ((PaperSourceKind)(-1), ps.Kind, "Kind #6"); Assert.AreEqual (-1, ps.RawKind, "RawKind #6"); // ps.RawKind = int.MinValue; Assert.AreEqual ((PaperSourceKind)(int.MinValue), ps.Kind, "Kind #7"); Assert.AreEqual (int.MinValue, ps.RawKind, "RawKind #7"); }
/// <summary> /// Provides some interesting information about the PageSettings in String form. /// </summary> public override string ToString() { return("[PageSettings:" + " Color=" + Color.ToString() + ", Landscape=" + Landscape.ToString() + ", Margins=" + Margins.ToString() + ", PaperSize=" + PaperSize.ToString() + ", PaperSource=" + PaperSource.ToString() + ", PrinterResolution=" + PrinterResolution.ToString() + "]"); }
public object Clone() { // We do a deep copy PrinterResolution pres = new PrinterResolution(this.printerResolution.X, this.printerResolution.Y, this.printerResolution.Kind); PaperSource psource = new PaperSource(this.paperSource.SourceName, this.paperSource.Kind); PaperSize psize = new PaperSize(this.paperSize.PaperName, this.paperSize.Width, this.paperSize.Height); psize.SetKind(this.paperSize.Kind); PageSettings ps = new PageSettings(this.printerSettings, this.color, this.landscape, psize, psource, pres); ps.Margins = (Margins)this.margins.Clone(); return(ps); }
/// <summary> /// Loads a printer's paper sources (trays). Returns the default PaperSource, and fills a list of paper_sources for use in dialogues /// </summary> /// <param name="settings">PrinterSettings object to fill</param> /// <param name="def_source">Default paper source, from the global options of the printer</param> /// <param name="paper_sources">List of available paper sizes that gets filled</param> private static PaperSource LoadPrinterPaperSources(PrinterSettings settings, string def_source, NameValueCollection paper_sources) { PaperSourceKind kind; PaperSource defsource = null; foreach (string source in paper_sources) { switch (source) { case "Auto": kind = PaperSourceKind.AutomaticFeed; break; case "Standard": kind = PaperSourceKind.AutomaticFeed; break; case "Tray": kind = PaperSourceKind.AutomaticFeed; break; case "Envelope": kind = PaperSourceKind.Envelope; break; case "Manual": kind = PaperSourceKind.Manual; break; default: kind = PaperSourceKind.Custom; break; } settings.paper_sources.Add(new PaperSource(kind, paper_sources[source])); if (def_source == source) { defsource = settings.paper_sources[settings.paper_sources.Count - 1]; } } if (defsource == null && settings.paper_sources.Count > 0) { return(settings.paper_sources[0]); } return(defsource); }
// Convert this object into a string. public override String ToString() { StringBuilder builder = new StringBuilder(); builder.Append("[PageSettings: Color="); builder.Append(Color.ToString()); builder.Append(", Landscape="); builder.Append(Landscape.ToString()); builder.Append(", Margins="); builder.Append(Margins.ToString()); builder.Append(", PaperSize="); builder.Append(PaperSize.ToString()); builder.Append(", PaperSource="); builder.Append(PaperSource.ToString()); builder.Append(", PrinterResolution="); builder.Append(PrinterResolution.ToString()); builder.Append(']'); return(builder.ToString()); }
/// <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 int Add (PaperSource paperSource) {return _PaperSources.Add (paperSource); }
internal PaperSource[] Get_PaperSources() { System.Drawing.IntSecurity.AllPrintingAndUnmanagedCode.Assert(); string printerName = this.PrinterName; int num = FastDeviceCapabilities(12, IntPtr.Zero, -1, printerName); if (num == -1) { return new PaperSource[0]; } int num2 = Marshal.SystemDefaultCharSize * 0x18; IntPtr pointerToBuffer = Marshal.AllocCoTaskMem(num2 * num); FastDeviceCapabilities(12, pointerToBuffer, -1, printerName); IntPtr ptr2 = Marshal.AllocCoTaskMem(2 * num); FastDeviceCapabilities(6, ptr2, -1, printerName); PaperSource[] sourceArray = new PaperSource[num]; for (int i = 0; i < num; i++) { string name = Marshal.PtrToStringAuto((IntPtr) (((long) pointerToBuffer) + (num2 * i))); short num4 = Marshal.ReadInt16((IntPtr) (((long) ptr2) + (2 * i))); sourceArray[i] = new PaperSource((PaperSourceKind) num4, name); } Marshal.FreeCoTaskMem(pointerToBuffer); Marshal.FreeCoTaskMem(ptr2); return sourceArray; }
public void CopyTo(PaperSource[] paperSources, int index) { Array.Copy(this.array, index, paperSources, 0, this.array.Length); }
public int Add(PaperSource paperSource) { PaperSource[] array = new PaperSource[this.Count + 1]; ((ICollection) this).CopyTo(array, 0); array[this.Count] = paperSource; this.array = array; return this.Count; }
public PaperSourceCollection(PaperSource[] array) { this.array = array; }
internal int Add(PaperSource paperSource) { return(_PaperSources.Add(paperSource)); }
internal int Add (PaperSource paperSource) {return _PaperSources.Add (paperSource); }
public Int32 Add(PaperSource paperSource) { PaperSource[] newArray = new PaperSource[this.Count + 1]; ((ICollection) this).CopyTo(newArray, 0); newArray[this.Count] = paperSource; this.array = newArray; return this.Count; }
/// <summary> /// Handler for PaperSourceComboBox selection changed event /// </summary> /// <param name="sender">not used</param> /// <param name="e">SelectionChangedEventArgs object for the event</param> void PaperSourceComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { PrinterSettings settings = new PrinterSettings(); settings.PrinterName = PrinterName; if(e.AddedItems.Count > 0) { foreach(PaperSource source in settings.PaperSources) { if(e.AddedItems[0].Equals(source.SourceName)) { Source = source; if(App.Logger.DebugPrinting) { App.Logger.Log("PaperSourceComboBox_SelectionChanged:" + Environment.NewLine + "PaperSource changed to " + source.SourceName + Environment.NewLine); } break; } } } }
public PaperSourceCollection(PaperSource[] array) { foreach (PaperSource ps in array) _PaperSources.Add(ps); }
internal PaperSource[] Get_PaperSources() { IntSecurity.AllPrintingAndUnmanagedCode.Assert(); string printerName = PrinterName; // this is quite expensive if PrinterName is left default int count = FastDeviceCapabilities(SafeNativeMethods.DC_BINNAMES, IntPtr.Zero, -1, printerName); if (count == -1) return new PaperSource[0]; // Contrary to documentation, DeviceCapabilities returns char[count, 24], // not char[count][24] int stringSize = Marshal.SystemDefaultCharSize * 24; IntPtr namesBuffer = Marshal.AllocCoTaskMem(checked(stringSize * count)); FastDeviceCapabilities(SafeNativeMethods.DC_BINNAMES, namesBuffer, -1, printerName); Debug.Assert(FastDeviceCapabilities(SafeNativeMethods.DC_BINS, IntPtr.Zero, -1, printerName) == count, "Not the same number of bin kinds as bin names?"); IntPtr kindsBuffer = Marshal.AllocCoTaskMem(2 * count); FastDeviceCapabilities(SafeNativeMethods.DC_BINS, kindsBuffer, -1, printerName); PaperSource[] result = new PaperSource[count]; for (int i = 0; i < count; i++) { string name = Marshal.PtrToStringAuto((IntPtr)(checked((long)namesBuffer + stringSize * i)), 24); int index = name.IndexOf('\0'); if (index > -1) { name = name.Substring(0, index); } short kind = Marshal.ReadInt16((IntPtr)(checked((long)kindsBuffer + 2*i))); result[i] = new PaperSource((PaperSourceKind) kind, name); } Marshal.FreeCoTaskMem(namesBuffer); Marshal.FreeCoTaskMem(kindsBuffer); return result; }
public int Add(PaperSource paperSource) { throw null; }
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 int Add(PaperSource paperSource) { return(_PaperSources.Add(paperSource)); }
public void CopyTo (PaperSource[] paperSources, int index) {throw new NotImplementedException (); }
public object Clone () { // We do a deep copy PrinterResolution pres = new PrinterResolution (this.printerResolution.X, this.printerResolution.Y, this.printerResolution.Kind); PaperSource psource = new PaperSource (this.paperSource.SourceName, this.paperSource.Kind); PaperSize psize = new PaperSize (this.paperSize.PaperName, this.paperSize.Width, this.paperSize.Height); psize.SetKind (this.paperSize.Kind); PageSettings ps = new PageSettings (this.printerSettings, this.color, this.landscape, psize, psource, pres); ps.Margins = (Margins) this.margins.Clone (); return ps; }