xref: /trunk/main/svtools/inc/svtools/svxbox.hxx (revision 01aa44aa)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SVX_BOX_HXX
24 #define _SVX_BOX_HXX
25 
26 // include ---------------------------------------------------------------
27 
28 #include <svl/svarray.hxx>
29 #include <tools/string.hxx>
30 #include <vcl/lstbox.hxx>
31 #include <vcl/combobox.hxx>
32 #include <svtools/svtdllapi.h>
33 
34 // forward ---------------------------------------------------------------
35 
36 class SvxBoxEntry;
37 class SvxListBase;
38 
39 SV_DECL_PTRARR( SvxEntryLst, SvxBoxEntry*, 10, 10 )
40 
41 // class SvxBoxEntry -----------------------------------------------------
42 
43 class SVT_DLLPUBLIC SvxBoxEntry
44 {
45 	friend class SvxListBox;
46 	friend class SvxComboBox;
47 
48 public:
49 	SvxBoxEntry( const String& aName, sal_uInt16 nId=0 );
50 	SvxBoxEntry( const SvxBoxEntry& rOrg );
51 	SvxBoxEntry();
52 
53 	String 				aName;
54 	sal_uInt16 				nId;
55 
56 private:
57 	sal_Bool   				bModified;
58 	sal_Bool   				bNew;
59 };
60 
61 // class SvxListBox ------------------------------------------------------
62 
63 class SVT_DLLPUBLIC SvxListBox : public ListBox
64 {
65 	using ListBox::InsertEntry;
66 	using ListBox::RemoveEntry;
67 	using ListBox::GetEntryPos;
68 	using ListBox::IsEntrySelected;
69 	using ListBox::SelectEntry;
70 
71 public:
72 	SvxListBox( Window* pParent, WinBits nBits = WB_BORDER );
73 	SvxListBox( Window* pParent, const ResId& rId );
74 	~SvxListBox();
75 
76 	void				InsertNewEntry( const SvxBoxEntry& rEntry );
77 	void				InsertEntry( const SvxBoxEntry& rEntry,
78 									 sal_uInt16 nId = LISTBOX_ENTRY_NOTFOUND );
79 
80 	void				RemoveEntry( sal_uInt16 nPos );
81 	void				RemoveEntry( const SvxBoxEntry& rEntry );
82 
83 	void				Clear();
84 
85 	sal_uInt16 				GetEntryPos( const SvxBoxEntry& rEntry ) const;
86 	const SvxBoxEntry&  GetSvxBoxEntry( sal_uInt16 nIdx ) const;
87 
88 	inline sal_Bool			IsEntrySelected( const SvxBoxEntry& rEntry ) const;
89 	const SvxBoxEntry&  GetSelectSvxBoxEntry( sal_uInt16 nIdx = 0 ) const;
90 	inline void			SelectEntry( const SvxBoxEntry& rEntry,
91 									 sal_Bool bSelect = sal_True );
92 
93 	void				ModifyEntry( sal_uInt16 nPos, const String& aName );
94 	sal_uInt16				GetModifiedCount() const;
95 	const SvxBoxEntry&	GetModifiedEntry( sal_uInt16 nPos ) const;
96 
97 	sal_uInt16				GetRemovedCount() const;
98 	const SvxBoxEntry&	GetRemovedEntry( sal_uInt16 nPos ) const;
99 
100 	sal_uInt16				GetNewCount() const;
101 	const SvxBoxEntry&	GetNewEntry( sal_uInt16 nPos ) const;
102 
103 private:
104 	SvxEntryLst			aEntryLst;
105 	SvxEntryLst			aDelEntryLst;
106 	SvxBoxEntry 		aDefault;
107 
108 	void				InitListBox();
109 	void				InsertSorted( SvxBoxEntry* pEntry );
110 };
111 
112 // inlines ---------------------------------------------------------------
113 
IsEntrySelected(const SvxBoxEntry & aEntry) const114 inline sal_Bool	SvxListBox::IsEntrySelected( const SvxBoxEntry& aEntry ) const
115 	{ return ListBox::IsEntrySelected( aEntry.aName ); }
116 
SelectEntry(const SvxBoxEntry & aEntry,sal_Bool bSelect)117 inline void SvxListBox::SelectEntry( const SvxBoxEntry& aEntry, sal_Bool bSelect )
118 	{ ListBox::SelectEntry( aEntry.aName, bSelect ); }
119 
120 // enum SvxComboBoxStyle -------------------------------------------------
121 
122 enum SvxComboBoxStyle
123 {
124 	SVX_CBS_UPPER 	 	= 0x01,
125 	SVX_CBS_LOWER	 	= 0x02,
126 	SVX_CBS_ALL	  	 	= 0x04,
127 	SVX_CBS_FILENAME 	= 0x08,
128 	SVX_CBS_SW_FILENAME = SVX_CBS_FILENAME
129 };
130 
131 // class SvxComboBox -----------------------------------------------------
132 
133 class SVT_DLLPUBLIC SvxComboBox : public ComboBox
134 {
135 	using ComboBox::InsertEntry;
136 	using ComboBox::RemoveEntry;
137 	using ComboBox::GetEntryPos;
138 	using Window::SetStyle;
139 
140 public:
141 	SvxComboBox( Window* pParent,
142 				 WinBits nBits = WB_BORDER, sal_uInt16 nStyleBits = SVX_CBS_ALL );
143 	SvxComboBox( Window* pParent, const ResId& rId, sal_uInt16 nStyleBits = SVX_CBS_ALL );
144 	~SvxComboBox();
145 
146 	void				InsertNewEntry( const SvxBoxEntry& );
147 	void				InsertEntry( const SvxBoxEntry& );
148 
149 	void				RemoveEntry( sal_uInt16 nPos );
150 	void				RemoveEntry( const SvxBoxEntry& rEntry );
151 
152 	void				Clear();
153 
154 	sal_uInt16 				GetEntryPos( const SvxBoxEntry& rEntry ) const;
155 	const SvxBoxEntry&  GetEntry( sal_uInt16 nIdx ) const;
156 
157 	void				ModifyEntry( sal_uInt16 nPos, const String& aName );
158 	sal_uInt16				GetModifiedCount() const;
159 	const SvxBoxEntry&	GetModifiedEntry( sal_uInt16 nPos ) const;
160 
161 	sal_uInt16				GetRemovedCount() const;
162 	const SvxBoxEntry&	GetRemovedEntry( sal_uInt16 nPos ) const;
163 
164 	sal_uInt16				GetNewCount() const;
165 	const SvxBoxEntry&	GetNewEntry( sal_uInt16 nPos ) const;
166 
GetStyle() const167 	sal_uInt16 				GetStyle() const 			 { return nStyle; }
SetStyle(const sal_uInt16 nSt)168 	void				SetStyle( const sal_uInt16 nSt ) { nStyle = nSt; }
169 
170 	String				GetText() const;
171 
172 private:
173 	SvxEntryLst			aEntryLst;
174 	SvxEntryLst			aDelEntryLst;
175 	SvxBoxEntry 		aDefault;
176 	sal_uInt16 				nStyle;
177 
178 	virtual void 		KeyInput( const KeyEvent& rKEvt );
179 
180 	void				InitComboBox();
181 	void				InsertSorted( SvxBoxEntry* pEntry );
182 };
183 
184 #endif
185 
186