LibreOffice Module vcl (master)  1
listbox.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 
21 #include <vcl/commandevent.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/toolkit/lstbox.hxx>
24 #include <vcl/settings.hxx>
25 #include <vcl/uitest/uiobject.hxx>
26 #include <sal/log.hxx>
27 
28 #include <svdata.hxx>
29 #include <controldata.hxx>
30 #include <listbox.hxx>
31 #include <dndeventdispatcher.hxx>
32 #include <comphelper/lok.hxx>
33 
34 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
35 #include <boost/property_tree/ptree.hpp>
36 #include <tools/json_writer.hxx>
37 
39  : Control(nType)
40  , mpImplLB(nullptr)
41 {
43 }
44 
46 {
48  ImplInit( pParent, nStyle );
49 }
50 
52 {
53  disposeOnce();
54 }
55 
57 {
59 
64 
66 }
67 
69 {
70  mpFloatWin = nullptr;
71  mpImplWin = nullptr;
72  mpBtn = nullptr;
73  mnDDHeight = 0;
74  mnLineCount = 0;
75  m_nMaxWidthChars = -1;
76  mbDDAutoSize = true;
77 }
78 
79 void ListBox::ImplInit( vcl::Window* pParent, WinBits nStyle )
80 {
81  nStyle = ImplInitStyle( nStyle );
82  if ( !(nStyle & WB_NOBORDER) && ( nStyle & WB_DROPDOWN ) )
83  nStyle |= WB_BORDER;
84 
85  Control::ImplInit( pParent, nStyle, nullptr );
86 
87  css::uno::Reference< css::datatransfer::dnd::XDropTargetListener> xDrop = new DNDEventDispatcher(this);
88 
89  if( nStyle & WB_DROPDOWN )
90  {
91  sal_Int32 nLeft, nTop, nRight, nBottom;
92  GetBorder( nLeft, nTop, nRight, nBottom );
93  mnDDHeight = static_cast<sal_uInt16>(GetTextHeight() + nTop + nBottom + 4);
94 
95  if( IsNativeWidgetEnabled() &&
97  {
98  ImplControlValue aControlValue;
99  tools::Rectangle aCtrlRegion( Point( 0, 0 ), Size( 20, mnDDHeight ) );
100  tools::Rectangle aBoundingRgn( aCtrlRegion );
101  tools::Rectangle aContentRgn( aCtrlRegion );
103  ControlState::ENABLED, aControlValue,
104  aBoundingRgn, aContentRgn ) )
105  {
106  sal_Int32 nHeight = aBoundingRgn.GetHeight();
107  if( nHeight > mnDDHeight )
108  mnDDHeight = static_cast<sal_uInt16>(nHeight);
109  }
110  }
111 
115  mpFloatWin->SetAutoWidth( true );
116  mpFloatWin->SetPopupModeEndHdl( LINK( this, ListBox, ImplPopupModeEndHdl ) );
117  mpFloatWin->GetDropTarget()->addDropTargetListener(xDrop);
118 
119  mpImplWin = VclPtr<ImplWin>::Create( this, (nStyle & (WB_LEFT|WB_RIGHT|WB_CENTER))|WB_NOBORDER );
120  mpImplWin->SetMBDownHdl( LINK( this, ListBox, ImplClickBtnHdl ) );
121  mpImplWin->Show();
122  mpImplWin->GetDropTarget()->addDropTargetListener(xDrop);
123  mpImplWin->SetEdgeBlending(false);
124 
127  mpBtn->SetMBDownHdl( LINK( this, ListBox, ImplClickBtnHdl ) );
128  mpBtn->Show();
129  mpBtn->GetDropTarget()->addDropTargetListener(xDrop);
130  }
131 
132  vcl::Window* pLBParent = this;
133  if ( mpFloatWin )
134  pLBParent = mpFloatWin;
135  mpImplLB = VclPtr<ImplListBox>::Create( pLBParent, nStyle&(~WB_BORDER) );
136  mpImplLB->SetSelectHdl( LINK( this, ListBox, ImplSelectHdl ) );
137  mpImplLB->SetScrollHdl( LINK( this, ListBox, ImplScrollHdl ) );
138  mpImplLB->SetCancelHdl( LINK( this, ListBox, ImplCancelHdl ) );
139  mpImplLB->SetDoubleClickHdl( LINK( this, ListBox, ImplDoubleClickHdl ) );
140  mpImplLB->SetFocusHdl( LINK( this, ListBox, ImplFocusHdl ) );
141  mpImplLB->SetListItemSelectHdl( LINK( this, ListBox, ImplListItemSelectHdl ) );
142  mpImplLB->SetPosPixel( Point() );
143  mpImplLB->SetEdgeBlending(false);
144  mpImplLB->Show();
145 
146  mpImplLB->GetDropTarget()->addDropTargetListener(xDrop);
147 
148  if ( mpFloatWin )
149  {
151  mpImplLB->SetSelectionChangedHdl( LINK( this, ListBox, ImplSelectionChangedHdl ) );
152  }
153  else
155 
156  SetCompoundControl( true );
157 }
158 
160 {
161  if ( !(nStyle & WB_NOTABSTOP) )
162  nStyle |= WB_TABSTOP;
163  if ( !(nStyle & WB_NOGROUP) )
164  nStyle |= WB_GROUP;
165  return nStyle;
166 }
167 
168 IMPL_LINK_NOARG(ListBox, ImplSelectHdl, LinkParamNone*, void)
169 {
170  bool bPopup = IsInDropDown();
171  if( IsDropDownBox() )
172  {
173  if( !mpImplLB->IsTravelSelect() )
174  {
175  mpFloatWin->EndPopupMode();
176  mpImplWin->GrabFocus();
177  }
178 
179  mpImplWin->SetItemPos( GetSelectedEntryPos() );
180  mpImplWin->SetString( GetSelectedEntry() );
181  if( mpImplLB->GetEntryList()->HasImages() )
182  {
183  Image aImage = mpImplLB->GetEntryList()->GetEntryImage( GetSelectedEntryPos() );
184  mpImplWin->SetImage( aImage );
185  }
186  mpImplWin->Invalidate();
187  }
188 
189  if ( ( !IsTravelSelect() || mpImplLB->IsSelectionChanged() ) || ( bPopup && !IsMultiSelectionEnabled() ) )
190  Select();
191 }
192 
193 IMPL_LINK( ListBox, ImplFocusHdl, sal_Int32, nPos, void )
194 {
195  CallEventListeners( VclEventId::ListboxFocus, reinterpret_cast<void*>(nPos) );
196 }
197 
198 IMPL_LINK_NOARG( ListBox, ImplListItemSelectHdl, LinkParamNone*, void )
199 {
200  CallEventListeners( VclEventId::DropdownSelect );
201 }
202 
203 IMPL_LINK_NOARG(ListBox, ImplScrollHdl, ImplListBox*, void)
204 {
205  CallEventListeners( VclEventId::ListboxScrolled );
206 }
207 
208 IMPL_LINK_NOARG(ListBox, ImplCancelHdl, LinkParamNone*, void)
209 {
210  if( IsInDropDown() )
211  mpFloatWin->EndPopupMode();
212 }
213 
214 IMPL_LINK( ListBox, ImplSelectionChangedHdl, sal_Int32, nChanged, void )
215 {
216  if ( mpImplLB->IsTrackingSelect() )
217  return;
218 
219  const ImplEntryList* pEntryList = mpImplLB->GetEntryList();
220  if ( pEntryList->IsEntryPosSelected( nChanged ) )
221  {
222  // FIXME? This should've been turned into an ImplPaintEntry some time ago...
223  if ( nChanged < pEntryList->GetMRUCount() )
224  nChanged = pEntryList->FindEntry( pEntryList->GetEntryText( nChanged ) );
225  mpImplWin->SetItemPos( nChanged );
226  mpImplWin->SetString( mpImplLB->GetEntryList()->GetEntryText( nChanged ) );
227  if( mpImplLB->GetEntryList()->HasImages() )
228  {
229  Image aImage = mpImplLB->GetEntryList()->GetEntryImage( nChanged );
230  mpImplWin->SetImage( aImage );
231  }
232  }
233  else
234  {
235  mpImplWin->SetItemPos( LISTBOX_ENTRY_NOTFOUND );
236  mpImplWin->SetString( OUString() );
237  Image aImage;
238  mpImplWin->SetImage( aImage );
239  }
240  mpImplWin->Invalidate();
241 }
242 
243 IMPL_LINK_NOARG(ListBox, ImplDoubleClickHdl, ImplListBoxWindow*, void)
244 {
245  DoubleClick();
246 }
247 
248 IMPL_LINK_NOARG(ListBox, ImplClickBtnHdl, void*, void)
249 {
250  if( mpFloatWin->IsInPopupMode() )
251  return;
252 
253  CallEventListeners( VclEventId::DropdownPreOpen );
254  mpImplWin->GrabFocus();
255  mpBtn->SetPressed( true );
256  mpFloatWin->StartFloat( true );
257  CallEventListeners( VclEventId::DropdownOpen );
258 
259  ImplClearLayoutData();
260  if( mpImplLB )
261  mpImplLB->GetMainWindow()->ImplClearLayoutData();
262  if( mpImplWin )
263  mpImplWin->ImplClearLayoutData();
264 }
265 
266 IMPL_LINK_NOARG(ListBox, ImplPopupModeEndHdl, FloatingWindow*, void)
267 {
268  if( mpFloatWin->IsPopupModeCanceled() )
269  {
270  if ( ( mpFloatWin->GetPopupModeStartSaveSelection() != LISTBOX_ENTRY_NOTFOUND )
271  && !IsEntryPosSelected( mpFloatWin->GetPopupModeStartSaveSelection() ) )
272  {
273  mpImplLB->SelectEntry( mpFloatWin->GetPopupModeStartSaveSelection(), true );
274  bool bTravelSelect = mpImplLB->IsTravelSelect();
275  mpImplLB->SetTravelSelect( true );
276 
277  VclPtr<vcl::Window> xWindow = this;
278  Select();
279  if ( xWindow->IsDisposed() )
280  return;
281 
282  mpImplLB->SetTravelSelect( bTravelSelect );
283  }
284  }
285 
286  ImplClearLayoutData();
287  if( mpImplLB )
288  mpImplLB->GetMainWindow()->ImplClearLayoutData();
289  if( mpImplWin )
290  mpImplWin->ImplClearLayoutData();
291 
292  mpBtn->SetPressed( false );
293  CallEventListeners( VclEventId::DropdownClose );
294 }
295 
297 {
298  if( !IsDropDownBox() )
299  return;
300 
301  if( mpFloatWin->IsInPopupMode() )
303  else
304  {
306  mpImplWin->GrabFocus();
307  mpBtn->SetPressed( true );
308  mpFloatWin->StartFloat( true );
310  }
311 }
312 
314 {
315  rRenderContext.SetBackground();
316 }
317 
318 void ListBox::Draw( OutputDevice* pDev, const Point& rPos, DrawFlags nFlags )
319 {
321 
322  Point aPos = pDev->LogicToPixel( rPos );
323  Size aSize = GetSizePixel();
324  vcl::Font aFont = mpImplLB->GetMainWindow()->GetDrawPixelFont( pDev );
325 
326  pDev->Push();
327  pDev->SetMapMode();
328  pDev->SetFont( aFont );
329  pDev->SetTextFillColor();
330 
331  // Border/Background
332  pDev->SetLineColor();
333  pDev->SetFillColor();
334  bool bBorder = (GetStyle() & WB_BORDER);
335  bool bBackground = IsControlBackground();
336  if ( bBorder || bBackground )
337  {
338  tools::Rectangle aRect( aPos, aSize );
339  if ( bBorder )
340  {
341  ImplDrawFrame( pDev, aRect );
342  }
343  if ( bBackground )
344  {
346  pDev->DrawRect( aRect );
347  }
348  }
349 
350  // Content
351  if ( nFlags & DrawFlags::Mono )
352  {
353  pDev->SetTextColor( COL_BLACK );
354  }
355  else
356  {
357  if ( !IsEnabled() )
358  {
359  const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
360  pDev->SetTextColor( rStyleSettings.GetDisableColor() );
361  }
362  else
363  {
364  pDev->SetTextColor( GetTextColor() );
365  }
366  }
367 
368  const tools::Long nOnePixel = GetDrawPixel( pDev, 1 );
369  const tools::Long nOffX = 3*nOnePixel;
371  tools::Rectangle aTextRect( aPos, aSize );
372 
373  if ( GetStyle() & WB_CENTER )
374  nTextStyle |= DrawTextFlags::Center;
375  else if ( GetStyle() & WB_RIGHT )
376  nTextStyle |= DrawTextFlags::Right;
377  else
378  nTextStyle |= DrawTextFlags::Left;
379 
380  aTextRect.AdjustLeft(nOffX );
381  aTextRect.AdjustRight( -nOffX );
382 
383  if ( IsDropDownBox() )
384  {
385  OUString aText = GetSelectedEntry();
386  tools::Long nTextHeight = pDev->GetTextHeight();
387  tools::Long nTextWidth = pDev->GetTextWidth( aText );
388  tools::Long nOffY = (aSize.Height()-nTextHeight) / 2;
389 
390  // Clipping?
391  if ( (nOffY < 0) ||
392  ((nOffY+nTextHeight) > aSize.Height()) ||
393  ((nOffX+nTextWidth) > aSize.Width()) )
394  {
395  tools::Rectangle aClip( aPos, aSize );
396  if ( nTextHeight > aSize.Height() )
397  aClip.AdjustBottom(nTextHeight-aSize.Height()+1 ); // So that HP Printers don't optimize this away
398  pDev->IntersectClipRegion( aClip );
399  }
400 
401  pDev->DrawText( aTextRect, aText, nTextStyle );
402  }
403  else
404  {
405  tools::Long nTextHeight = pDev->GetTextHeight();
406  sal_uInt16 nLines = ( nTextHeight > 0 ) ? static_cast<sal_uInt16>(aSize.Height() / nTextHeight) : 1;
407  tools::Rectangle aClip( aPos, aSize );
408 
409  pDev->IntersectClipRegion( aClip );
410 
411  if ( !nLines )
412  nLines = 1;
413 
414  for ( sal_uInt16 n = 0; n < nLines; n++ )
415  {
416  sal_Int32 nEntry = n+mpImplLB->GetTopEntry();
417  bool bSelected = mpImplLB->GetEntryList()->IsEntryPosSelected( nEntry );
418  if ( bSelected )
419  {
420  pDev->SetFillColor( COL_BLACK );
421  pDev->DrawRect( tools::Rectangle( Point( aPos.X(), aPos.Y() + n*nTextHeight ),
422  Point( aPos.X() + aSize.Width(), aPos.Y() + (n+1)*nTextHeight + 2*nOnePixel ) ) );
423  pDev->SetFillColor();
424  pDev->SetTextColor( COL_WHITE );
425  }
426 
427  aTextRect.SetTop( aPos.Y() + n*nTextHeight );
428  aTextRect.SetBottom( aTextRect.Top() + nTextHeight );
429 
430  pDev->DrawText( aTextRect, mpImplLB->GetEntryList()->GetEntryText( nEntry ), nTextStyle );
431 
432  if ( bSelected )
433  pDev->SetTextColor( COL_BLACK );
434  }
435  }
436 
437  pDev->Pop();
438 }
439 
441 {
442  if ( mpImplLB )
443  {
444  if( IsDropDownBox() )
445  mpImplWin->GrabFocus();
446  else
447  mpImplLB->GrabFocus();
448  }
449 
451 }
452 
454 {
455  if( IsDropDownBox() )
456  {
457  if (mpImplWin)
458  mpImplWin->HideFocus();
459  }
460  else
461  {
462  if (mpImplLB)
463  mpImplLB->HideFocus();
464  }
465 
467 }
468 
470 {
471  Control::DataChanged( rDCEvt );
472 
473  if ( !((rDCEvt.GetType() == DataChangedEventType::FONTS) ||
475  ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
476  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))) )
477  return;
478 
479  SetBackground(); // Due to a hack in Window::UpdateSettings the background must be reset
480  // otherwise it will overpaint NWF drawn listboxes
481  Resize();
482  mpImplLB->Resize(); // Is not called by ListBox::Resize() if the ImplLB does not change
483 
484  if ( mpImplWin )
485  {
486  mpImplWin->SetSettings( GetSettings() ); // If not yet set...
488 
491  }
492 
493  if ( IsDropDownBox() )
494  Invalidate();
495 }
496 
497 void ListBox::EnableAutoSize( bool bAuto )
498 {
499  mbDDAutoSize = bAuto;
500  if ( mpFloatWin )
501  {
502  if ( bAuto && !mpFloatWin->GetDropDownLineCount() )
503  {
504  // use GetListBoxMaximumLineCount here; before, was on fixed number of five
506  }
507  else if ( !bAuto )
508  {
510  }
511  }
512 }
513 
514 void ListBox::SetDropDownLineCount( sal_uInt16 nLines )
515 {
516  mnLineCount = nLines;
517  if ( mpFloatWin )
519 }
520 
522 {
523  // Adapt to maximum allowed number.
524  // Limit for LOK as we can't render outside of the dialog canvas.
527  else
528  SetDropDownLineCount(GetSettings().GetStyleSettings().GetListBoxMaximumLineCount());
529 }
530 
532 {
533  if ( mpFloatWin )
535  return mnLineCount;
536 }
537 
539 {
540  if( IsDropDownBox() && ( nFlags & PosSizeFlags::Size ) )
541  {
542  Size aPrefSz = mpFloatWin->GetPrefSize();
543  if ( ( nFlags & PosSizeFlags::Height ) && ( nHeight >= 2*mnDDHeight ) )
544  aPrefSz.setHeight( nHeight-mnDDHeight );
545  if ( nFlags & PosSizeFlags::Width )
546  aPrefSz.setWidth( nWidth );
547  mpFloatWin->SetPrefSize( aPrefSz );
548 
549  if (IsAutoSizeEnabled())
550  nHeight = mnDDHeight;
551  }
552 
553  Control::setPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
554 }
555 
557 {
558  Size aOutSz = GetOutputSizePixel();
559  if( IsDropDownBox() )
560  {
561  // Initialize the dropdown button size with the standard scrollbar width
563  tools::Long nBottom = aOutSz.Height();
564 
565  // Note: in case of no border, pBorder will actually be this
567  ImplControlValue aControlValue;
568  Point aPoint;
569  tools::Rectangle aContent, aBound;
570 
571  // Use the full extent of the control
572  tools::Rectangle aArea( aPoint, pBorder->GetOutputSizePixel() );
573 
575  aArea, ControlState::NONE, aControlValue, aBound, aContent) )
576  {
577  // Convert back from border space to local coordinates
578  aPoint = pBorder->ScreenToOutputPixel( OutputToScreenPixel( aPoint ) );
579  aContent.Move( -aPoint.X(), -aPoint.Y() );
580 
581  // Use the themes drop down size for the button
582  aOutSz.setWidth( aContent.Left() );
583  mpBtn->setPosSizePixel( aContent.Left(), 0, aContent.GetWidth(), nBottom );
584 
585  // Adjust the size of the edit field
587  aArea, ControlState::NONE, aControlValue, aBound, aContent) )
588  {
589  // Convert back from border space to local coordinates
590  aContent.Move( -aPoint.X(), -aPoint.Y() );
591 
592  // Use the themes drop down size
594  {
595  // No border but focus ring behavior -> we have a problem; the
596  // native rect relies on the border to draw the focus
597  // let's do the best we can and center vertically, so it doesn't look
598  // completely wrong.
599  Size aSz( GetOutputSizePixel() );
600  tools::Long nDiff = aContent.Top() - (aSz.Height() - aContent.GetHeight())/2;
601  aContent.AdjustTop( -nDiff );
602  aContent.AdjustBottom( -nDiff );
603  }
604  mpImplWin->SetPosSizePixel( aContent.TopLeft(), aContent.GetSize() );
605  }
606  else
607  mpImplWin->SetSizePixel( aOutSz );
608  }
609  else
610  {
611  nSBWidth = CalcZoom( nSBWidth );
612  mpImplWin->setPosSizePixel( 0, 0, aOutSz.Width() - nSBWidth, aOutSz.Height() );
613  mpBtn->setPosSizePixel( aOutSz.Width() - nSBWidth, 0, nSBWidth, aOutSz.Height() );
614  }
615  }
616  else
617  {
618  mpImplLB->SetSizePixel( aOutSz );
619  }
620 
621  // Retain FloatingWindow size even when it's invisible, as we still process KEY_PGUP/DOWN ...
622  if ( mpFloatWin )
624 
625  Control::Resize();
626 }
627 
629 {
630  mpControlData->mpLayoutData.reset( new vcl::ControlLayoutData );
631  const ImplListBoxWindow* rMainWin = mpImplLB->GetMainWindow();
632  if( mpFloatWin )
633  {
634  // Dropdown mode
637  if( mpFloatWin->IsReallyVisible() )
638  {
639  AppendLayoutData( *rMainWin );
640  rMainWin->SetLayoutDataParent( this );
641  }
642  }
643  else
644  {
645  AppendLayoutData( *rMainWin );
646  rMainWin->SetLayoutDataParent( this );
647  }
648 }
649 
650 tools::Long ListBox::GetIndexForPoint( const Point& rPoint, sal_Int32& rPos ) const
651 {
652  if( !HasLayoutData() )
653  FillLayoutData();
654 
655  // Check whether rPoint fits at all
657  if( nIndex != -1 )
658  {
659  // Point must be either in main list window
660  // or in impl window (dropdown case)
662 
663  // Convert coordinates to ImplListBoxWindow pixel coordinate space
664  Point aConvPoint = LogicToPixel( rPoint );
665  aConvPoint = OutputToAbsoluteScreenPixel( aConvPoint );
666  aConvPoint = rMain->AbsoluteScreenToOutputPixel( aConvPoint );
667  aConvPoint = rMain->PixelToLogic( aConvPoint );
668 
669  // Try to find entry
670  sal_Int32 nEntry = rMain->GetEntryPosForPoint( aConvPoint );
671  if( nEntry == LISTBOX_ENTRY_NOTFOUND )
672  {
673  // Not found, maybe dropdown case
675  {
676  // Convert to impl window pixel coordinates
677  aConvPoint = LogicToPixel( rPoint );
678  aConvPoint = OutputToAbsoluteScreenPixel( aConvPoint );
679  aConvPoint = mpImplWin->AbsoluteScreenToOutputPixel( aConvPoint );
680 
681  // Check whether converted point is inside impl window
682  Size aImplWinSize = mpImplWin->GetOutputSizePixel();
683  if( aConvPoint.X() >= 0 && aConvPoint.Y() >= 0 && aConvPoint.X() < aImplWinSize.Width() && aConvPoint.Y() < aImplWinSize.Height() )
684  {
685  // Inside the impl window, the position is the current item pos
686  rPos = mpImplWin->GetItemPos();
687  }
688  else
689  nIndex = -1;
690  }
691  else
692  nIndex = -1;
693  }
694  else
695  rPos = nEntry;
696 
697  SAL_WARN_IF( nIndex == -1, "vcl", "found index for point, but relative index failed" );
698  }
699 
700  // Get line relative index
701  if( nIndex != -1 )
702  nIndex = ToRelativeLineIndex( nIndex );
703 
704  return nIndex;
705 }
706 
708 {
709  if( nType == StateChangedType::ReadOnly )
710  {
711  if( mpImplWin )
712  mpImplWin->Enable( !IsReadOnly() );
713  if( mpBtn )
714  mpBtn->Enable( !IsReadOnly() );
715  }
716  else if( nType == StateChangedType::Enable )
717  {
718  mpImplLB->Enable( IsEnabled() );
719  if( mpImplWin )
720  {
721  mpImplWin->Enable( IsEnabled() );
724  {
726  }
727  else
729  }
730  if( mpBtn )
731  mpBtn->Enable( IsEnabled() );
732  }
733  else if( nType == StateChangedType::UpdateMode )
734  {
736  }
737  else if ( nType == StateChangedType::Zoom )
738  {
739  mpImplLB->SetZoom( GetZoom() );
740  if ( mpImplWin )
741  {
742  mpImplWin->SetZoom( GetZoom() );
745  }
746  Resize();
747  }
748  else if ( nType == StateChangedType::ControlFont )
749  {
751  if ( mpImplWin )
752  {
756  }
757  Resize();
758  }
759  else if ( nType == StateChangedType::ControlForeground )
760  {
762  if ( mpImplWin )
763  {
768  }
769  }
770  else if ( nType == StateChangedType::ControlBackground )
771  {
773  if ( mpImplWin )
774  {
776  {
777  // Transparent background
780  }
781  else
782  {
785  }
788  }
789  }
790  else if ( nType == StateChangedType::Style )
791  {
793  mpImplLB->GetMainWindow()->EnableSort( ( GetStyle() & WB_SORT ) != 0 );
794  bool bSimpleMode = ( GetStyle() & WB_SIMPLEMODE ) != 0;
795  mpImplLB->SetMultiSelectionSimpleMode( bSimpleMode );
796  }
797  else if( nType == StateChangedType::Mirroring )
798  {
799  if( mpBtn )
800  {
803  }
805  if( mpImplWin )
807  Resize();
808  }
809 
810  Control::StateChanged( nType );
811 }
812 
814 {
815  bool bDone = false;
816  if ( mpImplLB )
817  {
818  if( ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT ) && ( rNEvt.GetWindow() == mpImplWin ) )
819  {
820  KeyEvent aKeyEvt = *rNEvt.GetKeyEvent();
821  switch( aKeyEvt.GetKeyCode().GetCode() )
822  {
823  case KEY_DOWN:
824  {
825  if( mpFloatWin && !mpFloatWin->IsInPopupMode() &&
826  aKeyEvt.GetKeyCode().IsMod2() )
827  {
829  mpBtn->SetPressed( true );
830  mpFloatWin->StartFloat( false );
832  bDone = true;
833  }
834  else
835  {
836  bDone = mpImplLB->ProcessKeyInput( aKeyEvt );
837  }
838  }
839  break;
840  case KEY_UP:
841  {
842  if( mpFloatWin && mpFloatWin->IsInPopupMode() &&
843  aKeyEvt.GetKeyCode().IsMod2() )
844  {
846  bDone = true;
847  }
848  else
849  {
850  bDone = mpImplLB->ProcessKeyInput( aKeyEvt );
851  }
852  }
853  break;
854  case KEY_RETURN:
855  {
856  if( IsInDropDown() )
857  {
858  mpImplLB->ProcessKeyInput( aKeyEvt );
859  bDone = true;
860  }
861  }
862  break;
863 
864  default:
865  {
866  bDone = mpImplLB->ProcessKeyInput( aKeyEvt );
867  }
868  }
869  }
870  else if ( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS )
871  {
872  if ( IsInDropDown() && !HasChildPathFocus( true ) )
874  }
875  else if ( (rNEvt.GetType() == MouseNotifyEvent::COMMAND) &&
877  (rNEvt.GetWindow() == mpImplWin) )
878  {
879  MouseWheelBehaviour nWheelBehavior( GetSettings().GetMouseSettings().GetWheelBehavior() );
880  if ( ( nWheelBehavior == MouseWheelBehaviour::ALWAYS )
881  || ( ( nWheelBehavior == MouseWheelBehaviour::FocusOnly )
882  && HasChildPathFocus()
883  )
884  )
885  {
886  bDone = mpImplLB->HandleWheelAsCursorTravel(*rNEvt.GetCommandEvent(), *this);
887  }
888  else
889  {
890  bDone = false; // Don't consume this event, let the default handling take it (i.e. scroll the context)
891  }
892  }
893  }
894 
895  return bDone || Control::PreNotify( rNEvt );
896 }
897 
899 {
901 }
902 
904 {
906 }
907 
909 {
910  if (!mpImplLB)
911  return;
912  mpImplLB->Clear();
913  if( IsDropDownBox() )
914  {
916  mpImplWin->SetString( OUString() );
917  Image aImage;
918  mpImplWin->SetImage( aImage );
920  }
921  CallEventListeners( VclEventId::ListboxItemRemoved, reinterpret_cast<void*>(-1) );
922 }
923 
925 {
927  if( IsDropDownBox() )
928  {
930  mpImplWin->SetString( OUString() );
931  Image aImage;
932  mpImplWin->SetImage( aImage );
934  }
935 }
936 
937 sal_Int32 ListBox::InsertEntry( const OUString& rStr, sal_Int32 nPos )
938 {
939  sal_Int32 nRealPos = mpImplLB->InsertEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), rStr );
940  nRealPos = sal::static_int_cast<sal_Int32>(nRealPos - mpImplLB->GetEntryList()->GetMRUCount());
941  CallEventListeners( VclEventId::ListboxItemAdded, reinterpret_cast<void*>(nRealPos) );
942  return nRealPos;
943 }
944 
945 sal_Int32 ListBox::InsertEntry( const OUString& rStr, const Image& rImage, sal_Int32 nPos )
946 {
947  sal_Int32 nRealPos = mpImplLB->InsertEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), rStr, rImage );
948  nRealPos = sal::static_int_cast<sal_Int32>(nRealPos - mpImplLB->GetEntryList()->GetMRUCount());
949  CallEventListeners( VclEventId::ListboxItemAdded, reinterpret_cast<void*>(nRealPos) );
950  return nRealPos;
951 }
952 
953 void ListBox::RemoveEntry( sal_Int32 nPos )
954 {
956  CallEventListeners( VclEventId::ListboxItemRemoved, reinterpret_cast<void*>(nPos) );
957 }
958 
959 Image ListBox::GetEntryImage( sal_Int32 nPos ) const
960 {
961  if ( mpImplLB && mpImplLB->GetEntryList()->HasEntryImage( nPos ) )
962  return mpImplLB->GetEntryList()->GetEntryImage( nPos );
963  return Image();
964 }
965 
966 sal_Int32 ListBox::GetEntryPos( const OUString& rStr ) const
967 {
968  if (!mpImplLB)
969  return LISTBOX_ENTRY_NOTFOUND;
970  sal_Int32 nPos = mpImplLB->GetEntryList()->FindEntry( rStr );
971  if ( nPos != LISTBOX_ENTRY_NOTFOUND )
972  nPos = nPos - mpImplLB->GetEntryList()->GetMRUCount();
973  return nPos;
974 }
975 
976 OUString ListBox::GetEntry( sal_Int32 nPos ) const
977 {
978  if (!mpImplLB)
979  return OUString();
981 }
982 
983 sal_Int32 ListBox::GetEntryCount() const
984 {
985  if (!mpImplLB)
986  return 0;
988 }
989 
990 OUString ListBox::GetSelectedEntry(sal_Int32 nIndex) const
991 {
992  return GetEntry( GetSelectedEntryPos( nIndex ) );
993 }
994 
996 {
997  if (!mpImplLB)
998  return 0;
1000 }
1001 
1002 sal_Int32 ListBox::GetSelectedEntryPos( sal_Int32 nIndex ) const
1003 {
1004  if (!mpImplLB || !mpImplLB->GetEntryList())
1005  return LISTBOX_ENTRY_NOTFOUND;
1006 
1007  sal_Int32 nPos = mpImplLB->GetEntryList()->GetSelectedEntryPos( nIndex );
1008  if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1009  {
1010  if ( nPos < mpImplLB->GetEntryList()->GetMRUCount() )
1012  nPos = nPos - mpImplLB->GetEntryList()->GetMRUCount();
1013  }
1014  return nPos;
1015 }
1016 
1017 bool ListBox::IsEntryPosSelected( sal_Int32 nPos ) const
1018 {
1020 }
1021 
1022 void ListBox::SelectEntry( const OUString& rStr, bool bSelect )
1023 {
1024  SelectEntryPos( GetEntryPos( rStr ), bSelect );
1025 }
1026 
1027 void ListBox::SelectEntryPos( sal_Int32 nPos, bool bSelect )
1028 {
1029  if (!mpImplLB)
1030  return;
1031 
1032  if ( 0 <= nPos && nPos < mpImplLB->GetEntryList()->GetEntryCount() )
1033  {
1034  sal_Int32 nCurrentPos = mpImplLB->GetCurrentPos();
1035  mpImplLB->SelectEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), bSelect );
1036  //Only when bSelect == true, send both Selection & Focus events
1037  if (nCurrentPos != nPos && bSelect)
1038  {
1039  CallEventListeners( VclEventId::ListboxSelect, reinterpret_cast<void*>(nPos));
1040  if (HasFocus())
1041  CallEventListeners( VclEventId::ListboxFocus, reinterpret_cast<void*>(nPos));
1042  }
1043  }
1044 }
1045 
1046 void ListBox::SelectEntriesPos( const std::vector<sal_Int32>& rPositions, bool bSelect )
1047 {
1048  if (!mpImplLB)
1049  return;
1050 
1051  bool bCallListeners = false;
1052 
1053  const sal_Int32 nCurrentPos = mpImplLB->GetCurrentPos();
1054  const auto nEntryCount = mpImplLB->GetEntryList()->GetEntryCount();
1055  const auto nMRUCount = mpImplLB->GetEntryList()->GetMRUCount();
1056 
1057  for (auto nPos : rPositions)
1058  {
1059  if (0 <= nPos && nPos < nEntryCount)
1060  {
1061  mpImplLB->SelectEntry(nPos + nMRUCount, bSelect);
1062  if (nCurrentPos != nPos && bSelect)
1063  bCallListeners = true;
1064  }
1065  }
1066 
1067  //Only when bSelect == true, send both Selection & Focus events
1068  if (bCallListeners)
1069  {
1071  if (HasFocus())
1073  }
1074 }
1075 
1076 void ListBox::SetEntryData( sal_Int32 nPos, void* pNewData )
1077 {
1078  mpImplLB->SetEntryData( nPos + mpImplLB->GetEntryList()->GetMRUCount(), pNewData );
1079 }
1080 
1081 void* ListBox::GetEntryData( sal_Int32 nPos ) const
1082 {
1084 }
1085 
1086 void ListBox::SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags )
1087 {
1088  mpImplLB->SetEntryFlags( nPos + mpImplLB->GetEntryList()->GetMRUCount(), nFlags );
1089 }
1090 
1091 void ListBox::SetTopEntry( sal_Int32 nPos )
1092 {
1094 }
1095 
1096 sal_Int32 ListBox::GetTopEntry() const
1097 {
1099  if ( nPos < mpImplLB->GetEntryList()->GetMRUCount() )
1100  nPos = 0;
1101  return nPos;
1102 }
1103 
1105 {
1106  return mpImplLB->IsTravelSelect();
1107 }
1108 
1110 {
1111  // when the dropdown is dismissed, first mbInPopupMode is set to false, and on the next event iteration then
1112  // mbPopupMode is set to false
1114 }
1115 
1117 {
1119  tools::Rectangle aOffset = mpImplLB->GetMainWindow()->GetWindowExtentsRelative( static_cast<vcl::Window*>(const_cast<ListBox *>(this)) );
1120  aRect.Move( aOffset.TopLeft().X(), aOffset.TopLeft().Y() );
1121  return aRect;
1122 }
1123 
1125 {
1126  mpImplLB->EnableMultiSelection( bMulti );
1127 
1128  // WB_SIMPLEMODE:
1129  // The MultiListBox behaves just like a normal ListBox
1130  // MultiSelection is possible via corresponding additional keys
1131  bool bSimpleMode = ( GetStyle() & WB_SIMPLEMODE ) != 0;
1132  mpImplLB->SetMultiSelectionSimpleMode( bSimpleMode );
1133 
1134  // In a MultiSelection, we can't see us travelling without focus
1135  if ( mpFloatWin )
1136  mpImplLB->GetMainWindow()->AllowGrabFocus( bMulti );
1137 }
1138 
1140 {
1142 }
1143 
1145 {
1146  Size aSz;
1147 
1148  if (!mpImplLB)
1149  return aSz;
1150 
1151  aSz = CalcSubEditSize();
1152 
1153  bool bAddScrollWidth = false;
1154 
1155  if (IsDropDownBox())
1156  {
1157  aSz.AdjustHeight(4 ); // add a space between entry and border
1158  aSz.AdjustWidth(4 ); // add a little breathing space
1159  bAddScrollWidth = true;
1160  }
1161  else
1162  bAddScrollWidth = (GetStyle() & WB_VSCROLL) == WB_VSCROLL;
1163 
1164  if (bAddScrollWidth)
1165  {
1166  // Try native borders; scrollbar size may not be a good indicator
1167  // See how large the edit area inside is to estimate what is needed for the dropdown
1168  ImplControlValue aControlValue;
1169  tools::Rectangle aContent, aBound;
1170  Size aTestSize( 100, 20 );
1171  tools::Rectangle aArea( Point(), aTestSize );
1173  aControlValue, aBound, aContent) )
1174  {
1175  // use the themes drop down size
1176  aSz.AdjustWidth(aTestSize.Width() - aContent.GetWidth() );
1177  }
1178  else
1179  aSz.AdjustWidth(GetSettings().GetStyleSettings().GetScrollBarSize() );
1180  }
1181 
1182  aSz = CalcWindowSize( aSz );
1183 
1184  if (IsDropDownBox()) // Check minimum height of dropdown box
1185  {
1186  ImplControlValue aControlValue;
1187  tools::Rectangle aRect( Point( 0, 0 ), aSz );
1188  tools::Rectangle aContent, aBound;
1190  aControlValue, aBound, aContent) )
1191  {
1192  if( aBound.GetHeight() > aSz.Height() )
1193  aSz.setHeight( aBound.GetHeight() );
1194  }
1195  }
1196 
1197  return aSz;
1198 }
1199 
1201 {
1202  Size aSz;
1203 
1204  if (!mpImplLB)
1205  return aSz;
1206 
1207  if ( !IsDropDownBox() )
1209  else
1210  {
1211  aSz.setHeight( mpImplLB->GetEntryHeight() );
1212  // Size to maximum entry width
1214 
1215  if (m_nMaxWidthChars != -1)
1216  {
1218  aSz.setWidth( std::min(aSz.Width(), nMaxWidth) );
1219  }
1220 
1221  // Do not create ultrathin ListBoxes, it doesn't look good
1223  aSz.setWidth( GetSettings().GetStyleSettings().GetScrollBarSize() );
1224  }
1225 
1226  return aSz;
1227 }
1228 
1230 {
1231  return CalcMinimumSize();
1232 }
1233 
1234 Size ListBox::CalcAdjustedSize( const Size& rPrefSize ) const
1235 {
1236  Size aSz = rPrefSize;
1237  sal_Int32 nLeft, nTop, nRight, nBottom;
1238  static_cast<vcl::Window*>(const_cast<ListBox *>(this))->GetBorder( nLeft, nTop, nRight, nBottom );
1239  aSz.AdjustHeight( -(nTop+nBottom) );
1240  if ( !IsDropDownBox() )
1241  {
1242  tools::Long nEntryHeight = CalcBlockSize( 1, 1 ).Height();
1243  tools::Long nLines = aSz.Height() / nEntryHeight;
1244  if ( nLines < 1 )
1245  nLines = 1;
1246  aSz.setHeight( nLines * nEntryHeight );
1247  }
1248  else
1249  {
1250  aSz.setHeight( mnDDHeight );
1251  }
1252  aSz.AdjustHeight(nTop+nBottom );
1253 
1254  aSz = CalcWindowSize( aSz );
1255  return aSz;
1256 }
1257 
1258 Size ListBox::CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const
1259 {
1260  // ScrollBars are shown if needed
1261  Size aMinSz = CalcMinimumSize();
1262  // aMinSz = ImplCalcOutSz( aMinSz );
1263 
1264  Size aSz;
1265 
1266  // Height
1267  if ( nLines )
1268  {
1269  if ( !IsDropDownBox() )
1270  aSz.setHeight( mpImplLB->CalcSize( nLines ).Height() );
1271  else
1272  aSz.setHeight( mnDDHeight );
1273  }
1274  else
1275  aSz.setHeight( aMinSz.Height() );
1276 
1277  // Width
1278  if ( nColumns )
1279  aSz.setWidth( nColumns * GetTextWidth( OUString('X') ) );
1280  else
1281  aSz.setWidth( aMinSz.Width() );
1282 
1283  if ( IsDropDownBox() )
1284  aSz.AdjustWidth(GetSettings().GetStyleSettings().GetScrollBarSize() );
1285 
1286  if ( !IsDropDownBox() )
1287  {
1288  if ( aSz.Width() < aMinSz.Width() )
1289  aSz.AdjustHeight(GetSettings().GetStyleSettings().GetScrollBarSize() );
1290  if ( aSz.Height() < aMinSz.Height() )
1291  aSz.AdjustWidth(GetSettings().GetStyleSettings().GetScrollBarSize() );
1292  }
1293 
1294  aSz = CalcWindowSize( aSz );
1295  return aSz;
1296 }
1297 
1298 void ListBox::GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const
1299 {
1300  float nCharWidth = approximate_char_width();
1301  if ( !IsDropDownBox() )
1302  {
1304  rnCols = static_cast<sal_uInt16>(aOutSz.Width()/nCharWidth);
1305  rnLines = static_cast<sal_uInt16>(aOutSz.Height()/mpImplLB->GetEntryHeightWithMargin());
1306  }
1307  else
1308  {
1309  Size aOutSz = mpImplWin->GetOutputSizePixel();
1310  rnCols = static_cast<sal_uInt16>(aOutSz.Width()/nCharWidth);
1311  rnLines = 1;
1312  }
1313 }
1314 
1315 void ListBox::SetReadOnly( bool bReadOnly )
1316 {
1317  if ( mpImplLB->IsReadOnly() != bReadOnly )
1318  {
1319  mpImplLB->SetReadOnly( bReadOnly );
1321  }
1322 }
1323 
1325 {
1326  return mpImplLB->IsReadOnly();
1327 }
1328 
1329 void ListBox::SetSeparatorPos( sal_Int32 n )
1330 {
1331  mpImplLB->SetSeparatorPos( n );
1332 }
1333 
1334 sal_Int32 ListBox::GetSeparatorPos() const
1335 {
1336  return mpImplLB->GetSeparatorPos();
1337 }
1338 
1339 void ListBox::AddSeparator( sal_Int32 n )
1340 {
1341  mpImplLB->AddSeparator( n );
1342 }
1343 
1345 {
1346  return mpImplLB->GetDisplayLineCount();
1347 }
1348 
1350 {
1352 }
1353 
1355 {
1356  // !!! Recursion does not occur because the ImplListBox is initialized by default
1357  // to a non-transparent color in Window::ImplInitData
1358  return mpImplLB->GetDisplayBackground();
1359 }
1360 
1361 void ListBox::setMaxWidthChars(sal_Int32 nWidth)
1362 {
1363  if (nWidth != m_nMaxWidthChars)
1364  {
1365  m_nMaxWidthChars = nWidth;
1366  queue_resize();
1367  }
1368 }
1369 
1370 bool ListBox::set_property(const OString &rKey, const OUString &rValue)
1371 {
1372  if (rKey == "active")
1373  SelectEntryPos(rValue.toInt32());
1374  else if (rKey == "max-width-chars")
1375  setMaxWidthChars(rValue.toInt32());
1376  else if (rKey == "can-focus")
1377  {
1378  // as far as I can see in Gtk, setting a ComboBox as can.focus means
1379  // the focus gets stuck in it, so try here to behave like gtk does
1380  // with the settings that work, i.e. can.focus of false doesn't
1381  // set the hard WB_NOTABSTOP
1382  WinBits nBits = GetStyle();
1383  nBits &= ~(WB_TABSTOP|WB_NOTABSTOP);
1384  if (toBool(rValue))
1385  nBits |= WB_TABSTOP;
1386  SetStyle(nBits);
1387  }
1388  else
1389  return Control::set_property(rKey, rValue);
1390  return true;
1391 }
1392 
1394 {
1395  return ListBoxUIObject::create;
1396 }
1397 
1399 {
1400  Control::DumpAsPropertyTree(rJsonWriter);
1401 
1402  {
1403  auto entriesNode = rJsonWriter.startNode("entries");
1404  for (int i = 0; i < GetEntryCount(); ++i)
1405  {
1406  auto entryNode = rJsonWriter.startNode("");
1407  rJsonWriter.put("", GetEntry(i));
1408  }
1409  }
1410 
1411  rJsonWriter.put("selectedCount", GetSelectedEntryCount());
1412 
1413  {
1414  auto entriesNode = rJsonWriter.startNode("selectedEntries");
1415  for (int i = 0; i < GetSelectedEntryCount(); ++i)
1416  {
1417  auto entryNode = rJsonWriter.startNode("");
1418  rJsonWriter.put("", GetSelectedEntryPos(i));
1419  }
1420  }
1421 }
1422 
1423 MultiListBox::MultiListBox( vcl::Window* pParent, WinBits nStyle ) :
1425 {
1426  ImplInit( pParent, nStyle );
1427  EnableMultiSelection( true );
1428 }
1429 
1430 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool toBool(std::string_view rValue)
Definition: builder.cxx:80
sal_Int32 m_nMaxWidthChars
Definition: lstbox.hxx:91
Point TopLeft() const
const Color & GetTextColor() const
Definition: outdev.hxx:1132
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
Definition: text.cxx:795
bool IsControlBackground() const
Definition: window2.cxx:1087
virtual void EnableRTL(bool bEnable=true) override
Definition: ctrl.cxx:65
bool IsInPopupMode() const
Definition: floatwin.hxx:148
virtual Size GetOptimalSize() const override
Definition: listbox.cxx:1229
SAL_DLLPRIVATE float approximate_char_width() const
Definition: text.cxx:916
Image GetEntryImage(sal_Int32 nPos) const
Definition: listbox.cxx:959
bool IsDropDownBox() const
Definition: lstbox.hxx:115
bool ImplCallEventListenersAndHandler(VclEventId nEvent, std::function< void()> const &callHandler)
this calls both our event listeners, and a specified handler
Definition: ctrl.cxx:305
void SetSelectHdl(const Link< LinkParamNone *, void > &rLink)
Definition: listbox.hxx:475
OUString GetSelectedEntry(sal_Int32 nSelIndex=0) const
Definition: listbox.cxx:990
void HideFocus()
Definition: window2.cxx:91
SAL_DLLPRIVATE bool ImplIsInPrivatePopupMode() const
Definition: floatwin.hxx:122
sal_Int32 nIndex
void RemoveEntry(sal_Int32 nPos)
Definition: listbox.cxx:953
void SetPopupModeEndHdl(const Link< FloatingWindow *, void > &rLink)
Definition: floatwin.hxx:153
void SetMBDownHdl(const Link< void *, void > &rLink)
Definition: listbox.hxx:569
bool HasEntryImage(sal_Int32 nPos) const
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: listbox.cxx:313
const ImplEntryList * GetEntryList() const
Definition: listbox.hxx:410
void SetNoSelection()
sal_Int32 GetSelectedEntryPos(sal_Int32 nSelIndex=0) const
Definition: listbox.cxx:1002
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
sal_Int32 GetSeparatorPos() const
Gets the position of the separator which was added first.
Definition: listbox.hxx:441
void setWidth(tools::Long nWidth)
sal_uInt16 mnDDHeight
Definition: lstbox.hxx:90
bool GetNativeControlRegion(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, tools::Rectangle &rNativeBoundingRegion, tools::Rectangle &rNativeContentRegion) const
Query the native control's actual drawing region (including adornment)
sal_Int32 GetSelectedEntryPos(sal_Int32 nIndex) const
const CommandEvent * GetCommandEvent() const
Definition: event.hxx:326
bool IsTravelSelect() const
Definition: listbox.hxx:458
VclPtr< ImplBtn > mpBtn
Definition: lstbox.hxx:89
SAL_DLLPRIVATE void ImplDrawFrame(OutputDevice *pDev, tools::Rectangle &rRect)
draws a frame around the give rectangle, onto the given device
Definition: ctrl.cxx:336
A widget used to choose from a list of items and which has no entry.
Definition: lstbox.hxx:83
IMPL_LINK_NOARG(ListBox, ImplSelectHdl, LinkParamNone *, void)
Definition: listbox.cxx:168
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: listbox.cxx:79
void AllowGrabFocus(bool b)
Definition: listbox.hxx:297
WinBits const WB_NOGROUP
Point AbsoluteScreenToOutputPixel(const Point &rPos) const
Definition: window.cxx:2857
long Long
void disposeAndClear()
Definition: vclptr.hxx:200
const StyleSettings & GetStyleSettings() const
bool IsMultiSelectionEnabled() const
Definition: listbox.hxx:462
void Select()
Definition: listbox.cxx:898
const Size & GetPrefSize() const
Definition: listbox.hxx:516
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
ImplSVNWFData maNWFData
Definition: svdata.hxx:395
sal_Int64 n
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
sal_Int32 GetTopEntry() const
Definition: listbox.hxx:449
virtual Size GetSizePixel() const
Definition: window.cxx:2397
ScopedJsonWriterNode startNode(const char *)
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1262
WinBits const WB_RIGHT
sal_Int32 GetEntryPosForPoint(const Point &rPoint) const
void CompatStateChanged(StateChangedType nStateChange)
Definition: window.cxx:3879
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
virtual FactoryFunction GetUITestFactory() const override
Definition: listbox.cxx:1393
void SetTextFillColor()
Definition: text.cxx:701
sal_uInt16 GetCode() const
Definition: keycod.hxx:51
tools::Long GetWidth() const
sal_Int32 GetSelectedEntryCount() const
PosSizeFlags
Definition: window.hxx:140
DataChangedEventType GetType() const
Definition: event.hxx:356
const KeyEvent * GetKeyEvent() const
Definition: event.hxx:310
void IntersectClipRegion(const tools::Rectangle &rRect)
void AppendLayoutData(const Control &rSubControl) const
Definition: ctrl.cxx:273
WinBits const WB_VSCROLL
void SetDropDownLineCount(sal_uInt16 nLines)
Definition: listbox.cxx:514
void Clear()
Definition: listbox.cxx:908
virtual void SetSettings(const AllSettings &rSettings) override
const Color & GetControlBackground() const
Definition: window2.cxx:1082
VclPtr< ImplListBox > mpImplLB
Definition: lstbox.hxx:86
void SetSeparatorPos(sal_Int32 n)
Removes existing separators, and sets the position of the one and only separator. ...
Definition: listbox.cxx:1329
bool IsReadOnly() const
Definition: listbox.hxx:467
void DoubleClick()
Definition: listbox.cxx:903
void SetDropDownLineCount(sal_uInt16 n)
Definition: listbox.hxx:526
void SetEntryFlags(sal_Int32 nPos, ListBoxEntryFlags nFlags)
sal_Int32 FindEntry(const OUString &rStr, bool bSearchMRUArea=false) const
bool HasChildPathFocus(bool bSystemWindow=false) const
Definition: window.cxx:2982
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
void SetMapMode()
Definition: map.cxx:546
constexpr sal_uInt16 KEY_UP
Definition: keycodes.hxx:111
#define LISTBOX_ENTRY_NOTFOUND
Definition: lstbox.hxx:38
The invalidated area is painted with the background color/pattern.
const Fraction & GetZoom() const
Definition: window2.cxx:1210
void SelectEntry(const OUString &rStr, bool bSelect=true)
Definition: listbox.cxx:1022
void * GetEntryData(sal_Int32 nPos) const
StateChangedType
Definition: window.hxx:317
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
tools::Long GetMaxEntryWidth() const
Definition: listbox.hxx:472
sal_Int64 WinBits
vcl::Window * GetWindow() const
Definition: event.hxx:303
void SetBackground()
void SetControlFont()
Definition: window2.cxx:409
sal_Int32 GetCurrentPos() const
Definition: listbox.hxx:427
void SetReadOnly(bool b)
Definition: listbox.hxx:466
void Enable(bool bEnable=true, bool bChild=true)
Definition: window.cxx:2428
tools::Rectangle GetBoundingRectangle(sal_Int32 nItem) const
Definition: listbox.cxx:1116
void EnableAutoSize(bool bAuto)
Definition: listbox.cxx:497
sal_Int32 GetEntryCount() const
Definition: listbox.cxx:983
Size CalcAdjustedSize(const Size &rPrefSize) const
Definition: listbox.cxx:1234
tools::Long Left() const
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: listbox.cxx:469
virtual void DumpAsPropertyTree(tools::JsonWriter &)
Dumps itself and potentially its children to a property tree, to be written easily to JSON...
Definition: window.cxx:3327
const vcl::Font & GetFont() const
Definition: outdev.hxx:648
void AddSeparator(sal_Int32 n)
Adds a new separator at the given position n.
Definition: listbox.hxx:446
void SetEntryData(sal_Int32 nPos, void *pNewData)
Definition: listbox.hxx:419
AllSettingsFlags GetFlags() const
Definition: event.hxx:357
virtual const Wallpaper & GetDisplayBackground() const override
void EnableMultiSelection(bool bMulti)
Definition: listbox.cxx:1124
virtual void queue_resize(StateChangedType eReason=StateChangedType::Layout)
Definition: window2.cxx:1327
void * GetEntryData(sal_Int32 nPos) const
Definition: listbox.cxx:1081
void SetCompoundControl(bool bCompound)
Definition: window2.cxx:947
OUString GetEntry(sal_Int32 nPos) const
Definition: listbox.cxx:976
void SetDoubleClickHdl(const Link< ImplListBoxWindow *, void > &rLink)
Definition: listbox.hxx:477
tools::Rectangle GetWindowExtentsRelative(const vcl::Window *pRelativeWindow) const
Definition: window.cxx:2884
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
bool IsReadOnly() const
Definition: listbox.cxx:1324
bool mbDDAutoSize
Definition: lstbox.hxx:95
Image GetEntryImage(sal_Int32 nPos) const
ImplListBoxWindow * GetMainWindow()
Definition: listbox.hxx:411
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:51
const Color & GetControlForeground() const
Definition: window2.cxx:1072
void SetMultiSelectionSimpleMode(bool bSimple)
Definition: listbox.hxx:464
void SetTopEntry(sal_Int32 nTop)
Definition: listbox.hxx:448
constexpr sal_uInt16 KEY_DOWN
Definition: keycodes.hxx:110
void RemoveEntry(sal_Int32 nPos)
WinBits const WB_NOLIGHTBORDER
sal_Int32 GetMRUCount() const
Definition: listbox.hxx:157
sal_uInt16 GetDisplayLineCount() const
Definition: listbox.hxx:490
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:76
Size CalcWindowSize(const Size &rOutSz) const
Definition: window2.cxx:537
bool IsAutoSizeEnabled() const
Definition: lstbox.hxx:151
void SetScrollHdl(const Link< ImplListBox *, void > &rLink)
Definition: listbox.hxx:474
void SetLineColor()
const Color & GetDisableColor() const
bool IsRTLEnabled() const
Definition: outdev.hxx:1360
virtual bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:51
virtual bool set_property(const OString &rKey, const OUString &rValue) override
Definition: listbox.cxx:1370
int i
DrawFlags
Definition: window.hxx:360
virtual void Resize() override
void setMaxWidthChars(sal_Int32 nWidth)
Definition: listbox.cxx:1361
bool IsEntryPosSelected(sal_Int32 nIndex) const
tools::Long GetEntryHeight() const
Definition: listbox.hxx:470
The edit field part of a control, e.g.
bool IsNativeWidgetEnabled() const
Definition: window.cxx:3672
void AddSeparator(sal_Int32 n)
Adds a new separator at the given position n.
Definition: listbox.cxx:1339
void SetControlBackground()
Definition: window2.cxx:497
void SelectEntryPos(sal_Int32 nPos, bool bSelect=true)
Definition: listbox.cxx:1027
WinBits const WB_SIMPLEMODE
void SetReadOnly(bool bReadOnly=true)
Definition: listbox.cxx:1315
sal_uInt16 GetDropDownLineCount() const
Definition: listbox.hxx:527
void SetImage(const Image &rImg)
Definition: listbox.hxx:567
void SelectEntriesPos(const std::vector< sal_Int32 > &rPositions, bool bSelect=true)
Definition: listbox.cxx:1046
void SetControlForeground()
Definition: window2.cxx:457
tools::Rectangle GetDropDownPosSizePixel() const
Definition: listbox.cxx:1349
bool IsTravelSelect() const
Definition: listbox.cxx:1104
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1164
css::uno::Reference< css::datatransfer::dnd::XDropTarget > GetDropTarget()
Definition: mouse.cxx:659
void SetUpdateMode(bool bUpdate)
Definition: window.cxx:2945
sal_uInt16 GetDropDownLineCount() const
Definition: listbox.cxx:531
virtual ~ListBox() override
Definition: listbox.cxx:51
void CallEventListeners(VclEventId nEvent, void *pData=nullptr)
Definition: ctrl.cxx:297
bool IsUpdateMode() const
Definition: window2.cxx:1173
void SetFillColor()
tools::Long Width() const
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
CommandEventId GetCommand() const
void SetNoSelection()
Definition: listbox.cxx:924
sal_Int32 GetSelectedEntryCount() const
Definition: listbox.cxx:995
void SetZoom(const Fraction &rZoom)
Definition: window2.cxx:365
void SetTextColor(const Color &rColor)
Definition: text.cxx:666
void SetItemPos(sal_Int32 n)
Definition: listbox.hxx:563
WinBits const WB_RECTSTYLE
sal_Int32 InsertEntry(const OUString &rStr, sal_Int32 nPos=LISTBOX_APPEND)
Definition: listbox.cxx:937
bool bPopup
bool IsEntryPosSelected(sal_Int32 nPos) const
Definition: listbox.cxx:1017
MouseNotifyEvent GetType() const
Definition: event.hxx:302
void GetMaxVisColumnsAndLines(sal_uInt16 &rnCols, sal_uInt16 &rnLines) const
Definition: listbox.cxx:1298
sal_uInt16 GetDisplayLineCount() const
Definition: listbox.cxx:1344
void SetTop(tools::Long v)
void SetBottom(tools::Long v)
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:59
WinBits const WB_DROPDOWN
virtual void Resize() override
Definition: listbox.cxx:556
const AllSettings & GetSettings() const
Definition: outdev.hxx:417
Size GetOutputSizePixel() const
Definition: outdev.hxx:440
DrawTextFlags
Definition: outdev.hxx:142
tools::Long GetScrollBarSize() const
bool HandleWheelAsCursorTravel(const CommandEvent &rCEvt, Control &rControl)
virtual bool set_property(const OString &rKey, const OUString &rValue)
Definition: window2.cxx:1445
WinBits const WB_SORT
void RequestDoubleBuffering(bool bRequest)
Enable/disable double-buffering of the frame window and all its children.
Definition: window.cxx:3846
tools::Long Top() const
virtual void LoseFocus()
Definition: window.cxx:1851
Point ScreenToOutputPixel(const Point &rPos) const
Definition: window.cxx:2804
void GrabFocus()
Definition: window.cxx:2954
Size CalcSubEditSize() const
Definition: listbox.cxx:1200
void ToggleDropDown()
Definition: listbox.cxx:296
virtual const Wallpaper & GetDisplayBackground() const override
Definition: listbox.cxx:1354
SAL_DLLPRIVATE void ImplInitListBoxData()
Definition: listbox.cxx:68
WinBits const WB_LEFT
void SetStyle(WinBits nStyle)
Definition: window.cxx:1958
Point OutputToAbsoluteScreenPixel(const Point &rPos) const
Definition: window.cxx:2847
Size GetSize() const
void SetEntryFlags(sal_Int32 nPos, ListBoxEntryFlags nFlags)
this methods stores a combination of flags from the ListBoxEntryFlags::* defines at the given entry...
Definition: listbox.cxx:1086
void put(const char *pPropName, const OUString &rPropValue)
Size CalcSize(sal_Int32 nMaxLines) const
Definition: listbox.hxx:469
constexpr sal_uInt16 KEY_RETURN
Definition: keycodes.hxx:119
WinBits const WB_NOBORDER
void EnableSort(bool b)
Definition: listbox.hxx:356
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
Definition: window2.cxx:1268
Size CalcMinimumSize() const
Definition: listbox.cxx:1144
virtual bool PreNotify(NotifyEvent &rNEvt) override
Definition: listbox.cxx:813
tools::Long AdjustTop(tools::Long nVertMoveDelta)
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1039
Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1049
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:828
virtual void Draw(OutputDevice *pDev, const Point &rPos, DrawFlags nFlags) override
Definition: listbox.cxx:318
tools::Long GetIndexForPoint(const Point &rPoint, sal_Int32 &rPos) const
Definition: listbox.cxx:650
virtual void DumpAsPropertyTree(tools::JsonWriter &) override
Dumps itself and potentially its children to a property tree, to be written easily to JSON...
Definition: listbox.cxx:1398
virtual void setPosSizePixel(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2661
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:937
virtual void GetFocus() override
Definition: listbox.cxx:440
void GetBorder(sal_Int32 &rLeftBorder, sal_Int32 &rTopBorder, sal_Int32 &rRightBorder, sal_Int32 &rBottomBorder) const
Definition: window.cxx:2419
sal_Int32 GetEntryPos(const OUString &rStr) const
Definition: listbox.cxx:966
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:54
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: listbox.cxx:56
Size CalcBlockSize(sal_uInt16 nColumns, sal_uInt16 nLines) const
Definition: listbox.cxx:1258
void SetPressed(bool bPressed)
Definition: button.cxx:1544
static SAL_DLLPRIVATE WinBits ImplInitStyle(WinBits nStyle)
Definition: listbox.cxx:159
void EnableMultiSelection(bool bMulti)
Definition: listbox.hxx:461
virtual void Resize() override
Definition: ctrl.cxx:74
sal_uInt16 mnLineCount
Definition: lstbox.hxx:93
tools::Long GetIndexForPoint(const Point &rPoint) const
Definition: ctrl.cxx:134
void SetPrefSize(const Size &rSz)
Definition: listbox.hxx:515
bool ProcessKeyInput(const KeyEvent &rKEvt)
Definition: listbox.hxx:429
WindowType
VclPtr< ImplListBoxFloatingWindow > mpFloatWin
Definition: lstbox.hxx:87
Definition: ctrl.hxx:33
ListBoxEntryFlags
Definition: lstbox.hxx:48
virtual void GetFocus()
Definition: window.cxx:1837
bool mbNoFocusRects
Definition: svdata.hxx:320
#define SAL_WARN_IF(condition, area, stream)
WinBits const WB_BORDER
void SetFont(const vcl::Font &rNewFont)
std::unique_ptr< vcl::ImplControlData > mpControlData
Definition: ctrl.hxx:36
sal_Int32 GetTopEntry() const
Definition: listbox.cxx:1096
tools::Long GetEntryHeightWithMargin() const
Definition: listbox.hxx:471
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
tools::Long GetTextHeight() const
Height where any character of the current font fits; in logic coordinates.
Definition: text.cxx:903
void SetAutoWidth(bool b)
Definition: listbox.hxx:518
void SetSeparatorPos(sal_Int32 n)
Removes existing separators, and sets the position of the one and only separator. ...
Definition: listbox.hxx:436
virtual void FillLayoutData() const override
Definition: listbox.cxx:628
void SetEdgeBlending(bool bNew)
Definition: listbox.hxx:574
vcl::Font GetDrawPixelFont(::OutputDevice const *pDev) const
Definition: window2.cxx:553
tools::Long AdjustWidth(tools::Long n)
Definition: image.hxx:39
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
void SetSelectionChangedHdl(const Link< sal_Int32, void > &rLnk)
Definition: listbox.hxx:481
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
Width of the text.
Definition: text.cxx:892
tools::Long Height() const
tools::Long CalcZoom(tools::Long n) const
Definition: window2.cxx:397
tools::Long GetDrawPixel(::OutputDevice const *pDev, tools::Long nPixels) const
Definition: window2.cxx:563
sal_Int32 GetSeparatorPos() const
Gets the position of the separator which was added first.
Definition: listbox.cxx:1334
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
void SetCancelHdl(const Link< LinkParamNone *, void > &rLink)
Definition: listbox.hxx:476
tools::Long AdjustHeight(tools::Long n)
bool IsDisposed() const
Definition: window.cxx:142
WinBits const WB_TABSTOP
VclPtr< ImplWin > mpImplWin
Definition: lstbox.hxx:88
bool IsMultiSelectionEnabled() const
Definition: listbox.cxx:1139
void setHeight(tools::Long nHeight)
tools::Long GetHeight() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
WinBits const WB_CENTER
sal_Int32 InsertEntry(sal_Int32 nPos, const OUString &rStr)
bool IsEnabled() const
Definition: window2.cxx:1122
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
MouseWheelBehaviour
Definition: settings.hxx:80
void AdaptDropDownLineCountToMaximum()
Definition: listbox.cxx:521
void SetFocusHdl(const Link< sal_Int32, void > &rLink)
Definition: listbox.hxx:479
virtual void LoseFocus() override
Definition: listbox.cxx:453
WinBits GetStyle() const
Definition: window2.cxx:953
void SelectEntry(sal_Int32 nPos, bool bSelect)
OUString GetEntryText(sal_Int32 nPos) const
Point OutputToScreenPixel(const Point &rPos) const
Definition: window.cxx:2798
void StartFloat(bool bStartTracking)
WinBits const WB_GROUP
void ImplInitDropDownButton(PushButton *pButton)
Definition: imp_listbox.cxx:52
void SetTopEntry(sal_Int32 nPos)
Definition: listbox.cxx:1091
void SetString(const OUString &rStr)
Definition: listbox.hxx:565
void SetEntryData(sal_Int32 nPos, void *pNewData)
Definition: listbox.cxx:1076
bool IsReallyVisible() const
Definition: window2.cxx:1107
vcl::Font GetControlFont() const
Definition: window2.cxx:438
sal_Int32 GetItemPos() const
Definition: listbox.hxx:562
void SetImplListBox(ImplListBox *pLB)
Definition: listbox.hxx:513
Link< ListBox &, void > maSelectHdl
Definition: lstbox.hxx:92
bool HasFocus() const
Definition: window.cxx:2959
bool IsInDropDown() const
Definition: listbox.cxx:1109
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: outdevstate.cxx:60
void SetEdgeBlending(bool bNew)
void EndPopupMode(FloatWinPopupEndFlags nFlags=FloatWinPopupEndFlags::NONE)
Definition: floatwin.cxx:927
WinBits const WB_NOTABSTOP
virtual void SetPosPixel(const Point &rNewPos)
Definition: window2.cxx:1257
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
sal_Int32 GetEntryCount() const
Definition: listbox.hxx:127
virtual void StateChanged(StateChangedType nType) override
Definition: listbox.cxx:707
bool HasLayoutData() const
determines whether we currently have layout data
Definition: ctrl.cxx:90
void SetMBDownHdl(const Link< void *, void > &rLink)
Definition: listbox.hxx:592
sal_uInt16 nPos
tools::Long ToRelativeLineIndex(tools::Long nIndex) const
ToRelativeLineIndex changes a layout data index to a count relative to its line.
Definition: ctrl.cxx:211
tools::Rectangle GetBoundingRectangle(sal_Int32 nItem) const
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35
ListBox(WindowType nType)
Definition: listbox.cxx:38
virtual void setPosSizePixel(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags=PosSizeFlags::All) override
Definition: listbox.cxx:538
void SetLayoutDataParent(const Control *pParent) const
Definition: ctrl.cxx:324
void SetListItemSelectHdl(const Link< LinkParamNone *, void > &rLink)
Definition: listbox.hxx:480
bool IsMod2() const
Definition: keycod.hxx:60
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2183
IMPL_LINK(ListBox, ImplFocusHdl, sal_Int32, nPos, void)
Definition: listbox.cxx:193