/*
 * Function    : libaroma_ctl_list_item_position
 * Return Value: byte
 * Descriptions: get item position
 */
byte libaroma_ctl_list_item_position(
    LIBAROMA_CONTROLP ctl,LIBAROMA_CTL_LIST_ITEMP item,
    LIBAROMA_RECTP rect, byte absolute){
  if (!rect){
    return 0;
  }
  if (!item){
    return 0;
  }
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return 0;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return 0;
  }
  LIBAROMA_CTL_LISTP mi = (LIBAROMA_CTL_LISTP) client->internal;
  
  int x=0;
  int y=0;
  if (absolute){
    libaroma_window_calculate_pos_abs(NULL,ctl,&x,&y);
  }
  else{
    libaroma_window_calculate_pos(NULL,ctl,&x,&y);
  }
  int ctl_y = libaroma_ctl_scroll_get_scroll(ctl,NULL);
  rect->x=x;
  rect->y=item->y-(y+ctl_y+mi->vpad);
  rect->w=ctl->w-(mi->hpad*2);
  rect->h=item->h;
  return 1;
} /* End of libaroma_ctl_list_item_position */
Beispiel #2
0
/*
 * Function    : libaroma_ctl_list_del_itemp_internal
 * Return Value: byte
 * Descriptions: del item from list
 */
byte libaroma_ctl_list_del_itemp_internal(
  LIBAROMA_CONTROLP ctl, LIBAROMA_CTL_LIST_ITEMP f
){
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return 0;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return 0;
  }
  LIBAROMA_CTL_SCROLLP mi = (LIBAROMA_CTL_SCROLLP) client->internal;
  libaroma_mutex_lock(mi->imutex);
  libaroma_mutex_lock(mi->mutex);
  if (f){
    if ((f==mi->first)&&(f==mi->last)){
      mi->first=mi->last=NULL;
    }
    else if (f==mi->first){
      mi->first = f->next;
      mi->first->prev=NULL;
      __libaroma_ctl_list_repos_next_items(
        mi->first,
        f->y
      );
    }
    else if (f==mi->last){
      mi->last=f->prev;
      mi->last->next=NULL;
    }
    else{
      f->prev->next = f->next;
      f->next->prev = f->prev;
      __libaroma_ctl_list_repos_next_items(
        f->next,
        f->next->prev->y+f->next->prev->h
      );
    }
    
    mi->itemn--;
    mi->h-=f->h;
    if (f->handler->destroy!=NULL){
      f->handler->destroy(ctl,f);
    }
    _libaroma_ctl_list_free_state(f);
    __libaroma_ctl_list_item_unreg_thread(ctl, f);
    if (mi->touched==f){
      mi->touched=NULL;
    }
    free(f);
    libaroma_mutex_unlock(mi->mutex);
    libaroma_mutex_unlock(mi->imutex);
    libaroma_ctl_scroll_request_height(ctl, mi->h);
    return 1;
  }
  libaroma_mutex_unlock(mi->mutex);
  libaroma_mutex_unlock(mi->imutex);
  return 0;
} /* End of libaroma_ctl_list_del_itemp_internal */
Beispiel #3
0
/*
 * Function    : __libaroma_ctl_list_item_unreg_thread
 * Return Value: byte
 * Descriptions: unregister item thread
 */
