@@ -63,32 +63,19 @@ typedef std::list< IMEDelegate * >::iterator DelegateIter;
63
63
// Delegate List manage class
64
64
// ////////////////////////////////////////////////////////////////////////
65
65
66
- class IMEDispatcher ::Impl
66
+ struct IMEDispatcher ::Impl
67
67
{
68
- public:
69
- Impl ()
68
+ Impl () : _delegateWithIme(nullptr )
70
69
{
71
70
}
72
71
73
- ~Impl ()
74
- {
75
-
76
- }
77
-
78
- void init ()
79
- {
80
- _delegateWithIme = 0 ;
81
- }
82
-
83
72
DelegateIter findDelegate (IMEDelegate* delegate)
84
73
{
85
74
DelegateIter end = _delegateList.end ();
86
75
for (DelegateIter iter = _delegateList.begin (); iter != end; ++iter)
87
76
{
88
77
if (delegate == *iter)
89
- {
90
78
return iter;
91
- }
92
79
}
93
80
return end;
94
81
}
@@ -104,7 +91,6 @@ class IMEDispatcher::Impl
104
91
IMEDispatcher::IMEDispatcher ()
105
92
: _impl(new IMEDispatcher::Impl)
106
93
{
107
- _impl->init ();
108
94
}
109
95
110
96
IMEDispatcher::~IMEDispatcher ()
@@ -137,11 +123,8 @@ bool IMEDispatcher::attachDelegateWithIME(IMEDelegate * delegate)
137
123
{
138
124
CC_BREAK_IF (! _impl || ! delegate);
139
125
140
- DelegateIter end = _impl->_delegateList .end ();
141
- DelegateIter iter = _impl->findDelegate (delegate);
142
-
143
126
// if pDelegate is not in delegate list, return
144
- CC_BREAK_IF (end == iter );
127
+ CC_BREAK_IF (_impl-> findDelegate (delegate) == _impl-> _delegateList . end () );
145
128
146
129
if (_impl->_delegateWithIme )
147
130
{
@@ -155,10 +138,9 @@ bool IMEDispatcher::attachDelegateWithIME(IMEDelegate * delegate)
155
138
156
139
// detach first
157
140
IMEDelegate * oldDelegate = _impl->_delegateWithIme ;
158
- _impl->_delegateWithIme = 0 ;
159
141
oldDelegate->didDetachWithIME ();
160
142
161
- _impl->_delegateWithIme = *iter ;
143
+ _impl->_delegateWithIme = delegate ;
162
144
delegate->didAttachWithIME ();
163
145
}
164
146
ret = true ;
@@ -168,7 +150,7 @@ bool IMEDispatcher::attachDelegateWithIME(IMEDelegate * delegate)
168
150
// delegate hasn't attached to IME yet
169
151
CC_BREAK_IF (! delegate->canAttachWithIME ());
170
152
171
- _impl->_delegateWithIme = *iter ;
153
+ _impl->_delegateWithIme = delegate ;
172
154
delegate->didAttachWithIME ();
173
155
ret = true ;
174
156
} while (0 );
@@ -204,8 +186,6 @@ void IMEDispatcher::removeDelegate(IMEDelegate* delegate)
204
186
DelegateIter end = _impl->_delegateList .end ();
205
187
CC_BREAK_IF (end == iter);
206
188
207
- if (_impl->_delegateWithIme )
208
-
209
189
if (*iter == _impl->_delegateWithIme )
210
190
{
211
191
_impl->_delegateWithIme = 0 ;
@@ -268,9 +248,7 @@ const std::string& IMEDispatcher::getContentText()
268
248
269
249
bool IMEDispatcher::isAnyDelegateAttachedWithIME () const
270
250
{
271
- if (!_impl)
272
- return false ;
273
- return _impl->_delegateWithIme != nullptr ;
251
+ return _impl ? _impl->_delegateWithIme != nullptr : false ;
274
252
}
275
253
276
254
// ////////////////////////////////////////////////////////////////////////
@@ -281,15 +259,10 @@ void IMEDispatcher::dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info)
281
259
{
282
260
if (_impl)
283
261
{
284
- IMEDelegate * delegate = nullptr ;
285
- DelegateIter last = _impl->_delegateList .end ();
286
- for (DelegateIter first = _impl->_delegateList .begin (); first != last; ++first)
262
+ for (IMEDelegate *delegate : _impl->_delegateList )
287
263
{
288
- delegate = *(first);
289
264
if (delegate)
290
- {
291
265
delegate->keyboardWillShow (info);
292
- }
293
266
}
294
267
}
295
268
}
@@ -298,15 +271,10 @@ void IMEDispatcher::dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info)
298
271
{
299
272
if (_impl)
300
273
{
301
- IMEDelegate * delegate = nullptr ;
302
- DelegateIter last = _impl->_delegateList .end ();
303
- for (DelegateIter first = _impl->_delegateList .begin (); first != last; ++first)
274
+ for (IMEDelegate *delegate : _impl->_delegateList )
304
275
{
305
- delegate = *(first);
306
276
if (delegate)
307
- {
308
277
delegate->keyboardDidShow (info);
309
- }
310
278
}
311
279
}
312
280
}
@@ -315,15 +283,10 @@ void IMEDispatcher::dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info)
315
283
{
316
284
if (_impl)
317
285
{
318
- IMEDelegate * delegate = nullptr ;
319
- DelegateIter last = _impl->_delegateList .end ();
320
- for (DelegateIter first = _impl->_delegateList .begin (); first != last; ++first)
286
+ for (IMEDelegate *delegate : _impl->_delegateList )
321
287
{
322
- delegate = *(first);
323
288
if (delegate)
324
- {
325
289
delegate->keyboardWillHide (info);
326
- }
327
290
}
328
291
}
329
292
}
@@ -332,15 +295,10 @@ void IMEDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info)
332
295
{
333
296
if (_impl)
334
297
{
335
- IMEDelegate * delegate = nullptr ;
336
- DelegateIter last = _impl->_delegateList .end ();
337
- for (DelegateIter first = _impl->_delegateList .begin (); first != last; ++first)
298
+ for (IMEDelegate *delegate : _impl->_delegateList )
338
299
{
339
- delegate = *(first);
340
300
if (delegate)
341
- {
342
301
delegate->keyboardDidHide (info);
343
- }
344
302
}
345
303
}
346
304
}
0 commit comments