xref: /trunk/main/svtools/inc/svtools/ivctrl.hxx (revision 2bfcd321) !
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 
24 #ifndef _ICNVW_HXX
25 #define _ICNVW_HXX
26 
27 #include "svtools/svtdllapi.h"
28 #include <tools/string.hxx>
29 #include <vcl/ctrl.hxx>
30 #include <tools/link.hxx>
31 #include <vcl/image.hxx>
32 #include <vcl/seleng.hxx>
33 
34 class SvPtrarr;
35 class ResId;
36 class Point;
37 class SvxIconChoiceCtrl_Impl;
38 class Image;
39 
40 #define ICNVIEW_FLAG_POS_LOCKED		0x0001
41 #define ICNVIEW_FLAG_SELECTED		0x0002
42 #define ICNVIEW_FLAG_FOCUSED		0x0004
43 #define ICNVIEW_FLAG_IN_USE			0x0008
44 #define ICNVIEW_FLAG_CURSORED	   	0x0010 // Rahmen um Image
45 #define ICNVIEW_FLAG_POS_MOVED   	0x0020 // per D&D verschoben aber nicht gelockt
46 #define ICNVIEW_FLAG_DROP_TARGET	0x0040 // im QueryDrop gesetzt
47 #define ICNVIEW_FLAG_BLOCK_EMPHASIS	0x0080 // Emphasis nicht painten
48 #define ICNVIEW_FLAG_USER1			0x0100
49 #define ICNVIEW_FLAG_USER2			0x0200
50 #define ICNVIEW_FLAG_PRED_SET		0x0400 // Predecessor wurde umgesetzt
51 
52 enum SvxIconChoiceCtrlTextMode
53 {
54 	IcnShowTextFull = 1,		// BoundRect nach unten aufplustern
55 	IcnShowTextShort,      		// Abkuerzung mit "..."
56 	IcnShowTextSmart,			// Text komplett anzeigen, wenn moeglich (n.i.)
57 	IcnShowTextDontKnow			// Einstellung der View
58 };
59 
60 enum SvxIconChoiceCtrlPositionMode
61 {
62 	IcnViewPositionModeFree = 0,			    // freies pixelgenaues Positionieren
63 	IcnViewPositionModeAutoArrange = 1,         // automatisches Ausrichten
64 	IcnViewPositionModeAutoAdjust = 2,   		// automatisches Anordnen
65 	IcnViewPositionModeLast = IcnViewPositionModeAutoAdjust
66 };
67 
68 class SvxIconChoiceCtrlEntry
69 {
70 	Image aImage;
71 	Image aImageHC;
72 
73 	String aText;
74 	String aQuickHelpText;
75 	void*  pUserData;
76 
77 	friend class SvxIconChoiceCtrl_Impl;
78 	friend class IcnCursor_Impl;
79 	friend class EntryList_Impl;
80 	friend class IcnGridMap_Impl;
81 
82 	Rectangle 				aRect;				// Bounding-Rect des Entries
83 	Rectangle 				aGridRect;			// nur gesetzt im Grid-Modus
84 	sal_uLong					nPos;
85 
86 	// die Eintragsposition in der Eintragsliste entspricht der beim Insert vorgegebenen
87 	// [Sortier-]Reihenfolge (->Reihenfolge der Anker in der Ankerliste!). Im AutoArrange-Modus
88 	// kann die sichtbare Reihenfolge aber anders sein. Die Eintraege werden deshalb dann
89 	// verkettet
90 	SvxIconChoiceCtrlEntry*			pblink;		// backward (linker Nachbar)
91 	SvxIconChoiceCtrlEntry*			pflink;     // forward  (rechter Nachbar)
92 
93 	SvxIconChoiceCtrlTextMode 		eTextMode;
94 	sal_uInt16 					nX,nY;		// fuer Tastatursteuerung
95 	sal_uInt16					nFlags;
96 
ClearFlags(sal_uInt16 nMask)97 	void					ClearFlags( sal_uInt16 nMask ) { nFlags &= (~nMask); }
SetFlags(sal_uInt16 nMask)98 	void					SetFlags( sal_uInt16 nMask ) { nFlags |= nMask; }
AssignFlags(sal_uInt16 _nFlags)99 	void					AssignFlags( sal_uInt16 _nFlags ) { nFlags = _nFlags; }
100 
101 	// setzt den linken Nachbarn (A <-> B  ==>  A <-> this <-> B)
SetBacklink(SvxIconChoiceCtrlEntry * pA)102 	void					SetBacklink( SvxIconChoiceCtrlEntry* pA )
103 							{
104 								pA->pflink->pblink = this;  	// X <- B
105 								this->pflink = pA->pflink; 		// X -> B
106 								this->pblink = pA;  			// A <- X
107 								pA->pflink = this;  			// A -> X
108 							}
109 	// loest eine Verbindung (A <-> this <-> B  ==>  A <-> B)
Unlink()110 	void					Unlink()
111 							{
112 								this->pblink->pflink = this->pflink;
113 								this->pflink->pblink = this->pblink;
114 								this->pflink = 0;
115 								this->pblink = 0;
116 							}
117 
118 public:
119 							SvxIconChoiceCtrlEntry( sal_uInt16 nFlags = 0 );
120 							SvxIconChoiceCtrlEntry( const String& rText, const Image& rImage, sal_uInt16 nFlags = 0 );
121 							SvxIconChoiceCtrlEntry( const String& rText, const Image& rImage, const Image& rImageHC, sal_uInt16 nFlags = 0 );
~SvxIconChoiceCtrlEntry()122 							~SvxIconChoiceCtrlEntry () {}
123 
SetImage(const Image & rImage)124 	void					SetImage ( const Image& rImage ) { aImage = rImage; }
SetImageHC(const Image & rImage)125 	void					SetImageHC ( const Image& rImage ) { aImageHC = rImage; }
GetImage() const126 	Image					GetImage () const { return aImage; }
GetImageHC() const127 	Image					GetImageHC () const { return aImageHC; }
SetText(const String & rText)128 	void					SetText ( const String& rText ) { aText = rText; }
GetText() const129 	String					GetText () const { return aText; }
130 	String SVT_DLLPUBLIC                    GetDisplayText() const;
SetQuickHelpText(const String & rText)131 	void					SetQuickHelpText( const String& rText ) { aQuickHelpText = rText; }
GetQuickHelpText() const132 	String					GetQuickHelpText() const { return aQuickHelpText; }
SetUserData(void * _pUserData)133 	void					SetUserData ( void* _pUserData ) { pUserData = _pUserData; }
GetUserData()134 	void*					GetUserData () { return pUserData; }
135 
GetBoundRect() const136     const Rectangle &       GetBoundRect() const { return aRect; }
137 
SetFocus(sal_Bool bSet)138 	void					SetFocus ( sal_Bool bSet )
139 	                                 { nFlags = ( bSet ? nFlags | ICNVIEW_FLAG_FOCUSED : nFlags & ~ICNVIEW_FLAG_FOCUSED ); }
140 
GetTextMode() const141 	SvxIconChoiceCtrlTextMode 		GetTextMode() const { return eTextMode; }
GetFlags() const142 	sal_uInt16					GetFlags() const { return nFlags; }
IsSelected() const143 	sal_Bool					IsSelected() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_SELECTED) !=0); }
IsFocused() const144 	sal_Bool					IsFocused() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_FOCUSED) !=0); }
IsInUse() const145 	sal_Bool					IsInUse() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_IN_USE) !=0); }
IsCursored() const146 	sal_Bool					IsCursored() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_CURSORED) !=0); }
IsDropTarget() const147 	sal_Bool					IsDropTarget() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_DROP_TARGET) !=0); }
IsBlockingEmphasis() const148 	sal_Bool					IsBlockingEmphasis() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_BLOCK_EMPHASIS) !=0); }
WasMoved() const149 	sal_Bool					WasMoved() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_POS_MOVED) !=0); }
150 	void					SetMoved( sal_Bool bMoved );
IsPosLocked() const151 	sal_Bool					IsPosLocked() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_POS_LOCKED) !=0); }
152 	void					LockPos( sal_Bool bLock );
153 	// Nur bei AutoArrange gesetzt. Den Kopf der Liste gibts per SvxIconChoiceCtrl::GetPredecessorHead
GetSuccessor() const154 	SvxIconChoiceCtrlEntry*			GetSuccessor() const { return pflink; }
GetPredecessor() const155 	SvxIconChoiceCtrlEntry*			GetPredecessor() const { return pblink; }
156 
157 //	sal_Unicode				GetMnemonicChar() const;
158 };
159 
160 enum SvxIconChoiceCtrlColumnAlign
161 {
162 	IcnViewAlignLeft = 1,
163 	IcnViewAlignRight,
164 	IcnViewAlignCenter
165 };
166 
167 class SvxIconChoiceCtrlColumnInfo
168 {
169 	String					aColText;
170 	Image					aColImage;
171 	long					nWidth;
172 	SvxIconChoiceCtrlColumnAlign	eAlignment;
173 	sal_uInt16 					nSubItem;
174 
175 public:
SvxIconChoiceCtrlColumnInfo(sal_uInt16 nSub,long nWd,SvxIconChoiceCtrlColumnAlign eAlign)176 							SvxIconChoiceCtrlColumnInfo( sal_uInt16 nSub, long nWd,
177 								SvxIconChoiceCtrlColumnAlign eAlign ) :
178 								nWidth( nWd ), eAlignment( eAlign ), nSubItem( nSub ) {}
179 							SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& );
180 
SetText(const String & rText)181 	void					SetText( const String& rText ) { aColText = rText; }
SetImage(const Image & rImg)182 	void					SetImage( const Image& rImg ) { aColImage = rImg; }
SetWidth(long nWd)183 	void					SetWidth( long nWd ) { nWidth = nWd; }
SetAlignment(SvxIconChoiceCtrlColumnAlign eAlign)184 	void					SetAlignment( SvxIconChoiceCtrlColumnAlign eAlign ) { eAlignment = eAlign; }
SetSubItem(sal_uInt16 nSub)185 	void					SetSubItem( sal_uInt16 nSub) { nSubItem = nSub; }
186 
GetText() const187 	const String& 			GetText() const { return aColText; }
GetImage() const188 	const Image&			GetImage() const { return aColImage; }
GetWidth() const189 	long					GetWidth() const { return nWidth; }
GetAlignment() const190 	SvxIconChoiceCtrlColumnAlign	GetAlignment() const { return eAlignment; }
GetSubItem() const191 	sal_uInt16					GetSubItem() const { return nSubItem; }
192 };
193 
194 //###################################################################################################################################
195 /*
196 	Window-Bits:
197 		WB_ICON				// Text unter dem Icon
198 		WB_SMALL_ICON		// Text rechts neben Icon, beliebige Positionierung
199 		WB_DETAILS			// Text rechts neben Icon, eingeschraenkte Posit.
200 		WB_BORDER
201 		WB_NOHIDESELECTION	// Selektion inaktiv zeichnen, wenn kein Fokus
202 		WB_NOHSCROLL
203 		WB_NOVSCROLL
204 		WB_NOSELECTION
205 		WB_SMART_ARRANGE 	// im Arrange die Vis-Area beibehalten
206 		WB_ALIGN_TOP		// Anordnung zeilenweise von links nach rechts
207 		WB_ALIGN_LEFT 		// Anordnung spaltenweise von oben nach unten
208 		WB_NODRAGSELECTION	// Keine Selektion per Tracking-Rect
209 		WB_NOCOLUMNHEADER	// keine Headerbar in Detailsview (Headerbar not implemented)
210 		WB_NOPOINTERFOCUS	// Kein GrabFocus im MouseButtonDown
211 		WB_HIGHLIGHTFRAME	// der unter der Maus befindliche Eintrag wird hervorgehoben
212 		WB_NOASYNCSELECTHDL	// Selektionshandler synchron aufrufen, d.h. Events nicht sammeln
213 */
214 
215 #define WB_ICON					WB_RECTSTYLE
216 #define WB_SMALLICON       		WB_SMALLSTYLE
217 #define WB_DETAILS				WB_VCENTER
218 #define WB_NOHSCROLL			WB_SPIN
219 #define WB_NOVSCROLL			WB_DRAG
220 #define WB_NOSELECTION			WB_REPEAT
221 #define WB_NODRAGSELECTION		WB_PATHELLIPSIS
222 #define WB_SMART_ARRANGE		WB_PASSWORD
223 #define WB_ALIGN_TOP			WB_TOP
224 #define WB_ALIGN_LEFT			WB_LEFT
225 #define WB_NOCOLUMNHEADER		WB_CENTER
226 #define WB_HIGHLIGHTFRAME		WB_INFO
227 #define WB_NOASYNCSELECTHDL		WB_NOLABEL
228 
229 class MnemonicGenerator;
230 
231 class SVT_DLLPUBLIC SvtIconChoiceCtrl : public Control
232 {
233 	friend class SvxIconChoiceCtrl_Impl;
234 
235 	Link					_aClickIconHdl;
236 	Link					_aDocRectChangedHdl;
237 	Link					_aVisRectChangedHdl;
238 	KeyEvent*				_pCurKeyEvent;
239 	SvxIconChoiceCtrl_Impl*	_pImp;
240 	sal_Bool					_bAutoFontColor;
241 
242 protected:
243 
244 	virtual void    	KeyInput( const KeyEvent& rKEvt );
245 	virtual sal_Bool		EditedEntry( SvxIconChoiceCtrlEntry*, const XubString& rNewText, sal_Bool bCancelled );
246 	virtual void		DocumentRectChanged();
247 	virtual void		VisibleRectChanged();
248 	virtual sal_Bool		EditingEntry( SvxIconChoiceCtrlEntry* pEntry );
249 	virtual void    	Command( const CommandEvent& rCEvt );
250 	virtual void    	Paint( const Rectangle& rRect );
251 	virtual void    	MouseButtonDown( const MouseEvent& rMEvt );
252 	virtual void    	MouseButtonUp( const MouseEvent& rMEvt );
253 	virtual void    	MouseMove( const MouseEvent& rMEvt );
254 	virtual void    	Resize();
255 	virtual void    	GetFocus();
256 	virtual void    	LoseFocus();
257 	virtual void		ClickIcon();
258 	virtual void 		StateChanged( StateChangedType nType );
259 	virtual void 		DataChanged( const DataChangedEvent& rDCEvt );
260 	virtual void		RequestHelp( const HelpEvent& rHEvt );
261 	virtual void		DrawEntryImage(
262 							SvxIconChoiceCtrlEntry* pEntry,
263 							const Point& rPos,
264 							OutputDevice& rDev );
265 
266 	virtual String		GetEntryText(
267 							SvxIconChoiceCtrlEntry* pEntry,
268 							sal_Bool bInplaceEdit );
269 
270     virtual void		FillLayoutData() const;
271 
272 	void				CallImplEventListeners(sal_uLong nEvent, void* pData);
273 
274 public:
275 
276 						SvtIconChoiceCtrl( Window* pParent, WinBits nWinStyle = WB_ICON | WB_BORDER );
277 						SvtIconChoiceCtrl( Window* pParent, const ResId& rResId );
278 	virtual 			~SvtIconChoiceCtrl();
279 
280 	void				SetStyle( WinBits nWinStyle );
281 	WinBits				GetStyle() const;
282 
283 	sal_Bool				SetChoiceWithCursor ( sal_Bool bDo = sal_True );
284 
285 	void 				SetUpdateMode( sal_Bool bUpdateMode );
286 	void				SetFont( const Font& rFont );
287 	void				SetPointFont( const Font& rFont );
288 
SetClickHdl(const Link & rLink)289 	void            	SetClickHdl( const Link& rLink ) { _aClickIconHdl = rLink; }
GetClickHdl() const290 	const Link&     	GetClickHdl() const { return _aClickIconHdl; }
291 
292     using OutputDevice::SetBackground;
293 	void				SetBackground( const Wallpaper& rWallpaper );
294 
295 	void				ArrangeIcons();
296 
297 
298 	SvxIconChoiceCtrlEntry*	InsertEntry( sal_uLong nPos = LIST_APPEND,
299 									 const Point* pPos = 0,
300 									 sal_uInt16 nFlags = 0 );
301 	SvxIconChoiceCtrlEntry*	InsertEntry( const String& rText, const Image& rImage,
302 									 sal_uLong nPos = LIST_APPEND,
303 									 const Point* pPos = 0,
304 									 sal_uInt16 nFlags = 0 );
305 	SvxIconChoiceCtrlEntry*	InsertEntry( const String& rText, const Image& rImage, const Image& rImageHC,
306 									 sal_uLong nPos = LIST_APPEND,
307 									 const Point* pPos = 0,
308 									 sal_uInt16 nFlags = 0 );
309 
310     /** creates automatic mnemonics for all icon texts in the control
311     */
312 	void				CreateAutoMnemonics( void );
313 
314     /** creates automatic mnemonics for all icon texts in the control
315 
316     @param _rUsedMnemonics
317         a <type>MnemonicGenerator</type> at which some other mnemonics are already registered.
318         This can be used if the control needs to share the "mnemonic space" with other elements,
319         such as a menu bar.
320     */
321 	void				CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics );
322 
323 	void				RemoveEntry( SvxIconChoiceCtrlEntry* pEntry );
324 
325 	sal_Bool				DoKeyInput( const KeyEvent& rKEvt );
326 
327 	sal_Bool				IsEntryEditing() const;
328 	void				Clear();
329 
330 	sal_uLong					GetEntryCount() const;
331 	SvxIconChoiceCtrlEntry*	GetEntry( sal_uLong nPos ) const;
332 	sal_uLong					GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const;
333     using Window::SetCursor;
334 	void					SetCursor( SvxIconChoiceCtrlEntry* pEntry );
335 	SvxIconChoiceCtrlEntry*	GetCursor() const;
336 
337 	// Neu-Berechnung gecachter View-Daten und Invalidierung im Fenster
338 	void					InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry );
339 
340 	// bHit==sal_False: Eintrag gilt als getroffen, wenn Position im BoundRect liegt
341 	//     ==sal_True : Bitmap oder Text muss getroffen sein
342 	SvxIconChoiceCtrlEntry*	GetEntry( const Point& rPosPixel, sal_Bool bHit = sal_False ) const;
343 	// Gibt den naechsten ueber pCurEntry liegenden Eintrag (ZOrder)
344 	SvxIconChoiceCtrlEntry*	GetNextEntry( const Point& rPosPixel, SvxIconChoiceCtrlEntry* pCurEntry, sal_Bool  ) const;
345 	// Gibt den naechsten unter pCurEntry liegenden Eintrag (ZOrder)
346 	SvxIconChoiceCtrlEntry*	GetPrevEntry( const Point& rPosPixel, SvxIconChoiceCtrlEntry* pCurEntry, sal_Bool  ) const;
347 
348 	// in dem sal_uLong wird die Position in der Liste des gefunden Eintrags zurueckgegeben
349 	SvxIconChoiceCtrlEntry*	GetSelectedEntry( sal_uLong& rPos ) const;
350 
351 	void						SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry = 0 );
352 	SvxIconChoiceCtrlTextMode	GetEntryTextMode( const SvxIconChoiceCtrlEntry* pEntry = 0 ) const;
353 
354 	// offene asynchron abzuarbeitende Aktionen ausfuehren. Muss vor dem Speichern von
355 	// Eintragspositionen etc. gerufen werden
356 	void				Flush();
357 
358 
359 	virtual sal_Bool		HasBackground() const;
360 	virtual sal_Bool		HasFont() const;
361 	virtual sal_Bool		HasFontTextColor() const;
362 	virtual sal_Bool		HasFontFillColor() const;
363 
SetFontColorToBackground(sal_Bool bDo=sal_True)364 	void				SetFontColorToBackground ( sal_Bool bDo = sal_True ) { _bAutoFontColor = bDo; }
AutoFontColor()365 	sal_Bool				AutoFontColor () { return _bAutoFontColor; }
366 
367 	Point				GetLogicPos( const Point& rPosPixel ) const;
368 	Point		   		GetPixelPos( const Point& rPosLogic ) const;
369 	void				SetSelectionMode( SelectionMode eMode );
370 
371 	sal_Bool				HandleShortCutKey( const KeyEvent& rKeyEvent );
372 
373 	Rectangle			GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const;
374 	Rectangle			GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const;
375 
376 	void				SetNoSelection();
377 
378     // ACCESSIBILITY ==========================================================
379 
380     /** Creates and returns the accessible object of the Box. */
381     virtual ::com::sun::star::uno::Reference<
382 		::com::sun::star::accessibility::XAccessible > CreateAccessible();
383 };
384 
385 #endif // _ICNVW_HXX
386 
387