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 .
21 #include "baside2.hxx"
22 #include <baside3.hxx>
23 #include <localizationmgr.hxx>
24 #include <dlgedview.hxx>
25 #include <xmlscript/xmldlg_imexp.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/request.hxx>
28 #include <tools/diagnose_ex.h>
33 using namespace comphelper
;
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::io
;
38 VclPtr
<DialogWindow
> Shell::CreateDlgWin( const ScriptDocument
& rDocument
, const OUString
& rLibName
, const OUString
& rDlgName
)
40 bCreatingWindow
= true;
43 VclPtr
<DialogWindow
> pWin
;
44 OUString
aLibName( rLibName
);
45 OUString
aDlgName( rDlgName
);
47 if ( aLibName
.isEmpty() )
48 aLibName
= "Standard" ;
50 rDocument
.getOrCreateLibrary( E_DIALOGS
, aLibName
);
52 if ( aDlgName
.isEmpty() )
53 aDlgName
= rDocument
.createObjectName( E_DIALOGS
, aLibName
);
55 // maybe there's a suspended one?
56 pWin
= FindDlgWin( rDocument
, aLibName
, aDlgName
, false, true );
62 Reference
< io::XInputStreamProvider
> xISP
;
63 if ( rDocument
.hasDialog( aLibName
, aDlgName
) )
64 rDocument
.getDialog( aLibName
, aDlgName
, xISP
);
66 rDocument
.createDialog( aLibName
, aDlgName
, xISP
);
70 // create dialog model
71 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
72 Reference
< container::XNameContainer
> xDialogModel( xContext
->getServiceManager()->createInstanceWithContext
73 ( "com.sun.star.awt.UnoControlDialogModel", xContext
), UNO_QUERY
);
74 Reference
< XInputStream
> xInput( xISP
->createInputStream() );
75 ::xmlscript::importDialogModel( xInput
, xDialogModel
, xContext
, rDocument
.isDocument() ? rDocument
.getDocument() : Reference
< frame::XModel
>() );
76 LocalizationMgr::setStringResourceAtDialog( rDocument
, rLibName
, aDlgName
, xDialogModel
);
80 pDialogLayout
.reset(VclPtr
<DialogWindowLayout
>::Create(&GetViewFrame()->GetWindow(), *aObjectCatalog
.get()));
81 pWin
= VclPtr
<DialogWindow
>::Create(pDialogLayout
.get(), rDocument
, aLibName
, aDlgName
, xDialogModel
);
82 nKey
= InsertWindowInTable( pWin
);
85 catch (const uno::Exception
& )
87 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
92 pWin
->SetStatus( pWin
->GetStatus() & ~BASWIN_SUSPENDED
);
93 nKey
= GetWindowId( pWin
);
94 DBG_ASSERT( nKey
, "CreateDlgWin: No Key - Window not found!" );
99 pWin
->GrabScrollBars( aHScrollBar
.get(), aVScrollBar
.get() );
100 pTabBar
->InsertPage( nKey
, aDlgName
);
103 SetCurWindow( pWin
, false, false );
106 bCreatingWindow
= false;
110 VclPtr
<DialogWindow
> Shell::FindDlgWin (
111 ScriptDocument
const& rDocument
,
112 OUString
const& rLibName
, OUString
const& rName
,
113 bool bCreateIfNotExist
, bool bFindSuspended
116 if (VclPtr
<BaseWindow
> pWin
= FindWindow(rDocument
, rLibName
, rName
, TYPE_DIALOG
, bFindSuspended
))
117 return static_cast<DialogWindow
*>(pWin
.get());
118 return bCreateIfNotExist
? CreateDlgWin(rDocument
, rLibName
, rName
) : nullptr;
121 sal_uInt16
Shell::GetWindowId(const BaseWindow
* pWin
) const
123 for (auto const& window
: aWindowTable
)
124 if ( window
.second
== pWin
)
129 SdrView
* Shell::GetCurDlgView() const
131 if (DialogWindow
* pDCurWin
= dynamic_cast<DialogWindow
*>(pCurWin
.get()))
132 return &pDCurWin
->GetView();
137 // only if dialogue window above:
138 void Shell::ExecuteDialog( SfxRequest
& rReq
)
140 if (pCurWin
&& (dynamic_cast<DialogWindow
*>(pCurWin
.get()) || rReq
.GetSlot() == SID_IMPORT_DIALOG
))
141 pCurWin
->ExecuteCommand(rReq
);
144 } // namespace basctl
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */