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