1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <basidesh.hrc>
22 #include <basidesh.hxx>
23 #include <baside2.hxx>
24 #include <baside3.hxx>
26 #include <localizationmgr.hxx>
27 #include <dlgedview.hxx>
28 #include <comphelper/processfactory.hxx>
29 #include <com/sun/star/script/XLibraryContainer.hpp>
30 #include <com/sun/star/container/XNameContainer.hpp>
31 #include <xmlscript/xmldlg_imexp.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <sfx2/docfac.hxx>
34 #include <sfx2/request.hxx>
35 #include <tools/diagnose_ex.h>
40 using namespace comphelper
;
41 using namespace ::com::sun::star
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::io
;
45 DialogWindow
* Shell::CreateDlgWin( const ScriptDocument
& rDocument
, const OUString
& rLibName
, const OUString
& rDlgName
)
47 bCreatingWindow
= true;
50 DialogWindow
* pWin
= 0;
51 OUString
aLibName( rLibName
);
52 OUString
aDlgName( rDlgName
);
54 if ( aLibName
.isEmpty() )
55 aLibName
= "Standard" ;
57 rDocument
.getOrCreateLibrary( E_DIALOGS
, aLibName
);
59 if ( aDlgName
.isEmpty() )
60 aDlgName
= rDocument
.createObjectName( E_DIALOGS
, aLibName
);
62 // maybe there's a suspended one?
63 pWin
= FindDlgWin( rDocument
, aLibName
, aDlgName
, false, true );
69 Reference
< io::XInputStreamProvider
> xISP
;
70 if ( rDocument
.hasDialog( aLibName
, aDlgName
) )
71 rDocument
.getDialog( aLibName
, aDlgName
, xISP
);
73 rDocument
.createDialog( aLibName
, aDlgName
, xISP
);
77 // create dialog model
78 Reference
< lang::XMultiServiceFactory
> xMSF
= getProcessServiceFactory();
79 Reference
< container::XNameContainer
> xDialogModel( xMSF
->createInstance
80 ( "com.sun.star.awt.UnoControlDialogModel" ), UNO_QUERY
);
81 Reference
< XInputStream
> xInput( xISP
->createInputStream() );
82 Reference
< XComponentContext
> xContext(
83 comphelper::getComponentContext( xMSF
) );
84 ::xmlscript::importDialogModel( xInput
, xDialogModel
, xContext
, rDocument
.isDocument() ? rDocument
.getDocument() : Reference
< frame::XModel
>() );
85 LocalizationMgr::setStringResourceAtDialog( rDocument
, rLibName
, aDlgName
, xDialogModel
);
89 pDialogLayout
.reset(new DialogWindowLayout(&GetViewFrame()->GetWindow(), aObjectCatalog
));
90 pWin
= new DialogWindow(pDialogLayout
.get(), rDocument
, aLibName
, aDlgName
, xDialogModel
);
91 nKey
= InsertWindowInTable( pWin
);
94 catch (const uno::Exception
& )
96 DBG_UNHANDLED_EXCEPTION();
101 pWin
->SetStatus( pWin
->GetStatus() & ~BASWIN_SUSPENDED
);
102 nKey
= GetWindowId( pWin
);
103 DBG_ASSERT( nKey
, "CreateDlgWin: Kein Key - Fenster nicht gefunden!" );
108 pWin
->GrabScrollBars( &aHScrollBar
, &aVScrollBar
);
109 pTabBar
->InsertPage( (sal_uInt16
)nKey
, aDlgName
);
112 SetCurWindow( pWin
, false, false );
115 bCreatingWindow
= false;
119 DialogWindow
* Shell::FindDlgWin (
120 ScriptDocument
const& rDocument
,
121 OUString
const& rLibName
, OUString
const& rName
,
122 bool bCreateIfNotExist
, bool bFindSuspended
125 if (BaseWindow
* pWin
= FindWindow(rDocument
, rLibName
, rName
, TYPE_DIALOG
, bFindSuspended
))
126 return static_cast<DialogWindow
*>(pWin
);
127 return bCreateIfNotExist
? CreateDlgWin(rDocument
, rLibName
, rName
) : 0;
130 sal_uInt16
Shell::GetWindowId(const BaseWindow
* pWin
) const
132 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
133 if ( it
->second
== pWin
)
138 SdrView
* Shell::GetCurDlgView() const
140 if (DialogWindow
* pDCurWin
= dynamic_cast<DialogWindow
*>(pCurWin
))
141 return &pDCurWin
->GetView();
146 // only if dialogue window above:
147 void Shell::ExecuteDialog( SfxRequest
& rReq
)
149 if (pCurWin
&& (dynamic_cast<DialogWindow
*>(pCurWin
) || rReq
.GetSlot() == SID_IMPORT_DIALOG
))
150 pCurWin
->ExecuteCommand(rReq
);
153 } // namespace basctl
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */