1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_desktop.hxx"
30 
31 #include "dp_gui.hrc"
32 #include "svtools/controldims.hrc"
33 #include "svtools/svtools.hrc"
34 
35 #include "dp_gui.h"
36 #include "dp_gui_dialog2.hxx"
37 #include "dp_gui_extlistbox.hxx"
38 #include "dp_gui_shared.hxx"
39 #include "dp_gui_theextmgr.hxx"
40 #include "dp_gui_extensioncmdqueue.hxx"
41 #include "dp_misc.h"
42 #include "dp_ucb.h"
43 #include "dp_update.hxx"
44 #include "dp_identifier.hxx"
45 #include "dp_descriptioninfoset.hxx"
46 
47 #include "vcl/ctrl.hxx"
48 #include "vcl/menu.hxx"
49 #include "vcl/msgbox.hxx"
50 #include "vcl/scrbar.hxx"
51 #include "vcl/svapp.hxx"
52 
53 #include "vos/mutex.hxx"
54 
55 #include "svtools/extensionlistbox.hxx"
56 
57 #include "sfx2/sfxdlg.hxx"
58 
59 #include "comphelper/anytostring.hxx"
60 #include "cppuhelper/exc_hlp.hxx"
61 #include "cppuhelper/bootstrap.hxx"
62 
63 #include "comphelper/processfactory.hxx"
64 #include "ucbhelper/content.hxx"
65 #include "unotools/collatorwrapper.hxx"
66 
67 #include "com/sun/star/beans/StringPair.hpp"
68 
69 #include "com/sun/star/i18n/CollatorOptions.hpp"
70 
71 #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
72 #include "com/sun/star/system/XSystemShellExecute.hpp"
73 
74 #include "com/sun/star/ui/dialogs/ExecutableDialogResults.hpp"
75 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
76 #include "com/sun/star/ui/dialogs/XFilePicker.hpp"
77 #include "com/sun/star/ui/dialogs/XFilterManager.hpp"
78 
79 #include "com/sun/star/uno/Any.hxx"
80 #include "com/sun/star/uno/XComponentContext.hpp"
81 
82 #include <map>
83 #include <vector>
84 #include <boost/shared_ptr.hpp>
85 
86 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
87 
88 using namespace ::com::sun::star;
89 using namespace ::com::sun::star::system;
90 
91 using ::rtl::OUString;
92 
93 
94 namespace dp_gui {
95 
96 #define TOP_OFFSET           5
97 #define LINE_SIZE            4
98 #define PROGRESS_WIDTH      60
99 #define PROGRESS_HEIGHT     14
100 
101 //------------------------------------------------------------------------------
102 struct StrAllFiles : public rtl::StaticWithInit< const OUString, StrAllFiles >
103 {
104     const OUString operator () () {
105         const ::vos::OGuard guard( Application::GetSolarMutex() );
106         ::std::auto_ptr< ResMgr > const resmgr( ResMgr::CreateResMgr( "fps_office" ) );
107         OSL_ASSERT( resmgr.get() != 0 );
108         String ret( ResId( STR_FILTERNAME_ALL, *resmgr.get() ) );
109         return ret;
110     }
111 };
112 
113 //------------------------------------------------------------------------------
114 //                            ExtBoxWithBtns_Impl
115 //------------------------------------------------------------------------------
116 
117 enum MENU_COMMAND
118 {
119     CMD_NONE    = 0,
120     CMD_REMOVE  = 1,
121     CMD_ENABLE,
122     CMD_DISABLE,
123     CMD_UPDATE,
124     CMD_SHOW_LICENSE
125 };
126 
127 class ExtBoxWithBtns_Impl : public ExtensionBox_Impl
128 {
129     Size            m_aOutputSize;
130     bool            m_bInterfaceLocked;
131 
132     PushButton     *m_pOptionsBtn;
133     PushButton     *m_pEnableBtn;
134     PushButton     *m_pRemoveBtn;
135 
136     ExtMgrDialog   *m_pParent;
137 
138     void            SetButtonPos( const Rectangle& rRect );
139     void            SetButtonStatus( const TEntry_Impl pEntry );
140     bool            HandleTabKey( bool bReverse );
141     MENU_COMMAND    ShowPopupMenu( const Point &rPos, const long nPos );
142 
143     //-----------------
144     DECL_DLLPRIVATE_LINK( ScrollHdl, ScrollBar * );
145 
146     DECL_DLLPRIVATE_LINK( HandleOptionsBtn, void * );
147     DECL_DLLPRIVATE_LINK( HandleEnableBtn, void * );
148     DECL_DLLPRIVATE_LINK( HandleRemoveBtn, void * );
149     DECL_DLLPRIVATE_LINK( HandleHyperlink, svt::FixedHyperlink * );
150 
151 public:
152                     ExtBoxWithBtns_Impl( ExtMgrDialog* pParent, TheExtensionManager *pManager );
153                    ~ExtBoxWithBtns_Impl();
154 
155     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
156     virtual long    Notify( NotifyEvent& rNEvt );
157 
158     const Size      GetMinOutputSizePixel() const;
159 
160     virtual void    RecalcAll();
161     virtual void    selectEntry( const long nPos );
162     //-----------------
163     void            enableButtons( bool bEnable );
164 };
165 
166 //------------------------------------------------------------------------------
167 ExtBoxWithBtns_Impl::ExtBoxWithBtns_Impl( ExtMgrDialog* pParent, TheExtensionManager *pManager ) :
168     ExtensionBox_Impl( pParent, pManager ),
169     m_bInterfaceLocked( false ),
170     m_pOptionsBtn( NULL ),
171     m_pEnableBtn( NULL ),
172     m_pRemoveBtn( NULL ),
173     m_pParent( pParent )
174 {
175     m_pOptionsBtn = new PushButton( this, WB_TABSTOP );
176     m_pEnableBtn = new PushButton( this, WB_TABSTOP );
177     m_pRemoveBtn = new PushButton( this, WB_TABSTOP );
178 
179     SetHelpId( HID_EXTENSION_MANAGER_LISTBOX );
180     m_pOptionsBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_OPTIONS );
181     m_pEnableBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_DISABLE );
182     m_pRemoveBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_REMOVE );
183 
184     m_pOptionsBtn->SetClickHdl( LINK( this, ExtBoxWithBtns_Impl, HandleOptionsBtn ) );
185     m_pEnableBtn->SetClickHdl( LINK( this, ExtBoxWithBtns_Impl, HandleEnableBtn ) );
186     m_pRemoveBtn->SetClickHdl( LINK( this, ExtBoxWithBtns_Impl, HandleRemoveBtn ) );
187 
188     m_pOptionsBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_OPTIONS ) );
189     m_pEnableBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
190     m_pRemoveBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_REMOVE ) );
191 
192     Size aSize = LogicToPixel( Size( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ),
193                                MapMode( MAP_APPFONT ) );
194     m_pOptionsBtn->SetSizePixel( aSize );
195     m_pEnableBtn->SetSizePixel( aSize );
196     m_pRemoveBtn->SetSizePixel( aSize );
197 
198     SetExtraSize( aSize.Height() + 2 * TOP_OFFSET );
199 
200     SetScrollHdl( LINK( this, ExtBoxWithBtns_Impl, ScrollHdl ) );
201 }
202 
203 //------------------------------------------------------------------------------
204 ExtBoxWithBtns_Impl::~ExtBoxWithBtns_Impl()
205 {
206     delete m_pOptionsBtn;
207     delete m_pEnableBtn;
208     delete m_pRemoveBtn;
209 }
210 
211 //------------------------------------------------------------------------------
212 //------------------------------------------------------------------------------
213 //------------------------------------------------------------------------------
214 const Size ExtBoxWithBtns_Impl::GetMinOutputSizePixel() const
215 {
216     Size aMinSize( ExtensionBox_Impl::GetMinOutputSizePixel() );
217     long nHeight = aMinSize.Height();
218     nHeight += m_pOptionsBtn->GetSizePixel().Height();
219     nHeight +=  2 * TOP_OFFSET;
220     long nWidth = m_pOptionsBtn->GetSizePixel().Width();
221     nWidth *= 3;
222     nWidth += 5*TOP_OFFSET + 20;
223 
224     return Size( nWidth, nHeight );
225 }
226 
227 // -----------------------------------------------------------------------
228 void ExtBoxWithBtns_Impl::RecalcAll()
229 {
230     const sal_Int32 nActive = getSelIndex();
231 
232     if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
233     {
234         SetButtonStatus( GetEntryData( nActive) );
235     }
236     else
237     {
238         m_pOptionsBtn->Hide();
239         m_pEnableBtn->Hide();
240         m_pRemoveBtn->Hide();
241     }
242 
243     ExtensionBox_Impl::RecalcAll();
244 
245     if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
246         SetButtonPos( GetEntryRect( nActive ) );
247 }
248 
249 
250 //------------------------------------------------------------------------------
251 //This function may be called with nPos < 0
252 void ExtBoxWithBtns_Impl::selectEntry( const long nPos )
253 {
254     if ( HasActive() && ( nPos == getSelIndex() ) )
255         return;
256 
257     ExtensionBox_Impl::selectEntry( nPos );
258 }
259 
260 // -----------------------------------------------------------------------
261 void ExtBoxWithBtns_Impl::SetButtonPos( const Rectangle& rRect )
262 {
263     Size  aBtnSize( m_pOptionsBtn->GetSizePixel() );
264     Point aBtnPos( rRect.Left() + ICON_OFFSET,
265                    rRect.Bottom() - TOP_OFFSET - aBtnSize.Height() );
266 
267     m_pOptionsBtn->SetPosPixel( aBtnPos );
268     aBtnPos.X() = rRect.Right() - TOP_OFFSET - aBtnSize.Width();
269     m_pRemoveBtn->SetPosPixel( aBtnPos );
270     aBtnPos.X() -= ( TOP_OFFSET + aBtnSize.Width() );
271     m_pEnableBtn->SetPosPixel( aBtnPos );
272 }
273 
274 // -----------------------------------------------------------------------
275 void ExtBoxWithBtns_Impl::SetButtonStatus( const TEntry_Impl pEntry )
276 {
277     bool bShowOptionBtn = true;
278 
279     pEntry->m_bHasButtons = false;
280     if ( ( pEntry->m_eState == REGISTERED ) || ( pEntry->m_eState == NOT_AVAILABLE ) )
281     {
282         m_pEnableBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
283         m_pEnableBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_DISABLE );
284     }
285     else
286     {
287         m_pEnableBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_ENABLE ) );
288         m_pEnableBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_ENABLE );
289         bShowOptionBtn = false;
290     }
291 
292     if ( ( !pEntry->m_bUser || ( pEntry->m_eState == NOT_AVAILABLE ) || pEntry->m_bMissingDeps )
293          && !pEntry->m_bMissingLic )
294         m_pEnableBtn->Hide();
295     else
296     {
297         m_pEnableBtn->Enable( !pEntry->m_bLocked );
298         m_pEnableBtn->Show();
299         pEntry->m_bHasButtons = true;
300     }
301 
302     if ( pEntry->m_bHasOptions && bShowOptionBtn )
303     {
304         m_pOptionsBtn->Enable( pEntry->m_bHasOptions );
305         m_pOptionsBtn->Show();
306         pEntry->m_bHasButtons = true;
307     }
308     else
309         m_pOptionsBtn->Hide();
310 
311     if ( pEntry->m_bUser || pEntry->m_bShared )
312     {
313         m_pRemoveBtn->Enable( !pEntry->m_bLocked );
314         m_pRemoveBtn->Show();
315         pEntry->m_bHasButtons = true;
316     }
317     else
318         m_pRemoveBtn->Hide();
319 }
320 
321 // -----------------------------------------------------------------------
322 bool ExtBoxWithBtns_Impl::HandleTabKey( bool bReverse )
323 {
324     sal_Int32 nIndex = getSelIndex();
325 
326     if ( nIndex == EXTENSION_LISTBOX_ENTRY_NOTFOUND )
327         return false;
328 
329     PushButton *pNext = NULL;
330 
331     if ( m_pOptionsBtn->HasFocus() ) {
332         if ( !bReverse && !GetEntryData( nIndex )->m_bLocked )
333             pNext = m_pEnableBtn;
334     }
335     else if ( m_pEnableBtn->HasFocus() ) {
336         if ( !bReverse )
337             pNext = m_pRemoveBtn;
338         else if ( GetEntryData( nIndex )->m_bHasOptions )
339             pNext = m_pOptionsBtn;
340     }
341     else if ( m_pRemoveBtn->HasFocus() ) {
342         if ( bReverse )
343             pNext = m_pEnableBtn;
344     }
345     else {
346         if ( !bReverse ) {
347             if ( GetEntryData( nIndex )->m_bHasOptions )
348                 pNext = m_pOptionsBtn;
349             else if ( ! GetEntryData( nIndex )->m_bLocked )
350                 pNext = m_pEnableBtn;
351         } else {
352             if ( ! GetEntryData( nIndex )->m_bLocked )
353                 pNext = m_pRemoveBtn;
354             else if ( GetEntryData( nIndex )->m_bHasOptions )
355                 pNext = m_pOptionsBtn;
356         }
357     }
358 
359     if ( pNext )
360     {
361         pNext->GrabFocus();
362         return true;
363     }
364     else
365         return false;
366 }
367 
368 // -----------------------------------------------------------------------
369 MENU_COMMAND ExtBoxWithBtns_Impl::ShowPopupMenu( const Point & rPos, const long nPos )
370 {
371     if ( nPos >= (long) getItemCount() )
372         return CMD_NONE;
373 
374     PopupMenu aPopup;
375 
376     aPopup.InsertItem( CMD_UPDATE, DialogHelper::getResourceString( RID_CTX_ITEM_CHECK_UPDATE ) );
377 
378     if ( ! GetEntryData( nPos )->m_bLocked )
379     {
380     	if ( GetEntryData( nPos )->m_bUser )
381     	{
382             if ( GetEntryData( nPos )->m_eState == REGISTERED )
383                 aPopup.InsertItem( CMD_DISABLE, DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
384             else if ( GetEntryData( nPos )->m_eState != NOT_AVAILABLE )
385                 aPopup.InsertItem( CMD_ENABLE, DialogHelper::getResourceString( RID_CTX_ITEM_ENABLE ) );
386         }
387         aPopup.InsertItem( CMD_REMOVE, DialogHelper::getResourceString( RID_CTX_ITEM_REMOVE ) );
388     }
389 
390     if ( GetEntryData( nPos )->m_sLicenseText.Len() )
391         aPopup.InsertItem( CMD_SHOW_LICENSE, DialogHelper::getResourceString( RID_STR_SHOW_LICENSE_CMD ) );
392 
393     return (MENU_COMMAND) aPopup.Execute( this, rPos );
394 }
395 
396 //------------------------------------------------------------------------------
397 void ExtBoxWithBtns_Impl::MouseButtonDown( const MouseEvent& rMEvt )
398 {
399     if ( m_bInterfaceLocked )
400         return;
401 
402     const Point aMousePos( rMEvt.GetPosPixel() );
403     const long nPos = PointToPos( aMousePos );
404 
405     if ( rMEvt.IsRight() )
406     {
407         switch( ShowPopupMenu( aMousePos, nPos ) )
408         {
409             case CMD_NONE:      break;
410             case CMD_ENABLE:    m_pParent->enablePackage( GetEntryData( nPos )->m_xPackage, true );
411                                 break;
412             case CMD_DISABLE:   m_pParent->enablePackage( GetEntryData( nPos )->m_xPackage, false );
413                                 break;
414             case CMD_UPDATE:    m_pParent->updatePackage( GetEntryData( nPos )->m_xPackage );
415                                 break;
416             case CMD_REMOVE:    m_pParent->removePackage( GetEntryData( nPos )->m_xPackage );
417                                 break;
418             case CMD_SHOW_LICENSE:
419                 {
420                     ShowLicenseDialog aLicenseDlg( m_pParent, GetEntryData( nPos )->m_xPackage );
421                     aLicenseDlg.Execute();
422                     break;
423                 }
424         }
425     }
426     else if ( rMEvt.IsLeft() )
427     {
428         if ( rMEvt.IsMod1() && HasActive() )
429             selectEntry( EXTENSION_LISTBOX_ENTRY_NOTFOUND );   // Selecting an not existing entry will deselect the current one
430         else
431             selectEntry( nPos );
432     }
433 }
434 
435 //------------------------------------------------------------------------------
436 long ExtBoxWithBtns_Impl::Notify( NotifyEvent& rNEvt )
437 {
438     bool bHandled = false;
439 
440     if ( rNEvt.GetType() == EVENT_KEYINPUT )
441     {
442         const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
443         KeyCode         aKeyCode = pKEvt->GetKeyCode();
444         sal_uInt16          nKeyCode = aKeyCode.GetCode();
445 
446         if ( nKeyCode == KEY_TAB )
447             bHandled = HandleTabKey( aKeyCode.IsShift() );
448     }
449 
450     if ( !bHandled )
451         return ExtensionBox_Impl::Notify( rNEvt );
452     else
453         return true;
454 }
455 
456 //------------------------------------------------------------------------------
457 void ExtBoxWithBtns_Impl::enableButtons( bool bEnable )
458 {
459     m_bInterfaceLocked = ! bEnable;
460 
461     if ( bEnable )
462     {
463         sal_Int32 nIndex = getSelIndex();
464         if ( nIndex != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
465             SetButtonStatus( GetEntryData( nIndex ) );
466     }
467     else
468     {
469         m_pOptionsBtn->Enable( false );
470         m_pRemoveBtn->Enable( false );
471         m_pEnableBtn->Enable( false );
472     }
473 }
474 
475 // -----------------------------------------------------------------------
476 IMPL_LINK( ExtBoxWithBtns_Impl, ScrollHdl, ScrollBar*, pScrBar )
477 {
478     long nDelta = pScrBar->GetDelta();
479 
480     Point aNewOptPt( m_pOptionsBtn->GetPosPixel() - Point( 0, nDelta ) );
481     Point aNewRemPt( m_pRemoveBtn->GetPosPixel() - Point( 0, nDelta ) );
482     Point aNewEnPt( m_pEnableBtn->GetPosPixel() - Point( 0, nDelta ) );
483 
484     DoScroll( nDelta );
485 
486     m_pOptionsBtn->SetPosPixel( aNewOptPt );
487     m_pRemoveBtn->SetPosPixel( aNewRemPt );
488     m_pEnableBtn->SetPosPixel( aNewEnPt );
489 
490     return 1;
491 }
492 
493 // -----------------------------------------------------------------------
494 IMPL_LINK( ExtBoxWithBtns_Impl, HandleOptionsBtn, void*, EMPTYARG )
495 {
496     const sal_Int32 nActive = getSelIndex();
497 
498     if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
499     {
500         SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
501 
502         if ( pFact )
503         {
504             OUString sExtensionId = GetEntryData( nActive )->m_xPackage->getIdentifier().Value;
505             VclAbstractDialog* pDlg = pFact->CreateOptionsDialog( this, sExtensionId, rtl::OUString() );
506 
507             pDlg->Execute();
508 
509             delete pDlg;
510         }
511     }
512 
513     return 1;
514 }
515 
516 // -----------------------------------------------------------------------
517 IMPL_LINK( ExtBoxWithBtns_Impl, HandleEnableBtn, void*, EMPTYARG )
518 {
519     const sal_Int32 nActive = getSelIndex();
520 
521     if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
522     {
523         TEntry_Impl pEntry = GetEntryData( nActive );
524 
525         if ( pEntry->m_bMissingLic )
526             m_pParent->acceptLicense( pEntry->m_xPackage );
527         else
528         {
529             const bool bEnable( pEntry->m_eState != REGISTERED );
530             m_pParent->enablePackage( pEntry->m_xPackage, bEnable );
531         }
532     }
533 
534     return 1;
535 }
536 
537 // -----------------------------------------------------------------------
538 IMPL_LINK( ExtBoxWithBtns_Impl, HandleRemoveBtn, void*, EMPTYARG )
539 {
540     const sal_Int32 nActive = getSelIndex();
541 
542     if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
543     {
544         TEntry_Impl pEntry = GetEntryData( nActive );
545         m_pParent->removePackage( pEntry->m_xPackage );
546     }
547 
548     return 1;
549 }
550 
551 //------------------------------------------------------------------------------
552 //                             DialogHelper
553 //------------------------------------------------------------------------------
554 DialogHelper::DialogHelper( const uno::Reference< uno::XComponentContext > &xContext,
555                             Dialog *pWindow ) :
556     m_pVCLWindow( pWindow ),
557     m_nEventID(   0 ),
558     m_bIsBusy(    false )
559 {
560     m_xContext = xContext;
561 }
562 
563 //------------------------------------------------------------------------------
564 DialogHelper::~DialogHelper()
565 {
566     if ( m_nEventID )
567         Application::RemoveUserEvent( m_nEventID );
568 }
569 
570 //------------------------------------------------------------------------------
571 ResId DialogHelper::getResId( sal_uInt16 nId )
572 {
573     const ::vos::OGuard guard( Application::GetSolarMutex() );
574     return ResId( nId, *DeploymentGuiResMgr::get() );
575 }
576 
577 //------------------------------------------------------------------------------
578 String DialogHelper::getResourceString( sal_uInt16 id )
579 {
580     // init with non-acquired solar mutex:
581     BrandName::get();
582     const ::vos::OGuard guard( Application::GetSolarMutex() );
583     String ret( ResId( id, *DeploymentGuiResMgr::get() ) );
584     if (ret.SearchAscii( "%PRODUCTNAME" ) != STRING_NOTFOUND) {
585         ret.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
586     }
587     return ret;
588 }
589 
590 //------------------------------------------------------------------------------
591 bool DialogHelper::IsSharedPkgMgr( const uno::Reference< deployment::XPackage > &xPackage )
592 {
593     if ( xPackage->getRepositoryName().equals( OUSTR("shared") ) )
594         return true;
595     else
596         return false;
597 }
598 
599 //------------------------------------------------------------------------------
600 bool DialogHelper::continueOnSharedExtension( const uno::Reference< deployment::XPackage > &xPackage,
601                                               Window *pParent,
602                                               const sal_uInt16 nResID,
603                                               bool &bHadWarning )
604 {
605     if ( !bHadWarning && IsSharedPkgMgr( xPackage ) )
606     {
607         const ::vos::OGuard guard( Application::GetSolarMutex() );
608         WarningBox aInfoBox( pParent, getResId( nResID ) );
609         String aMsgText = aInfoBox.GetMessText();
610         aMsgText.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
611         aInfoBox.SetMessText( aMsgText );
612 
613         bHadWarning = true;
614 
615         if ( RET_OK == aInfoBox.Execute() )
616             return true;
617         else
618             return false;
619     }
620     else
621         return true;
622 }
623 
624 //------------------------------------------------------------------------------
625 void DialogHelper::openWebBrowser( const OUString & sURL, const OUString &sTitle ) const
626 {
627     if ( ! sURL.getLength() ) // Nothing to do, when the URL is empty
628         return;
629 
630     try
631     {
632         uno::Reference< XSystemShellExecute > xSystemShellExecute(
633             m_xContext->getServiceManager()->createInstanceWithContext( OUSTR( "com.sun.star.system.SystemShellExecute" ), m_xContext), uno::UNO_QUERY_THROW);
634         //throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException
635         xSystemShellExecute->execute( sURL, OUString(),  SystemShellExecuteFlags::DEFAULTS );
636     }
637     catch ( uno::Exception& )
638     {
639         uno::Any exc( ::cppu::getCaughtException() );
640         OUString msg( ::comphelper::anyToString( exc ) );
641         const ::vos::OGuard guard( Application::GetSolarMutex() );
642         ErrorBox aErrorBox( NULL, WB_OK, msg );
643         aErrorBox.SetText( sTitle );
644         aErrorBox.Execute();
645     }
646 }
647 
648 //------------------------------------------------------------------------------
649 bool DialogHelper::installExtensionWarn( const OUString &rExtensionName ) const
650 {
651     const ::vos::OGuard guard( Application::GetSolarMutex() );
652     WarningBox aInfo( m_pVCLWindow, getResId( RID_WARNINGBOX_INSTALL_EXTENSION ) );
653 
654     String sText( aInfo.GetMessText() );
655     sText.SearchAndReplaceAllAscii( "%NAME", rExtensionName );
656     aInfo.SetMessText( sText );
657 
658     return ( RET_OK == aInfo.Execute() );
659 }
660 
661 //------------------------------------------------------------------------------
662 bool DialogHelper::installForAllUsers( bool &bInstallForAll ) const
663 {
664     const ::vos::OGuard guard( Application::GetSolarMutex() );
665     QueryBox aQuery( m_pVCLWindow, getResId( RID_QUERYBOX_INSTALL_FOR_ALL ) );
666 
667     String sMsgText = aQuery.GetMessText();
668     sMsgText.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
669     aQuery.SetMessText( sMsgText );
670 
671     sal_uInt16 nYesBtnID = aQuery.GetButtonId( 0 );
672     sal_uInt16 nNoBtnID = aQuery.GetButtonId( 1 );
673 
674     if ( nYesBtnID != BUTTONDIALOG_BUTTON_NOTFOUND )
675         aQuery.SetButtonText( nYesBtnID, getResourceString( RID_STR_INSTALL_FOR_ME ) );
676     if ( nNoBtnID != BUTTONDIALOG_BUTTON_NOTFOUND )
677         aQuery.SetButtonText( nNoBtnID, getResourceString( RID_STR_INSTALL_FOR_ALL ) );
678 
679     short nRet = aQuery.Execute();
680 
681     if ( nRet == RET_CANCEL )
682         return false;
683 
684     bInstallForAll = ( nRet == RET_NO );
685     return true;
686 }
687 
688 //------------------------------------------------------------------------------
689 void DialogHelper::PostUserEvent( const Link& rLink, void* pCaller )
690 {
691     if ( m_nEventID )
692         Application::RemoveUserEvent( m_nEventID );
693 
694     m_nEventID = Application::PostUserEvent( rLink, pCaller );
695 }
696 
697 //------------------------------------------------------------------------------
698 //                             ExtMgrDialog
699 //------------------------------------------------------------------------------
700 ExtMgrDialog::ExtMgrDialog( Window *pParent, TheExtensionManager *pManager ) :
701     ModelessDialog( pParent, getResId( RID_DLG_EXTENSION_MANAGER ) ),
702     DialogHelper( pManager->getContext(), (Dialog*) this ),
703     m_aAddBtn( this,        getResId( RID_EM_BTN_ADD ) ),
704     m_aUpdateBtn( this,     getResId( RID_EM_BTN_CHECK_UPDATES ) ),
705     m_aCloseBtn( this,      getResId( RID_EM_BTN_CLOSE ) ),
706     m_aHelpBtn( this,       getResId( RID_EM_BTN_HELP ) ),
707     m_aDivider( this ),
708     m_aGetExtensions( this, getResId( RID_EM_FT_GET_EXTENSIONS ) ),
709     m_aProgressText( this,  getResId( RID_EM_FT_PROGRESS ) ),
710     m_aProgressBar( this,   WB_BORDER + WB_3DLOOK ),
711     m_aCancelBtn( this,     getResId( RID_EM_BTN_CANCEL ) ),
712     m_sAddPackages(         getResourceString( RID_STR_ADD_PACKAGES ) ),
713     m_bHasProgress(         false ),
714     m_bProgressChanged(     false ),
715     m_bStartProgress(       false ),
716     m_bStopProgress(        false ),
717     m_bUpdateWarning(       false ),
718     m_bEnableWarning(       false ),
719     m_bDisableWarning(      false ),
720     m_bDeleteWarning(       false ),
721     m_nProgress(            0 ),
722     m_pManager( pManager )
723 {
724     // free local resources (RID < 256):
725     FreeResource();
726 
727     m_pExtensionBox = new ExtBoxWithBtns_Impl( this, pManager );
728     m_pExtensionBox->SetHyperlinkHdl( LINK( this, ExtMgrDialog, HandleHyperlink ) );
729 
730     m_aAddBtn.SetClickHdl( LINK( this, ExtMgrDialog, HandleAddBtn ) );
731     m_aUpdateBtn.SetClickHdl( LINK( this, ExtMgrDialog, HandleUpdateBtn ) );
732     m_aGetExtensions.SetClickHdl( LINK( this, ExtMgrDialog, HandleHyperlink ) );
733     m_aCancelBtn.SetClickHdl( LINK( this, ExtMgrDialog, HandleCancelBtn ) );
734 
735     // resize update button
736     Size aBtnSize = m_aUpdateBtn.GetSizePixel();
737     String sTitle = m_aUpdateBtn.GetText();
738     long nWidth = m_aUpdateBtn.GetCtrlTextWidth( sTitle );
739     nWidth += 2 * m_aUpdateBtn.GetTextHeight();
740     if ( nWidth > aBtnSize.Width() )
741         m_aUpdateBtn.SetSizePixel( Size( nWidth, aBtnSize.Height() ) );
742 
743     // minimum size:
744     SetMinOutputSizePixel(
745         Size( // width:
746               (3 * m_aHelpBtn.GetSizePixel().Width()) +
747                    m_aUpdateBtn.GetSizePixel().Width() +
748               (5 * RSC_SP_DLG_INNERBORDER_LEFT ),
749               // height:
750               (1 * m_aHelpBtn.GetSizePixel().Height()) +
751               (1 * m_aGetExtensions.GetSizePixel().Height()) +
752               (1 * m_pExtensionBox->GetMinOutputSizePixel().Height()) +
753               (3 * RSC_SP_DLG_INNERBORDER_LEFT) ) );
754 
755     m_aDivider.Show();
756     m_aProgressBar.Hide();
757 
758     m_aUpdateBtn.Enable( false );
759 
760     m_aTimeoutTimer.SetTimeout( 500 ); // mSec
761     m_aTimeoutTimer.SetTimeoutHdl( LINK( this, ExtMgrDialog, TimeOutHdl ) );
762 }
763 
764 //------------------------------------------------------------------------------
765 ExtMgrDialog::~ExtMgrDialog()
766 {
767     m_aTimeoutTimer.Stop();
768     delete m_pExtensionBox;
769 }
770 
771 //------------------------------------------------------------------------------
772 void ExtMgrDialog::setGetExtensionsURL( const ::rtl::OUString &rURL )
773 {
774     m_aGetExtensions.SetURL( rURL );
775 }
776 
777 //------------------------------------------------------------------------------
778 long ExtMgrDialog::addPackageToList( const uno::Reference< deployment::XPackage > &xPackage,
779                                      bool bLicenseMissing )
780 {
781     m_aUpdateBtn.Enable( true );
782     return m_pExtensionBox->addEntry( xPackage, bLicenseMissing );
783 }
784 
785 //------------------------------------------------------------------------------
786 void ExtMgrDialog::prepareChecking()
787 {
788     m_pExtensionBox->prepareChecking();
789 }
790 
791 //------------------------------------------------------------------------------
792 void ExtMgrDialog::checkEntries()
793 {
794     const ::vos::OGuard guard( Application::GetSolarMutex() );
795     m_pExtensionBox->checkEntries();
796 }
797 
798 //------------------------------------------------------------------------------
799 bool ExtMgrDialog::removeExtensionWarn( const OUString &rExtensionName ) const
800 {
801     const ::vos::OGuard guard( Application::GetSolarMutex() );
802     WarningBox aInfo( const_cast< ExtMgrDialog* >(this), getResId( RID_WARNINGBOX_REMOVE_EXTENSION ) );
803 
804     String sText( aInfo.GetMessText() );
805     sText.SearchAndReplaceAllAscii( "%NAME", rExtensionName );
806     aInfo.SetMessText( sText );
807 
808     return ( RET_OK == aInfo.Execute() );
809 }
810 
811 //------------------------------------------------------------------------------
812 bool ExtMgrDialog::enablePackage( const uno::Reference< deployment::XPackage > &xPackage,
813                                   bool bEnable )
814 {
815     if ( !xPackage.is() )
816         return false;
817 
818     if ( bEnable )
819     {
820         if ( ! continueOnSharedExtension( xPackage, this, RID_WARNINGBOX_ENABLE_SHARED_EXTENSION, m_bEnableWarning ) )
821             return false;
822     }
823     else
824     {
825         if ( ! continueOnSharedExtension( xPackage, this, RID_WARNINGBOX_DISABLE_SHARED_EXTENSION, m_bDisableWarning ) )
826             return false;
827     }
828 
829     m_pManager->getCmdQueue()->enableExtension( xPackage, bEnable );
830 
831     return true;
832 }
833 
834 //------------------------------------------------------------------------------
835 bool ExtMgrDialog::removePackage( const uno::Reference< deployment::XPackage > &xPackage )
836 {
837     if ( !xPackage.is() )
838         return false;
839 
840     if ( !IsSharedPkgMgr( xPackage ) || m_bDeleteWarning )
841     {
842         if ( ! removeExtensionWarn( xPackage->getDisplayName() ) )
843             return false;
844     }
845 
846     if ( ! continueOnSharedExtension( xPackage, this, RID_WARNINGBOX_REMOVE_SHARED_EXTENSION, m_bDeleteWarning ) )
847         return false;
848 
849     m_pManager->getCmdQueue()->removeExtension( xPackage );
850 
851     return true;
852 }
853 
854 //------------------------------------------------------------------------------
855 bool ExtMgrDialog::updatePackage( const uno::Reference< deployment::XPackage > &xPackage )
856 {
857     if ( !xPackage.is() )
858         return false;
859 
860 	// get the extension with highest version
861 	uno::Sequence<uno::Reference<deployment::XPackage> > seqExtensions =
862 	m_pManager->getExtensionManager()->getExtensionsWithSameIdentifier(
863 		dp_misc::getIdentifier(xPackage), xPackage->getName(), uno::Reference<ucb::XCommandEnvironment>());
864 	uno::Reference<deployment::XPackage> extension =
865 		dp_misc::getExtensionWithHighestVersion(seqExtensions);
866 	OSL_ASSERT(extension.is());
867     std::vector< css::uno::Reference< css::deployment::XPackage > > vEntries;
868     vEntries.push_back(extension);
869 
870     m_pManager->getCmdQueue()->checkForUpdates( vEntries );
871 
872     return true;
873 }
874 
875 //------------------------------------------------------------------------------
876 bool ExtMgrDialog::acceptLicense( const uno::Reference< deployment::XPackage > &xPackage )
877 {
878     if ( !xPackage.is() )
879         return false;
880 
881     m_pManager->getCmdQueue()->acceptLicense( xPackage );
882 
883     return true;
884 }
885 
886 //------------------------------------------------------------------------------
887 uno::Sequence< OUString > ExtMgrDialog::raiseAddPicker()
888 {
889     const uno::Any mode( static_cast< sal_Int16 >( ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE ) );
890     const uno::Reference< uno::XComponentContext > xContext( m_pManager->getContext() );
891     const uno::Reference< ui::dialogs::XFilePicker > xFilePicker(
892         xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
893             OUSTR("com.sun.star.ui.dialogs.FilePicker"),
894             uno::Sequence< uno::Any >( &mode, 1 ), xContext ), uno::UNO_QUERY_THROW );
895     xFilePicker->setTitle( m_sAddPackages );
896 
897     if ( m_sLastFolderURL.Len() )
898         xFilePicker->setDisplayDirectory( m_sLastFolderURL );
899 
900     // collect and set filter list:
901     typedef ::std::map< OUString, OUString > t_string2string;
902     t_string2string title2filter;
903     OUString sDefaultFilter( StrAllFiles::get() );
904 
905     const uno::Sequence< uno::Reference< deployment::XPackageTypeInfo > > packageTypes(
906         m_pManager->getExtensionManager()->getSupportedPackageTypes() );
907 
908     for ( sal_Int32 pos = 0; pos < packageTypes.getLength(); ++pos )
909     {
910         uno::Reference< deployment::XPackageTypeInfo > const & xPackageType = packageTypes[ pos ];
911         const OUString filter( xPackageType->getFileFilter() );
912         if (filter.getLength() > 0)
913         {
914             const OUString title( xPackageType->getShortDescription() );
915             const ::std::pair< t_string2string::iterator, bool > insertion(
916                 title2filter.insert( t_string2string::value_type( title, filter ) ) );
917             if ( ! insertion.second )
918             { // already existing, append extensions:
919                 ::rtl::OUStringBuffer buf;
920                 buf.append( insertion.first->second );
921                 buf.append( static_cast<sal_Unicode>(';') );
922                 buf.append( filter );
923                 insertion.first->second = buf.makeStringAndClear();
924             }
925             if ( xPackageType->getMediaType() == OUSTR( "application/vnd.sun.star.package-bundle" ) )
926                 sDefaultFilter = title;
927         }
928     }
929 
930     const uno::Reference< ui::dialogs::XFilterManager > xFilterManager( xFilePicker, uno::UNO_QUERY_THROW );
931     // All files at top:
932     xFilterManager->appendFilter( StrAllFiles::get(), OUSTR("*.*") );
933     // then supported ones:
934     t_string2string::const_iterator iPos( title2filter.begin() );
935     const t_string2string::const_iterator iEnd( title2filter.end() );
936     for ( ; iPos != iEnd; ++iPos ) {
937         try {
938             xFilterManager->appendFilter( iPos->first, iPos->second );
939         }
940         catch (lang::IllegalArgumentException & exc) {
941             OSL_ENSURE( 0, ::rtl::OUStringToOString(
942                             exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
943             (void) exc;
944         }
945     }
946     xFilterManager->setCurrentFilter( sDefaultFilter );
947 
948     if ( xFilePicker->execute() != ui::dialogs::ExecutableDialogResults::OK )
949         return uno::Sequence<OUString>(); // cancelled
950 
951     m_sLastFolderURL = xFilePicker->getDisplayDirectory();
952     uno::Sequence< OUString > files( xFilePicker->getFiles() );
953     OSL_ASSERT( files.getLength() > 0 );
954     return files;
955 }
956 
957 //------------------------------------------------------------------------------
958 IMPL_LINK( ExtMgrDialog, HandleCancelBtn, void*, EMPTYARG )
959 {
960     // m_dialog->m_cmdEnv->m_aborted = true;
961     if ( m_xAbortChannel.is() )
962     {
963         try
964         {
965             m_xAbortChannel->sendAbort();
966         }
967         catch ( uno::RuntimeException & )
968         {
969             OSL_ENSURE( 0, "### unexpected RuntimeException!" );
970         }
971     }
972     return 1;
973 }
974 
975 // ------------------------------------------------------------------------------
976 IMPL_LINK( ExtMgrDialog, startProgress, void*, _bLockInterface )
977 {
978     ::osl::MutexGuard aGuard( m_aMutex );
979     bool bLockInterface = (bool) _bLockInterface;
980 
981     if ( m_bStartProgress && !m_bHasProgress )
982         m_aTimeoutTimer.Start();
983 
984     if ( m_bStopProgress )
985     {
986 		if ( m_aProgressBar.IsVisible() )
987 	        m_aProgressBar.SetValue( 100 );
988         m_xAbortChannel.clear();
989 
990         OSL_TRACE( " startProgress handler: stop\n" );
991     }
992     else
993     {
994         OSL_TRACE( " startProgress handler: start\n" );
995     }
996 
997     m_aCancelBtn.Enable( bLockInterface );
998     m_aAddBtn.Enable( !bLockInterface );
999     m_aUpdateBtn.Enable( !bLockInterface && m_pExtensionBox->getItemCount() );
1000     m_pExtensionBox->enableButtons( !bLockInterface );
1001 
1002     clearEventID();
1003 
1004     return 0;
1005 }
1006 
1007 // ------------------------------------------------------------------------------
1008 void ExtMgrDialog::showProgress( bool _bStart )
1009 {
1010     ::osl::MutexGuard aGuard( m_aMutex );
1011 
1012     bool bStart = _bStart;
1013 
1014     if ( bStart )
1015     {
1016         m_nProgress = 0;
1017         m_bStartProgress = true;
1018         OSL_TRACE( "showProgress start\n" );
1019     }
1020     else
1021     {
1022         m_nProgress = 100;
1023         m_bStopProgress = true;
1024         OSL_TRACE( "showProgress stop!\n" );
1025     }
1026 
1027     DialogHelper::PostUserEvent( LINK( this, ExtMgrDialog, startProgress ), (void*) bStart );
1028 }
1029 
1030 // -----------------------------------------------------------------------
1031 void ExtMgrDialog::updateProgress( const long nProgress )
1032 {
1033     ::osl::MutexGuard aGuard( m_aMutex );
1034 
1035     m_nProgress = nProgress;
1036 }
1037 
1038 // -----------------------------------------------------------------------
1039 void ExtMgrDialog::updateProgress( const OUString &rText,
1040                                    const uno::Reference< task::XAbortChannel > &xAbortChannel)
1041 {
1042     ::osl::MutexGuard aGuard( m_aMutex );
1043 
1044     m_xAbortChannel = xAbortChannel;
1045     m_sProgressText = rText;
1046     m_bProgressChanged = true;
1047 }
1048 
1049 //------------------------------------------------------------------------------
1050 void ExtMgrDialog::updatePackageInfo( const uno::Reference< deployment::XPackage > &xPackage )
1051 {
1052     m_pExtensionBox->updateEntry( xPackage );
1053 }
1054 
1055 // -----------------------------------------------------------------------
1056 IMPL_LINK( ExtMgrDialog, HandleAddBtn, void*, EMPTYARG )
1057 {
1058     setBusy( true );
1059 
1060     uno::Sequence< OUString > aFileList = raiseAddPicker();
1061 
1062     if ( aFileList.getLength() )
1063     {
1064         m_pManager->installPackage( aFileList[0] );
1065     }
1066 
1067     setBusy( false );
1068     return 1;
1069 }
1070 
1071 // -----------------------------------------------------------------------
1072 IMPL_LINK( ExtMgrDialog, HandleUpdateBtn, void*, EMPTYARG )
1073 {
1074     m_pManager->checkUpdates( false, true );
1075 
1076     return 1;
1077 }
1078 
1079 // -----------------------------------------------------------------------
1080 IMPL_LINK( ExtMgrDialog, HandleHyperlink, svt::FixedHyperlink*, pHyperlink )
1081 {
1082     openWebBrowser( pHyperlink->GetURL(), GetText() );
1083 
1084     return 1;
1085 }
1086 
1087 // -----------------------------------------------------------------------
1088 IMPL_LINK( ExtMgrDialog, TimeOutHdl, Timer*, EMPTYARG )
1089 {
1090     if ( m_bStopProgress )
1091     {
1092         m_bHasProgress = false;
1093         m_bStopProgress = false;
1094         m_aProgressText.Hide();
1095         m_aProgressBar.Hide();
1096         m_aCancelBtn.Hide();
1097     }
1098     else
1099     {
1100         if ( m_bProgressChanged )
1101         {
1102             m_bProgressChanged = false;
1103             m_aProgressText.SetText( m_sProgressText );
1104         }
1105 
1106         if ( m_bStartProgress )
1107         {
1108             m_bStartProgress = false;
1109             m_bHasProgress = true;
1110             m_aProgressBar.Show();
1111             m_aProgressText.Show();
1112             m_aCancelBtn.Enable();
1113             m_aCancelBtn.Show();
1114         }
1115 
1116 		if ( m_aProgressBar.IsVisible() )
1117 			m_aProgressBar.SetValue( (sal_uInt16) m_nProgress );
1118 
1119         m_aTimeoutTimer.Start();
1120     }
1121 
1122 	return 1;
1123 }
1124 
1125 //------------------------------------------------------------------------------
1126 // VCL::Window / Dialog
1127 void ExtMgrDialog::Resize()
1128 {
1129     Size aTotalSize( GetOutputSizePixel() );
1130     Size aBtnSize( m_aHelpBtn.GetSizePixel() );
1131     Size aUpdBtnSize( m_aUpdateBtn.GetSizePixel() );
1132 
1133     Point aPos( RSC_SP_DLG_INNERBORDER_LEFT,
1134                 aTotalSize.Height() - RSC_SP_DLG_INNERBORDER_BOTTOM - aBtnSize.Height() );
1135 
1136     m_aHelpBtn.SetPosPixel( aPos );
1137 
1138     aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - aBtnSize.Width();
1139     m_aCloseBtn.SetPosPixel( aPos );
1140 
1141     aPos.X() -= ( RSC_SP_CTRL_X + aUpdBtnSize.Width() );
1142     m_aUpdateBtn.SetPosPixel( aPos );
1143 
1144     aPos.X() -= ( RSC_SP_CTRL_GROUP_Y + aBtnSize.Width() );
1145     m_aAddBtn.SetPosPixel( aPos );
1146 
1147     Size aDivSize( aTotalSize.Width(), LINE_SIZE );
1148     aPos = Point( 0, aPos.Y() - LINE_SIZE - RSC_SP_DLG_INNERBORDER_BOTTOM );
1149     m_aDivider.SetPosSizePixel( aPos, aDivSize );
1150 
1151     Size aFTSize( m_aGetExtensions.CalcMinimumSize() );
1152     aPos = Point( RSC_SP_DLG_INNERBORDER_LEFT, aPos.Y() - RSC_CD_FIXEDTEXT_HEIGHT - 2*RSC_SP_DLG_INNERBORDER_BOTTOM );
1153 
1154     m_aGetExtensions.SetPosSizePixel( aPos, aFTSize );
1155 
1156     aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - aBtnSize.Width();
1157     m_aCancelBtn.SetPosPixel( Point( aPos.X(), aPos.Y() - ((aBtnSize.Height()-aFTSize.Height())/2) ) );
1158 
1159     // Calc progress height
1160     long nProgressHeight = aFTSize.Height();
1161 
1162     if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
1163     {
1164         ImplControlValue aValue;
1165         bool bNativeOK;
1166         Rectangle aControlRegion( Point( 0, 0 ), m_aProgressBar.GetSizePixel() );
1167         Rectangle aNativeControlRegion, aNativeContentRegion;
1168         if( (bNativeOK = GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
1169                                                  CTRL_STATE_ENABLED, aValue, rtl::OUString(),
1170                                                  aNativeControlRegion, aNativeContentRegion ) ) != sal_False )
1171         {
1172             nProgressHeight = aNativeControlRegion.GetHeight();
1173         }
1174     }
1175 
1176     if ( nProgressHeight < PROGRESS_HEIGHT )
1177         nProgressHeight = PROGRESS_HEIGHT;
1178 
1179     aPos.X() -= ( RSC_SP_CTRL_GROUP_Y + PROGRESS_WIDTH );
1180     m_aProgressBar.SetPosSizePixel( Point( aPos.X(), aPos.Y() - ((nProgressHeight-aFTSize.Height())/2) ),
1181                                     Size( PROGRESS_WIDTH, nProgressHeight ) );
1182 
1183     Rectangle aRect1( m_aGetExtensions.GetPosPixel(), m_aGetExtensions.GetSizePixel() );
1184     Rectangle aRect2( m_aProgressBar.GetPosPixel(), m_aProgressBar.GetSizePixel() );
1185 
1186     aFTSize.Width() = ( aRect2.Left() - aRect1.Right() ) - 2*RSC_SP_DLG_INNERBORDER_LEFT;
1187     aPos.X() = aRect1.Right() + RSC_SP_DLG_INNERBORDER_LEFT;
1188     m_aProgressText.SetPosSizePixel( aPos, aFTSize );
1189 
1190     Size aSize( aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_LEFT - RSC_SP_DLG_INNERBORDER_RIGHT,
1191                 aTotalSize.Height() - 2*aBtnSize.Height() - LINE_SIZE -
1192                 RSC_SP_DLG_INNERBORDER_TOP - 3*RSC_SP_DLG_INNERBORDER_BOTTOM );
1193 
1194     m_pExtensionBox->SetSizePixel( aSize );
1195 }
1196 //------------------------------------------------------------------------------
1197 // VCL::Window / Dialog
1198 
1199 long ExtMgrDialog::Notify( NotifyEvent& rNEvt )
1200 {
1201     bool bHandled = false;
1202 
1203     if ( rNEvt.GetType() == EVENT_KEYINPUT )
1204     {
1205         const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1206         KeyCode         aKeyCode = pKEvt->GetKeyCode();
1207         sal_uInt16          nKeyCode = aKeyCode.GetCode();
1208 
1209         if ( nKeyCode == KEY_TAB )
1210         {
1211             if ( aKeyCode.IsShift() ) {
1212                 if ( m_aAddBtn.HasFocus() ) {
1213                     m_pExtensionBox->GrabFocus();
1214                     bHandled = true;
1215                 }
1216             } else {
1217                 if ( m_aGetExtensions.HasFocus() ) {
1218                     m_pExtensionBox->GrabFocus();
1219                     bHandled = true;
1220                 }
1221             }
1222         }
1223         if ( aKeyCode.GetGroup() == KEYGROUP_CURSOR )
1224             bHandled = m_pExtensionBox->Notify( rNEvt );
1225     }
1226 // VCLEVENT_WINDOW_CLOSE
1227     if ( !bHandled )
1228         return ModelessDialog::Notify( rNEvt );
1229     else
1230         return true;
1231 }
1232 
1233 //------------------------------------------------------------------------------
1234 sal_Bool ExtMgrDialog::Close()
1235 {
1236     bool bRet = m_pManager->queryTermination();
1237     if ( bRet )
1238     {
1239         bRet = ModelessDialog::Close();
1240         m_pManager->terminateDialog();
1241     }
1242     return bRet;
1243 }
1244 
1245 //------------------------------------------------------------------------------
1246 //                             UpdateRequiredDialog
1247 //------------------------------------------------------------------------------
1248 UpdateRequiredDialog::UpdateRequiredDialog( Window *pParent, TheExtensionManager *pManager ) :
1249     ModalDialog( pParent,   getResId( RID_DLG_UPDATE_REQUIRED ) ),
1250     DialogHelper( pManager->getContext(), (Dialog*) this ),
1251     m_aUpdateNeeded( this,  getResId( RID_EM_FT_MSG ) ),
1252     m_aUpdateBtn( this,     getResId( RID_EM_BTN_CHECK_UPDATES ) ),
1253     m_aCloseBtn( this,      getResId( RID_EM_BTN_CLOSE ) ),
1254     m_aHelpBtn( this,       getResId( RID_EM_BTN_HELP ) ),
1255     m_aCancelBtn( this,     getResId( RID_EM_BTN_CANCEL ) ),
1256     m_aDivider( this ),
1257     m_aProgressText( this,  getResId( RID_EM_FT_PROGRESS ) ),
1258     m_aProgressBar( this,   WB_BORDER + WB_3DLOOK ),
1259     m_sAddPackages(         getResourceString( RID_STR_ADD_PACKAGES ) ),
1260     m_sCloseText(           getResourceString( RID_STR_CLOSE_BTN ) ),
1261     m_bHasProgress(         false ),
1262     m_bProgressChanged(     false ),
1263     m_bStartProgress(       false ),
1264     m_bStopProgress(        false ),
1265     m_bUpdateWarning(       false ),
1266     m_bDisableWarning(      false ),
1267     m_bHasLockedEntries(    false ),
1268     m_nProgress(            0 ),
1269     m_pManager( pManager )
1270 {
1271     // free local resources (RID < 256):
1272     FreeResource();
1273 
1274     m_pExtensionBox = new ExtensionBox_Impl( this, pManager );
1275     m_pExtensionBox->SetHyperlinkHdl( LINK( this, UpdateRequiredDialog, HandleHyperlink ) );
1276 
1277     m_aUpdateBtn.SetClickHdl( LINK( this, UpdateRequiredDialog, HandleUpdateBtn ) );
1278     m_aCloseBtn.SetClickHdl( LINK( this, UpdateRequiredDialog, HandleCloseBtn ) );
1279     m_aCancelBtn.SetClickHdl( LINK( this, UpdateRequiredDialog, HandleCancelBtn ) );
1280 
1281     String aText = m_aUpdateNeeded.GetText();
1282     aText.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
1283     m_aUpdateNeeded.SetText( aText );
1284 
1285     // resize update button
1286     Size aBtnSize = m_aUpdateBtn.GetSizePixel();
1287     String sTitle = m_aUpdateBtn.GetText();
1288     long nWidth = m_aUpdateBtn.GetCtrlTextWidth( sTitle );
1289     nWidth += 2 * m_aUpdateBtn.GetTextHeight();
1290     if ( nWidth > aBtnSize.Width() )
1291         m_aUpdateBtn.SetSizePixel( Size( nWidth, aBtnSize.Height() ) );
1292 
1293     // resize update button
1294     aBtnSize = m_aCloseBtn.GetSizePixel();
1295     sTitle = m_aCloseBtn.GetText();
1296     nWidth = m_aCloseBtn.GetCtrlTextWidth( sTitle );
1297     nWidth += 2 * m_aCloseBtn.GetTextHeight();
1298     if ( nWidth > aBtnSize.Width() )
1299         m_aCloseBtn.SetSizePixel( Size( nWidth, aBtnSize.Height() ) );
1300 
1301     // minimum size:
1302     SetMinOutputSizePixel(
1303         Size( // width:
1304               (5 * m_aHelpBtn.GetSizePixel().Width()) +
1305               (5 * RSC_SP_DLG_INNERBORDER_LEFT ),
1306               // height:
1307               (1 * m_aHelpBtn.GetSizePixel().Height()) +
1308               (1 * m_aUpdateNeeded.GetSizePixel().Height()) +
1309               (1 * m_pExtensionBox->GetMinOutputSizePixel().Height()) +
1310               (3 * RSC_SP_DLG_INNERBORDER_LEFT) ) );
1311 
1312     m_aDivider.Show();
1313     m_aProgressBar.Hide();
1314     m_aUpdateBtn.Enable( false );
1315     m_aCloseBtn.GrabFocus();
1316 
1317     m_aTimeoutTimer.SetTimeout( 50 ); // mSec
1318     m_aTimeoutTimer.SetTimeoutHdl( LINK( this, UpdateRequiredDialog, TimeOutHdl ) );
1319 }
1320 
1321 //------------------------------------------------------------------------------
1322 UpdateRequiredDialog::~UpdateRequiredDialog()
1323 {
1324     m_aTimeoutTimer.Stop();
1325 
1326     delete m_pExtensionBox;
1327 }
1328 
1329 //------------------------------------------------------------------------------
1330 long UpdateRequiredDialog::addPackageToList( const uno::Reference< deployment::XPackage > &xPackage,
1331                                              bool bLicenseMissing )
1332 {
1333     // We will only add entries to the list with unsatisfied dependencies
1334     if ( !bLicenseMissing && !checkDependencies( xPackage ) )
1335     {
1336         m_bHasLockedEntries |= m_pManager->isReadOnly( xPackage );
1337         m_aUpdateBtn.Enable( true );
1338         return m_pExtensionBox->addEntry( xPackage );
1339     }
1340     return 0;
1341 }
1342 
1343 //------------------------------------------------------------------------------
1344 void UpdateRequiredDialog::prepareChecking()
1345 {
1346     m_pExtensionBox->prepareChecking();
1347 }
1348 
1349 //------------------------------------------------------------------------------
1350 void UpdateRequiredDialog::checkEntries()
1351 {
1352     const ::vos::OGuard guard( Application::GetSolarMutex() );
1353     m_pExtensionBox->checkEntries();
1354 
1355     if ( ! hasActiveEntries() )
1356     {
1357         m_aCloseBtn.SetText( m_sCloseText );
1358         m_aCloseBtn.GrabFocus();
1359     }
1360 }
1361 
1362 //------------------------------------------------------------------------------
1363 bool UpdateRequiredDialog::enablePackage( const uno::Reference< deployment::XPackage > &xPackage,
1364                                           bool bEnable )
1365 {
1366     m_pManager->getCmdQueue()->enableExtension( xPackage, bEnable );
1367 
1368     return true;
1369 }
1370 
1371 //------------------------------------------------------------------------------
1372 IMPL_LINK( UpdateRequiredDialog, HandleCancelBtn, void*, EMPTYARG )
1373 {
1374     // m_dialog->m_cmdEnv->m_aborted = true;
1375     if ( m_xAbortChannel.is() )
1376     {
1377         try
1378         {
1379             m_xAbortChannel->sendAbort();
1380         }
1381         catch ( uno::RuntimeException & )
1382         {
1383             OSL_ENSURE( 0, "### unexpected RuntimeException!" );
1384         }
1385     }
1386     return 1;
1387 }
1388 
1389 // ------------------------------------------------------------------------------
1390 IMPL_LINK( UpdateRequiredDialog, startProgress, void*, _bLockInterface )
1391 {
1392     ::osl::MutexGuard aGuard( m_aMutex );
1393     bool bLockInterface = (bool) _bLockInterface;
1394 
1395     if ( m_bStartProgress && !m_bHasProgress )
1396         m_aTimeoutTimer.Start();
1397 
1398     if ( m_bStopProgress )
1399     {
1400 		if ( m_aProgressBar.IsVisible() )
1401 	        m_aProgressBar.SetValue( 100 );
1402         m_xAbortChannel.clear();
1403         OSL_TRACE( " startProgress handler: stop\n" );
1404     }
1405     else
1406     {
1407         OSL_TRACE( " startProgress handler: start\n" );
1408     }
1409 
1410     m_aCancelBtn.Enable( bLockInterface );
1411     m_aUpdateBtn.Enable( false );
1412     clearEventID();
1413 
1414     return 0;
1415 }
1416 
1417 // ------------------------------------------------------------------------------
1418 void UpdateRequiredDialog::showProgress( bool _bStart )
1419 {
1420     ::osl::MutexGuard aGuard( m_aMutex );
1421 
1422     bool bStart = _bStart;
1423 
1424     if ( bStart )
1425     {
1426         m_nProgress = 0;
1427         m_bStartProgress = true;
1428         OSL_TRACE( "showProgress start\n" );
1429     }
1430     else
1431     {
1432         m_nProgress = 100;
1433         m_bStopProgress = true;
1434         OSL_TRACE( "showProgress stop!\n" );
1435     }
1436 
1437     DialogHelper::PostUserEvent( LINK( this, UpdateRequiredDialog, startProgress ), (void*) bStart );
1438 }
1439 
1440 // -----------------------------------------------------------------------
1441 void UpdateRequiredDialog::updateProgress( const long nProgress )
1442 {
1443     ::osl::MutexGuard aGuard( m_aMutex );
1444 
1445     m_nProgress = nProgress;
1446 }
1447 
1448 // -----------------------------------------------------------------------
1449 void UpdateRequiredDialog::updateProgress( const OUString &rText,
1450                                            const uno::Reference< task::XAbortChannel > &xAbortChannel)
1451 {
1452     ::osl::MutexGuard aGuard( m_aMutex );
1453 
1454     m_xAbortChannel = xAbortChannel;
1455     m_sProgressText = rText;
1456     m_bProgressChanged = true;
1457 }
1458 
1459 //------------------------------------------------------------------------------
1460 void UpdateRequiredDialog::updatePackageInfo( const uno::Reference< deployment::XPackage > &xPackage )
1461 {
1462     // We will remove all updated packages with satisfied dependencies, but
1463     // we will show all disabled entries so the user sees the result
1464     // of the 'disable all' button
1465     if ( isEnabled( xPackage ) && checkDependencies( xPackage ) )
1466         m_pExtensionBox->removeEntry( xPackage );
1467     else
1468         m_pExtensionBox->updateEntry( xPackage );
1469 
1470     if ( ! hasActiveEntries() )
1471     {
1472         m_aCloseBtn.SetText( m_sCloseText );
1473         m_aCloseBtn.GrabFocus();
1474     }
1475 }
1476 
1477 // -----------------------------------------------------------------------
1478 IMPL_LINK( UpdateRequiredDialog, HandleUpdateBtn, void*, EMPTYARG )
1479 {
1480     ::osl::ClearableMutexGuard aGuard( m_aMutex );
1481 
1482     std::vector< uno::Reference< deployment::XPackage > > vUpdateEntries;
1483     sal_Int32 nCount = m_pExtensionBox->GetEntryCount();
1484 
1485     for ( sal_Int32 i = 0; i < nCount; ++i )
1486     {
1487         TEntry_Impl pEntry = m_pExtensionBox->GetEntryData( i );
1488         vUpdateEntries.push_back( pEntry->m_xPackage );
1489     }
1490 
1491     aGuard.clear();
1492 
1493     m_pManager->getCmdQueue()->checkForUpdates( vUpdateEntries );
1494 
1495     return 1;
1496 }
1497 
1498 // -----------------------------------------------------------------------
1499 IMPL_LINK( UpdateRequiredDialog, HandleCloseBtn, void*, EMPTYARG )
1500 {
1501     ::osl::MutexGuard aGuard( m_aMutex );
1502 
1503     if ( !isBusy() )
1504     {
1505         if ( m_bHasLockedEntries )
1506             EndDialog( -1 );
1507         else if ( hasActiveEntries() )
1508             disableAllEntries();
1509         else
1510             EndDialog( 0 );
1511     }
1512 
1513     return 1;
1514 }
1515 
1516 // -----------------------------------------------------------------------
1517 IMPL_LINK( UpdateRequiredDialog, HandleHyperlink, svt::FixedHyperlink*, pHyperlink )
1518 {
1519     openWebBrowser( pHyperlink->GetURL(), GetText() );
1520 
1521     return 1;
1522 }
1523 
1524 // -----------------------------------------------------------------------
1525 IMPL_LINK( UpdateRequiredDialog, TimeOutHdl, Timer*, EMPTYARG )
1526 {
1527     if ( m_bStopProgress )
1528     {
1529         m_bHasProgress = false;
1530         m_bStopProgress = false;
1531         m_aProgressText.Hide();
1532         m_aProgressBar.Hide();
1533         m_aCancelBtn.Hide();
1534     }
1535     else
1536     {
1537         if ( m_bProgressChanged )
1538         {
1539             m_bProgressChanged = false;
1540             m_aProgressText.SetText( m_sProgressText );
1541         }
1542 
1543         if ( m_bStartProgress )
1544         {
1545             m_bStartProgress = false;
1546             m_bHasProgress = true;
1547             m_aProgressBar.Show();
1548             m_aProgressText.Show();
1549             m_aCancelBtn.Enable();
1550             m_aCancelBtn.Show();
1551         }
1552 
1553 		if ( m_aProgressBar.IsVisible() )
1554 			m_aProgressBar.SetValue( (sal_uInt16) m_nProgress );
1555 
1556         m_aTimeoutTimer.Start();
1557     }
1558 
1559 	return 1;
1560 }
1561 
1562 //------------------------------------------------------------------------------
1563 // VCL::Window / Dialog
1564 void UpdateRequiredDialog::Resize()
1565 {
1566     Size aTotalSize( GetOutputSizePixel() );
1567     Size aBtnSize( m_aHelpBtn.GetSizePixel() );
1568 
1569     Point aPos( RSC_SP_DLG_INNERBORDER_LEFT,
1570                 aTotalSize.Height() - RSC_SP_DLG_INNERBORDER_BOTTOM - aBtnSize.Height() );
1571 
1572     m_aHelpBtn.SetPosPixel( aPos );
1573 
1574     aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - m_aCloseBtn.GetSizePixel().Width();
1575     m_aCloseBtn.SetPosPixel( aPos );
1576 
1577     aPos.X() -= ( RSC_SP_CTRL_X + m_aUpdateBtn.GetSizePixel().Width() );
1578     m_aUpdateBtn.SetPosPixel( aPos );
1579 
1580     Size aDivSize( aTotalSize.Width(), LINE_SIZE );
1581     aPos = Point( 0, aPos.Y() - LINE_SIZE - RSC_SP_DLG_INNERBORDER_BOTTOM );
1582     m_aDivider.SetPosSizePixel( aPos, aDivSize );
1583 
1584     // Calc fixed text size
1585     aPos = Point( RSC_SP_DLG_INNERBORDER_LEFT, RSC_SP_DLG_INNERBORDER_TOP );
1586     Size aFTSize = m_aUpdateNeeded.CalcMinimumSize( aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - RSC_SP_DLG_INNERBORDER_LEFT );
1587     m_aUpdateNeeded.SetPosSizePixel( aPos, aFTSize );
1588 
1589     // Calc list box size
1590     Size aSize( aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_LEFT - RSC_SP_DLG_INNERBORDER_RIGHT,
1591                 aTotalSize.Height() - 2*aBtnSize.Height() - LINE_SIZE -
1592                 2*RSC_SP_DLG_INNERBORDER_TOP - 3*RSC_SP_DLG_INNERBORDER_BOTTOM - aFTSize.Height() );
1593     aPos.Y() += aFTSize.Height()+RSC_SP_DLG_INNERBORDER_TOP;
1594 
1595     m_pExtensionBox->SetPosSizePixel( aPos, aSize );
1596 
1597     aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - aBtnSize.Width();
1598     aPos.Y() += aSize.Height()+RSC_SP_DLG_INNERBORDER_TOP;
1599     m_aCancelBtn.SetPosPixel( aPos );
1600 
1601     // Calc progress height
1602     aFTSize = m_aProgressText.GetSizePixel();
1603     long nProgressHeight = aFTSize.Height();
1604 
1605     if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
1606     {
1607         ImplControlValue aValue;
1608         bool bNativeOK;
1609         Rectangle aControlRegion( Point( 0, 0 ), m_aProgressBar.GetSizePixel() );
1610         Rectangle aNativeControlRegion, aNativeContentRegion;
1611         if( (bNativeOK = GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
1612                                                  CTRL_STATE_ENABLED, aValue, rtl::OUString(),
1613                                                  aNativeControlRegion, aNativeContentRegion ) ) != sal_False )
1614         {
1615             nProgressHeight = aNativeControlRegion.GetHeight();
1616         }
1617     }
1618 
1619     if ( nProgressHeight < PROGRESS_HEIGHT )
1620         nProgressHeight = PROGRESS_HEIGHT;
1621 
1622     aPos.X() -= ( RSC_SP_CTRL_GROUP_Y + PROGRESS_WIDTH );
1623     m_aProgressBar.SetPosSizePixel( Point( aPos.X(), aPos.Y() + ((aBtnSize.Height()-nProgressHeight)/2) ),
1624                                     Size( PROGRESS_WIDTH, nProgressHeight ) );
1625 
1626     aFTSize.Width() = aPos.X() - 2*RSC_SP_DLG_INNERBORDER_LEFT;
1627     aPos.X() = RSC_SP_DLG_INNERBORDER_LEFT;
1628     aPos.Y() += ( aBtnSize.Height() - aFTSize.Height() - 1 ) / 2;
1629     m_aProgressText.SetPosSizePixel( aPos, aFTSize );
1630 }
1631 
1632 //------------------------------------------------------------------------------
1633 // VCL::Dialog
1634 short UpdateRequiredDialog::Execute()
1635 {
1636     if ( m_bHasLockedEntries )
1637     {
1638         // Set other text, disable update btn, remove not shared entries from list;
1639         m_aUpdateNeeded.SetText( DialogHelper::getResourceString( RID_STR_NO_ADMIN_PRIVILEGE ) );
1640         m_aCloseBtn.SetText( DialogHelper::getResourceString( RID_STR_EXIT_BTN ) );
1641         m_aUpdateBtn.Enable( false );
1642         m_pExtensionBox->RemoveUnlocked();
1643         Resize();
1644     }
1645 
1646     return Dialog::Execute();
1647 }
1648 
1649 //------------------------------------------------------------------------------
1650 // VCL::Dialog
1651 sal_Bool UpdateRequiredDialog::Close()
1652 {
1653     ::osl::MutexGuard aGuard( m_aMutex );
1654 
1655     if ( !isBusy() )
1656     {
1657         if ( m_bHasLockedEntries )
1658             EndDialog( -1 );
1659         else if ( hasActiveEntries() )
1660             disableAllEntries();
1661         else
1662             EndDialog( 0 );
1663     }
1664 
1665     return false;
1666 }
1667 
1668 //------------------------------------------------------------------------------
1669 // Check dependencies of all packages
1670 //------------------------------------------------------------------------------
1671 bool UpdateRequiredDialog::isEnabled( const uno::Reference< deployment::XPackage > &xPackage ) const
1672 {
1673     bool bRegistered = false;
1674     try {
1675         beans::Optional< beans::Ambiguous< sal_Bool > > option( xPackage->isRegistered( uno::Reference< task::XAbortChannel >(),
1676                                                                                         uno::Reference< ucb::XCommandEnvironment >() ) );
1677         if ( option.IsPresent )
1678         {
1679             ::beans::Ambiguous< sal_Bool > const & reg = option.Value;
1680             if ( reg.IsAmbiguous )
1681                 bRegistered = false;
1682             else
1683                 bRegistered = reg.Value ? true : false;
1684         }
1685         else
1686             bRegistered = false;
1687     }
1688     catch ( uno::RuntimeException & ) { throw; }
1689     catch ( uno::Exception & exc) {
1690         (void) exc;
1691         OSL_ENSURE( 0, ::rtl::OUStringToOString( exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
1692         bRegistered = false;
1693     }
1694 
1695     return bRegistered;
1696 }
1697 
1698 //------------------------------------------------------------------------------
1699 bool UpdateRequiredDialog::checkDependencies( const uno::Reference< deployment::XPackage > &xPackage ) const
1700 {
1701     if ( isEnabled( xPackage ) )
1702     {
1703         bool bDependenciesValid = false;
1704         try {
1705             bDependenciesValid = xPackage->checkDependencies( uno::Reference< ucb::XCommandEnvironment >() );
1706         }
1707         catch ( deployment::DeploymentException & ) {}
1708         if ( ! bDependenciesValid )
1709         {
1710             return false;
1711         }
1712     }
1713     return true;
1714 }
1715 
1716 //------------------------------------------------------------------------------
1717 bool UpdateRequiredDialog::hasActiveEntries()
1718 {
1719     ::osl::MutexGuard aGuard( m_aMutex );
1720 
1721     bool bRet = false;
1722     long nCount = m_pExtensionBox->GetEntryCount();
1723     for ( long nIndex = 0; nIndex < nCount; nIndex++ )
1724     {
1725         TEntry_Impl pEntry = m_pExtensionBox->GetEntryData( nIndex );
1726 
1727         if ( !checkDependencies( pEntry->m_xPackage ) )
1728         {
1729             bRet = true;
1730             break;
1731         }
1732     }
1733 
1734     return bRet;
1735 }
1736 
1737 //------------------------------------------------------------------------------
1738 void UpdateRequiredDialog::disableAllEntries()
1739 {
1740     ::osl::MutexGuard aGuard( m_aMutex );
1741 
1742     setBusy( true );
1743 
1744     long nCount = m_pExtensionBox->GetEntryCount();
1745     for ( long nIndex = 0; nIndex < nCount; nIndex++ )
1746     {
1747         TEntry_Impl pEntry = m_pExtensionBox->GetEntryData( nIndex );
1748         enablePackage( pEntry->m_xPackage, false );
1749     }
1750 
1751     setBusy( false );
1752 
1753     if ( ! hasActiveEntries() )
1754         m_aCloseBtn.SetText( m_sCloseText );
1755 }
1756 
1757 //------------------------------------------------------------------------------
1758 //                             ShowLicenseDialog
1759 //------------------------------------------------------------------------------
1760 ShowLicenseDialog::ShowLicenseDialog( Window * pParent,
1761                                       const uno::Reference< deployment::XPackage > &xPackage ) :
1762     ModalDialog( pParent, DialogHelper::getResId( RID_DLG_SHOW_LICENSE ) ),
1763     m_aLicenseText( this, DialogHelper::getResId( ML_LICENSE ) ),
1764     m_aCloseBtn( this,    DialogHelper::getResId( RID_EM_BTN_CLOSE ) )
1765 {
1766     FreeResource();
1767 
1768     OUString aText = xPackage->getLicenseText();
1769     m_aLicenseText.SetText( aText );
1770 }
1771 
1772 //------------------------------------------------------------------------------
1773 ShowLicenseDialog::~ShowLicenseDialog()
1774 {}
1775 
1776 //------------------------------------------------------------------------------
1777 void ShowLicenseDialog::Resize()
1778 {
1779     Size aTotalSize( GetOutputSizePixel() );
1780     Size aTextSize( aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_LEFT - RSC_SP_DLG_INNERBORDER_RIGHT,
1781                     aTotalSize.Height() - RSC_SP_DLG_INNERBORDER_TOP - 2*RSC_SP_DLG_INNERBORDER_BOTTOM
1782                                         - m_aCloseBtn.GetSizePixel().Height() );
1783 
1784     m_aLicenseText.SetPosSizePixel( Point( RSC_SP_DLG_INNERBORDER_LEFT, RSC_SP_DLG_INNERBORDER_TOP ),
1785                                     aTextSize );
1786 
1787     Point aBtnPos( (aTotalSize.Width() - m_aCloseBtn.GetSizePixel().Width())/2,
1788                     aTotalSize.Height() - RSC_SP_DLG_INNERBORDER_BOTTOM
1789                                         - m_aCloseBtn.GetSizePixel().Height() );
1790     m_aCloseBtn.SetPosPixel( aBtnPos );
1791 }
1792 
1793 //=================================================================================
1794 // UpdateRequiredDialogService
1795 //=================================================================================
1796 UpdateRequiredDialogService::UpdateRequiredDialogService( uno::Sequence< uno::Any > const&,
1797                                                           uno::Reference< uno::XComponentContext > const& xComponentContext )
1798     : m_xComponentContext( xComponentContext )
1799 {
1800 }
1801 
1802 //------------------------------------------------------------------------------
1803 // XExecutableDialog
1804 //------------------------------------------------------------------------------
1805 void UpdateRequiredDialogService::setTitle( OUString const & ) throw ( uno::RuntimeException )
1806 {
1807 }
1808 
1809 //------------------------------------------------------------------------------
1810 sal_Int16 UpdateRequiredDialogService::execute() throw ( uno::RuntimeException )
1811 {
1812     ::rtl::Reference< ::dp_gui::TheExtensionManager > xManager( TheExtensionManager::get(
1813                                                               m_xComponentContext,
1814                                                               uno::Reference< awt::XWindow >(),
1815                                                               OUString() ) );
1816     xManager->createDialog( true );
1817     sal_Int16 nRet = xManager->execute();
1818 
1819     return nRet;
1820 }
1821 
1822 //------------------------------------------------------------------------------
1823 //------------------------------------------------------------------------------
1824 //------------------------------------------------------------------------------
1825 SelectedPackage::~SelectedPackage() {}
1826 
1827 } //namespace dp_gui
1828 
1829