1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: padialog.cxx,v $
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 ************************************************************************/
37 #include "tools/urlobj.hxx"
39 #ifndef FONTCONFIG_FONTS
40 #include "padialog.hrc"
42 #include "fontentry.hxx"
44 #include "padialog.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"
69 using namespace padmin
;
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
) ),
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
) ),
106 m_rPIManager( PrinterInfoManager::get() )
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
) ) );
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() );
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
);
159 PADialog::~PADialog()
161 m_rPIManager
.writePrinterConfig();
165 long PADialog::Notify( NotifyEvent
& rEv
)
168 (rEv
.GetType() == EVENT_GETFOCUS
|| rEv
.GetType() == EVENT_LOSEFOCUS
)
171 if( m_rPIManager
.checkPrintersChanged( true ) )
173 String aSelectEntry
= m_aDevicesLB
.GetSelectEntry();
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
) )
189 // push the new images into the listbox
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
);
208 IMPL_LINK( PADialog
, ClickBtnHdl
, PushButton
*, pButton
)
210 if( pButton
== &m_aStdPB
)
212 else if( pButton
== &m_aRemPB
&& AreYouSure( this, RID_QUERY_REMOVEPRINTER
) )
214 else if( pButton
== &m_aConfPB
)
216 else if( pButton
== &m_aRenamePB
)
218 else if( pButton
== &m_aTestPagePB
)
220 else if( pButton
== &m_aAddPB
)
222 #ifndef FONTCONFIG_FONTS
223 else if( pButton
== &m_aFontsPB
)
225 FontNameDlg
aDialog( this );
229 else if( static_cast<Button
*>(pButton
) == &m_aCUPSCB
)
231 m_rPIManager
.setCUPSDisabled( m_aCUPSCB
.IsChecked() );
239 IMPL_LINK( PADialog
, DoubleClickHdl
, ListBox
*, pListBox
)
241 if( pListBox
== &m_aDevicesLB
)
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
);
255 m_aRemPB
.Enable( TRUE
);
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
) ) );
273 void PADialog::UpdateDefPrt()
275 m_rPIManager
.setDefaultPrinter( getSelectedDevice() );
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
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();
320 // rotate around X axis
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 );
330 return Point( (sal_Int32
)x2
, (sal_Int32
)z2
);
333 static Color
approachColor( const Color
& rFrom
, const Color
& rTo
)
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 ) );
349 aColor
.SetRed( rFrom
.GetRed() );
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 ) );
363 aColor
.SetGreen( rFrom
.GetGreen() );
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 ) );
377 aColor
.SetBlue( rFrom
.GetBlue() );
383 void PADialog::PrintTestPage()
385 if( m_pPrinter
) // already printing; user pressed button twice
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
);
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
) ) );
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;
449 const char* const pDirect
;
453 { NULL
, RID_TXT_TESTPAGE_NAME
},
454 { NULL
, RID_TXT_TESTPAGE_MODEL
},
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
);
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: " );
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 ),
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);
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 );
566 aApproachColor
= Color( 0, 200, 0 );
569 m_pPrinter
->DrawLine( project( aP1
) + aCenter
,
570 project( aP2
) + aCenter
,
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
);
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
);
579 #if (OSL_DEBUG_LEVEL > 1) || defined DBG_UTIL
580 fprintf( stderr
, "%d lines\n",n
);
582 m_pPrinter
->EndPage();
583 m_pPrinter
->EndJob();
586 void PADialog::AddDevice()
588 AddPrinterDialog
aDlg( this );
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
) )
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
);
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
);
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() )
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() );
645 void PADialog::RenameDevice()
647 String
aPrinter( getSelectedDevice() );
648 OUString
aOldPrinter( aPrinter
);
650 if( ! aPrinter
.Len() )
653 String
aTmpString( PaResId( RID_QRY_PRTNAME
) );
654 QueryString
aQuery( this,
657 aQuery
.SetText( m_aRenameStr
);
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
);
673 m_rPIManager
.setDefaultPrinter( aPrinter
);
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;
694 while( nIndex
!= -1 && ! bAutoQueue
)
696 OUString
aToken( rInfo
.m_aFeatures
.getToken( 0, ',', nIndex
) );
697 if( aToken
.getLength() )
699 if( aToken
.compareToAscii( "autoqueue" ) == 0 )
701 else if( aToken
.compareToAscii( "pdf=", 4 ) == 0 )
703 else if( aToken
.compareToAscii( "fax", 3 ) == 0 )
710 String
aEntry( *it
);
711 if( *it
== m_rPIManager
.getDefaultPrinter() )
713 aEntry
.AppendAscii( " (" );
715 aEntry
.AppendAscii( ")" );
718 m_aDevicesLB
.InsertEntry( aEntry
,
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
);