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_SCROLL_PANEL_HXX
25 #define SD_TOOLPANEL_SCROLL_PANEL_HXX
26 
27 #include "taskpane/TaskPaneTreeNode.hxx"
28 
29 #include <vcl/ctrl.hxx>
30 #include <vcl/scrbar.hxx>
31 #include <memory>
32 #include <vector>
33 
34 namespace sd { namespace toolpanel {
35 
36 class TitledControl;
37 
38 /** The scroll panel shows its controls one above the other. When their
39 	total height is larger than the height of the scroll area then only a
40 	part of the controls is visible. Scroll bars control which part that
41 	is.
42 
43 	The scroll panel registers itself as window event listener at the
44 	controls and their title bars (conceptually; it really is the
45 	TitledControl) to track changes of the selection and focus rectangles.
46 	On such a change it tries to move the selected or focused part into the
47 	visible area. At the moment this moving into view only works with
48 	valuesets and TitleBars.
49 */
50 class ScrollPanel
51 	: public ::Control,
52 	  public TreeNode
53 {
54 public:
55 	/** Create a new scroll panel which itself is the root of a TreeNode hierarchy
56 		parent. This will usually be a child window.
57 	*/
58 	ScrollPanel (::Window& i_rParentWindow);
59 	virtual ~ScrollPanel (void);
60 
61 	/** Add a control to the sub panel. A title bar is added above the
62 		control.
63 		@param rTitle
64 			The title that will be shown in the two title bars that
65 			belong to the control.
66 		@param nHelpId
67 			The help id is set at the title bar not the actual control.
68 		@return
69 			The new titled control that contains the given control and a new
70 			title bar as children is returned.
71 	*/
72 	TitledControl* AddControl (
73 		::std::auto_ptr<TreeNode> pControl,
74 		const String& rTitle,
75 		const rtl::OString& sHelpId);
76 
77 	/** Add a control to the sub panel without a title bar.
78 	*/
79 	void AddControl (::std::auto_ptr<TreeNode> pControl);
80 
81 	virtual void Paint (const Rectangle& rRect);
82 
83 	/** Initiate a rearrangement of the controls and title bars.
84 	*/
85 	virtual void Resize (void);
86 
87 	virtual void RequestResize (void);
88 
89 	virtual Size GetPreferredSize (void);
90 	virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight);
91 	virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
92 	virtual bool IsResizable (void);
93 	virtual ::Window* GetWindow (void);
94 	virtual sal_Int32 GetMinimumWidth (void);
95 
96 	virtual void ExpandControl (
97 		TreeNode* pControl,
98 		bool bExpansionState);
99 
100 	bool IsVerticalScrollBarVisible (void) const;
101 	bool IsHorizontalScrollBarVisible (void) const;
102 	ScrollBar& GetVerticalScrollBar (void);
103 	ScrollBar& GetHorizontalScrollBar (void);
104 
105 	// ::Window
106 	virtual long Notify( NotifyEvent& rNEvt );
107 
108 	virtual ::com::sun::star::uno::Reference<
109 		::com::sun::star::accessibility::XAccessible> CreateAccessibleObject (
110 			const ::com::sun::star::uno::Reference<
111 			::com::sun::star::accessibility::XAccessible>& rxParent);
112 
113 	/** Scroll the given rectangle into the visible area.
114 		@param aRectangle
115 			The box to move into the visible area in pixel coordinates
116 			relative to the given window.
117 		@param pWindow
118 			This window is used to translate the given coordinates into ones
119 			that are relative to the scroll panel.
120 
121 	*/
122 	void MakeRectangleVisible (
123 		Rectangle& aRectangle,
124 		::Window* pWindow);
125 
126 private:
127 	::Control maScrollWindow;
128 	ScrollBar maVerticalScrollBar;
129 	ScrollBar maHorizontalScrollBar;
130 	::Window maScrollBarFiller;
131 	::Window maScrollWindowFiller;
132 	Point maScrollOffset;
133 	bool mbIsRearrangePending;
134 	bool mbIsLayoutPending;
135 	sal_uInt32 mnChildrenWidth;
136 	/// Border above top-most and below bottom-most control.
137 	const int mnVerticalBorder;
138 	/// Gap between two controls.
139 	const int mnVerticalGap;
140 	/// Border at the left and right of the controls.
141 	const int mnHorizontalBorder;
142 	/** List of horizontal stripes that is created from the gaps between
143 		children when they are layouted. The stripes are painted in Paint()
144 		to fill the space around the children.
145 	*/
146 	typedef ::std::vector< ::std::pair<int,int> > StripeList;
147 	StripeList maStripeList;
148 
149 	/** Calculate position, size, and visibility of the controls.
150 		Call this method after the list of controls, their expansion
151 		state, or the size of the sub panel has changed.
152 	*/
153 	void Rearrange (void);
154 
155 	/** Determine the minimal size that is necessary to show the controls
156 		one over the other. It may be smaller than the available area.
157 	*/
158 	Size GetRequiredSize (void);
159 
160 	/** Place the child windows one above the other and return the size of
161 		the bounding box.
162 	*/
163 	sal_Int32 LayoutChildren (void);
164 
165 	/** ctor-impl
166 	*/
167 	void Construct();
168 
169 	Size SetupScrollBars (const Size& rRequiresSize);
170 	sal_Int32 SetupVerticalScrollBar (bool bShow, sal_Int32 nRange);
171 	sal_Int32 SetupHorizontalScrollBar (bool bShow, sal_Int32 nRange);
172 
173 	DECL_LINK(ScrollBarHandler, ScrollBar*);
174 	DECL_LINK(WindowEventListener, VclSimpleEvent*);
175 
176 	using Window::GetWindow;
177 };
178 
179 } } // end of namespace ::sd::toolpanel
180 
181 #endif
182