1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SD_TOOLPANEL_SCROLL_PANEL_HXX 29 #define SD_TOOLPANEL_SCROLL_PANEL_HXX 30 31 #include "taskpane/TaskPaneTreeNode.hxx" 32 33 #include <vcl/ctrl.hxx> 34 #include <vcl/scrbar.hxx> 35 #include <memory> 36 #include <vector> 37 38 namespace sd { namespace toolpanel { 39 40 class TitledControl; 41 42 /** The scroll panel shows its controls one above the other. When their 43 total height is larger than the height of the scroll area then only a 44 part of the controls is visible. Scroll bars control which part that 45 is. 46 47 The scroll panel registers itself as window event listener at the 48 controls and their title bars (conceptually; it really is the 49 TitledControl) to track changes of the selection and focus rectangles. 50 On such a change it tries to move the selected or focused part into the 51 visible area. At the moment this moving into view only works with 52 valuesets and TitleBars. 53 */ 54 class ScrollPanel 55 : public ::Control, 56 public TreeNode 57 { 58 public: 59 /** Create a new scroll panel which itself is the root of a TreeNode hierarchy 60 parent. This will usually be a child window. 61 */ 62 ScrollPanel (::Window& i_rParentWindow); 63 virtual ~ScrollPanel (void); 64 65 /** Add a control to the sub panel. An title bar is added above the 66 control. 67 @param rTitle 68 The title that will be shown in the two title bars that 69 belong to the control. 70 @param nHelpId 71 The help id is set at the title bar not the actual control. 72 @return 73 The new titled control that contains the given control and a new 74 title bar as children is returned. 75 */ 76 TitledControl* AddControl ( 77 ::std::auto_ptr<TreeNode> pControl, 78 const String& rTitle, 79 const rtl::OString& sHelpId); 80 81 /** Add a control to the sub panel without a title bar. 82 */ 83 void AddControl (::std::auto_ptr<TreeNode> pControl); 84 85 virtual void Paint (const Rectangle& rRect); 86 87 /** Initiate a rearrangement of the controls and title bars. 88 */ 89 virtual void Resize (void); 90 91 virtual void RequestResize (void); 92 93 virtual Size GetPreferredSize (void); 94 virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight); 95 virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth); 96 virtual bool IsResizable (void); 97 virtual ::Window* GetWindow (void); 98 virtual sal_Int32 GetMinimumWidth (void); 99 100 virtual void ExpandControl ( 101 TreeNode* pControl, 102 bool bExpansionState); 103 104 bool IsVerticalScrollBarVisible (void) const; 105 bool IsHorizontalScrollBarVisible (void) const; 106 ScrollBar& GetVerticalScrollBar (void); 107 ScrollBar& GetHorizontalScrollBar (void); 108 109 // ::Window 110 virtual long Notify( NotifyEvent& rNEvt ); 111 112 virtual ::com::sun::star::uno::Reference< 113 ::com::sun::star::accessibility::XAccessible> CreateAccessibleObject ( 114 const ::com::sun::star::uno::Reference< 115 ::com::sun::star::accessibility::XAccessible>& rxParent); 116 117 /** Scroll the given rectangle into the visible area. 118 @param aRectangle 119 The box to move into the visible area in pixel coordinates 120 relative to the given window. 121 @param pWindow 122 This window is used to translate the given coordinates into ones 123 that are relative to the scroll panel. 124 125 */ 126 void MakeRectangleVisible ( 127 Rectangle& aRectangle, 128 ::Window* pWindow); 129 130 private: 131 ::Control maScrollWindow; 132 ScrollBar maVerticalScrollBar; 133 ScrollBar maHorizontalScrollBar; 134 ::Window maScrollBarFiller; 135 ::Window maScrollWindowFiller; 136 Point maScrollOffset; 137 bool mbIsRearrangePending; 138 bool mbIsLayoutPending; 139 sal_uInt32 mnChildrenWidth; 140 /// Border above top-most and below bottom-most control. 141 const int mnVerticalBorder; 142 /// Gap between two controls. 143 const int mnVerticalGap; 144 /// Border at the left and right of the controls. 145 const int mnHorizontalBorder; 146 /** List of horizontal stripes that is created from the gaps between 147 children when they are layouted. The stripes are painted in Paint() 148 to fill the space arround the children. 149 */ 150 typedef ::std::vector< ::std::pair<int,int> > StripeList; 151 StripeList maStripeList; 152 153 /** Calculate position, size, and visibility of the controls. 154 Call this method after the list of controls, their expansion 155 state, or the size of the sub panel has changed. 156 */ 157 void Rearrange (void); 158 159 /** Determine the minimal size that is necessary to show the controls 160 one over the other. It may be smaller than the available area. 161 */ 162 Size GetRequiredSize (void); 163 164 /** Place the child windows one above the other and return the size of 165 the bounding box. 166 */ 167 sal_Int32 LayoutChildren (void); 168 169 /** ctor-impl 170 */ 171 void Construct(); 172 173 Size SetupScrollBars (const Size& rRequiresSize); 174 sal_Int32 SetupVerticalScrollBar (bool bShow, sal_Int32 nRange); 175 sal_Int32 SetupHorizontalScrollBar (bool bShow, sal_Int32 nRange); 176 177 DECL_LINK(ScrollBarHandler, ScrollBar*); 178 DECL_LINK(WindowEventListener, VclSimpleEvent*); 179 180 using Window::GetWindow; 181 }; 182 183 } } // end of namespace ::sd::toolpanel 184 185 #endif 186