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

    File:    Pane2.PaneOpenH.c
    Author:  Copyright  1995 Andrew Sellors.
    Version: 1.05 (03 Oct 1995)
    Purpose: Handles windows with panes.
    History: 1.04 (4th August 1995) Andrew Sellors
             1.05 (03 Oct 1995) JS Added 'Desk_Pane2__' prefix
             1.06 (14 Nov 1995) JS Made SDLS compatible

*/

#include "DeskLib:Pane2.h"
#include "Desklib:Event.h"
#include "Desk.Template.h"
#include "Desklib:EventMsg.h"
#include "Desklib:Error.h"

#include "Pane2Defs.h"

/******************************************************************************/

Desk_SDLS_PtrFn(
	extern,
	Desk_bool,
	Desk_Pane2__PaneOpenEventHandler(Desk_event_pollblock *event, void *reference)
	)
/*extern Desk_bool Desk_Pane2__PaneOpenEventHandler(Desk_event_pollblock *event, void *reference)*/
{
 /*
  * event handler for panes that can be moved (!ArtWorks style)
  * records movement and updates paneoffset
  */
  Desk_window_state panestate;
  Desk_window_state mainstate;
  Desk_pane_listelement *paneelement = reference;

  Desk_Wimp_eOpenWindow(&(event->data.openblock));

 /*
  * get positions of main and pane windows
  */
  Desk_Wimp_eGetWindowState(paneelement->panewindow, &panestate);
  Desk_Wimp_eGetWindowState(paneelement->mainwindow, &mainstate);

 /*
  * update pane offset
  */
  if(paneelement->paneflags.data.mainright)
     paneelement->paneoffset.x = panestate.openblock.screenrect.min.x -
                                 mainstate.openblock.screenrect.max.x;
  else
     paneelement->paneoffset.x = panestate.openblock.screenrect.min.x -
                                 mainstate.openblock.screenrect.min.x;


  if(paneelement->paneflags.data.maintop) /* pane fixed to top of window */
     paneelement->paneoffset.y = mainstate.openblock.screenrect.max.y;

  else /* pane fixed to bottom of window */
     paneelement->paneoffset.y = mainstate.openblock.screenrect.min.y;

  if(paneelement->paneflags.data.panetop) /* pane fixed using top of pane */
     paneelement->paneoffset.y -= panestate.openblock.screenrect.max.y;

  else /* pane fixed using bottom of pane */
     paneelement->paneoffset.y -= panestate.openblock.screenrect.min.y;


  return(Desk_bool_TRUE);
}
