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

/*                                                              */

/*                          watchdog.c                          */

/*                                                              */

/*                Seal - free desktop environment               */

/*                                                              */

/*                      Copyright  (c) 2000                     */

/*                         Florian Xaver                        */

/*                     All Rights Reserved                      */

/*                                                              */

/* mail : free.seal@aon.at                                      */

/* web  : http://members.aon.at/seal                            */

/*                                                              */

/* This file is part of Seal.                                   */

/*                                                              */

/* Seal is free software; you can redistribute it and/or        */

/* modify it under the terms of the GNU General Public License  */

/* as published by the Free Software Foundation; either version */

/* 2, or (at your option) any later version.                    */

/*                                                              */

/* Seal is distributed in the hope that it will be useful, but  */

/* WITHOUT ANY WARRANTY; without even the implied warranty of   */

/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See    */

/* the GNU General Public License for more details.             */

/*                                                              */

/* You should have received a copy of the GNU General Public    */

/* License along with Seal; see the file COPYING.  If not,      */

/* write to the Free Software Foundation, 675 Mass Ave,         */

/* Cambridge, MA 02139, USA.                                    */

/*                                                              */

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



#include"dpmi.h"

#include"go32.h"

#include"allegro.h"

#include"seal.h"

#include"dos.h"

#include"app.h"

#include"button.h"

#include"dialogs.h"

#include"iodlg.h"

#include"program.h"

#include"list.h"









p_textline stat1 = NULL;

p_textline stat2 = NULL;

p_textline stat3 = NULL;

p_textline stat4 = NULL;

p_object   o = NULL;    // Window







void  imager_translate_event ( p_object o, p_event e )

{



  RETVIEW(o, e);

  win_translate_event(o, e);







    if (e->type & EV_MOUSE ) { /* mouse event */



    if ( OBJECT(mouse)->state & MO_SF_MOUSEMDOWN ) { /* select */



       msgbox(MW_INFO, MB_CLOSE, "(c) Florian Xaver 2000");

       clear_event(e);

       };

       };





};







void  stat1_func_callback ( p_object s ) /* it's call each second */

{





     l_long dpmi_phy = _go32_dpmi_remaining_physical_memory();     

     TEXTLINE(s)->set_text(TEXTLINE(s),

                               set_format_text(NULL, "[DPMI:physical:%dByte (%dMB)]",

                               dpmi_phy,

                               dpmi_phy/(1024*1024)

                               ));



};

                               

void  stat2_func_callback ( p_object s ) /* it's call each second */

{                               



     l_long dpmi_vir = _go32_dpmi_remaining_virtual_memory();

     TEXTLINE(s)->set_text(TEXTLINE(s),

                              set_format_text(NULL, "[DPMI:virtual:%dByte (%dMB)]",

                               dpmi_vir,

                               dpmi_vir/(1024*1024)

                               ));

};



void  stat3_func_callback ( p_object s ) /* it's call each second */

{                               

     struct time tm;

     gettime(&tm);     

     TEXTLINE(s)->set_text(TEXTLINE(s),

                               set_format_text(NULL, "[%02d:%02d.%02d|Tasks:%d|Processt:%d]",

                               tm.ti_hour,tm.ti_min,tm.ti_sec, OBJECT(desktop)->index_of (OBJECT(desktop), OBJECT(desktop)->last_view(OBJECT(desktop))),

                               OBJECT(OBJECT(desktop)->first_view(OBJECT(desktop)))->process_tick

                               ));

};



void  stat4_func_callback ( p_object s ) /* it's call each second */

{                               

     TEXTLINE(s)->set_text(TEXTLINE(s),

                               set_format_text(NULL, "[Focused: %s]",

                               OBJECT(OBJECT(desktop)->first_view(OBJECT(desktop)))->tag & TAG_WINDOW ? _strdup(WINDOW(OBJECT(desktop)->first_view(OBJECT(desktop)))->caption) : _strdup("<none>")

                               ));

                               

};











static t_point   new_win_size_minimum ( p_view o )

{



  return point_assign(200, 50);



};









