1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: taborder.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "taborder.hxx"
34 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_TABORDER_HRC
35 #include "taborder.hrc"
38 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
39 #include "modulepcr.hxx"
41 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_
42 #include "formresid.hrc"
44 #include "formstrings.hxx"
45 #include <comphelper/types.hxx>
46 #include <comphelper/property.hxx>
47 #include <cppuhelper/implbase1.hxx>
48 #include <com/sun/star/form/FormComponentType.hpp>
49 #include <com/sun/star/awt/XTabController.hpp>
50 #include <vcl/scrbar.hxx>
52 //............................................................................
55 //............................................................................
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::awt
;
59 using namespace ::com::sun::star::lang
;
60 using namespace ::com::sun::star::form
;
61 using namespace ::com::sun::star::beans
;
62 using namespace ::com::sun::star::datatransfer
;
64 //========================================================================
66 //========================================================================
67 class OSimpleTabModel
: public ::cppu::WeakImplHelper1
< XTabControllerModel
>
69 Sequence
< Reference
< XControlModel
> > m_aModels
;
72 OSimpleTabModel( const Sequence
< Reference
< XControlModel
> >& _rModels
)
73 :m_aModels( _rModels
)
77 // XTabControllerModel
78 virtual void SAL_CALL
setControlModels(const Sequence
< Reference
< XControlModel
> >& rModels
) throw( RuntimeException
) {m_aModels
= rModels
;}
79 virtual Sequence
< Reference
< XControlModel
> > SAL_CALL
getControlModels(void) throw( RuntimeException
) {return m_aModels
;}
80 virtual void SAL_CALL
setGroup(const Sequence
< Reference
< XControlModel
> >& /*Group*/, const ::rtl::OUString
& /*GroupName*/) throw( RuntimeException
) {}
81 virtual sal_Int32 SAL_CALL
getGroupCount(void) throw( RuntimeException
) {return 0;}
82 virtual void SAL_CALL
getGroup(sal_Int32
/*nGroup*/, Sequence
< Reference
< XControlModel
> >& /*Group*/, ::rtl::OUString
& /*Name*/) throw( RuntimeException
) {}
83 virtual void SAL_CALL
getGroupByName(const ::rtl::OUString
& /*Name*/, Sequence
< Reference
< XControlModel
> >& /*Group*/) throw( RuntimeException
) {}
84 virtual sal_Bool SAL_CALL
getGroupControl(void) throw( RuntimeException
){return sal_False
;} ;
85 virtual void SAL_CALL
setGroupControl(sal_Bool
/*GroupControl*/) throw( RuntimeException
){};
88 //========================================================================
90 //========================================================================
91 DBG_NAME(TabOrderDialog
)
92 //------------------------------------------------------------------------
93 TabOrderDialog::TabOrderDialog( Window
* _pParent
, const Reference
< XTabControllerModel
>& _rxTabModel
,
94 const Reference
< XControlContainer
>& _rxControlCont
, const Reference
< XMultiServiceFactory
>& _rxORB
)
95 :ModalDialog( _pParent
, PcrRes( RID_DLG_TABORDER
) )
96 ,m_xModel( _rxTabModel
)
97 ,m_xControlContainer( _rxControlCont
)
99 ,aFT_Controls( this, PcrRes( FT_CONTROLS
) )
100 ,aLB_Controls( this, PcrRes( CTRL_TREE
) )
101 ,aPB_OK( this, PcrRes( PB_OK
) )
102 ,aPB_CANCEL( this, PcrRes( PB_CANCEL
) )
103 ,aPB_HELP( this, PcrRes( PB_HELP
) )
104 ,aPB_MoveUp( this, PcrRes( PB_MOVE_UP
) )
105 ,aPB_MoveDown( this, PcrRes( PB_MOVE_DOWN
) )
106 ,aPB_AutoOrder( this, PcrRes( PB_AUTO_ORDER
) )
109 DBG_CTOR(TabOrderDialog
,NULL
);
111 aPB_MoveUp
.SetClickHdl( LINK( this, TabOrderDialog
, MoveUpClickHdl
) );
112 aPB_MoveDown
.SetClickHdl( LINK( this, TabOrderDialog
, MoveDownClickHdl
) );
113 aPB_AutoOrder
.SetClickHdl( LINK( this, TabOrderDialog
, AutoOrderClickHdl
) );
114 aPB_OK
.SetClickHdl( LINK( this, TabOrderDialog
, OKClickHdl
) );
117 sal_Bool bIsHighContrast
= GetDisplayBackground().GetColor().IsDark();
118 pImageList
= new ImageList( PcrRes( bIsHighContrast
? RID_IL_FORMEXPLORER_HC
: RID_IL_FORMEXPLORER
) );
122 m_xTempModel
= new OSimpleTabModel( m_xModel
->getControlModels() );
124 if ( m_xTempModel
.is() && m_xControlContainer
.is() )
127 if ( aLB_Controls
.GetEntryCount() < 2 )
129 aPB_MoveUp
.Disable();
130 aPB_MoveDown
.Disable();
131 aPB_AutoOrder
.Disable();
137 //------------------------------------------------------------------------
138 void TabOrderDialog::SetModified()
143 //------------------------------------------------------------------------
144 TabOrderDialog::~TabOrderDialog()
147 // delete pLB_Controls;
150 DBG_DTOR(TabOrderDialog
,NULL
);
153 //------------------------------------------------------------------------
154 Image
TabOrderDialog::GetImage( const Reference
< XPropertySet
>& _rxSet
) const
156 sal_uInt16 nImageId
= RID_SVXIMG_CONTROL
;
157 // TODO: classify controls also in Basic propbrw
158 if ( _rxSet
.is() && ::comphelper::hasProperty( PROPERTY_CLASSID
, _rxSet
) )
160 switch( ::comphelper::getINT16( _rxSet
->getPropertyValue( PROPERTY_CLASSID
) ) )
162 case FormComponentType::COMMANDBUTTON
: nImageId
= RID_SVXIMG_BUTTON
; break;
163 case FormComponentType::FIXEDTEXT
: nImageId
= RID_SVXIMG_FIXEDTEXT
; break;
164 case FormComponentType::TEXTFIELD
: nImageId
= RID_SVXIMG_EDIT
; break;
165 case FormComponentType::RADIOBUTTON
: nImageId
= RID_SVXIMG_RADIOBUTTON
; break;
166 case FormComponentType::CHECKBOX
: nImageId
= RID_SVXIMG_CHECKBOX
; break;
167 case FormComponentType::LISTBOX
: nImageId
= RID_SVXIMG_LISTBOX
; break;
168 case FormComponentType::COMBOBOX
: nImageId
= RID_SVXIMG_COMBOBOX
; break;
169 case FormComponentType::GROUPBOX
: nImageId
= RID_SVXIMG_GROUPBOX
; break;
170 case FormComponentType::IMAGEBUTTON
: nImageId
= RID_SVXIMG_IMAGEBUTTON
; break;
171 case FormComponentType::FILECONTROL
: nImageId
= RID_SVXIMG_FILECONTROL
; break;
172 case FormComponentType::HIDDENCONTROL
: nImageId
= RID_SVXIMG_HIDDEN
; break;
173 case FormComponentType::DATEFIELD
: nImageId
= RID_SVXIMG_DATEFIELD
; break;
174 case FormComponentType::TIMEFIELD
: nImageId
= RID_SVXIMG_TIMEFIELD
; break;
175 case FormComponentType::NUMERICFIELD
: nImageId
= RID_SVXIMG_NUMERICFIELD
; break;
176 case FormComponentType::CURRENCYFIELD
: nImageId
= RID_SVXIMG_CURRENCYFIELD
; break;
177 case FormComponentType::PATTERNFIELD
: nImageId
= RID_SVXIMG_PATTERNFIELD
; break;
178 case FormComponentType::IMAGECONTROL
: nImageId
= RID_SVXIMG_IMAGECONTROL
; break;
179 case FormComponentType::GRIDCONTROL
: nImageId
= RID_SVXIMG_GRID
; break;
180 case FormComponentType::SCROLLBAR
: nImageId
= RID_SVXIMG_SCROLLBAR
; break;
181 case FormComponentType::SPINBUTTON
: nImageId
= RID_SVXIMG_SPINBUTTON
; break;
182 case FormComponentType::NAVIGATIONBAR
: nImageId
= RID_SVXIMG_NAVIGATIONBAR
; break;
184 DBG_ERROR( "TabOrderDialog::GetImage: unknown control type" );
188 return pImageList
->GetImage( nImageId
);
191 //------------------------------------------------------------------------
192 void TabOrderDialog::FillList()
194 DBG_ASSERT( m_xTempModel
.is() && m_xControlContainer
.is(), "TabOrderDialog::FillList: invalid call!" );
195 if ( !m_xTempModel
.is() || !m_xControlContainer
.is() )
198 aLB_Controls
.Clear();
202 Sequence
< Reference
< XControlModel
> > aControlModels( m_xTempModel
->getControlModels() );
203 const Reference
< XControlModel
>* pControlModels
= aControlModels
.getConstArray();
205 ::rtl::OUString aName
;
208 for ( sal_Int32 i
=0; i
< aControlModels
.getLength(); ++i
, ++pControlModels
)
210 Reference
< XPropertySet
> xControl( *pControlModels
, UNO_QUERY
);
211 Reference
< XPropertySetInfo
> xPI
;
213 xPI
= xControl
->getPropertySetInfo();
217 if ( xPI
->hasPropertyByName( PROPERTY_TABSTOP
) )
219 aName
= ::comphelper::getString( xControl
->getPropertyValue( PROPERTY_NAME
) );
220 // TODO: do Basic controls have a name?
221 aImage
= GetImage( xControl
);
222 aLB_Controls
.InsertEntry( aName
, aImage
, aImage
, 0, sal_False
, LIST_APPEND
, xControl
.get() );
227 // no property set -> no tab order
228 DBG_ERROR( "TabOrderDialog::FillList: invalid control encountered!" );
229 aLB_Controls
.Clear();
234 catch( const Exception
& )
236 DBG_ERROR( "TabOrderDialog::FillList: caught an exception!" );
239 // select first entry
240 SvLBoxEntry
* pFirstEntry
= aLB_Controls
.GetEntry( 0 );
242 aLB_Controls
.Select( pFirstEntry
);
245 //------------------------------------------------------------------------
246 IMPL_LINK( TabOrderDialog
, MoveUpClickHdl
, Button
*, /*pButton*/ )
248 aLB_Controls
.MoveSelection( -1 );
252 //------------------------------------------------------------------------
253 IMPL_LINK( TabOrderDialog
, MoveDownClickHdl
, Button
*, /*pButton*/ )
255 aLB_Controls
.MoveSelection( 1 );
259 //------------------------------------------------------------------------
260 IMPL_LINK( TabOrderDialog
, AutoOrderClickHdl
, Button
*, /*pButton*/ )
264 Reference
< XTabController
> xTabController
;
266 xTabController
= xTabController
.query( m_xORB
->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.FormController" ) ) ) );
267 DBG_ASSERT( xTabController
.is(), "TabOrderDialog::AutoOrderClickHdl: could not instantiate a tab controller!" );
268 if ( !xTabController
.is() )
271 xTabController
->setModel( m_xTempModel
);
272 xTabController
->setContainer( m_xControlContainer
);
273 xTabController
->autoTabOrder();
278 ::comphelper::disposeComponent( xTabController
);
280 catch( const Exception
& )
282 OSL_ENSURE( sal_False
, "TabOrderDialog::AutoOrderClickHdl: caught an exception!" );
288 //------------------------------------------------------------------------
289 IMPL_LINK( TabOrderDialog
, OKClickHdl
, Button
*, /*pButton*/ )
291 ULONG nEntryCount
= aLB_Controls
.GetEntryCount();
292 Sequence
< Reference
< XControlModel
> > aSortedControlModelSeq( nEntryCount
);
293 Sequence
< Reference
< XControlModel
> > aControlModels( m_xTempModel
->getControlModels());
294 Reference
< XControlModel
> * pSortedControlModels
= aSortedControlModelSeq
.getArray();
295 const Reference
< XControlModel
> * pControlModels
= aControlModels
.getConstArray();
297 for (ULONG i
=0; i
< nEntryCount
; i
++)
299 SvLBoxEntry
* pEntry
= aLB_Controls
.GetEntry(i
);
301 for( sal_Int32 j
=0; j
<aControlModels
.getLength(); j
++ )
303 Reference
< XPropertySet
> xSet(pControlModels
[j
], UNO_QUERY
);
304 if ((XPropertySet
*)xSet
.get() == ((XPropertySet
*)pEntry
->GetUserData()))
306 pSortedControlModels
[i
] = pControlModels
[j
];
312 // TODO: UNO action (to bracket all the single actions which are being created)
313 // pDrawModel->BegUndo(PcrRes(RID_STR_UNDO_TABORDER));
314 m_xModel
->setControlModels( aSortedControlModelSeq
);
315 // pDrawModel->EndUndo();
317 EndDialog( sal_True
);
321 //========================================================================
323 //========================================================================
324 DBG_NAME(TabOrderListBox
);
325 //------------------------------------------------------------------------
326 TabOrderListBox::TabOrderListBox( Window
* pParent
, const ResId
& rResId
)
327 :SvTreeListBox( pParent
, rResId
)
329 DBG_CTOR(TabOrderListBox
,NULL
);
330 SetDragDropMode(0xFFFF/*SV_DRAGDROP_CTRL_MOVE*/);
331 // Hmm. The flag alone is not enough, so to be on the safe side ...
333 SetSelectionMode( MULTIPLE_SELECTION
);
336 //------------------------------------------------------------------------
337 TabOrderListBox::~TabOrderListBox()
339 DBG_DTOR(TabOrderListBox
,NULL
);
342 //------------------------------------------------------------------------
343 void TabOrderListBox::ModelHasMoved( SvListEntry
* _pSource
)
345 SvTreeListBox::ModelHasMoved( _pSource
);
347 ((TabOrderDialog
*)Window::GetParent())->SetModified();
350 //------------------------------------------------------------------------
351 void TabOrderListBox::MoveSelection( long nRelPos
)
353 UniString aSelEntryPrevText
,aSelEntryNextText
;
355 for (long i
=0; i
<labs(nRelPos
); i
++)
357 ((TabOrderDialog
*)Window::GetParent())->SetModified();
359 //////////////////////////////////////////////////////////////////////
363 SvLBoxEntry
* pFirstSelected
= FirstSelected();
364 if( !pFirstSelected
) return;
365 ULONG nFirstSelPos
= GetModel()->GetAbsPos( pFirstSelected
);
366 if( nFirstSelPos
== 0 ) return;
368 SvLBoxEntry
* pSelEntry
= pFirstSelected
;
371 ULONG nSelEntryPos
= GetModel()->GetAbsPos( pSelEntry
);
372 SvLBoxEntry
* pSelEntryPrev
= GetEntry( nSelEntryPos
-1 );
373 aSelEntryPrevText
= GetEntryText( pSelEntryPrev
);
374 aImage
= GetExpandedEntryBmp(pSelEntryPrev
);
375 void* pData
= pSelEntryPrev
->GetUserData();
377 GetModel()->Remove( pSelEntryPrev
);
378 InsertEntry( aSelEntryPrevText
, aImage
, aImage
, 0, sal_False
, nSelEntryPos
, pData
);
380 pSelEntry
= NextSelected( pSelEntry
);
384 else if( nRelPos
> 0 )
386 SvLBoxEntry
* pLastSelected
= LastSelected();
387 if( !pLastSelected
) return;
388 ULONG nLastSelPos
= GetModel()->GetAbsPos( pLastSelected
);
390 if( (nLastSelPos
+ nRelPos
- i
) > (GetEntryCount()-1) ) return;
392 #if OSL_DEBUG_LEVEL > 0
393 ULONG nSelCount
= GetSelectionCount();
398 SvLBoxEntry
* pSelEntry
= pLastSelected
;
401 ULONG nSelEntryPos
= GetModel()->GetAbsPos( pSelEntry
);
402 SvLBoxEntry
* pSelEntryNext
= GetEntry( nSelEntryPos
+1 );
403 void* pData
= pSelEntryNext
->GetUserData();
405 aSelEntryNextText
= GetEntryText( pSelEntryNext
);
406 aImage
= GetExpandedEntryBmp(pSelEntryNext
);
408 GetModel()->Remove( pSelEntryNext
);
409 InsertEntry( aSelEntryNextText
, aImage
, aImage
, 0, sal_False
, nSelEntryPos
, pData
);
411 pSelEntry
= PrevSelected( pSelEntry
);
413 long nThumbPos
= GetVScroll()->GetThumbPos();
414 long nVisibleSize
= GetVScroll()->GetVisibleSize();
415 long nFirstVisible
= GetModel()->GetAbsPos( FirstVisible());
417 if ( ( nThumbPos
+ nVisibleSize
+ 1 ) < (long)( nLastSelPos
+ 3 ) )
418 GetVScroll()->DoScrollAction(SCROLL_LINEDOWN
);
419 else if((nThumbPos
+nVisibleSize
+1) >= (nFirstVisible
))
420 GetVScroll()->DoScrollAction(SCROLL_LINEUP
);
425 //............................................................................
427 //............................................................................