sd: keep a non-owning pointer to the OverridingShell
[LibreOffice.git] / svx / source / form / fmexpl.cxx
blob4394201511d09dbdf2cebc6d29a713e71cca1060
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 .
21 #include <svx/strings.hrc>
22 #include <fmexpl.hxx>
24 #include <helpids.h>
25 #include <svx/svdobjkind.hxx>
26 #include <svx/fmtools.hxx>
27 #include <fmexch.hxx>
29 #include <svx/svxids.hrc>
31 #include <fmprop.hxx>
32 #include <bitmaps.hlst>
33 #include <svx/dialmgr.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <sfx2/objitem.hxx>
38 #include <svx/fmshell.hxx>
39 #include <comphelper/types.hxx>
40 #include <utility>
42 using namespace ::svxform;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::form;
45 using namespace ::com::sun::star::beans;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::container;
49 FmNavInsertedHint::FmNavInsertedHint( FmEntryData* pInsertedEntryData, sal_uInt32 nRelPos )
50 :SfxHint(SfxHintId::FmNavInserted)
51 ,pEntryData( pInsertedEntryData )
52 ,nPos( nRelPos )
58 FmNavInsertedHint::~FmNavInsertedHint()
64 FmNavModelReplacedHint::FmNavModelReplacedHint( FmEntryData* pAffectedEntryData )
65 :SfxHint(SfxHintId::FmNavModelReplaced), pEntryData( pAffectedEntryData )
70 FmNavModelReplacedHint::~FmNavModelReplacedHint()
74 FmNavRemovedHint::FmNavRemovedHint( FmEntryData* pRemovedEntryData )
75 :SfxHint(SfxHintId::FmNavRemoved), pEntryData( pRemovedEntryData )
80 FmNavRemovedHint::~FmNavRemovedHint()
84 FmNavNameChangedHint::FmNavNameChangedHint( FmEntryData* pData, OUString _aNewName )
85 :SfxHint(SfxHintId::FmNavNameChanged), pEntryData( pData )
86 ,aNewName(std::move( _aNewName ))
91 FmNavNameChangedHint::~FmNavNameChangedHint()
95 FmNavClearedHint::FmNavClearedHint() : SfxHint(SfxHintId::FmNavCleared)
100 FmNavClearedHint::~FmNavClearedHint()
105 FmEntryDataList::FmEntryDataList()
110 FmEntryDataList::~FmEntryDataList()
115 void FmEntryDataList::removeNoDelete( FmEntryData* pItem )
117 auto it = std::find_if(maEntryDataList.begin(), maEntryDataList.end(),
118 [&pItem](const std::unique_ptr<FmEntryData>& rEntryData) { return rEntryData.get() == pItem; });
119 if (it != maEntryDataList.end())
121 // coverity[leaked_storage] - deliberately not deleted, ownership transferred
122 it->release();
123 maEntryDataList.erase( it );
124 return;
126 assert(false);
130 void FmEntryDataList::insert( std::unique_ptr<FmEntryData> pItem, size_t Index )
132 if ( Index < maEntryDataList.size() )
134 maEntryDataList.insert( maEntryDataList.begin() + Index, std::move(pItem) );
136 else
137 maEntryDataList.push_back( std::move(pItem) );
141 void FmEntryDataList::clear()
143 maEntryDataList.clear();
147 FmEntryData::FmEntryData( FmEntryData* pParentData, const Reference< XInterface >& _rxIFace )
148 :pParent( pParentData )
150 pChildList.reset( new FmEntryDataList() );
152 newObject( _rxIFace );
156 FmEntryData::~FmEntryData()
158 pChildList->clear();
162 void FmEntryData::newObject( const css::uno::Reference< css::uno::XInterface >& _rxIFace )
164 // do not just copy, normalize it
165 m_xNormalizedIFace.set( _rxIFace, UNO_QUERY );
166 m_xProperties.set(m_xNormalizedIFace, css::uno::UNO_QUERY);
167 m_xChild.set(m_xNormalizedIFace, css::uno::UNO_QUERY);
174 bool FmEntryData::IsEqualWithoutChildren( FmEntryData* pEntryData )
176 if(this == pEntryData)
177 return true;
179 if( !pEntryData )
180 return false;
182 if( aText != pEntryData->GetText() )
183 return false;
185 if( !pEntryData->GetParent() && pParent )
186 return false;
188 if( pEntryData->GetParent() && !pParent )
189 return false;
191 if( !pEntryData->GetParent() && !pParent )
192 return true;
194 if( !pParent->IsEqualWithoutChildren(pEntryData->GetParent()) )
195 return false;
197 return true;
200 FmFormData::FmFormData(const Reference< XForm >& _rxForm, FmFormData* _pParent)
201 : FmEntryData(_pParent, _rxForm)
202 , m_xForm(_rxForm)
204 // set images
205 m_aNormalImage = RID_SVXBMP_FORM;
207 // set title
208 if (m_xForm.is())
210 Reference< XPropertySet > xSet(m_xForm, UNO_QUERY);
211 if (xSet.is())
213 OUString aEntryName(::comphelper::getString(xSet->getPropertyValue( FM_PROP_NAME )));
214 SetText(aEntryName);
217 else
218 SetText( OUString() );
221 FmFormData::~FmFormData()
225 bool FmFormData::IsEqualWithoutChildren( FmEntryData* pEntryData )
227 if(this == pEntryData)
228 return true;
229 FmFormData* pFormData = dynamic_cast<FmFormData*>(pEntryData);
230 if( !pFormData )
231 return false;
232 if( m_xForm.get() != pFormData->GetFormIface().get() )
233 return false;
235 return FmEntryData::IsEqualWithoutChildren( pFormData );
238 FmControlData::FmControlData(const Reference< XFormComponent >& _rxComponent, FmFormData* _pParent)
239 : FmEntryData( _pParent, _rxComponent ),
240 m_xFormComponent( _rxComponent )
243 // set images
244 m_aNormalImage = GetImage();
247 // set title
248 Reference< XPropertySet > xSet(m_xFormComponent, UNO_QUERY);
249 if( xSet.is() )
251 SetText( ::comphelper::getString(xSet->getPropertyValue( FM_PROP_NAME )));
256 FmControlData::~FmControlData()
261 OUString FmControlData::GetImage() const
263 // Default-Image
264 OUString aImage(RID_SVXBMP_CONTROL);
266 Reference< XServiceInfo > xInfo( m_xFormComponent, UNO_QUERY );
267 if (!m_xFormComponent.is())
268 return aImage;
271 // Spezielle Control-Images
272 SdrObjKind nObjectType = getControlTypeByObject(xInfo);
273 switch (nObjectType)
275 case SdrObjKind::FormButton:
276 aImage = RID_SVXBMP_BUTTON;
277 break;
279 case SdrObjKind::FormFixedText:
280 aImage = RID_SVXBMP_FIXEDTEXT;
281 break;
283 case SdrObjKind::FormEdit:
284 aImage = RID_SVXBMP_EDITBOX;
285 break;
287 case SdrObjKind::FormRadioButton:
288 aImage = RID_SVXBMP_RADIOBUTTON;
289 break;
291 case SdrObjKind::FormCheckbox:
292 aImage = RID_SVXBMP_CHECKBOX;
293 break;
295 case SdrObjKind::FormListbox:
296 aImage = RID_SVXBMP_LISTBOX;
297 break;
299 case SdrObjKind::FormCombobox:
300 aImage = RID_SVXBMP_COMBOBOX;
301 break;
303 case SdrObjKind::FormNavigationBar:
304 aImage = RID_SVXBMP_NAVIGATIONBAR;
305 break;
307 case SdrObjKind::FormGroupBox:
308 aImage = RID_SVXBMP_GROUPBOX;
309 break;
311 case SdrObjKind::FormImageButton:
312 aImage = RID_SVXBMP_IMAGEBUTTON;
313 break;
315 case SdrObjKind::FormFileControl:
316 aImage = RID_SVXBMP_FILECONTROL;
317 break;
319 case SdrObjKind::FormHidden:
320 aImage = RID_SVXBMP_HIDDEN;
321 break;
323 case SdrObjKind::FormDateField:
324 aImage = RID_SVXBMP_DATEFIELD;
325 break;
327 case SdrObjKind::FormTimeField:
328 aImage = RID_SVXBMP_TIMEFIELD;
329 break;
331 case SdrObjKind::FormNumericField:
332 aImage = RID_SVXBMP_NUMERICFIELD;
333 break;
335 case SdrObjKind::FormCurrencyField:
336 aImage = RID_SVXBMP_CURRENCYFIELD;
337 break;
339 case SdrObjKind::FormPatternField:
340 aImage = RID_SVXBMP_PATTERNFIELD;
341 break;
343 case SdrObjKind::FormImageControl:
344 aImage = RID_SVXBMP_IMAGECONTROL;
345 break;
347 case SdrObjKind::FormFormattedField:
348 aImage = RID_SVXBMP_FORMATTEDFIELD;
349 break;
351 case SdrObjKind::FormGrid:
352 aImage = RID_SVXBMP_GRID;
353 break;
355 case SdrObjKind::FormScrollbar:
356 aImage = RID_SVXBMP_SCROLLBAR;
357 break;
359 case SdrObjKind::FormSpinButton:
360 aImage = RID_SVXBMP_SPINBUTTON;
361 break;
363 default:;
366 return aImage;
369 bool FmControlData::IsEqualWithoutChildren( FmEntryData* pEntryData )
371 if(this == pEntryData)
372 return true;
374 FmControlData* pControlData = dynamic_cast<FmControlData*>(pEntryData);
375 if( !pControlData )
376 return false;
378 if( m_xFormComponent.get() != pControlData->GetFormComponent().get() )
379 return false;
381 return FmEntryData::IsEqualWithoutChildren( pControlData );
384 void FmControlData::ModelReplaced(const Reference< XFormComponent >& _rxNew)
386 m_xFormComponent = _rxNew;
387 newObject( m_xFormComponent );
388 // set images anew
389 m_aNormalImage = GetImage();
392 namespace svxform
395 NavigatorFrame::NavigatorFrame( SfxBindings* _pBindings, SfxChildWindow* _pMgr,
396 vcl::Window* _pParent )
397 : SfxDockingWindow(_pBindings, _pMgr, _pParent, u"FormNavigator"_ustr, u"svx/ui/formnavigator.ui"_ustr)
398 , SfxControllerItem( SID_FM_FMEXPLORER_CONTROL, *_pBindings )
399 , m_xNavigatorTree(new NavigatorTree(m_xBuilder->weld_tree_view(u"treeview"_ustr)))
401 SetHelpId( HID_FORM_NAVIGATOR_WIN );
403 SetText( SvxResId(RID_STR_FMEXPLORER) );
404 SfxDockingWindow::SetFloatingSize( Size(200,200) );
407 NavigatorFrame::~NavigatorFrame()
409 disposeOnce();
412 void NavigatorFrame::dispose()
414 m_xNavigatorTree.reset();
415 ::SfxControllerItem::dispose();
416 SfxDockingWindow::dispose();
419 void NavigatorFrame::UpdateContent( FmFormShell* pFormShell )
421 m_xNavigatorTree->UpdateContent(pFormShell);
424 void NavigatorFrame::StateChangedAtToolBoxControl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
426 if( !pState || SID_FM_FMEXPLORER_CONTROL != nSID )
427 return;
429 if( eState >= SfxItemState::DEFAULT )
431 FmFormShell* pShell = dynamic_cast<FmFormShell*>( static_cast<const SfxObjectItem*>(pState)->GetShell() );
432 UpdateContent( pShell );
434 else
435 UpdateContent( nullptr );
438 void NavigatorFrame::GetFocus()
440 if (m_xNavigatorTree )
441 m_xNavigatorTree->GrabFocus();
442 else
443 SfxDockingWindow::GetFocus();
446 bool NavigatorFrame::Close()
448 UpdateContent( nullptr );
449 return SfxDockingWindow::Close();
452 void NavigatorFrame::FillInfo( SfxChildWinInfo& rInfo ) const
454 SfxDockingWindow::FillInfo( rInfo );
455 rInfo.bVisible = false;
458 Size NavigatorFrame::CalcDockingSize( SfxChildAlignment eAlign )
460 if ( ( eAlign == SfxChildAlignment::TOP ) || ( eAlign == SfxChildAlignment::BOTTOM ) )
461 return Size();
463 return SfxDockingWindow::CalcDockingSize( eAlign );
466 SfxChildAlignment NavigatorFrame::CheckAlignment( SfxChildAlignment _eActAlign, SfxChildAlignment _eAlign )
468 if ( ( _eAlign == SfxChildAlignment::LEFT ) || ( _eAlign == SfxChildAlignment::RIGHT ) || ( _eAlign == SfxChildAlignment::NOALIGNMENT ) )
469 return _eAlign;
470 return _eActAlign;
473 SFX_IMPL_DOCKINGWINDOW( NavigatorFrameManager, SID_FM_SHOW_FMEXPLORER )
475 NavigatorFrameManager::NavigatorFrameManager( vcl::Window* _pParent, sal_uInt16 _nId,
476 SfxBindings* _pBindings, SfxChildWinInfo* _pInfo )
477 :SfxChildWindow( _pParent, _nId )
479 SetWindow( VclPtr<NavigatorFrame>::Create( _pBindings, this, _pParent ) );
480 static_cast<SfxDockingWindow*>(GetWindow())->Initialize( _pInfo );
484 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */