Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "taborder.hxx"
21 : #include "taborder.hrc"
22 :
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"
33 :
34 : //............................................................................
35 : namespace pcr
36 : {
37 : //............................................................................
38 :
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;
45 :
46 : //========================================================================
47 : //= OSimpleTabModel
48 : //========================================================================
49 0 : class OSimpleTabModel : public ::cppu::WeakImplHelper1< XTabControllerModel>
50 : {
51 : Sequence< Reference< XControlModel > > m_aModels;
52 :
53 : public:
54 0 : OSimpleTabModel( const Sequence< Reference< XControlModel > >& _rModels )
55 0 : :m_aModels( _rModels )
56 : {
57 0 : }
58 :
59 : // XTabControllerModel
60 0 : virtual void SAL_CALL setControlModels(const Sequence< Reference< XControlModel > >& rModels) throw( RuntimeException ) {m_aModels = rModels;}
61 0 : virtual Sequence< Reference< XControlModel > > SAL_CALL getControlModels(void) throw( RuntimeException ) {return m_aModels;}
62 0 : virtual void SAL_CALL setGroup(const Sequence< Reference< XControlModel > >& /*Group*/, const OUString& /*GroupName*/) throw( RuntimeException ) {}
63 0 : virtual sal_Int32 SAL_CALL getGroupCount(void) throw( RuntimeException ) {return 0;}
64 0 : virtual void SAL_CALL getGroup(sal_Int32 /*nGroup*/, Sequence< Reference< XControlModel > >& /*Group*/, OUString& /*Name*/) throw( RuntimeException ) {}
65 0 : virtual void SAL_CALL getGroupByName(const OUString& /*Name*/, Sequence< Reference< XControlModel > >& /*Group*/) throw( RuntimeException ) {}
66 0 : virtual sal_Bool SAL_CALL getGroupControl(void) throw( RuntimeException ){return sal_False;} ;
67 0 : virtual void SAL_CALL setGroupControl(sal_Bool /*GroupControl*/) throw( RuntimeException ){};
68 : };
69 :
70 : //========================================================================
71 : //= TabOrderDialog
72 : //========================================================================
73 : DBG_NAME(TabOrderDialog)
74 : //------------------------------------------------------------------------
75 0 : 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 )
80 : ,m_xORB( _rxORB )
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 ) )
89 0 : ,pImageList( NULL )
90 : {
91 : DBG_CTOR(TabOrderDialog,NULL);
92 :
93 0 : aPB_MoveUp.SetClickHdl( LINK( this, TabOrderDialog, MoveUpClickHdl ) );
94 0 : aPB_MoveDown.SetClickHdl( LINK( this, TabOrderDialog, MoveDownClickHdl ) );
95 0 : aPB_AutoOrder.SetClickHdl( LINK( this, TabOrderDialog, AutoOrderClickHdl ) );
96 0 : aPB_OK.SetClickHdl( LINK( this, TabOrderDialog, OKClickHdl ) );
97 0 : aPB_OK.Disable();
98 :
99 0 : pImageList = new ImageList( PcrRes( RID_IL_FORMEXPLORER ) );
100 :
101 0 : if ( m_xModel.is() )
102 0 : m_xTempModel = new OSimpleTabModel( m_xModel->getControlModels() );
103 :
104 0 : if ( m_xTempModel.is() && m_xControlContainer.is() )
105 0 : FillList();
106 :
107 0 : if ( aLB_Controls.GetEntryCount() < 2 )
108 : {
109 0 : aPB_MoveUp.Disable();
110 0 : aPB_MoveDown.Disable();
111 0 : aPB_AutoOrder.Disable();
112 : }
113 :
114 0 : FreeResource();
115 0 : }
116 :
117 : //------------------------------------------------------------------------
118 0 : void TabOrderDialog::SetModified()
119 : {
120 0 : aPB_OK.Enable();
121 0 : }
122 :
123 : //------------------------------------------------------------------------
124 0 : TabOrderDialog::~TabOrderDialog()
125 : {
126 0 : aLB_Controls.Hide();
127 : // delete pLB_Controls;
128 0 : delete pImageList;
129 :
130 : DBG_DTOR(TabOrderDialog,NULL);
131 0 : }
132 :
133 : //------------------------------------------------------------------------
134 0 : Image TabOrderDialog::GetImage( const Reference< XPropertySet >& _rxSet ) const
135 : {
136 0 : sal_uInt16 nImageId = RID_SVXIMG_CONTROL;
137 : // TODO: classify controls also in Basic propbrw
138 0 : if ( _rxSet.is() && ::comphelper::hasProperty( PROPERTY_CLASSID, _rxSet ) )
139 : {
140 0 : switch( ::comphelper::getINT16( _rxSet->getPropertyValue( PROPERTY_CLASSID ) ) )
141 : {
142 0 : case FormComponentType::COMMANDBUTTON: nImageId = RID_SVXIMG_BUTTON; break;
143 0 : case FormComponentType::FIXEDTEXT: nImageId = RID_SVXIMG_FIXEDTEXT; break;
144 0 : case FormComponentType::TEXTFIELD: nImageId = RID_SVXIMG_EDIT; break;
145 0 : case FormComponentType::RADIOBUTTON: nImageId = RID_SVXIMG_RADIOBUTTON; break;
146 0 : case FormComponentType::CHECKBOX: nImageId = RID_SVXIMG_CHECKBOX; break;
147 0 : case FormComponentType::LISTBOX: nImageId = RID_SVXIMG_LISTBOX; break;
148 0 : case FormComponentType::COMBOBOX: nImageId = RID_SVXIMG_COMBOBOX; break;
149 0 : case FormComponentType::GROUPBOX: nImageId = RID_SVXIMG_GROUPBOX; break;
150 0 : case FormComponentType::IMAGEBUTTON: nImageId = RID_SVXIMG_IMAGEBUTTON; break;
151 0 : case FormComponentType::FILECONTROL: nImageId = RID_SVXIMG_FILECONTROL; break;
152 0 : case FormComponentType::HIDDENCONTROL: nImageId = RID_SVXIMG_HIDDEN; break;
153 0 : case FormComponentType::DATEFIELD: nImageId = RID_SVXIMG_DATEFIELD; break;
154 0 : case FormComponentType::TIMEFIELD: nImageId = RID_SVXIMG_TIMEFIELD; break;
155 0 : case FormComponentType::NUMERICFIELD: nImageId = RID_SVXIMG_NUMERICFIELD; break;
156 0 : case FormComponentType::CURRENCYFIELD: nImageId = RID_SVXIMG_CURRENCYFIELD; break;
157 0 : case FormComponentType::PATTERNFIELD: nImageId = RID_SVXIMG_PATTERNFIELD; break;
158 0 : case FormComponentType::IMAGECONTROL: nImageId = RID_SVXIMG_IMAGECONTROL; break;
159 0 : case FormComponentType::GRIDCONTROL: nImageId = RID_SVXIMG_GRID; break;
160 0 : case FormComponentType::SCROLLBAR: nImageId = RID_SVXIMG_SCROLLBAR; break;
161 0 : case FormComponentType::SPINBUTTON: nImageId = RID_SVXIMG_SPINBUTTON; break;
162 0 : case FormComponentType::NAVIGATIONBAR: nImageId = RID_SVXIMG_NAVIGATIONBAR; break;
163 : default:
164 : OSL_FAIL( "TabOrderDialog::GetImage: unknown control type" );
165 : }
166 : }
167 :
168 0 : return pImageList->GetImage( nImageId );
169 : }
170 :
171 : //------------------------------------------------------------------------
172 0 : void TabOrderDialog::FillList()
173 : {
174 : DBG_ASSERT( m_xTempModel.is() && m_xControlContainer.is(), "TabOrderDialog::FillList: invalid call!" );
175 0 : if ( !m_xTempModel.is() || !m_xControlContainer.is() )
176 0 : return;
177 :
178 0 : aLB_Controls.Clear();
179 :
180 : try
181 : {
182 0 : Sequence< Reference< XControlModel > > aControlModels( m_xTempModel->getControlModels() );
183 0 : const Reference< XControlModel >* pControlModels = aControlModels.getConstArray();
184 :
185 0 : OUString aName;
186 0 : Image aImage;
187 :
188 0 : for ( sal_Int32 i=0; i < aControlModels.getLength(); ++i, ++pControlModels )
189 : {
190 0 : Reference< XPropertySet > xControl( *pControlModels, UNO_QUERY );
191 0 : Reference< XPropertySetInfo > xPI;
192 0 : if ( xControl.is() )
193 0 : xPI = xControl->getPropertySetInfo();
194 :
195 0 : if ( xPI.is() )
196 : {
197 0 : if ( xPI->hasPropertyByName( PROPERTY_TABSTOP ) )
198 : {
199 0 : aName = ::comphelper::getString( xControl->getPropertyValue( PROPERTY_NAME ) );
200 : // TODO: do Basic controls have a name?
201 0 : aImage = GetImage( xControl );
202 0 : aLB_Controls.InsertEntry( aName, aImage, aImage, 0, sal_False, LIST_APPEND, xControl.get() );
203 : }
204 : }
205 : else
206 : {
207 : // no property set -> no tab order
208 : OSL_FAIL( "TabOrderDialog::FillList: invalid control encountered!" );
209 0 : aLB_Controls.Clear();
210 0 : break;
211 : }
212 0 : }
213 : }
214 0 : catch( const Exception& )
215 : {
216 : OSL_FAIL( "TabOrderDialog::FillList: caught an exception!" );
217 : }
218 :
219 : // select first entry
220 0 : SvTreeListEntry* pFirstEntry = aLB_Controls.GetEntry( 0 );
221 0 : if ( pFirstEntry )
222 0 : aLB_Controls.Select( pFirstEntry );
223 : }
224 :
225 : //------------------------------------------------------------------------
226 0 : IMPL_LINK( TabOrderDialog, MoveUpClickHdl, Button*, /*pButton*/ )
227 : {
228 0 : aLB_Controls.MoveSelection( -1 );
229 0 : return 0;
230 : }
231 :
232 : //------------------------------------------------------------------------
233 0 : IMPL_LINK( TabOrderDialog, MoveDownClickHdl, Button*, /*pButton*/ )
234 : {
235 0 : aLB_Controls.MoveSelection( 1 );
236 0 : return 0;
237 : }
238 :
239 : //------------------------------------------------------------------------
240 0 : IMPL_LINK( TabOrderDialog, AutoOrderClickHdl, Button*, /*pButton*/ )
241 : {
242 : try
243 : {
244 0 : Reference< css::form::runtime::XFormController > xTabController = css::form::runtime::FormController::create( m_xORB );
245 :
246 0 : xTabController->setModel( m_xTempModel );
247 0 : xTabController->setContainer( m_xControlContainer );
248 0 : xTabController->autoTabOrder();
249 :
250 0 : SetModified();
251 0 : FillList();
252 :
253 0 : ::comphelper::disposeComponent( xTabController );
254 : }
255 0 : catch( const Exception& )
256 : {
257 : OSL_FAIL( "TabOrderDialog::AutoOrderClickHdl: caught an exception!" );
258 : }
259 :
260 0 : return 0;
261 : }
262 :
263 : //------------------------------------------------------------------------
264 0 : IMPL_LINK( TabOrderDialog, OKClickHdl, Button*, /*pButton*/ )
265 : {
266 0 : sal_uLong nEntryCount = aLB_Controls.GetEntryCount();
267 0 : Sequence< Reference< XControlModel > > aSortedControlModelSeq( nEntryCount );
268 0 : Sequence< Reference< XControlModel > > aControlModels( m_xTempModel->getControlModels());
269 0 : Reference< XControlModel > * pSortedControlModels = aSortedControlModelSeq.getArray();
270 0 : const Reference< XControlModel > * pControlModels = aControlModels.getConstArray();
271 :
272 0 : for (sal_uLong i=0; i < nEntryCount; i++)
273 : {
274 0 : SvTreeListEntry* pEntry = aLB_Controls.GetEntry(i);
275 :
276 0 : for( sal_Int32 j=0; j<aControlModels.getLength(); j++ )
277 : {
278 0 : Reference< XPropertySet > xSet(pControlModels[j], UNO_QUERY);
279 0 : if ((XPropertySet*)xSet.get() == ((XPropertySet*)pEntry->GetUserData()))
280 : {
281 0 : pSortedControlModels[i] = pControlModels[j];
282 0 : break;
283 : }
284 0 : }
285 : }
286 :
287 : // TODO: UNO action (to bracket all the single actions which are being created)
288 0 : m_xModel->setControlModels( aSortedControlModelSeq );
289 :
290 0 : EndDialog( sal_True );
291 0 : return 0;
292 : }
293 :
294 : //========================================================================
295 : //= TabOrderListBox
296 : //========================================================================
297 : DBG_NAME(TabOrderListBox);
298 : //------------------------------------------------------------------------
299 0 : TabOrderListBox::TabOrderListBox( Window* pParent, const ResId& rResId )
300 0 : :SvTreeListBox( pParent, rResId )
301 : {
302 : DBG_CTOR(TabOrderListBox,NULL);
303 0 : SetDragDropMode(0xFFFF/*SV_DRAGDROP_CTRL_MOVE*/);
304 : // Hmm. The flag alone is not enough, so to be on the safe side ...
305 :
306 0 : SetSelectionMode( MULTIPLE_SELECTION );
307 0 : }
308 :
309 : //------------------------------------------------------------------------
310 0 : TabOrderListBox::~TabOrderListBox()
311 : {
312 : DBG_DTOR(TabOrderListBox,NULL);
313 0 : }
314 :
315 : //------------------------------------------------------------------------
316 0 : void TabOrderListBox::ModelHasMoved( SvTreeListEntry* _pSource )
317 : {
318 0 : SvTreeListBox::ModelHasMoved( _pSource );
319 :
320 0 : ((TabOrderDialog*)GetParentDialog())->SetModified();
321 0 : }
322 :
323 : //------------------------------------------------------------------------
324 0 : void TabOrderListBox::MoveSelection( long nRelPos )
325 : {
326 0 : OUString aSelEntryPrevText, aSelEntryNextText;
327 0 : Image aImage;
328 0 : for (long i=0; i<labs(nRelPos); i++)
329 : {
330 0 : ((TabOrderDialog*)GetParentDialog())->SetModified();
331 :
332 : //////////////////////////////////////////////////////////////////////
333 : // move entries
334 0 : if( nRelPos < 0 )
335 : {
336 0 : SvTreeListEntry* pFirstSelected = FirstSelected();
337 0 : if( !pFirstSelected ) return;
338 0 : sal_uLong nFirstSelPos = GetModel()->GetAbsPos( pFirstSelected );
339 0 : if( nFirstSelPos == 0 ) return;
340 :
341 0 : SvTreeListEntry* pSelEntry = pFirstSelected;
342 0 : while( pSelEntry )
343 : {
344 0 : sal_uLong nSelEntryPos = GetModel()->GetAbsPos( pSelEntry );
345 0 : SvTreeListEntry* pSelEntryPrev = GetEntry( nSelEntryPos-1 );
346 0 : aSelEntryPrevText = GetEntryText( pSelEntryPrev );
347 0 : aImage = GetExpandedEntryBmp(pSelEntryPrev);
348 0 : void* pData = pSelEntryPrev->GetUserData();
349 :
350 0 : GetModel()->Remove( pSelEntryPrev );
351 0 : InsertEntry( aSelEntryPrevText, aImage, aImage, 0, sal_False, nSelEntryPos, pData );
352 :
353 0 : pSelEntry = NextSelected( pSelEntry );
354 : }
355 : }
356 :
357 0 : else if( nRelPos > 0 )
358 : {
359 0 : SvTreeListEntry* pLastSelected = LastSelected();
360 0 : if( !pLastSelected ) return;
361 0 : sal_uLong nLastSelPos = GetModel()->GetAbsPos( pLastSelected );
362 :
363 0 : if( (nLastSelPos + nRelPos - i) > (GetEntryCount()-1) ) return;
364 :
365 : #if OSL_DEBUG_LEVEL > 0
366 : sal_uLong nSelCount = GetSelectionCount();
367 : (void)nSelCount;
368 : #endif
369 :
370 :
371 0 : SvTreeListEntry* pSelEntry = pLastSelected;
372 0 : while( pSelEntry )
373 : {
374 0 : sal_uLong nSelEntryPos = GetModel()->GetAbsPos( pSelEntry );
375 0 : SvTreeListEntry* pSelEntryNext = GetEntry( nSelEntryPos+1 );
376 0 : void* pData = pSelEntryNext->GetUserData();
377 :
378 0 : aSelEntryNextText = GetEntryText( pSelEntryNext );
379 0 : aImage = GetExpandedEntryBmp(pSelEntryNext);
380 :
381 0 : GetModel()->Remove( pSelEntryNext );
382 0 : InsertEntry( aSelEntryNextText, aImage, aImage, 0, sal_False, nSelEntryPos, pData );
383 :
384 0 : pSelEntry = PrevSelected( pSelEntry );
385 : }
386 0 : long nThumbPos = GetVScroll()->GetThumbPos();
387 0 : long nVisibleSize = GetVScroll()->GetVisibleSize();
388 0 : long nFirstVisible = GetModel()->GetAbsPos( FirstVisible());
389 :
390 0 : if ( ( nThumbPos + nVisibleSize + 1 ) < (long)( nLastSelPos + 3 ) )
391 0 : GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
392 0 : else if((nThumbPos+nVisibleSize+1) >= (nFirstVisible))
393 0 : GetVScroll()->DoScrollAction(SCROLL_LINEUP);
394 : }
395 0 : }
396 : }
397 :
398 : //............................................................................
399 3 : } // namespace pcr
400 : //............................................................................
401 :
402 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|