android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbawindow.cxx
blob9114f4b8d44dad73668d4dd5b0efa39c315161f3
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 .
20 #include <ooo/vba/word/WdWindowState.hpp>
21 #include <sal/log.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <vcl/wrkwin.hxx>
25 #include "vbawindow.hxx"
26 #include "vbadocument.hxx"
27 #include "vbaview.hxx"
28 #include "vbapanes.hxx"
29 #include "vbapane.hxx"
30 #include "wordvbahelper.hxx"
31 #include <view.hxx>
33 using namespace ::com::sun::star;
34 using namespace ::ooo::vba;
36 SwVbaWindow::SwVbaWindow(
37 const uno::Reference< XHelperInterface >& xParent,
38 const uno::Reference< uno::XComponentContext >& xContext,
39 const uno::Reference< frame::XModel >& xModel,
40 const uno::Reference< frame::XController >& xController ) :
41 WindowImpl_BASE( xParent, xContext, xModel, xController )
45 void
46 SwVbaWindow::Activate()
48 rtl::Reference<SwVbaDocument> document( new SwVbaDocument(uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel) );
50 document->Activate();
53 void
54 SwVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& RouteDocument )
56 // FIXME: it is incorrect when there are more than 1 windows
57 rtl::Reference<SwVbaDocument> document( new SwVbaDocument(uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel) );
58 uno::Any FileName;
59 document->Close(SaveChanges, FileName, RouteDocument );
62 uno::Any SAL_CALL
63 SwVbaWindow::getView()
65 return uno::Any( uno::Reference< word::XView >( new SwVbaView( this, mxContext, m_xModel ) ) );
68 void SAL_CALL SwVbaWindow::setView( const uno::Any& _view )
70 sal_Int32 nType = 0;
71 if( _view >>= nType )
73 rtl::Reference<SwVbaView> view( new SwVbaView(this, mxContext, m_xModel) );
74 view->setType( nType );
78 uno::Any SAL_CALL
79 SwVbaWindow::getWindowState()
81 sal_Int32 nwindowState = word::WdWindowState::wdWindowStateNormal;
82 SwView* pView = word::getView( m_xModel );
83 SfxViewFrame& rViewFrame = pView->GetViewFrame();
84 WorkWindow* pWork = static_cast<WorkWindow*>( rViewFrame.GetFrame().GetSystemWindow() );
85 if ( pWork )
87 if ( pWork -> IsMaximized())
88 nwindowState = word::WdWindowState::wdWindowStateMaximize;
89 else if (pWork -> IsMinimized())
90 nwindowState = word::WdWindowState::wdWindowStateMinimize;
92 return uno::Any( nwindowState );
95 void SAL_CALL
96 SwVbaWindow::setWindowState( const uno::Any& _windowstate )
98 sal_Int32 nwindowState = word::WdWindowState::wdWindowStateMaximize;
99 _windowstate >>= nwindowState;
100 SwView* pView = word::getView( m_xModel );
101 SfxViewFrame& rViewFrame = pView->GetViewFrame();
102 WorkWindow* pWork = static_cast<WorkWindow*>( rViewFrame.GetFrame().GetSystemWindow() );
103 if ( pWork )
105 if ( nwindowState == word::WdWindowState::wdWindowStateMaximize )
106 pWork -> Maximize();
107 else if (nwindowState == word::WdWindowState::wdWindowStateMinimize)
108 pWork -> Minimize();
109 else if (nwindowState == word::WdWindowState::wdWindowStateNormal)
110 pWork -> Restore();
111 else
112 SAL_WARN("sw.vba", "Unhandled window state " << nwindowState);
116 OUString SAL_CALL
117 SwVbaWindow::getCaption()
119 SwView* pView = word::getView( m_xModel );
120 if( !pView )
121 return "";
123 uno::Reference< css::beans::XPropertySet > xFrameProps( pView->GetViewFrame().GetFrame().GetFrameInterface()->getController()->getFrame(), uno::UNO_QUERY );
124 if( !xFrameProps.is() )
125 return "";
127 OUString sTitle;
128 xFrameProps->getPropertyValue( "Title" ) >>= sTitle;
130 return sTitle;
133 void SAL_CALL
134 SwVbaWindow::setCaption( const OUString& _caption )
136 SwView* pView = word::getView( m_xModel );
137 if( !pView )
138 return;
140 uno::Reference< css::beans::XPropertySet > xFrameProps( pView->GetViewFrame().GetFrame().GetFrameInterface()->getController()->getFrame(), uno::UNO_QUERY );
141 if( !xFrameProps.is() )
142 return;
144 xFrameProps->setPropertyValue( "Title", uno::Any( _caption ) );
147 uno::Any SAL_CALL
148 SwVbaWindow::Panes( const uno::Any& aIndex )
150 uno::Reference< XCollection > xPanes( new SwVbaPanes( this, mxContext, m_xModel ) );
151 if( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
152 return uno::Any( xPanes );
154 return xPanes->Item( aIndex, uno::Any() );
157 uno::Any SAL_CALL
158 SwVbaWindow::ActivePane()
160 return uno::Any( uno::Reference< word::XPane >( new SwVbaPane( this, mxContext, m_xModel ) ) );
163 OUString
164 SwVbaWindow::getServiceImplName()
166 return "SwVbaWindow";
169 uno::Sequence< OUString >
170 SwVbaWindow::getServiceNames()
172 static uno::Sequence< OUString > const aServiceNames
174 "ooo.vba.word.Window"
176 return aServiceNames;
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */