LibreOffice Module basctl (master) 1
basides3.cxx
Go to the documentation of this file.
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
21#include <baside3.hxx>
22#include <basidesh.hxx>
23#include <localizationmgr.hxx>
24#include <dlgedview.hxx>
26#include <sfx2/request.hxx>
27#include <sfx2/sfxsids.hrc>
28#include <sfx2/viewfrm.hxx>
29#include <tools/debug.hxx>
32#include <com/sun/star/uno/XComponentContext.hpp>
33
34namespace basctl
35{
36
37using namespace comphelper;
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::uno;
40using namespace ::com::sun::star::io;
41
42VclPtr<DialogWindow> Shell::CreateDlgWin( const ScriptDocument& rDocument, const OUString& rLibName, const OUString& rDlgName )
43{
44 bCreatingWindow = true;
45
46 sal_uInt16 nKey = 0;
48 OUString aLibName( rLibName );
49 OUString aDlgName( rDlgName );
50
51 if ( aLibName.isEmpty() )
52 aLibName = "Standard" ;
53
54 rDocument.getOrCreateLibrary( E_DIALOGS, aLibName );
55
56 if ( aDlgName.isEmpty() )
57 aDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
58
59 // maybe there's a suspended one?
60 pWin = FindDlgWin( rDocument, aLibName, aDlgName, false, true );
61
62 if ( !pWin )
63 {
64 try
65 {
67 if ( rDocument.hasDialog( aLibName, aDlgName ) )
68 rDocument.getDialog( aLibName, aDlgName, xISP );
69 else
70 rDocument.createDialog( aLibName, aDlgName, xISP );
71
72 if ( xISP.is() )
73 {
74 // create dialog model
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 );
81
82 // new dialog window
83 if (!pDialogLayout)
85 pWin = VclPtr<DialogWindow>::Create(pDialogLayout.get(), rDocument, aLibName, aDlgName, xDialogModel);
86 nKey = InsertWindowInTable( pWin );
87 }
88 }
89 catch (const uno::Exception& )
90 {
91 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
92 }
93 }
94 else
95 {
96 pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
97 nKey = GetWindowId( pWin );
98 DBG_ASSERT( nKey, "CreateDlgWin: No Key - Window not found!" );
99 }
100
101 if( pWin )
102 {
103 pWin->GrabScrollBars( aHScrollBar.get(), aVScrollBar.get() );
104 pTabBar->InsertPage( nKey, aDlgName );
105 pTabBar->Sort();
106 if ( !pCurWin )
107 SetCurWindow( pWin, false, false );
108 }
109
110 bCreatingWindow = false;
111 return pWin;
112}
113
115 ScriptDocument const& rDocument,
116 OUString const& rLibName, OUString const& rName,
117 bool bCreateIfNotExist, bool bFindSuspended
118)
119{
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;
123}
124
125sal_uInt16 Shell::GetWindowId(const BaseWindow* pWin) const
126{
127 for (auto const& window : aWindowTable)
128 if ( window.second == pWin )
129 return window.first;
130 return 0;
131}
132
134{
135 if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin.get()))
136 return &pDCurWin->GetView();
137 else
138 return nullptr;
139}
140
141// only if dialogue window above:
143{
144 if (pCurWin && (dynamic_cast<DialogWindow*>(pCurWin.get()) || rReq.GetSlot() == SID_IMPORT_DIALOG))
145 pCurWin->ExecuteCommand(rReq);
146}
147
148} // namespace basctl
149
150/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetSlot() const
SfxViewFrame & GetViewFrame() const
vcl::Window * GetWindow() const
reference_type * get() const
static VclPtr< reference_type > Create(Arg &&... arg)
static void setStringResourceAtDialog(const ScriptDocument &rDocument, const OUString &aLibName, std::u16string_view aDlgName, const css::uno::Reference< css::container::XNameContainer > &xDialogModel)
encapsulates a document which contains Basic scripts and dialogs
css::uno::Reference< css::container::XNameContainer > getOrCreateLibrary(LibraryContainerType _eType, const OUString &_rLibName) const
creates a script or dialog library in the document, or returns an existing one
bool getDialog(const OUString &_rLibName, const OUString &_rDialogName, css::uno::Reference< css::io::XInputStreamProvider > &_out_rDialogProvider) const
retrieves a dialog
css::uno::Reference< css::frame::XModel > getDocument() const
returns the UNO component representing the document which the instance operates on
bool isDocument() const
determines whether the ScriptDocument instance operates on a real document, as opposed to the whole a...
bool hasDialog(const OUString &_rLibName, const OUString &_rDialogName) const
determines whether a dialog with the given name exists in the given library
bool createDialog(const OUString &_rLibName, const OUString &_rDialogName, css::uno::Reference< css::io::XInputStreamProvider > &_out_rDialogProvider) const
create a dialog
OUString createObjectName(LibraryContainerType _eType, const OUString &_rLibName) const
retrieves a name for a newly to be created module or dialog
VclPtr< BaseWindow > FindWindow(const ScriptDocument &rDocument, std::u16string_view rLibName, std::u16string_view rName, ItemType nType, bool bFindSuspended=false)
Definition: basides1.cxx:1391
sal_uInt16 GetWindowId(BaseWindow const *pWin) const
Definition: basides3.cxx:125
VclPtr< TabBar > pTabBar
Definition: basidesh.hxx:81
VclPtr< ScrollAdaptor > aVScrollBar
Definition: basidesh.hxx:80
SdrView * GetCurDlgView() const
Definition: basides3.cxx:133
bool bCreatingWindow
Definition: basidesh.hxx:82
VclPtr< DialogWindow > FindDlgWin(const ScriptDocument &rDocument, const OUString &rLibName, const OUString &rName, bool bCreateIfNotExist=false, bool bFindSuspended=false)
Definition: basides3.cxx:114
VclPtr< DialogWindow > CreateDlgWin(const ScriptDocument &rDocument, const OUString &rLibName, const OUString &rDlgName)
Definition: basides3.cxx:42
void ExecuteDialog(SfxRequest &rReq)
Definition: basides3.cxx:142
VclPtr< ObjectCatalog > aObjectCatalog
Definition: basidesh.hxx:89
VclPtr< ScrollAdaptor > aHScrollBar
Definition: basidesh.hxx:79
sal_uInt16 InsertWindowInTable(BaseWindow *pNewWin)
Definition: basidesh.cxx:841
VclPtr< BaseWindow > pCurWin
Definition: basidesh.hxx:72
WindowTable aWindowTable
Definition: basidesh.hxx:70
void SetCurWindow(BaseWindow *pNewWin, bool bUpdateTabBar=false, bool bRememberAsCurrent=true)
Definition: basides1.cxx:1271
VclPtr< DialogWindowLayout > pDialogLayout
Definition: basidesh.hxx:86
#define DBG_ASSERT(sCon, aError)
#define DBG_UNHANDLED_EXCEPTION(...)
@ BASWIN_SUSPENDED
Definition: bastypes.hxx:147
@ TYPE_DIALOG
Definition: sbxitem.hxx:33
Reference< XComponentContext > getProcessComponentContext()