1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23 #error "don't use this in new code"
27 #include <vcl/dllapi.h>
28 #include <vcl/toolkit/edit.hxx>
30 #define COMBOBOX_APPEND (SAL_MAX_INT32)
31 #define COMBOBOX_ENTRY_NOTFOUND (SAL_MAX_INT32)
32 #define COMBOBOX_MAX_ENTRIES (SAL_MAX_INT32 - 1)
34 class ImplListBoxWindow
;
37 /// A widget used to choose from a list of items and which has an entry.
38 class VCL_DLLPUBLIC ComboBox
: public Edit
41 struct SAL_DLLPRIVATE Impl
;
42 std::unique_ptr
<Impl
> m_pImpl
;
45 using Window::ImplInit
;
46 SAL_DLLPRIVATE
void ImplInit( vcl::Window
* pParent
, WinBits nStyle
);
47 SAL_DLLPRIVATE
static WinBits
ImplInitStyle( WinBits nStyle
);
48 SAL_DLLPRIVATE
void ImplCalcEditHeight();
49 SAL_DLLPRIVATE
tools::Long
getMaxWidthScrollBarAndDownButton() const;
52 bool IsDropDownBox() const;
54 virtual void FillLayoutData() const override
;
57 explicit ComboBox( vcl::Window
* pParent
, WinBits nStyle
= 0 );
58 virtual ~ComboBox() override
;
59 virtual void dispose() override
;
61 virtual void Draw( OutputDevice
* pDev
, const Point
& rPos
,SystemTextColorFlags nFlags
) override
;
62 virtual void Resize() override
;
63 virtual bool EventNotify( NotifyEvent
& rNEvt
) override
;
64 virtual void StateChanged( StateChangedType nType
) override
;
65 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
70 virtual void Modify() override
;
72 virtual const Wallpaper
& GetDisplayBackground() const override
;
74 virtual void setPosSizePixel( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, PosSizeFlags nFlags
= PosSizeFlags::All
) override
;
76 tools::Rectangle
GetDropDownPosSizePixel() const;
78 void AdaptDropDownLineCountToMaximum();
79 void SetDropDownLineCount( sal_uInt16 nLines
);
80 sal_uInt16
GetDropDownLineCount() const;
82 void EnableAutoSize( bool bAuto
);
83 bool IsAutoSizeEnabled() const;
85 virtual void SetText( const OUString
& rStr
) override
;
86 virtual void SetText( const OUString
& rStr
, const Selection
& rNewSelection
) override
;
88 sal_Int32
InsertEntry(const OUString
& rStr
, sal_Int32 nPos
= COMBOBOX_APPEND
);
89 sal_Int32
InsertEntryWithImage( const OUString
& rStr
, const Image
& rImage
, sal_Int32 nPos
= COMBOBOX_APPEND
);
91 void RemoveEntryAt(sal_Int32 nPos
);
94 sal_Int32
GetEntryPos( std::u16string_view rStr
) const;
95 Image
GetEntryImage( sal_Int32 nPos
) const;
96 OUString
GetEntry( sal_Int32 nPos
) const;
97 sal_Int32
GetEntryCount() const;
99 bool IsTravelSelect() const;
100 bool IsInDropDown() const;
101 void ToggleDropDown();
103 void SetUserItemSize( const Size
& rSz
);
104 void EnableUserDraw( bool bUserDraw
);
105 bool IsUserDrawEnabled() const;
107 void DrawEntry( const UserDrawEvent
& rEvt
);
108 void SetBorderStyle( WindowBorderStyle nBorderStyle
);
109 void SetHighlightColor(const Color
& rColor
);
110 void SetHighlightTextColor(const Color
& rColor
);
113 * Adds a new separator at the given position n.
115 void AddSeparator( sal_Int32 n
);
117 void EnableAutocomplete( bool bEnable
, bool bMatchCase
= false );
118 bool IsAutocompleteEnabled() const;
120 bool IsMultiSelectionEnabled() const;
122 void SetSelectHdl(const Link
<ComboBox
&,void>& rLink
);
123 void SetEntryActivateHdl(const Link
<Edit
&,bool>& rLink
);
124 void SetUserDrawHdl(const Link
<UserDrawEvent
*, void>& rLink
);
126 Size
CalcMinimumSize() const override
;
127 virtual Size
GetOptimalSize() const override
;
128 Size
CalcAdjustedSize( const Size
& rPrefSize
) const;
129 Size
CalcBlockSize( sal_uInt16 nColumns
, sal_uInt16 nLines
) const;
130 void GetMaxVisColumnsAndLines( sal_uInt16
& rnCols
, sal_uInt16
& rnLines
) const;
132 void SetMRUEntries( std::u16string_view rEntries
);
133 OUString
GetMRUEntries() const;
134 void SetMaxMRUCount( sal_Int32 n
);
135 sal_Int32
GetMaxMRUCount() const;
136 void SetEntryData( sal_Int32 nPos
, void* pNewData
);
137 void* GetEntryData( sal_Int32 nPos
) const;
139 sal_Int32
GetTopEntry() const;
141 sal_uInt16
GetDisplayLineCount() const;
143 sal_Int32
GetSelectedEntryCount() const;
144 sal_Int32
GetSelectedEntryPos( sal_Int32 nSelIndex
= 0 ) const;
145 bool IsEntryPosSelected( sal_Int32 nPos
) const;
146 void SelectEntryPos( sal_Int32 nPos
, bool bSelect
= true );
147 void SetNoSelection();
148 tools::Rectangle
GetBoundingRectangle( sal_Int32 nItem
) const;
150 // determine if Select was called due to typing or cursoring in the
151 // combobox, as opposed to something selected from the menu or via some
152 // other route. e.g. the toolbar fontsize combobox wants to immediately
153 // change size only if something is picked from the combobox menu, other
154 // changes don't auto-apply until the user presses return
155 bool IsModifyByKeyboard() const;
157 // determine if Edit::Modify was called due to the ComboBox changing the edit area
159 bool IsSyntheticModify() const;
162 /** checks whether a certain point lies within the bounds of
163 a list item and returns the item as well as the character position
166 <p>If the point is inside an item the item pos is put into <code>rPos</code> and
167 the item-relative character index is returned. If the point is not inside
168 an item -1 is returned and rPos is unchanged.</p>
171 tells the point for which an item is requested.
174 gets the item at the specified point <code>rPoint</code>
177 the item-relative character index at point <code>rPos</code> or -1
178 if no item is at that point.
180 using Control::GetIndexForPoint
;
181 tools::Long
GetIndexForPoint( const Point
& rPoint
, sal_Int32
& rPos
) const;
183 void setMaxWidthChars(sal_Int32 nWidth
);
185 void SetWidthInChars(sal_Int32 nWidthInChars
);
187 tools::Long
GetDropDownEntryHeight() const;
189 // the drop down window container
190 ImplListBoxWindow
* GetMainWindow() const;
192 virtual bool set_property(const OUString
&rKey
, const OUString
&rValue
) override
;
194 virtual FactoryFunction
GetUITestFactory() const override
;
196 virtual void DumpAsPropertyTree(tools::JsonWriter
&) override
;
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */