window.c
changeset 5416 b9a3326da943
parent 5415 60e096e4818d
child 5429 a664da42d64e
equal deleted inserted replaced
5415:60e096e4818d 5416:b9a3326da943
  1403 	_cursor.delta.x = 0;
  1403 	_cursor.delta.x = 0;
  1404 	_cursor.delta.y = 0;
  1404 	_cursor.delta.y = 0;
  1405 	return false;
  1405 	return false;
  1406 }
  1406 }
  1407 
  1407 
  1408 static void MaybeBringWindowToFront(const Window *w)
  1408 /** Check if a window can be made top-most window, and if so do
  1409 {
  1409  * it. If a window does not obscure any other windows, it will not
       
  1410  * be brought to the foreground. Also if the only obscuring windows
       
  1411  * are so-called system-windows, the window will not be moved.
       
  1412  * The function will return false when a child window of this window is a
       
  1413  * modal-popup; function returns a false and child window gets a white border
       
  1414  * @param w Window to bring on-top
       
  1415  * @return false if the window has an active modal child, true otherwise */
       
  1416 static bool MaybeBringWindowToFront(const Window *w)
       
  1417 {
       
  1418 	bool bring_to_front = false;
  1410 	Window* const *wz;
  1419 	Window* const *wz;
  1411 	Window* const *uz;
  1420 	Window* const *uz;
  1412 
  1421 
  1413 	if (w->window_class == WC_MAIN_WINDOW ||
  1422 	if (w->window_class == WC_MAIN_WINDOW ||
  1414 			IsVitalWindow(w) ||
  1423 			IsVitalWindow(w) ||
  1415 			w->window_class == WC_TOOLTIPS ||
  1424 			w->window_class == WC_TOOLTIPS ||
  1416 			w->window_class == WC_DROPDOWN_MENU) {
  1425 			w->window_class == WC_DROPDOWN_MENU) {
  1417 		return;
  1426 		return true;
  1418 	}
  1427 	}
  1419 
  1428 
  1420 	wz = FindWindowZPosition(w);
  1429 	wz = FindWindowZPosition(w);
  1421 	for (uz = wz; ++uz != _last_z_window;) {
  1430 	for (uz = wz; ++uz != _last_z_window;) {
  1422 		const Window *u = *uz;
  1431 		Window *u = *uz;
       
  1432 
       
  1433 		/* A modal child will prevent the activation of the parent window */
       
  1434 		if (u->parent == w && (u->desc_flags & WDF_MODAL)) {
       
  1435 			u->flags4 |= WF_WHITE_BORDER_MASK;
       
  1436 			SetWindowDirty(u);
       
  1437 			return false;
       
  1438 		}
  1423 
  1439 
  1424 		if (u->window_class == WC_MAIN_WINDOW ||
  1440 		if (u->window_class == WC_MAIN_WINDOW ||
  1425 				IsVitalWindow(u) ||
  1441 				IsVitalWindow(u) ||
  1426 				u->window_class == WC_TOOLTIPS ||
  1442 				u->window_class == WC_TOOLTIPS ||
  1427 				u->window_class == WC_DROPDOWN_MENU) {
  1443 				u->window_class == WC_DROPDOWN_MENU) {
  1428 			continue;
  1444 			continue;
  1429 		}
  1445 		}
  1430 
  1446 
       
  1447 		/* Window sizes don't interfere, leave z-order alone */
  1431 		if (w->left + w->width <= u->left ||
  1448 		if (w->left + w->width <= u->left ||
  1432 				u->left + u->width <= w->left ||
  1449 				u->left + u->width <= w->left ||
  1433 				w->top  + w->height <= u->top ||
  1450 				w->top  + w->height <= u->top ||
  1434 				u->top + u->height <= w->top) {
  1451 				u->top + u->height <= w->top) {
  1435 			continue;
  1452 			continue;
  1436 		}
  1453 		}
  1437 
  1454 
  1438 		BringWindowToFront(w);
  1455 		bring_to_front = true;
  1439 		return;
  1456 	}
  1440 	}
  1457 
       
  1458 	if (bring_to_front) BringWindowToFront(w);
       
  1459 	return true;
  1441 }
  1460 }
  1442 
  1461 
  1443 /** Send a message from one window to another. The receiving window is found by
  1462 /** Send a message from one window to another. The receiving window is found by
  1444  * @param w @see Window pointer pointing to the other window
  1463  * @param w @see Window pointer pointing to the other window
  1445  * @param msg Specifies the message to be sent
  1464  * @param msg Specifies the message to be sent
  1614 
  1633 
  1615 	if (click == 0 && mousewheel == 0) return;
  1634 	if (click == 0 && mousewheel == 0) return;
  1616 
  1635 
  1617 	w = FindWindowFromPt(x, y);
  1636 	w = FindWindowFromPt(x, y);
  1618 	if (w == NULL) return;
  1637 	if (w == NULL) return;
  1619 	MaybeBringWindowToFront(w);
  1638 	if (!MaybeBringWindowToFront(w)) return;
  1620 	vp = IsPtInWindowViewport(w, x, y);
  1639 	vp = IsPtInWindowViewport(w, x, y);
  1621 
  1640 
  1622 	/* Don't allow any action in a viewport if either in menu of in generating world */
  1641 	/* Don't allow any action in a viewport if either in menu of in generating world */
  1623 	if (vp != NULL && (_game_mode == GM_MENU || IsGeneratingWorld())) return;
  1642 	if (vp != NULL && (_game_mode == GM_MENU || IsGeneratingWorld())) return;
  1624 
  1643