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 "svtools/controldims.hrc"
21 :
22 : #include "RemoteDialogClientBox.hxx"
23 : #include "RemoteDialog.hrc"
24 :
25 : #include "comphelper/processfactory.hxx"
26 : #include "com/sun/star/i18n/CollatorOptions.hpp"
27 : #include "com/sun/star/deployment/DependencyException.hpp"
28 : #include "com/sun/star/deployment/DeploymentException.hpp"
29 :
30 : using namespace ::com::sun::star;
31 :
32 : namespace sd {
33 :
34 : //------------------------------------------------------------------------------
35 : // struct ClientBoxEntry
36 : //------------------------------------------------------------------------------
37 0 : ClientBoxEntry::ClientBoxEntry( ClientInfo* pClientInfo ) :
38 : m_bActive( false ),
39 0 : m_pClientInfo( pClientInfo )
40 : {
41 0 : }
42 :
43 : //------------------------------------------------------------------------------
44 0 : ClientBoxEntry::~ClientBoxEntry()
45 0 : {}
46 :
47 :
48 : //------------------------------------------------------------------------------
49 : // ClientRemovedListener
50 : //------------------------------------------------------------------------------
51 0 : void ClientRemovedListener::disposing( lang::EventObject const & rEvt )
52 : throw ( uno::RuntimeException )
53 : {
54 : (void) rEvt;
55 0 : }
56 :
57 : //------------------------------------------------------------------------------
58 0 : ClientRemovedListener::~ClientRemovedListener()
59 : {
60 0 : }
61 :
62 : //------------------------------------------------------------------------------
63 : // ClientBox
64 : //------------------------------------------------------------------------------
65 0 : ClientBox::ClientBox( Dialog* pParent, RemoteServer *pServer,
66 : const SdResId& aId ) :
67 : Control( pParent, aId ),
68 : m_bHasScrollBar( false ),
69 : m_bHasActive( false ),
70 : m_bNeedsRecalc( true ),
71 : m_bInCheckMode( false ),
72 : m_bAdjustActive( false ),
73 : m_bInDelete( false ),
74 : m_nActive( 0 ),
75 : m_nTopIndex( 0 ),
76 : m_nActiveHeight( 0 ),
77 : m_nExtraHeight( 2 ),
78 : m_aPinBox( this, SdResId( INPUT_PIN ) ),
79 : m_aPinDescription( this, SdResId( TEXT_PIN ) ),
80 0 : m_pScrollBar( new ScrollBar( this, WB_VERT ) ),
81 0 : m_pServer( pServer )
82 : {
83 0 : m_pScrollBar->SetScrollHdl( LINK( this, ClientBox, ScrollHdl ) );
84 0 : m_pScrollBar->EnableDrag();
85 :
86 0 : m_aPinBox.SetUseThousandSep(false);
87 : // m_aPinDescription.SetText( String( SdResId( STR_ENTER_PIN ) ) );
88 :
89 0 : SetPaintTransparent( true );
90 0 : SetPosPixel( Point( RSC_SP_DLG_INNERBORDER_LEFT, RSC_SP_DLG_INNERBORDER_TOP ) );
91 0 : long nIconHeight = 2*TOP_OFFSET + SMALL_ICON_SIZE;
92 0 : long nTitleHeight = 2*TOP_OFFSET + GetTextHeight();
93 0 : if ( nIconHeight < nTitleHeight )
94 0 : m_nStdHeight = nTitleHeight;
95 : else
96 0 : m_nStdHeight = nIconHeight;
97 0 : m_nStdHeight += GetTextHeight() + TOP_OFFSET;
98 :
99 : // nIconHeight = ICON_HEIGHT + 2*TOP_OFFSET + 1;
100 : // if ( m_nStdHeight < nIconHeight )
101 : // m_nStdHeight = nIconHeight;
102 :
103 0 : m_nActiveHeight = m_nStdHeight;
104 :
105 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
106 0 : if( IsControlBackground() )
107 0 : SetBackground( GetControlBackground() );
108 : else
109 0 : SetBackground( rStyleSettings.GetFieldColor() );
110 :
111 0 : m_xRemoveListener = new ClientRemovedListener( this );
112 :
113 0 : Show();
114 0 : }
115 :
116 : //------------------------------------------------------------------------------
117 0 : ClientBox::~ClientBox()
118 : {
119 0 : if ( ! m_bInDelete )
120 0 : DeleteRemoved();
121 :
122 0 : m_bInDelete = true;
123 :
124 : typedef std::vector< TClientBoxEntry >::iterator ITER;
125 :
126 0 : for ( ITER iIndex = m_vEntries.begin(); iIndex < m_vEntries.end(); ++iIndex )
127 : {
128 : // (*iIndex)->m_xPackage->removeEventListener( uno::Reference< lang::XEventListener > ( m_xRemoveListener, uno::UNO_QUERY ) );
129 : }
130 :
131 0 : m_vEntries.clear();
132 :
133 0 : m_xRemoveListener.clear();
134 0 : }
135 :
136 : //------------------------------------------------------------------------------
137 : // Title + description
138 0 : void ClientBox::CalcActiveHeight( const long nPos )
139 : {
140 : (void) nPos;
141 0 : const ::osl::MutexGuard aGuard( m_entriesMutex );
142 :
143 : // get title height
144 : long aTextHeight;
145 0 : long nIconHeight = 2*TOP_OFFSET + SMALL_ICON_SIZE;
146 0 : long nTitleHeight = 2*TOP_OFFSET + GetTextHeight();
147 0 : if ( nIconHeight < nTitleHeight )
148 0 : aTextHeight = nTitleHeight;
149 : else
150 0 : aTextHeight = nIconHeight;
151 :
152 : // Text entry height
153 0 : Size aSize = GetOutputSizePixel();
154 0 : if ( m_bHasScrollBar )
155 0 : aSize.Width() -= m_pScrollBar->GetSizePixel().Width();
156 :
157 0 : aSize.Width() -= ICON_OFFSET;
158 :
159 : aSize = LogicToPixel( Size( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ),
160 0 : MapMode( MAP_APPFONT ) );
161 0 : aTextHeight += aSize.Height();
162 :
163 0 : if ( aTextHeight < m_nStdHeight )
164 0 : aTextHeight = m_nStdHeight;
165 :
166 0 : m_nActiveHeight = aTextHeight + 2;
167 0 : }
168 :
169 : //------------------------------------------------------------------------------
170 0 : Rectangle ClientBox::GetEntryRect( const long nPos ) const
171 : {
172 0 : const ::osl::MutexGuard aGuard( m_entriesMutex );
173 :
174 0 : Size aSize( GetOutputSizePixel() );
175 :
176 0 : if ( m_bHasScrollBar )
177 0 : aSize.Width() -= m_pScrollBar->GetSizePixel().Width();
178 :
179 0 : if ( m_vEntries[ nPos ]->m_bActive )
180 0 : aSize.Height() = m_nActiveHeight;
181 : else
182 0 : aSize.Height() = m_nStdHeight;
183 :
184 0 : Point aPos( 0, -m_nTopIndex + nPos * m_nStdHeight );
185 0 : if ( m_bHasActive && ( nPos < m_nActive ) )
186 0 : aPos.Y() += m_nActiveHeight - m_nStdHeight;
187 :
188 0 : return Rectangle( aPos, aSize );
189 : }
190 :
191 : //------------------------------------------------------------------------------
192 0 : void ClientBox::DeleteRemoved()
193 : {
194 0 : const ::osl::MutexGuard aGuard( m_entriesMutex );
195 :
196 0 : m_bInDelete = true;
197 :
198 0 : if ( ! m_vRemovedEntries.empty() )
199 : {
200 0 : m_vRemovedEntries.clear();
201 : }
202 :
203 0 : m_bInDelete = false;
204 0 : }
205 :
206 0 : long ClientBox::GetActiveEntryIndex()
207 : {
208 0 : if ( m_bHasActive )
209 0 : return m_nActive;
210 : else
211 0 : return -1;
212 : }
213 :
214 : //------------------------------------------------------------------------------
215 : //This function may be called with nPos < 0
216 0 : void ClientBox::selectEntry( const long nPos )
217 : {
218 : //ToDo whe should not use the guard at such a big scope here.
219 : //Currently it is used to gard m_vEntries and m_nActive. m_nActive will be
220 : //modified in this function.
221 : //It would be probably best to always use a copy of m_vEntries
222 : //and some other state variables from ClientBox for
223 : //the whole painting operation. See issue i86993
224 0 : ::osl::ClearableMutexGuard guard(m_entriesMutex);
225 :
226 0 : if ( m_bInCheckMode )
227 0 : return;
228 :
229 0 : if ( m_bHasActive )
230 : {
231 0 : if ( nPos == m_nActive )
232 0 : return;
233 :
234 0 : m_bHasActive = false;
235 0 : m_vEntries[ m_nActive ]->m_bActive = false;
236 : }
237 :
238 0 : if ( ( nPos >= 0 ) && ( nPos < (long) m_vEntries.size() ) )
239 : {
240 0 : m_bHasActive = true;
241 0 : m_nActive = nPos;
242 0 : m_vEntries[ nPos ]->m_bActive = true;
243 :
244 0 : if ( IsReallyVisible() )
245 : {
246 0 : m_bAdjustActive = true;
247 : }
248 : }
249 :
250 0 : if ( IsReallyVisible() )
251 : {
252 0 : m_bNeedsRecalc = true;
253 0 : Invalidate();
254 : }
255 :
256 0 : guard.clear();
257 : }
258 :
259 : // -----------------------------------------------------------------------
260 0 : void ClientBox::DrawRow( const Rectangle& rRect, const TClientBoxEntry pEntry )
261 : {
262 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
263 :
264 0 : if ( pEntry->m_bActive )
265 0 : SetTextColor( rStyleSettings.GetHighlightTextColor() );
266 : else
267 0 : SetTextColor( rStyleSettings.GetFieldTextColor() );
268 :
269 0 : if ( pEntry->m_bActive )
270 : {
271 0 : SetLineColor();
272 0 : SetFillColor( rStyleSettings.GetHighlightColor() );
273 0 : DrawRect( rRect );
274 : }
275 : else
276 : {
277 0 : if( IsControlBackground() )
278 0 : SetBackground( GetControlBackground() );
279 : else
280 0 : SetBackground( rStyleSettings.GetFieldColor() );
281 :
282 0 : SetTextFillColor();
283 0 : Erase( rRect );
284 : }
285 :
286 : // FIXME: draw bluetooth or wifi icon
287 0 : Point aPos( rRect.TopLeft() );
288 : // aPos += Point( TOP_OFFSET, TOP_OFFSET );
289 : // Image aImage;
290 : // if ( ! pEntry->m_aIcon )
291 : // aImage = m_aDefaultImage;
292 : // else
293 : // aImage = pEntry->m_aIcon;
294 : // Size aImageSize = aImage.GetSizePixel();
295 : // if ( ( aImageSize.Width() <= ICON_WIDTH ) && ( aImageSize.Height() <= ICON_HEIGHT ) )
296 : // DrawImage( Point( aPos.X()+((ICON_WIDTH-aImageSize.Width())/2), aPos.Y()+((ICON_HEIGHT-aImageSize.Height())/2) ), aImage );
297 : // else
298 : // DrawImage( aPos, Size( ICON_WIDTH, ICON_HEIGHT ), aImage );
299 :
300 : // Setup fonts
301 0 : Font aStdFont( GetFont() );
302 0 : Font aBoldFont( aStdFont );
303 0 : aBoldFont.SetWeight( WEIGHT_BOLD );
304 0 : SetFont( aBoldFont );
305 0 : long aTextHeight = GetTextHeight();
306 :
307 : // Get max title width
308 0 : long nMaxTitleWidth = rRect.GetWidth() - ICON_OFFSET;
309 0 : nMaxTitleWidth -= ( 2 * SMALL_ICON_SIZE ) + ( 4 * SPACE_BETWEEN );
310 :
311 0 : long aTitleWidth = GetTextWidth( String( pEntry->m_pClientInfo->mName ) ) + (aTextHeight / 3);
312 :
313 0 : aPos = rRect.TopLeft() + Point( ICON_OFFSET, TOP_OFFSET );
314 :
315 0 : if ( aTitleWidth > nMaxTitleWidth )
316 : {
317 0 : aTitleWidth = nMaxTitleWidth - (aTextHeight / 3);
318 0 : String aShortTitle = GetEllipsisString( pEntry->m_pClientInfo->mName,
319 0 : aTitleWidth );
320 0 : DrawText( aPos, aShortTitle );
321 0 : aTitleWidth += (aTextHeight / 3);
322 : }
323 : else
324 0 : DrawText( aPos, pEntry->m_pClientInfo->mName );
325 :
326 0 : SetFont( aStdFont );
327 :
328 0 : aPos.Y() += aTextHeight;
329 0 : if ( pEntry->m_bActive )
330 : {
331 : Size aSize = LogicToPixel( Size( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ),
332 0 : MapMode( MAP_APPFONT ) );
333 0 : m_aPinBox.SetSizePixel( aSize );
334 0 : const Rectangle aRect( GetEntryRect( m_nActive ) );
335 0 : Size aBtnSize( m_aPinBox.GetSizePixel() );
336 : Point aBtnPos( aRect.Left(),
337 0 : aRect.Bottom() - TOP_OFFSET - aBtnSize.Height() );
338 : // m_aPinDescription.SetPosPixel( aBtnPos );
339 0 : DrawText( Rectangle( aBtnPos.X(), aBtnPos.Y(), rRect.Right(), rRect.Bottom() - TOP_OFFSET),
340 0 : String( SdResId( STR_ENTER_PIN ) ), 0 );
341 :
342 0 : aBtnPos = Point( aRect.Left() + GetTextWidth( String( SdResId( STR_ENTER_PIN ) ) ),
343 0 : aRect.Bottom() - TOP_OFFSET - aBtnSize.Height() );
344 :
345 0 : m_aPinBox.SetPosPixel( aBtnPos );
346 :
347 :
348 :
349 :
350 :
351 : // long nExtraHeight = 0;
352 : //
353 : // if ( pEntry->m_bHasButtons )
354 : // nExtraHeight = m_nExtraHeight;
355 : //
356 : // DrawText( Rectangle( aPos.X(), aPos.Y(), rRect.Right(), rRect.Bottom() - nExtraHeight ),
357 : // sDescription, TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
358 : }
359 : else
360 : {
361 : }
362 :
363 0 : SetLineColor( Color( COL_LIGHTGRAY ) );
364 0 : DrawLine( rRect.BottomLeft(), rRect.BottomRight() );
365 0 : }
366 :
367 : // -----------------------------------------------------------------------
368 0 : void ClientBox::RecalcAll()
369 : {
370 0 : if ( m_bHasActive )
371 0 : CalcActiveHeight( m_nActive );
372 :
373 0 : SetupScrollBar();
374 :
375 0 : if ( m_bHasActive )
376 : {
377 0 : Rectangle aEntryRect = GetEntryRect( m_nActive );
378 :
379 0 : if ( m_bAdjustActive )
380 : {
381 0 : m_bAdjustActive = false;
382 :
383 : // If the top of the selected entry isn't visible, make it visible
384 0 : if ( aEntryRect.Top() < 0 )
385 : {
386 0 : m_nTopIndex += aEntryRect.Top();
387 0 : aEntryRect.Move( 0, -aEntryRect.Top() );
388 : }
389 :
390 : // If the bottom of the selected entry isn't visible, make it visible even if now the top
391 : // isn't visible any longer ( the buttons are more important )
392 0 : Size aOutputSize = GetOutputSizePixel();
393 0 : if ( aEntryRect.Bottom() > aOutputSize.Height() )
394 : {
395 0 : m_nTopIndex += ( aEntryRect.Bottom() - aOutputSize.Height() );
396 0 : aEntryRect.Move( 0, -( aEntryRect.Bottom() - aOutputSize.Height() ) );
397 : }
398 :
399 : // If there is unused space below the last entry but all entries don't fit into the box,
400 : // move the content down to use the whole space
401 0 : const long nTotalHeight = GetTotalHeight();
402 0 : if ( m_bHasScrollBar && ( aOutputSize.Height() + m_nTopIndex > nTotalHeight ) )
403 : {
404 0 : long nOffset = m_nTopIndex;
405 0 : m_nTopIndex = nTotalHeight - aOutputSize.Height();
406 0 : nOffset -= m_nTopIndex;
407 0 : aEntryRect.Move( 0, nOffset );
408 : }
409 :
410 0 : if ( m_bHasScrollBar )
411 0 : m_pScrollBar->SetThumbPos( m_nTopIndex );
412 : }
413 : }
414 :
415 0 : m_bNeedsRecalc = false;
416 0 : }
417 :
418 : // -----------------------------------------------------------------------
419 0 : bool ClientBox::HandleTabKey( bool )
420 : {
421 0 : return false;
422 : }
423 :
424 : // -----------------------------------------------------------------------
425 0 : bool ClientBox::HandleCursorKey( sal_uInt16 nKeyCode )
426 : {
427 0 : if ( m_vEntries.empty() )
428 0 : return true;
429 :
430 0 : long nSelect = 0;
431 :
432 0 : if ( m_bHasActive )
433 : {
434 0 : long nPageSize = GetOutputSizePixel().Height() / m_nStdHeight;
435 0 : if ( nPageSize < 2 )
436 0 : nPageSize = 2;
437 :
438 0 : if ( ( nKeyCode == KEY_DOWN ) || ( nKeyCode == KEY_RIGHT ) )
439 0 : nSelect = m_nActive + 1;
440 0 : else if ( ( nKeyCode == KEY_UP ) || ( nKeyCode == KEY_LEFT ) )
441 0 : nSelect = m_nActive - 1;
442 0 : else if ( nKeyCode == KEY_HOME )
443 0 : nSelect = 0;
444 0 : else if ( nKeyCode == KEY_END )
445 0 : nSelect = m_vEntries.size() - 1;
446 0 : else if ( nKeyCode == KEY_PAGEUP )
447 0 : nSelect = m_nActive - nPageSize + 1;
448 0 : else if ( nKeyCode == KEY_PAGEDOWN )
449 0 : nSelect = m_nActive + nPageSize - 1;
450 : }
451 : else // when there is no selected entry, we will select the first or the last.
452 : {
453 0 : if ( ( nKeyCode == KEY_DOWN ) || ( nKeyCode == KEY_PAGEDOWN ) || ( nKeyCode == KEY_HOME ) )
454 0 : nSelect = 0;
455 0 : else if ( ( nKeyCode == KEY_UP ) || ( nKeyCode == KEY_PAGEUP ) || ( nKeyCode == KEY_END ) )
456 0 : nSelect = m_vEntries.size() - 1;
457 : }
458 :
459 0 : if ( nSelect < 0 )
460 0 : nSelect = 0;
461 0 : if ( nSelect >= (long) m_vEntries.size() )
462 0 : nSelect = m_vEntries.size() - 1;
463 :
464 0 : selectEntry( nSelect );
465 :
466 0 : return true;
467 : }
468 :
469 : // -----------------------------------------------------------------------
470 0 : void ClientBox::Paint( const Rectangle &/*rPaintRect*/ )
471 : {
472 0 : if ( !m_bInDelete )
473 0 : DeleteRemoved();
474 :
475 0 : if ( m_bNeedsRecalc )
476 0 : RecalcAll();
477 :
478 0 : Point aStart( 0, -m_nTopIndex );
479 0 : Size aSize( GetOutputSizePixel() );
480 :
481 0 : if ( m_bHasScrollBar )
482 0 : aSize.Width() -= m_pScrollBar->GetSizePixel().Width();
483 :
484 0 : const ::osl::MutexGuard aGuard( m_entriesMutex );
485 :
486 : typedef std::vector< TClientBoxEntry >::iterator ITER;
487 0 : for ( ITER iIndex = m_vEntries.begin(); iIndex < m_vEntries.end(); ++iIndex )
488 : {
489 0 : aSize.Height() = (*iIndex)->m_bActive ? m_nActiveHeight : m_nStdHeight;
490 0 : Rectangle aEntryRect( aStart, aSize );
491 0 : DrawRow( aEntryRect, *iIndex );
492 0 : aStart.Y() += aSize.Height();
493 0 : }
494 0 : }
495 :
496 : // -----------------------------------------------------------------------
497 0 : long ClientBox::GetTotalHeight() const
498 : {
499 0 : long nHeight = m_vEntries.size() * m_nStdHeight;
500 :
501 0 : if ( m_bHasActive )
502 : {
503 0 : nHeight += m_nActiveHeight - m_nStdHeight;
504 : }
505 :
506 0 : return nHeight;
507 : }
508 :
509 : // -----------------------------------------------------------------------
510 0 : void ClientBox::SetupScrollBar()
511 : {
512 0 : const Size aSize = GetOutputSizePixel();
513 0 : const long nScrBarSize = GetSettings().GetStyleSettings().GetScrollBarSize();
514 0 : const long nTotalHeight = GetTotalHeight();
515 0 : const bool bNeedsScrollBar = ( nTotalHeight > aSize.Height() );
516 :
517 0 : if ( bNeedsScrollBar )
518 : {
519 0 : if ( m_nTopIndex + aSize.Height() > nTotalHeight )
520 0 : m_nTopIndex = nTotalHeight - aSize.Height();
521 :
522 0 : m_pScrollBar->SetPosSizePixel( Point( aSize.Width() - nScrBarSize, 0 ),
523 0 : Size( nScrBarSize, aSize.Height() ) );
524 0 : m_pScrollBar->SetRangeMax( nTotalHeight );
525 0 : m_pScrollBar->SetVisibleSize( aSize.Height() );
526 0 : m_pScrollBar->SetPageSize( ( aSize.Height() * 4 ) / 5 );
527 0 : m_pScrollBar->SetLineSize( m_nStdHeight );
528 0 : m_pScrollBar->SetThumbPos( m_nTopIndex );
529 :
530 0 : if ( !m_bHasScrollBar )
531 0 : m_pScrollBar->Show();
532 : }
533 0 : else if ( m_bHasScrollBar )
534 : {
535 0 : m_pScrollBar->Hide();
536 0 : m_nTopIndex = 0;
537 : }
538 :
539 0 : m_bHasScrollBar = bNeedsScrollBar;
540 0 : }
541 :
542 : // -----------------------------------------------------------------------
543 0 : void ClientBox::Resize()
544 : {
545 0 : RecalcAll();
546 0 : }
547 :
548 : //------------------------------------------------------------------------------
549 0 : long ClientBox::PointToPos( const Point& rPos )
550 : {
551 0 : long nPos = ( rPos.Y() + m_nTopIndex ) / m_nStdHeight;
552 :
553 0 : if ( m_bHasActive && ( nPos > m_nActive ) )
554 : {
555 0 : if ( rPos.Y() + m_nTopIndex <= m_nActive*m_nStdHeight + m_nActiveHeight )
556 0 : nPos = m_nActive;
557 : else
558 0 : nPos = ( rPos.Y() + m_nTopIndex - (m_nActiveHeight - m_nStdHeight) ) / m_nStdHeight;
559 : }
560 :
561 0 : return nPos;
562 : }
563 :
564 0 : OUString ClientBox::getPin()
565 : {
566 0 : return OUString::valueOf( m_aPinBox.GetValue() );
567 : }
568 :
569 : //------------------------------------------------------------------------------
570 0 : void ClientBox::MouseButtonDown( const MouseEvent& rMEvt )
571 : {
572 0 : long nPos = PointToPos( rMEvt.GetPosPixel() );
573 :
574 0 : if ( rMEvt.IsLeft() )
575 : {
576 0 : if ( rMEvt.IsMod1() && m_bHasActive )
577 0 : selectEntry( m_vEntries.size() ); // Selecting an not existing entry will deselect the current one
578 : else
579 0 : selectEntry( nPos );
580 : }
581 0 : }
582 :
583 : //------------------------------------------------------------------------------
584 0 : long ClientBox::Notify( NotifyEvent& rNEvt )
585 : {
586 0 : if ( !m_bInDelete )
587 0 : DeleteRemoved();
588 :
589 0 : bool bHandled = false;
590 :
591 0 : if ( rNEvt.GetType() == EVENT_KEYINPUT )
592 : {
593 0 : const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
594 0 : KeyCode aKeyCode = pKEvt->GetKeyCode();
595 0 : sal_uInt16 nKeyCode = aKeyCode.GetCode();
596 :
597 0 : if ( nKeyCode == KEY_TAB )
598 0 : bHandled = HandleTabKey( aKeyCode.IsShift() );
599 0 : else if ( aKeyCode.GetGroup() == KEYGROUP_CURSOR )
600 0 : bHandled = HandleCursorKey( nKeyCode );
601 : }
602 :
603 0 : if ( rNEvt.GetType() == EVENT_COMMAND )
604 : {
605 0 : if ( m_bHasScrollBar &&
606 0 : ( rNEvt.GetCommandEvent()->GetCommand() == COMMAND_WHEEL ) )
607 : {
608 0 : const CommandWheelData* pData = rNEvt.GetCommandEvent()->GetWheelData();
609 0 : if ( pData->GetMode() == COMMAND_WHEEL_SCROLL )
610 : {
611 0 : long nThumbPos = m_pScrollBar->GetThumbPos();
612 0 : if ( pData->GetDelta() < 0 )
613 0 : m_pScrollBar->DoScroll( nThumbPos + m_nStdHeight );
614 : else
615 0 : m_pScrollBar->DoScroll( nThumbPos - m_nStdHeight );
616 0 : bHandled = true;
617 : }
618 : }
619 : }
620 :
621 0 : if ( !bHandled )
622 0 : return Control::Notify( rNEvt );
623 : else
624 0 : return true;
625 : }
626 :
627 :
628 : //------------------------------------------------------------------------------
629 0 : long ClientBox::addEntry( ClientInfo* pClientInfo )
630 : {
631 0 : long nPos = 0;
632 : // PackageState eState = m_pManager->getPackageState( xPackage );
633 : // bool bLocked = m_pManager->isReadOnly( xPackage );
634 :
635 0 : TClientBoxEntry pEntry( new ClientBoxEntry( pClientInfo ) );
636 :
637 0 : bool bNewEntryInserted = false;
638 :
639 0 : ::osl::ClearableMutexGuard guard(m_entriesMutex);
640 0 : if ( m_vEntries.empty() )
641 : {
642 0 : m_vEntries.push_back( pEntry );
643 0 : bNewEntryInserted = true;
644 : }
645 : else
646 : {
647 : // if ( !FindEntryPos( pEntry, 0, m_vEntries.size()-1, nPos ) )
648 : // {
649 0 : m_vEntries.insert( m_vEntries.begin()+nPos, pEntry );
650 0 : bNewEntryInserted = true;
651 : // }
652 : // else if ( !m_bInCheckMode )
653 : // {
654 : // OSL_FAIL( "ClientBox::addEntry(): Will not add duplicate entries" );
655 : // }
656 : }
657 :
658 : //Related: rhbz#702833 Only add a Listener if we're adding a new entry, to
659 : //keep in sync with removeEventListener logic
660 : if (bNewEntryInserted)
661 : {
662 :
663 : // pEntry->m_xPackage->addEventListener(uno::Reference< lang::XEventListener > ( m_xRemoveListener, uno::UNO_QUERY ) );
664 : }
665 :
666 :
667 : // pEntry->m_bHasOptions = m_pManager->supportsOptions( xPackage );
668 : // pEntry->m_bUser = xPackage->getRepositoryName().equals( USER_PACKAGE_MANAGER );
669 : // pEntry->m_bShared = xPackage->getRepositoryName().equals( SHARED_PACKAGE_MANAGER );
670 : // pEntry->m_bNew = m_bInCheckMode;
671 : // pEntry->m_bMissingLic = bLicenseMissing;
672 :
673 : // if ( bLicenseMissing )
674 : // pEntry->m_sErrorText = DialogHelper::getResourceString( RID_STR_ERROR_MISSING_LICENSE );
675 :
676 : //access to m_nActive must be guarded
677 0 : if ( !m_bInCheckMode && m_bHasActive && ( m_nActive >= nPos ) )
678 0 : m_nActive += 1;
679 :
680 0 : guard.clear();
681 :
682 0 : if ( IsReallyVisible() )
683 0 : Invalidate();
684 :
685 0 : m_bNeedsRecalc = true;
686 :
687 0 : return nPos;
688 : }
689 :
690 : // -----------------------------------------------------------------------
691 0 : void ClientBox::DoScroll( long nDelta )
692 : {
693 0 : m_nTopIndex += nDelta;
694 0 : Point aNewSBPt( m_pScrollBar->GetPosPixel() );
695 :
696 0 : Rectangle aScrRect( Point(), GetOutputSizePixel() );
697 0 : aScrRect.Right() -= m_pScrollBar->GetSizePixel().Width();
698 0 : Scroll( 0, -nDelta, aScrRect );
699 :
700 0 : m_pScrollBar->SetPosPixel( aNewSBPt );
701 0 : }
702 :
703 : // -----------------------------------------------------------------------
704 0 : IMPL_LINK( ClientBox, ScrollHdl, ScrollBar*, pScrBar )
705 : {
706 0 : DoScroll( pScrBar->GetDelta() );
707 :
708 0 : return 1;
709 : }
710 :
711 0 : } //namespace dp_gui
712 :
713 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|