1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ivctrl.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include "svtools/svtdllapi.h"
35 #include <tools/string.hxx>
36 #include <vcl/ctrl.hxx>
37 #include <tools/link.hxx>
38 #include <vcl/image.hxx>
39 #include <vcl/seleng.hxx>
44 class SvxIconChoiceCtrl_Impl
;
47 #define ICNVIEW_FLAG_POS_LOCKED 0x0001
48 #define ICNVIEW_FLAG_SELECTED 0x0002
49 #define ICNVIEW_FLAG_FOCUSED 0x0004
50 #define ICNVIEW_FLAG_IN_USE 0x0008
51 #define ICNVIEW_FLAG_CURSORED 0x0010 // Rahmen um Image
52 #define ICNVIEW_FLAG_POS_MOVED 0x0020 // per D&D verschoben aber nicht gelockt
53 #define ICNVIEW_FLAG_DROP_TARGET 0x0040 // im QueryDrop gesetzt
54 #define ICNVIEW_FLAG_BLOCK_EMPHASIS 0x0080 // Emphasis nicht painten
55 #define ICNVIEW_FLAG_USER1 0x0100
56 #define ICNVIEW_FLAG_USER2 0x0200
57 #define ICNVIEW_FLAG_PRED_SET 0x0400 // Predecessor wurde umgesetzt
59 enum SvxIconChoiceCtrlTextMode
61 IcnShowTextFull
= 1, // BoundRect nach unten aufplustern
62 IcnShowTextShort
, // Abkuerzung mit "..."
63 IcnShowTextSmart
, // Text komplett anzeigen, wenn moeglich (n.i.)
64 IcnShowTextDontKnow
// Einstellung der View
67 enum SvxIconChoiceCtrlPositionMode
69 IcnViewPositionModeFree
= 0, // freies pixelgenaues Positionieren
70 IcnViewPositionModeAutoArrange
= 1, // automatisches Ausrichten
71 IcnViewPositionModeAutoAdjust
= 2, // automatisches Anordnen
72 IcnViewPositionModeLast
= IcnViewPositionModeAutoAdjust
75 class SvxIconChoiceCtrlEntry
81 String aQuickHelpText
;
84 friend class SvxIconChoiceCtrl_Impl
;
85 friend class IcnCursor_Impl
;
86 friend class EntryList_Impl
;
87 friend class IcnGridMap_Impl
;
89 Rectangle aRect
; // Bounding-Rect des Entries
90 Rectangle aGridRect
; // nur gesetzt im Grid-Modus
93 // die Eintragsposition in der Eintragsliste entspricht der beim Insert vorgegebenen
94 // [Sortier-]Reihenfolge (->Reihenfolge der Anker in der Ankerliste!). Im AutoArrange-Modus
95 // kann die sichtbare Reihenfolge aber anders sein. Die Eintraege werden deshalb dann
97 SvxIconChoiceCtrlEntry
* pblink
; // backward (linker Nachbar)
98 SvxIconChoiceCtrlEntry
* pflink
; // forward (rechter Nachbar)
100 SvxIconChoiceCtrlTextMode eTextMode
;
101 USHORT nX
,nY
; // fuer Tastatursteuerung
104 void ClearFlags( USHORT nMask
) { nFlags
&= (~nMask
); }
105 void SetFlags( USHORT nMask
) { nFlags
|= nMask
; }
106 void AssignFlags( USHORT _nFlags
) { nFlags
= _nFlags
; }
108 // setzt den linken Nachbarn (A <-> B ==> A <-> this <-> B)
109 void SetBacklink( SvxIconChoiceCtrlEntry
* pA
)
111 pA
->pflink
->pblink
= this; // X <- B
112 this->pflink
= pA
->pflink
; // X -> B
113 this->pblink
= pA
; // A <- X
114 pA
->pflink
= this; // A -> X
116 // loest eine Verbindung (A <-> this <-> B ==> A <-> B)
119 this->pblink
->pflink
= this->pflink
;
120 this->pflink
->pblink
= this->pblink
;
126 SvxIconChoiceCtrlEntry( USHORT nFlags
= 0 );
127 SvxIconChoiceCtrlEntry( const String
& rText
, const Image
& rImage
, USHORT nFlags
= 0 );
128 SvxIconChoiceCtrlEntry( const String
& rText
, const Image
& rImage
, const Image
& rImageHC
, USHORT nFlags
= 0 );
129 ~SvxIconChoiceCtrlEntry () {}
131 void SetImage ( const Image
& rImage
) { aImage
= rImage
; }
132 void SetImageHC ( const Image
& rImage
) { aImageHC
= rImage
; }
133 Image
GetImage () const { return aImage
; }
134 Image
GetImageHC () const { return aImageHC
; }
135 void SetText ( const String
& rText
) { aText
= rText
; }
136 String
GetText () const { return aText
; }
137 String SVT_DLLPUBLIC
GetDisplayText() const;
138 void SetQuickHelpText( const String
& rText
) { aQuickHelpText
= rText
; }
139 String
GetQuickHelpText() const { return aQuickHelpText
; }
140 void SetUserData ( void* _pUserData
) { pUserData
= _pUserData
; }
141 void* GetUserData () { return pUserData
; }
143 const Rectangle
& GetBoundRect() const { return aRect
; }
145 void SetFocus ( BOOL bSet
)
146 { nFlags
= ( bSet
? nFlags
| ICNVIEW_FLAG_FOCUSED
: nFlags
& ~ICNVIEW_FLAG_FOCUSED
); }
148 SvxIconChoiceCtrlTextMode
GetTextMode() const { return eTextMode
; }
149 USHORT
GetFlags() const { return nFlags
; }
150 BOOL
IsSelected() const { return (BOOL
)((nFlags
& ICNVIEW_FLAG_SELECTED
) !=0); }
151 BOOL
IsFocused() const { return (BOOL
)((nFlags
& ICNVIEW_FLAG_FOCUSED
) !=0); }
152 BOOL
IsInUse() const { return (BOOL
)((nFlags
& ICNVIEW_FLAG_IN_USE
) !=0); }
153 BOOL
IsCursored() const { return (BOOL
)((nFlags
& ICNVIEW_FLAG_CURSORED
) !=0); }
154 BOOL
IsDropTarget() const { return (BOOL
)((nFlags
& ICNVIEW_FLAG_DROP_TARGET
) !=0); }
155 BOOL
IsBlockingEmphasis() const { return (BOOL
)((nFlags
& ICNVIEW_FLAG_BLOCK_EMPHASIS
) !=0); }
156 BOOL
WasMoved() const { return (BOOL
)((nFlags
& ICNVIEW_FLAG_POS_MOVED
) !=0); }
157 void SetMoved( BOOL bMoved
);
158 BOOL
IsPosLocked() const { return (BOOL
)((nFlags
& ICNVIEW_FLAG_POS_LOCKED
) !=0); }
159 void LockPos( BOOL bLock
);
160 // Nur bei AutoArrange gesetzt. Den Kopf der Liste gibts per SvxIconChoiceCtrl::GetPredecessorHead
161 SvxIconChoiceCtrlEntry
* GetSuccessor() const { return pflink
; }
162 SvxIconChoiceCtrlEntry
* GetPredecessor() const { return pblink
; }
164 // sal_Unicode GetMnemonicChar() const;
167 enum SvxIconChoiceCtrlColumnAlign
169 IcnViewAlignLeft
= 1,
174 class SvxIconChoiceCtrlColumnInfo
179 SvxIconChoiceCtrlColumnAlign eAlignment
;
183 SvxIconChoiceCtrlColumnInfo( USHORT nSub
, long nWd
,
184 SvxIconChoiceCtrlColumnAlign eAlign
) :
185 nWidth( nWd
), eAlignment( eAlign
), nSubItem( nSub
) {}
186 SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo
& );
188 void SetText( const String
& rText
) { aColText
= rText
; }
189 void SetImage( const Image
& rImg
) { aColImage
= rImg
; }
190 void SetWidth( long nWd
) { nWidth
= nWd
; }
191 void SetAlignment( SvxIconChoiceCtrlColumnAlign eAlign
) { eAlignment
= eAlign
; }
192 void SetSubItem( USHORT nSub
) { nSubItem
= nSub
; }
194 const String
& GetText() const { return aColText
; }
195 const Image
& GetImage() const { return aColImage
; }
196 long GetWidth() const { return nWidth
; }
197 SvxIconChoiceCtrlColumnAlign
GetAlignment() const { return eAlignment
; }
198 USHORT
GetSubItem() const { return nSubItem
; }
201 //###################################################################################################################################
204 WB_ICON // Text unter dem Icon
205 WB_SMALL_ICON // Text rechts neben Icon, beliebige Positionierung
206 WB_DETAILS // Text rechts neben Icon, eingeschraenkte Posit.
208 WB_NOHIDESELECTION // Selektion inaktiv zeichnen, wenn kein Fokus
212 WB_SMART_ARRANGE // im Arrange die Vis-Area beibehalten
213 WB_ALIGN_TOP // Anordnung zeilenweise von links nach rechts
214 WB_ALIGN_LEFT // Anordnung spaltenweise von oben nach unten
215 WB_NODRAGSELECTION // Keine Selektion per Tracking-Rect
216 WB_NOCOLUMNHEADER // keine Headerbar in Detailsview (Headerbar not implemented)
217 WB_NOPOINTERFOCUS // Kein GrabFocus im MouseButtonDown
218 WB_HIGHLIGHTFRAME // der unter der Maus befindliche Eintrag wird hervorgehoben
219 WB_NOASYNCSELECTHDL // Selektionshandler synchron aufrufen, d.h. Events nicht sammeln
222 #define WB_ICON WB_RECTSTYLE
223 #define WB_SMALLICON WB_SMALLSTYLE
224 #define WB_DETAILS WB_VCENTER
225 #define WB_NOHSCROLL WB_SPIN
226 #define WB_NOVSCROLL WB_DRAG
227 #define WB_NOSELECTION WB_REPEAT
228 #define WB_NODRAGSELECTION WB_PATHELLIPSIS
229 #define WB_SMART_ARRANGE WB_PASSWORD
230 #define WB_ALIGN_TOP WB_TOP
231 #define WB_ALIGN_LEFT WB_LEFT
232 #define WB_NOCOLUMNHEADER WB_CENTER
233 #define WB_HIGHLIGHTFRAME WB_INFO
234 #define WB_NOASYNCSELECTHDL WB_NOLABEL
236 class MnemonicGenerator
;
238 class SVT_DLLPUBLIC SvtIconChoiceCtrl
: public Control
240 friend class SvxIconChoiceCtrl_Impl
;
243 Link _aDocRectChangedHdl
;
244 Link _aVisRectChangedHdl
;
245 KeyEvent
* _pCurKeyEvent
;
246 SvxIconChoiceCtrl_Impl
* _pImp
;
247 BOOL _bAutoFontColor
;
251 virtual void KeyInput( const KeyEvent
& rKEvt
);
252 virtual BOOL
EditedEntry( SvxIconChoiceCtrlEntry
*, const XubString
& rNewText
, BOOL bCancelled
);
253 virtual void DocumentRectChanged();
254 virtual void VisibleRectChanged();
255 virtual BOOL
EditingEntry( SvxIconChoiceCtrlEntry
* pEntry
);
256 virtual void Command( const CommandEvent
& rCEvt
);
257 virtual void Paint( const Rectangle
& rRect
);
258 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
259 virtual void MouseButtonUp( const MouseEvent
& rMEvt
);
260 virtual void MouseMove( const MouseEvent
& rMEvt
);
261 virtual void Resize();
262 virtual void GetFocus();
263 virtual void LoseFocus();
264 virtual void ClickIcon();
265 virtual void StateChanged( StateChangedType nType
);
266 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
267 virtual void RequestHelp( const HelpEvent
& rHEvt
);
268 virtual void DrawEntryImage(
269 SvxIconChoiceCtrlEntry
* pEntry
,
271 OutputDevice
& rDev
);
273 virtual String
GetEntryText(
274 SvxIconChoiceCtrlEntry
* pEntry
,
277 virtual void FillLayoutData() const;
279 void CallImplEventListeners(ULONG nEvent
, void* pData
);
283 SvtIconChoiceCtrl( Window
* pParent
, WinBits nWinStyle
= WB_ICON
| WB_BORDER
);
284 SvtIconChoiceCtrl( Window
* pParent
, const ResId
& rResId
);
285 virtual ~SvtIconChoiceCtrl();
287 void SetStyle( WinBits nWinStyle
);
288 WinBits
GetStyle() const;
290 BOOL
SetChoiceWithCursor ( BOOL bDo
= TRUE
);
292 void SetUpdateMode( BOOL bUpdateMode
);
293 void SetFont( const Font
& rFont
);
294 void SetPointFont( const Font
& rFont
);
296 void SetClickHdl( const Link
& rLink
) { _aClickIconHdl
= rLink
; }
297 const Link
& GetClickHdl() const { return _aClickIconHdl
; }
299 using OutputDevice::SetBackground
;
300 void SetBackground( const Wallpaper
& rWallpaper
);
305 SvxIconChoiceCtrlEntry
* InsertEntry( ULONG nPos
= LIST_APPEND
,
306 const Point
* pPos
= 0,
308 SvxIconChoiceCtrlEntry
* InsertEntry( const String
& rText
, const Image
& rImage
,
309 ULONG nPos
= LIST_APPEND
,
310 const Point
* pPos
= 0,
312 SvxIconChoiceCtrlEntry
* InsertEntry( const String
& rText
, const Image
& rImage
, const Image
& rImageHC
,
313 ULONG nPos
= LIST_APPEND
,
314 const Point
* pPos
= 0,
317 /** creates automatic mnemonics for all icon texts in the control
319 void CreateAutoMnemonics( void );
321 /** creates automatic mnemonics for all icon texts in the control
323 @param _rUsedMnemonics
324 a <type>MnemonicGenerator</type> at which some other mnemonics are already registered.
325 This can be used if the control needs to share the "mnemonic space" with other elements,
328 void CreateAutoMnemonics( MnemonicGenerator
& _rUsedMnemonics
);
330 void RemoveEntry( SvxIconChoiceCtrlEntry
* pEntry
);
332 BOOL
DoKeyInput( const KeyEvent
& rKEvt
);
334 BOOL
IsEntryEditing() const;
337 ULONG
GetEntryCount() const;
338 SvxIconChoiceCtrlEntry
* GetEntry( ULONG nPos
) const;
339 ULONG
GetEntryListPos( SvxIconChoiceCtrlEntry
* pEntry
) const;
340 using Window::SetCursor
;
341 void SetCursor( SvxIconChoiceCtrlEntry
* pEntry
);
342 SvxIconChoiceCtrlEntry
* GetCursor() const;
344 // Neu-Berechnung gecachter View-Daten und Invalidierung im Fenster
345 void InvalidateEntry( SvxIconChoiceCtrlEntry
* pEntry
);
347 // bHit==FALSE: Eintrag gilt als getroffen, wenn Position im BoundRect liegt
348 // ==TRUE : Bitmap oder Text muss getroffen sein
349 SvxIconChoiceCtrlEntry
* GetEntry( const Point
& rPosPixel
, BOOL bHit
= FALSE
) const;
350 // Gibt den naechsten ueber pCurEntry liegenden Eintrag (ZOrder)
351 SvxIconChoiceCtrlEntry
* GetNextEntry( const Point
& rPosPixel
, SvxIconChoiceCtrlEntry
* pCurEntry
, BOOL
) const;
352 // Gibt den naechsten unter pCurEntry liegenden Eintrag (ZOrder)
353 SvxIconChoiceCtrlEntry
* GetPrevEntry( const Point
& rPosPixel
, SvxIconChoiceCtrlEntry
* pCurEntry
, BOOL
) const;
355 // in dem ULONG wird die Position in der Liste des gefunden Eintrags zurueckgegeben
356 SvxIconChoiceCtrlEntry
* GetSelectedEntry( ULONG
& rPos
) const;
358 void SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode
, SvxIconChoiceCtrlEntry
* pEntry
= 0 );
359 SvxIconChoiceCtrlTextMode
GetEntryTextMode( const SvxIconChoiceCtrlEntry
* pEntry
= 0 ) const;
361 // offene asynchron abzuarbeitende Aktionen ausfuehren. Muss vor dem Speichern von
362 // Eintragspositionen etc. gerufen werden
366 virtual BOOL
HasBackground() const;
367 virtual BOOL
HasFont() const;
368 virtual BOOL
HasFontTextColor() const;
369 virtual BOOL
HasFontFillColor() const;
371 void SetFontColorToBackground ( BOOL bDo
= TRUE
) { _bAutoFontColor
= bDo
; }
372 BOOL
AutoFontColor () { return _bAutoFontColor
; }
374 Point
GetLogicPos( const Point
& rPosPixel
) const;
375 Point
GetPixelPos( const Point
& rPosLogic
) const;
376 void SetSelectionMode( SelectionMode eMode
);
378 BOOL
HandleShortCutKey( const KeyEvent
& rKeyEvent
);
380 Rectangle
GetBoundingBox( SvxIconChoiceCtrlEntry
* pEntry
) const;
381 Rectangle
GetEntryCharacterBounds( const sal_Int32 _nEntryPos
, const sal_Int32 _nCharacterIndex
) const;
383 void SetNoSelection();
385 // ACCESSIBILITY ==========================================================
387 /** Creates and returns the accessible object of the Box. */
388 virtual ::com::sun::star::uno::Reference
<
389 ::com::sun::star::accessibility::XAccessible
> CreateAccessible();