Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include <basidesh.hrc>
21 : :
22 : : #define _SOLAR__PRIVATE 1
23 : :
24 : : #include <basidesh.hxx>
25 : : #include <baside2.hxx>
26 : : #include <baside3.hxx>
27 : : #include <basobj.hxx>
28 : : #include <localizationmgr.hxx>
29 : : #include <dlgedview.hxx>
30 : : #include <comphelper/processfactory.hxx>
31 : : #include <com/sun/star/script/XLibraryContainer.hpp>
32 : : #include <com/sun/star/container/XNameContainer.hpp>
33 : : #include <xmlscript/xmldlg_imexp.hxx>
34 : : #include <sfx2/dispatch.hxx>
35 : : #include <sfx2/docfac.hxx>
36 : : #include <sfx2/request.hxx>
37 : : #include <tools/diagnose_ex.h>
38 : :
39 : : using namespace comphelper;
40 : : using namespace ::com::sun::star;
41 : : using namespace ::com::sun::star::uno;
42 : : using namespace ::com::sun::star::io;
43 : :
44 : : using basctl::DialogWindow;
45 : : using basctl::DialogWindowLayout;
46 : :
47 : 0 : DialogWindow* BasicIDEShell::CreateDlgWin( const ScriptDocument& rDocument, const ::rtl::OUString& rLibName, const ::rtl::OUString& rDlgName )
48 : : {
49 : 0 : bCreatingWindow = true;
50 : :
51 : 0 : sal_uLong nKey = 0;
52 : 0 : DialogWindow* pWin = 0;
53 : 0 : ::rtl::OUString aLibName( rLibName );
54 : 0 : ::rtl::OUString aDlgName( rDlgName );
55 : :
56 : 0 : if ( aLibName.isEmpty() )
57 : 0 : aLibName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Standard"));
58 : :
59 : 0 : rDocument.getOrCreateLibrary( E_DIALOGS, aLibName );
60 : :
61 : 0 : if ( aDlgName.isEmpty() )
62 : 0 : aDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
63 : :
64 : : // maybe there's a suspended one?
65 : 0 : pWin = FindDlgWin( rDocument, aLibName, aDlgName, false, true );
66 : :
67 : 0 : if ( !pWin )
68 : : {
69 : : try
70 : : {
71 : 0 : Reference< io::XInputStreamProvider > xISP;
72 : 0 : if ( rDocument.hasDialog( aLibName, aDlgName ) )
73 : 0 : rDocument.getDialog( aLibName, aDlgName, xISP );
74 : : else
75 : 0 : rDocument.createDialog( aLibName, aDlgName, xISP );
76 : :
77 : 0 : if ( xISP.is() )
78 : : {
79 : : // create dialog model
80 : 0 : Reference< lang::XMultiServiceFactory > xMSF = getProcessServiceFactory();
81 : 0 : Reference< container::XNameContainer > xDialogModel( xMSF->createInstance
82 : 0 : ( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY );
83 : 0 : Reference< XInputStream > xInput( xISP->createInputStream() );
84 : 0 : Reference< XComponentContext > xContext;
85 : 0 : Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY );
86 : : OSL_ASSERT( xProps.is() );
87 : 0 : OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
88 : 0 : ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, rDocument.isDocument() ? rDocument.getDocument() : Reference< frame::XModel >() );
89 : 0 : LocalizationMgr::setStringResourceAtDialog( rDocument, rLibName, aDlgName, xDialogModel );
90 : :
91 : : // new dialog window
92 : 0 : if (!pDialogLayout)
93 : 0 : pDialogLayout.reset(new DialogWindowLayout(&GetViewFrame()->GetWindow(), aObjectCatalog));
94 : 0 : pWin = new DialogWindow(pDialogLayout.get(), rDocument, aLibName, aDlgName, xDialogModel);
95 : 0 : nKey = InsertWindowInTable( pWin );
96 : 0 : }
97 : : }
98 : 0 : catch (const uno::Exception& )
99 : : {
100 : : DBG_UNHANDLED_EXCEPTION();
101 : : }
102 : : }
103 : : else
104 : : {
105 : 0 : pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
106 : 0 : nKey = GetIDEWindowId( pWin );
107 : : DBG_ASSERT( nKey, "CreateDlgWin: Kein Key - Fenster nicht gefunden!" );
108 : : }
109 : :
110 : 0 : if( pWin )
111 : : {
112 : 0 : pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
113 : 0 : pTabBar->InsertPage( (sal_uInt16)nKey, aDlgName );
114 : 0 : pTabBar->Sort();
115 : 0 : if ( !pCurWin )
116 : 0 : SetCurWindow( pWin, false, false );
117 : : }
118 : :
119 : 0 : bCreatingWindow = false;
120 : 0 : return pWin;
121 : : }
122 : :
123 : 0 : DialogWindow* BasicIDEShell::FindDlgWin (
124 : : ScriptDocument const& rDocument,
125 : : rtl::OUString const& rLibName, rtl::OUString const& rName,
126 : : bool bCreateIfNotExist, bool bFindSuspended
127 : : )
128 : : {
129 : 0 : if (IDEBaseWindow* pWin = FindWindow(rDocument, rLibName, rName, BASICIDE_TYPE_DIALOG, bFindSuspended))
130 : 0 : return static_cast<DialogWindow*>(pWin);
131 : 0 : return bCreateIfNotExist ? CreateDlgWin(rDocument, rLibName, rName) : 0;
132 : : }
133 : :
134 : 0 : sal_uInt16 BasicIDEShell::GetIDEWindowId(const IDEBaseWindow* pWin) const
135 : : {
136 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
137 : 0 : if ( it->second == pWin )
138 : 0 : return it->first;
139 : 0 : return 0;
140 : : }
141 : :
142 : 0 : SdrView* BasicIDEShell::GetCurDlgView() const
143 : : {
144 : 0 : if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin))
145 : 0 : return pDCurWin->GetView();
146 : : else
147 : 0 : return 0;
148 : : }
149 : :
150 : : // only if dialogue window above:
151 : 0 : void BasicIDEShell::ExecuteDialog( SfxRequest& rReq )
152 : : {
153 : 0 : if (pCurWin && (dynamic_cast<DialogWindow*>(pCurWin) || rReq.GetSlot() == SID_IMPORT_DIALOG))
154 : 0 : pCurWin->ExecuteCommand(rReq);
155 : 0 : }
156 : :
157 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|