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