void afbox_scrolltoitem(ACONTROLP ctl){
  AFBOXDP d = (AFBOXDP) ctl->d;
  if (d->focusedItem>-1){
    afbox_redraw(ctl);
    d->scrollY = d->items[d->focusedItem]->y - round((ctl->h/2) - (d->items[d->focusedItem]->h/2));
    if (d->scrollY<0) d->scrollY=0;
    if (d->scrollY>d->maxScrollY) d->scrollY=d->maxScrollY;
  }
  ctl->ondraw(ctl);
  aw_redraw(ctl->win);
}
void afbox_changeboxtype(ACONTROLP ctl, byte t){
  ag_setbusy();
  AFBOXDP d = (AFBOXDP) ctl->d;
  if (d->acheck_signature != 177) return; //-- Not Valid Signature
  d->boxtype      = t;
  int i;
  for (i=0;i<d->itemn;i++){
    afbox_redrawitem(ctl,i);
  }
  ctl->ondraw(ctl);
  aw_redraw(ctl->win);
  ag_sync();
}
void afbox_setcheckall(ACONTROLP ctl, byte checked){
  AFBOXDP d = (AFBOXDP) ctl->d;
  if (d->acheck_signature != 177) return;
  int i;
  for (i=0;i<d->itemn;i++){
    AFBOXIP p = d->items[i];
    if (p->checked!=checked){
      p->checked=checked;
      afbox_redrawitem(ctl,i);
      d->check_n+=(checked)?1:-1;
    }
  }
  ctl->ondraw(ctl);
  aw_redraw(ctl->win);
  ag_sync();
  
  dword msg=aw_msg(d->changemsg,1,0,0);
  atouch_send_message(msg);
}
//-- Show Window
void aw_show(AWINDOWP win){
  win->threadnum    = 0;
  win->isActived    = 1;
  
  //-- Find First Focus
  if (win->controln>0){
    int i;
    for (i=0;i<win->controln;i++){
      ACONTROLP ctl = (ACONTROLP) win->controls[i];
      if (ctl->onfocus!=NULL){
        if (ctl->onfocus(ctl)){
          win->focusIndex = i;
          break;
        }
      }
    }
  }  
  aw_redraw(win);
  ag_sync_fade(acfg_var.fadeframes);
}
//*
//* CHANGE TOOLBAR STATE
//*
byte aui_tbstate(AUI_VARSP v, byte state, byte cstate) {
  if (cstate == state) {
    return state;
  }
  
  int ics[4] = { 11, 6, 16, 10 };
  int tid[4] = { 0, 1, 2, 7 };
  byte msg[4] = { 20, 21, 22, 3 };
  
  //-- On Check not all
  if (state == 1) {
    ics[0] = 2;
    msg[0] = 30;
    tid[0] = 4;	//-- Copy
    ics[1] = 3;
    msg[1] = 31;
    tid[1] = 5;	//-- Cut
    ics[2] = 16;
    msg[2] = 22;
    tid[2] = 2;	//-- Select All
    ics[3] = 10;
    msg[3] = 3;
    tid[3] = 7;	//-- MENU
  }
  //-- On Check all
  else if (state == 2) {
    ics[0] = 2;
    msg[0] = 30;
    tid[0] = 4;	//-- Copy
    ics[1] = 3;
    msg[1] = 31;
    tid[1] = 5;	//-- Cut
    ics[2] = 19;
    msg[2] = 23;
    tid[2] = 3;	//-- unselectall
    ics[3] = 10;
    msg[3] = 3;
    tid[3] = 7;	//-- MENU
  }
  //-- On Copy / Cut
  else if (state == 3) {
    ics[0] = 13;
    msg[0] = 40;
    tid[0] = 6;	//-- Paste
    ics[1] = 0;
    msg[1] = 41;
    tid[1] = 8;	//-- Cancel
    //ics[2]=11;  msg[2]  = 20;   tid[2]  = 0;      //-- New Folder
    ics[2] = 6;
    msg[2] = 21;
    tid[2] = 1;	//-- Favorite
    ics[3] = 10;
    msg[3] = 3;
    tid[3] = 7;	//-- MENU
  }
  
  //-- Change Buttons State
  imgbtn_reinit(NULL, v->b1, 0, 0, 0, 0, &UI_ICONS[ics[0]],
                aui_tbtitle(tid[0]), 1, msg[0]);
  imgbtn_reinit(NULL, v->b2, 0, 0, 0, 0, &UI_ICONS[ics[1]],
                aui_tbtitle(tid[1]), 1, msg[1]);
  imgbtn_reinit(NULL, v->b3, 0, 0, 0, 0, &UI_ICONS[ics[2]],
                aui_tbtitle(tid[2]), 1, msg[2]);
  imgbtn_reinit(NULL, v->b4, 0, 0, 0, 0, &UI_ICONS[ics[3]],
                aui_tbtitle(tid[3]), 1, msg[3]);
  //-- Redraw Window
  aw_redraw(v->b1->win);
  ag_sync();
  //-- Reture new state
  return state;
}