xref: /trunk/main/extensions/source/bibliography/bibbeam.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
12a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52a97ec55SAndrew Rist  * distributed with this work for additional information
62a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
82a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
92a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
142a97ec55SAndrew Rist  * software distributed under the License is distributed on an
152a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
172a97ec55SAndrew Rist  * specific language governing permissions and limitations
182a97ec55SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202a97ec55SAndrew Rist  *************************************************************/
212a97ec55SAndrew Rist 
222a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include <osl/mutex.hxx>
27cdf0e10cSrcweir #include <tools/urlobj.hxx>
28cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
29cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
30cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
31cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
32cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "bibliography.hrc"
35cdf0e10cSrcweir #include <vcl/lstbox.hxx>
36cdf0e10cSrcweir #include <vcl/edit.hxx>
37cdf0e10cSrcweir #include <tools/debug.hxx>
38cdf0e10cSrcweir #include "bibbeam.hxx"
39cdf0e10cSrcweir #include "toolbar.hrc"
40cdf0e10cSrcweir #include "bibresid.hxx"
41cdf0e10cSrcweir #include "datman.hxx"
42cdf0e10cSrcweir #ifndef BIBTOOLS_HXX
43cdf0e10cSrcweir #include "bibtools.hxx"
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using namespace rtl;
47cdf0e10cSrcweir using namespace ::com::sun::star;
48cdf0e10cSrcweir using namespace ::com::sun::star::beans;
49cdf0e10cSrcweir using namespace ::com::sun::star::uno;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar)
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #define PROPERTY_FRAME                      1
54cdf0e10cSrcweir #define ID_TOOLBAR                          1
55cdf0e10cSrcweir #define ID_GRIDWIN                          2
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //.........................................................................
58cdf0e10cSrcweir namespace bib
59cdf0e10cSrcweir {
60cdf0e10cSrcweir //.........................................................................
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
63cdf0e10cSrcweir 
HandleTaskPaneList(Window * pWindow,sal_Bool bAddToList)64cdf0e10cSrcweir     void HandleTaskPaneList( Window* pWindow, sal_Bool bAddToList )
65cdf0e10cSrcweir     {
66cdf0e10cSrcweir         Window*             pParent = pWindow->GetParent();
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         DBG_ASSERT( pParent, "-GetTaskPaneList(): everybody here should have a parent!" );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         SystemWindow*       pSysWin = pParent->GetSystemWindow();
71cdf0e10cSrcweir         if( pSysWin )
72cdf0e10cSrcweir         {
73cdf0e10cSrcweir             TaskPaneList*   pTaskPaneList = pSysWin->GetTaskPaneList();
74cdf0e10cSrcweir             if( pTaskPaneList )
75cdf0e10cSrcweir             {
76cdf0e10cSrcweir                 if( bAddToList )
77cdf0e10cSrcweir                     pTaskPaneList->AddWindow( pWindow );
78cdf0e10cSrcweir                 else
79cdf0e10cSrcweir                     pTaskPaneList->RemoveWindow( pWindow );
80cdf0e10cSrcweir             }
81cdf0e10cSrcweir         }
82cdf0e10cSrcweir     }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     //=====================================================================
85cdf0e10cSrcweir     //= BibGridwin
86cdf0e10cSrcweir     //=====================================================================
87cdf0e10cSrcweir     class BibGridwin
88cdf0e10cSrcweir                 :public Window //DockingWindow
89cdf0e10cSrcweir     {
90cdf0e10cSrcweir     private:
91cdf0e10cSrcweir             Reference< awt::XWindow >           m_xGridWin;
92cdf0e10cSrcweir             Reference< awt::XControlModel >     m_xGridModel;
93cdf0e10cSrcweir             Reference< awt::XControl >          m_xControl;
94cdf0e10cSrcweir             Reference< awt::XControlContainer > m_xControlContainer;
95cdf0e10cSrcweir             // #100312# ---------
96cdf0e10cSrcweir             Reference< frame::XDispatchProviderInterception> m_xDispatchProviderInterception;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     protected:
99cdf0e10cSrcweir 
100cdf0e10cSrcweir             virtual void        Resize();
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     public:
103cdf0e10cSrcweir 
104cdf0e10cSrcweir             BibGridwin(Window* pParent, WinBits nStyle = WB_3DLOOK );
105cdf0e10cSrcweir             ~BibGridwin();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             void createGridWin(const Reference< awt::XControlModel > & xDbForm);
108cdf0e10cSrcweir             void disposeGridWin();
109cdf0e10cSrcweir 
getControlContainer() const110cdf0e10cSrcweir             const Reference< awt::XControlContainer >& getControlContainer() const { return m_xControlContainer; }
111cdf0e10cSrcweir             // #100312# ---------
getDispatchProviderInterception() const112cdf0e10cSrcweir             const Reference< frame::XDispatchProviderInterception>& getDispatchProviderInterception() const { return m_xDispatchProviderInterception; }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir             virtual void GetFocus();
115cdf0e10cSrcweir     };
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     //---------------------------------------------------------------------
BibGridwin(Window * _pParent,WinBits _nStyle)118cdf0e10cSrcweir     BibGridwin::BibGridwin( Window* _pParent, WinBits _nStyle ) : Window( _pParent, _nStyle )
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         m_xControlContainer = VCLUnoHelper::CreateControlContainer(this);
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         AddToTaskPaneList( this );
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     //---------------------------------------------------------------------
~BibGridwin()126cdf0e10cSrcweir     BibGridwin::~BibGridwin()
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         RemoveFromTaskPaneList( this );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         disposeGridWin();
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     //---------------------------------------------------------------------
Resize()134cdf0e10cSrcweir     void BibGridwin::Resize()
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         if(m_xGridWin.is())
137cdf0e10cSrcweir         {
138cdf0e10cSrcweir             ::Size aSize = GetOutputSizePixel();
139cdf0e10cSrcweir             m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::SIZE);
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     //---------------------------------------------------------------------
createGridWin(const uno::Reference<awt::XControlModel> & xGModel)144cdf0e10cSrcweir     void BibGridwin::createGridWin(const uno::Reference< awt::XControlModel > & xGModel)
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         m_xGridModel = xGModel;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         if( m_xControlContainer.is())
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir             uno::Reference< lang::XMultiServiceFactory >  xMgr = comphelper::getProcessServiceFactory();
151cdf0e10cSrcweir 
152cdf0e10cSrcweir             if ( m_xGridModel.is() && xMgr.is())
153cdf0e10cSrcweir             {
154cdf0e10cSrcweir                 uno::Reference< XPropertySet >  xPropSet( m_xGridModel, UNO_QUERY );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir                 if ( xPropSet.is() && m_xGridModel.is() )
157cdf0e10cSrcweir                 {
158cdf0e10cSrcweir                     uno::Any aAny = xPropSet->getPropertyValue( C2U("DefaultControl") );
159cdf0e10cSrcweir                     rtl::OUString aControlName;
160cdf0e10cSrcweir                     aAny >>= aControlName;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir                     m_xControl = Reference< awt::XControl > (xMgr->createInstance( aControlName ), UNO_QUERY );
163cdf0e10cSrcweir                     DBG_ASSERT( m_xControl.is(), "no GridControl created" );
164cdf0e10cSrcweir                     if ( m_xControl.is() )
165cdf0e10cSrcweir                         m_xControl->setModel( m_xGridModel );
166cdf0e10cSrcweir                 }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir                 if ( m_xControl.is() )
169cdf0e10cSrcweir                 {
170cdf0e10cSrcweir                     // Peer als Child zu dem FrameWindow
171cdf0e10cSrcweir                     m_xControlContainer->addControl(C2U("GridControl"), m_xControl);
172cdf0e10cSrcweir                     m_xGridWin=uno::Reference< awt::XWindow > (m_xControl, UNO_QUERY );
173cdf0e10cSrcweir                     // #100312# -----
174cdf0e10cSrcweir                     m_xDispatchProviderInterception=uno::Reference< frame::XDispatchProviderInterception > (m_xControl, UNO_QUERY );
175cdf0e10cSrcweir                     m_xGridWin->setVisible( sal_True );
176cdf0e10cSrcweir                     m_xControl->setDesignMode( sal_True );
177*cfd52e18Smseidel                         // initially switch on the design mode - switch it off _after_ loading the form
178cdf0e10cSrcweir                         // 17.10.2001 - 93107 - frank.schoenheit@sun.com
179cdf0e10cSrcweir 
180cdf0e10cSrcweir                     ::Size aSize = GetOutputSizePixel();
181cdf0e10cSrcweir                     m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::POSSIZE);
182cdf0e10cSrcweir                 }
183cdf0e10cSrcweir             }
184cdf0e10cSrcweir         }
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     //---------------------------------------------------------------------
disposeGridWin()188cdf0e10cSrcweir     void BibGridwin::disposeGridWin()
189cdf0e10cSrcweir     {
190cdf0e10cSrcweir         if ( m_xControl.is() )
191cdf0e10cSrcweir         {
192cdf0e10cSrcweir             Reference< awt::XControl > xDel( m_xControl );
193cdf0e10cSrcweir             m_xControl = NULL;
194cdf0e10cSrcweir             m_xGridWin = NULL;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir             m_xControlContainer->removeControl( xDel );
197cdf0e10cSrcweir             xDel->dispose();
198cdf0e10cSrcweir         }
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     //---------------------------------------------------------------------
GetFocus()202cdf0e10cSrcweir     void BibGridwin::GetFocus()
203cdf0e10cSrcweir     {
204cdf0e10cSrcweir         if(m_xGridWin.is())
205cdf0e10cSrcweir             m_xGridWin->setFocus();
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     //---------------------------------------------------------------------
BibBeamer(Window * _pParent,BibDataManager * _pDM,WinBits _nStyle)209cdf0e10cSrcweir     BibBeamer::BibBeamer( Window* _pParent, BibDataManager* _pDM, WinBits _nStyle )
210cdf0e10cSrcweir         :BibSplitWindow( _pParent, _nStyle | WB_NOSPLITDRAW )
211cdf0e10cSrcweir         ,pDatMan( _pDM )
212cdf0e10cSrcweir         ,pToolBar( NULL )
213cdf0e10cSrcweir         ,pGridWin( NULL )
214cdf0e10cSrcweir     {
215cdf0e10cSrcweir         createToolBar();
216cdf0e10cSrcweir         createGridWin();
217cdf0e10cSrcweir         if ( pDatMan )
218cdf0e10cSrcweir             pDatMan->SetToolbar(pToolBar);
219cdf0e10cSrcweir         pGridWin->Show();
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         if ( pDatMan )
222cdf0e10cSrcweir             connectForm( pDatMan );
223cdf0e10cSrcweir     }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     //---------------------------------------------------------------------
~BibBeamer()226cdf0e10cSrcweir     BibBeamer::~BibBeamer()
227cdf0e10cSrcweir     {
228cdf0e10cSrcweir         if ( isFormConnected() )
229cdf0e10cSrcweir             disconnectForm();
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         if ( m_xToolBarRef.is() )
232cdf0e10cSrcweir             m_xToolBarRef->dispose();
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         if ( pToolBar )
235cdf0e10cSrcweir         {
236cdf0e10cSrcweir             if ( pDatMan )
237cdf0e10cSrcweir                 pDatMan->SetToolbar(0);
238cdf0e10cSrcweir 
239cdf0e10cSrcweir             DELETEZ( pToolBar );
240cdf0e10cSrcweir         }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir         if( pGridWin )
243cdf0e10cSrcweir         {
244cdf0e10cSrcweir             BibGridwin* pDel = pGridWin;
245cdf0e10cSrcweir             pGridWin = NULL;
246cdf0e10cSrcweir             pDel->disposeGridWin();
247cdf0e10cSrcweir             delete pDel;
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     //---------------------------------------------------------------------
createToolBar()253cdf0e10cSrcweir     void BibBeamer::createToolBar()
254cdf0e10cSrcweir     {
255cdf0e10cSrcweir         pToolBar= new BibToolBar(this, LINK( this, BibBeamer, RecalcLayout_Impl ));
256cdf0e10cSrcweir         ::Size aSize=pToolBar->GetSizePixel();
257cdf0e10cSrcweir         InsertItem(ID_TOOLBAR, pToolBar, aSize.Height(), 0, 0, SWIB_FIXED );
258cdf0e10cSrcweir         if ( m_xController.is() )
259cdf0e10cSrcweir             pToolBar->SetXController( m_xController );
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     //---------------------------------------------------------------------
createGridWin()263cdf0e10cSrcweir     void BibBeamer::createGridWin()
264cdf0e10cSrcweir     {
265cdf0e10cSrcweir         pGridWin = new BibGridwin(this,0);
266cdf0e10cSrcweir 
267cdf0e10cSrcweir         InsertItem(ID_GRIDWIN, pGridWin, 40, 1, 0, SWIB_RELATIVESIZE );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         pGridWin->createGridWin( pDatMan->updateGridModel() );
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     //---------------------------------------------------------------------
getControlContainer()273cdf0e10cSrcweir     Reference< awt::XControlContainer > BibBeamer::getControlContainer()
274cdf0e10cSrcweir     {
275cdf0e10cSrcweir         Reference< awt::XControlContainer > xReturn;
276cdf0e10cSrcweir         if ( pGridWin )
277cdf0e10cSrcweir             xReturn = pGridWin->getControlContainer();
278cdf0e10cSrcweir         return xReturn;
279cdf0e10cSrcweir     }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir     // #100312# -----------------------------------------------------------
getDispatchProviderInterception()282cdf0e10cSrcweir     Reference< frame::XDispatchProviderInterception > BibBeamer::getDispatchProviderInterception()
283cdf0e10cSrcweir     {
284cdf0e10cSrcweir         Reference< frame::XDispatchProviderInterception > xReturn;
285cdf0e10cSrcweir         if ( pGridWin )
286cdf0e10cSrcweir             xReturn = pGridWin->getDispatchProviderInterception();
287cdf0e10cSrcweir         return xReturn;
288cdf0e10cSrcweir     }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir     //---------------------------------------------------------------------
SetXController(const uno::Reference<frame::XController> & xCtr)291cdf0e10cSrcweir     void BibBeamer::SetXController(const uno::Reference< frame::XController > & xCtr)
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         m_xController = xCtr;
294cdf0e10cSrcweir 
295cdf0e10cSrcweir         if ( pToolBar )
296cdf0e10cSrcweir             pToolBar->SetXController( m_xController );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir     //---------------------------------------------------------------------
GetFocus()301cdf0e10cSrcweir     void BibBeamer::GetFocus()
302cdf0e10cSrcweir     {
303cdf0e10cSrcweir         if( pGridWin )
304cdf0e10cSrcweir             pGridWin->GrabFocus();
305cdf0e10cSrcweir     }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     //---------------------------------------------------------------------
308cdf0e10cSrcweir     IMPL_LINK( BibBeamer, RecalcLayout_Impl, void*, /*pVoid*/ )
309cdf0e10cSrcweir     {
310cdf0e10cSrcweir         long nHeight = pToolBar->GetSizePixel().Height();
311cdf0e10cSrcweir         SetItemSize( ID_TOOLBAR, nHeight );
312cdf0e10cSrcweir         return 0L;
313cdf0e10cSrcweir     }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir //.........................................................................
316cdf0e10cSrcweir }   // namespace bib
317cdf0e10cSrcweir //.........................................................................
318