
#include "CITApp.h"
#include "CITScreen.h"
#include "CITWindow.h"
#include "CITGroup.h"
#include "CITButton.h"
#include "CITCheckBox.h"

#include <libraries/gadtools.h>
#include <stdlib.h>
#include <iostream.h>


CITApp Application;

CITScreen DemoScreen;
CITWindow DemoWindow;
CITHGroup hGroup;
CITButton quitButton;
CITButton okButton;
CITButton checkBox;
//CITCheckBox checkBox;

void CloseEvent();
void QuitEvent(ULONG ID);

void ErrorReturn(char *ErrText)
{
  cerr << ErrText << '\n';
  exit(999);
}

int main(void)
{
  BOOL Error=FALSE;

  DemoScreen.Use("Workbench");
  Application.InsObject(DemoScreen,Error);

  // Ok?
  if( Error )
    ErrorReturn("Could'nt open the screen");

  DemoScreen.InsObject(DemoWindow,Error);
    DemoWindow.Position(1); //WPOS_CENTERSCREEN);
    DemoWindow.CloseGadget();
    DemoWindow.DragBar();
    DemoWindow.SizeGadget();
    DemoWindow.DepthGadget();
    DemoWindow.IconifyGadget();
    DemoWindow.Caption("CITGadgets");
    DemoWindow.CloseEventHandler(CloseEvent);
    DemoWindow.InsObject(hGroup,Error);
      hGroup.BevelStyle();
      hGroup.BevelLabel("En tekst");
      hGroup.InsObject(quitButton,Error);
        quitButton.Text("Quit");
        //quitButton.WeightedWidth(50);
        quitButton.EventHandler(QuitEvent);
      hGroup.InsObject(okButton,Error);
        okButton.Text("Ok");
        //okButton.WeightedWidth(25);
      hGroup.InsObject(checkBox,Error);
        checkBox.PushButton();
        checkBox.AutoButton(4); //BAG_CHECKBOX);
        //checkBox.Text("Check Me");
        //checkBox.TextPlace(PLACETEXT_RIGHT);

  DemoWindow.Open(Error);

  // Ok?
  if( Error )
    ErrorReturn("Could'nt create the gadgets");

  Application.Run();

  Application.RemObject(DemoScreen);
  return(0);
}

int repeatCount = 2;

void CloseEvent()
{
  BOOL Error = FALSE;

  switch( repeatCount )
  {
  	case 2:
    //DemoWindow.Busy(TRUE);
    hGroup.RemObject(okButton);
    //DemoWindow.Position(50,50);
    //hGroup.Disabled(TRUE);
    repeatCount--;
    break;
  	case 1:
    //DemoWindow.Busy(FALSE);
    hGroup.InsObject(okButton,Error);
    //DemoWindow.Size(300,180);
    //DemoWindow.Caption("Ny Titel");
    //hGroup.Disabled(FALSE);
    repeatCount--;
    break;
  	case 0:
    Application.Stop();
    break;
  }

}


void QuitEvent(ULONG ID)
{
  Application.Stop();
}
