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 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  long CalcWindowSizePixel( sal_uInt16 nLines ) const;
103 
104  void SetUserItemSize( const Size& rSz );
105  void EnableUserDraw( bool bUserDraw );
106 
107  void DrawEntry( const UserDrawEvent& rEvt, bool bDrawImage, bool bDrawText, bool bDrawTextAtImagePos = false );
108  void SetBorderStyle( WindowBorderStyle nBorderStyle );
109 
110  void SetSeparatorPos( sal_Int32 n );
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  const Link<ComboBox&,void>& GetSelectHdl() const;
124  void SetDoubleClickHdl(const Link<ComboBox&,void>& rLink);
125  const Link<ComboBox&,void>& GetDoubleClickHdl() const;
126  void SetEntryActivateHdl(const Link<Edit&,bool>& rLink);
127 
128  Size CalcMinimumSize() const override;
129  virtual Size GetOptimalSize() const override;
130  Size CalcAdjustedSize( const Size& rPrefSize ) const;
131  Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
132  void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
133 
134  void SetMRUEntries( const OUString& rEntries );
135  OUString GetMRUEntries() const;
136  void SetMaxMRUCount( sal_Int32 n );
137  sal_Int32 GetMaxMRUCount() const;
138  void SetEntryData( sal_Int32 nPos, void* pNewData );
139  void* GetEntryData( sal_Int32 nPos ) const;
140 
141  sal_Int32 GetTopEntry() const;
142 
143  void SetProminentEntryType( ProminentEntry eType );
144 
145  sal_uInt16 GetDisplayLineCount() const;
146 
147  sal_Int32 GetSelectedEntryCount() const;
148  sal_Int32 GetSelectedEntryPos( sal_Int32 nSelIndex = 0 ) const;
149  OUString GetSelectedEntry() const { return GetEntry( GetSelectedEntryPos() ); }
150  bool IsEntryPosSelected( sal_Int32 nPos ) const;
151  void SelectEntryPos( sal_Int32 nPos, bool bSelect = true );
152  void SetNoSelection();
153  tools::Rectangle GetBoundingRectangle( sal_Int32 nItem ) const;
154 
174  long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const;
175 
176  void setMaxWidthChars(sal_Int32 nWidth);
177 
178  void SetWidthInChars(sal_Int32 nWidthInChars);
179 
180  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
181 
182  virtual FactoryFunction GetUITestFactory() const override;
183 };
184 
185 #endif // _COMBOBOX_HXX
186 
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Size CalcMinimumSize() const
Definition: edit.cxx:2669
virtual const Wallpaper & GetDisplayBackground() const
Definition: window.cxx:3071
virtual FactoryFunction GetUITestFactory() const override
Definition: edit.cxx:2927
#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:213
PosSizeFlags
Definition: window.hxx:141
virtual bool set_property(const OString &rKey, const OUString &rValue) override
Definition: edit.cxx:176
StateChangedType
Definition: window.hxx:311
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2685
sal_Int64 WinBits
virtual void FillLayoutData() const override
Definition: edit.cxx:1703
std::unique_ptr< Impl > m_pImpl
Definition: combobox.hxx:37
void SetBorderStyle(WindowBorderStyle nBorderStyle)
Definition: window.cxx:1957
OUString GetSelectedEntry() const
Definition: combobox.hxx:149
Definition: edit.hxx:57
virtual Size GetOptimalSize() const override
Definition: edit.cxx:2682
DrawFlags
Definition: window.hxx:354
virtual void StateChanged(StateChangedType nType) override
Definition: edit.cxx:2145
static SAL_DLLPRIVATE WinBits ImplInitStyle(WinBits nStyle)
Definition: edit.cxx:336
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:2305
virtual void Resize() override
Definition: edit.cxx:1715
ProminentEntry
long GetIndexForPoint(const Point &rPoint) const
Definition: ctrl.cxx:134
void SetWidthInChars(sal_Int32 nWidthInChars)
Definition: edit.cxx:158
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: edit.cxx:2226
void setMaxWidthChars(sal_Int32 nWidth)
Definition: edit.cxx:167
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:205
WindowBorderStyle
Definition: vclenum.hxx:108
virtual void SetText(const OUString &rStr) override
Definition: edit.cxx:2545
virtual void Draw(OutputDevice *pDev, const Point &rPos, const Size &rSize, DrawFlags nFlags) override
Definition: edit.cxx:1728
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: edit.cxx:297
#define COMBOBOX_APPEND
Definition: combobox.hxx:27
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: ctrl.cxx:225