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