1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 #include <svx/fmglob.hxx>
26 #include <fmservs.hxx>
27 #include <svx/fmmodel.hxx>
30 #include <fmpgeimp.hxx>
32 #include <svx/svxids.hrc>
35 #include <bitmaps.hlst>
36 #include <svx/dialmgr.hxx>
37 #include <svx/svditer.hxx>
38 #include <svx/svdouno.hxx>
39 #include <svx/svdobj.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <sfx2/objsh.hxx>
42 #include <sfx2/viewsh.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/form/FormComponentType.hpp>
46 #include <com/sun/star/awt/XTabControllerModel.hpp>
47 #include <vcl/menu.hxx>
48 #include <sfx2/objitem.hxx>
49 #include <sfx2/request.hxx>
51 #include <svx/fmshell.hxx>
52 #include <fmshimp.hxx>
53 #include <svx/fmpage.hxx>
54 #include <com/sun/star/io/XPersistObject.hpp>
55 #include <com/sun/star/sdb/CommandType.hpp>
56 #include <com/sun/star/beans/PropertyAttribute.hpp>
57 #include <comphelper/types.hxx>
59 using namespace ::svxform
;
60 using namespace ::com::sun::star::uno
;
61 using namespace ::com::sun::star::sdbc
;
62 using namespace ::com::sun::star::sdb
;
63 using namespace ::com::sun::star::form
;
64 using namespace ::com::sun::star::beans
;
65 using namespace ::com::sun::star::lang
;
66 using namespace ::com::sun::star::container
;
68 FmNavInsertedHint::FmNavInsertedHint( FmEntryData
* pInsertedEntryData
, sal_uInt32 nRelPos
)
69 :pEntryData( pInsertedEntryData
)
76 FmNavInsertedHint::~FmNavInsertedHint()
81 // class FmNavInsertedHint
83 FmNavModelReplacedHint::FmNavModelReplacedHint( FmEntryData
* pAffectedEntryData
)
84 :pEntryData( pAffectedEntryData
)
89 FmNavModelReplacedHint::~FmNavModelReplacedHint()
93 FmNavRemovedHint::FmNavRemovedHint( FmEntryData
* pRemovedEntryData
)
94 :pEntryData( pRemovedEntryData
)
99 FmNavRemovedHint::~FmNavRemovedHint()
103 FmNavNameChangedHint::FmNavNameChangedHint( FmEntryData
* pData
, const OUString
& rNewName
)
105 ,aNewName( rNewName
)
110 FmNavNameChangedHint::~FmNavNameChangedHint()
114 FmNavClearedHint::FmNavClearedHint()
119 FmNavClearedHint::~FmNavClearedHint()
124 FmEntryDataList::FmEntryDataList()
129 FmEntryDataList::~FmEntryDataList()
134 void FmEntryDataList::removeNoDelete( FmEntryData
* pItem
)
136 auto it
= std::find_if(maEntryDataList
.begin(), maEntryDataList
.end(),
137 [&pItem
](const std::unique_ptr
<FmEntryData
>& rEntryData
) { return rEntryData
.get() == pItem
; });
138 if (it
!= maEntryDataList
.end())
141 maEntryDataList
.erase( it
);
148 void FmEntryDataList::insert( std::unique_ptr
<FmEntryData
> pItem
, size_t Index
)
150 if ( Index
< maEntryDataList
.size() )
152 maEntryDataList
.insert( maEntryDataList
.begin() + Index
, std::move(pItem
) );
155 maEntryDataList
.push_back( std::move(pItem
) );
159 void FmEntryDataList::clear()
161 maEntryDataList
.clear();
165 FmEntryData::FmEntryData( FmEntryData
* pParentData
, const Reference
< XInterface
>& _rxIFace
)
166 :pParent( pParentData
)
168 pChildList
.reset( new FmEntryDataList() );
170 newObject( _rxIFace
);
174 FmEntryData::~FmEntryData()
180 void FmEntryData::newObject( const css::uno::Reference
< css::uno::XInterface
>& _rxIFace
)
182 // do not just copy, normalize it
183 m_xNormalizedIFace
.set( _rxIFace
, UNO_QUERY
);
184 m_xProperties
.set(m_xNormalizedIFace
, css::uno::UNO_QUERY
);
185 m_xChild
.set(m_xNormalizedIFace
, css::uno::UNO_QUERY
);
189 FmEntryData::FmEntryData( const FmEntryData
& rEntryData
)
191 pChildList
.reset( new FmEntryDataList() );
192 aText
= rEntryData
.GetText();
193 m_aNormalImage
= rEntryData
.GetNormalImage();
194 pParent
= rEntryData
.GetParent();
196 FmEntryData
* pChildData
;
197 size_t nEntryCount
= rEntryData
.GetChildList()->size();
198 for( size_t i
= 0; i
< nEntryCount
; i
++ )
200 pChildData
= rEntryData
.GetChildList()->at( i
);
201 std::unique_ptr
<FmEntryData
> pNewChildData
= pChildData
->Clone();
202 pChildList
->insert( std::move(pNewChildData
), size_t(-1) );
205 m_xNormalizedIFace
= rEntryData
.m_xNormalizedIFace
;
206 m_xProperties
= rEntryData
.m_xProperties
;
207 m_xChild
= rEntryData
.m_xChild
;
212 bool FmEntryData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
214 if(this == pEntryData
)
220 if( aText
!= pEntryData
->GetText() )
223 if( !pEntryData
->GetParent() && pParent
)
226 if( pEntryData
->GetParent() && !pParent
)
229 if( !pEntryData
->GetParent() && !pParent
)
232 if( !pParent
->IsEqualWithoutChildren(pEntryData
->GetParent()) )
238 FmFormData::FmFormData(const Reference
< XForm
>& _rxForm
, FmFormData
* _pParent
)
239 : FmEntryData(_pParent
, _rxForm
)
243 m_aNormalImage
= Image(RID_SVXBMP_FORM
);
248 Reference
< XPropertySet
> xSet(m_xForm
, UNO_QUERY
);
251 OUString
aEntryName(::comphelper::getString(xSet
->getPropertyValue( FM_PROP_NAME
)));
256 SetText( OUString() );
259 FmFormData::~FmFormData()
263 FmFormData::FmFormData( const FmFormData
& rFormData
)
264 :FmEntryData( rFormData
)
266 m_xForm
= rFormData
.GetFormIface();
270 std::unique_ptr
<FmEntryData
> FmFormData::Clone()
272 return std::unique_ptr
<FmEntryData
>(new FmFormData( *this ));
276 bool FmFormData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
278 if(this == pEntryData
)
280 if( dynamic_cast<const FmFormData
*>( pEntryData
) == nullptr )
282 FmFormData
* pFormData
= static_cast<FmFormData
*>(pEntryData
);
283 if( m_xForm
.get() != pFormData
->GetFormIface().get() )
286 return FmEntryData::IsEqualWithoutChildren( pFormData
);
289 FmControlData::FmControlData(const Reference
< XFormComponent
>& _rxComponent
, FmFormData
* _pParent
)
290 : FmEntryData( _pParent
, _rxComponent
),
291 m_xFormComponent( _rxComponent
)
295 m_aNormalImage
= GetImage();
299 Reference
< XPropertySet
> xSet(m_xFormComponent
, UNO_QUERY
);
302 SetText( ::comphelper::getString(xSet
->getPropertyValue( FM_PROP_NAME
)));
307 FmControlData::~FmControlData()
312 FmControlData::FmControlData( const FmControlData
& rControlData
)
313 :FmEntryData( rControlData
)
315 m_xFormComponent
= rControlData
.GetFormComponent();
319 std::unique_ptr
<FmEntryData
> FmControlData::Clone()
321 return std::unique_ptr
<FmEntryData
>(new FmControlData( *this ));
325 Image
FmControlData::GetImage() const
328 Image
aImage(StockImage::Yes
, RID_SVXBMP_CONTROL
);
330 Reference
< XServiceInfo
> xInfo( m_xFormComponent
, UNO_QUERY
);
331 if (!m_xFormComponent
.is())
335 // Spezielle Control-Images
336 sal_Int16 nObjectType
= getControlTypeByObject(xInfo
);
340 aImage
= Image(StockImage::Yes
, RID_SVXBMP_BUTTON
);
343 case OBJ_FM_FIXEDTEXT
:
344 aImage
= Image(StockImage::Yes
, RID_SVXBMP_FIXEDTEXT
);
348 aImage
= Image(StockImage::Yes
, RID_SVXBMP_EDITBOX
);
351 case OBJ_FM_RADIOBUTTON
:
352 aImage
= Image(StockImage::Yes
, RID_SVXBMP_RADIOBUTTON
);
355 case OBJ_FM_CHECKBOX
:
356 aImage
= Image(StockImage::Yes
, RID_SVXBMP_CHECKBOX
);
360 aImage
= Image(StockImage::Yes
, RID_SVXBMP_LISTBOX
);
363 case OBJ_FM_COMBOBOX
:
364 aImage
= Image(StockImage::Yes
, RID_SVXBMP_COMBOBOX
);
367 case OBJ_FM_NAVIGATIONBAR
:
368 aImage
= Image(StockImage::Yes
, RID_SVXBMP_NAVIGATIONBAR
);
371 case OBJ_FM_GROUPBOX
:
372 aImage
= Image(StockImage::Yes
, RID_SVXBMP_GROUPBOX
);
375 case OBJ_FM_IMAGEBUTTON
:
376 aImage
= Image(StockImage::Yes
, RID_SVXBMP_IMAGEBUTTON
);
379 case OBJ_FM_FILECONTROL
:
380 aImage
= Image(StockImage::Yes
, RID_SVXBMP_FILECONTROL
);
384 aImage
= Image(StockImage::Yes
, RID_SVXBMP_HIDDEN
);
387 case OBJ_FM_DATEFIELD
:
388 aImage
= Image(StockImage::Yes
, RID_SVXBMP_DATEFIELD
);
391 case OBJ_FM_TIMEFIELD
:
392 aImage
= Image(StockImage::Yes
, RID_SVXBMP_TIMEFIELD
);
395 case OBJ_FM_NUMERICFIELD
:
396 aImage
= Image(StockImage::Yes
, RID_SVXBMP_NUMERICFIELD
);
399 case OBJ_FM_CURRENCYFIELD
:
400 aImage
= Image(StockImage::Yes
, RID_SVXBMP_CURRENCYFIELD
);
403 case OBJ_FM_PATTERNFIELD
:
404 aImage
= Image(StockImage::Yes
, RID_SVXBMP_PATTERNFIELD
);
407 case OBJ_FM_IMAGECONTROL
:
408 aImage
= Image(StockImage::Yes
, RID_SVXBMP_IMAGECONTROL
);
411 case OBJ_FM_FORMATTEDFIELD
:
412 aImage
= Image(StockImage::Yes
, RID_SVXBMP_FORMATTEDFIELD
);
416 aImage
= Image(StockImage::Yes
, RID_SVXBMP_GRID
);
419 case OBJ_FM_SCROLLBAR
:
420 aImage
= Image(StockImage::Yes
, RID_SVXBMP_SCROLLBAR
);
423 case OBJ_FM_SPINBUTTON
:
424 aImage
= Image(StockImage::Yes
, RID_SVXBMP_SPINBUTTON
);
431 bool FmControlData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
433 if(this == pEntryData
)
436 if( dynamic_cast<const FmControlData
*>( pEntryData
) == nullptr )
438 FmControlData
* pControlData
= static_cast<FmControlData
*>(pEntryData
);
440 if( m_xFormComponent
.get() != pControlData
->GetFormComponent().get() )
443 return FmEntryData::IsEqualWithoutChildren( pControlData
);
446 void FmControlData::ModelReplaced(const Reference
< XFormComponent
>& _rxNew
)
448 m_xFormComponent
= _rxNew
;
449 newObject( m_xFormComponent
);
451 m_aNormalImage
= GetImage();
457 NavigatorFrame::NavigatorFrame( SfxBindings
* _pBindings
, SfxChildWindow
* _pMgr
,
458 vcl::Window
* _pParent
)
459 :SfxDockingWindow( _pBindings
, _pMgr
, _pParent
, WinBits(WB_STDMODELESS
|WB_SIZEABLE
|WB_ROLLABLE
|WB_3DLOOK
|WB_DOCKABLE
) )
460 ,SfxControllerItem( SID_FM_FMEXPLORER_CONTROL
, *_pBindings
)
462 SetHelpId( HID_FORM_NAVIGATOR_WIN
);
464 m_pNavigatorTree
= VclPtr
<NavigatorTree
>::Create( this );
465 m_pNavigatorTree
->Show();
466 SetText( SvxResId(RID_STR_FMEXPLORER
) );
467 SfxDockingWindow::SetFloatingSize( Size(200,200) );
471 NavigatorFrame::~NavigatorFrame()
476 void NavigatorFrame::dispose()
478 m_pNavigatorTree
.disposeAndClear();
479 ::SfxControllerItem::dispose();
480 SfxDockingWindow::dispose();
484 void NavigatorFrame::UpdateContent( FmFormShell
* pFormShell
)
486 m_pNavigatorTree
->UpdateContent( pFormShell
);
490 void NavigatorFrame::StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
492 if( !pState
|| SID_FM_FMEXPLORER_CONTROL
!= nSID
)
495 if( eState
>= SfxItemState::DEFAULT
)
497 FmFormShell
* pShell
= dynamic_cast<FmFormShell
*>( static_cast<const SfxObjectItem
*>(pState
)->GetShell() );
498 UpdateContent( pShell
);
501 UpdateContent( nullptr );
505 void NavigatorFrame::GetFocus()
507 if ( m_pNavigatorTree
)
508 m_pNavigatorTree
->GrabFocus();
510 SfxDockingWindow::GetFocus();
514 bool NavigatorFrame::Close()
516 UpdateContent( nullptr );
517 return SfxDockingWindow::Close();
521 void NavigatorFrame::FillInfo( SfxChildWinInfo
& rInfo
) const
523 SfxDockingWindow::FillInfo( rInfo
);
524 rInfo
.bVisible
= false;
528 Size
NavigatorFrame::CalcDockingSize( SfxChildAlignment eAlign
)
530 if ( ( eAlign
== SfxChildAlignment::TOP
) || ( eAlign
== SfxChildAlignment::BOTTOM
) )
533 return SfxDockingWindow::CalcDockingSize( eAlign
);
537 SfxChildAlignment
NavigatorFrame::CheckAlignment( SfxChildAlignment _eActAlign
, SfxChildAlignment _eAlign
)
539 if ( ( _eAlign
== SfxChildAlignment::LEFT
) || ( _eAlign
== SfxChildAlignment::RIGHT
) || ( _eAlign
== SfxChildAlignment::NOALIGNMENT
) )
545 void NavigatorFrame::Resize()
547 SfxDockingWindow::Resize();
549 Size aLogOutputSize
= PixelToLogic(GetOutputSizePixel(), MapMode(MapUnit::MapAppFont
));
550 Size aLogExplSize
= aLogOutputSize
;
551 aLogExplSize
.AdjustWidth( -6 );
552 aLogExplSize
.AdjustHeight( -6 );
554 Point aExplPos
= LogicToPixel(Point(3, 3), MapMode(MapUnit::MapAppFont
));
555 Size aExplSize
= LogicToPixel(aLogExplSize
, MapMode(MapUnit::MapAppFont
));
557 m_pNavigatorTree
->SetPosSizePixel( aExplPos
, aExplSize
);
561 // class NavigatorFrameManager
564 SFX_IMPL_DOCKINGWINDOW( NavigatorFrameManager
, SID_FM_SHOW_FMEXPLORER
)
567 NavigatorFrameManager::NavigatorFrameManager( vcl::Window
* _pParent
, sal_uInt16 _nId
,
568 SfxBindings
* _pBindings
, SfxChildWinInfo
* _pInfo
)
569 :SfxChildWindow( _pParent
, _nId
)
571 SetWindow( VclPtr
<NavigatorFrame
>::Create( _pBindings
, this, _pParent
) );
572 static_cast<SfxDockingWindow
*>(GetWindow())->Initialize( _pInfo
);
576 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */