Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _ICNVW_HXX
30 : : #define _ICNVW_HXX
31 : :
32 : : #include "svtools/svtdllapi.h"
33 : : #include <tools/string.hxx>
34 : : #include <vcl/ctrl.hxx>
35 : : #include <tools/link.hxx>
36 : : #include <tools/contnr.hxx>
37 : : #include <vcl/image.hxx>
38 : : #include <vcl/seleng.hxx>
39 : :
40 : : class ResId;
41 : : class Point;
42 : : class SvxIconChoiceCtrl_Impl;
43 : : class Image;
44 : :
45 : : #define ICNVIEW_FLAG_POS_LOCKED 0x0001
46 : : #define ICNVIEW_FLAG_SELECTED 0x0002
47 : : #define ICNVIEW_FLAG_FOCUSED 0x0004
48 : : #define ICNVIEW_FLAG_IN_USE 0x0008
49 : : #define ICNVIEW_FLAG_CURSORED 0x0010 // Rahmen um Image
50 : : #define ICNVIEW_FLAG_POS_MOVED 0x0020 // per D&D verschoben aber nicht gelockt
51 : : #define ICNVIEW_FLAG_DROP_TARGET 0x0040 // im QueryDrop gesetzt
52 : : #define ICNVIEW_FLAG_BLOCK_EMPHASIS 0x0080 // Emphasis nicht painten
53 : : #define ICNVIEW_FLAG_USER1 0x0100
54 : : #define ICNVIEW_FLAG_USER2 0x0200
55 : : #define ICNVIEW_FLAG_PRED_SET 0x0400 // Predecessor wurde umgesetzt
56 : :
57 : : enum SvxIconChoiceCtrlTextMode
58 : : {
59 : : IcnShowTextFull = 1, // BoundRect nach unten aufplustern
60 : : IcnShowTextShort, // Abkuerzung mit "..."
61 : : IcnShowTextSmart, // Text komplett anzeigen, wenn moeglich (n.i.)
62 : : IcnShowTextDontKnow // Einstellung der View
63 : : };
64 : :
65 : : enum SvxIconChoiceCtrlPositionMode
66 : : {
67 : : IcnViewPositionModeFree = 0, // freies pixelgenaues Positionieren
68 : : IcnViewPositionModeAutoArrange = 1, // automatisches Ausrichten
69 : : IcnViewPositionModeAutoAdjust = 2, // automatisches Anordnen
70 : : IcnViewPositionModeLast = IcnViewPositionModeAutoAdjust
71 : : };
72 : :
73 : : class SvxIconChoiceCtrlEntry
74 : : {
75 : : Image aImage;
76 : :
77 : : String aText;
78 : : String aQuickHelpText;
79 : : void* pUserData;
80 : :
81 : : friend class SvxIconChoiceCtrl_Impl;
82 : : friend class IcnCursor_Impl;
83 : : friend class EntryList_Impl;
84 : : friend class IcnGridMap_Impl;
85 : :
86 : : Rectangle aRect; // Bounding-Rect des Entries
87 : : Rectangle aGridRect; // nur gesetzt im Grid-Modus
88 : : sal_uLong nPos;
89 : :
90 : : // die Eintragsposition in der Eintragsliste entspricht der beim Insert vorgegebenen
91 : : // [Sortier-]Reihenfolge (->Reihenfolge der Anker in der Ankerliste!). Im AutoArrange-Modus
92 : : // kann die sichtbare Reihenfolge aber anders sein. Die Eintraege werden deshalb dann
93 : : // verkettet
94 : : SvxIconChoiceCtrlEntry* pblink; // backward (linker Nachbar)
95 : : SvxIconChoiceCtrlEntry* pflink; // forward (rechter Nachbar)
96 : :
97 : : SvxIconChoiceCtrlTextMode eTextMode;
98 : : sal_uInt16 nX,nY; // fuer Tastatursteuerung
99 : : sal_uInt16 nFlags;
100 : :
101 : 0 : void ClearFlags( sal_uInt16 nMask ) { nFlags &= (~nMask); }
102 : 0 : void SetFlags( sal_uInt16 nMask ) { nFlags |= nMask; }
103 : 0 : void AssignFlags( sal_uInt16 _nFlags ) { nFlags = _nFlags; }
104 : :
105 : : // setzt den linken Nachbarn (A <-> B ==> A <-> this <-> B)
106 : 0 : void SetBacklink( SvxIconChoiceCtrlEntry* pA )
107 : : {
108 : 0 : pA->pflink->pblink = this; // X <- B
109 : 0 : this->pflink = pA->pflink; // X -> B
110 : 0 : this->pblink = pA; // A <- X
111 : 0 : pA->pflink = this; // A -> X
112 : 0 : }
113 : : // loest eine Verbindung (A <-> this <-> B ==> A <-> B)
114 : 0 : void Unlink()
115 : : {
116 : 0 : this->pblink->pflink = this->pflink;
117 : 0 : this->pflink->pblink = this->pblink;
118 : 0 : this->pflink = 0;
119 : 0 : this->pblink = 0;
120 : 0 : }
121 : :
122 : : public:
123 : : SvxIconChoiceCtrlEntry( const String& rText, const Image& rImage, sal_uInt16 nFlags = 0 );
124 [ # # ][ # # ]: 0 : ~SvxIconChoiceCtrlEntry () {}
125 : :
126 : 0 : void SetImage ( const Image& rImage ) { aImage = rImage; }
127 : 0 : Image GetImage () const { return aImage; }
128 : 0 : void SetText ( const String& rText ) { aText = rText; }
129 : 0 : String GetText () const { return aText; }
130 : : String SVT_DLLPUBLIC GetDisplayText() const;
131 : 0 : void SetQuickHelpText( const String& rText ) { aQuickHelpText = rText; }
132 : 0 : String GetQuickHelpText() const { return aQuickHelpText; }
133 : 0 : void SetUserData ( void* _pUserData ) { pUserData = _pUserData; }
134 : 0 : void* GetUserData () { return pUserData; }
135 : :
136 : 0 : const Rectangle & GetBoundRect() const { return aRect; }
137 : :
138 : : void SetFocus ( sal_Bool bSet )
139 : : { nFlags = ( bSet ? nFlags | ICNVIEW_FLAG_FOCUSED : nFlags & ~ICNVIEW_FLAG_FOCUSED ); }
140 : :
141 : 0 : SvxIconChoiceCtrlTextMode GetTextMode() const { return eTextMode; }
142 : 0 : sal_uInt16 GetFlags() const { return nFlags; }
143 : 0 : sal_Bool IsSelected() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_SELECTED) !=0); }
144 : 0 : sal_Bool IsFocused() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_FOCUSED) !=0); }
145 : : sal_Bool IsInUse() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_IN_USE) !=0); }
146 : 0 : sal_Bool IsCursored() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_CURSORED) !=0); }
147 : 0 : sal_Bool IsDropTarget() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_DROP_TARGET) !=0); }
148 : 0 : sal_Bool IsBlockingEmphasis() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_BLOCK_EMPHASIS) !=0); }
149 : 0 : sal_Bool IsPosLocked() const { return (sal_Bool)((nFlags & ICNVIEW_FLAG_POS_LOCKED) !=0); }
150 : :
151 : : // Nur bei AutoArrange gesetzt. Den Kopf der Liste gibts per SvxIconChoiceCtrl::GetPredecessorHead
152 : : SvxIconChoiceCtrlEntry* GetSuccessor() const { return pflink; }
153 : : SvxIconChoiceCtrlEntry* GetPredecessor() const { return pblink; }
154 : :
155 : : // sal_Unicode GetMnemonicChar() const;
156 : : };
157 : :
158 : : enum SvxIconChoiceCtrlColumnAlign
159 : : {
160 : : IcnViewAlignLeft = 1,
161 : : IcnViewAlignRight,
162 : : IcnViewAlignCenter
163 : : };
164 : :
165 [ # # ]: 0 : class SvxIconChoiceCtrlColumnInfo
166 : : {
167 : : String aColText;
168 : : Image aColImage;
169 : : long nWidth;
170 : : SvxIconChoiceCtrlColumnAlign eAlignment;
171 : : sal_uInt16 nSubItem;
172 : :
173 : : public:
174 : 0 : SvxIconChoiceCtrlColumnInfo( sal_uInt16 nSub, long nWd,
175 : : SvxIconChoiceCtrlColumnAlign eAlign ) :
176 [ # # ]: 0 : nWidth( nWd ), eAlignment( eAlign ), nSubItem( nSub ) {}
177 : : SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& );
178 : :
179 : : void SetText( const String& rText ) { aColText = rText; }
180 : : void SetImage( const Image& rImg ) { aColImage = rImg; }
181 : 0 : void SetWidth( long nWd ) { nWidth = nWd; }
182 : : void SetAlignment( SvxIconChoiceCtrlColumnAlign eAlign ) { eAlignment = eAlign; }
183 : : void SetSubItem( sal_uInt16 nSub) { nSubItem = nSub; }
184 : :
185 : : const String& GetText() const { return aColText; }
186 : : const Image& GetImage() const { return aColImage; }
187 : 0 : long GetWidth() const { return nWidth; }
188 : : SvxIconChoiceCtrlColumnAlign GetAlignment() const { return eAlignment; }
189 : : sal_uInt16 GetSubItem() const { return nSubItem; }
190 : : };
191 : :
192 : : //###################################################################################################################################
193 : : /*
194 : : Window-Bits:
195 : : WB_ICON // Text unter dem Icon
196 : : WB_SMALL_ICON // Text rechts neben Icon, beliebige Positionierung
197 : : WB_DETAILS // Text rechts neben Icon, eingeschraenkte Posit.
198 : : WB_BORDER
199 : : WB_NOHIDESELECTION // Selektion inaktiv zeichnen, wenn kein Fokus
200 : : WB_NOHSCROLL
201 : : WB_NOVSCROLL
202 : : WB_NOSELECTION
203 : : WB_SMART_ARRANGE // im Arrange die Vis-Area beibehalten
204 : : WB_ALIGN_TOP // Anordnung zeilenweise von links nach rechts
205 : : WB_ALIGN_LEFT // Anordnung spaltenweise von oben nach unten
206 : : WB_NODRAGSELECTION // Keine Selektion per Tracking-Rect
207 : : WB_NOCOLUMNHEADER // keine Headerbar in Detailsview (Headerbar not implemented)
208 : : WB_NOPOINTERFOCUS // Kein GrabFocus im MouseButtonDown
209 : : WB_HIGHLIGHTFRAME // der unter der Maus befindliche Eintrag wird hervorgehoben
210 : : WB_NOASYNCSELECTHDL // Selektionshandler synchron aufrufen, d.h. Events nicht sammeln
211 : : */
212 : :
213 : : #define WB_ICON WB_RECTSTYLE
214 : : #define WB_SMALLICON WB_SMALLSTYLE
215 : : #define WB_DETAILS WB_VCENTER
216 : : #define WB_NOHSCROLL WB_SPIN
217 : : #define WB_NOVSCROLL WB_DRAG
218 : : #define WB_NOSELECTION WB_REPEAT
219 : : #define WB_NODRAGSELECTION WB_PATHELLIPSIS
220 : : #define WB_SMART_ARRANGE WB_PASSWORD
221 : : #define WB_ALIGN_TOP WB_TOP
222 : : #define WB_ALIGN_LEFT WB_LEFT
223 : : #define WB_NOCOLUMNHEADER WB_CENTER
224 : : #define WB_HIGHLIGHTFRAME WB_INFO
225 : : #define WB_NOASYNCSELECTHDL WB_NOLABEL
226 : :
227 : : class MnemonicGenerator;
228 : :
229 : : class SVT_DLLPUBLIC SvtIconChoiceCtrl : public Control
230 : : {
231 : : friend class SvxIconChoiceCtrl_Impl;
232 : :
233 : : Link _aClickIconHdl;
234 : : Link _aDocRectChangedHdl;
235 : : Link _aVisRectChangedHdl;
236 : : KeyEvent* _pCurKeyEvent;
237 : : SvxIconChoiceCtrl_Impl* _pImp;
238 : : sal_Bool _bAutoFontColor;
239 : :
240 : : protected:
241 : :
242 : : virtual void KeyInput( const KeyEvent& rKEvt );
243 : : virtual sal_Bool EditedEntry( SvxIconChoiceCtrlEntry*, const rtl::OUString& rNewText, sal_Bool bCancelled );
244 : : virtual void DocumentRectChanged();
245 : : virtual void VisibleRectChanged();
246 : : virtual sal_Bool EditingEntry( SvxIconChoiceCtrlEntry* pEntry );
247 : : virtual void Command( const CommandEvent& rCEvt );
248 : : virtual void Paint( const Rectangle& rRect );
249 : : virtual void MouseButtonDown( const MouseEvent& rMEvt );
250 : : virtual void MouseButtonUp( const MouseEvent& rMEvt );
251 : : virtual void MouseMove( const MouseEvent& rMEvt );
252 : : virtual void Resize();
253 : : virtual void GetFocus();
254 : : virtual void LoseFocus();
255 : : virtual void ClickIcon();
256 : : virtual void StateChanged( StateChangedType nType );
257 : : virtual void DataChanged( const DataChangedEvent& rDCEvt );
258 : : virtual void RequestHelp( const HelpEvent& rHEvt );
259 : : virtual void DrawEntryImage(
260 : : SvxIconChoiceCtrlEntry* pEntry,
261 : : const Point& rPos,
262 : : OutputDevice& rDev );
263 : :
264 : : virtual String GetEntryText(
265 : : SvxIconChoiceCtrlEntry* pEntry,
266 : : sal_Bool bInplaceEdit );
267 : :
268 : : virtual void FillLayoutData() const;
269 : :
270 : : void CallImplEventListeners(sal_uLong nEvent, void* pData);
271 : :
272 : : public:
273 : :
274 : : SvtIconChoiceCtrl( Window* pParent, WinBits nWinStyle = WB_ICON | WB_BORDER );
275 : : virtual ~SvtIconChoiceCtrl();
276 : :
277 : : void SetStyle( WinBits nWinStyle );
278 : : WinBits GetStyle() const;
279 : :
280 : : sal_Bool SetChoiceWithCursor ( sal_Bool bDo = sal_True );
281 : :
282 : : void SetFont( const Font& rFont );
283 : : void SetPointFont( const Font& rFont );
284 : :
285 : 0 : void SetClickHdl( const Link& rLink ) { _aClickIconHdl = rLink; }
286 : 0 : const Link& GetClickHdl() const { return _aClickIconHdl; }
287 : :
288 : : using OutputDevice::SetBackground;
289 : : void SetBackground( const Wallpaper& rWallpaper );
290 : :
291 : : void ArrangeIcons();
292 : :
293 : :
294 : : SvxIconChoiceCtrlEntry* InsertEntry( const String& rText,
295 : : const Image& rImage,
296 : : sal_uLong nPos = LIST_APPEND,
297 : : const Point* pPos = 0,
298 : : sal_uInt16 nFlags = 0
299 : : );
300 : :
301 : : /** creates automatic mnemonics for all icon texts in the control
302 : : */
303 : : void CreateAutoMnemonics( void );
304 : :
305 : : /** creates automatic mnemonics for all icon texts in the control
306 : :
307 : : @param _rUsedMnemonics
308 : : a <type>MnemonicGenerator</type> at which some other mnemonics are already registered.
309 : : This can be used if the control needs to share the "mnemonic space" with other elements,
310 : : such as a menu bar.
311 : : */
312 : : void CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics );
313 : :
314 : : sal_Bool DoKeyInput( const KeyEvent& rKEvt );
315 : :
316 : : sal_Bool IsEntryEditing() const;
317 : :
318 : : sal_uLong GetEntryCount() const;
319 : : SvxIconChoiceCtrlEntry* GetEntry( sal_uLong nPos ) const;
320 : : sal_uLong GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const;
321 : : using Window::SetCursor;
322 : : void SetCursor( SvxIconChoiceCtrlEntry* pEntry );
323 : : SvxIconChoiceCtrlEntry* GetCursor() const;
324 : :
325 : : // Neu-Berechnung gecachter View-Daten und Invalidierung im Fenster
326 : : void InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry );
327 : :
328 : : // bHit==sal_False: Eintrag gilt als getroffen, wenn Position im BoundRect liegt
329 : : // ==sal_True : Bitmap oder Text muss getroffen sein
330 : : SvxIconChoiceCtrlEntry* GetEntry( const Point& rPosPixel, sal_Bool bHit = sal_False ) const;
331 : :
332 : : // in dem sal_uLong wird die Position in der Liste des gefunden Eintrags zurueckgegeben
333 : : SvxIconChoiceCtrlEntry* GetSelectedEntry( sal_uLong& rPos ) const;
334 : :
335 : : void SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry = 0 );
336 : :
337 : : virtual sal_Bool HasBackground() const;
338 : : virtual sal_Bool HasFont() const;
339 : : virtual sal_Bool HasFontTextColor() const;
340 : : virtual sal_Bool HasFontFillColor() const;
341 : :
342 : : void SetFontColorToBackground ( sal_Bool bDo = sal_True ) { _bAutoFontColor = bDo; }
343 : 0 : sal_Bool AutoFontColor () { return _bAutoFontColor; }
344 : :
345 : : Point GetPixelPos( const Point& rPosLogic ) const;
346 : : void SetSelectionMode( SelectionMode eMode );
347 : :
348 : : Rectangle GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const;
349 : : Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const;
350 : :
351 : : void SetNoSelection();
352 : :
353 : : // ACCESSIBILITY ==========================================================
354 : :
355 : : /** Creates and returns the accessible object of the Box. */
356 : : virtual ::com::sun::star::uno::Reference<
357 : : ::com::sun::star::accessibility::XAccessible > CreateAccessible();
358 : : };
359 : :
360 : : #endif // _ICNVW_HXX
361 : :
362 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|