1*c45d927aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c45d927aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c45d927aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c45d927aSAndrew Rist  * distributed with this work for additional information
6*c45d927aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c45d927aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c45d927aSAndrew Rist  * "License"); you may not use this file except in compliance
9*c45d927aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c45d927aSAndrew Rist  *
11*c45d927aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c45d927aSAndrew Rist  *
13*c45d927aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c45d927aSAndrew Rist  * software distributed under the License is distributed on an
15*c45d927aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c45d927aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c45d927aSAndrew Rist  * specific language governing permissions and limitations
18*c45d927aSAndrew Rist  * under the License.
19*c45d927aSAndrew Rist  *
20*c45d927aSAndrew Rist  *************************************************************/
21*c45d927aSAndrew Rist 
22*c45d927aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SD_TASKPANE_TITLED_CONTROL_HXX
25cdf0e10cSrcweir #define SD_TASKPANE_TITLED_CONTROL_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "taskpane/TaskPaneTreeNode.hxx"
28cdf0e10cSrcweir #include "taskpane/ControlContainer.hxx"
29cdf0e10cSrcweir #include "TitleBar.hxx"
30cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XResourceId.hpp>
31cdf0e10cSrcweir #include <tools/string.hxx>
32cdf0e10cSrcweir #include <tools/gen.hxx>
33cdf0e10cSrcweir #ifndef SD_WINDOW_HXX
34cdf0e10cSrcweir #include <vcl/window.hxx>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include <memory>
37cdf0e10cSrcweir #include <boost/function.hpp>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir class Window;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace sd { namespace toolpanel {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir class ControlContainer;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir /** This wrapper adds a title bar to a control.  Both title bar and
46cdf0e10cSrcweir     control are child windows.
47cdf0e10cSrcweir */
48cdf0e10cSrcweir class TitledControl
49cdf0e10cSrcweir     : public ::Window,
50cdf0e10cSrcweir       public TreeNode
51cdf0e10cSrcweir {
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir     typedef ::boost::function1<void, TitledControl&> ClickHandler;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     /** Create a new descriptor for the given control.
56cdf0e10cSrcweir         @param pParent
57cdf0e10cSrcweir             The parent window of the new descriptor.
58cdf0e10cSrcweir         @param pControl
59cdf0e10cSrcweir             The control that is shown when being in the expanded
60cdf0e10cSrcweir             state.
61cdf0e10cSrcweir         @param rTitle
62cdf0e10cSrcweir             String that is shown as title in the title area above the
63cdf0e10cSrcweir             control.
64cdf0e10cSrcweir         @param rClickHandler
65cdf0e10cSrcweir             The typical action of the click handler is to expand the control.
66cdf0e10cSrcweir         @param eType
67cdf0e10cSrcweir             Type of the title bar.  This specifies how the title bar
68cdf0e10cSrcweir             will be formated.  For more information see TitleBar.
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     */
71cdf0e10cSrcweir     TitledControl (
72cdf0e10cSrcweir         TreeNode* pParent,
73cdf0e10cSrcweir         ::std::auto_ptr<TreeNode> pControl,
74cdf0e10cSrcweir         const String& rTitle,
75cdf0e10cSrcweir         const ClickHandler& rClickHandler,
76cdf0e10cSrcweir         TitleBar::TitleBarType eType);
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     virtual ~TitledControl (void);
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     virtual Size GetPreferredSize (void);
82cdf0e10cSrcweir     virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight);
83cdf0e10cSrcweir     virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
84cdf0e10cSrcweir     virtual bool IsResizable (void);
85cdf0e10cSrcweir     virtual ::Window* GetWindow (void);
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     virtual void Resize (void);
88cdf0e10cSrcweir     virtual void GetFocus (void);
89cdf0e10cSrcweir     virtual void KeyInput (const KeyEvent& rEvent);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     //    void Select (bool bExpansionState);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     TitleBar* GetTitleBar (void);
94cdf0e10cSrcweir     /** Return the control child.  When a control factory has been given and
95cdf0e10cSrcweir         the control has not yet been created and the given flag is <TRUE/>
96cdf0e10cSrcweir         then the control is created.
97cdf0e10cSrcweir     */
98cdf0e10cSrcweir     TreeNode* GetControl (void);
99cdf0e10cSrcweir     const TreeNode* GetConstControl () const;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     const String& GetTitle (void) const;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     /** Expand the control without informing its container.  This
104cdf0e10cSrcweir         method ususally is called by the container as a result of a
105cdf0e10cSrcweir         higher level expand command.  You may want to use
106cdf0e10cSrcweir         ExpandViaContainer() instead.
107cdf0e10cSrcweir         @param bExpanded
108cdf0e10cSrcweir             When <TRUE/> then the control is expanded, otherwise it is
109cdf0e10cSrcweir             collapsed.
110cdf0e10cSrcweir     */
111cdf0e10cSrcweir     virtual bool Expand (bool bExpanded = true);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     /** Return whether the control is currently expanded (<TRUE/>) or
114cdf0e10cSrcweir         not (<FALSE/>).
115cdf0e10cSrcweir     */
116cdf0e10cSrcweir     virtual bool IsExpanded (void) const;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     /** Returns the value of the control.
119cdf0e10cSrcweir     */
120cdf0e10cSrcweir     virtual bool IsExpandable (void) const;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     virtual void SetEnabledState(bool bFlag);
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     virtual bool IsShowing (void) const;
125cdf0e10cSrcweir     virtual void Show (bool bVisible);
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference<
128cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible > CreateAccessibleObject (
129cdf0e10cSrcweir             const ::com::sun::star::uno::Reference<
130cdf0e10cSrcweir             ::com::sun::star::accessibility::XAccessible>& rxParent);
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	using Window::GetWindow;
133cdf0e10cSrcweir 	using Window::Show;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir private:
136cdf0e10cSrcweir     String msTitle;
137cdf0e10cSrcweir     bool mbVisible;
138cdf0e10cSrcweir     void* mpUserData;
139cdf0e10cSrcweir     ::std::auto_ptr<ClickHandler> mpClickHandler;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     /// Do not use! Assignment operator is not supported.
142cdf0e10cSrcweir     const TitledControl& operator= (
143cdf0e10cSrcweir         const TitledControl& aDescriptor);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     void UpdateStates (void);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     DECL_LINK(WindowEventListener, VclSimpleEvent*);
148cdf0e10cSrcweir };
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 
153cdf0e10cSrcweir /** This standard implementation of the ClickHandler expands, or toggles the
154cdf0e10cSrcweir     expansion state, of the control, whose title was clicked.
155cdf0e10cSrcweir */
156cdf0e10cSrcweir class TitledControlStandardClickHandler
157cdf0e10cSrcweir {
158cdf0e10cSrcweir public:
159cdf0e10cSrcweir     /** Create a new instance of this class.
160cdf0e10cSrcweir         @param rControlContainer
161cdf0e10cSrcweir             The container of which the TitledControl is part of.
162cdf0e10cSrcweir         @param eExpansionState
163cdf0e10cSrcweir             This specifies whether to always expand the titled control or to
164cdf0e10cSrcweir             toggle its expansion state.
165cdf0e10cSrcweir     */
166cdf0e10cSrcweir     TitledControlStandardClickHandler (
167cdf0e10cSrcweir         ControlContainer& rControlContainer,
168cdf0e10cSrcweir         ControlContainer::ExpansionState eExpansionState);
169cdf0e10cSrcweir     void operator () (TitledControl& rTitledControl);
170cdf0e10cSrcweir private:
171cdf0e10cSrcweir     ControlContainer& mrControlContainer;
172cdf0e10cSrcweir     ControlContainer::ExpansionState meExpansionState;
173cdf0e10cSrcweir };
174cdf0e10cSrcweir 
175cdf0e10cSrcweir } } // end of namespace ::sd::toolpanel
176cdf0e10cSrcweir 
177cdf0e10cSrcweir #endif
178