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

    File:    Pane2.GetPNumber.c
    Author:  Copyright  1995 Andrew Sellors.
    Version: 1.04 (4th August 1995)
    Purpose: Handles windows with panes.
*/

#include "Desk.Pane2.h"
#include "Pane2Defs.h"
#include "Desk.Event.h"
#include "Desk.Template.h"
#include "Desk.EventMsg.h"
#include "Desk.Error.h"

#include <stdlib.h>


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

extern int Desk_Pane2_GetPaneNumber(Desk_window_handle mainwindow, Desk_window_handle panewindow)
{
 /*
  * Returns pane number of 'panewindow' attatched to 'mainwindow' or 0 if the
  * window was not found.
  */
  Desk_main_listelement *mainelement;
  Desk_pane_listelement *paneelement;
  int panecount;

 /*
  * find element for main window and return 0 if mainwindow not present
  */
  mainelement = Desk_Pane2__FindMainWindow(mainwindow);
  if(mainelement == NULL)
     return(0); /* not found */

 /*
  * find first pane window
  */
  paneelement = Desk_LinkList_FirstItem(&(mainelement->paneanchor));

  panecount = 1;

  while(paneelement != NULL){

     if(paneelement->panewindow == panewindow)
        return(panecount); /* pane window found */

    /*
     * find next pane window
     */
     paneelement = Desk_LinkList_NextItem(&(paneelement->header));

     panecount++;
  }

  return(0); /* not found */

}
