xref: /trunk/main/svtools/source/control/valueset.cxx (revision 69a743679e823ad8f875be547552acb607b8ada5)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 #include <tools/list.hxx>
27 #include <tools/debug.hxx>
28 #include <vcl/decoview.hxx>
29 #include <vcl/svapp.hxx>
30 #ifndef _SCRBAR_HXX
31 #include <vcl/scrbar.hxx>
32 #endif
33 #ifndef _HELP_HXX
34 #include <vcl/help.hxx>
35 #endif
36 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
37 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
38 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <rtl/ustring.hxx>
41 #include "valueimp.hxx"
42 
43 #define _SV_VALUESET_CXX
44 #include <svtools/valueset.hxx>
45 
46 // ------------
47 // - ValueSet -
48 // ------------
49 
50 void ValueSet::ImplInit()
51 {
52     // Size aWinSize        = GetSizePixel();
53     mpImpl              = new ValueSet_Impl;
54     mpNoneItem          = NULL;
55     mpScrBar            = NULL;
56     mnTextOffset        = 0;
57     mnVisLines          = 0;
58     mnLines             = 0;
59     mnUserItemWidth     = 0;
60     mnUserItemHeight    = 0;
61     mnFirstLine         = 0;
62     mnOldItemId         = 0;
63     mnSelItemId         = 0;
64     mnHighItemId        = 0;
65     mnDropPos           = VALUESET_ITEM_NOTFOUND;
66     mnCols              = 0;
67     mnCurCol            = 0;
68     mnUserCols          = 0;
69     mnUserVisLines      = 0;
70     mnSpacing           = 0;
71     mnFrameStyle        = 0;
72     mbFormat            = true;
73     mbHighlight         = false;
74     mbSelection         = false;
75     mbNoSelection       = true;
76     mbDrawSelection     = true;
77     mbBlackSel          = false;
78     mbDoubleSel         = false;
79     mbScroll            = false;
80     mbDropPos           = false;
81     mbFullMode          = true;
82     mbEdgeBlending      = false;
83 
84     // #106446#, #106601# force mirroring of virtual device
85     maVirDev.EnableRTL( GetParent()->IsRTLEnabled() );
86 
87     ImplInitSettings( sal_True, sal_True, sal_True );
88 }
89 
90 // -----------------------------------------------------------------------
91 
92 ValueSet::ValueSet( Window* pParent, WinBits nWinStyle, bool bDisableTransientChildren ) :
93     Control( pParent, nWinStyle ),
94     maVirDev( *this ),
95     maColor( COL_TRANSPARENT )
96 {
97     ImplInit();
98     if( mpImpl )
99         mpImpl->mbIsTransientChildrenDisabled = bDisableTransientChildren;
100 }
101 
102 // -----------------------------------------------------------------------
103 
104 ValueSet::ValueSet( Window* pParent, const ResId& rResId, bool bDisableTransientChildren ) :
105     Control( pParent, rResId ),
106     maVirDev( *this ),
107     maColor( COL_TRANSPARENT )
108 {
109     ImplInit();
110     if( mpImpl )
111         mpImpl->mbIsTransientChildrenDisabled = bDisableTransientChildren;
112 }
113 
114 // -----------------------------------------------------------------------
115 
116 ValueSet::~ValueSet()
117 {
118     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>
119           xComponent (GetAccessible(sal_False), ::com::sun::star::uno::UNO_QUERY);
120     if (xComponent.is())
121         xComponent->dispose ();
122 
123     if ( mpScrBar )
124         delete mpScrBar;
125 
126     if ( mpNoneItem )
127         delete mpNoneItem;
128 
129     ImplDeleteItems();
130     delete mpImpl;
131 }
132 
133 // -----------------------------------------------------------------------
134 
135 void ValueSet::ImplDeleteItems()
136 {
137     for( ValueSetItem* pItem = mpImpl->mpItemList->First(); pItem; pItem = mpImpl->mpItemList->Next() )
138     {
139         if( !pItem->maRect.IsEmpty() && ImplHasAccessibleListeners() )
140         {
141             ::com::sun::star::uno::Any aOldAny, aNewAny;
142 
143             aOldAny <<= pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled );
144             ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
145         }
146 
147         delete pItem;
148     }
149 
150     mpImpl->mpItemList->Clear();
151 }
152 
153 // -----------------------------------------------------------------------
154 
155 void ValueSet::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
156 {
157     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
158 
159     if ( bFont )
160     {
161         Font aFont;
162         aFont = rStyleSettings.GetAppFont();
163         if ( IsControlFont() )
164             aFont.Merge( GetControlFont() );
165         SetZoomedPointFont( aFont );
166     }
167 
168     if ( bForeground || bFont )
169     {
170         Color aColor;
171         if ( IsControlForeground() )
172             aColor = GetControlForeground();
173         else
174             aColor = rStyleSettings.GetButtonTextColor();
175         SetTextColor( aColor );
176         SetTextFillColor();
177     }
178 
179     if ( bBackground )
180     {
181         Color aColor;
182         if ( IsControlBackground() )
183             aColor = GetControlBackground();
184         else if ( GetStyle() & WB_MENUSTYLEVALUESET )
185             aColor = rStyleSettings.GetMenuColor();
186         else if ( IsEnabled() && (GetStyle() & WB_FLATVALUESET) )
187             aColor = rStyleSettings.GetWindowColor();
188         else
189             aColor = rStyleSettings.GetFaceColor();
190         SetBackground( aColor );
191     }
192 }
193 
194 // -----------------------------------------------------------------------
195 
196 void ValueSet::ImplInitScrollBar()
197 {
198     if ( GetStyle() & WB_VSCROLL )
199     {
200         if ( !mpScrBar )
201         {
202             mpScrBar = new ScrollBar( this, WB_VSCROLL | WB_DRAG );
203             mpScrBar->SetScrollHdl( LINK( this, ValueSet, ImplScrollHdl ) );
204         }
205         else
206         {
207             // Wegen Einstellungsaenderungen passen wir hier die Breite an
208             long nScrBarWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
209             mpScrBar->SetPosSizePixel( 0, 0, nScrBarWidth, 0, WINDOW_POSSIZE_WIDTH );
210         }
211     }
212 }
213 
214 // -----------------------------------------------------------------------
215 
216 void ValueSet::ImplFormatItem( ValueSetItem* pItem )
217 {
218     if ( pItem->meType == VALUESETITEM_SPACE )
219         return;
220 
221     Rectangle aRect = pItem->maRect;
222     WinBits nStyle = GetStyle();
223     if ( nStyle & WB_ITEMBORDER )
224     {
225         aRect.Left()++;
226         aRect.Top()++;
227         aRect.Right()--;
228         aRect.Bottom()--;
229         if ( nStyle & WB_FLATVALUESET )
230         {
231             if ( nStyle  & WB_DOUBLEBORDER )
232             {
233                 aRect.Left()    += 2;
234                 aRect.Top()     += 2;
235                 aRect.Right()   -= 2;
236                 aRect.Bottom()  -= 2;
237             }
238             else
239             {
240                 aRect.Left()++;
241                 aRect.Top()++;
242                 aRect.Right()--;
243                 aRect.Bottom()--;
244             }
245         }
246         else
247         {
248             DecorationView aView( &maVirDev );
249             aRect = aView.DrawFrame( aRect, mnFrameStyle );
250         }
251     }
252 
253     if ( pItem == mpNoneItem )
254         pItem->maText = GetText();
255 
256     if ( (aRect.GetHeight() > 0) && (aRect.GetWidth() > 0) )
257     {
258         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
259 
260         if ( pItem == mpNoneItem )
261         {
262             maVirDev.SetFont( GetFont() );
263             maVirDev.SetTextColor( ( nStyle & WB_MENUSTYLEVALUESET ) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor() );
264             maVirDev.SetTextFillColor();
265             maVirDev.SetFillColor( ( nStyle & WB_MENUSTYLEVALUESET ) ? rStyleSettings.GetMenuColor() : rStyleSettings.GetWindowColor() );
266             maVirDev.DrawRect( aRect );
267             Point   aTxtPos( aRect.Left()+2, aRect.Top() );
268             long    nTxtWidth = GetTextWidth( pItem->maText );
269             if ( nStyle & WB_RADIOSEL )
270             {
271                 aTxtPos.X() += 4;
272                 aTxtPos.Y() += 4;
273             }
274             if ( (aTxtPos.X()+nTxtWidth) > aRect.Right() )
275             {
276                 maVirDev.SetClipRegion( Region( aRect ) );
277                 maVirDev.DrawText( aTxtPos, pItem->maText );
278                 maVirDev.SetClipRegion();
279             }
280             else
281                 maVirDev.DrawText( aTxtPos, pItem->maText );
282         }
283         else if ( pItem->meType == VALUESETITEM_COLOR )
284         {
285             maVirDev.SetFillColor( pItem->maColor );
286             maVirDev.DrawRect( aRect );
287         }
288         else
289         {
290             if ( IsColor() )
291                 maVirDev.SetFillColor( maColor );
292             else if ( nStyle & WB_MENUSTYLEVALUESET )
293                 maVirDev.SetFillColor( rStyleSettings.GetMenuColor() );
294             else if ( IsEnabled() )
295                 maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
296             else
297                 maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
298             maVirDev.DrawRect( aRect );
299 
300             if ( pItem->meType == VALUESETITEM_USERDRAW )
301             {
302                 UserDrawEvent aUDEvt( &maVirDev, aRect, pItem->mnId );
303                 UserDraw( aUDEvt );
304             }
305             else
306             {
307                 Size    aImageSize = pItem->maImage.GetSizePixel();
308                 Size    aRectSize = aRect.GetSize();
309                 Point   aPos( aRect.Left(), aRect.Top() );
310                 aPos.X() += (aRectSize.Width()-aImageSize.Width())/2;
311                 aPos.Y() += (aRectSize.Height()-aImageSize.Height())/2;
312 
313                 sal_uInt16  nImageStyle  = 0;
314                 if( !IsEnabled() )
315                     nImageStyle  |= IMAGE_DRAW_DISABLE;
316 
317                 if ( (aImageSize.Width()  > aRectSize.Width()) ||
318                      (aImageSize.Height() > aRectSize.Height()) )
319                 {
320                     maVirDev.SetClipRegion( Region( aRect ) );
321                     maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle);
322                     maVirDev.SetClipRegion();
323                 }
324                 else
325                     maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle );
326             }
327         }
328 
329         const sal_uInt16 nEdgeBlendingPercent(GetEdgeBlending() ? rStyleSettings.GetEdgeBlending() : 0);
330 
331         if(nEdgeBlendingPercent)
332         {
333             const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
334             const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
335             const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
336             const BitmapEx aBlendFrame(createBlendFrame(aRect.GetSize(), nAlpha, rTopLeft, rBottomRight));
337 
338             if(!aBlendFrame.IsEmpty())
339             {
340                 maVirDev.DrawBitmapEx(aRect.TopLeft(), aBlendFrame);
341             }
342         }
343     }
344 }
345 
346 // -----------------------------------------------------------------------
347 
348 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ValueSet::CreateAccessible()
349 {
350     return new ValueSetAcc( this, mpImpl->mbIsTransientChildrenDisabled );
351 }
352 
353 // -----------------------------------------------------------------------
354 
355 void ValueSet::Format()
356 {
357     Size        aWinSize = GetOutputSizePixel();
358     sal_uLong       nItemCount = mpImpl->mpItemList->Count();
359     WinBits     nStyle = GetStyle();
360     long        nTxtHeight = GetTextHeight();
361     long        nOff;
362     long        nSpace;
363     long        nNoneHeight;
364     long        nNoneSpace;
365     ScrollBar*  pDelScrBar = NULL;
366 
367     // Scrolling beruecksichtigen
368     if ( nStyle & WB_VSCROLL )
369         ImplInitScrollBar();
370     else
371     {
372         if ( mpScrBar )
373         {
374             // ScrollBar erst spaeter zerstoeren, damit keine rekursiven
375             // Aufrufe entstehen koennen
376             pDelScrBar = mpScrBar;
377             mpScrBar = NULL;
378         }
379     }
380 
381     // Item-Offset berechnen
382     if ( nStyle & WB_ITEMBORDER )
383     {
384         if ( nStyle & WB_DOUBLEBORDER )
385             nOff = ITEM_OFFSET_DOUBLE;
386         else
387             nOff = ITEM_OFFSET;
388     }
389     else
390         nOff = 0;
391     nSpace = mnSpacing;
392 
393     // Groesse beruecksichtigen, wenn NameField vorhanden
394     if ( nStyle & WB_NAMEFIELD )
395     {
396         mnTextOffset = aWinSize.Height()-nTxtHeight-NAME_OFFSET;
397         aWinSize.Height() -= nTxtHeight+NAME_OFFSET;
398 
399         if ( !(nStyle & WB_FLATVALUESET) )
400         {
401             mnTextOffset -= NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
402             aWinSize.Height() -= NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
403         }
404     }
405     else
406         mnTextOffset = 0;
407 
408     // Offset und Groesse beruecksichtigen, wenn NoneField vorhanden
409     if ( nStyle & WB_NONEFIELD )
410     {
411         nNoneHeight = nTxtHeight+nOff;
412         nNoneSpace = nSpace;
413         if ( nStyle & WB_RADIOSEL )
414             nNoneHeight += 8;
415     }
416     else
417     {
418         nNoneHeight = 0;
419         nNoneSpace = 0;
420 
421         if ( mpNoneItem )
422         {
423             delete mpNoneItem;
424             mpNoneItem = NULL;
425         }
426     }
427 
428     // Breite vom ScrollBar berechnen
429     long nScrBarWidth = 0;
430     if ( mpScrBar )
431         nScrBarWidth = mpScrBar->GetSizePixel().Width()+SCRBAR_OFFSET;
432 
433     // Spaltenanzahl berechnen
434     if ( !mnUserCols )
435     {
436         if ( mnUserItemWidth )
437         {
438             mnCols = (sal_uInt16)((aWinSize.Width()-nScrBarWidth+nSpace) / (mnUserItemWidth+nSpace));
439             if ( !mnCols )
440                 mnCols = 1;
441         }
442         else
443             mnCols = 1;
444     }
445     else
446         mnCols = mnUserCols;
447 
448     // Zeilenanzahl berechnen
449     mbScroll = false;
450     mnLines = (long)mpImpl->mpItemList->Count() / mnCols;
451     if ( mpImpl->mpItemList->Count() % mnCols )
452         mnLines++;
453     else if ( !mnLines )
454         mnLines = 1;
455 
456     long nCalcHeight = aWinSize.Height()-nNoneHeight;
457     if ( mnUserVisLines )
458         mnVisLines = mnUserVisLines;
459     else if ( mnUserItemHeight )
460     {
461         mnVisLines = (nCalcHeight-nNoneSpace+nSpace) / (mnUserItemHeight+nSpace);
462         if ( !mnVisLines )
463             mnVisLines = 1;
464     }
465     else
466         mnVisLines = mnLines;
467     if ( mnLines > mnVisLines )
468         mbScroll = true;
469     if ( mnLines <= mnVisLines )
470         mnFirstLine = 0;
471     else
472     {
473         if ( mnFirstLine > (sal_uInt16)(mnLines-mnVisLines) )
474             mnFirstLine = (sal_uInt16)(mnLines-mnVisLines);
475     }
476 
477     // Itemgroessen berechnen
478     long nColSpace  = (mnCols-1)*nSpace;
479     long nLineSpace = ((mnVisLines-1)*nSpace)+nNoneSpace;
480     long nItemWidth;
481     long nItemHeight;
482     if ( mnUserItemWidth && !mnUserCols )
483     {
484         nItemWidth = mnUserItemWidth;
485         if ( nItemWidth > aWinSize.Width()-nScrBarWidth-nColSpace )
486             nItemWidth = aWinSize.Width()-nScrBarWidth-nColSpace;
487     }
488     else
489         nItemWidth = (aWinSize.Width()-nScrBarWidth-nColSpace) / mnCols;
490     if ( mnUserItemHeight && !mnUserVisLines )
491     {
492         nItemHeight = mnUserItemHeight;
493         if ( nItemHeight > nCalcHeight-nNoneSpace )
494             nItemHeight = nCalcHeight-nNoneSpace;
495     }
496     else
497     {
498         nCalcHeight -= nLineSpace;
499         nItemHeight = nCalcHeight / mnVisLines;
500     }
501 
502     // Init VirDev
503     maVirDev.SetSettings( GetSettings() );
504     maVirDev.SetBackground( GetBackground() );
505     maVirDev.SetOutputSizePixel( aWinSize, sal_True );
506 
507     // Bei zu kleinen Items machen wir nichts
508     long nMinHeight = 2;
509     if ( nStyle & WB_ITEMBORDER )
510         nMinHeight = 4;
511     if ( (nItemWidth <= 0) || (nItemHeight <= nMinHeight) || !nItemCount )
512     {
513         if ( nStyle & WB_NONEFIELD )
514         {
515             if ( mpNoneItem )
516             {
517                 mpNoneItem->maRect.SetEmpty();
518                 mpNoneItem->maText = GetText();
519             }
520         }
521 
522         for ( sal_uLong i = 0; i < nItemCount; i++ )
523         {
524             ValueSetItem* pItem = mpImpl->mpItemList->GetObject( i );
525             pItem->maRect.SetEmpty();
526         }
527 
528         if ( mpScrBar )
529             mpScrBar->Hide();
530     }
531     else
532     {
533         // Frame-Style ermitteln
534         if ( nStyle & WB_DOUBLEBORDER )
535             mnFrameStyle = FRAME_DRAW_DOUBLEIN;
536         else
537             mnFrameStyle = FRAME_DRAW_IN;
538 
539         // Selektionsfarben und -breiten ermitteln
540         // Gegebenenfalls die Farben anpassen, damit man die Selektion besser
541         // erkennen kann
542         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
543         Color aHighColor( rStyleSettings.GetHighlightColor() );
544         if ( ((aHighColor.GetRed() > 0x80) || (aHighColor.GetGreen() > 0x80) ||
545               (aHighColor.GetBlue() > 0x80)) ||
546              ((aHighColor.GetRed() == 0x80) && (aHighColor.GetGreen() == 0x80) &&
547               (aHighColor.GetBlue() == 0x80)) )
548             mbBlackSel = true;
549         else
550             mbBlackSel = false;
551 
552         // Wenn die Items groesser sind, dann die Selektion doppelt so breit
553         // zeichnen
554         if ( (nStyle & WB_DOUBLEBORDER) &&
555              ((nItemWidth >= 25) && (nItemHeight >= 20)) )
556             mbDoubleSel = true;
557         else
558             mbDoubleSel = false;
559 
560         // Calculate offsets
561         long nStartX;
562         long nStartY;
563         if ( mbFullMode )
564         {
565             long nAllItemWidth = (nItemWidth*mnCols)+nColSpace;
566             long nAllItemHeight = (nItemHeight*mnVisLines)+nNoneHeight+nLineSpace;
567             nStartX = (aWinSize.Width()-nScrBarWidth-nAllItemWidth)/2;
568             nStartY = (aWinSize.Height()-nAllItemHeight)/2;
569         }
570         else
571         {
572             nStartX = 0;
573             nStartY = 0;
574         }
575 
576         // Items berechnen und zeichnen
577         maVirDev.SetLineColor();
578         long x = nStartX;
579         long y = nStartY;
580 
581         // NoSelection-Field erzeugen und anzeigen
582         if ( nStyle & WB_NONEFIELD )
583         {
584             if ( !mpNoneItem )
585                 mpNoneItem = new ValueSetItem( *this );
586 
587             mpNoneItem->mnId            = 0;
588             mpNoneItem->meType          = VALUESETITEM_NONE;
589             mpNoneItem->maRect.Left()   = x;
590             mpNoneItem->maRect.Top()    = y;
591             mpNoneItem->maRect.Right()  = mpNoneItem->maRect.Left()+aWinSize.Width()-x-1;
592             mpNoneItem->maRect.Bottom() = y+nNoneHeight-1;
593 
594             ImplFormatItem( mpNoneItem );
595 
596             y += nNoneHeight+nNoneSpace;
597         }
598 
599         // draw items
600         sal_uLong nFirstItem = mnFirstLine * mnCols;
601         sal_uLong nLastItem = nFirstItem + (mnVisLines * mnCols);
602 
603         if ( !mbFullMode )
604         {
605             // If want also draw parts of items in the last line,
606             // then we add one more line if parts of these line are
607             // visible
608             if ( y+(mnVisLines*(nItemHeight+nSpace)) < aWinSize.Height() )
609                 nLastItem += mnCols;
610         }
611         for ( sal_uLong i = 0; i < nItemCount; i++ )
612         {
613             ValueSetItem*   pItem = mpImpl->mpItemList->GetObject( i );
614 
615             if ( (i >= nFirstItem) && (i < nLastItem) )
616             {
617                 const sal_Bool bWasEmpty = pItem->maRect.IsEmpty();
618 
619                 pItem->maRect.Left()    = x;
620                 pItem->maRect.Top()     = y;
621                 pItem->maRect.Right()   = pItem->maRect.Left()+nItemWidth-1;
622                 pItem->maRect.Bottom()  = pItem->maRect.Top()+nItemHeight-1;
623 
624                 if( bWasEmpty && ImplHasAccessibleListeners() )
625                 {
626                     ::com::sun::star::uno::Any aOldAny, aNewAny;
627 
628                     aNewAny <<= pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled );
629                     ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
630                 }
631 
632                 ImplFormatItem( pItem );
633 
634                 if ( !((i+1) % mnCols) )
635                 {
636                     x = nStartX;
637                     y += nItemHeight+nSpace;
638                 }
639                 else
640                     x += nItemWidth+nSpace;
641             }
642             else
643             {
644                 if( !pItem->maRect.IsEmpty() && ImplHasAccessibleListeners() )
645                 {
646                     ::com::sun::star::uno::Any aOldAny, aNewAny;
647 
648                     aOldAny <<= pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled );
649                     ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
650                 }
651 
652                 pItem->maRect.SetEmpty();
653             }
654         }
655 
656         // ScrollBar anordnen, Werte setzen und anzeigen
657         if ( mpScrBar )
658         {
659             Point   aPos( aWinSize.Width()-nScrBarWidth+SCRBAR_OFFSET, 0 );
660             Size    aSize( nScrBarWidth-SCRBAR_OFFSET, aWinSize.Height() );
661             // If a none field is visible, then we center the scrollbar
662             if ( nStyle & WB_NONEFIELD )
663             {
664                 aPos.Y() = nStartY+nNoneHeight+1;
665                 aSize.Height() = ((nItemHeight+nSpace)*mnVisLines)-2-nSpace;
666             }
667             mpScrBar->SetPosSizePixel( aPos, aSize );
668             mpScrBar->SetRangeMax( mnLines );
669             mpScrBar->SetVisibleSize( mnVisLines );
670             mpScrBar->SetThumbPos( (long)mnFirstLine );
671             long nPageSize = mnVisLines;
672             if ( nPageSize < 1 )
673                 nPageSize = 1;
674             mpScrBar->SetPageSize( nPageSize );
675             mpScrBar->Show();
676         }
677     }
678 
679     // Jetzt haben wir formatiert und warten auf das naechste
680     mbFormat = false;
681 
682     // ScrollBar loeschen
683     if ( pDelScrBar )
684         delete pDelScrBar;
685 }
686 
687 // -----------------------------------------------------------------------
688 
689 void ValueSet::ImplDrawItemText( const XubString& rText )
690 {
691     if ( !(GetStyle() & WB_NAMEFIELD) )
692         return;
693 
694     Size    aWinSize = GetOutputSizePixel();
695     long    nTxtWidth = GetTextWidth( rText );
696     long    nTxtOffset = mnTextOffset;
697 
698     // Rechteck loeschen und Text ausgeben
699     if ( GetStyle() & WB_FLATVALUESET )
700     {
701         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
702         SetLineColor();
703         SetFillColor( rStyleSettings.GetFaceColor() );
704         DrawRect( Rectangle( Point( 0, nTxtOffset ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
705         SetTextColor( rStyleSettings.GetButtonTextColor() );
706     }
707     else
708     {
709         nTxtOffset += NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
710         Erase( Rectangle( Point( 0, nTxtOffset ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
711     }
712     DrawText( Point( (aWinSize.Width()-nTxtWidth) / 2, nTxtOffset+(NAME_OFFSET/2) ), rText );
713 }
714 
715 // -----------------------------------------------------------------------
716 
717 void ValueSet::ImplDrawSelect()
718 {
719     if ( !IsReallyVisible() )
720         return;
721 
722     sal_Bool bFocus = HasFocus();
723     sal_Bool bDrawSel;
724 
725     if ( (mbNoSelection && !mbHighlight) || (!mbDrawSelection && mbHighlight) )
726         bDrawSel = sal_False;
727     else
728         bDrawSel = sal_True;
729 
730     if ( !bFocus &&
731          ((mbNoSelection && !mbHighlight) || (!mbDrawSelection && mbHighlight)) )
732     {
733         XubString aEmptyStr;
734         ImplDrawItemText( aEmptyStr );
735         return;
736     }
737 
738     sal_uInt16 nItemId = mnSelItemId;
739 
740     for( int stage = 0; stage < 2; stage++ )
741     {
742         if( stage == 1 )
743         {
744             if ( mbHighlight )
745                 nItemId = mnHighItemId;
746             else
747                 break;
748         }
749 
750         ValueSetItem* pItem;
751         if ( nItemId )
752             pItem = mpImpl->mpItemList->GetObject( GetItemPos( nItemId ) );
753         else
754         {
755             if ( mpNoneItem )
756                 pItem = mpNoneItem;
757             else
758             {
759                 pItem = ImplGetFirstItem();
760                 if ( !bFocus || !pItem )
761                     continue;
762             }
763         }
764 
765         if ( pItem->maRect.IsEmpty() )
766             continue;
767 
768         // Selection malen
769         const StyleSettings&    rStyleSettings = GetSettings().GetStyleSettings();
770         Rectangle               aRect = pItem->maRect;
771         Control::SetFillColor();
772 
773         Color aDoubleColor( rStyleSettings.GetHighlightColor() );
774         Color aSingleColor( rStyleSettings.GetHighlightTextColor() );
775         if( ! mbDoubleSel )
776         {
777             /*
778             *  #99777# contrast enhancement for thin mode
779             */
780             const Wallpaper& rWall = GetDisplayBackground();
781             if( ! rWall.IsBitmap() && ! rWall.IsGradient() )
782             {
783                 const Color& rBack = rWall.GetColor();
784                 if( rBack.IsDark() && ! aDoubleColor.IsBright() )
785                 {
786                     aDoubleColor = Color( COL_WHITE );
787                     aSingleColor = Color( COL_BLACK );
788                 }
789                 else if( rBack.IsBright() && ! aDoubleColor.IsDark() )
790                 {
791                     aDoubleColor = Color( COL_BLACK );
792                     aSingleColor = Color( COL_WHITE );
793                 }
794             }
795         }
796 
797         // Selectionsausgabe festlegen
798         WinBits nStyle = GetStyle();
799         if ( nStyle & WB_MENUSTYLEVALUESET )
800         {
801             if ( bFocus )
802                 ShowFocus( aRect );
803 
804             if ( bDrawSel )
805             {
806                 if ( mbBlackSel )
807                     SetLineColor( Color( COL_BLACK ) );
808                 else
809                     SetLineColor( aDoubleColor );
810                 DrawRect( aRect );
811             }
812         }
813         else if ( nStyle & WB_RADIOSEL )
814         {
815             aRect.Left()    += 3;
816             aRect.Top()     += 3;
817             aRect.Right()   -= 3;
818             aRect.Bottom()  -= 3;
819             if ( nStyle & WB_DOUBLEBORDER )
820             {
821                 aRect.Left()++;
822                 aRect.Top()++;
823                 aRect.Right()--;
824                 aRect.Bottom()--;
825             }
826 
827             if ( bFocus )
828                 ShowFocus( aRect );
829 
830             aRect.Left()++;
831             aRect.Top()++;
832             aRect.Right()--;
833             aRect.Bottom()--;
834 
835             if ( bDrawSel )
836             {
837                 SetLineColor( aDoubleColor );
838                 aRect.Left()++;
839                 aRect.Top()++;
840                 aRect.Right()--;
841                 aRect.Bottom()--;
842                 DrawRect( aRect );
843                 aRect.Left()++;
844                 aRect.Top()++;
845                 aRect.Right()--;
846                 aRect.Bottom()--;
847                 DrawRect( aRect );
848             }
849         }
850         else
851         {
852             if ( bDrawSel )
853             {
854                 if ( mbBlackSel )
855                     SetLineColor( Color( COL_BLACK ) );
856                 else
857                     SetLineColor( aDoubleColor );
858                 DrawRect( aRect );
859             }
860             if ( mbDoubleSel )
861             {
862                 aRect.Left()++;
863                 aRect.Top()++;
864                 aRect.Right()--;
865                 aRect.Bottom()--;
866                 if ( bDrawSel )
867                     DrawRect( aRect );
868             }
869             aRect.Left()++;
870             aRect.Top()++;
871             aRect.Right()--;
872             aRect.Bottom()--;
873             Rectangle aRect2 = aRect;
874             aRect.Left()++;
875             aRect.Top()++;
876             aRect.Right()--;
877             aRect.Bottom()--;
878             if ( bDrawSel )
879                 DrawRect( aRect );
880             if ( mbDoubleSel )
881             {
882                 aRect.Left()++;
883                 aRect.Top()++;
884                 aRect.Right()--;
885                 aRect.Bottom()--;
886                 if ( bDrawSel )
887                     DrawRect( aRect );
888             }
889 
890             if ( bDrawSel )
891             {
892                 if ( mbBlackSel )
893                     SetLineColor( Color( COL_WHITE ) );
894                 else
895                     SetLineColor( aSingleColor );
896             }
897             else
898                 SetLineColor( Color( COL_LIGHTGRAY ) );
899             DrawRect( aRect2 );
900 
901             if ( bFocus )
902                 ShowFocus( aRect2 );
903         }
904 
905         ImplDrawItemText( pItem->maText );
906     }
907 }
908 
909 // -----------------------------------------------------------------------
910 
911 void ValueSet::ImplHideSelect( sal_uInt16 nItemId )
912 {
913     Rectangle aRect;
914 
915     sal_uInt16 nItemPos = GetItemPos( nItemId );
916     if ( nItemPos != sal::static_int_cast<sal_uInt16>(LIST_ENTRY_NOTFOUND) )
917         aRect = mpImpl->mpItemList->GetObject( nItemPos )->maRect;
918     else
919     {
920         if ( mpNoneItem )
921             aRect = mpNoneItem->maRect;
922     }
923 
924     if ( !aRect.IsEmpty() )
925     {
926         HideFocus();
927         Point aPos  = aRect.TopLeft();
928         Size  aSize = aRect.GetSize();
929         DrawOutDev( aPos, aSize, aPos, aSize, maVirDev );
930     }
931 }
932 
933 // -----------------------------------------------------------------------
934 
935 void ValueSet::ImplHighlightItem( sal_uInt16 nItemId, sal_Bool bIsSelection )
936 {
937     if ( mnHighItemId != nItemId )
938     {
939         // Alten merken, um vorherige Selektion zu entfernen
940         sal_uInt16 nOldItem = mnHighItemId;
941         mnHighItemId = nItemId;
942 
943         // Wenn keiner selektiert ist, dann Selektion nicht malen
944         if ( !bIsSelection && mbNoSelection )
945             mbDrawSelection = false;
946 
947         // Neu ausgeben und alte Selection wegnehmen
948         ImplHideSelect( nOldItem );
949         ImplDrawSelect();
950         mbDrawSelection = true;
951     }
952 }
953 
954 // -----------------------------------------------------------------------
955 
956 void ValueSet::ImplDrawDropPos( sal_Bool bShow )
957 {
958     if ( (mnDropPos != VALUESET_ITEM_NOTFOUND) && mpImpl->mpItemList->Count() )
959     {
960         sal_uInt16  nItemPos = mnDropPos;
961         sal_uInt16  nItemId1;
962         sal_uInt16  nItemId2 = 0;
963         sal_Bool    bRight;
964         if ( nItemPos >= mpImpl->mpItemList->Count() )
965         {
966             nItemPos = (sal_uInt16)(mpImpl->mpItemList->Count()-1);
967             bRight = sal_True;
968         }
969         else
970             bRight = sal_False;
971 
972         nItemId1 = GetItemId( nItemPos );
973         if ( (nItemId1 != mnSelItemId) && (nItemId1 != mnHighItemId) )
974             nItemId1 = 0;
975         Rectangle aRect2 = mpImpl->mpItemList->GetObject( nItemPos )->maRect;
976         Rectangle aRect1;
977         if ( bRight )
978         {
979             aRect1 = aRect2;
980             aRect2.SetEmpty();
981         }
982         else if ( nItemPos > 0 )
983         {
984             aRect1 = mpImpl->mpItemList->GetObject( nItemPos-1 )->maRect;
985             nItemId2 = GetItemId( nItemPos-1 );
986             if ( (nItemId2 != mnSelItemId) && (nItemId2 != mnHighItemId) )
987                 nItemId2 = 0;
988         }
989 
990         // Items ueberhaupt sichtbar (nur Erstes/Letztes)
991         if ( !aRect1.IsEmpty() || !aRect2.IsEmpty() )
992         {
993             if ( nItemId1 )
994                 ImplHideSelect( nItemId1 );
995             if ( nItemId2 )
996                 ImplHideSelect( nItemId2 );
997 
998             if ( bShow )
999             {
1000                 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1001                 long    nX;
1002                 long    nY;
1003                 SetLineColor( rStyleSettings.GetButtonTextColor() );
1004                 if ( !aRect1.IsEmpty() )
1005                 {
1006                     Point aPos = aRect1.RightCenter();
1007                     nX = aPos.X()-2;
1008                     nY = aPos.Y();
1009                     for ( sal_uInt16 i = 0; i < 4; i++ )
1010                         DrawLine( Point( nX-i, nY-i ), Point( nX-i, nY+i ) );
1011                 }
1012                 if ( !aRect2.IsEmpty() )
1013                 {
1014                     Point aPos = aRect2.LeftCenter();
1015                     nX = aPos.X()+2;
1016                     nY = aPos.Y();
1017                     for ( sal_uInt16 i = 0; i < 4; i++ )
1018                         DrawLine( Point( nX+i, nY-i ), Point( nX+i, nY+i ) );
1019                 }
1020             }
1021             else
1022             {
1023                 if ( !aRect1.IsEmpty() )
1024                 {
1025                     Point aPos  = aRect1.TopLeft();
1026                     Size  aSize = aRect1.GetSize();
1027                     DrawOutDev( aPos, aSize, aPos, aSize, maVirDev );
1028                 }
1029                 if ( !aRect2.IsEmpty() )
1030                 {
1031                     Point aPos  = aRect2.TopLeft();
1032                     Size  aSize = aRect2.GetSize();
1033                     DrawOutDev( aPos, aSize, aPos, aSize, maVirDev );
1034                 }
1035             }
1036 
1037             if ( nItemId1 || nItemId2 )
1038                 ImplDrawSelect();
1039         }
1040     }
1041 }
1042 
1043 // -----------------------------------------------------------------------
1044 
1045 void ValueSet::ImplDraw()
1046 {
1047     if ( mbFormat )
1048         Format();
1049 
1050     HideFocus();
1051 
1052     Point   aDefPos;
1053     Size    aSize = maVirDev.GetOutputSizePixel();
1054 
1055     if ( mpScrBar && mpScrBar->IsVisible() )
1056     {
1057         Point   aScrPos = mpScrBar->GetPosPixel();
1058         Size    aScrSize = mpScrBar->GetSizePixel();
1059         Point   aTempPos( 0, aScrPos.Y() );
1060         Size    aTempSize( aSize.Width(), aScrPos.Y() );
1061 
1062         DrawOutDev( aDefPos, aTempSize, aDefPos, aTempSize, maVirDev );
1063         aTempSize.Width()   = aScrPos.X()-1;
1064         aTempSize.Height()  = aScrSize.Height();
1065         DrawOutDev( aTempPos, aTempSize, aTempPos, aTempSize, maVirDev );
1066         aTempPos.Y()        = aScrPos.Y()+aScrSize.Height();
1067         aTempSize.Width()   = aSize.Width();
1068         aTempSize.Height()  = aSize.Height()-aTempPos.Y();
1069         DrawOutDev( aTempPos, aTempSize, aTempPos, aTempSize, maVirDev );
1070     }
1071     else
1072         DrawOutDev( aDefPos, aSize, aDefPos, aSize, maVirDev );
1073 
1074     // Trennlinie zum Namefield zeichnen
1075     if ( GetStyle() & WB_NAMEFIELD )
1076     {
1077         if ( !(GetStyle() & WB_FLATVALUESET) )
1078         {
1079             const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1080             Size aWinSize = GetOutputSizePixel();
1081             Point aPos1( NAME_LINE_OFF_X, mnTextOffset+NAME_LINE_OFF_Y );
1082             Point aPos2( aWinSize.Width()-(NAME_LINE_OFF_X*2), mnTextOffset+NAME_LINE_OFF_Y );
1083             if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1084             {
1085                 SetLineColor( rStyleSettings.GetShadowColor() );
1086                 DrawLine( aPos1, aPos2 );
1087                 aPos1.Y()++;
1088                 aPos2.Y()++;
1089                 SetLineColor( rStyleSettings.GetLightColor() );
1090             }
1091             else
1092                 SetLineColor( rStyleSettings.GetWindowTextColor() );
1093             DrawLine( aPos1, aPos2 );
1094         }
1095     }
1096 
1097     ImplDrawSelect();
1098 }
1099 
1100 // -----------------------------------------------------------------------
1101 
1102 sal_Bool ValueSet::ImplScroll( const Point& rPos )
1103 {
1104     Size aOutSize = GetOutputSizePixel();
1105     long nScrBarWidth;
1106 
1107     if ( mpScrBar )
1108         nScrBarWidth = mpScrBar->GetSizePixel().Width();
1109     else
1110         nScrBarWidth = 0;
1111 
1112     if ( !mbScroll || (rPos.X() < 0) || (rPos.X() > aOutSize.Width()-nScrBarWidth) )
1113         return sal_False;
1114 
1115     long             nScrollOffset;
1116     sal_uInt16           nOldLine = mnFirstLine;
1117     const Rectangle& rTopRect = mpImpl->mpItemList->GetObject( mnFirstLine*mnCols )->maRect;
1118     if ( rTopRect.GetHeight() <= 16 )
1119         nScrollOffset = VALUESET_SCROLL_OFFSET/2;
1120     else
1121         nScrollOffset = VALUESET_SCROLL_OFFSET;
1122     if ( (mnFirstLine > 0) && (rPos.Y() >= 0) )
1123     {
1124         long nTopPos = rTopRect.Top();
1125         if ( (rPos.Y() >= nTopPos) && (rPos.Y() <= nTopPos+nScrollOffset) )
1126             mnFirstLine--;
1127     }
1128     if ( (mnFirstLine == nOldLine) &&
1129          (mnFirstLine < (sal_uInt16)(mnLines-mnVisLines)) && (rPos.Y() < aOutSize.Height()) )
1130     {
1131         long nBottomPos = mpImpl->mpItemList->GetObject( (mnFirstLine+mnVisLines-1)*mnCols )->maRect.Bottom();
1132         if ( (rPos.Y() >= nBottomPos-nScrollOffset) && (rPos.Y() <= nBottomPos) )
1133             mnFirstLine++;
1134     }
1135 
1136     if ( mnFirstLine != nOldLine )
1137     {
1138         mbFormat = true;
1139         ImplDraw();
1140         return sal_True;
1141     }
1142     else
1143         return sal_False;
1144 }
1145 
1146 // -----------------------------------------------------------------------
1147 
1148 sal_uInt16 ValueSet::ImplGetItem( const Point& rPos, sal_Bool bMove ) const
1149 {
1150     if ( mpNoneItem )
1151     {
1152         if ( mpNoneItem->maRect.IsInside( rPos ) )
1153             return VALUESET_ITEM_NONEITEM;
1154     }
1155 
1156     Point     aDefPos;
1157     Rectangle aWinRect( aDefPos, maVirDev.GetOutputSizePixel() );
1158 
1159     sal_uLong nItemCount = mpImpl->mpItemList->Count();
1160     for ( sal_uLong i = 0; i < nItemCount; i++ )
1161     {
1162         ValueSetItem* pItem = mpImpl->mpItemList->GetObject( i );
1163         if ( pItem->maRect.IsInside( rPos ) )
1164         {
1165             if ( aWinRect.IsInside( rPos ) )
1166                 return (sal_uInt16)i;
1167             else
1168                 return VALUESET_ITEM_NOTFOUND;
1169         }
1170     }
1171 
1172     // Wenn Spacing gesetzt ist, wird der vorher selektierte
1173     // Eintrag zurueckgegeben, wenn die Maus noch nicht das Fenster
1174     // verlassen hat
1175     if ( bMove && mnSpacing && mnHighItemId )
1176     {
1177         if ( aWinRect.IsInside( rPos ) )
1178             return GetItemPos( mnHighItemId );
1179     }
1180 
1181     return VALUESET_ITEM_NOTFOUND;
1182 }
1183 
1184 // -----------------------------------------------------------------------
1185 
1186 ValueSetItem* ValueSet::ImplGetItem( sal_uInt16 nPos )
1187 {
1188     if ( nPos == VALUESET_ITEM_NONEITEM )
1189         return mpNoneItem;
1190     else
1191         return mpImpl->mpItemList->GetObject( nPos );
1192 }
1193 
1194 // -----------------------------------------------------------------------
1195 
1196 ValueSetItem* ValueSet::ImplGetFirstItem()
1197 {
1198     sal_uInt16 nItemCount = (sal_uInt16)mpImpl->mpItemList->Count();
1199     sal_uInt16 i = 0;
1200 
1201     while ( i < nItemCount )
1202     {
1203         ValueSetItem* pItem = mpImpl->mpItemList->GetObject( i );
1204         if ( pItem->meType != VALUESETITEM_SPACE )
1205             return pItem;
1206         i++;
1207     }
1208 
1209     return NULL;
1210 }
1211 
1212 // -----------------------------------------------------------------------
1213 
1214 sal_uInt16 ValueSet::ImplGetVisibleItemCount() const
1215 {
1216     sal_uInt16 nRet = 0;
1217 
1218     for( sal_Int32 n = 0, nItemCount = mpImpl->mpItemList->Count(); n < nItemCount; n++  )
1219     {
1220         ValueSetItem* pItem = mpImpl->mpItemList->GetObject( n );
1221 
1222         //IAccessible2 implementation - also count empty rectangles as visible...
1223         // if( pItem->meType != VALUESETITEM_SPACE && !pItem->maRect.IsEmpty() )
1224         if( pItem->meType != VALUESETITEM_SPACE )
1225             nRet++;
1226     }
1227 
1228     return nRet;
1229 }
1230 
1231 // -----------------------------------------------------------------------
1232 
1233 ValueSetItem* ValueSet::ImplGetVisibleItem( sal_uInt16 nVisiblePos )
1234 {
1235     ValueSetItem*   pRet = NULL;
1236     sal_uInt16          nFoundPos = 0;
1237 
1238     for( sal_Int32 n = 0, nItemCount = mpImpl->mpItemList->Count(); ( n < nItemCount ) && !pRet; n++  )
1239     {
1240         ValueSetItem* pItem = mpImpl->mpItemList->GetObject( n );
1241 
1242         if( ( pItem->meType != VALUESETITEM_SPACE ) && !pItem->maRect.IsEmpty() && ( nVisiblePos == nFoundPos++ ) )
1243             pRet = pItem;
1244     }
1245 
1246     return pRet;
1247 }
1248 
1249 // -----------------------------------------------------------------------
1250 
1251 void ValueSet::ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue )
1252 {
1253     ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( sal_False ) );
1254 
1255     if( pAcc )
1256         pAcc->FireAccessibleEvent( nEventId, rOldValue, rNewValue );
1257 }
1258 
1259 // -----------------------------------------------------------------------
1260 
1261 sal_Bool ValueSet::ImplHasAccessibleListeners()
1262 {
1263     ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( sal_False ) );
1264     return( pAcc && pAcc->HasAccessibleListeners() );
1265 }
1266 
1267 // -----------------------------------------------------------------------
1268 
1269 IMPL_LINK( ValueSet,ImplScrollHdl, ScrollBar*, pScrollBar )
1270 {
1271     sal_uInt16 nNewFirstLine = (sal_uInt16)pScrollBar->GetThumbPos();
1272     if ( nNewFirstLine != mnFirstLine )
1273     {
1274         mnFirstLine = nNewFirstLine;
1275         mbFormat = true;
1276         ImplDraw();
1277     }
1278     return 0;
1279 }
1280 
1281 // -----------------------------------------------------------------------
1282 
1283 IMPL_LINK( ValueSet,ImplTimerHdl, Timer*, EMPTYARG )
1284 {
1285     ImplTracking( GetPointerPosPixel(), sal_True );
1286     return 0;
1287 }
1288 
1289 // -----------------------------------------------------------------------
1290 
1291 void ValueSet::ImplTracking( const Point& rPos, sal_Bool bRepeat )
1292 {
1293     if ( bRepeat || mbSelection )
1294     {
1295         if ( ImplScroll( rPos ) )
1296         {
1297             if ( mbSelection )
1298             {
1299                 maTimer.SetTimeoutHdl( LINK( this, ValueSet, ImplTimerHdl ) );
1300                 maTimer.SetTimeout( GetSettings().GetMouseSettings().GetScrollRepeat() );
1301                 maTimer.Start();
1302             }
1303         }
1304     }
1305 
1306     ValueSetItem* pItem = ImplGetItem( ImplGetItem( rPos ) );
1307     if ( pItem && (pItem->meType != VALUESETITEM_SPACE) )
1308     {
1309         if( GetStyle() & WB_MENUSTYLEVALUESET )
1310             mbHighlight = true;
1311 
1312         ImplHighlightItem( pItem->mnId );
1313     }
1314     else
1315     {
1316         if( GetStyle() & WB_MENUSTYLEVALUESET )
1317             mbHighlight = true;
1318 
1319         ImplHighlightItem( mnSelItemId, sal_False );
1320     }
1321 }
1322 
1323 // -----------------------------------------------------------------------
1324 
1325 void ValueSet::ImplEndTracking( const Point& rPos, sal_Bool bCancel )
1326 {
1327     ValueSetItem* pItem;
1328 
1329     // Bei Abbruch, den alten Status wieder herstellen
1330     if ( bCancel )
1331         pItem = NULL;
1332     else
1333         pItem = ImplGetItem( ImplGetItem( rPos ) );
1334 
1335     if ( pItem && (pItem->meType != VALUESETITEM_SPACE) )
1336     {
1337         SelectItem( pItem->mnId );
1338         if ( !mbSelection && !(GetStyle() & WB_NOPOINTERFOCUS) )
1339             GrabFocus();
1340         mbHighlight = false;
1341         mbSelection = false;
1342         Select();
1343     }
1344     else
1345     {
1346         ImplHighlightItem( mnSelItemId, sal_False );
1347         mbHighlight = false;
1348         mbSelection = false;
1349     }
1350 }
1351 
1352 // -----------------------------------------------------------------------
1353 
1354 void ValueSet::MouseButtonDown( const MouseEvent& rMEvt )
1355 {
1356     if ( rMEvt.IsLeft() )
1357     {
1358         ValueSetItem* pItem = ImplGetItem( ImplGetItem( rMEvt.GetPosPixel() ) );
1359         if ( mbSelection )
1360         {
1361             mbHighlight = true;
1362             if ( pItem && (pItem->meType != VALUESETITEM_SPACE) )
1363             {
1364                 mnOldItemId  = mnSelItemId;
1365                 mnHighItemId = mnSelItemId;
1366                 ImplHighlightItem( pItem->mnId );
1367             }
1368 
1369             return;
1370         }
1371         else
1372         {
1373             if ( pItem && (pItem->meType != VALUESETITEM_SPACE) && !rMEvt.IsMod2() )
1374             {
1375                 if ( (pItem->mnBits & VIB_NODOUBLECLICK) || (rMEvt.GetClicks() == 1) )
1376                 {
1377                     mnOldItemId  = mnSelItemId;
1378                     mbHighlight  = true;
1379                     mnHighItemId = mnSelItemId;
1380                     ImplHighlightItem( pItem->mnId );
1381                     StartTracking( STARTTRACK_SCROLLREPEAT );
1382                 }
1383                 else if ( rMEvt.GetClicks() == 2 )
1384                     DoubleClick();
1385 
1386                 return;
1387             }
1388         }
1389     }
1390 
1391     Control::MouseButtonDown( rMEvt );
1392 }
1393 
1394 // -----------------------------------------------------------------------
1395 
1396 void ValueSet::MouseButtonUp( const MouseEvent& rMEvt )
1397 {
1398     // Wegen SelectionMode
1399     if ( rMEvt.IsLeft() && mbSelection )
1400         ImplEndTracking( rMEvt.GetPosPixel(), sal_False );
1401     else
1402         Control::MouseButtonUp( rMEvt );
1403 }
1404 
1405 // -----------------------------------------------------------------------
1406 
1407 void ValueSet::MouseMove( const MouseEvent& rMEvt )
1408 {
1409     // Wegen SelectionMode
1410     if ( mbSelection || (GetStyle() & WB_MENUSTYLEVALUESET) )
1411         ImplTracking( rMEvt.GetPosPixel(), sal_False );
1412     Control::MouseMove( rMEvt );
1413 }
1414 
1415 // -----------------------------------------------------------------------
1416 
1417 void ValueSet::Tracking( const TrackingEvent& rTEvt )
1418 {
1419     Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
1420 
1421     if ( rTEvt.IsTrackingEnded() )
1422         ImplEndTracking( aMousePos, rTEvt.IsTrackingCanceled() );
1423     else
1424         ImplTracking( aMousePos, rTEvt.IsTrackingRepeat() );
1425 }
1426 
1427 // -----------------------------------------------------------------------
1428 
1429 void ValueSet::KeyInput( const KeyEvent& rKEvt )
1430 {
1431     sal_uInt16 nLastItem = (sal_uInt16)mpImpl->mpItemList->Count();
1432     sal_uInt16 nItemPos = VALUESET_ITEM_NOTFOUND;
1433     sal_uInt16 nCurPos = VALUESET_ITEM_NONEITEM;
1434     sal_uInt16 nCalcPos;
1435 
1436     if ( !nLastItem || !ImplGetFirstItem() )
1437     {
1438         Control::KeyInput( rKEvt );
1439         return;
1440     }
1441     else
1442         nLastItem--;
1443 
1444     if ( mnSelItemId )
1445         nCurPos = GetItemPos( mnSelItemId );
1446     nCalcPos = nCurPos;
1447 
1448     //switch off selection mode if key travelling is used
1449     sal_Bool bDefault = sal_False;
1450     switch ( rKEvt.GetKeyCode().GetCode() )
1451     {
1452         case KEY_HOME:
1453             if ( mpNoneItem )
1454                 nItemPos = VALUESET_ITEM_NONEITEM;
1455             else
1456             {
1457                 nItemPos = 0;
1458                 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE )
1459                     nItemPos++;
1460             }
1461             break;
1462 
1463         case KEY_END:
1464             nItemPos = nLastItem;
1465             while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE )
1466             {
1467                 if ( nItemPos == 0 )
1468                     nItemPos = VALUESET_ITEM_NONEITEM;
1469                 else
1470                     nItemPos--;
1471             }
1472             break;
1473 
1474         case KEY_LEFT:
1475         case KEY_RIGHT:
1476             if ( rKEvt.GetKeyCode().GetCode()==KEY_LEFT )
1477             {
1478                 do
1479                 {
1480                     if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1481                         nItemPos = nLastItem;
1482                     else if ( !nCalcPos )
1483                     {
1484                         if ( mpNoneItem )
1485                             nItemPos = VALUESET_ITEM_NONEITEM;
1486                         else
1487                             nItemPos = nLastItem;
1488                     }
1489                     else
1490                         nItemPos = nCalcPos-1;
1491                     nCalcPos = nItemPos;
1492                 }
1493                 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1494             }
1495             else
1496             {
1497                 do
1498                 {
1499                     if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1500                         nItemPos = 0;
1501                     else if ( nCalcPos == nLastItem )
1502                     {
1503                         if ( mpNoneItem )
1504                             nItemPos = VALUESET_ITEM_NONEITEM;
1505                         else
1506                             nItemPos = 0;
1507                     }
1508                     else
1509                         nItemPos = nCalcPos+1;
1510                     nCalcPos = nItemPos;
1511                 }
1512                 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1513             }
1514             break;
1515 
1516         case KEY_UP:
1517         case KEY_PAGEUP:
1518         {
1519             if( rKEvt.GetKeyCode().GetCode() != KEY_PAGEUP ||
1520                 ( !rKEvt.GetKeyCode().IsShift() && !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsMod2() ) )
1521             {
1522                 const long nLineCount = ( ( KEY_UP == rKEvt.GetKeyCode().GetCode() ) ? 1 : mnVisLines );
1523                 do
1524                 {
1525                     if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1526                     {
1527                         if ( nLastItem+1 <= mnCols )
1528                             nItemPos = mnCurCol;
1529                         else
1530                         {
1531                             nItemPos = ((((nLastItem+1)/mnCols)-1)*mnCols)+(mnCurCol%mnCols);
1532                             if ( nItemPos+mnCols <= nLastItem )
1533                                 nItemPos = nItemPos + mnCols;
1534                         }
1535                     }
1536                     else if ( nCalcPos >= ( nLineCount * mnCols ) )
1537                         nItemPos = sal::static_int_cast< sal_uInt16 >(
1538                             nCalcPos - ( nLineCount * mnCols ));
1539                     else
1540                     {
1541                         if ( mpNoneItem )
1542                         {
1543                             mnCurCol  = nCalcPos%mnCols;
1544                             nItemPos = VALUESET_ITEM_NONEITEM;
1545                         }
1546                         else
1547                         {
1548                             if ( nLastItem+1 <= mnCols )
1549                                 nItemPos = nCalcPos;
1550                             else
1551                             {
1552                                 nItemPos = ((((nLastItem+1)/mnCols)-1)*mnCols)+(nCalcPos%mnCols);
1553                                 if ( nItemPos+mnCols <= nLastItem )
1554                                     nItemPos = nItemPos + mnCols;
1555                             }
1556                         }
1557                     }
1558                     nCalcPos = nItemPos;
1559                 }
1560                 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1561             }
1562             else
1563                 Control::KeyInput( rKEvt );
1564         }
1565         break;
1566 
1567         case KEY_DOWN:
1568         case KEY_PAGEDOWN:
1569         {
1570             if( rKEvt.GetKeyCode().GetCode() != KEY_PAGEDOWN ||
1571                 ( !rKEvt.GetKeyCode().IsShift() && !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsMod2() ) )
1572             {
1573                 const long nLineCount = ( ( KEY_DOWN == rKEvt.GetKeyCode().GetCode() ) ? 1 : mnVisLines );
1574                 do
1575                 {
1576                     if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1577                         nItemPos = mnCurCol;
1578                     else if ( nCalcPos + ( nLineCount * mnCols ) <= nLastItem )
1579                         nItemPos = sal::static_int_cast< sal_uInt16 >(
1580                             nCalcPos + ( nLineCount * mnCols ));
1581                     else
1582                     {
1583 #if 0
1584                         if( (KEY_DOWN == rKEvt.GetKeyCode().GetCode() ) && (GetStyle() & WB_MENUSTYLEVALUESET) )
1585                         {
1586                             Window* pParent = GetParent();
1587                             pParent->GrabFocus();
1588                             pParent->KeyInput( rKEvt );
1589                             break;
1590                         }
1591                         else
1592 #endif
1593                         {
1594                             if ( mpNoneItem )
1595                             {
1596                                 mnCurCol  = nCalcPos%mnCols;
1597                                 nItemPos = VALUESET_ITEM_NONEITEM;
1598                             }
1599                             else
1600                                 nItemPos = nCalcPos%mnCols;
1601                         }
1602                     }
1603                     nCalcPos = nItemPos;
1604                 }
1605                 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1606             }
1607             else
1608                 Control::KeyInput( rKEvt );
1609 
1610         }
1611         break;
1612         case KEY_RETURN:
1613             //enable default handling of KEY_RETURN in dialogs
1614             if(0 != (GetStyle()&WB_NO_DIRECTSELECT))
1615             {
1616                 Select();
1617                 break;
1618             }
1619             //no break;
1620         default:
1621             Control::KeyInput( rKEvt );
1622             bDefault = sal_True;
1623             break;
1624     }
1625     if(!bDefault)
1626         EndSelection();
1627     if ( nItemPos != VALUESET_ITEM_NOTFOUND )
1628     {
1629         sal_uInt16 nItemId;
1630         if ( nItemPos != VALUESET_ITEM_NONEITEM )
1631             nItemId = GetItemId( nItemPos );
1632         else
1633             nItemId = 0;
1634 
1635         if ( nItemId != mnSelItemId )
1636         {
1637             SelectItem( nItemId );
1638             //select only if WB_NO_DIRECTSELECT is not set
1639             if(0 == (GetStyle()&WB_NO_DIRECTSELECT))
1640                 Select();
1641         }
1642     }
1643 }
1644 
1645 // -----------------------------------------------------------------------
1646 
1647 void ValueSet::Command( const CommandEvent& rCEvt )
1648 {
1649     if ( (rCEvt.GetCommand() == COMMAND_WHEEL) ||
1650          (rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL) ||
1651          (rCEvt.GetCommand() == COMMAND_AUTOSCROLL) )
1652     {
1653         if ( HandleScrollCommand( rCEvt, NULL, mpScrBar ) )
1654             return;
1655     }
1656 
1657     Control::Command( rCEvt );
1658 }
1659 
1660 // -----------------------------------------------------------------------
1661 
1662 void ValueSet::Paint( const Rectangle& )
1663 {
1664     if ( GetStyle() & WB_FLATVALUESET )
1665     {
1666         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1667         SetLineColor();
1668         SetFillColor( rStyleSettings.GetFaceColor() );
1669         long nOffY = maVirDev.GetOutputSizePixel().Height();
1670         Size aWinSize = GetOutputSizePixel();
1671         DrawRect( Rectangle( Point( 0, nOffY ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
1672     }
1673 
1674     ImplDraw();
1675 }
1676 
1677 // -----------------------------------------------------------------------
1678 
1679 void ValueSet::GetFocus()
1680 {
1681     OSL_TRACE ("value set getting focus");
1682     ImplDrawSelect();
1683     Control::GetFocus();
1684 
1685     // Tell the accessible object that we got the focus.
1686     ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( sal_False ) );
1687     if( pAcc )
1688         pAcc->GetFocus();
1689 }
1690 
1691 // -----------------------------------------------------------------------
1692 
1693 void ValueSet::LoseFocus()
1694 {
1695     OSL_TRACE ("value set losing focus");
1696     if ( mbNoSelection && mnSelItemId )
1697         ImplHideSelect( mnSelItemId );
1698     else
1699         HideFocus();
1700     Control::LoseFocus();
1701 
1702     // Tell the accessible object that we lost the focus.
1703     ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( sal_False ) );
1704     if( pAcc )
1705         pAcc->LoseFocus();
1706 }
1707 
1708 // -----------------------------------------------------------------------
1709 
1710 void ValueSet::Resize()
1711 {
1712     mbFormat = true;
1713     if ( IsReallyVisible() && IsUpdateMode() )
1714         Invalidate();
1715     Control::Resize();
1716 }
1717 
1718 // -----------------------------------------------------------------------
1719 
1720 void ValueSet::RequestHelp( const HelpEvent& rHEvt )
1721 {
1722     if ( (rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON)) == HELPMODE_QUICK )
1723     {
1724         Point aPos = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
1725         sal_uInt16 nItemPos = ImplGetItem( aPos );
1726         if ( nItemPos != VALUESET_ITEM_NOTFOUND )
1727         {
1728             ValueSetItem* pItem = ImplGetItem( nItemPos );
1729             Rectangle aItemRect = pItem->maRect;
1730             Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1731             aItemRect.Left()   = aPt.X();
1732             aItemRect.Top()    = aPt.Y();
1733             aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1734             aItemRect.Right()  = aPt.X();
1735             aItemRect.Bottom() = aPt.Y();
1736             Help::ShowQuickHelp( this, aItemRect, GetItemText( pItem->mnId ) );
1737             return;
1738         }
1739     }
1740 
1741     Control::RequestHelp( rHEvt );
1742 }
1743 
1744 // -----------------------------------------------------------------------
1745 
1746 void ValueSet::StateChanged( StateChangedType nType )
1747 {
1748     Control::StateChanged( nType );
1749 
1750     if ( nType == STATE_CHANGE_INITSHOW )
1751     {
1752         if ( mbFormat )
1753             Format();
1754     }
1755     else if ( nType == STATE_CHANGE_UPDATEMODE )
1756     {
1757         if ( IsReallyVisible() && IsUpdateMode() )
1758             Invalidate();
1759     }
1760     else if ( nType == STATE_CHANGE_TEXT )
1761     {
1762         if ( mpNoneItem && !mbFormat && IsReallyVisible() && IsUpdateMode() )
1763         {
1764             ImplFormatItem( mpNoneItem );
1765             Invalidate( mpNoneItem->maRect );
1766         }
1767     }
1768     else if ( (nType == STATE_CHANGE_ZOOM) ||
1769               (nType == STATE_CHANGE_CONTROLFONT) )
1770     {
1771         ImplInitSettings( sal_True, sal_False, sal_False );
1772         Invalidate();
1773     }
1774     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1775     {
1776         ImplInitSettings( sal_False, sal_True, sal_False );
1777         Invalidate();
1778     }
1779     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1780     {
1781         ImplInitSettings( sal_False, sal_False, sal_True );
1782         Invalidate();
1783     }
1784     else if ( (nType == STATE_CHANGE_STYLE) || (nType == STATE_CHANGE_ENABLE) )
1785     {
1786         mbFormat = true;
1787         ImplInitSettings( sal_False, sal_False, sal_True );
1788         Invalidate();
1789     }
1790 }
1791 
1792 // -----------------------------------------------------------------------
1793 
1794 void ValueSet::DataChanged( const DataChangedEvent& rDCEvt )
1795 {
1796     Control::DataChanged( rDCEvt );
1797 
1798     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1799          (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1800          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1801          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1802           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1803     {
1804         mbFormat = true;
1805         ImplInitSettings( sal_True, sal_True, sal_True );
1806         Invalidate();
1807     }
1808 }
1809 
1810 // -----------------------------------------------------------------------
1811 
1812 void ValueSet::Select()
1813 {
1814     maSelectHdl.Call( this );
1815 }
1816 
1817 // -----------------------------------------------------------------------
1818 
1819 void ValueSet::DoubleClick()
1820 {
1821     maDoubleClickHdl.Call( this );
1822 }
1823 
1824 // -----------------------------------------------------------------------
1825 
1826 void ValueSet::UserDraw( const UserDrawEvent& )
1827 {
1828 }
1829 
1830 // -----------------------------------------------------------------------
1831 
1832 void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage, sal_uInt16 nPos )
1833 {
1834     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1835     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1836                 "ValueSet::InsertItem(): ItemId already exists" );
1837 
1838     ValueSetItem* pItem = new ValueSetItem( *this );
1839     pItem->mnId     = nItemId;
1840     pItem->meType   = VALUESETITEM_IMAGE;
1841     pItem->maImage  = rImage;
1842     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1843 
1844     mbFormat = true;
1845     if ( IsReallyVisible() && IsUpdateMode() )
1846         Invalidate();
1847 }
1848 
1849 // -----------------------------------------------------------------------
1850 
1851 void ValueSet::InsertItem( sal_uInt16 nItemId, const Color& rColor, sal_uInt16 nPos )
1852 {
1853     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1854     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1855                 "ValueSet::InsertItem(): ItemId already exists" );
1856 
1857     ValueSetItem* pItem = new ValueSetItem( *this );
1858     pItem->mnId     = nItemId;
1859     pItem->meType   = VALUESETITEM_COLOR;
1860     pItem->maColor  = rColor;
1861     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1862 
1863     mbFormat = true;
1864     if ( IsReallyVisible() && IsUpdateMode() )
1865         Invalidate();
1866 }
1867 
1868 // -----------------------------------------------------------------------
1869 
1870 void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage,
1871                            const XubString& rText, sal_uInt16 nPos )
1872 {
1873     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1874     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1875                 "ValueSet::InsertItem(): ItemId already exists" );
1876 
1877     ValueSetItem* pItem = new ValueSetItem( *this );
1878     pItem->mnId     = nItemId;
1879     pItem->meType   = VALUESETITEM_IMAGE;
1880     pItem->maImage  = rImage;
1881     pItem->maText   = rText;
1882     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1883 
1884     mbFormat = true;
1885     if ( IsReallyVisible() && IsUpdateMode() )
1886         Invalidate();
1887 }
1888 
1889 // -----------------------------------------------------------------------
1890 
1891 void ValueSet::InsertItem( sal_uInt16 nItemId, const Color& rColor,
1892                            const XubString& rText, sal_uInt16 nPos )
1893 {
1894     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1895     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1896                 "ValueSet::InsertItem(): ItemId already exists" );
1897 
1898     ValueSetItem* pItem = new ValueSetItem( *this );
1899     pItem->mnId     = nItemId;
1900     pItem->meType   = VALUESETITEM_COLOR;
1901     pItem->maColor  = rColor;
1902     pItem->maText   = rText;
1903     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1904 
1905     mbFormat = true;
1906     if ( IsReallyVisible() && IsUpdateMode() )
1907         Invalidate();
1908 }
1909 
1910 //IAccessibility2 Implementation 2009-----
1911 //method to set accessible when the style is user draw.
1912 void ValueSet::InsertItem( sal_uInt16 nItemId, const XubString& rText, sal_uInt16 nPos  )
1913 {
1914     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1915     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1916                 "ValueSet::InsertItem(): ItemId already exists" );
1917     ValueSetItem* pItem = new ValueSetItem( *this );
1918     pItem->mnId     = nItemId;
1919     pItem->meType   = VALUESETITEM_USERDRAW;
1920     pItem->maText   = rText;
1921     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1922     mbFormat = sal_True;
1923     if ( IsReallyVisible() && IsUpdateMode() )
1924         Invalidate();
1925 }
1926 //-----IAccessibility2 Implementation 2009
1927 
1928 // -----------------------------------------------------------------------
1929 
1930 void ValueSet::InsertItem( sal_uInt16 nItemId, sal_uInt16 nPos )
1931 {
1932     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1933     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1934                 "ValueSet::InsertItem(): ItemId already exists" );
1935 
1936     ValueSetItem* pItem = new ValueSetItem( *this );
1937     pItem->mnId     = nItemId;
1938     pItem->meType   = VALUESETITEM_USERDRAW;
1939     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1940 
1941     mbFormat = true;
1942     if ( IsReallyVisible() && IsUpdateMode() )
1943         Invalidate();
1944 }
1945 
1946 // -----------------------------------------------------------------------
1947 
1948 void ValueSet::InsertSpace( sal_uInt16 nItemId, sal_uInt16 nPos )
1949 {
1950     DBG_ASSERT( nItemId, "ValueSet::InsertSpace(): ItemId == 0" );
1951     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1952                 "ValueSet::InsertSpace(): ItemId already exists" );
1953 
1954     ValueSetItem* pItem = new ValueSetItem( *this );
1955     pItem->mnId     = nItemId;
1956     pItem->meType   = VALUESETITEM_SPACE;
1957     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1958 
1959     mbFormat = true;
1960     if ( IsReallyVisible() && IsUpdateMode() )
1961         Invalidate();
1962 }
1963 
1964 // -----------------------------------------------------------------------
1965 
1966 void ValueSet::RemoveItem( sal_uInt16 nItemId )
1967 {
1968     sal_uInt16 nPos = GetItemPos( nItemId );
1969 
1970     if ( nPos == VALUESET_ITEM_NOTFOUND )
1971         return;
1972 
1973     delete mpImpl->mpItemList->Remove( nPos );
1974 
1975     // Variablen zuruecksetzen
1976     if ( (mnHighItemId == nItemId) || (mnSelItemId == nItemId) )
1977     {
1978         mnCurCol        = 0;
1979         mnOldItemId     = 0;
1980         mnHighItemId    = 0;
1981         mnSelItemId     = 0;
1982         mbNoSelection   = true;
1983     }
1984 
1985     mbFormat = true;
1986     if ( IsReallyVisible() && IsUpdateMode() )
1987         Invalidate();
1988 }
1989 
1990 // -----------------------------------------------------------------------
1991 
1992 void ValueSet::CopyItems( const ValueSet& rValueSet )
1993 {
1994     ImplDeleteItems();
1995 
1996     ValueSetItem* pItem = rValueSet.mpImpl->mpItemList->First();
1997     while ( pItem )
1998     {
1999         ValueSetItem* pNewItem = new ValueSetItem( *this );
2000 
2001         pNewItem->mnId = pItem->mnId;
2002         pNewItem->mnBits = pItem->mnBits;
2003         pNewItem->meType = pItem->meType;
2004         pNewItem->maImage = pItem->maImage;
2005         pNewItem->maColor = pItem->maColor;
2006         pNewItem->maText = pItem->maText;
2007         pNewItem->mpData = pItem->mpData;
2008         pNewItem->maRect = pItem->maRect;
2009         pNewItem->mpxAcc = NULL;
2010 
2011         mpImpl->mpItemList->Insert( pNewItem );
2012         pItem = rValueSet.mpImpl->mpItemList->Next();
2013     }
2014 
2015     // Variablen zuruecksetzen
2016     mnFirstLine     = 0;
2017     mnCurCol        = 0;
2018     mnOldItemId     = 0;
2019     mnHighItemId    = 0;
2020     mnSelItemId     = 0;
2021     mbNoSelection   = true;
2022 
2023     mbFormat = true;
2024     if ( IsReallyVisible() && IsUpdateMode() )
2025         Invalidate();
2026 }
2027 
2028 // -----------------------------------------------------------------------
2029 
2030 void ValueSet::Clear()
2031 {
2032     ImplDeleteItems();
2033 
2034     // Variablen zuruecksetzen
2035     mnFirstLine     = 0;
2036     mnCurCol        = 0;
2037     mnOldItemId     = 0;
2038     mnHighItemId    = 0;
2039     mnSelItemId     = 0;
2040     mbNoSelection   = true;
2041 
2042     mbFormat = true;
2043     if ( IsReallyVisible() && IsUpdateMode() )
2044         Invalidate();
2045 }
2046 
2047 // -----------------------------------------------------------------------
2048 
2049 sal_uInt16 ValueSet::GetItemCount() const
2050 {
2051     return (sal_uInt16)mpImpl->mpItemList->Count();
2052 }
2053 
2054 // -----------------------------------------------------------------------
2055 
2056 sal_uInt16 ValueSet::GetItemPos( sal_uInt16 nItemId ) const
2057 {
2058     ValueSetItem* pItem = mpImpl->mpItemList->First();
2059     while ( pItem )
2060     {
2061         if ( pItem->mnId == nItemId )
2062             return (sal_uInt16)mpImpl->mpItemList->GetCurPos();
2063         pItem = mpImpl->mpItemList->Next();
2064     }
2065 
2066     return VALUESET_ITEM_NOTFOUND;
2067 }
2068 
2069 // -----------------------------------------------------------------------
2070 
2071 sal_uInt16 ValueSet::GetItemId( sal_uInt16 nPos ) const
2072 {
2073     ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2074 
2075     if ( pItem )
2076         return pItem->mnId;
2077     else
2078         return 0;
2079 }
2080 
2081 // -----------------------------------------------------------------------
2082 
2083 sal_uInt16 ValueSet::GetItemId( const Point& rPos ) const
2084 {
2085     sal_uInt16 nItemPos = ImplGetItem( rPos );
2086     if ( nItemPos != VALUESET_ITEM_NOTFOUND )
2087         return GetItemId( nItemPos );
2088 
2089     return 0;
2090 }
2091 
2092 // -----------------------------------------------------------------------
2093 
2094 Rectangle ValueSet::GetItemRect( sal_uInt16 nItemId ) const
2095 {
2096     sal_uInt16 nPos = GetItemPos( nItemId );
2097 
2098     if ( nPos != VALUESET_ITEM_NOTFOUND )
2099         return mpImpl->mpItemList->GetObject( nPos )->maRect;
2100     else
2101         return Rectangle();
2102 }
2103 
2104 // -----------------------------------------------------------------------
2105 
2106 void ValueSet::EnableFullItemMode( bool bFullMode )
2107 {
2108     mbFullMode = bFullMode;
2109 }
2110 
2111 // -----------------------------------------------------------------------
2112 
2113 void ValueSet::SetColCount( sal_uInt16 nNewCols )
2114 {
2115     if ( mnUserCols != nNewCols )
2116     {
2117         mnUserCols = nNewCols;
2118         mbFormat = true;
2119         if ( IsReallyVisible() && IsUpdateMode() )
2120             Invalidate();
2121     }
2122 }
2123 
2124 // -----------------------------------------------------------------------
2125 
2126 void ValueSet::SetLineCount( sal_uInt16 nNewLines )
2127 {
2128     if ( mnUserVisLines != nNewLines )
2129     {
2130         mnUserVisLines = nNewLines;
2131         mbFormat = true;
2132         if ( IsReallyVisible() && IsUpdateMode() )
2133             Invalidate();
2134     }
2135 }
2136 
2137 // -----------------------------------------------------------------------
2138 
2139 void ValueSet::SetItemWidth( long nNewItemWidth )
2140 {
2141     if ( mnUserItemWidth != nNewItemWidth )
2142     {
2143         mnUserItemWidth = nNewItemWidth;
2144         mbFormat = true;
2145         if ( IsReallyVisible() && IsUpdateMode() )
2146             Invalidate();
2147     }
2148 }
2149 
2150 // -----------------------------------------------------------------------
2151 
2152 void ValueSet::SetItemHeight( long nNewItemHeight )
2153 {
2154     if ( mnUserItemHeight != nNewItemHeight )
2155     {
2156         mnUserItemHeight = nNewItemHeight;
2157         mbFormat = true;
2158         if ( IsReallyVisible() && IsUpdateMode() )
2159             Invalidate();
2160     }
2161 }
2162 
2163 // -----------------------------------------------------------------------
2164 
2165 void ValueSet::SetFirstLine( sal_uInt16 nNewLine )
2166 {
2167     if ( mnFirstLine != nNewLine )
2168     {
2169         mnFirstLine = nNewLine;
2170         mbFormat = true;
2171         if ( IsReallyVisible() && IsUpdateMode() )
2172             Invalidate();
2173     }
2174 }
2175 
2176 // -----------------------------------------------------------------------
2177 
2178 void ValueSet::SelectItem( sal_uInt16 nItemId )
2179 {
2180     sal_uInt16 nItemPos = 0;
2181 
2182     if ( nItemId )
2183     {
2184         nItemPos = GetItemPos( nItemId );
2185         if ( nItemPos == VALUESET_ITEM_NOTFOUND )
2186             return;
2187         if ( mpImpl->mpItemList->GetObject( nItemPos )->meType == VALUESETITEM_SPACE )
2188             return;
2189     }
2190 
2191     if ( (mnSelItemId != nItemId) || mbNoSelection )
2192     {
2193         sal_uInt16 nOldItem = mnSelItemId ? mnSelItemId : 1;
2194         mnSelItemId = nItemId;
2195         mbNoSelection = false;
2196 
2197         sal_Bool bNewOut;
2198         sal_Bool bNewLine;
2199         if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2200             bNewOut = sal_True;
2201         else
2202             bNewOut = sal_False;
2203         bNewLine = sal_False;
2204 
2205         // Gegebenenfalls in den sichtbaren Bereich scrollen
2206         if ( mbScroll && nItemId )
2207         {
2208             sal_uInt16 nNewLine = (sal_uInt16)(nItemPos / mnCols);
2209             if ( nNewLine < mnFirstLine )
2210             {
2211                 mnFirstLine = nNewLine;
2212                 bNewLine = sal_True;
2213             }
2214             else if ( nNewLine > (sal_uInt16)(mnFirstLine+mnVisLines-1) )
2215             {
2216                 mnFirstLine = (sal_uInt16)(nNewLine-mnVisLines+1);
2217                 bNewLine = sal_True;
2218             }
2219         }
2220 
2221         if ( bNewOut )
2222         {
2223             if ( bNewLine )
2224             {
2225                 // Falls sich der sichtbare Bereich geaendert hat,
2226                 // alles neu ausgeben
2227                 mbFormat = true;
2228                 ImplDraw();
2229             }
2230             else
2231             {
2232                 // alte Selection wegnehmen und neue ausgeben
2233                 ImplHideSelect( nOldItem );
2234                 ImplDrawSelect();
2235             }
2236         }
2237 
2238         if( ImplHasAccessibleListeners() )
2239         {
2240             // focus event (deselect)
2241             if( nOldItem )
2242             {
2243                 const sal_uInt16 nPos = GetItemPos( nItemId );
2244 
2245                 if( nPos != VALUESET_ITEM_NOTFOUND )
2246                 {
2247                     ValueItemAcc* pItemAcc = ValueItemAcc::getImplementation(
2248                         mpImpl->mpItemList->GetObject( nPos )->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2249 
2250                     if( pItemAcc )
2251                     {
2252                         ::com::sun::star::uno::Any aOldAny, aNewAny;
2253                         if( !mpImpl->mbIsTransientChildrenDisabled)
2254                         {
2255                             aOldAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
2256                                 static_cast< ::cppu::OWeakObject* >( pItemAcc ));
2257                             ImplFireAccessibleEvent (::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
2258                         }
2259                         else
2260                         {
2261                             aOldAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
2262                             pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
2263                         }
2264                     }
2265                 }
2266             }
2267 
2268             // focus event (select)
2269             const sal_uInt16 nPos = GetItemPos( mnSelItemId );
2270 
2271             ValueSetItem* pItem;
2272             if( nPos != VALUESET_ITEM_NOTFOUND )
2273                 pItem = mpImpl->mpItemList->GetObject(nPos);
2274             else
2275                 pItem = mpNoneItem;
2276 
2277             ValueItemAcc* pItemAcc = NULL;
2278             if (pItem != NULL)
2279                 pItemAcc = ValueItemAcc::getImplementation(pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2280 
2281             if( pItemAcc )
2282             {
2283                 ::com::sun::star::uno::Any aOldAny, aNewAny;
2284                 if( !mpImpl->mbIsTransientChildrenDisabled)
2285                 {
2286                     aNewAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
2287                         static_cast< ::cppu::OWeakObject* >( pItemAcc ));
2288                     ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
2289                 }
2290                 else
2291                 {
2292                     aNewAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
2293                     pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
2294                 }
2295             }
2296 
2297             // selection event
2298             ::com::sun::star::uno::Any aOldAny, aNewAny;
2299             ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::SELECTION_CHANGED, aOldAny, aNewAny );
2300         }
2301         mpImpl->maHighlightHdl.Call(this);
2302     }
2303 }
2304 
2305 // -----------------------------------------------------------------------
2306 
2307 void ValueSet::SetNoSelection()
2308 {
2309     mbNoSelection   = true;
2310     mbHighlight     = false;
2311     mbSelection     = false;
2312 
2313     if ( IsReallyVisible() && IsUpdateMode() )
2314         ImplDraw();
2315 }
2316 
2317 // -----------------------------------------------------------------------
2318 
2319 void ValueSet::SetItemBits( sal_uInt16 nItemId, sal_uInt16 nItemBits )
2320 {
2321     sal_uInt16 nPos = GetItemPos( nItemId );
2322 
2323     if ( nPos != VALUESET_ITEM_NOTFOUND )
2324         mpImpl->mpItemList->GetObject( nPos )->mnBits = nItemBits;
2325 }
2326 
2327 // -----------------------------------------------------------------------
2328 
2329 sal_uInt16 ValueSet::GetItemBits( sal_uInt16 nItemId ) const
2330 {
2331     sal_uInt16 nPos = GetItemPos( nItemId );
2332 
2333     if ( nPos != VALUESET_ITEM_NOTFOUND )
2334         return mpImpl->mpItemList->GetObject( nPos )->mnBits;
2335     else
2336         return 0;
2337 }
2338 
2339 // -----------------------------------------------------------------------
2340 
2341 void ValueSet::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
2342 {
2343     sal_uInt16 nPos = GetItemPos( nItemId );
2344 
2345     if ( nPos == VALUESET_ITEM_NOTFOUND )
2346         return;
2347 
2348     ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2349     pItem->meType  = VALUESETITEM_IMAGE;
2350     pItem->maImage = rImage;
2351 
2352     if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2353     {
2354         ImplFormatItem( pItem );
2355         Invalidate( pItem->maRect );
2356     }
2357     else
2358         mbFormat = true;
2359 }
2360 
2361 // -----------------------------------------------------------------------
2362 
2363 Image ValueSet::GetItemImage( sal_uInt16 nItemId ) const
2364 {
2365     sal_uInt16 nPos = GetItemPos( nItemId );
2366 
2367     if ( nPos != VALUESET_ITEM_NOTFOUND )
2368         return mpImpl->mpItemList->GetObject( nPos )->maImage;
2369     else
2370         return Image();
2371 }
2372 
2373 // -----------------------------------------------------------------------
2374 
2375 void ValueSet::SetItemColor( sal_uInt16 nItemId, const Color& rColor )
2376 {
2377     sal_uInt16 nPos = GetItemPos( nItemId );
2378 
2379     if ( nPos == VALUESET_ITEM_NOTFOUND )
2380         return;
2381 
2382     ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2383     pItem->meType  = VALUESETITEM_COLOR;
2384     pItem->maColor = rColor;
2385 
2386     if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2387     {
2388         ImplFormatItem( pItem );
2389         Invalidate( pItem->maRect );
2390     }
2391     else
2392         mbFormat = true;
2393 }
2394 
2395 // -----------------------------------------------------------------------
2396 
2397 Color ValueSet::GetItemColor( sal_uInt16 nItemId ) const
2398 {
2399     sal_uInt16 nPos = GetItemPos( nItemId );
2400 
2401     if ( nPos != VALUESET_ITEM_NOTFOUND )
2402         return mpImpl->mpItemList->GetObject( nPos )->maColor;
2403     else
2404         return Color();
2405 }
2406 
2407 // -----------------------------------------------------------------------
2408 
2409 void ValueSet::SetItemData( sal_uInt16 nItemId, void* pData )
2410 {
2411     sal_uInt16 nPos = GetItemPos( nItemId );
2412 
2413     if ( nPos == VALUESET_ITEM_NOTFOUND )
2414         return;
2415 
2416     ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2417     pItem->mpData = pData;
2418 
2419     if ( pItem->meType == VALUESETITEM_USERDRAW )
2420     {
2421         if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2422         {
2423             ImplFormatItem( pItem );
2424             Invalidate( pItem->maRect );
2425         }
2426         else
2427             mbFormat = true;
2428     }
2429 }
2430 
2431 // -----------------------------------------------------------------------
2432 
2433 void* ValueSet::GetItemData( sal_uInt16 nItemId ) const
2434 {
2435     sal_uInt16 nPos = GetItemPos( nItemId );
2436 
2437     if ( nPos != VALUESET_ITEM_NOTFOUND )
2438         return mpImpl->mpItemList->GetObject( nPos )->mpData;
2439     else
2440         return NULL;
2441 }
2442 
2443 // -----------------------------------------------------------------------
2444 
2445 void ValueSet::SetItemText( sal_uInt16 nItemId, const XubString& rText )
2446 {
2447     sal_uInt16 nPos = GetItemPos( nItemId );
2448 
2449     if ( nPos == VALUESET_ITEM_NOTFOUND )
2450         return;
2451 
2452 
2453     ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2454 
2455     // Remember old and new name for accessibility event.
2456     ::com::sun::star::uno::Any aOldName, aNewName;
2457     ::rtl::OUString sString (pItem->maText);
2458     aOldName <<= sString;
2459     sString = rText;
2460     aNewName <<= sString;
2461 
2462     pItem->maText = rText;
2463 
2464     if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2465     {
2466         sal_uInt16 nTempId = mnSelItemId;
2467 
2468         if ( mbHighlight )
2469             nTempId = mnHighItemId;
2470 
2471         if ( nTempId == nItemId )
2472             ImplDrawItemText( pItem->maText );
2473     }
2474 
2475     if (ImplHasAccessibleListeners())
2476     {
2477         ::com::sun::star::uno::Reference<
2478               ::com::sun::star::accessibility::XAccessible> xAccessible (
2479                   pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2480         static_cast<ValueItemAcc*>(xAccessible.get())->FireAccessibleEvent (
2481             ::com::sun::star::accessibility::AccessibleEventId::NAME_CHANGED,
2482             aOldName, aNewName);
2483     }
2484 }
2485 
2486 // -----------------------------------------------------------------------
2487 
2488 XubString ValueSet::GetItemText( sal_uInt16 nItemId ) const
2489 {
2490     sal_uInt16 nPos = GetItemPos( nItemId );
2491 
2492     if ( nPos != VALUESET_ITEM_NOTFOUND )
2493         return mpImpl->mpItemList->GetObject( nPos )->maText;
2494     else
2495         return XubString();
2496 }
2497 
2498 // -----------------------------------------------------------------------
2499 
2500 void ValueSet::SetColor( const Color& rColor )
2501 {
2502     maColor     = rColor;
2503     mbFormat    = true;
2504     if ( IsReallyVisible() && IsUpdateMode() )
2505         ImplDraw();
2506 }
2507 
2508 // -----------------------------------------------------------------------
2509 
2510 void ValueSet::SetExtraSpacing( sal_uInt16 nNewSpacing )
2511 {
2512     if ( GetStyle() & WB_ITEMBORDER )
2513     {
2514         mnSpacing = nNewSpacing;
2515 
2516         mbFormat = true;
2517         if ( IsReallyVisible() && IsUpdateMode() )
2518             Invalidate();
2519     }
2520 }
2521 
2522 // -----------------------------------------------------------------------
2523 
2524 void ValueSet::StartSelection()
2525 {
2526     mnOldItemId     = mnSelItemId;
2527     mbHighlight     = true;
2528     mbSelection     = true;
2529     mnHighItemId    = mnSelItemId;
2530 }
2531 
2532 // -----------------------------------------------------------------------
2533 
2534 void ValueSet::EndSelection()
2535 {
2536     if ( mbHighlight )
2537     {
2538         if ( IsTracking() )
2539             EndTracking( ENDTRACK_CANCEL );
2540 
2541         ImplHighlightItem( mnSelItemId );
2542         mbHighlight = false;
2543     }
2544     mbSelection = false;
2545 }
2546 
2547 // -----------------------------------------------------------------------
2548 
2549 sal_Bool ValueSet::StartDrag( const CommandEvent& rCEvt, Region& rRegion )
2550 {
2551     if ( rCEvt.GetCommand() != COMMAND_STARTDRAG )
2552         return sal_False;
2553 
2554     // Gegebenenfalls eine vorhandene Aktion abbrechen
2555     EndSelection();
2556 
2557     // Testen, ob angeklickte Seite selektiert ist. Falls dies nicht
2558     // der Fall ist, setzen wir ihn als aktuellen Eintrag. Falls Drag and
2559     // Drop auch mal ueber Tastatur ausgeloest werden kann, testen wir
2560     // dies nur bei einer Mausaktion.
2561     sal_uInt16 nSelId;
2562     if ( rCEvt.IsMouseEvent() )
2563         nSelId = GetItemId( rCEvt.GetMousePosPixel() );
2564     else
2565         nSelId = mnSelItemId;
2566 
2567     // Falls kein Eintrag angeklickt wurde, starten wir kein Dragging
2568     if ( !nSelId )
2569         return sal_False;
2570 
2571     // Testen, ob Seite selektiertiert ist. Falls nicht, als aktuelle
2572     // Seite setzen und Select rufen.
2573     if ( nSelId != mnSelItemId )
2574     {
2575         SelectItem( nSelId );
2576         Update();
2577         Select();
2578     }
2579 
2580     Region aRegion;
2581 
2582     // Region zuweisen
2583     rRegion = aRegion;
2584 
2585     return sal_True;
2586 }
2587 
2588 // -----------------------------------------------------------------------
2589 
2590 Size ValueSet::CalcWindowSizePixel( const Size& rItemSize, sal_uInt16 nDesireCols,
2591                                     sal_uInt16 nDesireLines )
2592 {
2593     long nCalcCols = (long)nDesireCols;
2594     long nCalcLines = (long)nDesireLines;
2595 
2596     if ( !nCalcCols )
2597     {
2598         if ( mnUserCols )
2599             nCalcCols = (long)mnUserCols;
2600         else
2601             nCalcCols = 1;
2602     }
2603 
2604     if ( !nCalcLines )
2605     {
2606         nCalcLines = mnVisLines;
2607 
2608         if ( mbFormat )
2609         {
2610             if ( mnUserVisLines )
2611                 nCalcLines = mnUserVisLines;
2612             else
2613             {
2614                 nCalcLines = (long)mpImpl->mpItemList->Count() / nCalcCols;
2615                 if ( mpImpl->mpItemList->Count() % nCalcCols )
2616                     nCalcLines++;
2617                 else if ( !nCalcLines )
2618                     nCalcLines = 1;
2619             }
2620         }
2621     }
2622 
2623     Size        aSize( rItemSize.Width()*nCalcCols, rItemSize.Height()*nCalcLines );
2624     WinBits     nStyle = GetStyle();
2625     long        nTxtHeight = GetTextHeight();
2626     long        nSpace;
2627     long        n;
2628 
2629     if ( nStyle & WB_ITEMBORDER )
2630     {
2631         if ( nStyle & WB_DOUBLEBORDER )
2632             n = ITEM_OFFSET_DOUBLE;
2633         else
2634             n = ITEM_OFFSET;
2635 
2636         aSize.Width()  += n*nCalcCols;
2637         aSize.Height() += n*nCalcLines;
2638     }
2639     else
2640         n = 0;
2641 
2642     if ( mnSpacing )
2643     {
2644         nSpace = mnSpacing;
2645         aSize.Width()  += mnSpacing*(nCalcCols-1);
2646         aSize.Height() += mnSpacing*(nCalcLines-1);
2647     }
2648     else
2649         nSpace = 0;
2650 
2651     if ( nStyle & WB_NAMEFIELD )
2652     {
2653         aSize.Height() += nTxtHeight + NAME_OFFSET;
2654         if ( !(nStyle & WB_FLATVALUESET) )
2655             aSize.Height() += NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
2656     }
2657 
2658     if ( nStyle & WB_NONEFIELD )
2659     {
2660         aSize.Height() += nTxtHeight + n + nSpace;
2661         if ( nStyle & WB_RADIOSEL )
2662             aSize.Height() += 8;
2663     }
2664 
2665     // Evt. ScrollBar-Breite aufaddieren
2666     aSize.Width() += GetScrollWidth();
2667 
2668     return aSize;
2669 }
2670 
2671 // -----------------------------------------------------------------------
2672 
2673 Size ValueSet::CalcItemSizePixel( const Size& rItemSize, bool bOut ) const
2674 {
2675     Size aSize = rItemSize;
2676 
2677     WinBits nStyle = GetStyle();
2678     if ( nStyle & WB_ITEMBORDER )
2679     {
2680         long n;
2681 
2682         if ( nStyle & WB_DOUBLEBORDER )
2683             n = ITEM_OFFSET_DOUBLE;
2684         else
2685             n = ITEM_OFFSET;
2686 
2687         if ( bOut )
2688         {
2689             aSize.Width()  += n;
2690             aSize.Height() += n;
2691         }
2692         else
2693         {
2694             aSize.Width()  -= n;
2695             aSize.Height() -= n;
2696         }
2697     }
2698 
2699     return aSize;
2700 }
2701 
2702 // -----------------------------------------------------------------------
2703 
2704 long ValueSet::GetScrollWidth() const
2705 {
2706     if ( GetStyle() & WB_VSCROLL )
2707     {
2708         ((ValueSet*)this)->ImplInitScrollBar();
2709         return mpScrBar->GetSizePixel().Width()+SCRBAR_OFFSET;
2710     }
2711     else
2712         return 0;
2713 }
2714 
2715 // -----------------------------------------------------------------------
2716 
2717 sal_uInt16 ValueSet::ShowDropPos( const Point& rPos )
2718 {
2719     mbDropPos = true;
2720 
2721     // Gegebenenfalls scrollen
2722     ImplScroll( rPos );
2723 
2724     // DropPosition ermitteln
2725     sal_uInt16 nPos = ImplGetItem( rPos, sal_True );
2726     if ( nPos == VALUESET_ITEM_NONEITEM )
2727         nPos = 0;
2728     else if ( nPos == VALUESET_ITEM_NOTFOUND )
2729     {
2730         Size aOutSize = GetOutputSizePixel();
2731         if ( GetStyle() & WB_NAMEFIELD )
2732             aOutSize.Height() = mnTextOffset;
2733         if ( (rPos.X() >= 0) && (rPos.X() < aOutSize.Width()) &&
2734              (rPos.Y() >= 0) && (rPos.Y() < aOutSize.Height()) )
2735             nPos = (sal_uInt16)mpImpl->mpItemList->Count();
2736     }
2737     else
2738     {
2739         // Im letzten viertel, dann wird ein Item spaeter eingefuegt
2740         Rectangle aRect = mpImpl->mpItemList->GetObject( nPos )->maRect;
2741         if ( rPos.X() > aRect.Left()+aRect.GetWidth()-(aRect.GetWidth()/4) )
2742             nPos++;
2743     }
2744 
2745     if ( nPos != mnDropPos )
2746     {
2747         ImplDrawDropPos( sal_False );
2748         mnDropPos = nPos;
2749         ImplDrawDropPos( sal_True );
2750     }
2751 
2752     return mnDropPos;
2753 }
2754 
2755 // -----------------------------------------------------------------------
2756 
2757 void ValueSet::HideDropPos()
2758 {
2759     if ( mbDropPos )
2760     {
2761         ImplDrawDropPos( sal_False );
2762         mbDropPos = false;
2763     }
2764 }
2765 
2766 // -----------------------------------------------------------------------
2767 
2768 bool ValueSet::IsRTLActive (void)
2769 {
2770     return Application::GetSettings().GetLayoutRTL() && IsRTLEnabled();
2771 }
2772 
2773 // -----------------------------------------------------------------------
2774 
2775 void ValueSet::SetHighlightHdl( const Link& rLink )
2776 {
2777     mpImpl->maHighlightHdl = rLink;
2778 }
2779 
2780 // -----------------------------------------------------------------------
2781 
2782 const Link& ValueSet::GetHighlightHdl() const
2783 {
2784     return mpImpl->maHighlightHdl;
2785 }
2786 
2787 // -----------------------------------------------------------------------
2788 
2789 void ValueSet::SetEdgeBlending(bool bNew)
2790 {
2791     if(mbEdgeBlending != bNew)
2792     {
2793         mbEdgeBlending = bNew;
2794         mbFormat = true;
2795 
2796         if(IsReallyVisible() && IsUpdateMode())
2797         {
2798             Invalidate();
2799         }
2800     }
2801 }
2802 //IAccessibility2 Implementation 2009-----
2803 //For sending out the focused event on the first focused item when this valueset is first focused.
2804 // MT: Focus notifications changed in DEV300 meanwhile, so this is not used for now.
2805 // Just keeping it here for reference, in case something in out implementation doesn't work as expected...
2806 /*
2807 void ValueSet::SetFocusedItem(sal_Bool bFocused)
2808 {
2809     if( ImplHasAccessibleListeners() )
2810     {
2811         // selection event
2812         ::com::sun::star::uno::Any aSelOldAny, aSelNewAny;
2813         if ( mnSelItemId >= 0)
2814         {
2815             // focus event (select)
2816             sal_uInt16 nPos = GetItemPos( mnSelItemId );
2817 
2818             ValueSetItem* pItem;
2819             if ((GetStyle() & WB_NONEFIELD) != 0
2820                 && nPos == VALUESET_ITEM_NOTFOUND
2821                 && mnSelItemId == 0)
2822             {
2823                 // When present the first item is the then allways visible none field.
2824                 pItem = ImplGetItem (VALUESET_ITEM_NONEITEM);
2825             }
2826             else
2827             {
2828                 if (nPos == VALUESET_ITEM_NOTFOUND)
2829                     nPos = 0;
2830                 pItem = mpImpl->mpItemList->GetObject(nPos);
2831             }
2832             ValueItemAcc* pItemAcc = NULL;
2833             if (pItem != NULL)
2834                 pItemAcc = ValueItemAcc::getImplementation(pItem->GetAccessible(mpImpl->mbIsTransientChildrenDisabled) );
2835             if( pItemAcc )
2836             {
2837                 if (bFocused)
2838                     aSelNewAny <<= pItem->GetAccessible(mpImpl->mbIsTransientChildrenDisabled);
2839                 else
2840                     aSelOldAny <<= pItem->GetAccessible(mpImpl->mbIsTransientChildrenDisabled);
2841             }
2842             ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aSelOldAny, aSelNewAny );
2843             if (pItemAcc && bFocused)
2844             {
2845                 pItemAcc->FireAccessibleEvent(
2846                     ::com::sun::star::accessibility::AccessibleEventId::SELECTION_CHANGED,
2847                     ::com::sun::star::uno::Any(),::com::sun::star::uno::Any());
2848             }
2849         }
2850     }
2851 }
2852 */
2853 //end
2854 //-----IAccessibility2 Implementation 2009
2855 
2856 
2857 // -----------------------------------------------------------------------
2858 // eof
2859