MCPcopy Create free account
hub / github.com/Predelnik/DSpellCheck / init_suggestions_box

Method init_suggestions_box

src/ui/ContextMenuHandler.cpp:253–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253void ContextMenuHandler::init_suggestions_box(
254 SuggestionMenuButton &suggestion_button) {
255 if (m_settings.data.suggestions_mode != SuggestionMode::button)
256 return;
257 if (!m_speller_container.active_speller().is_working())
258 return;
259 POINT p;
260 if (!SpellCheckerHelpers::is_spell_checking_needed_for_file(
261 m_editor, m_settings)) // If there's no red underline let's do nothing
262 {
263 suggestion_button.display(false);
264 return;
265 }
266
267 TextPosition pos, length;
268 if (m_spell_checker.is_word_under_cursor_correct(pos, length)) {
269 return;
270 }
271 m_word_under_cursor_length = length;
272 m_word_under_cursor_pos = pos;
273 ACTIVE_VIEW_BLOCK(m_editor);
274 auto line = m_editor.line_from_position(m_word_under_cursor_pos);
275 auto text_height = m_editor.get_text_height(line);
276 auto x_pos =
277 m_editor.get_point_x_from_position(m_word_under_cursor_pos);
278 auto y_pos =
279 m_editor.get_point_y_from_position(m_word_under_cursor_pos);
280 p.x = static_cast<LONG>(x_pos);
281 p.y = static_cast<LONG>(y_pos);
282 auto npp = dynamic_cast<NppInterface *>(&m_editor);
283 if (npp == nullptr)
284 return;
285 RECT r;
286 auto hwnd = npp->get_view_hwnd();
287 GetWindowRect(hwnd, &r);
288
289 ClientToScreen(hwnd, &p);
290
291 if (p.y + text_height - 3 + m_settings.data.suggestion_button_size >= r.bottom) {
292 if (p.x > m_settings.data.suggestion_button_size) {
293 p.y -= m_settings.data.suggestion_button_size;
294 p.x -= m_settings.data.suggestion_button_size;
295 } else
296 p.y -= (text_height + m_settings.data.suggestion_button_size);
297 }
298
299 if (p.x + m_settings.data.suggestion_button_size > r.right)
300 p.x -= m_settings.data.suggestion_button_size;
301
302 if (r.top > p.y + text_height - 3 || r.left > p.x)
303 return;
304
305 MoveWindow(suggestion_button.getHSelf(), p.x,
306 p.y + static_cast<int>(text_height) - 3,
307 m_settings.data.suggestion_button_size,
308 m_settings.data.suggestion_button_size, 1);
309 suggestion_button.display(true, false);
310}

Callers 1

mouse_procFunction · 0.80

Calls 10

getHSelfMethod · 0.80
is_workingMethod · 0.45
displayMethod · 0.45
line_from_positionMethod · 0.45
get_text_heightMethod · 0.45
get_view_hwndMethod · 0.45

Tested by

no test coverage detected