LibreOffice Module vcl (master) 1
combobox.hxx
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#pragma once
21
22#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23#error "don't use this in new code"
24#endif
25
26#include <memory>
27#include <vcl/dllapi.h>
28#include <vcl/toolkit/edit.hxx>
29
30#define COMBOBOX_APPEND (SAL_MAX_INT32)
31#define COMBOBOX_ENTRY_NOTFOUND (SAL_MAX_INT32)
32#define COMBOBOX_MAX_ENTRIES (SAL_MAX_INT32 - 1)
33
35class UserDrawEvent;
36
39{
40private:
41 struct SAL_DLLPRIVATE Impl;
42 std::unique_ptr<Impl> m_pImpl;
43
44protected:
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;
50
51protected:
52 bool IsDropDownBox() const;
53
54 virtual void FillLayoutData() const override;
55
56public:
57 explicit ComboBox( vcl::Window* pParent, WinBits nStyle = 0 );
58 virtual ~ComboBox() override;
59 virtual void dispose() override;
60
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;
66
67 void Select();
68 void DoubleClick();
69
70 virtual void Modify() override;
71
72 virtual const Wallpaper& GetDisplayBackground() const override;
73
74 virtual void setPosSizePixel( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags = PosSizeFlags::All ) override;
75
76 tools::Rectangle GetDropDownPosSizePixel() const;
77
78 void AdaptDropDownLineCountToMaximum();
79 void SetDropDownLineCount( sal_uInt16 nLines );
80 sal_uInt16 GetDropDownLineCount() const;
81
82 void EnableAutoSize( bool bAuto );
83 bool IsAutoSizeEnabled() const;
84
85 virtual void SetText( const OUString& rStr ) override;
86 virtual void SetText( const OUString& rStr, const Selection& rNewSelection ) override;
87
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 );
90
91 void RemoveEntryAt(sal_Int32 nPos);
92
93 void Clear();
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;
98
99 bool IsTravelSelect() const;
100 bool IsInDropDown() const;
101 void ToggleDropDown();
102
103 void SetUserItemSize( const Size& rSz );
104 void EnableUserDraw( bool bUserDraw );
105 bool IsUserDrawEnabled() const;
106
107 void DrawEntry( const UserDrawEvent& rEvt );
108 void SetBorderStyle( WindowBorderStyle nBorderStyle );
109 void SetHighlightColor(const Color& rColor);
110 void SetHighlightTextColor(const Color& rColor);
111
115 void AddSeparator( sal_Int32 n );
116
117 void EnableAutocomplete( bool bEnable, bool bMatchCase = false );
118 bool IsAutocompleteEnabled() const;
119
120 bool IsMultiSelectionEnabled() const;
121
122 void SetSelectHdl(const Link<ComboBox&,void>& rLink);
123 void SetEntryActivateHdl(const Link<Edit&,bool>& rLink);
124 void SetUserDrawHdl(const Link<UserDrawEvent*, void>& rLink);
125
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;
131
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;
138
139 sal_Int32 GetTopEntry() const;
140
141 sal_uInt16 GetDisplayLineCount() const;
142
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;
149
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;
156
157 // determine if Edit::Modify was called due to the ComboBox changing the edit area
158 // itself
159 bool IsSyntheticModify() const;
160
161
181 tools::Long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const;
182
183 void setMaxWidthChars(sal_Int32 nWidth);
184
185 void SetWidthInChars(sal_Int32 nWidthInChars);
186
187 tools::Long GetDropDownEntryHeight() const;
188
189 // the drop down window container
190 ImplListBoxWindow* GetMainWindow() const;
191
192 virtual bool set_property(const OUString &rKey, const OUString &rValue) override;
193
194 virtual FactoryFunction GetUITestFactory() const override;
195
196 virtual void DumpAsPropertyTree(tools::JsonWriter&) override;
197};
198
199/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SystemTextColorFlags
A widget used to choose from a list of items and which has an entry.
Definition: combobox.hxx:39
std::unique_ptr< Impl > m_pImpl
Definition: combobox.hxx:42
tools::Long GetIndexForPoint(const Point &rPoint) const
Definition: ctrl.cxx:137
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: ctrl.cxx:225
Definition: edit.hxx:56
virtual void Modify()
Definition: edit.cxx:2320
void SetWidthInChars(sal_Int32 nWidthInChars)
Definition: edit.cxx:165
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: edit.cxx:306
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
Definition: edit.cxx:225
virtual void SetText(const OUString &rStr) override
Definition: edit.cxx:2551
virtual Size GetOptimalSize() const override
Definition: edit.cxx:2668
virtual bool set_property(const OUString &rKey, const OUString &rValue) override
Definition: edit.cxx:183
void setMaxWidthChars(sal_Int32 nWidth)
Definition: edit.cxx:174
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: edit.cxx:2241
static SAL_DLLPRIVATE WinBits ImplInitStyle(WinBits nStyle)
Definition: edit.cxx:345
virtual Size CalcMinimumSize() const
Definition: edit.cxx:2663
virtual void DumpAsPropertyTree(tools::JsonWriter &rJsonWriter) override
Dumps itself and potentially its children to a property tree, to be written easily to JSON.
Definition: edit.cxx:2924
virtual void FillLayoutData() const override
Definition: edit.cxx:1708
virtual FactoryFunction GetUITestFactory() const override
Definition: edit.cxx:2918
virtual void Draw(OutputDevice *pDev, const Point &rPos, SystemTextColorFlags nFlags) override
Definition: edit.cxx:1733
virtual void Resize() override
Definition: edit.cxx:1720
virtual void StateChanged(StateChangedType nType) override
Definition: edit.cxx:2160
Definition: image.hxx:40
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:170
Event to pass information for UserDraw() handling eg. in comboboxes.
Definition: event.hxx:222
virtual const Wallpaper & GetDisplayBackground() const
Definition: window.cxx:3067
virtual void setPosSizePixel(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2666
void SetBorderStyle(WindowBorderStyle nBorderStyle)
Definition: window.cxx:1994
#define COMBOBOX_APPEND
Definition: combobox.hxx:30
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
std::function< std::unique_ptr< UIObject >(vcl::Window *)> FactoryFunction
void Clear(EHistoryType eHistory)
long Long
WindowBorderStyle
Definition: vclenum.hxx:107
PosSizeFlags
Definition: window.hxx:127
StateChangedType
Definition: window.hxx:291
sal_Int64 WinBits
Definition: wintypes.hxx:109