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 : #include <basidesh.hxx>
23 : #include <baside2.hxx>
24 : #include <baside3.hxx>
25 : #include <basobj.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>
36 :
37 : namespace basctl
38 : {
39 :
40 : using namespace comphelper;
41 : using namespace ::com::sun::star;
42 : using namespace ::com::sun::star::uno;
43 : using namespace ::com::sun::star::io;
44 :
45 0 : DialogWindow* Shell::CreateDlgWin( const ScriptDocument& rDocument, const OUString& rLibName, const OUString& rDlgName )
46 : {
47 0 : bCreatingWindow = true;
48 :
49 0 : sal_uLong nKey = 0;
50 0 : DialogWindow* pWin = 0;
51 0 : OUString aLibName( rLibName );
52 0 : OUString aDlgName( rDlgName );
53 :
54 0 : if ( aLibName.isEmpty() )
55 0 : aLibName = "Standard" ;
56 :
57 0 : rDocument.getOrCreateLibrary( E_DIALOGS, aLibName );
58 :
59 0 : if ( aDlgName.isEmpty() )
60 0 : aDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
61 :
62 : // maybe there's a suspended one?
63 0 : pWin = FindDlgWin( rDocument, aLibName, aDlgName, false, true );
64 :
65 0 : if ( !pWin )
66 : {
67 : try
68 : {
69 0 : Reference< io::XInputStreamProvider > xISP;
70 0 : if ( rDocument.hasDialog( aLibName, aDlgName ) )
71 0 : rDocument.getDialog( aLibName, aDlgName, xISP );
72 : else
73 0 : rDocument.createDialog( aLibName, aDlgName, xISP );
74 :
75 0 : if ( xISP.is() )
76 : {
77 : // create dialog model
78 0 : Reference< lang::XMultiServiceFactory > xMSF = getProcessServiceFactory();
79 0 : Reference< container::XNameContainer > xDialogModel( xMSF->createInstance
80 0 : ( "com.sun.star.awt.UnoControlDialogModel" ), UNO_QUERY );
81 0 : Reference< XInputStream > xInput( xISP->createInputStream() );
82 : Reference< XComponentContext > xContext(
83 0 : comphelper::getComponentContext( xMSF ) );
84 0 : ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, rDocument.isDocument() ? rDocument.getDocument() : Reference< frame::XModel >() );
85 0 : LocalizationMgr::setStringResourceAtDialog( rDocument, rLibName, aDlgName, xDialogModel );
86 :
87 : // new dialog window
88 0 : if (!pDialogLayout)
89 0 : pDialogLayout.reset(new DialogWindowLayout(&GetViewFrame()->GetWindow(), aObjectCatalog));
90 0 : pWin = new DialogWindow(pDialogLayout.get(), rDocument, aLibName, aDlgName, xDialogModel);
91 0 : nKey = InsertWindowInTable( pWin );
92 0 : }
93 : }
94 0 : catch (const uno::Exception& )
95 : {
96 : DBG_UNHANDLED_EXCEPTION();
97 : }
98 : }
99 : else
100 : {
101 0 : pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
102 0 : nKey = GetWindowId( pWin );
103 : DBG_ASSERT( nKey, "CreateDlgWin: Kein Key - Fenster nicht gefunden!" );
104 : }
105 :
106 0 : if( pWin )
107 : {
108 0 : pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
109 0 : pTabBar->InsertPage( (sal_uInt16)nKey, aDlgName );
110 0 : pTabBar->Sort();
111 0 : if ( !pCurWin )
112 0 : SetCurWindow( pWin, false, false );
113 : }
114 :
115 0 : bCreatingWindow = false;
116 0 : return pWin;
117 : }
118 :
119 0 : DialogWindow* Shell::FindDlgWin (
120 : ScriptDocument const& rDocument,
121 : OUString const& rLibName, OUString const& rName,
122 : bool bCreateIfNotExist, bool bFindSuspended
123 : )
124 : {
125 0 : if (BaseWindow* pWin = FindWindow(rDocument, rLibName, rName, TYPE_DIALOG, bFindSuspended))
126 0 : return static_cast<DialogWindow*>(pWin);
127 0 : return bCreateIfNotExist ? CreateDlgWin(rDocument, rLibName, rName) : 0;
128 : }
129 :
130 0 : sal_uInt16 Shell::GetWindowId(const BaseWindow* pWin) const
131 : {
132 0 : for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
133 0 : if ( it->second == pWin )
134 0 : return it->first;
135 0 : return 0;
136 : }
137 :
138 0 : SdrView* Shell::GetCurDlgView() const
139 : {
140 0 : if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin))
141 0 : return &pDCurWin->GetView();
142 : else
143 0 : return 0;
144 : }
145 :
146 : // only if dialogue window above:
147 0 : void Shell::ExecuteDialog( SfxRequest& rReq )
148 : {
149 0 : if (pCurWin && (dynamic_cast<DialogWindow*>(pCurWin) || rReq.GetSlot() == SID_IMPORT_DIALOG))
150 0 : pCurWin->ExecuteCommand(rReq);
151 0 : }
152 :
153 : } // namespace basctl
154 :
155 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|