bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / bibliography / bibbeam.cxx
blob1699b8ddbd28cca37ccf8f222d1b9708cefab60d
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 <osl/mutex.hxx>
21 #include <toolkit/helper/vclunohelper.hxx>
22 #include <comphelper/processfactory.hxx>
23 #include <com/sun/star/awt/PosSize.hpp>
24 #include <com/sun/star/frame/XDispatch.hpp>
25 #include <com/sun/star/util/XURLTransformer.hpp>
27 #include "bibliography.hrc"
28 #include <vcl/lstbox.hxx>
29 #include <vcl/edit.hxx>
30 #include <tools/debug.hxx>
31 #include "bibbeam.hxx"
32 #include "bibview.hxx"
33 #include "toolbar.hrc"
34 #include "bibresid.hxx"
35 #include "datman.hxx"
36 #include "bibtools.hxx"
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::uno;
43 #define ID_TOOLBAR 1
44 #define ID_GRIDWIN 2
46 namespace bib
49 using namespace ::com::sun::star::uno;
51 void HandleTaskPaneList( vcl::Window* pWindow, bool bAddToList )
53 vcl::Window* pParent = pWindow->GetParent();
55 DBG_ASSERT( pParent, "-GetTaskPaneList(): everybody here should have a parent!" );
57 SystemWindow* pSysWin = pParent->GetSystemWindow();
58 if( pSysWin )
60 TaskPaneList* pTaskPaneList = pSysWin->GetTaskPaneList();
61 if( pTaskPaneList )
63 if( bAddToList )
64 pTaskPaneList->AddWindow( pWindow );
65 else
66 pTaskPaneList->RemoveWindow( pWindow );
72 class BibGridwin
73 :public vcl::Window //DockingWindow
75 private:
76 Reference< awt::XWindow > m_xGridWin;
77 Reference< awt::XControlModel > m_xGridModel;
78 Reference< awt::XControl > m_xControl;
79 Reference< awt::XControlContainer > m_xControlContainer;
80 // #100312#
81 Reference< frame::XDispatchProviderInterception> m_xDispatchProviderInterception;
83 protected:
85 virtual void Resize() SAL_OVERRIDE;
87 public:
89 BibGridwin(vcl::Window* pParent, WinBits nStyle = WB_3DLOOK );
90 virtual ~BibGridwin();
91 virtual void dispose() SAL_OVERRIDE;
93 void createGridWin(const Reference< awt::XControlModel > & xDbForm);
94 void disposeGridWin();
96 const Reference< awt::XControlContainer >& getControlContainer() const { return m_xControlContainer; }
97 // #100312#
98 const Reference< frame::XDispatchProviderInterception>& getDispatchProviderInterception() const { return m_xDispatchProviderInterception; }
100 virtual void GetFocus() SAL_OVERRIDE;
103 BibGridwin::BibGridwin( vcl::Window* _pParent, WinBits _nStyle ) : Window( _pParent, _nStyle )
105 m_xControlContainer = VCLUnoHelper::CreateControlContainer(this);
107 AddToTaskPaneList( this );
110 BibGridwin::~BibGridwin()
112 disposeOnce();
115 void BibGridwin::dispose()
117 RemoveFromTaskPaneList( this );
119 disposeGridWin();
120 vcl::Window::dispose();
123 void BibGridwin::Resize()
125 if(m_xGridWin.is())
127 ::Size aSize = GetOutputSizePixel();
128 m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::SIZE);
132 void BibGridwin::createGridWin(const uno::Reference< awt::XControlModel > & xGModel)
134 m_xGridModel = xGModel;
136 if( m_xControlContainer.is())
138 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
140 if ( m_xGridModel.is())
142 uno::Reference< XPropertySet > xPropSet( m_xGridModel, UNO_QUERY );
144 if ( xPropSet.is() && m_xGridModel.is() )
146 uno::Any aAny = xPropSet->getPropertyValue( "DefaultControl" );
147 OUString aControlName;
148 aAny >>= aControlName;
150 m_xControl = Reference< awt::XControl > ( xContext->getServiceManager()->createInstanceWithContext(aControlName, xContext), UNO_QUERY_THROW );
151 m_xControl->setModel( m_xGridModel );
154 if ( m_xControl.is() )
156 // Peer as Child to the FrameWindow
157 m_xControlContainer->addControl("GridControl", m_xControl);
158 m_xGridWin=uno::Reference< awt::XWindow > (m_xControl, UNO_QUERY );
159 // #100312#
160 m_xDispatchProviderInterception=uno::Reference< frame::XDispatchProviderInterception > (m_xControl, UNO_QUERY );
161 m_xGridWin->setVisible( sal_True );
162 m_xControl->setDesignMode( sal_True );
163 // initially switch on the design mode - switch it off _after_ loading the form
165 ::Size aSize = GetOutputSizePixel();
166 m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::POSSIZE);
172 void BibGridwin::disposeGridWin()
174 if ( m_xControl.is() )
176 Reference< awt::XControl > xDel( m_xControl );
177 m_xControl = NULL;
178 m_xGridWin = NULL;
180 m_xControlContainer->removeControl( xDel );
181 xDel->dispose();
185 void BibGridwin::GetFocus()
187 if(m_xGridWin.is())
188 m_xGridWin->setFocus();
191 BibBeamer::BibBeamer( vcl::Window* _pParent, BibDataManager* _pDM, WinBits _nStyle )
192 :BibSplitWindow( _pParent, _nStyle | WB_NOSPLITDRAW )
193 ,pDatMan( _pDM )
194 ,pToolBar( NULL )
195 ,pGridWin( NULL )
197 createToolBar();
198 createGridWin();
199 pDatMan->SetToolbar(pToolBar);
200 pGridWin->Show();
201 connectForm( pDatMan );
204 BibBeamer::~BibBeamer()
206 disposeOnce();
209 void BibBeamer::dispose()
211 if ( isFormConnected() )
212 disconnectForm();
214 if ( m_xToolBarRef.is() )
215 m_xToolBarRef->dispose();
217 if ( pToolBar )
218 pDatMan->SetToolbar(0);
220 pToolBar.disposeAndClear();
221 pGridWin.disposeAndClear();
222 BibSplitWindow::dispose();
225 void BibBeamer::createToolBar()
227 pToolBar= VclPtr<BibToolBar>::Create(this, LINK( this, BibBeamer, RecalcLayout_Impl ));
228 ::Size aSize=pToolBar->GetSizePixel();
229 InsertItem(ID_TOOLBAR, pToolBar, aSize.Height(), 0, 0, SWIB_FIXED );
230 if ( m_xController.is() )
231 pToolBar->SetXController( m_xController );
234 void BibBeamer::createGridWin()
236 pGridWin = VclPtr<BibGridwin>::Create(this,0);
238 InsertItem(ID_GRIDWIN, pGridWin, 40, 1, 0, SWIB_RELATIVESIZE );
240 pGridWin->createGridWin( pDatMan->updateGridModel() );
243 Reference< awt::XControlContainer > BibBeamer::getControlContainer()
245 Reference< awt::XControlContainer > xReturn;
246 if ( pGridWin )
247 xReturn = pGridWin->getControlContainer();
248 return xReturn;
251 // #100312#
252 Reference< frame::XDispatchProviderInterception > BibBeamer::getDispatchProviderInterception()
254 Reference< frame::XDispatchProviderInterception > xReturn;
255 if ( pGridWin )
256 xReturn = pGridWin->getDispatchProviderInterception();
257 return xReturn;
260 void BibBeamer::SetXController(const uno::Reference< frame::XController > & xCtr)
262 m_xController = xCtr;
264 if ( pToolBar )
265 pToolBar->SetXController( m_xController );
269 void BibBeamer::GetFocus()
271 if( pGridWin )
272 pGridWin->GrabFocus();
275 IMPL_LINK_NOARG( BibBeamer, RecalcLayout_Impl )
277 long nHeight = pToolBar->GetSizePixel().Height();
278 SetItemSize( ID_TOOLBAR, nHeight );
279 return 0L;
282 } // namespace bib
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */