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