sync master with lastest vba changes
[ooovba.git] / padmin / source / prtsetup.cxx
blob81e1a42ec49adcfc366a28b635bcbaa68d601101
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: prtsetup.cxx,v $
10 * $Revision: 1.14 $
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 <psprint/fontmanager.hxx>
32 #include <prtsetup.hxx>
33 #include <helper.hxx> // for PaResId
34 #ifndef _PAD_RTSETUP_HRC_
35 #include <rtsetup.hrc>
36 #endif
37 #include <cmddlg.hxx>
38 #include <osl/thread.h>
40 #define LSCAPE_STRING String( RTL_CONSTASCII_USTRINGPARAM( "Landscape" ) )
41 #define PORTRAIT_STRING String( RTL_CONSTASCII_USTRINGPARAM( "Portrait" ) )
43 using namespace rtl;
44 using namespace psp;
45 using namespace padmin;
47 void RTSDialog::insertAllPPDValues( ListBox& rBox, const PPDKey* pKey )
49 if( ! pKey )
50 return;
52 const PPDValue* pValue = NULL;
53 USHORT nPos = 0;
54 String aOptionText;
56 for( int i = 0; i < pKey->countValues(); i++ )
58 pValue = pKey->getValue( i );
59 aOptionText = pValue->m_aOptionTranslation.Len() ? pValue->m_aOptionTranslation : pValue->m_aOption;
61 if( m_aJobData.m_aContext.checkConstraints( pKey, pValue ) )
63 if( rBox.GetEntryPos( (void*)pValue ) == LISTBOX_ENTRY_NOTFOUND )
65 nPos = rBox.InsertEntry( aOptionText, LISTBOX_APPEND );
66 rBox.SetEntryData( nPos, (void*)pValue );
69 else
71 if( ( nPos = rBox.GetEntryPos( (void*)pValue ) ) != LISTBOX_ENTRY_NOTFOUND )
72 rBox.RemoveEntry( nPos );
75 pValue = m_aJobData.m_aContext.getValue( pKey );
76 if( pValue )
78 if( ( nPos = rBox.GetEntryPos( (void*)pValue ) ) != LISTBOX_ENTRY_NOTFOUND )
79 rBox.SelectEntryPos( nPos );
81 else
82 rBox.SelectEntry( m_aInvalidString );
85 // --------------------------------------------------------------------------
88 * RTSDialog
91 RTSDialog::RTSDialog( const PrinterInfo& rJobData, const String& rPrinter, bool bAllPages, Window* pParent ) :
92 TabDialog( pParent, PaResId( RID_RTS_RTSDIALOG ) ),
93 m_aJobData( rJobData ),
94 m_aPrinter( rPrinter ),
95 m_aTabControl( this, PaResId( RID_RTS_RTSDIALOG_TABCONTROL ) ),
96 m_aOKButton( this ),
97 m_aCancelButton( this ),
98 m_pPaperPage( NULL ),
99 m_pDevicePage( NULL ),
100 m_pOtherPage( NULL ),
101 m_pFontSubstPage( NULL ),
102 m_pCommandPage( NULL ),
103 m_aInvalidString( PaResId( RID_RTS_RTSDIALOG_INVALID_TXT ) ),
104 m_aFromDriverString( PaResId( RID_RTS_RTSDIALOG_FROMDRIVER_TXT ) )
106 FreeResource();
108 String aTitle( GetText() );
109 aTitle.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), m_aJobData.m_aPrinterName );
110 SetText( aTitle );
112 if( ! bAllPages )
114 m_aTabControl.RemovePage( RID_RTS_OTHERPAGE );
115 m_aTabControl.RemovePage( RID_RTS_FONTSUBSTPAGE );
116 m_aTabControl.RemovePage( RID_RTS_COMMANDPAGE );
118 else if( m_aJobData.m_aDriverName.compareToAscii( "CUPS:", 5 ) == 0 && ! PrinterInfoManager::get().isCUPSDisabled() )
120 // command page makes no sense for CUPS printers
121 m_aTabControl.RemovePage( RID_RTS_COMMANDPAGE );
124 m_aTabControl.SetActivatePageHdl( LINK( this, RTSDialog, ActivatePage ) );
125 m_aOKButton.SetClickHdl( LINK( this, RTSDialog, ClickButton ) );
126 m_aCancelButton.SetClickHdl( LINK( this, RTSDialog, ClickButton ) );
127 ActivatePage( &m_aTabControl );
129 m_aOKButton.Show();
130 m_aCancelButton.Show();
133 // --------------------------------------------------------------------------
135 RTSDialog::~RTSDialog()
137 if( m_pPaperPage )
138 delete m_pPaperPage;
139 if( m_pDevicePage )
140 delete m_pDevicePage;
141 if( m_pOtherPage )
142 delete m_pOtherPage;
143 if( m_pFontSubstPage )
144 delete m_pFontSubstPage;
145 if( m_pCommandPage )
146 delete m_pCommandPage;
149 // --------------------------------------------------------------------------
151 String RTSDialog::getPaperSize()
153 String aRet;
154 if( m_aJobData.m_pParser )
156 const PPDKey* pKey = m_aJobData.m_pParser->getKey( String::CreateFromAscii( "PageSize" ) );
157 if( pKey )
159 const PPDValue* pValue = m_aJobData.m_aContext.getValue( pKey );
160 aRet = pValue->m_aOption;
163 return aRet;
166 // --------------------------------------------------------------------------
168 IMPL_LINK( RTSDialog, ActivatePage, TabControl*, pTabCtrl )
170 if( pTabCtrl != &m_aTabControl )
171 return 0;
173 USHORT nId = m_aTabControl.GetCurPageId();
175 if ( ! m_aTabControl.GetTabPage( nId ) )
177 TabPage *pPage = NULL;
178 if( nId == RID_RTS_PAPERPAGE )
179 pPage = m_pPaperPage = new RTSPaperPage( this );
180 else if( nId == RID_RTS_DEVICEPAGE )
181 pPage = m_pDevicePage = new RTSDevicePage( this );
182 else if( nId == RID_RTS_OTHERPAGE )
183 pPage = m_pOtherPage = new RTSOtherPage( this );
184 else if( nId == RID_RTS_FONTSUBSTPAGE )
185 pPage = m_pFontSubstPage = new RTSFontSubstPage( this );
186 else if( nId == RID_RTS_COMMANDPAGE )
187 pPage = m_pCommandPage = new RTSCommandPage( this );
188 if( pPage )
189 m_aTabControl.SetTabPage( nId, pPage );
191 else
193 switch( nId )
195 case RID_RTS_PAPERPAGE: m_pPaperPage->update();break;
196 case RID_RTS_DEVICEPAGE: m_pDevicePage->update();break;
197 default: break;
201 return 0;
204 // --------------------------------------------------------------------------
206 IMPL_LINK( RTSDialog, ClickButton, Button*, pButton )
208 if( pButton == &m_aOKButton )
210 // refresh the changed values
211 if( m_pPaperPage )
213 // orientation
214 m_aJobData.m_eOrientation = m_pPaperPage->getOrientation().Equals( LSCAPE_STRING ) ? orientation::Landscape : orientation::Portrait;
216 if( m_pDevicePage )
218 m_aJobData.m_nColorDepth = m_pDevicePage->getDepth();
219 m_aJobData.m_nColorDevice = m_pDevicePage->getColorDevice();
220 m_aJobData.m_nPSLevel = m_pDevicePage->getLevel();
222 if( m_pOtherPage )
223 // write other settings
224 m_pOtherPage->save();
225 if( m_pCommandPage )
226 // write command settings
227 m_pCommandPage->save();
229 EndDialog( 1 );
231 else if( pButton == &m_aCancelButton )
232 EndDialog( 0 );
234 return 0;
237 // --------------------------------------------------------------------------
240 * RTSPaperPage
243 RTSPaperPage::RTSPaperPage( RTSDialog* pParent ) :
244 TabPage( & pParent->m_aTabControl, PaResId( RID_RTS_PAPERPAGE ) ),
246 m_pParent( pParent ),
248 m_aPaperText( this, PaResId( RID_RTS_PAPER_PAPER_TXT ) ),
249 m_aPaperBox( this, PaResId( RID_RTS_PAPER_PAPER_BOX ) ),
250 m_aOrientText( this, PaResId( RID_RTS_PAPER_ORIENTATION_TXT ) ),
251 m_aOrientBox( this, PaResId( RID_RTS_PAPER_ORIENTATION_BOX ) ),
252 m_aDuplexText( this, PaResId( RID_RTS_PAPER_DUPLEX_TXT ) ),
253 m_aDuplexBox( this, PaResId( RID_RTS_PAPER_DUPLEX_BOX ) ),
254 m_aSlotText( this, PaResId( RID_RTS_PAPER_SLOT_TXT ) ),
255 m_aSlotBox( this, PaResId( RID_RTS_PAPER_SLOT_BOX ) )
257 m_aPaperBox.SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
258 m_aOrientBox.SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
259 m_aDuplexBox.SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
260 m_aSlotBox.SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
262 FreeResource();
264 USHORT nPos = 0;
266 m_aOrientBox.InsertEntry( PORTRAIT_STRING );
267 m_aOrientBox.InsertEntry( LSCAPE_STRING );
268 // duplex
269 nPos = m_aDuplexBox.InsertEntry( m_pParent->m_aInvalidString );
270 m_aDuplexBox.SetEntryData( nPos, NULL );
272 // paper does not have an invalid entry
274 // input slots
275 nPos = m_aSlotBox.InsertEntry( m_pParent->m_aInvalidString );
276 m_aSlotBox.SetEntryData( nPos, NULL );
278 update();
281 // --------------------------------------------------------------------------
283 RTSPaperPage::~RTSPaperPage()
287 // --------------------------------------------------------------------------
289 void RTSPaperPage::update()
291 const PPDKey* pKey = NULL;
293 // orientation
294 m_aOrientBox.SelectEntry(
295 m_pParent->m_aJobData.m_eOrientation == orientation::Landscape
296 ? LSCAPE_STRING : PORTRAIT_STRING );
298 // duplex
299 if( m_pParent->m_aJobData.m_pParser &&
300 (pKey = m_pParent->m_aJobData.m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "Duplex" ) ) )) )
302 m_pParent->insertAllPPDValues( m_aDuplexBox, pKey );
304 else
306 m_aDuplexText.Enable( FALSE );
307 m_aDuplexBox.Enable( FALSE );
310 // paper
311 if( m_pParent->m_aJobData.m_pParser &&
312 (pKey = m_pParent->m_aJobData.m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) ) )) )
314 m_pParent->insertAllPPDValues( m_aPaperBox, pKey );
316 else
318 m_aPaperText.Enable( FALSE );
319 m_aPaperBox.Enable( FALSE );
322 // input slots
323 if( m_pParent->m_aJobData.m_pParser &&
324 (pKey = m_pParent->m_aJobData.m_pParser->getKey( String::CreateFromAscii( "InputSlot" ) )) )
326 m_pParent->insertAllPPDValues( m_aSlotBox, pKey );
328 else
330 m_aSlotText.Enable( FALSE );
331 m_aSlotBox.Enable( FALSE );
335 // --------------------------------------------------------------------------
337 IMPL_LINK( RTSPaperPage, SelectHdl, ListBox*, pBox )
339 const PPDKey* pKey = NULL;
340 if( pBox == &m_aPaperBox )
342 if( m_pParent->m_aJobData.m_pParser )
343 pKey = m_pParent->m_aJobData.m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) ) );
345 else if( pBox == &m_aDuplexBox )
347 if( m_pParent->m_aJobData.m_pParser )
348 pKey = m_pParent->m_aJobData.m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "Duplex" ) ) );
350 else if( pBox == &m_aSlotBox )
352 if( m_pParent->m_aJobData.m_pParser )
353 pKey = m_pParent->m_aJobData.m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "InputSlot" ) ) );
355 else if( pBox == &m_aOrientBox )
357 m_pParent->m_aJobData.m_eOrientation = m_aOrientBox.GetSelectEntry().Equals( LSCAPE_STRING ) ? orientation::Landscape : orientation::Portrait;
359 if( pKey )
361 PPDValue* pValue =
362 (PPDValue*)pBox->GetEntryData( pBox->GetSelectEntryPos() );
363 m_pParent->m_aJobData.m_aContext.setValue( pKey, pValue );
364 update();
366 return 0;
369 // --------------------------------------------------------------------------
372 * RTSDevicePage
375 RTSDevicePage::RTSDevicePage( RTSDialog* pParent ) :
376 TabPage( & pParent->m_aTabControl, PaResId( RID_RTS_DEVICEPAGE ) ),
378 m_pParent( pParent ),
380 m_aSpaceColor( PaResId( RID_RTS_DEVICE_COLOR_TXT ) ),
381 m_aSpaceGray( PaResId( RID_RTS_DEVICE_GRAY_TXT ) ),
382 m_aPPDKeyText( this, PaResId( RID_RTS_DEVICE_PPDKEY_TXT ) ),
383 m_aPPDKeyBox( this, PaResId( RID_RTS_DEVICE_PPDKEY_BOX ) ),
384 m_aPPDValueText( this, PaResId( RID_RTS_DEVICE_PPDVALUE_TXT ) ),
385 m_aPPDValueBox( this, PaResId( RID_RTS_DEVICE_PPDVALUE_BOX ) ),
386 m_aLevelText( this, PaResId( RID_RTS_DEVICE_LEVEL_TXT ) ),
387 m_aLevelBox( this, PaResId( RID_RTS_DEVICE_LEVEL_BOX ) ),
388 m_aSpaceText( this, PaResId( RID_RTS_DEVICE_SPACE_TXT ) ),
389 m_aSpaceBox( this, PaResId( RID_RTS_DEVICE_SPACE_BOX ) ),
390 m_aDepthText( this, PaResId( RID_RTS_DEVICE_DEPTH_TXT ) ),
391 m_aDepthBox( this, PaResId( RID_RTS_DEVICE_DEPTH_BOX ) )
393 FreeResource();
395 m_aPPDKeyBox.SetSelectHdl( LINK( this, RTSDevicePage, SelectHdl ) );
396 m_aPPDValueBox.SetSelectHdl( LINK( this, RTSDevicePage, SelectHdl ) );
398 m_aSpaceBox.InsertEntry( m_pParent->m_aFromDriverString );
399 m_aSpaceBox.InsertEntry( m_aSpaceColor );
400 m_aSpaceBox.InsertEntry( m_aSpaceGray );
401 switch( m_pParent->m_aJobData.m_nColorDevice )
403 case -1: m_aSpaceBox.SelectEntry( m_aSpaceGray );break;
404 case 0: m_aSpaceBox.SelectEntry( m_pParent->m_aFromDriverString );break;
405 case 1: m_aSpaceBox.SelectEntry( m_aSpaceColor );break;
408 m_aLevelBox.InsertEntry( m_pParent->m_aFromDriverString );
409 m_aLevelBox.InsertEntry( String( RTL_CONSTASCII_USTRINGPARAM( "1" ) ) );
410 m_aLevelBox.InsertEntry( String( RTL_CONSTASCII_USTRINGPARAM( "2" ) ) );
411 if( m_pParent->m_aJobData.m_nPSLevel == 0 )
412 m_aLevelBox.SelectEntry( m_pParent->m_aFromDriverString );
413 else
414 m_aLevelBox.SelectEntry( String::CreateFromInt32( m_pParent->m_aJobData.m_nPSLevel ) );
416 m_aDepthBox.SelectEntry( String::CreateFromInt32( m_pParent->m_aJobData.m_nColorDepth ).AppendAscii( " Bit" ) );
418 // fill ppd boxes
419 if( m_pParent->m_aJobData.m_pParser )
421 for( int i = 0; i < m_pParent->m_aJobData.m_pParser->getKeys(); i++ )
423 const PPDKey* pKey = m_pParent->m_aJobData.m_pParser->getKey( i );
424 if( pKey->isUIKey() &&
425 ! pKey->getKey().EqualsAscii( "PageSize" ) &&
426 ! pKey->getKey().EqualsAscii( "InputSlot" ) &&
427 ! pKey->getKey().EqualsAscii( "PageRegion" ) &&
428 ! pKey->getKey().EqualsAscii( "Duplex" )
431 USHORT nPos =
432 m_aPPDKeyBox.InsertEntry( pKey->getUITranslation().Len() ? pKey->getUITranslation() : pKey->getKey() );
433 m_aPPDKeyBox.SetEntryData( nPos, (void*)pKey );
439 // --------------------------------------------------------------------------
441 RTSDevicePage::~RTSDevicePage()
445 // --------------------------------------------------------------------------
447 void RTSDevicePage::update()
451 // ------------------------------------------------------------------
453 IMPL_LINK( RTSDevicePage, SelectHdl, ListBox*, pBox )
455 if( pBox == &m_aPPDKeyBox )
457 const PPDKey* pKey = (PPDKey*)m_aPPDKeyBox.GetEntryData( m_aPPDKeyBox.GetSelectEntryPos() );
458 FillValueBox( pKey );
460 else if( pBox == &m_aPPDValueBox )
462 const PPDKey* pKey = (PPDKey*)m_aPPDKeyBox.GetEntryData( m_aPPDKeyBox.GetSelectEntryPos() );
463 const PPDValue* pValue = (PPDValue*)m_aPPDValueBox.GetEntryData( m_aPPDValueBox.GetSelectEntryPos() );
464 if( pKey && pValue )
466 m_pParent->m_aJobData.m_aContext.setValue( pKey, pValue );
467 FillValueBox( pKey );
470 return 0;
473 // ------------------------------------------------------------------
475 void RTSDevicePage::FillValueBox( const PPDKey* pKey )
477 m_aPPDValueBox.Clear();
479 if( ! pKey )
480 return;
482 const PPDValue* pValue = NULL;
483 for( int i = 0; i < pKey->countValues(); i++ )
485 pValue = pKey->getValue( i );
486 if( m_pParent->m_aJobData.m_aContext.checkConstraints( pKey, pValue ) )
488 USHORT nPos =
489 m_aPPDValueBox.InsertEntry( pValue->m_aOptionTranslation.Len() ? pValue->m_aOptionTranslation : pValue->m_aOption );
490 m_aPPDValueBox.SetEntryData( nPos, (void*)pValue );
493 pValue = m_pParent->m_aJobData.m_aContext.getValue( pKey );
494 m_aPPDValueBox.SelectEntryPos( m_aPPDValueBox.GetEntryPos( (void*)pValue ) );
497 // --------------------------------------------------------------------------
500 * RTSOtherPage
503 RTSOtherPage::RTSOtherPage( RTSDialog* pParent ) :
504 TabPage( &pParent->m_aTabControl, PaResId( RID_RTS_OTHERPAGE ) ),
505 m_pParent( pParent ),
506 m_aLeftTxt( this, PaResId( RID_RTS_OTHER_LEFTMARGIN_TXT ) ),
507 m_aLeftLB( this, PaResId( RID_RTS_OTHER_LEFTMARGIN_BOX ) ),
508 m_aTopTxt( this, PaResId( RID_RTS_OTHER_TOPMARGIN_TXT ) ),
509 m_aTopLB( this, PaResId( RID_RTS_OTHER_TOPMARGIN_BOX ) ),
510 m_aRightTxt( this, PaResId( RID_RTS_OTHER_RIGHTMARGIN_TXT ) ),
511 m_aRightLB( this, PaResId( RID_RTS_OTHER_RIGHTMARGIN_BOX ) ),
512 m_aBottomTxt( this, PaResId( RID_RTS_OTHER_BOTTOMMARGIN_TXT ) ),
513 m_aBottomLB( this, PaResId( RID_RTS_OTHER_BOTTOMMARGIN_BOX ) ),
514 m_aCommentTxt( this, PaResId( RID_RTS_OTHER_COMMENT_TXT ) ),
515 m_aCommentEdt( this, PaResId( RID_RTS_OTHER_COMMENT_EDT ) ),
516 m_aDefaultBtn( this, PaResId( RID_RTS_OTHER_DEFAULT_BTN ) )
518 FreeResource();
520 m_aTopLB.EnableEmptyFieldValue( TRUE );
521 m_aBottomLB.EnableEmptyFieldValue( TRUE );
522 m_aLeftLB.EnableEmptyFieldValue( TRUE );
523 m_aRightLB.EnableEmptyFieldValue( TRUE );
525 m_aDefaultBtn.SetClickHdl( LINK( this, RTSOtherPage, ClickBtnHdl ) );
527 initValues();
530 // ------------------------------------------------------------------
532 RTSOtherPage::~RTSOtherPage()
536 // ------------------------------------------------------------------
538 void RTSOtherPage::initValues()
540 int nMarginLeft = 0;
541 int nMarginTop = 0;
542 int nMarginRight = 0;
543 int nMarginBottom = 0;
545 if( m_pParent->m_aJobData.m_pParser )
547 m_pParent->m_aJobData.m_pParser->
548 getMargins( m_pParent->m_aJobData.m_pParser->getDefaultPaperDimension(),
549 nMarginLeft,
550 nMarginRight,
551 nMarginTop,
552 nMarginBottom );
555 nMarginLeft += m_pParent->m_aJobData.m_nLeftMarginAdjust;
556 nMarginRight += m_pParent->m_aJobData.m_nRightMarginAdjust;
557 nMarginTop += m_pParent->m_aJobData.m_nTopMarginAdjust;
558 nMarginBottom += m_pParent->m_aJobData.m_nBottomMarginAdjust;
560 m_aLeftLB.SetValue( nMarginLeft, FUNIT_POINT );
561 m_aRightLB.SetValue( nMarginRight, FUNIT_POINT );
562 m_aTopLB.SetValue( nMarginTop, FUNIT_POINT );
563 m_aBottomLB.SetValue( nMarginBottom, FUNIT_POINT );
564 m_aCommentEdt.SetText( m_pParent->m_aJobData.m_aComment );
567 // ------------------------------------------------------------------
569 void RTSOtherPage::save()
571 int nMarginLeft = 0;
572 int nMarginTop = 0;
573 int nMarginRight = 0;
574 int nMarginBottom = 0;
576 if( m_pParent->m_aJobData.m_pParser )
578 m_pParent->m_aJobData.m_pParser->
579 getMargins( m_pParent->m_aJobData.m_pParser->getDefaultPaperDimension(),
580 nMarginLeft,
581 nMarginRight,
582 nMarginTop,
583 nMarginBottom );
586 m_pParent->m_aJobData.m_nLeftMarginAdjust = m_aLeftLB.GetValue( FUNIT_POINT ) - nMarginLeft;
587 m_pParent->m_aJobData.m_nRightMarginAdjust = m_aRightLB.GetValue( FUNIT_POINT ) - nMarginRight;
588 m_pParent->m_aJobData.m_nTopMarginAdjust = m_aTopLB.GetValue( FUNIT_POINT ) - nMarginTop;
589 m_pParent->m_aJobData.m_nBottomMarginAdjust = m_aBottomLB.GetValue( FUNIT_POINT ) - nMarginBottom;
590 m_pParent->m_aJobData.m_aComment = m_aCommentEdt.GetText();
593 // ------------------------------------------------------------------
595 IMPL_LINK( RTSOtherPage, ClickBtnHdl, Button*, pButton )
597 if( pButton == &m_aDefaultBtn )
599 m_pParent->m_aJobData.m_nLeftMarginAdjust =
600 m_pParent->m_aJobData.m_nRightMarginAdjust =
601 m_pParent->m_aJobData.m_nTopMarginAdjust =
602 m_pParent->m_aJobData.m_nBottomMarginAdjust = 0;
604 initValues();
606 return 0;
609 // ------------------------------------------------------------------
612 * RTSFontSubstPage
615 RTSFontSubstPage::RTSFontSubstPage( RTSDialog* pParent ) :
616 TabPage( &pParent->m_aTabControl, PaResId( RID_RTS_FONTSUBSTPAGE ) ),
617 m_pParent( pParent ),
618 m_aSubstitutionsText( this, PaResId( RID_RTS_FS_SUBST_TXT ) ),
619 m_aSubstitutionsBox( this, PaResId( RID_RTS_FS_SUBST_BOX ) ),
620 m_aFromFontText( this, PaResId( RID_RTS_FS_FROM_TXT ) ),
621 m_aFromFontBox( this, PaResId( RID_RTS_FS_FROM_BOX ) ),
622 m_aToFontText( this, PaResId( RID_RTS_FS_TO_TXT ) ),
623 m_aToFontBox( this, PaResId( RID_RTS_FS_TO_BOX ) ),
624 m_aAddButton( this, PaResId( RID_RTS_FS_ADD_BTN ) ),
625 m_aRemoveButton( this, PaResId( RID_RTS_FS_REMOVE_BTN ) ),
626 m_aEnableBox( this, PaResId( RID_RTS_FS_ENABLE_BTN ) )
628 FreeResource();
630 // fill to box
631 PrintFontManager& rFontManager = PrintFontManager::get();
632 ::std::list< FastPrintFontInfo > aFonts;
633 rFontManager.getFontListWithFastInfo( aFonts, m_pParent->m_aJobData.m_pParser, false );
634 ::std::list< FastPrintFontInfo >::const_iterator it;
635 ::std::hash_map< OUString, int, OUStringHash > aToMap, aFromMap;
636 for( it = aFonts.begin(); it != aFonts.end(); ++it )
638 if( it->m_eType == fonttype::Builtin )
640 if( aToMap.find( it->m_aFamilyName ) == aToMap.end() )
642 m_aToFontBox.InsertEntry( it->m_aFamilyName );
643 aToMap[ it->m_aFamilyName ] = 1;
646 else
648 if( aFromMap.find( it->m_aFamilyName ) == aFromMap.end() )
650 m_aFromFontBox.InsertEntry( it->m_aFamilyName );
651 aFromMap[ it->m_aFamilyName ] = 1;
656 m_aEnableBox.Check( m_pParent->m_aJobData.m_bPerformFontSubstitution );
657 m_aRemoveButton.Enable( FALSE );
658 if( ! m_pParent->m_aJobData.m_bPerformFontSubstitution )
660 m_aSubstitutionsBox.Enable( FALSE );
661 m_aSubstitutionsText.Enable( FALSE );
662 m_aAddButton.Enable( FALSE );
663 m_aToFontBox.Enable( FALSE );
664 m_aToFontText.Enable( FALSE );
665 m_aFromFontBox.Enable( FALSE );
666 m_aFromFontText.Enable( FALSE );
669 update();
671 m_aAddButton.SetClickHdl( LINK( this, RTSFontSubstPage, ClickBtnHdl ) );
672 m_aRemoveButton.SetClickHdl( LINK( this, RTSFontSubstPage, ClickBtnHdl ) );
673 m_aEnableBox.SetClickHdl( LINK( this, RTSFontSubstPage, ClickBtnHdl ) );
674 m_aSubstitutionsBox.SetSelectHdl( LINK( this, RTSFontSubstPage, SelectHdl ) );
675 m_aSubstitutionsBox.setDelPressedLink( LINK( this, RTSFontSubstPage, DelPressedHdl ) );
678 RTSFontSubstPage::~RTSFontSubstPage()
682 void RTSFontSubstPage::update()
684 m_aSubstitutionsBox.Clear();
685 m_aRemoveButton.Enable( FALSE );
686 // fill substitutions box
687 ::std::hash_map< OUString, OUString, OUStringHash >::const_iterator it;
688 for( it = m_pParent->m_aJobData.m_aFontSubstitutes.begin();
689 it != m_pParent->m_aJobData.m_aFontSubstitutes.end(); ++it )
691 String aEntry( it->first );
692 aEntry.AppendAscii( " -> " );
693 aEntry.Append( String( it->second ) );
694 m_aSubstitutionsBox.InsertEntry( aEntry );
698 IMPL_LINK( RTSFontSubstPage, DelPressedHdl, ListBox*, pBox )
700 if( pBox == &m_aSubstitutionsBox &&
701 m_aRemoveButton.IsEnabled() )
702 ClickBtnHdl( &m_aRemoveButton );
703 return 0;
706 IMPL_LINK( RTSFontSubstPage, SelectHdl, ListBox*, pBox )
708 if( pBox == &m_aSubstitutionsBox )
710 m_aRemoveButton.Enable( m_aSubstitutionsBox.GetSelectEntryCount() && m_pParent->m_aJobData.m_bPerformFontSubstitution );
712 return 0;
715 IMPL_LINK( RTSFontSubstPage, ClickBtnHdl, Button*, pButton )
717 if( pButton == &m_aAddButton )
719 m_pParent->m_aJobData.m_aFontSubstitutes[ m_aFromFontBox.GetText() ] = m_aToFontBox.GetSelectEntry();
720 update();
722 else if( pButton == &m_aRemoveButton )
724 for( int i = 0; i < m_aSubstitutionsBox.GetSelectEntryCount(); i++ )
726 String aEntry( m_aSubstitutionsBox.GetSelectEntry( i ) );
727 USHORT nPos = aEntry.SearchAscii( " -> " );
728 aEntry.Erase( nPos );
729 m_pParent->m_aJobData.m_aFontSubstitutes.erase( aEntry );
731 update();
733 else if( pButton == &m_aEnableBox )
735 m_pParent->m_aJobData.m_bPerformFontSubstitution = m_aEnableBox.IsChecked() ? true : false;
736 m_aSubstitutionsBox.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
737 m_aSubstitutionsText.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
738 m_aAddButton.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
739 m_aRemoveButton.Enable( m_aSubstitutionsBox.GetSelectEntryCount() && m_pParent->m_aJobData.m_bPerformFontSubstitution );
740 m_aToFontBox.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
741 m_aToFontText.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
742 m_aFromFontBox.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
743 m_aFromFontText.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
745 return 0;
749 class RTSPWDialog : public ModalDialog
751 FixedText m_aText;
752 FixedText m_aUserText;
753 Edit m_aUserEdit;
754 FixedText m_aPassText;
755 Edit m_aPassEdit;
757 OKButton m_aOKButton;
758 CancelButton m_aCancelButton;
759 public:
760 RTSPWDialog( const OString& rServer, const OString& rUserName, Window* pParent );
761 ~RTSPWDialog();
763 OString getUserName() const;
764 OString getPassword() const;
767 RTSPWDialog::RTSPWDialog( const OString& rServer, const OString& rUserName, Window* pParent )
769 ModalDialog( pParent, PaResId( RID_RTS_PWDIALOG ) ),
770 m_aText( this, PaResId( RID_RTS_PWDIALOG_TXT ) ),
771 m_aUserText( this, PaResId( RID_RTS_PWDIALOG_USER_TXT ) ),
772 m_aUserEdit( this, PaResId( RID_RTS_PWDIALOG_USER_EDT ) ),
773 m_aPassText( this, PaResId( RID_RTS_PWDIALOG_PASS_TXT ) ),
774 m_aPassEdit( this, PaResId( RID_RTS_PWDIALOG_PASS_EDT ) ),
775 m_aOKButton( this, PaResId( RID_RTS_PWDIALOG_OK_BTN ) ),
776 m_aCancelButton( this, PaResId( RID_RTS_PWDIALOG_CANCEL_BTN ) )
778 FreeResource();
779 String aText( m_aText.GetText() );
780 aText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), OStringToOUString( rServer, osl_getThreadTextEncoding() ) );
781 m_aText.SetText( aText );
782 m_aUserEdit.SetText( OStringToOUString( rUserName, osl_getThreadTextEncoding() ) );
785 RTSPWDialog::~RTSPWDialog()
789 OString RTSPWDialog::getUserName() const
791 return rtl::OUStringToOString( m_aUserEdit.GetText(), osl_getThreadTextEncoding() );
794 OString RTSPWDialog::getPassword() const
796 return rtl::OUStringToOString( m_aPassEdit.GetText(), osl_getThreadTextEncoding() );
799 extern "C" {
801 int Sal_SetupPrinterDriver( ::psp::PrinterInfo& rJobData )
803 int nRet = 0;
804 RTSDialog aDialog( rJobData, rJobData.m_aPrinterName, false );
806 if( aDialog.Execute() )
808 rJobData = aDialog.getSetup();
809 nRet = 1;
812 return nRet;
815 int Sal_queryFaxNumber( String& rNumber )
817 String aTmpString( PaResId( RID_TXT_QUERYFAXNUMBER ) );
818 QueryString aQuery( NULL, aTmpString, rNumber );
819 return aQuery.Execute();
822 bool Sal_authenticateQuery( const OString& rServer, OString& rUserName, OString& rPassword )
824 bool bRet = false;
826 RTSPWDialog aDialog( rServer, rUserName, NULL );
827 if( aDialog.Execute() )
829 rUserName = aDialog.getUserName();
830 rPassword = aDialog.getPassword();
831 bRet = true;
833 return bRet;
836 } // extern "C"