bump product version to 4.1.6.2
[LibreOffice.git] / padmin / source / prtsetup.cxx
blob5ee49581c1da24560aca436cb70b738d557347d2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "prtsetup.hxx"
21 #include "helper.hxx" // for PaResId
22 #include "rtsetup.hrc"
23 #include "cmddlg.hxx"
25 #include "vcl/fontmanager.hxx"
27 #include "osl/thread.h"
29 #include <officecfg/Office/Common.hxx>
31 using namespace psp;
32 using namespace padmin;
35 void RTSDialog::insertAllPPDValues( ListBox& rBox, const PPDParser* pParser, const PPDKey* pKey )
37 if( ! pKey || ! pParser )
38 return;
40 const PPDValue* pValue = NULL;
41 sal_uInt16 nPos = 0;
42 String aOptionText;
44 for( int i = 0; i < pKey->countValues(); i++ )
46 pValue = pKey->getValue( i );
47 aOptionText = pParser->translateOption( pKey->getKey(), pValue->m_aOption) ;
49 if( m_aJobData.m_aContext.checkConstraints( pKey, pValue ) )
51 if( rBox.GetEntryPos( (void*)pValue ) == LISTBOX_ENTRY_NOTFOUND )
53 nPos = rBox.InsertEntry( aOptionText, LISTBOX_APPEND );
54 rBox.SetEntryData( nPos, (void*)pValue );
57 else
59 if( ( nPos = rBox.GetEntryPos( (void*)pValue ) ) != LISTBOX_ENTRY_NOTFOUND )
60 rBox.RemoveEntry( nPos );
63 pValue = m_aJobData.m_aContext.getValue( pKey );
64 if( pValue )
66 if( ( nPos = rBox.GetEntryPos( (void*)pValue ) ) != LISTBOX_ENTRY_NOTFOUND )
67 rBox.SelectEntryPos( nPos );
69 else
70 rBox.SelectEntry( m_aInvalidString );
73 // --------------------------------------------------------------------------
76 * RTSDialog
79 RTSDialog::RTSDialog( const PrinterInfo& rJobData, const String& rPrinter, bool bAllPages, Window* pParent )
80 : TabDialog(pParent, "PrinterPropertiesDialog", "spa/ui/printerpropertiesdialog.ui" )
81 , m_aJobData(rJobData)
82 , m_aPrinter(rPrinter)
83 , m_pPaperPage(NULL)
84 , m_pDevicePage(NULL)
85 , m_pOtherPage(NULL)
86 , m_pFontSubstPage(NULL)
87 , m_pCommandPage(NULL)
88 , m_aInvalidString(PaResId(RID_RTS_RTSDIALOG_INVALID_TXT).toString())
90 get(m_pOKButton, "ok");
91 get(m_pCancelButton, "cancel");
92 get(m_pTabControl, "notebook");
94 OUString aTitle(GetText());
95 SetText(aTitle.replaceAll("%s", m_aJobData.m_aPrinterName));
97 if( ! bAllPages )
99 m_pTabControl->RemovePage(m_pTabControl->GetPageId("other"));
100 m_pTabControl->RemovePage(m_pTabControl->GetPageId("font"));
101 m_pTabControl->RemovePage(m_pTabControl->GetPageId("command"));
103 else if( m_aJobData.m_aDriverName.startsWith("CUPS:") && ! PrinterInfoManager::get().isCUPSDisabled() )
105 // command page makes no sense for CUPS printers
106 m_pTabControl->RemovePage(m_pTabControl->GetPageId("command"));
109 m_pTabControl->SetActivatePageHdl( LINK( this, RTSDialog, ActivatePage ) );
110 m_pOKButton->SetClickHdl( LINK( this, RTSDialog, ClickButton ) );
111 m_pCancelButton->SetClickHdl( LINK( this, RTSDialog, ClickButton ) );
112 ActivatePage(m_pTabControl);
115 // --------------------------------------------------------------------------
117 RTSDialog::~RTSDialog()
119 delete m_pPaperPage;
120 delete m_pDevicePage;
121 delete m_pOtherPage;
122 delete m_pFontSubstPage;
123 delete m_pCommandPage;
126 // --------------------------------------------------------------------------
128 IMPL_LINK( RTSDialog, ActivatePage, TabControl*, pTabCtrl )
130 if( pTabCtrl != m_pTabControl )
131 return 0;
133 sal_uInt16 nId = m_pTabControl->GetCurPageId();
134 OString sPage = m_pTabControl->GetPageName(nId);
135 if ( ! m_pTabControl->GetTabPage( nId ) )
137 TabPage *pPage = NULL;
138 if (sPage == "paper")
139 pPage = m_pPaperPage = new RTSPaperPage( this );
140 else if (sPage == "device")
141 pPage = m_pDevicePage = new RTSDevicePage( this );
142 else if (sPage == "other")
143 pPage = m_pOtherPage = new RTSOtherPage( this );
144 else if (sPage == "font")
145 pPage = m_pFontSubstPage = new RTSFontSubstPage( this );
146 else if (sPage == "command")
147 pPage = m_pCommandPage = new RTSCommandPage( this );
148 if( pPage )
149 m_pTabControl->SetTabPage( nId, pPage );
151 else
153 if (sPage == "paper")
154 m_pPaperPage->update();
155 else if (sPage == "device")
156 m_pDevicePage->update();
159 return 0;
162 // --------------------------------------------------------------------------
164 IMPL_LINK( RTSDialog, ClickButton, Button*, pButton )
166 if( pButton == m_pOKButton )
168 // refresh the changed values
169 if( m_pPaperPage )
171 // orientation
172 m_aJobData.m_eOrientation = m_pPaperPage->getOrientation() == 0 ?
173 orientation::Portrait : orientation::Landscape;
175 if( m_pDevicePage )
177 m_aJobData.m_nColorDepth = m_pDevicePage->getDepth();
178 m_aJobData.m_nColorDevice = m_pDevicePage->getColorDevice();
179 m_aJobData.m_nPSLevel = m_pDevicePage->getLevel();
180 m_aJobData.m_nPDFDevice = m_pDevicePage->getPDFDevice();
182 if( m_pOtherPage )
183 // write other settings
184 m_pOtherPage->save();
185 if( m_pCommandPage )
186 // write command settings
187 m_pCommandPage->save();
189 EndDialog( 1 );
191 else if( pButton == m_pCancelButton )
192 EndDialog( 0 );
194 return 0;
197 // --------------------------------------------------------------------------
200 * RTSPaperPage
203 RTSPaperPage::RTSPaperPage(RTSDialog* pParent)
204 : TabPage(pParent->m_pTabControl, "PrinterPaperPage", "spa/ui/printerpaperpage.ui" )
205 , m_pParent( pParent )
207 get(m_pPaperText, "paperft");
208 get(m_pPaperBox, "paperlb");
209 get(m_pOrientBox, "orientlb");
210 get(m_pDuplexText, "duplexft");
211 get(m_pDuplexBox, "duplexlb");
212 get(m_pSlotText, "slotft");
213 get(m_pSlotBox, "slotlb");
215 m_pPaperBox->SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
216 m_pOrientBox->SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
217 m_pDuplexBox->SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
218 m_pSlotBox->SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
220 sal_uInt16 nPos = 0;
222 // duplex
223 nPos = m_pDuplexBox->InsertEntry( m_pParent->m_aInvalidString );
224 m_pDuplexBox->SetEntryData( nPos, NULL );
226 // paper does not have an invalid entry
228 // input slots
229 nPos = m_pSlotBox->InsertEntry( m_pParent->m_aInvalidString );
230 m_pSlotBox->SetEntryData( nPos, NULL );
232 update();
235 // --------------------------------------------------------------------------
237 RTSPaperPage::~RTSPaperPage()
241 // --------------------------------------------------------------------------
243 void RTSPaperPage::update()
245 const PPDKey* pKey = NULL;
247 // orientation
248 m_pOrientBox->SelectEntryPos(
249 m_pParent->m_aJobData.m_eOrientation == orientation::Portrait ? 0 : 1);
251 // duplex
252 if( m_pParent->m_aJobData.m_pParser &&
253 (pKey = m_pParent->m_aJobData.m_pParser->getKey( String( "Duplex" ) )) )
255 m_pParent->insertAllPPDValues( *m_pDuplexBox, m_pParent->m_aJobData.m_pParser, pKey );
257 else
259 m_pDuplexText->Enable( sal_False );
260 m_pDuplexBox->Enable( sal_False );
263 // paper
264 if( m_pParent->m_aJobData.m_pParser &&
265 (pKey = m_pParent->m_aJobData.m_pParser->getKey( String( "PageSize" ) )) )
267 m_pParent->insertAllPPDValues( *m_pPaperBox, m_pParent->m_aJobData.m_pParser, pKey );
269 else
271 m_pPaperText->Enable( sal_False );
272 m_pPaperBox->Enable( sal_False );
275 // input slots
276 if( m_pParent->m_aJobData.m_pParser &&
277 (pKey = m_pParent->m_aJobData.m_pParser->getKey( OUString("InputSlot") )) )
279 m_pParent->insertAllPPDValues( *m_pSlotBox, m_pParent->m_aJobData.m_pParser, pKey );
281 else
283 m_pSlotText->Enable( sal_False );
284 m_pSlotBox->Enable( sal_False );
288 // --------------------------------------------------------------------------
290 IMPL_LINK( RTSPaperPage, SelectHdl, ListBox*, pBox )
292 const PPDKey* pKey = NULL;
293 if( pBox == m_pPaperBox )
295 if( m_pParent->m_aJobData.m_pParser )
296 pKey = m_pParent->m_aJobData.m_pParser->getKey( String( "PageSize" ) );
298 else if( pBox == m_pDuplexBox )
300 if( m_pParent->m_aJobData.m_pParser )
301 pKey = m_pParent->m_aJobData.m_pParser->getKey( String( "Duplex" ) );
303 else if( pBox == m_pSlotBox )
305 if( m_pParent->m_aJobData.m_pParser )
306 pKey = m_pParent->m_aJobData.m_pParser->getKey( String( "InputSlot" ) );
308 else if( pBox == m_pOrientBox )
310 m_pParent->m_aJobData.m_eOrientation = m_pOrientBox->GetSelectEntryPos() == 0 ? orientation::Portrait : orientation::Landscape;
312 if( pKey )
314 PPDValue* pValue =
315 (PPDValue*)pBox->GetEntryData( pBox->GetSelectEntryPos() );
316 m_pParent->m_aJobData.m_aContext.setValue( pKey, pValue );
317 update();
319 return 0;
322 // --------------------------------------------------------------------------
325 * RTSDevicePage
328 RTSDevicePage::RTSDevicePage( RTSDialog* pParent )
329 : TabPage(pParent->m_pTabControl, "PrinterDevicePage", "spa/ui/printerdevicepage.ui" )
330 , m_pParent( pParent )
332 get(m_pPPDKeyBox, "options");
333 get(m_pPPDValueBox, "values");
335 m_pPPDKeyBox->SetDropDownLineCount(12);
336 m_pPPDValueBox->SetDropDownLineCount(12);
338 get(m_pLevelBox, "level");
339 get(m_pSpaceBox, "colorspace");
340 get(m_pDepthBox, "colordepth");
342 m_pPPDKeyBox->SetSelectHdl( LINK( this, RTSDevicePage, SelectHdl ) );
343 m_pPPDValueBox->SetSelectHdl( LINK( this, RTSDevicePage, SelectHdl ) );
345 switch( m_pParent->m_aJobData.m_nColorDevice )
347 case 0: m_pSpaceBox->SelectEntryPos(0);break;
348 case 1: m_pSpaceBox->SelectEntryPos(1);break;
349 case -1: m_pSpaceBox->SelectEntryPos(2);break;
352 sal_uLong nLevelEntryData = 0; //automatic
353 if( m_pParent->m_aJobData.m_nPDFDevice == 2 ) //explicitly PDF
354 nLevelEntryData = 10;
355 else if (m_pParent->m_aJobData.m_nPSLevel > 0) //explicit PS Level
356 nLevelEntryData = m_pParent->m_aJobData.m_nPSLevel+1;
357 else if (m_pParent->m_aJobData.m_nPDFDevice == 1) //automatically PDF
358 nLevelEntryData = 0;
359 else if (m_pParent->m_aJobData.m_nPDFDevice == -1) //explicitly PS from driver
360 nLevelEntryData = 1;
362 bool bAutoIsPDF = officecfg::Office::Common::Print::Option::Printer::PDFAsStandardPrintJobFormat::get();
364 assert(nLevelEntryData != 0 || bAutoIsPDF == m_pParent->m_aJobData.m_nPDFDevice);
366 OUString sStr = m_pLevelBox->GetEntry(0);
367 m_pLevelBox->InsertEntry(sStr.replaceAll("%s", bAutoIsPDF ? m_pLevelBox->GetEntry(5) : m_pLevelBox->GetEntry(1)), 0);
368 m_pLevelBox->SetEntryData(0, m_pLevelBox->GetEntryData(1));
369 m_pLevelBox->RemoveEntry(1);
371 for( sal_uInt16 i = 0; i < m_pLevelBox->GetEntryCount(); i++ )
373 if( (sal_uLong)m_pLevelBox->GetEntryData( i ) == nLevelEntryData )
375 m_pLevelBox->SelectEntryPos( i );
376 break;
380 if (m_pParent->m_aJobData.m_nColorDepth == 8)
381 m_pDepthBox->SelectEntryPos(0);
382 else if (m_pParent->m_aJobData.m_nColorDepth == 24)
383 m_pDepthBox->SelectEntryPos(1);
385 // fill ppd boxes
386 if( m_pParent->m_aJobData.m_pParser )
388 for( int i = 0; i < m_pParent->m_aJobData.m_pParser->getKeys(); i++ )
390 const PPDKey* pKey = m_pParent->m_aJobData.m_pParser->getKey( i );
391 if( pKey->isUIKey() &&
392 ! pKey->getKey().EqualsAscii( "PageSize" ) &&
393 ! pKey->getKey().EqualsAscii( "InputSlot" ) &&
394 ! pKey->getKey().EqualsAscii( "PageRegion" ) &&
395 ! pKey->getKey().EqualsAscii( "Duplex" )
398 String aEntry( m_pParent->m_aJobData.m_pParser->translateKey( pKey->getKey() ) );
399 sal_uInt16 nPos = m_pPPDKeyBox->InsertEntry( aEntry );
400 m_pPPDKeyBox->SetEntryData( nPos, (void*)pKey );
406 // --------------------------------------------------------------------------
408 RTSDevicePage::~RTSDevicePage()
412 // --------------------------------------------------------------------------
414 void RTSDevicePage::update()
418 sal_uLong RTSDevicePage::getDepth()
420 sal_uInt16 nSelectPos = m_pDepthBox->GetSelectEntryPos();
421 if (nSelectPos == 0)
422 return 8;
423 else
424 return 24;
427 sal_uLong RTSDevicePage::getColorDevice()
429 sal_uInt16 nSelectPos = m_pSpaceBox->GetSelectEntryPos();
430 switch (nSelectPos)
432 case 0:
433 return 0;
434 case 1:
435 return 1;
436 case 2:
437 return -1;
439 return 0;
442 // ------------------------------------------------------------------
444 sal_uLong RTSDevicePage::getLevel()
446 sal_uLong nLevel = (sal_uLong)m_pLevelBox->GetEntryData( m_pLevelBox->GetSelectEntryPos() );
447 if (nLevel == 0)
448 return 0; //automatic
449 return nLevel < 10 ? nLevel-1 : 0;
452 // ------------------------------------------------------------------
454 sal_uLong RTSDevicePage::getPDFDevice()
456 sal_uLong nLevel = (sal_uLong)m_pLevelBox->GetEntryData( m_pLevelBox->GetSelectEntryPos() );
457 if (nLevel > 9)
458 return 2; //explictly PDF
459 else if (nLevel == 0)
460 return 0; //automatic
461 return -1; //explicitly PS
464 // ------------------------------------------------------------------
466 IMPL_LINK( RTSDevicePage, SelectHdl, ListBox*, pBox )
468 if( pBox == m_pPPDKeyBox )
470 const PPDKey* pKey = (PPDKey*)m_pPPDKeyBox->GetEntryData( m_pPPDKeyBox->GetSelectEntryPos() );
471 FillValueBox( pKey );
473 else if( pBox == m_pPPDValueBox )
475 const PPDKey* pKey = (PPDKey*)m_pPPDKeyBox->GetEntryData( m_pPPDKeyBox->GetSelectEntryPos() );
476 const PPDValue* pValue = (PPDValue*)m_pPPDValueBox->GetEntryData( m_pPPDValueBox->GetSelectEntryPos() );
477 if( pKey && pValue )
479 m_pParent->m_aJobData.m_aContext.setValue( pKey, pValue );
480 FillValueBox( pKey );
483 return 0;
486 // ------------------------------------------------------------------
488 void RTSDevicePage::FillValueBox( const PPDKey* pKey )
490 m_pPPDValueBox->Clear();
492 if( ! pKey )
493 return;
495 const PPDValue* pValue = NULL;
496 for( int i = 0; i < pKey->countValues(); i++ )
498 pValue = pKey->getValue( i );
499 if( m_pParent->m_aJobData.m_aContext.checkConstraints( pKey, pValue ) &&
500 m_pParent->m_aJobData.m_pParser )
502 String aEntry( m_pParent->m_aJobData.m_pParser->translateOption( pKey->getKey(), pValue->m_aOption ) );
503 sal_uInt16 nPos = m_pPPDValueBox->InsertEntry( aEntry );
504 m_pPPDValueBox->SetEntryData( nPos, (void*)pValue );
507 pValue = m_pParent->m_aJobData.m_aContext.getValue( pKey );
508 m_pPPDValueBox->SelectEntryPos( m_pPPDValueBox->GetEntryPos( (void*)pValue ) );
511 // --------------------------------------------------------------------------
514 * RTSOtherPage
517 RTSOtherPage::RTSOtherPage( RTSDialog* pParent ) :
518 TabPage( pParent->m_pTabControl, PaResId( RID_RTS_OTHERPAGE ) ),
519 m_pParent( pParent ),
520 m_aLeftTxt( this, PaResId( RID_RTS_OTHER_LEFTMARGIN_TXT ) ),
521 m_aLeftLB( this, PaResId( RID_RTS_OTHER_LEFTMARGIN_BOX ) ),
522 m_aTopTxt( this, PaResId( RID_RTS_OTHER_TOPMARGIN_TXT ) ),
523 m_aTopLB( this, PaResId( RID_RTS_OTHER_TOPMARGIN_BOX ) ),
524 m_aRightTxt( this, PaResId( RID_RTS_OTHER_RIGHTMARGIN_TXT ) ),
525 m_aRightLB( this, PaResId( RID_RTS_OTHER_RIGHTMARGIN_BOX ) ),
526 m_aBottomTxt( this, PaResId( RID_RTS_OTHER_BOTTOMMARGIN_TXT ) ),
527 m_aBottomLB( this, PaResId( RID_RTS_OTHER_BOTTOMMARGIN_BOX ) ),
528 m_aCommentTxt( this, PaResId( RID_RTS_OTHER_COMMENT_TXT ) ),
529 m_aCommentEdt( this, PaResId( RID_RTS_OTHER_COMMENT_EDT ) ),
530 m_aDefaultBtn( this, PaResId( RID_RTS_OTHER_DEFAULT_BTN ) )
532 FreeResource();
534 m_aTopLB.EnableEmptyFieldValue( sal_True );
535 m_aBottomLB.EnableEmptyFieldValue( sal_True );
536 m_aLeftLB.EnableEmptyFieldValue( sal_True );
537 m_aRightLB.EnableEmptyFieldValue( sal_True );
539 m_aDefaultBtn.SetClickHdl( LINK( this, RTSOtherPage, ClickBtnHdl ) );
541 initValues();
544 // ------------------------------------------------------------------
546 RTSOtherPage::~RTSOtherPage()
550 // ------------------------------------------------------------------
552 void RTSOtherPage::initValues()
554 int nMarginLeft = 0;
555 int nMarginTop = 0;
556 int nMarginRight = 0;
557 int nMarginBottom = 0;
559 if( m_pParent->m_aJobData.m_pParser )
561 m_pParent->m_aJobData.m_pParser->
562 getMargins( m_pParent->m_aJobData.m_pParser->getDefaultPaperDimension(),
563 nMarginLeft,
564 nMarginRight,
565 nMarginTop,
566 nMarginBottom );
569 nMarginLeft += m_pParent->m_aJobData.m_nLeftMarginAdjust;
570 nMarginRight += m_pParent->m_aJobData.m_nRightMarginAdjust;
571 nMarginTop += m_pParent->m_aJobData.m_nTopMarginAdjust;
572 nMarginBottom += m_pParent->m_aJobData.m_nBottomMarginAdjust;
574 m_aLeftLB.SetValue( nMarginLeft, FUNIT_POINT );
575 m_aRightLB.SetValue( nMarginRight, FUNIT_POINT );
576 m_aTopLB.SetValue( nMarginTop, FUNIT_POINT );
577 m_aBottomLB.SetValue( nMarginBottom, FUNIT_POINT );
578 m_aCommentEdt.SetText( m_pParent->m_aJobData.m_aComment );
581 // ------------------------------------------------------------------
583 void RTSOtherPage::save()
585 int nMarginLeft = 0;
586 int nMarginTop = 0;
587 int nMarginRight = 0;
588 int nMarginBottom = 0;
590 if( m_pParent->m_aJobData.m_pParser )
592 m_pParent->m_aJobData.m_pParser->
593 getMargins( m_pParent->m_aJobData.m_pParser->getDefaultPaperDimension(),
594 nMarginLeft,
595 nMarginRight,
596 nMarginTop,
597 nMarginBottom );
600 m_pParent->m_aJobData.m_nLeftMarginAdjust = m_aLeftLB.GetValue( FUNIT_POINT ) - nMarginLeft;
601 m_pParent->m_aJobData.m_nRightMarginAdjust = m_aRightLB.GetValue( FUNIT_POINT ) - nMarginRight;
602 m_pParent->m_aJobData.m_nTopMarginAdjust = m_aTopLB.GetValue( FUNIT_POINT ) - nMarginTop;
603 m_pParent->m_aJobData.m_nBottomMarginAdjust = m_aBottomLB.GetValue( FUNIT_POINT ) - nMarginBottom;
604 m_pParent->m_aJobData.m_aComment = m_aCommentEdt.GetText();
607 // ------------------------------------------------------------------
609 IMPL_LINK( RTSOtherPage, ClickBtnHdl, Button*, pButton )
611 if( pButton == &m_aDefaultBtn )
613 m_pParent->m_aJobData.m_nLeftMarginAdjust =
614 m_pParent->m_aJobData.m_nRightMarginAdjust =
615 m_pParent->m_aJobData.m_nTopMarginAdjust =
616 m_pParent->m_aJobData.m_nBottomMarginAdjust = 0;
618 initValues();
620 return 0;
623 // ------------------------------------------------------------------
626 * RTSFontSubstPage
629 RTSFontSubstPage::RTSFontSubstPage( RTSDialog* pParent ) :
630 TabPage( pParent->m_pTabControl, PaResId( RID_RTS_FONTSUBSTPAGE ) ),
631 m_pParent( pParent ),
632 m_aSubstitutionsText( this, PaResId( RID_RTS_FS_SUBST_TXT ) ),
633 m_aSubstitutionsBox( this, PaResId( RID_RTS_FS_SUBST_BOX ) ),
634 m_aFromFontText( this, PaResId( RID_RTS_FS_FROM_TXT ) ),
635 m_aFromFontBox( this, PaResId( RID_RTS_FS_FROM_BOX ) ),
636 m_aToFontText( this, PaResId( RID_RTS_FS_TO_TXT ) ),
637 m_aToFontBox( this, PaResId( RID_RTS_FS_TO_BOX ) ),
638 m_aAddButton( this, PaResId( RID_RTS_FS_ADD_BTN ) ),
639 m_aRemoveButton( this, PaResId( RID_RTS_FS_REMOVE_BTN ) ),
640 m_aEnableBox( this, PaResId( RID_RTS_FS_ENABLE_BTN ) )
642 FreeResource();
644 // fill to box
645 PrintFontManager& rFontManager = PrintFontManager::get();
646 ::std::list< FastPrintFontInfo > aFonts;
647 rFontManager.getFontListWithFastInfo( aFonts, m_pParent->m_aJobData.m_pParser );
648 ::std::list< FastPrintFontInfo >::const_iterator it;
649 ::boost::unordered_map< OUString, int, OUStringHash > aToMap, aFromMap;
650 for( it = aFonts.begin(); it != aFonts.end(); ++it )
652 if( it->m_eType == fonttype::Builtin )
654 if( aToMap.find( it->m_aFamilyName ) == aToMap.end() )
656 m_aToFontBox.InsertEntry( it->m_aFamilyName );
657 aToMap[ it->m_aFamilyName ] = 1;
660 else
662 if( aFromMap.find( it->m_aFamilyName ) == aFromMap.end() )
664 m_aFromFontBox.InsertEntry( it->m_aFamilyName );
665 aFromMap[ it->m_aFamilyName ] = 1;
670 m_aEnableBox.Check( m_pParent->m_aJobData.m_bPerformFontSubstitution );
671 m_aRemoveButton.Enable( sal_False );
672 if( ! m_pParent->m_aJobData.m_bPerformFontSubstitution )
674 m_aSubstitutionsBox.Enable( sal_False );
675 m_aSubstitutionsText.Enable( sal_False );
676 m_aAddButton.Enable( sal_False );
677 m_aToFontBox.Enable( sal_False );
678 m_aToFontText.Enable( sal_False );
679 m_aFromFontBox.Enable( sal_False );
680 m_aFromFontText.Enable( sal_False );
683 update();
685 m_aAddButton.SetClickHdl( LINK( this, RTSFontSubstPage, ClickBtnHdl ) );
686 m_aRemoveButton.SetClickHdl( LINK( this, RTSFontSubstPage, ClickBtnHdl ) );
687 m_aEnableBox.SetClickHdl( LINK( this, RTSFontSubstPage, ClickBtnHdl ) );
688 m_aSubstitutionsBox.SetSelectHdl( LINK( this, RTSFontSubstPage, SelectHdl ) );
689 m_aSubstitutionsBox.setDelPressedLink( LINK( this, RTSFontSubstPage, DelPressedHdl ) );
692 RTSFontSubstPage::~RTSFontSubstPage()
696 void RTSFontSubstPage::update()
698 m_aSubstitutionsBox.Clear();
699 m_aRemoveButton.Enable( sal_False );
700 // fill substitutions box
701 ::boost::unordered_map< OUString, OUString, OUStringHash >::const_iterator it;
702 for( it = m_pParent->m_aJobData.m_aFontSubstitutes.begin();
703 it != m_pParent->m_aJobData.m_aFontSubstitutes.end(); ++it )
705 OUString aEntry = it->first + " -> " + it->second;
706 m_aSubstitutionsBox.InsertEntry( aEntry );
710 IMPL_LINK( RTSFontSubstPage, DelPressedHdl, ListBox*, pBox )
712 if( pBox == &m_aSubstitutionsBox &&
713 m_aRemoveButton.IsEnabled() )
714 ClickBtnHdl( &m_aRemoveButton );
715 return 0;
718 IMPL_LINK( RTSFontSubstPage, SelectHdl, ListBox*, pBox )
720 if( pBox == &m_aSubstitutionsBox )
722 m_aRemoveButton.Enable( m_aSubstitutionsBox.GetSelectEntryCount() && m_pParent->m_aJobData.m_bPerformFontSubstitution );
724 return 0;
727 IMPL_LINK( RTSFontSubstPage, ClickBtnHdl, Button*, pButton )
729 if( pButton == &m_aAddButton )
731 m_pParent->m_aJobData.m_aFontSubstitutes[ m_aFromFontBox.GetText() ] = m_aToFontBox.GetSelectEntry();
732 update();
734 else if( pButton == &m_aRemoveButton )
736 for( int i = 0; i < m_aSubstitutionsBox.GetSelectEntryCount(); i++ )
738 String aEntry( m_aSubstitutionsBox.GetSelectEntry( i ) );
739 sal_uInt16 nPos = aEntry.SearchAscii( " -> " );
740 aEntry.Erase( nPos );
741 m_pParent->m_aJobData.m_aFontSubstitutes.erase( aEntry );
743 update();
745 else if( pButton == &m_aEnableBox )
747 m_pParent->m_aJobData.m_bPerformFontSubstitution = m_aEnableBox.IsChecked() ? true : false;
748 m_aSubstitutionsBox.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
749 m_aSubstitutionsText.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
750 m_aAddButton.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
751 m_aRemoveButton.Enable( m_aSubstitutionsBox.GetSelectEntryCount() && m_pParent->m_aJobData.m_bPerformFontSubstitution );
752 m_aToFontBox.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
753 m_aToFontText.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
754 m_aFromFontBox.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
755 m_aFromFontText.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
757 return 0;
761 class RTSPWDialog : public ModalDialog
763 FixedText m_aText;
764 FixedText m_aUserText;
765 Edit m_aUserEdit;
766 FixedText m_aPassText;
767 Edit m_aPassEdit;
769 OKButton m_aOKButton;
770 CancelButton m_aCancelButton;
771 public:
772 RTSPWDialog( const OString& rServer, const OString& rUserName, Window* pParent );
773 ~RTSPWDialog();
775 OString getUserName() const;
776 OString getPassword() const;
779 RTSPWDialog::RTSPWDialog( const OString& rServer, const OString& rUserName, Window* pParent )
781 ModalDialog( pParent, PaResId( RID_RTS_PWDIALOG ) ),
782 m_aText( this, PaResId( RID_RTS_PWDIALOG_TXT ) ),
783 m_aUserText( this, PaResId( RID_RTS_PWDIALOG_USER_TXT ) ),
784 m_aUserEdit( this, PaResId( RID_RTS_PWDIALOG_USER_EDT ) ),
785 m_aPassText( this, PaResId( RID_RTS_PWDIALOG_PASS_TXT ) ),
786 m_aPassEdit( this, PaResId( RID_RTS_PWDIALOG_PASS_EDT ) ),
787 m_aOKButton( this, PaResId( RID_RTS_PWDIALOG_OK_BTN ) ),
788 m_aCancelButton( this, PaResId( RID_RTS_PWDIALOG_CANCEL_BTN ) )
790 FreeResource();
791 String aText( m_aText.GetText() );
792 aText.SearchAndReplace( String( "%s" ), OStringToOUString( rServer, osl_getThreadTextEncoding() ) );
793 m_aText.SetText( aText );
794 m_aUserEdit.SetText( OStringToOUString( rUserName, osl_getThreadTextEncoding() ) );
797 RTSPWDialog::~RTSPWDialog()
801 OString RTSPWDialog::getUserName() const
803 return OUStringToOString( m_aUserEdit.GetText(), osl_getThreadTextEncoding() );
806 OString RTSPWDialog::getPassword() const
808 return OUStringToOString( m_aPassEdit.GetText(), osl_getThreadTextEncoding() );
811 extern "C" {
813 int SPA_DLLPUBLIC Sal_SetupPrinterDriver( ::psp::PrinterInfo& rJobData )
815 int nRet = 0;
816 RTSDialog aDialog( rJobData, rJobData.m_aPrinterName, false );
818 if( aDialog.Execute() )
820 rJobData = aDialog.getSetup();
821 nRet = 1;
824 return nRet;
827 int SPA_DLLPUBLIC Sal_queryFaxNumber( String& rNumber )
829 String aTmpString( PaResId( RID_TXT_QUERYFAXNUMBER ) );
830 QueryString aQuery( NULL, aTmpString, rNumber );
831 return aQuery.Execute();
834 bool SPA_DLLPUBLIC Sal_authenticateQuery( const OString& rServer, OString& rUserName, OString& rPassword )
836 bool bRet = false;
838 RTSPWDialog aDialog( rServer, rUserName, NULL );
839 if( aDialog.Execute() )
841 rUserName = aDialog.getUserName();
842 rPassword = aDialog.getPassword();
843 bRet = true;
845 return bRet;
848 } // extern "C"
850 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */