merge the formfield patch from ooo-build
[ooovba.git] / padmin / source / padialog.cxx
blob9cb16c9f2274ba81fd3e58d5f1a102c00a91d26d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: padialog.cxx,v $
10 * $Revision: 1.25 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <string.h>
35 #include <math.h>
37 #include "tools/urlobj.hxx"
39 #ifndef FONTCONFIG_FONTS
40 #include "padialog.hrc"
41 #endif
42 #include "fontentry.hxx"
43 #include "helper.hxx"
44 #include "padialog.hxx"
45 #include "adddlg.hxx"
46 #include "prtsetup.hxx"
48 #include "vcl/msgbox.hxx"
49 #include "vcl/print.hxx"
50 #include "vcl/gradient.hxx"
51 #include "vcl/bitmap.hxx"
52 #include "vcl/lineinfo.hxx"
53 #include "vcl/svapp.hxx"
54 #include "vcl/event.hxx"
55 #include "vcl/printerinfomanager.hxx"
57 #include "tools/stream.hxx"
58 #include "tools/color.hxx"
60 #include "osl/file.hxx"
62 #include "rtl/ustrbuf.hxx"
64 #include "unotools/localedatawrapper.hxx"
65 #include "unotools/configitem.hxx"
66 #include "unotools/configmgr.hxx"
67 using namespace psp;
68 using namespace rtl;
69 using namespace padmin;
70 using namespace osl;
71 using namespace com::sun::star::uno;
73 PADialog* PADialog::Create( Window* pParent, BOOL bAdmin )
75 return new PADialog( pParent, bAdmin );
78 PADialog::PADialog( Window* pParent, BOOL /*bAdmin*/ ) :
79 ModalDialog( pParent, PaResId( RID_PADIALOG ) ),
80 m_aDevicesLB( this, PaResId( RID_PA_LB_DEV ) ),
81 m_aConfPB( this, PaResId( RID_PA_BTN_CONF ) ),
82 m_aRenamePB( this, PaResId( RID_PA_BTN_RENAME ) ),
83 m_aStdPB( this, PaResId( RID_PA_BTN_STD ) ),
84 m_aRemPB( this, PaResId( RID_PA_BTN_DEL ) ),
85 m_aTestPagePB( this, PaResId( RID_PA_TESTPAGE ) ),
86 m_aPrintersFL( this, PaResId( RID_PA_FL_PRINTERS ) ),
87 m_aDriverTxt( this, PaResId( RID_PA_TXT_DRIVER ) ),
88 m_aDriver( this, PaResId( RID_PA_TXT_DRIVER_STRING ) ),
89 m_aLocationTxt( this, PaResId( RID_PA_TXT_LOCATION ) ),
90 m_aLocation( this, PaResId( RID_PA_TXT_LOCATION_STRING ) ),
91 m_aCommandTxt( this, PaResId( RID_PA_TXT_COMMAND ) ),
92 m_aCommand( this, PaResId( RID_PA_TXT_COMMAND_STRING ) ),
93 m_aCommentTxt( this, PaResId( RID_PA_TXT_COMMENT ) ),
94 m_aComment( this, PaResId( RID_PA_TXT_COMMENT_STRING ) ),
95 m_aCUPSFL( this, PaResId( RID_PA_FL_CUPSUSAGE ) ),
96 m_aCUPSCB( this, PaResId( RID_PA_CB_CUPSUSAGE ) ),
97 m_aSepButtonFL( this, PaResId( RID_PA_FL_SEPBUTTON ) ),
98 m_aAddPB( this, PaResId( RID_PA_BTN_ADD ) ),
99 #ifndef FONTCONFIG_FONTS
100 m_aFontsPB( this, PaResId( RID_PA_BTN_FONTS ) ),
101 #endif
102 m_aCancelButton( this, PaResId( RID_PA_BTN_CANCEL ) ),
103 m_aDefPrt( PaResId( RID_PA_STR_DEFPRT ) ),
104 m_aRenameStr( PaResId( RID_PA_STR_RENAME ) ),
105 m_pPrinter( 0 ),
106 m_rPIManager( PrinterInfoManager::get() )
108 FreeResource();
109 updateSettings();
110 Init();
113 void PADialog::updateSettings()
115 if( ! GetDisplayBackground().GetColor().IsDark() )
117 m_aPrinterImg = Image( BitmapEx( PaResId( RID_BMP_SMALL_PRINTER ) ) );
118 m_aFaxImg = Image( BitmapEx( PaResId( RID_BMP_SMALL_FAX ) ) );
119 m_aPdfImg = Image( BitmapEx( PaResId( RID_BMP_SMALL_PDF ) ) );
121 else
123 m_aPrinterImg = Image( BitmapEx( PaResId( RID_BMP_SMALL_PRINTER_HC ) ) );
124 m_aFaxImg = Image( BitmapEx( PaResId( RID_BMP_SMALL_FAX_HC ) ) );
125 m_aPdfImg = Image( BitmapEx( PaResId( RID_BMP_SMALL_PDF_HC ) ) );
129 void PADialog::Init()
131 // #i79787# initially ensure printer discovery has ended
132 m_rPIManager.checkPrintersChanged( true );
133 m_aCUPSCB.Check( m_rPIManager.isCUPSDisabled() );
135 UpdateDevice();
136 UpdateText();
138 m_aRemPB.Enable( FALSE );
140 m_aDevicesLB.SetDoubleClickHdl( LINK( this, PADialog, DoubleClickHdl ) );
141 m_aDevicesLB.SetSelectHdl( LINK( this, PADialog, SelectHdl ) );
142 m_aStdPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
143 m_aRemPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
144 m_aConfPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
145 m_aRenamePB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
146 m_aTestPagePB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
147 m_aAddPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
148 m_aDevicesLB.setDelPressedLink( LINK( this, PADialog, DelPressedHdl ) );
149 m_aCUPSCB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
151 #ifndef FONTCONFIG_FONTS
152 m_aFontsPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
153 ::psp::PrintFontManager& rFontManager( ::psp::PrintFontManager::get() );
154 if( ! rFontManager.checkImportPossible() )
155 m_aFontsPB.Enable( FALSE );
156 #endif
159 PADialog::~PADialog()
161 m_rPIManager.writePrinterConfig();
162 freePadminRC();
165 long PADialog::Notify( NotifyEvent& rEv )
167 if( IsVisible() &&
168 (rEv.GetType() == EVENT_GETFOCUS || rEv.GetType() == EVENT_LOSEFOCUS )
171 if( m_rPIManager.checkPrintersChanged( true ) )
173 String aSelectEntry = m_aDevicesLB.GetSelectEntry();
174 UpdateDevice();
175 UpdateText();
176 m_aDevicesLB.SelectEntry( aSelectEntry );
179 return ModalDialog::Notify( rEv );
182 void PADialog::DataChanged( const DataChangedEvent& rEv )
184 ModalDialog::DataChanged( rEv );
185 if( (rEv.GetType() == DATACHANGED_SETTINGS) &&
186 (rEv.GetFlags() & SETTINGS_STYLE) )
188 updateSettings();
189 // push the new images into the listbox
190 UpdateDevice();
194 String PADialog::getSelectedDevice()
196 int nPos = m_aDevicesLB.GetSelectEntryPos();
197 int nLen = (int)(sal_IntPtr)m_aDevicesLB.GetEntryData( nPos );
198 return m_aDevicesLB.GetEntry( nPos ).Copy( 0, nLen );
201 IMPL_LINK( PADialog, DelPressedHdl, ListBox*, pBox )
203 if( pBox == &m_aDevicesLB && m_aRemPB.IsEnabled() )
204 ClickBtnHdl( &m_aRemPB );
205 return 0;
208 IMPL_LINK( PADialog, ClickBtnHdl, PushButton*, pButton )
210 if( pButton == &m_aStdPB )
211 UpdateDefPrt();
212 else if( pButton == &m_aRemPB && AreYouSure( this, RID_QUERY_REMOVEPRINTER ) )
213 RemDevice();
214 else if( pButton == &m_aConfPB )
215 ConfigureDevice();
216 else if( pButton == &m_aRenamePB )
217 RenameDevice();
218 else if( pButton == &m_aTestPagePB )
219 PrintTestPage();
220 else if( pButton == &m_aAddPB )
221 AddDevice();
222 #ifndef FONTCONFIG_FONTS
223 else if( pButton == &m_aFontsPB )
225 FontNameDlg aDialog( this );
226 aDialog.Execute();
228 #endif
229 else if( static_cast<Button*>(pButton) == &m_aCUPSCB )
231 m_rPIManager.setCUPSDisabled( m_aCUPSCB.IsChecked() );
232 UpdateDevice();
233 UpdateText();
236 return 0;
239 IMPL_LINK( PADialog, DoubleClickHdl, ListBox*, pListBox )
241 if( pListBox == &m_aDevicesLB )
242 UpdateDefPrt();
243 return 0;
246 IMPL_LINK( PADialog, SelectHdl, ListBox*, pListBox )
248 if( pListBox == &m_aDevicesLB )
250 String sSelect = getSelectedDevice();
251 String sDefPrt = m_rPIManager.getDefaultPrinter();
252 if( sDefPrt == sSelect || ! m_rPIManager.removePrinter( sSelect, true ) )
253 m_aRemPB.Enable( FALSE );
254 else
255 m_aRemPB.Enable( TRUE );
256 UpdateText();
258 return 0;
261 IMPL_LINK( PADialog, EndPrintHdl, void*, EMPTYARG )
263 String aInfoString( PaResId( RID_PA_TXT_TESTPAGE_PRINTED ) );
264 InfoBox aInfoBox( this, aInfoString );
265 aInfoBox.SetText( String( PaResId( RID_BXT_TESTPAGE ) ) );
266 aInfoBox.Execute();
268 delete m_pPrinter;
269 m_pPrinter = NULL;
270 return 0;
273 void PADialog::UpdateDefPrt()
275 m_rPIManager.setDefaultPrinter( getSelectedDevice() );
277 UpdateDevice();
278 UpdateText();
280 if( m_aRemPB.HasFocus() )
281 m_aDevicesLB.GetFocus();
282 m_aRemPB.Enable( FALSE );
285 void PADialog::UpdateText()
287 OUString aDev( getSelectedDevice() );
288 if( aDev.getLength() )
290 const PrinterInfo& rInfo = m_rPIManager.getPrinterInfo( aDev );
291 String aDriver( rInfo.m_aPrinterName );
292 aDriver.AppendAscii( " (" );
293 aDriver += String( rInfo.m_aDriverName );
294 aDriver.Append( ')' );
295 m_aDriver.SetText( aDriver );
296 m_aCommand.SetText( rInfo.m_aCommand );
297 m_aComment.SetText( rInfo.m_aComment );
298 m_aLocation.SetText( rInfo.m_aLocation );
300 else // nothing selected
302 String aEmpty;
303 m_aDriver.SetText( aEmpty );
304 m_aCommand.SetText( aEmpty );
305 m_aComment.SetText( aEmpty );
306 m_aLocation.SetText( aEmpty );
310 static Point project( const Point& rPoint )
312 const double angle_x = M_PI / 6.0;
313 const double angle_z = M_PI / 6.0;
315 // transform planar coordinates to 3d
316 double x = rPoint.X();
317 double y = rPoint.Y();
318 //double z = 0;
320 // rotate around X axis
321 double x1 = x;
322 double y1 = y * cos( angle_x );
323 double z1 = y * sin( angle_x );
325 // rotate around Z axis
326 double x2 = x1 * cos( angle_z ) + y1 * sin( angle_z );
327 //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
328 double z2 = z1;
330 return Point( (sal_Int32)x2, (sal_Int32)z2 );
333 static Color approachColor( const Color& rFrom, const Color& rTo )
335 Color aColor;
336 UINT8 nDiff;
337 // approach red
338 if( rFrom.GetRed() < rTo.GetRed() )
340 nDiff = rTo.GetRed() - rFrom.GetRed();
341 aColor.SetRed( rFrom.GetRed() + ( nDiff < 10 ? nDiff : 10 ) );
343 else if( rFrom.GetRed() > rTo.GetRed() )
345 nDiff = rFrom.GetRed() - rTo.GetRed();
346 aColor.SetRed( rFrom.GetRed() - ( nDiff < 10 ? nDiff : 10 ) );
348 else
349 aColor.SetRed( rFrom.GetRed() );
351 // approach Green
352 if( rFrom.GetGreen() < rTo.GetGreen() )
354 nDiff = rTo.GetGreen() - rFrom.GetGreen();
355 aColor.SetGreen( rFrom.GetGreen() + ( nDiff < 10 ? nDiff : 10 ) );
357 else if( rFrom.GetGreen() > rTo.GetGreen() )
359 nDiff = rFrom.GetGreen() - rTo.GetGreen();
360 aColor.SetGreen( rFrom.GetGreen() - ( nDiff < 10 ? nDiff : 10 ) );
362 else
363 aColor.SetGreen( rFrom.GetGreen() );
365 // approach blue
366 if( rFrom.GetBlue() < rTo.GetBlue() )
368 nDiff = rTo.GetBlue() - rFrom.GetBlue();
369 aColor.SetBlue( rFrom.GetBlue() + ( nDiff < 10 ? nDiff : 10 ) );
371 else if( rFrom.GetBlue() > rTo.GetBlue() )
373 nDiff = rFrom.GetBlue() - rTo.GetBlue();
374 aColor.SetBlue( rFrom.GetBlue() - ( nDiff < 10 ? nDiff : 10 ) );
376 else
377 aColor.SetBlue( rFrom.GetBlue() );
379 return aColor;
382 #define DELTA 5.0
383 void PADialog::PrintTestPage()
385 if( m_pPrinter ) // already printing; user pressed button twice
386 return;
388 String sPrinter( getSelectedDevice() );
390 m_pPrinter = new Printer( sPrinter );
392 PrinterInfo aInfo( m_rPIManager.getPrinterInfo( sPrinter ) );
393 const PPDParser* pPrintParser = aInfo.m_pParser;
395 MapMode aMapMode( MAP_100TH_MM );
397 Bitmap aButterfly( PaResId( RID_BUTTERFLY ) );
399 m_pPrinter->SetMapMode( aMapMode );
400 m_pPrinter->SetEndPrintHdl( LINK( this, PADialog, EndPrintHdl ) );
402 Any aRet = utl::ConfigManager::GetDirectConfigProperty( utl::ConfigManager::PRODUCTNAME );
403 OUString aJobName;
404 aRet >>= aJobName;
406 aJobName = aJobName + OUString( RTL_CONSTASCII_USTRINGPARAM( " Testpage" ) );
407 if( m_pPrinter->GetName() != sPrinter || ! m_pPrinter->StartJob( aJobName ) )
409 String aString( PaResId( RID_ERR_NOPRINTER ) );
410 aString.SearchAndReplaceAscii( "%s", sPrinter );
412 ErrorBox aErrorBox( this, WB_OK | WB_DEF_OK, aString );
413 aErrorBox.SetText( String( PaResId( RID_BXT_ENVIRONMENT ) ) );
414 aErrorBox.Execute();
415 delete m_pPrinter;
416 m_pPrinter = 0;
417 return;
419 m_pPrinter->StartPage();
421 Size aPaperSize=m_pPrinter->GetOutputSize();
422 Point aCenter( aPaperSize.Width()/2-300,
423 aPaperSize.Height() - aPaperSize.Width()/2 );
424 Point aP1( aPaperSize.Width()/48, 0), aP2( aPaperSize.Width()/40, 0 ), aPoint;
426 m_pPrinter->DrawRect( Rectangle( Point( 0,0 ), aPaperSize ) );
427 m_pPrinter->DrawRect( Rectangle( Point( 100,100 ),
428 Size( aPaperSize.Width()-200,
429 aPaperSize.Height()-200 ) ) );
430 m_pPrinter->DrawRect( Rectangle( Point( 200,200 ),
431 Size( aPaperSize.Width()-400,
432 aPaperSize.Height()-400 ) ) );
433 m_pPrinter->DrawRect( Rectangle( Point( 300,300 ),
434 Size( aPaperSize.Width()-600,
435 aPaperSize.Height()-600 ) ) );
437 Font aFont( m_pPrinter->GetFont() );
438 aFont.SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Courier" ) ) );
439 aFont.SetWeight( WEIGHT_NORMAL );
440 aFont.SetItalic( ITALIC_NONE );
441 m_pPrinter->SetFont( aFont );
443 OUStringBuffer aPrintText(1024);
444 long nWidth = 0, nMaxWidth = 0;
445 String aToken;
447 static const struct
449 const char* const pDirect;
450 USHORT nResId;
451 } aResIds[] =
453 { NULL, RID_TXT_TESTPAGE_NAME },
454 { NULL, RID_TXT_TESTPAGE_MODEL },
455 { "PPD", 0 },
456 { NULL, RID_TXT_TESTPAGE_QUEUE },
457 { NULL, RID_TXT_TESTPAGE_COMMENT },
458 { NULL, RID_TXT_TESTPAGE_DATE },
459 { NULL, RID_TXT_TESTPAGE_TIME }
462 for( unsigned int i = 0; i < sizeof(aResIds)/sizeof(aResIds[0]); i++ )
464 if( aResIds[i].pDirect )
465 aToken = String::CreateFromAscii( aResIds[i].pDirect );
466 else
467 aToken = String( PaResId( aResIds[i].nResId ) );
468 nMaxWidth = ( nWidth = m_pPrinter->GetTextWidth( aToken ) ) > nMaxWidth ? nWidth : nMaxWidth;
469 aPrintText.append( aToken );
470 aPrintText.append( (sal_Unicode)'\n' );
473 m_pPrinter->DrawText( Rectangle( Point( 1000, 2000 ),
474 Size( aPaperSize.Width() - 2000,
475 aPaperSize.Height() - 4000 ) ),
476 aPrintText.makeStringAndClear(),
477 TEXT_DRAW_MULTILINE );
479 AllSettings aSettings( Application::GetSettings() );
480 const LocaleDataWrapper& rLocaleWrapper( aSettings.GetLocaleDataWrapper() );
482 aPrintText.appendAscii( ": " );
483 aPrintText.append( sPrinter );
484 aPrintText.appendAscii( "\n: " );
485 if( pPrintParser )
486 aPrintText.append( pPrintParser->getPrinterName() );
487 aPrintText.appendAscii( "\n: " );
488 INetURLObject aDriverPath( pPrintParser ? pPrintParser->getFilename() : String( RTL_CONSTASCII_USTRINGPARAM( "<undef>" ) ),
489 INET_PROT_FILE, INetURLObject::ENCODE_ALL );
490 aPrintText.append( aDriverPath.GetName() );
491 aPrintText.appendAscii( "\n: " );
492 aPrintText.append( aInfo.m_aCommand );
493 aPrintText.appendAscii( "\n: " );
494 aPrintText.append( aInfo.m_aComment );
495 aPrintText.appendAscii( "\n: " );
496 aPrintText.append( rLocaleWrapper.getDate( Date() ) );
497 aPrintText.appendAscii( "\n: " );
498 aPrintText.append( rLocaleWrapper.getTime( Time() ) );
500 m_pPrinter->DrawText( Rectangle( Point( 1100 + nMaxWidth, 2000 ),
501 Size( aPaperSize.Width() - 2100 - nMaxWidth,
502 aPaperSize.Height() - 4000 ) ),
503 aPrintText.makeStringAndClear(),
504 TEXT_DRAW_MULTILINE );
506 m_pPrinter->DrawBitmap( Point( aPaperSize.Width() - 4000, 1000 ),
507 Size( 3000,3000 ),
508 aButterfly );
509 m_pPrinter->SetFillColor();
510 m_pPrinter->DrawRect( Rectangle( Point( aPaperSize.Width() - 4000, 1000 ),
511 Size( 3000,3000 ) ) );
513 Color aWhite( 0xff, 0xff, 0xff );
514 Color aBlack( 0, 0, 0 );
515 Color aLightRed( 0xff, 0, 0 );
516 Color aDarkRed( 0x40, 0, 0 );
517 Color aLightBlue( 0, 0, 0xff );
518 Color aDarkBlue( 0,0,0x40 );
519 Color aLightGreen( 0, 0xff, 0 );
520 Color aDarkGreen( 0, 0x40, 0 );
522 Gradient aGradient( GRADIENT_LINEAR, aBlack, aWhite );
523 aGradient.SetAngle( 900 );
524 m_pPrinter->DrawGradient( Rectangle( Point( 1000, 5500 ),
525 Size( aPaperSize.Width() - 2000,
526 500 ) ), aGradient );
527 aGradient.SetStartColor( aDarkRed );
528 aGradient.SetEndColor( aLightBlue );
529 m_pPrinter->DrawGradient( Rectangle( Point( 1000, 6300 ),
530 Size( aPaperSize.Width() - 2000,
531 500 ) ), aGradient );
532 aGradient.SetStartColor( aDarkBlue );
533 aGradient.SetEndColor( aLightGreen );
534 m_pPrinter->DrawGradient( Rectangle( Point( 1000, 7100 ),
535 Size( aPaperSize.Width() - 2000,
536 500 ) ), aGradient );
537 aGradient.SetStartColor( aDarkGreen );
538 aGradient.SetEndColor( aLightRed );
539 m_pPrinter->DrawGradient( Rectangle( Point( 1000, 7900 ),
540 Size( aPaperSize.Width() - 2000,
541 500 ) ), aGradient );
545 LineInfo aLineInfo( LINE_SOLID, 200 );
546 double sind = sin( DELTA*M_PI/180.0 );
547 double cosd = cos( DELTA*M_PI/180.0 );
548 double factor = 1 + (DELTA/1000.0);
549 int n=0;
550 Color aLineColor( 0, 0, 0 );
551 Color aApproachColor( 0, 0, 200 );
552 while ( aP2.X() < aCenter.X() && n++ < 680 )
554 aLineInfo.SetWidth( n/3 );
555 aLineColor = approachColor( aLineColor, aApproachColor );
556 m_pPrinter->SetLineColor( aLineColor );
558 // switch aproach color
559 if( aApproachColor.IsRGBEqual( aLineColor ) )
561 if( aApproachColor.GetRed() )
562 aApproachColor = Color( 0, 0, 200 );
563 else if( aApproachColor.GetGreen() )
564 aApproachColor = Color( 200, 0, 0 );
565 else
566 aApproachColor = Color( 0, 200, 0 );
569 m_pPrinter->DrawLine( project( aP1 ) + aCenter,
570 project( aP2 ) + aCenter,
571 aLineInfo );
572 aPoint.X() = (int)((((double)aP1.X())*cosd - ((double)aP1.Y())*sind)*factor);
573 aPoint.Y() = (int)((((double)aP1.Y())*cosd + ((double)aP1.X())*sind)*factor);
574 aP1 = aPoint;
575 aPoint.X() = (int)((((double)aP2.X())*cosd - ((double)aP2.Y())*sind)*factor);
576 aPoint.Y() = (int)((((double)aP2.Y())*cosd + ((double)aP2.X())*sind)*factor);
577 aP2 = aPoint;
579 #if (OSL_DEBUG_LEVEL > 1) || defined DBG_UTIL
580 fprintf( stderr, "%d lines\n",n );
581 #endif
582 m_pPrinter->EndPage();
583 m_pPrinter->EndJob();
586 void PADialog::AddDevice()
588 AddPrinterDialog aDlg( this );
590 if( aDlg.Execute() )
591 UpdateDevice();
594 void PADialog::RemDevice()
596 String aPrinter( getSelectedDevice() );
597 String aDefPrinter( m_rPIManager.getDefaultPrinter() );
598 // do not remove the default printer
599 if( aPrinter.Equals( aDefPrinter ) )
600 return;
602 if( ! m_rPIManager.removePrinter( aPrinter ) )
604 String aText( PaResId( RID_ERR_PRINTERNOTREMOVEABLE ) );
605 aText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), aPrinter );
606 ErrorBox aBox( this, WB_OK | WB_DEF_OK, aText );
607 aBox.Execute();
608 return;
610 m_aPrinters.remove( aPrinter );
612 m_aDevicesLB.RemoveEntry( m_aDevicesLB.GetSelectEntryPos() );
613 for( int i=0; i < m_aDevicesLB.GetEntryCount(); i++ )
615 if( m_aDevicesLB.GetEntry( i ).CompareTo( aDefPrinter, aDefPrinter.Len() ) == COMPARE_EQUAL )
617 m_aDevicesLB.SelectEntryPos( i, TRUE );
618 UpdateText();
619 break;
623 m_aDevicesLB.GetFocus();
625 if( m_aDevicesLB.GetEntryCount() < 2 )
626 m_aRemPB.Enable( FALSE );
629 void PADialog::ConfigureDevice()
631 String aPrinter( getSelectedDevice() );
633 if( ! aPrinter.Len() )
634 return;
636 PrinterInfo aInfo( m_rPIManager.getPrinterInfo( aPrinter ) );
637 RTSDialog aDialog( aInfo, aPrinter, true, this );
639 if( aDialog.Execute() )
640 m_rPIManager.changePrinterInfo( aPrinter, aDialog.getSetup() );
642 UpdateText();
645 void PADialog::RenameDevice()
647 String aPrinter( getSelectedDevice() );
648 OUString aOldPrinter( aPrinter );
650 if( ! aPrinter.Len() )
651 return;
653 String aTmpString( PaResId( RID_QRY_PRTNAME ) );
654 QueryString aQuery( this,
655 aTmpString,
656 aPrinter );
657 aQuery.SetText( m_aRenameStr );
658 aQuery.Execute();
660 if( aPrinter.Len() )
662 PrinterInfo aInfo( m_rPIManager.getPrinterInfo( aOldPrinter ) );
663 aInfo.m_aPrinterName = aPrinter;
664 if( m_rPIManager.addPrinter( aPrinter, aInfo.m_aDriverName ) )
666 bool bWasDefault = m_rPIManager.getDefaultPrinter() == aOldPrinter;
667 m_aPrinters.push_back( aPrinter );
668 if( m_rPIManager.removePrinter( aOldPrinter ) )
669 m_aPrinters.remove( aOldPrinter );
670 m_rPIManager.changePrinterInfo( aPrinter, aInfo );
671 if( bWasDefault )
673 m_rPIManager.setDefaultPrinter( aPrinter );
674 UpdateDefPrt();
676 UpdateDevice();
681 void PADialog::UpdateDevice()
683 m_aDevicesLB.Clear();
685 m_rPIManager.listPrinters( m_aPrinters );
686 ::std::list< OUString >::iterator it;
687 for( it = m_aPrinters.begin(); it != m_aPrinters.end(); ++it )
689 const PrinterInfo& rInfo( m_rPIManager.getPrinterInfo( *it ) );
690 sal_Int32 nIndex = 0;
691 bool bAutoQueue = false;
692 bool bFax = false;
693 bool bPdf = false;
694 while( nIndex != -1 && ! bAutoQueue )
696 OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
697 if( aToken.getLength() )
699 if( aToken.compareToAscii( "autoqueue" ) == 0 )
700 bAutoQueue = true;
701 else if( aToken.compareToAscii( "pdf=", 4 ) == 0 )
702 bPdf = true;
703 else if( aToken.compareToAscii( "fax", 3 ) == 0 )
704 bFax = true;
707 if( bAutoQueue )
708 continue;
710 String aEntry( *it );
711 if( *it == m_rPIManager.getDefaultPrinter() )
713 aEntry.AppendAscii( " (" );
714 aEntry += m_aDefPrt;
715 aEntry.AppendAscii( ")" );
717 int nPos =
718 m_aDevicesLB.InsertEntry( aEntry,
719 bFax ? m_aFaxImg :
720 bPdf ? m_aPdfImg : m_aPrinterImg
722 m_aDevicesLB.SetEntryData( nPos, (void*)it->getLength() );
723 if( *it == m_rPIManager.getDefaultPrinter() )
725 m_aDevicesLB.SelectEntryPos( nPos );
726 UpdateText();