/* * Proyecto: PrinterInfo * Fichero: Form1.prg * Descripción: * Autor: * Fecha: 17/06/2004 */ #include "Xailer.ch" CLASS TForm1 FROM TForm COMPONENT oLabel1 COMPONENT oListbox1 COMPONENT oLabel2 COMPONENT oEdiDefPrinter COMPONENT oButton1 COMPONENT oButton2 COMPONENT oButton3 COMPONENT oButton4 COMPONENT oLabel3 COMPONENT oButton5 COMPONENT oButton6 COMPONENT oBrw COMPONENT oButton7 COMPONENT oButton8 METHOD CreateForm() METHOD Listbox1Change( oSender, nIndex ) METHOD FormInitialize( oSender ) METHOD Button1Click( oSender ) METHOD Button6Click( oSender ) METHOD Button2Click( oSender ) METHOD Button4Click( oSender ) METHOD Button3Click( oSender ) METHOD Button5Click( oSender ) METHOD EdiDefPrinterCreate( oSender ) METHOD UpdateInfo() METHOD Button7Click( oSender ) METHOD Button8Click( oSender ) ENDCLASS #include "Form1.xfm" //------------------------------------------------------------------------------ METHOD Listbox1Change( oSender, nIndex ) CLASS TForm1 Printer:nPrinterIndex := nIndex ::UpdateInfo() RETURN Nil //------------------------------------------------------------------------------ METHOD FormInitialize( oSender ) CLASS TForm1 WITH OBJECT ::oListbox1 :aItems := Printer:aPrinterNames :nIndex := Printer:nPrinterIndex END RETURN Nil //------------------------------------------------------------------------------ METHOD Button1Click( oSender ) CLASS TForm1 Printer:Setup() ::oListbox1:nIndex := Printer:PrinterIndex ::UpdateInfo() RETURN Nil //------------------------------------------------------------------------------ METHOD Button6Click( oSender ) CLASS TForm1 LOCAL aData aData := Printer:GetPrinterFonts() MsgPrinterFonts( aData ) RETURN Nil //------------------------------------------------------------------------------ STATIC FUNCTION MsgPrinterFonts( aData ) LOCAL cString LOCAL nFor cString := "" FOR nFor := 1 TO Len( aData ) cString += aData[ nFor ] + CRLF NEXT IF Empty( cString ) cString := "No Printer Fonts found" ENDIF MsgInfo( cString, "Printer Fonts" ) RETURN Nil //------------------------------------------------------------------------------ METHOD Button2Click( oSender ) CLASS TForm1 Printer:Run() ::oListbox1:nIndex := Printer:PrinterIndex ::UpdateInfo() RETURN Nil //------------------------------------------------------------------------------ METHOD Button4Click( oSender ) CLASS TForm1 Printer:DocumentSetup() ::Update() ::oListbox1:nIndex := Printer:PrinterIndex ::UpdateInfo() RETURN Nil //------------------------------------------------------------------------------ METHOD Button3Click( oSender ) CLASS TForm1 Printer:PageSetup() ::oListbox1:nIndex := Printer:PrinterIndex ::UpdateInfo() RETURN Nil //------------------------------------------------------------------------------ METHOD Button5Click( oSender ) CLASS TForm1 LOCAL ofrmPreview, oFont, oPen, oBmp, oJpg, oBrush LOCAL n := 100 oFont := TFont():New() oPen := TPen():New( PS_SOLID, 1, clRed ) oBmp := TPicture():Load( "Computer64" ) oJpg := TPicture():Load( "xailer" ) oBrush := TBrush():Create( HS_BDIAGONAL, clRed ) WITH OBJECT oFont :cName := "Arial" :nSize := 18 :lBold := .T. END WITH Printer:lPreview := .T. Printer:cJobTitle := "Xailer: Printer cJobTitle" Printer:StartDoc() Printer:oCanvas:nMapMode := mmHIMETRICS Printer:StartPage() WITH OBJECT Printer:oCanvas :oFont := oFont :oPen := oPen :DrawPicture( {100, 1500, 2000, 2500}, oJpg ) :TextOut( 0, 0, "This first line should be shown partially in almost any printer") :TextOut( 100, 100, "The above line should be cutted on almost any printer") :MoveTo( 0+n, 0+n ) :LineTo( 2100-n, 2970-n ) :LineTo( 0+n, 2970-n ) :LineTo( 0+n, 0+n ) :LineTo( 2100-n, 0+n ) :LineTo( 2100-n, 2970-n ) :lTransparent := .F. :nClrPane := clYellow :oFont:nSize := 14 :TextRect( {1000, 1000, 1500, 1500}, "Xailer printing demo", clBlue ) :lTransparent := .T. :nClrPane := clWhite :nMapMode := mmSIMULCHAR :oFont:nSize := 12 :oFont:lBold := .F. :nTextAlignment := taRIGHT FOR n := 10 TO :TextLines() :TextOut( 4, n, "Xailer printing demo, line: " + LTrim( Str( n ) ), 30, clBlue ) NEXT :nTextAlignment := taLEFT :nMapMode := mmHIMETRICS :nClrPane := clBlack :Rectangle( {700, 200, 800, 300} ) :nClrPane := clGreen :RoundRect( {1100, 200, 1200, 300} ) :DrawPicture( {1100, 200, 1200, 300}, oBmp ) :nClrPane := clBlue :lTransparent := .T. :Rectangle( { 1000, 500, 1700, 800 }, oBrush ) END Printer:EndPage() Printer:StartPage() WITH OBJECT Printer:oCanvas :TextOut( 100, 100, "Second page") END Printer:EndPage() Printer:StartPage() WITH OBJECT Printer:oCanvas :TextOut( 100, 100, "Third page") END Printer:EndPage() Printer:StartPage() WITH OBJECT Printer:oCanvas :TextOut( 100, 100, "Forth page") END Printer:EndPage() Printer:EndDoc() //Printer:Preview() WITH OBJECT Printer:PreviewControl() :nZoomIndex := 8 :oParent:Show() END oFont:Destroy() oBmp:Destroy() oJpg:Destroy() oBrush:Destroy() RETURN Nil //------------------------------------------------------------------------------ METHOD EdiDefPrinterCreate( oSender ) CLASS TForm1 oSender:cText := Printer:cPrinterName + " (" + str( Printer:nPrinterIndex, 1) + ")" RETURN Nil //------------------------------------------------------------------------------ METHOD UpdateInfo() CLASS TForm1 LOCAL aData := {} AAdd( aData, { "Port", Printer:Port() } ) AAdd( aData, { "Server", Printer:ServerName() } ) AAdd( aData, { "Share", Printer:ShareName() } ) AAdd( aData, { "Driver", Printer:DriverName() } ) AAdd( aData, { "Orientation", Str( Printer:nOrientation, 1 ) } ) AAdd( aData, { "Paper type", Str( Printer:nPaperSizeType, 10 ) } ) AAdd( aData, { "Paper width (mm*10)", Str( Printer:nPaperWidth, 10 ) } ) AAdd( aData, { "Paper height (mm*10)", Str( Printer:nPaperLength, 10 ) } ) AAdd( aData, { "Copies", Str( Printer:nCopies, 10 ) } ) AAdd( aData, { "Bin", Str( Printer:nDefaultBin, 10 ) } ) AAdd( aData, { "Color", IIF( Printer:nColor > 0, "Yes", "No" ) } ) AAdd( aData, { "Duplex", IIF( Printer:nDuplex > 0, "Yes", "No" ) } ) AAdd( aData, { "Resolution", Str( Printer:Resolution[ 1 ], 5 ) + " , " + str( Printer:Resolution[ 2 ], 5 ) } ) AAdd( aData, { "Paper Resolution", Str( Printer:PaperRes[ 1 ], 5 ) + " , " + str( Printer:PaperRes[ 2 ], 5 ) } ) AAdd( aData, { "Printeable Paper Size (mm*10)", Str( Printer:PaperSize[ 1 ], 5 ) + " , " + str( Printer:PaperSize[ 2 ], 5 ) } ) AAdd( aData, { "Non printeable offset (mm*10)", Str( Printer:PhysicalOffset[ 1 ], 5 ) + " , " + str( Printer:PhysicalOffset[ 2 ], 5 ) } ) AAdd( aData, { "Collate", IIF( Printer:lCollate, "Yes", "No" ) } ) AAdd( aData, { "Print Quality", Str( Printer:nPrintQuality, 10 ) } ) AAdd( aData, { "Printer State", Str( Printer:nStatus, 10 ) } ) WITH OBJECT ::oBrw :SetArray( aData ) :aCols[ 1 ]:nWidth := 150 :aCols[ 2 ]:nWidth := 190 :GoTop() END RETURN Nil //------------------------------------------------------------------------------ METHOD Button7Click( oSender ) CLASS TForm1 LOCAL aNames, aNumbers LOCAL cString LOCAL nFor aNames := Printer:GetBinSourceNames() aNumbers := Printer:GetBinSourceTypes() cString := "" FOR nFor := 1 TO Len( aNames ) cString += aNames[ nFor ] + " ( " + Ltrim( Str( aNumbers[ nFor ] ) ) + ")" + CRLF NEXT IF Empty( cString ) cString := "No Printer Bins found" ENDIF MsgInfo( cString, "Printer Bins" ) RETURN Nil //------------------------------------------------------------------------------ METHOD Button8Click( oSender ) CLASS TForm1 LOCAL aNames, aSizes, aNumbers LOCAL cString LOCAL nFor aNames := Printer:GetPaperNames() aSizes := Printer:GetPaperSizes() aNumbers := Printer:GetPaperTypes() cString := "" FOR nFor := 1 TO Len( aNames ) cString += aNames[ nFor ] + " [ " + Ltrim( Str( aSizes[ nFor, 1 ] ) ) + " x " +; Ltrim( Str( aSizes[ nFor, 2 ] ) ) + " ]" +; " ( " + Ltrim( Str( aNumbers[ nFor ] ) ) + ")" + CRLF NEXT IF Empty( cString ) cString := "No Printer papers found" ENDIF MsgInfo( cString, "Printer Papers" ) RETURN Nil //------------------------------------------------------------------------------