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< XComponentContext > xContext = comphelper::getProcessComponentContext();
79 0 : Reference< container::XNameContainer > xDialogModel( xContext->getServiceManager()->createInstanceWithContext
80 0 : ( "com.sun.star.awt.UnoControlDialogModel", xContext ), UNO_QUERY );
81 0 : Reference< XInputStream > xInput( xISP->createInputStream() );
82 0 : ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, rDocument.isDocument() ? rDocument.getDocument() : Reference< frame::XModel >() );
83 0 : LocalizationMgr::setStringResourceAtDialog( rDocument, rLibName, aDlgName, xDialogModel );
84 :
85 : // new dialog window
86 0 : if (!pDialogLayout)
87 0 : pDialogLayout.reset(new DialogWindowLayout(&GetViewFrame()->GetWindow(), aObjectCatalog));
88 0 : pWin = new DialogWindow(pDialogLayout.get(), rDocument, aLibName, aDlgName, xDialogModel);
89 0 : nKey = InsertWindowInTable( pWin );
90 0 : }
91 : }
92 0 : catch (const uno::Exception& )
93 : {
94 : DBG_UNHANDLED_EXCEPTION();
95 : }
96 : }
97 : else
98 : {
99 0 : pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
100 0 : nKey = GetWindowId( pWin );
101 : DBG_ASSERT( nKey, "CreateDlgWin: Kein Key - Fenster nicht gefunden!" );
102 : }
103 :
104 0 : if( pWin )
105 : {
106 0 : pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
107 0 : pTabBar->InsertPage( (sal_uInt16)nKey, aDlgName );
108 0 : pTabBar->Sort();
109 0 : if ( !pCurWin )
110 0 : SetCurWindow( pWin, false, false );
111 : }
112 :
113 0 : bCreatingWindow = false;
114 0 : return pWin;
115 : }
116 :
117 0 : DialogWindow* Shell::FindDlgWin (
118 : ScriptDocument const& rDocument,
119 : OUString const& rLibName, OUString const& rName,
120 : bool bCreateIfNotExist, bool bFindSuspended
121 : )
122 : {
123 0 : if (BaseWindow* pWin = FindWindow(rDocument, rLibName, rName, TYPE_DIALOG, bFindSuspended))
124 0 : return static_cast<DialogWindow*>(pWin);
125 0 : return bCreateIfNotExist ? CreateDlgWin(rDocument, rLibName, rName) : 0;
126 : }
127 :
128 0 : sal_uInt16 Shell::GetWindowId(const BaseWindow* pWin) const
129 : {
130 0 : for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
131 0 : if ( it->second == pWin )
132 0 : return it->first;
133 0 : return 0;
134 : }
135 :
136 0 : SdrView* Shell::GetCurDlgView() const
137 : {
138 0 : if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin))
139 0 : return &pDCurWin->GetView();
140 : else
141 0 : return 0;
142 : }
143 :
144 : // only if dialogue window above:
145 0 : void Shell::ExecuteDialog( SfxRequest& rReq )
146 : {
147 0 : if (pCurWin && (dynamic_cast<DialogWindow*>(pCurWin) || rReq.GetSlot() == SID_IMPORT_DIALOG))
148 0 : pCurWin->ExecuteCommand(rReq);
149 0 : }
150 :
151 0 : } // namespace basctl
152 :
153 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|