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

    File:    Icon.StartDrag.c
    Author:  Copyright  1992 Jason Williams
    Version: 1.00 (31 Mar 1992)
    Purpose: Starts the drag operation of any icon (i.e. file icon)
*/


#include "Desk.Wimp.h"
#include "Desk.WimpSWIS.h"
#include "Desk.Screen.h"
#include "Desk.Icon.h"


/*  Note: Use Desk_Icon_StartSolidDrag() or Desk_DragASprite_DragIcon() to start
 *  dragging an icon with DragASprite
 */

extern void Desk_Icon_StartDrag(Desk_window_handle window, Desk_icon_handle icon)
{
  Desk_icon_block   istate;
  Desk_window_state wstate;
  Desk_drag_block   drag;
  int          left, top;

  Desk_Wimp_eGetWindowState(window, &wstate);
  Desk_Wimp_eGetIconState(window, icon, &istate);
  left = wstate.openblock.screenrect.min.x - wstate.openblock.scroll.x;
  top  = wstate.openblock.screenrect.max.y - wstate.openblock.scroll.y;

  drag.window = window;
  drag.type   = Desk_drag_FIXEDBOX;

  drag.screenrect.min.x = left + istate.workarearect.min.x;
  drag.screenrect.max.x = left + istate.workarearect.max.x;
  drag.screenrect.min.y = top  + istate.workarearect.min.y;
  drag.screenrect.max.y = top  + istate.workarearect.max.y;

  Desk_Screen_CacheModeInfo();
  drag.parent.min.x = 0;
  drag.parent.min.y = 0;
  drag.parent.max   = Desk_screen_size;

  Desk_Wimp_eDragBox(&drag);
}
