LibreOffice Module sw (master) 1
vbawindow.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#include <ooo/vba/word/WdWindowState.hpp>
21#include <sal/log.hxx>
22#include <sfx2/viewfrm.hxx>
23#include <vcl/wrkwin.hxx>
24
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>
32
33using namespace ::com::sun::star;
34using namespace ::ooo::vba;
35
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 )
42{
43}
44
45void
47{
48 rtl::Reference<SwVbaDocument> document( new SwVbaDocument(uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel) );
49
50 document->Activate();
51}
52
53void
54SwVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& RouteDocument )
55{
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 );
60}
61
62uno::Any SAL_CALL
64{
65 return uno::Any( uno::Reference< word::XView >( new SwVbaView( this, mxContext, m_xModel ) ) );
66}
67
68void SAL_CALL SwVbaWindow::setView( const uno::Any& _view )
69{
70 sal_Int32 nType = 0;
71 if( _view >>= nType )
72 {
74 view->setType( nType );
75 }
76}
77
78uno::Any SAL_CALL
80{
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 )
86 {
87 if ( pWork -> IsMaximized())
88 nwindowState = word::WdWindowState::wdWindowStateMaximize;
89 else if (pWork -> IsMinimized())
90 nwindowState = word::WdWindowState::wdWindowStateMinimize;
91 }
92 return uno::Any( nwindowState );
93}
94
95void SAL_CALL
97{
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 )
104 {
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);
113 }
114}
115
116OUString SAL_CALL
118{
119 SwView* pView = word::getView( m_xModel );
120 if( !pView )
121 return "";
122
123 uno::Reference< css::beans::XPropertySet > xFrameProps( pView->GetViewFrame().GetFrame().GetFrameInterface()->getController()->getFrame(), uno::UNO_QUERY );
124 if( !xFrameProps.is() )
125 return "";
126
127 OUString sTitle;
128 xFrameProps->getPropertyValue( "Title" ) >>= sTitle;
129
130 return sTitle;
131}
132
133void SAL_CALL
134SwVbaWindow::setCaption( const OUString& _caption )
135{
136 SwView* pView = word::getView( m_xModel );
137 if( !pView )
138 return;
139
140 uno::Reference< css::beans::XPropertySet > xFrameProps( pView->GetViewFrame().GetFrame().GetFrameInterface()->getController()->getFrame(), uno::UNO_QUERY );
141 if( !xFrameProps.is() )
142 return;
143
144 xFrameProps->setPropertyValue( "Title", uno::Any( _caption ) );
145}
146
147uno::Any SAL_CALL
149{
150 uno::Reference< XCollection > xPanes( new SwVbaPanes( this, mxContext, m_xModel ) );
151 if( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
152 return uno::Any( xPanes );
153
154 return xPanes->Item( aIndex, uno::Any() );
155}
156
157uno::Any SAL_CALL
159{
160 return uno::Any( uno::Reference< word::XPane >( new SwVbaPane( this, mxContext, m_xModel ) ) );
161}
162
163OUString
165{
166 return "SwVbaWindow";
167}
168
169uno::Sequence< OUString >
171{
172 static uno::Sequence< OUString > const aServiceNames
173 {
174 "ooo.vba.word.Window"
175 };
176 return aServiceNames;
177}
178
179/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
SystemWindow * GetSystemWindow() const
SfxFrame & GetFrame() const
SfxViewFrame & GetViewFrame() const
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbawindow.cxx:170
virtual css::uno::Any SAL_CALL getView() override
Definition: vbawindow.cxx:63
SwVbaWindow(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::frame::XController > &xController)
Definition: vbawindow.cxx:36
virtual void SAL_CALL setCaption(const OUString &_caption) override
Definition: vbawindow.cxx:134
virtual css::uno::Any SAL_CALL ActivePane() override
Definition: vbawindow.cxx:158
virtual css::uno::Any SAL_CALL Panes(const css::uno::Any &aIndex) override
Definition: vbawindow.cxx:148
virtual OUString SAL_CALL getCaption() override
Definition: vbawindow.cxx:117
virtual css::uno::Any SAL_CALL getWindowState() override
Definition: vbawindow.cxx:79
virtual void SAL_CALL Close(const css::uno::Any &SaveChanges, const css::uno::Any &RouteDocument) override
Definition: vbawindow.cxx:54
virtual void SAL_CALL setWindowState(const css::uno::Any &_windowstate) override
Definition: vbawindow.cxx:96
virtual void SAL_CALL setView(const css::uno::Any &_view) override
Definition: vbawindow.cxx:68
virtual void SAL_CALL Activate() override
Definition: vbawindow.cxx:46
virtual OUString getServiceImplName() override
Definition: vbawindow.cxx:164
Definition: view.hxx:146
Reference< frame::XModel > m_xModel
uno::Reference< uno::XComponentContext > mxContext
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
#define SAL_WARN(area, stream)
SwView * getView(const uno::Reference< frame::XModel > &xModel)
QPRO_FUNC_TYPE nType
Reference< XController > xController
Reference< XModel > xModel
cppu::ImplInheritanceHelper< VbaWindowBase, ov::excel::XWindow > WindowImpl_BASE
BOOL IsMinimized(HWND hWnd)
BOOL IsMaximized(HWND hWnd)