/*
    ####             #    #     # #
    #   #            #    #       #          The FreeWare C library for
    #   #  ##   ###  #  # #     # ###             RISC OS machines
    #   # #  # #     # #  #     # #  #   ___________________________________
    #   # ####  ###  ##   #     # #  #
    #   # #        # # #  #     # #  #    Please refer to the accompanying
    ####   ### ####  #  # ##### # ###    documentation for conditions of use
    ________________________________________________________________________

    File:    Window.DeleteOrig.c
    Author:  Copyright  1995 Sergio Monesi (original code from
                              Window.Delete.c by Jason Williams)
    Version: 1.00 (15 Feb 1995)
    Purpose: High-level window management functions: Delete a window
             created with Desk_Window_CreateOrig
*/


#include "Desk.LinkList.h"
#include "Desk.WimpSWIs.h"
#include "Desk.Template.h"
#include "Desk.Event.h"
#include "Desk.EventMsg.h"
#include "Desk.Window.h"
#include "Desk.Screen.h"
#include "Desk.Error.h"
#include "Desk.Window.h"
#include "Desk.DeskMem.h"

#include "WindowDefs.h"

#include <stdlib.h>
#include <string.h>


extern Desk_linklist_header Desk_window_listanchor;



extern void Desk_Window_DeleteOrig(Desk_window_handle window)
{
  windowrec       *ptr;

  Desk_Event_ReleaseWindow(window);       /* Release all handlers for this window */
  Desk_EventMsg_ReleaseWindow(window);

  Desk_Wimp_eCloseWindow(window);                                  /* say bye bye! */
  Desk_Wimp_eDeleteWindow(window);

  ptr = (windowrec *) Desk_window_listanchor.next;
  while (ptr != NULL)
  {
    if (ptr->window == window)
      break;
    ptr = (windowrec *) ptr->header.next;
  }

  if (ptr == NULL)
    return;              /* Window not created with Desk_Window_Show(). Bad user! */

  Desk_LinkList_Unlink(&Desk_window_listanchor, &(ptr->header));

  Desk_DeskMem_Free(ptr);                         /* Free up the window's list entry      */
}
