bump product version to 4.2.0.1
[LibreOffice.git] / include / svtools / ivctrl.hxx
blob6b8e904d24eea604d158fca8e67b79fd45d16070
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 INCLUDED_SVTOOLS_IVCTRL_HXX
21 #define INCLUDED_SVTOOLS_IVCTRL_HXX
23 #include <svtools/svtdllapi.h>
24 #include <vcl/ctrl.hxx>
25 #include <tools/link.hxx>
26 #include <tools/contnr.hxx>
27 #include <vcl/image.hxx>
28 #include <vcl/seleng.hxx>
30 class ResId;
31 class Point;
32 class SvxIconChoiceCtrl_Impl;
33 class Image;
35 #define ICNVIEW_FLAG_POS_LOCKED 0x0001
36 #define ICNVIEW_FLAG_SELECTED 0x0002
37 #define ICNVIEW_FLAG_FOCUSED 0x0004
38 #define ICNVIEW_FLAG_IN_USE 0x0008
39 #define ICNVIEW_FLAG_CURSORED 0x0010 // Rahmen um Image
40 #define ICNVIEW_FLAG_POS_MOVED 0x0020 // per D&D verschoben aber nicht gelockt
41 #define ICNVIEW_FLAG_DROP_TARGET 0x0040 // im QueryDrop gesetzt
42 #define ICNVIEW_FLAG_BLOCK_EMPHASIS 0x0080 // Emphasis nicht painten
43 #define ICNVIEW_FLAG_USER1 0x0100
44 #define ICNVIEW_FLAG_USER2 0x0200
45 #define ICNVIEW_FLAG_PRED_SET 0x0400 // Predecessor wurde umgesetzt
47 enum SvxIconChoiceCtrlTextMode
49 IcnShowTextFull = 1, // BoundRect nach unten aufplustern
50 IcnShowTextShort, // Abkuerzung mit "..."
51 IcnShowTextSmart, // Text komplett anzeigen, wenn moeglich (n.i.)
52 IcnShowTextDontKnow // Einstellung der View
55 enum SvxIconChoiceCtrlPositionMode
57 IcnViewPositionModeFree = 0, // freies pixelgenaues Positionieren
58 IcnViewPositionModeAutoArrange = 1, // automatisches Ausrichten
59 IcnViewPositionModeAutoAdjust = 2, // automatisches Anordnen
60 IcnViewPositionModeLast = IcnViewPositionModeAutoAdjust
63 class SvxIconChoiceCtrlEntry
65 Image aImage;
67 OUString aText;
68 OUString aQuickHelpText;
69 void* pUserData;
71 friend class SvxIconChoiceCtrl_Impl;
72 friend class IcnCursor_Impl;
73 friend class EntryList_Impl;
74 friend class IcnGridMap_Impl;
76 Rectangle aRect; // Bounding-Rect des Entries
77 Rectangle aGridRect; // nur gesetzt im Grid-Modus
78 sal_uLong nPos;
80 // die Eintragsposition in der Eintragsliste entspricht der beim Insert vorgegebenen
81 // [Sortier-]Reihenfolge (->Reihenfolge der Anker in der Ankerliste!). Im AutoArrange-Modus
82 // kann die sichtbare Reihenfolge aber anders sein. Die Eintraege werden deshalb dann
83 // verkettet
84 SvxIconChoiceCtrlEntry* pblink; // backward (linker Nachbar)
85 SvxIconChoiceCtrlEntry* pflink; // forward (rechter Nachbar)
87 SvxIconChoiceCtrlTextMode eTextMode;
88 sal_uInt16 nX,nY; // fuer Tastatursteuerung
89 sal_uInt16 nFlags;
91 void ClearFlags( sal_uInt16 nMask ) { nFlags &= (~nMask); }
92 void SetFlags( sal_uInt16 nMask ) { nFlags |= nMask; }
93 void AssignFlags( sal_uInt16 _nFlags ) { nFlags = _nFlags; }
95 // setzt den linken Nachbarn (A <-> B ==> A <-> this <-> B)
96 void SetBacklink( SvxIconChoiceCtrlEntry* pA )
98 pA->pflink->pblink = this; // X <- B
99 this->pflink = pA->pflink; // X -> B
100 this->pblink = pA; // A <- X
101 pA->pflink = this; // A -> X
103 // loest eine Verbindung (A <-> this <-> B ==> A <-> B)
104 void Unlink()
106 this->pblink->pflink = this->pflink;
107 this->pflink->pblink = this->pblink;
108 this->pflink = 0;
109 this->pblink = 0;
112 public:
113 SvxIconChoiceCtrlEntry( const OUString& rText, const Image& rImage, sal_uInt16 nFlags = 0 );
114 ~SvxIconChoiceCtrlEntry () {}
116 void SetImage ( const Image& rImage ) { aImage = rImage; }
117 Image GetImage () const { return aImage; }
118 void SetText ( const OUString& rText ) { aText = rText; }
119 OUString GetText () const { return aText; }
120 OUString SVT_DLLPUBLIC GetDisplayText() const;
121 void SetQuickHelpText( const OUString& rText ) { aQuickHelpText = rText; }
122 OUString GetQuickHelpText() const { return aQuickHelpText; }
123 void SetUserData ( void* _pUserData ) { pUserData = _pUserData; }
124 void* GetUserData () { return pUserData; }
126 const Rectangle & GetBoundRect() const { return aRect; }
128 void SetFocus ( sal_Bool bSet )
129 { nFlags = ( bSet ? nFlags | ICNVIEW_FLAG_FOCUSED : nFlags & ~ICNVIEW_FLAG_FOCUSED ); }
131 SvxIconChoiceCtrlTextMode GetTextMode() const { return eTextMode; }
132 sal_uInt16 GetFlags() const { return nFlags; }
133 sal_Bool IsSelected() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_SELECTED) !=0); }
134 sal_Bool IsFocused() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_FOCUSED) !=0); }
135 sal_Bool IsInUse() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_IN_USE) !=0); }
136 sal_Bool IsCursored() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_CURSORED) !=0); }
137 sal_Bool IsDropTarget() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_DROP_TARGET) !=0); }
138 sal_Bool IsBlockingEmphasis() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_BLOCK_EMPHASIS) !=0); }
139 sal_Bool IsPosLocked() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_POS_LOCKED) !=0); }
141 // Nur bei AutoArrange gesetzt. Den Kopf der Liste gibts per SvxIconChoiceCtrl::GetPredecessorHead
142 SvxIconChoiceCtrlEntry* GetSuccessor() const { return pflink; }
143 SvxIconChoiceCtrlEntry* GetPredecessor() const { return pblink; }
145 // sal_Unicode GetMnemonicChar() const;
148 enum SvxIconChoiceCtrlColumnAlign
150 IcnViewAlignLeft = 1,
151 IcnViewAlignRight,
152 IcnViewAlignCenter
155 class SvxIconChoiceCtrlColumnInfo
157 OUString aColText;
158 Image aColImage;
159 long nWidth;
160 SvxIconChoiceCtrlColumnAlign eAlignment;
161 sal_uInt16 nSubItem;
163 public:
164 SvxIconChoiceCtrlColumnInfo( sal_uInt16 nSub, long nWd,
165 SvxIconChoiceCtrlColumnAlign eAlign ) :
166 nWidth( nWd ), eAlignment( eAlign ), nSubItem( nSub ) {}
167 SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& );
169 void SetText( const OUString& rText ) { aColText = rText; }
170 void SetImage( const Image& rImg ) { aColImage = rImg; }
171 void SetWidth( long nWd ) { nWidth = nWd; }
172 void SetAlignment( SvxIconChoiceCtrlColumnAlign eAlign ) { eAlignment = eAlign; }
173 void SetSubItem( sal_uInt16 nSub) { nSubItem = nSub; }
175 const OUString& GetText() const { return aColText; }
176 const Image& GetImage() const { return aColImage; }
177 long GetWidth() const { return nWidth; }
178 SvxIconChoiceCtrlColumnAlign GetAlignment() const { return eAlignment; }
179 sal_uInt16 GetSubItem() const { return nSubItem; }
182 //###################################################################################################################################
184 Window-Bits:
185 WB_ICON // Text unter dem Icon
186 WB_SMALL_ICON // Text rechts neben Icon, beliebige Positionierung
187 WB_DETAILS // Text rechts neben Icon, eingeschraenkte Posit.
188 WB_BORDER
189 WB_NOHIDESELECTION // Selektion inaktiv zeichnen, wenn kein Fokus
190 WB_NOHSCROLL
191 WB_NOVSCROLL
192 WB_NOSELECTION
193 WB_SMART_ARRANGE // im Arrange die Vis-Area beibehalten
194 WB_ALIGN_TOP // Anordnung zeilenweise von links nach rechts
195 WB_ALIGN_LEFT // Anordnung spaltenweise von oben nach unten
196 WB_NODRAGSELECTION // Keine Selektion per Tracking-Rect
197 WB_NOCOLUMNHEADER // keine Headerbar in Detailsview (Headerbar not implemented)
198 WB_NOPOINTERFOCUS // Kein GrabFocus im MouseButtonDown
199 WB_HIGHLIGHTFRAME // der unter der Maus befindliche Eintrag wird hervorgehoben
200 WB_NOASYNCSELECTHDL // Selektionshandler synchron aufrufen, d.h. Events nicht sammeln
203 #define WB_ICON WB_RECTSTYLE
204 #define WB_SMALLICON WB_SMALLSTYLE
205 #define WB_DETAILS WB_VCENTER
206 #define WB_NOHSCROLL WB_SPIN
207 #define WB_NOVSCROLL WB_DRAG
208 #define WB_NOSELECTION WB_REPEAT
209 #define WB_NODRAGSELECTION WB_PATHELLIPSIS
210 #define WB_SMART_ARRANGE WB_PASSWORD
211 #define WB_ALIGN_TOP WB_TOP
212 #define WB_ALIGN_LEFT WB_LEFT
213 #define WB_NOCOLUMNHEADER WB_CENTER
214 #define WB_HIGHLIGHTFRAME WB_INFO
215 #define WB_NOASYNCSELECTHDL WB_NOLABEL
217 class MnemonicGenerator;
219 class SVT_DLLPUBLIC SvtIconChoiceCtrl : public Control
221 friend class SvxIconChoiceCtrl_Impl;
223 Link _aClickIconHdl;
224 Link _aDocRectChangedHdl;
225 Link _aVisRectChangedHdl;
226 KeyEvent* _pCurKeyEvent;
227 SvxIconChoiceCtrl_Impl* _pImp;
228 sal_Bool _bAutoFontColor;
230 protected:
232 virtual void KeyInput( const KeyEvent& rKEvt );
233 virtual sal_Bool EditedEntry( SvxIconChoiceCtrlEntry*, const OUString& rNewText, sal_Bool bCancelled );
234 virtual void DocumentRectChanged();
235 virtual void VisibleRectChanged();
236 virtual sal_Bool EditingEntry( SvxIconChoiceCtrlEntry* pEntry );
237 virtual void Command( const CommandEvent& rCEvt );
238 virtual void Paint( const Rectangle& rRect );
239 virtual void MouseButtonDown( const MouseEvent& rMEvt );
240 virtual void MouseButtonUp( const MouseEvent& rMEvt );
241 virtual void MouseMove( const MouseEvent& rMEvt );
242 virtual void Resize();
243 virtual void GetFocus();
244 virtual void LoseFocus();
245 virtual void ClickIcon();
246 virtual void StateChanged( StateChangedType nType );
247 virtual void DataChanged( const DataChangedEvent& rDCEvt );
248 virtual void RequestHelp( const HelpEvent& rHEvt );
249 virtual void DrawEntryImage(
250 SvxIconChoiceCtrlEntry* pEntry,
251 const Point& rPos,
252 OutputDevice& rDev );
254 OUString GetEntryText(
255 SvxIconChoiceCtrlEntry* pEntry,
256 sal_Bool bInplaceEdit );
258 virtual void FillLayoutData() const;
260 void CallImplEventListeners(sal_uLong nEvent, void* pData);
262 public:
264 SvtIconChoiceCtrl( Window* pParent, WinBits nWinStyle = WB_ICON | WB_BORDER );
265 virtual ~SvtIconChoiceCtrl();
267 void SetStyle( WinBits nWinStyle );
268 WinBits GetStyle() const;
270 sal_Bool SetChoiceWithCursor ( sal_Bool bDo = sal_True );
272 void SetFont( const Font& rFont );
273 void SetPointFont( const Font& rFont );
275 void SetClickHdl( const Link& rLink ) { _aClickIconHdl = rLink; }
276 const Link& GetClickHdl() const { return _aClickIconHdl; }
278 using OutputDevice::SetBackground;
279 void SetBackground( const Wallpaper& rWallpaper );
281 void ArrangeIcons();
284 SvxIconChoiceCtrlEntry* InsertEntry( const OUString& rText,
285 const Image& rImage,
286 sal_uLong nPos = LIST_APPEND,
287 const Point* pPos = 0,
288 sal_uInt16 nFlags = 0
291 /** creates automatic mnemonics for all icon texts in the control
293 void CreateAutoMnemonics( void );
295 /** creates automatic mnemonics for all icon texts in the control
297 @param _rUsedMnemonics
298 a MnemonicGenerator at which some other mnemonics are already registered.
299 This can be used if the control needs to share the "mnemonic space" with other elements,
300 such as a menu bar.
302 void CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics );
304 sal_Bool DoKeyInput( const KeyEvent& rKEvt );
306 sal_Bool IsEntryEditing() const;
308 sal_uLong GetEntryCount() const;
309 SvxIconChoiceCtrlEntry* GetEntry( sal_uLong nPos ) const;
310 sal_uLong GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const;
311 using Window::SetCursor;
312 void SetCursor( SvxIconChoiceCtrlEntry* pEntry );
313 SvxIconChoiceCtrlEntry* GetCursor() const;
315 // Neu-Berechnung gecachter View-Daten und Invalidierung im Fenster
316 void InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry );
318 // bHit==sal_False: Eintrag gilt als getroffen, wenn Position im BoundRect liegt
319 // ==sal_True : Bitmap oder Text muss getroffen sein
320 SvxIconChoiceCtrlEntry* GetEntry( const Point& rPosPixel, sal_Bool bHit = sal_False ) const;
322 // in dem sal_uLong wird die Position in der Liste des gefunden Eintrags zurueckgegeben
323 SvxIconChoiceCtrlEntry* GetSelectedEntry( sal_uLong& rPos ) const;
325 void SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry = 0 );
327 virtual sal_Bool HasBackground() const;
328 virtual sal_Bool HasFont() const;
329 virtual sal_Bool HasFontTextColor() const;
330 virtual sal_Bool HasFontFillColor() const;
332 void SetFontColorToBackground ( sal_Bool bDo = sal_True ) { _bAutoFontColor = bDo; }
333 sal_Bool AutoFontColor () { return _bAutoFontColor; }
335 Point GetPixelPos( const Point& rPosLogic ) const;
336 void SetSelectionMode( SelectionMode eMode );
338 Rectangle GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const;
339 Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const;
341 void SetNoSelection();
343 // ACCESSIBILITY ==========================================================
345 /** Creates and returns the accessible object of the Box. */
346 virtual ::com::sun::star::uno::Reference<
347 ::com::sun::star::accessibility::XAccessible > CreateAccessible();
350 #endif // INCLUDED_SVTOOLS_IVCTRL_HXX
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */