1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef SD_TOOLPANEL_CONTROL_CONTAINER_HXX 29*cdf0e10cSrcweir #define SD_TOOLPANEL_CONTROL_CONTAINER_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <osl/mutex.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <vector> 34*cdf0e10cSrcweir #include <memory> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir class Window; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir namespace sd { namespace toolpanel { 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir class TreeNode; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir /** This container manages the children of a TreeNode. It handles the 43*cdf0e10cSrcweir expansion and visibility state of its child controls. The container 44*cdf0e10cSrcweir does not do the layouting or painting of the controls. Instead it asks 45*cdf0e10cSrcweir its owner to do that. 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir The difference between expansion state and visibility is that when a 48*cdf0e10cSrcweir control is collapsed at least a title bar is shown for it. When it is 49*cdf0e10cSrcweir not visible then even this title bar is not shown. In that case the 50*cdf0e10cSrcweir user can not expand the control. A control has to be visible in order 51*cdf0e10cSrcweir to be expanded or collapsed. 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir Whenever you expand or collapse, show or hide a child control then use 54*cdf0e10cSrcweir this container class. Do not call the respective methods of the child 55*cdf0e10cSrcweir directly. 56*cdf0e10cSrcweir */ 57*cdf0e10cSrcweir class ControlContainer 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir public: 60*cdf0e10cSrcweir enum VisibilityState { VS_SHOW, VS_HIDE, VS_TOGGLE }; 61*cdf0e10cSrcweir enum ExpansionState { ES_EXPAND, ES_COLLAPSE, ES_TOGGLE }; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir /** Create a new control container. 64*cdf0e10cSrcweir @param pParent 65*cdf0e10cSrcweir This node is asked to re-calculate the size of its children when 66*cdf0e10cSrcweir a child of this container is expanded or collapsed. 67*cdf0e10cSrcweir */ 68*cdf0e10cSrcweir ControlContainer (TreeNode* pNode); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir virtual ~ControlContainer (void); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir /** This is function makes sure that all children are deleted. Call 73*cdf0e10cSrcweir this function from the destructor of a sub class to have all child 74*cdf0e10cSrcweir windows deleted before the destructor of another base class of that 75*cdf0e10cSrcweir sub class is called. When that other base class is some kind of a 76*cdf0e10cSrcweir window it would otherwise complain that there are living children. 77*cdf0e10cSrcweir */ 78*cdf0e10cSrcweir void DeleteChildren (void); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir /** Add the given control to the set of controls managed by the 81*cdf0e10cSrcweir container. This control is then expanded. 82*cdf0e10cSrcweir @return 83*cdf0e10cSrcweir Return the index under which the control has been inserted in 84*cdf0e10cSrcweir the container. It is the same index that is returned by 85*cdf0e10cSrcweir GetControlIndex(). 86*cdf0e10cSrcweir */ 87*cdf0e10cSrcweir sal_uInt32 AddControl (::std::auto_ptr<TreeNode> pControl); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir /** Expand (default) or collapse the specified control. When 90*cdf0e10cSrcweir expanding a control in a single expansion environment then all 91*cdf0e10cSrcweir other controls are collapsed. The specified control is being 92*cdf0e10cSrcweir made the active control as returned by GetActiveControl(). 93*cdf0e10cSrcweir */ 94*cdf0e10cSrcweir virtual void SetExpansionState ( 95*cdf0e10cSrcweir sal_uInt32 nIndex, 96*cdf0e10cSrcweir ExpansionState aState); 97*cdf0e10cSrcweir virtual void SetExpansionState ( 98*cdf0e10cSrcweir TreeNode* pControl, 99*cdf0e10cSrcweir ExpansionState aState); 100*cdf0e10cSrcweir virtual void SetVisibilityState ( 101*cdf0e10cSrcweir sal_uInt32 nIndex, 102*cdf0e10cSrcweir VisibilityState aState); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir /** Return the index of the given control. 105*cdf0e10cSrcweir */ 106*cdf0e10cSrcweir sal_uInt32 GetControlIndex (TreeNode* pControl) const; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir /** Return the number of controls in the container. 109*cdf0e10cSrcweir */ 110*cdf0e10cSrcweir sal_uInt32 GetControlCount (void) const; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir /** Return the number of visible controls in the container. 113*cdf0e10cSrcweir */ 114*cdf0e10cSrcweir sal_uInt32 GetVisibleControlCount (void) const; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir /** Return the control with the specified index regardless of whether 117*cdf0e10cSrcweir that control is hidden or visible. 118*cdf0e10cSrcweir */ 119*cdf0e10cSrcweir TreeNode* GetControl (sal_uInt32 nIndex) const; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir /** Return the index of the control previous to that that is specified 122*cdf0e10cSrcweir by the given index. 123*cdf0e10cSrcweir @param nIndex 124*cdf0e10cSrcweir Index of the control for which to return the index of the 125*cdf0e10cSrcweir previous control. This index is guaranteed not to be returned. 126*cdf0e10cSrcweir @param bIncludeHidden 127*cdf0e10cSrcweir This flag tells the method whether to include the controls that 128*cdf0e10cSrcweir are not visible in the search for the previous control. When it 129*cdf0e10cSrcweir is <FALSE/> the hidden controls are skipped. 130*cdf0e10cSrcweir @param bCycle 131*cdf0e10cSrcweir When this flag is <TRUE/> then the search for the previous 132*cdf0e10cSrcweir control wraps arround when reaching the first control. 133*cdf0e10cSrcweir @return 134*cdf0e10cSrcweir Returns the index to the previous control or (sal_uInt32)-1 when 135*cdf0e10cSrcweir there is no previous control. This would be the case when there 136*cdf0e10cSrcweir is only one (visible) child. 137*cdf0e10cSrcweir */ 138*cdf0e10cSrcweir sal_uInt32 GetPreviousIndex ( 139*cdf0e10cSrcweir sal_uInt32 nIndex, 140*cdf0e10cSrcweir bool bIncludeHidden=false, 141*cdf0e10cSrcweir bool bCycle=false) const; 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir /** Return the index of the control next to that that is specified by 144*cdf0e10cSrcweir the given index. 145*cdf0e10cSrcweir @param nIndex 146*cdf0e10cSrcweir Index of the control for which to return the index of the next 147*cdf0e10cSrcweir control. This index is guaranteed not to be returned. 148*cdf0e10cSrcweir @param bIncludeHidden 149*cdf0e10cSrcweir This flag tells the method whether to include the controls that 150*cdf0e10cSrcweir are not visible in the search for the next control. When it is 151*cdf0e10cSrcweir <FALSE/> the hidden controls are skipped. 152*cdf0e10cSrcweir @param bCycle 153*cdf0e10cSrcweir When this flag is <TRUE/> then the search for the next control 154*cdf0e10cSrcweir wraps arround when reaching the last control. 155*cdf0e10cSrcweir @return 156*cdf0e10cSrcweir Returns the index to the next control or (sal_uInt32)-1 when 157*cdf0e10cSrcweir there is no next control. This would be the case when there is 158*cdf0e10cSrcweir only one (visible) child. 159*cdf0e10cSrcweir */ 160*cdf0e10cSrcweir sal_uInt32 GetNextIndex ( 161*cdf0e10cSrcweir sal_uInt32 nIndex, 162*cdf0e10cSrcweir bool bIncludeHidden=false, 163*cdf0e10cSrcweir bool bCycle=false) const; 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir void SetMultiSelection (bool bFlag); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir /** This is method is called when the list of controls has changed, 168*cdf0e10cSrcweir i.e. a new control has been added. The default implementation is 169*cdf0e10cSrcweir empty. Overwrite this method in derived classes in order to react to 170*cdf0e10cSrcweir such changes. 171*cdf0e10cSrcweir */ 172*cdf0e10cSrcweir virtual void ListHasChanged (void); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir private: 175*cdf0e10cSrcweir osl::Mutex maMutex; 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir /// List of controls managed by a container. 178*cdf0e10cSrcweir typedef ::std::vector<TreeNode*> ControlList; 179*cdf0e10cSrcweir ControlList maControlList; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir /** This parent is used for resize requests when children are expanded 182*cdf0e10cSrcweir or collapsed. 183*cdf0e10cSrcweir */ 184*cdf0e10cSrcweir TreeNode* mpNode; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir /** The index of the currently expanded control. A value of 187*cdf0e10cSrcweir (sal_uInt32)-1 indicates that no control is active. This may be the 188*cdf0e10cSrcweir case after adding controls to the container. 189*cdf0e10cSrcweir */ 190*cdf0e10cSrcweir sal_uInt32 mnActiveControlIndex; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir bool mbMultiSelection; 193*cdf0e10cSrcweir }; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir } } // end of namespace ::sd::toolpanel 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir #endif 198