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 <sfx2/viewfrm.hxx>
22 #include <vcl/wrkwin.hxx>
23 
24 #include "vbawindow.hxx"
25 #include "vbadocument.hxx"
26 #include "vbaview.hxx"
27 #include "vbapanes.hxx"
28 #include "vbapane.hxx"
29 #include "wordvbahelper.hxx"
30 #include <view.hxx>
31 
32 using namespace ::com::sun::star;
33 using namespace ::ooo::vba;
34 
36  const uno::Reference< XHelperInterface >& xParent,
37  const uno::Reference< uno::XComponentContext >& xContext,
38  const uno::Reference< frame::XModel >& xModel,
39  const uno::Reference< frame::XController >& xController ) :
40  WindowImpl_BASE( xParent, xContext, xModel, xController )
41 {
42 }
43 
44 void
46 {
47  rtl::Reference<SwVbaDocument> document( new SwVbaDocument(uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel) );
48 
49  document->Activate();
50 }
51 
52 void
53 SwVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& RouteDocument )
54 {
55  // FIXME: it is incorrect when there are more than 1 windows
56  rtl::Reference<SwVbaDocument> document( new SwVbaDocument(uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel) );
57  uno::Any FileName;
58  document->Close(SaveChanges, FileName, RouteDocument );
59 }
60 
61 uno::Any SAL_CALL
63 {
64  return uno::makeAny( uno::Reference< word::XView >( new SwVbaView( this, mxContext, m_xModel ) ) );
65 }
66 
67 void SAL_CALL SwVbaWindow::setView( const uno::Any& _view )
68 {
69  sal_Int32 nType = 0;
70  if( _view >>= nType )
71  {
73  view->setType( nType );
74  }
75 }
76 
77 uno::Any SAL_CALL
79 {
80  sal_Int32 nwindowState = word::WdWindowState::wdWindowStateNormal;
81  SwView* pView = word::getView( m_xModel );
82  SfxViewFrame* pViewFrame = pView -> GetViewFrame();
83  WorkWindow* pWork = static_cast<WorkWindow*>( pViewFrame->GetFrame().GetSystemWindow() );
84  if ( pWork )
85  {
86  if ( pWork -> IsMaximized())
87  nwindowState = word::WdWindowState::wdWindowStateMaximize;
88  else if (pWork -> IsMinimized())
89  nwindowState = word::WdWindowState::wdWindowStateMinimize;
90  }
91  return uno::makeAny( nwindowState );
92 }
93 
94 void SAL_CALL
95 SwVbaWindow::setWindowState( const uno::Any& _windowstate )
96 {
97  sal_Int32 nwindowState = word::WdWindowState::wdWindowStateMaximize;
98  _windowstate >>= nwindowState;
99  SwView* pView = word::getView( m_xModel );
100  SfxViewFrame* pViewFrame = pView -> GetViewFrame();
101  WorkWindow* pWork = static_cast<WorkWindow*>( pViewFrame->GetFrame().GetSystemWindow() );
102  if ( pWork )
103  {
104  if ( nwindowState == word::WdWindowState::wdWindowStateMaximize )
105  pWork -> Maximize();
106  else if (nwindowState == word::WdWindowState::wdWindowStateMinimize)
107  pWork -> Minimize();
108  else if (nwindowState == word::WdWindowState::wdWindowStateNormal)
109  pWork -> Restore();
110  else
111  SAL_WARN("sw.vba", "Unhandled window state " << nwindowState);
112  }
113 }
114 
115 OUString SAL_CALL
117 {
118  SwView* pView = word::getView( m_xModel );
119  if( !pView )
120  return "";
121 
122  uno::Reference< css::beans::XPropertySet > xFrameProps( pView->GetViewFrame()->GetFrame().GetFrameInterface()->getController()->getFrame(), uno::UNO_QUERY );
123  if( !xFrameProps.is() )
124  return "";
125 
126  OUString sTitle;
127  xFrameProps->getPropertyValue( "Title" ) >>= sTitle;
128 
129  return sTitle;
130 }
131 
132 void SAL_CALL
133 SwVbaWindow::setCaption( const OUString& _caption )
134 {
135  SwView* pView = word::getView( m_xModel );
136  if( !pView )
137  return;
138 
139  uno::Reference< css::beans::XPropertySet > xFrameProps( pView->GetViewFrame()->GetFrame().GetFrameInterface()->getController()->getFrame(), uno::UNO_QUERY );
140  if( !xFrameProps.is() )
141  return;
142 
143  xFrameProps->setPropertyValue( "Title", uno::makeAny( _caption ) );
144 }
145 
146 uno::Any SAL_CALL
147 SwVbaWindow::Panes( const uno::Any& aIndex )
148 {
149  uno::Reference< XCollection > xPanes( new SwVbaPanes( this, mxContext, m_xModel ) );
150  if( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
151  return uno::makeAny( xPanes );
152 
153  return xPanes->Item( aIndex, uno::Any() );
154 }
155 
156 uno::Any SAL_CALL
158 {
159  return uno::makeAny( uno::Reference< word::XPane >( new SwVbaPane( this, mxContext, m_xModel ) ) );
160 }
161 
162 OUString
164 {
165  return "SwVbaWindow";
166 }
167 
168 uno::Sequence< OUString >
170 {
171  static uno::Sequence< OUString > const aServiceNames
172  {
173  "ooo.vba.word.Window"
174  };
175  return aServiceNames;
176 }
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
cppu::ImplInheritanceHelper< VbaWindowBase, ov::excel::XWindow > WindowImpl_BASE
Reference< frame::XModel > m_xModel
virtual css::uno::Any SAL_CALL Panes(const css::uno::Any &aIndex) override
Definition: vbawindow.cxx:147
virtual void SAL_CALL setCaption(const OUString &_caption) override
Definition: vbawindow.cxx:133
virtual void SAL_CALL Close(const css::uno::Any &SaveChanges, const css::uno::Any &RouteDocument) override
Definition: vbawindow.cxx:53
uno::Reference< uno::XComponentContext > mxContext
Sequence< OUString > aServiceNames
SfxFrame & GetFrame() const
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:35
BOOL IsMinimized(HWND hWnd)
BOOL IsMaximized(HWND hWnd)
SwView * getView(const uno::Reference< frame::XModel > &xModel)
virtual void SAL_CALL Activate() override
Definition: vbawindow.cxx:45
exports com.sun.star. view
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbawindow.cxx:169
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
virtual css::uno::Any SAL_CALL ActivePane() override
Definition: vbawindow.cxx:157
virtual void SAL_CALL setView(const css::uno::Any &_view) override
Definition: vbawindow.cxx:67
exports com.sun.star. document
virtual css::uno::Any SAL_CALL getWindowState() override
Definition: vbawindow.cxx:78
QPRO_FUNC_TYPE nType
virtual void SAL_CALL setWindowState(const css::uno::Any &_windowstate) override
Definition: vbawindow.cxx:95
virtual OUString getServiceImplName() override
Definition: vbawindow.cxx:163
#define SAL_WARN(area, stream)
virtual OUString SAL_CALL getCaption() override
Definition: vbawindow.cxx:116
SystemWindow * GetSystemWindow() const
virtual css::uno::Any SAL_CALL getView() override
Definition: vbawindow.cxx:62
Definition: view.hxx:144