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 #ifndef INCLUDED_VCL_COMBOBOX_HXX
21 #define INCLUDED_VCL_COMBOBOX_HXX
22 
23 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
24 #error "don't use this in new code"
25 #endif
26 
27 #include <memory>
28 #include <vcl/dllapi.h>
29 #include <vcl/edit.hxx>
30 
31 #define COMBOBOX_APPEND (SAL_MAX_INT32)
32 #define COMBOBOX_ENTRY_NOTFOUND (SAL_MAX_INT32)
33 #define COMBOBOX_MAX_ENTRIES (SAL_MAX_INT32 - 1)
34 
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 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, DrawFlags 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( long nX, long nY, long nWidth, 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( const OUString& 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 
106  void DrawEntry( const UserDrawEvent& rEvt );
107  void SetBorderStyle( WindowBorderStyle nBorderStyle );
108 
112  void AddSeparator( sal_Int32 n );
113 
114  void EnableAutocomplete( bool bEnable, bool bMatchCase = false );
115  bool IsAutocompleteEnabled() const;
116 
117  bool IsMultiSelectionEnabled() const;
118 
119  void SetSelectHdl(const Link<ComboBox&,void>& rLink);
120  void SetEntryActivateHdl(const Link<Edit&,bool>& rLink);
121  void SetUserDrawHdl(const Link<UserDrawEvent*, void>& rLink);
122 
123  Size CalcMinimumSize() const override;
124  virtual Size GetOptimalSize() const override;
125  Size CalcAdjustedSize( const Size& rPrefSize ) const;
126  Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
127  void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
128 
129  void SetMRUEntries( const OUString& rEntries );
130  OUString GetMRUEntries() const;
131  void SetMaxMRUCount( sal_Int32 n );
132  sal_Int32 GetMaxMRUCount() const;
133  void SetEntryData( sal_Int32 nPos, void* pNewData );
134  void* GetEntryData( sal_Int32 nPos ) const;
135 
136  sal_Int32 GetTopEntry() const;
137 
138  sal_uInt16 GetDisplayLineCount() const;
139 
140  sal_Int32 GetSelectedEntryCount() const;
141  sal_Int32 GetSelectedEntryPos( sal_Int32 nSelIndex = 0 ) const;
142  bool IsEntryPosSelected( sal_Int32 nPos ) const;
143  void SelectEntryPos( sal_Int32 nPos, bool bSelect = true );
144  void SetNoSelection();
145  tools::Rectangle GetBoundingRectangle( sal_Int32 nItem ) const;
146 
147  // determine if Select was called due to typing or cursoring in the
148  // combobox, as opposed to something selected from the menu or via some
149  // other route. e.g. the toolbar fontsize combobox wants to immediately
150  // change size only if something is picked from the combobox menu, other
151  // changes don't auto-apply until the user presses return
152  bool IsModifyByKeyboard() const;
153 
154  // determine if Edit::Modify was called due to the ComboBox changing the edit area
155  // itself
156  bool IsSyntheticModify() const;
157 
158 
178  long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const;
179 
180  void setMaxWidthChars(sal_Int32 nWidth);
181 
182  void SetWidthInChars(sal_Int32 nWidthInChars);
183 
184  long GetDropDownEntryHeight() const;
185 
186  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
187 
188  virtual FactoryFunction GetUITestFactory() const override;
189 };
190 
191 #endif // _COMBOBOX_HXX
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Size CalcMinimumSize() const
Definition: edit.cxx:2667
virtual const Wallpaper & GetDisplayBackground() const
Definition: window.cxx:3097
virtual FactoryFunction GetUITestFactory() const override
Definition: edit.cxx:2923
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
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:216
PosSizeFlags
Definition: window.hxx:140
virtual bool set_property(const OString &rKey, const OUString &rValue) override
Definition: edit.cxx:179
StateChangedType
Definition: window.hxx:310
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2713
sal_Int64 WinBits
virtual void FillLayoutData() const override
Definition: edit.cxx:1710
std::unique_ptr< Impl > m_pImpl
Definition: combobox.hxx:42
virtual void Draw(OutputDevice *pDev, const Point &rPos, DrawFlags nFlags) override
Definition: edit.cxx:1735
void SetBorderStyle(WindowBorderStyle nBorderStyle)
Definition: window.cxx:1989
Definition: edit.hxx:56
virtual Size GetOptimalSize() const override
Definition: edit.cxx:2680
DrawFlags
Definition: window.hxx:353
virtual void StateChanged(StateChangedType nType) override
Definition: edit.cxx:2152
static SAL_DLLPRIVATE WinBits ImplInitStyle(WinBits nStyle)
Definition: edit.cxx:338
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
virtual void Modify()
Definition: edit.cxx:2312
virtual void Resize() override
Definition: edit.cxx:1722
long GetIndexForPoint(const Point &rPoint) const
Definition: ctrl.cxx:134
void SetWidthInChars(sal_Int32 nWidthInChars)
Definition: edit.cxx:161
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: edit.cxx:2233
void setMaxWidthChars(sal_Int32 nWidth)
Definition: edit.cxx:170
Definition: image.hxx:40
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:218
WindowBorderStyle
Definition: vclenum.hxx:108
virtual void SetText(const OUString &rStr) override
Definition: edit.cxx:2543
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: edit.cxx:299
#define COMBOBOX_APPEND
Definition: combobox.hxx:31
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: ctrl.cxx:225