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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_fpicker.hxx"
30 #include "customcontrolcontainer.hxx"
31 
32 #include <algorithm>
33 #include <functional>
34 
35 //-----------------------------------
36 //
37 //-----------------------------------
38 
39 namespace /* private */
40 {
41 	void DeleteCustomControl(CCustomControl* aCustomControl)
42 	{
43 		delete aCustomControl;
44 	};
45 
46 	void AlignCustomControl(CCustomControl* aCustomControl)
47 	{
48 		aCustomControl->Align();
49 	};
50 
51 	class CSetFontHelper
52 	{
53 	public:
54 		CSetFontHelper(HFONT hFont) :
55 			m_hFont(hFont)
56 		{
57 		}
58 
59 		void SAL_CALL operator()(CCustomControl* aCustomControl)
60 		{
61 			aCustomControl->SetFont(m_hFont);
62 		}
63 
64 	private:
65 		HFONT m_hFont;
66 	};
67 }
68 
69 //-----------------------------------
70 //
71 //-----------------------------------
72 
73 CCustomControlContainer::~CCustomControlContainer()
74 {
75 	RemoveAllControls();
76 }
77 
78 //-----------------------------------
79 //
80 //-----------------------------------
81 
82 void SAL_CALL CCustomControlContainer::Align()
83 {
84 	std::for_each(
85 		m_ControlContainer.begin(),
86 		m_ControlContainer.end(),
87 		AlignCustomControl);
88 }
89 
90 //-----------------------------------
91 //
92 //-----------------------------------
93 
94 void SAL_CALL CCustomControlContainer::SetFont(HFONT hFont)
95 {
96 	CSetFontHelper aSetFontHelper(hFont);
97 
98 	std::for_each(
99 		m_ControlContainer.begin(),
100 		m_ControlContainer.end(),
101 		aSetFontHelper);
102 }
103 
104 //-----------------------------------
105 //
106 //-----------------------------------
107 
108 void SAL_CALL CCustomControlContainer::AddControl(CCustomControl* aCustomControl)
109 {
110 	m_ControlContainer.push_back(aCustomControl);
111 }
112 
113 //-----------------------------------
114 //
115 //-----------------------------------
116 
117 void SAL_CALL CCustomControlContainer::RemoveControl(CCustomControl* aCustomControl)
118 {
119 	ControlContainer_t::iterator iter_end = m_ControlContainer.end();
120 
121 	ControlContainer_t::iterator iter =
122 		std::find(m_ControlContainer.begin(),iter_end,aCustomControl);
123 
124 	if (iter != iter_end)
125 	{
126 		delete *iter;
127 		m_ControlContainer.remove(aCustomControl);
128 	}
129 }
130 
131 //-----------------------------------
132 //
133 //-----------------------------------
134 
135 void SAL_CALL CCustomControlContainer::RemoveAllControls()
136 {
137 	std::for_each(
138 		m_ControlContainer.begin(),
139 		m_ControlContainer.end(),
140 		DeleteCustomControl);
141 
142 	m_ControlContainer.clear();
143 }
144