Bump version to 24.04.3.4
[LibreOffice.git] / basctl / source / basicide / basides3.cxx
blob44bc54ba624f57c0c3f6b7c722f58e6a2ca5d140
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <baside3.hxx>
22 #include <basidesh.hxx>
23 #include <localizationmgr.hxx>
24 #include <dlgedview.hxx>
25 #include <xmlscript/xmldlg_imexp.hxx>
26 #include <sfx2/request.hxx>
27 #include <sfx2/sfxsids.hrc>
28 #include <sfx2/viewfrm.hxx>
29 #include <tools/debug.hxx>
30 #include <comphelper/diagnose_ex.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <com/sun/star/uno/XComponentContext.hpp>
34 namespace basctl
37 using namespace comphelper;
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::io;
42 VclPtr<DialogWindow> Shell::CreateDlgWin( const ScriptDocument& rDocument, const OUString& rLibName, const OUString& rDlgName )
44 bCreatingWindow = true;
46 sal_uInt16 nKey = 0;
47 VclPtr<DialogWindow> pWin;
48 OUString aLibName( rLibName );
49 OUString aDlgName( rDlgName );
51 if ( aLibName.isEmpty() )
52 aLibName = "Standard" ;
54 rDocument.getOrCreateLibrary( E_DIALOGS, aLibName );
56 if ( aDlgName.isEmpty() )
57 aDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
59 // maybe there's a suspended one?
60 pWin = FindDlgWin( rDocument, aLibName, aDlgName, false, true );
62 if ( !pWin )
64 try
66 Reference< io::XInputStreamProvider > xISP;
67 if ( rDocument.hasDialog( aLibName, aDlgName ) )
68 rDocument.getDialog( aLibName, aDlgName, xISP );
69 else
70 rDocument.createDialog( aLibName, aDlgName, xISP );
72 if ( xISP.is() )
74 // create dialog model
75 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
76 Reference< container::XNameContainer > xDialogModel( xContext->getServiceManager()->createInstanceWithContext
77 ( "com.sun.star.awt.UnoControlDialogModel", xContext ), UNO_QUERY );
78 Reference< XInputStream > xInput( xISP->createInputStream() );
79 ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, rDocument.isDocument() ? rDocument.getDocument() : Reference< frame::XModel >() );
80 LocalizationMgr::setStringResourceAtDialog( rDocument, rLibName, aDlgName, xDialogModel );
82 // new dialog window
83 if (!pDialogLayout)
84 pDialogLayout.reset(VclPtr<DialogWindowLayout>::Create(&GetViewFrame().GetWindow(), *aObjectCatalog));
85 pWin = VclPtr<DialogWindow>::Create(pDialogLayout.get(), rDocument, aLibName, aDlgName, xDialogModel);
86 nKey = InsertWindowInTable( pWin );
89 catch (const uno::Exception& )
91 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
94 else
96 pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
97 nKey = GetWindowId( pWin );
98 DBG_ASSERT( nKey, "CreateDlgWin: No Key - Window not found!" );
101 if( pWin )
103 pWin->GrabScrollBars( aHScrollBar.get(), aVScrollBar.get() );
104 pTabBar->InsertPage( nKey, aDlgName );
105 pTabBar->Sort();
106 if ( !pCurWin )
107 SetCurWindow( pWin, false, false );
110 bCreatingWindow = false;
111 return pWin;
114 VclPtr<DialogWindow> Shell::FindDlgWin (
115 ScriptDocument const& rDocument,
116 OUString const& rLibName, OUString const& rName,
117 bool bCreateIfNotExist, bool bFindSuspended
120 if (VclPtr<BaseWindow> pWin = FindWindow(rDocument, rLibName, rName, TYPE_DIALOG, bFindSuspended))
121 return static_cast<DialogWindow*>(pWin.get());
122 return bCreateIfNotExist ? CreateDlgWin(rDocument, rLibName, rName) : nullptr;
125 sal_uInt16 Shell::GetWindowId(const BaseWindow* pWin) const
127 for (auto const& window : aWindowTable)
128 if ( window.second == pWin )
129 return window.first;
130 return 0;
133 SdrView* Shell::GetCurDlgView() const
135 if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin.get()))
136 return &pDCurWin->GetView();
137 else
138 return nullptr;
141 // only if dialogue window above:
142 void Shell::ExecuteDialog( SfxRequest& rReq )
144 if (pCurWin && (dynamic_cast<DialogWindow*>(pCurWin.get()) || rReq.GetSlot() == SID_IMPORT_DIALOG))
145 pCurWin->ExecuteCommand(rReq);
148 } // namespace basctl
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */