update dev300-m58
[ooovba.git] / extensions / source / bibliography / bibbeam.cxx
blob96bddc0879c351bc38e28b913648c05ead1246bf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bibbeam.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include <osl/mutex.hxx>
34 #include <tools/urlobj.hxx>
35 #ifndef _TOOLKIT_UNOHLP_HXX
36 #include <toolkit/helper/vclunohelper.hxx>
37 #endif
38 #include <comphelper/processfactory.hxx>
39 #include <com/sun/star/awt/PosSize.hpp>
40 #include <com/sun/star/frame/XDispatch.hpp>
41 #include <com/sun/star/util/XURLTransformer.hpp>
43 #ifndef EXTENSIONS_INC_EXTENSIO_HRC
44 #include "extensio.hrc"
45 #endif
46 #include <vcl/lstbox.hxx>
47 #include <vcl/edit.hxx>
48 #include <tools/debug.hxx>
49 #include "bibbeam.hxx"
50 #include "toolbar.hrc"
51 #include "bibresid.hxx"
52 #include "datman.hxx"
53 #ifndef BIBTOOLS_HXX
54 #include "bibtools.hxx"
55 #endif
57 using namespace rtl;
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::beans;
60 using namespace ::com::sun::star::uno;
62 #define C2U(cChar) OUString::createFromAscii(cChar)
64 #define PROPERTY_FRAME 1
65 #define ID_TOOLBAR 1
66 #define ID_GRIDWIN 2
68 //.........................................................................
69 namespace bib
71 //.........................................................................
73 using namespace ::com::sun::star::uno;
75 void HandleTaskPaneList( Window* pWindow, BOOL bAddToList )
77 Window* pParent = pWindow->GetParent();
79 DBG_ASSERT( pParent, "-GetTaskPaneList(): everybody here should have a parent!" );
81 SystemWindow* pSysWin = pParent->GetSystemWindow();
82 if( pSysWin )
84 TaskPaneList* pTaskPaneList = pSysWin->GetTaskPaneList();
85 if( pTaskPaneList )
87 if( bAddToList )
88 pTaskPaneList->AddWindow( pWindow );
89 else
90 pTaskPaneList->RemoveWindow( pWindow );
95 //=====================================================================
96 //= BibGridwin
97 //=====================================================================
98 class BibGridwin
99 :public Window //DockingWindow
101 private:
102 Reference< awt::XWindow > m_xGridWin;
103 Reference< awt::XControlModel > m_xGridModel;
104 Reference< awt::XControl > m_xControl;
105 Reference< awt::XControlContainer > m_xControlContainer;
106 // #100312# ---------
107 Reference< frame::XDispatchProviderInterception> m_xDispatchProviderInterception;
109 protected:
111 virtual void Resize();
113 public:
115 BibGridwin(Window* pParent, WinBits nStyle = WB_3DLOOK );
116 ~BibGridwin();
118 void createGridWin(const Reference< awt::XControlModel > & xDbForm);
119 void disposeGridWin();
121 const Reference< awt::XControlContainer >& getControlContainer() const { return m_xControlContainer; }
122 // #100312# ---------
123 const Reference< frame::XDispatchProviderInterception>& getDispatchProviderInterception() const { return m_xDispatchProviderInterception; }
125 virtual void GetFocus();
128 //---------------------------------------------------------------------
129 BibGridwin::BibGridwin( Window* _pParent, WinBits _nStyle ) : Window( _pParent, _nStyle )
131 m_xControlContainer = VCLUnoHelper::CreateControlContainer(this);
133 AddToTaskPaneList( this );
136 //---------------------------------------------------------------------
137 BibGridwin::~BibGridwin()
139 RemoveFromTaskPaneList( this );
141 disposeGridWin();
144 //---------------------------------------------------------------------
145 void BibGridwin::Resize()
147 if(m_xGridWin.is())
149 ::Size aSize = GetOutputSizePixel();
150 m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::SIZE);
154 //---------------------------------------------------------------------
155 void BibGridwin::createGridWin(const uno::Reference< awt::XControlModel > & xGModel)
157 m_xGridModel = xGModel;
159 if( m_xControlContainer.is())
161 uno::Reference< lang::XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
163 if ( m_xGridModel.is() && xMgr.is())
165 uno::Reference< XPropertySet > xPropSet( m_xGridModel, UNO_QUERY );
167 if ( xPropSet.is() && m_xGridModel.is() )
169 uno::Any aAny = xPropSet->getPropertyValue( C2U("DefaultControl") );
170 rtl::OUString aControlName;
171 aAny >>= aControlName;
173 m_xControl = Reference< awt::XControl > (xMgr->createInstance( aControlName ), UNO_QUERY );
174 DBG_ASSERT( m_xControl.is(), "no GridControl created" );
175 if ( m_xControl.is() )
176 m_xControl->setModel( m_xGridModel );
179 if ( m_xControl.is() )
181 // Peer als Child zu dem FrameWindow
182 m_xControlContainer->addControl(C2U("GridControl"), m_xControl);
183 m_xGridWin=uno::Reference< awt::XWindow > (m_xControl, UNO_QUERY );
184 // #100312# -----
185 m_xDispatchProviderInterception=uno::Reference< frame::XDispatchProviderInterception > (m_xControl, UNO_QUERY );
186 m_xGridWin->setVisible( sal_True );
187 m_xControl->setDesignMode( sal_True );
188 // initially switch on the desing mode - switch it off _after_ loading the form
189 // 17.10.2001 - 93107 - frank.schoenheit@sun.com
191 ::Size aSize = GetOutputSizePixel();
192 m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::POSSIZE);
198 //---------------------------------------------------------------------
199 void BibGridwin::disposeGridWin()
201 if ( m_xControl.is() )
203 Reference< awt::XControl > xDel( m_xControl );
204 m_xControl = NULL;
205 m_xGridWin = NULL;
207 m_xControlContainer->removeControl( xDel );
208 xDel->dispose();
212 //---------------------------------------------------------------------
213 void BibGridwin::GetFocus()
215 if(m_xGridWin.is())
216 m_xGridWin->setFocus();
219 //---------------------------------------------------------------------
220 BibBeamer::BibBeamer( Window* _pParent, BibDataManager* _pDM, WinBits _nStyle )
221 :BibSplitWindow( _pParent, _nStyle | WB_NOSPLITDRAW )
222 ,pDatMan( _pDM )
223 ,pToolBar( NULL )
224 ,pGridWin( NULL )
226 createToolBar();
227 createGridWin();
228 if ( pDatMan )
229 pDatMan->SetToolbar(pToolBar);
230 pGridWin->Show();
232 if ( pDatMan )
233 connectForm( pDatMan );
236 //---------------------------------------------------------------------
237 BibBeamer::~BibBeamer()
239 if ( isFormConnected() )
240 disconnectForm();
242 if ( m_xToolBarRef.is() )
243 m_xToolBarRef->dispose();
245 if ( pToolBar )
247 if ( pDatMan )
248 pDatMan->SetToolbar(0);
250 DELETEZ( pToolBar );
253 if( pGridWin )
255 BibGridwin* pDel = pGridWin;
256 pGridWin = NULL;
257 pDel->disposeGridWin();
258 delete pDel;
263 //---------------------------------------------------------------------
264 void BibBeamer::createToolBar()
266 pToolBar= new BibToolBar(this, LINK( this, BibBeamer, RecalcLayout_Impl ));
267 ::Size aSize=pToolBar->GetSizePixel();
268 InsertItem(ID_TOOLBAR, pToolBar, aSize.Height(), 0, 0, SWIB_FIXED );
269 if ( m_xController.is() )
270 pToolBar->SetXController( m_xController );
273 //---------------------------------------------------------------------
274 void BibBeamer::createGridWin()
276 pGridWin = new BibGridwin(this,0);
278 InsertItem(ID_GRIDWIN, pGridWin, 40, 1, 0, SWIB_RELATIVESIZE );
280 pGridWin->createGridWin( pDatMan->updateGridModel() );
283 //---------------------------------------------------------------------
284 Reference< awt::XControlContainer > BibBeamer::getControlContainer()
286 Reference< awt::XControlContainer > xReturn;
287 if ( pGridWin )
288 xReturn = pGridWin->getControlContainer();
289 return xReturn;
292 // #100312# -----------------------------------------------------------
293 Reference< frame::XDispatchProviderInterception > BibBeamer::getDispatchProviderInterception()
295 Reference< frame::XDispatchProviderInterception > xReturn;
296 if ( pGridWin )
297 xReturn = pGridWin->getDispatchProviderInterception();
298 return xReturn;
301 //---------------------------------------------------------------------
302 void BibBeamer::SetXController(const uno::Reference< frame::XController > & xCtr)
304 m_xController = xCtr;
306 if ( pToolBar )
307 pToolBar->SetXController( m_xController );
311 //---------------------------------------------------------------------
312 void BibBeamer::GetFocus()
314 if( pGridWin )
315 pGridWin->GrabFocus();
318 //---------------------------------------------------------------------
319 IMPL_LINK( BibBeamer, RecalcLayout_Impl, void*, /*pVoid*/ )
321 long nHeight = pToolBar->GetSizePixel().Height();
322 SetItemSize( ID_TOOLBAR, nHeight );
323 return 0L;
326 //.........................................................................
327 } // namespace bib
328 //.........................................................................