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 .
20 #include "taborder.hxx"
21 #include "taborder.hrc"
23 #include "modulepcr.hxx"
24 #include "formresid.hrc"
25 #include "formstrings.hxx"
26 #include <comphelper/types.hxx>
27 #include <comphelper/property.hxx>
28 #include <cppuhelper/implbase1.hxx>
29 #include <com/sun/star/form/FormComponentType.hpp>
30 #include <com/sun/star/form/runtime/FormController.hpp>
31 #include <vcl/scrbar.hxx>
32 #include "svtools/treelistentry.hxx"
34 //............................................................................
37 //............................................................................
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::awt
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::form
;
43 using namespace ::com::sun::star::beans
;
44 using namespace ::com::sun::star::datatransfer
;
46 //========================================================================
48 //========================================================================
49 class OSimpleTabModel
: public ::cppu::WeakImplHelper1
< XTabControllerModel
>
51 Sequence
< Reference
< XControlModel
> > m_aModels
;
54 OSimpleTabModel( const Sequence
< Reference
< XControlModel
> >& _rModels
)
55 :m_aModels( _rModels
)
59 // XTabControllerModel
60 virtual void SAL_CALL
setControlModels(const Sequence
< Reference
< XControlModel
> >& rModels
) throw( RuntimeException
) {m_aModels
= rModels
;}
61 virtual Sequence
< Reference
< XControlModel
> > SAL_CALL
getControlModels(void) throw( RuntimeException
) {return m_aModels
;}
62 virtual void SAL_CALL
setGroup(const Sequence
< Reference
< XControlModel
> >& /*Group*/, const OUString
& /*GroupName*/) throw( RuntimeException
) {}
63 virtual sal_Int32 SAL_CALL
getGroupCount(void) throw( RuntimeException
) {return 0;}
64 virtual void SAL_CALL
getGroup(sal_Int32
/*nGroup*/, Sequence
< Reference
< XControlModel
> >& /*Group*/, OUString
& /*Name*/) throw( RuntimeException
) {}
65 virtual void SAL_CALL
getGroupByName(const OUString
& /*Name*/, Sequence
< Reference
< XControlModel
> >& /*Group*/) throw( RuntimeException
) {}
66 virtual sal_Bool SAL_CALL
getGroupControl(void) throw( RuntimeException
){return sal_False
;} ;
67 virtual void SAL_CALL
setGroupControl(sal_Bool
/*GroupControl*/) throw( RuntimeException
){};
70 //========================================================================
72 //========================================================================
73 DBG_NAME(TabOrderDialog
)
74 //------------------------------------------------------------------------
75 TabOrderDialog::TabOrderDialog( Window
* _pParent
, const Reference
< XTabControllerModel
>& _rxTabModel
,
76 const Reference
< XControlContainer
>& _rxControlCont
, const Reference
< XComponentContext
>& _rxORB
)
77 :ModalDialog( _pParent
, PcrRes( RID_DLG_TABORDER
) )
78 ,m_xModel( _rxTabModel
)
79 ,m_xControlContainer( _rxControlCont
)
81 ,aFT_Controls( this, PcrRes( FT_CONTROLS
) )
82 ,aLB_Controls( this, PcrRes( CTRL_TREE
) )
83 ,aPB_OK( this, PcrRes( PB_OK
) )
84 ,aPB_CANCEL( this, PcrRes( PB_CANCEL
) )
85 ,aPB_HELP( this, PcrRes( PB_HELP
) )
86 ,aPB_MoveUp( this, PcrRes( PB_MOVE_UP
) )
87 ,aPB_MoveDown( this, PcrRes( PB_MOVE_DOWN
) )
88 ,aPB_AutoOrder( this, PcrRes( PB_AUTO_ORDER
) )
91 DBG_CTOR(TabOrderDialog
,NULL
);
93 aPB_MoveUp
.SetClickHdl( LINK( this, TabOrderDialog
, MoveUpClickHdl
) );
94 aPB_MoveDown
.SetClickHdl( LINK( this, TabOrderDialog
, MoveDownClickHdl
) );
95 aPB_AutoOrder
.SetClickHdl( LINK( this, TabOrderDialog
, AutoOrderClickHdl
) );
96 aPB_OK
.SetClickHdl( LINK( this, TabOrderDialog
, OKClickHdl
) );
99 pImageList
= new ImageList( PcrRes( RID_IL_FORMEXPLORER
) );
102 m_xTempModel
= new OSimpleTabModel( m_xModel
->getControlModels() );
104 if ( m_xTempModel
.is() && m_xControlContainer
.is() )
107 if ( aLB_Controls
.GetEntryCount() < 2 )
109 aPB_MoveUp
.Disable();
110 aPB_MoveDown
.Disable();
111 aPB_AutoOrder
.Disable();
117 //------------------------------------------------------------------------
118 void TabOrderDialog::SetModified()
123 //------------------------------------------------------------------------
124 TabOrderDialog::~TabOrderDialog()
127 // delete pLB_Controls;
130 DBG_DTOR(TabOrderDialog
,NULL
);
133 //------------------------------------------------------------------------
134 Image
TabOrderDialog::GetImage( const Reference
< XPropertySet
>& _rxSet
) const
136 sal_uInt16 nImageId
= RID_SVXIMG_CONTROL
;
137 // TODO: classify controls also in Basic propbrw
138 if ( _rxSet
.is() && ::comphelper::hasProperty( PROPERTY_CLASSID
, _rxSet
) )
140 switch( ::comphelper::getINT16( _rxSet
->getPropertyValue( PROPERTY_CLASSID
) ) )
142 case FormComponentType::COMMANDBUTTON
: nImageId
= RID_SVXIMG_BUTTON
; break;
143 case FormComponentType::FIXEDTEXT
: nImageId
= RID_SVXIMG_FIXEDTEXT
; break;
144 case FormComponentType::TEXTFIELD
: nImageId
= RID_SVXIMG_EDIT
; break;
145 case FormComponentType::RADIOBUTTON
: nImageId
= RID_SVXIMG_RADIOBUTTON
; break;
146 case FormComponentType::CHECKBOX
: nImageId
= RID_SVXIMG_CHECKBOX
; break;
147 case FormComponentType::LISTBOX
: nImageId
= RID_SVXIMG_LISTBOX
; break;
148 case FormComponentType::COMBOBOX
: nImageId
= RID_SVXIMG_COMBOBOX
; break;
149 case FormComponentType::GROUPBOX
: nImageId
= RID_SVXIMG_GROUPBOX
; break;
150 case FormComponentType::IMAGEBUTTON
: nImageId
= RID_SVXIMG_IMAGEBUTTON
; break;
151 case FormComponentType::FILECONTROL
: nImageId
= RID_SVXIMG_FILECONTROL
; break;
152 case FormComponentType::HIDDENCONTROL
: nImageId
= RID_SVXIMG_HIDDEN
; break;
153 case FormComponentType::DATEFIELD
: nImageId
= RID_SVXIMG_DATEFIELD
; break;
154 case FormComponentType::TIMEFIELD
: nImageId
= RID_SVXIMG_TIMEFIELD
; break;
155 case FormComponentType::NUMERICFIELD
: nImageId
= RID_SVXIMG_NUMERICFIELD
; break;
156 case FormComponentType::CURRENCYFIELD
: nImageId
= RID_SVXIMG_CURRENCYFIELD
; break;
157 case FormComponentType::PATTERNFIELD
: nImageId
= RID_SVXIMG_PATTERNFIELD
; break;
158 case FormComponentType::IMAGECONTROL
: nImageId
= RID_SVXIMG_IMAGECONTROL
; break;
159 case FormComponentType::GRIDCONTROL
: nImageId
= RID_SVXIMG_GRID
; break;
160 case FormComponentType::SCROLLBAR
: nImageId
= RID_SVXIMG_SCROLLBAR
; break;
161 case FormComponentType::SPINBUTTON
: nImageId
= RID_SVXIMG_SPINBUTTON
; break;
162 case FormComponentType::NAVIGATIONBAR
: nImageId
= RID_SVXIMG_NAVIGATIONBAR
; break;
164 OSL_FAIL( "TabOrderDialog::GetImage: unknown control type" );
168 return pImageList
->GetImage( nImageId
);
171 //------------------------------------------------------------------------
172 void TabOrderDialog::FillList()
174 DBG_ASSERT( m_xTempModel
.is() && m_xControlContainer
.is(), "TabOrderDialog::FillList: invalid call!" );
175 if ( !m_xTempModel
.is() || !m_xControlContainer
.is() )
178 aLB_Controls
.Clear();
182 Sequence
< Reference
< XControlModel
> > aControlModels( m_xTempModel
->getControlModels() );
183 const Reference
< XControlModel
>* pControlModels
= aControlModels
.getConstArray();
188 for ( sal_Int32 i
=0; i
< aControlModels
.getLength(); ++i
, ++pControlModels
)
190 Reference
< XPropertySet
> xControl( *pControlModels
, UNO_QUERY
);
191 Reference
< XPropertySetInfo
> xPI
;
193 xPI
= xControl
->getPropertySetInfo();
197 if ( xPI
->hasPropertyByName( PROPERTY_TABSTOP
) )
199 aName
= ::comphelper::getString( xControl
->getPropertyValue( PROPERTY_NAME
) );
200 // TODO: do Basic controls have a name?
201 aImage
= GetImage( xControl
);
202 aLB_Controls
.InsertEntry( aName
, aImage
, aImage
, 0, sal_False
, LIST_APPEND
, xControl
.get() );
207 // no property set -> no tab order
208 OSL_FAIL( "TabOrderDialog::FillList: invalid control encountered!" );
209 aLB_Controls
.Clear();
214 catch( const Exception
& )
216 OSL_FAIL( "TabOrderDialog::FillList: caught an exception!" );
219 // select first entry
220 SvTreeListEntry
* pFirstEntry
= aLB_Controls
.GetEntry( 0 );
222 aLB_Controls
.Select( pFirstEntry
);
225 //------------------------------------------------------------------------
226 IMPL_LINK( TabOrderDialog
, MoveUpClickHdl
, Button
*, /*pButton*/ )
228 aLB_Controls
.MoveSelection( -1 );
232 //------------------------------------------------------------------------
233 IMPL_LINK( TabOrderDialog
, MoveDownClickHdl
, Button
*, /*pButton*/ )
235 aLB_Controls
.MoveSelection( 1 );
239 //------------------------------------------------------------------------
240 IMPL_LINK( TabOrderDialog
, AutoOrderClickHdl
, Button
*, /*pButton*/ )
244 Reference
< css::form::runtime::XFormController
> xTabController
= css::form::runtime::FormController::create( m_xORB
);
246 xTabController
->setModel( m_xTempModel
);
247 xTabController
->setContainer( m_xControlContainer
);
248 xTabController
->autoTabOrder();
253 ::comphelper::disposeComponent( xTabController
);
255 catch( const Exception
& )
257 OSL_FAIL( "TabOrderDialog::AutoOrderClickHdl: caught an exception!" );
263 //------------------------------------------------------------------------
264 IMPL_LINK( TabOrderDialog
, OKClickHdl
, Button
*, /*pButton*/ )
266 sal_uLong nEntryCount
= aLB_Controls
.GetEntryCount();
267 Sequence
< Reference
< XControlModel
> > aSortedControlModelSeq( nEntryCount
);
268 Sequence
< Reference
< XControlModel
> > aControlModels( m_xTempModel
->getControlModels());
269 Reference
< XControlModel
> * pSortedControlModels
= aSortedControlModelSeq
.getArray();
270 const Reference
< XControlModel
> * pControlModels
= aControlModels
.getConstArray();
272 for (sal_uLong i
=0; i
< nEntryCount
; i
++)
274 SvTreeListEntry
* pEntry
= aLB_Controls
.GetEntry(i
);
276 for( sal_Int32 j
=0; j
<aControlModels
.getLength(); j
++ )
278 Reference
< XPropertySet
> xSet(pControlModels
[j
], UNO_QUERY
);
279 if ((XPropertySet
*)xSet
.get() == ((XPropertySet
*)pEntry
->GetUserData()))
281 pSortedControlModels
[i
] = pControlModels
[j
];
287 // TODO: UNO action (to bracket all the single actions which are being created)
288 m_xModel
->setControlModels( aSortedControlModelSeq
);
290 EndDialog( sal_True
);
294 //========================================================================
296 //========================================================================
297 DBG_NAME(TabOrderListBox
);
298 //------------------------------------------------------------------------
299 TabOrderListBox::TabOrderListBox( Window
* pParent
, const ResId
& rResId
)
300 :SvTreeListBox( pParent
, rResId
)
302 DBG_CTOR(TabOrderListBox
,NULL
);
303 SetDragDropMode(0xFFFF/*SV_DRAGDROP_CTRL_MOVE*/);
304 // Hmm. The flag alone is not enough, so to be on the safe side ...
306 SetSelectionMode( MULTIPLE_SELECTION
);
309 //------------------------------------------------------------------------
310 TabOrderListBox::~TabOrderListBox()
312 DBG_DTOR(TabOrderListBox
,NULL
);
315 //------------------------------------------------------------------------
316 void TabOrderListBox::ModelHasMoved( SvTreeListEntry
* _pSource
)
318 SvTreeListBox::ModelHasMoved( _pSource
);
320 ((TabOrderDialog
*)GetParentDialog())->SetModified();
323 //------------------------------------------------------------------------
324 void TabOrderListBox::MoveSelection( long nRelPos
)
326 OUString aSelEntryPrevText
, aSelEntryNextText
;
328 for (long i
=0; i
<labs(nRelPos
); i
++)
330 ((TabOrderDialog
*)GetParentDialog())->SetModified();
332 //////////////////////////////////////////////////////////////////////
336 SvTreeListEntry
* pFirstSelected
= FirstSelected();
337 if( !pFirstSelected
) return;
338 sal_uLong nFirstSelPos
= GetModel()->GetAbsPos( pFirstSelected
);
339 if( nFirstSelPos
== 0 ) return;
341 SvTreeListEntry
* pSelEntry
= pFirstSelected
;
344 sal_uLong nSelEntryPos
= GetModel()->GetAbsPos( pSelEntry
);
345 SvTreeListEntry
* pSelEntryPrev
= GetEntry( nSelEntryPos
-1 );
346 aSelEntryPrevText
= GetEntryText( pSelEntryPrev
);
347 aImage
= GetExpandedEntryBmp(pSelEntryPrev
);
348 void* pData
= pSelEntryPrev
->GetUserData();
350 GetModel()->Remove( pSelEntryPrev
);
351 InsertEntry( aSelEntryPrevText
, aImage
, aImage
, 0, sal_False
, nSelEntryPos
, pData
);
353 pSelEntry
= NextSelected( pSelEntry
);
357 else if( nRelPos
> 0 )
359 SvTreeListEntry
* pLastSelected
= LastSelected();
360 if( !pLastSelected
) return;
361 sal_uLong nLastSelPos
= GetModel()->GetAbsPos( pLastSelected
);
363 if( (nLastSelPos
+ nRelPos
- i
) > (GetEntryCount()-1) ) return;
365 #if OSL_DEBUG_LEVEL > 0
366 sal_uLong nSelCount
= GetSelectionCount();
371 SvTreeListEntry
* pSelEntry
= pLastSelected
;
374 sal_uLong nSelEntryPos
= GetModel()->GetAbsPos( pSelEntry
);
375 SvTreeListEntry
* pSelEntryNext
= GetEntry( nSelEntryPos
+1 );
376 void* pData
= pSelEntryNext
->GetUserData();
378 aSelEntryNextText
= GetEntryText( pSelEntryNext
);
379 aImage
= GetExpandedEntryBmp(pSelEntryNext
);
381 GetModel()->Remove( pSelEntryNext
);
382 InsertEntry( aSelEntryNextText
, aImage
, aImage
, 0, sal_False
, nSelEntryPos
, pData
);
384 pSelEntry
= PrevSelected( pSelEntry
);
386 long nThumbPos
= GetVScroll()->GetThumbPos();
387 long nVisibleSize
= GetVScroll()->GetVisibleSize();
388 long nFirstVisible
= GetModel()->GetAbsPos( FirstVisible());
390 if ( ( nThumbPos
+ nVisibleSize
+ 1 ) < (long)( nLastSelPos
+ 3 ) )
391 GetVScroll()->DoScrollAction(SCROLL_LINEDOWN
);
392 else if((nThumbPos
+nVisibleSize
+1) >= (nFirstVisible
))
393 GetVScroll()->DoScrollAction(SCROLL_LINEUP
);
398 //............................................................................
400 //............................................................................
402 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */