bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / form / fmexpl.cxx
blob1d4e3db2a160e09490ce497a6fae7094e651b97f
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>
41 using namespace ::svxform;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::form;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::container;
48 FmNavInsertedHint::FmNavInsertedHint( FmEntryData* pInsertedEntryData, sal_uInt32 nRelPos )
49 :pEntryData( pInsertedEntryData )
50 ,nPos( nRelPos )
56 FmNavInsertedHint::~FmNavInsertedHint()
62 FmNavModelReplacedHint::FmNavModelReplacedHint( FmEntryData* pAffectedEntryData )
63 :pEntryData( pAffectedEntryData )
68 FmNavModelReplacedHint::~FmNavModelReplacedHint()
72 FmNavRemovedHint::FmNavRemovedHint( FmEntryData* pRemovedEntryData )
73 :pEntryData( pRemovedEntryData )
78 FmNavRemovedHint::~FmNavRemovedHint()
82 FmNavNameChangedHint::FmNavNameChangedHint( FmEntryData* pData, const OUString& rNewName )
83 :pEntryData( pData )
84 ,aNewName( rNewName )
89 FmNavNameChangedHint::~FmNavNameChangedHint()
93 FmNavClearedHint::FmNavClearedHint()
98 FmNavClearedHint::~FmNavClearedHint()
103 FmEntryDataList::FmEntryDataList()
108 FmEntryDataList::~FmEntryDataList()
113 void FmEntryDataList::removeNoDelete( FmEntryData* pItem )
115 auto it = std::find_if(maEntryDataList.begin(), maEntryDataList.end(),
116 [&pItem](const std::unique_ptr<FmEntryData>& rEntryData) { return rEntryData.get() == pItem; });
117 if (it != maEntryDataList.end())
119 it->release();
120 maEntryDataList.erase( it );
121 return;
123 assert(false);
127 void FmEntryDataList::insert( std::unique_ptr<FmEntryData> pItem, size_t Index )
129 if ( Index < maEntryDataList.size() )
131 maEntryDataList.insert( maEntryDataList.begin() + Index, std::move(pItem) );
133 else
134 maEntryDataList.push_back( std::move(pItem) );
138 void FmEntryDataList::clear()
140 maEntryDataList.clear();
144 FmEntryData::FmEntryData( FmEntryData* pParentData, const Reference< XInterface >& _rxIFace )
145 :pParent( pParentData )
147 pChildList.reset( new FmEntryDataList() );
149 newObject( _rxIFace );
153 FmEntryData::~FmEntryData()
155 pChildList->clear();
159 void FmEntryData::newObject( const css::uno::Reference< css::uno::XInterface >& _rxIFace )
161 // do not just copy, normalize it
162 m_xNormalizedIFace.set( _rxIFace, UNO_QUERY );
163 m_xProperties.set(m_xNormalizedIFace, css::uno::UNO_QUERY);
164 m_xChild.set(m_xNormalizedIFace, css::uno::UNO_QUERY);
168 FmEntryData::FmEntryData( const FmEntryData& rEntryData )
170 pChildList.reset( new FmEntryDataList() );
171 aText = rEntryData.GetText();
172 m_aNormalImage = rEntryData.GetNormalImage();
173 pParent = rEntryData.GetParent();
175 FmEntryData* pChildData;
176 size_t nEntryCount = rEntryData.GetChildList()->size();
177 for( size_t i = 0; i < nEntryCount; i++ )
179 pChildData = rEntryData.GetChildList()->at( i );
180 std::unique_ptr<FmEntryData> pNewChildData = pChildData->Clone();
181 pChildList->insert( std::move(pNewChildData), size_t(-1) );
184 m_xNormalizedIFace = rEntryData.m_xNormalizedIFace;
185 m_xProperties = rEntryData.m_xProperties;
186 m_xChild = rEntryData.m_xChild;
191 bool FmEntryData::IsEqualWithoutChildren( FmEntryData* pEntryData )
193 if(this == pEntryData)
194 return true;
196 if( !pEntryData )
197 return false;
199 if( aText != pEntryData->GetText() )
200 return false;
202 if( !pEntryData->GetParent() && pParent )
203 return false;
205 if( pEntryData->GetParent() && !pParent )
206 return false;
208 if( !pEntryData->GetParent() && !pParent )
209 return true;
211 if( !pParent->IsEqualWithoutChildren(pEntryData->GetParent()) )
212 return false;
214 return true;
217 FmFormData::FmFormData(const Reference< XForm >& _rxForm, FmFormData* _pParent)
218 : FmEntryData(_pParent, _rxForm)
219 , m_xForm(_rxForm)
221 // set images
222 m_aNormalImage = RID_SVXBMP_FORM;
224 // set title
225 if (m_xForm.is())
227 Reference< XPropertySet > xSet(m_xForm, UNO_QUERY);
228 if (xSet.is())
230 OUString aEntryName(::comphelper::getString(xSet->getPropertyValue( FM_PROP_NAME )));
231 SetText(aEntryName);
234 else
235 SetText( OUString() );
238 FmFormData::~FmFormData()
242 FmFormData::FmFormData( const FmFormData& rFormData )
243 :FmEntryData( rFormData )
245 m_xForm = rFormData.GetFormIface();
249 std::unique_ptr<FmEntryData> FmFormData::Clone()
251 return std::unique_ptr<FmEntryData>(new FmFormData( *this ));
255 bool FmFormData::IsEqualWithoutChildren( FmEntryData* pEntryData )
257 if(this == pEntryData)
258 return true;
259 FmFormData* pFormData = dynamic_cast<FmFormData*>(pEntryData);
260 if( !pFormData )
261 return false;
262 if( m_xForm.get() != pFormData->GetFormIface().get() )
263 return false;
265 return FmEntryData::IsEqualWithoutChildren( pFormData );
268 FmControlData::FmControlData(const Reference< XFormComponent >& _rxComponent, FmFormData* _pParent)
269 : FmEntryData( _pParent, _rxComponent ),
270 m_xFormComponent( _rxComponent )
273 // set images
274 m_aNormalImage = GetImage();
277 // set title
278 Reference< XPropertySet > xSet(m_xFormComponent, UNO_QUERY);
279 if( xSet.is() )
281 SetText( ::comphelper::getString(xSet->getPropertyValue( FM_PROP_NAME )));
286 FmControlData::~FmControlData()
291 FmControlData::FmControlData( const FmControlData& rControlData )
292 :FmEntryData( rControlData )
294 m_xFormComponent = rControlData.GetFormComponent();
298 std::unique_ptr<FmEntryData> FmControlData::Clone()
300 return std::unique_ptr<FmEntryData>(new FmControlData( *this ));
304 OUString FmControlData::GetImage() const
306 // Default-Image
307 OUString aImage(RID_SVXBMP_CONTROL);
309 Reference< XServiceInfo > xInfo( m_xFormComponent, UNO_QUERY );
310 if (!m_xFormComponent.is())
311 return aImage;
314 // Spezielle Control-Images
315 sal_Int16 nObjectType = getControlTypeByObject(xInfo);
316 switch (nObjectType)
318 case OBJ_FM_BUTTON:
319 aImage = RID_SVXBMP_BUTTON;
320 break;
322 case OBJ_FM_FIXEDTEXT:
323 aImage = RID_SVXBMP_FIXEDTEXT;
324 break;
326 case OBJ_FM_EDIT:
327 aImage = RID_SVXBMP_EDITBOX;
328 break;
330 case OBJ_FM_RADIOBUTTON:
331 aImage = RID_SVXBMP_RADIOBUTTON;
332 break;
334 case OBJ_FM_CHECKBOX:
335 aImage = RID_SVXBMP_CHECKBOX;
336 break;
338 case OBJ_FM_LISTBOX:
339 aImage = RID_SVXBMP_LISTBOX;
340 break;
342 case OBJ_FM_COMBOBOX:
343 aImage = RID_SVXBMP_COMBOBOX;
344 break;
346 case OBJ_FM_NAVIGATIONBAR:
347 aImage = RID_SVXBMP_NAVIGATIONBAR;
348 break;
350 case OBJ_FM_GROUPBOX:
351 aImage = RID_SVXBMP_GROUPBOX;
352 break;
354 case OBJ_FM_IMAGEBUTTON:
355 aImage = RID_SVXBMP_IMAGEBUTTON;
356 break;
358 case OBJ_FM_FILECONTROL:
359 aImage = RID_SVXBMP_FILECONTROL;
360 break;
362 case OBJ_FM_HIDDEN:
363 aImage = RID_SVXBMP_HIDDEN;
364 break;
366 case OBJ_FM_DATEFIELD:
367 aImage = RID_SVXBMP_DATEFIELD;
368 break;
370 case OBJ_FM_TIMEFIELD:
371 aImage = RID_SVXBMP_TIMEFIELD;
372 break;
374 case OBJ_FM_NUMERICFIELD:
375 aImage = RID_SVXBMP_NUMERICFIELD;
376 break;
378 case OBJ_FM_CURRENCYFIELD:
379 aImage = RID_SVXBMP_CURRENCYFIELD;
380 break;
382 case OBJ_FM_PATTERNFIELD:
383 aImage = RID_SVXBMP_PATTERNFIELD;
384 break;
386 case OBJ_FM_IMAGECONTROL:
387 aImage = RID_SVXBMP_IMAGECONTROL;
388 break;
390 case OBJ_FM_FORMATTEDFIELD:
391 aImage = RID_SVXBMP_FORMATTEDFIELD;
392 break;
394 case OBJ_FM_GRID:
395 aImage = RID_SVXBMP_GRID;
396 break;
398 case OBJ_FM_SCROLLBAR:
399 aImage = RID_SVXBMP_SCROLLBAR;
400 break;
402 case OBJ_FM_SPINBUTTON:
403 aImage = RID_SVXBMP_SPINBUTTON;
404 break;
407 return aImage;
410 bool FmControlData::IsEqualWithoutChildren( FmEntryData* pEntryData )
412 if(this == pEntryData)
413 return true;
415 FmControlData* pControlData = dynamic_cast<FmControlData*>(pEntryData);
416 if( !pControlData )
417 return false;
419 if( m_xFormComponent.get() != pControlData->GetFormComponent().get() )
420 return false;
422 return FmEntryData::IsEqualWithoutChildren( pControlData );
425 void FmControlData::ModelReplaced(const Reference< XFormComponent >& _rxNew)
427 m_xFormComponent = _rxNew;
428 newObject( m_xFormComponent );
429 // set images anew
430 m_aNormalImage = GetImage();
433 namespace svxform
436 NavigatorFrame::NavigatorFrame( SfxBindings* _pBindings, SfxChildWindow* _pMgr,
437 vcl::Window* _pParent )
438 : SfxDockingWindow(_pBindings, _pMgr, _pParent, "FormNavigator", "svx/ui/formnavigator.ui")
439 , SfxControllerItem( SID_FM_FMEXPLORER_CONTROL, *_pBindings )
440 , m_xNavigatorTree(new NavigatorTree(m_xBuilder->weld_tree_view("treeview")))
442 SetHelpId( HID_FORM_NAVIGATOR_WIN );
444 SetText( SvxResId(RID_STR_FMEXPLORER) );
445 SfxDockingWindow::SetFloatingSize( Size(200,200) );
448 NavigatorFrame::~NavigatorFrame()
450 disposeOnce();
453 void NavigatorFrame::dispose()
455 m_xNavigatorTree.reset();
456 ::SfxControllerItem::dispose();
457 SfxDockingWindow::dispose();
460 void NavigatorFrame::UpdateContent( FmFormShell* pFormShell )
462 m_xNavigatorTree->UpdateContent(pFormShell);
465 void NavigatorFrame::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
467 if( !pState || SID_FM_FMEXPLORER_CONTROL != nSID )
468 return;
470 if( eState >= SfxItemState::DEFAULT )
472 FmFormShell* pShell = dynamic_cast<FmFormShell*>( static_cast<const SfxObjectItem*>(pState)->GetShell() );
473 UpdateContent( pShell );
475 else
476 UpdateContent( nullptr );
479 void NavigatorFrame::GetFocus()
481 if (m_xNavigatorTree )
482 m_xNavigatorTree->GrabFocus();
483 else
484 SfxDockingWindow::GetFocus();
487 bool NavigatorFrame::Close()
489 UpdateContent( nullptr );
490 return SfxDockingWindow::Close();
493 void NavigatorFrame::FillInfo( SfxChildWinInfo& rInfo ) const
495 SfxDockingWindow::FillInfo( rInfo );
496 rInfo.bVisible = false;
499 Size NavigatorFrame::CalcDockingSize( SfxChildAlignment eAlign )
501 if ( ( eAlign == SfxChildAlignment::TOP ) || ( eAlign == SfxChildAlignment::BOTTOM ) )
502 return Size();
504 return SfxDockingWindow::CalcDockingSize( eAlign );
507 SfxChildAlignment NavigatorFrame::CheckAlignment( SfxChildAlignment _eActAlign, SfxChildAlignment _eAlign )
509 if ( ( _eAlign == SfxChildAlignment::LEFT ) || ( _eAlign == SfxChildAlignment::RIGHT ) || ( _eAlign == SfxChildAlignment::NOALIGNMENT ) )
510 return _eAlign;
511 return _eActAlign;
514 SFX_IMPL_DOCKINGWINDOW( NavigatorFrameManager, SID_FM_SHOW_FMEXPLORER )
516 NavigatorFrameManager::NavigatorFrameManager( vcl::Window* _pParent, sal_uInt16 _nId,
517 SfxBindings* _pBindings, SfxChildWinInfo* _pInfo )
518 :SfxChildWindow( _pParent, _nId )
520 SetWindow( VclPtr<NavigatorFrame>::Create( _pBindings, this, _pParent ) );
521 static_cast<SfxDockingWindow*>(GetWindow())->Initialize( _pInfo );
525 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */