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