MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / MaybeBringWindowToFront

Function MaybeBringWindowToFront

src/window.cpp:2504–2554  ·  view source on GitHub ↗

* Check if a window can be made relative top-most window, and if so do * it. If a window does not obscure any other windows, it will not * be brought to the foreground. Also if the only obscuring windows * are so-called system-windows, the window will not be moved. * The function will return false when a child window of this window is a * modal-popup; function returns a false and child window

Source from the content-addressed store, hash-verified

2502 * @return false if the window has an active modal child, true otherwise
2503 */
2504static bool MaybeBringWindowToFront(Window *w)
2505{
2506 bool bring_to_front = false;
2507
2508 if (w->window_class == WC_MAIN_WINDOW ||
2509 IsVitalWindow(w) ||
2510 w->window_class == WC_TOOLTIPS ||
2511 w->window_class == WC_DROPDOWN_MENU) {
2512 return true;
2513 }
2514
2515 /* Use unshaded window size rather than current size for shaded windows. */
2516 int w_width = w->width;
2517 int w_height = w->height;
2518 if (w->IsShaded()) {
2519 w_width = w->unshaded_size.width;
2520 w_height = w->unshaded_size.height;
2521 }
2522
2523 Window::IteratorToFront it(w);
2524 ++it;
2525 for (; !it.IsEnd(); ++it) {
2526 Window *u = *it;
2527 /* A modal child will prevent the activation of the parent window */
2528 if (u->parent == w && u->window_desc.flags.Test(WindowDefaultFlag::Modal)) {
2529 u->SetWhiteBorder();
2530 u->SetDirty();
2531 return false;
2532 }
2533
2534 if (u->window_class == WC_MAIN_WINDOW ||
2535 IsVitalWindow(u) ||
2536 u->window_class == WC_TOOLTIPS ||
2537 u->window_class == WC_DROPDOWN_MENU) {
2538 continue;
2539 }
2540
2541 /* Window sizes don't interfere, leave z-order alone */
2542 if (w->left + w_width <= u->left ||
2543 u->left + u->width <= w->left ||
2544 w->top + w_height <= u->top ||
2545 u->top + u->height <= w->top) {
2546 continue;
2547 }
2548
2549 bring_to_front = true;
2550 }
2551
2552 if (bring_to_front) BringWindowToFront(w);
2553 return true;
2554}
2555
2556/**
2557 * Process keypress for editbox widget.

Callers 1

MouseLoopFunction · 0.85

Calls 7

IsVitalWindowFunction · 0.85
BringWindowToFrontFunction · 0.85
IsShadedMethod · 0.80
TestMethod · 0.80
SetWhiteBorderMethod · 0.80
IsEndMethod · 0.45
SetDirtyMethod · 0.45

Tested by

no test coverage detected