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