SAVEDS ULONG ASM ApplyChangesFunc(REG(a0) struct Hook *h,
                                  REG(a2) Object *win,
                                  REG(a1) ULONG *num)
{ Object *app, *actobj;
        
  get(win,MUIA_ApplicationObject,&app);
  get(app,MUIA_UserData,&actobj);
  
  if(actobj != NULL)
    ApplyChanges(actobj);
  else
    MUI_Request(app,win,0,"warning","*_Too bad","no active object.");

  return(0);
}

SAVEDS ULONG ASM DisplayFunc(REG(a2) char **array,
                             REG(a1) struct VBList *str)
{
  *array++ = str->Key;
  *array = str->Value;
  
  return(0);
}

SAVEDS ULONG ASM ConstructFunc(REG(a2) APTR pool,
                               REG(a1) struct VBList *str)
{
  char *key, *value;
  struct VBList *entry;
  
  if(key=AllocPooled(pool,strlen(str->Key)+1))
    strcpy(key,str->Key);
    
  if(value=AllocPooled(pool,strlen(str->Value)+1))
    strcpy(value,str->Value);
    
  if(entry=AllocPooled(pool,sizeof(struct VBList)))
  { entry->Key = key;
    entry->Value = value;
  }

  return((ULONG)entry);
}

SAVEDS ULONG ASM DestructFunc(REG(a2) APTR pool,
                              REG(a1) struct VBList *entry)
{ 
  FreePooled(pool,entry->Key,strlen(entry->Key)+1);
  FreePooled(pool,entry->Value,strlen(entry->Value)+1);
  FreePooled(pool,entry,sizeof(entry));
  
  return(0);
}

SAVEDS ULONG ASM DeleteObjectFunc(REG(a0) struct Hook *h,
                                  REG(a2) Object *win,
                                  REG(a1) ULONG *num)
{ Object *app, *actobj;
        
  get(win,MUIA_ApplicationObject,&app);
  get(app,MUIA_UserData,&actobj);
  
  if(actobj != NULL)
    Group_Remove(actobj);
  else
    MUI_Request(app,win,0,"Could not delete object","*_Say what!","No active object.");

  return(0);
}

SAVEDS ULONG ASM InsertWindowFunc(REG(a0) struct Hook *h,
                                  REG(a2) Object *win,
                                  REG(a1) ULONG *num)
{ 
  Object *app;
  int i;
  
  get(win,MUIA_ApplicationObject,&app);

  for(i=0;a->UserWin[i]!=NULL;i++);
  
  if(i<15)
  { 
    a->UserWin[i] = WindowObject,
      MUIA_Window_Title, "NewWindow",
      MUIA_Window_ID, MAKE_ID('W','I','N',i),
      WindowContents, HGroup,
        Child, DropGroupObject("Group1"),
          Child, HSpace(0),
        End,
      End,
    End;

    DoMethod(app,OM_ADDMEMBER,a->UserWin[i]);
    set(a->UserWin[i],MUIA_Window_Open,TRUE);

    DoMethod(a->UserWin[i], MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
             a->UserWin[i], 3, MUIM_Set, MUIA_Window_Open, FALSE);
  }
  else
  { MUI_Request(app,win,0,"Warning","*_This sucks!",
                "Insert window:\nThe maximum amount of windows is 15!");
  }

  return(0);
}

SAVEDS ULONG ASM AboutVBFunc(REG(a0) struct Hook *h,
                             REG(a2) Object *win,
                             REG(a1) ULONG *num)
{ 
  Object *app;
  
  get(win,MUIA_ApplicationObject,&app);

  MUI_Request(app,win,0,"About Visual Builder","*_Okido",
                "Visual builder v1.0 alpha\nWritten by Jan Klok.");

  return(0);
}

SAVEDS ULONG ASM ObjStrFunc(REG(a0) struct Hook *h,
                            REG(a2) Object *list,
                            REG(a1) Object *str)
{
  struct VBList *x;

  DoMethod(list,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&x);
  set(str,MUIA_String_Contents,x->Value);

  return(TRUE);
}

SAVEDS ULONG ASM StrObjFunc(REG(a0) struct Hook *h,
                            REG(a2) Object *list,
                            REG(a1) Object *str)
{
  struct VBList *x;
  char *s;
  int i;

  get(str,MUIA_String_Contents,&s);

  for (i=0;;i++)
  {
    DoMethod(list,MUIM_List_GetEntry,i,&x);
    if (!x)
    {
      set(list,MUIA_List_Active,MUIV_List_Active_Off);
      break;
    }
    else if (!stricmp(x->Value,s))
    {
      set(list,MUIA_List_Active,i);
      break;
    }
  }
  return(TRUE);
}

SAVEDS ULONG ASM ShowHideToolBarFunc(REG(a0) struct Hook *h,
                                     REG(a2) Object *toolbar,
                                     REG(a1) ULONG *visible)
{ 
  if (DoMethod(a->MainWinGroup,MUIM_Group_InitChange))
  { 
    if(XGet(a->ViewToolbar,MUIA_Menuitem_Checked)) 
      DoMethod(a->MainWinGroup,OM_ADDMEMBER,toolbar);
    else
      DoMethod(a->MainWinGroup,OM_REMMEMBER,toolbar);
      
    DoMethod(a->MainWinGroup,MUIM_Group_ExitChange);
  }
  return(0);
}

