LibreOffice Module vcl (master)  1
imp_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 #include <memory>
21 
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/event.hxx>
25 #include <vcl/scrbar.hxx>
26 #include <vcl/lstbox.hxx>
27 #include <vcl/i18nhelp.hxx>
28 #include <vcl/naturalsort.hxx>
29 
30 #include <listbox.hxx>
31 #include <controldata.hxx>
32 #include <svdata.hxx>
33 #include <window.h>
34 
35 #include <com/sun/star/accessibility/AccessibleRole.hpp>
36 
37 #include <rtl/instance.hxx>
38 #include <sal/log.hxx>
39 #include <o3tl/safeint.hxx>
40 #include <osl/diagnose.h>
41 #include <comphelper/string.hxx>
43 
44 #include <limits>
45 
46 #define MULTILINE_ENTRY_DRAW_FLAGS ( DrawTextFlags::WordBreak | DrawTextFlags::MultiLine | DrawTextFlags::VCenter )
47 
48 using namespace ::com::sun::star;
49 
50 static constexpr long gnBorder = 1;
51 
53 {
54  pButton->SetSymbol( SymbolType::SPIN_DOWN );
55 
58  pButton->SetBackground();
59 }
60 
62 {
63  mpWindow = pWindow;
66  mnImages = 0;
68 
69  mnMRUCount = 0;
70  mnMaxMRUCount = 0;
71 }
72 
74 {
75  Clear();
76 }
77 
79 {
80  mnImages = 0;
81  maEntries.clear();
82 }
83 
84 void ImplEntryList::SelectEntry( sal_Int32 nPos, bool bSelect )
85 {
86  if (0 <= nPos && o3tl::make_unsigned(nPos) < maEntries.size())
87  {
88  std::vector<std::unique_ptr<ImplEntryType> >::iterator iter = maEntries.begin()+nPos;
89 
90  if ( ( (*iter)->mbIsSelected != bSelect ) &&
92  {
93  (*iter)->mbIsSelected = bSelect;
95  maSelectionChangedHdl.Call( nPos );
96  }
97  }
98 }
99 
100 namespace
101 {
102  struct theSorter
103  : public rtl::StaticWithInit< comphelper::string::NaturalStringSorter, theSorter >
104  {
106  {
109  Application::GetSettings().GetLanguageTag().getLocale());
110  }
111  };
112 }
113 
114 namespace vcl
115 {
116  sal_Int32 NaturalSortCompare(const OUString &rA, const OUString &rB)
117  {
118  const comphelper::string::NaturalStringSorter &rSorter = theSorter::get();
119  return rSorter.compare(rA, rB);
120  }
121 }
122 
123 sal_Int32 ImplEntryList::InsertEntry( sal_Int32 nPos, ImplEntryType* pNewEntry, bool bSort )
124 {
125  assert(nPos >= 0);
126  assert(maEntries.size() < LISTBOX_MAX_ENTRIES);
127 
128  if ( !!pNewEntry->maImage )
129  mnImages++;
130 
131  sal_Int32 insPos = 0;
132  const sal_Int32 nEntriesSize = static_cast<sal_Int32>(maEntries.size());
133 
134  if ( !bSort || maEntries.empty())
135  {
136  if (0 <= nPos && nPos < nEntriesSize)
137  {
138  insPos = nPos;
139  maEntries.insert( maEntries.begin() + nPos, std::unique_ptr<ImplEntryType>(pNewEntry) );
140  }
141  else
142  {
143  insPos = nEntriesSize;
144  maEntries.push_back(std::unique_ptr<ImplEntryType>(pNewEntry));
145  }
146  }
147  else
148  {
149  const comphelper::string::NaturalStringSorter &rSorter = theSorter::get();
150 
151  const OUString& rStr = pNewEntry->maStr;
152 
153  ImplEntryType* pTemp = GetEntry( nEntriesSize-1 );
154 
155  try
156  {
157  sal_Int32 nComp = rSorter.compare(rStr, pTemp->maStr);
158 
159  // fast insert for sorted data
160  if ( nComp >= 0 )
161  {
162  insPos = nEntriesSize;
163  maEntries.push_back(std::unique_ptr<ImplEntryType>(pNewEntry));
164  }
165  else
166  {
167  pTemp = GetEntry( mnMRUCount );
168 
169  nComp = rSorter.compare(rStr, pTemp->maStr);
170  if ( nComp <= 0 )
171  {
172  insPos = 0;
173  maEntries.insert(maEntries.begin(), std::unique_ptr<ImplEntryType>(pNewEntry));
174  }
175  else
176  {
177  sal_uLong nLow = mnMRUCount;
178  sal_uLong nHigh = maEntries.size()-1;
179  sal_Int32 nMid;
180 
181  // binary search
182  do
183  {
184  nMid = static_cast<sal_Int32>((nLow + nHigh) / 2);
185  pTemp = GetEntry( nMid );
186 
187  nComp = rSorter.compare(rStr, pTemp->maStr);
188 
189  if ( nComp < 0 )
190  nHigh = nMid-1;
191  else
192  {
193  if ( nComp > 0 )
194  nLow = nMid + 1;
195  else
196  break;
197  }
198  }
199  while ( nLow <= nHigh );
200 
201  if ( nComp >= 0 )
202  nMid++;
203 
204  insPos = nMid;
205  maEntries.insert(maEntries.begin()+nMid, std::unique_ptr<ImplEntryType>(pNewEntry));
206  }
207  }
208  }
209  catch (uno::RuntimeException& )
210  {
211  // XXX this is arguable, if the exception occurred because pNewEntry is
212  // garbage you wouldn't insert it. If the exception occurred because the
213  // Collator implementation is garbage then give the user a chance to see
214  // his stuff
215  insPos = 0;
216  maEntries.insert(maEntries.begin(), std::unique_ptr<ImplEntryType>(pNewEntry));
217  }
218 
219  }
220 
221  return insPos;
222 }
223 
224 void ImplEntryList::RemoveEntry( sal_Int32 nPos )
225 {
226  if (0 <= nPos && o3tl::make_unsigned(nPos) < maEntries.size())
227  {
228  std::vector<std::unique_ptr<ImplEntryType> >::iterator iter = maEntries.begin()+ nPos;
229 
230  if ( !!(*iter)->maImage )
231  mnImages--;
232 
233  maEntries.erase(iter);
234  }
235 }
236 
237 sal_Int32 ImplEntryList::FindEntry( const OUString& rString, bool bSearchMRUArea ) const
238 {
239  const sal_Int32 nEntries = static_cast<sal_Int32>(maEntries.size());
240  for ( sal_Int32 n = bSearchMRUArea ? 0 : GetMRUCount(); n < nEntries; n++ )
241  {
242  OUString aComp( vcl::I18nHelper::filterFormattingChars( maEntries[n]->maStr ) );
243  if ( aComp == rString )
244  return n;
245  }
246  return LISTBOX_ENTRY_NOTFOUND;
247 }
248 
249 sal_Int32 ImplEntryList::FindMatchingEntry( const OUString& rStr, sal_Int32 nStart, bool bLazy ) const
250 {
251  sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND;
252  sal_Int32 nEntryCount = GetEntryCount();
253 
254  const vcl::I18nHelper& rI18nHelper = mpWindow->GetSettings().GetLocaleI18nHelper();
255  for ( sal_Int32 n = nStart; n < nEntryCount; )
256  {
257  ImplEntryType* pImplEntry = GetEntry( n );
258  bool bMatch;
259  if ( bLazy )
260  {
261  bMatch = rI18nHelper.MatchString( rStr, pImplEntry->maStr );
262  }
263  else
264  {
265  bMatch = pImplEntry->maStr.startsWith(rStr);
266  }
267  if ( bMatch )
268  {
269  nPos = n;
270  break;
271  }
272 
273  n++;
274  }
275 
276  return nPos;
277 }
278 
279 long ImplEntryList::GetAddedHeight( sal_Int32 i_nEndIndex, sal_Int32 i_nBeginIndex ) const
280 {
281  long nHeight = 0;
282  sal_Int32 nStart = std::min(i_nEndIndex, i_nBeginIndex);
283  sal_Int32 nStop = std::max(i_nEndIndex, i_nBeginIndex);
284  sal_Int32 nEntryCount = GetEntryCount();
285  if( 0 <= nStop && nStop != LISTBOX_ENTRY_NOTFOUND && nEntryCount != 0 )
286  {
287  // sanity check
288  if( nStop > nEntryCount-1 )
289  nStop = nEntryCount-1;
290  if (nStart < 0)
291  nStart = 0;
292  else if( nStart > nEntryCount-1 )
293  nStart = nEntryCount-1;
294 
295  sal_Int32 nIndex = nStart;
296  while( nIndex != LISTBOX_ENTRY_NOTFOUND && nIndex < nStop )
297  {
298  long nPosHeight = GetEntryPtr( nIndex )->getHeightWithMargin();
299  if (nHeight > ::std::numeric_limits<long>::max() - nPosHeight)
300  {
301  SAL_WARN( "vcl", "ImplEntryList::GetAddedHeight: truncated");
302  break;
303  }
304  nHeight += nPosHeight;
305  nIndex++;
306  }
307  }
308  else
309  nHeight = 0;
310  return i_nEndIndex > i_nBeginIndex ? nHeight : -nHeight;
311 }
312 
313 long ImplEntryList::GetEntryHeight( sal_Int32 nPos ) const
314 {
315  ImplEntryType* pImplEntry = GetEntry( nPos );
316  return pImplEntry ? pImplEntry->getHeightWithMargin() : 0;
317 }
318 
319 OUString ImplEntryList::GetEntryText( sal_Int32 nPos ) const
320 {
321  OUString aEntryText;
322  ImplEntryType* pImplEntry = GetEntry( nPos );
323  if ( pImplEntry )
324  aEntryText = pImplEntry->maStr;
325  return aEntryText;
326 }
327 
328 bool ImplEntryList::HasEntryImage( sal_Int32 nPos ) const
329 {
330  bool bImage = false;
331  ImplEntryType* pImplEntry = GetEntry( nPos );
332  if ( pImplEntry )
333  bImage = !!pImplEntry->maImage;
334  return bImage;
335 }
336 
337 Image ImplEntryList::GetEntryImage( sal_Int32 nPos ) const
338 {
339  Image aImage;
340  ImplEntryType* pImplEntry = GetEntry( nPos );
341  if ( pImplEntry )
342  aImage = pImplEntry->maImage;
343  return aImage;
344 }
345 
346 void ImplEntryList::SetEntryData( sal_Int32 nPos, void* pNewData )
347 {
348  ImplEntryType* pImplEntry = GetEntry( nPos );
349  if ( pImplEntry )
350  pImplEntry->mpUserData = pNewData;
351 }
352 
353 void* ImplEntryList::GetEntryData( sal_Int32 nPos ) const
354 {
355  ImplEntryType* pImplEntry = GetEntry( nPos );
356  return pImplEntry ? pImplEntry->mpUserData : nullptr;
357 }
358 
359 void ImplEntryList::SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags )
360 {
361  ImplEntryType* pImplEntry = GetEntry( nPos );
362  if ( pImplEntry )
363  pImplEntry->mnFlags = nFlags;
364 }
365 
367 {
368  sal_Int32 nSelCount = 0;
369  for ( sal_Int32 n = GetEntryCount(); n; )
370  {
371  ImplEntryType* pImplEntry = GetEntry( --n );
372  if ( pImplEntry->mbIsSelected )
373  nSelCount++;
374  }
375  return nSelCount;
376 }
377 
378 OUString ImplEntryList::GetSelectedEntry( sal_Int32 nIndex ) const
379 {
380  return GetEntryText( GetSelectedEntryPos( nIndex ) );
381 }
382 
383 sal_Int32 ImplEntryList::GetSelectedEntryPos( sal_Int32 nIndex ) const
384 {
385  sal_Int32 nSelEntryPos = LISTBOX_ENTRY_NOTFOUND;
386  sal_Int32 nSel = 0;
387  sal_Int32 nEntryCount = GetEntryCount();
388 
389  for ( sal_Int32 n = 0; n < nEntryCount; n++ )
390  {
391  ImplEntryType* pImplEntry = GetEntry( n );
392  if ( pImplEntry->mbIsSelected )
393  {
394  if ( nSel == nIndex )
395  {
396  nSelEntryPos = n;
397  break;
398  }
399  nSel++;
400  }
401  }
402 
403  return nSelEntryPos;
404 }
405 
406 bool ImplEntryList::IsEntryPosSelected( sal_Int32 nIndex ) const
407 {
408  ImplEntryType* pImplEntry = GetEntry( nIndex );
409  return pImplEntry && pImplEntry->mbIsSelected;
410 }
411 
412 bool ImplEntryList::IsEntrySelectable( sal_Int32 nPos ) const
413 {
414  ImplEntryType* pImplEntry = GetEntry( nPos );
415  return pImplEntry == nullptr || ((pImplEntry->mnFlags & ListBoxEntryFlags::DisableSelection) == ListBoxEntryFlags::NONE);
416 }
417 
418 sal_Int32 ImplEntryList::FindFirstSelectable( sal_Int32 nPos, bool bForward /* = true */ )
419 {
420  if( IsEntrySelectable( nPos ) )
421  return nPos;
422 
423  if( bForward )
424  {
425  for( nPos = nPos + 1; nPos < GetEntryCount(); nPos++ )
426  {
427  if( IsEntrySelectable( nPos ) )
428  return nPos;
429  }
430  }
431  else
432  {
433  while( nPos )
434  {
435  nPos--;
436  if( IsEntrySelectable( nPos ) )
437  return nPos;
438  }
439  }
440 
441  return LISTBOX_ENTRY_NOTFOUND;
442 }
443 
445  Control( pParent, 0 ),
446  maQuickSelectionEngine( *this )
447 {
448  mpEntryList.reset(new ImplEntryList( this ));
449 
450  mnTop = 0;
451  mnLeft = 0;
452  mnSelectModifier = 0;
454  mbTrack = false;
455  mbTravelSelect = false;
456  mbTrackingSelect = false;
457  mbSelectionChanged = false;
458  mbMouseMoveSelect = false;
459  mbMulti = false;
460  mbStackMode = false;
461  mbGrabFocus = false;
462  mbUserDrawEnabled = false;
463  mbInUserDraw = false;
464  mbReadOnly = false;
465  mbHasFocusRect = false;
466  mbRight = ( nWinStyle & WB_RIGHT );
467  mbCenter = ( nWinStyle & WB_CENTER );
468  mbSimpleMode = ( nWinStyle & WB_SIMPLEMODE );
469  mbSort = ( nWinStyle & WB_SORT );
470  mbIsDropdown = ( nWinStyle & WB_DROPDOWN ) || ( nWinStyle & WB_LISTBOX_POPUP );
471  mbEdgeBlending = false;
472 
473  // pb: #106948# explicit mirroring for calc
474  mbMirroring = false;
475 
478 
479  SetLineColor();
481  SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
482 
483  ApplySettings(*this);
484  ImplCalcMetrics();
485 }
486 
488 {
489  disposeOnce();
490 }
491 
493 {
494  mpEntryList.reset();
496 }
497 
499 {
500  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
501 
502  ApplyControlFont(rRenderContext, rStyleSettings.GetFieldFont());
503  ApplyControlForeground(rRenderContext, rStyleSettings.GetFieldTextColor());
504 
505  if (IsControlBackground())
506  rRenderContext.SetBackground(GetControlBackground());
507  else
508  rRenderContext.SetBackground(rStyleSettings.GetFieldColor());
509 }
510 
512 {
513  mnMaxWidth = 0;
514  mnMaxTxtWidth = 0;
515  mnMaxImgWidth = 0;
516  mnMaxImgTxtWidth= 0;
517  mnMaxImgHeight = 0;
518 
519  mnTextHeight = static_cast<sal_uInt16>(GetTextHeight());
522 
524  mnMaxHeight = static_cast<sal_uInt16>(maUserItemSize.Height());
525  if ( maUserItemSize.Width() > mnMaxWidth )
526  mnMaxWidth= static_cast<sal_uInt16>(maUserItemSize.Width());
527 
528  for ( sal_Int32 n = mpEntryList->GetEntryCount(); n; )
529  {
530  ImplEntryType* pEntry = mpEntryList->GetMutableEntryPtr( --n );
531  ImplUpdateEntryMetrics( *pEntry );
532  }
533 
535  {
536  Size aSz( GetOutputSizePixel().Width(), mpEntryList->GetEntryPtr( mnCurrentPos )->getHeightWithMargin() );
537  maFocusRect.SetSize( aSz );
538  }
539 }
540 
542 {
543  mpEntryList->Clear();
544 
546  mnMaxWidth = 0;
547  mnMaxTxtWidth = 0;
548  mnMaxImgTxtWidth= 0;
549  mnMaxImgWidth = 0;
550  mnMaxImgHeight = 0;
551  mnTop = 0;
552  mnLeft = 0;
554 
557 
558  Invalidate();
559 }
560 
562 {
564  maUserItemSize = rSz;
565  ImplCalcMetrics();
566 }
567 
568 namespace {
569 
570 struct ImplEntryMetrics
571 {
572  bool bText;
573  bool bImage;
574  long nEntryWidth;
575  long nEntryHeight;
576  long nTextWidth;
577  long nImgWidth;
578  long nImgHeight;
579 };
580 
581 }
582 
584 {
586 }
587 
589 {
590  if (maStrGlyphs.IsValid())
591  // Use pre-calculated result.
592  return &maStrGlyphs;
593 
594  std::unique_ptr<SalLayout> pLayout = pOutputDevice->ImplLayout(
595  maStr, 0, maStr.getLength(), Point(0, 0), 0, nullptr, SalLayoutFlags::GlyphItemsOnly);
596  if (!pLayout)
597  return nullptr;
598 
599  const SalLayoutGlyphs* pGlyphs = pLayout->GetGlyphs();
600  if (!pGlyphs)
601  return nullptr;
602 
603  // Remember the calculation result.
604  maStrGlyphs = *pGlyphs;
605 
606  return &maStrGlyphs;
607 }
608 
610 {
611  ImplEntryMetrics aMetrics;
612  aMetrics.bText = !rEntry.maStr.isEmpty();
613  aMetrics.bImage = !!rEntry.maImage;
614  aMetrics.nEntryWidth = 0;
615  aMetrics.nEntryHeight = 0;
616  aMetrics.nTextWidth = 0;
617  aMetrics.nImgWidth = 0;
618  aMetrics.nImgHeight = 0;
619 
620  if ( aMetrics.bText )
621  {
623  {
624  // multiline case
625  Size aCurSize( PixelToLogic( GetSizePixel() ) );
626  // set the current size to a large number
627  // GetTextRect should shrink it to the actual size
628  aCurSize.setHeight( 0x7fffff );
629  tools::Rectangle aTextRect( Point( 0, 0 ), aCurSize );
630  aTextRect = GetTextRect( aTextRect, rEntry.maStr, DrawTextFlags::WordBreak | DrawTextFlags::MultiLine );
631  aMetrics.nTextWidth = aTextRect.GetWidth();
632  if( aMetrics.nTextWidth > mnMaxTxtWidth )
633  mnMaxTxtWidth = aMetrics.nTextWidth;
634  aMetrics.nEntryWidth = mnMaxTxtWidth;
635  aMetrics.nEntryHeight = aTextRect.GetHeight() + gnBorder;
636  }
637  else
638  {
639  // normal single line case
640  const SalLayoutGlyphs* pGlyphs = rEntry.GetTextGlyphs(this);
641  aMetrics.nTextWidth
642  = static_cast<sal_uInt16>(GetTextWidth(rEntry.maStr, 0, -1, nullptr, pGlyphs));
643  if( aMetrics.nTextWidth > mnMaxTxtWidth )
644  mnMaxTxtWidth = aMetrics.nTextWidth;
645  aMetrics.nEntryWidth = mnMaxTxtWidth;
646  aMetrics.nEntryHeight = mnTextHeight + gnBorder;
647  }
648  }
649  if ( aMetrics.bImage )
650  {
651  Size aImgSz = rEntry.maImage.GetSizePixel();
652  aMetrics.nImgWidth = static_cast<sal_uInt16>(CalcZoom( aImgSz.Width() ));
653  aMetrics.nImgHeight = static_cast<sal_uInt16>(CalcZoom( aImgSz.Height() ));
654 
655  if( aMetrics.nImgWidth > mnMaxImgWidth )
656  mnMaxImgWidth = aMetrics.nImgWidth;
657  if( aMetrics.nImgHeight > mnMaxImgHeight )
658  mnMaxImgHeight = aMetrics.nImgHeight;
659 
660  mnMaxImgTxtWidth = std::max( mnMaxImgTxtWidth, aMetrics.nTextWidth );
661  aMetrics.nEntryHeight = std::max( aMetrics.nImgHeight, aMetrics.nEntryHeight );
662 
663  }
664 
665  bool bIsUserDrawEnabled = IsUserDrawEnabled();
666  if (bIsUserDrawEnabled || aMetrics.bImage)
667  {
668  aMetrics.nEntryWidth = std::max( aMetrics.nImgWidth, maUserItemSize.Width() );
669  if (!bIsUserDrawEnabled && aMetrics.bText)
670  aMetrics.nEntryWidth += aMetrics.nTextWidth + IMG_TXT_DISTANCE;
671  aMetrics.nEntryHeight = std::max( std::max( mnMaxImgHeight, maUserItemSize.Height() ) + 2,
672  aMetrics.nEntryHeight );
673  }
674 
675  if (!aMetrics.bText && !aMetrics.bImage && !bIsUserDrawEnabled)
676  {
677  // entries which have no (aka an empty) text, and no image,
678  // and are not user-drawn, should be shown nonetheless
679  aMetrics.nEntryHeight = mnTextHeight + gnBorder;
680  }
681 
682  if ( aMetrics.nEntryWidth > mnMaxWidth )
683  mnMaxWidth = aMetrics.nEntryWidth;
684  if ( aMetrics.nEntryHeight > mnMaxHeight )
685  mnMaxHeight = aMetrics.nEntryHeight;
686 
687  rEntry.mnHeight = aMetrics.nEntryHeight;
688 }
689 
691 {
692  if ( !IsTravelSelect() && GetEntryList()->GetMaxMRUCount() )
693  {
694  // Insert the selected entry as MRU, if not already first MRU
695  sal_Int32 nSelected = GetEntryList()->GetSelectedEntryPos( 0 );
696  sal_Int32 nMRUCount = GetEntryList()->GetMRUCount();
697  OUString aSelected = GetEntryList()->GetEntryText( nSelected );
698  sal_Int32 nFirstMatchingEntryPos = GetEntryList()->FindEntry( aSelected, true );
699  if ( nFirstMatchingEntryPos || !nMRUCount )
700  {
701  bool bSelectNewEntry = false;
702  if ( nFirstMatchingEntryPos < nMRUCount )
703  {
704  RemoveEntry( nFirstMatchingEntryPos );
705  nMRUCount--;
706  if ( nFirstMatchingEntryPos == nSelected )
707  bSelectNewEntry = true;
708  }
709  else if ( nMRUCount == GetEntryList()->GetMaxMRUCount() )
710  {
711  RemoveEntry( nMRUCount - 1 );
712  nMRUCount--;
713  }
714 
716 
717  ImplEntryType* pNewEntry = new ImplEntryType( aSelected );
718  pNewEntry->mbIsSelected = bSelectNewEntry;
719  GetEntryList()->InsertEntry( 0, pNewEntry, false );
720  ImplUpdateEntryMetrics( *pNewEntry );
721  GetEntryList()->SetMRUCount( ++nMRUCount );
722  SetSeparatorPos( nMRUCount ? nMRUCount-1 : 0 );
723  maMRUChangedHdl.Call( nullptr );
724  }
725  }
726 
727  maSelectHdl.Call( nullptr );
728  mbSelectionChanged = false;
729 }
730 
731 sal_Int32 ImplListBoxWindow::InsertEntry(sal_Int32 nPos, ImplEntryType* pNewEntry, bool bSort)
732 {
733  assert(nPos >= 0);
734  assert(mpEntryList->GetEntryCount() < LISTBOX_MAX_ENTRIES);
735 
737  sal_Int32 nNewPos = mpEntryList->InsertEntry( nPos, pNewEntry, bSort );
738 
739  if( GetStyle() & WB_WORDBREAK )
741 
742  ImplUpdateEntryMetrics( *pNewEntry );
743  return nNewPos;
744 }
745 
746 sal_Int32 ImplListBoxWindow::InsertEntry( sal_Int32 nPos, ImplEntryType* pNewEntry )
747 {
748  return InsertEntry(nPos, pNewEntry, mbSort);
749 }
750 
751 void ImplListBoxWindow::RemoveEntry( sal_Int32 nPos )
752 {
754  mpEntryList->RemoveEntry( nPos );
755  if( mnCurrentPos >= mpEntryList->GetEntryCount() )
757  ImplCalcMetrics();
758 }
759 
761 {
762  mpEntryList->SetEntryFlags( nPos, nFlags );
763  ImplEntryType* pEntry = mpEntryList->GetMutableEntryPtr( nPos );
764  if( pEntry )
765  ImplUpdateEntryMetrics( *pEntry );
766 }
767 
769 {
770  if ( mbHasFocusRect )
771  HideFocus();
773  mbHasFocusRect = true;
774 }
775 
777 {
778  if ( mbHasFocusRect )
779  {
780  HideFocus();
781  mbHasFocusRect = false;
782  }
783 }
784 
785 sal_Int32 ImplListBoxWindow::GetEntryPosForPoint( const Point& rPoint ) const
786 {
787  long nY = gnBorder;
788 
789  sal_Int32 nSelect = mnTop;
790  const ImplEntryType* pEntry = mpEntryList->GetEntryPtr( nSelect );
791  while (pEntry)
792  {
793  long nEntryHeight = pEntry->getHeightWithMargin();
794  if (rPoint.Y() <= nEntryHeight + nY)
795  break;
796  nY += nEntryHeight;
797  pEntry = mpEntryList->GetEntryPtr( ++nSelect );
798  }
799  if( pEntry == nullptr )
800  nSelect = LISTBOX_ENTRY_NOTFOUND;
801 
802  return nSelect;
803 }
804 
805 bool ImplListBoxWindow::IsVisible( sal_Int32 i_nEntry ) const
806 {
807  bool bRet = false;
808 
809  if( i_nEntry >= mnTop )
810  {
811  if( mpEntryList->GetAddedHeight( i_nEntry, mnTop ) <
812  PixelToLogic( GetSizePixel() ).Height() )
813  {
814  bRet = true;
815  }
816  }
817 
818  return bRet;
819 }
820 
822 {
823  long nMargin = ImplGetSVData()->maNWFData.mnListBoxEntryMargin;
824  return mnMaxHeight + nMargin;
825 }
826 
828 {
829  sal_Int32 nPos = mnTop;
830  long nWindowHeight = GetSizePixel().Height();
831  sal_Int32 nCount = mpEntryList->GetEntryCount();
832  long nDiff;
833  for( nDiff = 0; nDiff < nWindowHeight && nPos < nCount; nDiff = mpEntryList->GetAddedHeight( nPos, mnTop ) )
834  nPos++;
835 
836  if( nDiff > nWindowHeight && nPos > mnTop )
837  nPos--;
838 
839  if( nPos >= nCount )
840  nPos = nCount-1;
841 
842  return nPos;
843 }
844 
846 {
847  mbMouseMoveSelect = false; // only till the first MouseButtonDown
849 
850  if ( !IsReadOnly() )
851  {
852  if( rMEvt.GetClicks() == 1 )
853  {
854  sal_Int32 nSelect = GetEntryPosForPoint( rMEvt.GetPosPixel() );
855  if( nSelect != LISTBOX_ENTRY_NOTFOUND )
856  {
859  else
861 
862  mnCurrentPos = nSelect;
863  mbTrackingSelect = true;
864  bool bCurPosChange = (mnCurrentPos != nSelect);
865  (void)SelectEntries( nSelect, LET_MBDOWN, rMEvt.IsShift(), rMEvt.IsMod1() ,bCurPosChange);
866  mbTrackingSelect = false;
867  if ( mbGrabFocus )
868  GrabFocus();
869 
871  }
872  }
873  if( rMEvt.GetClicks() == 2 )
874  {
875  maDoubleClickHdl.Call( this );
876  }
877  }
878  else // if ( mbGrabFocus )
879  {
880  GrabFocus();
881  }
882 }
883 
885 {
886  if ( rMEvt.IsLeaveWindow() )
887  {
889  {
890  if ( rMEvt.GetPosPixel().Y() < 0 )
891  {
892  DeselectAll();
894  SetTopEntry( 0 );
895  if ( mbStackMode )
896  {
897  mbTravelSelect = true;
898  mnSelectModifier = rMEvt.GetModifier();
899  ImplCallSelect();
900  mbTravelSelect = false;
901  }
902 
903  }
904  }
905  }
906  else if ( ( ( !mbMulti && IsMouseMoveSelect() ) || mbStackMode ) && mpEntryList->GetEntryCount() )
907  {
909  if( aRect.IsInside( rMEvt.GetPosPixel() ) )
910  {
911  if ( IsMouseMoveSelect() )
912  {
913  sal_Int32 nSelect = GetEntryPosForPoint( rMEvt.GetPosPixel() );
914  if( nSelect == LISTBOX_ENTRY_NOTFOUND )
915  nSelect = mpEntryList->GetEntryCount() - 1;
916  nSelect = std::min( nSelect, GetLastVisibleEntry() );
917  nSelect = std::min( nSelect, static_cast<sal_Int32>( mpEntryList->GetEntryCount() - 1 ) );
918  // Select only visible Entries with MouseMove, otherwise Tracking...
919  if ( IsVisible( nSelect ) &&
920  mpEntryList->IsEntrySelectable( nSelect ) &&
921  ( ( nSelect != mnCurrentPos ) || !GetEntryList()->GetSelectedEntryCount() || ( nSelect != GetEntryList()->GetSelectedEntryPos( 0 ) ) ) )
922  {
923  mbTrackingSelect = true;
924  if ( SelectEntries( nSelect, LET_TRACKING ) )
925  {
926  if ( mbStackMode )
927  {
928  mbTravelSelect = true;
929  mnSelectModifier = rMEvt.GetModifier();
930  ImplCallSelect();
931  mbTravelSelect = false;
932  }
933  // When list box selection change by mouse move, notify
934  // VclEventId::ListboxSelect vcl event.
935  else
936  {
937  maListItemSelectHdl.Call(nullptr);
938  }
939  }
940  mbTrackingSelect = false;
941  }
942  }
943 
944  // if the DD button was pressed and someone moved into the ListBox
945  // with the mouse button pressed...
946  if ( rMEvt.IsLeft() && !rMEvt.IsSynthetic() )
947  {
950  else
952 
953  if ( mbStackMode && ( mpEntryList->GetSelectionAnchor() == LISTBOX_ENTRY_NOTFOUND ) )
954  mpEntryList->SetSelectionAnchor( 0 );
955 
957  }
958  }
959  }
960 }
961 
963 {
964  while ( GetEntryList()->GetSelectedEntryCount() )
965  {
966  sal_Int32 nS = GetEntryList()->GetSelectedEntryPos( 0 );
967  SelectEntry( nS, false );
968  }
969 }
970 
971 void ImplListBoxWindow::SelectEntry( sal_Int32 nPos, bool bSelect )
972 {
973  if( (mpEntryList->IsEntryPosSelected( nPos ) != bSelect) && mpEntryList->IsEntrySelectable( nPos ) )
974  {
976  if( bSelect )
977  {
978  if( !mbMulti )
979  {
980  // deselect the selected entry
981  sal_Int32 nDeselect = GetEntryList()->GetSelectedEntryPos( 0 );
982  if( nDeselect != LISTBOX_ENTRY_NOTFOUND )
983  {
984  //SelectEntryPos( nDeselect, false );
985  GetEntryList()->SelectEntry( nDeselect, false );
986  if (IsUpdateMode() && IsReallyVisible())
987  Invalidate();
988  }
989  }
990  mpEntryList->SelectEntry( nPos, true );
991  mnCurrentPos = nPos;
992  if ( ( nPos != LISTBOX_ENTRY_NOTFOUND ) && IsUpdateMode() )
993  {
994  Invalidate();
995  if ( !IsVisible( nPos ) )
996  {
998  sal_Int32 nVisibleEntries = GetLastVisibleEntry()-mnTop;
999  if ( !nVisibleEntries || !IsReallyVisible() || ( nPos < GetTopEntry() ) )
1000  {
1001  Resize();
1002  ShowProminentEntry( nPos );
1003  }
1004  else
1005  {
1006  ShowProminentEntry( nPos );
1007  }
1008  }
1009  }
1010  }
1011  else
1012  {
1013  mpEntryList->SelectEntry( nPos, false );
1014  Invalidate();
1015  }
1016  mbSelectionChanged = true;
1017  }
1018 }
1019 
1020 bool ImplListBoxWindow::SelectEntries( sal_Int32 nSelect, LB_EVENT_TYPE eLET, bool bShift, bool bCtrl, bool bSelectPosChange /*=FALSE*/ )
1021 {
1022  bool bSelectionChanged = false;
1023 
1024  if( IsEnabled() && mpEntryList->IsEntrySelectable( nSelect ) )
1025  {
1026  bool bFocusChanged = false;
1027 
1028  // here (Single-ListBox) only one entry can be deselected
1029  if( !mbMulti )
1030  {
1031  sal_Int32 nDeselect = mpEntryList->GetSelectedEntryPos( 0 );
1032  if( nSelect != nDeselect )
1033  {
1034  SelectEntry( nSelect, true );
1035  mpEntryList->SetLastSelected( nSelect );
1036  bFocusChanged = true;
1037  bSelectionChanged = true;
1038  }
1039  }
1040  // MultiListBox without Modifier
1041  else if( mbSimpleMode && !bCtrl && !bShift )
1042  {
1043  sal_Int32 nEntryCount = mpEntryList->GetEntryCount();
1044  for ( sal_Int32 nPos = 0; nPos < nEntryCount; nPos++ )
1045  {
1046  bool bSelect = nPos == nSelect;
1047  if ( mpEntryList->IsEntryPosSelected( nPos ) != bSelect )
1048  {
1049  SelectEntry( nPos, bSelect );
1050  bFocusChanged = true;
1051  bSelectionChanged = true;
1052  }
1053  }
1054  mpEntryList->SetLastSelected( nSelect );
1055  mpEntryList->SetSelectionAnchor( nSelect );
1056  }
1057  // MultiListBox only with CTRL/SHIFT or not in SimpleMode
1058  else if( ( !mbSimpleMode /* && !bShift */ ) || ( (mbSimpleMode && ( bCtrl || bShift )) || mbStackMode ) )
1059  {
1060  // Space for selection change
1061  if( !bShift && ( ( eLET == LET_KEYSPACE ) || ( eLET == LET_MBDOWN ) ) )
1062  {
1063  bool bSelect = ( mbStackMode && IsMouseMoveSelect() ) || !mpEntryList->IsEntryPosSelected( nSelect );
1064  if ( mbStackMode )
1065  {
1066  sal_Int32 n;
1067  if ( bSelect )
1068  {
1069  // All entries before nSelect must be selected...
1070  for ( n = 0; n < nSelect; n++ )
1071  SelectEntry( n, true );
1072  }
1073  if ( !bSelect )
1074  {
1075  for ( n = nSelect+1; n < mpEntryList->GetEntryCount(); n++ )
1076  SelectEntry( n, false );
1077  }
1078  }
1079  SelectEntry( nSelect, bSelect );
1080  mpEntryList->SetLastSelected( nSelect );
1081  mpEntryList->SetSelectionAnchor( mbStackMode ? 0 : nSelect );
1082  if ( !mpEntryList->IsEntryPosSelected( nSelect ) )
1083  mpEntryList->SetSelectionAnchor( LISTBOX_ENTRY_NOTFOUND );
1084  bFocusChanged = true;
1085  bSelectionChanged = true;
1086  }
1087  else if( ( ( eLET == LET_TRACKING ) && ( nSelect != mnCurrentPos ) ) ||
1088  ( (bShift||mbStackMode) && ( ( eLET == LET_KEYMOVE ) || ( eLET == LET_MBDOWN ) ) ) )
1089  {
1090  mnCurrentPos = nSelect;
1091  bFocusChanged = true;
1092 
1093  sal_Int32 nAnchor = mpEntryList->GetSelectionAnchor();
1094  if( ( nAnchor == LISTBOX_ENTRY_NOTFOUND ) && ( mpEntryList->GetSelectedEntryCount() || mbStackMode ) )
1095  {
1096  nAnchor = mbStackMode ? 0 : mpEntryList->GetSelectedEntryPos( mpEntryList->GetSelectedEntryCount() - 1 );
1097  }
1098  if( nAnchor != LISTBOX_ENTRY_NOTFOUND )
1099  {
1100  // All entries from Anchor to nSelect have to be selected
1101  sal_Int32 nStart = std::min( nSelect, nAnchor );
1102  sal_Int32 nEnd = std::max( nSelect, nAnchor );
1103  for ( sal_Int32 n = nStart; n <= nEnd; n++ )
1104  {
1105  if ( !mpEntryList->IsEntryPosSelected( n ) )
1106  {
1107  SelectEntry( n, true );
1108  bSelectionChanged = true;
1109  }
1110  }
1111 
1112  // if appropriate some more has to be deselected...
1113  sal_Int32 nLast = mpEntryList->GetLastSelected();
1114  if ( nLast != LISTBOX_ENTRY_NOTFOUND )
1115  {
1116  if ( ( nLast > nSelect ) && ( nLast > nAnchor ) )
1117  {
1118  for ( sal_Int32 n = nSelect+1; n <= nLast; n++ )
1119  {
1120  if ( mpEntryList->IsEntryPosSelected( n ) )
1121  {
1122  SelectEntry( n, false );
1123  bSelectionChanged = true;
1124  }
1125  }
1126  }
1127  else if ( ( nLast < nSelect ) && ( nLast < nAnchor ) )
1128  {
1129  for ( sal_Int32 n = nLast; n < nSelect; n++ )
1130  {
1131  if ( mpEntryList->IsEntryPosSelected( n ) )
1132  {
1133  SelectEntry( n, false );
1134  bSelectionChanged = true;
1135  }
1136  }
1137  }
1138  }
1139  mpEntryList->SetLastSelected( nSelect );
1140  }
1141  }
1142  else if( eLET != LET_TRACKING )
1143  {
1145  Invalidate();
1146  bFocusChanged = true;
1147  }
1148  }
1149  else if( bShift )
1150  {
1151  bFocusChanged = true;
1152  }
1153 
1154  if( bSelectionChanged )
1155  mbSelectionChanged = true;
1156 
1157  if( bFocusChanged )
1158  {
1159  long nHeightDiff = mpEntryList->GetAddedHeight( nSelect, mnTop );
1160  maFocusRect.SetPos( Point( 0, nHeightDiff ) );
1161  Size aSz( maFocusRect.GetWidth(),
1162  mpEntryList->GetEntryHeight( nSelect ) );
1163  maFocusRect.SetSize( aSz );
1164  if( HasFocus() )
1166  if (bSelectPosChange)
1167  {
1168  maFocusHdl.Call(nSelect);
1169  }
1170  }
1172  }
1173  return bSelectionChanged;
1174 }
1175 
1177 {
1179  bool bInside = aRect.IsInside( rTEvt.GetMouseEvent().GetPosPixel() );
1180 
1181  if( rTEvt.IsTrackingCanceled() || rTEvt.IsTrackingEnded() ) // MouseButtonUp
1182  {
1183  if ( bInside && !rTEvt.IsTrackingCanceled() )
1184  {
1186  ImplCallSelect();
1187  }
1188  else
1189  {
1190  maCancelHdl.Call( nullptr );
1191  if ( !mbMulti )
1192  {
1193  mbTrackingSelect = true;
1195  mbTrackingSelect = false;
1197  {
1198  long nHeightDiff = mpEntryList->GetAddedHeight( mnCurrentPos, mnTop );
1199  maFocusRect.SetPos( Point( 0, nHeightDiff ) );
1200  Size aSz( maFocusRect.GetWidth(),
1201  mpEntryList->GetEntryHeight( mnCurrentPos ) );
1202  maFocusRect.SetSize( aSz );
1204  }
1205  }
1206  }
1207 
1208  mbTrack = false;
1209  }
1210  else
1211  {
1212  bool bTrackOrQuickClick = mbTrack;
1213  if( !mbTrack )
1214  {
1215  if ( bInside )
1216  {
1217  mbTrack = true;
1218  }
1219 
1220  // this case only happens, if the mouse button is pressed very briefly
1221  if( rTEvt.IsTrackingEnded() && mbTrack )
1222  {
1223  bTrackOrQuickClick = true;
1224  mbTrack = false;
1225  }
1226  }
1227 
1228  if( bTrackOrQuickClick )
1229  {
1230  MouseEvent aMEvt = rTEvt.GetMouseEvent();
1231  Point aPt( aMEvt.GetPosPixel() );
1232  bool bShift = aMEvt.IsShift();
1233  bool bCtrl = aMEvt.IsMod1();
1234 
1235  sal_Int32 nSelect = LISTBOX_ENTRY_NOTFOUND;
1236  if( aPt.Y() < 0 )
1237  {
1239  {
1240  nSelect = mnCurrentPos ? ( mnCurrentPos - 1 ) : 0;
1241  if( nSelect < mnTop )
1242  SetTopEntry( mnTop-1 );
1243  }
1244  }
1245  else if( aPt.Y() > GetOutputSizePixel().Height() )
1246  {
1248  {
1249  nSelect = std::min( static_cast<sal_Int32>(mnCurrentPos+1), static_cast<sal_Int32>(mpEntryList->GetEntryCount()-1) );
1250  if( nSelect >= GetLastVisibleEntry() )
1251  SetTopEntry( mnTop+1 );
1252  }
1253  }
1254  else
1255  {
1256  nSelect = static_cast<sal_Int32>( ( aPt.Y() + gnBorder ) / mnMaxHeight ) + mnTop;
1257  nSelect = std::min( nSelect, GetLastVisibleEntry() );
1258  nSelect = std::min( nSelect, static_cast<sal_Int32>( mpEntryList->GetEntryCount() - 1 ) );
1259  }
1260 
1261  if ( bInside )
1262  {
1263  if ( ( nSelect != mnCurrentPos ) || !GetEntryList()->GetSelectedEntryCount() )
1264  {
1265  mbTrackingSelect = true;
1266  if ( SelectEntries( nSelect, LET_TRACKING, bShift, bCtrl ) )
1267  {
1268  if ( mbStackMode )
1269  {
1270  mbTravelSelect = true;
1272  ImplCallSelect();
1273  mbTravelSelect = false;
1274  }
1275  }
1276  mbTrackingSelect = false;
1277  }
1278  }
1279  else
1280  {
1281  if ( !mbMulti && GetEntryList()->GetSelectedEntryCount() )
1282  {
1283  mbTrackingSelect = true;
1284  SelectEntry( GetEntryList()->GetSelectedEntryPos( 0 ), false );
1285  mbTrackingSelect = false;
1286  }
1287  else if ( mbStackMode )
1288  {
1289  if ( ( rTEvt.GetMouseEvent().GetPosPixel().X() > 0 ) && ( rTEvt.GetMouseEvent().GetPosPixel().X() < aRect.Right() ) )
1290  {
1291  if ( ( rTEvt.GetMouseEvent().GetPosPixel().Y() < 0 ) || ( rTEvt.GetMouseEvent().GetPosPixel().Y() > GetOutputSizePixel().Height() ) )
1292  {
1293  bool bSelectionChanged = false;
1294  if ( ( rTEvt.GetMouseEvent().GetPosPixel().Y() < 0 )
1295  && !mnCurrentPos )
1296  {
1297  if ( mpEntryList->IsEntryPosSelected( 0 ) )
1298  {
1299  SelectEntry( 0, false );
1300  bSelectionChanged = true;
1301  nSelect = LISTBOX_ENTRY_NOTFOUND;
1302 
1303  }
1304  }
1305  else
1306  {
1307  mbTrackingSelect = true;
1308  bSelectionChanged = SelectEntries( nSelect, LET_TRACKING, bShift, bCtrl );
1309  mbTrackingSelect = false;
1310  }
1311 
1312  if ( bSelectionChanged )
1313  {
1314  mbSelectionChanged = true;
1315  mbTravelSelect = true;
1317  ImplCallSelect();
1318  mbTravelSelect = false;
1319  }
1320  }
1321  }
1322  }
1323  }
1324  mnCurrentPos = nSelect;
1326  {
1328  }
1329  else
1330  {
1331  long nHeightDiff = mpEntryList->GetAddedHeight( mnCurrentPos, mnTop );
1332  maFocusRect.SetPos( Point( 0, nHeightDiff ) );
1333  Size aSz( maFocusRect.GetWidth(), mpEntryList->GetEntryHeight( mnCurrentPos ) );
1334  maFocusRect.SetSize( aSz );
1336  }
1337  }
1338  }
1339 }
1340 
1342 {
1343  if( !ProcessKeyInput( rKEvt ) )
1344  Control::KeyInput( rKEvt );
1345 }
1346 
1348 {
1349  // entry to be selected
1350  sal_Int32 nSelect = LISTBOX_ENTRY_NOTFOUND;
1351  LB_EVENT_TYPE eLET = LET_KEYMOVE;
1352 
1353  vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
1354 
1355  bool bShift = aKeyCode.IsShift();
1356  bool bCtrl = aKeyCode.IsMod1() || aKeyCode.IsMod3();
1357  bool bMod2 = aKeyCode.IsMod2();
1358  bool bDone = false;
1359  bool bHandleKey = false;
1360 
1361  switch( aKeyCode.GetCode() )
1362  {
1363  case KEY_UP:
1364  {
1365  if ( IsReadOnly() )
1366  {
1367  if ( GetTopEntry() )
1368  SetTopEntry( GetTopEntry()-1 );
1369  }
1370  else if ( !bMod2 )
1371  {
1373  {
1374  nSelect = mpEntryList->FindFirstSelectable( 0 );
1375  }
1376  else if ( mnCurrentPos )
1377  {
1378  // search first selectable above the current position
1379  nSelect = mpEntryList->FindFirstSelectable( mnCurrentPos - 1, false );
1380  }
1381 
1382  if( ( nSelect != LISTBOX_ENTRY_NOTFOUND ) && ( nSelect < mnTop ) )
1383  SetTopEntry( mnTop-1 );
1384 
1385  bDone = true;
1386  }
1388  }
1389  break;
1390 
1391  case KEY_DOWN:
1392  {
1393  if ( IsReadOnly() )
1394  {
1395  SetTopEntry( GetTopEntry()+1 );
1396  }
1397  else if ( !bMod2 )
1398  {
1400  {
1401  nSelect = mpEntryList->FindFirstSelectable( 0 );
1402  }
1403  else if ( (mnCurrentPos+1) < mpEntryList->GetEntryCount() )
1404  {
1405  // search first selectable below the current position
1406  nSelect = mpEntryList->FindFirstSelectable( mnCurrentPos + 1 );
1407  }
1408 
1409  if( ( nSelect != LISTBOX_ENTRY_NOTFOUND ) && ( nSelect >= GetLastVisibleEntry() ) )
1410  SetTopEntry( mnTop+1 );
1411 
1412  bDone = true;
1413  }
1415  }
1416  break;
1417 
1418  case KEY_PAGEUP:
1419  {
1420  if ( IsReadOnly() )
1421  {
1422  sal_Int32 nCurVis = GetLastVisibleEntry() - mnTop +1;
1423  SetTopEntry( ( mnTop > nCurVis ) ?
1424  (mnTop-nCurVis) : 0 );
1425  }
1426  else if ( !bCtrl && !bMod2 )
1427  {
1429  {
1430  nSelect = mpEntryList->FindFirstSelectable( 0 );
1431  }
1432  else if ( mnCurrentPos )
1433  {
1434  if( mnCurrentPos == mnTop )
1435  {
1436  sal_Int32 nCurVis = GetLastVisibleEntry() - mnTop +1;
1437  SetTopEntry( ( mnTop > nCurVis ) ? ( mnTop-nCurVis+1 ) : 0 );
1438  }
1439 
1440  // find first selectable starting from mnTop looking forward
1441  nSelect = mpEntryList->FindFirstSelectable( mnTop );
1442  }
1443  bDone = true;
1444  }
1446  }
1447  break;
1448 
1449  case KEY_PAGEDOWN:
1450  {
1451  if ( IsReadOnly() )
1452  {
1454  }
1455  else if ( !bCtrl && !bMod2 )
1456  {
1458  {
1459  nSelect = mpEntryList->FindFirstSelectable( 0 );
1460  }
1461  else if ( (mnCurrentPos+1) < mpEntryList->GetEntryCount() )
1462  {
1463  sal_Int32 nCount = mpEntryList->GetEntryCount();
1464  sal_Int32 nCurVis = GetLastVisibleEntry() - mnTop;
1465  sal_Int32 nTmp = std::min( nCurVis, nCount );
1466  nTmp += mnTop - 1;
1467  if( mnCurrentPos == nTmp && mnCurrentPos != nCount - 1 )
1468  {
1469  long nTmp2 = std::min( static_cast<long>(nCount-nCurVis), static_cast<long>(static_cast<long>(mnTop)+static_cast<long>(nCurVis)-1) );
1470  nTmp2 = std::max( long(0) , nTmp2 );
1471  nTmp = static_cast<sal_Int32>(nTmp2+(nCurVis-1) );
1472  SetTopEntry( static_cast<sal_Int32>(nTmp2) );
1473  }
1474  // find first selectable starting from nTmp looking backwards
1475  nSelect = mpEntryList->FindFirstSelectable( nTmp, false );
1476  }
1477  bDone = true;
1478  }
1480  }
1481  break;
1482 
1483  case KEY_HOME:
1484  {
1485  if ( IsReadOnly() )
1486  {
1487  SetTopEntry( 0 );
1488  }
1489  else if ( !bCtrl && !bMod2 && mnCurrentPos )
1490  {
1491  nSelect = mpEntryList->FindFirstSelectable( mpEntryList->GetEntryCount() ? 0 : LISTBOX_ENTRY_NOTFOUND );
1492  if( mnTop != 0 )
1493  SetTopEntry( 0 );
1494 
1495  bDone = true;
1496  }
1498  }
1499  break;
1500 
1501  case KEY_END:
1502  {
1503  if ( IsReadOnly() )
1504  {
1505  SetTopEntry( 0xFFFF );
1506  }
1507  else if ( !bCtrl && !bMod2 )
1508  {
1510  {
1511  nSelect = mpEntryList->FindFirstSelectable( 0 );
1512  }
1513  else if ( (mnCurrentPos+1) < mpEntryList->GetEntryCount() )
1514  {
1515  sal_Int32 nCount = mpEntryList->GetEntryCount();
1516  nSelect = mpEntryList->FindFirstSelectable( nCount - 1, false );
1517  sal_Int32 nCurVis = GetLastVisibleEntry() - mnTop + 1;
1518  if( nCount > nCurVis )
1519  SetTopEntry( nCount - nCurVis );
1520  }
1521  bDone = true;
1522  }
1524  }
1525  break;
1526 
1527  case KEY_LEFT:
1528  {
1529  if ( !bCtrl && !bMod2 )
1530  {
1531  ScrollHorz( -HORZ_SCROLL );
1532  bDone = true;
1533  }
1535  }
1536  break;
1537 
1538  case KEY_RIGHT:
1539  {
1540  if ( !bCtrl && !bMod2 )
1541  {
1543  bDone = true;
1544  }
1546  }
1547  break;
1548 
1549  case KEY_RETURN:
1550  {
1551  if ( !bMod2 && !IsReadOnly() )
1552  {
1554  ImplCallSelect();
1555  bDone = false; // do not catch RETURN
1556  }
1558  }
1559  break;
1560 
1561  case KEY_SPACE:
1562  {
1563  if ( !bMod2 && !IsReadOnly() )
1564  {
1565  if( mbMulti && ( !mbSimpleMode || ( mbSimpleMode && bCtrl && !bShift ) || mbStackMode ) )
1566  {
1567  nSelect = mnCurrentPos;
1568  eLET = LET_KEYSPACE;
1569  }
1570  bDone = true;
1571  }
1572  bHandleKey = true;
1573  }
1574  break;
1575 
1576  case KEY_A:
1577  {
1578  if( bCtrl && mbMulti )
1579  {
1580  // paint only once
1581  bool bUpdates = IsUpdateMode();
1582  SetUpdateMode( false );
1583 
1584  sal_Int32 nEntryCount = mpEntryList->GetEntryCount();
1585  for( sal_Int32 i = 0; i < nEntryCount; i++ )
1586  SelectEntry( i, true );
1587 
1588  // restore update mode
1589  SetUpdateMode( bUpdates );
1590  Invalidate();
1591 
1593 
1594  bDone = true;
1595  }
1596  else
1597  {
1598  bHandleKey = true;
1599  }
1600  }
1601  break;
1602 
1603  default:
1604  bHandleKey = true;
1605  break;
1606  }
1607  if (bHandleKey && !IsReadOnly())
1608  {
1609  bDone = maQuickSelectionEngine.HandleKeyEvent( rKEvt );
1610  }
1611 
1612  if ( ( nSelect != LISTBOX_ENTRY_NOTFOUND )
1613  && ( ( !mpEntryList->IsEntryPosSelected( nSelect ) )
1614  || ( eLET == LET_KEYSPACE )
1615  )
1616  )
1617  {
1618  SAL_WARN_IF( mpEntryList->IsEntryPosSelected( nSelect ) && !mbMulti, "vcl", "ImplListBox: Selecting same Entry" );
1619  sal_Int32 nCount = mpEntryList->GetEntryCount();
1620  if (nSelect >= nCount)
1621  nSelect = nCount ? nCount-1 : LISTBOX_ENTRY_NOTFOUND;
1622  bool bCurPosChange = (mnCurrentPos != nSelect);
1623  mnCurrentPos = nSelect;
1624  if(SelectEntries( nSelect, eLET, bShift, bCtrl, bCurPosChange))
1625  {
1626  // tdf#129043 Correctly deliver events when changing values with arrow keys in combobox
1627  if (mbIsDropdown && IsReallyVisible())
1628  mbTravelSelect = true;
1630  ImplCallSelect();
1631  mbTravelSelect = false;
1632  }
1633  }
1634 
1635  return bDone;
1636 }
1637 
1638 namespace
1639 {
1640  vcl::StringEntryIdentifier lcl_getEntry( const ImplEntryList& _rList, sal_Int32 _nPos, OUString& _out_entryText )
1641  {
1642  OSL_PRECOND( ( _nPos != LISTBOX_ENTRY_NOTFOUND ), "lcl_getEntry: invalid position!" );
1643  sal_Int32 nEntryCount( _rList.GetEntryCount() );
1644  if ( _nPos >= nEntryCount )
1645  _nPos = 0;
1646  _out_entryText = _rList.GetEntryText( _nPos );
1647 
1648  // vcl::StringEntryIdentifier does not allow for 0 values, but our position is 0-based
1649  // => normalize
1650  return reinterpret_cast< vcl::StringEntryIdentifier >( _nPos + 1 );
1651  }
1652 
1653  sal_Int32 lcl_getEntryPos( vcl::StringEntryIdentifier _entry )
1654  {
1655  // our pos is 0-based, but StringEntryIdentifier does not allow for a NULL
1656  return static_cast< sal_Int32 >( reinterpret_cast< sal_Int64 >( _entry ) ) - 1;
1657  }
1658 }
1659 
1661 {
1662  return lcl_getEntry( *GetEntryList(), ( mnCurrentPos == LISTBOX_ENTRY_NOTFOUND ) ? 0 : mnCurrentPos, _out_entryText );
1663 }
1664 
1666 {
1667  sal_Int32 nNextPos = lcl_getEntryPos( _currentEntry ) + 1;
1668  return lcl_getEntry( *GetEntryList(), nNextPos, _out_entryText );
1669 }
1670 
1672 {
1673  sal_Int32 nSelect = lcl_getEntryPos( _entry );
1674  if ( mpEntryList->IsEntryPosSelected( nSelect ) )
1675  {
1676  // ignore that. This method is a callback from the QuickSelectionEngine, which means the user attempted
1677  // to select the given entry by typing its starting letters. No need to act.
1678  return;
1679  }
1680 
1681  // normalize
1682  OSL_ENSURE( nSelect < mpEntryList->GetEntryCount(), "ImplListBoxWindow::SelectEntry: how that?" );
1683  sal_Int32 nCount = mpEntryList->GetEntryCount();
1684  if (nSelect >= nCount)
1685  nSelect = nCount ? nCount-1 : LISTBOX_ENTRY_NOTFOUND;
1686 
1687  // make visible
1688  ShowProminentEntry( nSelect );
1689 
1690  // actually select
1691  mnCurrentPos = nSelect;
1692  if ( SelectEntries( nSelect, LET_KEYMOVE ) )
1693  {
1694  mbTravelSelect = true;
1695  mnSelectModifier = 0;
1696  ImplCallSelect();
1697  mbTravelSelect = false;
1698  }
1699 }
1700 
1701 void ImplListBoxWindow::ImplPaint(vcl::RenderContext& rRenderContext, sal_Int32 nPos)
1702 {
1703  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
1704 
1705  const ImplEntryType* pEntry = mpEntryList->GetEntryPtr( nPos );
1706  if (!pEntry)
1707  return;
1708 
1709  long nWidth = GetOutputSizePixel().Width();
1710  long nY = mpEntryList->GetAddedHeight(nPos, mnTop);
1711  tools::Rectangle aRect(Point(0, nY), Size(nWidth, pEntry->getHeightWithMargin()));
1712 
1713  bool bSelected = mpEntryList->IsEntryPosSelected(nPos);
1714  if (bSelected)
1715  {
1716  rRenderContext.SetTextColor(!IsEnabled() ? rStyleSettings.GetDisableColor() : rStyleSettings.GetHighlightTextColor());
1717  rRenderContext.SetFillColor(rStyleSettings.GetHighlightColor());
1718  rRenderContext.SetLineColor();
1719  rRenderContext.DrawRect(aRect);
1720  }
1721  else
1722  {
1723  ApplySettings(rRenderContext);
1724  if (!IsEnabled())
1725  rRenderContext.SetTextColor(rStyleSettings.GetDisableColor());
1726  }
1727  rRenderContext.SetTextFillColor();
1728 
1729  if (IsUserDrawEnabled())
1730  {
1731  mbInUserDraw = true;
1732  mnUserDrawEntry = nPos;
1733  aRect.AdjustLeft( -mnLeft );
1734  if (nPos < GetEntryList()->GetMRUCount())
1735  nPos = GetEntryList()->FindEntry(GetEntryList()->GetEntryText(nPos));
1736  nPos = nPos - GetEntryList()->GetMRUCount();
1737 
1738  UserDrawEvent aUDEvt(this, &rRenderContext, aRect, nPos, bSelected);
1739  maUserDrawHdl.Call( &aUDEvt );
1740  mbInUserDraw = false;
1741  }
1742  else
1743  {
1744  DrawEntry(rRenderContext, nPos, true, true, /*bDrawTextAtImagePos*/false);
1745  }
1746 }
1747 
1748 void ImplListBoxWindow::DrawEntry(vcl::RenderContext& rRenderContext, sal_Int32 nPos, bool bDrawImage, bool bDrawText, bool bDrawTextAtImagePos)
1749 {
1750  const ImplEntryType* pEntry = mpEntryList->GetEntryPtr(nPos);
1751  if (!pEntry)
1752  return;
1753 
1754  long nEntryHeight = pEntry->getHeightWithMargin();
1755 
1756  // when changing this function don't forget to adjust ImplWin::DrawEntry()
1757 
1758  if (mbInUserDraw)
1759  nPos = mnUserDrawEntry; // real entry, not the matching entry from MRU
1760 
1761  long nY = mpEntryList->GetAddedHeight(nPos, mnTop);
1762  Size aImgSz;
1763 
1764  if (bDrawImage && mpEntryList->HasImages())
1765  {
1766  Image aImage = mpEntryList->GetEntryImage(nPos);
1767  if (!!aImage)
1768  {
1769  aImgSz = aImage.GetSizePixel();
1770  Point aPtImg(gnBorder - mnLeft, nY + ((nEntryHeight - aImgSz.Height()) / 2));
1771 
1772  // pb: #106948# explicit mirroring for calc
1773  if (mbMirroring)
1774  // right aligned
1775  aPtImg.setX( mnMaxWidth + gnBorder - aImgSz.Width() - mnLeft );
1776 
1777  if (!IsZoom())
1778  {
1779  rRenderContext.DrawImage(aPtImg, aImage);
1780  }
1781  else
1782  {
1783  aImgSz.setWidth( CalcZoom(aImgSz.Width()) );
1784  aImgSz.setHeight( CalcZoom(aImgSz.Height()) );
1785  rRenderContext.DrawImage(aPtImg, aImgSz, aImage);
1786  }
1787 
1788  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1789  const sal_uInt16 nEdgeBlendingPercent(GetEdgeBlending() ? rStyleSettings.GetEdgeBlending() : 0);
1790 
1791  if (nEdgeBlendingPercent && aImgSz.Width() && aImgSz.Height())
1792  {
1793  const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
1794  const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
1795  const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
1796  const BitmapEx aBlendFrame(createBlendFrame(aImgSz, nAlpha, rTopLeft, rBottomRight));
1797 
1798  if (!aBlendFrame.IsEmpty())
1799  {
1800  rRenderContext.DrawBitmapEx(aPtImg, aBlendFrame);
1801  }
1802  }
1803  }
1804  }
1805 
1806  if (bDrawText)
1807  {
1808  OUString aStr(mpEntryList->GetEntryText(nPos));
1809  if (!aStr.isEmpty())
1810  {
1811  long nMaxWidth = std::max(mnMaxWidth, GetOutputSizePixel().Width() - 2 * gnBorder);
1812  // a multiline entry should only be as wide as the window
1813  if (pEntry->mnFlags & ListBoxEntryFlags::MultiLine)
1814  nMaxWidth = GetOutputSizePixel().Width() - 2 * gnBorder;
1815 
1816  tools::Rectangle aTextRect(Point(gnBorder - mnLeft, nY),
1817  Size(nMaxWidth, nEntryHeight));
1818 
1819  if (!bDrawTextAtImagePos && (mpEntryList->HasEntryImage(nPos) || IsUserDrawEnabled()))
1820  {
1821  long nImageWidth = std::max(mnMaxImgWidth, maUserItemSize.Width());
1822  aTextRect.AdjustLeft(nImageWidth + IMG_TXT_DISTANCE );
1823  }
1824 
1825  // pb: #106948# explicit mirroring for calc
1826  if (mbMirroring)
1827  {
1828  // right aligned
1829  aTextRect.SetLeft( nMaxWidth + gnBorder - rRenderContext.GetTextWidth(aStr) - mnLeft );
1830  if (aImgSz.Width() > 0)
1831  aTextRect.AdjustLeft( -(aImgSz.Width() + IMG_TXT_DISTANCE) );
1832  }
1833 
1834  DrawTextFlags nDrawStyle = ImplGetTextStyle();
1835  if (pEntry->mnFlags & ListBoxEntryFlags::MultiLine)
1836  nDrawStyle |= MULTILINE_ENTRY_DRAW_FLAGS;
1838  nDrawStyle |= DrawTextFlags::Disable;
1839 
1840  rRenderContext.DrawText(aTextRect, aStr, nDrawStyle);
1841  }
1842  }
1843 
1844  if ( !maSeparators.empty() && ( isSeparator(nPos) || isSeparator(nPos-1) ) )
1845  {
1846  Color aOldLineColor(rRenderContext.GetLineColor());
1847  rRenderContext.SetLineColor((GetBackground() != COL_LIGHTGRAY) ? COL_LIGHTGRAY : COL_GRAY);
1848  Point aStartPos(0, nY);
1849  if (isSeparator(nPos))
1850  aStartPos.AdjustY(pEntry->getHeightWithMargin() - 1 );
1851  Point aEndPos(aStartPos);
1852  aEndPos.setX( GetOutputSizePixel().Width() );
1853  rRenderContext.DrawLine(aStartPos, aEndPos);
1854  rRenderContext.SetLineColor(aOldLineColor);
1855  }
1856 }
1857 
1859 {
1860  mpControlData->mpLayoutData.reset( new vcl::ControlLayoutData );
1861  const_cast<ImplListBoxWindow*>(this)->Invalidate(tools::Rectangle(Point(0, 0), GetOutputSize()));
1862 }
1863 
1865 {
1866  sal_Int32 nCount = mpEntryList->GetEntryCount();
1867 
1868  bool bShowFocusRect = mbHasFocusRect;
1869  if (mbHasFocusRect)
1871 
1872  long nY = 0; // + gnBorder;
1873  long nHeight = GetOutputSizePixel().Height();// - mnMaxHeight + gnBorder;
1874 
1875  for (sal_Int32 i = mnTop; i < nCount && nY < nHeight + mnMaxHeight; i++)
1876  {
1877  const ImplEntryType* pEntry = mpEntryList->GetEntryPtr(i);
1878  long nEntryHeight = pEntry->getHeightWithMargin();
1879  if (nY + nEntryHeight >= rRect.Top() &&
1880  nY <= rRect.Bottom() + mnMaxHeight)
1881  {
1882  ImplPaint(rRenderContext, i);
1883  }
1884  nY += nEntryHeight;
1885  }
1886 
1887  long nHeightDiff = mpEntryList->GetAddedHeight(mnCurrentPos, mnTop);
1888  maFocusRect.SetPos(Point(0, nHeightDiff));
1889  Size aSz(maFocusRect.GetWidth(), mpEntryList->GetEntryHeight(mnCurrentPos));
1890  maFocusRect.SetSize(aSz);
1891  if (HasFocus() && bShowFocusRect)
1893 }
1894 
1896 {
1898  {
1899  // This widget is explicitly double-buffered, so avoid partial paints.
1900  tools::Rectangle aRect(Point(0, 0), GetOutputSizePixel());
1901  ImplDoPaint(rRenderContext, aRect);
1902  }
1903  else
1904  ImplDoPaint(rRenderContext, rRect);
1905 }
1906 
1908 {
1909  // FIXME: ListBoxEntryFlags::MultiLine
1910 
1911  const sal_Int32 nCount = mpEntryList->GetEntryCount()-mnTop;
1912  long nHeight = GetOutputSizePixel().Height();// - mnMaxHeight + gnBorder;
1913  sal_uInt16 nEntries = static_cast< sal_uInt16 >( ( nHeight + mnMaxHeight - 1 ) / mnMaxHeight );
1914  if( nEntries > nCount )
1915  nEntries = static_cast<sal_uInt16>(nCount);
1916 
1917  return nEntries;
1918 }
1919 
1921 {
1922  Control::Resize();
1923 
1924  bool bShowFocusRect = mbHasFocusRect;
1925  if ( bShowFocusRect )
1927 
1929  {
1930  Size aSz( GetOutputSizePixel().Width(), mpEntryList->GetEntryHeight( mnCurrentPos ) );
1931  maFocusRect.SetSize( aSz );
1932  }
1933 
1934  if ( bShowFocusRect )
1936 
1938 }
1939 
1941 {
1942  sal_Int32 nPos = mnCurrentPos;
1943  if ( nPos == LISTBOX_ENTRY_NOTFOUND )
1944  nPos = 0;
1945  long nHeightDiff = mpEntryList->GetAddedHeight( nPos, mnTop );
1946  maFocusRect.SetPos( Point( 0, nHeightDiff ) );
1947  Size aSz( maFocusRect.GetWidth(), mpEntryList->GetEntryHeight( nPos ) );
1948  maFocusRect.SetSize( aSz );
1951 }
1952 
1954 {
1957 }
1958 
1959 void ImplListBoxWindow::SetTopEntry( sal_Int32 nTop )
1960 {
1961  if( mpEntryList->GetEntryCount() == 0 )
1962  return;
1963 
1964  long nWHeight = PixelToLogic( GetSizePixel() ).Height();
1965 
1966  sal_Int32 nLastEntry = mpEntryList->GetEntryCount()-1;
1967  if( nTop > nLastEntry )
1968  nTop = nLastEntry;
1969  const ImplEntryType* pLast = mpEntryList->GetEntryPtr( nLastEntry );
1970  while( nTop > 0 && mpEntryList->GetAddedHeight( nLastEntry, nTop-1 ) + pLast->getHeightWithMargin() <= nWHeight )
1971  nTop--;
1972 
1973  if ( nTop != mnTop )
1974  {
1976  long nDiff = mpEntryList->GetAddedHeight( mnTop, nTop );
1977  PaintImmediately();
1979  mnTop = nTop;
1980  Scroll( 0, nDiff );
1981  PaintImmediately();
1982  if( HasFocus() )
1984  maScrollHdl.Call( this );
1985  }
1986 }
1987 
1988 void ImplListBoxWindow::ShowProminentEntry( sal_Int32 nEntryPos )
1989 {
1990  SetTopEntry( nEntryPos );
1991 }
1992 
1994 {
1995  ScrollHorz( n - mnLeft );
1996 }
1997 
1999 {
2000  long nDiff = 0;
2001  if ( n > 0 )
2002  {
2003  long nWidth = GetOutputSizePixel().Width();
2004  if( ( mnMaxWidth - mnLeft + n ) > nWidth )
2005  nDiff = n;
2006  }
2007  else if ( n < 0 )
2008  {
2009  if( mnLeft )
2010  {
2011  long nAbs = -n;
2012  nDiff = - std::min( mnLeft, nAbs );
2013  }
2014  }
2015 
2016  if ( nDiff )
2017  {
2019  mnLeft = sal::static_int_cast<sal_uInt16>(mnLeft + nDiff);
2020  PaintImmediately();
2022  Scroll( -nDiff, 0 );
2023  PaintImmediately();
2024  if( HasFocus() )
2026  maScrollHdl.Call( this );
2027  }
2028 }
2029 
2031 {
2032  maSeparators.clear();
2033 
2034  if ( n != LISTBOX_ENTRY_NOTFOUND )
2035  {
2036  maSeparators.insert( n );
2037  }
2038 }
2039 
2041 {
2042  if (!maSeparators.empty())
2043  return *(maSeparators.begin());
2044  else
2045  return LISTBOX_ENTRY_NOTFOUND;
2046 }
2047 
2048 bool ImplListBoxWindow::isSeparator( const sal_Int32 &n) const
2049 {
2050  return maSeparators.find(n) != maSeparators.end();
2051 }
2052 
2053 Size ImplListBoxWindow::CalcSize(sal_Int32 nMaxLines) const
2054 {
2055  // FIXME: ListBoxEntryFlags::MultiLine
2056 
2057  Size aSz;
2058  aSz.setHeight(nMaxLines * GetEntryHeightWithMargin());
2059  aSz.setWidth( mnMaxWidth + 2*gnBorder );
2060  return aSz;
2061 }
2062 
2064 {
2065  const ImplEntryType* pEntry = mpEntryList->GetEntryPtr( nItem );
2066  Size aSz( GetSizePixel().Width(), pEntry ? pEntry->getHeightWithMargin() : GetEntryHeightWithMargin() );
2067  long nY = mpEntryList->GetAddedHeight( nItem, GetTopEntry() ) + GetEntryList()->GetMRUCount()*GetEntryHeightWithMargin();
2068  tools::Rectangle aRect( Point( 0, nY ), aSz );
2069  return aRect;
2070 }
2071 
2073 {
2074  Control::StateChanged( nType );
2075 
2076  if ( nType == StateChangedType::Zoom )
2077  {
2078  ApplySettings(*this);
2079  ImplCalcMetrics();
2080  Invalidate();
2081  }
2082  else if ( nType == StateChangedType::UpdateMode )
2083  {
2084  if ( IsUpdateMode() && IsReallyVisible() )
2085  Invalidate();
2086  }
2087  else if ( nType == StateChangedType::ControlFont )
2088  {
2089  ApplySettings(*this);
2090  ImplCalcMetrics();
2091  Invalidate();
2092  }
2093  else if ( nType == StateChangedType::ControlForeground )
2094  {
2095  ApplySettings(*this);
2096  Invalidate();
2097  }
2098  else if ( nType == StateChangedType::ControlBackground )
2099  {
2100  ApplySettings(*this);
2101  Invalidate();
2102  }
2103  else if( nType == StateChangedType::Enable )
2104  {
2105  Invalidate();
2106  }
2107 
2109 }
2110 
2112 {
2113  Control::DataChanged( rDCEvt );
2114 
2115  if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
2117  ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
2118  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
2119  {
2121  ApplySettings(*this);
2122  ImplCalcMetrics();
2123  Invalidate();
2124  }
2125 }
2126 
2128 {
2130 
2131  if (mpEntryList->HasImages())
2132  nTextStyle |= DrawTextFlags::Left;
2133  else if (mbCenter)
2134  nTextStyle |= DrawTextFlags::Center;
2135  else if (mbRight)
2136  nTextStyle |= DrawTextFlags::Right;
2137  else
2138  nTextStyle |= DrawTextFlags::Left;
2139 
2140  return nTextStyle;
2141 }
2142 
2144  Control( pParent, nWinStyle ),
2145  maLBWindow(VclPtr<ImplListBoxWindow>::Create( this, nWinStyle&(~WB_BORDER) ))
2146 {
2147  // for native widget rendering we must be able to detect this window type
2148  SetType( WindowType::LISTBOXWINDOW );
2149 
2153 
2154  Link<ScrollBar*,void> aLink( LINK( this, ImplListBox, ScrollBarHdl ) );
2155  mpVScrollBar->SetScrollHdl( aLink );
2156  mpHScrollBar->SetScrollHdl( aLink );
2157 
2158  mbVScroll = false;
2159  mbHScroll = false;
2160  mbAutoHScroll = ( nWinStyle & WB_AUTOHSCROLL );
2161  mbEdgeBlending = false;
2162 
2163  maLBWindow->SetScrollHdl( LINK( this, ImplListBox, LBWindowScrolled ) );
2164  maLBWindow->SetMRUChangedHdl( LINK( this, ImplListBox, MRUChanged ) );
2166  maLBWindow->Show();
2167 }
2168 
2170 {
2171  disposeOnce();
2172 }
2173 
2175 {
2180  Control::dispose();
2181 }
2182 
2184 {
2185  maLBWindow->Clear();
2186  if ( GetEntryList()->GetMRUCount() )
2187  {
2190  }
2191  mpVScrollBar->SetThumbPos( 0 );
2192  mpHScrollBar->SetThumbPos( 0 );
2194 }
2195 
2196 sal_Int32 ImplListBox::InsertEntry( sal_Int32 nPos, const OUString& rStr )
2197 {
2198  ImplEntryType* pNewEntry = new ImplEntryType( rStr );
2199  sal_Int32 nNewPos = maLBWindow->InsertEntry( nPos, pNewEntry );
2201  return nNewPos;
2202 }
2203 
2204 sal_Int32 ImplListBox::InsertEntry( sal_Int32 nPos, const OUString& rStr, const Image& rImage )
2205 {
2206  ImplEntryType* pNewEntry = new ImplEntryType( rStr, rImage );
2207  sal_Int32 nNewPos = maLBWindow->InsertEntry( nPos, pNewEntry );
2209  return nNewPos;
2210 }
2211 
2212 void ImplListBox::RemoveEntry( sal_Int32 nPos )
2213 {
2214  maLBWindow->RemoveEntry( nPos );
2216 }
2217 
2218 void ImplListBox::SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags )
2219 {
2220  maLBWindow->SetEntryFlags( nPos, nFlags );
2221 }
2222 
2223 void ImplListBox::SelectEntry( sal_Int32 nPos, bool bSelect )
2224 {
2225  maLBWindow->SelectEntry( nPos, bSelect );
2226 }
2227 
2229 {
2231 }
2232 
2234 {
2235  if (maLBWindow)
2236  maLBWindow->GrabFocus();
2237  else
2239 }
2240 
2242 {
2243  Control::Resize();
2246 }
2247 
2249 {
2250  CompatStateChanged( StateChangedType::Data );
2251 }
2252 
2254 {
2255  long nSet = GetTopEntry();
2256  if( nSet > mpVScrollBar->GetRangeMax() )
2257  mpVScrollBar->SetRangeMax( GetEntryList()->GetEntryCount() );
2258  mpVScrollBar->SetThumbPos( GetTopEntry() );
2259 
2260  mpHScrollBar->SetThumbPos( GetLeftIndent() );
2261 
2262  maScrollHdl.Call( this );
2263 }
2264 
2265 IMPL_LINK( ImplListBox, ScrollBarHdl, ScrollBar*, pSB, void )
2266 {
2267  sal_uInt16 nPos = static_cast<sal_uInt16>(pSB->GetThumbPos());
2268  if( pSB == mpVScrollBar )
2269  SetTopEntry( nPos );
2270  else if( pSB == mpHScrollBar )
2271  SetLeftIndent( nPos );
2272  if( GetParent() )
2273  GetParent()->Invalidate( InvalidateFlags::Update );
2274 }
2275 
2277 {
2278  bool bArrange = false;
2279 
2280  Size aOutSz = GetOutputSizePixel();
2281  sal_Int32 nEntries = GetEntryList()->GetEntryCount();
2282  sal_uInt16 nMaxVisEntries = static_cast<sal_uInt16>(aOutSz.Height() / GetEntryHeightWithMargin());
2283 
2284  // vertical ScrollBar
2285  if( nEntries > nMaxVisEntries )
2286  {
2287  if( !mbVScroll )
2288  bArrange = true;
2289  mbVScroll = true;
2290 
2291  // check of the scrolled-out region
2292  if( GetEntryList()->GetSelectedEntryCount() == 1 &&
2295  else
2296  SetTopEntry( GetTopEntry() ); // MaxTop is being checked...
2297  }
2298  else
2299  {
2300  if( mbVScroll )
2301  bArrange = true;
2302  mbVScroll = false;
2303  SetTopEntry( 0 );
2304  }
2305 
2306  // horizontal ScrollBar
2307  if( mbAutoHScroll )
2308  {
2309  long nWidth = static_cast<sal_uInt16>(aOutSz.Width());
2310  if ( mbVScroll )
2311  nWidth -= mpVScrollBar->GetSizePixel().Width();
2312 
2313  long nMaxWidth = GetMaxEntryWidth();
2314  if( nWidth < nMaxWidth )
2315  {
2316  if( !mbHScroll )
2317  bArrange = true;
2318  mbHScroll = true;
2319 
2320  if ( !mbVScroll ) // maybe we do need one now
2321  {
2322  nMaxVisEntries = static_cast<sal_uInt16>( ( aOutSz.Height() - mpHScrollBar->GetSizePixel().Height() ) / GetEntryHeightWithMargin() );
2323  if( nEntries > nMaxVisEntries )
2324  {
2325  bArrange = true;
2326  mbVScroll = true;
2327 
2328  // check of the scrolled-out region
2329  if( GetEntryList()->GetSelectedEntryCount() == 1 &&
2332  else
2333  SetTopEntry( GetTopEntry() ); // MaxTop is being checked...
2334  }
2335  }
2336 
2337  // check of the scrolled-out region
2338  sal_uInt16 nMaxLI = static_cast<sal_uInt16>(nMaxWidth - nWidth);
2339  if ( nMaxLI < GetLeftIndent() )
2340  SetLeftIndent( nMaxLI );
2341  }
2342  else
2343  {
2344  if( mbHScroll )
2345  bArrange = true;
2346  mbHScroll = false;
2347  SetLeftIndent( 0 );
2348  }
2349  }
2350 
2351  if( bArrange )
2353 
2355 }
2356 
2358 {
2359  Size aOutSz = maLBWindow->GetOutputSizePixel();
2360 
2361  if ( mbVScroll )
2362  {
2363  sal_Int32 nEntries = GetEntryList()->GetEntryCount();
2364  sal_uInt16 nVisEntries = static_cast<sal_uInt16>(aOutSz.Height() / GetEntryHeightWithMargin());
2365  mpVScrollBar->SetRangeMax( nEntries );
2366  mpVScrollBar->SetVisibleSize( nVisEntries );
2367  mpVScrollBar->SetPageSize( nVisEntries - 1 );
2368  }
2369 
2370  if ( mbHScroll )
2371  {
2373  mpHScrollBar->SetVisibleSize( static_cast<sal_uInt16>(aOutSz.Width()) );
2375  mpHScrollBar->SetPageSize( aOutSz.Width() - HORZ_SCROLL );
2376  }
2377 }
2378 
2380 {
2381  // Here we only position the Controls; if the Scrollbars are to be
2382  // visible is already determined in ImplCheckScrollBars
2383 
2384  Size aOutSz = GetOutputSizePixel();
2385  long nSBWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
2386  nSBWidth = CalcZoom( nSBWidth );
2387 
2388  Size aInnerSz( aOutSz );
2389  if ( mbVScroll )
2390  aInnerSz.AdjustWidth( -nSBWidth );
2391  if ( mbHScroll )
2392  aInnerSz.AdjustHeight( -nSBWidth );
2393 
2394  // pb: #106948# explicit mirroring for calc
2395  // Scrollbar on left or right side?
2396  bool bMirroring = maLBWindow->IsMirroring();
2397  Point aWinPos( bMirroring && mbVScroll ? nSBWidth : 0, 0 );
2398  maLBWindow->SetPosSizePixel( aWinPos, aInnerSz );
2399 
2400  // ScrollBarBox
2401  if( mbVScroll && mbHScroll )
2402  {
2403  Point aBoxPos( bMirroring ? 0 : aInnerSz.Width(), aInnerSz.Height() );
2404  mpScrollBarBox->SetPosSizePixel( aBoxPos, Size( nSBWidth, nSBWidth ) );
2405  mpScrollBarBox->Show();
2406  }
2407  else
2408  {
2409  mpScrollBarBox->Hide();
2410  }
2411 
2412  // vertical ScrollBar
2413  if( mbVScroll )
2414  {
2415  // Scrollbar on left or right side?
2416  Point aVPos( bMirroring ? 0 : aOutSz.Width() - nSBWidth, 0 );
2417  mpVScrollBar->SetPosSizePixel( aVPos, Size( nSBWidth, aInnerSz.Height() ) );
2418  mpVScrollBar->Show();
2419  }
2420  else
2421  {
2422  mpVScrollBar->Hide();
2423  // #107254# Don't reset top entry after resize, but check for max top entry
2424  SetTopEntry( GetTopEntry() );
2425  }
2426 
2427  // horizontal ScrollBar
2428  if( mbHScroll )
2429  {
2430  Point aHPos( ( bMirroring && mbVScroll ) ? nSBWidth : 0, aOutSz.Height() - nSBWidth );
2431  mpHScrollBar->SetPosSizePixel( aHPos, Size( aInnerSz.Width(), nSBWidth ) );
2432  mpHScrollBar->Show();
2433  }
2434  else
2435  {
2436  mpHScrollBar->Hide();
2437  SetLeftIndent( 0 );
2438  }
2439 }
2440 
2442 {
2443  if ( nType == StateChangedType::InitShow )
2444  {
2446  }
2447  else if ( ( nType == StateChangedType::UpdateMode ) || ( nType == StateChangedType::Data ) )
2448  {
2449  bool bUpdate = IsUpdateMode();
2450  maLBWindow->SetUpdateMode( bUpdate );
2451  if ( bUpdate && IsReallyVisible() )
2453  }
2454  else if( nType == StateChangedType::Enable )
2455  {
2459  maLBWindow->Enable( IsEnabled() );
2460 
2461  Invalidate();
2462  }
2463  else if ( nType == StateChangedType::Zoom )
2464  {
2465  maLBWindow->SetZoom( GetZoom() );
2466  Resize();
2467  }
2468  else if ( nType == StateChangedType::ControlFont )
2469  {
2471  }
2472  else if ( nType == StateChangedType::ControlForeground )
2473  {
2475  }
2476  else if ( nType == StateChangedType::ControlBackground )
2477  {
2479  }
2480  else if( nType == StateChangedType::Mirroring )
2481  {
2486  }
2487 
2488  Control::StateChanged( nType );
2489 }
2490 
2492 {
2493  bool bDone = false;
2494  if ( rNEvt.GetType() == MouseNotifyEvent::COMMAND )
2495  {
2496  const CommandEvent& rCEvt = *rNEvt.GetCommandEvent();
2497  if ( rCEvt.GetCommand() == CommandEventId::Wheel )
2498  {
2499  const CommandWheelData* pData = rCEvt.GetWheelData();
2500  if( !pData->GetModifier() && ( pData->GetMode() == CommandWheelMode::SCROLL ) )
2501  {
2502  bDone = HandleScrollCommand( rCEvt, mpHScrollBar, mpVScrollBar );
2503  }
2504  }
2505  else if (rCEvt.GetCommand() == CommandEventId::Gesture)
2506  {
2508  }
2509  }
2510 
2511  return bDone || Window::EventNotify( rNEvt );
2512 }
2513 
2515 {
2516  return maLBWindow->GetDisplayBackground();
2517 }
2518 
2520 {
2521  bool bDone = false;
2522  if ( rCEvt.GetCommand() == CommandEventId::Wheel )
2523  {
2524  const CommandWheelData* pData = rCEvt.GetWheelData();
2525  if( !pData->GetModifier() && ( pData->GetMode() == CommandWheelMode::SCROLL ) )
2526  {
2527  sal_uInt16 nKey = ( pData->GetDelta() < 0 ) ? KEY_DOWN : KEY_UP;
2528  KeyEvent aKeyEvent( 0, vcl::KeyCode( nKey ) );
2529  bDone = ProcessKeyInput( aKeyEvent );
2530  }
2531  }
2532  return bDone;
2533 }
2534 
2535 void ImplListBox::SetMRUEntries( const OUString& rEntries, sal_Unicode cSep )
2536 {
2537  bool bChanges = GetEntryList()->GetMRUCount() != 0;
2538 
2539  // Remove old MRU entries
2540  for ( sal_Int32 n = GetEntryList()->GetMRUCount();n; )
2541  maLBWindow->RemoveEntry( --n );
2542 
2543  sal_Int32 nMRUCount = 0;
2544  sal_Int32 nIndex = 0;
2545  do
2546  {
2547  OUString aEntry = rEntries.getToken( 0, cSep, nIndex );
2548  // Accept only existing entries
2549  if ( GetEntryList()->FindEntry( aEntry ) != LISTBOX_ENTRY_NOTFOUND )
2550  {
2551  ImplEntryType* pNewEntry = new ImplEntryType( aEntry );
2552  maLBWindow->InsertEntry(nMRUCount++, pNewEntry, false);
2553  bChanges = true;
2554  }
2555  }
2556  while ( nIndex >= 0 );
2557 
2558  if ( bChanges )
2559  {
2560  maLBWindow->GetEntryList()->SetMRUCount( nMRUCount );
2561  SetSeparatorPos( nMRUCount ? nMRUCount-1 : 0 );
2563  }
2564 }
2565 
2567 {
2568  OUStringBuffer aEntries;
2569  for ( sal_Int32 n = 0; n < GetEntryList()->GetMRUCount(); n++ )
2570  {
2571  aEntries.append(GetEntryList()->GetEntryText( n ));
2572  if( n < ( GetEntryList()->GetMRUCount() - 1 ) )
2573  aEntries.append(cSep);
2574  }
2575  return aEntries.makeStringAndClear();
2576 }
2577 
2579 {
2580  if(mbEdgeBlending != bNew)
2581  {
2582  mbEdgeBlending = bNew;
2584  }
2585 }
2586 
2587 ImplWin::ImplWin( vcl::Window* pParent, WinBits nWinStyle ) :
2588  Control ( pParent, nWinStyle )
2589 {
2592  SetBackground();
2593  else
2594  SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
2595 
2597 
2598  mbEdgeBlending = false;
2600 }
2601 
2603 {
2604  if( IsEnabled() )
2605  {
2606  maMBDownHdl.Call(this);
2607  }
2608 }
2609 
2611 {
2612  mpControlData->mpLayoutData.reset( new vcl::ControlLayoutData );
2613  ImplWin* pThis = const_cast<ImplWin*>(this);
2614  pThis->ImplDraw(*pThis, true);
2615 }
2616 
2618 {
2619  if( rNEvt.GetType() == MouseNotifyEvent::MOUSEMOVE )
2620  {
2621  const MouseEvent* pMouseEvt = rNEvt.GetMouseEvent();
2622  if( pMouseEvt && (pMouseEvt->IsEnterWindow() || pMouseEvt->IsLeaveWindow()) )
2623  {
2624  // trigger redraw as mouse over state has changed
2627  {
2629  }
2630  }
2631  }
2632 
2633  return Control::PreNotify(rNEvt);
2634 }
2635 
2636 void ImplWin::ImplDraw(vcl::RenderContext& rRenderContext, bool bLayout)
2637 {
2638  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
2639 
2640  if (!bLayout)
2641  {
2642  bool bNativeOK = false;
2643  bool bHasFocus = HasFocus();
2644  bool bIsEnabled = IsEnabled();
2645 
2649  {
2650  // Repaint the (focused) area similarly to
2651  // ImplSmallBorderWindowView::DrawWindow() in
2652  // vcl/source/window/brdwin.cxx
2653  vcl::Window *pWin = GetParent();
2654 
2655  ImplControlValue aControlValue;
2656  bIsEnabled &= pWin->IsEnabled();
2657  if ( !bIsEnabled )
2658  nState &= ~ControlState::ENABLED;
2659  bHasFocus |= pWin->HasFocus();
2660  if ( bHasFocus )
2661  nState |= ControlState::FOCUSED;
2662 
2663  // The listbox is painted over the entire control including the
2664  // border, but ImplWin does not contain the border => correction
2665  // needed.
2666  sal_Int32 nLeft, nTop, nRight, nBottom;
2667  pWin->GetBorder( nLeft, nTop, nRight, nBottom );
2668  Point aPoint( -nLeft, -nTop );
2669  tools::Rectangle aCtrlRegion( aPoint - GetPosPixel(), pWin->GetSizePixel() );
2670 
2671  bool bMouseOver = false;
2672  vcl::Window *pChild = pWin->GetWindow( GetWindowType::FirstChild );
2673  while( pChild )
2674  {
2675  bMouseOver = pChild->IsMouseOver();
2676  if (bMouseOver)
2677  break;
2678  pChild = pChild->GetWindow( GetWindowType::Next );
2679  }
2680  if( bMouseOver )
2681  nState |= ControlState::ROLLOVER;
2682 
2683  // if parent has no border, then nobody has drawn the background
2684  // since no border window exists. so draw it here.
2685  WinBits nParentStyle = pWin->GetStyle();
2686  if( ! (nParentStyle & WB_BORDER) || (nParentStyle & WB_NOBORDER) )
2687  {
2688  tools::Rectangle aParentRect( Point( 0, 0 ), pWin->GetSizePixel() );
2690  nState, aControlValue, OUString() );
2691  }
2692 
2693  bNativeOK = rRenderContext.DrawNativeControl(ControlType::Listbox, ControlPart::Entire, aCtrlRegion,
2694  nState, aControlValue, OUString());
2695  }
2696 
2697  if (bIsEnabled)
2698  {
2699  if (bHasFocus && !ImplGetSVData()->maNWFData.mbDDListBoxNoTextArea)
2700  {
2701  if ( !ImplGetSVData()->maNWFData.mbNoFocusRects )
2702  {
2703  rRenderContext.SetFillColor( rStyleSettings.GetHighlightColor() );
2704  rRenderContext.SetTextColor( rStyleSettings.GetHighlightTextColor() );
2705  }
2706  else
2707  {
2708  rRenderContext.SetLineColor();
2709  rRenderContext.SetFillColor();
2710  rRenderContext.SetTextColor( rStyleSettings.GetFieldTextColor() );
2711  }
2712  rRenderContext.DrawRect( maFocusRect );
2713  }
2714  else
2715  {
2716  Color aColor;
2717  if (IsControlForeground())
2718  aColor = GetControlForeground();
2719  else if (ImplGetSVData()->maNWFData.mbDDListBoxNoTextArea)
2720  {
2721  if( bNativeOK && (nState & ControlState::ROLLOVER) )
2722  aColor = rStyleSettings.GetButtonRolloverTextColor();
2723  else
2724  aColor = rStyleSettings.GetButtonTextColor();
2725  }
2726  else
2727  {
2728  if( bNativeOK && (nState & ControlState::ROLLOVER) )
2729  aColor = rStyleSettings.GetFieldRolloverTextColor();
2730  else
2731  aColor = rStyleSettings.GetFieldTextColor();
2732  }
2733  rRenderContext.SetTextColor(aColor);
2734  if (!bNativeOK)
2735  rRenderContext.Erase(maFocusRect);
2736  }
2737  }
2738  else // Disabled
2739  {
2740  rRenderContext.SetTextColor(rStyleSettings.GetDisableColor());
2741  if (!bNativeOK)
2742  rRenderContext.Erase(maFocusRect);
2743  }
2744  }
2745 
2746  DrawEntry(rRenderContext, bLayout);
2747 }
2748 
2750 {
2751  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
2752 
2753  ApplyControlFont(rRenderContext, rStyleSettings.GetFieldFont());
2754  ApplyControlForeground(rRenderContext, rStyleSettings.GetFieldTextColor());
2755 
2756  if (IsControlBackground())
2757  rRenderContext.SetBackground(GetControlBackground());
2758  else
2759  rRenderContext.SetBackground(rStyleSettings.GetFieldColor());
2760 }
2761 
2762 void ImplWin::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
2763 {
2764  ImplDraw(rRenderContext);
2765 }
2766 
2767 void ImplWin::DrawEntry(vcl::RenderContext& rRenderContext, bool bLayout)
2768 {
2769  long nBorder = 1;
2770  Size aOutSz(GetOutputSizePixel());
2771 
2772  bool bImage = !!maImage;
2773  if (bImage && !bLayout)
2774  {
2776  Size aImgSz = maImage.GetSizePixel();
2777  Point aPtImg( nBorder, ( ( aOutSz.Height() - aImgSz.Height() ) / 2 ) );
2778  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
2779 
2780  // check for HC mode
2781  Image *pImage = &maImage;
2782 
2783  if ( !IsZoom() )
2784  {
2785  rRenderContext.DrawImage( aPtImg, *pImage, nStyle );
2786  }
2787  else
2788  {
2789  aImgSz.setWidth( CalcZoom( aImgSz.Width() ) );
2790  aImgSz.setHeight( CalcZoom( aImgSz.Height() ) );
2791  rRenderContext.DrawImage( aPtImg, aImgSz, *pImage, nStyle );
2792  }
2793 
2794  const sal_uInt16 nEdgeBlendingPercent(GetEdgeBlending() ? rStyleSettings.GetEdgeBlending() : 0);
2795 
2796  if(nEdgeBlendingPercent)
2797  {
2798  const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
2799  const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
2800  const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
2801  const BitmapEx aBlendFrame(createBlendFrame(aImgSz, nAlpha, rTopLeft, rBottomRight));
2802 
2803  if(!aBlendFrame.IsEmpty())
2804  {
2805  rRenderContext.DrawBitmapEx(aPtImg, aBlendFrame);
2806  }
2807  }
2808  }
2809 
2810  if( !maString.isEmpty() )
2811  {
2813 
2814  if ( bImage && !bLayout )
2815  nTextStyle |= DrawTextFlags::Left;
2816  else if ( GetStyle() & WB_CENTER )
2817  nTextStyle |= DrawTextFlags::Center;
2818  else if ( GetStyle() & WB_RIGHT )
2819  nTextStyle |= DrawTextFlags::Right;
2820  else
2821  nTextStyle |= DrawTextFlags::Left;
2822 
2823  tools::Rectangle aTextRect( Point( nBorder, 0 ), Size( aOutSz.Width()-2*nBorder, aOutSz.Height() ) );
2824 
2825  if ( bImage )
2826  {
2828  }
2829 
2830  MetricVector* pVector = bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : nullptr;
2831  OUString* pDisplayText = bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : nullptr;
2832  rRenderContext.DrawText( aTextRect, maString, nTextStyle, pVector, pDisplayText );
2833  }
2834 
2835  if( HasFocus() && !bLayout )
2837 }
2838 
2840 {
2841  Control::Resize();
2843  Invalidate();
2844 }
2845 
2847 {
2849  if( ImplGetSVData()->maNWFData.mbNoFocusRects &&
2852  {
2854  if( ! pWin )
2855  pWin = GetParent();
2856  pWin->Invalidate();
2857  }
2858  else
2859  Invalidate();
2861 }
2862 
2864 {
2865  HideFocus();
2866  if( ImplGetSVData()->maNWFData.mbNoFocusRects &&
2869  {
2871  if( ! pWin )
2872  pWin = GetParent();
2873  pWin->Invalidate();
2874  }
2875  else
2876  Invalidate();
2878 }
2879 
2881 {
2883  {
2884  ImplControlValue aControlValue;
2885 
2886  vcl::Window *pWin = GetParent();
2887  tools::Rectangle aParentRect(Point(0, 0), pWin->GetSizePixel());
2889  ControlState::FOCUSED, aControlValue, OUString());
2890  }
2891  Control::ShowFocus(rRect);
2892 }
2893 
2894 ImplBtn::ImplBtn( vcl::Window* pParent, WinBits nWinStyle ) :
2895  PushButton( pParent, nWinStyle )
2896 {
2897 }
2898 
2900 {
2901  if( IsEnabled() )
2902  maMBDownHdl.Call(this);
2903 }
2904 
2906  FloatingWindow( pParent, WB_BORDER | WB_SYSTEMWINDOW | WB_NOSHADOW ) // no drop shadow for list boxes
2907 {
2908  mpImplLB = nullptr;
2909  mnDDLineCount = 0;
2910  mbAutoWidth = false;
2911 
2913 
2914  vcl::Window * pBorderWindow = ImplGetBorderWindow();
2915  if( pBorderWindow )
2916  {
2917  SetAccessibleRole(accessibility::AccessibleRole::PANEL);
2918  pBorderWindow->SetAccessibleRole(accessibility::AccessibleRole::WINDOW);
2919  }
2920  else
2921  {
2922  SetAccessibleRole(accessibility::AccessibleRole::WINDOW);
2923  }
2924 
2925 }
2926 
2928 {
2929  disposeOnce();
2930 }
2931 
2933 {
2934  mpImplLB.clear();
2936 }
2937 
2938 
2940 {
2941  if( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS )
2942  {
2943  if( !GetParent()->HasChildPathFocus( true ) )
2944  EndPopupMode();
2945  }
2946 
2947  return FloatingWindow::PreNotify( rNEvt );
2948 }
2949 
2950 void ImplListBoxFloatingWindow::setPosSizePixel( long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags )
2951 {
2952  FloatingWindow::setPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
2953 
2954  // Fix #60890# ( MBA ): to be able to resize the Listbox even in its open state
2955  // after a call to Resize(), we adjust its position if necessary
2956  if ( IsReallyVisible() && ( nFlags & PosSizeFlags::Height ) )
2957  {
2958  Point aPos = GetParent()->GetPosPixel();
2959  aPos = GetParent()->GetParent()->OutputToScreenPixel( aPos );
2960 
2961  if ( nFlags & PosSizeFlags::X )
2962  aPos.setX( nX );
2963 
2964  if ( nFlags & PosSizeFlags::Y )
2965  aPos.setY( nY );
2966 
2967  sal_uInt16 nIndex;
2969  }
2970 
2971 // if( !IsReallyVisible() )
2972  {
2973  // The ImplListBox does not get a Resize() as not visible.
2974  // But the windows must get a Resize(), so that the number of
2975  // visible entries is correct for PgUp/PgDown.
2976  // The number also cannot be calculated by List/Combobox, as for
2977  // this the presence of the vertical Scrollbar has to be known.
2979  static_cast<vcl::Window*>(mpImplLB)->Resize();
2980  static_cast<vcl::Window*>(mpImplLB->GetMainWindow())->Resize();
2981  }
2982 }
2983 
2985 {
2988 }
2989 
2991 {
2992  Size aFloatSz( maPrefSz );
2993 
2994  sal_Int32 nLeft, nTop, nRight, nBottom;
2995  GetBorder( nLeft, nTop, nRight, nBottom );
2996 
2997  sal_Int32 nLines = mpImplLB->GetEntryList()->GetEntryCount();
2998  if ( mnDDLineCount && ( nLines > mnDDLineCount ) )
2999  nLines = mnDDLineCount;
3000 
3001  Size aSz = mpImplLB->CalcSize( nLines );
3002  long nMaxHeight = aSz.Height() + nTop + nBottom;
3003 
3004  if ( mnDDLineCount )
3005  aFloatSz.setHeight( nMaxHeight );
3006 
3007  if( mbAutoWidth )
3008  {
3009  // AutoSize first only for width...
3010 
3011  aFloatSz.setWidth( aSz.Width() + nLeft + nRight );
3012  aFloatSz.AdjustWidth(nRight ); // adding some space looks better...
3013 
3014  if ( ( aFloatSz.Height() < nMaxHeight ) || ( mnDDLineCount && ( mnDDLineCount < mpImplLB->GetEntryList()->GetEntryCount() ) ) )
3015  {
3016  // then we also need the vertical Scrollbar
3017  long nSBWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
3018  aFloatSz.AdjustWidth(nSBWidth );
3019  }
3020 
3021  long nDesktopWidth = GetDesktopRectPixel().getWidth();
3022  if (aFloatSz.Width() > nDesktopWidth)
3023  // Don't exceed the desktop width.
3024  aFloatSz.setWidth( nDesktopWidth );
3025  }
3026 
3027  if ( aFloatSz.Height() > nMaxHeight )
3028  aFloatSz.setHeight( nMaxHeight );
3029 
3030  // Minimal height, in case height is not set to Float height.
3031  // The parent of FloatWin must be DropDown-Combo/Listbox.
3032  Size aParentSz = GetParent()->GetSizePixel();
3033  if( (!mnDDLineCount || !nLines) && ( aFloatSz.Height() < aParentSz.Height() ) )
3034  aFloatSz.setHeight( aParentSz.Height() );
3035 
3036  // do not get narrower than the parent...
3037  if( aFloatSz.Width() < aParentSz.Width() )
3038  aFloatSz.setWidth( aParentSz.Width() );
3039 
3040  // align height to entries...
3041  long nInnerHeight = aFloatSz.Height() - nTop - nBottom;
3042  long nEntryHeight = mpImplLB->GetEntryHeightWithMargin();
3043  if ( nInnerHeight % nEntryHeight )
3044  {
3045  nInnerHeight /= nEntryHeight;
3046  nInnerHeight++;
3047  nInnerHeight *= nEntryHeight;
3048  aFloatSz.setHeight( nInnerHeight + nTop + nBottom );
3049  }
3050 
3051  if (aFloatSz.Width() < aSz.Width())
3052  {
3053  // The max width of list box entries exceeds the window width.
3054  // Account for the scroll bar height.
3055  long nSBWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
3056  aFloatSz.AdjustHeight(nSBWidth );
3057  }
3058 
3059  return aFloatSz;
3060 }
3061 
3062 void ImplListBoxFloatingWindow::StartFloat( bool bStartTracking )
3063 {
3064  if( IsInPopupMode() )
3065  return;
3066 
3067  Size aFloatSz = CalcFloatSize();
3068 
3069  SetSizePixel( aFloatSz );
3071 
3072  sal_Int32 nPos = mpImplLB->GetEntryList()->GetSelectedEntryPos( 0 );
3074 
3075  Size aSz = GetParent()->GetSizePixel();
3076  Point aPos = GetParent()->GetPosPixel();
3077  aPos = GetParent()->GetParent()->OutputToScreenPixel( aPos );
3078  // FIXME: this ugly hack is for Mac/Aqua
3079  // should be replaced by a real mechanism to place the float rectangle
3080  if( ImplGetSVData()->maNWFData.mbNoFocusRects &&
3082  {
3083  const sal_Int32 nLeft = 4, nTop = 4, nRight = 4, nBottom = 4;
3084  aPos.AdjustX(nLeft );
3085  aPos.AdjustY(nTop );
3086  aSz.AdjustWidth( -(nLeft + nRight) );
3087  aSz.AdjustHeight( -(nTop + nBottom) );
3088  }
3089  tools::Rectangle aRect( aPos, aSz );
3090 
3091  // check if the control's parent is un-mirrored which is the case for form controls in a mirrored UI
3092  // where the document is unmirrored
3093  // because StartPopupMode() expects a rectangle in mirrored coordinates we have to re-mirror
3094  vcl::Window *pGrandparent = GetParent()->GetParent();
3095  const OutputDevice *pGrandparentOutDev = pGrandparent->GetOutDev();
3096 
3097  if( pGrandparent->ImplIsAntiparallel() )
3098  pGrandparentOutDev->ReMirror( aRect );
3099 
3100  // mouse-button right: close the List-Box-Float-win and don't stop the handling fdo#84795
3102 
3103  if( nPos != LISTBOX_ENTRY_NOTFOUND )
3104  mpImplLB->ShowProminentEntry( nPos );
3105 
3106  if( bStartTracking )
3108 
3111 
3113 
3114 }
3115 
3116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Point GetPosPixel() const
Definition: window.cxx:2860
tools::Rectangle maFocusRect
Definition: listbox.hxx:551
long Width() const
void SelectEntry(sal_Int32 nPos, bool bSelect)
Size GetSizePixel() const
Definition: Image.cxx:86
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:782
void SetPos(const Point &rPoint)
bool IsControlBackground() const
Definition: window2.cxx:1087
bool GetEdgeBlending() const
Definition: listbox.hxx:499
virtual void EnableRTL(bool bEnable=true) override
Definition: ctrl.cxx:65
virtual void ShowFocus(const tools::Rectangle &rRect) override
bool IsInPopupMode() const
Definition: floatwin.hxx:148
virtual const Wallpaper & GetDisplayBackground() const
Definition: window.cxx:3125
bool mbAutoHScroll
Definition: listbox.hxx:392
WinBits const WB_NOSHADOW
virtual void LoseFocus() override
Link< sal_Int32, void > maFocusHdl
Definition: listbox.hxx:232
bool mbEdgeBlending
Definition: listbox.hxx:555
long GetWidth() const
void SetMRUEntries(const OUString &rEntries, sal_Unicode cSep)
const Wallpaper & GetBackground() const
Definition: outdev.hxx:637
sal_Int32 NaturalSortCompare(const OUString &rA, const OUString &rB)
void StartPopupMode(const tools::Rectangle &rRect, FloatWinPopupFlags nFlags)
Definition: floatwin.cxx:736
void HideFocus()
Definition: window2.cxx:91
sal_Int32 nIndex
SalLayoutGlyphs maStrGlyphs
Definition: listbox.hxx:53
bool mbTrack
Tracking.
Definition: listbox.hxx:207
virtual void Resize() override
#define HORZ_SCROLL
Definition: listbox.hxx:39
virtual void LoseFocus() override
bool HandleKeyEvent(const KeyEvent &_rKEvt)
WinBits const WB_SYSTEMWINDOW
bool HasEntryImage(sal_Int32 nPos) const
long GetHeight() const
virtual void StateChanged(StateChangedType nType) override
const ImplEntryList * GetEntryList() const
Definition: listbox.hxx:416
void SetNoSelection()
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::vector< tools::Rectangle > MetricVector
Definition: outdev.hxx:139
bool DrawNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption)
Request rendering of a particular control and/or part.
OUString maString
Definition: listbox.hxx:548
static OUString filterFormattingChars(const OUString &)
Definition: i18nhelp.cxx:93
virtual void FillLayoutData() const override
long AdjustWidth(long n)
sal_Int32 GetSelectedEntryPos(sal_Int32 nIndex) const
static constexpr long gnBorder
Definition: imp_listbox.cxx:50
void SetUserItemSize(const Size &rSz)
const CommandEvent * GetCommandEvent() const
Definition: event.hxx:327
const Color & GetHighlightTextColor() const
BitmapEx createBlendFrame(const Size &rSize, sal_uInt8 nAlpha, Color aColorTopLeft, Color aColorBottomRight)
Create a blend frame as BitmapEx.
Definition: bitmapex.cxx:1174
std::unique_ptr< ContentProperties > pData
void SetEntryFlags(sal_Int32 nPos, ListBoxEntryFlags nFlags)
virtual ~ImplListBoxWindow() override
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: button.hxx:32
long Height() const
Image maImage
Definition: listbox.hxx:54
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool mbVScroll
Definition: listbox.hxx:390
ImplEntryList * GetEntryList() const
Definition: listbox.hxx:267
long getWidth() const
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
SAL_DLLPRIVATE void ImplClearLayoutData() const
Definition: ctrl.cxx:330
long AdjustLeft(long nHorzMoveDelta)
tools::Rectangle maFocusRect
Definition: listbox.hxx:178
sal_uIntPtr sal_uLong
long mnLeft
output from column on
Definition: listbox.hxx:200
void disposeAndClear()
Definition: vclptr.hxx:200
long mnMaxTxtWidth
Maximum width of a text item Entry without Image.
Definition: listbox.hxx:183
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:715
constexpr sal_uInt16 KEY_A
Definition: keycodes.hxx:56
bool mbSelectionChanged
Do not call Select() too often ...
Definition: listbox.hxx:213
void ImplResizeControls()
bool mbEdgeBlending
Definition: listbox.hxx:393
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
ImplSVNWFData maNWFData
Definition: svdata.hxx:399
sal_Int64 n
SAL_DLLPRIVATE vcl::Window * ImplGetBorderWindow() const
Definition: window2.cxx:875
Link< ImplListBoxWindow *, void > maScrollHdl
Definition: listbox.hxx:226
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
void EnableMouseMoveSelect(bool bMouseMoveSelect)
Definition: listbox.hxx:336
sal_Int32 GetTopEntry() const
Definition: listbox.hxx:455
virtual Size GetSizePixel() const
Definition: window.cxx:2418
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1262
WinBits const WB_RIGHT
#define IMG_TXT_DISTANCE
Definition: listbox.hxx:40
SAL_DLLPRIVATE WindowImpl * ImplGetWindowImpl() const
Definition: window.hxx:555
sal_Int32 GetEntryPosForPoint(const Point &rPoint) const
void CompatStateChanged(StateChangedType nStateChange)
Definition: window.cxx:3910
bool IsShift() const
Definition: event.hxx:155
bool MatchString(const OUString &rStr1, const OUString &rStr2) const
Definition: i18nhelp.cxx:124
void SetMRUCount(sal_Int32 n)
Definition: listbox.hxx:156
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
constexpr::Color COL_GRAY(0x80, 0x80, 0x80)
void SetTextFillColor()
Definition: text.cxx:700
const Color & GetFieldRolloverTextColor() const
sal_uInt16 GetCode() const
Definition: keycod.hxx:53
void SelectEntry(sal_Int32 nPos, bool bSelect)
Definition: imp_listbox.cxx:84
sal_Int32 GetSelectedEntryCount() const
PosSizeFlags
Definition: window.hxx:141
DataChangedEventType GetType() const
Definition: event.hxx:357
long GetMaxEntryWidth() const
Definition: listbox.hxx:478
tools::Rectangle GetDesktopRectPixel() const
Definition: window.cxx:2865
sal_Int32 mnMRUCount
Definition: listbox.hxx:93
long CalcZoom(long n) const
Definition: window2.cxx:397
bool mbMouseMoveSelect
Select at MouseMove.
Definition: listbox.hxx:214
long GetLeftIndent() const
Definition: listbox.hxx:460
WinBits const WB_VSCROLL
sal_Int32 mnTop
output from line on
Definition: listbox.hxx:199
constexpr::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
sal_uInt16 GetDisplayLineCount() const
const Color & GetControlBackground() const
Definition: window2.cxx:1082
const CommandWheelData * GetWheelData() const
constexpr sal_uInt16 KEY_SPACE
Definition: keycodes.hxx:123
void SetSeparatorPos(sal_Int32 n)
Removes existing separators, and sets the position of the one and only separator. ...
void SetType(WindowType nType)
Definition: window2.cxx:968
bool mbCenter
center Text output
Definition: listbox.hxx:220
void PaintImmediately()
Definition: paint.cxx:1284
bool HandleScrollCommand(const CommandEvent &rCmd, ScrollBar *pHScrl, ScrollBar *pVScrl)
Definition: window2.cxx:609
void SetEntryFlags(sal_Int32 nPos, ListBoxEntryFlags nFlags)
long AdjustHeight(long n)
virtual void Tracking(const TrackingEvent &rTEvt) override
static Point ImplCalcPos(vcl::Window *pWindow, const tools::Rectangle &rRect, FloatWinPopupFlags nFlags, sal_uInt16 &rArrangeIndex, Point *pLOKTwipsPos=nullptr)
Definition: floatwin.cxx:236
sal_Int32 FindEntry(const OUString &rStr, bool bSearchMRUArea=false) const
void StartTracking(StartTrackingFlags nFlags=StartTrackingFlags::NONE)
Definition: window2.cxx:244
bool HasChildPathFocus(bool bSystemWindow=false) const
Definition: window.cxx:3062
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
const vcl::Font & GetFieldFont() const
const Color & GetFieldTextColor() const
int mnListBoxEntryMargin
Definition: svdata.hxx:340
void ImplUpdateEntryMetrics(ImplEntryType &rEntry)
constexpr sal_uInt16 KEY_UP
Definition: keycodes.hxx:111
#define LISTBOX_ENTRY_NOTFOUND
Definition: lstbox.hxx:34
const Color & GetHighlightColor() const
VclPtr< ImplListBoxWindow > maLBWindow
Definition: listbox.hxx:385
bool mbReadOnly
ReadOnly.
Definition: listbox.hxx:218
ImplEntryList(vcl::Window *pWindow)
Definition: imp_listbox.cxx:61
long GetEntryHeightWithMargin() const
void ImplInitScrollBars()
Link< void *, void > maMBDownHdl
Definition: listbox.hxx:595
sal_Int32 GetTopEntry() const
Definition: listbox.hxx:288
constexpr sal_uInt16 KEY_END
Definition: keycodes.hxx:115
bool HandleWheelAsCursorTravel(const CommandEvent &rCEvt)
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All) override
void RemoveEntry(sal_Int32 nPos)
const Fraction & GetZoom() const
Definition: window2.cxx:1210
void * GetEntryData(sal_Int32 nPos) const
StateChangedType
Definition: window.hxx:311
tools::Rectangle GetTextRect(const tools::Rectangle &rRect, const OUString &rStr, DrawTextFlags nStyle=DrawTextFlags::WordBreak, TextRectInfo *pInfo=nullptr, const vcl::ITextLayout *_pTextLayout=nullptr) const
Definition: text.cxx:1797
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
sal_uInt16 GetEdgeBlending() const
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2735
sal_uInt16 GetClicks() const
Definition: event.hxx:123
VclPtr< vcl::Window > mpWindow
For getting the current locale when matching strings.
Definition: listbox.hxx:88
sal_Int64 WinBits
IMPL_LINK_NOARG(ImplListBox, MRUChanged, LinkParamNone *, void)
sal_uInt16 sal_Unicode
bool IsTravelSelect() const
Definition: listbox.hxx:323
std::set< sal_Int32 > maSeparators
Separator positions.
Definition: listbox.hxx:195
virtual bool PreNotify(NotifyEvent &rNEvt) override
void RemoveEntry(sal_Int32 nPos)
void SetBackground()
void SetControlFont()
Definition: window2.cxx:409
long Right() const
void Enable(bool bEnable=true, bool bChild=true)
Definition: window.cxx:2449
SAL_DLLPRIVATE void ReMirror(Point &rPoint) const
Definition: outdev.cxx:613
this flags lets the item be drawn disabled (e.g.
VclPtr< ImplListBox > mpImplLB
Definition: listbox.hxx:509
void SetSymbol(SymbolType eSymbol)
Definition: button.cxx:1482
virtual void StateChanged(StateChangedType nType) override
LB_EVENT_TYPE
Definition: listbox.hxx:42
virtual ~ImplListBoxFloatingWindow() override
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
long mnTextHeight
text height
Definition: listbox.hxx:201
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
bool IsControlForeground() const
Definition: window2.cxx:1077
bool IsEnterWindow() const
Definition: event.hxx:135
bool mbHScroll
Definition: listbox.hxx:391
WinBits const WB_HSCROLL
int nCount
void SetMRUChangedHdl(const Link< LinkParamNone *, void > &rLink)
Definition: listbox.hxx:351
void Hide()
Definition: window.hxx:936
AllSettingsFlags GetFlags() const
Definition: event.hxx:358
constexpr sal_uInt16 KEY_PAGEUP
Definition: keycodes.hxx:116
virtual const Wallpaper & GetDisplayBackground() const override
bool mbIsDropdown
Listbox is actually a dropdown (either combobox, or popup window treated as dropdown) ...
Definition: listbox.hxx:224
virtual void Resize() override
sal_uInt16 GetModifier() const
Definition: keycod.hxx:56
long mnHeight
Definition: listbox.hxx:58
const void * StringEntryIdentifier
Link< LinkParamNone *, void > maListItemSelectHdl
Definition: listbox.hxx:233
long Top() const
bool IsValid() const
ImplWin(vcl::Window *pParent, WinBits nWinStyle)
sal_Int32 mnMaxMRUCount
Definition: listbox.hxx:94
bool mbSimpleMode
SimpleMode for MultiListBox.
Definition: listbox.hxx:210
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:88
const Color & GetEdgeBlendingBottomRightColor() const
Image GetEntryImage(sal_Int32 nPos) const
long mnMaxTxtHeight
Maximum height of a text item.
Definition: listbox.hxx:182
ImplListBoxWindow * GetMainWindow()
Definition: listbox.hxx:417
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:32
sal_Int32 mnTrackingSaveSelection
Selection before Tracking();.
Definition: listbox.hxx:193
void SetEntryFlags(sal_Int32 nPos, ListBoxEntryFlags nFlags)
const Color & GetControlForeground() const
Definition: window2.cxx:1072
this flag disables a selection of an entry completely.
void SetTopEntry(sal_Int32 nTop)
Definition: listbox.hxx:454
constexpr sal_uInt16 KEY_DOWN
Definition: keycodes.hxx:110
void RemoveEntry(sal_Int32 nPos)
void SetScrollHdl(const Link< ImplListBoxWindow *, void > &rLink)
Definition: listbox.hxx:346
Link< void *, void > maMBDownHdl
Definition: listbox.hxx:553
ImplListBoxFloatingWindow(vcl::Window *pParent)
sal_Int32 GetSeparatorPos() const
Gets the position of the separator which was added first.
sal_Int32 GetMRUCount() const
Definition: listbox.hxx:157
bool IsEmpty() const
Definition: bitmapex.cxx:204
void ShowProminentEntry(sal_Int32 nPos)
Definition: listbox.hxx:456
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:75
bool ProcessKeyInput(const KeyEvent &rKEvt)
this flag can be used to make an entry multiline capable A normal entry is single line and will there...
void SetLineColor()
virtual void KeyInput(const KeyEvent &rKEvt) override
void clear()
Definition: vclptr.hxx:190
const Color & GetDisableColor() const
virtual bool PreNotify(NotifyEvent &rNEvt) override
Definition: syswin.cxx:202
std::vector< std::unique_ptr< ImplEntryType > > maEntries
Definition: listbox.hxx:98
sal_Int32 FindFirstSelectable(sal_Int32 nPos, bool bForward=true)
bool IsRTLEnabled() const
Definition: outdev.hxx:1361
virtual bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:51
bool mbStackMode
StackSelection.
Definition: listbox.hxx:209
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
void ScrollHorz(long nDiff)
bool IsLeaveWindow() const
Definition: event.hxx:137
int i
virtual void Resize() override
bool IsEntryPosSelected(sal_Int32 nIndex) const
bool IsNativeWidgetEnabled() const
Definition: window.cxx:3761
ImplBtn(vcl::Window *pParent, WinBits nWinStyle)
virtual void Resize() override
constexpr sal_uInt16 KEY_HOME
Definition: keycodes.hxx:114
virtual ~ImplListBox() override
void SetControlBackground()
Definition: window2.cxx:497
virtual bool PreNotify(NotifyEvent &rNEvt) override
WinBits const WB_SIMPLEMODE
void SetRangeMax(long nNewRange)
Definition: scrbar.cxx:1333
long mnMaxWidth
Maximum width of an entry.
Definition: listbox.hxx:189
IMPL_LINK(ImplListBox, ScrollBarHdl, ScrollBar *, pSB, void)
void SetVisibleSize(long nNewSize)
Definition: scrbar.cxx:1377
bool mbMulti
MultiListBox.
Definition: listbox.hxx:208
void ImplCheckScrollBars()
Link< ImplListBoxWindow *, void > maDoubleClickHdl
Definition: listbox.hxx:229
void SetSize(const Size &rSize)
void SetControlForeground()
Definition: window2.cxx:457
CommandWheelMode GetMode() const
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1160
SAL_DLLPRIVATE bool ImplIsAntiparallel() const
Definition: outdev.cxx:597
void SetUpdateMode(bool bUpdate)
Definition: window.cxx:3025
Size GetOutputSize() const
Definition: outdev.hxx:450
sal_Int32 mnSelectionAnchor
Definition: listbox.hxx:90
long mnMaxHeight
Maximum height of an entry.
Definition: listbox.hxx:190
ImplListBox(vcl::Window *pParent, WinBits nWinStyle)
bool IsUpdateMode() const
Definition: window2.cxx:1173
void SetFillColor()
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
void DrawEntry(vcl::RenderContext &rRenderContext, sal_Int32 nPos, bool bDrawImage, bool bDrawText, bool bDrawTextAtImagePos)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
const Color & GetFieldColor() const
CommandEventId GetCommand() const
const Color & GetLineColor() const
Definition: outdev.hxx:624
VclPtr< ScrollBarBox > mpScrollBarBox
Definition: listbox.hxx:388
void SetZoom(const Fraction &rZoom)
Definition: window2.cxx:365
sal_uInt16 GetModifier() const
Size CalcSize(sal_Int32 nMaxLines) const
void SetTextColor(const Color &rColor)
Definition: text.cxx:665
long Bottom() const
long GetEntryHeight(sal_Int32 nPos) const
constexpr sal_uInt16 KEY_PAGEDOWN
Definition: keycodes.hxx:117
long const nBorder
DrawTextFlags ImplGetTextStyle() const
bool IsZoom() const
Definition: window2.cxx:1215
void SetEdgeBlending(bool bNew)
Definition: listbox.hxx:370
void ImplDoPaint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
MouseNotifyEvent GetType() const
Definition: event.hxx:303
void SetPageSize(long nNewSize)
Definition: scrbar.hxx:125
bool IsInside(const Point &rPOINT) const
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
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
vcl::QuickSelectionEngine maQuickSelectionEngine
Definition: listbox.hxx:235
DrawTextFlags
Definition: outdev.hxx:144
bool GetEdgeBlending() const
Definition: listbox.hxx:582
VclPtr< ScrollBar > mpHScrollBar
Definition: listbox.hxx:386
void ApplyControlForeground(vcl::RenderContext &rRenderContext, const Color &rDefaultColor)
Definition: window2.cxx:489
Link< LinkParamNone *, void > maCancelHdl
Definition: listbox.hxx:228
std::unique_ptr< ImplEntryList > mpEntryList
EntryList.
Definition: listbox.hxx:177
WinBits const WB_SORT
sal_uInt16 GetModifier() const
Definition: event.hxx:153
bool mbSort
ListBox sorted.
Definition: listbox.hxx:206
virtual void LoseFocus()
Definition: window.cxx:1872
bool GetEdgeBlending() const
Definition: listbox.hxx:369
OUString maStr
Definition: listbox.hxx:52
std::unique_ptr< SalLayout > ImplLayout(const OUString &, sal_Int32 nIndex, sal_Int32 nLen, const Point &rLogicPos=Point(0, 0), long nLogicWidth=0, const long *pLogicDXArray=nullptr, SalLayoutFlags flags=SalLayoutFlags::NONE, vcl::TextLayoutCache const *=nullptr, const SalLayoutGlyphs *pGlyphs=nullptr) const
Definition: text.cxx:1241
void GrabFocus()
Definition: window.cxx:3034
Link< UserDrawEvent *, void > maUserDrawHdl
Definition: listbox.hxx:230
long GetTextHeight() const
Height where any character of the current font fits; in logic coordinates.
Definition: text.cxx:891
virtual void ShowFocus(const tools::Rectangle &rRect)
Definition: window2.cxx:49
bool mbTravelSelect
TravelSelect.
Definition: listbox.hxx:211
vcl::Window * GetParent() const
Definition: window2.cxx:1097
ListBoxEntryFlags mnFlags
Definition: listbox.hxx:57
sal_Int32 FindMatchingEntry(const OUString &rStr, sal_Int32 nStart, bool bLazy) const
void SetLeftIndent(sal_uInt16 n)
Definition: listbox.hxx:461
void ImplPaint(vcl::RenderContext &rRenderContext, sal_Int32 nPos)
bool IsTrackingEnded() const
Definition: event.hxx:263
Link< LinkParamNone *, void > maMRUChangedHdl
Definition: listbox.hxx:231
virtual void MouseMove(const MouseEvent &rMEvt) override
void DrawEntry(vcl::RenderContext &rRenderContext, bool bLayout)
Size CalcSize(sal_Int32 nMaxLines) const
Definition: listbox.hxx:475
constexpr sal_uInt16 KEY_RETURN
Definition: keycodes.hxx:119
WinBits const WB_NOBORDER
const Color & GetButtonRolloverTextColor() const
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
Definition: window2.cxx:1268
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1046
constexpr sal_uInt16 KEY_RIGHT
Definition: keycodes.hxx:113
#define MULTILINE_ENTRY_DRAW_FLAGS
Definition: imp_listbox.cxx:46
void SetLineSize(long nNewSize)
Definition: scrbar.hxx:123
bool mbIsSelected
Definition: listbox.hxx:56
sal_Int32 mnCurrentPos
Position (Focus)
Definition: listbox.hxx:192
bool mbUserDrawEnabled
UserDraw possible.
Definition: listbox.hxx:216
Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1179
VclPtr< ScrollBar > mpVScrollBar
Definition: listbox.hxx:387
bool IsMouseMoveSelect() const
Definition: listbox.hxx:337
long mnMaxImgWidth
Maximum width of an image item.
Definition: listbox.hxx:187
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1822
const LanguageTag & getLocale()
const vcl::I18nHelper & GetLocaleI18nHelper() const
bool mbUseNativeFocus
Definition: window.h:317
void GetBorder(sal_Int32 &rLeftBorder, sal_Int32 &rTopBorder, sal_Int32 &rRightBorder, sal_Int32 &rBottomBorder) const
Definition: window.cxx:2440
void * mpUserData
Definition: listbox.hxx:55
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:54
virtual void Scroll(long nHorzScroll, long nVertScroll, ScrollFlags nFlags=ScrollFlags::NONE)
Definition: window.cxx:2998
void Erase()
Definition: wallpaper.cxx:103
bool IsShift() const
Definition: keycod.hxx:58
bool IsUserDrawEnabled() const
Definition: listbox.hxx:329
bool IsMouseOver() const
Definition: mouse.cxx:606
virtual void Resize() override
Definition: ctrl.cxx:74
ImplEntryType * GetEntry(sal_Int32 nPos) const
Definition: listbox.hxx:100
bool ProcessKeyInput(const KeyEvent &rKEvt)
Definition: listbox.hxx:435
const ImplEntryType * GetEntryPtr(sal_Int32 nPos) const
Definition: listbox.hxx:113
Definition: ctrl.hxx:33
long GetDelta() const
bool IsEntrySelectable(sal_Int32 nPos) const
An Entry is selectable if its mnFlags does not have the ListBoxEntryFlags::DisableSelection flag set...
#define LISTBOX_MAX_ENTRIES
Definition: lstbox.hxx:35
ListBoxEntryFlags
Definition: lstbox.hxx:44
bool IsSynthetic() const
Definition: event.hxx:139
virtual void GetFocus()
Definition: window.cxx:1858
const Color & GetButtonTextColor() const
bool mbNoFocusRects
Definition: svdata.hxx:321
sal_Int32 mnItemPos
because of UserDraw I have to know which item I draw
Definition: listbox.hxx:547
#define SAL_WARN_IF(condition, area, stream)
WinBits const WB_BORDER
unsigned char sal_uInt8
bool bIsEnabled
const MouseEvent * GetMouseEvent() const
Definition: event.hxx:319
std::unique_ptr< vcl::ImplControlData > mpControlData
Definition: ctrl.hxx:36
virtual void GetFocus() override
sal_Int32 mnLastSelected
Definition: listbox.hxx:89
bool IsVisible() const
Definition: window2.cxx:1102
virtual vcl::StringEntryIdentifier CurrentEntry(OUString &_out_entryText) const override
returns the current entry in the list of searchable strings.
sal_Int32 mnPopupModeStartSaveSelection
Definition: listbox.hxx:512
long mnMaxImgHeight
Maximum height of an image item.
Definition: listbox.hxx:188
void SetSeparatorPos(sal_Int32 n)
Removes existing separators, and sets the position of the one and only separator. ...
Definition: listbox.hxx:442
bool SelectEntries(sal_Int32 nSelect, LB_EVENT_TYPE eLET, bool bShift=false, bool bCtrl=false, bool bSelectPosChange=false)
bool mbMirroring
pb: #106948# explicit mirroring for calc
Definition: listbox.hxx:219
sal_uInt16 mnSelectModifier
Modifiers.
Definition: listbox.hxx:203
::OutputDevice const * GetOutDev() const
Definition: window.cxx:575
bool IsLeft() const
Definition: event.hxx:146
void SetScrollHdl(const Link< ScrollBar *, void > &rLink)
Definition: scrbar.hxx:133
Definition: image.hxx:40
bool IsMod1() const
Definition: keycod.hxx:60
long GetAddedHeight(sal_Int32 nEndIndex, sal_Int32 nBeginIndex) const
helper: add up heights up to index nEndIndex.
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
long GetEntryHeightWithMargin() const
Definition: listbox.hxx:477
long mnMaxImgTxtWidth
Maximum width of a text item Entry AND Image.
Definition: listbox.hxx:185
Reference< XComponentContext > getProcessComponentContext()
ImplListBoxWindow(vcl::Window *pParent, WinBits nWinStyle)
bool IsGrabFocusAllowed() const
Definition: listbox.hxx:300
const Point & GetPosPixel() const
Definition: event.hxx:120
sal_Int32 mnImages
Definition: listbox.hxx:91
WinBits const WB_AUTOHSCROLL
long getHeightWithMargin() const
virtual void GetFocus() override
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:880
sal_Int32 InsertEntry(sal_Int32 nPos, ImplEntryType *pNewEntry)
virtual bool EventNotify(NotifyEvent &rNEvt) override
Event to pass information for UserDraw() handling eg. in comboboxes.
Definition: event.hxx:218
WinBits const WB_CENTER
sal_Int32 InsertEntry(sal_Int32 nPos, const OUString &rStr)
bool isSeparator(const sal_Int32 &n) const
Checks if the given number n is an element of the separator positions set.
ScXMLEditAttributeMap::Entry const aEntries[]
bool IsEnabled() const
Definition: window2.cxx:1122
void SetLeft(long v)
#define SAL_WARN(area, stream)
Image maImage
Definition: listbox.hxx:549
OUString GetSelectedEntry(sal_Int32 nIndex) const
void SetTopEntry(sal_Int32 nTop)
bool IsTrackingCanceled() const
Definition: event.hxx:265
OUString GetMRUEntries(sal_Unicode cSep) const
WinBits GetStyle() const
Definition: window2.cxx:953
void SelectEntry(sal_Int32 nPos, bool bSelect)
Link< sal_Int32, void > maSelectionChangedHdl
Definition: listbox.hxx:96
sal_Int32 mnUserDrawEntry
Definition: listbox.hxx:197
virtual void FillLayoutData() const override
bool IsReadOnly() const
Definition: listbox.hxx:361
void ApplyControlFont(vcl::RenderContext &rRenderContext, const vcl::Font &rDefaultFont)
Definition: window2.cxx:449
OUString GetEntryText(sal_Int32 nPos) const
constexpr sal_uInt16 KEY_LEFT
Definition: keycodes.hxx:112
Point OutputToScreenPixel(const Point &rPos) const
Definition: window.cxx:2872
void StartFloat(bool bStartTracking)
sal_Int32 GetLastVisibleEntry() const
void SetEntryData(sal_Int32 nPos, void *pNewData)
void ImplInitDropDownButton(PushButton *pButton)
Definition: imp_listbox.cxx:52
sal_Int32 compare(const OUString &rLHS, const OUString &rRHS) const
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
void SetLeftIndent(long n)
void SetAccessibleRole(sal_uInt16 nRole)
long GetScrollBarSize() const
bool mbInUserDraw
In UserDraw.
Definition: listbox.hxx:217
const MouseEvent & GetMouseEvent() const
Definition: event.hxx:259
bool IsReallyVisible() const
Definition: window2.cxx:1107
vcl::Font GetControlFont() const
Definition: window2.cxx:438
bool IsMirroring() const
Definition: listbox.hxx:367
bool mbGrabFocus
Grab focus at MBDown.
Definition: listbox.hxx:215
virtual vcl::StringEntryIdentifier NextEntry(vcl::StringEntryIdentifier _currentEntry, OUString &_out_entryText) const override
returns the next entry in the list.
SalLayoutGlyphs * GetTextGlyphs(const OutputDevice *pOutputDevice)
Computes maStr's text layout (glyphs), cached in maStrGlyphs.
bool HasFocus() const
Definition: window.cxx:3039
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: floatwin.cxx:204
const Color & GetEdgeBlendingTopLeftColor() const
void SetEdgeBlending(bool bNew)
WinBits const WB_WORDBREAK
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
bool SupportsDoubleBuffering() const
Can the widget derived from this Window do the double-buffering via RenderContext properly...
Definition: window.cxx:3872
void setWidth(long nWidth)
void ShowProminentEntry(sal_Int32 nEntryPos)
ShowProminentEntry will set the entry corresponding to nEntryPos either at top or in the middle depen...
void EndPopupMode(FloatWinPopupEndFlags nFlags=FloatWinPopupEndFlags::NONE)
Definition: floatwin.cxx:910
sal_Int32 InsertEntry(sal_Int32 nPos, ImplEntryType *pNewEntry, bool bSort)
sal_Int32 nState
DrawImageFlags
Definition: outdev.hxx:172
virtual void SetPosPixel(const Point &rNewPos)
Definition: window2.cxx:1257
aStr
virtual void Resize() override
Definition: syswin.cxx:1053
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
virtual void GetFocus() override
bool mbCallSelectionChangedHdl
Definition: listbox.hxx:97
sal_Int32 GetEntryCount() const
Definition: listbox.hxx:127
void SetThumbPos(long nThumbPos)
Definition: scrbar.cxx:1363
bool IsMod3() const
Definition: keycod.hxx:64
sal_uInt16 nPos
tools::Rectangle GetBoundingRectangle(sal_Int32 nItem) const
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35
Link< LinkParamNone *, void > maSelectHdl
Definition: listbox.hxx:227
bool IsMod1() const
Definition: event.hxx:157
void ImplDraw(vcl::RenderContext &rRenderContext, bool bLayout=false)
WinBits const WB_DRAG
bool IsMod2() const
Definition: keycod.hxx:62
bool mbTrackingSelect
Selected at a MouseMove.
Definition: listbox.hxx:212
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2204
void setHeight(long nHeight)
bool mbRight
right align Text output
Definition: listbox.hxx:221
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
WinBits const WB_LISTBOX_POPUP