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