lok: Don't attempt to select the exact text after a failed search.
[LibreOffice.git] / basctl / source / basicide / basides3.cxx
blobcd84dd4972b11c59e15b1da026efc027556bdaa3
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 <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>
30 namespace basctl
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;
42 sal_uLong nKey = 0;
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 );
58 if ( !pWin )
60 try
62 Reference< io::XInputStreamProvider > xISP;
63 if ( rDocument.hasDialog( aLibName, aDlgName ) )
64 rDocument.getDialog( aLibName, aDlgName, xISP );
65 else
66 rDocument.createDialog( aLibName, aDlgName, xISP );
68 if ( xISP.is() )
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 );
78 // new dialog window
79 if (!pDialogLayout)
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();
90 else
92 pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
93 nKey = GetWindowId( pWin );
94 DBG_ASSERT( nKey, "CreateDlgWin: Kein Key - Fenster nicht gefunden!" );
97 if( pWin )
99 pWin->GrabScrollBars( aHScrollBar.get(), aVScrollBar.get() );
100 pTabBar->InsertPage( (sal_uInt16)nKey, aDlgName );
101 pTabBar->Sort();
102 if ( !pCurWin )
103 SetCurWindow( pWin, false, false );
106 bCreatingWindow = false;
107 return pWin;
110 VclPtr<DialogWindow> Shell::FindDlgWin (
111 ScriptDocument const& rDocument,
112 OUString const& rLibName, OUString const& rName,
113 bool bCreateIfNotExist, bool bFindSuspended
116 if (BaseWindow* pWin = FindWindow(rDocument, rLibName, rName, TYPE_DIALOG, bFindSuspended))
117 return static_cast<DialogWindow*>(pWin);
118 return bCreateIfNotExist ? CreateDlgWin(rDocument, rLibName, rName) : 0;
121 sal_uInt16 Shell::GetWindowId(const BaseWindow* pWin) const
123 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
124 if ( it->second == pWin )
125 return it->first;
126 return 0;
129 SdrView* Shell::GetCurDlgView() const
131 if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin.get()))
132 return &pDCurWin->GetView();
133 else
134 return 0;
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: */