app_begin ( void ) {



  if ( ap_process == AP_INIT ) {





      p_button   b1 = NULL;





      t_rect r = rect_assign(0, 0, 250, 135);





      AP_SETNUMOFCALLS(1);





      o = OBJECT(appwin_init(malloc(sizeof(t_appwin)), /* make window */

                            r,

                            INI_TEXT("Seal Watchdog 0.1"),

                            0x02,

                            ap_id, /* application id */

                            &imager_translate_event));



      VIEW(o)->size_minimum = &new_win_size_minimum;







      VIEW(o)->align = TX_ALIGN_CENTER;



      OBJECT(desktop)->insert(OBJECT(desktop), OBJECT(o));





      r = rect_assign(5, 20, 235, 40);



     stat1 = textline_init( _malloc(sizeof(t_textline)),

                            r,

                            255,

                            TF_REWRITEUNABLE);



     OBJECT(stat1)->func_callback = &stat1_func_callback;

     



     OBJECT(o)->insert(OBJECT(o), OBJECT(stat1));



     TEXTLINE(stat1)->set_text(TEXTLINE(stat1), set_format_text(NULL, "DPMI: physical: %dByte, virtual: %dByte \n",_go32_dpmi_remaining_physical_memory(),_go32_dpmi_remaining_virtual_memory()));



     init_stillprocess ( OBJECT(stat1), 1000 );



      r = rect_assign(5, 40, 235, 60);



     stat2 = textline_init( _malloc(sizeof(t_textline)),

                            r,

                            255,

                            TF_REWRITEUNABLE);





     OBJECT(stat2)->func_callback = &stat2_func_callback;



     OBJECT(o)->insert(OBJECT(o), OBJECT(stat2));



     TEXTLINE(stat2)->set_text(TEXTLINE(stat2), set_format_text(NULL, "DPMI: physical: %dByte, virtual: %dByte \n",_go32_dpmi_remaining_physical_memory(),_go32_dpmi_remaining_virtual_memory()));



     init_stillprocess ( OBJECT(stat2), 1000 );



      r = rect_assign(5, 60, 235, 80);



     stat3 = textline_init( _malloc(sizeof(t_textline)),

                            r,

                            255,

                            TF_REWRITEUNABLE);



     OBJECT(stat3)->func_callback = &stat3_func_callback;

     



     OBJECT(o)->insert(OBJECT(o), OBJECT(stat3));



     TEXTLINE(stat3)->set_text(TEXTLINE(stat3), set_format_text(NULL, "DPMI: physical: %dByte, virtual: %dByte \n",_go32_dpmi_remaining_physical_memory(),_go32_dpmi_remaining_virtual_memory()));



     init_stillprocess ( OBJECT(stat3), 1000 );



      r = rect_assign(5, 80, 235, 100);



     stat4 = textline_init( _malloc(sizeof(t_textline)),

                            r,

                            255,

                            TF_REWRITEUNABLE);





     OBJECT(stat4)->func_callback = &stat4_func_callback;



     OBJECT(o)->insert(OBJECT(o), OBJECT(stat4));



     TEXTLINE(stat4)->set_text(TEXTLINE(stat4), set_format_text(NULL, "DPMI: physical: %dByte, virtual: %dByte \n",_go32_dpmi_remaining_physical_memory(),_go32_dpmi_remaining_virtual_memory()));



     init_stillprocess ( OBJECT(stat4), 1000 );



      r = rect_assign(5, 110, 95, 130); /* assign rect of button */



    /* init new button */

      b1 = button_init(

                            malloc(sizeof(t_button)), /* memory for class t_button */

                            r, /* button area */

                            "Quit", /* title of the button */

                            MSG_QUIT,         /* message of the button */

                            BF_DEFAULT);                /* flags of the button */





//      VIEW(b1)->info_text = strdup(TXT_JUSTWHATITSAYS);



//      OBJECT(o)->insert(OBJECT(o), OBJECT(b1)); /* insert button into the window "Hello" */

      











  }







  if ( ap_process == AP_DONE ) {







  }





  if ( ap_process == AP_FREE ) {





  };



} app_end;

