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