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_CONTROL_FACTORY_HXX
29 #define SD_TASKPANE_CONTROL_FACTORY_HXX
30 
31 #include "taskpane/TaskPaneTreeNode.hxx"
32 
33 #include <memory>
34 
35 namespace sd {
36 class ViewShellBase;
37 }
38 
39 namespace sd { namespace toolpanel {
40 class TreeNode;
41 } }
42 
43 
44 
45 
46 namespace sd { namespace toolpanel {
47 
48 /** A simple factory base class defines the interface that is used by
49     some of the control containers of the task pane to create controls on
50     demand when they are about to be displayed for the first time.
51 
52     It provides the InternalCreateControl() method as hook that can be
53     overloaded by derived classes to provide a new control.
54 */
55 class ControlFactory
56 {
57 public:
58     ControlFactory (void);
59     virtual ~ControlFactory (void);
60 
61     /** creates a tree node which acts as root of an own tree
62 
63         Derived classes should overload InternalCreateControl.
64     */
65     ::std::auto_ptr<TreeNode> CreateControl( ::Window& i_rParent );
66 
67 protected:
68     virtual TreeNode* InternalCreateControl( ::Window& i_rParent ) = 0;
69 };
70 
71 
72 
73 /** A simple helper class that realizes a ControlFactory that is able to create root controls, providing
74     the to-be-created control with an additional parameter.
75 */
76 template<class ControlType, class ArgumentType>
77 class RootControlFactoryWithArg
78     : public ControlFactory
79 {
80 public:
81     RootControlFactoryWithArg (ArgumentType& rArgument)
82         : mrArgument(rArgument)
83     {}
84 
85 protected:
86     virtual TreeNode* InternalCreateControl( ::Window& i_rParent )
87     {
88         return new ControlType( i_rParent, mrArgument );
89     }
90 
91 private:
92     ArgumentType& mrArgument;
93 };
94 
95 
96 } } // end of namespace ::sd::toolpanel
97 
98 #endif
99