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