byte __libaroma_ctl_list_item_unreg_thread(
    LIBAROMA_CONTROLP ctl, LIBAROMA_CTL_LIST_ITEMP item){
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return 0;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return 0;
  }
  LIBAROMA_CTL_SCROLLP mi = (LIBAROMA_CTL_SCROLLP) client->internal;
  if (mi->threadn<1){
    return 0;
  }
  
  if (mi->threadn==1){
    if (mi->threads[0]==item){
      free(mi->threads);
      mi->threads=NULL;
      mi->threadn=0;
      return 1;
    }
    return 0;
  }
  
  LIBAROMA_CTL_LIST_ITEMP * new_threads = (LIBAROMA_CTL_LIST_ITEMP *)
      malloc(sizeof(LIBAROMA_CTL_LIST_ITEMP)*(mi->threadn-1));
  if (!new_threads){
    ALOGW("item_unreg_thread cannot allocate new threads");
    if (mi->threads){
      free(mi->threads);
    }
    mi->threads=NULL;
    mi->threadn=0;
    return 0;
  }
  
  int i;
  int z=0;
  int n=-1;
  for (i=0;i<mi->threadn;i++){
    if (mi->threads[i]==item){
      n=i;
    }
    else{
      new_threads[z++]=mi->threads[i];
    }
  }
  if (n>-1){
    free(mi->threads);
    mi->threads=new_threads;
    mi->threadn--;
    return 1;
  }
  free(new_threads);
  ALOGV("item_unreg_thread item is unregistered");
  return 0;
} /* End of __libaroma_ctl_list_item_unreg_thread */
Beispiel #4
0
/*
 * Function    : libaroma_ctl_list_is_valid
 * Return Value: byte
 * Descriptions: check control, if it was valid list control
 */
byte libaroma_ctl_list_is_valid(LIBAROMA_CONTROLP ctl){
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return 0;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return 0;
  }
  return 1;
} /* End of libaroma_ctl_list_is_valid */
Beispiel #5
0
/*
 * Function    : libaroma_ctl_list_getpos
 * Return Value: LIBAROMA_CTL_LIST_TOUCHPOSP
 * Descriptions: get touch positions
 */
LIBAROMA_CTL_LIST_TOUCHPOSP libaroma_ctl_list_getpos(LIBAROMA_CONTROLP ctl){
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return NULL;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return NULL;
  }
  LIBAROMA_CTL_SCROLLP mi = (LIBAROMA_CTL_SCROLLP) client->internal;
  return &mi->pos;
} /* End of libaroma_ctl_list_getpos */
Beispiel #6
0
/*
 * Function    : __libaroma_ctl_list_item_reg_thread
 * Return Value: byte
 * Descriptions: register item thread
 */
byte __libaroma_ctl_list_item_reg_thread(
    LIBAROMA_CONTROLP ctl, LIBAROMA_CTL_LIST_ITEMP item){
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return 0;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return 0;
  }
  /*
  if (!item->handler->message){
    ALOGW("item_reg_thread item doesn't have message handler");
    return 0;
  }
  */
  
  LIBAROMA_CTL_SCROLLP mi = (LIBAROMA_CTL_SCROLLP) client->internal;
  if (mi->threadn==0){
    mi->threads = (LIBAROMA_CTL_LIST_ITEMP *)
      malloc(sizeof(LIBAROMA_CTL_LIST_ITEMP));
    mi->threads[0] = item;
    mi->threadn=1;
  }
  else{
    int i;
    for (i=0;i<mi->threadn;i++){
      if (mi->threads[i]==item){
        /* already registered */
        return 2;
      }
    }
    
    LIBAROMA_CTL_LIST_ITEMP * new_threads = (LIBAROMA_CTL_LIST_ITEMP *)
      realloc(mi->threads, sizeof(LIBAROMA_CTL_LIST_ITEMP)*(mi->threadn+1));
    if (!new_threads){
      if (mi->threads){
        free(mi->threads);
      }
      mi->threads=NULL;
      mi->threadn=0;
      ALOGW("item_reg_thread cannot realloc threads");
      return 0;
    }
    mi->threads=new_threads;
    mi->threads[mi->threadn]=item;
    mi->threadn++;
  }
  return 1;
} /* End of __libaroma_ctl_list_item_reg_thread */
Beispiel #7
0
/*
 * Function    : libaroma_ctl_list_item_setheight
 * Return Value: byte
 * Descriptions: update item height
 */
byte libaroma_ctl_list_item_setheight(
    LIBAROMA_CONTROLP ctl,LIBAROMA_CTL_LIST_ITEMP item, int h){
  if (!item){
    return 0;
  }
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return 0;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return 0;
  }
  LIBAROMA_CTL_SCROLLP mi = (LIBAROMA_CTL_SCROLLP) client->internal;
  if (item->h!=h){
    mi->h-=item->h;
    item->h=h;
    mi->h+=item->h;
    __libaroma_ctl_list_repos_next_items(item,item->y);
    libaroma_ctl_scroll_request_height(ctl, mi->h);
    return 1;
  }
  return 2;
} /* End of libaroma_ctl_list_item_setheight */
Beispiel #8
0
/*
 * Function    : _libaroma_ctl_list_init_state_cache
 * Return Value: byte
 * Descriptions: init cache canvases
 */
