1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SD_TASKPANE_CONTROL_FACTORY_HXX 25 #define SD_TASKPANE_CONTROL_FACTORY_HXX 26 27 #include "taskpane/TaskPaneTreeNode.hxx" 28 29 #include <memory> 30 31 namespace sd { 32 class ViewShellBase; 33 } 34 35 namespace sd { namespace toolpanel { 36 class TreeNode; 37 } } 38 39 40 41 42 namespace sd { namespace toolpanel { 43 44 /** A simple factory base class defines the interface that is used by 45 some of the control containers of the task pane to create controls on 46 demand when they are about to be displayed for the first time. 47 48 It provides the InternalCreateControl() method as hook that can be 49 overloaded by derived classes to provide a new control. 50 */ 51 class ControlFactory 52 { 53 public: 54 ControlFactory (void); 55 virtual ~ControlFactory (void); 56 57 /** creates a tree node which acts as root of an own tree 58 59 Derived classes should overload InternalCreateControl. 60 */ 61 ::std::auto_ptr<TreeNode> CreateControl( ::Window& i_rParent ); 62 63 protected: 64 virtual TreeNode* InternalCreateControl( ::Window& i_rParent ) = 0; 65 }; 66 67 68 69 /** A simple helper class that realizes a ControlFactory that is able to create root controls, providing 70 the to-be-created control with an additional parameter. 71 */ 72 template<class ControlType, class ArgumentType> 73 class RootControlFactoryWithArg 74 : public ControlFactory 75 { 76 public: 77 RootControlFactoryWithArg (ArgumentType& rArgument) 78 : mrArgument(rArgument) 79 {} 80 81 protected: 82 virtual TreeNode* InternalCreateControl( ::Window& i_rParent ) 83 { 84 return new ControlType( i_rParent, mrArgument ); 85 } 86 87 private: 88 ArgumentType& mrArgument; 89 }; 90 91 92 } } // end of namespace ::sd::toolpanel 93 94 #endif 95