src/window.cpp
changeset 9083 e18c37b3a45e
parent 9082 8a28686aeff2
child 9111 48ce04029fe4
equal deleted inserted replaced
9082:8a28686aeff2 9083:e18c37b3a45e
   414  */
   414  */
   415 void DeleteWindow(Window *w)
   415 void DeleteWindow(Window *w)
   416 {
   416 {
   417 	if (w == NULL) return;
   417 	if (w == NULL) return;
   418 
   418 
   419 	/* Delete any children a window might have in a head-recursive manner */
       
   420 	Window *v = FindChildWindow(w);
       
   421 	if (v != NULL) DeleteWindow(v);
       
   422 
       
   423 	if (_thd.place_mode != VHM_NONE &&
   419 	if (_thd.place_mode != VHM_NONE &&
   424 			_thd.window_class == w->window_class &&
   420 			_thd.window_class == w->window_class &&
   425 			_thd.window_number == w->window_number) {
   421 			_thd.window_number == w->window_number) {
   426 		ResetObjectToPlace();
   422 		ResetObjectToPlace();
   427 	}
   423 	}
       
   424 
       
   425 	/* Prevent Mouseover() from resetting mouse-over coordinates on a non-existing window */
       
   426 	if (_mouseover_last_w == w) _mouseover_last_w = NULL;
       
   427 
       
   428 	/* Find the window in the z-array, and effectively remove it
       
   429 	 * by moving all windows after it one to the left. This must be
       
   430 	 * done before removing the child so we cannot cause recursion
       
   431 	 * between the deletion of the parent and the child. */
       
   432 	Window **wz = FindWindowZPosition(w);
       
   433 	if (wz == NULL) return;
       
   434 	memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz);
       
   435 	_last_z_window--;
       
   436 
       
   437 	/* Delete any children a window might have in a head-recursive manner */
       
   438 	Window *v = FindChildWindow(w);
       
   439 	if (v != NULL) DeleteWindow(v);
   428 
   440 
   429 	CallWindowEventNP(w, WE_DESTROY);
   441 	CallWindowEventNP(w, WE_DESTROY);
   430 	if (w->viewport != NULL) DeleteWindowViewport(w);
   442 	if (w->viewport != NULL) DeleteWindowViewport(w);
   431 
   443 
   432 	SetWindowDirty(w);
   444 	SetWindowDirty(w);
   433 	free(w->widget);
   445 	free(w->widget);
   434 	w->widget = NULL;
   446 	w->widget = NULL;
   435 	w->widget_count = 0;
   447 	w->widget_count = 0;
   436 	w->parent = NULL;
   448 	w->parent = NULL;
   437 
       
   438 	/* Prevent Mouseover() from resetting mouse-over coordinates on a non-existing window */
       
   439 	if (_mouseover_last_w == w) _mouseover_last_w = NULL;
       
   440 
       
   441 	/* Find the window in the z-array, and effectively remove it
       
   442 	 * by moving all windows after it one to the left */
       
   443 	Window **wz = FindWindowZPosition(w);
       
   444 	if (wz == NULL) return;
       
   445 	memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz);
       
   446 	_last_z_window--;
       
   447 
   449 
   448 	delete w;
   450 	delete w;
   449 }
   451 }
   450 
   452 
   451 /**
   453 /**