byte _libaroma_ctl_list_init_state_cache(
  LIBAROMA_CONTROLP ctl,
  LIBAROMA_CTL_LIST_ITEMP item
){
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return 0;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return 0;
  }
  LIBAROMA_CTL_SCROLLP mi = (LIBAROMA_CTL_SCROLLP) client->internal;
  
  if (item->state){
    if (!item->state->cache_rest){
      item->state->cache_rest=libaroma_canvas(ctl->w,item->h);
    }
    if (!item->state->cache_push){
      item->state->cache_push=libaroma_canvas(ctl->w,item->h);
    }
    word bgcolor = libaroma_ctl_scroll_get_bg_color(ctl);
    if (item->state->cache_rest){
      _libaroma_ctl_list_draw_item_fresh(
        ctl,item,item->state->cache_rest,bgcolor,mi->hpad,
        LIBAROMA_CTL_LIST_ITEM_DRAW_NORMAL|LIBAROMA_CTL_LIST_ITEM_DRAW_CACHE
      );
    }
    if (item->state->cache_push){
      _libaroma_ctl_list_draw_item_fresh(
        ctl,item,item->state->cache_push,bgcolor,mi->hpad,
        LIBAROMA_CTL_LIST_ITEM_DRAW_PUSHED|LIBAROMA_CTL_LIST_ITEM_DRAW_CACHE
      );
    }
    return 1;
  }
  return 0;
} /* End of _libaroma_ctl_list_init_state_cache */
Beispiel #9
0
/*
 * Function    : libaroma_ctl_list_get_item_internal
 * Return Value: LIBAROMA_CTL_LIST_ITEMP
 * Descriptions: get item at index or id
 */
LIBAROMA_CTL_LIST_ITEMP libaroma_ctl_list_get_item_internal(
  LIBAROMA_CONTROLP ctl, int index, byte find_id
){
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return NULL;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return NULL;
  }
  LIBAROMA_CTL_SCROLLP mi = (LIBAROMA_CTL_SCROLLP) client->internal;
  if (!find_id){
    if (index==-1){
      return mi->last;
    }
    else if (index==0){
      return mi->first;
    }
  }
  int curr_index = 0;
  libaroma_mutex_lock(mi->imutex);
  LIBAROMA_CTL_LIST_ITEMP f = mi->first;
  if (f){
    while(f){
      if (((!find_id)&&(curr_index==index))||((find_id)&&(f->id==index))) {
        libaroma_mutex_unlock(mi->imutex);
        return f;
      }
      f = f->next;
      curr_index++;
    }
  }
  libaroma_mutex_unlock(mi->imutex);
  /* not found */
  return NULL;
} /* End of libaroma_ctl_list_get_item_internal */
Beispiel #10
0
/*
 * Function    : _libaroma_ctl_list_draw_item
 * Return Value: void
 * Descriptions: draw item
 */
