1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #ifndef INCLUDED_VCL_TREELISTBOX_HXX 21 #define INCLUDED_VCL_TREELISTBOX_HXX 22 23 #include <vcl/dllapi.h> 24 25 #include <deque> 26 #include <memory> 27 #include <vector> 28 29 #include <vcl/ctrl.hxx> 30 #include <vcl/accel.hxx> 31 #include <vcl/mnemonicengine.hxx> 32 #include <vcl/quickselectionengine.hxx> 33 #include <vcl/image.hxx> 34 #include <tools/gen.hxx> 35 #include <tools/contnr.hxx> 36 #include <vcl/treelist.hxx> 37 #include <vcl/transfer.hxx> 38 #include <vcl/idle.hxx> 39 #include <vcl/menu.hxx> 40 #include <o3tl/typed_flags_set.hxx> 41 42 class SvTreeListBox; 43 class SvTreeListEntry; 44 struct SvViewDataItem; 45 class SvViewDataEntry; 46 class SvInplaceEdit2; 47 class SvLBoxString; 48 class SvImpLBox; 49 class SvLBoxButtonData; 50 class Timer; 51 class Edit; 52 53 namespace utl { 54 class AccessibleStateSetHelper; 55 } 56 57 enum class SvButtonState { Unchecked, Checked, Tristate }; 58 59 // ********************************************************************* 60 // *************************** Tabulators ****************************** 61 // ********************************************************************* 62 63 enum class SvLBoxTabFlags 64 { 65 NONE = 0x0000, 66 DYNAMIC = 0x0001, // Item's output column changes according to the Child Depth 67 ADJUST_RIGHT = 0x0002, // Item's right margin at the tabulator 68 ADJUST_LEFT = 0x0004, // Left margin 69 ADJUST_CENTER = 0x0008, // Center the item at the tabulator 70 71 SHOW_SELECTION = 0x0010, // Visualize selection state 72 // Item needs to be able to return the surrounding polygon (D'n'D cursor) 73 EDITABLE = 0x0020, // Item editable at the tabulator 74 FORCE = 0x0040, // Switch off the default calculation of the first tabulator 75 // (on which Abo Tabpage/Extras/Option/Customize, etc. rely on) 76 // The first tab's position corresponds precisely to the Flags set 77 // and column widths 78 }; 79 namespace o3tl 80 { 81 template<> struct typed_flags<SvLBoxTabFlags> : is_typed_flags<SvLBoxTabFlags, 0x007f> {}; 82 } 83 84 #define SV_TAB_BORDER 8 85 86 #define SV_ENTRYHEIGHTOFFS_PIXEL 2 87 88 enum class SvTreeFlags 89 { 90 CHKBTN = 0x01, 91 USESEL = 0x02, 92 MANINS = 0x04, 93 RECALCTABS = 0x08, 94 FIXEDHEIGHT = 0x10, 95 }; 96 namespace o3tl 97 { 98 template<> struct typed_flags<SvTreeFlags> : is_typed_flags<SvTreeFlags, 0x1f> {}; 99 } 100 101 enum class SvLBoxItemType {String, Button, ContextBmp}; 102 103 class SvLBoxTab 104 { 105 long nPos; 106 public: 107 SvLBoxTab(); 108 SvLBoxTab( long nPos, SvLBoxTabFlags nFlags ); 109 SvLBoxTab( const SvLBoxTab& ); 110 ~SvLBoxTab(); 111 112 SvLBoxTabFlags nFlags; 113 IsDynamic() const114 bool IsDynamic() const { return bool(nFlags & SvLBoxTabFlags::DYNAMIC); } SetPos(long nNewPos)115 void SetPos( long nNewPos) { nPos = nNewPos; } GetPos() const116 long GetPos() const { return nPos; } 117 long CalcOffset( long nItemLength, long nTabWidth ); IsEditable() const118 bool IsEditable() const { return bool(nFlags & SvLBoxTabFlags::EDITABLE); } 119 }; 120 121 class VCL_DLLPUBLIC SvLBoxItem 122 { 123 protected: 124 bool mbDisabled; 125 126 public: 127 SvLBoxItem(); 128 virtual ~SvLBoxItem(); 129 virtual SvLBoxItemType GetType() const = 0; 130 virtual int CalcWidth(const SvTreeListBox* pView) const; 131 int GetWidth(const SvTreeListBox* pView, const SvTreeListEntry* pEntry) const; 132 int GetWidth(const SvTreeListBox* pView, const SvViewDataEntry* pData, sal_uInt16 nItemPos); 133 int GetHeight(const SvTreeListBox* pView, const SvTreeListEntry* pEntry) const; 134 static int GetHeight(const SvViewDataEntry* pData, sal_uInt16 nItemPos); Enable(bool bEnabled)135 void Enable(bool bEnabled) { mbDisabled = !bEnabled; } 136 137 virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev, vcl::RenderContext& rRenderContext, const SvViewDataEntry* pView, const SvTreeListEntry& rEntry) = 0; 138 139 virtual void InitViewData(SvTreeListBox* pView, SvTreeListEntry* pEntry, 140 // If != 0: this Pointer must be used! 141 // If == 0: it needs to be retrieved via the View 142 SvViewDataItem* pViewData = nullptr) = 0; 143 // View-dependent data is not cloned 144 virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const = 0; 145 }; 146 147 enum class DragDropMode 148 { 149 NONE = 0x0000, 150 CTRL_MOVE = 0x0001, 151 CTRL_COPY = 0x0002, 152 APP_MOVE = 0x0004, 153 APP_COPY = 0x0008, 154 APP_DROP = 0x0010, 155 // Entries may be dropped via the uppermost Entry 156 // The DropTarget is 0 in that case 157 ENABLE_TOP = 0x0020, 158 ALL = 0x003f, 159 }; 160 namespace o3tl 161 { 162 template<> struct typed_flags<DragDropMode> : is_typed_flags<DragDropMode, 0x003f> {}; 163 } 164 165 enum class SvTreeListBoxFlags 166 { 167 NONE = 0x0000, 168 IN_EDT = 0x0001, 169 EDT_ENABLED = 0x0002, 170 TARGEMPH_VIS = 0x0004, 171 EDTEND_CALLED = 0x0008, 172 }; 173 namespace o3tl 174 { 175 template<> struct typed_flags<SvTreeListBoxFlags> : is_typed_flags<SvTreeListBoxFlags, 0x000f> {}; 176 } 177 178 struct SvTreeListBoxImpl; 179 180 class VCL_DLLPUBLIC SvTreeListBox 181 :public Control 182 ,public SvListView 183 ,public DropTargetHelper 184 ,public DragSourceHelper 185 ,public vcl::IMnemonicEntryList 186 ,public vcl::ISearchableStringList 187 { 188 friend class SvImpLBox; 189 friend class IconViewImpl; 190 friend class TreeControlPeer; 191 friend class SalInstanceIconView; 192 friend class SalInstanceTreeView; 193 friend class SalInstanceEntryTreeView; 194 195 std::unique_ptr<SvTreeListBoxImpl> mpImpl; 196 Link<SvTreeListBox*,void> aCheckButtonHdl; 197 Link<SvTreeListBox*,void> aScrolledHdl; 198 Link<SvTreeListBox*,void> aExpandedHdl; 199 Link<SvTreeListBox*,bool> aExpandingHdl; 200 Link<SvTreeListBox*,void> aSelectHdl; 201 Link<SvTreeListBox*,void> aDeselectHdl; 202 Link<const CommandEvent&, bool> aPopupMenuHdl; 203 204 Image aPrevInsertedExpBmp; 205 Image aPrevInsertedColBmp; 206 Image aCurInsertedExpBmp; 207 Image aCurInsertedColBmp; 208 209 short nContextBmpWidthMax; 210 short nEntryHeightOffs; 211 short nIndent; 212 short nFocusWidth; 213 sal_uInt16 nFirstSelTab; 214 sal_uInt16 nLastSelTab; 215 long mnCheckboxItemWidth; 216 bool mbContextBmpExpanded; 217 bool mbAlternatingRowColors; 218 bool mbUpdateAlternatingRows; 219 bool mbQuickSearch; // Enables type-ahead search in the check list box. 220 221 SvTreeListEntry* pHdlEntry; 222 223 DragDropMode nDragDropMode; 224 DragDropMode nOldDragMode; 225 SelectionMode eSelMode; 226 sal_Int32 nMinWidthInChars; 227 228 SvTreeListEntry* pEdEntry; 229 SvLBoxItem* pEdItem; 230 231 protected: 232 std::unique_ptr<SvImpLBox> pImpl; 233 short nColumns; 234 short nEntryHeight; 235 short nEntryWidth; 236 bool mbCenterAndClipText; 237 238 Link<SvTreeListBox*,bool> aDoubleClickHdl; 239 SvTreeListEntry* pTargetEntry; 240 SvLBoxButtonData* pCheckButtonData; 241 std::vector<std::unique_ptr<SvLBoxTab>> aTabs; 242 SvTreeFlags nTreeFlags; 243 SvTreeListBoxFlags nImpFlags; 244 // Move/CopySelection: Position of the current Entry in SelectionList 245 sal_uInt16 nCurEntrySelPos; 246 247 private: 248 DECL_DLLPRIVATE_LINK( CheckButtonClick, SvLBoxButtonData *, void ); 249 DECL_DLLPRIVATE_LINK( TextEditEndedHdl_Impl, SvInplaceEdit2&, void ); 250 // Handler that is called by TreeList to clone an Entry 251 DECL_DLLPRIVATE_LINK( CloneHdl_Impl, SvTreeListEntry*, SvTreeListEntry* ); 252 253 // Handler and methods for Drag - finished handler. 254 // The Handle retrieved by GetDragFinishedHdl can be set on the 255 // TransferDataContainer. This link is a callback for the DragFinished 256 // call. The AddBox method is called from the GetDragFinishedHdl() and the 257 // remove is called in the link callback and in the dtor. So it can't be 258 // called for a deleted object. 259 VCL_DLLPRIVATE static void AddBoxToDDList_Impl( const SvTreeListBox& rB ); 260 VCL_DLLPRIVATE static void RemoveBoxFromDDList_Impl( const SvTreeListBox& rB ); 261 DECL_DLLPRIVATE_LINK( DragFinishHdl_Impl, sal_Int8, void ); 262 263 // after a checkbox entry is inserted, use this to get its width to support 264 // autowidth for the 1st checkbox column 265 VCL_DLLPRIVATE void CheckBoxInserted(SvTreeListEntry* pEntry); 266 267 protected: 268 269 bool CheckDragAndDropMode( SvTreeListBox const * pSource, sal_Int8 ); 270 void ImplShowTargetEmphasis( SvTreeListEntry* pEntry, bool bShow); 271 void EnableSelectionAsDropTarget( bool bEnable = true ); 272 // Standard impl returns 0; derived classes which support D'n'D must override 273 using Window::GetDropTarget; 274 virtual SvTreeListEntry* GetDropTarget( const Point& ); 275 276 // Invalidate children on enable/disable 277 virtual void StateChanged( StateChangedType eType ) override; 278 279 virtual sal_uLong Insert( SvTreeListEntry* pEnt,SvTreeListEntry* pPar,sal_uLong nPos=TREELIST_APPEND); 280 virtual sal_uLong Insert( SvTreeListEntry* pEntry,sal_uLong nRootPos = TREELIST_APPEND ); 281 282 // In-place editing 283 std::unique_ptr<SvInplaceEdit2> pEdCtrl; 284 void EditText( const OUString&, const tools::Rectangle&,const Selection&); 285 void CancelTextEditing(); 286 bool EditingCanceled() const; 287 288 // InitViewData is called right after CreateViewData 289 // The Entry is has not yet been added to the View in InitViewData! 290 virtual void InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry ) override; 291 // Calls InitViewData for all Items 292 void RecalcViewData(); 293 294 // Handler and methods for Drag - finished handler. This link can be set 295 // to the TransferDataContainer. The AddBox/RemoveBox methods must be 296 // called before the StartDrag call. 297 // The Remove will be called from the handler, which then calls DragFinish. 298 // The Remove is also called in the DTOR of the SvTreeListBox - 299 // so it can't be called for a deleted object. 300 Link<sal_Int8,void> GetDragFinishedHdl() const; 301 302 // For asynchronous D'n'D 303 sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt, SvTreeListBox* pSourceView ); 304 305 void OnCurrentEntryChanged(); 306 307 // IMnemonicEntryList 308 virtual const void* FirstSearchEntry( OUString& _rEntryText ) const override; 309 virtual const void* NextSearchEntry( const void* _pCurrentSearchEntry, OUString& _rEntryText ) const override; 310 virtual void SelectSearchEntry( const void* _pEntry ) override; 311 virtual void ExecuteSearchEntry( const void* _pEntry ) const override; 312 313 // ISearchableStringList 314 virtual vcl::StringEntryIdentifier CurrentEntry( OUString& _out_entryText ) const override; 315 virtual vcl::StringEntryIdentifier NextEntry( vcl::StringEntryIdentifier _currentEntry, OUString& _out_entryText ) const override; 316 virtual void SelectEntry( vcl::StringEntryIdentifier _entry ) override; 317 318 public: 319 320 SvTreeListBox( vcl::Window* pParent, WinBits nWinStyle=0 ); 321 virtual ~SvTreeListBox() override; 322 virtual void dispose() override; 323 GetModel() const324 SvTreeList* GetModel() const 325 { 326 return pModel.get(); 327 } 328 GetEntryCount() const329 sal_uLong GetEntryCount() const 330 { 331 return pModel ? pModel->GetEntryCount() : 0; 332 } First() const333 SvTreeListEntry* First() const 334 { 335 return pModel ? pModel->First() : nullptr; 336 } Next(SvTreeListEntry * pEntry) const337 SvTreeListEntry* Next( SvTreeListEntry* pEntry ) const 338 { 339 return pModel->Next(pEntry); 340 } Prev(SvTreeListEntry * pEntry) const341 SvTreeListEntry* Prev( SvTreeListEntry* pEntry ) const 342 { 343 return pModel->Prev(pEntry); 344 } Last() const345 SvTreeListEntry* Last() const 346 { 347 return pModel ? pModel->Last() : nullptr; 348 } 349 350 SvTreeListEntry* FirstChild( SvTreeListEntry* pParent ) const; 351 352 bool CopySelection( SvTreeListBox* pSource, SvTreeListEntry* pTarget ); 353 bool MoveSelectionCopyFallbackPossible( SvTreeListBox* pSource, SvTreeListEntry* pTarget, bool bAllowCopyFallback ); 354 void RemoveSelection(); 355 /** 356 * Removes the entry along with all of its descendants 357 */ 358 void RemoveEntry(SvTreeListEntry const * pEntry); 359 GetDragDropMode() const360 DragDropMode GetDragDropMode() const { return nDragDropMode; } GetSelectionMode() const361 SelectionMode GetSelectionMode() const { return eSelMode; } 362 363 // pParent == 0 -> Root level 364 SvTreeListEntry* GetEntry( SvTreeListEntry* pParent, sal_uLong nPos ) const; 365 SvTreeListEntry* GetEntry( sal_uLong nRootPos ) const; 366 367 SvTreeListEntry* GetEntryFromPath( const ::std::deque< sal_Int32 >& _rPath ) const; 368 void FillEntryPath( SvTreeListEntry* pEntry, ::std::deque< sal_Int32 >& _rPath ) const; 369 370 using Window::GetParent; 371 const SvTreeListEntry* GetParent( const SvTreeListEntry* pEntry ) const; 372 SvTreeListEntry* GetParent( SvTreeListEntry* pEntry ) const; 373 SvTreeListEntry* GetRootLevelParent(SvTreeListEntry* pEntry ) const; 374 375 using Window::GetChildCount; 376 sal_uLong GetChildCount( SvTreeListEntry const * pParent ) const; 377 sal_uLong GetLevelChildCount( SvTreeListEntry* pParent ) const; 378 379 SvViewDataEntry* GetViewDataEntry( SvTreeListEntry const * pEntry ) const; 380 SvViewDataItem* GetViewDataItem(SvTreeListEntry const *, SvLBoxItem const *); 381 const SvViewDataItem* GetViewDataItem(const SvTreeListEntry*, const SvLBoxItem*) const; 382 IsInplaceEditingEnabled() const383 bool IsInplaceEditingEnabled() const { return bool(nImpFlags & SvTreeListBoxFlags::EDT_ENABLED); } IsEditingActive() const384 bool IsEditingActive() const { return bool(nImpFlags & SvTreeListBoxFlags::IN_EDT); } 385 void EndEditing( bool bCancel = false ); 386 387 void Clear(); 388 389 /** Enables or disables mnemonic characters in the entry texts. 390 391 If mnemonics are enabled, then entries are selected and made current when 392 there mnemonic character is pressed. If there are multiple entries with the 393 same mnemonic, the selection cycles between them. 394 395 Entries with a collapsed ancestor are not included in the calculation of 396 mnemonics. That is, if you press the accelerator key of an invisible 397 entry, then this entry is *not* selected. 398 399 Be aware that enabling mnemonics gets more expensive as you add to the list. 400 */ 401 void EnableEntryMnemonics(); 402 bool IsEntryMnemonicsEnabled() const; 403 TextCenterAndClipEnabled() const404 bool TextCenterAndClipEnabled() const { return mbCenterAndClipText; } 405 406 /** Handles the given key event. 407 408 At the moment this merely checks for accelerator keys, if entry mnemonics 409 are enabled. 410 411 This method may come in handy if you want to use keyboard acceleration 412 while the control does not have the focus. 413 414 If the key event describes the pressing of a shortcut for an entry, 415 then SelectSearchEntry resp. ExecuteSearchEntry are called. 416 417 @see IMnemonicEntryList 418 @see MnemonicEngine 419 420 @return 421 <TRUE/> if the event has been consumed, <FALSE/> otherwise. 422 */ 423 bool HandleKeyInput( const KeyEvent& rKEvt ); 424 SetSelectHdl(const Link<SvTreeListBox *,void> & rNewHdl)425 void SetSelectHdl( const Link<SvTreeListBox*,void>& rNewHdl ) {aSelectHdl=rNewHdl; } SetDeselectHdl(const Link<SvTreeListBox *,void> & rNewHdl)426 void SetDeselectHdl( const Link<SvTreeListBox*,void>& rNewHdl ) {aDeselectHdl=rNewHdl; } SetDoubleClickHdl(const Link<SvTreeListBox *,bool> & rNewHdl)427 void SetDoubleClickHdl(const Link<SvTreeListBox*,bool>& rNewHdl) {aDoubleClickHdl=rNewHdl;} GetDoubleClickHdl() const428 const Link<SvTreeListBox*,bool>& GetDoubleClickHdl() const { return aDoubleClickHdl; } SetExpandingHdl(const Link<SvTreeListBox *,bool> & rNewHdl)429 void SetExpandingHdl(const Link<SvTreeListBox*,bool>& rNewHdl){aExpandingHdl=rNewHdl;} SetExpandedHdl(const Link<SvTreeListBox *,void> & rNewHdl)430 void SetExpandedHdl(const Link<SvTreeListBox*,void>& rNewHdl){aExpandedHdl=rNewHdl;} SetPopupMenuHdl(const Link<const CommandEvent &,bool> & rLink)431 void SetPopupMenuHdl(const Link<const CommandEvent&, bool>& rLink) { aPopupMenuHdl = rLink; } 432 433 virtual void ExpandedHdl(); 434 virtual bool ExpandingHdl(); 435 virtual void SelectHdl(); 436 virtual void DeselectHdl(); 437 virtual bool DoubleClickHdl(); GetHdlEntry() const438 SvTreeListEntry* GetHdlEntry() const { return pHdlEntry; } 439 440 // Is called for an Entry that gets expanded with the Flag 441 // ENTRYFLAG_CHILDREN_ON_DEMAND set. 442 virtual void RequestingChildren( SvTreeListEntry* pParent ); 443 444 // Drag & Drop 445 // New D'n'D API 446 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; 447 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; 448 virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override; 449 virtual DragDropMode NotifyStartDrag( TransferDataContainer& rData, 450 SvTreeListEntry* ); 451 virtual void DragFinished( sal_Int8 nDropAction ); 452 virtual bool NotifyAcceptDrop( SvTreeListEntry* ); 453 454 virtual SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ); 455 456 // Return value: TRISTATE_TRUE == Ok, TRISTATE_FALSE == Cancel, TRISTATE_INDET == Ok and Make visible moved entry 457 virtual TriState NotifyMoving( 458 SvTreeListEntry* pTarget, // D'n'D DropPosition in GetModel() 459 SvTreeListEntry* pEntry, // Entry to be moved from GetSourceListBox()->GetModel() 460 SvTreeListEntry*& rpNewParent, // New TargetParent 461 sal_uLong& rNewChildPos); // The TargetParent's position in Childlist 462 463 // Return value: TRISTATE_TRUE == Ok, TRISTATE_FALSE == Cancel, TRISTATE_INDET == Ok and Make visible moved entry 464 virtual TriState NotifyCopying( 465 SvTreeListEntry* pTarget, // D'n'D DropPosition in GetModel() 466 SvTreeListEntry* pEntry, // Entry to be copied from GetSourceListBox()->GetModel() 467 SvTreeListEntry*& rpNewParent, // New TargetParent 468 sal_uLong& rNewChildPos); // The TargetParent's position in Childlist 469 470 // ACCESSIBILITY ========================================================== 471 472 /** Creates and returns the accessible object of the Box. */ 473 virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override; 474 475 /** Fills the StateSet of one entry. */ 476 void FillAccessibleEntryStateSet( SvTreeListEntry* pEntry, ::utl::AccessibleStateSetHelper& rStateSet ) const; 477 478 /** Calculate and return the bounding rectangle of an entry. 479 @param pEntry 480 The entry. 481 @return The bounding rectangle of an entry. */ 482 tools::Rectangle GetBoundingRect( SvTreeListEntry* pEntry ); 483 GetTreeFlags() const484 SvTreeFlags GetTreeFlags() const {return nTreeFlags;} 485 486 static OUString SearchEntryTextWithHeadTitle(SvTreeListEntry* pEntry); 487 virtual OUString GetEntryAltText(SvTreeListEntry* pEntry) const; 488 virtual OUString GetEntryLongDescription(SvTreeListEntry* pEntry) const; 489 490 void set_min_width_in_chars(sal_Int32 nChars); 491 492 virtual bool set_property(const OString &rKey, const OUString &rValue) override; 493 494 protected: 495 496 VCL_DLLPRIVATE void SetEntryHeight( SvTreeListEntry const * pEntry ); 497 void AdjustEntryHeight( const Image& rBmp ); 498 VCL_DLLPRIVATE void AdjustEntryHeight(); 499 500 VCL_DLLPRIVATE void ImpEntryInserted( SvTreeListEntry* pEntry ); 501 VCL_DLLPRIVATE void PaintEntry1( SvTreeListEntry&, long nLine, vcl::RenderContext& rRenderContext ); 502 503 VCL_DLLPRIVATE void InitTreeView(); 504 VCL_DLLPRIVATE SvLBoxItem* GetItem_Impl( SvTreeListEntry*, long nX, SvLBoxTab** ppTab ); 505 VCL_DLLPRIVATE void ImplInitStyle(); 506 507 void SetupDragOrigin(); 508 void EditItemText( SvTreeListEntry* pEntry, SvLBoxString* pItem, 509 const Selection& ); 510 void EditedText(const OUString&); 511 512 // Recalculate all tabs depending on TreeListStyle and Bitmap sizes 513 // Is called automatically when inserting/changing Bitmaps, changing the Model etc. 514 virtual void SetTabs(); 515 void AddTab( long nPos, SvLBoxTabFlags nFlags ); TabCount() const516 sal_uInt16 TabCount() const { return aTabs.size(); } 517 SvLBoxTab* GetFirstDynamicTab() const; 518 SvLBoxTab* GetFirstDynamicTab( sal_uInt16& rTabPos ) const; 519 SvLBoxTab* GetFirstTab( SvLBoxTabFlags nFlagMask, sal_uInt16& rTabPos ); 520 void GetLastTab( SvLBoxTabFlags nFlagMask, sal_uInt16& rTabPos ); 521 SvLBoxTab* GetTab( SvTreeListEntry const *, SvLBoxItem const * ) const; 522 void ClearTabList(); 523 524 virtual void InitEntry(SvTreeListEntry*, const OUString&, const Image&, const Image&); 525 526 virtual void NotifyEndScroll(); 527 virtual void NotifyScrolled(); SetScrolledHdl(const Link<SvTreeListBox *,void> & rLink)528 void SetScrolledHdl( const Link<SvTreeListBox*,void>& rLink ) { aScrolledHdl = rLink; } GetXOffset() const529 long GetXOffset() const { return GetMapMode().GetOrigin().X(); } 530 531 virtual void Command( const CommandEvent& rCEvt ) override; 532 533 virtual void RequestHelp( const HelpEvent& rHEvt ) override; 534 virtual void PreparePaint(vcl::RenderContext& rRenderContext, SvTreeListEntry& rEntry); 535 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; 536 537 void InitSettings(); 538 539 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; 540 541 bool IsCellFocusEnabled() const; 542 bool SetCurrentTabPos( sal_uInt16 _nNewPos ); 543 sal_uInt16 GetCurrentTabPos() const; 544 void CallImplEventListeners(VclEventId nEvent, void* pData); 545 546 void ImplEditEntry( SvTreeListEntry* pEntry ); 547 548 bool AreChildrenTransient() const; 549 550 void AdjustEntryHeightAndRecalc(); 551 public: 552 553 void SetNoAutoCurEntry( bool b ); 554 555 void EnableCheckButton( SvLBoxButtonData* ); 556 void SetCheckButtonData( SvLBoxButtonData* ); 557 void SetNodeBitmaps( const Image& rCollapsedNodeBmp, const Image& rExpandedNodeBmp ); 558 559 /** Returns the default image which clients should use for expanded nodes, to have a consistent user 560 interface experience in the whole product. 561 */ 562 static const Image& GetDefaultExpandedNodeImage( ); 563 564 /** Returns the default image which clients should use for expanded nodes, to have a consistent user 565 interface experience in the whole product. 566 */ 567 static const Image& GetDefaultCollapsedNodeImage( ); 568 569 /** Sets default bitmaps for collapsed and expanded nodes. 570 */ SetNodeDefaultImages()571 void SetNodeDefaultImages( ) 572 { 573 SetNodeBitmaps( 574 GetDefaultCollapsedNodeImage( ), 575 GetDefaultExpandedNodeImage( ) 576 ); 577 } 578 579 virtual SvTreeListEntry* InsertEntry( const OUString& rText, SvTreeListEntry* pParent = nullptr, 580 bool bChildrenOnDemand = false, 581 sal_uLong nPos=TREELIST_APPEND, void* pUserData = nullptr); 582 583 virtual SvTreeListEntry* InsertEntry( const OUString& rText, 584 const Image& rExpandedEntryBmp, 585 const Image& rCollapsedEntryBmp, 586 SvTreeListEntry* pParent = nullptr, 587 bool bChildrenOnDemand = false, 588 sal_uLong nPos = TREELIST_APPEND, void* pUserData = nullptr ); 589 590 const Image& GetDefaultExpandedEntryBmp( ) const; 591 const Image& GetDefaultCollapsedEntryBmp( ) const; 592 593 void SetDefaultExpandedEntryBmp( const Image& rBmp ); 594 void SetDefaultCollapsedEntryBmp( const Image& rBmp ); 595 596 void SetCheckButtonState( SvTreeListEntry*, SvButtonState ); 597 SvButtonState GetCheckButtonState( SvTreeListEntry* ) const; 598 599 void SetEntryText(SvTreeListEntry*, const OUString& ); 600 void SetExpandedEntryBmp( SvTreeListEntry* _pEntry, const Image& _rImage ); 601 void SetCollapsedEntryBmp( SvTreeListEntry* _pEntry, const Image& _rImage ); 602 603 virtual OUString GetEntryText( SvTreeListEntry* pEntry ) const; 604 static const Image& GetExpandedEntryBmp(const SvTreeListEntry* _pEntry ); 605 static const Image& GetCollapsedEntryBmp(const SvTreeListEntry* _pEntry ); 606 SetCheckButtonHdl(const Link<SvTreeListBox *,void> & rLink)607 void SetCheckButtonHdl( const Link<SvTreeListBox*,void>& rLink ) { aCheckButtonHdl=rLink; } 608 virtual void CheckButtonHdl(); 609 610 void SetSublistOpenWithReturn(); // open/close sublist with return/enter 611 void SetSublistOpenWithLeftRight(); // open/close sublist with cursor left/right 612 void SetSublistDontOpenWithDoubleClick( bool bDontOpen ); // set mouse double click open/close sublist behavior 613 614 void EnableInplaceEditing( bool bEnable ); 615 // Edits the Entry's first StringItem, 0 == Cursor 616 void EditEntry( SvTreeListEntry* pEntry ); 617 virtual bool EditingEntry( SvTreeListEntry* pEntry, Selection& ); 618 virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ); 619 620 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; 621 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; 622 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; 623 virtual void MouseMove( const MouseEvent& rMEvt ) override; 624 virtual void KeyInput( const KeyEvent& rKEvt ) override; 625 virtual void Resize() override; 626 virtual void GetFocus() override; 627 virtual void LoseFocus() override; 628 void SetUpdateMode( bool ); 629 630 virtual void ModelHasCleared() override; 631 virtual void ModelHasInserted( SvTreeListEntry* pEntry ) override; 632 virtual void ModelHasInsertedTree( SvTreeListEntry* pEntry ) override; 633 virtual void ModelIsMoving(SvTreeListEntry* pSource ) override; 634 virtual void ModelHasMoved(SvTreeListEntry* pSource ) override; 635 virtual void ModelIsRemoving( SvTreeListEntry* pEntry ) override; 636 virtual void ModelHasRemoved( SvTreeListEntry* pEntry ) override; 637 void ModelHasEntryInvalidated( SvTreeListEntry* pEntry ) override; 638 639 void ScrollOutputArea( short nDeltaEntries ); 640 GetColumnsCount() const641 short GetColumnsCount() const { return nColumns; } GetEntryHeight() const642 short GetEntryHeight() const { return nEntryHeight; } 643 void SetEntryHeight( short nHeight, bool bForce = false ); GetEntryWidth() const644 short GetEntryWidth() const { return nEntryWidth; } 645 void SetEntryWidth( short nWidth ); 646 Size GetOutputSizePixel() const; GetIndent() const647 short GetIndent() const { return nIndent; } 648 void SetIndent( short nIndent ); 649 // Place the expander checkitem at the optimal indent for hierarchical lists SetOptimalImageIndent()650 void SetOptimalImageIndent() { SetIndent(12); } 651 void SetSpaceBetweenEntries( short nSpace ); 652 Point GetEntryPosition( SvTreeListEntry* ) const; 653 void MakeVisible( SvTreeListEntry* pEntry ); 654 void MakeVisible( SvTreeListEntry* pEntry, bool bMoveToTop ); 655 656 void SetCollapsedNodeBmp( const Image& ); 657 void SetExpandedNodeBmp( const Image& ); 658 Image const & GetExpandedNodeBmp( ) const; 659 660 void SetFont( const vcl::Font& rFont ); 661 662 using Window::SetCursor; 663 void SetCursor( SvTreeListEntry* pEntry, bool bForceNoSelect = false ); 664 665 SvTreeListEntry* GetEntry( const Point& rPos, bool bHit = false ) const; 666 667 virtual tools::Rectangle GetFocusRect( SvTreeListEntry*, long nLine ); 668 // Respects indentation 669 virtual sal_IntPtr GetTabPos( SvTreeListEntry*, SvLBoxTab* ); 670 void InvalidateEntry( SvTreeListEntry* ); 671 SvLBoxItem* GetItem( SvTreeListEntry*, long nX, SvLBoxTab** ppTab); 672 SvLBoxItem* GetItem( SvTreeListEntry*, long nX ); 673 674 void SetDragDropMode( DragDropMode ); 675 void SetSelectionMode( SelectionMode ); 676 677 virtual bool Expand( SvTreeListEntry* pParent ); 678 virtual bool Collapse( SvTreeListEntry* pParent ); 679 virtual bool Select( SvTreeListEntry* pEntry, bool bSelect=true ); 680 sal_uLong SelectChildren( SvTreeListEntry* pParent, bool bSelect ); 681 void SelectAll( bool bSelect, bool bPaint = true ); 682 683 void SetCurEntry( SvTreeListEntry* _pEntry ); 684 SvTreeListEntry* GetCurEntry() const; 685 686 using Window::Invalidate; 687 virtual void Invalidate( InvalidateFlags nFlags = InvalidateFlags::NONE) override; 688 virtual void Invalidate( const tools::Rectangle&, InvalidateFlags nFlags = InvalidateFlags::NONE ) override; 689 690 void SetHighlightRange(sal_uInt16 nFirstTab=0, sal_uInt16 nLastTab=0xffff); 691 692 // A Parent's Children are turned into Children of the Parent which comes next in hierarchy 693 void RemoveParentKeepChildren( SvTreeListEntry* pParent ); 694 695 sal_Int32 DefaultCompare(const SvLBoxString* pLeftText, const SvLBoxString* pRightText); 696 697 DECL_LINK( DefaultCompare, const SvSortData&, sal_Int32 ); 698 virtual void ModelNotification( SvListAction nActionId, SvTreeListEntry* pEntry1, 699 SvTreeListEntry* pEntry2, sal_uLong nPos ) override; 700 701 void EndSelection(); 702 ScrollBar* GetVScroll(); 703 ScrollBar* GetHScroll(); 704 void EnableAsyncDrag( bool b ); 705 706 SvTreeListEntry* GetFirstEntryInView() const; 707 SvTreeListEntry* GetNextEntryInView(SvTreeListEntry*) const; 708 SvTreeListEntry* GetPrevEntryInView(SvTreeListEntry*) const; 709 SvTreeListEntry* GetLastEntryInView() const; 710 void ScrollToAbsPos( long nPos ); 711 712 void ShowFocusRect( const SvTreeListEntry* pEntry ); 713 714 virtual VclPtr<PopupMenu> CreateContextMenu(); 715 virtual void ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ); 716 717 void EnableContextMenuHandling(); 718 719 long getPreferredDimensions(std::vector<long> &rWidths) const; 720 721 virtual Size GetOptimalSize() const override; 722 723 void SetAlternatingRowColors( const bool bEnable ); 724 725 // Enables type-ahead search in the check list box. SetQuickSearch(bool bEnable)726 void SetQuickSearch(bool bEnable) { mbQuickSearch = bEnable; } 727 728 void SetForceMakeVisible(bool bEnable); 729 730 virtual FactoryFunction GetUITestFactory() const override; 731 }; 732 733 class SvInplaceEdit2 734 { 735 Link<SvInplaceEdit2&,void> const aCallBackHdl; 736 Accelerator aAccReturn; 737 Accelerator aAccEscape; 738 Idle aIdle; 739 VclPtr<Edit> pEdit; 740 bool bCanceled; 741 bool bAlreadyInCallBack; 742 743 void CallCallBackHdl_Impl(); 744 DECL_LINK( Timeout_Impl, Timer *, void ); 745 DECL_LINK( ReturnHdl_Impl, Accelerator&, void ); 746 DECL_LINK( EscapeHdl_Impl, Accelerator&, void ); 747 748 public: 749 SvInplaceEdit2( vcl::Window* pParent, const Point& rPos, const Size& rSize, 750 const OUString& rData, const Link<SvInplaceEdit2&,void>& rNotifyEditEnd, 751 const Selection& ); 752 ~SvInplaceEdit2(); 753 bool KeyInput( const KeyEvent& rKEvt ); 754 void LoseFocus(); EditingCanceled() const755 bool EditingCanceled() const { return bCanceled; } 756 OUString GetText() const; 757 OUString const & GetSavedValue() const; 758 void StopEditing( bool bCancel ); 759 void Hide(); 760 }; 761 762 #endif 763 764 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 765