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 #include <memory>
24 #include <vcl/dllapi.h>
25 #include <vcl/edit.hxx>
26 
27 #define COMBOBOX_APPEND (SAL_MAX_INT32)
28 #define COMBOBOX_ENTRY_NOTFOUND (SAL_MAX_INT32)
29 #define COMBOBOX_MAX_ENTRIES (SAL_MAX_INT32 - 1)
30 
31 class UserDrawEvent;
32 
34 class VCL_DLLPUBLIC ComboBox : public Edit
35 {
36 private:
37  struct SAL_DLLPRIVATE Impl;
38  std::unique_ptr<Impl> m_pImpl;
39 
40 protected:
41  using Window::ImplInit;
42  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
43  SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle );
44  SAL_DLLPRIVATE void ImplCalcEditHeight();
45  SAL_DLLPRIVATE long getMaxWidthScrollBarAndDownButton() const;
46 
47 protected:
48  bool IsDropDownBox() const;
49 
50  virtual void FillLayoutData() const override;
51 
52 public:
53  explicit ComboBox( vcl::Window* pParent, WinBits nStyle = 0 );
54  virtual ~ComboBox() override;
55  virtual void dispose() override;
56 
57  virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags ) override;
58  virtual void Resize() override;
59  virtual bool EventNotify( NotifyEvent& rNEvt ) override;
60  virtual void StateChanged( StateChangedType nType ) override;
61  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
62 
63  virtual void UserDraw( const UserDrawEvent& rUDEvt );
64  virtual void Select();
65  void DoubleClick();
66 
67  virtual void Modify() override;
68 
69  virtual const Wallpaper& GetDisplayBackground() const override;
70 
71  virtual void setPosSizePixel( long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags = PosSizeFlags::All ) override;
72 
73  tools::Rectangle GetDropDownPosSizePixel() const;
74 
75  void AdaptDropDownLineCountToMaximum();
76  void SetDropDownLineCount( sal_uInt16 nLines );
77  sal_uInt16 GetDropDownLineCount() const;
78 
79  void EnableAutoSize( bool bAuto );
80  bool IsAutoSizeEnabled() const;
81 
82  virtual void SetText( const OUString& rStr ) override;
83  virtual void SetText( const OUString& rStr, const Selection& rNewSelection ) override;
84 
85  sal_Int32 InsertEntry(const OUString& rStr, sal_Int32 nPos = COMBOBOX_APPEND);
86  sal_Int32 InsertEntryWithImage( const OUString& rStr, const Image& rImage, sal_Int32 nPos = COMBOBOX_APPEND );
87 
88  void RemoveEntry( const OUString& rStr );
89  void RemoveEntryAt(sal_Int32 nPos);
90 
91  void Clear();
92  void EnableSelectAll();
93  sal_Int32 GetEntryPos( const OUString& rStr ) const;
94  Image GetEntryImage( sal_Int32 nPos ) const;
95  OUString GetEntry( sal_Int32 nPos ) const;
96  sal_Int32 GetEntryCount() const;
97 
98  bool IsTravelSelect() const;
99  bool IsInDropDown() const;
100  void ToggleDropDown();
101 
102  void SetUserItemSize( const Size& rSz );
103  void EnableUserDraw( bool bUserDraw );
104 
105  void DrawEntry( const UserDrawEvent& rEvt, bool bDrawImage, bool bDrawText, bool bDrawTextAtImagePos = false );
106  void SetBorderStyle( WindowBorderStyle nBorderStyle );
107 
108  void SetSeparatorPos( sal_Int32 n );
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 SetDoubleClickHdl(const Link<ComboBox&,void>& rLink);
122  const Link<ComboBox&,void>& GetDoubleClickHdl() const;
123  void SetEntryActivateHdl(const Link<Edit&,bool>& rLink);
124 
125  Size CalcMinimumSize() const override;
126  virtual Size GetOptimalSize() const override;
127  Size CalcAdjustedSize( const Size& rPrefSize ) const;
128  Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
129  void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
130 
131  void SetMRUEntries( const OUString& rEntries );
132  OUString GetMRUEntries() const;
133  void SetMaxMRUCount( sal_Int32 n );
134  sal_Int32 GetMaxMRUCount() const;
135  void SetEntryData( sal_Int32 nPos, void* pNewData );
136  void* GetEntryData( sal_Int32 nPos ) const;
137 
138  sal_Int32 GetTopEntry() const;
139 
140  sal_uInt16 GetDisplayLineCount() const;
141 
142  sal_Int32 GetSelectedEntryCount() const;
143  sal_Int32 GetSelectedEntryPos( sal_Int32 nSelIndex = 0 ) const;
144  OUString GetSelectedEntry() const { return GetEntry( GetSelectedEntryPos() ); }
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  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  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
188 
189  virtual FactoryFunction GetUITestFactory() const override;
190 };
191 
192 #endif // _COMBOBOX_HXX
193 
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Size CalcMinimumSize() const
Definition: edit.cxx:2673
virtual const Wallpaper & GetDisplayBackground() const
Definition: window.cxx:3122
virtual FactoryFunction GetUITestFactory() const override
Definition: edit.cxx:2929
#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:215
PosSizeFlags
Definition: window.hxx:141
virtual bool set_property(const OString &rKey, const OUString &rValue) override
Definition: edit.cxx:178
StateChangedType
Definition: window.hxx:311
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2732
sal_Int64 WinBits
virtual void FillLayoutData() const override
Definition: edit.cxx:1708
std::unique_ptr< Impl > m_pImpl
Definition: combobox.hxx:38
void SetBorderStyle(WindowBorderStyle nBorderStyle)
Definition: window.cxx:2008
OUString GetSelectedEntry() const
Definition: combobox.hxx:144
Definition: edit.hxx:55
virtual Size GetOptimalSize() const override
Definition: edit.cxx:2686
DrawFlags
Definition: window.hxx:354
virtual void StateChanged(StateChangedType nType) override
Definition: edit.cxx:2149
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:304
virtual void Modify()
Definition: edit.cxx:2309
virtual void Resize() override
Definition: edit.cxx:1720
long GetIndexForPoint(const Point &rPoint) const
Definition: ctrl.cxx:134
void SetWidthInChars(sal_Int32 nWidthInChars)
Definition: edit.cxx:160
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: edit.cxx:2230
void setMaxWidthChars(sal_Int32 nWidth)
Definition: edit.cxx:169
Definition: image.hxx:40
A widget used to choose from a list of items and which has an entry.
Definition: combobox.hxx:34
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:2549
virtual void Draw(OutputDevice *pDev, const Point &rPos, const Size &rSize, DrawFlags nFlags) override
Definition: edit.cxx:1733
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: edit.cxx:299
#define COMBOBOX_APPEND
Definition: combobox.hxx:27
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: ctrl.cxx:225