xref: /AOO41X/main/svtools/source/control/valueset.cxx (revision 3ea0c3d5cfef7203d1d18b0d5fde9ed31f4a4181)
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 
ImplInit()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 
ValueSet(Window * pParent,WinBits nWinStyle,bool bDisableTransientChildren)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 
ValueSet(Window * pParent,const ResId & rResId,bool bDisableTransientChildren)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 
~ValueSet()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 
ImplDeleteItems()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 
ImplInitSettings(sal_Bool bFont,sal_Bool bForeground,sal_Bool bBackground)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 
ImplInitScrollBar()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 
ImplFormatItem(ValueSetItem * pItem)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 
CreateAccessible()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 
Format()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 
ImplDrawItemText(const XubString & rText)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 
ImplDrawSelect()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 
ImplHideSelect(sal_uInt16 nItemId)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 
ImplHighlightItem(sal_uInt16 nItemId,sal_Bool bIsSelection)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 
ImplDrawDropPos(sal_Bool bShow)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 
ImplDraw()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 
ImplScroll(const Point & rPos)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 
ImplGetItem(const Point & rPos,sal_Bool bMove) const1148 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 
ImplGetItem(sal_uInt16 nPos)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 
ImplGetFirstItem()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 
ImplGetVisibleItemCount() const1214 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 )
1224             nRet++;
1225     }
1226 
1227     return nRet;
1228 }
1229 
1230 // -----------------------------------------------------------------------
1231 
ImplGetVisibleItem(sal_uInt16 nVisiblePos)1232 ValueSetItem* ValueSet::ImplGetVisibleItem( sal_uInt16 nVisiblePos )
1233 {
1234     ValueSetItem*   pRet = NULL;
1235     sal_uInt16          nFoundPos = 0;
1236 
1237     for( sal_Int32 n = 0, nItemCount = mpImpl->mpItemList->Count(); ( n < nItemCount ) && !pRet; n++  )
1238     {
1239         ValueSetItem* pItem = mpImpl->mpItemList->GetObject( n );
1240 
1241         if( ( pItem->meType != VALUESETITEM_SPACE ) && !pItem->maRect.IsEmpty() && ( nVisiblePos == nFoundPos++ ) )
1242             pRet = pItem;
1243     }
1244 
1245     return pRet;
1246 }
1247 
1248 // -----------------------------------------------------------------------
1249 
ImplFireAccessibleEvent(short nEventId,const::com::sun::star::uno::Any & rOldValue,const::com::sun::star::uno::Any & rNewValue)1250 void ValueSet::ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue )
1251 {
1252     ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( sal_False ) );
1253 
1254     if( pAcc )
1255         pAcc->FireAccessibleEvent( nEventId, rOldValue, rNewValue );
1256 }
1257 
1258 // -----------------------------------------------------------------------
1259 
ImplHasAccessibleListeners()1260 sal_Bool ValueSet::ImplHasAccessibleListeners()
1261 {
1262     ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( sal_False ) );
1263     return( pAcc && pAcc->HasAccessibleListeners() );
1264 }
1265 
1266 // -----------------------------------------------------------------------
1267 
IMPL_LINK(ValueSet,ImplScrollHdl,ScrollBar *,pScrollBar)1268 IMPL_LINK( ValueSet,ImplScrollHdl, ScrollBar*, pScrollBar )
1269 {
1270     sal_uInt16 nNewFirstLine = (sal_uInt16)pScrollBar->GetThumbPos();
1271     if ( nNewFirstLine != mnFirstLine )
1272     {
1273         mnFirstLine = nNewFirstLine;
1274         mbFormat = true;
1275         ImplDraw();
1276     }
1277     return 0;
1278 }
1279 
1280 // -----------------------------------------------------------------------
1281 
IMPL_LINK(ValueSet,ImplTimerHdl,Timer *,EMPTYARG)1282 IMPL_LINK( ValueSet,ImplTimerHdl, Timer*, EMPTYARG )
1283 {
1284     ImplTracking( GetPointerPosPixel(), sal_True );
1285     return 0;
1286 }
1287 
1288 // -----------------------------------------------------------------------
1289 
ImplTracking(const Point & rPos,sal_Bool bRepeat)1290 void ValueSet::ImplTracking( const Point& rPos, sal_Bool bRepeat )
1291 {
1292     if ( bRepeat || mbSelection )
1293     {
1294         if ( ImplScroll( rPos ) )
1295         {
1296             if ( mbSelection )
1297             {
1298                 maTimer.SetTimeoutHdl( LINK( this, ValueSet, ImplTimerHdl ) );
1299                 maTimer.SetTimeout( GetSettings().GetMouseSettings().GetScrollRepeat() );
1300                 maTimer.Start();
1301             }
1302         }
1303     }
1304 
1305     ValueSetItem* pItem = ImplGetItem( ImplGetItem( rPos ) );
1306     if ( pItem && (pItem->meType != VALUESETITEM_SPACE) )
1307     {
1308         if( GetStyle() & WB_MENUSTYLEVALUESET )
1309             mbHighlight = true;
1310 
1311         ImplHighlightItem( pItem->mnId );
1312     }
1313     else
1314     {
1315         if( GetStyle() & WB_MENUSTYLEVALUESET )
1316             mbHighlight = true;
1317 
1318         ImplHighlightItem( mnSelItemId, sal_False );
1319     }
1320 }
1321 
1322 // -----------------------------------------------------------------------
1323 
ImplEndTracking(const Point & rPos,sal_Bool bCancel)1324 void ValueSet::ImplEndTracking( const Point& rPos, sal_Bool bCancel )
1325 {
1326     ValueSetItem* pItem;
1327 
1328     // Bei Abbruch, den alten Status wieder herstellen
1329     if ( bCancel )
1330         pItem = NULL;
1331     else
1332         pItem = ImplGetItem( ImplGetItem( rPos ) );
1333 
1334     if ( pItem && (pItem->meType != VALUESETITEM_SPACE) )
1335     {
1336         SelectItem( pItem->mnId );
1337         if ( !mbSelection && !(GetStyle() & WB_NOPOINTERFOCUS) )
1338             GrabFocus();
1339         mbHighlight = false;
1340         mbSelection = false;
1341         Select();
1342     }
1343     else
1344     {
1345         ImplHighlightItem( mnSelItemId, sal_False );
1346         mbHighlight = false;
1347         mbSelection = false;
1348     }
1349 }
1350 
1351 // -----------------------------------------------------------------------
1352 
MouseButtonDown(const MouseEvent & rMEvt)1353 void ValueSet::MouseButtonDown( const MouseEvent& rMEvt )
1354 {
1355     if ( rMEvt.IsLeft() )
1356     {
1357         ValueSetItem* pItem = ImplGetItem( ImplGetItem( rMEvt.GetPosPixel() ) );
1358         if ( mbSelection )
1359         {
1360             mbHighlight = true;
1361             if ( pItem && (pItem->meType != VALUESETITEM_SPACE) )
1362             {
1363                 mnOldItemId  = mnSelItemId;
1364                 mnHighItemId = mnSelItemId;
1365                 ImplHighlightItem( pItem->mnId );
1366             }
1367 
1368             return;
1369         }
1370         else
1371         {
1372             if ( pItem && (pItem->meType != VALUESETITEM_SPACE) && !rMEvt.IsMod2() )
1373             {
1374                 if ( (pItem->mnBits & VIB_NODOUBLECLICK) || (rMEvt.GetClicks() == 1) )
1375                 {
1376                     mnOldItemId  = mnSelItemId;
1377                     mbHighlight  = true;
1378                     mnHighItemId = mnSelItemId;
1379                     ImplHighlightItem( pItem->mnId );
1380                     StartTracking( STARTTRACK_SCROLLREPEAT );
1381                 }
1382                 else if ( rMEvt.GetClicks() == 2 )
1383                     DoubleClick();
1384 
1385                 return;
1386             }
1387         }
1388     }
1389 
1390     Control::MouseButtonDown( rMEvt );
1391 }
1392 
1393 // -----------------------------------------------------------------------
1394 
MouseButtonUp(const MouseEvent & rMEvt)1395 void ValueSet::MouseButtonUp( const MouseEvent& rMEvt )
1396 {
1397     // Wegen SelectionMode
1398     if ( rMEvt.IsLeft() && mbSelection )
1399         ImplEndTracking( rMEvt.GetPosPixel(), sal_False );
1400     else
1401         Control::MouseButtonUp( rMEvt );
1402 }
1403 
1404 // -----------------------------------------------------------------------
1405 
MouseMove(const MouseEvent & rMEvt)1406 void ValueSet::MouseMove( const MouseEvent& rMEvt )
1407 {
1408     // Wegen SelectionMode
1409     if ( mbSelection || (GetStyle() & WB_MENUSTYLEVALUESET) )
1410         ImplTracking( rMEvt.GetPosPixel(), sal_False );
1411     Control::MouseMove( rMEvt );
1412 }
1413 
1414 // -----------------------------------------------------------------------
1415 
Tracking(const TrackingEvent & rTEvt)1416 void ValueSet::Tracking( const TrackingEvent& rTEvt )
1417 {
1418     Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
1419 
1420     if ( rTEvt.IsTrackingEnded() )
1421         ImplEndTracking( aMousePos, rTEvt.IsTrackingCanceled() );
1422     else
1423         ImplTracking( aMousePos, rTEvt.IsTrackingRepeat() );
1424 }
1425 
1426 // -----------------------------------------------------------------------
1427 
KeyInput(const KeyEvent & rKEvt)1428 void ValueSet::KeyInput( const KeyEvent& rKEvt )
1429 {
1430     sal_uInt16 nLastItem = (sal_uInt16)mpImpl->mpItemList->Count();
1431     sal_uInt16 nItemPos = VALUESET_ITEM_NOTFOUND;
1432     sal_uInt16 nCurPos = VALUESET_ITEM_NONEITEM;
1433     sal_uInt16 nCalcPos;
1434 
1435     if ( !nLastItem || !ImplGetFirstItem() )
1436     {
1437         Control::KeyInput( rKEvt );
1438         return;
1439     }
1440     else
1441         nLastItem--;
1442 
1443     if ( mnSelItemId )
1444         nCurPos = GetItemPos( mnSelItemId );
1445     nCalcPos = nCurPos;
1446 
1447     //switch off selection mode if key travelling is used
1448     sal_Bool bDefault = sal_False;
1449     switch ( rKEvt.GetKeyCode().GetCode() )
1450     {
1451         case KEY_HOME:
1452             if ( mpNoneItem )
1453                 nItemPos = VALUESET_ITEM_NONEITEM;
1454             else
1455             {
1456                 nItemPos = 0;
1457                 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE )
1458                     nItemPos++;
1459             }
1460             break;
1461 
1462         case KEY_END:
1463             nItemPos = nLastItem;
1464             while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE )
1465             {
1466                 if ( nItemPos == 0 )
1467                     nItemPos = VALUESET_ITEM_NONEITEM;
1468                 else
1469                     nItemPos--;
1470             }
1471             break;
1472 
1473         case KEY_LEFT:
1474         case KEY_RIGHT:
1475             if ( rKEvt.GetKeyCode().GetCode()==KEY_LEFT )
1476             {
1477                 do
1478                 {
1479                     if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1480                         nItemPos = nLastItem;
1481                     else if ( !nCalcPos )
1482                     {
1483                         if ( mpNoneItem )
1484                             nItemPos = VALUESET_ITEM_NONEITEM;
1485                         else
1486                             nItemPos = nLastItem;
1487                     }
1488                     else
1489                         nItemPos = nCalcPos-1;
1490                     nCalcPos = nItemPos;
1491                 }
1492                 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1493             }
1494             else
1495             {
1496                 do
1497                 {
1498                     if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1499                         nItemPos = 0;
1500                     else if ( nCalcPos == nLastItem )
1501                     {
1502                         if ( mpNoneItem )
1503                             nItemPos = VALUESET_ITEM_NONEITEM;
1504                         else
1505                             nItemPos = 0;
1506                     }
1507                     else
1508                         nItemPos = nCalcPos+1;
1509                     nCalcPos = nItemPos;
1510                 }
1511                 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1512             }
1513             break;
1514 
1515         case KEY_UP:
1516         case KEY_PAGEUP:
1517         {
1518             if( rKEvt.GetKeyCode().GetCode() != KEY_PAGEUP ||
1519                 ( !rKEvt.GetKeyCode().IsShift() && !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsMod2() ) )
1520             {
1521                 const long nLineCount = ( ( KEY_UP == rKEvt.GetKeyCode().GetCode() ) ? 1 : mnVisLines );
1522                 do
1523                 {
1524                     if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1525                     {
1526                         if ( nLastItem+1 <= mnCols )
1527                             nItemPos = mnCurCol;
1528                         else
1529                         {
1530                             nItemPos = ((((nLastItem+1)/mnCols)-1)*mnCols)+(mnCurCol%mnCols);
1531                             if ( nItemPos+mnCols <= nLastItem )
1532                                 nItemPos = nItemPos + mnCols;
1533                         }
1534                     }
1535                     else if ( nCalcPos >= ( nLineCount * mnCols ) )
1536                         nItemPos = sal::static_int_cast< sal_uInt16 >(
1537                             nCalcPos - ( nLineCount * mnCols ));
1538                     else
1539                     {
1540                         if ( mpNoneItem )
1541                         {
1542                             mnCurCol  = nCalcPos%mnCols;
1543                             nItemPos = VALUESET_ITEM_NONEITEM;
1544                         }
1545                         else
1546                         {
1547                             if ( nLastItem+1 <= mnCols )
1548                                 nItemPos = nCalcPos;
1549                             else
1550                             {
1551                                 nItemPos = ((((nLastItem+1)/mnCols)-1)*mnCols)+(nCalcPos%mnCols);
1552                                 if ( nItemPos+mnCols <= nLastItem )
1553                                     nItemPos = nItemPos + mnCols;
1554                             }
1555                         }
1556                     }
1557                     nCalcPos = nItemPos;
1558                 }
1559                 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1560             }
1561             else
1562                 Control::KeyInput( rKEvt );
1563         }
1564         break;
1565 
1566         case KEY_DOWN:
1567         case KEY_PAGEDOWN:
1568         {
1569             if( rKEvt.GetKeyCode().GetCode() != KEY_PAGEDOWN ||
1570                 ( !rKEvt.GetKeyCode().IsShift() && !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsMod2() ) )
1571             {
1572                 const long nLineCount = ( ( KEY_DOWN == rKEvt.GetKeyCode().GetCode() ) ? 1 : mnVisLines );
1573                 do
1574                 {
1575                     if ( nCalcPos == VALUESET_ITEM_NONEITEM )
1576                         nItemPos = mnCurCol;
1577                     else if ( nCalcPos + ( nLineCount * mnCols ) <= nLastItem )
1578                         nItemPos = sal::static_int_cast< sal_uInt16 >(
1579                             nCalcPos + ( nLineCount * mnCols ));
1580                     else
1581                     {
1582 #if 0
1583                         if( (KEY_DOWN == rKEvt.GetKeyCode().GetCode() ) && (GetStyle() & WB_MENUSTYLEVALUESET) )
1584                         {
1585                             Window* pParent = GetParent();
1586                             pParent->GrabFocus();
1587                             pParent->KeyInput( rKEvt );
1588                             break;
1589                         }
1590                         else
1591 #endif
1592                         {
1593                             if ( mpNoneItem )
1594                             {
1595                                 mnCurCol  = nCalcPos%mnCols;
1596                                 nItemPos = VALUESET_ITEM_NONEITEM;
1597                             }
1598                             else
1599                                 nItemPos = nCalcPos%mnCols;
1600                         }
1601                     }
1602                     nCalcPos = nItemPos;
1603                 }
1604                 while ( ImplGetItem( nItemPos )->meType == VALUESETITEM_SPACE );
1605             }
1606             else
1607                 Control::KeyInput( rKEvt );
1608 
1609         }
1610         break;
1611         case KEY_RETURN:
1612             //enable default handling of KEY_RETURN in dialogs
1613             if(0 != (GetStyle()&WB_NO_DIRECTSELECT))
1614             {
1615                 Select();
1616                 break;
1617             }
1618             //no break;
1619         default:
1620             Control::KeyInput( rKEvt );
1621             bDefault = sal_True;
1622             break;
1623     }
1624     if(!bDefault)
1625         EndSelection();
1626     if ( nItemPos != VALUESET_ITEM_NOTFOUND )
1627     {
1628         sal_uInt16 nItemId;
1629         if ( nItemPos != VALUESET_ITEM_NONEITEM )
1630             nItemId = GetItemId( nItemPos );
1631         else
1632             nItemId = 0;
1633 
1634         if ( nItemId != mnSelItemId )
1635         {
1636             SelectItem( nItemId );
1637             //select only if WB_NO_DIRECTSELECT is not set
1638             if(0 == (GetStyle()&WB_NO_DIRECTSELECT))
1639                 Select();
1640         }
1641     }
1642 }
1643 
1644 // -----------------------------------------------------------------------
1645 
Command(const CommandEvent & rCEvt)1646 void ValueSet::Command( const CommandEvent& rCEvt )
1647 {
1648     if ( (rCEvt.GetCommand() == COMMAND_WHEEL) ||
1649          (rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL) ||
1650          (rCEvt.GetCommand() == COMMAND_AUTOSCROLL) )
1651     {
1652         if ( HandleScrollCommand( rCEvt, NULL, mpScrBar ) )
1653             return;
1654     }
1655 
1656     Control::Command( rCEvt );
1657 }
1658 
1659 // -----------------------------------------------------------------------
1660 
Paint(const Rectangle &)1661 void ValueSet::Paint( const Rectangle& )
1662 {
1663     if ( GetStyle() & WB_FLATVALUESET )
1664     {
1665         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1666         SetLineColor();
1667         SetFillColor( rStyleSettings.GetFaceColor() );
1668         long nOffY = maVirDev.GetOutputSizePixel().Height();
1669         Size aWinSize = GetOutputSizePixel();
1670         DrawRect( Rectangle( Point( 0, nOffY ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
1671     }
1672 
1673     ImplDraw();
1674 }
1675 
1676 // -----------------------------------------------------------------------
1677 
GetFocus()1678 void ValueSet::GetFocus()
1679 {
1680     OSL_TRACE ("value set getting focus");
1681     ImplDrawSelect();
1682     Control::GetFocus();
1683 
1684     // Tell the accessible object that we got the focus.
1685     ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( sal_False ) );
1686     if( pAcc )
1687         pAcc->GetFocus();
1688 }
1689 
1690 // -----------------------------------------------------------------------
1691 
LoseFocus()1692 void ValueSet::LoseFocus()
1693 {
1694     OSL_TRACE ("value set losing focus");
1695     if ( mbNoSelection && mnSelItemId )
1696         ImplHideSelect( mnSelItemId );
1697     else
1698         HideFocus();
1699     Control::LoseFocus();
1700 
1701     // Tell the accessible object that we lost the focus.
1702     ValueSetAcc* pAcc = ValueSetAcc::getImplementation( GetAccessible( sal_False ) );
1703     if( pAcc )
1704         pAcc->LoseFocus();
1705 }
1706 
1707 // -----------------------------------------------------------------------
1708 
Resize()1709 void ValueSet::Resize()
1710 {
1711     mbFormat = true;
1712     if ( IsReallyVisible() && IsUpdateMode() )
1713         Invalidate();
1714     Control::Resize();
1715 }
1716 
1717 // -----------------------------------------------------------------------
1718 
RequestHelp(const HelpEvent & rHEvt)1719 void ValueSet::RequestHelp( const HelpEvent& rHEvt )
1720 {
1721     if ( (rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON)) == HELPMODE_QUICK )
1722     {
1723         Point aPos = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
1724         sal_uInt16 nItemPos = ImplGetItem( aPos );
1725         if ( nItemPos != VALUESET_ITEM_NOTFOUND )
1726         {
1727             ValueSetItem* pItem = ImplGetItem( nItemPos );
1728             Rectangle aItemRect = pItem->maRect;
1729             Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1730             aItemRect.Left()   = aPt.X();
1731             aItemRect.Top()    = aPt.Y();
1732             aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1733             aItemRect.Right()  = aPt.X();
1734             aItemRect.Bottom() = aPt.Y();
1735             Help::ShowQuickHelp( this, aItemRect, GetItemText( pItem->mnId ) );
1736             return;
1737         }
1738     }
1739 
1740     Control::RequestHelp( rHEvt );
1741 }
1742 
1743 // -----------------------------------------------------------------------
1744 
StateChanged(StateChangedType nType)1745 void ValueSet::StateChanged( StateChangedType nType )
1746 {
1747     Control::StateChanged( nType );
1748 
1749     if ( nType == STATE_CHANGE_INITSHOW )
1750     {
1751         if ( mbFormat )
1752             Format();
1753     }
1754     else if ( nType == STATE_CHANGE_UPDATEMODE )
1755     {
1756         if ( IsReallyVisible() && IsUpdateMode() )
1757             Invalidate();
1758     }
1759     else if ( nType == STATE_CHANGE_TEXT )
1760     {
1761         if ( mpNoneItem && !mbFormat && IsReallyVisible() && IsUpdateMode() )
1762         {
1763             ImplFormatItem( mpNoneItem );
1764             Invalidate( mpNoneItem->maRect );
1765         }
1766     }
1767     else if ( (nType == STATE_CHANGE_ZOOM) ||
1768               (nType == STATE_CHANGE_CONTROLFONT) )
1769     {
1770         ImplInitSettings( sal_True, sal_False, sal_False );
1771         Invalidate();
1772     }
1773     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1774     {
1775         ImplInitSettings( sal_False, sal_True, sal_False );
1776         Invalidate();
1777     }
1778     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1779     {
1780         ImplInitSettings( sal_False, sal_False, sal_True );
1781         Invalidate();
1782     }
1783     else if ( (nType == STATE_CHANGE_STYLE) || (nType == STATE_CHANGE_ENABLE) )
1784     {
1785         mbFormat = true;
1786         ImplInitSettings( sal_False, sal_False, sal_True );
1787         Invalidate();
1788     }
1789 }
1790 
1791 // -----------------------------------------------------------------------
1792 
DataChanged(const DataChangedEvent & rDCEvt)1793 void ValueSet::DataChanged( const DataChangedEvent& rDCEvt )
1794 {
1795     Control::DataChanged( rDCEvt );
1796 
1797     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1798          (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1799          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1800          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1801           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1802     {
1803         mbFormat = true;
1804         ImplInitSettings( sal_True, sal_True, sal_True );
1805         Invalidate();
1806     }
1807 }
1808 
1809 // -----------------------------------------------------------------------
1810 
Select()1811 void ValueSet::Select()
1812 {
1813     maSelectHdl.Call( this );
1814 }
1815 
1816 // -----------------------------------------------------------------------
1817 
DoubleClick()1818 void ValueSet::DoubleClick()
1819 {
1820     maDoubleClickHdl.Call( this );
1821 }
1822 
1823 // -----------------------------------------------------------------------
1824 
UserDraw(const UserDrawEvent &)1825 void ValueSet::UserDraw( const UserDrawEvent& )
1826 {
1827 }
1828 
1829 // -----------------------------------------------------------------------
1830 
InsertItem(sal_uInt16 nItemId,const Image & rImage,sal_uInt16 nPos)1831 void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage, sal_uInt16 nPos )
1832 {
1833     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1834     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1835                 "ValueSet::InsertItem(): ItemId already exists" );
1836 
1837     ValueSetItem* pItem = new ValueSetItem( *this );
1838     pItem->mnId     = nItemId;
1839     pItem->meType   = VALUESETITEM_IMAGE;
1840     pItem->maImage  = rImage;
1841     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1842 
1843     mbFormat = true;
1844     if ( IsReallyVisible() && IsUpdateMode() )
1845         Invalidate();
1846 }
1847 
1848 // -----------------------------------------------------------------------
1849 
InsertItem(sal_uInt16 nItemId,const Color & rColor,sal_uInt16 nPos)1850 void ValueSet::InsertItem( sal_uInt16 nItemId, const Color& rColor, sal_uInt16 nPos )
1851 {
1852     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1853     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1854                 "ValueSet::InsertItem(): ItemId already exists" );
1855 
1856     ValueSetItem* pItem = new ValueSetItem( *this );
1857     pItem->mnId     = nItemId;
1858     pItem->meType   = VALUESETITEM_COLOR;
1859     pItem->maColor  = rColor;
1860     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1861 
1862     mbFormat = true;
1863     if ( IsReallyVisible() && IsUpdateMode() )
1864         Invalidate();
1865 }
1866 
1867 // -----------------------------------------------------------------------
1868 
InsertItem(sal_uInt16 nItemId,const Image & rImage,const XubString & rText,sal_uInt16 nPos)1869 void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage,
1870                            const XubString& rText, sal_uInt16 nPos )
1871 {
1872     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1873     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1874                 "ValueSet::InsertItem(): ItemId already exists" );
1875 
1876     ValueSetItem* pItem = new ValueSetItem( *this );
1877     pItem->mnId     = nItemId;
1878     pItem->meType   = VALUESETITEM_IMAGE;
1879     pItem->maImage  = rImage;
1880     pItem->maText   = rText;
1881     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1882 
1883     mbFormat = true;
1884     if ( IsReallyVisible() && IsUpdateMode() )
1885         Invalidate();
1886 }
1887 
1888 // -----------------------------------------------------------------------
1889 
InsertItem(sal_uInt16 nItemId,const Color & rColor,const XubString & rText,sal_uInt16 nPos)1890 void ValueSet::InsertItem( sal_uInt16 nItemId, const Color& rColor,
1891                            const XubString& rText, sal_uInt16 nPos )
1892 {
1893     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1894     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1895                 "ValueSet::InsertItem(): ItemId already exists" );
1896 
1897     ValueSetItem* pItem = new ValueSetItem( *this );
1898     pItem->mnId     = nItemId;
1899     pItem->meType   = VALUESETITEM_COLOR;
1900     pItem->maColor  = rColor;
1901     pItem->maText   = rText;
1902     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1903 
1904     mbFormat = true;
1905     if ( IsReallyVisible() && IsUpdateMode() )
1906         Invalidate();
1907 }
1908 
1909 //method to set accessible when the style is user draw.
InsertItem(sal_uInt16 nItemId,const XubString & rText,sal_uInt16 nPos)1910 void ValueSet::InsertItem( sal_uInt16 nItemId, const XubString& rText, sal_uInt16 nPos  )
1911 {
1912     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1913     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1914                 "ValueSet::InsertItem(): ItemId already exists" );
1915     ValueSetItem* pItem = new ValueSetItem( *this );
1916     pItem->mnId     = nItemId;
1917     pItem->meType   = VALUESETITEM_USERDRAW;
1918     pItem->maText   = rText;
1919     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1920     mbFormat = sal_True;
1921     if ( IsReallyVisible() && IsUpdateMode() )
1922         Invalidate();
1923 }
1924 
1925 // -----------------------------------------------------------------------
1926 
InsertItem(sal_uInt16 nItemId,sal_uInt16 nPos)1927 void ValueSet::InsertItem( sal_uInt16 nItemId, sal_uInt16 nPos )
1928 {
1929     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
1930     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1931                 "ValueSet::InsertItem(): ItemId already exists" );
1932 
1933     ValueSetItem* pItem = new ValueSetItem( *this );
1934     pItem->mnId     = nItemId;
1935     pItem->meType   = VALUESETITEM_USERDRAW;
1936     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1937 
1938     mbFormat = true;
1939     if ( IsReallyVisible() && IsUpdateMode() )
1940         Invalidate();
1941 }
1942 
1943 // -----------------------------------------------------------------------
1944 
InsertSpace(sal_uInt16 nItemId,sal_uInt16 nPos)1945 void ValueSet::InsertSpace( sal_uInt16 nItemId, sal_uInt16 nPos )
1946 {
1947     DBG_ASSERT( nItemId, "ValueSet::InsertSpace(): ItemId == 0" );
1948     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
1949                 "ValueSet::InsertSpace(): ItemId already exists" );
1950 
1951     ValueSetItem* pItem = new ValueSetItem( *this );
1952     pItem->mnId     = nItemId;
1953     pItem->meType   = VALUESETITEM_SPACE;
1954     mpImpl->mpItemList->Insert( pItem, (sal_uLong)nPos );
1955 
1956     mbFormat = true;
1957     if ( IsReallyVisible() && IsUpdateMode() )
1958         Invalidate();
1959 }
1960 
1961 // -----------------------------------------------------------------------
1962 
RemoveItem(sal_uInt16 nItemId)1963 void ValueSet::RemoveItem( sal_uInt16 nItemId )
1964 {
1965     sal_uInt16 nPos = GetItemPos( nItemId );
1966 
1967     if ( nPos == VALUESET_ITEM_NOTFOUND )
1968         return;
1969 
1970     delete mpImpl->mpItemList->Remove( nPos );
1971 
1972     // Variablen zuruecksetzen
1973     if ( (mnHighItemId == nItemId) || (mnSelItemId == nItemId) )
1974     {
1975         mnCurCol        = 0;
1976         mnOldItemId     = 0;
1977         mnHighItemId    = 0;
1978         mnSelItemId     = 0;
1979         mbNoSelection   = true;
1980     }
1981 
1982     mbFormat = true;
1983     if ( IsReallyVisible() && IsUpdateMode() )
1984         Invalidate();
1985 }
1986 
1987 // -----------------------------------------------------------------------
1988 
CopyItems(const ValueSet & rValueSet)1989 void ValueSet::CopyItems( const ValueSet& rValueSet )
1990 {
1991     ImplDeleteItems();
1992 
1993     ValueSetItem* pItem = rValueSet.mpImpl->mpItemList->First();
1994     while ( pItem )
1995     {
1996         ValueSetItem* pNewItem = new ValueSetItem( *this );
1997 
1998         pNewItem->mnId = pItem->mnId;
1999         pNewItem->mnBits = pItem->mnBits;
2000         pNewItem->meType = pItem->meType;
2001         pNewItem->maImage = pItem->maImage;
2002         pNewItem->maColor = pItem->maColor;
2003         pNewItem->maText = pItem->maText;
2004         pNewItem->mpData = pItem->mpData;
2005         pNewItem->maRect = pItem->maRect;
2006         pNewItem->mpxAcc = NULL;
2007 
2008         mpImpl->mpItemList->Insert( pNewItem );
2009         pItem = rValueSet.mpImpl->mpItemList->Next();
2010     }
2011 
2012     // Variablen zuruecksetzen
2013     mnFirstLine     = 0;
2014     mnCurCol        = 0;
2015     mnOldItemId     = 0;
2016     mnHighItemId    = 0;
2017     mnSelItemId     = 0;
2018     mbNoSelection   = true;
2019 
2020     mbFormat = true;
2021     if ( IsReallyVisible() && IsUpdateMode() )
2022         Invalidate();
2023 }
2024 
2025 // -----------------------------------------------------------------------
2026 
Clear()2027 void ValueSet::Clear()
2028 {
2029     ImplDeleteItems();
2030 
2031     // Variablen zuruecksetzen
2032     mnFirstLine     = 0;
2033     mnCurCol        = 0;
2034     mnOldItemId     = 0;
2035     mnHighItemId    = 0;
2036     mnSelItemId     = 0;
2037     mbNoSelection   = true;
2038 
2039     mbFormat = true;
2040     if ( IsReallyVisible() && IsUpdateMode() )
2041         Invalidate();
2042 }
2043 
2044 // -----------------------------------------------------------------------
2045 
GetItemCount() const2046 sal_uInt16 ValueSet::GetItemCount() const
2047 {
2048     return (sal_uInt16)mpImpl->mpItemList->Count();
2049 }
2050 
2051 // -----------------------------------------------------------------------
2052 
GetItemPos(sal_uInt16 nItemId) const2053 sal_uInt16 ValueSet::GetItemPos( sal_uInt16 nItemId ) const
2054 {
2055     ValueSetItem* pItem = mpImpl->mpItemList->First();
2056     while ( pItem )
2057     {
2058         if ( pItem->mnId == nItemId )
2059             return (sal_uInt16)mpImpl->mpItemList->GetCurPos();
2060         pItem = mpImpl->mpItemList->Next();
2061     }
2062 
2063     return VALUESET_ITEM_NOTFOUND;
2064 }
2065 
2066 // -----------------------------------------------------------------------
2067 
GetItemId(sal_uInt16 nPos) const2068 sal_uInt16 ValueSet::GetItemId( sal_uInt16 nPos ) const
2069 {
2070     ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2071 
2072     if ( pItem )
2073         return pItem->mnId;
2074     else
2075         return 0;
2076 }
2077 
2078 // -----------------------------------------------------------------------
2079 
GetItemId(const Point & rPos) const2080 sal_uInt16 ValueSet::GetItemId( const Point& rPos ) const
2081 {
2082     sal_uInt16 nItemPos = ImplGetItem( rPos );
2083     if ( nItemPos != VALUESET_ITEM_NOTFOUND )
2084         return GetItemId( nItemPos );
2085 
2086     return 0;
2087 }
2088 
2089 // -----------------------------------------------------------------------
2090 
GetItemRect(sal_uInt16 nItemId) const2091 Rectangle ValueSet::GetItemRect( sal_uInt16 nItemId ) const
2092 {
2093     sal_uInt16 nPos = GetItemPos( nItemId );
2094 
2095     if ( nPos != VALUESET_ITEM_NOTFOUND )
2096         return mpImpl->mpItemList->GetObject( nPos )->maRect;
2097     else
2098         return Rectangle();
2099 }
2100 
2101 // -----------------------------------------------------------------------
2102 
EnableFullItemMode(bool bFullMode)2103 void ValueSet::EnableFullItemMode( bool bFullMode )
2104 {
2105     mbFullMode = bFullMode;
2106 }
2107 
2108 // -----------------------------------------------------------------------
2109 
SetColCount(sal_uInt16 nNewCols)2110 void ValueSet::SetColCount( sal_uInt16 nNewCols )
2111 {
2112     if ( mnUserCols != nNewCols )
2113     {
2114         mnUserCols = nNewCols;
2115         mbFormat = true;
2116         if ( IsReallyVisible() && IsUpdateMode() )
2117             Invalidate();
2118     }
2119 }
2120 
2121 // -----------------------------------------------------------------------
2122 
SetLineCount(sal_uInt16 nNewLines)2123 void ValueSet::SetLineCount( sal_uInt16 nNewLines )
2124 {
2125     if ( mnUserVisLines != nNewLines )
2126     {
2127         mnUserVisLines = nNewLines;
2128         mbFormat = true;
2129         if ( IsReallyVisible() && IsUpdateMode() )
2130             Invalidate();
2131     }
2132 }
2133 
2134 // -----------------------------------------------------------------------
2135 
SetItemWidth(long nNewItemWidth)2136 void ValueSet::SetItemWidth( long nNewItemWidth )
2137 {
2138     if ( mnUserItemWidth != nNewItemWidth )
2139     {
2140         mnUserItemWidth = nNewItemWidth;
2141         mbFormat = true;
2142         if ( IsReallyVisible() && IsUpdateMode() )
2143             Invalidate();
2144     }
2145 }
2146 
2147 // -----------------------------------------------------------------------
2148 
SetItemHeight(long nNewItemHeight)2149 void ValueSet::SetItemHeight( long nNewItemHeight )
2150 {
2151     if ( mnUserItemHeight != nNewItemHeight )
2152     {
2153         mnUserItemHeight = nNewItemHeight;
2154         mbFormat = true;
2155         if ( IsReallyVisible() && IsUpdateMode() )
2156             Invalidate();
2157     }
2158 }
2159 
2160 // -----------------------------------------------------------------------
2161 
SetFirstLine(sal_uInt16 nNewLine)2162 void ValueSet::SetFirstLine( sal_uInt16 nNewLine )
2163 {
2164     if ( mnFirstLine != nNewLine )
2165     {
2166         mnFirstLine = nNewLine;
2167         mbFormat = true;
2168         if ( IsReallyVisible() && IsUpdateMode() )
2169             Invalidate();
2170     }
2171 }
2172 
2173 // -----------------------------------------------------------------------
2174 
SelectItem(sal_uInt16 nItemId)2175 void ValueSet::SelectItem( sal_uInt16 nItemId )
2176 {
2177     sal_uInt16 nItemPos = 0;
2178 
2179     if ( nItemId )
2180     {
2181         nItemPos = GetItemPos( nItemId );
2182         if ( nItemPos == VALUESET_ITEM_NOTFOUND )
2183             return;
2184         if ( mpImpl->mpItemList->GetObject( nItemPos )->meType == VALUESETITEM_SPACE )
2185             return;
2186     }
2187 
2188     if ( (mnSelItemId != nItemId) || mbNoSelection )
2189     {
2190         sal_uInt16 nOldItem = mnSelItemId ? mnSelItemId : 1;
2191         mnSelItemId = nItemId;
2192         mbNoSelection = false;
2193 
2194         sal_Bool bNewOut;
2195         sal_Bool bNewLine;
2196         if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2197             bNewOut = sal_True;
2198         else
2199             bNewOut = sal_False;
2200         bNewLine = sal_False;
2201 
2202         // Gegebenenfalls in den sichtbaren Bereich scrollen
2203         if ( mbScroll && nItemId )
2204         {
2205             sal_uInt16 nNewLine = (sal_uInt16)(nItemPos / mnCols);
2206             if ( nNewLine < mnFirstLine )
2207             {
2208                 mnFirstLine = nNewLine;
2209                 bNewLine = sal_True;
2210             }
2211             else if ( nNewLine > (sal_uInt16)(mnFirstLine+mnVisLines-1) )
2212             {
2213                 mnFirstLine = (sal_uInt16)(nNewLine-mnVisLines+1);
2214                 bNewLine = sal_True;
2215             }
2216         }
2217 
2218         if ( bNewOut )
2219         {
2220             if ( bNewLine )
2221             {
2222                 // Falls sich der sichtbare Bereich geaendert hat,
2223                 // alles neu ausgeben
2224                 mbFormat = true;
2225                 ImplDraw();
2226             }
2227             else
2228             {
2229                 // alte Selection wegnehmen und neue ausgeben
2230                 ImplHideSelect( nOldItem );
2231                 ImplDrawSelect();
2232             }
2233         }
2234 
2235         if( ImplHasAccessibleListeners() )
2236         {
2237             // focus event (deselect)
2238             if( nOldItem )
2239             {
2240                 const sal_uInt16 nPos = GetItemPos( nItemId );
2241 
2242                 if( nPos != VALUESET_ITEM_NOTFOUND )
2243                 {
2244                     ValueItemAcc* pItemAcc = ValueItemAcc::getImplementation(
2245                         mpImpl->mpItemList->GetObject( nPos )->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2246 
2247                     if( pItemAcc )
2248                     {
2249                         ::com::sun::star::uno::Any aOldAny, aNewAny;
2250                         if( !mpImpl->mbIsTransientChildrenDisabled)
2251                         {
2252                             aOldAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
2253                                 static_cast< ::cppu::OWeakObject* >( pItemAcc ));
2254                             ImplFireAccessibleEvent (::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
2255                         }
2256                         else
2257                         {
2258                             aOldAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
2259                             pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
2260                         }
2261                     }
2262                 }
2263             }
2264 
2265             // focus event (select)
2266             const sal_uInt16 nPos = GetItemPos( mnSelItemId );
2267 
2268             ValueSetItem* pItem;
2269             if( nPos != VALUESET_ITEM_NOTFOUND )
2270                 pItem = mpImpl->mpItemList->GetObject(nPos);
2271             else
2272                 pItem = mpNoneItem;
2273 
2274             ValueItemAcc* pItemAcc = NULL;
2275             if (pItem != NULL)
2276                 pItemAcc = ValueItemAcc::getImplementation(pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2277 
2278             if( pItemAcc )
2279             {
2280                 ::com::sun::star::uno::Any aOldAny, aNewAny;
2281                 if( !mpImpl->mbIsTransientChildrenDisabled)
2282                 {
2283                     aNewAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
2284                         static_cast< ::cppu::OWeakObject* >( pItemAcc ));
2285                     ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
2286                 }
2287                 else
2288                 {
2289                     aNewAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
2290                     pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
2291                 }
2292             }
2293 
2294             // selection event
2295             ::com::sun::star::uno::Any aOldAny, aNewAny;
2296             ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::SELECTION_CHANGED, aOldAny, aNewAny );
2297         }
2298         mpImpl->maHighlightHdl.Call(this);
2299     }
2300 }
2301 
2302 // -----------------------------------------------------------------------
2303 
SetNoSelection()2304 void ValueSet::SetNoSelection()
2305 {
2306     mbNoSelection   = true;
2307     mbHighlight     = false;
2308     mbSelection     = false;
2309 
2310     if ( IsReallyVisible() && IsUpdateMode() )
2311         ImplDraw();
2312 }
2313 
2314 // -----------------------------------------------------------------------
2315 
SetItemBits(sal_uInt16 nItemId,sal_uInt16 nItemBits)2316 void ValueSet::SetItemBits( sal_uInt16 nItemId, sal_uInt16 nItemBits )
2317 {
2318     sal_uInt16 nPos = GetItemPos( nItemId );
2319 
2320     if ( nPos != VALUESET_ITEM_NOTFOUND )
2321         mpImpl->mpItemList->GetObject( nPos )->mnBits = nItemBits;
2322 }
2323 
2324 // -----------------------------------------------------------------------
2325 
GetItemBits(sal_uInt16 nItemId) const2326 sal_uInt16 ValueSet::GetItemBits( sal_uInt16 nItemId ) const
2327 {
2328     sal_uInt16 nPos = GetItemPos( nItemId );
2329 
2330     if ( nPos != VALUESET_ITEM_NOTFOUND )
2331         return mpImpl->mpItemList->GetObject( nPos )->mnBits;
2332     else
2333         return 0;
2334 }
2335 
2336 // -----------------------------------------------------------------------
2337 
SetItemImage(sal_uInt16 nItemId,const Image & rImage)2338 void ValueSet::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
2339 {
2340     sal_uInt16 nPos = GetItemPos( nItemId );
2341 
2342     if ( nPos == VALUESET_ITEM_NOTFOUND )
2343         return;
2344 
2345     ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2346     pItem->meType  = VALUESETITEM_IMAGE;
2347     pItem->maImage = rImage;
2348 
2349     if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2350     {
2351         ImplFormatItem( pItem );
2352         Invalidate( pItem->maRect );
2353     }
2354     else
2355         mbFormat = true;
2356 }
2357 
2358 // -----------------------------------------------------------------------
2359 
GetItemImage(sal_uInt16 nItemId) const2360 Image ValueSet::GetItemImage( sal_uInt16 nItemId ) const
2361 {
2362     sal_uInt16 nPos = GetItemPos( nItemId );
2363 
2364     if ( nPos != VALUESET_ITEM_NOTFOUND )
2365         return mpImpl->mpItemList->GetObject( nPos )->maImage;
2366     else
2367         return Image();
2368 }
2369 
2370 // -----------------------------------------------------------------------
2371 
SetItemColor(sal_uInt16 nItemId,const Color & rColor)2372 void ValueSet::SetItemColor( sal_uInt16 nItemId, const Color& rColor )
2373 {
2374     sal_uInt16 nPos = GetItemPos( nItemId );
2375 
2376     if ( nPos == VALUESET_ITEM_NOTFOUND )
2377         return;
2378 
2379     ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2380     pItem->meType  = VALUESETITEM_COLOR;
2381     pItem->maColor = rColor;
2382 
2383     if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2384     {
2385         ImplFormatItem( pItem );
2386         Invalidate( pItem->maRect );
2387     }
2388     else
2389         mbFormat = true;
2390 }
2391 
2392 // -----------------------------------------------------------------------
2393 
GetItemColor(sal_uInt16 nItemId) const2394 Color ValueSet::GetItemColor( sal_uInt16 nItemId ) const
2395 {
2396     sal_uInt16 nPos = GetItemPos( nItemId );
2397 
2398     if ( nPos != VALUESET_ITEM_NOTFOUND )
2399         return mpImpl->mpItemList->GetObject( nPos )->maColor;
2400     else
2401         return Color();
2402 }
2403 
2404 // -----------------------------------------------------------------------
2405 
SetItemData(sal_uInt16 nItemId,void * pData)2406 void ValueSet::SetItemData( sal_uInt16 nItemId, void* pData )
2407 {
2408     sal_uInt16 nPos = GetItemPos( nItemId );
2409 
2410     if ( nPos == VALUESET_ITEM_NOTFOUND )
2411         return;
2412 
2413     ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2414     pItem->mpData = pData;
2415 
2416     if ( pItem->meType == VALUESETITEM_USERDRAW )
2417     {
2418         if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2419         {
2420             ImplFormatItem( pItem );
2421             Invalidate( pItem->maRect );
2422         }
2423         else
2424             mbFormat = true;
2425     }
2426 }
2427 
2428 // -----------------------------------------------------------------------
2429 
GetItemData(sal_uInt16 nItemId) const2430 void* ValueSet::GetItemData( sal_uInt16 nItemId ) const
2431 {
2432     sal_uInt16 nPos = GetItemPos( nItemId );
2433 
2434     if ( nPos != VALUESET_ITEM_NOTFOUND )
2435         return mpImpl->mpItemList->GetObject( nPos )->mpData;
2436     else
2437         return NULL;
2438 }
2439 
2440 // -----------------------------------------------------------------------
2441 
SetItemText(sal_uInt16 nItemId,const XubString & rText)2442 void ValueSet::SetItemText( sal_uInt16 nItemId, const XubString& rText )
2443 {
2444     sal_uInt16 nPos = GetItemPos( nItemId );
2445 
2446     if ( nPos == VALUESET_ITEM_NOTFOUND )
2447         return;
2448 
2449 
2450     ValueSetItem* pItem = mpImpl->mpItemList->GetObject( nPos );
2451 
2452     // Remember old and new name for accessibility event.
2453     ::com::sun::star::uno::Any aOldName, aNewName;
2454     ::rtl::OUString sString (pItem->maText);
2455     aOldName <<= sString;
2456     sString = rText;
2457     aNewName <<= sString;
2458 
2459     pItem->maText = rText;
2460 
2461     if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
2462     {
2463         sal_uInt16 nTempId = mnSelItemId;
2464 
2465         if ( mbHighlight )
2466             nTempId = mnHighItemId;
2467 
2468         if ( nTempId == nItemId )
2469             ImplDrawItemText( pItem->maText );
2470     }
2471 
2472     if (ImplHasAccessibleListeners())
2473     {
2474         ::com::sun::star::uno::Reference<
2475               ::com::sun::star::accessibility::XAccessible> xAccessible (
2476                   pItem->GetAccessible( mpImpl->mbIsTransientChildrenDisabled ) );
2477         static_cast<ValueItemAcc*>(xAccessible.get())->FireAccessibleEvent (
2478             ::com::sun::star::accessibility::AccessibleEventId::NAME_CHANGED,
2479             aOldName, aNewName);
2480     }
2481 }
2482 
2483 // -----------------------------------------------------------------------
2484 
GetItemText(sal_uInt16 nItemId) const2485 XubString ValueSet::GetItemText( sal_uInt16 nItemId ) const
2486 {
2487     sal_uInt16 nPos = GetItemPos( nItemId );
2488 
2489     if ( nPos != VALUESET_ITEM_NOTFOUND )
2490         return mpImpl->mpItemList->GetObject( nPos )->maText;
2491     else
2492         return XubString();
2493 }
2494 
2495 // -----------------------------------------------------------------------
2496 
SetColor(const Color & rColor)2497 void ValueSet::SetColor( const Color& rColor )
2498 {
2499     maColor     = rColor;
2500     mbFormat    = true;
2501     if ( IsReallyVisible() && IsUpdateMode() )
2502         ImplDraw();
2503 }
2504 
2505 // -----------------------------------------------------------------------
2506 
SetExtraSpacing(sal_uInt16 nNewSpacing)2507 void ValueSet::SetExtraSpacing( sal_uInt16 nNewSpacing )
2508 {
2509     if ( GetStyle() & WB_ITEMBORDER )
2510     {
2511         mnSpacing = nNewSpacing;
2512 
2513         mbFormat = true;
2514         if ( IsReallyVisible() && IsUpdateMode() )
2515             Invalidate();
2516     }
2517 }
2518 
2519 // -----------------------------------------------------------------------
2520 
StartSelection()2521 void ValueSet::StartSelection()
2522 {
2523     mnOldItemId     = mnSelItemId;
2524     mbHighlight     = true;
2525     mbSelection     = true;
2526     mnHighItemId    = mnSelItemId;
2527 }
2528 
2529 // -----------------------------------------------------------------------
2530 
EndSelection()2531 void ValueSet::EndSelection()
2532 {
2533     if ( mbHighlight )
2534     {
2535         if ( IsTracking() )
2536             EndTracking( ENDTRACK_CANCEL );
2537 
2538         ImplHighlightItem( mnSelItemId );
2539         mbHighlight = false;
2540     }
2541     mbSelection = false;
2542 }
2543 
2544 // -----------------------------------------------------------------------
2545 
StartDrag(const CommandEvent & rCEvt,Region & rRegion)2546 sal_Bool ValueSet::StartDrag( const CommandEvent& rCEvt, Region& rRegion )
2547 {
2548     if ( rCEvt.GetCommand() != COMMAND_STARTDRAG )
2549         return sal_False;
2550 
2551     // Gegebenenfalls eine vorhandene Aktion abbrechen
2552     EndSelection();
2553 
2554     // Testen, ob angeklickte Seite selektiert ist. Falls dies nicht
2555     // der Fall ist, setzen wir ihn als aktuellen Eintrag. Falls Drag and
2556     // Drop auch mal ueber Tastatur ausgeloest werden kann, testen wir
2557     // dies nur bei einer Mausaktion.
2558     sal_uInt16 nSelId;
2559     if ( rCEvt.IsMouseEvent() )
2560         nSelId = GetItemId( rCEvt.GetMousePosPixel() );
2561     else
2562         nSelId = mnSelItemId;
2563 
2564     // Falls kein Eintrag angeklickt wurde, starten wir kein Dragging
2565     if ( !nSelId )
2566         return sal_False;
2567 
2568     // Testen, ob Seite selektiertiert ist. Falls nicht, als aktuelle
2569     // Seite setzen und Select rufen.
2570     if ( nSelId != mnSelItemId )
2571     {
2572         SelectItem( nSelId );
2573         Update();
2574         Select();
2575     }
2576 
2577     Region aRegion;
2578 
2579     // Region zuweisen
2580     rRegion = aRegion;
2581 
2582     return sal_True;
2583 }
2584 
2585 // -----------------------------------------------------------------------
2586 
CalcWindowSizePixel(const Size & rItemSize,sal_uInt16 nDesireCols,sal_uInt16 nDesireLines)2587 Size ValueSet::CalcWindowSizePixel( const Size& rItemSize, sal_uInt16 nDesireCols,
2588                                     sal_uInt16 nDesireLines )
2589 {
2590     long nCalcCols = (long)nDesireCols;
2591     long nCalcLines = (long)nDesireLines;
2592 
2593     if ( !nCalcCols )
2594     {
2595         if ( mnUserCols )
2596             nCalcCols = (long)mnUserCols;
2597         else
2598             nCalcCols = 1;
2599     }
2600 
2601     if ( !nCalcLines )
2602     {
2603         nCalcLines = mnVisLines;
2604 
2605         if ( mbFormat )
2606         {
2607             if ( mnUserVisLines )
2608                 nCalcLines = mnUserVisLines;
2609             else
2610             {
2611                 nCalcLines = (long)mpImpl->mpItemList->Count() / nCalcCols;
2612                 if ( mpImpl->mpItemList->Count() % nCalcCols )
2613                     nCalcLines++;
2614                 else if ( !nCalcLines )
2615                     nCalcLines = 1;
2616             }
2617         }
2618     }
2619 
2620     Size        aSize( rItemSize.Width()*nCalcCols, rItemSize.Height()*nCalcLines );
2621     WinBits     nStyle = GetStyle();
2622     long        nTxtHeight = GetTextHeight();
2623     long        nSpace;
2624     long        n;
2625 
2626     if ( nStyle & WB_ITEMBORDER )
2627     {
2628         if ( nStyle & WB_DOUBLEBORDER )
2629             n = ITEM_OFFSET_DOUBLE;
2630         else
2631             n = ITEM_OFFSET;
2632 
2633         aSize.Width()  += n*nCalcCols;
2634         aSize.Height() += n*nCalcLines;
2635     }
2636     else
2637         n = 0;
2638 
2639     if ( mnSpacing )
2640     {
2641         nSpace = mnSpacing;
2642         aSize.Width()  += mnSpacing*(nCalcCols-1);
2643         aSize.Height() += mnSpacing*(nCalcLines-1);
2644     }
2645     else
2646         nSpace = 0;
2647 
2648     if ( nStyle & WB_NAMEFIELD )
2649     {
2650         aSize.Height() += nTxtHeight + NAME_OFFSET;
2651         if ( !(nStyle & WB_FLATVALUESET) )
2652             aSize.Height() += NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
2653     }
2654 
2655     if ( nStyle & WB_NONEFIELD )
2656     {
2657         aSize.Height() += nTxtHeight + n + nSpace;
2658         if ( nStyle & WB_RADIOSEL )
2659             aSize.Height() += 8;
2660     }
2661 
2662     // Evt. ScrollBar-Breite aufaddieren
2663     aSize.Width() += GetScrollWidth();
2664 
2665     return aSize;
2666 }
2667 
2668 // -----------------------------------------------------------------------
2669 
CalcItemSizePixel(const Size & rItemSize,bool bOut) const2670 Size ValueSet::CalcItemSizePixel( const Size& rItemSize, bool bOut ) const
2671 {
2672     Size aSize = rItemSize;
2673 
2674     WinBits nStyle = GetStyle();
2675     if ( nStyle & WB_ITEMBORDER )
2676     {
2677         long n;
2678 
2679         if ( nStyle & WB_DOUBLEBORDER )
2680             n = ITEM_OFFSET_DOUBLE;
2681         else
2682             n = ITEM_OFFSET;
2683 
2684         if ( bOut )
2685         {
2686             aSize.Width()  += n;
2687             aSize.Height() += n;
2688         }
2689         else
2690         {
2691             aSize.Width()  -= n;
2692             aSize.Height() -= n;
2693         }
2694     }
2695 
2696     return aSize;
2697 }
2698 
2699 // -----------------------------------------------------------------------
2700 
GetScrollWidth() const2701 long ValueSet::GetScrollWidth() const
2702 {
2703     if ( GetStyle() & WB_VSCROLL )
2704     {
2705         ((ValueSet*)this)->ImplInitScrollBar();
2706         return mpScrBar->GetSizePixel().Width()+SCRBAR_OFFSET;
2707     }
2708     else
2709         return 0;
2710 }
2711 
2712 // -----------------------------------------------------------------------
2713 
ShowDropPos(const Point & rPos)2714 sal_uInt16 ValueSet::ShowDropPos( const Point& rPos )
2715 {
2716     mbDropPos = true;
2717 
2718     // Gegebenenfalls scrollen
2719     ImplScroll( rPos );
2720 
2721     // DropPosition ermitteln
2722     sal_uInt16 nPos = ImplGetItem( rPos, sal_True );
2723     if ( nPos == VALUESET_ITEM_NONEITEM )
2724         nPos = 0;
2725     else if ( nPos == VALUESET_ITEM_NOTFOUND )
2726     {
2727         Size aOutSize = GetOutputSizePixel();
2728         if ( GetStyle() & WB_NAMEFIELD )
2729             aOutSize.Height() = mnTextOffset;
2730         if ( (rPos.X() >= 0) && (rPos.X() < aOutSize.Width()) &&
2731              (rPos.Y() >= 0) && (rPos.Y() < aOutSize.Height()) )
2732             nPos = (sal_uInt16)mpImpl->mpItemList->Count();
2733     }
2734     else
2735     {
2736         // Im letzten viertel, dann wird ein Item spaeter eingefuegt
2737         Rectangle aRect = mpImpl->mpItemList->GetObject( nPos )->maRect;
2738         if ( rPos.X() > aRect.Left()+aRect.GetWidth()-(aRect.GetWidth()/4) )
2739             nPos++;
2740     }
2741 
2742     if ( nPos != mnDropPos )
2743     {
2744         ImplDrawDropPos( sal_False );
2745         mnDropPos = nPos;
2746         ImplDrawDropPos( sal_True );
2747     }
2748 
2749     return mnDropPos;
2750 }
2751 
2752 // -----------------------------------------------------------------------
2753 
HideDropPos()2754 void ValueSet::HideDropPos()
2755 {
2756     if ( mbDropPos )
2757     {
2758         ImplDrawDropPos( sal_False );
2759         mbDropPos = false;
2760     }
2761 }
2762 
2763 // -----------------------------------------------------------------------
2764 
IsRTLActive(void)2765 bool ValueSet::IsRTLActive (void)
2766 {
2767     return Application::GetSettings().GetLayoutRTL() && IsRTLEnabled();
2768 }
2769 
2770 // -----------------------------------------------------------------------
2771 
SetHighlightHdl(const Link & rLink)2772 void ValueSet::SetHighlightHdl( const Link& rLink )
2773 {
2774     mpImpl->maHighlightHdl = rLink;
2775 }
2776 
2777 // -----------------------------------------------------------------------
2778 
GetHighlightHdl() const2779 const Link& ValueSet::GetHighlightHdl() const
2780 {
2781     return mpImpl->maHighlightHdl;
2782 }
2783 
2784 // -----------------------------------------------------------------------
2785 
SetEdgeBlending(bool bNew)2786 void ValueSet::SetEdgeBlending(bool bNew)
2787 {
2788     if(mbEdgeBlending != bNew)
2789     {
2790         mbEdgeBlending = bNew;
2791         mbFormat = true;
2792 
2793         if(IsReallyVisible() && IsUpdateMode())
2794         {
2795             Invalidate();
2796         }
2797     }
2798 }
2799 //For sending out the focused event on the first focused item when this valueset is first focused.
2800 // MT: Focus notifications changed in DEV300 meanwhile, so this is not used for now.
2801 // Just keeping it here for reference, in case something in out implementation doesn't work as expected...
2802 /*
2803 void ValueSet::SetFocusedItem(sal_Bool bFocused)
2804 {
2805     if( ImplHasAccessibleListeners() )
2806     {
2807         // selection event
2808         ::com::sun::star::uno::Any aSelOldAny, aSelNewAny;
2809         if ( mnSelItemId >= 0)
2810         {
2811             // focus event (select)
2812             sal_uInt16 nPos = GetItemPos( mnSelItemId );
2813 
2814             ValueSetItem* pItem;
2815             if ((GetStyle() & WB_NONEFIELD) != 0
2816                 && nPos == VALUESET_ITEM_NOTFOUND
2817                 && mnSelItemId == 0)
2818             {
2819                 // When present the first item is the then allways visible none field.
2820                 pItem = ImplGetItem (VALUESET_ITEM_NONEITEM);
2821             }
2822             else
2823             {
2824                 if (nPos == VALUESET_ITEM_NOTFOUND)
2825                     nPos = 0;
2826                 pItem = mpImpl->mpItemList->GetObject(nPos);
2827             }
2828             ValueItemAcc* pItemAcc = NULL;
2829             if (pItem != NULL)
2830                 pItemAcc = ValueItemAcc::getImplementation(pItem->GetAccessible(mpImpl->mbIsTransientChildrenDisabled) );
2831             if( pItemAcc )
2832             {
2833                 if (bFocused)
2834                     aSelNewAny <<= pItem->GetAccessible(mpImpl->mbIsTransientChildrenDisabled);
2835                 else
2836                     aSelOldAny <<= pItem->GetAccessible(mpImpl->mbIsTransientChildrenDisabled);
2837             }
2838             ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aSelOldAny, aSelNewAny );
2839             if (pItemAcc && bFocused)
2840             {
2841                 pItemAcc->FireAccessibleEvent(
2842                     ::com::sun::star::accessibility::AccessibleEventId::SELECTION_CHANGED,
2843                     ::com::sun::star::uno::Any(),::com::sun::star::uno::Any());
2844             }
2845         }
2846     }
2847 }
2848 */
2849 //end
2850 
2851 
2852 // -----------------------------------------------------------------------
2853 // eof
2854