InvalidPrinterException with differentiated messages.
* PrintingServices.cs: Declares IsPrinterValid to enable easy checking
if printer name is a valid printer
* PrintingServicesWin32.cs: Implements IsPrinterValid, caches
last assigned printer name and if it is valid to speed up next calls.
* PrintingServicesUnix.cs: Implements IsPrinterValid, caches
last assigned printer name and if it is valid to speed up next calls.
* PageSettings.cs:
- throw InvalidPrinterException in the properties,
according to the docs: Color, Landscape, PaperSize, PaperSource,
PrinterResolution
- change the private fields above to internal, so that in the
constructor we can access them without triggering the exceptions
if there are no printers installed
* PrinterSettings.cs: Implement IsValid to call IsPrinterValid
implemented above
* PreviewPrintController.cs: throw InvalidPrinterException on
StartPrint() if there's no valid printer configured
* InvalidPrinterException.cs: New private GetMessage() to customize
printer error message, used by constructor
2006-11-14 Andreia Gaita <avidigal@novell.com>
svn path=/trunk/mcs/; revision=67880
+2006-11-14 Andreia Gaita <avidigal@novell.com>
+ Fixes #79835, implements PrinterSettings.IsValid, throws proper
+ InvalidPrinterException with differentiated messages.
+
+ * PrintingServices.cs: Declares IsPrinterValid to enable easy checking
+ if printer name is a valid printer
+
+ * PrintingServicesWin32.cs: Implements IsPrinterValid, caches
+ last assigned printer name and if it is valid to speed up next calls.
+
+ * PrintingServicesUnix.cs: Implements IsPrinterValid, caches
+ last assigned printer name and if it is valid to speed up next calls.
+
+ * PageSettings.cs:
+ - throw InvalidPrinterException in the properties,
+ according to the docs: Color, Landscape, PaperSize, PaperSource,
+ PrinterResolution
+ - change the private fields above to internal, so that in the
+ constructor we can access them without triggering the exceptions
+ if there are no printers installed
+
+ * PrinterSettings.cs: Implement IsValid to call IsPrinterValid
+ implemented above
+
+ * PreviewPrintController.cs: throw InvalidPrinterException on
+ StartPrint() if there's no valid printer configured
+
+ * InvalidPrinterException.cs: New private GetMessage() to customize
+ printer error message, used by constructor
+
2006-09-27 Jordi Mas i Hernandez <jordimash@gmail.com>
* PrintingServicesUnix.cs: Implements LoadPrinterPaperSources member,
private PrinterSettings settings;
- public InvalidPrinterException (PrinterSettings settings)
+ public InvalidPrinterException (PrinterSettings settings): base(InvalidPrinterException.GetMessage(settings))
{
this.settings = settings;
}
base.GetObjectData (info, context);
}
+
+ private static string GetMessage(PrinterSettings settings)
+ {
+ if (settings.PrinterName == null || settings.PrinterName == String.Empty)
+ return "No Printers Installed";
+ return String.Format("Tried to access printer '{0}' with invalid settings.", settings.PrinterName);
+ }
}
}
#endif
public class PageSettings : ICloneable
{
- bool _Color;
- bool _Landscape;
+ internal bool _Color;
+ internal bool _Landscape;
+ internal PaperSize _PaperSize;
+ internal PaperSource _PaperSource;
+ internal PrinterResolution _PrinterResolution;
float _HardMarginX;\r
float _HardMarginY;
RectangleF _PrintableArea;
// create a new default Margins object (is 1 inch for all margins)
Margins _Margins = new Margins();
- PaperSize _PaperSize;
- PaperSource _PaperSource;
- PrinterResolution _PrinterResolution;
PrinterSettings _PrinterSettings;
public PageSettings() : this(new PrinterSettings())
{
PrinterSettings = printerSettings;
- Color = printerSettings.DefaultPageSettings.Color;
- Landscape = printerSettings.DefaultPageSettings.Landscape;
- PaperSize = printerSettings.DefaultPageSettings.PaperSize;
- PaperSource = printerSettings.DefaultPageSettings.PaperSource;
- PrinterResolution = printerSettings.DefaultPageSettings.PrinterResolution;
+ Color = printerSettings.DefaultPageSettings._Color;
+ Landscape = printerSettings.DefaultPageSettings._Landscape;
+ PaperSize = printerSettings.DefaultPageSettings._PaperSize;
+ PaperSource = printerSettings.DefaultPageSettings._PaperSource;
+ PrinterResolution = printerSettings.DefaultPageSettings._PrinterResolution;
}
// used by PrinterSettings.DefaultPageSettings
{
PrinterSettings = printerSettings;
- Color = color;
- Landscape = landscape;
- PaperSize = paperSize;
- PaperSource = paperSource;
- PrinterResolution = printerResolution;
+ _Color = color;
+ _Landscape = landscape;
+ _PaperSize = paperSize;
+ _PaperSource = paperSource;
+ _PrinterResolution = printerResolution;
}
//props
public bool Color{
get{
+ if (!this._PrinterSettings.IsValid)
+ throw new InvalidPrinterException(this._PrinterSettings);
return _Color;
}
set{
public bool Landscape {
get{
+ if (!this._PrinterSettings.IsValid)
+ throw new InvalidPrinterException(this._PrinterSettings);
return _Landscape;
}
set{
public Margins Margins{
get{
+ if (!this._PrinterSettings.IsValid)
+ throw new InvalidPrinterException(this._PrinterSettings);
return _Margins;
}
set{
public PaperSize PaperSize{
get{
+ if (!this._PrinterSettings.IsValid)
+ throw new InvalidPrinterException(this._PrinterSettings);
return _PaperSize;
}
set{
public PaperSource PaperSource{
get{
+ if (!this._PrinterSettings.IsValid)
+ throw new InvalidPrinterException(this._PrinterSettings);
return _PaperSource;
}
set{
public PrinterResolution PrinterResolution{
get{
+ if (!this._PrinterSettings.IsValid)
+ throw new InvalidPrinterException(this._PrinterSettings);
return _PrinterResolution;
}
set{
[MonoTODO]
public override void OnStartPrint(PrintDocument document, PrintEventArgs e)
{
+ if (document.PrinterSettings.IsValid)
+ throw new InvalidPrinterException(document.PrinterSettings);
+
/* maybe we should reuse the images, and clear them? */
foreach (PreviewPageInfo pi in pageInfoList)
pi.Image.Dispose ();
get { return false; }
}
- [MonoTODO("PrinterSettings.IsValid")]
public bool IsValid
{
- get { return true; }
+ get { return SysPrn.Service.IsPrinterValid(this.printer_name, false); }
}
public int LandscapeAngle
public PrinterSettings.PaperSizeCollection PaperSizes
{
get {
+ if (!this.IsValid)
+ throw new InvalidPrinterException(this);
if (paper_sizes == null) {
paper_sizes = new PrinterSettings.PaperSizeCollection (new PaperSize [] {});
SysPrn.Service.LoadPrinterPaperSizes (printer_name, this);
public PrinterSettings.PaperSourceCollection PaperSources
{
get {
+ if (!this.IsValid)
+ throw new InvalidPrinterException(this);
if (paper_sources == null) {
paper_sources = new PrinterSettings.PaperSourceCollection (new PaperSource [] {});
SysPrn.Service.LoadPrinterPaperSources (printer_name, this);
public PrinterSettings.PrinterResolutionCollection PrinterResolutions
{
get {
+ if (!this.IsValid)
+ throw new InvalidPrinterException(this);
if (printer_resolutions == null) {
printer_resolutions = new PrinterSettings.PrinterResolutionCollection (new PrinterResolution[] {});
SysPrn.Service.LoadPrinterResolutions (printer_name, this);
internal abstract void LoadPrinterResolutions (string printer, PrinterSettings settings);
internal abstract void LoadPrinterPaperSizes (string printer, PrinterSettings settings);
internal abstract void LoadPrinterPaperSources (string printer, PrinterSettings settings);
+ internal abstract bool IsPrinterValid(string printer, bool force);
//Used from SWF
internal abstract void GetPrintDialogInfo (string printer, ref string port, ref string type, ref string status, ref string comment);
{
private Hashtable doc_info = new Hashtable ();
private bool cups_installed;
+ private string printer_name;
+ private bool is_printer_valid;
internal PrintingServicesUnix ()
{
cups_installed = true;
}
+
+ internal override bool IsPrinterValid(string printer, bool force)
+ {
+ if (!cups_installed || printer == null | printer == String.Empty)
+ return false;
+
+ if (!force && this.printer_name != null && String.Intern(this.printer_name).Equals(printer))
+ return is_printer_valid;
+
+ IntPtr ptr = cupsGetPPD (printer);
+ string ppd_filename = Marshal.PtrToStringAnsi (ptr);
+ is_printer_valid = ppd_filename != null;
+ this.printer_name = printer;
+ return is_printer_valid;
+ }
// Methods
internal override void LoadPrinterSettings (string printer, PrinterSettings settings)
{
internal class PrintingServicesWin32 : PrintingServices
{
+ private string printer_name;
+ private bool is_printer_valid;
+
internal PrintingServicesWin32 ()
{
}
+ internal override bool IsPrinterValid(string printer, bool force)
+ {
+ if (printer == null | printer == String.Empty)
+ return false;
+
+ if (!force && this.printer_name != null && String.Intern(this.printer_name).Equals(printer))
+ return is_printer_valid;
+
+ int ret = Win32DocumentProperties (IntPtr.Zero, IntPtr.Zero, printer, IntPtr.Zero, IntPtr.Zero, 0);
+ is_printer_valid = (ret < 1);
+ this.printer_name = printer;
+ return is_printer_valid;
+ }
+
internal override void LoadPrinterSettings (string printer, PrinterSettings settings)
{
int ret;