void _libaroma_ctl_list_draw_item(
    LIBAROMA_CONTROLP ctl,
    LIBAROMA_CTL_LIST_ITEMP item,
    LIBAROMA_CANVASP canvas,
    word bgcolor
){
  if ((!item)||(!canvas)){
    return;
  }
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return;
  }
  LIBAROMA_CTL_SCROLLP mi = (LIBAROMA_CTL_SCROLLP) client->internal;
  
  /* normal animation handler */
  if (item->state){
    if (item->state->normal_handler){
      libaroma_draw(canvas, item->state->cache_rest, 0, 0, 0);
      int ripple_i = 0;
      int ripple_p = 0;
      while(libaroma_ripple_loop(&item->state->ripple,&ripple_i,&ripple_p)){
        int x=0;
        int y=(item->y+libaroma_dp(1));
        int size=0;
        byte push_opacity=0;
        byte ripple_opacity=0;
        if (libaroma_ripple_calculation(
          &item->state->ripple, canvas->w, canvas->h,
          &push_opacity, &ripple_opacity,
          &x, &y, &size, ripple_p
        )){
          libaroma_draw_opacity(canvas, 
            item->state->cache_push, 0, 0, 2, 
            (byte) push_opacity
          );
          libaroma_draw_mask_circle(
              canvas, 
              item->state->cache_push, 
              x, y,
              x, y,
              size,
              ripple_opacity
            );
        }
      }
      if (item->state->normal_handler==2){
        _libaroma_ctl_list_draw_item_fresh(
          ctl, item,canvas,bgcolor,mi->hpad,
          LIBAROMA_CTL_LIST_ITEM_DRAW_ADDONS
        );
      }
      return;
    }
  }
  
  /* draw fresh */
  _libaroma_ctl_list_draw_item_fresh(
    ctl, item,canvas,bgcolor,mi->hpad, LIBAROMA_CTL_LIST_ITEM_DRAW_NORMAL
  );
} /* End of _libaroma_ctl_list_draw_item */
Beispiel #11
0
/*
 * Function    : libaroma_ctl_list_add_item_internal
 * Return Value: LIBAROMA_CTL_LIST_ITEMP
 * Descriptions: add item internally
 */
LIBAROMA_CTL_LIST_ITEMP libaroma_ctl_list_add_item_internal(
    LIBAROMA_CONTROLP ctl,
    int id,
    int height,
    byte flags,
    voidp internal,
    LIBAROMA_CTL_LIST_ITEM_HANDLERP handler,
    int at_index){
  if (!handler){
    return NULL;
  }
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return NULL;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return NULL;
  }
  LIBAROMA_CTL_SCROLLP mi = (LIBAROMA_CTL_SCROLLP) client->internal;
  
  LIBAROMA_CTL_LIST_ITEMP item = (LIBAROMA_CTL_LIST_ITEMP)
      calloc(sizeof(LIBAROMA_CTL_LIST_ITEM),1);
  if (item==NULL){
    ALOGW("list_add_item_internal cannot allocating memory for item");
    return NULL;
  }
  
  libaroma_mutex_lock(mi->imutex);
  libaroma_mutex_lock(mi->mutex);
  item->y=0;
  item->h=height;
  item->id=id;
  item->flags=flags;
  item->handler=handler;
  item->internal=internal;
  
  if (mi->last==NULL){
    mi->first=mi->last=item;
    item->y=mi->vpad;
    mi->h+=item->h;
  }
  else if (at_index<0){
    /* at last */
    item->prev=mi->last;
    mi->last->next = item;
    item->y = mi->last->y + mi->last->h;
    mi->last = item;
    mi->h+=item->h;
  }
  else if (at_index==0){
    /* at first */
    item->next = mi->first;
    item->y=mi->vpad;
    mi->first = item;
    mi->h+=item->h;
    __libaroma_ctl_list_repos_next_items(item,mi->vpad);
  }
  else{
    int curr_index = 0;
    LIBAROMA_CTL_LIST_ITEMP f = mi->first;
    if (f){
      while(f){
        if (curr_index==at_index){
          item->prev = f;
          item->next = f->next;
          __libaroma_ctl_list_repos_next_items(item,f->y+f->h);
          f->next = item;
          if (item->next==NULL){
            mi->last = item;
          }
          mi->h+=item->h;
          break;
        }
        f = f->next;
        if (!f){
          curr_index=-1;
          break;
        }
        curr_index++;
      }
    }
    else{
      curr_index=-1;
    }
    if (curr_index<0){
      /* add in last */
      item->prev=mi->last;
      mi->last->next = item;
      item->y = mi->last->y + mi->last->h;
      mi->last = item;
      mi->h+=item->h;
    }
  }
  mi->itemn++;
  
  if (flags&LIBAROMA_CTL_LIST_ITEM_REGISTER_THREAD){
    __libaroma_ctl_list_item_reg_thread(ctl,item);
  }
  
  libaroma_mutex_unlock(mi->mutex);
  libaroma_mutex_unlock(mi->imutex);
  
  /* set current height */
  libaroma_ctl_scroll_request_height(ctl, mi->h);
  return item;
} /* End of libaroma_ctl_list_add_item_internal */