xref: /trunk/main/sd/source/ui/inc/taskpane/TitleBar.hxx (revision 69cb9f15)
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_TITLE_BAR_HXX
25 #define SD_TASKPANE_TITLE_BAR_HXX
26 
27 #include "taskpane/TaskPaneTreeNode.hxx"
28 #include <vcl/image.hxx>
29 #include <tools/string.hxx>
30 #include <vcl/window.hxx>
31 #include <memory>
32 
33 class Rectangle;
34 class String;
35 class VirtualDevice;
36 
37 namespace sd { namespace toolpanel {
38 
39 
40 /** The title bar above a control in a sub tool panel.
41 
42 	<p>The title bar shows two kinds of indicators: 1) Expansion is
43 	displayed by two sets of two bitmaps, a triangle pointing to the right
44 	resp. a minus in a square indicates that the control is collapsed, a
45 	triangle pointing down resp. a plus in a square stands for an expanded
46 	control. 2) Keyboard focus is indicated by a dotted rectangle.
47 */
48 class TitleBar
49 	: public ::Window,
50 	  public TreeNode
51 {
52 public:
53 	enum TitleBarType {
54 		TBT_SUB_CONTROL_HEADLINE
55 	};
56 
57 	/** Create a new title bar whose content, the given title string,
58 		will be formatted according to the given type.
59 	*/
60 	TitleBar (
61 		::Window* pParent,
62 		const String& rsTitle,
63 		TitleBarType eType,
64 		bool bIsExpandable);
65 	virtual ~TitleBar (void);
66 
67 	virtual Size GetPreferredSize (void);
68 	virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight);
69 	virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
70 	virtual bool IsResizable (void);
71 	virtual ::Window* GetWindow (void);
72 	virtual sal_Int32 GetMinimumWidth (void);
73 
74 	virtual void Paint (const Rectangle& rBoundingBox);
75 	virtual bool Expand (bool bFlag = true);
76 	virtual bool IsExpanded (void) const;
77 	virtual void SetEnabledState(bool bFlag);
78 	virtual void GetFocus (void);
79 	virtual void LoseFocus (void);
80 
81 	virtual void MouseMove(const MouseEvent& rEvent);
82 	/** Empty implementation prevents forwarding to docking window.
83 	*/
84 	virtual void MouseButtonDown (const MouseEvent& rEvent);
85 	/** Empty implementation prevents forwarding to docking window.
86 	*/
87 	virtual void MouseButtonUp (const MouseEvent& rEvent);
88 
89 	virtual void DataChanged (const DataChangedEvent& rEvent);
90 
91 	String GetTitle (void) const;
92 
93 	::com::sun::star::uno::Reference<
94 		::com::sun::star::accessibility::XAccessible > CreateAccessibleObject (
95 			const ::com::sun::star::uno::Reference<
96 			::com::sun::star::accessibility::XAccessible>& rxParent);
97 
98 private:
99 	TitleBarType meType;
100 	String msTitle;
101 	bool mbExpanded;
102 	bool mbFocused;
103 	// Size of the bounding box that encloses the title string.
104 	::std::auto_ptr<VirtualDevice> mpDevice;
105 	bool mbIsExpandable;
106 
107 	/** Return whether this TitleBar object has an expansion indicator
108 		bitmap. It is safe to call GetExpansionIndicator() when this method
109 		returns <FALSE/> but unnecessary.
110 	*/
111 	bool HasExpansionIndicator (void) const;
112 
113 	/** Return the image of the expansion indicator.
114 		@return
115 			When there is no expansion indicator for this TitleBar object,
116 			then an empty Image is returned. You better call
117 			HasExpansionIndicator() to prevent this.
118 	*/
119 	Image GetExpansionIndicator (void) const;
120 
121 	/** Calculate the bounding box of the title text. This takes into
122 		account indentation due to an expansion indicator and the given
123 		available width. When the text can not be displayed on one line, it
124 		is broken into multiple lines.
125 		@param nAvailableWidth
126 			When 0 is given then the natural text width is used, i.e. the
127 			text is not broken into multiple lines.
128 	*/
129 	Rectangle CalculateTextBoundingBox (
130 		int nAvailableWidth,
131 		bool bEmphasizeExpanded);
132 
133 	/** Add some space to the given text box and return the bounding box of
134 		the title bar.
135 	*/
136 	Rectangle CalculateTitleBarBox (
137 		const Rectangle& rTextBox,
138 		int nTitleBarWidth);
139 
140 	void PaintSubPanelHeadLineBar (void);
141 
142 	void PaintBackground (const Rectangle& rTextBox);
143 
144 	/// Paint a focus indicator that encloses the given rectangle.
145 	void PaintFocusIndicator (const Rectangle& rIndicatorBox);
146 
147 	Rectangle PaintExpansionIndicator (const Rectangle& rTextBox);
148 
149 	void PaintText (const Rectangle& rTextBox);
150 
151 	sal_uInt16 GetTextStyle (void);
152 
153 	const static int snIndentationWidth;
154 
155 	// Default constructor, copy constructor, and assignment are not supported.
156 	TitleBar (void);
157 	TitleBar (const TitleBar&);
158 	TitleBar& operator= (const TitleBar&);
159 
160 	using Window::GetWindow;
161 };
162 
163 } } // end of namespace ::sd::toolpanel
164 
165 #endif
166