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