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/fmresids.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 <svx/dialmgr.hxx>
36 #include "svx/svditer.hxx"
37 #include <svx/svdouno.hxx>
38 #include <svx/svdobj.hxx>
39 #include <vcl/msgbox.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 <vcl/wrkwin.hxx>
52 #include <svx/fmshell.hxx>
53 #include "fmshimp.hxx"
54 #include <svx/fmpage.hxx>
55 #include <com/sun/star/io/XPersistObject.hpp>
56 #include <com/sun/star/script/XEventAttacherManager.hpp>
57 #include <com/sun/star/sdb/CommandType.hpp>
58 #include <com/sun/star/beans/PropertyAttribute.hpp>
59 #include <comphelper/property.hxx>
60 #include <comphelper/processfactory.hxx>
61 #include <osl/diagnose.h>
63 using namespace ::svxform
;
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::sdbc
;
66 using namespace ::com::sun::star::sdb
;
67 using namespace ::com::sun::star::form
;
68 using namespace ::com::sun::star::beans
;
69 using namespace ::com::sun::star::lang
;
70 using namespace ::com::sun::star::container
;
72 FmNavInsertedHint::FmNavInsertedHint( FmEntryData
* pInsertedEntryData
, sal_uInt32 nRelPos
)
73 :pEntryData( pInsertedEntryData
)
80 FmNavInsertedHint::~FmNavInsertedHint()
86 // class FmNavInsertedHint
88 FmNavModelReplacedHint::FmNavModelReplacedHint( FmEntryData
* pAffectedEntryData
)
89 :pEntryData( pAffectedEntryData
)
94 FmNavModelReplacedHint::~FmNavModelReplacedHint()
98 FmNavRemovedHint::FmNavRemovedHint( FmEntryData
* pRemovedEntryData
)
99 :pEntryData( pRemovedEntryData
)
104 FmNavRemovedHint::~FmNavRemovedHint()
108 FmNavNameChangedHint::FmNavNameChangedHint( FmEntryData
* pData
, const OUString
& rNewName
)
110 ,aNewName( rNewName
)
115 FmNavNameChangedHint::~FmNavNameChangedHint()
119 FmNavClearedHint::FmNavClearedHint()
124 FmNavClearedHint::~FmNavClearedHint()
129 FmEntryDataList::FmEntryDataList()
134 FmEntryDataList::~FmEntryDataList()
139 FmEntryData
* FmEntryDataList::remove( FmEntryData
* pItem
)
141 for ( FmEntryDataBaseList::iterator it
= maEntryDataList
.begin();
142 it
!= maEntryDataList
.end();
148 maEntryDataList
.erase( it
);
156 void FmEntryDataList::insert( FmEntryData
* pItem
, size_t Index
)
158 if ( Index
< maEntryDataList
.size() )
160 FmEntryDataBaseList::iterator it
= maEntryDataList
.begin();
161 ::std::advance( it
, Index
);
162 maEntryDataList
.insert( it
, pItem
);
165 maEntryDataList
.push_back( pItem
);
169 void FmEntryDataList::clear()
171 for ( size_t i
= 0, n
= maEntryDataList
.size(); i
< n
; ++i
)
172 delete maEntryDataList
[ i
];
173 maEntryDataList
.clear();
176 TYPEINIT0( FmEntryData
);
178 FmEntryData::FmEntryData( FmEntryData
* pParentData
, const Reference
< XInterface
>& _rxIFace
)
179 :pParent( pParentData
)
181 pChildList
= new FmEntryDataList();
183 newObject( _rxIFace
);
187 FmEntryData::~FmEntryData()
194 void FmEntryData::newObject( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxIFace
)
196 // do not just copy, normalize it
197 m_xNormalizedIFace
= Reference
< XInterface
>( _rxIFace
, UNO_QUERY
);
198 m_xProperties
.set(m_xNormalizedIFace
, css::uno::UNO_QUERY
);
199 m_xChild
.set(m_xNormalizedIFace
, css::uno::UNO_QUERY
);
203 FmEntryData::FmEntryData( const FmEntryData
& rEntryData
)
205 pChildList
= new FmEntryDataList();
206 aText
= rEntryData
.GetText();
207 m_aNormalImage
= rEntryData
.GetNormalImage();
208 pParent
= rEntryData
.GetParent();
210 FmEntryData
* pChildData
;
211 size_t nEntryCount
= rEntryData
.GetChildList()->size();
212 for( size_t i
= 0; i
< nEntryCount
; i
++ )
214 pChildData
= rEntryData
.GetChildList()->at( i
);
215 FmEntryData
* pNewChildData
= pChildData
->Clone();
216 pChildList
->insert( pNewChildData
, size_t(-1) );
219 m_xNormalizedIFace
= rEntryData
.m_xNormalizedIFace
;
220 m_xProperties
= rEntryData
.m_xProperties
;
221 m_xChild
= rEntryData
.m_xChild
;
225 void FmEntryData::Clear()
227 GetChildList()->clear();
231 bool FmEntryData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
233 if(this == pEntryData
)
239 if( !aText
.equals(pEntryData
->GetText()))
242 if( !pEntryData
->GetParent() && pParent
)
245 if( pEntryData
->GetParent() && !pParent
)
248 if( !pEntryData
->GetParent() && !pParent
)
251 if( !pParent
->IsEqualWithoutChildren(pEntryData
->GetParent()) )
257 TYPEINIT1( FmFormData
, FmEntryData
);
259 FmFormData::FmFormData(
260 const Reference
< XForm
>& _rxForm
,
261 const ImageList
& _rNormalImages
,
264 : FmEntryData( _pParent
, _rxForm
),
270 m_aNormalImage
= _rNormalImages
.GetImage( RID_SVXIMG_FORM
);
276 Reference
< XPropertySet
> xSet(m_xForm
, UNO_QUERY
);
279 OUString
aEntryName(::comphelper::getString(xSet
->getPropertyValue( FM_PROP_NAME
)));
284 SetText( OUString() );
288 FmFormData::~FmFormData()
293 FmFormData::FmFormData( const FmFormData
& rFormData
)
294 :FmEntryData( rFormData
)
296 m_xForm
= rFormData
.GetFormIface();
300 FmEntryData
* FmFormData::Clone()
302 return new FmFormData( *this );
306 bool FmFormData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
308 if(this == pEntryData
)
310 if( !pEntryData
->ISA(FmFormData
) )
312 FmFormData
* pFormData
= static_cast<FmFormData
*>(pEntryData
);
313 if( (XForm
*)m_xForm
.get() != (XForm
*)pFormData
->GetFormIface().get() )
316 return FmEntryData::IsEqualWithoutChildren( pFormData
);
319 TYPEINIT1( FmControlData
, FmEntryData
);
321 FmControlData::FmControlData(
322 const Reference
< XFormComponent
>& _rxComponent
,
323 const ImageList
& _rNormalImages
,
326 : FmEntryData( _pParent
, _rxComponent
),
327 m_xFormComponent( _rxComponent
)
331 m_aNormalImage
= GetImage( _rNormalImages
);
335 Reference
< XPropertySet
> xSet(m_xFormComponent
, UNO_QUERY
);
338 SetText( ::comphelper::getString(xSet
->getPropertyValue( FM_PROP_NAME
)));
343 FmControlData::~FmControlData()
348 FmControlData::FmControlData( const FmControlData
& rControlData
)
349 :FmEntryData( rControlData
)
351 m_xFormComponent
= rControlData
.GetFormComponent();
355 FmEntryData
* FmControlData::Clone()
357 return new FmControlData( *this );
361 Image
FmControlData::GetImage(const ImageList
& ilNavigatorImages
) const
365 Image aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_CONTROL
);
367 Reference
< XServiceInfo
> xInfo( m_xFormComponent
, UNO_QUERY
);
368 if (!m_xFormComponent
.is())
372 // Spezielle Control-Images
373 sal_Int16 nObjectType
= getControlTypeByObject(xInfo
);
377 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_BUTTON
);
380 case OBJ_FM_FIXEDTEXT
:
381 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_FIXEDTEXT
);
385 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_EDIT
);
388 case OBJ_FM_RADIOBUTTON
:
389 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_RADIOBUTTON
);
392 case OBJ_FM_CHECKBOX
:
393 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_CHECKBOX
);
397 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_LISTBOX
);
400 case OBJ_FM_COMBOBOX
:
401 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_COMBOBOX
);
404 case OBJ_FM_NAVIGATIONBAR
:
405 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_NAVIGATIONBAR
);
408 case OBJ_FM_GROUPBOX
:
409 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_GROUPBOX
);
412 case OBJ_FM_IMAGEBUTTON
:
413 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_IMAGEBUTTON
);
416 case OBJ_FM_FILECONTROL
:
417 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_FILECONTROL
);
421 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_HIDDEN
);
424 case OBJ_FM_DATEFIELD
:
425 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_DATEFIELD
);
428 case OBJ_FM_TIMEFIELD
:
429 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_TIMEFIELD
);
432 case OBJ_FM_NUMERICFIELD
:
433 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_NUMERICFIELD
);
436 case OBJ_FM_CURRENCYFIELD
:
437 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_CURRENCYFIELD
);
440 case OBJ_FM_PATTERNFIELD
:
441 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_PATTERNFIELD
);
444 case OBJ_FM_IMAGECONTROL
:
445 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_IMAGECONTROL
);
448 case OBJ_FM_FORMATTEDFIELD
:
449 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_FORMATTEDFIELD
);
453 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_GRID
);
456 case OBJ_FM_SCROLLBAR
:
457 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_SCROLLBAR
);
460 case OBJ_FM_SPINBUTTON
:
461 aImage
= ilNavigatorImages
.GetImage( RID_SVXIMG_SPINBUTTON
);
469 bool FmControlData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
471 if(this == pEntryData
)
474 if( !pEntryData
->ISA(FmControlData
) )
476 FmControlData
* pControlData
= static_cast<FmControlData
*>(pEntryData
);
478 if( (XFormComponent
*)m_xFormComponent
.get() != (XFormComponent
*)pControlData
->GetFormComponent().get() )
481 return FmEntryData::IsEqualWithoutChildren( pControlData
);
485 void FmControlData::ModelReplaced(
486 const Reference
< XFormComponent
>& _rxNew
,
487 const ImageList
& _rNormalImages
490 m_xFormComponent
= _rxNew
;
491 newObject( m_xFormComponent
);
494 m_aNormalImage
= GetImage( _rNormalImages
);
501 NavigatorFrame::NavigatorFrame( SfxBindings
* _pBindings
, SfxChildWindow
* _pMgr
,
502 vcl::Window
* _pParent
)
503 :SfxDockingWindow( _pBindings
, _pMgr
, _pParent
, WinBits(WB_STDMODELESS
|WB_SIZEABLE
|WB_ROLLABLE
|WB_3DLOOK
|WB_DOCKABLE
) )
504 ,SfxControllerItem( SID_FM_FMEXPLORER_CONTROL
, *_pBindings
)
506 SetHelpId( HID_FORM_NAVIGATOR_WIN
);
508 m_pNavigatorTree
= VclPtr
<NavigatorTree
>::Create( this );
509 m_pNavigatorTree
->Show();
510 SetText( SVX_RES(RID_STR_FMEXPLORER
) );
511 SfxDockingWindow::SetFloatingSize( Size(200,200) );
515 NavigatorFrame::~NavigatorFrame()
520 void NavigatorFrame::dispose()
522 m_pNavigatorTree
.disposeAndClear();
523 SfxDockingWindow::dispose();
527 void NavigatorFrame::UpdateContent( FmFormShell
* pFormShell
)
529 m_pNavigatorTree
->UpdateContent( pFormShell
);
533 void NavigatorFrame::StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
535 if( !pState
|| SID_FM_FMEXPLORER_CONTROL
!= nSID
)
538 if( eState
>= SfxItemState::DEFAULT
)
540 FmFormShell
* pShell
= PTR_CAST( FmFormShell
, static_cast<const SfxObjectItem
*>(pState
)->GetShell() );
541 UpdateContent( pShell
);
544 UpdateContent( NULL
);
548 void NavigatorFrame::GetFocus()
550 if ( m_pNavigatorTree
)
551 m_pNavigatorTree
->GrabFocus();
553 SfxDockingWindow::GetFocus();
557 bool NavigatorFrame::Close()
559 UpdateContent( NULL
);
560 return SfxDockingWindow::Close();
564 void NavigatorFrame::FillInfo( SfxChildWinInfo
& rInfo
) const
566 SfxDockingWindow::FillInfo( rInfo
);
567 rInfo
.bVisible
= false;
571 Size
NavigatorFrame::CalcDockingSize( SfxChildAlignment eAlign
)
573 if ( ( eAlign
== SfxChildAlignment::TOP
) || ( eAlign
== SfxChildAlignment::BOTTOM
) )
576 return SfxDockingWindow::CalcDockingSize( eAlign
);
580 SfxChildAlignment
NavigatorFrame::CheckAlignment( SfxChildAlignment _eActAlign
, SfxChildAlignment _eAlign
)
582 if ( ( _eAlign
== SfxChildAlignment::LEFT
) || ( _eAlign
== SfxChildAlignment::RIGHT
) || ( _eAlign
== SfxChildAlignment::NOALIGNMENT
) )
588 void NavigatorFrame::Resize()
590 SfxDockingWindow::Resize();
592 Size aLogOutputSize
= PixelToLogic( GetOutputSizePixel(), MAP_APPFONT
);
593 Size aLogExplSize
= aLogOutputSize
;
594 aLogExplSize
.Width() -= 6;
595 aLogExplSize
.Height() -= 6;
597 Point aExplPos
= LogicToPixel( Point(3,3), MAP_APPFONT
);
598 Size aExplSize
= LogicToPixel( aLogExplSize
, MAP_APPFONT
);
600 m_pNavigatorTree
->SetPosSizePixel( aExplPos
, aExplSize
);
605 // class NavigatorFrameManager
609 SFX_IMPL_DOCKINGWINDOW( NavigatorFrameManager
, SID_FM_SHOW_FMEXPLORER
)
612 NavigatorFrameManager::NavigatorFrameManager( vcl::Window
* _pParent
, sal_uInt16 _nId
,
613 SfxBindings
* _pBindings
, SfxChildWinInfo
* _pInfo
)
614 :SfxChildWindow( _pParent
, _nId
)
616 pWindow
= VclPtr
<NavigatorFrame
>::Create( _pBindings
, this, _pParent
);
617 eChildAlignment
= SfxChildAlignment::NOALIGNMENT
;
618 static_cast<SfxDockingWindow
*>(pWindow
.get())->Initialize( _pInfo
);
625 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */