#include "allegro.h" 
#include "seal.h" 
#include "app.h" 
#include "dialogs.h" 
#include "button.h" 

#define MSG_B1 10001

p_appwin win;
p_button b1;
p_textline tl1;

static void translate_event(p_object o, p_event event)
{
  if (event->type == EV_MESSAGE)
  {
    switch (event->message)
    {
      case MSG_B1: {
        msgbox(MW_INFO, MB_OK, "Textline's text is %s", tl1->text);
      } break;
    };
  }
}

void testapp_init() 
{ 
  t_rect r = rect_assign(100, 100, 300, 200);
  p_stattext st1;

  win = appwin_init(malloc(sizeof(t_appwin)), r, "Window's title", WF_MINIMIZE, ap_id, &translate_event);
  OBJECT(desktop)->insert(OBJECT(desktop), OBJECT(win)); 

  r = rect_assign(5, 25, 85, 45);
  b1 = button_init(malloc(sizeof(t_button)), r, "Button 1", MSG_B1, BF_NORMAL);
  OBJECT(win)->insert(OBJECT(win), OBJECT(b1));

  r = rect_assign(5, 50, 69, 65);
  st1 = stattext_init(malloc(sizeof(t_stattext)), r, TX_ALIGN_LEFT, "Static text");
  OBJECT(win)->insert(OBJECT(win), OBJECT(st1));

  r = rect_assign(70, 48, 210, 67);
  tl1 = textline_init(malloc(sizeof(t_textline)), r, 255, TF_NONE);
  OBJECT(win)->insert(OBJECT(win), OBJECT(tl1));
} 

app_begin(void) 
{ 
  if (ap_process == AP_INIT) { 
    testapp_init(); 
  }; 
} app_end;
