LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/padmin/source - padialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 407 0.0 %
Date: 2013-07-09 Functions: 0 36 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <stdio.h>
      21             : #include <stdlib.h>
      22             : #include <unistd.h>
      23             : #include <string.h>
      24             : #include <math.h>
      25             : 
      26             : #include "padialog.hrc"
      27             : #include "helper.hxx"
      28             : #include "padialog.hxx"
      29             : #include "adddlg.hxx"
      30             : #include "prtsetup.hxx"
      31             : 
      32             : #include "vcl/msgbox.hxx"
      33             : #include "vcl/print.hxx"
      34             : #include "vcl/gradient.hxx"
      35             : #include "vcl/bitmap.hxx"
      36             : #include "vcl/lineinfo.hxx"
      37             : #include "vcl/svapp.hxx"
      38             : #include "vcl/event.hxx"
      39             : #include "vcl/printerinfomanager.hxx"
      40             : 
      41             : #include "tools/stream.hxx"
      42             : #include "tools/color.hxx"
      43             : #include "tools/urlobj.hxx"
      44             : 
      45             : #include "osl/file.hxx"
      46             : 
      47             : #include "rtl/ustrbuf.hxx"
      48             : #include <sal/macros.h>
      49             : 
      50             : #include "unotools/localedatawrapper.hxx"
      51             : #include "unotools/configitem.hxx"
      52             : #include "unotools/configmgr.hxx"
      53             : 
      54             : #include "com/sun/star/awt/Size.hpp"
      55             : 
      56             : using namespace psp;
      57             : using namespace padmin;
      58             : using namespace osl;
      59             : using namespace com::sun::star;
      60             : using namespace com::sun::star::uno;
      61             : using namespace com::sun::star::beans;
      62             : 
      63             : 
      64           0 : PADialog* PADialog::Create( Window* pParent, sal_Bool bAdmin )
      65             : {
      66           0 :     return new PADialog( pParent, bAdmin );
      67             : }
      68             : 
      69           0 : PADialog::PADialog( Window* pParent, sal_Bool /*bAdmin*/ ) :
      70             :         ModalDialog( pParent, PaResId( RID_PADIALOG ) ),
      71             :         m_aDevicesLB( this, PaResId( RID_PA_LB_DEV ) ),
      72             :         m_aConfPB( this, PaResId( RID_PA_BTN_CONF ) ),
      73             :         m_aRenamePB( this, PaResId( RID_PA_BTN_RENAME ) ),
      74             :         m_aStdPB( this, PaResId( RID_PA_BTN_STD ) ),
      75             :         m_aRemPB( this, PaResId( RID_PA_BTN_DEL ) ),
      76             :         m_aTestPagePB( this, PaResId( RID_PA_TESTPAGE ) ),
      77             :         m_aPrintersFL( this, PaResId( RID_PA_FL_PRINTERS ) ),
      78             :         m_aDriverTxt( this, PaResId( RID_PA_TXT_DRIVER ) ),
      79             :         m_aDriver( this, PaResId( RID_PA_TXT_DRIVER_STRING ) ),
      80             :         m_aLocationTxt( this, PaResId( RID_PA_TXT_LOCATION ) ),
      81             :         m_aLocation( this, PaResId( RID_PA_TXT_LOCATION_STRING ) ),
      82             :         m_aCommandTxt( this, PaResId( RID_PA_TXT_COMMAND ) ),
      83             :         m_aCommand( this, PaResId( RID_PA_TXT_COMMAND_STRING ) ),
      84             :         m_aCommentTxt( this, PaResId( RID_PA_TXT_COMMENT ) ),
      85             :         m_aComment( this, PaResId( RID_PA_TXT_COMMENT_STRING ) ),
      86             :         m_aCUPSFL( this, PaResId( RID_PA_FL_CUPSUSAGE ) ),
      87             :         m_aCUPSCB( this, PaResId( RID_PA_CB_CUPSUSAGE ) ),
      88             :         m_aSepButtonFL( this, PaResId( RID_PA_FL_SEPBUTTON ) ),
      89             :         m_aAddPB( this, PaResId( RID_PA_BTN_ADD ) ),
      90             :         m_aCancelButton( this, PaResId( RID_PA_BTN_CANCEL ) ),
      91             :         m_aDefPrt( PaResId( RID_PA_STR_DEFPRT ) ),
      92             :         m_aRenameStr( PaResId( RID_PA_STR_RENAME ) ),
      93           0 :         m_rPIManager( PrinterInfoManager::get() )
      94             : {
      95           0 :     FreeResource();
      96           0 :     updateSettings();
      97           0 :     Init();
      98           0 : }
      99             : 
     100           0 : void PADialog::updateSettings()
     101             : {
     102           0 :     m_aPrinterImg = Image( BitmapEx( PaResId( RID_BMP_SMALL_PRINTER ) ) );
     103           0 :     m_aFaxImg     = Image( BitmapEx( PaResId( RID_BMP_SMALL_FAX     ) ) );
     104           0 :     m_aPdfImg     = Image( BitmapEx( PaResId( RID_BMP_SMALL_PDF     ) ) );
     105           0 : }
     106             : 
     107           0 : void PADialog::Init()
     108             : {
     109             :     // #i79787# initially ensure printer discovery has ended
     110           0 :     m_rPIManager.checkPrintersChanged( true );
     111           0 :     m_aCUPSCB.Check( m_rPIManager.isCUPSDisabled() );
     112             : 
     113           0 :     UpdateDevice();
     114           0 :     UpdateText();
     115             : 
     116           0 :     m_aRemPB.Enable( sal_False );
     117             : 
     118           0 :     m_aDevicesLB.SetDoubleClickHdl( LINK( this, PADialog, DoubleClickHdl ) );
     119           0 :     m_aDevicesLB.SetSelectHdl( LINK( this, PADialog, SelectHdl ) );
     120           0 :     m_aStdPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
     121           0 :     m_aRemPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
     122           0 :     m_aConfPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
     123           0 :     m_aRenamePB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
     124           0 :     m_aTestPagePB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
     125           0 :     m_aAddPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
     126           0 :     m_aDevicesLB.setDelPressedLink( LINK( this, PADialog, DelPressedHdl ) );
     127           0 :     m_aCUPSCB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
     128             : 
     129             :     // at this point no actual changes will be  written
     130             :     // but the write will have checked whether any writeable config exists
     131           0 :     if( ! m_rPIManager.writePrinterConfig() )
     132             :     {
     133           0 :         m_aAddPB.Enable( sal_False );
     134           0 :         m_aRemPB.Enable( sal_False );
     135           0 :         m_aConfPB.Enable( sal_False );
     136           0 :         m_aRenamePB.Enable( sal_False );
     137           0 :         m_aStdPB.Enable( sal_False );
     138           0 :         m_aCUPSCB.Enable( sal_False );
     139           0 :         ErrorBox aBox( GetParent(), WB_OK | WB_DEF_OK, String( PaResId( RID_ERR_NOWRITE ) ) );
     140           0 :         aBox.Execute();
     141             :     }
     142           0 : }
     143             : 
     144           0 : PADialog::~PADialog()
     145             : {
     146           0 :     m_rPIManager.writePrinterConfig();
     147           0 :     freePadminRC();
     148           0 : }
     149             : 
     150           0 : long PADialog::Notify( NotifyEvent& rEv )
     151             : {
     152           0 :     if( IsVisible() &&
     153           0 :         (rEv.GetType() == EVENT_GETFOCUS || rEv.GetType() == EVENT_LOSEFOCUS )
     154             :       )
     155             :     {
     156           0 :         if( m_rPIManager.checkPrintersChanged( true ) )
     157             :         {
     158           0 :             String aSelectEntry = m_aDevicesLB.GetSelectEntry();
     159           0 :             UpdateDevice();
     160           0 :             UpdateText();
     161           0 :             m_aDevicesLB.SelectEntry( aSelectEntry );
     162             :         }
     163             :     }
     164           0 :     return ModalDialog::Notify( rEv );
     165             : }
     166             : 
     167           0 : void PADialog::DataChanged( const DataChangedEvent& rEv )
     168             : {
     169           0 :     ModalDialog::DataChanged( rEv );
     170           0 :     if( (rEv.GetType() == DATACHANGED_SETTINGS) &&
     171           0 :         (rEv.GetFlags() & SETTINGS_STYLE) )
     172             :     {
     173           0 :         updateSettings();
     174             :         // push the new images into the listbox
     175           0 :         UpdateDevice();
     176             :     }
     177           0 : }
     178             : 
     179           0 : String PADialog::getSelectedDevice()
     180             : {
     181           0 :     int nPos = m_aDevicesLB.GetSelectEntryPos();
     182           0 :     int nLen = (int)(sal_IntPtr)m_aDevicesLB.GetEntryData( nPos );
     183           0 :     return m_aDevicesLB.GetEntry( nPos ).Copy( 0, nLen );
     184             : }
     185             : 
     186           0 : IMPL_LINK( PADialog, DelPressedHdl, ListBox*, pBox )
     187             : {
     188           0 :     if( pBox == &m_aDevicesLB && m_aRemPB.IsEnabled() )
     189           0 :         ClickBtnHdl( &m_aRemPB );
     190           0 :     return 0;
     191             : }
     192             : 
     193           0 : IMPL_LINK( PADialog, ClickBtnHdl, PushButton*, pButton )
     194             : {
     195           0 :     if( pButton == &m_aStdPB )
     196           0 :         UpdateDefPrt();
     197           0 :     else if( pButton == &m_aRemPB && AreYouSure( this, RID_QUERY_REMOVEPRINTER ) )
     198           0 :         RemDevice();
     199           0 :     else if( pButton == &m_aConfPB )
     200           0 :         ConfigureDevice();
     201           0 :     else if( pButton == &m_aRenamePB )
     202           0 :         RenameDevice();
     203           0 :     else if( pButton == &m_aTestPagePB )
     204           0 :         PrintTestPage();
     205           0 :     else if( pButton == &m_aAddPB )
     206           0 :         AddDevice();
     207           0 :     else if( static_cast<Button*>(pButton) == &m_aCUPSCB )
     208             :     {
     209           0 :         m_rPIManager.setCUPSDisabled( m_aCUPSCB.IsChecked() );
     210           0 :             UpdateDevice();
     211           0 :             UpdateText();
     212             :     }
     213             : 
     214           0 :     return 0;
     215             : }
     216             : 
     217           0 : IMPL_LINK( PADialog, DoubleClickHdl, ListBox*, pListBox )
     218             : {
     219           0 :     if( pListBox == &m_aDevicesLB )
     220           0 :         UpdateDefPrt();
     221           0 :     return 0;
     222             : }
     223             : 
     224           0 : IMPL_LINK( PADialog, SelectHdl, ListBox*, pListBox )
     225             : {
     226           0 :     if( pListBox == &m_aDevicesLB )
     227             :     {
     228           0 :         String sSelect = getSelectedDevice();
     229           0 :         String sDefPrt = m_rPIManager.getDefaultPrinter();
     230           0 :         if( sDefPrt == sSelect || ! m_rPIManager.removePrinter( sSelect, true ) )
     231           0 :             m_aRemPB.Enable( sal_False );
     232             :         else
     233           0 :             m_aRemPB.Enable( sal_True );
     234           0 :         UpdateText();
     235             :     }
     236           0 :     return 0;
     237             : }
     238             : 
     239           0 : void PADialog::UpdateDefPrt()
     240             : {
     241           0 :     m_rPIManager.setDefaultPrinter( getSelectedDevice() );
     242             : 
     243           0 :     UpdateDevice();
     244           0 :     UpdateText();
     245             : 
     246           0 :     if( m_aRemPB.HasFocus() )
     247           0 :         m_aDevicesLB.GetFocus();
     248           0 :     m_aRemPB.Enable( sal_False );
     249           0 : }
     250             : 
     251           0 : void PADialog::UpdateText()
     252             : {
     253           0 :     OUString aDev( getSelectedDevice() );
     254           0 :     if( !aDev.isEmpty() )
     255             :     {
     256           0 :         const PrinterInfo& rInfo = m_rPIManager.getPrinterInfo( aDev );
     257             : 
     258           0 :         OUString aDriver = rInfo.m_aPrinterName + " (" + rInfo.m_aDriverName + ")";
     259             : 
     260           0 :         m_aDriver.SetText( aDriver );
     261           0 :         m_aCommand.SetText( rInfo.m_aCommand );
     262           0 :         m_aComment.SetText( rInfo.m_aComment );
     263           0 :         m_aLocation.SetText( rInfo.m_aLocation );
     264             :     }
     265             :     else // nothing selected
     266             :     {
     267           0 :         String aEmpty;
     268           0 :         m_aDriver.SetText( aEmpty );
     269           0 :         m_aCommand.SetText( aEmpty );
     270           0 :         m_aComment.SetText( aEmpty );
     271           0 :         m_aLocation.SetText( aEmpty );
     272           0 :     }
     273           0 : }
     274             : 
     275           0 : static Point project( const Point& rPoint )
     276             : {
     277           0 :     const double angle_x = M_PI / 6.0;
     278           0 :     const double angle_z = M_PI / 6.0;
     279             : 
     280             :     // transform planar coordinates to 3d
     281           0 :     double x = rPoint.X();
     282           0 :     double y = rPoint.Y();
     283             :     //double z = 0;
     284             : 
     285             :     // rotate around X axis
     286           0 :     double x1 = x;
     287           0 :     double y1 = y * cos( angle_x );
     288           0 :     double z1 = y * sin( angle_x );
     289             : 
     290             :     // rotate around Z axis
     291           0 :     double x2 = x1 * cos( angle_z ) + y1 * sin( angle_z );
     292             :     //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
     293           0 :     double z2 = z1;
     294             : 
     295           0 :     return Point( (sal_Int32)x2, (sal_Int32)z2 );
     296             : }
     297             : 
     298           0 : static Color approachColor( const Color& rFrom, const Color& rTo )
     299             : {
     300           0 :     Color aColor;
     301             :     sal_uInt8 nDiff;
     302             :     // approach red
     303           0 :     if( rFrom.GetRed() < rTo.GetRed() )
     304             :     {
     305           0 :         nDiff = rTo.GetRed() - rFrom.GetRed();
     306           0 :         aColor.SetRed( rFrom.GetRed() + ( nDiff < 10 ? nDiff : 10 ) );
     307             :     }
     308           0 :     else if( rFrom.GetRed() > rTo.GetRed() )
     309             :     {
     310           0 :         nDiff = rFrom.GetRed() - rTo.GetRed();
     311           0 :         aColor.SetRed( rFrom.GetRed() - ( nDiff < 10 ? nDiff : 10 ) );
     312             :     }
     313             :     else
     314           0 :         aColor.SetRed( rFrom.GetRed() );
     315             : 
     316             :     // approach Green
     317           0 :     if( rFrom.GetGreen() < rTo.GetGreen() )
     318             :     {
     319           0 :         nDiff = rTo.GetGreen() - rFrom.GetGreen();
     320           0 :         aColor.SetGreen( rFrom.GetGreen() + ( nDiff < 10 ? nDiff : 10 ) );
     321             :     }
     322           0 :     else if( rFrom.GetGreen() > rTo.GetGreen() )
     323             :     {
     324           0 :         nDiff = rFrom.GetGreen() - rTo.GetGreen();
     325           0 :         aColor.SetGreen( rFrom.GetGreen() - ( nDiff < 10 ? nDiff : 10 ) );
     326             :     }
     327             :     else
     328           0 :         aColor.SetGreen( rFrom.GetGreen() );
     329             : 
     330             :     // approach blue
     331           0 :     if( rFrom.GetBlue() < rTo.GetBlue() )
     332             :     {
     333           0 :         nDiff = rTo.GetBlue() - rFrom.GetBlue();
     334           0 :         aColor.SetBlue( rFrom.GetBlue() + ( nDiff < 10 ? nDiff : 10 ) );
     335             :     }
     336           0 :     else if( rFrom.GetBlue() > rTo.GetBlue() )
     337             :     {
     338           0 :         nDiff = rFrom.GetBlue() - rTo.GetBlue();
     339           0 :         aColor.SetBlue( rFrom.GetBlue() - ( nDiff < 10 ? nDiff : 10 ) );
     340             :     }
     341             :     else
     342           0 :         aColor.SetBlue( rFrom.GetBlue() );
     343             : 
     344           0 :     return aColor;
     345             : }
     346             : 
     347             : class SpaPrinterController : public vcl::PrinterController
     348             : {
     349             : public:
     350           0 :     SpaPrinterController( const boost::shared_ptr<Printer>& i_pPrinter )
     351           0 :     : vcl::PrinterController( i_pPrinter )
     352           0 :     {}
     353           0 :     virtual ~SpaPrinterController()
     354           0 :     {}
     355             : 
     356           0 :     virtual int getPageCount() const { return 1; }
     357             :     virtual Sequence< PropertyValue > getPageParameters( int i_nPage ) const;
     358             :     virtual void printPage( int i_nPage ) const;
     359             :     virtual void jobFinished( com::sun::star::view::PrintableState );
     360             : };
     361             : 
     362           0 : Sequence< PropertyValue > SpaPrinterController::getPageParameters( int ) const
     363             : {
     364           0 :     Sequence< PropertyValue > aRet( 1 );
     365             : 
     366           0 :     Size aPageSize( getPrinter()->GetPaperSizePixel() );
     367           0 :     aPageSize = getPrinter()->PixelToLogic( aPageSize, MapMode( MAP_100TH_MM ) );
     368             : 
     369           0 :     awt::Size aSize;
     370           0 :     aSize.Width = aPageSize.Width();
     371           0 :     aSize.Height = aPageSize.Height();
     372           0 :     aRet[0].Value = makeAny(aSize);
     373             : 
     374           0 :     return aRet;
     375             : }
     376             : 
     377           0 : void SpaPrinterController::printPage( int ) const
     378             : {
     379           0 :     const double DELTA = 5.0;
     380             : 
     381           0 :     boost::shared_ptr<Printer> pPrinter( getPrinter() );
     382             : 
     383           0 :     PrinterInfo aInfo( psp::PrinterInfoManager::get().getPrinterInfo( pPrinter->GetName() ) );
     384           0 :     const PPDParser* pPrintParser = aInfo.m_pParser;
     385             : 
     386           0 :     MapMode aMapMode( MAP_100TH_MM );
     387             : 
     388           0 :     Bitmap aButterfly( PaResId( RID_BUTTERFLY ) );
     389             : 
     390           0 :     pPrinter->SetMapMode( aMapMode );
     391             : 
     392           0 :     Size aPaperSize=pPrinter->GetOutputSize();
     393           0 :     Point aCenter( aPaperSize.Width()/2-300,
     394           0 :                    aPaperSize.Height() - aPaperSize.Width()/2 );
     395           0 :     Point aP1( aPaperSize.Width()/48, 0), aP2( aPaperSize.Width()/40, 0 ), aPoint;
     396             : 
     397           0 :     pPrinter->DrawRect( Rectangle( Point( 0,0 ), aPaperSize ) );
     398           0 :     pPrinter->DrawRect( Rectangle( Point( 100,100 ),
     399           0 :                                     Size( aPaperSize.Width()-200,
     400           0 :                                           aPaperSize.Height()-200 ) ) );
     401           0 :     pPrinter->DrawRect( Rectangle( Point( 200,200 ),
     402           0 :                                     Size( aPaperSize.Width()-400,
     403           0 :                                           aPaperSize.Height()-400 ) ) );
     404           0 :     pPrinter->DrawRect( Rectangle( Point( 300,300 ),
     405           0 :                                     Size( aPaperSize.Width()-600,
     406           0 :                                           aPaperSize.Height()-600 ) ) );
     407             : 
     408           0 :     Font aFont( String( "Courier" ), Size( 0, 400 ) );
     409           0 :     aFont.SetWeight( WEIGHT_NORMAL );
     410           0 :     aFont.SetItalic( ITALIC_NONE );
     411           0 :     pPrinter->SetFont( aFont );
     412             : 
     413           0 :     OUStringBuffer aPrintText(1024);
     414           0 :     long nWidth = 0, nMaxWidth = 0;
     415           0 :     String aToken;
     416             : 
     417             :     static const struct
     418             :     {
     419             :             const char* const pDirect;
     420             :             sal_uInt16 nResId;
     421             :     } aResIds[] =
     422             :         {
     423             :             { NULL, RID_TXT_TESTPAGE_NAME },
     424             :             { NULL, RID_TXT_TESTPAGE_MODEL },
     425             :             { "PPD", 0 },
     426             :             { NULL, RID_TXT_TESTPAGE_QUEUE },
     427             :             { NULL, RID_TXT_TESTPAGE_COMMENT },
     428             :             { NULL, RID_TXT_TESTPAGE_DATE },
     429             :             { NULL, RID_TXT_TESTPAGE_TIME }
     430             :         };
     431             : 
     432           0 :     for( unsigned int i = 0; i < SAL_N_ELEMENTS(aResIds); i++ )
     433             :     {
     434           0 :         if( aResIds[i].pDirect )
     435           0 :             aToken = OUString::createFromAscii(aResIds[i].pDirect);
     436             :         else
     437           0 :             aToken = String( PaResId( aResIds[i].nResId ) );
     438           0 :         nMaxWidth = ( nWidth = pPrinter->GetTextWidth( aToken ) ) > nMaxWidth ? nWidth : nMaxWidth;
     439           0 :         aPrintText.append( aToken );
     440           0 :         aPrintText.append( (sal_Unicode)'\n' );
     441             :     };
     442             : 
     443           0 :     pPrinter->DrawText( Rectangle( Point( 1000, 1000 ),
     444           0 :                                     Size( aPaperSize.Width() - 2000,
     445           0 :                                           aPaperSize.Height() - 4000 ) ),
     446             :                           aPrintText.makeStringAndClear(),
     447           0 :                           TEXT_DRAW_MULTILINE );
     448             : 
     449           0 :     AllSettings aSettings( Application::GetSettings() );
     450           0 :     const LocaleDataWrapper& rLocaleWrapper( aSettings.GetLocaleDataWrapper() );
     451             : 
     452           0 :     aPrintText.appendAscii( ": " );
     453           0 :     aPrintText.append( pPrinter->GetName() );
     454           0 :     aPrintText.appendAscii( "\n: " );
     455           0 :     if( pPrintParser )
     456           0 :         aPrintText.append( pPrintParser->getPrinterName() );
     457           0 :     aPrintText.appendAscii( "\n: " );
     458           0 :     INetURLObject aDriverPath( pPrintParser ? pPrintParser->getFilename() : String( "<undef>" ),
     459           0 :                                INET_PROT_FILE, INetURLObject::ENCODE_ALL );
     460           0 :     aPrintText.append( aDriverPath.GetName() );
     461           0 :     aPrintText.appendAscii( "\n: " );
     462           0 :     aPrintText.append( aInfo.m_aCommand );
     463           0 :     aPrintText.appendAscii( "\n: " );
     464           0 :     aPrintText.append( aInfo.m_aComment );
     465           0 :     aPrintText.appendAscii( "\n: " );
     466           0 :     aPrintText.append( rLocaleWrapper.getDate( Date( Date::SYSTEM ) ) );
     467           0 :     aPrintText.appendAscii( "\n: " );
     468           0 :     aPrintText.append( rLocaleWrapper.getTime( Time( Time::SYSTEM ) ) );
     469             : 
     470           0 :     pPrinter->DrawText( Rectangle( Point( 1100 + nMaxWidth, 1000 ),
     471           0 :                                     Size( aPaperSize.Width() - 2100 - nMaxWidth,
     472           0 :                                           aPaperSize.Height() - 4000 ) ),
     473             :                          aPrintText.makeStringAndClear(),
     474           0 :                          TEXT_DRAW_MULTILINE );
     475             : 
     476           0 :     pPrinter->DrawBitmap( Point( aPaperSize.Width() - 4000, 1000 ),
     477             :                            Size( 3000,3000 ),
     478           0 :                            aButterfly );
     479           0 :     pPrinter->SetFillColor();
     480           0 :     pPrinter->DrawRect( Rectangle( Point( aPaperSize.Width() - 4000, 1000 ),
     481           0 :                                      Size( 3000,3000 ) ) );
     482             : 
     483           0 :     Color aWhite( 0xff, 0xff, 0xff );
     484           0 :     Color aBlack( 0, 0, 0 );
     485           0 :     Color aLightRed( 0xff, 0, 0 );
     486           0 :     Color aDarkRed( 0x40, 0, 0 );
     487           0 :     Color aLightBlue( 0, 0, 0xff );
     488           0 :     Color aDarkBlue( 0,0,0x40 );
     489           0 :     Color aLightGreen( 0, 0xff, 0 );
     490           0 :     Color aDarkGreen( 0, 0x40, 0 );
     491             : 
     492           0 :     Gradient aGradient( GradientStyle_LINEAR, aBlack, aWhite );
     493           0 :     aGradient.SetAngle( 900 );
     494           0 :     pPrinter->DrawGradient( Rectangle( Point( 1000, 5500 ),
     495           0 :                                         Size( aPaperSize.Width() - 2000,
     496           0 :                                               500 ) ), aGradient );
     497           0 :     aGradient.SetStartColor( aDarkRed );
     498           0 :     aGradient.SetEndColor( aLightBlue );
     499           0 :     pPrinter->DrawGradient( Rectangle( Point( 1000, 6300 ),
     500           0 :                                         Size( aPaperSize.Width() - 2000,
     501           0 :                                               500 ) ), aGradient );
     502           0 :     aGradient.SetStartColor( aDarkBlue );
     503           0 :     aGradient.SetEndColor( aLightGreen );
     504           0 :     pPrinter->DrawGradient( Rectangle( Point( 1000, 7100 ),
     505           0 :                                         Size( aPaperSize.Width() - 2000,
     506           0 :                                               500 ) ), aGradient );
     507           0 :     aGradient.SetStartColor( aDarkGreen );
     508           0 :     aGradient.SetEndColor( aLightRed );
     509           0 :     pPrinter->DrawGradient( Rectangle( Point( 1000, 7900 ),
     510           0 :                                         Size( aPaperSize.Width() - 2000,
     511           0 :                                               500 ) ), aGradient );
     512             : 
     513             : 
     514             : 
     515           0 :     LineInfo aLineInfo( LINE_SOLID, 200 );
     516           0 :     double sind = sin( DELTA*M_PI/180.0 );
     517           0 :     double cosd = cos( DELTA*M_PI/180.0 );
     518           0 :     double factor = 1 + (DELTA/1000.0);
     519           0 :     int n=0;
     520           0 :     Color aLineColor( 0, 0, 0 );
     521           0 :     Color aApproachColor( 0, 0, 200 );
     522           0 :     while ( aP2.X() < aCenter.X() && n++ < 680 )
     523             :     {
     524           0 :         aLineInfo.SetWidth( n/3 );
     525           0 :         aLineColor = approachColor( aLineColor, aApproachColor );
     526           0 :         pPrinter->SetLineColor( aLineColor );
     527             : 
     528             :         // switch aproach color
     529           0 :         if( aApproachColor.IsRGBEqual( aLineColor ) )
     530             :         {
     531           0 :             if( aApproachColor.GetRed() )
     532           0 :                 aApproachColor = Color( 0, 0, 200 );
     533           0 :             else if( aApproachColor.GetGreen() )
     534           0 :                 aApproachColor = Color( 200, 0, 0 );
     535             :             else
     536           0 :                 aApproachColor = Color( 0, 200, 0 );
     537             :         }
     538             : 
     539           0 :         pPrinter->DrawLine( project( aP1 ) + aCenter,
     540           0 :                              project( aP2 ) + aCenter,
     541           0 :                              aLineInfo );
     542           0 :         aPoint.X() = (int)((((double)aP1.X())*cosd - ((double)aP1.Y())*sind)*factor);
     543           0 :         aPoint.Y() = (int)((((double)aP1.Y())*cosd + ((double)aP1.X())*sind)*factor);
     544           0 :         aP1 = aPoint;
     545           0 :         aPoint.X() = (int)((((double)aP2.X())*cosd - ((double)aP2.Y())*sind)*factor);
     546           0 :         aPoint.Y() = (int)((((double)aP2.Y())*cosd + ((double)aP2.X())*sind)*factor);
     547           0 :         aP2 = aPoint;
     548           0 :     }
     549             : #if (OSL_DEBUG_LEVEL > 1) || defined DBG_UTIL
     550             :     fprintf( stderr, "%d lines\n",n );
     551             : #endif
     552           0 : }
     553             : 
     554           0 : void SpaPrinterController::jobFinished( com::sun::star::view::PrintableState )
     555             : {
     556           0 :     String aInfoString( PaResId( RID_PA_TXT_TESTPAGE_PRINTED ) );
     557           0 :     InfoBox aInfoBox( NULL, aInfoString );
     558           0 :     aInfoBox.SetText( String( PaResId( RID_BXT_TESTPAGE ) ) );
     559           0 :     aInfoBox.Execute();
     560           0 : }
     561             : 
     562           0 : void PADialog::PrintTestPage()
     563             : {
     564           0 :     const OUString sPrinter( getSelectedDevice() );
     565             : 
     566           0 :     boost::shared_ptr<Printer> pPrinter( new Printer( sPrinter ) );
     567             : 
     568           0 :     if( pPrinter->GetName() != sPrinter )
     569             :     {
     570           0 :         String aString( PaResId( RID_ERR_NOPRINTER ) );
     571           0 :         aString.SearchAndReplaceAscii( "%s", sPrinter );
     572             : 
     573           0 :         ErrorBox aErrorBox( this, WB_OK | WB_DEF_OK, aString );
     574           0 :         aErrorBox.SetText( String( PaResId( RID_BXT_ENVIRONMENT ) ) );
     575           0 :         aErrorBox.Execute();
     576           0 :         return;
     577             :     }
     578             : 
     579           0 :     boost::shared_ptr<vcl::PrinterController> pController( new SpaPrinterController( pPrinter ) );
     580           0 :     JobSetup aJobSetup( pPrinter->GetJobSetup() );
     581           0 :     aJobSetup.SetValue( "IsQuickJob", "true" );
     582           0 :     Printer::PrintJob( pController, aJobSetup );
     583             : }
     584             : 
     585           0 : void PADialog::AddDevice()
     586             : {
     587           0 :     AddPrinterDialog aDlg( this );
     588             : 
     589           0 :     if( aDlg.Execute() )
     590           0 :         UpdateDevice();
     591           0 : }
     592             : 
     593           0 : void PADialog::RemDevice()
     594             : {
     595           0 :     String aPrinter( getSelectedDevice() );
     596           0 :     String aDefPrinter( m_rPIManager.getDefaultPrinter() );
     597             :     // do not remove the default printer
     598           0 :     if( aPrinter.Equals( aDefPrinter ) )
     599           0 :         return;
     600             : 
     601           0 :     if( ! m_rPIManager.removePrinter( aPrinter ) )
     602             :     {
     603           0 :         String aText( PaResId( RID_ERR_PRINTERNOTREMOVABLE ) );
     604           0 :         aText.SearchAndReplace( String( "%s" ), aPrinter );
     605           0 :         ErrorBox aBox( this, WB_OK | WB_DEF_OK, aText );
     606           0 :         aBox.Execute();
     607           0 :         return;
     608             :     }
     609           0 :     m_aPrinters.remove( aPrinter );
     610             : 
     611           0 :     m_aDevicesLB.RemoveEntry( m_aDevicesLB.GetSelectEntryPos() );
     612           0 :     for( int i=0; i < m_aDevicesLB.GetEntryCount(); i++ )
     613             :     {
     614           0 :         if( m_aDevicesLB.GetEntry( i ).CompareTo( aDefPrinter, aDefPrinter.Len() ) == COMPARE_EQUAL )
     615             :         {
     616           0 :             m_aDevicesLB.SelectEntryPos( i, sal_True );
     617           0 :             UpdateText();
     618           0 :             break;
     619             :         }
     620             :     }
     621             : 
     622           0 :     m_aDevicesLB.GetFocus();
     623             : 
     624           0 :     if( m_aDevicesLB.GetEntryCount() < 2 )
     625           0 :         m_aRemPB.Enable( sal_False );
     626             : }
     627             : 
     628           0 : void PADialog::ConfigureDevice()
     629             : {
     630           0 :     String aPrinter( getSelectedDevice() );
     631             : 
     632           0 :     if( ! aPrinter.Len() )
     633           0 :         return;
     634             : 
     635           0 :     PrinterInfo aInfo( m_rPIManager.getPrinterInfo( aPrinter ) );
     636           0 :     RTSDialog aDialog( aInfo, aPrinter, true, this );
     637             : 
     638           0 :     if( aDialog.Execute() )
     639           0 :         m_rPIManager.changePrinterInfo( aPrinter, aDialog.getSetup() );
     640             : 
     641           0 :     UpdateText();
     642             : }
     643             : 
     644           0 : void PADialog::RenameDevice()
     645             : {
     646           0 :     String aPrinter( getSelectedDevice() );
     647           0 :     OUString aOldPrinter( aPrinter );
     648             : 
     649           0 :     if( ! aPrinter.Len() )
     650           0 :         return;
     651             : 
     652           0 :     String aTmpString( PaResId( RID_QRY_PRTNAME ) );
     653             :     QueryString aQuery( this,
     654             :                         aTmpString,
     655           0 :                         aPrinter );
     656           0 :     aQuery.SetText( m_aRenameStr );
     657           0 :     aQuery.Execute();
     658             : 
     659           0 :     if( aPrinter.Len() )
     660             :     {
     661           0 :         PrinterInfo aInfo( m_rPIManager.getPrinterInfo( aOldPrinter ) );
     662           0 :         aInfo.m_aPrinterName = aPrinter;
     663           0 :         if( m_rPIManager.addPrinter( aPrinter, aInfo.m_aDriverName ) )
     664             :         {
     665           0 :             bool bWasDefault = m_rPIManager.getDefaultPrinter() == aOldPrinter;
     666           0 :             m_aPrinters.push_back( aPrinter );
     667           0 :             if( m_rPIManager.removePrinter( aOldPrinter ) )
     668           0 :                 m_aPrinters.remove( aOldPrinter );
     669           0 :             m_rPIManager.changePrinterInfo( aPrinter, aInfo );
     670           0 :             if( bWasDefault )
     671             :             {
     672           0 :                 m_rPIManager.setDefaultPrinter( aPrinter );
     673           0 :                 UpdateDefPrt();
     674             :             }
     675           0 :             UpdateDevice();
     676           0 :         }
     677           0 :     }
     678             : }
     679             : 
     680           0 : void PADialog::UpdateDevice()
     681             : {
     682           0 :     m_aDevicesLB.Clear();
     683             : 
     684           0 :     m_rPIManager.listPrinters( m_aPrinters );
     685           0 :     ::std::list< OUString >::iterator it;
     686           0 :     for( it = m_aPrinters.begin(); it != m_aPrinters.end(); ++it )
     687             :     {
     688           0 :         const PrinterInfo& rInfo( m_rPIManager.getPrinterInfo( *it ) );
     689           0 :         sal_Int32 nIndex = 0;
     690           0 :         bool bAutoQueue = false;
     691           0 :         bool bFax = false;
     692           0 :         bool bPdf = false;
     693           0 :         while( nIndex != -1 && ! bAutoQueue )
     694             :         {
     695           0 :             OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
     696           0 :             if( !aToken.isEmpty() )
     697             :             {
     698           0 :                 if( aToken.compareToAscii( "autoqueue" ) == 0 )
     699           0 :                     bAutoQueue = true;
     700           0 :                 else if( aToken.startsWith("pdf=") )
     701           0 :                     bPdf = true;
     702           0 :                 else if( aToken.startsWith("fax") )
     703           0 :                     bFax = true;
     704             :             }
     705           0 :         }
     706           0 :         if( bAutoQueue )
     707           0 :             continue;
     708             : 
     709           0 :         OUString aEntry( *it );
     710           0 :         if( *it == m_rPIManager.getDefaultPrinter() )
     711             :         {
     712           0 :             aEntry += " (" + OUString( m_aDefPrt ) + ")";
     713             :         }
     714             :         int nPos =
     715             :             m_aDevicesLB.InsertEntry( aEntry,
     716             :                                       bFax ? m_aFaxImg :
     717             :                                       bPdf ? m_aPdfImg : m_aPrinterImg
     718           0 :                                       );
     719           0 :         m_aDevicesLB.SetEntryData( nPos, (void*)(sal_IntPtr)it->getLength() );
     720           0 :         if( *it == m_rPIManager.getDefaultPrinter() )
     721             :         {
     722           0 :             m_aDevicesLB.SelectEntryPos( nPos );
     723           0 :             UpdateText();
     724             :         }
     725           0 :     }
     726           0 : }
     727             : 
     728             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10