xref: /trunk/main/vcl/source/control/combobox.cxx (revision ffad8df045fe8db79e3e50f731c1fa6ab6501c83)
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_vcl.hxx"
26 
27 #include <tools/table.hxx>
28 #include <tools/debug.hxx>
29 #include <tools/rc.h>
30 
31 #include <vcl/decoview.hxx>
32 #include <vcl/lstbox.h>
33 #include <vcl/button.hxx>
34 #include <vcl/event.hxx>
35 #include <vcl/combobox.hxx>
36 
37 #include <svdata.hxx>
38 #include <subedit.hxx>
39 #include <ilstbox.hxx>
40 #include <controldata.hxx>
41 
42 // =======================================================================
43 
44 inline sal_uLong ImplCreateKey( sal_uInt16 nPos )
45 {
46     // Key = Pos+1, wegen Pos 0
47     return nPos+1;
48 }
49 
50 // -----------------------------------------------------------------------
51 
52 static void lcl_GetSelectedEntries( Table& rSelectedPos, const XubString& rText, xub_Unicode cTokenSep, const ImplEntryList* pEntryList )
53 {
54     for( xub_StrLen n = rText.GetTokenCount( cTokenSep ); n; )
55     {
56         XubString aToken = rText.GetToken( --n, cTokenSep );
57         aToken.EraseLeadingAndTrailingChars( ' ' );
58         sal_uInt16 nPos = pEntryList->FindEntry( aToken );
59         if ( nPos != LISTBOX_ENTRY_NOTFOUND )
60             rSelectedPos.Insert( ImplCreateKey( nPos ), (void*)sal_IntPtr(1L) );
61     }
62 }
63 
64 // =======================================================================
65 
66 ComboBox::ComboBox( WindowType nType ) :
67     Edit( nType )
68 {
69     ImplInitComboBoxData();
70 }
71 
72 // -----------------------------------------------------------------------
73 
74 ComboBox::ComboBox( Window* pParent, WinBits nStyle ) :
75     Edit( WINDOW_COMBOBOX )
76 {
77     ImplInitComboBoxData();
78     ImplInit( pParent, nStyle );
79 }
80 
81 // -----------------------------------------------------------------------
82 
83 ComboBox::ComboBox( Window* pParent, const ResId& rResId ) :
84     Edit( WINDOW_COMBOBOX )
85 {
86     ImplInitComboBoxData();
87     rResId.SetRT( RSC_COMBOBOX );
88     WinBits nStyle = ImplInitRes( rResId );
89     ImplInit( pParent, nStyle );
90     ImplLoadRes( rResId );
91 
92     if ( !(nStyle & WB_HIDE ) )
93         Show();
94 }
95 
96 // -----------------------------------------------------------------------
97 
98 ComboBox::~ComboBox()
99 {
100     SetSubEdit( NULL );
101     delete mpSubEdit;
102 
103     delete mpImplLB;
104     mpImplLB = NULL;
105 
106     delete mpFloatWin;
107     delete mpBtn;
108 }
109 
110 // -----------------------------------------------------------------------
111 
112 void ComboBox::ImplInitComboBoxData()
113 {
114     mpSubEdit           = NULL;
115     mpBtn               = NULL;
116     mpImplLB            = NULL;
117     mpFloatWin          = NULL;
118 
119     mnDDHeight          = 0;
120     mbDDAutoSize        = sal_True;
121     mbSyntheticModify   = sal_False;
122     mbMatchCase         = sal_False;
123     mcMultiSep          = ';';
124 }
125 
126 // -----------------------------------------------------------------------
127 
128 void ComboBox::ImplCalcEditHeight()
129 {
130     sal_Int32 nLeft, nTop, nRight, nBottom;
131     GetBorder( nLeft, nTop, nRight, nBottom );
132     mnDDHeight = (sal_uInt16)(mpSubEdit->GetTextHeight() + nTop + nBottom + 4);
133     if ( !IsDropDownBox() )
134         mnDDHeight += 4;
135 
136     Rectangle aCtrlRegion( Point( 0, 0 ), Size( 10, 10 ) );
137     Rectangle aBoundRegion, aContentRegion;
138     ImplControlValue aControlValue;
139     ControlType aType = IsDropDownBox() ? CTRL_COMBOBOX : CTRL_EDITBOX;
140     if( GetNativeControlRegion( aType, PART_ENTIRE_CONTROL,
141                                 aCtrlRegion,
142                                 CTRL_STATE_ENABLED,
143                                 aControlValue, rtl::OUString(),
144                                 aBoundRegion, aContentRegion ) )
145     {
146         const long nNCHeight = aBoundRegion.GetHeight();
147         if( mnDDHeight < nNCHeight )
148             mnDDHeight = sal::static_int_cast<sal_uInt16>( nNCHeight );
149     }
150 }
151 
152 // -----------------------------------------------------------------------
153 
154 void ComboBox::ImplInit( Window* pParent, WinBits nStyle )
155 {
156     ImplInitStyle( nStyle );
157 
158     sal_Bool bNoBorder = ( nStyle & WB_NOBORDER ) ? sal_True : sal_False;
159     if ( !(nStyle & WB_DROPDOWN) )
160     {
161         nStyle &= ~WB_BORDER;
162         nStyle |= WB_NOBORDER;
163     }
164     else
165     {
166         if ( !bNoBorder )
167             nStyle |= WB_BORDER;
168     }
169 
170     Edit::ImplInit( pParent, nStyle );
171     SetBackground();
172 
173     // DropDown ?
174     WinBits nEditStyle = nStyle & ( WB_LEFT | WB_RIGHT | WB_CENTER );
175     WinBits nListStyle = nStyle;
176     if( nStyle & WB_DROPDOWN )
177     {
178         mpFloatWin = new ImplListBoxFloatingWindow( this );
179         mpFloatWin->SetAutoWidth( sal_True );
180         mpFloatWin->SetPopupModeEndHdl( LINK( this, ComboBox, ImplPopupModeEndHdl ) );
181 
182         mpBtn = new ImplBtn( this, WB_NOLIGHTBORDER | WB_RECTSTYLE );
183         ImplInitDropDownButton( mpBtn );
184         mpBtn->SetMBDownHdl( LINK( this, ComboBox, ImplClickBtnHdl ) );
185         mpBtn->Show();
186 
187         nEditStyle |= WB_NOBORDER;
188         nListStyle &= ~WB_BORDER;
189         nListStyle |= WB_NOBORDER;
190     }
191     else
192     {
193         if ( !bNoBorder )
194         {
195             nEditStyle |= WB_BORDER;
196             nListStyle &= ~WB_NOBORDER;
197             nListStyle |= WB_BORDER;
198         }
199     }
200 
201     mpSubEdit = new Edit( this, nEditStyle );
202     mpSubEdit->EnableRTL( sal_False );
203     SetSubEdit( mpSubEdit );
204     mpSubEdit->SetPosPixel( Point() );
205     EnableAutocomplete( sal_True );
206     mpSubEdit->Show();
207 
208     Window* pLBParent = this;
209     if ( mpFloatWin )
210         pLBParent = mpFloatWin;
211     mpImplLB = new ImplListBox( pLBParent, nListStyle|WB_SIMPLEMODE );
212     mpImplLB->SetPosPixel( Point() );
213     mpImplLB->SetSelectHdl( LINK( this, ComboBox, ImplSelectHdl ) );
214     mpImplLB->SetCancelHdl( LINK( this, ComboBox, ImplCancelHdl ) );
215     mpImplLB->SetDoubleClickHdl( LINK( this, ComboBox, ImplDoubleClickHdl ) );
216     mpImplLB->SetUserDrawHdl( LINK( this, ComboBox, ImplUserDrawHdl ) );
217     mpImplLB->SetSelectionChangedHdl( LINK( this, ComboBox, ImplSelectionChangedHdl ) );
218 //IAccessibility2 Implementation 2009-----
219     mpImplLB->SetListItemSelectHdl( LINK( this, ComboBox, ImplListItemSelectHdl ) );
220 //-----IAccessibility2 Implementation 2009
221     mpImplLB->Show();
222 
223     if ( mpFloatWin )
224         mpFloatWin->SetImplListBox( mpImplLB );
225     else
226         mpImplLB->GetMainWindow()->AllowGrabFocus( sal_True );
227 
228     ImplCalcEditHeight();
229 
230     SetCompoundControl( sal_True );
231 }
232 
233 // -----------------------------------------------------------------------
234 
235 WinBits ComboBox::ImplInitStyle( WinBits nStyle )
236 {
237     if ( !(nStyle & WB_NOTABSTOP) )
238         nStyle |= WB_TABSTOP;
239     if ( !(nStyle & WB_NOGROUP) )
240         nStyle |= WB_GROUP;
241     return nStyle;
242 }
243 
244 // -----------------------------------------------------------------------
245 
246 void ComboBox::ImplLoadRes( const ResId& rResId )
247 {
248     Edit::ImplLoadRes( rResId );
249 
250     sal_uLong nNumber = ReadLongRes();
251 
252     if( nNumber )
253     {
254         for( sal_uInt16 i = 0; i < nNumber; i++ )
255         {
256             InsertEntry( ReadStringRes(), LISTBOX_APPEND );
257         }
258     }
259 }
260 
261 // -----------------------------------------------------------------------
262 
263 void ComboBox::EnableAutocomplete( sal_Bool bEnable, sal_Bool bMatchCase )
264 {
265     mbMatchCase = bMatchCase;
266 
267     if ( bEnable )
268         mpSubEdit->SetAutocompleteHdl( LINK( this, ComboBox, ImplAutocompleteHdl ) );
269     else
270         mpSubEdit->SetAutocompleteHdl( Link() );
271 }
272 
273 // -----------------------------------------------------------------------
274 
275 sal_Bool ComboBox::IsAutocompleteEnabled() const
276 {
277     return mpSubEdit->GetAutocompleteHdl().IsSet();
278 }
279 //IAccessibility2 Implementation 2009-----
280 void  ComboBox::SetMpSubEditAccessibleName(String &aName)
281 {
282     if(mpSubEdit!=NULL)
283         mpSubEdit->SetAccessibleName(aName);
284 }
285 //-----IAccessibility2 Implementation 2009
286 // -----------------------------------------------------------------------
287 
288 IMPL_LINK( ComboBox, ImplClickBtnHdl, void*, EMPTYARG )
289 {
290     ImplCallEventListeners( VCLEVENT_DROPDOWN_PRE_OPEN );
291     mpSubEdit->GrabFocus();
292     if ( !mpImplLB->GetEntryList()->GetMRUCount() )
293         ImplUpdateFloatSelection();
294     else
295         mpImplLB->SelectEntry( 0 , sal_True );
296     mpBtn->SetPressed( sal_True );
297     SetSelection( Selection( 0, SELECTION_MAX ) );
298     mpFloatWin->StartFloat( sal_True );
299     ImplCallEventListeners( VCLEVENT_DROPDOWN_OPEN );
300 
301     ImplClearLayoutData();
302     if( mpImplLB )
303         mpImplLB->GetMainWindow()->ImplClearLayoutData();
304 
305     return 0;
306 }
307 
308 // -----------------------------------------------------------------------
309 
310 IMPL_LINK( ComboBox, ImplPopupModeEndHdl, void*, EMPTYARG )
311 {
312     if( mpFloatWin->IsPopupModeCanceled() )
313     {
314         if ( !mpImplLB->GetEntryList()->IsEntryPosSelected( mpFloatWin->GetPopupModeStartSaveSelection() ) )
315         {
316             mpImplLB->SelectEntry( mpFloatWin->GetPopupModeStartSaveSelection(), sal_True );
317             sal_Bool bTravelSelect = mpImplLB->IsTravelSelect();
318             mpImplLB->SetTravelSelect( sal_True );
319             Select();
320             mpImplLB->SetTravelSelect( bTravelSelect );
321         }
322     }
323 
324     ImplClearLayoutData();
325     if( mpImplLB )
326         mpImplLB->GetMainWindow()->ImplClearLayoutData();
327 
328     mpBtn->SetPressed( sal_False );
329     ImplCallEventListeners( VCLEVENT_DROPDOWN_CLOSE );
330     return 0;
331 }
332 
333 // -----------------------------------------------------------------------
334 
335 IMPL_LINK( ComboBox, ImplAutocompleteHdl, Edit*, pEdit )
336 {
337     Selection           aSel = pEdit->GetSelection();
338     AutocompleteAction  eAction = pEdit->GetAutocompleteAction();
339 
340     /* If there is no current selection do not auto complete on
341        Tab/Shift-Tab since then we would not cycle to the next field.
342     */
343     if ( aSel.Len() ||
344          ((eAction != AUTOCOMPLETE_TABFORWARD) && (eAction != AUTOCOMPLETE_TABBACKWARD)) )
345     {
346         XubString   aFullText = pEdit->GetText();
347         XubString   aStartText = aFullText.Copy( 0, (xub_StrLen)aSel.Max() );
348         sal_uInt16      nStart = mpImplLB->GetCurrentPos();
349 
350         if ( nStart == LISTBOX_ENTRY_NOTFOUND )
351             nStart = 0;
352 
353         sal_Bool bForward = sal_True;
354         if ( eAction == AUTOCOMPLETE_TABFORWARD )
355             nStart++;
356         else if ( eAction == AUTOCOMPLETE_TABBACKWARD )
357         {
358             bForward = sal_False;
359             nStart = nStart ? nStart - 1 : mpImplLB->GetEntryList()->GetEntryCount()-1;
360         }
361 
362         sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND;
363         if( ! mbMatchCase )
364         {
365             // Try match case insensitive from current position
366             nPos = mpImplLB->GetEntryList()->FindMatchingEntry( aStartText, nStart, bForward, sal_True );
367             if ( nPos == LISTBOX_ENTRY_NOTFOUND )
368                 // Try match case insensitive, but from start
369                 nPos = mpImplLB->GetEntryList()->FindMatchingEntry( aStartText, bForward ? 0 : (mpImplLB->GetEntryList()->GetEntryCount()-1), bForward, sal_True );
370         }
371 
372         if ( nPos == LISTBOX_ENTRY_NOTFOUND )
373             // Try match full from current position
374             nPos = mpImplLB->GetEntryList()->FindMatchingEntry( aStartText, nStart, bForward, sal_False );
375         if ( nPos == LISTBOX_ENTRY_NOTFOUND )
376             //  Match full, but from start
377             nPos = mpImplLB->GetEntryList()->FindMatchingEntry( aStartText, bForward ? 0 : (mpImplLB->GetEntryList()->GetEntryCount()-1), bForward, sal_False );
378 
379         if ( nPos != LISTBOX_ENTRY_NOTFOUND )
380         {
381             XubString aText = mpImplLB->GetEntryList()->GetEntryText( nPos );
382             Selection aSelection( aText.Len(), aStartText.Len() );
383             pEdit->SetText( aText, aSelection );
384         }
385     }
386 
387     return 0;
388 }
389 
390 // -----------------------------------------------------------------------
391 
392 IMPL_LINK( ComboBox, ImplSelectHdl, void*, EMPTYARG )
393 {
394     sal_Bool bPopup = IsInDropDown();
395     sal_Bool bCallSelect = sal_False;
396     if ( mpImplLB->IsSelectionChanged() || bPopup )
397     {
398         XubString aText;
399         if ( IsMultiSelectionEnabled() )
400         {
401             aText = mpSubEdit->GetText();
402 
403             // Alle Eintraege entfernen, zu denen es einen Entry gibt, der aber nicht selektiert ist.
404             xub_StrLen nIndex = 0;
405             while ( nIndex != STRING_NOTFOUND )
406             {
407                 xub_StrLen  nPrevIndex = nIndex;
408                 XubString   aToken = aText.GetToken( 0, mcMultiSep, nIndex );
409                 xub_StrLen  nTokenLen = aToken.Len();
410                 aToken.EraseLeadingAndTrailingChars( ' ' );
411                 sal_uInt16      nP = mpImplLB->GetEntryList()->FindEntry( aToken );
412                 if ( (nP != LISTBOX_ENTRY_NOTFOUND) && (!mpImplLB->GetEntryList()->IsEntryPosSelected( nP )) )
413                 {
414                     aText.Erase( nPrevIndex, nTokenLen );
415                     nIndex = sal::static_int_cast<xub_StrLen>(nIndex - nTokenLen);
416                     if ( (nPrevIndex < aText.Len()) && (aText.GetChar( nPrevIndex ) == mcMultiSep) )
417                     {
418                         aText.Erase( nPrevIndex, 1 );
419                         nIndex--;
420                     }
421                 }
422                 aText.EraseLeadingAndTrailingChars( ' ' );
423             }
424 
425             // Fehlende Eintraege anhaengen...
426             Table aSelInText;
427             lcl_GetSelectedEntries( aSelInText, aText, mcMultiSep, mpImplLB->GetEntryList() );
428             sal_uInt16 nSelectedEntries = mpImplLB->GetEntryList()->GetSelectEntryCount();
429             for ( sal_uInt16 n = 0; n < nSelectedEntries; n++ )
430             {
431                 sal_uInt16 nP = mpImplLB->GetEntryList()->GetSelectEntryPos( n );
432                 if ( !aSelInText.IsKeyValid( ImplCreateKey( nP ) ) )
433                 {
434                     if ( aText.Len() && (aText.GetChar( aText.Len()-1 ) != mcMultiSep) )
435                         aText += mcMultiSep;
436                     if ( aText.Len() )
437                         aText += ' ';   // etwas auflockern
438                     aText += mpImplLB->GetEntryList()->GetEntryText( nP );
439                     aText += mcMultiSep;
440                 }
441             }
442             if ( aText.Len() && (aText.GetChar( aText.Len()-1 ) == mcMultiSep) )
443                 aText.Erase( aText.Len()-1, 1 );
444         }
445         else
446         {
447             aText = mpImplLB->GetEntryList()->GetSelectEntry( 0 );
448         }
449 
450         mpSubEdit->SetText( aText );
451 
452         Selection aNewSelection( 0, aText.Len() );
453         if ( IsMultiSelectionEnabled() )
454             aNewSelection.Min() = aText.Len();
455         mpSubEdit->SetSelection( aNewSelection );
456 
457         bCallSelect = sal_True;
458     }
459 
460     // #84652# Call GrabFocus and EndPopupMode before calling Select/Modify, but after changing the text
461 
462     if ( bPopup && !mpImplLB->IsTravelSelect() &&
463         ( !IsMultiSelectionEnabled() || !mpImplLB->GetSelectModifier() ) )
464     {
465         mpFloatWin->EndPopupMode();
466         GrabFocus();
467     }
468 
469     if ( bCallSelect )
470     {
471         mpSubEdit->SetModifyFlag();
472         mbSyntheticModify = sal_True;
473         Modify();
474         mbSyntheticModify = sal_False;
475         Select();
476     }
477 
478     return 0;
479 }
480 //IAccessibility2 Implementation 2009-----
481 IMPL_LINK( ComboBox, ImplListItemSelectHdl,  void*, EMPTYARG )
482 {
483     ImplCallEventListeners( VCLEVENT_LISTBOX_SELECT );
484     return 1;
485 }
486 //-----IAccessibility2 Implementation 2009
487 // -----------------------------------------------------------------------
488 
489 IMPL_LINK( ComboBox, ImplCancelHdl, void*, EMPTYARG )
490 {
491     if( IsInDropDown() )
492         mpFloatWin->EndPopupMode();
493 
494     return 1;
495 }
496 
497 // -----------------------------------------------------------------------
498 
499 IMPL_LINK( ComboBox, ImplSelectionChangedHdl, void*, n )
500 {
501     if ( !mpImplLB->IsTrackingSelect() )
502     {
503         sal_uInt16 nChanged = (sal_uInt16)(sal_uLong)n;
504         if ( !mpSubEdit->IsReadOnly() && mpImplLB->GetEntryList()->IsEntryPosSelected( nChanged ) )
505             mpSubEdit->SetText( mpImplLB->GetEntryList()->GetEntryText( nChanged ) );
506     }
507     return 1;
508 }
509 
510 // -----------------------------------------------------------------------
511 
512 IMPL_LINK( ComboBox, ImplDoubleClickHdl, void*, EMPTYARG )
513 {
514     DoubleClick();
515     return 0;
516 }
517 
518 // -----------------------------------------------------------------------
519 
520 void ComboBox::ToggleDropDown()
521 {
522     if( IsDropDownBox() )
523     {
524         if( mpFloatWin->IsInPopupMode() )
525             mpFloatWin->EndPopupMode();
526         else
527         {
528             mpSubEdit->GrabFocus();
529             if ( !mpImplLB->GetEntryList()->GetMRUCount() )
530                 ImplUpdateFloatSelection();
531             else
532                 mpImplLB->SelectEntry( 0 , sal_True );
533             ImplCallEventListeners( VCLEVENT_DROPDOWN_PRE_OPEN );
534             mpBtn->SetPressed( sal_True );
535             SetSelection( Selection( 0, SELECTION_MAX ) );
536             mpFloatWin->StartFloat( sal_True );
537             ImplCallEventListeners( VCLEVENT_DROPDOWN_OPEN );
538         }
539     }
540 }
541 
542 // -----------------------------------------------------------------------
543 
544 void ComboBox::Select()
545 {
546     ImplCallEventListenersAndHandler( VCLEVENT_COMBOBOX_SELECT, maSelectHdl, this );
547 }
548 
549 // -----------------------------------------------------------------------
550 
551 void ComboBox::DoubleClick()
552 {
553     ImplCallEventListenersAndHandler( VCLEVENT_COMBOBOX_DOUBLECLICK, maDoubleClickHdl, this );
554 }
555 
556 // -----------------------------------------------------------------------
557 
558 void ComboBox::EnableAutoSize( sal_Bool bAuto )
559 {
560     mbDDAutoSize = bAuto;
561     if ( mpFloatWin )
562     {
563         if ( bAuto && !mpFloatWin->GetDropDownLineCount() )
564         {
565             // Adapt to GetListBoxMaximumLineCount here; was on fixed number of five before
566             AdaptDropDownLineCountToMaximum();
567         }
568         else if ( !bAuto )
569         {
570             mpFloatWin->SetDropDownLineCount( 0 );
571         }
572     }
573 }
574 
575 // -----------------------------------------------------------------------
576 
577 void ComboBox::EnableDDAutoWidth( sal_Bool b )
578 {
579     if ( mpFloatWin )
580         mpFloatWin->SetAutoWidth( b );
581 }
582 
583  // -----------------------------------------------------------------------
584 
585 sal_Bool ComboBox::IsDDAutoWidthEnabled() const
586 {
587     return mpFloatWin ? mpFloatWin->IsAutoWidth() : sal_False;
588 }
589 
590 
591 // -----------------------------------------------------------------------
592 
593 void ComboBox::SetDropDownLineCount( sal_uInt16 nLines )
594 {
595     if ( mpFloatWin )
596         mpFloatWin->SetDropDownLineCount( nLines );
597 }
598 
599 // -----------------------------------------------------------------------
600 
601 void ComboBox::AdaptDropDownLineCountToMaximum()
602 {
603     // adapt to maximum allowed number
604     SetDropDownLineCount(std::min(GetEntryCount(), GetSettings().GetStyleSettings().GetListBoxMaximumLineCount()));
605 }
606 
607 // -----------------------------------------------------------------------
608 
609 sal_uInt16 ComboBox::GetDropDownLineCount() const
610 {
611     sal_uInt16 nLines = 0;
612     if ( mpFloatWin )
613         nLines = mpFloatWin->GetDropDownLineCount();
614     return nLines;
615 }
616 
617 // -----------------------------------------------------------------------
618 
619 void ComboBox::SetPosSizePixel( long nX, long nY, long nWidth, long nHeight,
620                                 sal_uInt16 nFlags )
621 {
622     if( IsDropDownBox() && ( nFlags & WINDOW_POSSIZE_SIZE ) )
623     {
624         Size aPrefSz = mpFloatWin->GetPrefSize();
625         if ( ( nFlags & WINDOW_POSSIZE_HEIGHT ) && ( nHeight >= 2*mnDDHeight ) )
626             aPrefSz.Height() = nHeight-mnDDHeight;
627         if ( nFlags & WINDOW_POSSIZE_WIDTH )
628             aPrefSz.Width() = nWidth;
629         mpFloatWin->SetPrefSize( aPrefSz );
630 
631         if ( IsAutoSizeEnabled() && ! (nFlags & WINDOW_POSSIZE_DROPDOWN) )
632             nHeight = mnDDHeight;
633     }
634 
635     Edit::SetPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
636 }
637 
638 // -----------------------------------------------------------------------
639 
640 void ComboBox::Resize()
641 {
642     Control::Resize();
643 
644     Size aOutSz = GetOutputSizePixel();
645     if( IsDropDownBox() )
646     {
647         long nSBWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
648         long    nTop = 0;
649         long    nBottom = aOutSz.Height();
650 
651         Window *pBorder = GetWindow( WINDOW_BORDER );
652         ImplControlValue aControlValue;
653         Point aPoint;
654         Rectangle aContent, aBound;
655 
656         // use the full extent of the control
657         Rectangle aArea( aPoint, pBorder->GetOutputSizePixel() );
658 
659         if ( GetNativeControlRegion(CTRL_COMBOBOX, PART_BUTTON_DOWN,
660                 aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
661         {
662             // convert back from border space to local coordinates
663             aPoint = pBorder->ScreenToOutputPixel( OutputToScreenPixel( aPoint ) );
664             aContent.Move(-aPoint.X(), -aPoint.Y());
665 
666             mpBtn->SetPosSizePixel( aContent.Left(), nTop, aContent.getWidth(), (nBottom-nTop) );
667 
668             // adjust the size of the edit field
669             if ( GetNativeControlRegion(CTRL_COMBOBOX, PART_SUB_EDIT,
670                         aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
671             {
672                 // convert back from border space to local coordinates
673                 aContent.Move(-aPoint.X(), -aPoint.Y());
674 
675                 // use the themes drop down size
676                 mpSubEdit->SetPosSizePixel( aContent.TopLeft(), aContent.GetSize() );
677             }
678             else
679             {
680                 // use the themes drop down size for the button
681                 aOutSz.Width() -= aContent.getWidth();
682                 mpSubEdit->SetSizePixel( aOutSz );
683             }
684         }
685         else
686         {
687             nSBWidth = CalcZoom( nSBWidth );
688             mpSubEdit->SetPosSizePixel( Point( 0, 0 ), Size( aOutSz.Width() - nSBWidth, aOutSz.Height() ) );
689             mpBtn->SetPosSizePixel( aOutSz.Width() - nSBWidth, nTop, nSBWidth, (nBottom-nTop) );
690         }
691     }
692     else
693     {
694         mpSubEdit->SetSizePixel( Size( aOutSz.Width(), mnDDHeight ) );
695         mpImplLB->SetPosSizePixel( 0, mnDDHeight, aOutSz.Width(), aOutSz.Height() - mnDDHeight );
696         if ( GetText().Len() )
697             ImplUpdateFloatSelection();
698     }
699 
700     // FloatingWindow-Groesse auch im unsichtbare Zustand auf Stand halten,
701     // weil KEY_PGUP/DOWN ausgewertet wird...
702     if ( mpFloatWin )
703         mpFloatWin->SetSizePixel( mpFloatWin->CalcFloatSize() );
704 }
705 
706 // -----------------------------------------------------------------------
707 
708 void ComboBox::FillLayoutData() const
709 {
710     mpControlData->mpLayoutData = new vcl::ControlLayoutData();
711     AppendLayoutData( *mpSubEdit );
712     mpSubEdit->SetLayoutDataParent( this );
713     Control* pMainWindow = mpImplLB->GetMainWindow();
714     if( mpFloatWin )
715     {
716         // dropdown mode
717         if( mpFloatWin->IsReallyVisible() )
718         {
719             AppendLayoutData( *pMainWindow );
720             pMainWindow->SetLayoutDataParent( this );
721         }
722     }
723     else
724     {
725         AppendLayoutData( *pMainWindow );
726         pMainWindow->SetLayoutDataParent( this );
727     }
728 }
729 
730 // -----------------------------------------------------------------------
731 
732 void ComboBox::StateChanged( StateChangedType nType )
733 {
734     Edit::StateChanged( nType );
735 
736     if ( nType == STATE_CHANGE_READONLY )
737     {
738         mpImplLB->SetReadOnly( IsReadOnly() );
739         if ( mpBtn )
740             mpBtn->Enable( IsEnabled() && !IsReadOnly() );
741     }
742     else if ( nType == STATE_CHANGE_ENABLE )
743     {
744         mpSubEdit->Enable( IsEnabled() );
745         mpImplLB->Enable( IsEnabled() && !IsReadOnly() );
746         if ( mpBtn )
747             mpBtn->Enable( IsEnabled() && !IsReadOnly() );
748         Invalidate();
749     }
750     else if( nType == STATE_CHANGE_UPDATEMODE )
751     {
752         mpImplLB->SetUpdateMode( IsUpdateMode() );
753     }
754     else if ( nType == STATE_CHANGE_ZOOM )
755     {
756         mpImplLB->SetZoom( GetZoom() );
757         mpSubEdit->SetZoom( GetZoom() );
758         ImplCalcEditHeight();
759         Resize();
760     }
761     else if ( nType == STATE_CHANGE_CONTROLFONT )
762     {
763         mpImplLB->SetControlFont( GetControlFont() );
764         mpSubEdit->SetControlFont( GetControlFont() );
765         ImplCalcEditHeight();
766         Resize();
767     }
768     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
769     {
770         mpImplLB->SetControlForeground( GetControlForeground() );
771         mpSubEdit->SetControlForeground( GetControlForeground() );
772     }
773     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
774     {
775         mpImplLB->SetControlBackground( GetControlBackground() );
776         mpSubEdit->SetControlBackground( GetControlBackground() );
777     }
778     else if ( nType == STATE_CHANGE_STYLE )
779     {
780         SetStyle( ImplInitStyle( GetStyle() ) );
781         mpImplLB->GetMainWindow()->EnableSort( ( GetStyle() & WB_SORT ) ? sal_True : sal_False );
782     }
783     else if( nType == STATE_CHANGE_MIRRORING )
784     {
785         if( mpBtn )
786         {
787             mpBtn->EnableRTL( IsRTLEnabled() );
788             ImplInitDropDownButton( mpBtn );
789         }
790         mpSubEdit->StateChanged( STATE_CHANGE_MIRRORING );
791         mpImplLB->EnableRTL( IsRTLEnabled() );
792         Resize();
793     }
794 }
795 
796 // -----------------------------------------------------------------------
797 
798 void ComboBox::DataChanged( const DataChangedEvent& rDCEvt )
799 {
800     Control::DataChanged( rDCEvt );
801 
802     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
803          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
804          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
805           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
806     {
807         if ( mpBtn )
808         {
809             mpBtn->SetSettings( GetSettings() );
810             ImplInitDropDownButton( mpBtn );
811         }
812         Resize();
813         mpImplLB->Resize(); // Wird nicht durch ComboBox::Resize() gerufen, wenn sich die ImplLB nicht aendert.
814         SetBackground();    // due to a hack in Window::UpdateSettings the background must be reset
815                             // otherwise it will overpaint NWF drawn comboboxes
816     }
817 }
818 
819 // -----------------------------------------------------------------------
820 
821 long ComboBox::PreNotify( NotifyEvent& rNEvt )
822 {
823 
824     return Edit::PreNotify( rNEvt );
825 }
826 
827 // -----------------------------------------------------------------------
828 
829 long ComboBox::Notify( NotifyEvent& rNEvt )
830 {
831     long nDone = 0;
832     if( ( rNEvt.GetType() == EVENT_KEYINPUT ) && ( rNEvt.GetWindow() == mpSubEdit )
833             && !IsReadOnly() )
834     {
835         KeyEvent aKeyEvt = *rNEvt.GetKeyEvent();
836         sal_uInt16   nKeyCode = aKeyEvt.GetKeyCode().GetCode();
837         switch( nKeyCode )
838         {
839             case KEY_UP:
840             case KEY_DOWN:
841             case KEY_PAGEUP:
842             case KEY_PAGEDOWN:
843             {
844                 ImplUpdateFloatSelection();
845                 if( ( nKeyCode == KEY_DOWN ) && mpFloatWin && !mpFloatWin->IsInPopupMode() && aKeyEvt.GetKeyCode().IsMod2() )
846                 {
847                     ImplCallEventListeners( VCLEVENT_DROPDOWN_PRE_OPEN );
848                     mpBtn->SetPressed( sal_True );
849                     if ( mpImplLB->GetEntryList()->GetMRUCount() )
850                         mpImplLB->SelectEntry( 0 , sal_True );
851                     SetSelection( Selection( 0, SELECTION_MAX ) );
852                     mpFloatWin->StartFloat( sal_False );
853                     ImplCallEventListeners( VCLEVENT_DROPDOWN_OPEN );
854                     nDone = 1;
855                 }
856                 else if( ( nKeyCode == KEY_UP ) && mpFloatWin && mpFloatWin->IsInPopupMode() && aKeyEvt.GetKeyCode().IsMod2() )
857                 {
858                     mpFloatWin->EndPopupMode();
859                     nDone = 1;
860                 }
861                 else
862                 {
863                     nDone = mpImplLB->ProcessKeyInput( aKeyEvt );
864                 }
865             }
866             break;
867 
868             case KEY_RETURN:
869             {
870                 if( ( rNEvt.GetWindow() == mpSubEdit ) && IsInDropDown() )
871                 {
872                     mpImplLB->ProcessKeyInput( aKeyEvt );
873                     nDone = 1;
874                 }
875             }
876             break;
877         }
878     }
879     else if ( (rNEvt.GetType() == EVENT_LOSEFOCUS) && mpFloatWin )
880     {
881         if( mpFloatWin->HasChildPathFocus() )
882             mpSubEdit->GrabFocus();
883         else if ( mpFloatWin->IsInPopupMode() && !HasChildPathFocus( sal_True ) )
884             mpFloatWin->EndPopupMode();
885     }
886     else if( (rNEvt.GetType() == EVENT_COMMAND) &&
887              (rNEvt.GetCommandEvent()->GetCommand() == COMMAND_WHEEL) &&
888              (rNEvt.GetWindow() == mpSubEdit) )
889     {
890         sal_uInt16 nWheelBehavior( GetSettings().GetMouseSettings().GetWheelBehavior() );
891         if  (   ( nWheelBehavior == MOUSE_WHEEL_ALWAYS )
892             ||  (   ( nWheelBehavior == MOUSE_WHEEL_FOCUS_ONLY )
893                 &&  HasChildPathFocus()
894                 )
895             )
896         {
897             nDone = mpImplLB->HandleWheelAsCursorTravel( *rNEvt.GetCommandEvent() );
898         }
899         else
900         {
901             nDone = 0;  // don't eat this event, let the default handling happen (i.e. scroll the context)
902         }
903     }
904     else if( ( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN ) && ( rNEvt.GetWindow() == mpImplLB->GetMainWindow() ) )
905     {
906         mpSubEdit->GrabFocus();
907     }
908 
909     return nDone ? nDone : Edit::Notify( rNEvt );
910 }
911 
912 // -----------------------------------------------------------------------
913 
914 void ComboBox::SetText( const XubString& rStr )
915 {
916     ImplCallEventListeners( VCLEVENT_COMBOBOX_SETTEXT );
917 
918     Edit::SetText( rStr );
919     ImplUpdateFloatSelection();
920 }
921 
922 // -----------------------------------------------------------------------
923 
924 void ComboBox::SetText( const XubString& rStr, const Selection& rNewSelection )
925 {
926     ImplCallEventListeners( VCLEVENT_COMBOBOX_SETTEXT );
927 
928     Edit::SetText( rStr, rNewSelection );
929     ImplUpdateFloatSelection();
930 }
931 
932 // -----------------------------------------------------------------------
933 
934 void ComboBox::Modify()
935 {
936     if ( !mbSyntheticModify )
937         ImplUpdateFloatSelection();
938 
939     Edit::Modify();
940 }
941 
942 // -----------------------------------------------------------------------
943 
944 void ComboBox::ImplUpdateFloatSelection()
945 {
946     // Text in der ListBox in den sichtbaren Bereich bringen
947     mpImplLB->SetCallSelectionChangedHdl( sal_False );
948     if ( !IsMultiSelectionEnabled() )
949     {
950         XubString   aSearchStr( mpSubEdit->GetText() );
951         sal_uInt16      nSelect = LISTBOX_ENTRY_NOTFOUND;
952         sal_Bool        bSelect = sal_True;
953 
954         if ( mpImplLB->GetCurrentPos() != LISTBOX_ENTRY_NOTFOUND )
955         {
956             XubString aCurrent = mpImplLB->GetEntryList()->GetEntryText( mpImplLB->GetCurrentPos() );
957             if ( aCurrent == aSearchStr )
958                 nSelect = mpImplLB->GetCurrentPos();
959         }
960 
961         if ( nSelect == LISTBOX_ENTRY_NOTFOUND )
962             nSelect = mpImplLB->GetEntryList()->FindEntry( aSearchStr );
963         if ( nSelect == LISTBOX_ENTRY_NOTFOUND )
964         {
965             nSelect = mpImplLB->GetEntryList()->FindMatchingEntry( aSearchStr );
966             bSelect = sal_False;
967         }
968 
969         if( nSelect != LISTBOX_ENTRY_NOTFOUND )
970         {
971             if ( !mpImplLB->IsVisible( nSelect ) )
972                 mpImplLB->ShowProminentEntry( nSelect );
973             mpImplLB->SelectEntry( nSelect, bSelect );
974         }
975         else
976         {
977             nSelect = mpImplLB->GetEntryList()->GetSelectEntryPos( 0 );
978             if( nSelect != LISTBOX_ENTRY_NOTFOUND )
979                 mpImplLB->SelectEntry( nSelect, sal_False );
980             mpImplLB->ResetCurrentPos();
981         }
982     }
983     else
984     {
985         Table aSelInText;
986         lcl_GetSelectedEntries( aSelInText, mpSubEdit->GetText(), mcMultiSep, mpImplLB->GetEntryList() );
987         for ( sal_uInt16 n = 0; n < mpImplLB->GetEntryList()->GetEntryCount(); n++ )
988             mpImplLB->SelectEntry( n, aSelInText.IsKeyValid( ImplCreateKey( n ) ) );
989     }
990     mpImplLB->SetCallSelectionChangedHdl( sal_True );
991 }
992 
993 // -----------------------------------------------------------------------
994 
995 sal_uInt16 ComboBox::InsertEntry( const XubString& rStr, sal_uInt16 nPos )
996 {
997     sal_uInt16 nRealPos = mpImplLB->InsertEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), rStr );
998     nRealPos = sal::static_int_cast<sal_uInt16>(nRealPos - mpImplLB->GetEntryList()->GetMRUCount());
999     CallEventListeners( VCLEVENT_COMBOBOX_ITEMADDED, (void*) sal_IntPtr(nRealPos) );
1000     return nRealPos;
1001 }
1002 
1003 // -----------------------------------------------------------------------
1004 
1005 sal_uInt16 ComboBox::InsertEntry( const XubString& rStr, const Image& rImage, sal_uInt16 nPos )
1006 {
1007     sal_uInt16 nRealPos = mpImplLB->InsertEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), rStr, rImage );
1008     nRealPos = sal::static_int_cast<sal_uInt16>(nRealPos - mpImplLB->GetEntryList()->GetMRUCount());
1009     CallEventListeners( VCLEVENT_COMBOBOX_ITEMADDED, (void*) sal_IntPtr(nRealPos) );
1010     return nRealPos;
1011 }
1012 
1013 // -----------------------------------------------------------------------
1014 
1015 void ComboBox::RemoveEntry( const XubString& rStr )
1016 {
1017     RemoveEntry( GetEntryPos( rStr ) );
1018 }
1019 
1020 // -----------------------------------------------------------------------
1021 
1022 void ComboBox::RemoveEntry( sal_uInt16 nPos )
1023 {
1024     mpImplLB->RemoveEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1025     CallEventListeners( VCLEVENT_COMBOBOX_ITEMREMOVED, (void*) sal_IntPtr(nPos) );
1026 }
1027 
1028 // -----------------------------------------------------------------------
1029 
1030 void ComboBox::Clear()
1031 {
1032     mpImplLB->Clear();
1033     CallEventListeners( VCLEVENT_COMBOBOX_ITEMREMOVED, (void*) sal_IntPtr(-1) );
1034 }
1035 // -----------------------------------------------------------------------
1036 
1037 Image ComboBox::GetEntryImage( sal_uInt16 nPos ) const
1038 {
1039     if ( mpImplLB->GetEntryList()->HasEntryImage( nPos ) )
1040         return mpImplLB->GetEntryList()->GetEntryImage( nPos );
1041     return Image();
1042 }
1043 
1044 // -----------------------------------------------------------------------
1045 
1046 sal_uInt16 ComboBox::GetEntryPos( const XubString& rStr ) const
1047 {
1048     sal_uInt16 nPos = mpImplLB->GetEntryList()->FindEntry( rStr );
1049     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1050         nPos = sal::static_int_cast<sal_uInt16>(nPos - mpImplLB->GetEntryList()->GetMRUCount());
1051     return nPos;
1052 }
1053 
1054 // -----------------------------------------------------------------------
1055 
1056 sal_uInt16 ComboBox::GetEntryPos( const void* pData ) const
1057 {
1058     sal_uInt16 nPos = mpImplLB->GetEntryList()->FindEntry( pData );
1059     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1060         nPos = sal::static_int_cast<sal_uInt16>(nPos - mpImplLB->GetEntryList()->GetMRUCount());
1061     return nPos;
1062 }
1063 
1064 // -----------------------------------------------------------------------
1065 
1066 XubString ComboBox::GetEntry( sal_uInt16 nPos ) const
1067 {
1068     return mpImplLB->GetEntryList()->GetEntryText( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1069 }
1070 
1071 // -----------------------------------------------------------------------
1072 
1073 sal_uInt16 ComboBox::GetEntryCount() const
1074 {
1075     return mpImplLB->GetEntryList()->GetEntryCount() - mpImplLB->GetEntryList()->GetMRUCount();
1076 }
1077 
1078 // -----------------------------------------------------------------------
1079 
1080 sal_Bool ComboBox::IsTravelSelect() const
1081 {
1082     return mpImplLB->IsTravelSelect();
1083 }
1084 
1085 // -----------------------------------------------------------------------
1086 
1087 sal_Bool ComboBox::IsInDropDown() const
1088 {
1089     return mpFloatWin && mpFloatWin->IsInPopupMode();
1090 }
1091 
1092 // -----------------------------------------------------------------------
1093 
1094 void ComboBox::EnableMultiSelection( sal_Bool bMulti )
1095 {
1096     mpImplLB->EnableMultiSelection( bMulti, sal_False );
1097     mpImplLB->SetMultiSelectionSimpleMode( sal_True );
1098 }
1099 
1100 // -----------------------------------------------------------------------
1101 
1102 sal_Bool ComboBox::IsMultiSelectionEnabled() const
1103 {
1104     return mpImplLB->IsMultiSelectionEnabled();
1105 }
1106 
1107 // -----------------------------------------------------------------------
1108 
1109 long ComboBox::CalcWindowSizePixel( sal_uInt16 nLines ) const
1110 {
1111     return mpImplLB->GetEntryHeight() * nLines;
1112 }
1113 
1114 // -----------------------------------------------------------------------
1115 
1116 Size ComboBox::GetOptimalSize(WindowSizeType eType) const
1117 {
1118     switch (eType) {
1119     case WINDOWSIZE_MINIMUM:
1120         return CalcMinimumSize();
1121     default:
1122         return Edit::GetOptimalSize( eType );
1123     }
1124 }
1125 
1126 // -----------------------------------------------------------------------
1127 
1128 Size ComboBox::CalcMinimumSize() const
1129 {
1130     Size aSz;
1131     if ( !IsDropDownBox() )
1132     {
1133         aSz = mpImplLB->CalcSize( mpImplLB->GetEntryList()->GetEntryCount() );
1134         aSz.Height() += mnDDHeight;
1135     }
1136     else
1137     {
1138         aSz.Height() = mpImplLB->CalcSize( 1 ).Height();
1139         aSz.Width() = mpImplLB->GetMaxEntryWidth();
1140         aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize();
1141     }
1142 
1143     aSz = CalcWindowSize( aSz );
1144     return aSz;
1145 }
1146 
1147 // -----------------------------------------------------------------------
1148 
1149 Size ComboBox::CalcAdjustedSize( const Size& rPrefSize ) const
1150 {
1151     Size aSz = rPrefSize;
1152     sal_Int32 nLeft, nTop, nRight, nBottom;
1153     ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
1154     aSz.Height() -= nTop+nBottom;
1155     if ( !IsDropDownBox() )
1156     {
1157         long nEntryHeight = CalcSize( 1, 1 ).Height();
1158         long nLines = aSz.Height() / nEntryHeight;
1159         if ( nLines < 1 )
1160             nLines = 1;
1161         aSz.Height() = nLines * nEntryHeight;
1162         aSz.Height() += mnDDHeight;
1163     }
1164     else
1165     {
1166         aSz.Height() = mnDDHeight;
1167     }
1168     aSz.Height() += nTop+nBottom;
1169 
1170     aSz = CalcWindowSize( aSz );
1171     return aSz;
1172 }
1173 
1174 // -----------------------------------------------------------------------
1175 
1176 Size ComboBox::CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const
1177 {
1178     // ggf. werden ScrollBars eingeblendet
1179     Size aMinSz = CalcMinimumSize();
1180     Size aSz;
1181 
1182     // Hoehe
1183     if ( nLines )
1184     {
1185         if ( !IsDropDownBox() )
1186             aSz.Height() = mpImplLB->CalcSize( nLines ).Height() + mnDDHeight;
1187         else
1188             aSz.Height() = mnDDHeight;
1189     }
1190     else
1191         aSz.Height() = aMinSz.Height();
1192 
1193     // Breite
1194     if ( nColumns )
1195         aSz.Width() = nColumns * GetTextWidth( UniString( 'X' ) );
1196     else
1197         aSz.Width() = aMinSz.Width();
1198 
1199     if ( IsDropDownBox() )
1200         aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize();
1201 
1202     if ( !IsDropDownBox() )
1203     {
1204         if ( aSz.Width() < aMinSz.Width() )
1205             aSz.Height() += GetSettings().GetStyleSettings().GetScrollBarSize();
1206         if ( aSz.Height() < aMinSz.Height() )
1207             aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize();
1208     }
1209 
1210     aSz = CalcWindowSize( aSz );
1211     return aSz;
1212 }
1213 
1214 // -----------------------------------------------------------------------
1215 
1216 void ComboBox::GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const
1217 {
1218     long nCharWidth = GetTextWidth( UniString( 'x' ) );
1219     if ( !IsDropDownBox() )
1220     {
1221         Size aOutSz = mpImplLB->GetMainWindow()->GetOutputSizePixel();
1222         rnCols = (sal_uInt16)(aOutSz.Width()/nCharWidth);
1223         rnLines = (sal_uInt16)(aOutSz.Height()/mpImplLB->GetEntryHeight());
1224     }
1225     else
1226     {
1227         Size aOutSz = mpSubEdit->GetOutputSizePixel();
1228         rnCols = (sal_uInt16)(aOutSz.Width()/nCharWidth);
1229         rnLines = 1;
1230     }
1231 }
1232 
1233 // -----------------------------------------------------------------------
1234 
1235 void ComboBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags )
1236 {
1237     mpImplLB->GetMainWindow()->ImplInitSettings( sal_True, sal_True, sal_True );
1238 
1239     Point aPos = pDev->LogicToPixel( rPos );
1240     Size aSize = pDev->LogicToPixel( rSize );
1241     Font aFont = mpImplLB->GetMainWindow()->GetDrawPixelFont( pDev );
1242     OutDevType eOutDevType = pDev->GetOutDevType();
1243 
1244     pDev->Push();
1245     pDev->SetMapMode();
1246     pDev->SetFont( aFont );
1247     pDev->SetTextFillColor();
1248 
1249     // Border/Background
1250     pDev->SetLineColor();
1251     pDev->SetFillColor();
1252     sal_Bool bBorder = !(nFlags & WINDOW_DRAW_NOBORDER ) && (GetStyle() & WB_BORDER);
1253     sal_Bool bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && IsControlBackground();
1254     if ( bBorder || bBackground )
1255     {
1256         Rectangle aRect( aPos, aSize );
1257         // aRect.Top() += nEditHeight;
1258         if ( bBorder )
1259         {
1260             ImplDrawFrame( pDev, aRect );
1261         }
1262         if ( bBackground )
1263         {
1264             pDev->SetFillColor( GetControlBackground() );
1265             pDev->DrawRect( aRect );
1266         }
1267     }
1268 
1269     // Inhalt
1270     if ( !IsDropDownBox() )
1271     {
1272         long        nOnePixel = GetDrawPixel( pDev, 1 );
1273         long        nTextHeight = pDev->GetTextHeight();
1274         long        nEditHeight = nTextHeight + 6*nOnePixel;
1275         sal_uInt16      nTextStyle = TEXT_DRAW_VCENTER;
1276 
1277         // First, draw the edit part
1278         mpSubEdit->Draw( pDev, aPos, Size( aSize.Width(), nEditHeight ), nFlags );
1279 
1280         // Second, draw the listbox
1281         if ( GetStyle() & WB_CENTER )
1282             nTextStyle |= TEXT_DRAW_CENTER;
1283         else if ( GetStyle() & WB_RIGHT )
1284             nTextStyle |= TEXT_DRAW_RIGHT;
1285         else
1286             nTextStyle |= TEXT_DRAW_LEFT;
1287 
1288         if ( ( nFlags & WINDOW_DRAW_MONO ) || ( eOutDevType == OUTDEV_PRINTER ) )
1289         {
1290             pDev->SetTextColor( Color( COL_BLACK ) );
1291         }
1292         else
1293         {
1294             if ( !(nFlags & WINDOW_DRAW_NODISABLE ) && !IsEnabled() )
1295             {
1296                 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1297                 pDev->SetTextColor( rStyleSettings.GetDisableColor() );
1298             }
1299             else
1300             {
1301                 pDev->SetTextColor( GetTextColor() );
1302             }
1303         }
1304 
1305         Rectangle aClip( aPos, aSize );
1306         pDev->IntersectClipRegion( aClip );
1307         sal_uInt16 nLines = (sal_uInt16) ( (aSize.Height()-nEditHeight) / nTextHeight );
1308         if ( !nLines )
1309             nLines = 1;
1310         sal_uInt16 nTEntry = IsReallyVisible() ? mpImplLB->GetTopEntry() : 0;
1311 
1312         Rectangle aTextRect( aPos, aSize );
1313 
1314         aTextRect.Left() += 3*nOnePixel;
1315         aTextRect.Right() -= 3*nOnePixel;
1316         aTextRect.Top() += nEditHeight + nOnePixel;
1317         aTextRect.Bottom() = aTextRect.Top() + nTextHeight;
1318 
1319         // the drawing starts here
1320         for ( sal_uInt16 n = 0; n < nLines; n++ )
1321         {
1322             pDev->DrawText( aTextRect, mpImplLB->GetEntryList()->GetEntryText( n+nTEntry ), nTextStyle );
1323             aTextRect.Top() += nTextHeight;
1324             aTextRect.Bottom() += nTextHeight;
1325         }
1326     }
1327 
1328     pDev->Pop();
1329 
1330     // Call Edit::Draw after restoring the MapMode...
1331     if ( IsDropDownBox() )
1332     {
1333         mpSubEdit->Draw( pDev, rPos, rSize, nFlags );
1334         // DD-Button ?
1335     }
1336 
1337 }
1338 
1339 // -----------------------------------------------------------------------
1340 
1341 IMPL_LINK( ComboBox, ImplUserDrawHdl, UserDrawEvent*, pEvent )
1342 {
1343     UserDraw( *pEvent );
1344     return 1;
1345 }
1346 
1347 // -----------------------------------------------------------------------
1348 
1349 void ComboBox::UserDraw( const UserDrawEvent& )
1350 {
1351 }
1352 
1353 // -----------------------------------------------------------------------
1354 
1355 void ComboBox::SetUserItemSize( const Size& rSz )
1356 {
1357     mpImplLB->GetMainWindow()->SetUserItemSize( rSz );
1358 }
1359 
1360 // -----------------------------------------------------------------------
1361 
1362 const Size& ComboBox::GetUserItemSize() const
1363 {
1364     return mpImplLB->GetMainWindow()->GetUserItemSize();
1365 }
1366 
1367 // -----------------------------------------------------------------------
1368 
1369 void ComboBox::EnableUserDraw( sal_Bool bUserDraw )
1370 {
1371     mpImplLB->GetMainWindow()->EnableUserDraw( bUserDraw );
1372 }
1373 
1374 // -----------------------------------------------------------------------
1375 
1376 sal_Bool ComboBox::IsUserDrawEnabled() const
1377 {
1378     return mpImplLB->GetMainWindow()->IsUserDrawEnabled();
1379 }
1380 
1381 // -----------------------------------------------------------------------
1382 
1383 void ComboBox::DrawEntry( const UserDrawEvent& rEvt, sal_Bool bDrawImage, sal_Bool bDrawText, sal_Bool bDrawTextAtImagePos )
1384 {
1385     DBG_ASSERT( rEvt.GetDevice() == mpImplLB->GetMainWindow(), "DrawEntry?!" );
1386     mpImplLB->GetMainWindow()->DrawEntry( rEvt.GetItemId(), bDrawImage, bDrawText, bDrawTextAtImagePos );
1387 }
1388 
1389 // -----------------------------------------------------------------------
1390 
1391 void ComboBox::SetSeparatorPos( sal_uInt16 n )
1392 {
1393     mpImplLB->SetSeparatorPos( n );
1394 }
1395 
1396 // -----------------------------------------------------------------------
1397 
1398 void ComboBox::SetSeparatorPos()
1399 {
1400     mpImplLB->SetSeparatorPos( LISTBOX_ENTRY_NOTFOUND );
1401 }
1402 
1403 // -----------------------------------------------------------------------
1404 
1405 sal_uInt16 ComboBox::GetSeparatorPos() const
1406 {
1407     return mpImplLB->GetSeparatorPos();
1408 }
1409 
1410 // -----------------------------------------------------------------------
1411 
1412 void ComboBox::SetMRUEntries( const XubString& rEntries, xub_Unicode cSep )
1413 {
1414     mpImplLB->SetMRUEntries( rEntries, cSep );
1415 }
1416 
1417 // -----------------------------------------------------------------------
1418 
1419 XubString ComboBox::GetMRUEntries( xub_Unicode cSep ) const
1420 {
1421     return mpImplLB->GetMRUEntries( cSep );
1422 }
1423 
1424 // -----------------------------------------------------------------------
1425 
1426 void ComboBox::SetMaxMRUCount( sal_uInt16 n )
1427 {
1428     mpImplLB->SetMaxMRUCount( n );
1429 }
1430 
1431 // -----------------------------------------------------------------------
1432 
1433 sal_uInt16 ComboBox::GetMaxMRUCount() const
1434 {
1435     return mpImplLB->GetMaxMRUCount();
1436 }
1437 
1438 //IAccessibility2 Implementation 2009-----
1439 sal_uInt16 ComboBox::GetMRUCount() const
1440 {
1441     return mpImplLB->GetEntryList()->GetMRUCount();
1442 }
1443 //-----IAccessibility2 Implementation 2009
1444 // -----------------------------------------------------------------------
1445 
1446 sal_uInt16 ComboBox::GetDisplayLineCount() const
1447 {
1448     return mpImplLB->GetDisplayLineCount();
1449 }
1450 
1451 // -----------------------------------------------------------------------
1452 
1453 void ComboBox::SetEntryData( sal_uInt16 nPos, void* pNewData )
1454 {
1455     mpImplLB->SetEntryData( nPos + mpImplLB->GetEntryList()->GetMRUCount(), pNewData );
1456 }
1457 
1458 // -----------------------------------------------------------------------
1459 
1460 void* ComboBox::GetEntryData( sal_uInt16 nPos ) const
1461 {
1462     return mpImplLB->GetEntryList()->GetEntryData( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1463 }
1464 
1465 // -----------------------------------------------------------------------
1466 
1467 void ComboBox::SetTopEntry( sal_uInt16 nPos )
1468 {
1469     mpImplLB->SetTopEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1470 }
1471 
1472 // -----------------------------------------------------------------------
1473 
1474 void ComboBox::ShowProminentEntry( sal_uInt16 nPos )
1475 {
1476     mpImplLB->ShowProminentEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1477 }
1478 
1479 // -----------------------------------------------------------------------
1480 
1481 sal_uInt16 ComboBox::GetTopEntry() const
1482 {
1483     sal_uInt16 nPos = GetEntryCount() ? mpImplLB->GetTopEntry() : LISTBOX_ENTRY_NOTFOUND;
1484     if ( nPos < mpImplLB->GetEntryList()->GetMRUCount() )
1485         nPos = 0;
1486     return nPos;
1487 }
1488 
1489 // -----------------------------------------------------------------------
1490 
1491 void ComboBox::SetProminentEntryType( ProminentEntry eType )
1492 {
1493     mpImplLB->SetProminentEntryType( eType );
1494 }
1495 
1496 // -----------------------------------------------------------------------
1497 
1498 ProminentEntry ComboBox::GetProminentEntryType() const
1499 {
1500     return mpImplLB->GetProminentEntryType();
1501 }
1502 
1503 // -----------------------------------------------------------------------
1504 
1505 Rectangle ComboBox::GetDropDownPosSizePixel() const
1506 {
1507     return mpFloatWin ? mpFloatWin->GetWindowExtentsRelative( const_cast<ComboBox*>(this) ) : Rectangle();
1508 }
1509 
1510 // -----------------------------------------------------------------------
1511 
1512 Rectangle ComboBox::GetListPosSizePixel() const
1513 {
1514     return mpFloatWin ? Rectangle() : mpImplLB->GetMainWindow()->GetWindowExtentsRelative( const_cast<ComboBox*>(this) );
1515 }
1516 
1517 // -----------------------------------------------------------------------
1518 
1519 const Wallpaper& ComboBox::GetDisplayBackground() const
1520 {
1521     if( ! mpSubEdit->IsBackground() )
1522         return Control::GetDisplayBackground();
1523 
1524     const Wallpaper& rBack = mpSubEdit->GetBackground();
1525     if( ! rBack.IsBitmap() &&
1526         ! rBack.IsGradient() &&
1527         rBack.GetColor().GetColor() == COL_TRANSPARENT
1528         )
1529         return Control::GetDisplayBackground();
1530     return rBack;
1531 }
1532 // -----------------------------------------------------------------------------
1533 sal_uInt16 ComboBox::GetSelectEntryCount() const
1534 {
1535     return mpImplLB->GetEntryList()->GetSelectEntryCount();
1536 }
1537 // -----------------------------------------------------------------------------
1538 sal_uInt16 ComboBox::GetSelectEntryPos( sal_uInt16 nIndex ) const
1539 {
1540     sal_uInt16 nPos = mpImplLB->GetEntryList()->GetSelectEntryPos( nIndex );
1541     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1542     {
1543         if ( nPos < mpImplLB->GetEntryList()->GetMRUCount() )
1544             nPos = mpImplLB->GetEntryList()->FindEntry( mpImplLB->GetEntryList()->GetEntryText( nPos ) );
1545         nPos = sal::static_int_cast<sal_uInt16>(nPos - mpImplLB->GetEntryList()->GetMRUCount());
1546     }
1547     return nPos;
1548 }
1549 // -----------------------------------------------------------------------------
1550 sal_Bool ComboBox::IsEntryPosSelected( sal_uInt16 nPos ) const
1551 {
1552     return mpImplLB->GetEntryList()->IsEntryPosSelected( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1553 }
1554 // -----------------------------------------------------------------------------
1555 void ComboBox::SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect)
1556 {
1557     if ( nPos < mpImplLB->GetEntryList()->GetEntryCount() )
1558         mpImplLB->SelectEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), bSelect );
1559 }
1560 // -----------------------------------------------------------------------------
1561 void ComboBox::SetNoSelection()
1562 {
1563     mpImplLB->SetNoSelection();
1564     mpSubEdit->SetText( String() );
1565 }
1566 // -----------------------------------------------------------------------------
1567 Rectangle ComboBox::GetBoundingRectangle( sal_uInt16 nItem ) const
1568 {
1569     Rectangle aRect = mpImplLB->GetMainWindow()->GetBoundingRectangle( nItem );
1570     Rectangle aOffset = mpImplLB->GetMainWindow()->GetWindowExtentsRelative( (Window*)this );
1571     aRect.Move( aOffset.TopLeft().X(), aOffset.TopLeft().Y() );
1572     return aRect;
1573 }
1574 // -----------------------------------------------------------------------------
1575 
1576 void ComboBox::SetBorderStyle( sal_uInt16 nBorderStyle )
1577 {
1578     Window::SetBorderStyle( nBorderStyle );
1579     if ( !IsDropDownBox() )
1580     {
1581         mpSubEdit->SetBorderStyle( nBorderStyle );
1582         mpImplLB->SetBorderStyle( nBorderStyle );
1583     }
1584 }
1585 // -----------------------------------------------------------------------------
1586 
1587 long ComboBox::GetIndexForPoint( const Point& rPoint, sal_uInt16& rPos ) const
1588 {
1589     if( !HasLayoutData() )
1590         FillLayoutData();
1591 
1592     // check whether rPoint fits at all
1593     long nIndex = Control::GetIndexForPoint( rPoint );
1594     if( nIndex != -1 )
1595     {
1596         // point must be either in main list window
1597         // or in impl window (dropdown case)
1598         ImplListBoxWindow* pMain = mpImplLB->GetMainWindow();
1599 
1600         // convert coordinates to ImplListBoxWindow pixel coordinate space
1601         Point aConvPoint = LogicToPixel( rPoint );
1602         aConvPoint = OutputToAbsoluteScreenPixel( aConvPoint );
1603         aConvPoint = pMain->AbsoluteScreenToOutputPixel( aConvPoint );
1604         aConvPoint = pMain->PixelToLogic( aConvPoint );
1605 
1606         // try to find entry
1607         sal_uInt16 nEntry = pMain->GetEntryPosForPoint( aConvPoint );
1608         if( nEntry == LISTBOX_ENTRY_NOTFOUND )
1609             nIndex = -1;
1610         else
1611             rPos = nEntry;
1612     }
1613 
1614     // get line relative index
1615     if( nIndex != -1 )
1616         nIndex = ToRelativeLineIndex( nIndex );
1617 
1618     return nIndex;
1619 }
1620