1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _SVTREEBOX_HXX 24 #define _SVTREEBOX_HXX 25 26 #include "svtools/svtdllapi.h" 27 #include <svtools/svlbox.hxx> 28 #include <svtools/svlbitm.hxx> 29 30 // forward and defines --------------------------------------------------- 31 32 class SvImpLBox; 33 class SvInplaceEdit; 34 class TabBar; 35 36 #define SV_TAB_BORDER 8 37 38 #define SV_LISTBOX_ID_TREEBOX 1 // fuer SvLBox::IsA() 39 #define SV_ENTRYHEIGHTOFFS_PIXEL 2 40 41 #define TREEFLAG_CHKBTN 0x0001 42 #define TREEFLAG_USESEL 0x0002 43 #define TREEFLAG_MANINS 0x0004 44 #define TREEFLAG_RECALCTABS 0x0008 45 46 #define TREEBOX_ALLITEM_ACCROLE_TYPE_NOTSET 0x00 47 #define TREEBOX_ALLITEM_ACCROLE_TYPE_LIST 0x01 48 #define TREEBOX_ALLITEM_ACCROLE_TYPE_TREE 0x02 49 50 51 typedef sal_Int64 ExtendedWinBits; 52 53 // disable the behavior of automatically selecting a "CurEntry" upon painting the control 54 #define EWB_NO_AUTO_CURENTRY 0x00000001 55 56 // class SvTreeListBox --------------------------------------------------- 57 58 class SVT_DLLPUBLIC SvTreeListBox : public SvLBox 59 { 60 friend class SvImpLBox; 61 friend class ImpLBSelEng; 62 friend class TreeControlPeer; 63 64 SvImpLBox* pImp; 65 Link aCheckButtonHdl; 66 Link aScrolledHdl; 67 Accelerator aInpEditAcc; 68 Image aPrevInsertedExpBmp; 69 Image aPrevInsertedColBmp; 70 Image aCurInsertedExpBmp; 71 Image aCurInsertedColBmp; 72 73 short nContextBmpWidthMax; 74 sal_uInt16 nFirstSelTab, nLastSelTab; 75 short nEntryHeight; 76 short nEntryHeightOffs; 77 short nIndent; 78 short nFocusWidth; 79 sal_uInt16 aContextBmpMode; 80 81 short nAllItemAccRoleType; 82 83 #ifdef _SVTREEBX_CXX 84 DECL_DLLPRIVATE_LINK( CheckButtonClick, SvLBoxButtonData * ); 85 86 SVT_DLLPRIVATE short GetHeightOffset( const Image& rBmp, Size& rLogicSize); 87 SVT_DLLPRIVATE short GetHeightOffset( const Font& rFont, Size& rLogicSize); 88 89 SVT_DLLPRIVATE void SetEntryHeight( SvLBoxEntry* pEntry ); 90 SVT_DLLPRIVATE void AdjustEntryHeight( const Image& rBmp ); 91 SVT_DLLPRIVATE void AdjustEntryHeight( const Font& rFont ); 92 93 SVT_DLLPRIVATE void ImpEntryInserted( SvLBoxEntry* pEntry ); 94 SVT_DLLPRIVATE long PaintEntry1( SvLBoxEntry*, long nLine, 95 sal_uInt16 nTabFlagMask=0xffff, 96 sal_Bool bHasClipRegion=sal_False ); 97 98 SVT_DLLPRIVATE void InitTreeView(); 99 SVT_DLLPRIVATE SvLBoxItem* GetItem_Impl( SvLBoxEntry*, long nX, SvLBoxTab** ppTab, 100 sal_uInt16 nEmptyWidth ); 101 SVT_DLLPRIVATE void ImplInitStyle(); 102 103 #endif 104 105 protected: 106 SvLBoxButtonData* pCheckButtonData; 107 sal_uInt16 nTreeFlags; 108 109 SvLBoxEntry* pEdEntry; 110 SvLBoxItem* pEdItem; 111 112 void EditItemText( SvLBoxEntry* pEntry, SvLBoxString* pItem, 113 const Selection& ); 114 void EditedText( const XubString& ); 115 void EditingRequest( SvLBoxEntry* pEntry, SvLBoxItem* pItem, 116 const Point& rMousePos ); 117 118 SvPtrarr aTabs; 119 120 // berechnet abhaengig von TreeList-Style & Bitmap-Groessen 121 // alle Tabulatoren neu; wird beim Einfuegen/Austauschen von 122 // Bitmaps, beim Wechsel des Models usw. automatisch gerufen 123 virtual void SetTabs(); 124 void SetTabs_Impl(); 125 void AddTab( long nPos,sal_uInt16 nFlags=SV_LBOXTAB_ADJUST_LEFT, 126 void* pUserData = 0 ); TabCount() const127 sal_uInt16 TabCount() const { return aTabs.Count(); } 128 SvLBoxTab* GetFirstDynamicTab() const; 129 SvLBoxTab* GetFirstDynamicTab( sal_uInt16& rTabPos ) const; 130 SvLBoxTab* GetFirstTab( sal_uInt16 nFlagMask, sal_uInt16& rTabPos ); 131 SvLBoxTab* GetLastTab( sal_uInt16 nFlagMask, sal_uInt16& rTabPos ); 132 SvLBoxTab* GetTab( SvLBoxEntry*, SvLBoxItem* ) const; 133 void ClearTabList(); 134 135 virtual void InitEntry(SvLBoxEntry*,const XubString&,const Image&,const Image&,SvLBoxButtonKind); 136 137 virtual void NotifyBeginScroll(); 138 virtual void NotifyEndScroll(); 139 // nLines == 0 => horizontales Scrolling 140 virtual void NotifyScrolling( long nLines ); 141 virtual void NotifyScrolled(); SetScrolledHdl(const Link & rLink)142 void SetScrolledHdl( const Link& rLink ) { aScrolledHdl = rLink; } GetScrolledHdl() const143 const Link& GetScrolledHdl() const { return aScrolledHdl; } GetXOffset() const144 long GetXOffset() const { return GetMapMode().GetOrigin().X(); } 145 146 // wird aufgerufen, _bevor_ Bereiche im Control invalidiert werden, 147 // kann zum Hiden von Elementen benutzt werden, die von aussen 148 // in das Control hineingezeichnet werden 149 virtual void NotifyInvalidating(); 150 151 virtual sal_uLong GetAscInsertionPos( SvLBoxEntry*, SvLBoxEntry* pParent ); 152 virtual sal_uLong GetDescInsertionPos( SvLBoxEntry*, SvLBoxEntry* pParent ); 153 virtual void Command( const CommandEvent& rCEvt ); 154 155 virtual void RequestHelp( const HelpEvent& rHEvt ); 156 virtual void CursorMoved( SvLBoxEntry* pNewCursor ); 157 virtual void PreparePaint( SvLBoxEntry* ); 158 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 159 virtual void StateChanged( StateChangedType nStateChange ); 160 161 void InitSettings(sal_Bool bFont,sal_Bool bForeground,sal_Bool bBackground); 162 sal_Bool IsCellFocusEnabled() const; 163 bool SetCurrentTabPos( sal_uInt16 _nNewPos ); 164 sal_uInt16 GetCurrentTabPos() const; 165 void CallImplEventListeners(sal_uLong nEvent, void* pData); 166 167 void ImplEditEntry( SvLBoxEntry* pEntry ); 168 169 sal_Bool AreChildrenTransient() const; 170 void SetChildrenNotTransient(); 171 172 public: 173 SvTreeListBox( Window* pParent, WinBits nWinStyle=0 ); 174 SvTreeListBox( Window* pParent, const ResId& rResId ); 175 ~SvTreeListBox(); 176 177 void SetExtendedWinBits( ExtendedWinBits _nBits ); 178 ExtendedWinBits GetExtendedWinBits() const; 179 180 void DisconnectFromModel(); 181 182 void EnableCheckButton( SvLBoxButtonData* ); 183 void SetCheckButtonData( SvLBoxButtonData* ); 184 void SetNodeBitmaps( const Image& rCollapsedNodeBmp, const Image& rExpandedNodeBmp, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 185 void SetDontKnowNodeBitmap( const Image& rDontKnowBmp, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 186 187 /** returns the default image which clients should use for expanded nodes, to have a consistent user 188 interface experience in the whole product. 189 */ 190 static const Image& GetDefaultExpandedNodeImage( BmpColorMode _eMode = BMP_COLOR_NORMAL ); 191 192 /** returns the default image which clients should use for expanded nodes, to have a consistent user 193 interface experience in the whole product. 194 */ 195 static const Image& GetDefaultCollapsedNodeImage( BmpColorMode _eMode = BMP_COLOR_NORMAL ); 196 197 /** sets default bitmaps for collapsed and expanded nodes. 198 */ SetNodeDefaultImages()199 inline void SetNodeDefaultImages( ) 200 { 201 SetNodeBitmaps( GetDefaultCollapsedNodeImage( BMP_COLOR_NORMAL ), GetDefaultExpandedNodeImage( BMP_COLOR_NORMAL ), BMP_COLOR_NORMAL ); 202 SetNodeBitmaps( GetDefaultCollapsedNodeImage( BMP_COLOR_HIGHCONTRAST ), GetDefaultExpandedNodeImage( BMP_COLOR_HIGHCONTRAST ), BMP_COLOR_HIGHCONTRAST ); 203 } 204 205 virtual SvLBoxEntry* InsertEntry( const XubString& rText, SvLBoxEntry* pParent = 0, 206 sal_Bool bChildsOnDemand = sal_False, 207 sal_uLong nPos=LIST_APPEND, void* pUserData = 0, 208 SvLBoxButtonKind eButtonKind = SvLBoxButtonKind_enabledCheckbox ); 209 210 virtual SvLBoxEntry* InsertEntry( const XubString& rText, 211 const Image& rExpandedEntryBmp, 212 const Image& rCollapsedEntryBmp, 213 SvLBoxEntry* pParent = 0, 214 sal_Bool bChildsOnDemand = sal_False, 215 sal_uLong nPos = LIST_APPEND, void* pUserData = 0, 216 SvLBoxButtonKind eButtonKind = SvLBoxButtonKind_enabledCheckbox ); 217 218 const Image& GetDefaultExpandedEntryBmp( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 219 const Image& GetDefaultCollapsedEntryBmp( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 220 221 void SetDefaultExpandedEntryBmp( const Image& rBmp, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 222 void SetDefaultCollapsedEntryBmp( const Image& rBmp, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 223 224 void SetCheckButtonState( SvLBoxEntry*, SvButtonState ); 225 SvButtonState GetCheckButtonState( SvLBoxEntry* ) const; 226 227 void ShowExpandBitmapOnCursor( sal_Bool ); IsExpandBitmapOnCursor() const228 sal_Bool IsExpandBitmapOnCursor() const { return (sal_Bool)(aContextBmpMode & SVLISTENTRYFLAG_FOCUSED)!=0; } 229 230 void SetEntryText(SvLBoxEntry*, const XubString& ); 231 void SetExpandedEntryBmp( SvLBoxEntry* _pEntry, const Image& _rImage, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 232 void SetCollapsedEntryBmp( SvLBoxEntry* _pEntry, const Image& _rImage, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 233 234 virtual String GetEntryText( SvLBoxEntry* pEntry ) const; 235 String SearchEntryText( SvLBoxEntry* pEntry ) const; 236 const Image& GetExpandedEntryBmp(SvLBoxEntry* _pEntry, BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 237 const Image& GetCollapsedEntryBmp(SvLBoxEntry* _pEntry, BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 238 SetCheckButtonHdl(const Link & rLink)239 void SetCheckButtonHdl( const Link& rLink ) { aCheckButtonHdl=rLink; } GetCheckButtonHdl() const240 Link GetCheckButtonHdl() const { return aCheckButtonHdl; } 241 virtual void CheckButtonHdl(); 242 243 virtual SvLBoxEntry* CloneEntry( SvLBoxEntry* pSource ); 244 245 virtual sal_uInt16 IsA(); 246 247 void SetSublistOpenWithReturn( sal_Bool bMode = sal_True ); // open/close sublist with return/enter 248 sal_Bool IsSublistOpenWithReturn() const; 249 void SetSublistOpenWithLeftRight( sal_Bool bMode = sal_True ); // open/close sublist with cursor left/right 250 sal_Bool IsSublistOpenWithLeftRight() const; 251 252 void EnableInplaceEditing( sal_Bool bEnable ); IsInplaceEditingEnabled() const253 sal_Bool IsInplaceEditingEnabled() const { return SvLBox::IsInplaceEditingEnabled(); } ForbidEmptyText()254 inline void ForbidEmptyText() { SvLBox::ForbidEmptyText(); } 255 // Editiert das erste StringItem des Entries, 0==Cursor 256 void EditEntry( SvLBoxEntry* pEntry = NULL ); 257 void CancelEditing(); 258 virtual sal_Bool EditingEntry( SvLBoxEntry* pEntry, Selection& ); 259 virtual sal_Bool EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText ); IsEditingActive() const260 sal_Bool IsEditingActive() const { return SvLBox::IsEditingActive(); } EndEditing(sal_Bool bCancel=sal_False)261 void EndEditing( sal_Bool bCancel = sal_False ) { SvLBox::EndEditing( bCancel ); } EditingCanceled() const262 sal_Bool EditingCanceled() const { return SvLBox::EditingCanceled(); } 263 264 virtual void RequestingChilds( SvLBoxEntry* pParent ); 265 266 virtual void Paint( const Rectangle& rRect ); 267 virtual void MouseButtonDown( const MouseEvent& rMEvt ); 268 virtual void MouseButtonUp( const MouseEvent& rMEvt ); 269 virtual void MouseMove( const MouseEvent& rMEvt ); 270 virtual void KeyInput( const KeyEvent& rKEvt ); 271 virtual void Resize(); 272 virtual void GetFocus(); 273 virtual void LoseFocus(); 274 void SetUpdateMode( sal_Bool ); 275 // aktualisiert nicht die vertikale ScrollBar 276 void SetUpdateModeFast( sal_Bool ); 277 278 using SvListView::SetModel; 279 void SetModel( SvLBoxTreeList* ); 280 virtual void ModelHasCleared(); 281 virtual void ModelHasInserted( SvListEntry* pEntry ); 282 virtual void ModelHasInsertedTree( SvListEntry* pEntry ); 283 virtual void ModelIsMoving(SvListEntry* pSource, 284 SvListEntry* pTargetParent, sal_uLong nChildPos ); 285 virtual void ModelHasMoved(SvListEntry* pSource ); 286 virtual void ModelIsRemoving( SvListEntry* pEntry ); 287 virtual void ModelHasRemoved( SvListEntry* pEntry ); 288 virtual void ModelHasEntryInvalidated( SvListEntry* pEntry ); 289 290 void ShowTargetEmphasis( SvLBoxEntry*, sal_Bool bShow ); 291 using Window::GetDropTarget; 292 SvLBoxEntry* GetDropTarget( const Point& ); 293 void ScrollOutputArea( short nDeltaEntries ); 294 GetEntryHeight() const295 short GetEntryHeight() const { return nEntryHeight; } 296 void SetEntryHeight( short nHeight, sal_Bool bAlways = sal_False ); 297 Size GetOutputSizePixel() const; GetIndent() const298 short GetIndent() const { return nIndent; } 299 void SetIndent( short nIndent ); 300 void SetSpaceBetweenEntries( short nSpace ); GetSpaceBetweenEntries() const301 short GetSpaceBetweenEntries() const {return nEntryHeightOffs;} 302 Point GetEntryPosition( SvLBoxEntry* ) const; 303 void ShowEntry( SvLBoxEntry* ); // !!!OBSOLETE, use MakeVisible 304 virtual void MakeVisible( SvLBoxEntry* ); 305 void MakeVisible( SvLBoxEntry*, sal_Bool bMoveToTop ); 306 307 void SetCollapsedNodeBmp( const Image&, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 308 void SetExpandedNodeBmp( const Image&, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 309 Image GetCollapsedNodeBmp( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 310 Image GetExpandedNodeBmp( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 311 312 void SetFont( const Font& rFont ); 313 314 using Window::SetCursor; 315 void SetCursor( SvLBoxEntry* pEntry, sal_Bool bForceNoSelect = sal_False ); 316 317 SvLBoxEntry* GetEntry( const Point& rPos, sal_Bool bHit = sal_False ) const; GetEntry(SvLBoxEntry * pParent,sal_uLong nPos) const318 SvLBoxEntry* GetEntry( SvLBoxEntry* pParent, sal_uLong nPos ) const { return SvLBox::GetEntry(pParent,nPos); } GetEntry(sal_uLong nRootPos) const319 SvLBoxEntry* GetEntry( sal_uLong nRootPos ) const { return SvLBox::GetEntry(nRootPos);} 320 321 void PaintEntry( SvLBoxEntry* ); 322 long PaintEntry( SvLBoxEntry*, long nLine, 323 sal_uInt16 nTabFlagMask=0xffff ); 324 virtual Rectangle GetFocusRect( SvLBoxEntry*, long nLine ); 325 // Beruecksichtigt Einrueckung 326 virtual long GetTabPos( SvLBoxEntry*, SvLBoxTab* ); 327 void InvalidateEntry( SvLBoxEntry* ); 328 SvLBoxItem* GetItem( SvLBoxEntry*, long nX, SvLBoxTab** ppTab); 329 SvLBoxItem* GetItem( SvLBoxEntry*, long nX ); 330 SvLBoxItem* GetFirstDynamicItem( SvLBoxEntry* pEntry ); 331 332 void SetDragDropMode( DragDropMode ); 333 void SetSelectionMode( SelectionMode ); 334 void SetAddMode( sal_Bool bAdd ); 335 sal_Bool IsAddMode() const; 336 337 virtual sal_Bool Expand( SvLBoxEntry* pParent ); 338 virtual sal_Bool Collapse( SvLBoxEntry* pParent ); 339 virtual sal_Bool Select( SvLBoxEntry* pEntry, sal_Bool bSelect=sal_True ); 340 virtual sal_uLong SelectChilds( SvLBoxEntry* pParent, sal_Bool bSelect ); 341 virtual void SelectAll( sal_Bool bSelect, sal_Bool bPaint = sal_True ); 342 virtual void SetCurEntry( SvLBoxEntry* _pEntry ); 343 virtual SvLBoxEntry* 344 GetCurEntry() const; 345 346 using Window::Invalidate; 347 virtual void Invalidate( sal_uInt16 nFlags = 0); 348 virtual void Invalidate( const Rectangle&, sal_uInt16 nFlags = 0 ); 349 350 void SetHighlightRange(sal_uInt16 nFirstTab=0,sal_uInt16 nLastTab=0xffff); 351 void RemoveHighlightRange(); 352 353 virtual Region GetDragRegion() const; 354 355 // Childs des Parents werden Childs des naechstoberen Parents 356 void RemoveParentKeepChilds( SvLBoxEntry* pParent ); 357 358 DECL_LINK( DefaultCompare, SvSortData* ); 359 virtual void ModelNotification( sal_uInt16 nActionId, SvListEntry* pEntry1, 360 SvListEntry* pEntry2, sal_uLong nPos ); 361 362 long GetTextOffset() const; 363 void EndSelection(); 364 sal_Bool IsNodeButton( const Point& rPos ) const; 365 void RepaintScrollBars() const; 366 ScrollBar* GetVScroll(); 367 ScrollBar* GetHScroll(); 368 void EnableAsyncDrag( sal_Bool b ); 369 370 SvLBoxEntry* GetFirstEntryInView() const; 371 SvLBoxEntry* GetNextEntryInView(SvLBoxEntry*) const; 372 373 void ShowFocusRect( const SvLBoxEntry* pEntry ); 374 void SetTabBar( TabBar* pTabBar ); 375 void InitStartEntry(); 376 377 // reset all what could lead to editingText in e.g. a contextmenu call 378 void CancelPendingEdit(); 379 380 virtual PopupMenu* CreateContextMenu( void ); 381 virtual void ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ); 382 383 void EnableContextMenuHandling( void ); 384 void EnableContextMenuHandling( sal_Bool bEnable ); 385 sal_Bool IsContextMenuHandlingEnabled( void ) const; 386 387 void EnableList( bool _bEnable ); 388 389 // ACCESSIBILITY ========================================================== 390 391 /** Creates and returns the accessible object of the Box. */ 392 virtual ::com::sun::star::uno::Reference< 393 ::com::sun::star::accessibility::XAccessible > CreateAccessible(); 394 395 /** Fills the StateSet with all states (except DEFUNC, done by the accessible object). */ 396 virtual void FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& rStateSet ) const; 397 398 /** Fills the StateSet of one entry. */ 399 virtual void FillAccessibleEntryStateSet( SvLBoxEntry* pEntry, ::utl::AccessibleStateSetHelper& rStateSet ) const; 400 401 /** Calculate and returns the bounding rectangle of an entry. 402 @param pEntry 403 The entry. 404 @return The bounding rectangle of an entry. */ 405 virtual Rectangle GetBoundingRect( SvLBoxEntry* pEntry ); 406 407 /** Enables, that one cell of a tablistbox entry can be focused */ 408 void EnableCellFocus(); 409 410 // For overwriting accessible role for all entries - normally 0, so each entry can be different SetAllEntriesAccessibleRoleType(short n)411 void SetAllEntriesAccessibleRoleType( short n ) { nAllItemAccRoleType = n; } GetAllEntriesAccessibleRoleType() const412 short GetAllEntriesAccessibleRoleType() const { return nAllItemAccRoleType; } 413 GetTreeFlags() const414 sal_uInt16 GetTreeFlags() const {return nTreeFlags;} 415 416 XubString headString ; 417 String SearchEntryTextWithHeadTitle( SvLBoxEntry* pEntry ) ; 418 virtual String GetEntryAltText( SvLBoxEntry* pEntry) const; 419 virtual String GetEntryLongDescription( SvLBoxEntry* pEntry) const; 420 421 protected: 422 using SvListView::Expand; 423 using SvListView::Collapse; 424 using SvListView::Select; 425 using SvListView::SelectChilds; 426 using SvListView::SelectAll; 427 }; 428 429 #endif 430 431