Added std:: prefix for Mac and GUI tools
BUG=#392
TEST=unittest
REF_BUG=71969651
REF_CL=181934774
REF_TIME=2018-01-15T17:41:24+09:00
REF_TIME_RAW=1516005684 +0900
Hiroyuki Komatsu
6 years ago
29 | 29 | |
30 | 30 | MAJOR=2 |
31 | 31 | MINOR=23 |
32 | BUILD=2789 | |
32 | BUILD=2790 | |
33 | 33 | REVISION=102 |
34 | 34 | # This version represents the version of Mozc IME engine (converter, predictor, |
35 | 35 | # etc.). This version info is included both in the Mozc server and in the Mozc |
49 | 49 | POSListProvider::POSListProvider() = default; |
50 | 50 | POSListProvider::~POSListProvider() = default; |
51 | 51 | |
52 | void POSListProvider::GetPOSList(vector<string> *pos_list) const { | |
52 | void POSListProvider::GetPOSList(std::vector<string> *pos_list) const { | |
53 | 53 | SerializedStringArray array; |
54 | 54 | CHECK(array.Init(LoadEmbeddedFile(kPosArray))); |
55 | 55 | pos_list->resize(array.size()); |
39 | 39 | POSListProvider(); |
40 | 40 | ~POSListProvider() override; |
41 | 41 | |
42 | void GetPOSList(vector<string> *pos_list) const override; | |
42 | void GetPOSList(std::vector<string> *pos_list) const override; | |
43 | 43 | }; |
44 | 44 | |
45 | 45 | } // namespace mozc |
117 | 117 | QPainter painter(this); |
118 | 118 | const QRect image_rect = product_image_->rect(); |
119 | 119 | // allow clipping on right / bottom borders |
120 | const QRect draw_rect(max(5, width() - image_rect.width() - 15), | |
121 | max(0, color_frame->y() - image_rect.height()), | |
120 | const QRect draw_rect(std::max(5, width() - image_rect.width() - 15), | |
121 | std::max(0, color_frame->y() - image_rect.height()), | |
122 | 122 | image_rect.width(), image_rect.height()); |
123 | 123 | painter.drawImage(draw_rect, *product_image_.get()); |
124 | 124 | } |
69 | 69 | |
70 | 70 | TranslationDataImpl(); |
71 | 71 | ~TranslationDataImpl() { |
72 | for (map<string, QTranslator *>::iterator it = translators_.begin(); | |
72 | for (std::map<string, QTranslator *>::iterator it = translators_.begin(); | |
73 | 73 | it != translators_.end(); ++it) { |
74 | 74 | delete it->second; |
75 | 75 | } |
77 | 77 | } |
78 | 78 | |
79 | 79 | private: |
80 | map<string, QTranslator *> translators_; | |
80 | std::map<string, QTranslator *> translators_; | |
81 | 81 | QTranslator default_translator_; |
82 | 82 | QFont font_; |
83 | 83 | #ifdef MOZC_SHOW_BUILD_NUMBER_ON_TITLE |
117 | 117 | } |
118 | 118 | QTranslator *translator = new QTranslator; |
119 | 119 | CHECK(translator); |
120 | translators_.insert(make_pair(resource_name, translator)); | |
120 | translators_.insert(std::make_pair(resource_name, translator)); | |
121 | 121 | |
122 | 122 | // Load ":/<resource_name>_<lang>.qm" from a qrc file. |
123 | 123 | if (translator->load(QLocale::system(), resource_name, "_", ":/", ".qm")) { |
102 | 102 | } |
103 | 103 | } |
104 | 104 | #else |
105 | InputFileStream is(lock_name.c_str(), ios::binary|ios::in); | |
105 | InputFileStream is(lock_name.c_str(), std::ios::binary|std::ios::in); | |
106 | 106 | if (!is) { |
107 | 107 | LOG(ERROR) << "cannot open: " << lock_name; |
108 | 108 | return false; |
179 | 179 | } |
180 | 180 | |
181 | 181 | void HandWritingCanvas::listUpdated() { |
182 | vector<string> candidates; | |
182 | std::vector<string> candidates; | |
183 | 183 | recognizer_thread_.GetCandidates(&candidates); |
184 | 184 | |
185 | 185 | list_widget_->clear(); |
201 | 201 | strokes_.resize(strokes_.size() + 1); |
202 | 202 | const float x = static_cast<float>(event->pos().x()) / width(); |
203 | 203 | const float y = static_cast<float>(event->pos().y()) / height(); |
204 | strokes_.back().push_back(make_pair(x, y)); | |
204 | strokes_.back().push_back(std::make_pair(x, y)); | |
205 | 205 | is_drawing_ = true; |
206 | 206 | update(); |
207 | 207 | } |
213 | 213 | |
214 | 214 | const float x = static_cast<float>(event->pos().x()) / width(); |
215 | 215 | const float y = static_cast<float>(event->pos().y()) / height(); |
216 | strokes_.back().push_back(make_pair(x, y)); | |
216 | strokes_.back().push_back(std::make_pair(x, y)); | |
217 | 217 | update(); |
218 | 218 | } |
219 | 219 |
57 | 57 | } |
58 | 58 | |
59 | 59 | // Thread-safe copying of candidates. |
60 | void CopyCandidates( | |
61 | const vector<string> &source, vector<string> *target, QMutex *mutex) { | |
60 | void CopyCandidates(const std::vector<string> &source, | |
61 | std::vector<string> *target, | |
62 | QMutex *mutex) { | |
62 | 63 | DCHECK(target); |
63 | 64 | DCHECK(mutex); |
64 | 65 | QMutexLocker l(mutex); |
98 | 99 | Clock::GetTimeOfDay(&strokes_sec_, &strokes_usec_); |
99 | 100 | } |
100 | 101 | |
101 | void HandWritingThread::GetCandidates(vector<string> *candidates) { | |
102 | void HandWritingThread::GetCandidates(std::vector<string> *candidates) { | |
102 | 103 | CopyCandidates(candidates_, candidates, &candidates_mutex_); |
103 | 104 | } |
104 | 105 | |
117 | 118 | return; |
118 | 119 | } |
119 | 120 | |
120 | vector<string> candidates; | |
121 | std::vector<string> candidates; | |
121 | 122 | status = handwriting::HandwritingManager::Recognize(strokes, &candidates); |
122 | 123 | CopyCandidates(candidates, &candidates_, &candidates_mutex_); |
123 | 124 | last_requested_sec_ = strokes_sec_; |
57 | 57 | void SetStrokes(const handwriting::Strokes &strokes); |
58 | 58 | // Copy internal candidates_ into the candidates. This will make |
59 | 59 | // lock on candidates_ so thead-safe. |
60 | void GetCandidates(vector<string> *candidates); | |
60 | void GetCandidates(std::vector<string> *candidates); | |
61 | 61 | |
62 | 62 | public slots: |
63 | 63 | // This slot invokes the recognition and emit candidatesUpdated(). |
70 | 70 | |
71 | 71 | private: |
72 | 72 | handwriting::Strokes strokes_; |
73 | vector<string> candidates_; | |
73 | std::vector<string> candidates_; | |
74 | 74 | |
75 | 75 | uint64 strokes_sec_; |
76 | 76 | uint32 strokes_usec_; |
89 | 89 | CP932MapData key; |
90 | 90 | key.ucs4 = ucs4; |
91 | 91 | const CP932MapData *result = |
92 | lower_bound(kCP932MapData, | |
93 | kCP932MapData + kCP932MapDataSize, | |
94 | key, | |
95 | UnicodeDataCompare<CP932MapData>()); | |
92 | std::lower_bound(kCP932MapData, | |
93 | kCP932MapData + kCP932MapDataSize, | |
94 | key, | |
95 | UnicodeDataCompare<CP932MapData>()); | |
96 | 96 | if (result == kCP932MapData + kCP932MapDataSize || |
97 | 97 | result->ucs4 != key.ucs4) { |
98 | 98 | return 0; |
108 | 108 | UnihanData key; |
109 | 109 | key.ucs4 = ucs4; |
110 | 110 | const UnihanData *result = |
111 | lower_bound(kUnihanData, | |
112 | kUnihanData + kUnihanDataSize, | |
113 | key, | |
114 | UnicodeDataCompare<UnihanData>()); | |
111 | std::lower_bound(kUnihanData, | |
112 | kUnihanData + kUnihanDataSize, | |
113 | key, | |
114 | UnicodeDataCompare<UnihanData>()); | |
115 | 115 | if (result == kUnihanData + kUnihanDataSize || |
116 | 116 | result->ucs4 != ucs4) { |
117 | 117 | return NULL; |
129 | 129 | key.ucs4 = ucs4; |
130 | 130 | key.description = NULL; |
131 | 131 | const UnicodeData *result = |
132 | lower_bound(kUnicodeData, | |
133 | kUnicodeData + kUnicodeDataSize, | |
134 | key, | |
135 | UnicodeDataCompare<UnicodeData>()); | |
132 | std::lower_bound(kUnicodeData, | |
133 | kUnicodeData + kUnicodeDataSize, | |
134 | key, | |
135 | UnicodeDataCompare<UnicodeData>()); | |
136 | 136 | if (result == kUnicodeData + kUnicodeDataSize || |
137 | 137 | result->ucs4 != ucs4) { |
138 | 138 | return QString(""); |
588 | 588 | SET_CHECKBOX(dictionarySuggestCheckBox, use_dictionary_suggest); |
589 | 589 | SET_CHECKBOX(realtimeConversionCheckBox, use_realtime_conversion); |
590 | 590 | |
591 | suggestionsSizeSpinBox->setValue | |
592 | (max(1, min(9, static_cast<int>(config.suggestions_size())))); | |
591 | suggestionsSizeSpinBox->setValue( | |
592 | std::max(1, std::min(9, static_cast<int>(config.suggestions_size())))); | |
593 | 593 | |
594 | 594 | // tab5 |
595 | 595 | SetSendStatsCheckBox(); |
805 | 805 | void ConfigDialog::EditKeymap() { |
806 | 806 | string current_keymap_table = ""; |
807 | 807 | const QString keymap_name = keymapSettingComboBox->currentText(); |
808 | const map<QString, config::Config::SessionKeymap>::const_iterator itr = | |
808 | const std::map<QString, config::Config::SessionKeymap>::const_iterator itr = | |
809 | 809 | keymapname_sessionkeymap_map_.find(keymap_name); |
810 | 810 | if (itr != keymapname_sessionkeymap_map_.end()) { |
811 | 811 | // Load from predefined mapping file. |
812 | 812 | const char *keymap_file = |
813 | 813 | keymap::KeyMapManager::GetKeyMapFileName(itr->second); |
814 | std::unique_ptr<istream> ifs( | |
814 | std::unique_ptr<std::istream> ifs( | |
815 | 815 | ConfigFileStream::LegacyOpen(keymap_file)); |
816 | 816 | CHECK(ifs.get() != NULL); // should never happen |
817 | stringstream buffer; | |
817 | std::stringstream buffer; | |
818 | 818 | buffer << ifs->rdbuf(); |
819 | 819 | current_keymap_table = buffer.str(); |
820 | 820 | } else { |
108 | 108 | int initial_preedit_method_; |
109 | 109 | bool initial_use_keyboard_to_change_preedit_method_; |
110 | 110 | bool initial_use_mode_indicator_; |
111 | map<QString, config::Config::SessionKeymap> keymapname_sessionkeymap_map_; | |
111 | std::map<QString, config::Config::SessionKeymap> | |
112 | keymapname_sessionkeymap_map_; | |
112 | 113 | }; |
113 | 114 | } // namespace gui |
114 | 115 | } // namespace mozc |
36 | 36 | |
37 | 37 | #include <algorithm> // for unique |
38 | 38 | #include <cctype> |
39 | #include <set> | |
40 | 39 | #include <sstream> |
41 | 40 | #include <string> |
42 | 41 | #include <vector> |
139 | 138 | } |
140 | 139 | |
141 | 140 | bool GenericTableEditorDialog::LoadFromString(const string &str) { |
142 | istringstream istr(str); | |
141 | std::istringstream istr(str); | |
143 | 142 | return LoadFromStream(&istr); |
144 | 143 | } |
145 | 144 | |
146 | 145 | void GenericTableEditorDialog::DeleteSelectedItems() { |
147 | vector<int> rows; | |
146 | std::vector<int> rows; | |
148 | 147 | QList<QTableWidgetItem *> selected = |
149 | 148 | editorTableWidget->selectedItems(); |
150 | 149 | |
157 | 156 | rows.push_back(selected[i]->row()); |
158 | 157 | } |
159 | 158 | |
160 | vector<int>::iterator last = unique(rows.begin(), rows.end()); | |
159 | std::vector<int>::iterator last = unique(rows.begin(), rows.end()); | |
161 | 160 | rows.erase(last, rows.end()); |
162 | 161 | |
163 | 162 | if (rows.empty()) { |
360 | 359 | return kMaxEntrySize; |
361 | 360 | } |
362 | 361 | |
363 | bool GenericTableEditorDialog::LoadFromStream(istream *is) { | |
362 | bool GenericTableEditorDialog::LoadFromStream(std::istream *is) { | |
364 | 363 | return true; |
365 | 364 | } |
366 | 365 |
74 | 74 | |
75 | 75 | // implements a method which loads |
76 | 76 | // internal data from istream |
77 | virtual bool LoadFromStream(istream *is) = 0; | |
77 | virtual bool LoadFromStream(std::istream *is) = 0; | |
78 | 78 | |
79 | 79 | // implements a method which called when |
80 | 80 | // the current view is updated. |
159 | 159 | |
160 | 160 | // Returns true if the key map entry is valid |
161 | 161 | // invalid keymaps are not exported/imported. |
162 | bool IsValidEntry(const vector<string> &fields) { | |
162 | bool IsValidEntry(const std::vector<string> &fields) { | |
163 | 163 | if (fields.size() < 3) { |
164 | 164 | return false; |
165 | 165 | } |
174 | 174 | |
175 | 175 | // Returns true if the key map entry is configurable and |
176 | 176 | // we want to show them. |
177 | bool IsVisibleEntry(const vector<string> &fields) { | |
177 | bool IsVisibleEntry(const std::vector<string> &fields) { | |
178 | 178 | if (fields.size() < 3) { |
179 | 179 | return false; |
180 | 180 | } |
191 | 191 | } |
192 | 192 | |
193 | 193 | private: |
194 | set<uint32> invisible_modifiers_; | |
195 | set<uint32> invisible_key_events_; | |
196 | set<string> invisible_commands_; | |
194 | std::set<uint32> invisible_modifiers_; | |
195 | std::set<uint32> invisible_key_events_; | |
196 | std::set<string> invisible_commands_; | |
197 | 197 | }; |
198 | 198 | |
199 | 199 | class KeyMapTableLoader { |
200 | 200 | public: |
201 | 201 | KeyMapTableLoader() { |
202 | 202 | string line; |
203 | vector<string> fields; | |
204 | set<string> status; | |
205 | set<string> commands; | |
203 | std::vector<string> fields; | |
204 | std::set<string> status; | |
205 | std::set<string> commands; | |
206 | 206 | KeyMapValidator *validator = mozc::Singleton<KeyMapValidator>::get(); |
207 | 207 | |
208 | 208 | // get all command names |
209 | set<string> command_names; | |
209 | std::set<string> command_names; | |
210 | 210 | mozc::keymap::KeyMapManager manager; |
211 | 211 | manager.GetAvailableCommandNameDirect(&command_names); |
212 | 212 | manager.GetAvailableCommandNamePrecomposition(&command_names); |
215 | 215 | manager.GetAvailableCommandNameZeroQuerySuggestion(&command_names); |
216 | 216 | manager.GetAvailableCommandNameSuggestion(&command_names); |
217 | 217 | manager.GetAvailableCommandNamePrediction(&command_names); |
218 | for (set<string>::const_iterator itr = command_names.begin(); | |
218 | for (std::set<string>::const_iterator itr = command_names.begin(); | |
219 | 219 | itr != command_names.end(); ++itr) { |
220 | 220 | if (validator->IsVisibleCommand(*itr)) { |
221 | 221 | commands.insert(*itr); |
226 | 226 | status_ << QString::fromUtf8(kKeyMapStatus[i]); |
227 | 227 | } |
228 | 228 | |
229 | for (set<string>::const_iterator it = commands.begin(); | |
229 | for (std::set<string>::const_iterator it = commands.begin(); | |
230 | 230 | it != commands.end(); ++it) { |
231 | 231 | commands_ << QString::fromUtf8(it->c_str()); |
232 | 232 | } |
322 | 322 | |
323 | 323 | KeyMapEditorDialog::~KeyMapEditorDialog() {} |
324 | 324 | |
325 | bool KeyMapEditorDialog::LoadFromStream(istream *is) { | |
325 | bool KeyMapEditorDialog::LoadFromStream(std::istream *is) { | |
326 | 326 | if (is == NULL) { |
327 | 327 | return false; |
328 | 328 | } |
332 | 332 | return false; |
333 | 333 | } |
334 | 334 | |
335 | vector<string> fields; | |
335 | std::vector<string> fields; | |
336 | 336 | int row = 0; |
337 | 337 | mutable_table_widget()->setRowCount(0); |
338 | 338 | mutable_table_widget()->verticalHeader()->hide(); |
407 | 407 | return false; |
408 | 408 | } |
409 | 409 | |
410 | set<string> new_direct_mode_commands; | |
410 | std::set<string> new_direct_mode_commands; | |
411 | 411 | |
412 | 412 | KeyMapValidator *validator = Singleton<KeyMapValidator>::get(); |
413 | 413 | string *keymap_table = mutable_table(); |
422 | 422 | const string &i18n_command = |
423 | 423 | TableUtil::SafeGetItemText(mutable_table_widget(), i, 2).toStdString(); |
424 | 424 | |
425 | const map<string, string>::const_iterator status_it = | |
425 | const std::map<string, string>::const_iterator status_it = | |
426 | 426 | normalized_status_map_.find(i18n_status); |
427 | 427 | if (status_it == normalized_status_map_.end()) { |
428 | 428 | LOG(ERROR) << "Unsupported i18n status name: " << i18n_status; |
430 | 430 | } |
431 | 431 | const string &status = status_it->second; |
432 | 432 | |
433 | const map<string, string>::const_iterator command_it = | |
433 | const std::map<string, string>::const_iterator command_it = | |
434 | 434 | normalized_command_map_.find(i18n_command); |
435 | 435 | if (command_it == normalized_command_map_.end()) { |
436 | 436 | LOG(ERROR) << "Unsupported i18n command name:" << i18n_command; |
511 | 511 | import_index < arraysize(kKeyMaps)) { |
512 | 512 | const char *keymap_file = |
513 | 513 | keymap::KeyMapManager::GetKeyMapFileName(kKeyMaps[import_index]); |
514 | std::unique_ptr<istream> ifs( | |
514 | std::unique_ptr<std::istream> ifs( | |
515 | 515 | ConfigFileStream::LegacyOpen(keymap_file)); |
516 | 516 | CHECK(ifs.get() != NULL); // should never happen |
517 | 517 | CHECK(LoadFromStream(ifs.get())); |
31 | 31 | |
32 | 32 | #include <QtWidgets/QWidget> |
33 | 33 | |
34 | #include <map> | |
34 | 35 | #include <memory> |
35 | 36 | #include <set> |
36 | 37 | #include <string> |
66 | 67 | virtual string GetDefaultFilename() const { |
67 | 68 | return "keymap.txt"; |
68 | 69 | } |
69 | virtual bool LoadFromStream(istream *is); | |
70 | virtual bool LoadFromStream(std::istream *is); | |
70 | 71 | virtual bool Update(); |
71 | 72 | |
72 | 73 | private: |
73 | 74 | string invisible_keymap_table_; |
74 | 75 | // This is used for deciding whether the user has changed the settings that |
75 | 76 | // are valid only for new applications. |
76 | set<string> direct_mode_commands_; | |
77 | std::set<string> direct_mode_commands_; | |
77 | 78 | std::unique_ptr<QAction *[]> actions_; |
78 | 79 | std::unique_ptr<QAction *[]> import_actions_; |
79 | 80 | std::unique_ptr<ComboBoxDelegate> status_delegate_; |
80 | 81 | std::unique_ptr<ComboBoxDelegate> commands_delegate_; |
81 | 82 | std::unique_ptr<KeyBindingEditorDelegate> keybinding_delegate_; |
82 | 83 | |
83 | map<string, string> normalized_command_map_; | |
84 | map<string, string> normalized_status_map_; | |
84 | std::map<string, string> normalized_command_map_; | |
85 | std::map<string, string> normalized_status_map_; | |
85 | 86 | }; |
86 | 87 | |
87 | 88 | } // namespace gui |
88 | 88 | RomanTableEditorDialog::~RomanTableEditorDialog() {} |
89 | 89 | |
90 | 90 | string RomanTableEditorDialog::GetDefaultRomanTable() { |
91 | std::unique_ptr<istream> ifs(ConfigFileStream::LegacyOpen(kRomanTableFile)); | |
91 | std::unique_ptr<std::istream> ifs( | |
92 | ConfigFileStream::LegacyOpen(kRomanTableFile)); | |
92 | 93 | CHECK(ifs.get() != NULL); // should never happen |
93 | 94 | string line, result; |
94 | vector<string> fields; | |
95 | std::vector<string> fields; | |
95 | 96 | while (getline(*ifs.get(), line)) { |
96 | 97 | if (line.empty()) { |
97 | 98 | continue; |
115 | 116 | return result; |
116 | 117 | } |
117 | 118 | |
118 | bool RomanTableEditorDialog::LoadFromStream(istream *is) { | |
119 | bool RomanTableEditorDialog::LoadFromStream(std::istream *is) { | |
119 | 120 | CHECK(is); |
120 | 121 | string line; |
121 | vector<string> fields; | |
122 | std::vector<string> fields; | |
122 | 123 | mutable_table_widget()->setRowCount(0); |
123 | 124 | mutable_table_widget()->verticalHeader()->hide(); |
124 | 125 | |
168 | 169 | } |
169 | 170 | |
170 | 171 | bool RomanTableEditorDialog::LoadDefaultRomanTable() { |
171 | std::unique_ptr<istream> ifs(ConfigFileStream::LegacyOpen(kRomanTableFile)); | |
172 | std::unique_ptr<std::istream> | |
173 | ifs(ConfigFileStream::LegacyOpen(kRomanTableFile)); | |
172 | 174 | CHECK(ifs.get() != NULL); // should never happen |
173 | 175 | CHECK(LoadFromStream(ifs.get())); |
174 | 176 | return true; |
62 | 62 | virtual string GetDefaultFilename() const { |
63 | 63 | return "romantable.txt"; |
64 | 64 | } |
65 | virtual bool LoadFromStream(istream *is); | |
65 | virtual bool LoadFromStream(std::istream *is); | |
66 | 66 | virtual bool Update(); |
67 | 67 | |
68 | 68 | private: |
187 | 187 | ifs_(new InputFileStream(filename.c_str())), |
188 | 188 | first_line_(true) { |
189 | 189 | const std::streampos begin = ifs_->tellg(); |
190 | ifs_->seekg(0, ios::end); | |
190 | ifs_->seekg(0, std::ios::end); | |
191 | 191 | const size_t size = static_cast<size_t>(ifs_->tellg() - begin); |
192 | ifs_->seekg(0, ios::beg); | |
192 | ifs_->seekg(0, std::ios::beg); | |
193 | 193 | progress_.reset(CreateProgressDialog(message, parent, size)); |
194 | 194 | } |
195 | 195 | |
247 | 247 | void Reset() { |
248 | 248 | // Clear state bit (eofbit, failbit, badbit). |
249 | 249 | ifs_->clear(); |
250 | ifs_->seekg(0, ios_base::beg); | |
250 | ifs_->seekg(0, std::ios_base::beg); | |
251 | 251 | first_line_ = true; |
252 | 252 | } |
253 | 253 | |
391 | 391 | GetTableHeight(dic_content_)); |
392 | 392 | |
393 | 393 | // Get a list of POS and set a custom delagate that holds the list. |
394 | vector<string> tmp_pos_vec; | |
394 | std::vector<string> tmp_pos_vec; | |
395 | 395 | pos_list_provider_->GetPOSList(&tmp_pos_vec); |
396 | 396 | QStringList pos_list; |
397 | 397 | for (size_t i = 0; i < tmp_pos_vec.size(); ++i) { |
1028 | 1028 | UpdateUIStatus(); |
1029 | 1029 | } |
1030 | 1030 | |
1031 | void DictionaryTool::GetSortedSelectedRows(vector<int> *rows) const { | |
1031 | void DictionaryTool::GetSortedSelectedRows(std::vector<int> *rows) const { | |
1032 | 1032 | DCHECK(rows); |
1033 | 1033 | rows->clear(); |
1034 | 1034 | |
1041 | 1041 | rows->push_back(items[i]->row()); |
1042 | 1042 | } |
1043 | 1043 | |
1044 | sort(rows->begin(), rows->end(), greater<int>()); | |
1045 | vector<int>::const_iterator end = unique(rows->begin(), rows->end()); | |
1044 | sort(rows->begin(), rows->end(), std::greater<int>()); | |
1045 | std::vector<int>::const_iterator end = unique(rows->begin(), rows->end()); | |
1046 | 1046 | |
1047 | 1047 | rows->resize(end - rows->begin()); |
1048 | 1048 | } |
1060 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | void DictionaryTool::DeleteWord() { |
1063 | vector<int> rows; | |
1063 | std::vector<int> rows; | |
1064 | 1064 | GetSortedSelectedRows(&rows); |
1065 | 1065 | if (rows.size() == 0) { |
1066 | 1066 | return; |
1144 | 1144 | target_dict_item->data(Qt::UserRole).toULongLong()); |
1145 | 1145 | } |
1146 | 1146 | |
1147 | vector<int> rows; | |
1147 | std::vector<int> rows; | |
1148 | 1148 | GetSortedSelectedRows(&rows); |
1149 | 1149 | if (rows.size() == 0) { |
1150 | 1150 | return; |
1295 | 1295 | } |
1296 | 1296 | } |
1297 | 1297 | } |
1298 | vector<pair<int, QAction *> > change_dictionary_actions; | |
1298 | std::vector<std::pair<int, QAction *> > change_dictionary_actions; | |
1299 | 1299 | // "Move to" is available only when we have 2 or more dictionaries. |
1300 | 1300 | if (dic_list_->count() > 1) { |
1301 | 1301 | QMenu *move_to = menu->addMenu(move_to_menu_text); |
1311 | 1311 | continue; |
1312 | 1312 | } |
1313 | 1313 | change_dictionary_actions.push_back( |
1314 | make_pair(i, move_to->addAction(item->text()))); | |
1314 | std::make_pair(i, move_to->addAction(item->text()))); | |
1315 | 1315 | } |
1316 | 1316 | } |
1317 | 1317 | } |
1320 | 1320 | |
1321 | 1321 | menu->addSeparator(); |
1322 | 1322 | QMenu *change_category_to = menu->addMenu(tr("Change category to")); |
1323 | vector<string> pos_list; | |
1323 | std::vector<string> pos_list; | |
1324 | 1324 | pos_list_provider_->GetPOSList(&pos_list); |
1325 | vector<QAction *> change_pos_actions(pos_list.size()); | |
1325 | std::vector<QAction *> change_pos_actions(pos_list.size()); | |
1326 | 1326 | for (size_t i = 0; i < pos_list.size(); ++i) { |
1327 | 1327 | change_pos_actions[i] = change_category_to->addAction( |
1328 | 1328 | QString::fromUtf8(pos_list[i].c_str())); |
36 | 36 | |
37 | 37 | #include <memory> |
38 | 38 | #include <string> |
39 | #include <vector> | |
39 | 40 | |
40 | 41 | #include "base/port.h" |
41 | 42 | #include "gui/dictionary_tool/ui_dictionary_tool.h" |
177 | 178 | |
178 | 179 | // Helper function for DeleteWord and MoveTo. |
179 | 180 | // Fills selected word entry rows as a unique sorted sequence. |
180 | void GetSortedSelectedRows(vector<int> *rows) const; | |
181 | void GetSortedSelectedRows(std::vector<int> *rows) const; | |
181 | 182 | |
182 | 183 | // Returns a pointer to the first selected dictionary. |
183 | 184 | // Returns NULL if no dictionary is selected. |
105 | 105 | |
106 | 106 | void FindDialog::Find(FindDialog::Direction direction) { |
107 | 107 | const QString &query = QuerylineEdit->text(); |
108 | const int start_row = max(0, table_->currentRow()); | |
109 | int start_column = min(1, max(0, table_->currentColumn())); | |
108 | const int start_row = std::max(0, table_->currentRow()); | |
109 | int start_column = std::min(1, std::max(0, table_->currentColumn())); | |
110 | 110 | int matched_column = -1; |
111 | 111 | int matched_row = -1; |
112 | 112 |
89 | 89 | } |
90 | 90 | if (!mozc_flags::SetFlag(key, env)) { |
91 | 91 | #ifndef IGNORE_INVALID_FLAG |
92 | cerr << "Unknown/Invalid flag " << key << endl; | |
92 | std::cerr << "Unknown/Invalid flag " << key << std::endl; | |
93 | 93 | #endif |
94 | 94 | } |
95 | 95 | } |
144 | 144 | #endif // !ENABLE_CLOUD_SYNC |
145 | 145 | |
146 | 146 | // Initialize ComboBox |
147 | vector<string> pos_set; | |
147 | std::vector<string> pos_set; | |
148 | 148 | pos_list_provider_->GetPOSList(&pos_set); |
149 | 149 | CHECK(!pos_set.empty()); |
150 | 150 |
32 | 32 | #include "ipc/ipc.h" |
33 | 33 | |
34 | 34 | #include <map> |
35 | #include <vector> | |
36 | 35 | |
37 | 36 | #include <launch.h> |
38 | 37 | #include <mach/mach.h> |
134 | 133 | class DefaultServerMachPortManager : public MachPortManagerInterface { |
135 | 134 | public: |
136 | 135 | ~DefaultServerMachPortManager() { |
137 | for (map<string, mach_port_t>::const_iterator it = mach_ports_.begin(); | |
136 | for (std::map<string, mach_port_t>::const_iterator it = mach_ports_.begin(); | |
138 | 137 | it != mach_ports_.end(); ++it) { |
139 | 138 | mach_port_destroy(mach_task_self(), it->second); |
140 | 139 | } |
150 | 149 | |
151 | 150 | DLOG(INFO) << "\"" << port_name << "\""; |
152 | 151 | |
153 | map<string, mach_port_t>::const_iterator it = mach_ports_.find(port_name); | |
152 | std::map<string, mach_port_t>::const_iterator it = | |
153 | mach_ports_.find(port_name); | |
154 | 154 | if (it != mach_ports_.end()) { |
155 | 155 | *port = it->second; |
156 | 156 | return true; |
169 | 169 | } |
170 | 170 | |
171 | 171 | private: |
172 | map<string, mach_port_t> mach_ports_; | |
172 | std::map<string, mach_port_t> mach_ports_; | |
173 | 173 | }; |
174 | 174 | |
175 | 175 | struct mach_ipc_send_message { |
74 | 74 | |
75 | 75 | namespace { |
76 | 76 | // set of bundle IDs of applications on which Mozc should not open urls. |
77 | const set<string> *gNoOpenLinkApps = nullptr; | |
77 | const std::set<string> *gNoOpenLinkApps = nullptr; | |
78 | 78 | // The mapping from the CompositionMode enum to the actual id string |
79 | 79 | // of composition modes. |
80 | const map<CompositionMode, NSString *> *gModeIdMap = nullptr; | |
81 | const set<string> *gNoSelectedRangeApps = nullptr; | |
82 | const set<string> *gNoDisplayModeSwitchApps = nullptr; | |
83 | const set<string> *gNoSurroundingTextApps = nullptr; | |
80 | const std::map<CompositionMode, NSString *> *gModeIdMap = nullptr; | |
81 | const std::set<string> *gNoSelectedRangeApps = nullptr; | |
82 | const std::set<string> *gNoDisplayModeSwitchApps = nullptr; | |
83 | const std::set<string> *gNoSurroundingTextApps = nullptr; | |
84 | 84 | |
85 | 85 | // TODO(horo): This value should be get from system configuration. |
86 | 86 | // DoubleClickInterval can be get from NSEvent (MacOSX ver >= 10.6) |
143 | 143 | return mozc::commands::DIRECT; |
144 | 144 | } |
145 | 145 | |
146 | bool IsBannedApplication(const set<string>* bundleIdSet, | |
146 | bool IsBannedApplication(const std::set<string>* bundleIdSet, | |
147 | 147 | const string& bundleId) { |
148 | 148 | return bundleIdSet == nullptr || bundleId.empty() || |
149 | 149 | bundleIdSet->find(bundleId) != bundleIdSet->end(); |
187 | 187 | return self; |
188 | 188 | } |
189 | 189 | keyCodeMap_ = [[KeyCodeMap alloc] init]; |
190 | clientBundle_ = new(nothrow) string; | |
190 | clientBundle_ = new(std::nothrow) string; | |
191 | 191 | replacementRange_ = NSMakeRange(NSNotFound, 0); |
192 | 192 | originalString_ = [[NSMutableString alloc] init]; |
193 | 193 | composedString_ = [[NSMutableAttributedString alloc] init]; |
196 | 196 | checkInputMode_ = YES; |
197 | 197 | suppressSuggestion_ = NO; |
198 | 198 | yenSignCharacter_ = mozc::config::Config::YEN_SIGN; |
199 | candidateController_ = new(nothrow) mozc::renderer::RendererClient; | |
200 | rendererCommand_ = new(nothrow)RendererCommand; | |
199 | candidateController_ = new(std::nothrow) mozc::renderer::RendererClient; | |
200 | rendererCommand_ = new(std::nothrow)RendererCommand; | |
201 | 201 | mozcClient_ = mozc::client::ClientFactory::NewClient(); |
202 | 202 | imkServer_ = reinterpret_cast<id<ServerCallback> >(server); |
203 | 203 | imkClientForTest_ = nil; |
257 | 257 | } |
258 | 258 | |
259 | 259 | + (void)initializeConstants { |
260 | set<string> *noOpenlinkApps = new(nothrow) set<string>; | |
260 | std::set<string> *noOpenlinkApps = new(std::nothrow) std::set<string>; | |
261 | 261 | if (noOpenlinkApps) { |
262 | 262 | // should not open links during screensaver. |
263 | 263 | noOpenlinkApps->insert("com.apple.securityagent"); |
264 | 264 | gNoOpenLinkApps = noOpenlinkApps; |
265 | 265 | } |
266 | 266 | |
267 | map<CompositionMode, NSString *> *newMap = | |
268 | new(nothrow) map<CompositionMode, NSString *>; | |
267 | std::map<CompositionMode, NSString *> *newMap = | |
268 | new(std::nothrow) std::map<CompositionMode, NSString *>; | |
269 | 269 | if (newMap) { |
270 | 270 | (*newMap)[mozc::commands::DIRECT] = GetLabelForSuffix("Roman"); |
271 | 271 | (*newMap)[mozc::commands::HIRAGANA] = GetLabelForSuffix("base"); |
277 | 277 | gModeIdMap = newMap; |
278 | 278 | } |
279 | 279 | |
280 | set<string> *noSelectedRangeApps = new(nothrow) set<string>; | |
280 | std::set<string> *noSelectedRangeApps = new(std::nothrow) std::set<string>; | |
281 | 281 | if (noSelectedRangeApps) { |
282 | 282 | // Do not call selectedRange: method for the following |
283 | 283 | // applications because it could lead to application crash. |
294 | 294 | // mode. When the first composition character is alphanumeric (such |
295 | 295 | // like pressing Shift-A at first), that character is directly |
296 | 296 | // inserted into application instead of composition starting "A". |
297 | set<string> *noDisplayModeSwitchApps = new(nothrow) set<string>; | |
297 | std::set<string> *noDisplayModeSwitchApps = | |
298 | new(std::nothrow) std::set<string>; | |
298 | 299 | if (noDisplayModeSwitchApps) { |
299 | 300 | noDisplayModeSwitchApps->insert("com.microsoft.Word"); |
300 | 301 | gNoDisplayModeSwitchApps = noDisplayModeSwitchApps; |
301 | 302 | } |
302 | 303 | |
303 | set<string> *noSurroundingTextApps = new(nothrow) set<string>; | |
304 | std::set<string> *noSurroundingTextApps = new(std::nothrow) std::set<string>; | |
304 | 305 | if (noSurroundingTextApps) { |
305 | 306 | // Disables the surrounding text feature for the following application |
306 | 307 | // because calling attributedSubstringFromRange to it is very heavy. |
479 | 480 | return; |
480 | 481 | } |
481 | 482 | |
482 | map<CompositionMode, NSString *>::const_iterator it = gModeIdMap->find(mode_); | |
483 | std::map<CompositionMode, NSString *>::const_iterator it = | |
484 | gModeIdMap->find(mode_); | |
483 | 485 | if (it == gModeIdMap->end()) { |
484 | 486 | LOG(ERROR) << "mode: " << mode_ << " is invalid"; |
485 | 487 | return; |
167 | 167 | unsigned short keyCode = [event keyCode]; |
168 | 168 | unichar inputChar = [((nsModifiers == NSShiftKeyMask) ? |
169 | 169 | inputString : inputStringRaw) characterAtIndex:0]; |
170 | map<unsigned short, KeyEvent::SpecialKey>::const_iterator sp_iter = | |
170 | std::map<unsigned short, KeyEvent::SpecialKey>::const_iterator sp_iter = | |
171 | 171 | kSpecialKeyMap->find(keyCode); |
172 | 172 | if (sp_iter != kSpecialKeyMap->end()) { |
173 | 173 | keyEvent->set_special_key(sp_iter->second); |
174 | 174 | } else { |
175 | map<unichar, KeyEvent::SpecialKey>::const_iterator spc_iter = | |
175 | std::map<unichar, KeyEvent::SpecialKey>::const_iterator spc_iter = | |
176 | 176 | kSpecialCharMap->find(inputChar); |
177 | 177 | if (spc_iter != kSpecialCharMap->end()) { |
178 | 178 | keyEvent->set_special_key(spc_iter->second); |
184 | 184 | |
185 | 185 | // fill kana "key_string" if mode is kana. |
186 | 186 | if (inputMode_ == KANA && !keyEvent->has_special_key()) { |
187 | map<unsigned short, const char *>::const_iterator kana_iter; | |
187 | std::map<unsigned short, const char *>::const_iterator kana_iter; | |
188 | 188 | if (nsModifiers == NSShiftKeyMask && kKanaMapShift && |
189 | 189 | (kana_iter = kKanaMapShift->find(keyCode)) != kKanaMapShift->end()) { |
190 | 190 | keyEvent->set_key_string(kana_iter->second); |
67 | 67 | // than KeyCodeMap.mm |
68 | 68 | |
69 | 69 | namespace { |
70 | static map<%(key_type)s, %(result_type)s> *k%(mapname)s = nullptr; | |
71 | static map<%(key_type)s, %(result_type)s> *k%(mapname)sShift = nullptr; | |
70 | static std::map<%(key_type)s, %(result_type)s> *k%(mapname)s = nullptr; | |
71 | static std::map<%(key_type)s, %(result_type)s> *k%(mapname)sShift = nullptr; | |
72 | 72 | static once_t kOnceFor%(mapname)s = MOZC_ONCE_INIT; |
73 | 73 | void Init%(mapname)s() { |
74 | 74 | if (k%(mapname)s != nullptr || k%(mapname)sShift != nullptr) { |
75 | 75 | return; |
76 | 76 | } |
77 | k%(mapname)s = new(nothrow)map<%(key_type)s, %(result_type)s>; | |
77 | k%(mapname)s = new(std::nothrow)std::map<%(key_type)s, %(result_type)s>; | |
78 | 78 | if (k%(mapname)s == nullptr) { |
79 | 79 | return; |
80 | 80 | } |
81 | k%(mapname)sShift = new(nothrow)map<%(key_type)s, %(result_type)s>; | |
81 | k%(mapname)sShift = new(std::nothrow)std::map<%(key_type)s, %(result_type)s>; | |
82 | 82 | if (k%(mapname)sShift == nullptr) { |
83 | 83 | delete k%(mapname)s; |
84 | 84 | k%(mapname)s = nullptr; |
186 | 186 | candidates.focused_index() - candidates.candidate(0).index(); |
187 | 187 | if (candidates.candidate_size() >= focused_row && |
188 | 188 | candidates.candidate(focused_row).has_information_id()) { |
189 | const uint32 delay = max(0u, candidates.usages().delay()); | |
189 | const uint32 delay = std::max(0u, candidates.usages().delay()); | |
190 | 190 | infolist_window_->DelayShow(delay); |
191 | 191 | } else { |
192 | 192 | infolist_window_->DelayHide(kHideWindowDelay); |
122 | 122 | CallOnce(&g_OnceForInitializeStyle, InitializeDefaultStyle); |
123 | 123 | self = [super initWithFrame:frame]; |
124 | 124 | if (self) { |
125 | tableLayout_ = new(nothrow)TableLayout; | |
126 | RendererStyle *style = new(nothrow)RendererStyle; | |
125 | tableLayout_ = new(std::nothrow)TableLayout; | |
126 | RendererStyle *style = new(std::nothrow)RendererStyle; | |
127 | 127 | if (style) { |
128 | 128 | RendererStyleHandler::GetRendererStyle(style); |
129 | 129 | } |