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