Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : /*
31 : : TODO:
32 : : - delete anchor in SelectionEngine when selecting manually
33 : : - SelectAll( sal_False ) => only repaint the delselected entries
34 : : */
35 : :
36 : : #include <string.h>
37 : : #include <svtools/svlbox.hxx>
38 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 : : #include <vcl/svapp.hxx>
40 : : #include <vcl/accel.hxx>
41 : : #include <vcl/i18nhelp.hxx>
42 : : #include <sot/formats.hxx>
43 : : #include <unotools/accessiblestatesethelper.hxx>
44 : : #include <rtl/instance.hxx>
45 : :
46 : : #include <svtools/svmedit.hxx>
47 : : #include <svtools/svlbitm.hxx>
48 : :
49 : : #include <set>
50 : :
51 : : using namespace ::com::sun::star::accessibility;
52 : :
53 : : // Drag&Drop
54 : : static SvLBox* pDDSource = NULL;
55 : : static SvLBox* pDDTarget = NULL;
56 : :
57 : : DBG_NAME(SvInplaceEdit2)
58 : :
59 : : #define SVLBOX_ACC_RETURN 1
60 : : #define SVLBOX_ACC_ESCAPE 2
61 : :
62 : : // ***************************************************************
63 : :
64 [ # # ]: 0 : class MyEdit_Impl : public Edit
65 : : {
66 : : SvInplaceEdit2* pOwner;
67 : : public:
68 : : MyEdit_Impl( Window* pParent, SvInplaceEdit2* pOwner );
69 : : virtual void KeyInput( const KeyEvent& rKEvt );
70 : : virtual void LoseFocus();
71 : : };
72 : :
73 [ # # ]: 0 : class MyMultiEdit_Impl : public MultiLineEdit
74 : : {
75 : : SvInplaceEdit2* pOwner;
76 : : public:
77 : : MyMultiEdit_Impl( Window* pParent, SvInplaceEdit2* pOwner );
78 : : virtual void KeyInput( const KeyEvent& rKEvt );
79 : : virtual void LoseFocus();
80 : : };
81 : :
82 : 0 : MyEdit_Impl::MyEdit_Impl( Window* pParent, SvInplaceEdit2* _pOwner ) :
83 : :
84 : : Edit( pParent, WB_LEFT ),
85 : :
86 : 0 : pOwner( _pOwner )
87 : :
88 : : {
89 : 0 : }
90 : :
91 : 0 : void MyEdit_Impl::KeyInput( const KeyEvent& rKEvt )
92 : : {
93 [ # # ]: 0 : if( !pOwner->KeyInput( rKEvt ))
94 : 0 : Edit::KeyInput( rKEvt );
95 : 0 : }
96 : :
97 : 0 : void MyEdit_Impl::LoseFocus()
98 : : {
99 : 0 : pOwner->LoseFocus();
100 : 0 : }
101 : :
102 : 0 : MyMultiEdit_Impl::MyMultiEdit_Impl( Window* pParent, SvInplaceEdit2* _pOwner )
103 : : : MultiLineEdit( pParent,
104 : : WB_CENTER
105 : 0 : ), pOwner(_pOwner)
106 : : {
107 : 0 : }
108 : :
109 : 0 : void MyMultiEdit_Impl::KeyInput( const KeyEvent& rKEvt )
110 : : {
111 [ # # ]: 0 : if( !pOwner->KeyInput( rKEvt ))
112 : 0 : MultiLineEdit::KeyInput( rKEvt );
113 : 0 : }
114 : :
115 : 0 : void MyMultiEdit_Impl::LoseFocus()
116 : : {
117 : 0 : pOwner->LoseFocus();
118 : 0 : }
119 : :
120 : :
121 : 0 : SvInplaceEdit2::SvInplaceEdit2
122 : : (
123 : : Window* pParent, const Point& rPos,
124 : : const Size& rSize,
125 : : const String& rData,
126 : : const Link& rNotifyEditEnd,
127 : : const Selection& rSelection,
128 : : sal_Bool bMulti
129 : : ) :
130 : :
131 : : aCallBackHdl ( rNotifyEditEnd ),
132 : : bCanceled ( sal_False ),
133 [ # # ][ # # ]: 0 : bAlreadyInCallBack ( sal_False )
134 : :
135 : : {
136 : : DBG_CTOR(SvInplaceEdit2,0);
137 : :
138 [ # # ]: 0 : if( bMulti )
139 [ # # ][ # # ]: 0 : pEdit = new MyMultiEdit_Impl( pParent, this );
140 : : else
141 [ # # ][ # # ]: 0 : pEdit = new MyEdit_Impl( pParent, this );
142 : :
143 [ # # ]: 0 : Font aFont( pParent->GetFont() );
144 [ # # ]: 0 : aFont.SetTransparent( sal_False );
145 [ # # ]: 0 : Color aColor( pParent->GetBackground().GetColor() );
146 [ # # ]: 0 : aFont.SetFillColor(aColor );
147 [ # # ]: 0 : pEdit->SetFont( aFont );
148 [ # # ]: 0 : pEdit->SetBackground( pParent->GetBackground() );
149 [ # # ]: 0 : pEdit->SetPosPixel( rPos );
150 [ # # ]: 0 : pEdit->SetSizePixel( rSize );
151 [ # # ]: 0 : pEdit->SetText( rData );
152 [ # # ]: 0 : pEdit->SetSelection( rSelection );
153 [ # # ]: 0 : pEdit->SaveValue();
154 : :
155 [ # # ]: 0 : aAccReturn.InsertItem( SVLBOX_ACC_RETURN, KeyCode(KEY_RETURN) );
156 [ # # ]: 0 : aAccEscape.InsertItem( SVLBOX_ACC_ESCAPE, KeyCode(KEY_ESCAPE) );
157 : :
158 [ # # ]: 0 : aAccReturn.SetActivateHdl( LINK( this, SvInplaceEdit2, ReturnHdl_Impl) );
159 [ # # ]: 0 : aAccEscape.SetActivateHdl( LINK( this, SvInplaceEdit2, EscapeHdl_Impl) );
160 [ # # ][ # # ]: 0 : GetpApp()->InsertAccel( &aAccReturn );
161 [ # # ][ # # ]: 0 : GetpApp()->InsertAccel( &aAccEscape );
162 : :
163 [ # # ]: 0 : pEdit->Show();
164 [ # # ][ # # ]: 0 : pEdit->GrabFocus();
165 : 0 : }
166 : :
167 [ # # ][ # # ]: 0 : SvInplaceEdit2::~SvInplaceEdit2()
168 : : {
169 : : DBG_DTOR(SvInplaceEdit2,0);
170 [ # # ]: 0 : if( !bAlreadyInCallBack )
171 : : {
172 [ # # ][ # # ]: 0 : GetpApp()->RemoveAccel( &aAccReturn );
173 [ # # ][ # # ]: 0 : GetpApp()->RemoveAccel( &aAccEscape );
174 : : }
175 [ # # ][ # # ]: 0 : delete pEdit;
176 : 0 : }
177 : :
178 : 0 : String SvInplaceEdit2::GetSavedValue() const
179 : : {
180 : 0 : return pEdit->GetSavedValue();
181 : : }
182 : :
183 : 0 : void SvInplaceEdit2::Hide()
184 : : {
185 : 0 : pEdit->Hide();
186 : 0 : }
187 : :
188 : :
189 : 0 : IMPL_LINK_NOARG_INLINE_START(SvInplaceEdit2, ReturnHdl_Impl)
190 : : {
191 : : DBG_CHKTHIS(SvInplaceEdit2,0);
192 : 0 : bCanceled = sal_False;
193 : 0 : CallCallBackHdl_Impl();
194 : 0 : return 1;
195 : : }
196 : 0 : IMPL_LINK_NOARG_INLINE_END(SvInplaceEdit2, ReturnHdl_Impl)
197 : :
198 : 0 : IMPL_LINK_NOARG_INLINE_START(SvInplaceEdit2, EscapeHdl_Impl)
199 : : {
200 : : DBG_CHKTHIS(SvInplaceEdit2,0);
201 : 0 : bCanceled = sal_True;
202 : 0 : CallCallBackHdl_Impl();
203 : 0 : return 1;
204 : : }
205 : 0 : IMPL_LINK_NOARG_INLINE_END(SvInplaceEdit2, EscapeHdl_Impl)
206 : :
207 : :
208 : 0 : sal_Bool SvInplaceEdit2::KeyInput( const KeyEvent& rKEvt )
209 : : {
210 : : DBG_CHKTHIS(SvInplaceEdit2,0);
211 : 0 : KeyCode aCode = rKEvt.GetKeyCode();
212 : 0 : sal_uInt16 nCode = aCode.GetCode();
213 : :
214 [ # # # ]: 0 : switch ( nCode )
215 : : {
216 : : case KEY_ESCAPE:
217 : 0 : bCanceled = sal_True;
218 [ # # ]: 0 : CallCallBackHdl_Impl();
219 : 0 : return sal_True;
220 : :
221 : : case KEY_RETURN:
222 : 0 : bCanceled = sal_False;
223 [ # # ]: 0 : CallCallBackHdl_Impl();
224 : 0 : return sal_True;
225 : : }
226 : 0 : return sal_False;
227 : : }
228 : :
229 : 0 : void SvInplaceEdit2::StopEditing( sal_Bool bCancel )
230 : : {
231 : : DBG_CHKTHIS(SvInplaceEdit2,0);
232 [ # # ]: 0 : if ( !bAlreadyInCallBack )
233 : : {
234 : 0 : bCanceled = bCancel;
235 : 0 : CallCallBackHdl_Impl();
236 : : }
237 : 0 : }
238 : :
239 : 0 : void SvInplaceEdit2::LoseFocus()
240 : : {
241 : : DBG_CHKTHIS(SvInplaceEdit2,0);
242 [ # # # # : 0 : if ( !bAlreadyInCallBack
# # ][ # # ]
243 : 0 : && ((!Application::GetFocusWindow()) || !pEdit->IsChild( Application::GetFocusWindow()) )
244 : : )
245 : : {
246 : 0 : bCanceled = sal_False;
247 : 0 : aTimer.SetTimeout(10);
248 : 0 : aTimer.SetTimeoutHdl(LINK(this,SvInplaceEdit2,Timeout_Impl));
249 : 0 : aTimer.Start();
250 : : }
251 : 0 : }
252 : :
253 : 0 : IMPL_LINK_NOARG_INLINE_START(SvInplaceEdit2, Timeout_Impl)
254 : : {
255 : : DBG_CHKTHIS(SvInplaceEdit2,0);
256 : 0 : CallCallBackHdl_Impl();
257 : 0 : return 0;
258 : : }
259 : 0 : IMPL_LINK_NOARG_INLINE_END(SvInplaceEdit2, Timeout_Impl)
260 : :
261 : 0 : void SvInplaceEdit2::CallCallBackHdl_Impl()
262 : : {
263 : : DBG_CHKTHIS(SvInplaceEdit2,0);
264 : 0 : aTimer.Stop();
265 [ # # ]: 0 : if ( !bAlreadyInCallBack )
266 : : {
267 : 0 : bAlreadyInCallBack = sal_True;
268 : 0 : GetpApp()->RemoveAccel( &aAccReturn );
269 : 0 : GetpApp()->RemoveAccel( &aAccEscape );
270 : 0 : pEdit->Hide();
271 : 0 : aCallBackHdl.Call( this );
272 : : }
273 : 0 : }
274 : :
275 : 0 : String SvInplaceEdit2::GetText() const
276 : : {
277 : 0 : return pEdit->GetText();
278 : : }
279 : :
280 : : // ***************************************************************
281 : : // class SvLBoxTab
282 : : // ***************************************************************
283 : :
284 : : DBG_NAME(SvLBoxTab);
285 : :
286 : 0 : SvLBoxTab::SvLBoxTab()
287 : : {
288 : : DBG_CTOR(SvLBoxTab,0);
289 : 0 : nPos = 0;
290 : 0 : pUserData = 0;
291 : 0 : nFlags = 0;
292 : 0 : }
293 : :
294 : 752 : SvLBoxTab::SvLBoxTab( long nPosition, sal_uInt16 nTabFlags )
295 : : {
296 : : DBG_CTOR(SvLBoxTab,0);
297 : 752 : nPos = nPosition;
298 : 752 : pUserData = 0;
299 : 752 : nFlags = nTabFlags;
300 : 752 : }
301 : :
302 : 0 : SvLBoxTab::SvLBoxTab( const SvLBoxTab& rTab )
303 : : {
304 : : DBG_CTOR(SvLBoxTab,0);
305 : 0 : nPos = rTab.nPos;
306 : 0 : pUserData = rTab.pUserData;
307 : 0 : nFlags = rTab.nFlags;
308 : 0 : }
309 : :
310 : 752 : SvLBoxTab::~SvLBoxTab()
311 : : {
312 : : DBG_DTOR(SvLBoxTab,0);
313 : 752 : }
314 : :
315 : :
316 : 9258 : long SvLBoxTab::CalcOffset( long nItemWidth, long nTabWidth )
317 : : {
318 : : DBG_CHKTHIS(SvLBoxTab,0);
319 : 9258 : long nOffset = 0;
320 [ - + ]: 9258 : if ( nFlags & SV_LBOXTAB_ADJUST_RIGHT )
321 : : {
322 : 0 : nOffset = nTabWidth - nItemWidth;
323 [ # # ]: 0 : if( nOffset < 0 )
324 : 0 : nOffset = 0;
325 : : }
326 [ + + ]: 9258 : else if ( nFlags & SV_LBOXTAB_ADJUST_CENTER )
327 : : {
328 [ - + ]: 3359 : if( nFlags & SV_LBOXTAB_FORCE )
329 : : {
330 : : // correct implementation of centering
331 : 0 : nOffset = ( nTabWidth - nItemWidth ) / 2;
332 [ # # ]: 0 : if( nOffset < 0 )
333 : 0 : nOffset = 0;
334 : : }
335 : : else
336 : : {
337 : : // historically grown, wrong calculation of tabs which is needed by
338 : : // Abo-Tabbox, Tools/Options/Customize etc.
339 : 3359 : nItemWidth++;
340 : 3359 : nOffset = -( nItemWidth / 2 );
341 : : }
342 : : }
343 : 9258 : return nOffset;
344 : : }
345 : :
346 : : // ***************************************************************
347 : : // class SvLBoxItem
348 : : // ***************************************************************
349 : :
350 : : DBG_NAME(SvLBoxItem);
351 : :
352 : 4804 : SvLBoxItem::SvLBoxItem( SvLBoxEntry*, sal_uInt16 )
353 : : {
354 : : DBG_CTOR(SvLBoxItem,0);
355 : 4804 : }
356 : :
357 : 0 : SvLBoxItem::SvLBoxItem()
358 : : {
359 : : DBG_CTOR(SvLBoxItem,0);
360 : 0 : }
361 : :
362 : 4804 : SvLBoxItem::~SvLBoxItem()
363 : : {
364 : : DBG_DTOR(SvLBoxItem,0);
365 [ - + ]: 4804 : }
366 : :
367 : 5880 : const Size& SvLBoxItem::GetSize( SvLBox* pView,SvLBoxEntry* pEntry )
368 : : {
369 : : DBG_CHKTHIS(SvLBoxItem,0);
370 : 5880 : SvViewDataItem* pViewData = pView->GetViewDataItem( pEntry, this );
371 : 5880 : return pViewData->aSize;
372 : : }
373 : :
374 : : DBG_NAME(SvViewDataItem);
375 : :
376 : 4796 : SvViewDataItem::SvViewDataItem()
377 : : {
378 : : DBG_CTOR(SvViewDataItem,0);
379 : 4796 : }
380 : :
381 : 4796 : SvViewDataItem::~SvViewDataItem()
382 : : {
383 : : DBG_DTOR(SvViewDataItem,0);
384 : 4796 : }
385 : :
386 : :
387 : :
388 : : // ***************************************************************
389 : : // class SvLBoxEntry
390 : : // ***************************************************************
391 : :
392 : : DBG_NAME(SvLBoxEntry);
393 : :
394 [ + - ]: 2398 : SvLBoxEntry::SvLBoxEntry() : aItems()
395 : : {
396 : : DBG_CTOR(SvLBoxEntry,0);
397 : 2398 : nEntryFlags = 0;
398 : 2398 : pUserData = 0;
399 : 2398 : }
400 : :
401 : 2398 : SvLBoxEntry::~SvLBoxEntry()
402 : : {
403 : : DBG_DTOR(SvLBoxEntry,0);
404 [ + - ]: 2398 : DeleteItems_Impl();
405 [ - + ]: 4796 : }
406 : :
407 : 2398 : void SvLBoxEntry::DeleteItems_Impl()
408 : : {
409 : : DBG_CHKTHIS(SvLBoxEntry,0);
410 : 2398 : sal_uInt16 nCount = aItems.size();
411 [ + + ]: 7194 : while( nCount )
412 : : {
413 : 4796 : nCount--;
414 : 4796 : SvLBoxItem* pItem = aItems[ nCount ];
415 [ + - ]: 4796 : delete pItem;
416 : : }
417 : 2398 : aItems.clear();
418 : 2398 : }
419 : :
420 : :
421 : 4796 : void SvLBoxEntry::AddItem( SvLBoxItem* pItem )
422 : : {
423 : : DBG_CHKTHIS(SvLBoxEntry,0);
424 : 4796 : aItems.push_back( pItem );
425 : 4796 : }
426 : :
427 : 0 : void SvLBoxEntry::Clone( SvListEntry* pSource )
428 : : {
429 : : DBG_CHKTHIS(SvLBoxEntry,0);
430 : 0 : SvListEntry::Clone( pSource );
431 : : SvLBoxItem* pNewItem;
432 : 0 : DeleteItems_Impl();
433 : 0 : sal_uInt16 nCount = ((SvLBoxEntry*)pSource)->ItemCount();
434 : 0 : sal_uInt16 nCurPos = 0;
435 [ # # ]: 0 : while( nCurPos < nCount )
436 : : {
437 : 0 : SvLBoxItem* pItem = ((SvLBoxEntry*)pSource)->GetItem( nCurPos );
438 : 0 : pNewItem = pItem->Create();
439 : 0 : pNewItem->Clone( pItem );
440 : 0 : AddItem( pNewItem );
441 : 0 : nCurPos++;
442 : : }
443 : 0 : pUserData = ((SvLBoxEntry*)pSource)->GetUserData();
444 : 0 : nEntryFlags = ((SvLBoxEntry*)pSource)->nEntryFlags;
445 : 0 : }
446 : :
447 : 2398 : void SvLBoxEntry::EnableChildrenOnDemand( sal_Bool bEnable )
448 : : {
449 : : DBG_CHKTHIS(SvLBoxEntry,0);
450 [ + + ]: 2398 : if ( bEnable )
451 : 4 : nEntryFlags |= SV_ENTRYFLAG_CHILDREN_ON_DEMAND;
452 : : else
453 : 2394 : nEntryFlags &= (~SV_ENTRYFLAG_CHILDREN_ON_DEMAND);
454 : 2398 : }
455 : :
456 : 8 : void SvLBoxEntry::ReplaceItem( SvLBoxItem* pNewItem, sal_uInt16 nPos )
457 : : {
458 : : DBG_CHKTHIS(SvLBoxEntry,0);
459 : : DBG_ASSERT(pNewItem,"ReplaceItem:No Item");
460 : 8 : SvLBoxItem* pOld = GetItem( nPos );
461 [ + - ]: 8 : if ( pOld )
462 : : {
463 : 8 : aItems[ nPos ] = pNewItem;
464 [ + - ]: 8 : delete pOld;
465 : : }
466 : 8 : }
467 : :
468 : 26052 : SvLBoxItem* SvLBoxEntry::GetFirstItem( sal_uInt16 nId )
469 : : {
470 : 26052 : sal_uInt16 nCount = aItems.size();
471 : 26052 : sal_uInt16 nCur = 0;
472 : : SvLBoxItem* pItem;
473 [ + - ]: 49686 : while( nCur < nCount )
474 : : {
475 : 49686 : pItem = GetItem( nCur );
476 [ + + ]: 49686 : if( pItem->IsA() == nId )
477 : 26052 : return pItem;
478 : 23634 : nCur++;
479 : : }
480 : 26052 : return 0;
481 : : }
482 : :
483 : : // ***************************************************************
484 : : // class SvLBoxViewData
485 : : // ***************************************************************
486 : :
487 : : DBG_NAME(SvViewDataEntry);
488 : :
489 : 2398 : SvViewDataEntry::SvViewDataEntry()
490 : 2398 : : SvViewData()
491 : : {
492 : : DBG_CTOR(SvViewDataEntry,0);
493 : 2398 : pItemData = 0;
494 : 2398 : }
495 : :
496 : 2398 : SvViewDataEntry::~SvViewDataEntry()
497 : : {
498 : : DBG_DTOR(SvViewDataEntry,0);
499 [ + - ][ + + ]: 7194 : delete [] pItemData;
500 [ - + ]: 4796 : }
501 : :
502 : : // ***************************************************************
503 : : // struct SvLBox_Impl
504 : : // ***************************************************************
505 : 122 : SvLBox_Impl::SvLBox_Impl( SvLBox& _rBox )
506 : : :m_bIsEmptyTextAllowed( true )
507 : : ,m_bEntryMnemonicsEnabled( false )
508 : : ,m_bDoingQuickSelection( false )
509 : : ,m_pLink( NULL )
510 : : ,m_aMnemonicEngine( _rBox )
511 [ + - ]: 122 : ,m_aQuickSelectionEngine( _rBox )
512 : : {
513 : 122 : }
514 : :
515 : : // ***************************************************************
516 : : // class SvLBox
517 : : // ***************************************************************
518 : :
519 : : DBG_NAME(SvLBox);
520 : :
521 : 122 : SvLBox::SvLBox( Window* pParent, WinBits nWinStyle ) :
522 : : Control( pParent, nWinStyle | WB_CLIPCHILDREN ),
523 [ + - ][ + - ]: 122 : DropTargetHelper( this ), DragSourceHelper( this ), eSelMode( NO_SELECTION )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
524 : : {
525 : : DBG_CTOR(SvLBox,0);
526 : 122 : nDragOptions = DND_ACTION_COPYMOVE | DND_ACTION_LINK;
527 : 122 : nImpFlags = 0;
528 : 122 : pTargetEntry = 0;
529 : 122 : nDragDropMode = 0;
530 [ + - ][ + - ]: 122 : pLBoxImpl = new SvLBox_Impl( *this );
531 [ + - ][ + - ]: 122 : SvLBoxTreeList* pTempModel = new SvLBoxTreeList;
532 : 122 : pTempModel->SetRefCount( 0 );
533 [ + - ]: 122 : SetModel( pTempModel );
534 [ + - ]: 122 : pModel->SetCloneLink( LINK(this, SvLBox, CloneHdl_Impl ));
535 [ + - ]: 122 : pModel->InsertView( this );
536 : 122 : pHdlEntry = 0;
537 : 122 : pEdCtrl = 0;
538 [ + - ]: 122 : SetSelectionMode( SINGLE_SELECTION ); // check if TreeListBox is called
539 [ + - ]: 122 : SetDragDropMode( SV_DRAGDROP_NONE );
540 [ + - ]: 122 : SetType(WINDOW_TREELISTBOX);
541 : 122 : }
542 : :
543 : 0 : SvLBox::SvLBox( Window* pParent, const ResId& rResId ) :
544 : : Control( pParent, rResId ),
545 [ # # ][ # # ]: 0 : DropTargetHelper( this ), DragSourceHelper( this ), eSelMode( NO_SELECTION )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
546 : : {
547 : : DBG_CTOR(SvLBox,0);
548 : 0 : pTargetEntry = 0;
549 : 0 : nImpFlags = 0;
550 [ # # ][ # # ]: 0 : pLBoxImpl = new SvLBox_Impl( *this );
551 : 0 : nDragOptions = DND_ACTION_COPYMOVE | DND_ACTION_LINK;
552 : 0 : nDragDropMode = 0;
553 [ # # ][ # # ]: 0 : SvLBoxTreeList* pTempModel = new SvLBoxTreeList;
554 : 0 : pTempModel->SetRefCount( 0 );
555 [ # # ]: 0 : SetModel( pTempModel );
556 [ # # ]: 0 : pModel->InsertView( this );
557 : 0 : pHdlEntry = 0;
558 : 0 : pEdCtrl = 0;
559 [ # # ]: 0 : pModel->SetCloneLink( LINK(this, SvLBox, CloneHdl_Impl ));
560 [ # # ]: 0 : SetType(WINDOW_TREELISTBOX);
561 : 0 : }
562 : :
563 [ + - ][ + - ]: 122 : SvLBox::~SvLBox()
[ + - ]
564 : : {
565 : : DBG_DTOR(SvLBox,0);
566 [ - + ][ # # ]: 122 : delete pEdCtrl;
567 : 122 : pEdCtrl = 0;
568 [ + - ]: 122 : pModel->RemoveView( this );
569 [ + - ]: 122 : if ( pModel->GetRefCount() == 0 )
570 : : {
571 [ + - ]: 122 : pModel->Clear();
572 [ + - ][ + - ]: 122 : delete pModel;
573 : 122 : pModel = NULL;
574 : : }
575 : :
576 [ + - ]: 122 : SvLBox::RemoveBoxFromDDList_Impl( *this );
577 : :
578 [ - + ]: 122 : if( this == pDDSource )
579 : 0 : pDDSource = 0;
580 [ - + ]: 122 : if( this == pDDTarget )
581 : 0 : pDDTarget = 0;
582 [ + - ][ + - ]: 122 : delete pLBoxImpl;
583 [ - + ]: 122 : }
584 : :
585 : 124 : void SvLBox::SetModel( SvLBoxTreeList* pNewModel )
586 : : {
587 : : DBG_CHKTHIS(SvLBox,0);
588 : : // does the CleanUp
589 : 124 : SvListView::SetModel( pNewModel );
590 : 124 : pModel->SetCloneLink( LINK(this, SvLBox, CloneHdl_Impl ));
591 : 124 : SvLBoxEntry* pEntry = First();
592 [ - + ]: 124 : while( pEntry )
593 : : {
594 : 0 : ModelHasInserted( pEntry );
595 : 0 : pEntry = Next( pEntry );
596 : : }
597 : 124 : }
598 : :
599 : 2 : void SvLBox::DisconnectFromModel()
600 : : {
601 : : DBG_CHKTHIS(SvLBox,0);
602 [ + - ]: 2 : SvLBoxTreeList* pNewModel = new SvLBoxTreeList;
603 : 2 : pNewModel->SetRefCount( 0 ); // else this will never be deleted
604 : 2 : SvListView::SetModel( pNewModel );
605 : 2 : }
606 : :
607 : 120 : void SvLBox::Clear()
608 : : {
609 : : DBG_CHKTHIS(SvLBox,0);
610 : 120 : pModel->Clear(); // Model calls SvLBox::ModelHasCleared()
611 : 120 : }
612 : :
613 : 0 : void SvLBox::EnableEntryMnemonics( bool _bEnable )
614 : : {
615 [ # # ]: 0 : if ( _bEnable == IsEntryMnemonicsEnabled() )
616 : 0 : return;
617 : :
618 : 0 : pLBoxImpl->m_bEntryMnemonicsEnabled = _bEnable;
619 : 0 : Invalidate();
620 : : }
621 : :
622 : 3340 : bool SvLBox::IsEntryMnemonicsEnabled() const
623 : : {
624 : 3340 : return pLBoxImpl->m_bEntryMnemonicsEnabled;
625 : : }
626 : :
627 : 0 : sal_uInt16 SvLBox::IsA()
628 : : {
629 : : DBG_CHKTHIS(SvLBox,0);
630 : 0 : return SVLISTBOX_ID_LBOX;
631 : : }
632 : :
633 : 0 : IMPL_LINK_INLINE_START( SvLBox, CloneHdl_Impl, SvListEntry*, pEntry )
634 : : {
635 : : DBG_CHKTHIS(SvLBox,0);
636 : 0 : return (long)(CloneEntry((SvLBoxEntry*)pEntry));
637 : : }
638 : 0 : IMPL_LINK_INLINE_END( SvLBox, CloneHdl_Impl, SvListEntry*, pEntry )
639 : :
640 : 6 : sal_uLong SvLBox::Insert( SvLBoxEntry* pEntry, SvLBoxEntry* pParent, sal_uLong nPos )
641 : : {
642 : : DBG_CHKTHIS(SvLBox,0);
643 : 6 : sal_uLong nInsPos = pModel->Insert( pEntry, pParent, nPos );
644 : 6 : return nInsPos;
645 : : }
646 : :
647 : 2392 : sal_uLong SvLBox::Insert( SvLBoxEntry* pEntry,sal_uLong nRootPos )
648 : : {
649 : : DBG_CHKTHIS(SvLBox,0);
650 : 2392 : sal_uLong nInsPos = pModel->Insert( pEntry, nRootPos );
651 : 2392 : return nInsPos;
652 : : }
653 : :
654 : 4 : long SvLBox::ExpandingHdl()
655 : : {
656 : : DBG_CHKTHIS(SvLBox,0);
657 [ - + ]: 4 : return aExpandingHdl.IsSet() ? aExpandingHdl.Call( this ) : 1;
658 : : }
659 : :
660 : 4 : void SvLBox::ExpandedHdl()
661 : : {
662 : : DBG_CHKTHIS(SvLBox,0);
663 : 4 : aExpandedHdl.Call( this );
664 : 4 : }
665 : :
666 : 122 : void SvLBox::SelectHdl()
667 : : {
668 : : DBG_CHKTHIS(SvLBox,0);
669 : 122 : aSelectHdl.Call( this );
670 : 122 : }
671 : :
672 : 2 : void SvLBox::DeselectHdl()
673 : : {
674 : : DBG_CHKTHIS(SvLBox,0);
675 : 2 : aDeselectHdl.Call( this );
676 : 2 : }
677 : :
678 : 0 : sal_Bool SvLBox::DoubleClickHdl()
679 : : {
680 : : DBG_CHKTHIS(SvLBox,0);
681 : 0 : aDoubleClickHdl.Call( this );
682 : 0 : return sal_True;
683 : : }
684 : :
685 : :
686 : 0 : sal_Bool SvLBox::CheckDragAndDropMode( SvLBox* pSource, sal_Int8 nAction )
687 : : {
688 : : DBG_CHKTHIS(SvLBox,0);
689 [ # # ]: 0 : if ( pSource == this )
690 : : {
691 [ # # ]: 0 : if ( !(nDragDropMode & (SV_DRAGDROP_CTRL_MOVE | SV_DRAGDROP_CTRL_COPY) ) )
692 : 0 : return sal_False; // D&D locked within list
693 [ # # ]: 0 : if( DND_ACTION_MOVE == nAction )
694 : : {
695 [ # # ]: 0 : if ( !(nDragDropMode & SV_DRAGDROP_CTRL_MOVE) )
696 : 0 : return sal_False; // no local move
697 : : }
698 : : else
699 : : {
700 [ # # ]: 0 : if ( !(nDragDropMode & SV_DRAGDROP_CTRL_COPY))
701 : 0 : return sal_False; // no local copy
702 : : }
703 : : }
704 : : else
705 : : {
706 [ # # ]: 0 : if ( !(nDragDropMode & SV_DRAGDROP_APP_DROP ) )
707 : 0 : return sal_False; // no drop
708 [ # # ]: 0 : if ( DND_ACTION_MOVE == nAction )
709 : : {
710 [ # # ]: 0 : if ( !(nDragDropMode & SV_DRAGDROP_APP_MOVE) )
711 : 0 : return sal_False; // no global move
712 : : }
713 : : else
714 : : {
715 [ # # ]: 0 : if ( !(nDragDropMode & SV_DRAGDROP_APP_COPY))
716 : 0 : return sal_False; // no global copy
717 : : }
718 : : }
719 : 0 : return sal_True;
720 : : }
721 : :
722 : :
723 : :
724 : :
725 : 0 : void SvLBox::NotifyRemoving( SvLBoxEntry* )
726 : : {
727 : : DBG_CHKTHIS(SvLBox,0);
728 : 0 : }
729 : :
730 : : /*
731 : : NotifyMoving/Copying
732 : : ====================
733 : :
734 : : default behavior:
735 : :
736 : : 1. target doesn't have children
737 : : - entry becomes sibling of target. entry comes after target
738 : : (->Window: below the target)
739 : : 2. target is an expanded parent
740 : : - entry inserted at the beginning of the target childlist
741 : : 3. target is a collapsed parent
742 : : - entry is inserted at the end of the target childlist
743 : : */
744 : : #ifdef DBG_UTIL
745 : : sal_Bool SvLBox::NotifyMoving(
746 : : SvLBoxEntry* pTarget, // D&D dropping position in this->GetModel()
747 : : SvLBoxEntry* pEntry, // entry that we want to move, from
748 : : // GetSourceListBox()->GetModel()
749 : : SvLBoxEntry*& rpNewParent, // new target parent
750 : : sal_uLong& rNewChildPos) // position in childlist of target parent
751 : : #else
752 : 0 : sal_Bool SvLBox::NotifyMoving(
753 : : SvLBoxEntry* pTarget, // D&D dropping position in this->GetModel()
754 : : SvLBoxEntry*, // entry that we want to move, from
755 : : // GetSourceListBox()->GetModel()
756 : : SvLBoxEntry*& rpNewParent, // new target parent
757 : : sal_uLong& rNewChildPos) // position in childlist of target parent
758 : : #endif
759 : : {
760 : : DBG_CHKTHIS(SvLBox,0);
761 : : DBG_ASSERT(pEntry,"NotifyMoving:SoureEntry?");
762 [ # # ]: 0 : if( !pTarget )
763 : : {
764 : 0 : rpNewParent = 0;
765 : 0 : rNewChildPos = 0;
766 : 0 : return sal_True;
767 : : }
768 [ # # ][ # # ]: 0 : if ( !pTarget->HasChildren() && !pTarget->HasChildrenOnDemand() )
[ # # ]
769 : : {
770 : : // case 1
771 : 0 : rpNewParent = GetParent( pTarget );
772 : 0 : rNewChildPos = pModel->GetRelPos( pTarget ) + 1;
773 : 0 : rNewChildPos += nCurEntrySelPos;
774 : 0 : nCurEntrySelPos++;
775 : : }
776 : : else
777 : : {
778 : : // cases 2 & 3
779 : 0 : rpNewParent = pTarget;
780 [ # # ]: 0 : if( IsExpanded(pTarget))
781 : 0 : rNewChildPos = 0;
782 : : else
783 : 0 : rNewChildPos = LIST_APPEND;
784 : : }
785 : 0 : return sal_True;
786 : : }
787 : :
788 : 0 : sal_Bool SvLBox::NotifyCopying(
789 : : SvLBoxEntry* pTarget, // D&D dropping position in this->GetModel()
790 : : SvLBoxEntry* pEntry, // entry that we want to move, from
791 : : // GetSourceListBox()->GetModel()
792 : : SvLBoxEntry*& rpNewParent, // new target parent
793 : : sal_uLong& rNewChildPos) // position in childlist of target parent
794 : : {
795 : : DBG_CHKTHIS(SvLBox,0);
796 : 0 : return NotifyMoving(pTarget,pEntry,rpNewParent,rNewChildPos);
797 : : }
798 : :
799 : 0 : SvLBoxEntry* SvLBox::CloneEntry( SvLBoxEntry* pSource )
800 : : {
801 : : DBG_CHKTHIS(SvLBox,0);
802 : 0 : SvLBoxEntry* pEntry = (SvLBoxEntry*)CreateEntry(); // new SvLBoxEntry;
803 : 0 : pEntry->Clone( (SvListEntry*)pSource );
804 : 0 : return pEntry;
805 : : }
806 : :
807 : :
808 : : // return: all entries copied
809 : 0 : sal_Bool SvLBox::CopySelection( SvLBox* pSource, SvLBoxEntry* pTarget )
810 : : {
811 : : DBG_CHKTHIS(SvLBox,0);
812 : 0 : nCurEntrySelPos = 0; // selection counter for NotifyMoving/Copying
813 : 0 : sal_Bool bSuccess = sal_True;
814 [ # # ]: 0 : SvTreeEntryList aList;
815 : 0 : sal_Bool bClone = (sal_Bool)( (sal_uLong)(pSource->GetModel()) != (sal_uLong)GetModel() );
816 : 0 : Link aCloneLink( pModel->GetCloneLink() );
817 [ # # ]: 0 : pModel->SetCloneLink( LINK(this, SvLBox, CloneHdl_Impl ));
818 : :
819 : : // cache selection to simplify iterating over the selection when doing a D&D
820 : : // exchange within the same listbox
821 [ # # ]: 0 : SvLBoxEntry* pSourceEntry = pSource->FirstSelected();
822 [ # # ]: 0 : while ( pSourceEntry )
823 : : {
824 : : // children are copied automatically
825 [ # # ]: 0 : pSource->SelectChildren( pSourceEntry, sal_False );
826 [ # # ]: 0 : aList.push_back( pSourceEntry );
827 [ # # ]: 0 : pSourceEntry = pSource->NextSelected( pSourceEntry );
828 : : }
829 : :
830 [ # # ]: 0 : pSourceEntry = (SvLBoxEntry*)aList.First();
831 [ # # ]: 0 : while ( pSourceEntry )
832 : : {
833 : 0 : SvLBoxEntry* pNewParent = 0;
834 : 0 : sal_uLong nInsertionPos = ULONG_MAX;
835 [ # # ]: 0 : sal_Bool bOk=NotifyCopying(pTarget,pSourceEntry,pNewParent,nInsertionPos);
836 [ # # ]: 0 : if ( bOk )
837 : : {
838 [ # # ]: 0 : if ( bClone )
839 : : {
840 : 0 : sal_uLong nCloneCount = 0;
841 : : pSourceEntry = (SvLBoxEntry*)
842 [ # # ]: 0 : pModel->Clone( (SvListEntry*)pSourceEntry, nCloneCount );
843 : : pModel->InsertTree( (SvListEntry*)pSourceEntry,
844 [ # # ]: 0 : (SvListEntry*)pNewParent, nInsertionPos );
845 : : }
846 : : else
847 : : {
848 : : sal_uLong nListPos = pModel->Copy( (SvListEntry*)pSourceEntry,
849 [ # # ]: 0 : (SvListEntry*)pNewParent, nInsertionPos );
850 [ # # ]: 0 : pSourceEntry = GetEntry( pNewParent, nListPos );
851 : : }
852 : : }
853 : : else
854 : 0 : bSuccess = sal_False;
855 : :
856 [ # # ]: 0 : if( bOk == (sal_Bool)2 ) // HACK: make visible moved entry?
857 [ # # ]: 0 : MakeVisible( pSourceEntry );
858 : :
859 [ # # ]: 0 : pSourceEntry = (SvLBoxEntry*)aList.Next();
860 : : }
861 : 0 : pModel->SetCloneLink( aCloneLink );
862 : 0 : return bSuccess;
863 : : }
864 : :
865 : : // return: all entries were moved
866 : 0 : sal_Bool SvLBox::MoveSelection( SvLBox* pSource, SvLBoxEntry* pTarget )
867 : : {
868 : 0 : return MoveSelectionCopyFallbackPossible( pSource, pTarget, sal_False );
869 : : }
870 : :
871 : 0 : sal_Bool SvLBox::MoveSelectionCopyFallbackPossible( SvLBox* pSource, SvLBoxEntry* pTarget, sal_Bool bAllowCopyFallback )
872 : : {
873 : : DBG_CHKTHIS(SvLBox,0);
874 : 0 : nCurEntrySelPos = 0; // selection counter for NotifyMoving/Copying
875 : 0 : sal_Bool bSuccess = sal_True;
876 [ # # ]: 0 : SvTreeEntryList aList;
877 : 0 : sal_Bool bClone = (sal_Bool)( (sal_uLong)(pSource->GetModel()) != (sal_uLong)GetModel() );
878 : 0 : Link aCloneLink( pModel->GetCloneLink() );
879 [ # # ]: 0 : if ( bClone )
880 [ # # ]: 0 : pModel->SetCloneLink( LINK(this, SvLBox, CloneHdl_Impl ));
881 : :
882 [ # # ]: 0 : SvLBoxEntry* pSourceEntry = pSource->FirstSelected();
883 [ # # ]: 0 : while ( pSourceEntry )
884 : : {
885 : : // children are automatically moved
886 [ # # ]: 0 : pSource->SelectChildren( pSourceEntry, sal_False );
887 [ # # ]: 0 : aList.push_back( pSourceEntry );
888 [ # # ]: 0 : pSourceEntry = pSource->NextSelected( pSourceEntry );
889 : : }
890 : :
891 [ # # ]: 0 : pSourceEntry = (SvLBoxEntry*)aList.First();
892 [ # # ]: 0 : while ( pSourceEntry )
893 : : {
894 : 0 : SvLBoxEntry* pNewParent = 0;
895 : 0 : sal_uLong nInsertionPos = ULONG_MAX;
896 [ # # ]: 0 : sal_Bool bOk = NotifyMoving(pTarget,pSourceEntry,pNewParent,nInsertionPos);
897 : 0 : sal_Bool bCopyOk = bOk;
898 [ # # ][ # # ]: 0 : if ( !bOk && bAllowCopyFallback )
899 : : {
900 : 0 : nInsertionPos = LIST_APPEND;
901 [ # # ]: 0 : bCopyOk = NotifyCopying(pTarget,pSourceEntry,pNewParent,nInsertionPos);
902 : : }
903 : :
904 [ # # ][ # # ]: 0 : if ( bOk || bCopyOk )
905 : : {
906 [ # # ]: 0 : if ( bClone )
907 : : {
908 : 0 : sal_uLong nCloneCount = 0;
909 : : pSourceEntry = (SvLBoxEntry*)
910 [ # # ]: 0 : pModel->Clone( (SvListEntry*)pSourceEntry, nCloneCount );
911 : : pModel->InsertTree( (SvListEntry*)pSourceEntry,
912 [ # # ]: 0 : (SvListEntry*)pNewParent, nInsertionPos );
913 : : }
914 : : else
915 : : {
916 [ # # ]: 0 : if ( bOk )
917 : : pModel->Move( (SvListEntry*)pSourceEntry,
918 [ # # ]: 0 : (SvListEntry*)pNewParent, nInsertionPos );
919 : : else
920 : : pModel->Copy( (SvListEntry*)pSourceEntry,
921 [ # # ]: 0 : (SvListEntry*)pNewParent, nInsertionPos );
922 : 0 : }
923 : : }
924 : : else
925 : 0 : bSuccess = sal_False;
926 : :
927 [ # # ]: 0 : if( bOk == (sal_Bool)2 ) // HACK: make moved entry visible?
928 [ # # ]: 0 : MakeVisible( pSourceEntry );
929 : :
930 [ # # ]: 0 : pSourceEntry = (SvLBoxEntry*)aList.Next();
931 : : }
932 : 0 : pModel->SetCloneLink( aCloneLink );
933 : 0 : return bSuccess;
934 : : }
935 : :
936 : 0 : void SvLBox::RemoveSelection()
937 : : {
938 : : DBG_CHKTHIS(SvLBox,0);
939 [ # # ]: 0 : SvTreeEntryList aList;
940 : : // cache selection, as the implementation deselects everything on the first
941 : : // remove
942 [ # # ]: 0 : SvLBoxEntry* pEntry = FirstSelected();
943 [ # # ]: 0 : while ( pEntry )
944 : : {
945 [ # # ]: 0 : aList.push_back( pEntry );
946 [ # # ]: 0 : if ( pEntry->HasChildren() )
947 : : // remove deletes all children automatically
948 [ # # ]: 0 : SelectChildren( pEntry, sal_False );
949 [ # # ]: 0 : pEntry = NextSelected( pEntry );
950 : : }
951 [ # # ]: 0 : pEntry = (SvLBoxEntry*)aList.First();
952 [ # # ]: 0 : while ( pEntry )
953 : : {
954 [ # # ]: 0 : pModel->Remove( pEntry );
955 [ # # ]: 0 : pEntry = (SvLBoxEntry*)aList.Next();
956 : 0 : }
957 : 0 : }
958 : :
959 : 0 : SvLBox* SvLBox::GetSourceView() const
960 : : {
961 : 0 : return pDDSource;
962 : : }
963 : :
964 : 0 : void SvLBox::RequestingChildren( SvLBoxEntry* )
965 : : {
966 : : DBG_CHKTHIS(SvLBox,0);
967 : : OSL_FAIL("Child-Request-Hdl not implemented!");
968 : 0 : }
969 : :
970 : 1066 : void SvLBox::RecalcViewData()
971 : : {
972 : : DBG_CHKTHIS(SvLBox,0);
973 : 1066 : SvLBoxEntry* pEntry = First();
974 [ + + ]: 12164 : while( pEntry )
975 : : {
976 : 11098 : sal_uInt16 nCount = pEntry->ItemCount();
977 : 11098 : sal_uInt16 nCurPos = 0;
978 [ + + ]: 33294 : while ( nCurPos < nCount )
979 : : {
980 : 22196 : SvLBoxItem* pItem = pEntry->GetItem( nCurPos );
981 : 22196 : pItem->InitViewData( this, pEntry );
982 : 22196 : nCurPos++;
983 : : }
984 : 11098 : ViewDataInitialized( pEntry );
985 : 11098 : pEntry = Next( pEntry );
986 : : }
987 : 1066 : }
988 : :
989 : 11098 : void SvLBox::ViewDataInitialized( SvLBoxEntry* )
990 : : {
991 : : DBG_CHKTHIS(SvLBox,0);
992 : 11098 : }
993 : :
994 : 360 : void SvLBox::StateChanged( StateChangedType eType )
995 : : {
996 [ - + ]: 360 : if( eType == STATE_CHANGE_ENABLE )
997 : 0 : Invalidate( INVALIDATE_CHILDREN );
998 : 360 : Control::StateChanged( eType );
999 : 360 : }
1000 : :
1001 : 0 : void SvLBox::ImplShowTargetEmphasis( SvLBoxEntry* pEntry, sal_Bool bShow)
1002 : : {
1003 : : DBG_CHKTHIS(SvLBox,0);
1004 [ # # ][ # # ]: 0 : if ( bShow && (nImpFlags & SVLBOX_TARGEMPH_VIS) )
1005 : 0 : return;
1006 [ # # ][ # # ]: 0 : if ( !bShow && !(nImpFlags & SVLBOX_TARGEMPH_VIS) )
1007 : 0 : return;
1008 : 0 : ShowTargetEmphasis( pEntry, bShow );
1009 [ # # ]: 0 : if( bShow )
1010 : 0 : nImpFlags |= SVLBOX_TARGEMPH_VIS;
1011 : : else
1012 : 0 : nImpFlags &= ~SVLBOX_TARGEMPH_VIS;
1013 : : }
1014 : :
1015 : 0 : void SvLBox::ShowTargetEmphasis( SvLBoxEntry*, sal_Bool /* bShow */ )
1016 : : {
1017 : : DBG_CHKTHIS(SvLBox,0);
1018 : 0 : }
1019 : :
1020 : :
1021 : 0 : sal_Bool SvLBox::Expand( SvLBoxEntry* )
1022 : : {
1023 : : DBG_CHKTHIS(SvLBox,0);
1024 : 0 : return sal_True;
1025 : : }
1026 : :
1027 : 0 : sal_Bool SvLBox::Collapse( SvLBoxEntry* )
1028 : : {
1029 : : DBG_CHKTHIS(SvLBox,0);
1030 : 0 : return sal_True;
1031 : : }
1032 : :
1033 : 0 : sal_Bool SvLBox::Select( SvLBoxEntry*, sal_Bool )
1034 : : {
1035 : : DBG_CHKTHIS(SvLBox,0);
1036 : 0 : return sal_False;
1037 : : }
1038 : :
1039 : 0 : sal_uLong SvLBox::SelectChildren( SvLBoxEntry* , sal_Bool )
1040 : : {
1041 : : DBG_CHKTHIS(SvLBox,0);
1042 : 0 : return 0;
1043 : : }
1044 : :
1045 : 124 : void SvLBox::OnCurrentEntryChanged()
1046 : : {
1047 [ + - ]: 124 : if ( !pLBoxImpl->m_bDoingQuickSelection )
1048 : 124 : pLBoxImpl->m_aQuickSelectionEngine.Reset();
1049 : 124 : }
1050 : :
1051 : 0 : void SvLBox::SelectAll( sal_Bool /* bSelect */ , sal_Bool /* bPaint */ )
1052 : : {
1053 : : DBG_CHKTHIS(SvLBox,0);
1054 : 0 : }
1055 : :
1056 : 480 : SvLBoxEntry* SvLBox::GetEntryFromPath( const ::std::deque< sal_Int32 >& _rPath ) const
1057 : : {
1058 : : DBG_CHKTHIS(SvLBox,0);
1059 : :
1060 : 480 : SvLBoxEntry* pEntry = NULL;
1061 : 480 : SvLBoxEntry* pParent = NULL;
1062 [ + - ][ + - ]: 960 : for( ::std::deque< sal_Int32 >::const_iterator pItem = _rPath.begin(); pItem != _rPath.end(); ++pItem )
[ + + ]
1063 : : {
1064 [ + - ][ + - ]: 480 : pEntry = GetEntry( pParent, *pItem );
1065 [ - + ]: 480 : if ( !pEntry )
1066 : 0 : break;
1067 : 480 : pParent = pEntry;
1068 : : }
1069 : :
1070 : 480 : return pEntry;
1071 : : }
1072 : :
1073 : 122 : void SvLBox::FillEntryPath( SvLBoxEntry* pEntry, ::std::deque< sal_Int32 >& _rPath ) const
1074 : : {
1075 : : DBG_CHKTHIS(SvLBox,0);
1076 : :
1077 [ + - ]: 122 : if ( pEntry )
1078 : : {
1079 : 122 : SvLBoxEntry* pParentEntry = GetParent( pEntry );
1080 : 0 : while ( sal_True )
1081 : : {
1082 : 122 : sal_uLong i, nCount = GetLevelChildCount( pParentEntry );
1083 [ + - ]: 1264 : for ( i = 0; i < nCount; ++i )
1084 : : {
1085 : 1264 : SvLBoxEntry* pTemp = GetEntry( pParentEntry, i );
1086 : : DBG_ASSERT( pEntry, "invalid entry" );
1087 [ + + ]: 1264 : if ( pEntry == pTemp )
1088 : : {
1089 [ + - ]: 122 : _rPath.push_front( (sal_Int32)i );
1090 : 122 : break;
1091 : : }
1092 : : }
1093 : :
1094 [ - + ]: 122 : if ( pParentEntry )
1095 : : {
1096 : 0 : pEntry = pParentEntry;
1097 : 0 : pParentEntry = GetParent( pParentEntry );
1098 : : }
1099 : : else
1100 : 122 : break;
1101 : : }
1102 : : }
1103 : 122 : }
1104 : :
1105 : 0 : String SvLBox::GetEntryText( SvLBoxEntry* ) const
1106 : : {
1107 : : DBG_CHKTHIS(SvLBox,0);
1108 : :
1109 : 0 : return String();
1110 : : }
1111 : :
1112 : 374 : sal_uLong SvLBox::GetLevelChildCount( SvLBoxEntry* _pParent ) const
1113 : : {
1114 : : DBG_CHKTHIS(SvLBox,0);
1115 : :
1116 : 374 : sal_uLong nCount = 0;
1117 : 374 : SvLBoxEntry* pEntry = FirstChild( _pParent );
1118 [ + + ]: 3054 : while ( pEntry )
1119 : : {
1120 : 2680 : ++nCount;
1121 : 2680 : pEntry = NextSibling( pEntry );
1122 : : }
1123 : :
1124 : 374 : return nCount;
1125 : : }
1126 : :
1127 : 122 : void SvLBox::SetSelectionMode( SelectionMode eSelectMode )
1128 : : {
1129 : : DBG_CHKTHIS(SvLBox,0);
1130 : 122 : eSelMode = eSelectMode;
1131 : 122 : }
1132 : :
1133 : 124 : void SvLBox::SetDragDropMode( DragDropMode nDDMode )
1134 : : {
1135 : : DBG_CHKTHIS(SvLBox,0);
1136 : 124 : nDragDropMode = nDDMode;
1137 : 124 : }
1138 : :
1139 : 2398 : SvViewData* SvLBox::CreateViewData( SvListEntry* )
1140 : : {
1141 : : DBG_CHKTHIS(SvLBox,0);
1142 [ + - ]: 2398 : SvViewDataEntry* pEntryData = new SvViewDataEntry;
1143 : 2398 : return (SvViewData*)pEntryData;
1144 : : }
1145 : :
1146 : 2398 : void SvLBox::InitViewData( SvViewData* pData, SvListEntry* pEntry )
1147 : : {
1148 : : DBG_CHKTHIS(SvLBox,0);
1149 : 2398 : SvLBoxEntry* pInhEntry = (SvLBoxEntry*)pEntry;
1150 : 2398 : SvViewDataEntry* pEntryData = (SvViewDataEntry*)pData;
1151 : :
1152 [ + + ]: 7194 : pEntryData->pItemData = new SvViewDataItem[ pInhEntry->ItemCount() ];
1153 : 2398 : SvViewDataItem* pItemData = pEntryData->pItemData;
1154 : 2398 : pEntryData->nItmCnt = pInhEntry->ItemCount(); // number of items to delete
1155 : 2398 : sal_uInt16 nCount = pInhEntry->ItemCount();
1156 : 2398 : sal_uInt16 nCurPos = 0;
1157 [ + + ]: 7194 : while( nCurPos < nCount )
1158 : : {
1159 : 4796 : SvLBoxItem* pItem = pInhEntry->GetItem( nCurPos );
1160 : 4796 : pItem->InitViewData( this, pInhEntry, pItemData );
1161 : 4796 : pItemData++;
1162 : 4796 : nCurPos++;
1163 : : }
1164 : 2398 : }
1165 : :
1166 : :
1167 : :
1168 : 0 : void SvLBox::EnableSelectionAsDropTarget( sal_Bool bEnable, sal_Bool bWithChildren )
1169 : : {
1170 : : DBG_CHKTHIS(SvLBox,0);
1171 : : sal_uInt16 nRefDepth;
1172 : : SvLBoxEntry* pTemp;
1173 : :
1174 : 0 : SvLBoxEntry* pSelEntry = FirstSelected();
1175 [ # # ]: 0 : while( pSelEntry )
1176 : : {
1177 [ # # ]: 0 : if ( !bEnable )
1178 : : {
1179 : 0 : pSelEntry->nEntryFlags |= SV_ENTRYFLAG_DISABLE_DROP;
1180 [ # # ]: 0 : if ( bWithChildren )
1181 : : {
1182 : 0 : nRefDepth = pModel->GetDepth( pSelEntry );
1183 : 0 : pTemp = Next( pSelEntry );
1184 [ # # ][ # # ]: 0 : while( pTemp && pModel->GetDepth( pTemp ) > nRefDepth )
[ # # ]
1185 : : {
1186 : 0 : pTemp->nEntryFlags |= SV_ENTRYFLAG_DISABLE_DROP;
1187 : 0 : pTemp = Next( pTemp );
1188 : : }
1189 : : }
1190 : : }
1191 : : else
1192 : : {
1193 : 0 : pSelEntry->nEntryFlags &= (~SV_ENTRYFLAG_DISABLE_DROP);
1194 [ # # ]: 0 : if ( bWithChildren )
1195 : : {
1196 : 0 : nRefDepth = pModel->GetDepth( pSelEntry );
1197 : 0 : pTemp = Next( pSelEntry );
1198 [ # # ][ # # ]: 0 : while( pTemp && pModel->GetDepth( pTemp ) > nRefDepth )
[ # # ]
1199 : : {
1200 : 0 : pTemp->nEntryFlags &= (~SV_ENTRYFLAG_DISABLE_DROP);
1201 : 0 : pTemp = Next( pTemp );
1202 : : }
1203 : : }
1204 : : }
1205 : 0 : pSelEntry = NextSelected( pSelEntry );
1206 : : }
1207 : 0 : }
1208 : :
1209 : 0 : SvLBoxEntry* SvLBox::GetDropTarget( const Point& )
1210 : : {
1211 : : DBG_CHKTHIS(SvLBox,0);
1212 : 0 : return 0;
1213 : : }
1214 : :
1215 : : // ******************************************************************
1216 : : // InplaceEditing
1217 : : // ******************************************************************
1218 : :
1219 : 0 : void SvLBox::EditText( const String& rStr, const Rectangle& rRect,
1220 : : const Selection& rSel )
1221 : : {
1222 : 0 : EditText( rStr, rRect, rSel, sal_False );
1223 : 0 : }
1224 : :
1225 : 0 : void SvLBox::EditText( const String& rStr, const Rectangle& rRect,
1226 : : const Selection& rSel, sal_Bool bMulti )
1227 : : {
1228 : : DBG_CHKTHIS(SvLBox,0);
1229 [ # # ]: 0 : if( pEdCtrl )
1230 [ # # ]: 0 : delete pEdCtrl;
1231 : 0 : nImpFlags |= SVLBOX_IN_EDT;
1232 : 0 : nImpFlags &= ~SVLBOX_EDTEND_CALLED;
1233 : 0 : HideFocus();
1234 : : pEdCtrl = new SvInplaceEdit2(
1235 : : this, rRect.TopLeft(), rRect.GetSize(), rStr,
1236 : : LINK( this, SvLBox, TextEditEndedHdl_Impl ),
1237 [ # # ][ # # ]: 0 : rSel, bMulti );
[ # # ][ # # ]
1238 : 0 : }
1239 : :
1240 : 0 : IMPL_LINK_NOARG(SvLBox, TextEditEndedHdl_Impl)
1241 : : {
1242 : : DBG_CHKTHIS(SvLBox,0);
1243 [ # # ]: 0 : if ( nImpFlags & SVLBOX_EDTEND_CALLED ) // avoid nesting
1244 : 0 : return 0;
1245 : 0 : nImpFlags |= SVLBOX_EDTEND_CALLED;
1246 [ # # ]: 0 : String aStr;
1247 [ # # ]: 0 : if ( !pEdCtrl->EditingCanceled() )
1248 [ # # ][ # # ]: 0 : aStr = pEdCtrl->GetText();
[ # # ]
1249 : : else
1250 [ # # ][ # # ]: 0 : aStr = pEdCtrl->GetSavedValue();
[ # # ]
1251 [ # # ][ # # ]: 0 : if ( IsEmptyTextAllowed() || aStr.Len() > 0 )
[ # # ][ # # ]
1252 [ # # ]: 0 : EditedText( aStr );
1253 : : // Hide may only be called after the new text was put into the entry, so
1254 : : // that we don't call the selection handler in the GetFocus of the listbox
1255 : : // with the old entry text.
1256 [ # # ]: 0 : pEdCtrl->Hide();
1257 : : // delete pEdCtrl;
1258 : : // pEdCtrl = 0;
1259 : 0 : nImpFlags &= (~SVLBOX_IN_EDT);
1260 [ # # ]: 0 : GrabFocus();
1261 [ # # ]: 0 : return 0;
1262 : : }
1263 : :
1264 : 124 : void SvLBox::CancelTextEditing()
1265 : : {
1266 : : DBG_CHKTHIS(SvLBox,0);
1267 [ - + ]: 124 : if ( pEdCtrl )
1268 : 0 : pEdCtrl->StopEditing( sal_True );
1269 : 124 : nImpFlags &= (~SVLBOX_IN_EDT);
1270 : 124 : }
1271 : :
1272 : 0 : void SvLBox::EndEditing( sal_Bool bCancel )
1273 : : {
1274 : : DBG_CHKTHIS(SvLBox,0);
1275 [ # # ]: 0 : if( pEdCtrl )
1276 : 0 : pEdCtrl->StopEditing( bCancel );
1277 : 0 : nImpFlags &= (~SVLBOX_IN_EDT);
1278 : 0 : }
1279 : :
1280 : :
1281 : 0 : bool SvLBox::IsEmptyTextAllowed() const
1282 : : {
1283 : : DBG_CHKTHIS(SvLBox,0);
1284 : 0 : return pLBoxImpl->m_bIsEmptyTextAllowed;
1285 : : }
1286 : :
1287 : 0 : void SvLBox::ForbidEmptyText()
1288 : : {
1289 : : DBG_CHKTHIS(SvLBox,0);
1290 : 0 : pLBoxImpl->m_bIsEmptyTextAllowed = false;
1291 : 0 : }
1292 : :
1293 : 0 : void SvLBox::EditedText( const String& )
1294 : : {
1295 : : DBG_CHKTHIS(SvLBox,0);
1296 : 0 : }
1297 : :
1298 : 0 : void SvLBox::EditingRequest( SvLBoxEntry*, SvLBoxItem*,const Point& )
1299 : : {
1300 : : DBG_CHKTHIS(SvLBox,0);
1301 : 0 : }
1302 : :
1303 : :
1304 : 2398 : SvLBoxEntry* SvLBox::CreateEntry() const
1305 : : {
1306 : : DBG_CHKTHIS(SvLBox,0);
1307 [ + - ]: 2398 : return new SvLBoxEntry;
1308 : : }
1309 : :
1310 : 0 : void SvLBox::MakeVisible( SvLBoxEntry* )
1311 : : {
1312 : : DBG_CHKTHIS(SvLBox,0);
1313 : 0 : }
1314 : :
1315 : 0 : void SvLBox::Command( const CommandEvent& i_rCommandEvent )
1316 : : {
1317 : : DBG_CHKTHIS(SvLBox,0);
1318 : :
1319 [ # # ]: 0 : if ( COMMAND_STARTDRAG == i_rCommandEvent.GetCommand() )
1320 : : {
1321 : 0 : Point aEventPos( i_rCommandEvent.GetMousePosPixel() );
1322 [ # # ]: 0 : MouseEvent aMouseEvt( aEventPos, 1, MOUSE_SELECT, MOUSE_LEFT );
1323 [ # # ]: 0 : MouseButtonUp( aMouseEvt );
1324 : : }
1325 : 0 : Control::Command( i_rCommandEvent );
1326 : 0 : }
1327 : :
1328 : 0 : void SvLBox::KeyInput( const KeyEvent& rKEvt )
1329 : : {
1330 : 0 : bool bHandled = HandleKeyInput( rKEvt );
1331 [ # # ]: 0 : if ( !bHandled )
1332 : 0 : Control::KeyInput( rKEvt );
1333 : 0 : }
1334 : :
1335 : 0 : const void* SvLBox::FirstSearchEntry( String& _rEntryText ) const
1336 : : {
1337 : 0 : SvLBoxEntry* pEntry = GetCurEntry();
1338 [ # # ]: 0 : if ( pEntry )
1339 : 0 : pEntry = const_cast< SvLBoxEntry* >( static_cast< const SvLBoxEntry* >( NextSearchEntry( pEntry, _rEntryText ) ) );
1340 : : else
1341 : : {
1342 : 0 : pEntry = FirstSelected();
1343 [ # # ]: 0 : if ( !pEntry )
1344 : 0 : pEntry = First();
1345 : : }
1346 : :
1347 [ # # ]: 0 : if ( pEntry )
1348 [ # # ]: 0 : _rEntryText = GetEntryText( pEntry );
1349 : :
1350 : 0 : return pEntry;
1351 : : }
1352 : :
1353 : 0 : const void* SvLBox::NextSearchEntry( const void* _pCurrentSearchEntry, String& _rEntryText ) const
1354 : : {
1355 : 0 : SvLBoxEntry* pEntry = const_cast< SvLBoxEntry* >( static_cast< const SvLBoxEntry* >( _pCurrentSearchEntry ) );
1356 : :
1357 [ # # # # : 0 : if ( ( ( GetChildCount( pEntry ) > 0 )
# # ][ # # ]
1358 : 0 : || ( pEntry->HasChildrenOnDemand() )
1359 : : )
1360 : 0 : && !IsExpanded( pEntry )
1361 : : )
1362 : : {
1363 : 0 : pEntry = NextSibling( pEntry );
1364 : : }
1365 : : else
1366 : : {
1367 : 0 : pEntry = Next( pEntry );
1368 : : }
1369 : :
1370 [ # # ]: 0 : if ( !pEntry )
1371 : 0 : pEntry = First();
1372 : :
1373 [ # # ]: 0 : if ( pEntry )
1374 [ # # ]: 0 : _rEntryText = GetEntryText( pEntry );
1375 : :
1376 : 0 : return pEntry;
1377 : : }
1378 : :
1379 : 0 : void SvLBox::SelectSearchEntry( const void* _pEntry )
1380 : : {
1381 : 0 : SvLBoxEntry* pEntry = const_cast< SvLBoxEntry* >( static_cast< const SvLBoxEntry* >( _pEntry ) );
1382 : : DBG_ASSERT( pEntry, "SvLBox::SelectSearchEntry: invalid entry!" );
1383 [ # # ]: 0 : if ( !pEntry )
1384 : 0 : return;
1385 : :
1386 : 0 : SelectAll( sal_False );
1387 : 0 : SetCurEntry( pEntry );
1388 : 0 : Select( pEntry );
1389 : : }
1390 : :
1391 : 0 : void SvLBox::ExecuteSearchEntry( const void* /*_pEntry*/ ) const
1392 : : {
1393 : : // nothing to do here, we have no "execution"
1394 : 0 : }
1395 : :
1396 : 0 : ::vcl::StringEntryIdentifier SvLBox::CurrentEntry( String& _out_entryText ) const
1397 : : {
1398 : : // always accept the current entry if there is one
1399 : 0 : SvLBoxEntry* pCurrentEntry( GetCurEntry() );
1400 [ # # ]: 0 : if ( pCurrentEntry )
1401 : : {
1402 [ # # ]: 0 : _out_entryText = GetEntryText( pCurrentEntry );
1403 : 0 : return pCurrentEntry;
1404 : : }
1405 : 0 : return FirstSearchEntry( _out_entryText );
1406 : : }
1407 : :
1408 : 0 : ::vcl::StringEntryIdentifier SvLBox::NextEntry( ::vcl::StringEntryIdentifier _currentEntry, String& _out_entryText ) const
1409 : : {
1410 : 0 : return NextSearchEntry( _currentEntry, _out_entryText );
1411 : : }
1412 : :
1413 : 0 : void SvLBox::SelectEntry( ::vcl::StringEntryIdentifier _entry )
1414 : : {
1415 : 0 : SelectSearchEntry( _entry );
1416 : 0 : }
1417 : :
1418 : 0 : bool SvLBox::HandleKeyInput( const KeyEvent& _rKEvt )
1419 : : {
1420 [ # # # # ]: 0 : if ( IsEntryMnemonicsEnabled()
[ # # ]
1421 : 0 : && pLBoxImpl->m_aMnemonicEngine.HandleKeyEvent( _rKEvt )
1422 : : )
1423 : 0 : return true;
1424 : :
1425 [ # # ]: 0 : if ( ( GetStyle() & WB_QUICK_SEARCH ) != 0 )
1426 : : {
1427 : 0 : pLBoxImpl->m_bDoingQuickSelection = true;
1428 : 0 : const bool bHandled = pLBoxImpl->m_aQuickSelectionEngine.HandleKeyEvent( _rKEvt );
1429 : 0 : pLBoxImpl->m_bDoingQuickSelection = false;
1430 [ # # ]: 0 : if ( bHandled )
1431 : 0 : return true;
1432 : : }
1433 : :
1434 : 0 : return false;
1435 : : }
1436 : :
1437 : 0 : SvLBoxEntry* SvLBox::GetEntry( const Point&, sal_Bool ) const
1438 : : {
1439 : : DBG_CHKTHIS(SvLBox,0);
1440 : 0 : return 0;
1441 : : }
1442 : :
1443 : 14 : void SvLBox::ModelHasEntryInvalidated( SvListEntry* pEntry )
1444 : : {
1445 : : DBG_CHKTHIS(SvLBox,0);
1446 : 14 : sal_uInt16 nCount = ((SvLBoxEntry*)pEntry)->ItemCount();
1447 [ + + ]: 42 : for( sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++ )
1448 : : {
1449 : 28 : SvLBoxItem* pItem = ((SvLBoxEntry*)pEntry)->GetItem( nIdx );
1450 : 28 : pItem->InitViewData( this, (SvLBoxEntry*)pEntry, 0 );
1451 : : }
1452 : 14 : }
1453 : :
1454 : 0 : void SvLBox::WriteDragServerInfo( const Point&, SvLBoxDDInfo* )
1455 : : {
1456 : : DBG_CHKTHIS(SvLBox,0);
1457 : 0 : }
1458 : :
1459 : 0 : void SvLBox::ReadDragServerInfo(const Point&, SvLBoxDDInfo* )
1460 : : {
1461 : : DBG_CHKTHIS(SvLBox,0);
1462 : 0 : }
1463 : :
1464 : 0 : sal_Bool SvLBox::EditingCanceled() const
1465 : : {
1466 [ # # ][ # # ]: 0 : if( pEdCtrl && pEdCtrl->EditingCanceled() )
[ # # ]
1467 : 0 : return sal_True;
1468 : 0 : return sal_False;
1469 : : }
1470 : :
1471 : :
1472 : : //JP 28.3.2001: new Drag & Drop API
1473 : 0 : sal_Int8 SvLBox::AcceptDrop( const AcceptDropEvent& rEvt )
1474 : : {
1475 : : DBG_CHKTHIS(SvLBox,0);
1476 : 0 : sal_Int8 nRet = DND_ACTION_NONE;
1477 : :
1478 [ # # ][ # # ]: 0 : if( rEvt.mbLeaving || !CheckDragAndDropMode( pDDSource, rEvt.mnAction ) )
[ # # ]
1479 : : {
1480 : 0 : ImplShowTargetEmphasis( pTargetEntry, sal_False );
1481 : : }
1482 [ # # ]: 0 : else if( !nDragDropMode )
1483 : : {
1484 : : SAL_WARN( "svtools.contnr", "SvLBox::QueryDrop(): no target" );
1485 : : }
1486 : : else
1487 : : {
1488 : 0 : SvLBoxEntry* pEntry = GetDropTarget( rEvt.maPosPixel );
1489 [ # # ]: 0 : if( !IsDropFormatSupported( SOT_FORMATSTR_ID_TREELISTBOX ) )
1490 : : {
1491 : : SAL_WARN( "svtools.contnr", "SvLBox::QueryDrop(): no format" );
1492 : : }
1493 : : else
1494 : : {
1495 : : DBG_ASSERT( pDDSource, "SvLBox::QueryDrop(): SourceBox == 0" );
1496 [ # # ]: 0 : if( !( pEntry && pDDSource->GetModel() == this->GetModel()
1497 : : && DND_ACTION_MOVE == rEvt.mnAction
1498 [ # # # # ]: 0 : && ( pEntry->nEntryFlags & SV_ENTRYFLAG_DISABLE_DROP ) ))
[ # # ][ # # ]
1499 : : {
1500 [ # # ]: 0 : if( NotifyAcceptDrop( pEntry ))
1501 : 0 : nRet = rEvt.mnAction;
1502 : : }
1503 : : }
1504 : :
1505 : : // **** draw emphasis ****
1506 [ # # ]: 0 : if( DND_ACTION_NONE == nRet )
1507 : 0 : ImplShowTargetEmphasis( pTargetEntry, sal_False );
1508 [ # # ][ # # ]: 0 : else if( pEntry != pTargetEntry || !(nImpFlags & SVLBOX_TARGEMPH_VIS) )
1509 : : {
1510 : 0 : ImplShowTargetEmphasis( pTargetEntry, sal_False );
1511 : 0 : pTargetEntry = pEntry;
1512 : 0 : ImplShowTargetEmphasis( pTargetEntry, sal_True );
1513 : : }
1514 : : }
1515 : 0 : return nRet;
1516 : : }
1517 : :
1518 : 0 : sal_Int8 SvLBox::ExecuteDrop( const ExecuteDropEvent& rEvt, SvLBox* pSourceView )
1519 : : {
1520 : : DBG_CHKTHIS(SvLBox,0);
1521 : 0 : sal_Int8 nRet = DND_ACTION_NONE;
1522 : :
1523 : : DBG_ASSERT( pSourceView, "SvLBox::ExecuteDrop(): no source view" );
1524 [ # # ]: 0 : pSourceView->EnableSelectionAsDropTarget( sal_True, sal_True );
1525 : :
1526 [ # # ]: 0 : ImplShowTargetEmphasis( pTargetEntry, sal_False );
1527 : 0 : pDDTarget = this;
1528 : :
1529 : : SvLBoxDDInfo aDDInfo;
1530 : :
1531 [ # # ]: 0 : TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
1532 [ # # ][ # # ]: 0 : if( aData.HasFormat( SOT_FORMATSTR_ID_TREELISTBOX ))
1533 : : {
1534 [ # # ]: 0 : ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
1535 [ # # ]: 0 : if( aData.GetSequence( SOT_FORMATSTR_ID_TREELISTBOX, aSeq ) &&
[ # # # # ]
[ # # ]
1536 : 0 : sizeof(SvLBoxDDInfo) == aSeq.getLength() )
1537 : : {
1538 : 0 : memcpy( &aDDInfo, aSeq.getConstArray(), sizeof(SvLBoxDDInfo) );
1539 : 0 : nRet = rEvt.mnAction;
1540 [ # # ]: 0 : }
1541 : : }
1542 : :
1543 [ # # ]: 0 : if( DND_ACTION_NONE != nRet )
1544 : : {
1545 : 0 : nRet = DND_ACTION_NONE;
1546 : :
1547 [ # # ]: 0 : ReadDragServerInfo( rEvt.maPosPixel, &aDDInfo );
1548 : :
1549 : 0 : SvLBoxEntry* pTarget = pTargetEntry; // may be 0!
1550 : :
1551 [ # # ]: 0 : if( DND_ACTION_COPY == rEvt.mnAction )
1552 : : {
1553 [ # # ][ # # ]: 0 : if ( CopySelection( aDDInfo.pSource, pTarget ) )
1554 : 0 : nRet = rEvt.mnAction;
1555 : : }
1556 [ # # ]: 0 : else if( DND_ACTION_MOVE == rEvt.mnAction )
1557 : : {
1558 [ # # ][ # # ]: 0 : if ( MoveSelection( aDDInfo.pSource, pTarget ) )
1559 : 0 : nRet = rEvt.mnAction;
1560 : : }
1561 [ # # ]: 0 : else if( DND_ACTION_COPYMOVE == rEvt.mnAction )
1562 : : {
1563 [ # # ][ # # ]: 0 : if ( MoveSelectionCopyFallbackPossible( aDDInfo.pSource, pTarget, sal_True ) )
1564 : 0 : nRet = rEvt.mnAction;
1565 : : }
1566 : : }
1567 [ # # ]: 0 : return nRet;
1568 : : }
1569 : :
1570 : 0 : sal_Int8 SvLBox::ExecuteDrop( const ExecuteDropEvent& rEvt )
1571 : : {
1572 : : DBG_CHKTHIS(SvLBox,0);
1573 : 0 : return ExecuteDrop( rEvt, GetSourceView() );
1574 : : }
1575 : :
1576 : 0 : void SvLBox::StartDrag( sal_Int8, const Point& rPosPixel )
1577 : : {
1578 : : DBG_CHKTHIS(SvLBox,0);
1579 : :
1580 : 0 : Point aEventPos( rPosPixel );
1581 [ # # ]: 0 : MouseEvent aMouseEvt( aEventPos, 1, MOUSE_SELECT, MOUSE_LEFT );
1582 [ # # ]: 0 : MouseButtonUp( aMouseEvt );
1583 : :
1584 : 0 : nOldDragMode = GetDragDropMode();
1585 [ # # ]: 0 : if ( !nOldDragMode )
1586 : : return;
1587 : :
1588 [ # # ]: 0 : ReleaseMouse();
1589 : :
1590 [ # # ]: 0 : SvLBoxEntry* pEntry = GetEntry( rPosPixel ); // GetDropTarget( rPos );
1591 [ # # ]: 0 : if( !pEntry )
1592 : : {
1593 [ # # ]: 0 : DragFinished( DND_ACTION_NONE );
1594 : : return;
1595 : : }
1596 : :
1597 [ # # ]: 0 : TransferDataContainer* pContainer = new TransferDataContainer;
1598 : : ::com::sun::star::uno::Reference<
1599 [ # # ][ # # ]: 0 : ::com::sun::star::datatransfer::XTransferable > xRef( pContainer );
1600 : :
1601 [ # # ]: 0 : nDragDropMode = NotifyStartDrag( *pContainer, pEntry );
1602 [ # # ][ # # ]: 0 : if( !nDragDropMode || 0 == GetSelectionCount() )
[ # # ]
1603 : : {
1604 : 0 : nDragDropMode = nOldDragMode;
1605 [ # # ]: 0 : DragFinished( DND_ACTION_NONE );
1606 : : return;
1607 : : }
1608 : :
1609 : : SvLBoxDDInfo aDDInfo;
1610 : 0 : memset(&aDDInfo,0,sizeof(SvLBoxDDInfo));
1611 [ # # ]: 0 : aDDInfo.pApp = GetpApp();
1612 : 0 : aDDInfo.pSource = this;
1613 : 0 : aDDInfo.pDDStartEntry = pEntry;
1614 : : // let derived views do their thing
1615 [ # # ]: 0 : WriteDragServerInfo( rPosPixel, &aDDInfo );
1616 : :
1617 : : pContainer->CopyAnyData( SOT_FORMATSTR_ID_TREELISTBOX,
1618 [ # # ]: 0 : (sal_Char*)&aDDInfo, sizeof(SvLBoxDDInfo) );
1619 : 0 : pDDSource = this;
1620 : 0 : pDDTarget = 0;
1621 : :
1622 [ # # ]: 0 : sal_Bool bOldUpdateMode = Control::IsUpdateMode();
1623 [ # # ]: 0 : Control::SetUpdateMode( sal_True );
1624 [ # # ]: 0 : Update();
1625 [ # # ]: 0 : Control::SetUpdateMode( bOldUpdateMode );
1626 : :
1627 : : // Disallow using the selection and its children as drop targets.
1628 : : // Important: If the selection of the SourceListBox is changed in the
1629 : : // DropHandler, the entries have to be allowed as drop targets again:
1630 : : // (GetSourceListBox()->EnableSelectionAsDropTarget( sal_True, sal_True );)
1631 [ # # ]: 0 : EnableSelectionAsDropTarget( sal_False, sal_True /* with children */ );
1632 : :
1633 [ # # ][ # # ]: 0 : pContainer->StartDrag( this, nDragOptions, GetDragFinishedHdl() );
[ # # ]
1634 : : }
1635 : :
1636 : 0 : void SvLBox::DragFinished( sal_Int8
1637 : : #ifndef UNX
1638 : : nAction
1639 : : #endif
1640 : : )
1641 : : {
1642 : 0 : EnableSelectionAsDropTarget( sal_True, sal_True );
1643 : :
1644 : : #ifndef UNX
1645 : : if( (nAction == DND_ACTION_MOVE) && ( (pDDTarget &&
1646 : : ((sal_uLong)(pDDTarget->GetModel())!=(sal_uLong)(this->GetModel()))) ||
1647 : : !pDDTarget ))
1648 : : {
1649 : : RemoveSelection();
1650 : : }
1651 : : #endif
1652 : :
1653 : 0 : ImplShowTargetEmphasis( pTargetEntry, sal_False );
1654 : 0 : pDDSource = 0;
1655 : 0 : pDDTarget = 0;
1656 : 0 : pTargetEntry = 0;
1657 : 0 : nDragDropMode = nOldDragMode;
1658 : 0 : }
1659 : :
1660 : 0 : DragDropMode SvLBox::NotifyStartDrag( TransferDataContainer&, SvLBoxEntry* )
1661 : : {
1662 : : DBG_CHKTHIS(SvLBox,0);
1663 : 0 : return (DragDropMode)0xffff;
1664 : : }
1665 : :
1666 : 0 : sal_Bool SvLBox::NotifyAcceptDrop( SvLBoxEntry* )
1667 : : {
1668 : : DBG_CHKTHIS(SvLBox,0);
1669 : 0 : return sal_True;
1670 : : }
1671 : :
1672 : : // Handler and methods for Drag - finished handler.
1673 : : // The with get GetDragFinishedHdl() get link can set on the
1674 : : // TransferDataContainer. This link is a callback for the DragFinished
1675 : : // call. AddBox method is called from the GetDragFinishedHdl() and the
1676 : : // remove is called in link callback and in the destructor. So it can't
1677 : : // called to a deleted object.
1678 : :
1679 : : namespace
1680 : : {
1681 : : struct SortLBoxes : public rtl::Static<std::set<sal_uLong>, SortLBoxes> {};
1682 : : }
1683 : :
1684 : 0 : void SvLBox::AddBoxToDDList_Impl( const SvLBox& rB )
1685 : : {
1686 : 0 : sal_uLong nVal = (sal_uLong)&rB;
1687 [ # # ][ # # ]: 0 : SortLBoxes::get().insert( nVal );
1688 : 0 : }
1689 : :
1690 : 122 : void SvLBox::RemoveBoxFromDDList_Impl( const SvLBox& rB )
1691 : : {
1692 : 122 : sal_uLong nVal = (sal_uLong)&rB;
1693 [ + - ][ + - ]: 122 : SortLBoxes::get().erase( nVal );
1694 : 122 : }
1695 : :
1696 : 0 : IMPL_STATIC_LINK( SvLBox, DragFinishHdl_Impl, sal_Int8*, pAction )
1697 : : {
1698 : 0 : sal_uLong nVal = (sal_uLong)pThis;
1699 [ # # ]: 0 : std::set<sal_uLong> &rSortLBoxes = SortLBoxes::get();
1700 [ # # ]: 0 : std::set<sal_uLong>::const_iterator it = rSortLBoxes.find(nVal);
1701 [ # # ][ # # ]: 0 : if( it != rSortLBoxes.end() )
1702 : : {
1703 [ # # ]: 0 : pThis->DragFinished( *pAction );
1704 [ # # ]: 0 : rSortLBoxes.erase( it );
1705 : : }
1706 : 0 : return 0;
1707 : : }
1708 : :
1709 : 0 : Link SvLBox::GetDragFinishedHdl() const
1710 : : {
1711 : 0 : AddBoxToDDList_Impl( *this );
1712 : 0 : return STATIC_LINK( this, SvLBox, DragFinishHdl_Impl );
1713 : : }
1714 : :
1715 : 0 : void SvLBox::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& ) const
1716 : : {
1717 : 0 : }
1718 : :
1719 : 0 : ::com::sun::star::uno::Reference< XAccessible > SvLBox::CreateAccessible()
1720 : : {
1721 : 0 : return ::com::sun::star::uno::Reference< XAccessible >();
1722 : : }
1723 : :
1724 : 0 : Rectangle SvLBox::GetBoundingRect( SvLBoxEntry* )
1725 : : {
1726 : 0 : return Rectangle();
1727 : : }
1728 : :
1729 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|