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_TITLED_CONTROL_HXX
29 #define SD_TASKPANE_TITLED_CONTROL_HXX
30 
31 #include "taskpane/TaskPaneTreeNode.hxx"
32 #include "taskpane/ControlContainer.hxx"
33 #include "TitleBar.hxx"
34 #include <com/sun/star/drawing/framework/XResourceId.hpp>
35 #include <tools/string.hxx>
36 #include <tools/gen.hxx>
37 #ifndef SD_WINDOW_HXX
38 #include <vcl/window.hxx>
39 #endif
40 #include <memory>
41 #include <boost/function.hpp>
42 
43 class Window;
44 
45 namespace sd { namespace toolpanel {
46 
47 class ControlContainer;
48 
49 /** This wrapper adds a title bar to a control.  Both title bar and
50     control are child windows.
51 */
52 class TitledControl
53     : public ::Window,
54       public TreeNode
55 {
56 public:
57     typedef ::boost::function1<void, TitledControl&> ClickHandler;
58 
59     /** Create a new descriptor for the given control.
60         @param pParent
61             The parent window of the new descriptor.
62         @param pControl
63             The control that is shown when being in the expanded
64             state.
65         @param rTitle
66             String that is shown as title in the title area above the
67             control.
68         @param rClickHandler
69             The typical action of the click handler is to expand the control.
70         @param eType
71             Type of the title bar.  This specifies how the title bar
72             will be formated.  For more information see TitleBar.
73 
74     */
75     TitledControl (
76         TreeNode* pParent,
77         ::std::auto_ptr<TreeNode> pControl,
78         const String& rTitle,
79         const ClickHandler& rClickHandler,
80         TitleBar::TitleBarType eType);
81 
82     virtual ~TitledControl (void);
83 
84 
85     virtual Size GetPreferredSize (void);
86     virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight);
87     virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
88     virtual bool IsResizable (void);
89     virtual ::Window* GetWindow (void);
90 
91     virtual void Resize (void);
92     virtual void GetFocus (void);
93     virtual void KeyInput (const KeyEvent& rEvent);
94 
95     //    void Select (bool bExpansionState);
96 
97     TitleBar* GetTitleBar (void);
98     /** Return the control child.  When a control factory has been given and
99         the control has not yet been created and the given flag is <TRUE/>
100         then the control is created.
101     */
102     TreeNode* GetControl (void);
103     const TreeNode* GetConstControl () const;
104 
105     const String& GetTitle (void) const;
106 
107     /** Expand the control without informing its container.  This
108         method ususally is called by the container as a result of a
109         higher level expand command.  You may want to use
110         ExpandViaContainer() instead.
111         @param bExpanded
112             When <TRUE/> then the control is expanded, otherwise it is
113             collapsed.
114     */
115     virtual bool Expand (bool bExpanded = true);
116 
117     /** Return whether the control is currently expanded (<TRUE/>) or
118         not (<FALSE/>).
119     */
120     virtual bool IsExpanded (void) const;
121 
122     /** Returns the value of the control.
123     */
124     virtual bool IsExpandable (void) const;
125 
126     virtual void SetEnabledState(bool bFlag);
127 
128     virtual bool IsShowing (void) const;
129     virtual void Show (bool bVisible);
130 
131     virtual ::com::sun::star::uno::Reference<
132         ::com::sun::star::accessibility::XAccessible > CreateAccessibleObject (
133             const ::com::sun::star::uno::Reference<
134             ::com::sun::star::accessibility::XAccessible>& rxParent);
135 
136 	using Window::GetWindow;
137 	using Window::Show;
138 
139 private:
140     String msTitle;
141     bool mbVisible;
142     void* mpUserData;
143     ::std::auto_ptr<ClickHandler> mpClickHandler;
144 
145     /// Do not use! Assignment operator is not supported.
146     const TitledControl& operator= (
147         const TitledControl& aDescriptor);
148 
149     void UpdateStates (void);
150 
151     DECL_LINK(WindowEventListener, VclSimpleEvent*);
152 };
153 
154 
155 
156 
157 /** This standard implementation of the ClickHandler expands, or toggles the
158     expansion state, of the control, whose title was clicked.
159 */
160 class TitledControlStandardClickHandler
161 {
162 public:
163     /** Create a new instance of this class.
164         @param rControlContainer
165             The container of which the TitledControl is part of.
166         @param eExpansionState
167             This specifies whether to always expand the titled control or to
168             toggle its expansion state.
169     */
170     TitledControlStandardClickHandler (
171         ControlContainer& rControlContainer,
172         ControlContainer::ExpansionState eExpansionState);
173     void operator () (TitledControl& rTitledControl);
174 private:
175     ControlContainer& mrControlContainer;
176     ControlContainer::ExpansionState meExpansionState;
177 };
178 
179 } } // end of namespace ::sd::toolpanel
180 
181 #endif
182