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 
34 class ImplListBoxWindow;
35 class UserDrawEvent;
36 
38 class VCL_DLLPUBLIC ComboBox : public Edit
39 {
40 private:
41  struct SAL_DLLPRIVATE Impl;
42  std::unique_ptr<Impl> m_pImpl;
43 
44 protected:
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 
51 protected:
52  bool IsDropDownBox() const;
53 
54  virtual void FillLayoutData() const override;
55 
56 public:
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 
113  void AddSeparator( sal_Int32 n );
114 
115  void EnableAutocomplete( bool bEnable, bool bMatchCase = false );
116  bool IsAutocompleteEnabled() const;
117 
118  bool IsMultiSelectionEnabled() const;
119 
120  void SetSelectHdl(const Link<ComboBox&,void>& rLink);
121  void SetEntryActivateHdl(const Link<Edit&,bool>& rLink);
122  void SetUserDrawHdl(const Link<UserDrawEvent*, void>& rLink);
123 
124  Size CalcMinimumSize() const override;
125  virtual Size GetOptimalSize() const override;
126  Size CalcAdjustedSize( const Size& rPrefSize ) const;
127  Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
128  void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
129 
130  void SetMRUEntries( const OUString& rEntries );
131  OUString GetMRUEntries() const;
132  void SetMaxMRUCount( sal_Int32 n );
133  sal_Int32 GetMaxMRUCount() const;
134  void SetEntryData( sal_Int32 nPos, void* pNewData );
135  void* GetEntryData( sal_Int32 nPos ) const;
136 
137  sal_Int32 GetTopEntry() const;
138 
139  sal_uInt16 GetDisplayLineCount() const;
140 
141  sal_Int32 GetSelectedEntryCount() const;
142  sal_Int32 GetSelectedEntryPos( sal_Int32 nSelIndex = 0 ) const;
143  bool IsEntryPosSelected( sal_Int32 nPos ) const;
144  void SelectEntryPos( sal_Int32 nPos, bool bSelect = true );
145  void SetNoSelection();
146  tools::Rectangle GetBoundingRectangle( sal_Int32 nItem ) const;
147 
148  // determine if Select was called due to typing or cursoring in the
149  // combobox, as opposed to something selected from the menu or via some
150  // other route. e.g. the toolbar fontsize combobox wants to immediately
151  // change size only if something is picked from the combobox menu, other
152  // changes don't auto-apply until the user presses return
153  bool IsModifyByKeyboard() const;
154 
155  // determine if Edit::Modify was called due to the ComboBox changing the edit area
156  // itself
157  bool IsSyntheticModify() const;
158 
159 
179  tools::Long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const;
180 
181  void setMaxWidthChars(sal_Int32 nWidth);
182 
183  void SetWidthInChars(sal_Int32 nWidthInChars);
184 
185  tools::Long GetDropDownEntryHeight() const;
186 
187  // the drop down window container
188  ImplListBoxWindow* GetMainWindow() const;
189 
190  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
191 
192  virtual FactoryFunction GetUITestFactory() const override;
193 
194  virtual void DumpAsPropertyTree(tools::JsonWriter&) override;
195 };
196 
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Size CalcMinimumSize() const
Definition: edit.cxx:2657
virtual const Wallpaper & GetDisplayBackground() const
Definition: window.cxx:3057
virtual FactoryFunction GetUITestFactory() const override
Definition: edit.cxx:2912
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
long Long
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: edit.cxx:223
PosSizeFlags
Definition: window.hxx:125
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:2918
virtual bool set_property(const OString &rKey, const OUString &rValue) override
Definition: edit.cxx:181
StateChangedType
Definition: window.hxx:289
sal_Int64 WinBits
virtual void FillLayoutData() const override
Definition: edit.cxx:1716
std::unique_ptr< Impl > m_pImpl
Definition: combobox.hxx:42
SystemTextColorFlags
void SetBorderStyle(WindowBorderStyle nBorderStyle)
Definition: window.cxx:1984
Definition: edit.hxx:55
virtual Size GetOptimalSize() const override
Definition: edit.cxx:2662
virtual void StateChanged(StateChangedType nType) override
Definition: edit.cxx:2154
static SAL_DLLPRIVATE WinBits ImplInitStyle(WinBits nStyle)
Definition: edit.cxx:343
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:167
virtual void Modify()
Definition: edit.cxx:2314
virtual void Resize() override
Definition: edit.cxx:1728
void Clear(EHistoryType eHistory)
virtual void setPosSizePixel(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2656
void SetWidthInChars(sal_Int32 nWidthInChars)
Definition: edit.cxx:163
tools::Long GetIndexForPoint(const Point &rPoint) const
Definition: ctrl.cxx:133
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: edit.cxx:2235
void setMaxWidthChars(sal_Int32 nWidth)
Definition: edit.cxx:172
Definition: image.hxx:39
A widget used to choose from a list of items and which has an entry.
Definition: combobox.hxx:38
Event to pass information for UserDraw() handling eg. in comboboxes.
Definition: event.hxx:221
WindowBorderStyle
Definition: vclenum.hxx:106
virtual void SetText(const OUString &rStr) override
Definition: edit.cxx:2545
virtual void Draw(OutputDevice *pDev, const Point &rPos, SystemTextColorFlags nFlags) override
Definition: edit.cxx:1741
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: edit.cxx:304
#define COMBOBOX_APPEND
Definition: combobox.hxx:30
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: ctrl.cxx:224