Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / form / fmexpl.cxx
blob53827917d9ea44cfe215b759f19bbe6db512d5bd
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 :pEntryData( pInsertedEntryData )
51 ,nPos( nRelPos )
57 FmNavInsertedHint::~FmNavInsertedHint()
63 FmNavModelReplacedHint::FmNavModelReplacedHint( FmEntryData* pAffectedEntryData )
64 :pEntryData( pAffectedEntryData )
69 FmNavModelReplacedHint::~FmNavModelReplacedHint()
73 FmNavRemovedHint::FmNavRemovedHint( FmEntryData* pRemovedEntryData )
74 :pEntryData( pRemovedEntryData )
79 FmNavRemovedHint::~FmNavRemovedHint()
83 FmNavNameChangedHint::FmNavNameChangedHint( FmEntryData* pData, OUString _aNewName )
84 :pEntryData( pData )
85 ,aNewName(std::move( _aNewName ))
90 FmNavNameChangedHint::~FmNavNameChangedHint()
94 FmNavClearedHint::FmNavClearedHint()
99 FmNavClearedHint::~FmNavClearedHint()
104 FmEntryDataList::FmEntryDataList()
109 FmEntryDataList::~FmEntryDataList()
114 void FmEntryDataList::removeNoDelete( FmEntryData* pItem )
116 auto it = std::find_if(maEntryDataList.begin(), maEntryDataList.end(),
117 [&pItem](const std::unique_ptr<FmEntryData>& rEntryData) { return rEntryData.get() == pItem; });
118 if (it != maEntryDataList.end())
120 // coverity[leaked_storage] - deliberately not deleted, ownership transferred
121 it->release();
122 maEntryDataList.erase( it );
123 return;
125 assert(false);
129 void FmEntryDataList::insert( std::unique_ptr<FmEntryData> pItem, size_t Index )
131 if ( Index < maEntryDataList.size() )
133 maEntryDataList.insert( maEntryDataList.begin() + Index, std::move(pItem) );
135 else
136 maEntryDataList.push_back( std::move(pItem) );
140 void FmEntryDataList::clear()
142 maEntryDataList.clear();
146 FmEntryData::FmEntryData( FmEntryData* pParentData, const Reference< XInterface >& _rxIFace )
147 :pParent( pParentData )
149 pChildList.reset( new FmEntryDataList() );
151 newObject( _rxIFace );
155 FmEntryData::~FmEntryData()
157 pChildList->clear();
161 void FmEntryData::newObject( const css::uno::Reference< css::uno::XInterface >& _rxIFace )
163 // do not just copy, normalize it
164 m_xNormalizedIFace.set( _rxIFace, UNO_QUERY );
165 m_xProperties.set(m_xNormalizedIFace, css::uno::UNO_QUERY);
166 m_xChild.set(m_xNormalizedIFace, css::uno::UNO_QUERY);
170 FmEntryData::FmEntryData( const FmEntryData& rEntryData )
172 pChildList.reset( new FmEntryDataList() );
173 aText = rEntryData.GetText();
174 m_aNormalImage = rEntryData.GetNormalImage();
175 pParent = rEntryData.GetParent();
177 FmEntryData* pChildData;
178 size_t nEntryCount = rEntryData.GetChildList()->size();
179 for( size_t i = 0; i < nEntryCount; i++ )
181 pChildData = rEntryData.GetChildList()->at( i );
182 std::unique_ptr<FmEntryData> pNewChildData = pChildData->Clone();
183 pChildList->insert( std::move(pNewChildData), size_t(-1) );
186 m_xNormalizedIFace = rEntryData.m_xNormalizedIFace;
187 m_xProperties = rEntryData.m_xProperties;
188 m_xChild = rEntryData.m_xChild;
193 bool FmEntryData::IsEqualWithoutChildren( FmEntryData* pEntryData )
195 if(this == pEntryData)
196 return true;
198 if( !pEntryData )
199 return false;
201 if( aText != pEntryData->GetText() )
202 return false;
204 if( !pEntryData->GetParent() && pParent )
205 return false;
207 if( pEntryData->GetParent() && !pParent )
208 return false;
210 if( !pEntryData->GetParent() && !pParent )
211 return true;
213 if( !pParent->IsEqualWithoutChildren(pEntryData->GetParent()) )
214 return false;
216 return true;
219 FmFormData::FmFormData(const Reference< XForm >& _rxForm, FmFormData* _pParent)
220 : FmEntryData(_pParent, _rxForm)
221 , m_xForm(_rxForm)
223 // set images
224 m_aNormalImage = RID_SVXBMP_FORM;
226 // set title
227 if (m_xForm.is())
229 Reference< XPropertySet > xSet(m_xForm, UNO_QUERY);
230 if (xSet.is())
232 OUString aEntryName(::comphelper::getString(xSet->getPropertyValue( FM_PROP_NAME )));
233 SetText(aEntryName);
236 else
237 SetText( OUString() );
240 FmFormData::~FmFormData()
244 FmFormData::FmFormData( const FmFormData& rFormData )
245 :FmEntryData( rFormData )
247 m_xForm = rFormData.GetFormIface();
251 std::unique_ptr<FmEntryData> FmFormData::Clone()
253 return std::unique_ptr<FmEntryData>(new FmFormData( *this ));
257 bool FmFormData::IsEqualWithoutChildren( FmEntryData* pEntryData )
259 if(this == pEntryData)
260 return true;
261 FmFormData* pFormData = dynamic_cast<FmFormData*>(pEntryData);
262 if( !pFormData )
263 return false;
264 if( m_xForm.get() != pFormData->GetFormIface().get() )
265 return false;
267 return FmEntryData::IsEqualWithoutChildren( pFormData );
270 FmControlData::FmControlData(const Reference< XFormComponent >& _rxComponent, FmFormData* _pParent)
271 : FmEntryData( _pParent, _rxComponent ),
272 m_xFormComponent( _rxComponent )
275 // set images
276 m_aNormalImage = GetImage();
279 // set title
280 Reference< XPropertySet > xSet(m_xFormComponent, UNO_QUERY);
281 if( xSet.is() )
283 SetText( ::comphelper::getString(xSet->getPropertyValue( FM_PROP_NAME )));
288 FmControlData::~FmControlData()
293 FmControlData::FmControlData( const FmControlData& rControlData )
294 :FmEntryData( rControlData )
296 m_xFormComponent = rControlData.GetFormComponent();
300 std::unique_ptr<FmEntryData> FmControlData::Clone()
302 return std::unique_ptr<FmEntryData>(new FmControlData( *this ));
306 OUString FmControlData::GetImage() const
308 // Default-Image
309 OUString aImage(RID_SVXBMP_CONTROL);
311 Reference< XServiceInfo > xInfo( m_xFormComponent, UNO_QUERY );
312 if (!m_xFormComponent.is())
313 return aImage;
316 // Spezielle Control-Images
317 SdrObjKind nObjectType = getControlTypeByObject(xInfo);
318 switch (nObjectType)
320 case SdrObjKind::FormButton:
321 aImage = RID_SVXBMP_BUTTON;
322 break;
324 case SdrObjKind::FormFixedText:
325 aImage = RID_SVXBMP_FIXEDTEXT;
326 break;
328 case SdrObjKind::FormEdit:
329 aImage = RID_SVXBMP_EDITBOX;
330 break;
332 case SdrObjKind::FormRadioButton:
333 aImage = RID_SVXBMP_RADIOBUTTON;
334 break;
336 case SdrObjKind::FormCheckbox:
337 aImage = RID_SVXBMP_CHECKBOX;
338 break;
340 case SdrObjKind::FormListbox:
341 aImage = RID_SVXBMP_LISTBOX;
342 break;
344 case SdrObjKind::FormCombobox:
345 aImage = RID_SVXBMP_COMBOBOX;
346 break;
348 case SdrObjKind::FormNavigationBar:
349 aImage = RID_SVXBMP_NAVIGATIONBAR;
350 break;
352 case SdrObjKind::FormGroupBox:
353 aImage = RID_SVXBMP_GROUPBOX;
354 break;
356 case SdrObjKind::FormImageButton:
357 aImage = RID_SVXBMP_IMAGEBUTTON;
358 break;
360 case SdrObjKind::FormFileControl:
361 aImage = RID_SVXBMP_FILECONTROL;
362 break;
364 case SdrObjKind::FormHidden:
365 aImage = RID_SVXBMP_HIDDEN;
366 break;
368 case SdrObjKind::FormDateField:
369 aImage = RID_SVXBMP_DATEFIELD;
370 break;
372 case SdrObjKind::FormTimeField:
373 aImage = RID_SVXBMP_TIMEFIELD;
374 break;
376 case SdrObjKind::FormNumericField:
377 aImage = RID_SVXBMP_NUMERICFIELD;
378 break;
380 case SdrObjKind::FormCurrencyField:
381 aImage = RID_SVXBMP_CURRENCYFIELD;
382 break;
384 case SdrObjKind::FormPatternField:
385 aImage = RID_SVXBMP_PATTERNFIELD;
386 break;
388 case SdrObjKind::FormImageControl:
389 aImage = RID_SVXBMP_IMAGECONTROL;
390 break;
392 case SdrObjKind::FormFormattedField:
393 aImage = RID_SVXBMP_FORMATTEDFIELD;
394 break;
396 case SdrObjKind::FormGrid:
397 aImage = RID_SVXBMP_GRID;
398 break;
400 case SdrObjKind::FormScrollbar:
401 aImage = RID_SVXBMP_SCROLLBAR;
402 break;
404 case SdrObjKind::FormSpinButton:
405 aImage = RID_SVXBMP_SPINBUTTON;
406 break;
408 default:;
411 return aImage;
414 bool FmControlData::IsEqualWithoutChildren( FmEntryData* pEntryData )
416 if(this == pEntryData)
417 return true;
419 FmControlData* pControlData = dynamic_cast<FmControlData*>(pEntryData);
420 if( !pControlData )
421 return false;
423 if( m_xFormComponent.get() != pControlData->GetFormComponent().get() )
424 return false;
426 return FmEntryData::IsEqualWithoutChildren( pControlData );
429 void FmControlData::ModelReplaced(const Reference< XFormComponent >& _rxNew)
431 m_xFormComponent = _rxNew;
432 newObject( m_xFormComponent );
433 // set images anew
434 m_aNormalImage = GetImage();
437 namespace svxform
440 NavigatorFrame::NavigatorFrame( SfxBindings* _pBindings, SfxChildWindow* _pMgr,
441 vcl::Window* _pParent )
442 : SfxDockingWindow(_pBindings, _pMgr, _pParent, "FormNavigator", "svx/ui/formnavigator.ui")
443 , SfxControllerItem( SID_FM_FMEXPLORER_CONTROL, *_pBindings )
444 , m_xNavigatorTree(new NavigatorTree(m_xBuilder->weld_tree_view("treeview")))
446 SetHelpId( HID_FORM_NAVIGATOR_WIN );
448 SetText( SvxResId(RID_STR_FMEXPLORER) );
449 SfxDockingWindow::SetFloatingSize( Size(200,200) );
452 NavigatorFrame::~NavigatorFrame()
454 disposeOnce();
457 void NavigatorFrame::dispose()
459 m_xNavigatorTree.reset();
460 ::SfxControllerItem::dispose();
461 SfxDockingWindow::dispose();
464 void NavigatorFrame::UpdateContent( FmFormShell* pFormShell )
466 m_xNavigatorTree->UpdateContent(pFormShell);
469 void NavigatorFrame::StateChangedAtToolBoxControl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
471 if( !pState || SID_FM_FMEXPLORER_CONTROL != nSID )
472 return;
474 if( eState >= SfxItemState::DEFAULT )
476 FmFormShell* pShell = dynamic_cast<FmFormShell*>( static_cast<const SfxObjectItem*>(pState)->GetShell() );
477 UpdateContent( pShell );
479 else
480 UpdateContent( nullptr );
483 void NavigatorFrame::GetFocus()
485 if (m_xNavigatorTree )
486 m_xNavigatorTree->GrabFocus();
487 else
488 SfxDockingWindow::GetFocus();
491 bool NavigatorFrame::Close()
493 UpdateContent( nullptr );
494 return SfxDockingWindow::Close();
497 void NavigatorFrame::FillInfo( SfxChildWinInfo& rInfo ) const
499 SfxDockingWindow::FillInfo( rInfo );
500 rInfo.bVisible = false;
503 Size NavigatorFrame::CalcDockingSize( SfxChildAlignment eAlign )
505 if ( ( eAlign == SfxChildAlignment::TOP ) || ( eAlign == SfxChildAlignment::BOTTOM ) )
506 return Size();
508 return SfxDockingWindow::CalcDockingSize( eAlign );
511 SfxChildAlignment NavigatorFrame::CheckAlignment( SfxChildAlignment _eActAlign, SfxChildAlignment _eAlign )
513 if ( ( _eAlign == SfxChildAlignment::LEFT ) || ( _eAlign == SfxChildAlignment::RIGHT ) || ( _eAlign == SfxChildAlignment::NOALIGNMENT ) )
514 return _eAlign;
515 return _eActAlign;
518 SFX_IMPL_DOCKINGWINDOW( NavigatorFrameManager, SID_FM_SHOW_FMEXPLORER )
520 NavigatorFrameManager::NavigatorFrameManager( vcl::Window* _pParent, sal_uInt16 _nId,
521 SfxBindings* _pBindings, SfxChildWinInfo* _pInfo )
522 :SfxChildWindow( _pParent, _nId )
524 SetWindow( VclPtr<NavigatorFrame>::Create( _pBindings, this, _pParent ) );
525 static_cast<SfxDockingWindow*>(GetWindow())->Initialize( _pInfo );
529 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */