merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / control / valueset.cxx
blob014df3c2a4a925f85f4f2a620ccd6f121700b98c
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 // Tell the accessible object that we got the focus.
1687 ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( FALSE ) );
1688 if( pAcc )
1689 pAcc->GetFocus();
1692 // -----------------------------------------------------------------------
1694 void ValueSet::LoseFocus()
1696 OSL_TRACE ("value set losing focus");
1697 if ( mbNoSelection && mnSelItemId )
1698 ImplHideSelect( mnSelItemId );
1699 else
1700 HideFocus();
1701 Control::LoseFocus();
1703 // Tell the accessible object that we lost the focus.
1704 ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( FALSE ) );
1705 if( pAcc )
1706 pAcc->LoseFocus();
1709 // -----------------------------------------------------------------------
1711 void ValueSet::Resize()
1713 mbFormat = TRUE;
1714 if ( IsReallyVisible() && IsUpdateMode() )
1715 Invalidate();
1716 Control::Resize();
1719 // -----------------------------------------------------------------------
1721 void ValueSet::RequestHelp( const HelpEvent& rHEvt )
1723 if ( (rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON)) == HELPMODE_QUICK )
1725 Point aPos = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
1726 USHORT nItemPos = ImplGetItem( aPos );
1727 if ( nItemPos != VALUESET_ITEM_NOTFOUND )
1729 ValueSetItem* pItem = ImplGetItem( nItemPos );
1730 Rectangle aItemRect = pItem->maRect;
1731 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1732 aItemRect.Left() = aPt.X();
1733 aItemRect.Top() = aPt.Y();
1734 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1735 aItemRect.Right() = aPt.X();
1736 aItemRect.Bottom() = aPt.Y();
1737 Help::ShowQuickHelp( this, aItemRect, GetItemText( pItem->mnId ) );
1738 return;
1742 Control::RequestHelp( rHEvt );
1745 // -----------------------------------------------------------------------
1747 void ValueSet::StateChanged( StateChangedType nType )
1749 Control::StateChanged( nType );
1751 if ( nType == STATE_CHANGE_INITSHOW )
1753 if ( mbFormat )
1754 Format();
1756 else if ( nType == STATE_CHANGE_UPDATEMODE )
1758 if ( IsReallyVisible() && IsUpdateMode() )
1759 Invalidate();
1761 else if ( nType == STATE_CHANGE_TEXT )
1763 if ( mpNoneItem && !mbFormat && IsReallyVisible() && IsUpdateMode() )
1765 ImplFormatItem( mpNoneItem );
1766 Invalidate( mpNoneItem->maRect );
1769 else if ( (nType == STATE_CHANGE_ZOOM) ||
1770 (nType == STATE_CHANGE_CONTROLFONT) )
1772 ImplInitSettings( TRUE, FALSE, FALSE );
1773 Invalidate();
1775 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1777 ImplInitSettings( FALSE, TRUE, FALSE );
1778 Invalidate();
1780 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1782 ImplInitSettings( FALSE, FALSE, TRUE );
1783 Invalidate();
1785 else if ( (nType == STATE_CHANGE_STYLE) || (nType == STATE_CHANGE_ENABLE) )
1787 mbFormat = TRUE;
1788 ImplInitSettings( FALSE, FALSE, TRUE );
1789 Invalidate();
1793 // -----------------------------------------------------------------------
1795 void ValueSet::DataChanged( const DataChangedEvent& rDCEvt )
1797 Control::DataChanged( rDCEvt );
1799 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1800 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1801 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1802 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1803 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1805 mbFormat = TRUE;
1806 ImplInitSettings( TRUE, TRUE, TRUE );
1807 Invalidate();
1811 // -----------------------------------------------------------------------
1813 void ValueSet::Select()
1815 maSelectHdl.Call( this );
1818 // -----------------------------------------------------------------------
1820 void ValueSet::DoubleClick()
1822 maDoubleClickHdl.Call( this );
1825 // -----------------------------------------------------------------------
1827 void ValueSet::UserDraw( const UserDrawEvent& )
1831 // -----------------------------------------------------------------------
1833 void ValueSet::InsertItem( USHORT nItemId, const Image& rImage, USHORT nPos )
1835 DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1836 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1837 "ValueSet::InsertItem(): ItemId already exists" );
1839 ValueSetItem* pItem = new ValueSetItem( *this );
1840 pItem->mnId = nItemId;
1841 pItem->meType = VALUESETITEM_IMAGE;
1842 pItem->maImage = rImage;
1843 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1845 mbFormat = TRUE;
1846 if ( IsReallyVisible() && IsUpdateMode() )
1847 Invalidate();
1850 // -----------------------------------------------------------------------
1852 void ValueSet::InsertItem( USHORT nItemId, const Color& rColor, USHORT nPos )
1854 DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1855 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1856 "ValueSet::InsertItem(): ItemId already exists" );
1858 ValueSetItem* pItem = new ValueSetItem( *this );
1859 pItem->mnId = nItemId;
1860 pItem->meType = VALUESETITEM_COLOR;
1861 pItem->maColor = rColor;
1862 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1864 mbFormat = TRUE;
1865 if ( IsReallyVisible() && IsUpdateMode() )
1866 Invalidate();
1869 // -----------------------------------------------------------------------
1871 void ValueSet::InsertItem( USHORT nItemId, const Image& rImage,
1872 const XubString& rText, USHORT nPos )
1874 DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1875 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1876 "ValueSet::InsertItem(): ItemId already exists" );
1878 ValueSetItem* pItem = new ValueSetItem( *this );
1879 pItem->mnId = nItemId;
1880 pItem->meType = VALUESETITEM_IMAGE;
1881 pItem->maImage = rImage;
1882 pItem->maText = rText;
1883 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1885 mbFormat = TRUE;
1886 if ( IsReallyVisible() && IsUpdateMode() )
1887 Invalidate();
1890 // -----------------------------------------------------------------------
1892 void ValueSet::InsertItem( USHORT nItemId, const Color& rColor,
1893 const XubString& rText, USHORT nPos )
1895 DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1896 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1897 "ValueSet::InsertItem(): ItemId already exists" );
1899 ValueSetItem* pItem = new ValueSetItem( *this );
1900 pItem->mnId = nItemId;
1901 pItem->meType = VALUESETITEM_COLOR;
1902 pItem->maColor = rColor;
1903 pItem->maText = rText;
1904 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1906 mbFormat = TRUE;
1907 if ( IsReallyVisible() && IsUpdateMode() )
1908 Invalidate();
1911 // -----------------------------------------------------------------------
1913 void ValueSet::InsertItem( USHORT nItemId, USHORT nPos )
1915 DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1916 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1917 "ValueSet::InsertItem(): ItemId already exists" );
1919 ValueSetItem* pItem = new ValueSetItem( *this );
1920 pItem->mnId = nItemId;
1921 pItem->meType = VALUESETITEM_USERDRAW;
1922 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1924 mbFormat = TRUE;
1925 if ( IsReallyVisible() && IsUpdateMode() )
1926 Invalidate();
1929 // -----------------------------------------------------------------------
1931 void ValueSet::InsertSpace( USHORT nItemId, USHORT nPos )
1933 DBG_ASSERT( nItemId, "ValueSet::InsertSpace(): ItemId == 0" );
1934 DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1935 "ValueSet::InsertSpace(): ItemId already exists" );
1937 ValueSetItem* pItem = new ValueSetItem( *this );
1938 pItem->mnId = nItemId;
1939 pItem->meType = VALUESETITEM_SPACE;
1940 mpImpl->mpItemList->Insert( pItem, (ULONG)nPos );
1942 mbFormat = TRUE;
1943 if ( IsReallyVisible() && IsUpdateMode() )
1944 Invalidate();
1947 // -----------------------------------------------------------------------
1949 void ValueSet::RemoveItem( USHORT nItemId )
1951 USHORT nPos = GetItemPos( nItemId );
1953 if ( nPos == VALUESET_ITEM_NOTFOUND )
1954 return;
1956 delete mpImpl->mpItemList->Remove( nPos );
1958 // Variablen zuruecksetzen
1959 if ( (mnHighItemId == nItemId) || (mnSelItemId == nItemId) )
1961 mnCurCol = 0;
1962 mnOldItemId = 0;
1963 mnHighItemId = 0;
1964 mnSelItemId = 0;
1965 mbNoSelection = TRUE;
1968 mbFormat = TRUE;
1969 if ( IsReallyVisible() && IsUpdateMode() )
1970 Invalidate();
1973 // -----------------------------------------------------------------------
1975 void ValueSet::CopyItems( const ValueSet& rValueSet )
1977 ImplDeleteItems();
1979 ValueSetItem* pItem = rValueSet.mpImpl->mpItemList->First();
1980 while ( pItem )
1982 ValueSetItem* pNewItem = new ValueSetItem( *this );
1984 pNewItem->mnId = pItem->mnId;
1985 pNewItem->mnBits = pItem->mnBits;
1986 pNewItem->meType = pItem->meType;
1987 pNewItem->maImage = pItem->maImage;
1988 pNewItem->maColor = pItem->maColor;
1989 pNewItem->maText = pItem->maText;
1990 pNewItem->mpData = pItem->mpData;
1991 pNewItem->maRect = pItem->maRect;
1992 pNewItem->mpxAcc = NULL;
1994 mpImpl->mpItemList->Insert( pNewItem );
1995 pItem = rValueSet.mpImpl->mpItemList->Next();
1998 // Variablen zuruecksetzen
1999 mnFirstLine = 0;
2000 mnCurCol = 0;
2001 mnOldItemId = 0;
2002 mnHighItemId = 0;
2003 mnSelItemId = 0;
2004 mbNoSelection = TRUE;
2006 mbFormat = TRUE;
2007 if ( IsReallyVisible() && IsUpdateMode() )
2008 Invalidate();
2011 // -----------------------------------------------------------------------
2013 void ValueSet::Clear()
2015 ImplDeleteItems();
2017 // Variablen zuruecksetzen
2018 mnFirstLine = 0;
2019 mnCurCol = 0;
2020 mnOldItemId = 0;
2021 mnHighItemId = 0;
2022 mnSelItemId = 0;
2023 mbNoSelection = TRUE;
2025 mbFormat = TRUE;
2026 if ( IsReallyVisible() && IsUpdateMode() )
2027 Invalidate();
2030 // -----------------------------------------------------------------------
2032 USHORT ValueSet::GetItemCount() const
2034 return (USHORT)mpImpl->mpItemList->Count();
2037 // -----------------------------------------------------------------------
2039 USHORT ValueSet::GetItemPos( USHORT nItemId ) const
2041 ValueSetItem* pItem = mpImpl->mpItemList->First();
2042 while ( pItem )
2044 if ( pItem->mnId == nItemId )
2045 return (USHORT)mpImpl->mpItemList->GetCurPos();
2046 pItem = mpImpl->mpItemList->Next();
2049 return VALUESET_ITEM_NOTFOUND;
2052 // -----------------------------------------------------------------------
2054 USHORT ValueSet::GetItemId( USHORT nPos ) const
2056 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2058 if ( pItem )
2059 return pItem->mnId;
2060 else
2061 return 0;
2064 // -----------------------------------------------------------------------
2066 USHORT ValueSet::GetItemId( const Point& rPos ) const
2068 USHORT nItemPos = ImplGetItem( rPos );
2069 if ( nItemPos != VALUESET_ITEM_NOTFOUND )
2070 return GetItemId( nItemPos );
2072 return 0;
2075 // -----------------------------------------------------------------------
2077 Rectangle ValueSet::GetItemRect( USHORT nItemId ) const
2079 USHORT nPos = GetItemPos( nItemId );
2081 if ( nPos != VALUESET_ITEM_NOTFOUND )
2082 return mpImpl->mpItemList->GetObject( nPos )->maRect;
2083 else
2084 return Rectangle();
2087 // -----------------------------------------------------------------------
2089 void ValueSet::EnableFullItemMode( BOOL bFullMode )
2091 mbFullMode = bFullMode;
2094 // -----------------------------------------------------------------------
2096 void ValueSet::SetColCount( USHORT nNewCols )
2098 if ( mnUserCols != nNewCols )
2100 mnUserCols = nNewCols;
2101 mbFormat = TRUE;
2102 if ( IsReallyVisible() && IsUpdateMode() )
2103 Invalidate();
2107 // -----------------------------------------------------------------------
2109 void ValueSet::SetLineCount( USHORT nNewLines )
2111 if ( mnUserVisLines != nNewLines )
2113 mnUserVisLines = nNewLines;
2114 mbFormat = TRUE;
2115 if ( IsReallyVisible() && IsUpdateMode() )
2116 Invalidate();
2120 // -----------------------------------------------------------------------
2122 void ValueSet::SetItemWidth( long nNewItemWidth )
2124 if ( mnUserItemWidth != nNewItemWidth )
2126 mnUserItemWidth = nNewItemWidth;
2127 mbFormat = TRUE;
2128 if ( IsReallyVisible() && IsUpdateMode() )
2129 Invalidate();
2133 // -----------------------------------------------------------------------
2135 void ValueSet::SetItemHeight( long nNewItemHeight )
2137 if ( mnUserItemHeight != nNewItemHeight )
2139 mnUserItemHeight = nNewItemHeight;
2140 mbFormat = TRUE;
2141 if ( IsReallyVisible() && IsUpdateMode() )
2142 Invalidate();
2146 // -----------------------------------------------------------------------
2148 void ValueSet::SetFirstLine( USHORT nNewLine )
2150 if ( mnFirstLine != nNewLine )
2152 mnFirstLine = nNewLine;
2153 mbFormat = TRUE;
2154 if ( IsReallyVisible() && IsUpdateMode() )
2155 Invalidate();
2159 // -----------------------------------------------------------------------
2161 void ValueSet::SelectItem( USHORT nItemId )
2163 USHORT nItemPos = 0;
2165 if ( nItemId )
2167 nItemPos = GetItemPos( nItemId );
2168 if ( nItemPos == VALUESET_ITEM_NOTFOUND )
2169 return;
2170 if ( mpImpl->mpItemList->GetObject( nItemPos )->meType == VALUESETITEM_SPACE )
2171 return;
2174 if ( (mnSelItemId != nItemId) || mbNoSelection )
2176 USHORT nOldItem = mnSelItemId ? mnSelItemId : 1;
2177 mnSelItemId = nItemId;
2178 mbNoSelection = FALSE;
2180 BOOL bNewOut;
2181 BOOL bNewLine;
2182 if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2183 bNewOut = TRUE;
2184 else
2185 bNewOut = FALSE;
2186 bNewLine = FALSE;
2188 // Gegebenenfalls in den sichtbaren Bereich scrollen
2189 if ( mbScroll && nItemId )
2191 USHORT nNewLine = (USHORT)(nItemPos / mnCols);
2192 if ( nNewLine < mnFirstLine )
2194 mnFirstLine = nNewLine;
2195 bNewLine = TRUE;
2197 else if ( nNewLine > (USHORT)(mnFirstLine+mnVisLines-1) )
2199 mnFirstLine = (USHORT)(nNewLine-mnVisLines+1);
2200 bNewLine = TRUE;
2204 if ( bNewOut )
2206 if ( bNewLine )
2208 // Falls sich der sichtbare Bereich geaendert hat,
2209 // alles neu ausgeben
2210 mbFormat = TRUE;
2211 ImplDraw();
2213 else
2215 // alte Selection wegnehmen und neue ausgeben
2216 ImplHideSelect( nOldItem );
2217 ImplDrawSelect();
2221 if( ImplHasAccessibleListeners() )
2223 // focus event (deselect)
2224 if( nOldItem )
2226 const USHORT nPos = GetItemPos( nItemId );
2228 if( nPos != VALUESET_ITEM_NOTFOUND )
2230 ValueItemAcc* pItemAcc = ValueItemAcc::getImplementation(
2231 mpImpl->mpItemList->GetObject( nPos )->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2233 if( pItemAcc )
2235 ::com::sun::star::uno::Any aOldAny, aNewAny;
2236 if( !mpImpl->mbIsTransientChildrenDisabled)
2238 aOldAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
2239 static_cast< ::cppu::OWeakObject* >( pItemAcc ));
2240 ImplFireAccessibleEvent (::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
2242 else
2244 aOldAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
2245 pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
2251 // focus event (select)
2252 const USHORT nPos = GetItemPos( mnSelItemId );
2254 ValueSetItem* pItem;
2255 if( nPos != VALUESET_ITEM_NOTFOUND )
2256 pItem = mpImpl->mpItemList->GetObject(nPos);
2257 else
2258 pItem = mpNoneItem;
2260 ValueItemAcc* pItemAcc = NULL;
2261 if (pItem != NULL)
2262 pItemAcc = ValueItemAcc::getImplementation(pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2264 if( pItemAcc )
2266 ::com::sun::star::uno::Any aOldAny, aNewAny;
2267 if( !mpImpl->mbIsTransientChildrenDisabled)
2269 aNewAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
2270 static_cast< ::cppu::OWeakObject* >( pItemAcc ));
2271 ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
2273 else
2275 aNewAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
2276 pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
2280 // selection event
2281 ::com::sun::star::uno::Any aOldAny, aNewAny;
2282 ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::SELECTION_CHANGED, aOldAny, aNewAny );
2287 // -----------------------------------------------------------------------
2289 void ValueSet::SetNoSelection()
2291 mbNoSelection = TRUE;
2292 mbHighlight = FALSE;
2293 mbSelection = FALSE;
2295 if ( IsReallyVisible() && IsUpdateMode() )
2296 ImplDraw();
2299 // -----------------------------------------------------------------------
2301 void ValueSet::SetItemBits( USHORT nItemId, USHORT nItemBits )
2303 USHORT nPos = GetItemPos( nItemId );
2305 if ( nPos != VALUESET_ITEM_NOTFOUND )
2306 mpImpl->mpItemList->GetObject( nPos )->mnBits = nItemBits;
2309 // -----------------------------------------------------------------------
2311 USHORT ValueSet::GetItemBits( USHORT nItemId ) const
2313 USHORT nPos = GetItemPos( nItemId );
2315 if ( nPos != VALUESET_ITEM_NOTFOUND )
2316 return mpImpl->mpItemList->GetObject( nPos )->mnBits;
2317 else
2318 return 0;
2321 // -----------------------------------------------------------------------
2323 void ValueSet::SetItemImage( USHORT nItemId, const Image& rImage )
2325 USHORT nPos = GetItemPos( nItemId );
2327 if ( nPos == VALUESET_ITEM_NOTFOUND )
2328 return;
2330 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2331 pItem->meType = VALUESETITEM_IMAGE;
2332 pItem->maImage = rImage;
2334 if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2336 ImplFormatItem( pItem );
2337 Invalidate( pItem->maRect );
2339 else
2340 mbFormat = TRUE;
2343 // -----------------------------------------------------------------------
2345 Image ValueSet::GetItemImage( USHORT nItemId ) const
2347 USHORT nPos = GetItemPos( nItemId );
2349 if ( nPos != VALUESET_ITEM_NOTFOUND )
2350 return mpImpl->mpItemList->GetObject( nPos )->maImage;
2351 else
2352 return Image();
2355 // -----------------------------------------------------------------------
2357 void ValueSet::SetItemColor( USHORT nItemId, const Color& rColor )
2359 USHORT nPos = GetItemPos( nItemId );
2361 if ( nPos == VALUESET_ITEM_NOTFOUND )
2362 return;
2364 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2365 pItem->meType = VALUESETITEM_COLOR;
2366 pItem->maColor = rColor;
2368 if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2370 ImplFormatItem( pItem );
2371 Invalidate( pItem->maRect );
2373 else
2374 mbFormat = TRUE;
2377 // -----------------------------------------------------------------------
2379 Color ValueSet::GetItemColor( USHORT nItemId ) const
2381 USHORT nPos = GetItemPos( nItemId );
2383 if ( nPos != VALUESET_ITEM_NOTFOUND )
2384 return mpImpl->mpItemList->GetObject( nPos )->maColor;
2385 else
2386 return Color();
2389 // -----------------------------------------------------------------------
2391 void ValueSet::SetItemData( USHORT nItemId, void* pData )
2393 USHORT nPos = GetItemPos( nItemId );
2395 if ( nPos == VALUESET_ITEM_NOTFOUND )
2396 return;
2398 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2399 pItem->mpData = pData;
2401 if ( pItem->meType == VALUESETITEM_USERDRAW )
2403 if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2405 ImplFormatItem( pItem );
2406 Invalidate( pItem->maRect );
2408 else
2409 mbFormat = TRUE;
2413 // -----------------------------------------------------------------------
2415 void* ValueSet::GetItemData( USHORT nItemId ) const
2417 USHORT nPos = GetItemPos( nItemId );
2419 if ( nPos != VALUESET_ITEM_NOTFOUND )
2420 return mpImpl->mpItemList->GetObject( nPos )->mpData;
2421 else
2422 return NULL;
2425 // -----------------------------------------------------------------------
2427 void ValueSet::SetItemText( USHORT nItemId, const XubString& rText )
2429 USHORT nPos = GetItemPos( nItemId );
2431 if ( nPos == VALUESET_ITEM_NOTFOUND )
2432 return;
2435 ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2437 // Remember old and new name for accessibility event.
2438 ::com::sun::star::uno::Any aOldName, aNewName;
2439 ::rtl::OUString sString (pItem->maText);
2440 aOldName <<= sString;
2441 sString = rText;
2442 aNewName <<= sString;
2444 pItem->maText = rText;
2446 if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2448 USHORT nTempId = mnSelItemId;
2450 if ( mbHighlight )
2451 nTempId = mnHighItemId;
2453 if ( nTempId == nItemId )
2454 ImplDrawItemText( pItem->maText );
2457 if (ImplHasAccessibleListeners())
2459 ::com::sun::star::uno::Reference<
2460 ::com::sun::star::accessibility::XAccessible> xAccessible (
2461 pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2462 static_cast<ValueItemAcc*>(xAccessible.get())->FireAccessibleEvent (
2463 ::com::sun::star::accessibility::AccessibleEventId::NAME_CHANGED,
2464 aOldName, aNewName);
2468 // -----------------------------------------------------------------------
2470 XubString ValueSet::GetItemText( USHORT nItemId ) const
2472 USHORT nPos = GetItemPos( nItemId );
2474 if ( nPos != VALUESET_ITEM_NOTFOUND )
2475 return mpImpl->mpItemList->GetObject( nPos )->maText;
2476 else
2477 return XubString();
2480 // -----------------------------------------------------------------------
2482 void ValueSet::SetColor( const Color& rColor )
2484 maColor = rColor;
2485 mbFormat = TRUE;
2486 if ( IsReallyVisible() && IsUpdateMode() )
2487 ImplDraw();
2490 // -----------------------------------------------------------------------
2492 void ValueSet::SetExtraSpacing( USHORT nNewSpacing )
2494 if ( GetStyle() & WB_ITEMBORDER )
2496 mnSpacing = nNewSpacing;
2498 mbFormat = TRUE;
2499 if ( IsReallyVisible() && IsUpdateMode() )
2500 Invalidate();
2504 // -----------------------------------------------------------------------
2506 void ValueSet::StartSelection()
2508 mnOldItemId = mnSelItemId;
2509 mbHighlight = TRUE;
2510 mbSelection = TRUE;
2511 mnHighItemId = mnSelItemId;
2514 // -----------------------------------------------------------------------
2516 void ValueSet::EndSelection()
2518 if ( mbHighlight )
2520 if ( IsTracking() )
2521 EndTracking( ENDTRACK_CANCEL );
2523 ImplHighlightItem( mnSelItemId );
2524 mbHighlight = FALSE;
2526 mbSelection = FALSE;
2529 // -----------------------------------------------------------------------
2531 BOOL ValueSet::StartDrag( const CommandEvent& rCEvt, Region& rRegion )
2533 if ( rCEvt.GetCommand() != COMMAND_STARTDRAG )
2534 return FALSE;
2536 // Gegebenenfalls eine vorhandene Aktion abbrechen
2537 EndSelection();
2539 // Testen, ob angeklickte Seite selektiert ist. Falls dies nicht
2540 // der Fall ist, setzen wir ihn als aktuellen Eintrag. Falls Drag and
2541 // Drop auch mal ueber Tastatur ausgeloest werden kann, testen wir
2542 // dies nur bei einer Mausaktion.
2543 USHORT nSelId;
2544 if ( rCEvt.IsMouseEvent() )
2545 nSelId = GetItemId( rCEvt.GetMousePosPixel() );
2546 else
2547 nSelId = mnSelItemId;
2549 // Falls kein Eintrag angeklickt wurde, starten wir kein Dragging
2550 if ( !nSelId )
2551 return FALSE;
2553 // Testen, ob Seite selektiertiert ist. Falls nicht, als aktuelle
2554 // Seite setzen und Select rufen.
2555 if ( nSelId != mnSelItemId )
2557 SelectItem( nSelId );
2558 Update();
2559 Select();
2562 Region aRegion;
2564 // Region zuweisen
2565 rRegion = aRegion;
2567 return TRUE;
2570 // -----------------------------------------------------------------------
2572 Size ValueSet::CalcWindowSizePixel( const Size& rItemSize, USHORT nDesireCols,
2573 USHORT nDesireLines )
2575 long nCalcCols = (long)nDesireCols;
2576 long nCalcLines = (long)nDesireLines;
2578 if ( !nCalcCols )
2580 if ( mnUserCols )
2581 nCalcCols = (long)mnUserCols;
2582 else
2583 nCalcCols = 1;
2586 if ( !nCalcLines )
2588 nCalcLines = mnVisLines;
2590 if ( mbFormat )
2592 if ( mnUserVisLines )
2593 nCalcLines = mnUserVisLines;
2594 else
2596 nCalcLines = (long)mpImpl->mpItemList->Count() / nCalcCols;
2597 if ( mpImpl->mpItemList->Count() % nCalcCols )
2598 nCalcLines++;
2599 else if ( !nCalcLines )
2600 nCalcLines = 1;
2605 Size aSize( rItemSize.Width()*nCalcCols, rItemSize.Height()*nCalcLines );
2606 WinBits nStyle = GetStyle();
2607 long nTxtHeight = GetTextHeight();
2608 long nSpace;
2609 long n;
2611 if ( nStyle & WB_ITEMBORDER )
2613 if ( nStyle & WB_DOUBLEBORDER )
2614 n = ITEM_OFFSET_DOUBLE;
2615 else
2616 n = ITEM_OFFSET;
2618 aSize.Width() += n*nCalcCols;
2619 aSize.Height() += n*nCalcLines;
2621 else
2622 n = 0;
2624 if ( mnSpacing )
2626 nSpace = mnSpacing;
2627 aSize.Width() += mnSpacing*(nCalcCols-1);
2628 aSize.Height() += mnSpacing*(nCalcLines-1);
2630 else
2631 nSpace = 0;
2633 if ( nStyle & WB_NAMEFIELD )
2635 aSize.Height() += nTxtHeight + NAME_OFFSET;
2636 if ( !(nStyle & WB_FLATVALUESET) )
2637 aSize.Height() += NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
2640 if ( nStyle & WB_NONEFIELD )
2642 aSize.Height() += nTxtHeight + n + nSpace;
2643 if ( nStyle & WB_RADIOSEL )
2644 aSize.Height() += 8;
2647 // Evt. ScrollBar-Breite aufaddieren
2648 aSize.Width() += GetScrollWidth();
2650 return aSize;
2653 // -----------------------------------------------------------------------
2655 Size ValueSet::CalcItemSizePixel( const Size& rItemSize, BOOL bOut ) const
2657 Size aSize = rItemSize;
2659 WinBits nStyle = GetStyle();
2660 if ( nStyle & WB_ITEMBORDER )
2662 long n;
2664 if ( nStyle & WB_DOUBLEBORDER )
2665 n = ITEM_OFFSET_DOUBLE;
2666 else
2667 n = ITEM_OFFSET;
2669 if ( bOut )
2671 aSize.Width() += n;
2672 aSize.Height() += n;
2674 else
2676 aSize.Width() -= n;
2677 aSize.Height() -= n;
2681 return aSize;
2684 // -----------------------------------------------------------------------
2686 long ValueSet::GetScrollWidth() const
2688 if ( GetStyle() & WB_VSCROLL )
2690 ((ValueSet*)this)->ImplInitScrollBar();
2691 return mpScrBar->GetSizePixel().Width()+SCRBAR_OFFSET;
2693 else
2694 return 0;
2697 // -----------------------------------------------------------------------
2699 USHORT ValueSet::ShowDropPos( const Point& rPos )
2701 mbDropPos = TRUE;
2703 // Gegebenenfalls scrollen
2704 ImplScroll( rPos );
2706 // DropPosition ermitteln
2707 USHORT nPos = ImplGetItem( rPos, TRUE );
2708 if ( nPos == VALUESET_ITEM_NONEITEM )
2709 nPos = 0;
2710 else if ( nPos == VALUESET_ITEM_NOTFOUND )
2712 Size aOutSize = GetOutputSizePixel();
2713 if ( GetStyle() & WB_NAMEFIELD )
2714 aOutSize.Height() = mnTextOffset;
2715 if ( (rPos.X() >= 0) && (rPos.X() < aOutSize.Width()) &&
2716 (rPos.Y() >= 0) && (rPos.Y() < aOutSize.Height()) )
2717 nPos = (USHORT)mpImpl->mpItemList->Count();
2719 else
2721 // Im letzten viertel, dann wird ein Item spaeter eingefuegt
2722 Rectangle aRect = mpImpl->mpItemList->GetObject( nPos )->maRect;
2723 if ( rPos.X() > aRect.Left()+aRect.GetWidth()-(aRect.GetWidth()/4) )
2724 nPos++;
2727 if ( nPos != mnDropPos )
2729 ImplDrawDropPos( FALSE );
2730 mnDropPos = nPos;
2731 ImplDrawDropPos( TRUE );
2734 return mnDropPos;
2737 // -----------------------------------------------------------------------
2739 void ValueSet::HideDropPos()
2741 if ( mbDropPos )
2743 ImplDrawDropPos( FALSE );
2744 mbDropPos = FALSE;
2748 // -----------------------------------------------------------------------
2750 bool ValueSet::IsRTLActive (void)
2752 return Application::GetSettings().GetLayoutRTL() && IsRTLEnabled();