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