1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <toolkit/helper/vclunohelper.hxx>
21 #include <comphelper/processfactory.hxx>
22 #include <com/sun/star/awt/PosSize.hpp>
23 #include <com/sun/star/util/XURLTransformer.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 
26 #include <vcl/edit.hxx>
27 #include <tools/debug.hxx>
28 #include "bibbeam.hxx"
29 #include "bibview.hxx"
30 #include "bibresid.hxx"
31 #include "datman.hxx"
32 #include "bibtools.hxx"
33 
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::uno;
37 
38 
39 #define ID_TOOLBAR                          1
40 #define ID_GRIDWIN                          2
41 
42 namespace bib
43 {
44 
HandleTaskPaneList(vcl::Window * pWindow,bool bAddToList)45     void HandleTaskPaneList( vcl::Window* pWindow, bool bAddToList )
46     {
47         vcl::Window*             pParent = pWindow->GetParent();
48 
49         DBG_ASSERT( pParent, "-GetTaskPaneList(): everybody here should have a parent!" );
50 
51         SystemWindow*       pSysWin = pParent->GetSystemWindow();
52         if( pSysWin )
53         {
54             TaskPaneList*   pTaskPaneList = pSysWin->GetTaskPaneList();
55             if( pTaskPaneList )
56             {
57                 if( bAddToList )
58                     pTaskPaneList->AddWindow( pWindow );
59                 else
60                     pTaskPaneList->RemoveWindow( pWindow );
61             }
62         }
63     }
64 
65 
66     class BibGridwin
67                 :public vcl::Window //DockingWindow
68     {
69     private:
70             Reference< awt::XWindow >           m_xGridWin;
71             Reference< awt::XControlModel >     m_xGridModel;
72             Reference< awt::XControl >          m_xControl;
73             Reference< awt::XControlContainer > m_xControlContainer;
74             Reference< frame::XDispatchProviderInterception> m_xDispatchProviderInterception;
75 
76     protected:
77 
78             virtual void        Resize() override;
79 
80     public:
81 
82             BibGridwin(vcl::Window* pParent, WinBits nStyle );
83             virtual ~BibGridwin() override;
84             virtual void dispose() override;
85 
86             void createGridWin(const Reference< awt::XControlModel > & xDbForm);
87             void disposeGridWin();
88 
getControlContainer() const89             const Reference< awt::XControlContainer >& getControlContainer() const { return m_xControlContainer; }
getDispatchProviderInterception() const90             const Reference< frame::XDispatchProviderInterception>& getDispatchProviderInterception() const { return m_xDispatchProviderInterception; }
91 
92             virtual void GetFocus() override;
93     };
94 
BibGridwin(vcl::Window * _pParent,WinBits _nStyle)95     BibGridwin::BibGridwin( vcl::Window* _pParent, WinBits _nStyle ) : Window( _pParent, _nStyle )
96     {
97         m_xControlContainer = VCLUnoHelper::CreateControlContainer(this);
98 
99         AddToTaskPaneList( this );
100     }
101 
~BibGridwin()102     BibGridwin::~BibGridwin()
103     {
104         disposeOnce();
105     }
106 
dispose()107     void BibGridwin::dispose()
108     {
109         RemoveFromTaskPaneList( this );
110 
111         disposeGridWin();
112         vcl::Window::dispose();
113     }
114 
Resize()115     void BibGridwin::Resize()
116     {
117         if(m_xGridWin.is())
118         {
119             ::Size aSize = GetOutputSizePixel();
120             m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::SIZE);
121         }
122     }
123 
createGridWin(const uno::Reference<awt::XControlModel> & xGModel)124     void BibGridwin::createGridWin(const uno::Reference< awt::XControlModel > & xGModel)
125     {
126         m_xGridModel = xGModel;
127 
128         if( m_xControlContainer.is())
129         {
130             uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
131 
132             if ( m_xGridModel.is())
133             {
134                 uno::Reference< XPropertySet >  xPropSet( m_xGridModel, UNO_QUERY );
135 
136                 if ( xPropSet.is() && m_xGridModel.is() )
137                 {
138                     uno::Any aAny = xPropSet->getPropertyValue( "DefaultControl" );
139                     OUString aControlName;
140                     aAny >>= aControlName;
141 
142                     m_xControl.set( xContext->getServiceManager()->createInstanceWithContext(aControlName, xContext), UNO_QUERY_THROW );
143                     m_xControl->setModel( m_xGridModel );
144                 }
145 
146                 if ( m_xControl.is() )
147                 {
148                     // Peer as Child to the FrameWindow
149                     m_xControlContainer->addControl("GridControl", m_xControl);
150                     m_xGridWin.set(m_xControl, UNO_QUERY );
151                     m_xDispatchProviderInterception.set(m_xControl, UNO_QUERY );
152                     m_xGridWin->setVisible( true );
153                     m_xControl->setDesignMode( true );
154                     // initially switch on the design mode - switch it off _after_ loading the form
155 
156                     ::Size aSize = GetOutputSizePixel();
157                     m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::POSSIZE);
158                 }
159             }
160         }
161     }
162 
disposeGridWin()163     void BibGridwin::disposeGridWin()
164     {
165         if ( m_xControl.is() )
166         {
167             Reference< awt::XControl > xDel( m_xControl );
168             m_xControl = nullptr;
169             m_xGridWin = nullptr;
170 
171             m_xControlContainer->removeControl( xDel );
172             xDel->dispose();
173         }
174     }
175 
GetFocus()176     void BibGridwin::GetFocus()
177     {
178         if(m_xGridWin.is())
179             m_xGridWin->setFocus();
180     }
181 
BibBeamer(vcl::Window * _pParent,BibDataManager * _pDM)182     BibBeamer::BibBeamer( vcl::Window* _pParent, BibDataManager* _pDM )
183         :BibSplitWindow( _pParent, WB_3DLOOK | WB_NOSPLITDRAW )
184         ,pDatMan( _pDM )
185         ,pToolBar( nullptr )
186         ,pGridWin( nullptr )
187     {
188         createToolBar();
189         createGridWin();
190         pDatMan->SetToolbar(pToolBar);
191         pGridWin->Show();
192         connectForm( pDatMan );
193     }
194 
~BibBeamer()195     BibBeamer::~BibBeamer()
196     {
197         disposeOnce();
198     }
199 
dispose()200     void BibBeamer::dispose()
201     {
202         if ( isFormConnected() )
203             disconnectForm();
204 
205         if ( pToolBar )
206             pDatMan->SetToolbar(nullptr);
207 
208         pToolBar.disposeAndClear();
209         pGridWin.disposeAndClear();
210         BibSplitWindow::dispose();
211     }
212 
createToolBar()213     void BibBeamer::createToolBar()
214     {
215         pToolBar= VclPtr<BibToolBar>::Create(this, LINK( this, BibBeamer, RecalcLayout_Impl ));
216         ::Size aSize=pToolBar->get_preferred_size();
217         InsertItem(ID_TOOLBAR, pToolBar, aSize.Height(), 0, 0, SplitWindowItemFlags::Fixed );
218         if ( m_xController.is() )
219             pToolBar->SetXController( m_xController );
220     }
221 
createGridWin()222     void BibBeamer::createGridWin()
223     {
224         pGridWin = VclPtr<BibGridwin>::Create(this,0);
225 
226         InsertItem(ID_GRIDWIN, pGridWin, 40, 1, 0, SplitWindowItemFlags::RelativeSize );
227 
228         pGridWin->createGridWin( pDatMan->updateGridModel() );
229     }
230 
getControlContainer()231     Reference< awt::XControlContainer > BibBeamer::getControlContainer()
232     {
233         Reference< awt::XControlContainer > xReturn;
234         if ( pGridWin )
235             xReturn = pGridWin->getControlContainer();
236         return xReturn;
237     }
238 
getDispatchProviderInterception() const239     Reference< frame::XDispatchProviderInterception > BibBeamer::getDispatchProviderInterception() const
240     {
241         Reference< frame::XDispatchProviderInterception > xReturn;
242         if ( pGridWin )
243             xReturn = pGridWin->getDispatchProviderInterception();
244         return xReturn;
245     }
246 
SetXController(const uno::Reference<frame::XController> & xCtr)247     void BibBeamer::SetXController(const uno::Reference< frame::XController > & xCtr)
248     {
249         m_xController = xCtr;
250 
251         if ( pToolBar )
252             pToolBar->SetXController( m_xController );
253 
254     }
255 
GetFocus()256     void BibBeamer::GetFocus()
257     {
258         if( pGridWin )
259             pGridWin->GrabFocus();
260     }
261 
IMPL_LINK_NOARG(BibBeamer,RecalcLayout_Impl,void *,void)262     IMPL_LINK_NOARG( BibBeamer, RecalcLayout_Impl, void*, void )
263     {
264         long nHeight = pToolBar->get_preferred_size().Height();
265         SetItemSize( ID_TOOLBAR, nHeight );
266     }
267 
268 }   // namespace bib
269 
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
271