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