update dev300-m58
[ooovba.git] / svtools / source / control / valueset.cxx
blobfa58b80c4fe84732b9b2d45409090aec3c1c5937
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: valueset.cxx,v $
10 * $Revision: 1.34 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <tools/list.hxx>
34 #include <tools/debug.hxx>
35 #include <vcl/decoview.hxx>
36 #include <vcl/svapp.hxx>
37 #ifndef _SCRBAR_HXX
38 #include <vcl/scrbar.hxx>
39 #endif
40 #ifndef _HELP_HXX
41 #include <vcl/help.hxx>
42 #endif
43 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
44 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
45 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
46 #include <com/sun/star/lang/XComponent.hpp>
47 #include <rtl/ustring.hxx>
49 #include "valueimp.hxx"
51 #define _SV_VALUESET_CXX
52 #include <svtools/valueset.hxx>
54 // ------------
55 // - ValueSet -
56 // ------------
58 void ValueSet::ImplInit()
60 // Size aWinSize = GetSizePixel();
61 mpImpl = new ValueSet_Impl;
62 mpNoneItem = NULL;
63 mpScrBar = NULL;
64 mnTextOffset = 0;
65 mnVisLines = 0;
66 mnLines = 0;
67 mnUserItemWidth = 0;
68 mnUserItemHeight = 0;
69 mnFirstLine = 0;
70 mnOldItemId = 0;
71 mnSelItemId = 0;
72 mnHighItemId = 0;
73 mnDropPos = VALUESET_ITEM_NOTFOUND;
74 mnCols = 0;
75 mnCurCol = 0;
76 mnUserCols = 0;
77 mnUserVisLines = 0;
78 mnSpacing = 0;
79 mnFrameStyle = 0;
80 mbFormat = TRUE;
81 mbHighlight = FALSE ;
82 mbSelection = FALSE;
83 mbNoSelection = TRUE;
84 mbDrawSelection = TRUE;
85 mbBlackSel = FALSE;
86 mbDoubleSel = FALSE;
87 mbScroll = FALSE;
88 mbDropPos = FALSE;
89 mbFullMode = TRUE;
91 // #106446#, #106601# force mirroring of virtual device
92 maVirDev.EnableRTL( GetParent()->IsRTLEnabled() );
94 ImplInitSettings( TRUE, TRUE, TRUE );
97 // -----------------------------------------------------------------------
99 ValueSet::ValueSet( Window* pParent, WinBits nWinStyle, bool bDisableTransientChildren ) :
100 Control( pParent, nWinStyle ),
101 maVirDev( *this ),
102 maColor( COL_TRANSPARENT )
104 ImplInit();
105 if( mpImpl )
106 mpImpl->mbIsTransientChildrenDisabled = bDisableTransientChildren;
109 // -----------------------------------------------------------------------
111 ValueSet::ValueSet( Window* pParent, const ResId& rResId, bool bDisableTransientChildren ) :
112 Control( pParent, rResId ),
113 maVirDev( *this ),
114 maColor( COL_TRANSPARENT )
116 ImplInit();
117 if( mpImpl )
118 mpImpl->mbIsTransientChildrenDisabled = bDisableTransientChildren;
121 // -----------------------------------------------------------------------
123 ValueSet::~ValueSet()
125 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>
126 xComponent (GetAccessible(FALSE), ::com::sun::star::uno::UNO_QUERY);
127 if (xComponent.is())
128 xComponent->dispose ();
130 if ( mpScrBar )
131 delete mpScrBar;
133 if ( mpNoneItem )
134 delete mpNoneItem;
136 ImplDeleteItems();
137 delete mpImpl;
140 // -----------------------------------------------------------------------
142 void ValueSet::ImplDeleteItems()
144 for( ValueSetItem* pItem = mpImpl->mpItemList->First(); pItem; pItem = mpImpl->mpItemList->Next() )
146 if( !pItem->maRect.IsEmpty() && ImplHasAccessibleListeners() )
148 ::com::sun::star::uno::Any aOldAny, aNewAny;
150 aOldAny <<= pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled );
151 ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
154 delete pItem;
157 mpImpl->mpItemList->Clear();
160 // -----------------------------------------------------------------------
162 void ValueSet::ImplInitSettings( BOOL bFont,
163 BOOL bForeground, BOOL bBackground )
165 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
167 if ( bFont )
169 Font aFont;
170 aFont = rStyleSettings.GetAppFont();
171 if ( IsControlFont() )
172 aFont.Merge( GetControlFont() );
173 SetZoomedPointFont( aFont );
176 if ( bForeground || bFont )
178 Color aColor;
179 if ( IsControlForeground() )
180 aColor = GetControlForeground();
181 else
182 aColor = rStyleSettings.GetButtonTextColor();
183 SetTextColor( aColor );
184 SetTextFillColor();
187 if ( bBackground )
189 Color aColor;
190 if ( IsControlBackground() )
191 aColor = GetControlBackground();
192 else if ( GetStyle() & WB_MENUSTYLEVALUESET )
193 aColor = rStyleSettings.GetMenuColor();
194 else if ( IsEnabled() && (GetStyle() & WB_FLATVALUESET) )
195 aColor = rStyleSettings.GetWindowColor();
196 else
197 aColor = rStyleSettings.GetFaceColor();
198 SetBackground( aColor );
202 // -----------------------------------------------------------------------
204 void ValueSet::ImplInitScrollBar()
206 if ( GetStyle() & WB_VSCROLL )
208 if ( !mpScrBar )
210 mpScrBar = new ScrollBar( this, WB_VSCROLL | WB_DRAG );
211 mpScrBar->SetScrollHdl( LINK( this, ValueSet, ImplScrollHdl ) );
213 else
215 // Wegen Einstellungsaenderungen passen wir hier die Breite an
216 long nScrBarWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
217 mpScrBar->SetPosSizePixel( 0, 0, nScrBarWidth, 0, WINDOW_POSSIZE_WIDTH );
222 // -----------------------------------------------------------------------
224 void ValueSet::ImplFormatItem( ValueSetItem* pItem )
226 if ( pItem->meType == VALUESETITEM_SPACE )
227 return;
229 Rectangle aRect = pItem->maRect;
230 WinBits nStyle = GetStyle();
231 if ( nStyle & WB_ITEMBORDER )
233 aRect.Left()++;
234 aRect.Top()++;
235 aRect.Right()--;
236 aRect.Bottom()--;
237 if ( nStyle & WB_FLATVALUESET )
239 if ( nStyle & WB_DOUBLEBORDER )
241 aRect.Left() += 2;
242 aRect.Top() += 2;
243 aRect.Right() -= 2;
244 aRect.Bottom() -= 2;
246 else
248 aRect.Left()++;
249 aRect.Top()++;
250 aRect.Right()--;
251 aRect.Bottom()--;
254 else
256 DecorationView aView( &maVirDev );
257 aRect = aView.DrawFrame( aRect, mnFrameStyle );
261 if ( pItem == mpNoneItem )
262 pItem->maText = GetText();
264 if ( (aRect.GetHeight() > 0) && (aRect.GetWidth() > 0) )
266 if ( pItem == mpNoneItem )
268 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
269 maVirDev.SetFont( GetFont() );
270 maVirDev.SetTextColor( ( nStyle & WB_MENUSTYLEVALUESET ) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor() );
271 maVirDev.SetTextFillColor();
272 maVirDev.SetFillColor( ( nStyle & WB_MENUSTYLEVALUESET ) ? rStyleSettings.GetMenuColor() : rStyleSettings.GetWindowColor() );
273 maVirDev.DrawRect( aRect );
274 Point aTxtPos( aRect.Left()+2, aRect.Top() );
275 long nTxtWidth = GetTextWidth( pItem->maText );
276 if ( nStyle & WB_RADIOSEL )
278 aTxtPos.X() += 4;
279 aTxtPos.Y() += 4;
281 if ( (aTxtPos.X()+nTxtWidth) > aRect.Right() )
283 maVirDev.SetClipRegion( Region( aRect ) );
284 maVirDev.DrawText( aTxtPos, pItem->maText );
285 maVirDev.SetClipRegion();
287 else
288 maVirDev.DrawText( aTxtPos, pItem->maText );
290 else if ( pItem->meType == VALUESETITEM_COLOR )
292 maVirDev.SetFillColor( pItem->maColor );
293 maVirDev.DrawRect( aRect );
295 else
297 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
298 if ( IsColor() )
299 maVirDev.SetFillColor( maColor );
300 else if ( nStyle & WB_MENUSTYLEVALUESET )
301 maVirDev.SetFillColor( rStyleSettings.GetMenuColor() );
302 else if ( IsEnabled() )
303 maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
304 else
305 maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
306 maVirDev.DrawRect( aRect );
308 if ( pItem->meType == VALUESETITEM_USERDRAW )
310 UserDrawEvent aUDEvt( &maVirDev, aRect, pItem->mnId );
311 UserDraw( aUDEvt );
313 else
315 Size aImageSize = pItem->maImage.GetSizePixel();
316 Size aRectSize = aRect.GetSize();
317 Point aPos( aRect.Left(), aRect.Top() );
318 aPos.X() += (aRectSize.Width()-aImageSize.Width())/2;
319 aPos.Y() += (aRectSize.Height()-aImageSize.Height())/2;
321 USHORT nImageStyle = 0;
322 if( !IsEnabled() )
323 nImageStyle |= IMAGE_DRAW_DISABLE;
325 if ( (aImageSize.Width() > aRectSize.Width()) ||
326 (aImageSize.Height() > aRectSize.Height()) )
328 maVirDev.SetClipRegion( Region( aRect ) );
329 maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle);
330 maVirDev.SetClipRegion();
332 else
333 maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle );
339 // -----------------------------------------------------------------------
341 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ValueSet::CreateAccessible()
343 return new ValueSetAcc( this, mpImpl->mbIsTransientChildrenDisabled );
346 // -----------------------------------------------------------------------
348 void ValueSet::Format()
350 Size aWinSize = GetOutputSizePixel();
351 ULONG nItemCount = mpImpl->mpItemList->Count();
352 WinBits nStyle = GetStyle();
353 long nTxtHeight = GetTextHeight();
354 long nOff;
355 long nSpace;
356 long nNoneHeight;
357 long nNoneSpace;
358 ScrollBar* pDelScrBar = NULL;
360 // Scrolling beruecksichtigen
361 if ( nStyle & WB_VSCROLL )
362 ImplInitScrollBar();
363 else
365 if ( mpScrBar )
367 // ScrollBar erst spaeter zerstoeren, damit keine rekursiven
368 // Aufrufe entstehen koennen
369 pDelScrBar = mpScrBar;
370 mpScrBar = NULL;
374 // Item-Offset berechnen
375 if ( nStyle & WB_ITEMBORDER )
377 if ( nStyle & WB_DOUBLEBORDER )
378 nOff = ITEM_OFFSET_DOUBLE;
379 else
380 nOff = ITEM_OFFSET;
382 else
383 nOff = 0;
384 nSpace = mnSpacing;
386 // Groesse beruecksichtigen, wenn NameField vorhanden
387 if ( nStyle & WB_NAMEFIELD )
389 mnTextOffset = aWinSize.Height()-nTxtHeight-NAME_OFFSET;
390 aWinSize.Height() -= nTxtHeight+NAME_OFFSET;
392 if ( !(nStyle & WB_FLATVALUESET) )
394 mnTextOffset -= NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
395 aWinSize.Height() -= NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
398 else
399 mnTextOffset = 0;
401 // Offset und Groesse beruecksichtigen, wenn NoneField vorhanden
402 if ( nStyle & WB_NONEFIELD )
404 nNoneHeight = nTxtHeight+nOff;
405 nNoneSpace = nSpace;
406 if ( nStyle & WB_RADIOSEL )
407 nNoneHeight += 8;
409 else
411 nNoneHeight = 0;
412 nNoneSpace = 0;
414 if ( mpNoneItem )
416 delete mpNoneItem;
417 mpNoneItem = NULL;
421 // Breite vom ScrollBar berechnen
422 long nScrBarWidth = 0;
423 if ( mpScrBar )
424 nScrBarWidth = mpScrBar->GetSizePixel().Width()+SCRBAR_OFFSET;
426 // Spaltenanzahl berechnen
427 if ( !mnUserCols )
429 if ( mnUserItemWidth )
431 mnCols = (USHORT)((aWinSize.Width()-nScrBarWidth+nSpace) / (mnUserItemWidth+nSpace));
432 if ( !mnCols )
433 mnCols = 1;
435 else
436 mnCols = 1;
438 else
439 mnCols = mnUserCols;
441 // Zeilenanzahl berechnen
442 mbScroll = FALSE;
443 mnLines = (long)mpImpl->mpItemList->Count() / mnCols;
444 if ( mpImpl->mpItemList->Count() % mnCols )
445 mnLines++;
446 else if ( !mnLines )
447 mnLines = 1;
449 long nCalcHeight = aWinSize.Height()-nNoneHeight;
450 if ( mnUserVisLines )
451 mnVisLines = mnUserVisLines;
452 else if ( mnUserItemHeight )
454 mnVisLines = (nCalcHeight-nNoneSpace+nSpace) / (mnUserItemHeight+nSpace);
455 if ( !mnVisLines )
456 mnVisLines = 1;
458 else
459 mnVisLines = mnLines;
460 if ( mnLines > mnVisLines )
461 mbScroll = TRUE;
462 if ( mnLines <= mnVisLines )
463 mnFirstLine = 0;
464 else
466 if ( mnFirstLine > (USHORT)(mnLines-mnVisLines) )
467 mnFirstLine = (USHORT)(mnLines-mnVisLines);
470 // Itemgroessen berechnen
471 long nColSpace = (mnCols-1)*nSpace;
472 long nLineSpace = ((mnVisLines-1)*nSpace)+nNoneSpace;
473 long nItemWidth;
474 long nItemHeight;
475 if ( mnUserItemWidth && !mnUserCols )
477 nItemWidth = mnUserItemWidth;
478 if ( nItemWidth > aWinSize.Width()-nScrBarWidth-nColSpace )
479 nItemWidth = aWinSize.Width()-nScrBarWidth-nColSpace;
481 else
482 nItemWidth = (aWinSize.Width()-nScrBarWidth-nColSpace) / mnCols;
483 if ( mnUserItemHeight && !mnUserVisLines )
485 nItemHeight = mnUserItemHeight;
486 if ( nItemHeight > nCalcHeight-nNoneSpace )
487 nItemHeight = nCalcHeight-nNoneSpace;
489 else
491 nCalcHeight -= nLineSpace;
492 nItemHeight = nCalcHeight / mnVisLines;
495 // Init VirDev
496 maVirDev.SetSettings( GetSettings() );
497 maVirDev.SetBackground( GetBackground() );
498 maVirDev.SetOutputSizePixel( aWinSize, TRUE );
500 // Bei zu kleinen Items machen wir nichts
501 long nMinHeight = 2;
502 if ( nStyle & WB_ITEMBORDER )
503 nMinHeight = 4;
504 if ( (nItemWidth <= 0) || (nItemHeight <= nMinHeight) || !nItemCount )
506 if ( nStyle & WB_NONEFIELD )
508 if ( mpNoneItem )
510 mpNoneItem->maRect.SetEmpty();
511 mpNoneItem->maText = GetText();
515 for ( ULONG i = 0; i < nItemCount; i++ )
517 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( i );
518 pItem->maRect.SetEmpty();
521 if ( mpScrBar )
522 mpScrBar->Hide();
524 else
526 // Frame-Style ermitteln
527 if ( nStyle & WB_DOUBLEBORDER )
528 mnFrameStyle = FRAME_DRAW_DOUBLEIN;
529 else
530 mnFrameStyle = FRAME_DRAW_IN;
532 // Selektionsfarben und -breiten ermitteln
533 // Gegebenenfalls die Farben anpassen, damit man die Selektion besser
534 // erkennen kann
535 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
536 Color aHighColor( rStyleSettings.GetHighlightColor() );
537 if ( ((aHighColor.GetRed() > 0x80) || (aHighColor.GetGreen() > 0x80) ||
538 (aHighColor.GetBlue() > 0x80)) ||
539 ((aHighColor.GetRed() == 0x80) && (aHighColor.GetGreen() == 0x80) &&
540 (aHighColor.GetBlue() == 0x80)) )
541 mbBlackSel = TRUE;
542 else
543 mbBlackSel = FALSE;
545 // Wenn die Items groesser sind, dann die Selektion doppelt so breit
546 // zeichnen
547 if ( (nStyle & WB_DOUBLEBORDER) &&
548 ((nItemWidth >= 25) && (nItemHeight >= 20)) )
549 mbDoubleSel = TRUE;
550 else
551 mbDoubleSel = FALSE;
553 // Calculate offsets
554 long nStartX;
555 long nStartY;
556 if ( mbFullMode )
558 long nAllItemWidth = (nItemWidth*mnCols)+nColSpace;
559 long nAllItemHeight = (nItemHeight*mnVisLines)+nNoneHeight+nLineSpace;
560 nStartX = (aWinSize.Width()-nScrBarWidth-nAllItemWidth)/2;
561 nStartY = (aWinSize.Height()-nAllItemHeight)/2;
563 else
565 nStartX = 0;
566 nStartY = 0;
569 // Items berechnen und zeichnen
570 maVirDev.SetLineColor();
571 long x = nStartX;
572 long y = nStartY;
574 // NoSelection-Field erzeugen und anzeigen
575 if ( nStyle & WB_NONEFIELD )
577 if ( !mpNoneItem )
578 mpNoneItem = new ValueSetItem( *this );
580 mpNoneItem->mnId = 0;
581 mpNoneItem->meType = VALUESETITEM_NONE;
582 mpNoneItem->maRect.Left() = x;
583 mpNoneItem->maRect.Top() = y;
584 mpNoneItem->maRect.Right() = mpNoneItem->maRect.Left()+aWinSize.Width()-x-1;
585 mpNoneItem->maRect.Bottom() = y+nNoneHeight-1;
587 ImplFormatItem( mpNoneItem );
589 y += nNoneHeight+nNoneSpace;
592 // draw items
593 ULONG nFirstItem = mnFirstLine * mnCols;
594 ULONG nLastItem = nFirstItem + (mnVisLines * mnCols);
596 if ( !mbFullMode )
598 // If want also draw parts of items in the last line,
599 // then we add one more line if parts of these line are
600 // visible
601 if ( y+(mnVisLines*(nItemHeight+nSpace)) < aWinSize.Height() )
602 nLastItem += mnCols;
604 for ( ULONG i = 0; i < nItemCount; i++ )
606 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( i );
608 if ( (i >= nFirstItem) && (i < nLastItem) )
610 const BOOL bWasEmpty = pItem->maRect.IsEmpty();
612 pItem->maRect.Left() = x;
613 pItem->maRect.Top() = y;
614 pItem->maRect.Right() = pItem->maRect.Left()+nItemWidth-1;
615 pItem->maRect.Bottom() = pItem->maRect.Top()+nItemHeight-1;
617 if( bWasEmpty && ImplHasAccessibleListeners() )
619 ::com::sun::star::uno::Any aOldAny, aNewAny;
621 aNewAny <<= pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled );
622 ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
625 ImplFormatItem( pItem );
627 if ( !((i+1) % mnCols) )
629 x = nStartX;
630 y += nItemHeight+nSpace;
632 else
633 x += nItemWidth+nSpace;
635 else
637 if( !pItem->maRect.IsEmpty() && ImplHasAccessibleListeners() )
639 ::com::sun::star::uno::Any aOldAny, aNewAny;
641 aOldAny <<= pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled );
642 ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
645 pItem->maRect.SetEmpty();
649 // ScrollBar anordnen, Werte setzen und anzeigen
650 if ( mpScrBar )
652 Point aPos( aWinSize.Width()-nScrBarWidth+SCRBAR_OFFSET, 0 );
653 Size aSize( nScrBarWidth-SCRBAR_OFFSET, aWinSize.Height() );
654 // If a none field is visible, then we center the scrollbar
655 if ( nStyle & WB_NONEFIELD )
657 aPos.Y() = nStartY+nNoneHeight+1;
658 aSize.Height() = ((nItemHeight+nSpace)*mnVisLines)-2-nSpace;
660 mpScrBar->SetPosSizePixel( aPos, aSize );
661 mpScrBar->SetRangeMax( mnLines );
662 mpScrBar->SetVisibleSize( mnVisLines );
663 mpScrBar->SetThumbPos( (long)mnFirstLine );
664 long nPageSize = mnVisLines;
665 if ( nPageSize < 1 )
666 nPageSize = 1;
667 mpScrBar->SetPageSize( nPageSize );
668 mpScrBar->Show();
672 // Jetzt haben wir formatiert und warten auf das naechste
673 mbFormat = FALSE;
675 // ScrollBar loeschen
676 if ( pDelScrBar )
677 delete pDelScrBar;
680 // -----------------------------------------------------------------------
682 void ValueSet::ImplDrawItemText( const XubString& rText )
684 if ( !(GetStyle() & WB_NAMEFIELD) )
685 return;
687 Size aWinSize = GetOutputSizePixel();
688 long nTxtWidth = GetTextWidth( rText );
689 long nTxtOffset = mnTextOffset;
691 // Rechteck loeschen und Text ausgeben
692 if ( GetStyle() & WB_FLATVALUESET )
694 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
695 SetLineColor();
696 SetFillColor( rStyleSettings.GetFaceColor() );
697 DrawRect( Rectangle( Point( 0, nTxtOffset ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
698 SetTextColor( rStyleSettings.GetButtonTextColor() );
700 else
702 nTxtOffset += NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
703 Erase( Rectangle( Point( 0, nTxtOffset ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
705 DrawText( Point( (aWinSize.Width()-nTxtWidth) / 2, nTxtOffset+(NAME_OFFSET/2) ), rText );
708 // -----------------------------------------------------------------------
710 void ValueSet::ImplDrawSelect()
712 if ( !IsReallyVisible() )
713 return;
715 BOOL bFocus = HasFocus();
716 BOOL bDrawSel;
718 if ( (mbNoSelection && !mbHighlight) || (!mbDrawSelection && mbHighlight) )
719 bDrawSel = FALSE;
720 else
721 bDrawSel = TRUE;
723 if ( !bFocus &&
724 ((mbNoSelection && !mbHighlight) || (!mbDrawSelection && mbHighlight)) )
726 XubString aEmptyStr;
727 ImplDrawItemText( aEmptyStr );
728 return;
731 USHORT nItemId = mnSelItemId;
733 for( int stage = 0; stage < 2; stage++ )
735 if( stage == 1 )
737 if ( mbHighlight )
738 nItemId = mnHighItemId;
739 else
740 break;
743 ValueSetItem* pItem;
744 if ( nItemId )
745 pItem = mpImpl->mpItemList->GetObject( GetItemPos( nItemId ) );
746 else
748 if ( mpNoneItem )
749 pItem = mpNoneItem;
750 else
752 pItem = ImplGetFirstItem();
753 if ( !bFocus || !pItem )
754 continue;
758 if ( pItem->maRect.IsEmpty() )
759 continue;
761 // Selection malen
762 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
763 Rectangle aRect = pItem->maRect;
764 Control::SetFillColor();
766 Color aDoubleColor( rStyleSettings.GetHighlightColor() );
767 Color aSingleColor( rStyleSettings.GetHighlightTextColor() );
768 if( ! mbDoubleSel )
771 * #99777# contrast enhancement for thin mode
773 const Wallpaper& rWall = GetDisplayBackground();
774 if( ! rWall.IsBitmap() && ! rWall.IsGradient() )
776 const Color& rBack = rWall.GetColor();
777 if( rBack.IsDark() && ! aDoubleColor.IsBright() )
779 aDoubleColor = Color( COL_WHITE );
780 aSingleColor = Color( COL_BLACK );
782 else if( rBack.IsBright() && ! aDoubleColor.IsDark() )
784 aDoubleColor = Color( COL_BLACK );
785 aSingleColor = Color( COL_WHITE );
790 // Selectionsausgabe festlegen
791 WinBits nStyle = GetStyle();
792 if ( nStyle & WB_MENUSTYLEVALUESET )
794 if ( bFocus )
795 ShowFocus( aRect );
797 if ( bDrawSel )
799 if ( mbBlackSel )
800 SetLineColor( Color( COL_BLACK ) );
801 else
802 SetLineColor( aDoubleColor );
803 DrawRect( aRect );
806 else if ( nStyle & WB_RADIOSEL )
808 aRect.Left() += 3;
809 aRect.Top() += 3;
810 aRect.Right() -= 3;
811 aRect.Bottom() -= 3;
812 if ( nStyle & WB_DOUBLEBORDER )
814 aRect.Left()++;
815 aRect.Top()++;
816 aRect.Right()--;
817 aRect.Bottom()--;
820 if ( bFocus )
821 ShowFocus( aRect );
823 aRect.Left()++;
824 aRect.Top()++;
825 aRect.Right()--;
826 aRect.Bottom()--;
828 if ( bDrawSel )
830 SetLineColor( aDoubleColor );
831 aRect.Left()++;
832 aRect.Top()++;
833 aRect.Right()--;
834 aRect.Bottom()--;
835 DrawRect( aRect );
836 aRect.Left()++;
837 aRect.Top()++;
838 aRect.Right()--;
839 aRect.Bottom()--;
840 DrawRect( aRect );
843 else
845 if ( bDrawSel )
847 if ( mbBlackSel )
848 SetLineColor( Color( COL_BLACK ) );
849 else
850 SetLineColor( aDoubleColor );
851 DrawRect( aRect );
853 if ( mbDoubleSel )
855 aRect.Left()++;
856 aRect.Top()++;
857 aRect.Right()--;
858 aRect.Bottom()--;
859 if ( bDrawSel )
860 DrawRect( aRect );
862 aRect.Left()++;
863 aRect.Top()++;
864 aRect.Right()--;
865 aRect.Bottom()--;
866 Rectangle aRect2 = aRect;
867 aRect.Left()++;
868 aRect.Top()++;
869 aRect.Right()--;
870 aRect.Bottom()--;
871 if ( bDrawSel )
872 DrawRect( aRect );
873 if ( mbDoubleSel )
875 aRect.Left()++;
876 aRect.Top()++;
877 aRect.Right()--;
878 aRect.Bottom()--;
879 if ( bDrawSel )
880 DrawRect( aRect );
883 if ( bDrawSel )
885 if ( mbBlackSel )
886 SetLineColor( Color( COL_WHITE ) );
887 else
888 SetLineColor( aSingleColor );
890 else
891 SetLineColor( Color( COL_LIGHTGRAY ) );
892 DrawRect( aRect2 );
894 if ( bFocus )
895 ShowFocus( aRect2 );
898 ImplDrawItemText( pItem->maText );
902 // -----------------------------------------------------------------------
904 void ValueSet::ImplHideSelect( USHORT nItemId )
906 Rectangle aRect;
908 USHORT nItemPos = GetItemPos( nItemId );
909 if ( nItemPos != sal::static_int_cast<USHORT>(LIST_ENTRY_NOTFOUND) )
910 aRect = mpImpl->mpItemList->GetObject( nItemPos )->maRect;
911 else
913 if ( mpNoneItem )
914 aRect = mpNoneItem->maRect;
917 if ( !aRect.IsEmpty() )
919 HideFocus();
920 Point aPos = aRect.TopLeft();
921 Size aSize = aRect.GetSize();
922 DrawOutDev( aPos, aSize, aPos, aSize, maVirDev );
926 // -----------------------------------------------------------------------
928 void ValueSet::ImplHighlightItem( USHORT nItemId, BOOL bIsSelection )
930 if ( mnHighItemId != nItemId )
932 // Alten merken, um vorherige Selektion zu entfernen
933 USHORT nOldItem = mnHighItemId;
934 mnHighItemId = nItemId;
936 // Wenn keiner selektiert ist, dann Selektion nicht malen
937 if ( !bIsSelection && mbNoSelection )
938 mbDrawSelection = FALSE;
940 // Neu ausgeben und alte Selection wegnehmen
941 ImplHideSelect( nOldItem );
942 ImplDrawSelect();
943 mbDrawSelection = TRUE;
947 // -----------------------------------------------------------------------
949 void ValueSet::ImplDrawDropPos( BOOL bShow )
951 if ( (mnDropPos != VALUESET_ITEM_NOTFOUND) && mpImpl->mpItemList->Count() )
953 USHORT nItemPos = mnDropPos;
954 USHORT nItemId1;
955 USHORT nItemId2 = 0;
956 BOOL bRight;
957 if ( nItemPos >= mpImpl->mpItemList->Count() )
959 nItemPos = (USHORT)(mpImpl->mpItemList->Count()-1);
960 bRight = TRUE;
962 else
963 bRight = FALSE;
965 nItemId1 = GetItemId( nItemPos );
966 if ( (nItemId1 != mnSelItemId) && (nItemId1 != mnHighItemId) )
967 nItemId1 = 0;
968 Rectangle aRect2 = mpImpl->mpItemList->GetObject( nItemPos )->maRect;
969 Rectangle aRect1;
970 if ( bRight )
972 aRect1 = aRect2;
973 aRect2.SetEmpty();
975 else if ( nItemPos > 0 )
977 aRect1 = mpImpl->mpItemList->GetObject( nItemPos-1 )->maRect;
978 nItemId2 = GetItemId( nItemPos-1 );
979 if ( (nItemId2 != mnSelItemId) && (nItemId2 != mnHighItemId) )
980 nItemId2 = 0;
983 // Items ueberhaupt sichtbar (nur Erstes/Letztes)
984 if ( !aRect1.IsEmpty() || !aRect2.IsEmpty() )
986 if ( nItemId1 )
987 ImplHideSelect( nItemId1 );
988 if ( nItemId2 )
989 ImplHideSelect( nItemId2 );
991 if ( bShow )
993 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
994 long nX;
995 long nY;
996 SetLineColor( rStyleSettings.GetButtonTextColor() );
997 if ( !aRect1.IsEmpty() )
999 Point aPos = aRect1.RightCenter();
1000 nX = aPos.X()-2;
1001 nY = aPos.Y();
1002 for ( USHORT i = 0; i < 4; i++ )
1003 DrawLine( Point( nX-i, nY-i ), Point( nX-i, nY+i ) );
1005 if ( !aRect2.IsEmpty() )
1007 Point aPos = aRect2.LeftCenter();
1008 nX = aPos.X()+2;
1009 nY = aPos.Y();
1010 for ( USHORT i = 0; i < 4; i++ )
1011 DrawLine( Point( nX+i, nY-i ), Point( nX+i, nY+i ) );
1014 else
1016 if ( !aRect1.IsEmpty() )
1018 Point aPos = aRect1.TopLeft();
1019 Size aSize = aRect1.GetSize();
1020 DrawOutDev( aPos, aSize, aPos, aSize, maVirDev );
1022 if ( !aRect2.IsEmpty() )
1024 Point aPos = aRect2.TopLeft();
1025 Size aSize = aRect2.GetSize();
1026 DrawOutDev( aPos, aSize, aPos, aSize, maVirDev );
1030 if ( nItemId1 || nItemId2 )
1031 ImplDrawSelect();
1036 // -----------------------------------------------------------------------
1038 void ValueSet::ImplDraw()
1040 if ( mbFormat )
1041 Format();
1043 HideFocus();
1045 Point aDefPos;
1046 Size aSize = maVirDev.GetOutputSizePixel();
1048 if ( mpScrBar && mpScrBar->IsVisible() )
1050 Point aScrPos = mpScrBar->GetPosPixel();
1051 Size aScrSize = mpScrBar->GetSizePixel();
1052 Point aTempPos( 0, aScrPos.Y() );
1053 Size aTempSize( aSize.Width(), aScrPos.Y() );
1055 DrawOutDev( aDefPos, aTempSize, aDefPos, aTempSize, maVirDev );
1056 aTempSize.Width() = aScrPos.X()-1;
1057 aTempSize.Height() = aScrSize.Height();
1058 DrawOutDev( aTempPos, aTempSize, aTempPos, aTempSize, maVirDev );
1059 aTempPos.Y() = aScrPos.Y()+aScrSize.Height();
1060 aTempSize.Width() = aSize.Width();
1061 aTempSize.Height() = aSize.Height()-aTempPos.Y();
1062 DrawOutDev( aTempPos, aTempSize, aTempPos, aTempSize, maVirDev );
1064 else
1065 DrawOutDev( aDefPos, aSize, aDefPos, aSize, maVirDev );
1067 // Trennlinie zum Namefield zeichnen
1068 if ( GetStyle() & WB_NAMEFIELD )
1070 if ( !(GetStyle() & WB_FLATVALUESET) )
1072 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1073 Size aWinSize = GetOutputSizePixel();
1074 Point aPos1( NAME_LINE_OFF_X, mnTextOffset+NAME_LINE_OFF_Y );
1075 Point aPos2( aWinSize.Width()-(NAME_LINE_OFF_X*2), mnTextOffset+NAME_LINE_OFF_Y );
1076 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1078 SetLineColor( rStyleSettings.GetShadowColor() );
1079 DrawLine( aPos1, aPos2 );
1080 aPos1.Y()++;
1081 aPos2.Y()++;
1082 SetLineColor( rStyleSettings.GetLightColor() );
1084 else
1085 SetLineColor( rStyleSettings.GetWindowTextColor() );
1086 DrawLine( aPos1, aPos2 );
1090 ImplDrawSelect();
1093 // -----------------------------------------------------------------------
1095 BOOL ValueSet::ImplScroll( const Point& rPos )
1097 Size aOutSize = GetOutputSizePixel();
1098 long nScrBarWidth;
1100 if ( mpScrBar )
1101 nScrBarWidth = mpScrBar->GetSizePixel().Width();
1102 else
1103 nScrBarWidth = 0;
1105 if ( !mbScroll || (rPos.X() < 0) || (rPos.X() > aOutSize.Width()-nScrBarWidth) )
1106 return FALSE;
1108 long nScrollOffset;
1109 USHORT nOldLine = mnFirstLine;
1110 const Rectangle& rTopRect = mpImpl->mpItemList->GetObject( mnFirstLine*mnCols )->maRect;
1111 if ( rTopRect.GetHeight() <= 16 )
1112 nScrollOffset = VALUESET_SCROLL_OFFSET/2;
1113 else
1114 nScrollOffset = VALUESET_SCROLL_OFFSET;
1115 if ( (mnFirstLine > 0) && (rPos.Y() >= 0) )
1117 long nTopPos = rTopRect.Top();
1118 if ( (rPos.Y() >= nTopPos) && (rPos.Y() <= nTopPos+nScrollOffset) )
1119 mnFirstLine--;
1121 if ( (mnFirstLine == nOldLine) &&
1122 (mnFirstLine < (USHORT)(mnLines-mnVisLines)) && (rPos.Y() < aOutSize.Height()) )
1124 long nBottomPos = mpImpl->mpItemList->GetObject( (mnFirstLine+mnVisLines-1)*mnCols )->maRect.Bottom();
1125 if ( (rPos.Y() >= nBottomPos-nScrollOffset) && (rPos.Y() <= nBottomPos) )
1126 mnFirstLine++;
1129 if ( mnFirstLine != nOldLine )
1131 mbFormat = TRUE;
1132 ImplDraw();
1133 return TRUE;
1135 else
1136 return FALSE;
1139 // -----------------------------------------------------------------------
1141 USHORT ValueSet::ImplGetItem( const Point& rPos, BOOL bMove ) const
1143 if ( mpNoneItem )
1145 if ( mpNoneItem->maRect.IsInside( rPos ) )
1146 return VALUESET_ITEM_NONEITEM;
1149 Point aDefPos;
1150 Rectangle aWinRect( aDefPos, maVirDev.GetOutputSizePixel() );
1152 ULONG nItemCount = mpImpl->mpItemList->Count();
1153 for ( ULONG i = 0; i < nItemCount; i++ )
1155 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( i );
1156 if ( pItem->maRect.IsInside( rPos ) )
1158 if ( aWinRect.IsInside( rPos ) )
1159 return (USHORT)i;
1160 else
1161 return VALUESET_ITEM_NOTFOUND;
1165 // Wenn Spacing gesetzt ist, wird der vorher selektierte
1166 // Eintrag zurueckgegeben, wenn die Maus noch nicht das Fenster
1167 // verlassen hat
1168 if ( bMove && mnSpacing && mnHighItemId )
1170 if ( aWinRect.IsInside( rPos ) )
1171 return GetItemPos( mnHighItemId );
1174 return VALUESET_ITEM_NOTFOUND;
1177 // -----------------------------------------------------------------------
1179 ValueSetItem* ValueSet::ImplGetItem( USHORT nPos )
1181 if ( nPos == VALUESET_ITEM_NONEITEM )
1182 return mpNoneItem;
1183 else
1184 return mpImpl->mpItemList->GetObject( nPos );
1187 // -----------------------------------------------------------------------
1189 ValueSetItem* ValueSet::ImplGetFirstItem()
1191 USHORT nItemCount = (USHORT)mpImpl->mpItemList->Count();
1192 USHORT i = 0;
1194 while ( i < nItemCount )
1196 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( i );
1197 if ( pItem->meType != VALUESETITEM_SPACE )
1198 return pItem;
1199 i++;
1202 return NULL;
1205 // -----------------------------------------------------------------------
1207 USHORT ValueSet::ImplGetVisibleItemCount() const
1209 USHORT nRet = 0;
1211 for( sal_Int32 n = 0, nItemCount = mpImpl->mpItemList->Count(); n < nItemCount; n++ )
1213 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( n );
1215 if( pItem->meType != VALUESETITEM_SPACE && !pItem->maRect.IsEmpty() )
1216 nRet++;
1219 return nRet;
1222 // -----------------------------------------------------------------------
1224 ValueSetItem* ValueSet::ImplGetVisibleItem( USHORT nVisiblePos )
1226 ValueSetItem* pRet = NULL;
1227 USHORT nFoundPos = 0;
1229 for( sal_Int32 n = 0, nItemCount = mpImpl->mpItemList->Count(); ( n < nItemCount ) && !pRet; n++ )
1231 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( n );
1233 if( ( pItem->meType != VALUESETITEM_SPACE ) && !pItem->maRect.IsEmpty() && ( nVisiblePos == nFoundPos++ ) )
1234 pRet = pItem;
1237 return pRet;
1240 // -----------------------------------------------------------------------
1242 void ValueSet::ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue )
1244 ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( FALSE ) );
1246 if( pAcc )
1247 pAcc->FireAccessibleEvent( nEventId, rOldValue, rNewValue );
1250 // -----------------------------------------------------------------------
1252 BOOL ValueSet::ImplHasAccessibleListeners()
1254 ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( FALSE ) );
1255 return( pAcc && pAcc->HasAccessibleListeners() );
1258 // -----------------------------------------------------------------------
1260 IMPL_LINK( ValueSet,ImplScrollHdl, ScrollBar*, pScrollBar )
1262 USHORT nNewFirstLine = (USHORT)pScrollBar->GetThumbPos();
1263 if ( nNewFirstLine != mnFirstLine )
1265 mnFirstLine = nNewFirstLine;
1266 mbFormat = TRUE;
1267 ImplDraw();
1269 return 0;
1272 // -----------------------------------------------------------------------
1274 IMPL_LINK( ValueSet,ImplTimerHdl, Timer*, EMPTYARG )
1276 ImplTracking( GetPointerPosPixel(), TRUE );
1277 return 0;
1280 // -----------------------------------------------------------------------
1282 void ValueSet::ImplTracking( const Point& rPos, BOOL bRepeat )
1284 if ( bRepeat || mbSelection )
1286 if ( ImplScroll( rPos ) )
1288 if ( mbSelection )
1290 maTimer.SetTimeoutHdl( LINK( this, ValueSet, ImplTimerHdl ) );
1291 maTimer.SetTimeout( GetSettings().GetMouseSettings().GetScrollRepeat() );
1292 maTimer.Start();
1297 ValueSetItem* pItem = ImplGetItem( ImplGetItem( rPos ) );
1298 if ( pItem && (pItem->meType != VALUESETITEM_SPACE) )
1300 if( GetStyle() & WB_MENUSTYLEVALUESET )
1301 mbHighlight = TRUE;
1303 ImplHighlightItem( pItem->mnId );
1305 else
1307 if( GetStyle() & WB_MENUSTYLEVALUESET )
1308 mbHighlight = TRUE;
1310 ImplHighlightItem( mnSelItemId, FALSE );
1314 // -----------------------------------------------------------------------
1316 void ValueSet::ImplEndTracking( const Point& rPos, BOOL bCancel )
1318 ValueSetItem* pItem;
1320 // Bei Abbruch, den alten Status wieder herstellen
1321 if ( bCancel )
1322 pItem = NULL;
1323 else
1324 pItem = ImplGetItem( ImplGetItem( rPos ) );
1326 if ( pItem && (pItem->meType != VALUESETITEM_SPACE) )
1328 SelectItem( pItem->mnId );
1329 if ( !mbSelection && !(GetStyle() & WB_NOPOINTERFOCUS) )
1330 GrabFocus();
1331 mbHighlight = FALSE;
1332 mbSelection = FALSE;
1333 Select();
1335 else
1337 ImplHighlightItem( mnSelItemId, FALSE );
1338 mbHighlight = FALSE;
1339 mbSelection = FALSE;
1343 // -----------------------------------------------------------------------
1345 void ValueSet::MouseButtonDown( const MouseEvent& rMEvt )
1347 if ( rMEvt.IsLeft() )
1349 ValueSetItem* pItem = ImplGetItem( ImplGetItem( rMEvt.GetPosPixel() ) );
1350 if ( mbSelection )
1352 mbHighlight = TRUE;
1353 if ( pItem && (pItem->meType != VALUESETITEM_SPACE) )
1355 mnOldItemId = mnSelItemId;
1356 mnHighItemId = mnSelItemId;
1357 ImplHighlightItem( pItem->mnId );
1360 return;
1362 else
1364 if ( pItem && (pItem->meType != VALUESETITEM_SPACE) && !rMEvt.IsMod2() )
1366 if ( (pItem->mnBits & VIB_NODOUBLECLICK) || (rMEvt.GetClicks() == 1) )
1368 mnOldItemId = mnSelItemId;
1369 mbHighlight = TRUE;
1370 mnHighItemId = mnSelItemId;
1371 ImplHighlightItem( pItem->mnId );
1372 StartTracking( STARTTRACK_SCROLLREPEAT );
1374 else if ( rMEvt.GetClicks() == 2 )
1375 DoubleClick();
1377 return;
1382 Control::MouseButtonDown( rMEvt );
1385 // -----------------------------------------------------------------------
1387 void ValueSet::MouseButtonUp( const MouseEvent& rMEvt )
1389 // Wegen SelectionMode
1390 if ( rMEvt.IsLeft() && mbSelection )
1391 ImplEndTracking( rMEvt.GetPosPixel(), FALSE );
1392 else
1393 Control::MouseButtonUp( rMEvt );
1396 // -----------------------------------------------------------------------
1398 void ValueSet::MouseMove( const MouseEvent& rMEvt )
1400 // Wegen SelectionMode
1401 if ( mbSelection || (GetStyle() & WB_MENUSTYLEVALUESET) )
1402 ImplTracking( rMEvt.GetPosPixel(), FALSE );
1403 Control::MouseMove( rMEvt );
1406 // -----------------------------------------------------------------------
1408 void ValueSet::Tracking( const TrackingEvent& rTEvt )
1410 Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
1412 if ( rTEvt.IsTrackingEnded() )
1413 ImplEndTracking( aMousePos, rTEvt.IsTrackingCanceled() );
1414 else
1415 ImplTracking( aMousePos, rTEvt.IsTrackingRepeat() );
1418 // -----------------------------------------------------------------------
1420 void ValueSet::KeyInput( const KeyEvent& rKEvt )
1422 USHORT nLastItem = (USHORT)mpImpl->mpItemList->Count();
1423 USHORT nItemPos = VALUESET_ITEM_NOTFOUND;
1424 USHORT nCurPos;
1425 USHORT nCalcPos;
1427 if ( !nLastItem || !ImplGetFirstItem() )
1429 Control::KeyInput( rKEvt );
1430 return;
1432 else
1433 nLastItem--;
1435 if ( mnSelItemId )
1436 nCurPos = GetItemPos( mnSelItemId );
1437 else
1438 nCurPos = VALUESET_ITEM_NONEITEM;
1439 nCalcPos = nCurPos;
1441 //switch off selection mode if key travelling is used
1442 BOOL bDefault = FALSE;
1443 switch ( rKEvt.GetKeyCode().GetCode() )
1445 case KEY_HOME:
1446 if ( mpNoneItem )
1447 nItemPos = VALUESET_ITEM_NONEITEM;
1448 else
1450 nItemPos = 0;
1451 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE )
1452 nItemPos++;
1454 break;
1456 case KEY_END:
1457 nItemPos = nLastItem;
1458 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE )
1460 if ( nItemPos == 0 )
1461 nItemPos = VALUESET_ITEM_NONEITEM;
1462 else
1463 nItemPos--;
1465 break;
1467 case KEY_LEFT:
1468 case KEY_RIGHT:
1469 if ( rKEvt.GetKeyCode().GetCode()==KEY_LEFT )
1473 if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1474 nItemPos = nLastItem;
1475 else if ( !nCalcPos )
1477 if ( mpNoneItem )
1478 nItemPos = VALUESET_ITEM_NONEITEM;
1479 else
1480 nItemPos = nLastItem;
1482 else
1483 nItemPos = nCalcPos-1;
1484 nCalcPos = nItemPos;
1486 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1488 else
1492 if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1493 nItemPos = 0;
1494 else if ( nCalcPos == nLastItem )
1496 if ( mpNoneItem )
1497 nItemPos = VALUESET_ITEM_NONEITEM;
1498 else
1499 nItemPos = 0;
1501 else
1502 nItemPos = nCalcPos+1;
1503 nCalcPos = nItemPos;
1505 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1507 break;
1509 case KEY_UP:
1510 case KEY_PAGEUP:
1512 if( rKEvt.GetKeyCode().GetCode() != KEY_PAGEUP ||
1513 ( !rKEvt.GetKeyCode().IsShift() && !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsMod2() ) )
1515 const long nLineCount = ( ( KEY_UP == rKEvt.GetKeyCode().GetCode() ) ? 1 : mnVisLines );
1518 if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1520 if ( nLastItem+1 <= mnCols )
1521 nItemPos = mnCurCol;
1522 else
1524 nItemPos = ((((nLastItem+1)/mnCols)-1)*mnCols)+(mnCurCol%mnCols);
1525 if ( nItemPos+mnCols <= nLastItem )
1526 nItemPos = nItemPos + mnCols;
1529 else if ( nCalcPos >= ( nLineCount * mnCols ) )
1530 nItemPos = sal::static_int_cast< USHORT >(
1531 nCalcPos - ( nLineCount * mnCols ));
1532 else
1534 if( (KEY_UP == rKEvt.GetKeyCode().GetCode() ) && (GetStyle() & WB_MENUSTYLEVALUESET) )
1536 Window* pParent = GetParent();
1537 pParent->GrabFocus();
1538 pParent->KeyInput( rKEvt );
1539 break;
1541 else
1543 if ( mpNoneItem )
1545 mnCurCol = nCalcPos%mnCols;
1546 nItemPos = VALUESET_ITEM_NONEITEM;
1548 else
1550 if ( nLastItem+1 <= mnCols )
1551 nItemPos = nCalcPos;
1552 else
1554 nItemPos = ((((nLastItem+1)/mnCols)-1)*mnCols)+(nCalcPos%mnCols);
1555 if ( nItemPos+mnCols <= nLastItem )
1556 nItemPos = nItemPos + mnCols;
1561 nCalcPos = nItemPos;
1563 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1565 else
1566 Control::KeyInput( rKEvt );
1568 break;
1570 case KEY_DOWN:
1571 case KEY_PAGEDOWN:
1573 if( rKEvt.GetKeyCode().GetCode() != KEY_PAGEDOWN ||
1574 ( !rKEvt.GetKeyCode().IsShift() && !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsMod2() ) )
1576 const long nLineCount = ( ( KEY_DOWN == rKEvt.GetKeyCode().GetCode() ) ? 1 : mnVisLines );
1579 if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1580 nItemPos = mnCurCol;
1581 else if ( nCalcPos + ( nLineCount * mnCols ) <= nLastItem )
1582 nItemPos = sal::static_int_cast< USHORT >(
1583 nCalcPos + ( nLineCount * mnCols ));
1584 else
1586 if( (KEY_DOWN == rKEvt.GetKeyCode().GetCode() ) && (GetStyle() & WB_MENUSTYLEVALUESET) )
1588 Window* pParent = GetParent();
1589 pParent->GrabFocus();
1590 pParent->KeyInput( rKEvt );
1591 break;
1593 else
1595 if ( mpNoneItem )
1597 mnCurCol = nCalcPos%mnCols;
1598 nItemPos = VALUESET_ITEM_NONEITEM;
1600 else
1601 nItemPos = nCalcPos%mnCols;
1604 nCalcPos = nItemPos;
1606 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1608 else
1609 Control::KeyInput( rKEvt );
1612 break;
1613 case KEY_RETURN:
1614 //enable default handling of KEY_RETURN in dialogs
1615 if(0 != (GetStyle()&WB_NO_DIRECTSELECT))
1617 Select();
1618 break;
1620 //no break;
1621 default:
1622 Control::KeyInput( rKEvt );
1623 bDefault = TRUE;
1624 break;
1627 if(!bDefault)
1628 EndSelection();
1629 if ( nItemPos != VALUESET_ITEM_NOTFOUND )
1631 USHORT nItemId;
1632 if ( nItemPos != VALUESET_ITEM_NONEITEM )
1633 nItemId = GetItemId( nItemPos );
1634 else
1635 nItemId = 0;
1636 if ( nItemId != mnSelItemId )
1638 SelectItem( nItemId );
1639 //select only if WB_NO_DIRECTSELECT is not set
1640 if(0 == (GetStyle()&WB_NO_DIRECTSELECT))
1641 Select();
1646 // -----------------------------------------------------------------------
1648 void ValueSet::Command( const CommandEvent& rCEvt )
1650 if ( (rCEvt.GetCommand() == COMMAND_WHEEL) ||
1651 (rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL) ||
1652 (rCEvt.GetCommand() == COMMAND_AUTOSCROLL) )
1654 if ( HandleScrollCommand( rCEvt, NULL, mpScrBar ) )
1655 return;
1658 Control::Command( rCEvt );
1661 // -----------------------------------------------------------------------
1663 void ValueSet::Paint( const Rectangle& )
1665 if ( GetStyle() & WB_FLATVALUESET )
1667 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1668 SetLineColor();
1669 SetFillColor( rStyleSettings.GetFaceColor() );
1670 long nOffY = maVirDev.GetOutputSizePixel().Height();
1671 Size aWinSize = GetOutputSizePixel();
1672 DrawRect( Rectangle( Point( 0, nOffY ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
1675 ImplDraw();
1678 // -----------------------------------------------------------------------
1680 void ValueSet::GetFocus()
1682 OSL_TRACE ("value set getting focus");
1683 ImplDrawSelect();
1684 Control::GetFocus();
1686 // Send accessibility event.
1687 ::com::sun::star::uno::Any aOldState, aNewState;
1688 aNewState <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
1689 ImplFireAccessibleEvent (
1690 ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED,
1691 aOldState, aNewState);
1695 // -----------------------------------------------------------------------
1697 void ValueSet::LoseFocus()
1699 OSL_TRACE ("value set losing focus");
1700 if ( mbNoSelection && mnSelItemId )
1701 ImplHideSelect( mnSelItemId );
1702 else
1703 HideFocus();
1704 Control::LoseFocus();
1706 // Send accessibility event.
1707 ::com::sun::star::uno::Any aOldState, aNewState;
1708 aOldState <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
1709 ImplFireAccessibleEvent (
1710 ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED,
1711 aOldState, aNewState);
1714 // -----------------------------------------------------------------------
1716 void ValueSet::Resize()
1718 mbFormat = TRUE;
1719 if ( IsReallyVisible() && IsUpdateMode() )
1720 Invalidate();
1721 Control::Resize();
1724 // -----------------------------------------------------------------------
1726 void ValueSet::RequestHelp( const HelpEvent& rHEvt )
1728 if ( (rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON)) == HELPMODE_QUICK )
1730 Point aPos = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
1731 USHORT nItemPos = ImplGetItem( aPos );
1732 if ( nItemPos != VALUESET_ITEM_NOTFOUND )
1734 ValueSetItem* pItem = ImplGetItem( nItemPos );
1735 Rectangle aItemRect = pItem->maRect;
1736 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1737 aItemRect.Left() = aPt.X();
1738 aItemRect.Top() = aPt.Y();
1739 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1740 aItemRect.Right() = aPt.X();
1741 aItemRect.Bottom() = aPt.Y();
1742 Help::ShowQuickHelp( this, aItemRect, GetItemText( pItem->mnId ) );
1743 return;
1747 Control::RequestHelp( rHEvt );
1750 // -----------------------------------------------------------------------
1752 void ValueSet::StateChanged( StateChangedType nType )
1754 Control::StateChanged( nType );
1756 if ( nType == STATE_CHANGE_INITSHOW )
1758 if ( mbFormat )
1759 Format();
1761 else if ( nType == STATE_CHANGE_UPDATEMODE )
1763 if ( IsReallyVisible() && IsUpdateMode() )
1764 Invalidate();
1766 else if ( nType == STATE_CHANGE_TEXT )
1768 if ( mpNoneItem && !mbFormat && IsReallyVisible() && IsUpdateMode() )
1770 ImplFormatItem( mpNoneItem );
1771 Invalidate( mpNoneItem->maRect );
1774 else if ( (nType == STATE_CHANGE_ZOOM) ||
1775 (nType == STATE_CHANGE_CONTROLFONT) )
1777 ImplInitSettings( TRUE, FALSE, FALSE );
1778 Invalidate();
1780 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1782 ImplInitSettings( FALSE, TRUE, FALSE );
1783 Invalidate();
1785 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1787 ImplInitSettings( FALSE, FALSE, TRUE );
1788 Invalidate();
1790 else if ( (nType == STATE_CHANGE_STYLE) || (nType == STATE_CHANGE_ENABLE) )
1792 mbFormat = TRUE;
1793 ImplInitSettings( FALSE, FALSE, TRUE );
1794 Invalidate();
1798 // -----------------------------------------------------------------------
1800 void ValueSet::DataChanged( const DataChangedEvent& rDCEvt )
1802 Control::DataChanged( rDCEvt );
1804 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1805 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1806 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1807 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1808 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1810 mbFormat = TRUE;
1811 ImplInitSettings( TRUE, TRUE, TRUE );
1812 Invalidate();
1816 // -----------------------------------------------------------------------
1818 void ValueSet::Select()
1820 maSelectHdl.Call( this );
1823 // -----------------------------------------------------------------------
1825 void ValueSet::DoubleClick()
1827 maDoubleClickHdl.Call( this );
1830 // -----------------------------------------------------------------------
1832 void ValueSet::UserDraw( const UserDrawEvent& )
1836 // -----------------------------------------------------------------------
1838 void ValueSet::InsertItem( USHORT nItemId, const Image& rImage, USHORT nPos )
1840 DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1841 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1842 "ValueSet::InsertItem(): ItemId already exists" );
1844 ValueSetItem* pItem = new ValueSetItem( *this );
1845 pItem->mnId = nItemId;
1846 pItem->meType = VALUESETITEM_IMAGE;
1847 pItem->maImage = rImage;
1848 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1850 mbFormat = TRUE;
1851 if ( IsReallyVisible() && IsUpdateMode() )
1852 Invalidate();
1855 // -----------------------------------------------------------------------
1857 void ValueSet::InsertItem( USHORT nItemId, const Color& rColor, USHORT nPos )
1859 DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1860 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1861 "ValueSet::InsertItem(): ItemId already exists" );
1863 ValueSetItem* pItem = new ValueSetItem( *this );
1864 pItem->mnId = nItemId;
1865 pItem->meType = VALUESETITEM_COLOR;
1866 pItem->maColor = rColor;
1867 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1869 mbFormat = TRUE;
1870 if ( IsReallyVisible() && IsUpdateMode() )
1871 Invalidate();
1874 // -----------------------------------------------------------------------
1876 void ValueSet::InsertItem( USHORT nItemId, const Image& rImage,
1877 const XubString& rText, USHORT nPos )
1879 DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1880 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1881 "ValueSet::InsertItem(): ItemId already exists" );
1883 ValueSetItem* pItem = new ValueSetItem( *this );
1884 pItem->mnId = nItemId;
1885 pItem->meType = VALUESETITEM_IMAGE;
1886 pItem->maImage = rImage;
1887 pItem->maText = rText;
1888 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1890 mbFormat = TRUE;
1891 if ( IsReallyVisible() && IsUpdateMode() )
1892 Invalidate();
1895 // -----------------------------------------------------------------------
1897 void ValueSet::InsertItem( USHORT nItemId, const Color& rColor,
1898 const XubString& rText, USHORT nPos )
1900 DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1901 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1902 "ValueSet::InsertItem(): ItemId already exists" );
1904 ValueSetItem* pItem = new ValueSetItem( *this );
1905 pItem->mnId = nItemId;
1906 pItem->meType = VALUESETITEM_COLOR;
1907 pItem->maColor = rColor;
1908 pItem->maText = rText;
1909 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1911 mbFormat = TRUE;
1912 if ( IsReallyVisible() && IsUpdateMode() )
1913 Invalidate();
1916 // -----------------------------------------------------------------------
1918 void ValueSet::InsertItem( USHORT nItemId, USHORT nPos )
1920 DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1921 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1922 "ValueSet::InsertItem(): ItemId already exists" );
1924 ValueSetItem* pItem = new ValueSetItem( *this );
1925 pItem->mnId = nItemId;
1926 pItem->meType = VALUESETITEM_USERDRAW;
1927 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1929 mbFormat = TRUE;
1930 if ( IsReallyVisible() && IsUpdateMode() )
1931 Invalidate();
1934 // -----------------------------------------------------------------------
1936 void ValueSet::InsertSpace( USHORT nItemId, USHORT nPos )
1938 DBG_ASSERT( nItemId, "ValueSet::InsertSpace(): ItemId == 0" );
1939 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1940 "ValueSet::InsertSpace(): ItemId already exists" );
1942 ValueSetItem* pItem = new ValueSetItem( *this );
1943 pItem->mnId = nItemId;
1944 pItem->meType = VALUESETITEM_SPACE;
1945 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1947 mbFormat = TRUE;
1948 if ( IsReallyVisible() && IsUpdateMode() )
1949 Invalidate();
1952 // -----------------------------------------------------------------------
1954 void ValueSet::RemoveItem( USHORT nItemId )
1956 USHORT nPos = GetItemPos( nItemId );
1958 if ( nPos == VALUESET_ITEM_NOTFOUND )
1959 return;
1961 delete mpImpl->mpItemList->Remove( nPos );
1963 // Variablen zuruecksetzen
1964 if ( (mnHighItemId == nItemId) || (mnSelItemId == nItemId) )
1966 mnCurCol = 0;
1967 mnOldItemId = 0;
1968 mnHighItemId = 0;
1969 mnSelItemId = 0;
1970 mbNoSelection = TRUE;
1973 mbFormat = TRUE;
1974 if ( IsReallyVisible() && IsUpdateMode() )
1975 Invalidate();
1978 // -----------------------------------------------------------------------
1980 void ValueSet::CopyItems( const ValueSet& rValueSet )
1982 ImplDeleteItems();
1984 ValueSetItem* pItem = rValueSet.mpImpl->mpItemList->First();
1985 while ( pItem )
1987 ValueSetItem* pNewItem = new ValueSetItem( *this );
1989 pNewItem->mnId = pItem->mnId;
1990 pNewItem->mnBits = pItem->mnBits;
1991 pNewItem->meType = pItem->meType;
1992 pNewItem->maImage = pItem->maImage;
1993 pNewItem->maColor = pItem->maColor;
1994 pNewItem->maText = pItem->maText;
1995 pNewItem->mpData = pItem->mpData;
1996 pNewItem->maRect = pItem->maRect;
1997 pNewItem->mpxAcc = NULL;
1999 mpImpl->mpItemList->Insert( pNewItem );
2000 pItem = rValueSet.mpImpl->mpItemList->Next();
2003 // Variablen zuruecksetzen
2004 mnFirstLine = 0;
2005 mnCurCol = 0;
2006 mnOldItemId = 0;
2007 mnHighItemId = 0;
2008 mnSelItemId = 0;
2009 mbNoSelection = TRUE;
2011 mbFormat = TRUE;
2012 if ( IsReallyVisible() && IsUpdateMode() )
2013 Invalidate();
2016 // -----------------------------------------------------------------------
2018 void ValueSet::Clear()
2020 ImplDeleteItems();
2022 // Variablen zuruecksetzen
2023 mnFirstLine = 0;
2024 mnCurCol = 0;
2025 mnOldItemId = 0;
2026 mnHighItemId = 0;
2027 mnSelItemId = 0;
2028 mbNoSelection = TRUE;
2030 mbFormat = TRUE;
2031 if ( IsReallyVisible() && IsUpdateMode() )
2032 Invalidate();
2035 // -----------------------------------------------------------------------
2037 USHORT ValueSet::GetItemCount() const
2039 return (USHORT)mpImpl->mpItemList->Count();
2042 // -----------------------------------------------------------------------
2044 USHORT ValueSet::GetItemPos( USHORT nItemId ) const
2046 ValueSetItem* pItem = mpImpl->mpItemList->First();
2047 while ( pItem )
2049 if ( pItem->mnId == nItemId )
2050 return (USHORT)mpImpl->mpItemList->GetCurPos();
2051 pItem = mpImpl->mpItemList->Next();
2054 return VALUESET_ITEM_NOTFOUND;
2057 // -----------------------------------------------------------------------
2059 USHORT ValueSet::GetItemId( USHORT nPos ) const
2061 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2063 if ( pItem )
2064 return pItem->mnId;
2065 else
2066 return 0;
2069 // -----------------------------------------------------------------------
2071 USHORT ValueSet::GetItemId( const Point& rPos ) const
2073 USHORT nItemPos = ImplGetItem( rPos );
2074 if ( nItemPos != VALUESET_ITEM_NOTFOUND )
2075 return GetItemId( nItemPos );
2077 return 0;
2080 // -----------------------------------------------------------------------
2082 Rectangle ValueSet::GetItemRect( USHORT nItemId ) const
2084 USHORT nPos = GetItemPos( nItemId );
2086 if ( nPos != VALUESET_ITEM_NOTFOUND )
2087 return mpImpl->mpItemList->GetObject( nPos )->maRect;
2088 else
2089 return Rectangle();
2092 // -----------------------------------------------------------------------
2094 void ValueSet::EnableFullItemMode( BOOL bFullMode )
2096 mbFullMode = bFullMode;
2099 // -----------------------------------------------------------------------
2101 void ValueSet::SetColCount( USHORT nNewCols )
2103 if ( mnUserCols != nNewCols )
2105 mnUserCols = nNewCols;
2106 mbFormat = TRUE;
2107 if ( IsReallyVisible() && IsUpdateMode() )
2108 Invalidate();
2112 // -----------------------------------------------------------------------
2114 void ValueSet::SetLineCount( USHORT nNewLines )
2116 if ( mnUserVisLines != nNewLines )
2118 mnUserVisLines = nNewLines;
2119 mbFormat = TRUE;
2120 if ( IsReallyVisible() && IsUpdateMode() )
2121 Invalidate();
2125 // -----------------------------------------------------------------------
2127 void ValueSet::SetItemWidth( long nNewItemWidth )
2129 if ( mnUserItemWidth != nNewItemWidth )
2131 mnUserItemWidth = nNewItemWidth;
2132 mbFormat = TRUE;
2133 if ( IsReallyVisible() && IsUpdateMode() )
2134 Invalidate();
2138 // -----------------------------------------------------------------------
2140 void ValueSet::SetItemHeight( long nNewItemHeight )
2142 if ( mnUserItemHeight != nNewItemHeight )
2144 mnUserItemHeight = nNewItemHeight;
2145 mbFormat = TRUE;
2146 if ( IsReallyVisible() && IsUpdateMode() )
2147 Invalidate();
2151 // -----------------------------------------------------------------------
2153 void ValueSet::SetFirstLine( USHORT nNewLine )
2155 if ( mnFirstLine != nNewLine )
2157 mnFirstLine = nNewLine;
2158 mbFormat = TRUE;
2159 if ( IsReallyVisible() && IsUpdateMode() )
2160 Invalidate();
2164 // -----------------------------------------------------------------------
2166 void ValueSet::SelectItem( USHORT nItemId )
2168 USHORT nItemPos = 0;
2170 if ( nItemId )
2172 nItemPos = GetItemPos( nItemId );
2173 if ( nItemPos == VALUESET_ITEM_NOTFOUND )
2174 return;
2175 if ( mpImpl->mpItemList->GetObject( nItemPos )->meType == VALUESETITEM_SPACE )
2176 return;
2179 if ( (mnSelItemId != nItemId) || mbNoSelection )
2181 USHORT nOldItem = mnSelItemId ? mnSelItemId : 1;
2182 mnSelItemId = nItemId;
2183 mbNoSelection = FALSE;
2185 BOOL bNewOut;
2186 BOOL bNewLine;
2187 if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2188 bNewOut = TRUE;
2189 else
2190 bNewOut = FALSE;
2191 bNewLine = FALSE;
2193 // Gegebenenfalls in den sichtbaren Bereich scrollen
2194 if ( mbScroll && nItemId )
2196 USHORT nNewLine = (USHORT)(nItemPos / mnCols);
2197 if ( nNewLine < mnFirstLine )
2199 mnFirstLine = nNewLine;
2200 bNewLine = TRUE;
2202 else if ( nNewLine > (USHORT)(mnFirstLine+mnVisLines-1) )
2204 mnFirstLine = (USHORT)(nNewLine-mnVisLines+1);
2205 bNewLine = TRUE;
2209 if ( bNewOut )
2211 if ( bNewLine )
2213 // Falls sich der sichtbare Bereich geaendert hat,
2214 // alles neu ausgeben
2215 mbFormat = TRUE;
2216 ImplDraw();
2218 else
2220 // alte Selection wegnehmen und neue ausgeben
2221 ImplHideSelect( nOldItem );
2222 ImplDrawSelect();
2226 if( ImplHasAccessibleListeners() )
2228 // focus event (deselect)
2229 if( nOldItem )
2231 const USHORT nPos = GetItemPos( nItemId );
2233 if( nPos != VALUESET_ITEM_NOTFOUND )
2235 ValueItemAcc* pItemAcc = ValueItemAcc::getImplementation(
2236 mpImpl->mpItemList->GetObject( nPos )->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2238 if( pItemAcc )
2240 ::com::sun::star::uno::Any aOldAny, aNewAny;
2241 if( !mpImpl->mbIsTransientChildrenDisabled)
2243 aOldAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
2244 static_cast< ::cppu::OWeakObject* >( pItemAcc ));
2245 ImplFireAccessibleEvent (::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
2247 else
2249 aOldAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
2250 pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
2256 // focus event (select)
2257 const USHORT nPos = GetItemPos( mnSelItemId );
2259 ValueSetItem* pItem;
2260 if( nPos != VALUESET_ITEM_NOTFOUND )
2261 pItem = mpImpl->mpItemList->GetObject(nPos);
2262 else
2263 pItem = mpNoneItem;
2265 ValueItemAcc* pItemAcc = NULL;
2266 if (pItem != NULL)
2267 pItemAcc = ValueItemAcc::getImplementation(pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2269 if( pItemAcc )
2271 ::com::sun::star::uno::Any aOldAny, aNewAny;
2272 if( !mpImpl->mbIsTransientChildrenDisabled)
2274 aNewAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
2275 static_cast< ::cppu::OWeakObject* >( pItemAcc ));
2276 ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
2278 else
2280 aNewAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
2281 pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
2285 // selection event
2286 ::com::sun::star::uno::Any aOldAny, aNewAny;
2287 ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::SELECTION_CHANGED, aOldAny, aNewAny );
2292 // -----------------------------------------------------------------------
2294 void ValueSet::SetNoSelection()
2296 mbNoSelection = TRUE;
2297 mbHighlight = FALSE;
2298 mbSelection = FALSE;
2300 if ( IsReallyVisible() && IsUpdateMode() )
2301 ImplDraw();
2304 // -----------------------------------------------------------------------
2306 void ValueSet::SetItemBits( USHORT nItemId, USHORT nItemBits )
2308 USHORT nPos = GetItemPos( nItemId );
2310 if ( nPos != VALUESET_ITEM_NOTFOUND )
2311 mpImpl->mpItemList->GetObject( nPos )->mnBits = nItemBits;
2314 // -----------------------------------------------------------------------
2316 USHORT ValueSet::GetItemBits( USHORT nItemId ) const
2318 USHORT nPos = GetItemPos( nItemId );
2320 if ( nPos != VALUESET_ITEM_NOTFOUND )
2321 return mpImpl->mpItemList->GetObject( nPos )->mnBits;
2322 else
2323 return 0;
2326 // -----------------------------------------------------------------------
2328 void ValueSet::SetItemImage( USHORT nItemId, const Image& rImage )
2330 USHORT nPos = GetItemPos( nItemId );
2332 if ( nPos == VALUESET_ITEM_NOTFOUND )
2333 return;
2335 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2336 pItem->meType = VALUESETITEM_IMAGE;
2337 pItem->maImage = rImage;
2339 if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2341 ImplFormatItem( pItem );
2342 Invalidate( pItem->maRect );
2344 else
2345 mbFormat = TRUE;
2348 // -----------------------------------------------------------------------
2350 Image ValueSet::GetItemImage( USHORT nItemId ) const
2352 USHORT nPos = GetItemPos( nItemId );
2354 if ( nPos != VALUESET_ITEM_NOTFOUND )
2355 return mpImpl->mpItemList->GetObject( nPos )->maImage;
2356 else
2357 return Image();
2360 // -----------------------------------------------------------------------
2362 void ValueSet::SetItemColor( USHORT nItemId, const Color& rColor )
2364 USHORT nPos = GetItemPos( nItemId );
2366 if ( nPos == VALUESET_ITEM_NOTFOUND )
2367 return;
2369 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2370 pItem->meType = VALUESETITEM_COLOR;
2371 pItem->maColor = rColor;
2373 if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2375 ImplFormatItem( pItem );
2376 Invalidate( pItem->maRect );
2378 else
2379 mbFormat = TRUE;
2382 // -----------------------------------------------------------------------
2384 Color ValueSet::GetItemColor( USHORT nItemId ) const
2386 USHORT nPos = GetItemPos( nItemId );
2388 if ( nPos != VALUESET_ITEM_NOTFOUND )
2389 return mpImpl->mpItemList->GetObject( nPos )->maColor;
2390 else
2391 return Color();
2394 // -----------------------------------------------------------------------
2396 void ValueSet::SetItemData( USHORT nItemId, void* pData )
2398 USHORT nPos = GetItemPos( nItemId );
2400 if ( nPos == VALUESET_ITEM_NOTFOUND )
2401 return;
2403 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2404 pItem->mpData = pData;
2406 if ( pItem->meType == VALUESETITEM_USERDRAW )
2408 if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2410 ImplFormatItem( pItem );
2411 Invalidate( pItem->maRect );
2413 else
2414 mbFormat = TRUE;
2418 // -----------------------------------------------------------------------
2420 void* ValueSet::GetItemData( USHORT nItemId ) const
2422 USHORT nPos = GetItemPos( nItemId );
2424 if ( nPos != VALUESET_ITEM_NOTFOUND )
2425 return mpImpl->mpItemList->GetObject( nPos )->mpData;
2426 else
2427 return NULL;
2430 // -----------------------------------------------------------------------
2432 void ValueSet::SetItemText( USHORT nItemId, const XubString& rText )
2434 USHORT nPos = GetItemPos( nItemId );
2436 if ( nPos == VALUESET_ITEM_NOTFOUND )
2437 return;
2440 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2442 // Remember old and new name for accessibility event.
2443 ::com::sun::star::uno::Any aOldName, aNewName;
2444 ::rtl::OUString sString (pItem->maText);
2445 aOldName <<= sString;
2446 sString = rText;
2447 aNewName <<= sString;
2449 pItem->maText = rText;
2451 if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2453 USHORT nTempId = mnSelItemId;
2455 if ( mbHighlight )
2456 nTempId = mnHighItemId;
2458 if ( nTempId == nItemId )
2459 ImplDrawItemText( pItem->maText );
2462 if (ImplHasAccessibleListeners())
2464 ::com::sun::star::uno::Reference<
2465 ::com::sun::star::accessibility::XAccessible> xAccessible (
2466 pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2467 static_cast<ValueItemAcc*>(xAccessible.get())->FireAccessibleEvent (
2468 ::com::sun::star::accessibility::AccessibleEventId::NAME_CHANGED,
2469 aOldName, aNewName);
2473 // -----------------------------------------------------------------------
2475 XubString ValueSet::GetItemText( USHORT nItemId ) const
2477 USHORT nPos = GetItemPos( nItemId );
2479 if ( nPos != VALUESET_ITEM_NOTFOUND )
2480 return mpImpl->mpItemList->GetObject( nPos )->maText;
2481 else
2482 return XubString();
2485 // -----------------------------------------------------------------------
2487 void ValueSet::SetColor( const Color& rColor )
2489 maColor = rColor;
2490 mbFormat = TRUE;
2491 if ( IsReallyVisible() && IsUpdateMode() )
2492 ImplDraw();
2495 // -----------------------------------------------------------------------
2497 void ValueSet::SetExtraSpacing( USHORT nNewSpacing )
2499 if ( GetStyle() & WB_ITEMBORDER )
2501 mnSpacing = nNewSpacing;
2503 mbFormat = TRUE;
2504 if ( IsReallyVisible() && IsUpdateMode() )
2505 Invalidate();
2509 // -----------------------------------------------------------------------
2511 void ValueSet::StartSelection()
2513 mnOldItemId = mnSelItemId;
2514 mbHighlight = TRUE;
2515 mbSelection = TRUE;
2516 mnHighItemId = mnSelItemId;
2519 // -----------------------------------------------------------------------
2521 void ValueSet::EndSelection()
2523 if ( mbHighlight )
2525 if ( IsTracking() )
2526 EndTracking( ENDTRACK_CANCEL );
2528 ImplHighlightItem( mnSelItemId );
2529 mbHighlight = FALSE;
2531 mbSelection = FALSE;
2534 // -----------------------------------------------------------------------
2536 BOOL ValueSet::StartDrag( const CommandEvent& rCEvt, Region& rRegion )
2538 if ( rCEvt.GetCommand() != COMMAND_STARTDRAG )
2539 return FALSE;
2541 // Gegebenenfalls eine vorhandene Aktion abbrechen
2542 EndSelection();
2544 // Testen, ob angeklickte Seite selektiert ist. Falls dies nicht
2545 // der Fall ist, setzen wir ihn als aktuellen Eintrag. Falls Drag and
2546 // Drop auch mal ueber Tastatur ausgeloest werden kann, testen wir
2547 // dies nur bei einer Mausaktion.
2548 USHORT nSelId;
2549 if ( rCEvt.IsMouseEvent() )
2550 nSelId = GetItemId( rCEvt.GetMousePosPixel() );
2551 else
2552 nSelId = mnSelItemId;
2554 // Falls kein Eintrag angeklickt wurde, starten wir kein Dragging
2555 if ( !nSelId )
2556 return FALSE;
2558 // Testen, ob Seite selektiertiert ist. Falls nicht, als aktuelle
2559 // Seite setzen und Select rufen.
2560 if ( nSelId != mnSelItemId )
2562 SelectItem( nSelId );
2563 Update();
2564 Select();
2567 Region aRegion;
2569 // Region zuweisen
2570 rRegion = aRegion;
2572 return TRUE;
2575 // -----------------------------------------------------------------------
2577 Size ValueSet::CalcWindowSizePixel( const Size& rItemSize, USHORT nDesireCols,
2578 USHORT nDesireLines )
2580 long nCalcCols = (long)nDesireCols;
2581 long nCalcLines = (long)nDesireLines;
2583 if ( !nCalcCols )
2585 if ( mnUserCols )
2586 nCalcCols = (long)mnUserCols;
2587 else
2588 nCalcCols = 1;
2591 if ( !nCalcLines )
2593 nCalcLines = mnVisLines;
2595 if ( mbFormat )
2597 if ( mnUserVisLines )
2598 nCalcLines = mnUserVisLines;
2599 else
2601 nCalcLines = (long)mpImpl->mpItemList->Count() / nCalcCols;
2602 if ( mpImpl->mpItemList->Count() % nCalcCols )
2603 nCalcLines++;
2604 else if ( !nCalcLines )
2605 nCalcLines = 1;
2610 Size aSize( rItemSize.Width()*nCalcCols, rItemSize.Height()*nCalcLines );
2611 WinBits nStyle = GetStyle();
2612 long nTxtHeight = GetTextHeight();
2613 long nSpace;
2614 long n;
2616 if ( nStyle & WB_ITEMBORDER )
2618 if ( nStyle & WB_DOUBLEBORDER )
2619 n = ITEM_OFFSET_DOUBLE;
2620 else
2621 n = ITEM_OFFSET;
2623 aSize.Width() += n*nCalcCols;
2624 aSize.Height() += n*nCalcLines;
2626 else
2627 n = 0;
2629 if ( mnSpacing )
2631 nSpace = mnSpacing;
2632 aSize.Width() += mnSpacing*(nCalcCols-1);
2633 aSize.Height() += mnSpacing*(nCalcLines-1);
2635 else
2636 nSpace = 0;
2638 if ( nStyle & WB_NAMEFIELD )
2640 aSize.Height() += nTxtHeight + NAME_OFFSET;
2641 if ( !(nStyle & WB_FLATVALUESET) )
2642 aSize.Height() += NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
2645 if ( nStyle & WB_NONEFIELD )
2647 aSize.Height() += nTxtHeight + n + nSpace;
2648 if ( nStyle & WB_RADIOSEL )
2649 aSize.Height() += 8;
2652 // Evt. ScrollBar-Breite aufaddieren
2653 aSize.Width() += GetScrollWidth();
2655 return aSize;
2658 // -----------------------------------------------------------------------
2660 Size ValueSet::CalcItemSizePixel( const Size& rItemSize, BOOL bOut ) const
2662 Size aSize = rItemSize;
2664 WinBits nStyle = GetStyle();
2665 if ( nStyle & WB_ITEMBORDER )
2667 long n;
2669 if ( nStyle & WB_DOUBLEBORDER )
2670 n = ITEM_OFFSET_DOUBLE;
2671 else
2672 n = ITEM_OFFSET;
2674 if ( bOut )
2676 aSize.Width() += n;
2677 aSize.Height() += n;
2679 else
2681 aSize.Width() -= n;
2682 aSize.Height() -= n;
2686 return aSize;
2689 // -----------------------------------------------------------------------
2691 long ValueSet::GetScrollWidth() const
2693 if ( GetStyle() & WB_VSCROLL )
2695 ((ValueSet*)this)->ImplInitScrollBar();
2696 return mpScrBar->GetSizePixel().Width()+SCRBAR_OFFSET;
2698 else
2699 return 0;
2702 // -----------------------------------------------------------------------
2704 USHORT ValueSet::ShowDropPos( const Point& rPos )
2706 mbDropPos = TRUE;
2708 // Gegebenenfalls scrollen
2709 ImplScroll( rPos );
2711 // DropPosition ermitteln
2712 USHORT nPos = ImplGetItem( rPos, TRUE );
2713 if ( nPos == VALUESET_ITEM_NONEITEM )
2714 nPos = 0;
2715 else if ( nPos == VALUESET_ITEM_NOTFOUND )
2717 Size aOutSize = GetOutputSizePixel();
2718 if ( GetStyle() & WB_NAMEFIELD )
2719 aOutSize.Height() = mnTextOffset;
2720 if ( (rPos.X() >= 0) && (rPos.X() < aOutSize.Width()) &&
2721 (rPos.Y() >= 0) && (rPos.Y() < aOutSize.Height()) )
2722 nPos = (USHORT)mpImpl->mpItemList->Count();
2724 else
2726 // Im letzten viertel, dann wird ein Item spaeter eingefuegt
2727 Rectangle aRect = mpImpl->mpItemList->GetObject( nPos )->maRect;
2728 if ( rPos.X() > aRect.Left()+aRect.GetWidth()-(aRect.GetWidth()/4) )
2729 nPos++;
2732 if ( nPos != mnDropPos )
2734 ImplDrawDropPos( FALSE );
2735 mnDropPos = nPos;
2736 ImplDrawDropPos( TRUE );
2739 return mnDropPos;
2742 // -----------------------------------------------------------------------
2744 void ValueSet::HideDropPos()
2746 if ( mbDropPos )
2748 ImplDrawDropPos( FALSE );
2749 mbDropPos = FALSE;
2753 // -----------------------------------------------------------------------
2755 bool ValueSet::IsRTLActive (void)
2757 return Application::GetSettings().GetLayoutRTL() && IsRTLEnabled();