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