Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / listbox.hxx
blob8b37562971874dc482fc775d6986e67b1053f4bc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_INC_LISTBOX_HXX
21 #define INCLUDED_VCL_INC_LISTBOX_HXX
23 #include <sal/config.h>
25 #include <o3tl/safeint.hxx>
26 #include <utility>
27 #include <vcl/glyphitem.hxx>
28 #include <vcl/toolkit/button.hxx>
29 #include <vcl/toolkit/floatwin.hxx>
30 #include <vcl/toolkit/lstbox.hxx>
31 #include <vcl/quickselectionengine.hxx>
33 #include <set>
34 #include <vector>
35 #include <memory>
37 class ScrollBar;
38 class ScrollBarBox;
40 #define HORZ_SCROLL 4
41 #define IMG_TXT_DISTANCE 6
43 enum LB_EVENT_TYPE
45 LET_MBDOWN,
46 LET_TRACKING,
47 LET_KEYMOVE,
48 LET_KEYSPACE
51 struct ImplEntryType
53 OUString maStr;
54 SalLayoutGlyphs maStrGlyphs;
55 Image maImage;
56 void* mpUserData;
57 bool mbIsSelected;
58 ListBoxEntryFlags mnFlags;
59 tools::Long mnHeight;
61 tools::Long getHeightWithMargin() const;
63 ImplEntryType( OUString aStr, Image aImage ) :
64 maStr(std::move( aStr )),
65 maImage(std::move( aImage )),
66 mnFlags( ListBoxEntryFlags::NONE ),
67 mnHeight( 0 )
69 mbIsSelected = false;
70 mpUserData = nullptr;
73 ImplEntryType( OUString aStr ) :
74 maStr(std::move( aStr )),
75 mnFlags( ListBoxEntryFlags::NONE ),
76 mnHeight( 0 )
78 mbIsSelected = false;
79 mpUserData = nullptr;
82 /// Computes maStr's text layout (glyphs), cached in maStrGlyphs.
83 SalLayoutGlyphs* GetTextGlyphs(const OutputDevice* pOutputDevice);
86 class ImplEntryList
88 private:
89 VclPtr<vcl::Window> mpWindow; ///< For getting the current locale when matching strings
90 sal_Int32 mnLastSelected;
91 sal_Int32 mnSelectionAnchor;
92 sal_Int32 mnImages;
94 sal_Int32 mnMRUCount;
95 sal_Int32 mnMaxMRUCount;
97 Link<sal_Int32,void> maSelectionChangedHdl;
98 bool mbCallSelectionChangedHdl;
99 std::vector<std::unique_ptr<ImplEntryType> > maEntries;
101 ImplEntryType* GetEntry( sal_Int32 nPos ) const
103 if (nPos < 0 || o3tl::make_unsigned(nPos) >= maEntries.size())
104 return nullptr;
105 return maEntries[nPos].get();
108 public:
109 ImplEntryList( vcl::Window* pWindow );
110 ~ImplEntryList();
112 sal_Int32 InsertEntry( sal_Int32 nPos, ImplEntryType* pNewEntry, bool bSort );
113 void RemoveEntry( sal_Int32 nPos );
114 const ImplEntryType* GetEntryPtr( sal_Int32 nPos ) const { return GetEntry( nPos ); }
115 ImplEntryType* GetMutableEntryPtr( sal_Int32 nPos ) const { return GetEntry( nPos ); }
116 void Clear();
117 void dispose();
119 sal_Int32 FindMatchingEntry( const OUString& rStr, sal_Int32 nStart, bool bLazy ) const;
120 sal_Int32 FindEntry( std::u16string_view rStr, bool bSearchMRUArea = false ) const;
122 /// helper: add up heights up to index nEndIndex.
123 /// GetAddedHeight( 0 ) @return 0
124 /// GetAddedHeight( LISTBOX_ENTRY_NOTFOUND ) @return 0
125 /// GetAddedHeight( i, k ) with k > i is equivalent -GetAddedHeight( k, i )
126 tools::Long GetAddedHeight( sal_Int32 nEndIndex, sal_Int32 nBeginIndex ) const;
127 tools::Long GetEntryHeight( sal_Int32 nPos ) const;
129 sal_Int32 GetEntryCount() const { return static_cast<sal_Int32>(maEntries.size()); }
130 bool HasImages() const { return mnImages != 0; }
132 OUString GetEntryText( sal_Int32 nPos ) const;
134 bool HasEntryImage( sal_Int32 nPos ) const;
135 Image GetEntryImage( sal_Int32 nPos ) const;
137 void SetEntryData( sal_Int32 nPos, void* pNewData );
138 void* GetEntryData( sal_Int32 nPos ) const;
140 void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags );
142 void SelectEntry( sal_Int32 nPos, bool bSelect );
144 sal_Int32 GetSelectedEntryCount() const;
145 OUString GetSelectedEntry( sal_Int32 nIndex ) const;
146 sal_Int32 GetSelectedEntryPos( sal_Int32 nIndex ) const;
147 bool IsEntryPosSelected( sal_Int32 nIndex ) const;
149 void SetLastSelected( sal_Int32 nPos ) { mnLastSelected = nPos; }
150 sal_Int32 GetLastSelected() const { return mnLastSelected; }
152 void SetSelectionAnchor( sal_Int32 nPos ) { mnSelectionAnchor = nPos; }
153 sal_Int32 GetSelectionAnchor() const { return mnSelectionAnchor; }
155 void SetSelectionChangedHdl( const Link<sal_Int32,void>& rLnk ) { maSelectionChangedHdl = rLnk; }
156 void SetCallSelectionChangedHdl( bool bCall ) { mbCallSelectionChangedHdl = bCall; }
158 void SetMRUCount( sal_Int32 n ) { mnMRUCount = n; }
159 sal_Int32 GetMRUCount() const { return mnMRUCount; }
161 void SetMaxMRUCount( sal_Int32 n ) { mnMaxMRUCount = n; }
162 sal_Int32 GetMaxMRUCount() const { return mnMaxMRUCount; }
164 /** An Entry is selectable if its mnFlags does not have the
165 ListBoxEntryFlags::DisableSelection flag set. */
166 bool IsEntrySelectable( sal_Int32 nPos ) const;
168 /** @return the first entry found from the given position nPos that is selectable
169 or LISTBOX_ENTRY_NOTFOUND if non is found. If the entry at nPos is not selectable,
170 it returns the first selectable entry after nPos if bForward is true and the
171 first selectable entry after nPos is bForward is false.
173 sal_Int32 FindFirstSelectable( sal_Int32 nPos, bool bForward = true ) const;
176 class ImplListBoxWindow final : public Control, public vcl::ISearchableStringList
178 private:
179 ImplEntryList maEntryList; ///< EntryList
180 tools::Rectangle maFocusRect;
182 Size maUserItemSize;
184 tools::Long mnMaxTxtHeight; ///< Maximum height of a text item
185 tools::Long mnMaxTxtWidth; ///< Maximum width of a text item
186 ///< Entry without Image
187 tools::Long mnMaxImgTxtWidth;///< Maximum width of a text item
188 ///< Entry AND Image
189 tools::Long mnMaxImgWidth; ///< Maximum width of an image item
190 tools::Long mnMaxImgHeight; ///< Maximum height of an image item
191 tools::Long mnMaxWidth; ///< Maximum width of an entry
192 tools::Long mnMaxHeight; ///< Maximum height of an entry
194 sal_Int32 mnCurrentPos; ///< Position (Focus)
195 sal_Int32 mnTrackingSaveSelection; ///< Selection before Tracking();
197 std::set< sal_Int32 > maSeparators; ///< Separator positions
199 sal_Int32 mnUserDrawEntry;
201 sal_Int32 mnTop; ///< output from line on
202 tools::Long mnLeft; ///< output from column on
203 tools::Long mnTextHeight; ///< text height
205 sal_uInt16 mnSelectModifier; ///< Modifiers
207 bool mbHasFocusRect : 1;
208 bool mbSort : 1; ///< ListBox sorted
209 bool mbTrack : 1; ///< Tracking
210 bool mbMulti : 1; ///< MultiListBox
211 bool mbSimpleMode : 1; ///< SimpleMode for MultiListBox
212 bool mbTravelSelect : 1; ///< TravelSelect
213 bool mbTrackingSelect : 1; ///< Selected at a MouseMove
214 bool mbSelectionChanged : 1; ///< Do not call Select() too often ...
215 bool mbMouseMoveSelect : 1; ///< Select at MouseMove
216 bool mbGrabFocus : 1; ///< Grab focus at MBDown
217 bool mbUserDrawEnabled : 1; ///< UserDraw possible
218 bool mbInUserDraw : 1; ///< In UserDraw
219 bool mbReadOnly : 1; ///< ReadOnly
220 bool mbCenter : 1; ///< center Text output
221 bool mbRight : 1; ///< right align Text output
222 bool mbEdgeBlending : 1;
223 /// Listbox is actually a dropdown (either combobox, or popup window treated as dropdown)
224 bool mbIsDropdown : 1;
226 Link<ImplListBoxWindow*,void> maScrollHdl;
227 Link<LinkParamNone*,void> maSelectHdl;
228 Link<LinkParamNone*,void> maCancelHdl;
229 Link<ImplListBoxWindow*,void> maDoubleClickHdl;
230 Link<UserDrawEvent*, void> maUserDrawHdl;
231 Link<LinkParamNone*,void> maMRUChangedHdl;
232 Link<sal_Int32,void> maFocusHdl;
233 Link<LinkParamNone*,void> maListItemSelectHdl;
235 vcl::QuickSelectionEngine maQuickSelectionEngine;
237 virtual void KeyInput( const KeyEvent& rKEvt ) override;
238 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
239 virtual void MouseMove( const MouseEvent& rMEvt ) override;
240 virtual void Tracking( const TrackingEvent& rTEvt ) override;
241 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
242 virtual void Resize() override;
243 virtual void GetFocus() override;
244 virtual void LoseFocus() override;
246 bool SelectEntries( sal_Int32 nSelect, LB_EVENT_TYPE eLET, bool bShift = false, bool bCtrl = false, bool bSelectPosChange = false );
247 void ImplPaint(vcl::RenderContext& rRenderContext, sal_Int32 nPos);
248 void ImplDoPaint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect);
249 void ImplCalcMetrics();
250 void ImplUpdateEntryMetrics( ImplEntryType& rEntry );
251 void ImplCallSelect();
253 void ImplShowFocusRect();
254 void ImplHideFocusRect();
256 virtual void StateChanged( StateChangedType nType ) override;
257 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
259 public:
260 virtual void FillLayoutData() const override;
262 ImplListBoxWindow( vcl::Window* pParent, WinBits nWinStyle );
263 virtual ~ImplListBoxWindow() override;
264 virtual void dispose() override;
266 const ImplEntryList& GetEntryList() const { return maEntryList; }
267 ImplEntryList& GetEntryList() { return maEntryList; }
269 sal_Int32 InsertEntry( sal_Int32 nPos, ImplEntryType* pNewEntry ); // sorts using mbSort
270 sal_Int32 InsertEntry( sal_Int32 nPos, ImplEntryType* pNewEntry, bool bSort ); // to insert ignoring mbSort, e.g. mru
271 void RemoveEntry( sal_Int32 nPos );
272 void Clear();
273 void ResetCurrentPos() { mnCurrentPos = LISTBOX_ENTRY_NOTFOUND; }
274 sal_Int32 GetCurrentPos() const { return mnCurrentPos; }
275 sal_uInt16 GetDisplayLineCount() const;
276 void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags );
278 void DrawEntry(vcl::RenderContext& rRenderContext, sal_Int32 nPos, bool bDrawImage, bool bDrawText);
280 void SelectEntry( sal_Int32 nPos, bool bSelect );
281 void DeselectAll();
282 sal_Int32 GetEntryPosForPoint( const Point& rPoint ) const;
283 sal_Int32 GetLastVisibleEntry() const;
285 bool ProcessKeyInput( const KeyEvent& rKEvt );
287 void SetTopEntry( sal_Int32 nTop );
288 sal_Int32 GetTopEntry() const { return mnTop; }
289 /** ShowProminentEntry will set the entry corresponding to nEntryPos
290 either at top or in the middle depending on the chosen style*/
291 void ShowProminentEntry( sal_Int32 nEntryPos );
292 using Window::IsVisible;
293 bool IsVisible( sal_Int32 nEntry ) const;
295 tools::Long GetLeftIndent() const { return mnLeft; }
296 void SetLeftIndent( tools::Long n );
297 void ScrollHorz( tools::Long nDiff );
299 void AllowGrabFocus( bool b ) { mbGrabFocus = b; }
300 bool IsGrabFocusAllowed() const { return mbGrabFocus; }
303 * Removes existing separators, and sets the position of the
304 * one and only separator.
306 void SetSeparatorPos( sal_Int32 n );
308 * Gets the position of the separator which was added first.
309 * Returns LISTBOX_ENTRY_NOTFOUND if there is no separator.
311 sal_Int32 GetSeparatorPos() const;
314 * Adds a new separator at the given position n.
316 void AddSeparator( sal_Int32 n ) { maSeparators.insert( n ); }
318 * Checks if the given number n is an element of the separator positions set.
320 bool isSeparator( const sal_Int32 &n ) const;
322 void SetTravelSelect( bool bTravelSelect ) { mbTravelSelect = bTravelSelect; }
323 bool IsTravelSelect() const { return mbTravelSelect; }
324 bool IsTrackingSelect() const { return mbTrackingSelect; }
326 void SetUserItemSize( const Size& rSz );
328 void EnableUserDraw( bool bUserDraw ) { mbUserDrawEnabled = bUserDraw; }
329 bool IsUserDrawEnabled() const { return mbUserDrawEnabled; }
331 void EnableMultiSelection( bool bMulti ) { mbMulti = bMulti; }
332 bool IsMultiSelectionEnabled() const { return mbMulti; }
334 void SetMultiSelectionSimpleMode( bool bSimple ) { mbSimpleMode = bSimple; }
336 void EnableMouseMoveSelect( bool bMouseMoveSelect ) { mbMouseMoveSelect = bMouseMoveSelect; }
337 bool IsMouseMoveSelect() const { return mbMouseMoveSelect; }
339 Size CalcSize(sal_Int32 nMaxLines) const;
340 tools::Rectangle GetBoundingRectangle( sal_Int32 nItem ) const;
342 tools::Long GetEntryHeight() const { return mnMaxHeight; }
343 tools::Long GetEntryHeightWithMargin() const;
344 tools::Long GetMaxEntryWidth() const { return mnMaxWidth; }
346 void SetScrollHdl( const Link<ImplListBoxWindow*,void>& rLink ) { maScrollHdl = rLink; }
347 void SetSelectHdl( const Link<LinkParamNone*,void>& rLink ) { maSelectHdl = rLink; }
348 void SetCancelHdl( const Link<LinkParamNone*,void>& rLink ) { maCancelHdl = rLink; }
349 void SetDoubleClickHdl( const Link<ImplListBoxWindow*,void>& rLink ) { maDoubleClickHdl = rLink; }
350 void SetUserDrawHdl( const Link<UserDrawEvent*, void>& rLink ) { maUserDrawHdl = rLink; }
351 void SetMRUChangedHdl( const Link<LinkParamNone*,void>& rLink ) { maMRUChangedHdl = rLink; }
352 void SetFocusHdl( const Link<sal_Int32,void>& rLink ) { maFocusHdl = rLink ; }
354 void SetListItemSelectHdl( const Link<LinkParamNone*,void>& rLink ) { maListItemSelectHdl = rLink ; }
355 bool IsSelectionChanged() const { return mbSelectionChanged; }
356 sal_uInt16 GetSelectModifier() const { return mnSelectModifier; }
358 void EnableSort( bool b ) { mbSort = b; }
360 void SetReadOnly( bool bReadOnly ) { mbReadOnly = bReadOnly; }
361 bool IsReadOnly() const { return mbReadOnly; }
363 DrawTextFlags ImplGetTextStyle() const;
365 bool GetEdgeBlending() const { return mbEdgeBlending; }
366 void SetEdgeBlending(bool bNew) { mbEdgeBlending = bNew; }
368 using Control::ImplInitSettings;
369 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
371 private:
372 // ISearchableStringList
373 virtual vcl::StringEntryIdentifier CurrentEntry( OUString& _out_entryText ) const override;
374 virtual vcl::StringEntryIdentifier NextEntry( vcl::StringEntryIdentifier _currentEntry, OUString& _out_entryText ) const override;
375 virtual void SelectEntry( vcl::StringEntryIdentifier _entry ) override;
378 class ImplListBox final : public Control
380 private:
381 VclPtr<ImplListBoxWindow> maLBWindow;
382 VclPtr<ScrollBar> mpHScrollBar;
383 VclPtr<ScrollBar> mpVScrollBar;
384 VclPtr<ScrollBarBox> mpScrollBarBox;
386 bool mbVScroll : 1; // VScroll on or off
387 bool mbHScroll : 1; // HScroll on or off
388 bool mbAutoHScroll : 1; // AutoHScroll on or off
389 bool mbEdgeBlending : 1;
391 Link<ImplListBox*,void> maScrollHdl; // because it is needed by ImplListBoxWindow itself
393 virtual void GetFocus() override;
394 virtual void StateChanged( StateChangedType nType ) override;
396 virtual bool EventNotify( NotifyEvent& rNEvt ) override;
398 void ImplResizeControls();
399 void ImplCheckScrollBars();
400 void ImplInitScrollBars();
402 DECL_LINK( ScrollBarHdl, ScrollBar*, void );
403 DECL_LINK( LBWindowScrolled, ImplListBoxWindow*, void );
404 DECL_LINK( MRUChanged, LinkParamNone*, void );
406 public:
407 ImplListBox( vcl::Window* pParent, WinBits nWinStyle );
408 virtual ~ImplListBox() override;
409 virtual void dispose() override;
411 const ImplEntryList& GetEntryList() const { return maLBWindow->GetEntryList(); }
412 ImplListBoxWindow* GetMainWindow() { return maLBWindow.get(); }
414 virtual void Resize() override;
415 virtual const Wallpaper& GetDisplayBackground() const override;
417 sal_Int32 InsertEntry( sal_Int32 nPos, const OUString& rStr );
418 sal_Int32 InsertEntry( sal_Int32 nPos, const OUString& rStr, const Image& rImage );
419 void RemoveEntry( sal_Int32 nPos );
420 void SetEntryData( sal_Int32 nPos, void* pNewData ) { maLBWindow->GetEntryList().SetEntryData( nPos, pNewData ); }
421 void Clear();
423 void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags );
425 void SelectEntry( sal_Int32 nPos, bool bSelect );
426 void SetNoSelection();
427 void ResetCurrentPos() { maLBWindow->ResetCurrentPos(); }
428 sal_Int32 GetCurrentPos() const { return maLBWindow->GetCurrentPos(); }
430 bool ProcessKeyInput( const KeyEvent& rKEvt ) { return maLBWindow->ProcessKeyInput( rKEvt ); }
431 bool HandleWheelAsCursorTravel(const CommandEvent& rCEvt, Control& rControl);
434 * Removes existing separators, and sets the position of the
435 * one and only separator.
437 void SetSeparatorPos( sal_Int32 n ) { maLBWindow->SetSeparatorPos( n ); }
439 * Gets the position of the separator which was added first.
440 * Returns LISTBOX_ENTRY_NOTFOUND if there is no separator.
442 sal_Int32 GetSeparatorPos() const { return maLBWindow->GetSeparatorPos(); }
445 * Adds a new separator at the given position n.
447 void AddSeparator( sal_Int32 n ) { maLBWindow->AddSeparator( n ); }
449 void SetTopEntry( sal_Int32 nTop ) { maLBWindow->SetTopEntry( nTop ); }
450 sal_Int32 GetTopEntry() const { return maLBWindow->GetTopEntry(); }
451 void ShowProminentEntry( sal_Int32 nPos ) { maLBWindow->ShowProminentEntry( nPos ); }
452 using Window::IsVisible;
453 bool IsVisible( sal_Int32 nEntry ) const { return maLBWindow->IsVisible( nEntry ); }
455 tools::Long GetLeftIndent() const { return maLBWindow->GetLeftIndent(); }
456 void SetLeftIndent( sal_uInt16 n ) { maLBWindow->SetLeftIndent( n ); }
458 void SetTravelSelect( bool bTravelSelect ) { maLBWindow->SetTravelSelect( bTravelSelect ); }
459 bool IsTravelSelect() const { return maLBWindow->IsTravelSelect(); }
460 bool IsTrackingSelect() const { return maLBWindow->IsTrackingSelect(); }
462 void EnableMultiSelection( bool bMulti ) { maLBWindow->EnableMultiSelection( bMulti ); }
463 bool IsMultiSelectionEnabled() const { return maLBWindow->IsMultiSelectionEnabled(); }
465 void SetMultiSelectionSimpleMode( bool bSimple ) { maLBWindow->SetMultiSelectionSimpleMode( bSimple ); }
467 void SetReadOnly( bool b ) { maLBWindow->SetReadOnly( b ); }
468 bool IsReadOnly() const { return maLBWindow->IsReadOnly(); }
470 Size CalcSize( sal_Int32 nMaxLines ) const { return maLBWindow->CalcSize( nMaxLines ); }
471 tools::Long GetEntryHeight() const { return maLBWindow->GetEntryHeight(); }
472 tools::Long GetEntryHeightWithMargin() const{ return maLBWindow->GetEntryHeightWithMargin(); }
473 tools::Long GetMaxEntryWidth() const { return maLBWindow->GetMaxEntryWidth(); }
475 void SetScrollHdl( const Link<ImplListBox*,void>& rLink ) { maScrollHdl = rLink; }
476 void SetSelectHdl( const Link<LinkParamNone*,void>& rLink ) { maLBWindow->SetSelectHdl( rLink ); }
477 void SetCancelHdl( const Link<LinkParamNone*,void>& rLink ) { maLBWindow->SetCancelHdl( rLink ); }
478 void SetDoubleClickHdl( const Link<ImplListBoxWindow*,void>& rLink ) { maLBWindow->SetDoubleClickHdl( rLink ); }
479 void SetUserDrawHdl( const Link<UserDrawEvent*, void>& rLink ) { maLBWindow->SetUserDrawHdl( rLink ); }
480 void SetFocusHdl( const Link<sal_Int32,void>& rLink ) { maLBWindow->SetFocusHdl( rLink ); }
481 void SetListItemSelectHdl( const Link<LinkParamNone*,void>& rLink ) { maLBWindow->SetListItemSelectHdl( rLink ); }
482 void SetSelectionChangedHdl( const Link<sal_Int32,void>& rLnk ) { maLBWindow->GetEntryList().SetSelectionChangedHdl( rLnk ); }
483 void SetCallSelectionChangedHdl( bool bCall ) { maLBWindow->GetEntryList().SetCallSelectionChangedHdl( bCall ); }
484 bool IsSelectionChanged() const { return maLBWindow->IsSelectionChanged(); }
485 sal_uInt16 GetSelectModifier() const { return maLBWindow->GetSelectModifier(); }
486 void SetHighlightColor(const Color& rColor);
487 void SetHighlightTextColor(const Color& rColor);
489 void SetMRUEntries( std::u16string_view rEntries, sal_Unicode cSep );
490 OUString GetMRUEntries( sal_Unicode cSep ) const;
491 void SetMaxMRUCount( sal_Int32 n ) { maLBWindow->GetEntryList().SetMaxMRUCount( n ); }
492 sal_Int32 GetMaxMRUCount() const { return maLBWindow->GetEntryList().GetMaxMRUCount(); }
493 sal_uInt16 GetDisplayLineCount() const
494 { return maLBWindow->GetDisplayLineCount(); }
496 bool GetEdgeBlending() const { return mbEdgeBlending; }
497 void SetEdgeBlending(bool bNew);
500 class ImplListBoxFloatingWindow final : public FloatingWindow
502 private:
503 VclPtr<ImplListBox> mpImplLB;
504 Size maPrefSz;
505 sal_uInt16 mnDDLineCount;
506 sal_Int32 mnPopupModeStartSaveSelection;
507 bool mbAutoWidth;
509 virtual bool PreNotify( NotifyEvent& rNEvt ) override;
511 public:
512 ImplListBoxFloatingWindow( vcl::Window* pParent );
513 virtual ~ImplListBoxFloatingWindow() override;
514 virtual void dispose() override;
515 void SetImplListBox( ImplListBox* pLB ) { mpImplLB = pLB; }
517 void SetPrefSize( const Size& rSz ) { maPrefSz = rSz; }
518 const Size& GetPrefSize() const { return maPrefSz; }
520 void SetAutoWidth( bool b ) { mbAutoWidth = b; }
522 Size CalcFloatSize() const;
523 void StartFloat( bool bStartTracking );
525 virtual void setPosSizePixel( tools::Long nX, tools::Long nY,
526 tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags = PosSizeFlags::All ) override;
528 void SetDropDownLineCount( sal_uInt16 n ) { mnDDLineCount = n; }
529 sal_uInt16 GetDropDownLineCount() const { return mnDDLineCount; }
531 sal_Int32 GetPopupModeStartSaveSelection() const { return mnPopupModeStartSaveSelection; }
533 virtual void Resize() override;
536 class ImplWin final : public Control
538 private:
540 sal_Int32 mnItemPos; ///< because of UserDraw I have to know which item I draw
541 OUString maString;
542 Image maImage;
544 tools::Rectangle maFocusRect;
546 Link<void*,void> maMBDownHdl;
548 bool mbEdgeBlending : 1;
550 void ImplDraw(vcl::RenderContext& rRenderContext, bool bLayout = false);
551 virtual void FillLayoutData() const override;
553 public:
554 ImplWin( vcl::Window* pParent, WinBits nWinStyle );
556 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
557 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
558 virtual void Resize() override;
559 virtual void GetFocus() override;
560 virtual void LoseFocus() override;
562 sal_Int32 GetItemPos() const { return mnItemPos; }
563 void SetItemPos( sal_Int32 n ) { mnItemPos = n; }
565 void SetString( const OUString& rStr ) { maString = rStr; }
567 void SetImage( const Image& rImg ) { maImage = rImg; }
569 void SetMBDownHdl( const Link<void*,void>& rLink ) { maMBDownHdl = rLink; }
571 void DrawEntry(vcl::RenderContext& rRenderContext, bool bLayout);
573 bool GetEdgeBlending() const { return mbEdgeBlending; }
574 void SetEdgeBlending(bool bNew) { mbEdgeBlending = bNew; }
576 virtual void ShowFocus(const tools::Rectangle& rRect) override;
578 using Control::ImplInitSettings;
579 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
583 class ImplBtn final : public PushButton
585 private:
586 Link<void*,void> maMBDownHdl;
588 public:
589 ImplBtn( vcl::Window* pParent, WinBits nWinStyle );
591 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
592 void SetMBDownHdl( const Link<void*,void>& rLink ) { maMBDownHdl = rLink; }
595 void ImplInitDropDownButton( PushButton* pButton );
597 #endif // INCLUDED_VCL_INC_LISTBOX_HXX
599 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */