update credits
[LibreOffice.git] / include / svtools / ivctrl.hxx
blob3c5aafc5784839d71a5c89f57ebd83cf01acd8be
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _ICNVW_HXX
21 #define _ICNVW_HXX
23 #include "svtools/svtdllapi.h"
24 #include <tools/string.hxx>
25 #include <vcl/ctrl.hxx>
26 #include <tools/link.hxx>
27 #include <tools/contnr.hxx>
28 #include <vcl/image.hxx>
29 #include <vcl/seleng.hxx>
31 class ResId;
32 class Point;
33 class SvxIconChoiceCtrl_Impl;
34 class Image;
36 #define ICNVIEW_FLAG_POS_LOCKED 0x0001
37 #define ICNVIEW_FLAG_SELECTED 0x0002
38 #define ICNVIEW_FLAG_FOCUSED 0x0004
39 #define ICNVIEW_FLAG_IN_USE 0x0008
40 #define ICNVIEW_FLAG_CURSORED 0x0010 // Rahmen um Image
41 #define ICNVIEW_FLAG_POS_MOVED 0x0020 // per D&D verschoben aber nicht gelockt
42 #define ICNVIEW_FLAG_DROP_TARGET 0x0040 // im QueryDrop gesetzt
43 #define ICNVIEW_FLAG_BLOCK_EMPHASIS 0x0080 // Emphasis nicht painten
44 #define ICNVIEW_FLAG_USER1 0x0100
45 #define ICNVIEW_FLAG_USER2 0x0200
46 #define ICNVIEW_FLAG_PRED_SET 0x0400 // Predecessor wurde umgesetzt
48 enum SvxIconChoiceCtrlTextMode
50 IcnShowTextFull = 1, // BoundRect nach unten aufplustern
51 IcnShowTextShort, // Abkuerzung mit "..."
52 IcnShowTextSmart, // Text komplett anzeigen, wenn moeglich (n.i.)
53 IcnShowTextDontKnow // Einstellung der View
56 enum SvxIconChoiceCtrlPositionMode
58 IcnViewPositionModeFree = 0, // freies pixelgenaues Positionieren
59 IcnViewPositionModeAutoArrange = 1, // automatisches Ausrichten
60 IcnViewPositionModeAutoAdjust = 2, // automatisches Anordnen
61 IcnViewPositionModeLast = IcnViewPositionModeAutoAdjust
64 class SvxIconChoiceCtrlEntry
66 Image aImage;
68 OUString aText;
69 String aQuickHelpText;
70 void* pUserData;
72 friend class SvxIconChoiceCtrl_Impl;
73 friend class IcnCursor_Impl;
74 friend class EntryList_Impl;
75 friend class IcnGridMap_Impl;
77 Rectangle aRect; // Bounding-Rect des Entries
78 Rectangle aGridRect; // nur gesetzt im Grid-Modus
79 sal_uLong nPos;
81 // die Eintragsposition in der Eintragsliste entspricht der beim Insert vorgegebenen
82 // [Sortier-]Reihenfolge (->Reihenfolge der Anker in der Ankerliste!). Im AutoArrange-Modus
83 // kann die sichtbare Reihenfolge aber anders sein. Die Eintraege werden deshalb dann
84 // verkettet
85 SvxIconChoiceCtrlEntry* pblink; // backward (linker Nachbar)
86 SvxIconChoiceCtrlEntry* pflink; // forward (rechter Nachbar)
88 SvxIconChoiceCtrlTextMode eTextMode;
89 sal_uInt16 nX,nY; // fuer Tastatursteuerung
90 sal_uInt16 nFlags;
92 void ClearFlags( sal_uInt16 nMask ) { nFlags &= (~nMask); }
93 void SetFlags( sal_uInt16 nMask ) { nFlags |= nMask; }
94 void AssignFlags( sal_uInt16 _nFlags ) { nFlags = _nFlags; }
96 // setzt den linken Nachbarn (A <-> B ==> A <-> this <-> B)
97 void SetBacklink( SvxIconChoiceCtrlEntry* pA )
99 pA->pflink->pblink = this; // X <- B
100 this->pflink = pA->pflink; // X -> B
101 this->pblink = pA; // A <- X
102 pA->pflink = this; // A -> X
104 // loest eine Verbindung (A <-> this <-> B ==> A <-> B)
105 void Unlink()
107 this->pblink->pflink = this->pflink;
108 this->pflink->pblink = this->pblink;
109 this->pflink = 0;
110 this->pblink = 0;
113 public:
114 SvxIconChoiceCtrlEntry( const String& rText, const Image& rImage, sal_uInt16 nFlags = 0 );
115 ~SvxIconChoiceCtrlEntry () {}
117 void SetImage ( const Image& rImage ) { aImage = rImage; }
118 Image GetImage () const { return aImage; }
119 void SetText ( const OUString& rText ) { aText = rText; }
120 OUString GetText () const { return aText; }
121 String SVT_DLLPUBLIC GetDisplayText() const;
122 void SetQuickHelpText( const String& rText ) { aQuickHelpText = rText; }
123 String GetQuickHelpText() const { return aQuickHelpText; }
124 void SetUserData ( void* _pUserData ) { pUserData = _pUserData; }
125 void* GetUserData () { return pUserData; }
127 const Rectangle & GetBoundRect() const { return aRect; }
129 void SetFocus ( sal_Bool bSet )
130 { nFlags = ( bSet ? nFlags | ICNVIEW_FLAG_FOCUSED : nFlags & ~ICNVIEW_FLAG_FOCUSED ); }
132 SvxIconChoiceCtrlTextMode GetTextMode() const { return eTextMode; }
133 sal_uInt16 GetFlags() const { return nFlags; }
134 sal_Bool IsSelected() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_SELECTED) !=0); }
135 sal_Bool IsFocused() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_FOCUSED) !=0); }
136 sal_Bool IsInUse() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_IN_USE) !=0); }
137 sal_Bool IsCursored() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_CURSORED) !=0); }
138 sal_Bool IsDropTarget() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_DROP_TARGET) !=0); }
139 sal_Bool IsBlockingEmphasis() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_BLOCK_EMPHASIS) !=0); }
140 sal_Bool IsPosLocked() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_POS_LOCKED) !=0); }
142 // Nur bei AutoArrange gesetzt. Den Kopf der Liste gibts per SvxIconChoiceCtrl::GetPredecessorHead
143 SvxIconChoiceCtrlEntry* GetSuccessor() const { return pflink; }
144 SvxIconChoiceCtrlEntry* GetPredecessor() const { return pblink; }
146 // sal_Unicode GetMnemonicChar() const;
149 enum SvxIconChoiceCtrlColumnAlign
151 IcnViewAlignLeft = 1,
152 IcnViewAlignRight,
153 IcnViewAlignCenter
156 class SvxIconChoiceCtrlColumnInfo
158 OUString aColText;
159 Image aColImage;
160 long nWidth;
161 SvxIconChoiceCtrlColumnAlign eAlignment;
162 sal_uInt16 nSubItem;
164 public:
165 SvxIconChoiceCtrlColumnInfo( sal_uInt16 nSub, long nWd,
166 SvxIconChoiceCtrlColumnAlign eAlign ) :
167 nWidth( nWd ), eAlignment( eAlign ), nSubItem( nSub ) {}
168 SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& );
170 void SetText( const OUString& rText ) { aColText = rText; }
171 void SetImage( const Image& rImg ) { aColImage = rImg; }
172 void SetWidth( long nWd ) { nWidth = nWd; }
173 void SetAlignment( SvxIconChoiceCtrlColumnAlign eAlign ) { eAlignment = eAlign; }
174 void SetSubItem( sal_uInt16 nSub) { nSubItem = nSub; }
176 const OUString& GetText() const { return aColText; }
177 const Image& GetImage() const { return aColImage; }
178 long GetWidth() const { return nWidth; }
179 SvxIconChoiceCtrlColumnAlign GetAlignment() const { return eAlignment; }
180 sal_uInt16 GetSubItem() const { return nSubItem; }
183 //###################################################################################################################################
185 Window-Bits:
186 WB_ICON // Text unter dem Icon
187 WB_SMALL_ICON // Text rechts neben Icon, beliebige Positionierung
188 WB_DETAILS // Text rechts neben Icon, eingeschraenkte Posit.
189 WB_BORDER
190 WB_NOHIDESELECTION // Selektion inaktiv zeichnen, wenn kein Fokus
191 WB_NOHSCROLL
192 WB_NOVSCROLL
193 WB_NOSELECTION
194 WB_SMART_ARRANGE // im Arrange die Vis-Area beibehalten
195 WB_ALIGN_TOP // Anordnung zeilenweise von links nach rechts
196 WB_ALIGN_LEFT // Anordnung spaltenweise von oben nach unten
197 WB_NODRAGSELECTION // Keine Selektion per Tracking-Rect
198 WB_NOCOLUMNHEADER // keine Headerbar in Detailsview (Headerbar not implemented)
199 WB_NOPOINTERFOCUS // Kein GrabFocus im MouseButtonDown
200 WB_HIGHLIGHTFRAME // der unter der Maus befindliche Eintrag wird hervorgehoben
201 WB_NOASYNCSELECTHDL // Selektionshandler synchron aufrufen, d.h. Events nicht sammeln
204 #define WB_ICON WB_RECTSTYLE
205 #define WB_SMALLICON WB_SMALLSTYLE
206 #define WB_DETAILS WB_VCENTER
207 #define WB_NOHSCROLL WB_SPIN
208 #define WB_NOVSCROLL WB_DRAG
209 #define WB_NOSELECTION WB_REPEAT
210 #define WB_NODRAGSELECTION WB_PATHELLIPSIS
211 #define WB_SMART_ARRANGE WB_PASSWORD
212 #define WB_ALIGN_TOP WB_TOP
213 #define WB_ALIGN_LEFT WB_LEFT
214 #define WB_NOCOLUMNHEADER WB_CENTER
215 #define WB_HIGHLIGHTFRAME WB_INFO
216 #define WB_NOASYNCSELECTHDL WB_NOLABEL
218 class MnemonicGenerator;
220 class SVT_DLLPUBLIC SvtIconChoiceCtrl : public Control
222 friend class SvxIconChoiceCtrl_Impl;
224 Link _aClickIconHdl;
225 Link _aDocRectChangedHdl;
226 Link _aVisRectChangedHdl;
227 KeyEvent* _pCurKeyEvent;
228 SvxIconChoiceCtrl_Impl* _pImp;
229 sal_Bool _bAutoFontColor;
231 protected:
233 virtual void KeyInput( const KeyEvent& rKEvt );
234 virtual sal_Bool EditedEntry( SvxIconChoiceCtrlEntry*, const OUString& rNewText, sal_Bool bCancelled );
235 virtual void DocumentRectChanged();
236 virtual void VisibleRectChanged();
237 virtual sal_Bool EditingEntry( SvxIconChoiceCtrlEntry* pEntry );
238 virtual void Command( const CommandEvent& rCEvt );
239 virtual void Paint( const Rectangle& rRect );
240 virtual void MouseButtonDown( const MouseEvent& rMEvt );
241 virtual void MouseButtonUp( const MouseEvent& rMEvt );
242 virtual void MouseMove( const MouseEvent& rMEvt );
243 virtual void Resize();
244 virtual void GetFocus();
245 virtual void LoseFocus();
246 virtual void ClickIcon();
247 virtual void StateChanged( StateChangedType nType );
248 virtual void DataChanged( const DataChangedEvent& rDCEvt );
249 virtual void RequestHelp( const HelpEvent& rHEvt );
250 virtual void DrawEntryImage(
251 SvxIconChoiceCtrlEntry* pEntry,
252 const Point& rPos,
253 OutputDevice& rDev );
255 virtual String GetEntryText(
256 SvxIconChoiceCtrlEntry* pEntry,
257 sal_Bool bInplaceEdit );
259 virtual void FillLayoutData() const;
261 void CallImplEventListeners(sal_uLong nEvent, void* pData);
263 public:
265 SvtIconChoiceCtrl( Window* pParent, WinBits nWinStyle = WB_ICON | WB_BORDER );
266 virtual ~SvtIconChoiceCtrl();
268 void SetStyle( WinBits nWinStyle );
269 WinBits GetStyle() const;
271 sal_Bool SetChoiceWithCursor ( sal_Bool bDo = sal_True );
273 void SetFont( const Font& rFont );
274 void SetPointFont( const Font& rFont );
276 void SetClickHdl( const Link& rLink ) { _aClickIconHdl = rLink; }
277 const Link& GetClickHdl() const { return _aClickIconHdl; }
279 using OutputDevice::SetBackground;
280 void SetBackground( const Wallpaper& rWallpaper );
282 void ArrangeIcons();
285 SvxIconChoiceCtrlEntry* InsertEntry( const String& rText,
286 const Image& rImage,
287 sal_uLong nPos = LIST_APPEND,
288 const Point* pPos = 0,
289 sal_uInt16 nFlags = 0
292 /** creates automatic mnemonics for all icon texts in the control
294 void CreateAutoMnemonics( void );
296 /** creates automatic mnemonics for all icon texts in the control
298 @param _rUsedMnemonics
299 a <type>MnemonicGenerator</type> at which some other mnemonics are already registered.
300 This can be used if the control needs to share the "mnemonic space" with other elements,
301 such as a menu bar.
303 void CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics );
305 sal_Bool DoKeyInput( const KeyEvent& rKEvt );
307 sal_Bool IsEntryEditing() const;
309 sal_uLong GetEntryCount() const;
310 SvxIconChoiceCtrlEntry* GetEntry( sal_uLong nPos ) const;
311 sal_uLong GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const;
312 using Window::SetCursor;
313 void SetCursor( SvxIconChoiceCtrlEntry* pEntry );
314 SvxIconChoiceCtrlEntry* GetCursor() const;
316 // Neu-Berechnung gecachter View-Daten und Invalidierung im Fenster
317 void InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry );
319 // bHit==sal_False: Eintrag gilt als getroffen, wenn Position im BoundRect liegt
320 // ==sal_True : Bitmap oder Text muss getroffen sein
321 SvxIconChoiceCtrlEntry* GetEntry( const Point& rPosPixel, sal_Bool bHit = sal_False ) const;
323 // in dem sal_uLong wird die Position in der Liste des gefunden Eintrags zurueckgegeben
324 SvxIconChoiceCtrlEntry* GetSelectedEntry( sal_uLong& rPos ) const;
326 void SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry = 0 );
328 virtual sal_Bool HasBackground() const;
329 virtual sal_Bool HasFont() const;
330 virtual sal_Bool HasFontTextColor() const;
331 virtual sal_Bool HasFontFillColor() const;
333 void SetFontColorToBackground ( sal_Bool bDo = sal_True ) { _bAutoFontColor = bDo; }
334 sal_Bool AutoFontColor () { return _bAutoFontColor; }
336 Point GetPixelPos( const Point& rPosLogic ) const;
337 void SetSelectionMode( SelectionMode eMode );
339 Rectangle GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const;
340 Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const;
342 void SetNoSelection();
344 // ACCESSIBILITY ==========================================================
346 /** Creates and returns the accessible object of the Box. */
347 virtual ::com::sun::star::uno::Reference<
348 ::com::sun::star::accessibility::XAccessible > CreateAccessible();
351 #endif // _ICNVW_HXX
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */