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 #include <vbahelper/helperdecl.hxx>
20 #include <ooo/vba/word/WdWindowState.hpp>
21 #include <sfx2/viewfrm.hxx>
22 #include <vcl/wrkwin.hxx>
23 
24 #include "vbawindow.hxx"
25 #include "vbaglobals.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 
33 using namespace ::com::sun::star;
34 using 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 
45 void
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 
53 void
54 SwVbaWindow::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 
62 uno::Any SAL_CALL
64 {
65  return uno::makeAny( uno::Reference< word::XView >( new SwVbaView( this, mxContext, m_xModel ) ) );
66 }
67 
68 void SAL_CALL SwVbaWindow::setView( const uno::Any& _view )
69 {
70  sal_Int32 nType = 0;
71  if( _view >>= nType )
72  {
73  rtl::Reference<SwVbaView> view( new SwVbaView(this, mxContext, m_xModel) );
74  view->setType( nType );
75  }
76 }
77 
78 uno::Any SAL_CALL
80 {
81  sal_Int32 nwindowState = word::WdWindowState::wdWindowStateNormal;
82  SwView* pView = word::getView( m_xModel );
83  SfxViewFrame* pViewFrame = pView -> GetViewFrame();
84  WorkWindow* pWork = static_cast<WorkWindow*>( pViewFrame->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::makeAny( nwindowState );
93 }
94 
95 void SAL_CALL
96 SwVbaWindow::setWindowState( const uno::Any& _windowstate )
97 {
98  sal_Int32 nwindowState = word::WdWindowState::wdWindowStateMaximize;
99  _windowstate >>= nwindowState;
100  SwView* pView = word::getView( m_xModel );
101  SfxViewFrame* pViewFrame = pView -> GetViewFrame();
102  WorkWindow* pWork = static_cast<WorkWindow*>( pViewFrame->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 
116 OUString 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 
133 void SAL_CALL
134 SwVbaWindow::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::makeAny( _caption ) );
145 }
146 
147 uno::Any SAL_CALL
148 SwVbaWindow::Panes( const uno::Any& aIndex )
149 {
150  uno::Reference< XCollection > xPanes( new SwVbaPanes( this, mxContext, m_xModel ) );
151  if( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
152  return uno::makeAny( xPanes );
153 
154  return xPanes->Item( aIndex, uno::Any() );
155 }
156 
157 uno::Any SAL_CALL
159 {
160  return uno::makeAny( uno::Reference< word::XPane >( new SwVbaPane( this, mxContext, m_xModel ) ) );
161 }
162 
163 OUString
165 {
166  return "SwVbaWindow";
167 }
168 
169 uno::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: */
SfxViewFrame * GetViewFrame() const
cppu::ImplInheritanceHelper< VbaWindowBase, ov::excel::XWindow > WindowImpl_BASE
virtual css::uno::Any SAL_CALL Panes(const css::uno::Any &aIndex) override
Definition: vbawindow.cxx:148
virtual void SAL_CALL setCaption(const OUString &_caption) override
Definition: vbawindow.cxx:134
virtual void SAL_CALL Close(const css::uno::Any &SaveChanges, const css::uno::Any &RouteDocument) override
Definition: vbawindow.cxx:54
FUNC_TYPE const nType
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:36
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:46
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbawindow.cxx:170
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
virtual css::uno::Any SAL_CALL ActivePane() override
Definition: vbawindow.cxx:158
virtual void SAL_CALL setView(const css::uno::Any &_view) override
Definition: vbawindow.cxx:68
virtual css::uno::Any SAL_CALL getWindowState() override
Definition: vbawindow.cxx:79
virtual void SAL_CALL setWindowState(const css::uno::Any &_windowstate) override
Definition: vbawindow.cxx:96
virtual OUString getServiceImplName() override
Definition: vbawindow.cxx:164
#define SAL_WARN(area, stream)
virtual OUString SAL_CALL getCaption() override
Definition: vbawindow.cxx:117
SystemWindow * GetSystemWindow() const
virtual css::uno::Any SAL_CALL getView() override
Definition: vbawindow.cxx:63
Definition: view.hxx:146