Update ooo320-m1
[ooovba.git] / vcl / source / control / lstbox.cxx
blob62822aba80e36edeb4cbc25053de681148170526
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lstbox.cxx,v $
10 * $Revision: 1.43 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include "tools/rc.h"
36 #include "vcl/svdata.hxx"
37 #include "vcl/decoview.hxx"
38 #include "vcl/event.hxx"
39 #include "vcl/scrbar.hxx"
40 #include "vcl/button.hxx"
41 #include "vcl/edit.hxx"
42 #include "vcl/subedit.hxx"
43 #include "vcl/ilstbox.hxx"
44 #include "vcl/lstbox.hxx"
45 #include "vcl/combobox.hxx"
46 #include "vcl/controllayout.hxx"
48 #include "tools/debug.hxx"
52 \f// =======================================================================
54 ListBox::ListBox( WindowType nType ) : Control( nType )
56 ImplInitListBoxData();
59 // -----------------------------------------------------------------------
61 ListBox::ListBox( Window* pParent, WinBits nStyle ) : Control( WINDOW_LISTBOX )
63 ImplInitListBoxData();
64 ImplInit( pParent, nStyle );
67 // -----------------------------------------------------------------------
69 ListBox::ListBox( Window* pParent, const ResId& rResId ) :
70 Control( WINDOW_LISTBOX )
72 ImplInitListBoxData();
73 rResId.SetRT( RSC_LISTBOX );
74 WinBits nStyle = ImplInitRes( rResId );
75 ImplInit( pParent, nStyle );
76 ImplLoadRes( rResId );
78 if ( !(nStyle & WB_HIDE ) )
79 Show();
82 // -----------------------------------------------------------------------
84 ListBox::~ListBox()
86 //#109201#
87 ImplCallEventListeners( VCLEVENT_OBJECT_DYING );
89 delete mpImplLB;
91 // Beim zerstoeren des FloatWins macht TH ein GrabFocus auf den Parent,
92 // also diese ListBox => PreNotify()...
93 mpImplLB = NULL;
95 delete mpFloatWin;
96 delete mpImplWin;
97 delete mpBtn;
100 // -----------------------------------------------------------------------
102 void ListBox::ImplInitListBoxData()
104 mpFloatWin = NULL;
105 mpImplWin = NULL;
106 mpBtn = NULL;
108 mnDDHeight = 0;
109 mbDDAutoSize = TRUE;
110 mnSaveValue = LISTBOX_ENTRY_NOTFOUND;
113 // -----------------------------------------------------------------------
115 void ListBox::ImplInit( Window* pParent, WinBits nStyle )
117 nStyle = ImplInitStyle( nStyle );
118 if ( !(nStyle & WB_NOBORDER) && ( nStyle & WB_DROPDOWN ) )
119 nStyle |= WB_BORDER;
121 Control::ImplInit( pParent, nStyle, NULL );
122 SetBackground();
124 if( nStyle & WB_DROPDOWN )
126 sal_Int32 nLeft, nTop, nRight, nBottom;
127 GetBorder( nLeft, nTop, nRight, nBottom );
128 mnDDHeight = (USHORT)(GetTextHeight() + nTop + nBottom + 4);
130 if( IsNativeWidgetEnabled() &&
131 IsNativeControlSupported( CTRL_LISTBOX, PART_ENTIRE_CONTROL ) )
133 ImplControlValue aControlValue;
134 Region aCtrlRegion( Rectangle( (const Point&)Point(), Size( 20, mnDDHeight ) ) );
135 Region aBoundingRgn( aCtrlRegion );
136 Region aContentRgn( aCtrlRegion );
137 if( GetNativeControlRegion( CTRL_LISTBOX, PART_ENTIRE_CONTROL, aCtrlRegion,
138 CTRL_STATE_ENABLED, aControlValue, rtl::OUString(),
139 aBoundingRgn, aContentRgn ) )
141 sal_Int32 nHeight = aBoundingRgn.GetBoundRect().GetHeight();
142 if( nHeight > mnDDHeight )
143 mnDDHeight = static_cast<USHORT>(nHeight);
147 mpFloatWin = new ImplListBoxFloatingWindow( this );
148 mpFloatWin->SetAutoWidth( TRUE );
149 mpFloatWin->SetPopupModeEndHdl( LINK( this, ListBox, ImplPopupModeEndHdl ) );
151 mpImplWin = new ImplWin( this, (nStyle & (WB_LEFT|WB_RIGHT|WB_CENTER))|WB_NOBORDER );
152 mpImplWin->SetMBDownHdl( LINK( this, ListBox, ImplClickBtnHdl ) );
153 mpImplWin->SetUserDrawHdl( LINK( this, ListBox, ImplUserDrawHdl ) );
154 mpImplWin->Show();
156 mpBtn = new ImplBtn( this, WB_NOLIGHTBORDER | WB_RECTSTYLE );
157 ImplInitDropDownButton( mpBtn );
158 mpBtn->SetMBDownHdl( LINK( this, ListBox, ImplClickBtnHdl ) );
159 mpBtn->Show();
163 Window* pLBParent = this;
164 if ( mpFloatWin )
165 pLBParent = mpFloatWin;
166 mpImplLB = new ImplListBox( pLBParent, nStyle&(~WB_BORDER) );
167 mpImplLB->SetSelectHdl( LINK( this, ListBox, ImplSelectHdl ) );
168 mpImplLB->SetScrollHdl( LINK( this, ListBox, ImplScrollHdl ) );
169 mpImplLB->SetCancelHdl( LINK( this, ListBox, ImplCancelHdl ) );
170 mpImplLB->SetDoubleClickHdl( LINK( this, ListBox, ImplDoubleClickHdl ) );
171 mpImplLB->SetUserDrawHdl( LINK( this, ListBox, ImplUserDrawHdl ) );
172 mpImplLB->SetPosPixel( Point() );
173 mpImplLB->Show();
175 if ( mpFloatWin )
177 mpFloatWin->SetImplListBox( mpImplLB );
178 mpImplLB->SetSelectionChangedHdl( LINK( this, ListBox, ImplSelectionChangedHdl ) );
180 else
181 mpImplLB->GetMainWindow()->AllowGrabFocus( TRUE );
183 SetCompoundControl( TRUE );
186 // -----------------------------------------------------------------------
188 WinBits ListBox::ImplInitStyle( WinBits nStyle )
190 if ( !(nStyle & WB_NOTABSTOP) )
191 nStyle |= WB_TABSTOP;
192 if ( !(nStyle & WB_NOGROUP) )
193 nStyle |= WB_GROUP;
194 return nStyle;
197 // -----------------------------------------------------------------------
199 void ListBox::ImplLoadRes( const ResId& rResId )
201 Control::ImplLoadRes( rResId );
203 USHORT nSelPos = ReadShortRes();
204 USHORT nNumber = sal::static_int_cast<USHORT>(ReadLongRes());
206 for( USHORT i = 0; i < nNumber; i++ )
208 USHORT nPos = InsertEntry( ReadStringRes(), LISTBOX_APPEND );
210 long nId = ReadLongRes();
211 if( nId )
212 SetEntryData( nPos, (void *)nId ); // ID als UserData
215 if( nSelPos < nNumber )
216 SelectEntryPos( nSelPos );
219 // -----------------------------------------------------------------------
221 IMPL_LINK( ListBox, ImplSelectHdl, void*, EMPTYARG )
223 BOOL bPopup = IsInDropDown();
224 if( IsDropDownBox() )
226 if( !mpImplLB->IsTravelSelect() )
228 mpFloatWin->EndPopupMode();
229 mpImplWin->GrabFocus();
232 mpImplWin->SetItemPos( GetSelectEntryPos() );
233 mpImplWin->SetString( GetSelectEntry() );
234 if( mpImplLB->GetEntryList()->HasImages() )
236 Image aImage = mpImplLB->GetEntryList()->GetEntryImage( GetSelectEntryPos() );
237 mpImplWin->SetImage( aImage );
239 mpImplWin->Invalidate();
242 if ( ( !IsTravelSelect() || mpImplLB->IsSelectionChanged() ) || ( bPopup && !IsMultiSelectionEnabled() ) )
243 Select();
245 return 1;
248 // -----------------------------------------------------------------------
250 IMPL_LINK( ListBox, ImplScrollHdl, void*, EMPTYARG )
252 ImplCallEventListeners( VCLEVENT_LISTBOX_SCROLLED );
253 return 1;
256 // -----------------------------------------------------------------------
258 IMPL_LINK( ListBox, ImplCancelHdl, void*, EMPTYARG )
260 if( IsInDropDown() )
261 mpFloatWin->EndPopupMode();
263 return 1;
266 // -----------------------------------------------------------------------
268 IMPL_LINK( ListBox, ImplSelectionChangedHdl, void*, n )
270 if ( !mpImplLB->IsTrackingSelect() )
272 USHORT nChanged = (USHORT)(ULONG)n;
273 const ImplEntryList* pEntryList = mpImplLB->GetEntryList();
274 if ( pEntryList->IsEntryPosSelected( nChanged ) )
276 // Sollte mal ein ImplPaintEntry werden...
277 if ( nChanged < pEntryList->GetMRUCount() )
278 nChanged = pEntryList->FindEntry( pEntryList->GetEntryText( nChanged ) );
279 mpImplWin->SetItemPos( nChanged );
280 mpImplWin->SetString( mpImplLB->GetEntryList()->GetEntryText( nChanged ) );
281 if( mpImplLB->GetEntryList()->HasImages() )
283 Image aImage = mpImplLB->GetEntryList()->GetEntryImage( nChanged );
284 mpImplWin->SetImage( aImage );
286 mpImplWin->Invalidate();
289 return 1;
292 // -----------------------------------------------------------------------
294 IMPL_LINK( ListBox, ImplDoubleClickHdl, void*, EMPTYARG )
296 DoubleClick();
297 return 1;
300 // -----------------------------------------------------------------------
302 IMPL_LINK( ListBox, ImplClickBtnHdl, void*, EMPTYARG )
304 if( !mpFloatWin->IsInPopupMode() )
306 ImplCallEventListeners( VCLEVENT_DROPDOWN_PRE_OPEN );
307 mpImplWin->GrabFocus();
308 mpBtn->SetPressed( TRUE );
309 mpFloatWin->StartFloat( TRUE );
310 ImplCallEventListeners( VCLEVENT_DROPDOWN_OPEN );
312 ImplClearLayoutData();
313 if( mpImplLB )
314 mpImplLB->GetMainWindow()->ImplClearLayoutData();
315 if( mpImplWin )
316 mpImplWin->ImplClearLayoutData();
319 return 0;
322 // -----------------------------------------------------------------------
324 IMPL_LINK( ListBox, ImplPopupModeEndHdl, void*, EMPTYARG )
326 if( mpFloatWin->IsPopupModeCanceled() )
328 if ( ( mpFloatWin->GetPopupModeStartSaveSelection() != LISTBOX_ENTRY_NOTFOUND )
329 && !IsEntryPosSelected( mpFloatWin->GetPopupModeStartSaveSelection() ) )
331 mpImplLB->SelectEntry( mpFloatWin->GetPopupModeStartSaveSelection(), TRUE );
332 BOOL bTravelSelect = mpImplLB->IsTravelSelect();
333 mpImplLB->SetTravelSelect( TRUE );
335 ImplDelData aCheckDelete;
336 ImplAddDel( &aCheckDelete );
337 Select();
338 if ( aCheckDelete.IsDelete() )
339 return 0;
340 ImplRemoveDel( &aCheckDelete );
342 mpImplLB->SetTravelSelect( bTravelSelect );
346 ImplClearLayoutData();
347 if( mpImplLB )
348 mpImplLB->GetMainWindow()->ImplClearLayoutData();
349 if( mpImplWin )
350 mpImplWin->ImplClearLayoutData();
352 mpBtn->SetPressed( FALSE );
353 ImplCallEventListeners( VCLEVENT_DROPDOWN_CLOSE );
354 return 0;
357 // -----------------------------------------------------------------------
359 void ListBox::ToggleDropDown()
361 if( IsDropDownBox() )
363 if( mpFloatWin->IsInPopupMode() )
364 mpFloatWin->EndPopupMode();
365 else
367 ImplCallEventListeners( VCLEVENT_DROPDOWN_PRE_OPEN );
368 mpImplWin->GrabFocus();
369 mpBtn->SetPressed( TRUE );
370 mpFloatWin->StartFloat( TRUE );
371 ImplCallEventListeners( VCLEVENT_DROPDOWN_OPEN );
376 // -----------------------------------------------------------------------
378 void ListBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, ULONG nFlags )
380 mpImplLB->GetMainWindow()->ImplInitSettings( TRUE, TRUE, TRUE );
382 Point aPos = pDev->LogicToPixel( rPos );
383 Size aSize = pDev->LogicToPixel( rSize );
384 Font aFont = mpImplLB->GetMainWindow()->GetDrawPixelFont( pDev );
385 OutDevType eOutDevType = pDev->GetOutDevType();
387 pDev->Push();
388 pDev->SetMapMode();
389 pDev->SetFont( aFont );
390 pDev->SetTextFillColor();
392 // Border/Background
393 pDev->SetLineColor();
394 pDev->SetFillColor();
395 BOOL bBorder = !(nFlags & WINDOW_DRAW_NOBORDER ) && (GetStyle() & WB_BORDER);
396 BOOL bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && IsControlBackground();
397 if ( bBorder || bBackground )
399 Rectangle aRect( aPos, aSize );
400 if ( bBorder )
402 ImplDrawFrame( pDev, aRect );
404 if ( bBackground )
406 pDev->SetFillColor( GetControlBackground() );
407 pDev->DrawRect( aRect );
411 // Inhalt
412 if ( ( nFlags & WINDOW_DRAW_MONO ) || ( eOutDevType == OUTDEV_PRINTER ) )
414 pDev->SetTextColor( Color( COL_BLACK ) );
416 else
418 if ( !(nFlags & WINDOW_DRAW_NODISABLE ) && !IsEnabled() )
420 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
421 pDev->SetTextColor( rStyleSettings.GetDisableColor() );
423 else
425 pDev->SetTextColor( GetTextColor() );
429 long nOnePixel = GetDrawPixel( pDev, 1 );
430 USHORT nTextStyle = TEXT_DRAW_VCENTER;
431 Rectangle aTextRect( aPos, aSize );
433 if ( GetStyle() & WB_CENTER )
434 nTextStyle |= TEXT_DRAW_CENTER;
435 else if ( GetStyle() & WB_RIGHT )
436 nTextStyle |= TEXT_DRAW_RIGHT;
437 else
438 nTextStyle |= TEXT_DRAW_LEFT;
440 aTextRect.Left() += 3*nOnePixel;
441 aTextRect.Right() -= 3*nOnePixel;
443 if ( IsDropDownBox() )
445 XubString aText = GetSelectEntry();
446 long nTextHeight = pDev->GetTextHeight();
447 long nTextWidth = pDev->GetTextWidth( aText );
448 long nOffX = 3*nOnePixel;
449 long nOffY = (aSize.Height()-nTextHeight) / 2;
451 // Clipping?
452 if ( (nOffY < 0) ||
453 ((nOffY+nTextHeight) > aSize.Height()) ||
454 ((nOffX+nTextWidth) > aSize.Width()) )
456 Rectangle aClip( aPos, aSize );
457 if ( nTextHeight > aSize.Height() )
458 aClip.Bottom() += nTextHeight-aSize.Height()+1; // Damit HP-Drucker nicht 'weg-optimieren'
459 pDev->IntersectClipRegion( aClip );
462 pDev->DrawText( aTextRect, aText, nTextStyle );
464 else
466 long nTextHeight = pDev->GetTextHeight();
467 USHORT nLines = (USHORT)(aSize.Height() / nTextHeight);
468 Rectangle aClip( aPos, aSize );
470 pDev->IntersectClipRegion( aClip );
472 if ( !nLines )
473 nLines = 1;
475 for ( USHORT n = 0; n < nLines; n++ )
477 USHORT nEntry = n+mpImplLB->GetTopEntry();
478 BOOL bSelected = mpImplLB->GetEntryList()->IsEntryPosSelected( nEntry );
479 if ( bSelected )
481 pDev->SetFillColor( COL_BLACK );
482 pDev->DrawRect( Rectangle( Point( aPos.X(), aPos.Y() + n*nTextHeight ),
483 Point( aPos.X() + aSize.Width(), aPos.Y() + (n+1)*nTextHeight + 2*nOnePixel ) ) );
484 pDev->SetFillColor();
485 pDev->SetTextColor( COL_WHITE );
488 aTextRect.Top() = aPos.Y() + n*nTextHeight;
489 aTextRect.Bottom() = aTextRect.Top() + nTextHeight;
491 pDev->DrawText( aTextRect, mpImplLB->GetEntryList()->GetEntryText( nEntry ), nTextStyle );
493 if ( bSelected )
494 pDev->SetTextColor( COL_BLACK );
498 pDev->Pop();
501 // -----------------------------------------------------------------------
503 void ListBox::GetFocus()
505 if ( mpImplLB )
507 if( IsDropDownBox() )
508 mpImplWin->GrabFocus();
509 else
510 mpImplLB->GrabFocus();
513 Control::GetFocus();
516 // -----------------------------------------------------------------------
518 Window* ListBox::GetPreferredKeyInputWindow()
520 if ( mpImplLB )
522 if( IsDropDownBox() )
523 return mpImplWin->GetPreferredKeyInputWindow();
524 else
525 return mpImplLB->GetPreferredKeyInputWindow();
528 return Control::GetPreferredKeyInputWindow();
531 // -----------------------------------------------------------------------
533 void ListBox::LoseFocus()
535 if( IsDropDownBox() )
536 mpImplWin->HideFocus();
537 else
538 mpImplLB->HideFocus();
540 Control::LoseFocus();
543 // -----------------------------------------------------------------------
545 void ListBox::DataChanged( const DataChangedEvent& rDCEvt )
547 Control::DataChanged( rDCEvt );
549 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
550 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
551 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
552 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
554 SetBackground(); // due to a hack in Window::UpdateSettings the background must be reset
555 // otherwise it will overpaint NWF drawn listboxes
556 Resize();
557 mpImplLB->Resize(); // Wird nicht durch ListBox::Resize() gerufen, wenn sich die ImplLB nicht aendert.
559 if ( mpImplWin )
561 mpImplWin->SetSettings( GetSettings() ); // Falls noch nicht eingestellt...
562 ImplInitFieldSettings( mpImplWin, TRUE, TRUE, TRUE );
564 mpBtn->SetSettings( GetSettings() );
565 ImplInitDropDownButton( mpBtn );
569 if ( IsDropDownBox() )
570 Invalidate();
574 // -----------------------------------------------------------------------
576 void ListBox::EnableAutoSize( BOOL bAuto )
578 mbDDAutoSize = bAuto;
579 if ( mpFloatWin )
581 if ( bAuto && !mpFloatWin->GetDropDownLineCount() )
582 mpFloatWin->SetDropDownLineCount( 5 );
583 else if ( !bAuto )
584 mpFloatWin->SetDropDownLineCount( 0 );
588 // -----------------------------------------------------------------------
590 void ListBox::EnableDDAutoWidth( BOOL b )
592 if ( mpFloatWin )
593 mpFloatWin->SetAutoWidth( b );
596 // -----------------------------------------------------------------------
598 BOOL ListBox::IsDDAutoWidthEnabled() const
600 return mpFloatWin ? mpFloatWin->IsAutoWidth() : FALSE;
603 // -----------------------------------------------------------------------
605 void ListBox::SetDropDownLineCount( USHORT nLines )
607 mnLineCount = nLines;
608 if ( mpFloatWin )
609 mpFloatWin->SetDropDownLineCount( mnLineCount );
612 // -----------------------------------------------------------------------
614 USHORT ListBox::GetDropDownLineCount() const
616 if ( mpFloatWin )
617 return mpFloatWin->GetDropDownLineCount();
618 return mnLineCount;
621 // -----------------------------------------------------------------------
623 void ListBox::SetPosSizePixel( long nX, long nY, long nWidth, long nHeight, USHORT nFlags )
625 if( IsDropDownBox() && ( nFlags & WINDOW_POSSIZE_SIZE ) )
627 Size aPrefSz = mpFloatWin->GetPrefSize();
628 if ( ( nFlags & WINDOW_POSSIZE_HEIGHT ) && ( nHeight >= 2*mnDDHeight ) )
629 aPrefSz.Height() = nHeight-mnDDHeight;
630 if ( nFlags & WINDOW_POSSIZE_WIDTH )
631 aPrefSz.Width() = nWidth;
632 mpFloatWin->SetPrefSize( aPrefSz );
634 if ( IsAutoSizeEnabled() && ! (nFlags & WINDOW_POSSIZE_DROPDOWN) )
635 nHeight = mnDDHeight;
638 Control::SetPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
641 // -----------------------------------------------------------------------
643 void ListBox::Resize()
645 Size aOutSz = GetOutputSizePixel();
646 if( IsDropDownBox() )
648 // initialize the dropdown button size with the standard scrollbar width
649 long nSBWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
650 long nTop = 0;
651 long nBottom = aOutSz.Height();
653 // note: in case of no border, pBorder will actually be this
654 Window *pBorder = GetWindow( WINDOW_BORDER );
655 ImplControlValue aControlValue;
656 Point aPoint;
657 Region aContent, aBound;
659 // use the full extent of the control
660 Region aArea( Rectangle(aPoint, pBorder->GetOutputSizePixel()) );
662 if ( GetNativeControlRegion( CTRL_LISTBOX, PART_BUTTON_DOWN,
663 aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
665 // convert back from border space to local coordinates
666 aPoint = pBorder->ScreenToOutputPixel( OutputToScreenPixel( aPoint ) );
667 aContent.Move( -aPoint.X(), -aPoint.Y() );
669 // use the themes drop down size for the button
670 aOutSz.Width() = aContent.GetBoundRect().Left();
671 mpBtn->SetPosSizePixel( aContent.GetBoundRect().Left(), nTop, aContent.GetBoundRect().Right(), (nBottom-nTop) );
673 // adjust the size of the edit field
674 if ( GetNativeControlRegion( CTRL_LISTBOX, PART_SUB_EDIT,
675 aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
677 // convert back from border space to local coordinates
678 aContent.Move( -aPoint.X(), -aPoint.Y() );
680 // use the themes drop down size
681 Rectangle aContentRect = aContent.GetBoundRect();
682 if( ! (GetStyle() & WB_BORDER) && ImplGetSVData()->maNWFData.mbNoFocusRects )
684 // no border but focus ring behavior -> we have a problem; the
685 // native rect relies on the border to draw the focus
686 // let's do the best we can and center vertically, so it doesn't look
687 // completely wrong.
688 Size aSz( GetOutputSizePixel() );
689 long nDiff = aContentRect.Top() - (aSz.Height() - aContentRect.GetHeight())/2;
690 aContentRect.Top() -= nDiff;
691 aContentRect.Bottom() -= nDiff;
693 mpImplWin->SetPosSizePixel( aContentRect.TopLeft(), aContentRect.GetSize() );
695 else
696 mpImplWin->SetSizePixel( aOutSz );
698 else
700 nSBWidth = CalcZoom( nSBWidth );
701 mpImplWin->SetPosSizePixel( 0, 0, aOutSz.Width() - nSBWidth, aOutSz.Height() );
702 mpBtn->SetPosSizePixel( aOutSz.Width() - nSBWidth, 0, nSBWidth, aOutSz.Height() );
705 else
707 mpImplLB->SetSizePixel( aOutSz );
710 // FloatingWindow-Groesse auch im unsichtbare Zustand auf Stand halten,
711 // weil KEY_PGUP/DOWN ausgewertet wird...
712 if ( mpFloatWin )
713 mpFloatWin->SetSizePixel( mpFloatWin->CalcFloatSize() );
715 Control::Resize();
718 // -----------------------------------------------------------------------
720 void ListBox::FillLayoutData() const
722 mpLayoutData = new vcl::ControlLayoutData();
723 const Control* pMainWin = mpImplLB->GetMainWindow();
724 if( mpFloatWin )
726 // dropdown mode
727 AppendLayoutData( *mpImplWin );
728 mpImplWin->SetLayoutDataParent( this );
729 if( mpFloatWin->IsReallyVisible() )
731 AppendLayoutData( *pMainWin );
732 pMainWin->SetLayoutDataParent( this );
735 else
737 AppendLayoutData( *pMainWin );
738 pMainWin->SetLayoutDataParent( this );
742 // -----------------------------------------------------------------------
744 long ListBox::GetIndexForPoint( const Point& rPoint, USHORT& rPos ) const
746 if( ! mpLayoutData )
747 FillLayoutData();
749 // check whether rPoint fits at all
750 long nIndex = Control::GetIndexForPoint( rPoint );
751 if( nIndex != -1 )
753 // point must be either in main list window
754 // or in impl window (dropdown case)
755 ImplListBoxWindow* pMain = mpImplLB->GetMainWindow();
757 // convert coordinates to ImplListBoxWindow pixel coordinate space
758 Point aConvPoint = LogicToPixel( rPoint );
759 aConvPoint = OutputToAbsoluteScreenPixel( aConvPoint );
760 aConvPoint = pMain->AbsoluteScreenToOutputPixel( aConvPoint );
761 aConvPoint = pMain->PixelToLogic( aConvPoint );
763 // try to find entry
764 USHORT nEntry = pMain->GetEntryPosForPoint( aConvPoint );
765 if( nEntry == LISTBOX_ENTRY_NOTFOUND )
767 // not found, maybe dropdown case
768 if( mpImplWin && mpImplWin->IsReallyVisible() )
770 // convert to impl window pixel coordinates
771 aConvPoint = LogicToPixel( rPoint );
772 aConvPoint = OutputToAbsoluteScreenPixel( aConvPoint );
773 aConvPoint = mpImplWin->AbsoluteScreenToOutputPixel( aConvPoint );
775 // check whether converted point is inside impl window
776 Size aImplWinSize = mpImplWin->GetOutputSizePixel();
777 if( aConvPoint.X() >= 0 && aConvPoint.Y() >= 0 && aConvPoint.X() < aImplWinSize.Width() && aConvPoint.Y() < aImplWinSize.Height() )
779 // inside the impl window, the position is the current item pos
780 rPos = mpImplWin->GetItemPos();
782 else
783 nIndex = -1;
785 else
786 nIndex = -1;
788 else
789 rPos = nEntry;
791 DBG_ASSERT( nIndex != -1, "found index for point, but relative index failed" );
794 // get line relative index
795 if( nIndex != -1 )
796 nIndex = ToRelativeLineIndex( nIndex );
798 return nIndex;
801 // -----------------------------------------------------------------------
803 void ListBox::StateChanged( StateChangedType nType )
805 if( nType == STATE_CHANGE_READONLY )
807 if( mpImplWin )
808 mpImplWin->Enable( !IsReadOnly() );
809 if( mpBtn )
810 mpBtn->Enable( !IsReadOnly() );
812 else if( nType == STATE_CHANGE_ENABLE )
814 mpImplLB->Enable( IsEnabled() );
815 if( mpImplWin )
817 mpImplWin->Enable( IsEnabled() );
818 if ( IsNativeControlSupported(CTRL_LISTBOX, PART_ENTIRE_CONTROL)
819 && ! IsNativeControlSupported(CTRL_LISTBOX, PART_BUTTON_DOWN) )
821 GetWindow( WINDOW_BORDER )->Invalidate( INVALIDATE_NOERASE );
823 else
824 mpImplWin->Invalidate();
826 if( mpBtn )
827 mpBtn->Enable( IsEnabled() );
829 else if( nType == STATE_CHANGE_UPDATEMODE )
831 mpImplLB->SetUpdateMode( IsUpdateMode() );
833 else if ( nType == STATE_CHANGE_ZOOM )
835 mpImplLB->SetZoom( GetZoom() );
836 if ( mpImplWin )
838 mpImplWin->SetZoom( GetZoom() );
839 mpImplWin->SetFont( mpImplLB->GetMainWindow()->GetFont() );
840 mpImplWin->Invalidate();
842 Resize();
844 else if ( nType == STATE_CHANGE_CONTROLFONT )
846 mpImplLB->SetControlFont( GetControlFont() );
847 if ( mpImplWin )
849 mpImplWin->SetControlFont( GetControlFont() );
850 mpImplWin->SetFont( mpImplLB->GetMainWindow()->GetFont() );
851 mpImplWin->Invalidate();
853 Resize();
855 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
857 mpImplLB->SetControlForeground( GetControlForeground() );
858 if ( mpImplWin )
860 mpImplWin->SetControlForeground( GetControlForeground() );
861 mpImplWin->SetTextColor( GetControlForeground() );
862 mpImplWin->SetFont( mpImplLB->GetMainWindow()->GetFont() );
863 mpImplWin->Invalidate();
866 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
868 mpImplLB->SetControlBackground( GetControlBackground() );
869 if ( mpImplWin )
871 if ( mpImplWin->IsNativeControlSupported(CTRL_LISTBOX, PART_ENTIRE_CONTROL) )
873 // Transparent background
874 mpImplWin->SetBackground();
875 mpImplWin->SetControlBackground();
877 else
879 mpImplWin->SetBackground( mpImplLB->GetMainWindow()->GetControlBackground() );
880 mpImplWin->SetControlBackground( mpImplLB->GetMainWindow()->GetControlBackground() );
882 mpImplWin->SetFont( mpImplLB->GetMainWindow()->GetFont() );
883 mpImplWin->Invalidate();
886 else if ( nType == STATE_CHANGE_STYLE )
888 SetStyle( ImplInitStyle( GetStyle() ) );
889 mpImplLB->GetMainWindow()->EnableSort( ( GetStyle() & WB_SORT ) ? TRUE : FALSE );
891 else if( nType == STATE_CHANGE_MIRRORING )
893 if( mpBtn )
895 mpBtn->EnableRTL( IsRTLEnabled() );
896 ImplInitDropDownButton( mpBtn );
898 mpImplLB->EnableRTL( IsRTLEnabled() );
899 if( mpImplWin )
900 mpImplWin->EnableRTL( IsRTLEnabled() );
901 Resize();
904 Control::StateChanged( nType );
907 // -----------------------------------------------------------------------
909 long ListBox::PreNotify( NotifyEvent& rNEvt )
911 long nDone = 0;
912 if ( mpImplLB )
914 if( ( rNEvt.GetType() == EVENT_KEYINPUT ) && ( rNEvt.GetWindow() == mpImplWin ) )
916 KeyEvent aKeyEvt = *rNEvt.GetKeyEvent();
917 switch( aKeyEvt.GetKeyCode().GetCode() )
919 case KEY_DOWN:
921 if( mpFloatWin && !mpFloatWin->IsInPopupMode() &&
922 aKeyEvt.GetKeyCode().IsMod2() )
924 ImplCallEventListeners( VCLEVENT_DROPDOWN_PRE_OPEN );
925 mpBtn->SetPressed( TRUE );
926 mpFloatWin->StartFloat( FALSE );
927 ImplCallEventListeners( VCLEVENT_DROPDOWN_OPEN );
928 nDone = 1;
930 else
932 nDone = mpImplLB->ProcessKeyInput( aKeyEvt );
935 break;
936 case KEY_UP:
938 if( mpFloatWin && mpFloatWin->IsInPopupMode() &&
939 aKeyEvt.GetKeyCode().IsMod2() )
941 mpFloatWin->EndPopupMode();
942 nDone = 1;
944 else
946 nDone = mpImplLB->ProcessKeyInput( aKeyEvt );
949 break;
950 case KEY_RETURN:
952 if( IsInDropDown() )
954 mpImplLB->ProcessKeyInput( aKeyEvt );
955 nDone = 1;
958 break;
960 default:
962 nDone = mpImplLB->ProcessKeyInput( aKeyEvt );
966 else if ( rNEvt.GetType() == EVENT_LOSEFOCUS )
968 if ( IsInDropDown() && !HasChildPathFocus( TRUE ) )
969 mpFloatWin->EndPopupMode();
971 else if ( (rNEvt.GetType() == EVENT_COMMAND) &&
972 (rNEvt.GetCommandEvent()->GetCommand() == COMMAND_WHEEL) &&
973 (rNEvt.GetWindow() == mpImplWin) )
975 USHORT nWheelBehavior( GetSettings().GetMouseSettings().GetWheelBehavior() );
976 if ( ( nWheelBehavior == MOUSE_WHEEL_ALWAYS )
977 || ( ( nWheelBehavior == MOUSE_WHEEL_FOCUS_ONLY )
978 && HasChildPathFocus()
982 nDone = mpImplLB->HandleWheelAsCursorTravel( *rNEvt.GetCommandEvent() );
984 else
986 nDone = 0; // don't eat this event, let the default handling happen (i.e. scroll the context)
991 return nDone ? nDone : Control::PreNotify( rNEvt );
994 // -----------------------------------------------------------------------
996 void ListBox::Select()
998 ImplCallEventListenersAndHandler( VCLEVENT_LISTBOX_SELECT, maSelectHdl, this );
1001 // -----------------------------------------------------------------------
1003 void ListBox::DoubleClick()
1005 ImplCallEventListenersAndHandler( VCLEVENT_LISTBOX_DOUBLECLICK, maDoubleClickHdl, this );
1008 // -----------------------------------------------------------------------
1010 void ListBox::Clear()
1012 mpImplLB->Clear();
1013 if( IsDropDownBox() )
1015 mpImplWin->SetItemPos( LISTBOX_ENTRY_NOTFOUND );
1016 mpImplWin->SetString( ImplGetSVEmptyStr() );
1017 Image aImage;
1018 mpImplWin->SetImage( aImage );
1019 mpImplWin->Invalidate();
1021 CallEventListeners( VCLEVENT_LISTBOX_ITEMREMOVED, (void*) sal_IntPtr(-1) );
1024 // -----------------------------------------------------------------------
1026 void ListBox::SetNoSelection()
1028 mpImplLB->SetNoSelection();
1029 if( IsDropDownBox() )
1031 mpImplWin->SetItemPos( LISTBOX_ENTRY_NOTFOUND );
1032 mpImplWin->SetString( ImplGetSVEmptyStr() );
1033 Image aImage;
1034 mpImplWin->SetImage( aImage );
1035 mpImplWin->Invalidate();
1039 // -----------------------------------------------------------------------
1041 USHORT ListBox::InsertEntry( const XubString& rStr, USHORT nPos )
1043 USHORT nRealPos = mpImplLB->InsertEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), rStr );
1044 nRealPos = sal::static_int_cast<USHORT>(nRealPos - mpImplLB->GetEntryList()->GetMRUCount());
1045 CallEventListeners( VCLEVENT_LISTBOX_ITEMADDED, (void*) sal_IntPtr(nRealPos) );
1046 return nRealPos;
1049 // -----------------------------------------------------------------------
1051 USHORT ListBox::InsertEntry( const Image& rImage, USHORT nPos )
1053 USHORT nRealPos = mpImplLB->InsertEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), rImage );
1054 nRealPos = sal::static_int_cast<USHORT>(nRealPos - mpImplLB->GetEntryList()->GetMRUCount());
1055 CallEventListeners( VCLEVENT_LISTBOX_ITEMADDED, (void*) sal_IntPtr(nRealPos) );
1056 return nRealPos;
1059 // -----------------------------------------------------------------------
1061 USHORT ListBox::InsertEntry( const XubString& rStr, const Image& rImage, USHORT nPos )
1063 USHORT nRealPos = mpImplLB->InsertEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), rStr, rImage );
1064 nRealPos = sal::static_int_cast<USHORT>(nRealPos - mpImplLB->GetEntryList()->GetMRUCount());
1065 CallEventListeners( VCLEVENT_LISTBOX_ITEMADDED, (void*) sal_IntPtr(nRealPos) );
1066 return nRealPos;
1069 // -----------------------------------------------------------------------
1071 void ListBox::RemoveEntry( const XubString& rStr )
1073 RemoveEntry( GetEntryPos( rStr ) );
1076 // -----------------------------------------------------------------------
1078 void ListBox::RemoveEntry( USHORT nPos )
1080 mpImplLB->RemoveEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1081 CallEventListeners( VCLEVENT_LISTBOX_ITEMREMOVED, (void*) sal_IntPtr(nPos) );
1084 // -----------------------------------------------------------------------
1086 USHORT ListBox::GetEntryPos( const XubString& rStr ) const
1088 USHORT nPos = mpImplLB->GetEntryList()->FindEntry( rStr );
1089 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1090 nPos = sal::static_int_cast<USHORT>(nPos - mpImplLB->GetEntryList()->GetMRUCount());
1091 return nPos;
1094 // -----------------------------------------------------------------------
1096 USHORT ListBox::GetEntryPos( const void* pData ) const
1098 USHORT nPos = mpImplLB->GetEntryList()->FindEntry( pData );
1099 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1100 nPos = sal::static_int_cast<USHORT>(nPos - mpImplLB->GetEntryList()->GetMRUCount());
1101 return nPos;
1104 // -----------------------------------------------------------------------
1106 XubString ListBox::GetEntry( USHORT nPos ) const
1108 return mpImplLB->GetEntryList()->GetEntryText( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1111 // -----------------------------------------------------------------------
1113 USHORT ListBox::GetEntryCount() const
1115 return mpImplLB->GetEntryList()->GetEntryCount() - mpImplLB->GetEntryList()->GetMRUCount();
1118 // -----------------------------------------------------------------------
1120 XubString ListBox::GetSelectEntry( USHORT nIndex ) const
1122 return GetEntry( GetSelectEntryPos( nIndex ) );
1125 // -----------------------------------------------------------------------
1127 USHORT ListBox::GetSelectEntryCount() const
1129 return mpImplLB->GetEntryList()->GetSelectEntryCount();
1132 // -----------------------------------------------------------------------
1134 USHORT ListBox::GetSelectEntryPos( USHORT nIndex ) const
1136 USHORT nPos = mpImplLB->GetEntryList()->GetSelectEntryPos( nIndex );
1137 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1139 if ( nPos < mpImplLB->GetEntryList()->GetMRUCount() )
1140 nPos = mpImplLB->GetEntryList()->FindEntry( mpImplLB->GetEntryList()->GetEntryText( nPos ) );
1141 nPos = sal::static_int_cast<USHORT>(nPos - mpImplLB->GetEntryList()->GetMRUCount());
1143 return nPos;
1146 // -----------------------------------------------------------------------
1148 BOOL ListBox::IsEntrySelected( const XubString& rStr ) const
1150 return IsEntryPosSelected( GetEntryPos( rStr ) );
1153 // -----------------------------------------------------------------------
1155 BOOL ListBox::IsEntryPosSelected( USHORT nPos ) const
1157 return mpImplLB->GetEntryList()->IsEntryPosSelected( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1160 // -----------------------------------------------------------------------
1162 void ListBox::SelectEntry( const XubString& rStr, BOOL bSelect )
1164 SelectEntryPos( GetEntryPos( rStr ), bSelect );
1167 // -----------------------------------------------------------------------
1169 void ListBox::SelectEntryPos( USHORT nPos, BOOL bSelect )
1171 if ( nPos < mpImplLB->GetEntryList()->GetEntryCount() )
1172 mpImplLB->SelectEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), bSelect );
1175 // -----------------------------------------------------------------------
1177 void ListBox::SetEntryData( USHORT nPos, void* pNewData )
1179 mpImplLB->SetEntryData( nPos + mpImplLB->GetEntryList()->GetMRUCount(), pNewData );
1182 // -----------------------------------------------------------------------
1184 void* ListBox::GetEntryData( USHORT nPos ) const
1186 return mpImplLB->GetEntryList()->GetEntryData( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1189 // -----------------------------------------------------------------------
1191 void ListBox::SetEntryFlags( USHORT nPos, long nFlags )
1193 mpImplLB->SetEntryFlags( nPos + mpImplLB->GetEntryList()->GetMRUCount(), nFlags );
1196 // -----------------------------------------------------------------------
1198 long ListBox::GetEntryFlags( USHORT nPos ) const
1200 return mpImplLB->GetEntryList()->GetEntryFlags( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1203 // -----------------------------------------------------------------------
1205 void ListBox::SetTopEntry( USHORT nPos )
1207 mpImplLB->SetTopEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount() );
1210 // -----------------------------------------------------------------------
1212 USHORT ListBox::GetTopEntry() const
1214 USHORT nPos = GetEntryCount() ? mpImplLB->GetTopEntry() : LISTBOX_ENTRY_NOTFOUND;
1215 if ( nPos < mpImplLB->GetEntryList()->GetMRUCount() )
1216 nPos = 0;
1217 return nPos;
1220 // -----------------------------------------------------------------------
1222 BOOL ListBox::IsTravelSelect() const
1224 return mpImplLB->IsTravelSelect();
1227 // -----------------------------------------------------------------------
1229 BOOL ListBox::IsInDropDown() const
1231 return mpFloatWin && mpFloatWin->IsInPopupMode();
1234 // -----------------------------------------------------------------------
1236 long ListBox::CalcWindowSizePixel( USHORT nLines ) const
1238 return mpImplLB->GetEntryHeight() * nLines;
1241 Rectangle ListBox::GetBoundingRectangle( USHORT nItem ) const
1243 Rectangle aRect = mpImplLB->GetMainWindow()->GetBoundingRectangle( nItem );
1244 Rectangle aOffset = mpImplLB->GetMainWindow()->GetWindowExtentsRelative( (Window*)this );
1245 aRect.Move( aOffset.TopLeft().X(), aOffset.TopLeft().Y() );
1246 return aRect;
1249 // -----------------------------------------------------------------------
1251 void ListBox::EnableMultiSelection( BOOL bMulti )
1253 EnableMultiSelection( bMulti, FALSE );
1256 void ListBox::EnableMultiSelection( BOOL bMulti, BOOL bStackSelection )
1258 mpImplLB->EnableMultiSelection( bMulti, bStackSelection );
1260 // WB_SIMPLEMODE:
1261 // Die MultiListBox verh�lt sich wie eine normale ListBox.
1262 // Die Mehrfachselektion kann nur �ber entsprechende Zusatztasten erfolgen.
1264 BOOL bSimpleMode = ( GetStyle() & WB_SIMPLEMODE ) ? TRUE : FALSE;
1265 mpImplLB->SetMultiSelectionSimpleMode( bSimpleMode );
1267 // ohne Focus ist das Traveln in einer MultiSelection nicht zu sehen:
1268 if ( mpFloatWin )
1269 mpImplLB->GetMainWindow()->AllowGrabFocus( bMulti );
1272 // -----------------------------------------------------------------------
1274 BOOL ListBox::IsMultiSelectionEnabled() const
1276 return mpImplLB->IsMultiSelectionEnabled();
1279 // -----------------------------------------------------------------------
1281 Size ListBox::CalcMinimumSize() const
1283 Size aSz;
1284 if ( !IsDropDownBox() )
1285 aSz = mpImplLB->CalcSize (mnLineCount ? mnLineCount : mpImplLB->GetEntryList()->GetEntryCount());
1286 else
1288 aSz.Height() = mpImplLB->CalcSize( 1 ).Height();
1289 if( aSz.Height() < mnDDHeight )
1291 aSz.Height() = mnDDHeight;
1292 // FIXME: this is currently only on mac/aqua
1293 if( ImplGetSVData()->maNWFData.mbNoFocusRects &&
1294 IsNativeWidgetEnabled() &&
1295 const_cast<ListBox*>(this)->IsNativeControlSupported( CTRL_LISTBOX, PART_ENTIRE_CONTROL ) )
1297 ImplControlValue aControlValue;
1298 Region aCtrlRegion( Rectangle( (const Point&)Point(), Size( 20, mnDDHeight ) ) );
1299 Region aBoundingRgn( aCtrlRegion );
1300 Region aContentRgn( aCtrlRegion );
1301 // adjust the size of the edit field
1302 if( const_cast<ListBox*>(this)->GetNativeControlRegion( CTRL_LISTBOX, PART_ENTIRE_CONTROL,
1303 aCtrlRegion, 0, aControlValue, rtl::OUString(), aBoundingRgn, aContentRgn) )
1305 aSz.Height() = aContentRgn.GetBoundRect().GetHeight();
1309 aSz.Width() = mpImplLB->GetMaxEntryWidth();
1310 aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize();
1313 aSz = CalcWindowSize( aSz );
1314 return aSz;
1317 // -----------------------------------------------------------------------
1319 Size ListBox::GetOptimalSize(WindowSizeType eType) const
1321 switch (eType) {
1322 case WINDOWSIZE_MINIMUM:
1323 return CalcMinimumSize();
1324 default:
1325 return Control::GetOptimalSize( eType );
1329 // -----------------------------------------------------------------------
1331 Size ListBox::CalcAdjustedSize( const Size& rPrefSize ) const
1333 Size aSz = rPrefSize;
1334 sal_Int32 nLeft, nTop, nRight, nBottom;
1335 ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
1336 aSz.Height() -= nTop+nBottom;
1337 if ( !IsDropDownBox() )
1339 long nEntryHeight = CalcSize( 1, 1 ).Height();
1340 long nLines = aSz.Height() / nEntryHeight;
1341 if ( nLines < 1 )
1342 nLines = 1;
1343 aSz.Height() = nLines * nEntryHeight;
1345 else
1347 aSz.Height() = mnDDHeight;
1349 aSz.Height() += nTop+nBottom;
1351 aSz = CalcWindowSize( aSz );
1352 return aSz;
1355 // -----------------------------------------------------------------------
1357 Size ListBox::CalcSize( USHORT nColumns, USHORT nLines ) const
1359 // ggf. werden ScrollBars eingeblendet
1360 Size aMinSz = CalcMinimumSize();
1361 // aMinSz = ImplCalcOutSz( aMinSz );
1363 Size aSz;
1365 // Hoehe
1366 if ( nLines )
1368 if ( !IsDropDownBox() )
1369 aSz.Height() = mpImplLB->CalcSize( nLines ).Height();
1370 else
1371 aSz.Height() = mnDDHeight;
1373 else
1374 aSz.Height() = aMinSz.Height();
1376 // Breite
1377 if ( nColumns )
1378 aSz.Width() = nColumns * GetTextWidth( XubString( 'X' ) );
1379 else
1380 aSz.Width() = aMinSz.Width();
1382 if ( IsDropDownBox() )
1383 aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize();
1385 if ( !IsDropDownBox() )
1387 if ( aSz.Width() < aMinSz.Width() )
1388 aSz.Height() += GetSettings().GetStyleSettings().GetScrollBarSize();
1389 if ( aSz.Height() < aMinSz.Height() )
1390 aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize();
1393 aSz = CalcWindowSize( aSz );
1394 return aSz;
1397 // -----------------------------------------------------------------------
1399 void ListBox::GetMaxVisColumnsAndLines( USHORT& rnCols, USHORT& rnLines ) const
1401 long nCharWidth = GetTextWidth( UniString( 'x' ) );
1402 if ( !IsDropDownBox() )
1404 Size aOutSz = mpImplLB->GetMainWindow()->GetOutputSizePixel();
1405 rnCols = (USHORT) (aOutSz.Width()/nCharWidth);
1406 rnLines = (USHORT) (aOutSz.Height()/mpImplLB->GetEntryHeight());
1408 else
1410 Size aOutSz = mpImplWin->GetOutputSizePixel();
1411 rnCols = (USHORT) (aOutSz.Width()/nCharWidth);
1412 rnLines = 1;
1416 // -----------------------------------------------------------------------
1418 IMPL_LINK( ListBox, ImplUserDrawHdl, UserDrawEvent*, pEvent )
1420 UserDraw( *pEvent );
1421 return 1;
1424 // -----------------------------------------------------------------------
1426 void ListBox::UserDraw( const UserDrawEvent& )
1430 // -----------------------------------------------------------------------
1432 void ListBox::DrawEntry( const UserDrawEvent& rEvt, BOOL bDrawImage, BOOL bDrawText, BOOL bDrawTextAtImagePos )
1434 if ( rEvt.GetDevice() == mpImplLB->GetMainWindow() )
1435 mpImplLB->GetMainWindow()->DrawEntry( rEvt.GetItemId(), bDrawImage, bDrawText, bDrawTextAtImagePos );
1436 else if ( rEvt.GetDevice() == mpImplWin )
1437 mpImplWin->DrawEntry( bDrawImage, bDrawText, bDrawTextAtImagePos );
1440 // -----------------------------------------------------------------------
1442 void ListBox::SetUserItemSize( const Size& rSz )
1444 mpImplLB->GetMainWindow()->SetUserItemSize( rSz );
1445 if ( mpImplWin )
1446 mpImplWin->SetUserItemSize( rSz );
1449 // -----------------------------------------------------------------------
1451 const Size& ListBox::GetUserItemSize() const
1453 return mpImplLB->GetMainWindow()->GetUserItemSize();
1456 // -----------------------------------------------------------------------
1458 void ListBox::EnableUserDraw( BOOL bUserDraw )
1460 mpImplLB->GetMainWindow()->EnableUserDraw( bUserDraw );
1461 if ( mpImplWin )
1462 mpImplWin->EnableUserDraw( bUserDraw );
1465 // -----------------------------------------------------------------------
1467 BOOL ListBox::IsUserDrawEnabled() const
1469 return mpImplLB->GetMainWindow()->IsUserDrawEnabled();
1472 // -----------------------------------------------------------------------
1474 void ListBox::SetReadOnly( BOOL bReadOnly )
1476 if ( mpImplLB->IsReadOnly() != bReadOnly )
1478 mpImplLB->SetReadOnly( bReadOnly );
1479 StateChanged( STATE_CHANGE_READONLY );
1483 // -----------------------------------------------------------------------
1485 BOOL ListBox::IsReadOnly() const
1487 return mpImplLB->IsReadOnly();
1490 // -----------------------------------------------------------------------
1492 void ListBox::SetSeparatorPos( USHORT n )
1494 mpImplLB->SetSeparatorPos( n );
1497 // -----------------------------------------------------------------------
1499 void ListBox::SetSeparatorPos()
1501 mpImplLB->SetSeparatorPos( LISTBOX_ENTRY_NOTFOUND );
1504 // -----------------------------------------------------------------------
1506 USHORT ListBox::GetSeparatorPos() const
1508 return mpImplLB->GetSeparatorPos();
1511 // -----------------------------------------------------------------------
1513 void ListBox::SetMRUEntries( const XubString& rEntries, xub_Unicode cSep )
1515 mpImplLB->SetMRUEntries( rEntries, cSep );
1518 // -----------------------------------------------------------------------
1520 XubString ListBox::GetMRUEntries( xub_Unicode cSep ) const
1522 return mpImplLB->GetMRUEntries( cSep );
1525 // -----------------------------------------------------------------------
1527 void ListBox::SetMaxMRUCount( USHORT n )
1529 mpImplLB->SetMaxMRUCount( n );
1532 // -----------------------------------------------------------------------
1534 USHORT ListBox::GetMaxMRUCount() const
1536 return mpImplLB->GetMaxMRUCount();
1539 // -----------------------------------------------------------------------
1541 USHORT ListBox::GetDisplayLineCount() const
1543 return mpImplLB->GetDisplayLineCount();
1546 // -----------------------------------------------------------------------
1548 // pb: #106948# explicit mirroring for calc
1550 void ListBox::EnableMirroring()
1552 mpImplLB->EnableMirroring();
1555 // -----------------------------------------------------------------------
1557 Rectangle ListBox::GetDropDownPosSizePixel() const
1559 return mpFloatWin ? mpFloatWin->GetWindowExtentsRelative( const_cast<ListBox*>(this) ) : Rectangle();
1562 // -----------------------------------------------------------------------
1564 const Wallpaper& ListBox::GetDisplayBackground() const
1566 // !!! recursion does not occur because the ImplListBox is default
1567 // initialized to a nontransparent color in Window::ImplInitData
1568 return mpImplLB->GetDisplayBackground();
1571 // =======================================================================
1573 MultiListBox::MultiListBox( Window* pParent, WinBits nStyle ) :
1574 ListBox( WINDOW_MULTILISTBOX )
1576 ImplInit( pParent, nStyle );
1577 EnableMultiSelection( TRUE );
1580 // -----------------------------------------------------------------------
1582 MultiListBox::MultiListBox( Window* pParent, const ResId& rResId ) :
1583 ListBox( WINDOW_MULTILISTBOX )
1585 rResId.SetRT( RSC_MULTILISTBOX );
1586 WinBits nStyle = ImplInitRes( rResId );
1587 ImplInit( pParent, nStyle );
1588 ImplLoadRes( rResId );
1590 if ( !(nStyle & WB_HIDE ) )
1591 Show();
1592 EnableMultiSelection( TRUE );