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