tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / extensions / source / bibliography / bibbeam.cxx
blobe6694f5579104675817dc1596f31abb5821ff2ef
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 <toolkit/helper/vclunohelper.hxx>
21 #include <comphelper/processfactory.hxx>
22 #include <com/sun/star/awt/PosSize.hpp>
23 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <vcl/taskpanelist.hxx>
26 #include <tools/debug.hxx>
27 #include "bibbeam.hxx"
28 #include "datman.hxx"
29 #include "bibtools.hxx"
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::beans;
33 using namespace ::com::sun::star::uno;
36 #define ID_TOOLBAR 1
37 #define ID_GRIDWIN 2
39 namespace bib
42 void HandleTaskPaneList( vcl::Window* pWindow, bool bAddToList )
44 vcl::Window* pParent = pWindow->GetParent();
46 assert(pParent && "-GetTaskPaneList(): everybody here should have a parent!");
48 SystemWindow* pSysWin = pParent->GetSystemWindow();
49 if( pSysWin )
51 TaskPaneList* pTaskPaneList = pSysWin->GetTaskPaneList();
52 if( pTaskPaneList )
54 if( bAddToList )
55 pTaskPaneList->AddWindow( pWindow );
56 else
57 pTaskPaneList->RemoveWindow( pWindow );
63 class BibGridwin
64 :public vcl::Window //DockingWindow
66 private:
67 Reference< awt::XWindow > m_xGridWin;
68 Reference< awt::XControlModel > m_xGridModel;
69 Reference< awt::XControl > m_xControl;
70 Reference< awt::XControlContainer > m_xControlContainer;
71 Reference< frame::XDispatchProviderInterception> m_xDispatchProviderInterception;
73 protected:
75 virtual void Resize() override;
77 public:
79 BibGridwin(vcl::Window* pParent, WinBits nStyle );
80 virtual ~BibGridwin() override;
81 virtual void dispose() override;
83 void createGridWin(const Reference< awt::XControlModel > & xDbForm);
84 void disposeGridWin();
86 const Reference< awt::XControlContainer >& getControlContainer() const { return m_xControlContainer; }
87 const Reference< frame::XDispatchProviderInterception>& getDispatchProviderInterception() const { return m_xDispatchProviderInterception; }
89 virtual void GetFocus() override;
92 BibGridwin::BibGridwin( vcl::Window* _pParent, WinBits _nStyle ) : Window( _pParent, _nStyle )
94 m_xControlContainer = VCLUnoHelper::CreateControlContainer(this);
96 AddToTaskPaneList( this );
99 BibGridwin::~BibGridwin()
101 disposeOnce();
104 void BibGridwin::dispose()
106 RemoveFromTaskPaneList( this );
108 disposeGridWin();
109 vcl::Window::dispose();
112 void BibGridwin::Resize()
114 if(m_xGridWin.is())
116 ::Size aSize = GetOutputSizePixel();
117 m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::SIZE);
121 void BibGridwin::createGridWin(const uno::Reference< awt::XControlModel > & xGModel)
123 m_xGridModel = xGModel;
125 if( !m_xControlContainer.is())
126 return;
128 const uno::Reference< uno::XComponentContext >& xContext = comphelper::getProcessComponentContext();
130 if ( !m_xGridModel.is())
131 return;
133 uno::Reference< XPropertySet > xPropSet( m_xGridModel, UNO_QUERY );
135 if ( xPropSet.is() && m_xGridModel.is() )
137 uno::Any aAny = xPropSet->getPropertyValue( u"DefaultControl"_ustr );
138 OUString aControlName;
139 aAny >>= aControlName;
141 m_xControl.set( xContext->getServiceManager()->createInstanceWithContext(aControlName, xContext), UNO_QUERY_THROW );
142 m_xControl->setModel( m_xGridModel );
145 if ( !m_xControl.is() )
146 return;
148 // Peer as Child to the FrameWindow
149 m_xControlContainer->addControl(u"GridControl"_ustr, 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
156 ::Size aSize = GetOutputSizePixel();
157 m_xGridWin->setPosSize(0, 0, aSize.Width(),aSize.Height(), awt::PosSize::POSSIZE);
160 void BibGridwin::disposeGridWin()
162 if ( m_xControl.is() )
164 Reference< awt::XControl > xDel( m_xControl );
165 m_xControl = nullptr;
166 m_xGridWin = nullptr;
168 m_xControlContainer->removeControl( xDel );
169 xDel->dispose();
173 void BibGridwin::GetFocus()
175 if(m_xGridWin.is())
176 m_xGridWin->setFocus();
179 BibBeamer::BibBeamer( vcl::Window* _pParent, BibDataManager* _pDM )
180 :BibSplitWindow( _pParent, WB_3DLOOK | WB_NOSPLITDRAW )
181 ,pDatMan( _pDM )
182 ,pToolBar( nullptr )
183 ,pGridWin( nullptr )
185 createToolBar();
186 createGridWin();
187 pDatMan->SetToolbar(pToolBar);
188 pGridWin->Show();
189 connectForm( pDatMan );
192 BibBeamer::~BibBeamer()
194 disposeOnce();
197 void BibBeamer::dispose()
199 if ( isFormConnected() )
200 disconnectForm();
202 if ( pToolBar )
203 pDatMan->SetToolbar(nullptr);
205 pToolBar.disposeAndClear();
206 pGridWin.disposeAndClear();
207 BibSplitWindow::dispose();
210 void BibBeamer::createToolBar()
212 pToolBar= VclPtr<BibToolBar>::Create(this, LINK( this, BibBeamer, RecalcLayout_Impl ));
213 ::Size aSize=pToolBar->get_preferred_size();
214 InsertItem(ID_TOOLBAR, pToolBar, aSize.Height(), 0, 0, SplitWindowItemFlags::Fixed );
215 if ( m_xController.is() )
216 pToolBar->SetXController( m_xController );
219 void BibBeamer::createGridWin()
221 pGridWin = VclPtr<BibGridwin>::Create(this,0);
223 InsertItem(ID_GRIDWIN, pGridWin, 40, 1, 0, SplitWindowItemFlags::RelativeSize );
225 pGridWin->createGridWin( pDatMan->updateGridModel() );
228 Reference< awt::XControlContainer > BibBeamer::getControlContainer()
230 Reference< awt::XControlContainer > xReturn;
231 if ( pGridWin )
232 xReturn = pGridWin->getControlContainer();
233 return xReturn;
236 Reference< frame::XDispatchProviderInterception > BibBeamer::getDispatchProviderInterception() const
238 Reference< frame::XDispatchProviderInterception > xReturn;
239 if ( pGridWin )
240 xReturn = pGridWin->getDispatchProviderInterception();
241 return xReturn;
244 void BibBeamer::SetXController(const uno::Reference< frame::XController > & xCtr)
246 m_xController = xCtr;
248 if ( pToolBar )
249 pToolBar->SetXController( m_xController );
253 void BibBeamer::GetFocus()
255 if( pGridWin )
256 pGridWin->GrabFocus();
259 IMPL_LINK_NOARG( BibBeamer, RecalcLayout_Impl, void*, void )
261 tools::Long nHeight = pToolBar->get_preferred_size().Height();
262 SetItemSize( ID_TOOLBAR, nHeight );
265 } // namespace bib
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */