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