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