📄 dialogs.c
字号:
}; break;
case KB_HOME : { /* key HOME was pressed */
LISTBOX(o)->rewrite_item(LISTBOX(o), 0);
clear_event(event);
}; break;
case KB_END : { /* key END was pressed */
LISTBOX(o)->rewrite_item(LISTBOX(o), LISTBOX(o)->get_max(LISTBOX(o)));
clear_event(event);
}; break;
default :
if ( (l_byte)TO_CHAR(keyb->code) >= 32 &&
(l_byte)TO_CHAR(keyb->code) <= 255 ) {
listbox_go_char(LISTBOX(o),TO_CHAR(keyb->code));
clear_event(event);
}; break;
};
};
};
l_bool listbox_done ( p_object o )
{
return scroller_done ( o );
};
void listbox_set_state ( p_object o, l_dword st, l_bool set )
{
view_set_state(o, st, set);
if ( st & OB_SF_FOCUSED ) {
LISTBOX(o)->draw_item(LISTBOX(o), LISTBOX(o)->current, true);
};
};
void listbox_set_options ( p_object o, l_dword op, l_bool set )
{
obj_set_options(o, op, set);
if ( op & OB_OF_ENABLE ) {
VIEW(o)->draw_view(VIEW(o));
};
};
l_bool listbox_get_data ( p_object o, t_data *rec )
{
return obj_get_data(o, rec);
};
l_bool listbox_set_data ( p_object o, t_data *rec )
{
return obj_set_data(o, rec);
};
void listbox_draw ( p_view o )
{
t_rect r = o->get_local_extent(o);
t_point p;
BITMAP *out = o->begin_paint(o, &p, r);
if ( out ) {
button3d(o,out, p.x+r.a.x, p.y+r.a.y, p.x+r.b.x, p.y+r.b.y, 1);
LISTBOX(o)->draw_box(LISTBOX(o));
};
o->end_of_paint(o, r);
};
t_rect listbox_size_limits ( p_view o )
{
return rect_assign(2, 2, rect_sizex(o->bounds)-2, rect_sizey(o->bounds)-2);
};
t_rect listbox_scroll_limits ( p_scroller o )
{
t_rect r = VIEW(o)->size_limits(VIEW(o));
r.b.y = r.a.y+LISTBOX(o)->get_rows(LISTBOX(o))*LISTBOX(o)->get_item_size(LISTBOX(o)).y;
r.b.x = r.a.x+LISTBOX(o)->cells*LISTBOX(o)->get_item_size(LISTBOX(o)).x;
return r;
};
void listbox_scroll_size ( p_scroller o, l_long *x, l_long *y )
{
p_listbox lo = LISTBOX(o);
SCROLLER(o)->deltax = lo->get_item_size(lo).x;
SCROLLER(o)->deltay = lo->get_item_size(lo).y;
scroller_scroll_size(o, x, y);
if ( lo->cells > 1 ) {
l_long oldx = *x;
*x = (l_int)ceil((double)(lo->get_max(lo)+1)/(double)lo->get_rows(lo))*lo->get_item_size(lo).x;
*x = lmax(*x, oldx);
} else {
l_long oldy = *y;
*y = (lo->get_max(lo)+1)*lo->get_item_size(lo).y;
*y = lmax(*y, oldy);
};
};
void listbox_recalc_positions ( p_scroller o, l_long x, l_long y )
{
p_listbox lb = LISTBOX(o);
if ( x )
lb->from += (x/lb->get_item_size(lb).x)*lb->get_rows(lb); /* set o->from */
else
if ( y )
lb->from += y/lb->get_item_size(lb).y; /* set o->from */
};
p_list listbox_get_selected_items ( p_listbox o, l_bool sel )
{
p_list list = NULL;
if ( o->list && o->get_max(o) >= 0 ) {
list = list_init(malloc(sizeof(t_list)), NULL, DAT_TEXT);
if ( list ) {
p_item i = o->list->last;
p_item l = i;
if ( i )
do {
if ( ((p_listbox_item)i->rec)->sel == sel )
list->insert(list, _strdup(((p_listbox_item)i->rec)->name));
i = i->next;
} while ( i != l );
};
};
return list;
};
l_long listbox_get_pos_from_xy ( p_listbox o, t_point p )
{
l_long pos = 0;
l_long delta = 0;
l_int rows = o->get_rows(o);
t_point s = o->get_item_size(o);
if ( o->cells < 2 ) p.x = 0;
delta = lmin(o->get_max_in_box(o)-1, lmax(0, (min(o->cells, p.x/s.x)*rows+min(rows-1,(p.y/s.y)))));
pos = o->from+delta;
return pos;
};
void listbox_draw_item_ptr ( p_listbox o, l_long item, void *recitem, l_bool set )
{
p_view vo = VIEW(o);
t_point p;
l_text item_text = recitem?((p_listbox_item)recitem)->name:NULL;
BITMAP *item_icon = recitem?((p_listbox_item)recitem)->icon:NULL;
l_bool item_sel = recitem?((p_listbox_item)recitem)->sel:false;
t_rect r = o->get_item_rect(o, item);
t_rect t = r;
t_rect safe = r;
BITMAP *out;
if ( !recitem || rect_check_empty(r) ) return;
out = vo->begin_paint(vo, &p, safe);
if ( out ) {
l_color fcolor = color_flat_text;
l_color bcolor = color_flat_face;
vo->background(vo, out, rect_move(r, p.x, p.y));
if ( OBJECT(o)->is_options(OBJECT(o), OB_OF_ENABLE) && /*) {
if (*/ (set || item_sel ) ) {
fcolor = color_selected_text;
bcolor = color_selected_face;
//rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_selected_face);
/*} else
if ( item_sel ) {
fcolor = color_selected_text;
rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_selected_face);
if ( set ) {
rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_selected_face);
};
} else {
// vo->background(vo, out, rect_move(r, p.x, p.y));
rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_flat_face);
}
*/
} else
rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_flat_face );
if ( item_icon ) {
l_int dy = (rect_sizey(r)-icon_size(o))/2;
if ( ( set || item_sel ) && get_depth(out) >= 16 ) {
set_trans_blender(getr(color_selected_face), getg(color_selected_face), getb(color_selected_face), 0);
draw_lit_sprite(out, item_icon, r.a.x+p.x+5, r.a.y+p.y+dy,128);
solid_mode();
} else
stretch_sprite(out, item_icon, r.a.x+p.x+5, r.a.y+p.y+dy, icon_size(o), icon_size(o));
t.a.x = r.a.x+rect_sizey(r)+5;
};
if ( item_text )
textout_draw_rect_ex(out, vo->font, item_text, -1, t.a.x+p.x+5, r.a.y+p.y,
r.b.x+p.x, r.b.y+p.y, TX_ALIGN_LEFT|TX_ALIGN_CENTERY,
fcolor, bcolor, 1, 2);
};
vo->end_of_paint(vo, safe);
};
void listbox_draw_item ( p_listbox o, l_long item, l_bool set )
{
void *recitem = LISTBOX_ITEM_AT(o->list, item);
o->draw_item_ptr(o, item, recitem, set);
};
void listbox_draw_box ( p_listbox o )
{
p_view vo = VIEW(o);
t_rect r = vo->size_limits(vo);
t_point p;
BITMAP *out;
out = vo->begin_paint(vo, &p, r);
if ( out ) {
l_long max = o->from+o->get_max_in_box(o);
l_long abs_max = o->get_max(o);
l_long i = o->from;
p_item it = o->list?o->list->at_item(o->list, i):NULL;
if ( OBJECT(o)->is_options(OBJECT(o), OB_OF_ENABLE) )
vo->background(vo, out, rect_move(r, p.x, p.y));
// rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, vo->get_color(vo, 0));
else
rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_flat_face);
if ( it )
while ( i < max && i <= abs_max ) {
o->draw_item_ptr(o, i, it?(l_text)it->rec:NULL, (i == o->current));
it = it->next;
i++;
};
};
vo->end_of_paint(vo, r);
};
/*
return rect area of item ( item )
*/
t_rect listbox_get_item_rect ( p_listbox o, l_long item )
{
p_view vo = VIEW(o);
t_rect s = vo->size_limits(vo);
l_int rows = o->get_rows ( o );
l_int xpos = (o->cells>1)?(item-o->from)/rows:0;
l_int ypos = (o->cells>1)?(item-o->from)%rows:item-o->from;
t_point item_size = o->get_item_size ( o );
l_rect dx = xpos*item_size.x;
l_rect dy = ypos*item_size.y;
t_rect r = (o->cells>1)?rect_assign(s.a.x+dx, s.a.y+dy, s.a.x+dx+item_size.x-o->between.x, s.a.y+dy+item_size.y-1):
rect_assign(s.a.x+dx, s.a.y+dy, s.b.x, s.a.y+dy+item_size.y-1);
return rect_cliped(s, r);
};
/*
listbox rewrite item :
it rewrite item and control all item moves.
- item is new position of listbox item.
It clip item, so it make max(item, 0) and min(item, get_max_item(o))
If item is greater than [o->from - the first item that we see in current pos,
so it's left upper item] + [get_max_in_box(o) max number of items
in one listbox, that we can see. ], it scroll listbox to the right, if item
is lower than o->from, it scroll listbox to the left.
*/
void listbox_rewrite_item ( p_listbox o, l_long item )
{
l_long dx = 0;
l_long dy = 0;
l_long abs_cur = 0;
l_long old_current = o->current;
l_long max = o->get_max(o);
l_int max_box = o->get_max_in_box(o);
l_bool can_scroll = false;
o->current = lmax(0, lmin(item, max));
if ( o->current >= max_box+o->from ) { /* is greater than box */
l_int rows = o->get_rows(o);
l_long old_from = o->from;
/* current+1, because it starts from 0 and rows may be 1,2,3... not 0,1,2,3 */
abs_cur = (l_int)ceil((double)(o->current+1)/(double)rows)*rows;
if ( o->cells == 1 ) /* other type of scrolling in 1 cell */
abs_cur = o->current+1;
abs_cur -= max_box; /* set o->from */
if ( o->cells == 1 ) /* other type of scrolling in 1 cell */
dy = (abs_cur-old_from)*o->get_item_size(o).y;
else
dx = ((abs_cur-old_from)/rows)*o->get_item_size(o).x;
can_scroll = true;
} else
if ( o->current < o->from ) { /* is lower than box */
l_int rows = o->get_rows(o);
l_long old_from = o->from;
abs_cur = (l_int)floor((double)(o->current)/(double)rows)*rows;
if ( o->cells == 1 ) /* other type of scrolling in 1 cell */
abs_cur = o->current;
if ( o->cells == 1 ) /* other type of scrolling in 1 cell */
dy = (abs_cur-old_from)*o->get_item_size(o).y;
else
dx = ((abs_cur-old_from)/rows)*o->get_item_size(o).x;
can_scroll = true;
};
if ( o->current != old_current || can_scroll ) {
o->draw_item(o, old_current, false);
if ( !can_scroll )
o->draw_item(o, o->current, true);
};
if ( can_scroll ) {
SCROLLER(o)->scroll_place(SCROLLER(o), dx, dy, SCROLL_NOW); /* scroll place */
o->draw_item(o, o->current, true);
};
};
l_long listbox_get_max ( p_listbox o )
{
if ( o->list ) return o->list->get_max_item(o->list);
return -1;
};
t_point listbox_get_item_size ( p_listbox o )
{
l_rect sx = rect_sizex(VIEW(o)->size_limits(VIEW(o)));
t_point p = point_assign(max(1, sx/o->cells), max(1, max(FONT_GETHEIGHT(VIEW(o)->font), icon_size(o))+o->between.y));
return p;
};
l_int listbox_get_rows ( p_listbox o )
{
l_int sizey_item = o->get_item_size(o).y;
t_rect s = VIEW(o)->size_limits(VIEW(o));
return (rect_sizey(s)/max(1, sizey_item));
};
l_bool listbox_set_list ( p_listbox o, p_list p )
{
o->list = p;
o->current = o->from = 0;
/* redraw box */
o->draw_box(o);
/* redraw scroll bars */
draw_scroller_bars(o);
return true;
};
l_int listbox_get_max_in_box ( p_listbox o )
{
return (o->get_rows(o)*o->cells);
};
/* t_worklistbox */
t_rect worklistbox_size_limits ( p_view o )
{
return rect_assign(1, 1, rect_sizex(o->bounds)-1, rect_sizey(o->bounds)-1);
};
void worklistbox_draw ( p_view o )
{
t_rect r = o->get_local_extent(o);
t_point p;
BITMAP *out = o->begin_paint(o, &p, r);
if ( out ) {
button(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_3d_shadow, color_3d_light);
LISTBOX(o)->draw_box(LISTBOX(o));
};
o->end_of_paint(o, r);
};
/* textline functions */
void textline_ins_text ( p_textline o, l_int pos, l_text text )
{
if ( pos < o->limit && pos >= 0 )
o->text = insstr(o->text, text, pos, min(o->limit-pos, strlen(text)));
};
void textline_ins_char ( p_textline o, l_int pos, l_char chr )
{
l_char txt[2] = {0, '\0'};
txt[0] = chr;
o->ins_text(o, pos, txt);
};
void textline_del_text ( p_textline o, l_int pos, l_int size )
{
if ( pos < o->limit && pos >= 0 )
o->text = delstr(o->text, pos, min(o->limit-pos, size));
};
void textline_del_char ( p_textline o, l_int pos )
{
o->del_text(o, pos, 1);
};
l_bool textline_done ( p_object o )
{
if ( !view_done(o) ) return false;
afree((void**)(&(TEXTLINE(o)->text)));
return true;
};
void textline_set_state ( p_object o, l_dword st, l_bool set )
{
view_set_state(o, st, set);
if ( st & OB_SF_SELECTED ) {
if ( set || o->owner && o->owner->is_state(o->owner, OB_SF_SELECTED) ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -