masterfix DEV300: #i10000# build fix
[LibreOffice.git] / extensions / source / propctrlr / taborder.cxx
blobc3e0268bbc7a4481fb8aaa5040c5de53faece2b0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "taborder.hxx"
31 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_TABORDER_HRC
32 #include "taborder.hrc"
33 #endif
35 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
36 #include "modulepcr.hxx"
37 #endif
38 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_
39 #include "formresid.hrc"
40 #endif
41 #include "formstrings.hxx"
42 #include <comphelper/types.hxx>
43 #include <comphelper/property.hxx>
44 #include <cppuhelper/implbase1.hxx>
45 #include <com/sun/star/form/FormComponentType.hpp>
46 #include <com/sun/star/awt/XTabController.hpp>
47 #include <vcl/scrbar.hxx>
49 //............................................................................
50 namespace pcr
52 //............................................................................
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::awt;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::form;
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::datatransfer;
61 //========================================================================
62 //= OSimpleTabModel
63 //========================================================================
64 class OSimpleTabModel : public ::cppu::WeakImplHelper1< XTabControllerModel>
66 Sequence< Reference< XControlModel > > m_aModels;
68 public:
69 OSimpleTabModel( const Sequence< Reference< XControlModel > >& _rModels )
70 :m_aModels( _rModels )
74 // XTabControllerModel
75 virtual void SAL_CALL setControlModels(const Sequence< Reference< XControlModel > >& rModels) throw( RuntimeException ) {m_aModels = rModels;}
76 virtual Sequence< Reference< XControlModel > > SAL_CALL getControlModels(void) throw( RuntimeException ) {return m_aModels;}
77 virtual void SAL_CALL setGroup(const Sequence< Reference< XControlModel > >& /*Group*/, const ::rtl::OUString& /*GroupName*/) throw( RuntimeException ) {}
78 virtual sal_Int32 SAL_CALL getGroupCount(void) throw( RuntimeException ) {return 0;}
79 virtual void SAL_CALL getGroup(sal_Int32 /*nGroup*/, Sequence< Reference< XControlModel > >& /*Group*/, ::rtl::OUString& /*Name*/) throw( RuntimeException ) {}
80 virtual void SAL_CALL getGroupByName(const ::rtl::OUString& /*Name*/, Sequence< Reference< XControlModel > >& /*Group*/) throw( RuntimeException ) {}
81 virtual sal_Bool SAL_CALL getGroupControl(void) throw( RuntimeException ){return sal_False;} ;
82 virtual void SAL_CALL setGroupControl(sal_Bool /*GroupControl*/) throw( RuntimeException ){};
85 //========================================================================
86 //= TabOrderDialog
87 //========================================================================
88 DBG_NAME(TabOrderDialog)
89 //------------------------------------------------------------------------
90 TabOrderDialog::TabOrderDialog( Window* _pParent, const Reference< XTabControllerModel >& _rxTabModel,
91 const Reference< XControlContainer >& _rxControlCont, const Reference< XMultiServiceFactory >& _rxORB )
92 :ModalDialog( _pParent, PcrRes( RID_DLG_TABORDER ) )
93 ,m_xModel( _rxTabModel )
94 ,m_xControlContainer( _rxControlCont )
95 ,m_xORB( _rxORB )
96 ,aFT_Controls( this, PcrRes( FT_CONTROLS ) )
97 ,aLB_Controls( this, PcrRes( CTRL_TREE ) )
98 ,aPB_OK( this, PcrRes( PB_OK ) )
99 ,aPB_CANCEL( this, PcrRes( PB_CANCEL ) )
100 ,aPB_HELP( this, PcrRes( PB_HELP ) )
101 ,aPB_MoveUp( this, PcrRes( PB_MOVE_UP ) )
102 ,aPB_MoveDown( this, PcrRes( PB_MOVE_DOWN ) )
103 ,aPB_AutoOrder( this, PcrRes( PB_AUTO_ORDER ) )
104 ,pImageList( NULL )
106 DBG_CTOR(TabOrderDialog,NULL);
108 aPB_MoveUp.SetClickHdl( LINK( this, TabOrderDialog, MoveUpClickHdl ) );
109 aPB_MoveDown.SetClickHdl( LINK( this, TabOrderDialog, MoveDownClickHdl ) );
110 aPB_AutoOrder.SetClickHdl( LINK( this, TabOrderDialog, AutoOrderClickHdl ) );
111 aPB_OK.SetClickHdl( LINK( this, TabOrderDialog, OKClickHdl ) );
112 aPB_OK.Disable();
114 sal_Bool bIsHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
115 pImageList = new ImageList( PcrRes( bIsHighContrast ? RID_IL_FORMEXPLORER_HC : RID_IL_FORMEXPLORER ) );
118 if ( m_xModel.is() )
119 m_xTempModel = new OSimpleTabModel( m_xModel->getControlModels() );
121 if ( m_xTempModel.is() && m_xControlContainer.is() )
122 FillList();
124 if ( aLB_Controls.GetEntryCount() < 2 )
126 aPB_MoveUp.Disable();
127 aPB_MoveDown.Disable();
128 aPB_AutoOrder.Disable();
131 FreeResource();
134 //------------------------------------------------------------------------
135 void TabOrderDialog::SetModified()
137 aPB_OK.Enable();
140 //------------------------------------------------------------------------
141 TabOrderDialog::~TabOrderDialog()
143 aLB_Controls.Hide();
144 // delete pLB_Controls;
145 delete pImageList;
147 DBG_DTOR(TabOrderDialog,NULL);
150 //------------------------------------------------------------------------
151 Image TabOrderDialog::GetImage( const Reference< XPropertySet >& _rxSet ) const
153 sal_uInt16 nImageId = RID_SVXIMG_CONTROL;
154 // TODO: classify controls also in Basic propbrw
155 if ( _rxSet.is() && ::comphelper::hasProperty( PROPERTY_CLASSID, _rxSet ) )
157 switch( ::comphelper::getINT16( _rxSet->getPropertyValue( PROPERTY_CLASSID ) ) )
159 case FormComponentType::COMMANDBUTTON: nImageId = RID_SVXIMG_BUTTON; break;
160 case FormComponentType::FIXEDTEXT: nImageId = RID_SVXIMG_FIXEDTEXT; break;
161 case FormComponentType::TEXTFIELD: nImageId = RID_SVXIMG_EDIT; break;
162 case FormComponentType::RADIOBUTTON: nImageId = RID_SVXIMG_RADIOBUTTON; break;
163 case FormComponentType::CHECKBOX: nImageId = RID_SVXIMG_CHECKBOX; break;
164 case FormComponentType::LISTBOX: nImageId = RID_SVXIMG_LISTBOX; break;
165 case FormComponentType::COMBOBOX: nImageId = RID_SVXIMG_COMBOBOX; break;
166 case FormComponentType::GROUPBOX: nImageId = RID_SVXIMG_GROUPBOX; break;
167 case FormComponentType::IMAGEBUTTON: nImageId = RID_SVXIMG_IMAGEBUTTON; break;
168 case FormComponentType::FILECONTROL: nImageId = RID_SVXIMG_FILECONTROL; break;
169 case FormComponentType::HIDDENCONTROL: nImageId = RID_SVXIMG_HIDDEN; break;
170 case FormComponentType::DATEFIELD: nImageId = RID_SVXIMG_DATEFIELD; break;
171 case FormComponentType::TIMEFIELD: nImageId = RID_SVXIMG_TIMEFIELD; break;
172 case FormComponentType::NUMERICFIELD: nImageId = RID_SVXIMG_NUMERICFIELD; break;
173 case FormComponentType::CURRENCYFIELD: nImageId = RID_SVXIMG_CURRENCYFIELD; break;
174 case FormComponentType::PATTERNFIELD: nImageId = RID_SVXIMG_PATTERNFIELD; break;
175 case FormComponentType::IMAGECONTROL: nImageId = RID_SVXIMG_IMAGECONTROL; break;
176 case FormComponentType::GRIDCONTROL: nImageId = RID_SVXIMG_GRID; break;
177 case FormComponentType::SCROLLBAR: nImageId = RID_SVXIMG_SCROLLBAR; break;
178 case FormComponentType::SPINBUTTON: nImageId = RID_SVXIMG_SPINBUTTON; break;
179 case FormComponentType::NAVIGATIONBAR: nImageId = RID_SVXIMG_NAVIGATIONBAR; break;
180 default:
181 DBG_ERROR( "TabOrderDialog::GetImage: unknown control type" );
185 return pImageList->GetImage( nImageId );
188 //------------------------------------------------------------------------
189 void TabOrderDialog::FillList()
191 DBG_ASSERT( m_xTempModel.is() && m_xControlContainer.is(), "TabOrderDialog::FillList: invalid call!" );
192 if ( !m_xTempModel.is() || !m_xControlContainer.is() )
193 return;
195 aLB_Controls.Clear();
199 Sequence< Reference< XControlModel > > aControlModels( m_xTempModel->getControlModels() );
200 const Reference< XControlModel >* pControlModels = aControlModels.getConstArray();
202 ::rtl::OUString aName;
203 Image aImage;
205 for ( sal_Int32 i=0; i < aControlModels.getLength(); ++i, ++pControlModels )
207 Reference< XPropertySet > xControl( *pControlModels, UNO_QUERY );
208 Reference< XPropertySetInfo > xPI;
209 if ( xControl.is() )
210 xPI = xControl->getPropertySetInfo();
212 if ( xPI.is() )
214 if ( xPI->hasPropertyByName( PROPERTY_TABSTOP ) )
216 aName = ::comphelper::getString( xControl->getPropertyValue( PROPERTY_NAME ) );
217 // TODO: do Basic controls have a name?
218 aImage = GetImage( xControl );
219 aLB_Controls.InsertEntry( aName, aImage, aImage, 0, sal_False, LIST_APPEND, xControl.get() );
222 else
224 // no property set -> no tab order
225 DBG_ERROR( "TabOrderDialog::FillList: invalid control encountered!" );
226 aLB_Controls.Clear();
227 break;
231 catch( const Exception& )
233 DBG_ERROR( "TabOrderDialog::FillList: caught an exception!" );
236 // select first entry
237 SvLBoxEntry* pFirstEntry = aLB_Controls.GetEntry( 0 );
238 if ( pFirstEntry )
239 aLB_Controls.Select( pFirstEntry );
242 //------------------------------------------------------------------------
243 IMPL_LINK( TabOrderDialog, MoveUpClickHdl, Button*, /*pButton*/ )
245 aLB_Controls.MoveSelection( -1 );
246 return 0;
249 //------------------------------------------------------------------------
250 IMPL_LINK( TabOrderDialog, MoveDownClickHdl, Button*, /*pButton*/ )
252 aLB_Controls.MoveSelection( 1 );
253 return 0;
256 //------------------------------------------------------------------------
257 IMPL_LINK( TabOrderDialog, AutoOrderClickHdl, Button*, /*pButton*/ )
261 Reference< XTabController > xTabController;
262 if ( m_xORB.is() )
263 xTabController = xTabController.query( m_xORB->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.FormController" ) ) ) );
264 DBG_ASSERT( xTabController.is(), "TabOrderDialog::AutoOrderClickHdl: could not instantiate a tab controller!" );
265 if ( !xTabController.is() )
266 return 0;
268 xTabController->setModel( m_xTempModel );
269 xTabController->setContainer( m_xControlContainer );
270 xTabController->autoTabOrder();
272 SetModified();
273 FillList();
275 ::comphelper::disposeComponent( xTabController );
277 catch( const Exception& )
279 OSL_ENSURE( sal_False, "TabOrderDialog::AutoOrderClickHdl: caught an exception!" );
282 return 0;
285 //------------------------------------------------------------------------
286 IMPL_LINK( TabOrderDialog, OKClickHdl, Button*, /*pButton*/ )
288 sal_uLong nEntryCount = aLB_Controls.GetEntryCount();
289 Sequence< Reference< XControlModel > > aSortedControlModelSeq( nEntryCount );
290 Sequence< Reference< XControlModel > > aControlModels( m_xTempModel->getControlModels());
291 Reference< XControlModel > * pSortedControlModels = aSortedControlModelSeq.getArray();
292 const Reference< XControlModel > * pControlModels = aControlModels.getConstArray();
294 for (sal_uLong i=0; i < nEntryCount; i++)
296 SvLBoxEntry* pEntry = aLB_Controls.GetEntry(i);
298 for( sal_Int32 j=0; j<aControlModels.getLength(); j++ )
300 Reference< XPropertySet > xSet(pControlModels[j], UNO_QUERY);
301 if ((XPropertySet*)xSet.get() == ((XPropertySet*)pEntry->GetUserData()))
303 pSortedControlModels[i] = pControlModels[j];
304 break;
309 // TODO: UNO action (to bracket all the single actions which are being created)
310 // pDrawModel->BegUndo(PcrRes(RID_STR_UNDO_TABORDER));
311 m_xModel->setControlModels( aSortedControlModelSeq );
312 // pDrawModel->EndUndo();
314 EndDialog( sal_True );
315 return 0;
318 //========================================================================
319 //= TabOrderListBox
320 //========================================================================
321 DBG_NAME(TabOrderListBox);
322 //------------------------------------------------------------------------
323 TabOrderListBox::TabOrderListBox( Window* pParent, const ResId& rResId )
324 :SvTreeListBox( pParent, rResId )
326 DBG_CTOR(TabOrderListBox,NULL);
327 SetDragDropMode(0xFFFF/*SV_DRAGDROP_CTRL_MOVE*/);
328 // Hmm. The flag alone is not enough, so to be on the safe side ...
330 SetSelectionMode( MULTIPLE_SELECTION );
333 //------------------------------------------------------------------------
334 TabOrderListBox::~TabOrderListBox()
336 DBG_DTOR(TabOrderListBox,NULL);
339 //------------------------------------------------------------------------
340 void TabOrderListBox::ModelHasMoved( SvListEntry* _pSource )
342 SvTreeListBox::ModelHasMoved( _pSource );
344 ((TabOrderDialog*)Window::GetParent())->SetModified();
347 //------------------------------------------------------------------------
348 void TabOrderListBox::MoveSelection( long nRelPos )
350 UniString aSelEntryPrevText,aSelEntryNextText;
351 Image aImage;
352 for (long i=0; i<labs(nRelPos); i++)
354 ((TabOrderDialog*)Window::GetParent())->SetModified();
356 //////////////////////////////////////////////////////////////////////
357 // move entries
358 if( nRelPos < 0 )
360 SvLBoxEntry* pFirstSelected = FirstSelected();
361 if( !pFirstSelected ) return;
362 sal_uLong nFirstSelPos = GetModel()->GetAbsPos( pFirstSelected );
363 if( nFirstSelPos == 0 ) return;
365 SvLBoxEntry* pSelEntry = pFirstSelected;
366 while( pSelEntry )
368 sal_uLong nSelEntryPos = GetModel()->GetAbsPos( pSelEntry );
369 SvLBoxEntry* pSelEntryPrev = GetEntry( nSelEntryPos-1 );
370 aSelEntryPrevText = GetEntryText( pSelEntryPrev );
371 aImage = GetExpandedEntryBmp(pSelEntryPrev);
372 void* pData = pSelEntryPrev->GetUserData();
374 GetModel()->Remove( pSelEntryPrev );
375 InsertEntry( aSelEntryPrevText, aImage, aImage, 0, sal_False, nSelEntryPos, pData );
377 pSelEntry = NextSelected( pSelEntry );
381 else if( nRelPos > 0 )
383 SvLBoxEntry* pLastSelected = LastSelected();
384 if( !pLastSelected ) return;
385 sal_uLong nLastSelPos = GetModel()->GetAbsPos( pLastSelected );
387 if( (nLastSelPos + nRelPos - i) > (GetEntryCount()-1) ) return;
389 #if OSL_DEBUG_LEVEL > 0
390 sal_uLong nSelCount = GetSelectionCount();
391 (void)nSelCount;
392 #endif
395 SvLBoxEntry* pSelEntry = pLastSelected;
396 while( pSelEntry )
398 sal_uLong nSelEntryPos = GetModel()->GetAbsPos( pSelEntry );
399 SvLBoxEntry* pSelEntryNext = GetEntry( nSelEntryPos+1 );
400 void* pData = pSelEntryNext->GetUserData();
402 aSelEntryNextText = GetEntryText( pSelEntryNext );
403 aImage = GetExpandedEntryBmp(pSelEntryNext);
405 GetModel()->Remove( pSelEntryNext );
406 InsertEntry( aSelEntryNextText, aImage, aImage, 0, sal_False, nSelEntryPos, pData );
408 pSelEntry = PrevSelected( pSelEntry );
410 long nThumbPos = GetVScroll()->GetThumbPos();
411 long nVisibleSize = GetVScroll()->GetVisibleSize();
412 long nFirstVisible = GetModel()->GetAbsPos( FirstVisible());
414 if ( ( nThumbPos + nVisibleSize + 1 ) < (long)( nLastSelPos + 3 ) )
415 GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
416 else if((nThumbPos+nVisibleSize+1) >= (nFirstVisible))
417 GetVScroll()->DoScrollAction(SCROLL_LINEUP);
422 //............................................................................
423 } // namespace pcr
424 //............................................................................