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_TASKPANE_TITLED_CONTROL_HXX 25 #define SD_TASKPANE_TITLED_CONTROL_HXX 26 27 #include "taskpane/TaskPaneTreeNode.hxx" 28 #include "taskpane/ControlContainer.hxx" 29 #include "TitleBar.hxx" 30 #include <com/sun/star/drawing/framework/XResourceId.hpp> 31 #include <tools/string.hxx> 32 #include <tools/gen.hxx> 33 #ifndef SD_WINDOW_HXX 34 #include <vcl/window.hxx> 35 #endif 36 #include <memory> 37 #include <boost/function.hpp> 38 39 class Window; 40 41 namespace sd { namespace toolpanel { 42 43 class ControlContainer; 44 45 /** This wrapper adds a title bar to a control. Both title bar and 46 control are child windows. 47 */ 48 class TitledControl 49 : public ::Window, 50 public TreeNode 51 { 52 public: 53 typedef ::boost::function1<void, TitledControl&> ClickHandler; 54 55 /** Create a new descriptor for the given control. 56 @param pParent 57 The parent window of the new descriptor. 58 @param pControl 59 The control that is shown when being in the expanded 60 state. 61 @param rTitle 62 String that is shown as title in the title area above the 63 control. 64 @param rClickHandler 65 The typical action of the click handler is to expand the control. 66 @param eType 67 Type of the title bar. This specifies how the title bar 68 will be formatted. For more information see TitleBar. 69 70 */ 71 TitledControl ( 72 TreeNode* pParent, 73 ::std::auto_ptr<TreeNode> pControl, 74 const String& rTitle, 75 const ClickHandler& rClickHandler, 76 TitleBar::TitleBarType eType); 77 78 virtual ~TitledControl (void); 79 80 81 virtual Size GetPreferredSize (void); 82 virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight); 83 virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth); 84 virtual bool IsResizable (void); 85 virtual ::Window* GetWindow (void); 86 87 virtual void Resize (void); 88 virtual void GetFocus (void); 89 virtual void KeyInput (const KeyEvent& rEvent); 90 91 // void Select (bool bExpansionState); 92 93 TitleBar* GetTitleBar (void); 94 /** Return the control child. When a control factory has been given and 95 the control has not yet been created and the given flag is <TRUE/> 96 then the control is created. 97 */ 98 TreeNode* GetControl (void); 99 const TreeNode* GetConstControl () const; 100 101 const String& GetTitle (void) const; 102 103 /** Expand the control without informing its container. This 104 method usually is called by the container as a result of a 105 higher level expand command. You may want to use 106 ExpandViaContainer() instead. 107 @param bExpanded 108 When <TRUE/> then the control is expanded, otherwise it is 109 collapsed. 110 */ 111 virtual bool Expand (bool bExpanded = true); 112 113 /** Return whether the control is currently expanded (<TRUE/>) or 114 not (<FALSE/>). 115 */ 116 virtual bool IsExpanded (void) const; 117 118 /** Returns the value of the control. 119 */ 120 virtual bool IsExpandable (void) const; 121 122 virtual void SetEnabledState(bool bFlag); 123 124 virtual bool IsShowing (void) const; 125 virtual void Show (bool bVisible); 126 127 virtual ::com::sun::star::uno::Reference< 128 ::com::sun::star::accessibility::XAccessible > CreateAccessibleObject ( 129 const ::com::sun::star::uno::Reference< 130 ::com::sun::star::accessibility::XAccessible>& rxParent); 131 132 using Window::GetWindow; 133 using Window::Show; 134 135 private: 136 String msTitle; 137 bool mbVisible; 138 void* mpUserData; 139 ::std::auto_ptr<ClickHandler> mpClickHandler; 140 141 /// Do not use! Assignment operator is not supported. 142 const TitledControl& operator= ( 143 const TitledControl& aDescriptor); 144 145 void UpdateStates (void); 146 147 DECL_LINK(WindowEventListener, VclSimpleEvent*); 148 }; 149 150 151 152 153 /** This standard implementation of the ClickHandler expands, or toggles the 154 expansion state, of the control, whose title was clicked. 155 */ 156 class TitledControlStandardClickHandler 157 { 158 public: 159 /** Create a new instance of this class. 160 @param rControlContainer 161 The container of which the TitledControl is part of. 162 @param eExpansionState 163 This specifies whether to always expand the titled control or to 164 toggle its expansion state. 165 */ 166 TitledControlStandardClickHandler ( 167 ControlContainer& rControlContainer, 168 ControlContainer::ExpansionState eExpansionState); 169 void operator () (TitledControl& rTitledControl); 170 private: 171 ControlContainer& mrControlContainer; 172 ControlContainer::ExpansionState meExpansionState; 173 }; 174 175 } } // end of namespace ::sd::toolpanel 176 177 #endif 178