/****************************************************************
** Title  :!IntSoundapp main ** **
** Purpose: internal sound(s) level and bip test
** Version: 0.00 19.11.21 JMB
** fichier: iconbar.c
*****************************************************************/

#include "swis.h"
#include "kernel.h"
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <math.h>

#define TOOLBOX_H   // #include "toolbox.h"
#define WIMP_H	    // #include "wimp.h"
#define WINDOW_H
#define MESSAGETRANS_H

// **********  from Oslib support   **********
#include "OSLibSupport:SysTypes.h"
#include "OSLibSupport:Err.h"	// error handling library
#include "OSLibSupport:x.h"
#include "OSLibSupport:event.h"
#include "OSLibSupport:message.h"
#include "OSLibSupport:ToolBoxTypes.h"

// **********  from Oslib  **********
#include "OSLib/menu.h"
#include "OSLib/proginfo.h"
#include "OSLib/quit.h"

#include "debug.h"
#include "ResEventComps.h"
#include "Main.h"
#include "iconbarmenu.h"
#include "iconbar.h"




//-----   constructeur ------
IconBar::IconBar(toolbox_id OBJ_TEMPLATE)
{
  x_exception xx;
  x_TRY( &xx )
  {
    IconBarId = toolbox_create_object( 0, OBJ_TEMPLATE );
    IconBarHd = window_get_wimp_handle( 0,IconBarId );

    gfenprinstate = FALSE;
    // -------------  ToolBox handlers  registration  ---------------
    event_register_toolbox_handler( IconBarId, IconBar_ADJUST_EVENT, IconbarAdjust_TBhandler, this );
    event_register_toolbox_handler( IconBarId, IconBar_SELECT_EVENT, IconbarSelect_TBhandler, this );
    event_register_toolbox_handler( object_ANY ,action_OBJECT_AUTO_CREATED, FindId_TBhandler, this );
    //event_register_toolbox_handler( event_ANY, action_PROG_INFO_ABOUT_TO_BE_SHOWN, ProgInfo_TBhandler, this );
  }
  x_CATCH( &xx )
  {
    Err_ReportError( !Err_FATAL, "Unable to create MainWindow: %s", xx.error -> errmess );
  }

}

//-----   destructeur ------
IconBar::~IconBar()
{
  delete MenuIconBar;

}


            /*  ==============   ToolBox handlers  IconBar ==============  */

osbool IconBar::IconbarAdjust_TBhandler(bits  Event_code, toolbox_action *Event, toolbox_block *TBblock,void *vhandle)
{
  IGNORE(Event_code);IGNORE(Event);IGNORE(vhandle);IGNORE(TBblock);
  //toolbox_hide_object(0,gMainWindow_id);
  toolbox_hide_object(0,gMainWindow->get_mainwinid() );
   gfenprinstate = FALSE;

   return TRUE;
}


osbool IconBar::IconbarSelect_TBhandler(uint Event_code, ToolboxEvent *Event, toolbox_block *TBblock,void *vhandle)
{
  IGNORE(Event_code);IGNORE(Event);IGNORE(vhandle);IGNORE(TBblock);
   toolbox_show_object(0, gMainWindow->get_mainwinid() ,0,0,0,0);
  gfenprinstate = TRUE;

   return TRUE;
}


osbool IconBar::FindId_TBhandler( uint Event_code, ToolboxEvent *Event, toolbox_block *TBblock, void *vhandle)
{
  IGNORE(Event_code);IGNORE(vhandle); IGNORE(TBblock);
  IconBar *IBar;
  IBar = (IconBar*) vhandle;
  x_exception xx;
  toolbox_class obj_class = toolbox_get_object_class(0,TBblock->self_id);
  x_TRY( &xx )
  {
    switch(obj_class)
    {
      case class_MENU:
        if (!strcmp ( Event->data.created.name, "IconBarMenu")){
          IBar->MenuBar_id = TBblock->self_id;
          //debug_printf("FindId_TBhandler MenuBar_id: %0X ", IBar->MenuBar_id);
          IBar->MenuIconBar = new  IconBarMenu(IBar->MenuBar_id);
        }
      break;
      case class_PROG_INFO:
        if (!strcmp ( Event->data.created.name, "ProgInfo")){
          IBar->ProgInfo_id  =  TBblock->self_id;
          //debug_printf("FindId_TBhandler ProgInfo_id: %0X ", IBar->ProgInfo_id);
        }
      break;
    }

  }
  x_CATCH( &xx )
  {
    Err_ReportError( !Err_FATAL, "Impossible de rcuprer tous les identifiants pour le menu Iconbar: %s", xx.error -> errmess );
  }

   return TRUE;
}

        /* ====  WIMP handlers  ========*/

        /* ====  Messages handlers  ========*/




