@@ -68,12 +68,6 @@ TextService::~TextService(void) {
6868 }
6969 }
7070
71- if (!langBarButtons_.empty ()) {
72- for (vector<LangBarButton*>::iterator it = langBarButtons_.begin (); it != langBarButtons_.end (); ++it) {
73- LangBarButton* button = *it;
74- button->Release ();
75- }
76- }
7771 if (langBarMgr_) {
7872 langBarMgr_->UnadviseEventSink (langBarSinkCookie_);
7973 }
@@ -108,31 +102,26 @@ DWORD TextService::langBarStatus() const {
108102
109103void TextService::addButton (LangBarButton* button) {
110104 if (button) {
111- langBarButtons_.push_back (button);
112- button->AddRef ();
105+ langBarButtons_.emplace_back (button);
113106 if (isActivated ()) {
114- ITfLangBarItemMgr* langBarItemMgr;
107+ ComPtr< ITfLangBarItemMgr> langBarItemMgr;
115108 if (threadMgr_->QueryInterface (IID_ITfLangBarItemMgr, (void **)&langBarItemMgr) == S_OK) {
116109 langBarItemMgr->AddItem (button);
117- langBarItemMgr->Release ();
118110 }
119111 }
120112 }
121113}
122114
123115void TextService::removeButton (LangBarButton* button) {
124116 if (button) {
125- vector<LangBarButton*>::iterator it;
126- it = find (langBarButtons_.begin (), langBarButtons_.end (), button);
117+ auto it = find (langBarButtons_.begin (), langBarButtons_.end (), button);
127118 if (it != langBarButtons_.end ()) {
128119 if (isActivated ()) {
129- ITfLangBarItemMgr* langBarItemMgr;
120+ ComPtr< ITfLangBarItemMgr> langBarItemMgr;
130121 if (threadMgr_->QueryInterface (IID_ITfLangBarItemMgr, (void **)&langBarItemMgr) == S_OK) {
131122 langBarItemMgr->RemoveItem (button);
132- langBarItemMgr->Release ();
133123 }
134124 }
135- button->Release ();
136125 langBarButtons_.erase (it);
137126 }
138127 }
@@ -621,13 +610,13 @@ STDMETHODIMP_(ULONG) TextService::AddRef(void) {
621610
622611STDMETHODIMP_ (ULONG) TextService::Release(void ) {
623612 assert (refCount_ > 0 );
624- --refCount_;
613+ const ULONG newCount = --refCount_;
625614 if (0 == refCount_) {
626615 // ImeModule needs to do some clean up before deleting the TextService object.
627616 module_->removeTextService (this );
628617 delete this ;
629618 }
630- return refCount_ ;
619+ return newCount ;
631620}
632621
633622// ITfTextInputProcessor
@@ -700,8 +689,7 @@ STDMETHODIMP TextService::Activate(ITfThreadMgr *pThreadMgr, TfClientId tfClient
700689 if (!langBarButtons_.empty ()) {
701690 ComPtr<ITfLangBarItemMgr> langBarItemMgr;
702691 if (threadMgr_->QueryInterface (IID_ITfLangBarItemMgr, (void **)&langBarItemMgr) == S_OK) {
703- for (vector<LangBarButton*>::iterator it = langBarButtons_.begin (); it != langBarButtons_.end (); ++it) {
704- LangBarButton* button = *it;
692+ for (auto & button: langBarButtons_) {
705693 langBarItemMgr->AddItem (button);
706694 }
707695 }
@@ -729,8 +717,7 @@ STDMETHODIMP TextService::Deactivate() {
729717 if (!langBarButtons_.empty ()) {
730718 ComPtr<ITfLangBarItemMgr> langBarItemMgr;
731719 if (threadMgr_->QueryInterface (IID_ITfLangBarItemMgr, (void **)&langBarItemMgr) == S_OK) {
732- for (vector<LangBarButton*>::iterator it = langBarButtons_.begin (); it != langBarButtons_.end (); ++it) {
733- LangBarButton* button = *it;
720+ for (auto & button: langBarButtons_) {
734721 langBarItemMgr->RemoveItem (button);
735722 }
736723 }
0 commit comments