bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / bibliography / bibbeam.cxx
blob05c78c394ed2bb4ba667b565a50d66bb3e163db9
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 "toolbar.hrc"
33 #include "bibresid.hxx"
34 #include "datman.hxx"
35 #include "bibtools.hxx"
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::uno;
42 #define ID_TOOLBAR 1
43 #define ID_GRIDWIN 2
45 //.........................................................................
46 namespace bib
48 //.........................................................................
50 using namespace ::com::sun::star::uno;
52 void HandleTaskPaneList( Window* pWindow, sal_Bool bAddToList )
54 Window* pParent = pWindow->GetParent();
56 DBG_ASSERT( pParent, "-GetTaskPaneList(): everybody here should have a parent!" );
58 SystemWindow* pSysWin = pParent->GetSystemWindow();
59 if( pSysWin )
61 TaskPaneList* pTaskPaneList = pSysWin->GetTaskPaneList();
62 if( pTaskPaneList )
64 if( bAddToList )
65 pTaskPaneList->AddWindow( pWindow );
66 else
67 pTaskPaneList->RemoveWindow( pWindow );
72 //=====================================================================
73 //= BibGridwin
74 //=====================================================================
75 class BibGridwin
76 :public Window //DockingWindow
78 private:
79 Reference< awt::XWindow > m_xGridWin;
80 Reference< awt::XControlModel > m_xGridModel;
81 Reference< awt::XControl > m_xControl;
82 Reference< awt::XControlContainer > m_xControlContainer;
83 // #100312# ---------
84 Reference< frame::XDispatchProviderInterception> m_xDispatchProviderInterception;
86 protected:
88 virtual void Resize();
90 public:
92 BibGridwin(Window* pParent, WinBits nStyle = WB_3DLOOK );
93 ~BibGridwin();
95 void createGridWin(const Reference< awt::XControlModel > & xDbForm);
96 void disposeGridWin();
98 const Reference< awt::XControlContainer >& getControlContainer() const { return m_xControlContainer; }
99 // #100312# ---------
100 const Reference< frame::XDispatchProviderInterception>& getDispatchProviderInterception() const { return m_xDispatchProviderInterception; }
102 virtual void GetFocus();
105 //---------------------------------------------------------------------
106 BibGridwin::BibGridwin( Window* _pParent, WinBits _nStyle ) : Window( _pParent, _nStyle )
108 m_xControlContainer = VCLUnoHelper::CreateControlContainer(this);
110 AddToTaskPaneList( this );
113 //---------------------------------------------------------------------
114 BibGridwin::~BibGridwin()
116 RemoveFromTaskPaneList( this );
118 disposeGridWin();
121 //---------------------------------------------------------------------
122 void BibGridwin::Resize()
124 if(m_xGridWin.is())
126 ::Size aSize = GetOutputSizePixel();
127 m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::SIZE);
131 //---------------------------------------------------------------------
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 als Child zu dem 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 desing 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 //---------------------------------------------------------------------
173 void BibGridwin::disposeGridWin()
175 if ( m_xControl.is() )
177 Reference< awt::XControl > xDel( m_xControl );
178 m_xControl = NULL;
179 m_xGridWin = NULL;
181 m_xControlContainer->removeControl( xDel );
182 xDel->dispose();
186 //---------------------------------------------------------------------
187 void BibGridwin::GetFocus()
189 if(m_xGridWin.is())
190 m_xGridWin->setFocus();
193 //---------------------------------------------------------------------
194 BibBeamer::BibBeamer( Window* _pParent, BibDataManager* _pDM, WinBits _nStyle )
195 :BibSplitWindow( _pParent, _nStyle | WB_NOSPLITDRAW )
196 ,pDatMan( _pDM )
197 ,pToolBar( NULL )
198 ,pGridWin( NULL )
200 createToolBar();
201 createGridWin();
202 if ( pDatMan )
203 pDatMan->SetToolbar(pToolBar);
204 pGridWin->Show();
206 if ( pDatMan )
207 connectForm( pDatMan );
210 //---------------------------------------------------------------------
211 BibBeamer::~BibBeamer()
213 if ( isFormConnected() )
214 disconnectForm();
216 if ( m_xToolBarRef.is() )
217 m_xToolBarRef->dispose();
219 if ( pToolBar )
221 if ( pDatMan )
222 pDatMan->SetToolbar(0);
224 DELETEZ( pToolBar );
227 if( pGridWin )
229 BibGridwin* pDel = pGridWin;
230 pGridWin = NULL;
231 pDel->disposeGridWin();
232 delete pDel;
237 //---------------------------------------------------------------------
238 void BibBeamer::createToolBar()
240 pToolBar= new BibToolBar(this, LINK( this, BibBeamer, RecalcLayout_Impl ));
241 ::Size aSize=pToolBar->GetSizePixel();
242 InsertItem(ID_TOOLBAR, pToolBar, aSize.Height(), 0, 0, SWIB_FIXED );
243 if ( m_xController.is() )
244 pToolBar->SetXController( m_xController );
247 //---------------------------------------------------------------------
248 void BibBeamer::createGridWin()
250 pGridWin = new BibGridwin(this,0);
252 InsertItem(ID_GRIDWIN, pGridWin, 40, 1, 0, SWIB_RELATIVESIZE );
254 pGridWin->createGridWin( pDatMan->updateGridModel() );
257 //---------------------------------------------------------------------
258 Reference< awt::XControlContainer > BibBeamer::getControlContainer()
260 Reference< awt::XControlContainer > xReturn;
261 if ( pGridWin )
262 xReturn = pGridWin->getControlContainer();
263 return xReturn;
266 // #100312# -----------------------------------------------------------
267 Reference< frame::XDispatchProviderInterception > BibBeamer::getDispatchProviderInterception()
269 Reference< frame::XDispatchProviderInterception > xReturn;
270 if ( pGridWin )
271 xReturn = pGridWin->getDispatchProviderInterception();
272 return xReturn;
275 //---------------------------------------------------------------------
276 void BibBeamer::SetXController(const uno::Reference< frame::XController > & xCtr)
278 m_xController = xCtr;
280 if ( pToolBar )
281 pToolBar->SetXController( m_xController );
285 //---------------------------------------------------------------------
286 void BibBeamer::GetFocus()
288 if( pGridWin )
289 pGridWin->GrabFocus();
292 //---------------------------------------------------------------------
293 IMPL_LINK( BibBeamer, RecalcLayout_Impl, void*, /*pVoid*/ )
295 long nHeight = pToolBar->GetSizePixel().Height();
296 SetItemSize( ID_TOOLBAR, nHeight );
297 return 0L;
300 //.........................................................................
301 } // namespace bib
302 //.........................................................................
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */