1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TitledControl.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SD_TASKPANE_TITLED_CONTROL_HXX
32 #define SD_TASKPANE_TITLED_CONTROL_HXX
34 #include "taskpane/TaskPaneTreeNode.hxx"
35 #include "taskpane/ControlContainer.hxx"
36 #include "TitleBar.hxx"
37 #include <com/sun/star/drawing/framework/XResourceId.hpp>
38 #include <tools/string.hxx>
39 #include <tools/gen.hxx>
41 #include <vcl/window.hxx>
44 #include <boost/function.hpp>
48 namespace sd
{ namespace toolpanel
{
50 class ControlContainer
;
53 /** This wrapper adds a title bar to a control. Both title bar and
54 control are child windows.
61 typedef ::boost::function1
<void, TitledControl
&> ClickHandler
;
63 /** Create a new descriptor for the given control.
65 The parent window of the new descriptor.
67 The control that is shown when being in the expanded
70 String that is shown as title in the title area above the
73 The typical action of the click handler is to expand the control.
75 Type of the title bar. This specifies how the title bar
76 will be formated. For more information see TitleBar.
81 ::std::auto_ptr
<TreeNode
> pControl
,
83 const ClickHandler
& rClickHandler
,
84 TitleBar::TitleBarType eType
);
88 ::std::auto_ptr
<ControlFactory
> pControlFactory
,
90 const ClickHandler
& rClickHandler
,
91 TitleBar::TitleBarType eType
);
93 virtual ~TitledControl (void);
96 virtual Size
GetPreferredSize (void);
97 virtual sal_Int32
GetPreferredWidth (sal_Int32 nHeight
);
98 virtual sal_Int32
GetPreferredHeight (sal_Int32 nWidth
);
99 virtual bool IsResizable (void);
100 virtual ::Window
* GetWindow (void);
102 virtual void Resize (void);
103 virtual void GetFocus (void);
104 virtual void LoseFocus (void);
105 virtual void KeyInput (const KeyEvent
& rEvent
);
107 // void Select (bool bExpansionState);
109 TitleBar
* GetTitleBar (void);
110 /** Return the control child. When a control factory has been given and
111 the control has not yet been created and the given flag is <TRUE/>
112 then the control is created.
114 TreeNode
* GetControl (bool bCreate
=true);
115 const TreeNode
* GetConstControl (bool bCreate
=true) const;
117 const String
& GetTitle (void) const;
119 /** Expand the control without informing its container. This
120 method ususally is called by the container as a result of a
121 higher level expand command. You may want to use
122 ExpandViaContainer() instead.
124 When <TRUE/> then the control is expanded, otherwise it is
127 virtual bool Expand (bool bExpanded
= true);
129 /** Return whether the control is currently expanded (<TRUE/>) or
132 virtual bool IsExpanded (void) const;
134 /** Returns the value of the control.
136 virtual bool IsExpandable (void) const;
138 virtual void SetEnabledState(bool bFlag
);
140 /** Ownership of the given data remains with the caller. The data
141 is thus not destroyed when the destructor of this class is
144 void SetUserData (void* pUserData
);
145 void* GetUserData (void) const;
147 virtual bool IsShowing (void) const;
148 virtual void Show (bool bVisible
);
150 virtual ::com::sun::star::uno::Reference
<
151 ::com::sun::star::accessibility::XAccessible
> CreateAccessibleObject (
152 const ::com::sun::star::uno::Reference
<
153 ::com::sun::star::accessibility::XAccessible
>& rxParent
);
155 using Window::GetWindow
;
162 ::std::auto_ptr
<ControlFactory
> mpControlFactory
;
163 ::std::auto_ptr
<ClickHandler
> mpClickHandler
;
165 /** Remember whether to toggle (true) the expansion state when the title
166 bar is clicked on. When set to false then the control is always
169 bool mbExpansionModeIsToggle
;
171 /// Do not use! Assignment operator is not supported.
172 const TitledControl
& operator= (
173 const TitledControl
& aDescriptor
);
175 void UpdateStates (void);
177 DECL_LINK(WindowEventListener
, VclSimpleEvent
*);
183 /** This standard implementation of the ClickHandler expands, or toggles the
184 expansion state, of the control, whose title was clicked.
186 class TitledControlStandardClickHandler
189 /** Create a new instance of this class.
190 @param rControlContainer
191 The container of which the TitledControl is part of.
192 @param eExpansionState
193 This specifies whether to always expand the titled control or to
194 toggle its expansion state.
196 TitledControlStandardClickHandler (
197 ControlContainer
& rControlContainer
,
198 ControlContainer::ExpansionState eExpansionState
);
199 void operator () (TitledControl
& rTitledControl
);
201 ControlContainer
& mrControlContainer
;
202 ControlContainer::ExpansionState meExpansionState
;
205 } } // end of namespace ::sd::toolpanel