📄 desktop5.c
字号:
VIEW(o)->draw = &it_draw;
VIEW(o)->transparent = true;
OBJECT(o)->set_options(OBJECT(o), OB_OF_SELECTABLE+OB_OF_ENABLE, false);
return o;
};
////////////////////////////////////////////////////////////////////////////////
void free_it ( void *o ) {
if ( o )
dispose(OBJECT(o));
};
////////////////////////////////////////////////////////////////////////////////
p_list load_it_from_dir_in_object(p_object object, t_rect r, l_text path ) {
p_list list = list_init(_malloc(sizeof(t_list)),&free_it,0);
t_rect rx = rect_assign(r.a.x, r.a.y, r.a.x + 90, r.a.y + 50);
struct t_ffblk f;
l_int done = 0;
l_text fi = io_realpath(path, "*.*");
its_zone = r;
done = io_findfirst(fi, &f, FA_ARCH+FA_DIREC);
while ( !done ) {
if ( io_isfilename (f.ff_filename) ) {
l_text realfile = io_realpath(path, f.ff_filename);
l_text nicename = lnk_nice_link(f.ff_filename);
l_bool ownmem = false;
l_text id = strupr(_strdup(realfile));
l_long *p = NULL, x = 0, y = 0;
p_it it = NULL;
BITMAP *bmp = get_icon_for_file_ex(realfile,f.info.ff_attrib,&ownmem,32);
t_rect fr = rx;
p = (long *)getini_fromfile("desktop.inf", id, "X");
if ( p ) x = *(p);
p = (long *)getini_fromfile("desktop.inf", id, "Y");
if ( p ) y = *(p);
if ( p ) {
fr = rect_assign(r.a.x+x,r.a.y+y,r.a.x+x+90,r.a.y+y+50);
if (fr.b.x > r.b.x ) fr = rx;
};
it = _it_init( _malloc(sizeof(t_it)), fr, realfile , nicename, bmp,ownmem );
object->insert(object,OBJECT(it));
list->insert(list,it);
rx.a.x += 90;
rx.b.x += 90;
if (rx.b.x > r.b.x ) {
rx.a.x = r.a.x;
rx.b.x = r.a.x + 90;
rx.a.y += 60;
rx.b.y += 60;
};
_free(nicename);
_free(realfile);
_free(id);
};
done = io_findnext(&f);
};
_free(fi);
return list;
};
////////////////////////////////////////////////////////////////////////////////
typedef struct t_userbox *p_userbox;
typedef struct t_userbox {
struct t_view obclass;
} t_userbox;
p_userbox userbox = NULL;
////////////////////////////////////////////////////////////////////////////////
void userbox_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) {
rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_deskbar_face);
button(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_deskbar_shadow, color_deskbar_light );
};
o->end_of_paint(o, r);
};
////////////////////////////////////////////////////////////////////////////////
p_userbox userbox_init(p_userbox o, t_rect r)
{
if (!o) return NULL;
clear_type(o, sizeof(t_userbox));
view_init(&o->obclass, r);
VIEW(o)->draw = &userbox_draw;
return o;
};
////////////////////////////////////////////////////////////////////////////////
void refresh_userbox() {
if ( !OBJECT(userbox) || !OBJECT(userbox)->last ) return;
if ( BarPosition == 1 || BarPosition == 3 ) {
p_object p = OBJECT(userbox)->first_view(OBJECT(userbox));
p_object f = p;
t_rect b = rect_assign(VIEW(userbox)->bounds.a.x,VIEW(userbox)->bounds.a.y,VIEW(userbox)->bounds.b.x,VIEW(userbox)->bounds.a.y+2);
l_int ht = 2;
l_int wt = abs (b.a.x - b.b.x);
do {
t_rect r = VIEW(p)->bounds;
l_int h = abs(r.a.y - r.b.y);
l_int w = abs(r.a.x - r.b.x);
r.a.y = ht;
r.b.y = ht + 16;
r.a.x = (wt-w)/2;
r.b.x = (wt-w)/2+w;
VIEW(p)->change_bounds(VIEW(p), r);
ht += 18;
p = OBJECT(OBJECT(p)->next_view(OBJECT(p)));
} while(f != p);
b.b.y = ht+2;
VIEW(userbox)->change_bounds(VIEW(userbox), b);
} else {
p_object p = OBJECT(userbox)->first_view(OBJECT(userbox));
p_object f = p;
t_rect b = rect_assign(VIEW(userbox)->bounds.b.x-2,VIEW(userbox)->bounds.a.y,VIEW(userbox)->bounds.b.x,VIEW(userbox)->bounds.b.y);
l_int wt = 2;
do {
t_rect r = VIEW(p)->bounds;
l_int w = abs(r.a.x - r.b.x);
b.a.x -= w + 2;
wt += w + 2;
p = p->next_view(p);
} while(f != p);
p = OBJECT(userbox)->first_view(OBJECT(userbox));
do {
t_rect r = VIEW(p)->bounds;
l_int w = abs(r.a.x - r.b.x);
r.a.x = wt - w - 2;
r.b.x = wt - 2;
r.a.y = 2;
r.b.y = 18;
VIEW(p)->change_bounds(VIEW(p), r);
wt -= w + 2;
p = p->next_view(p);
} while(f != p);
VIEW(userbox)->change_bounds(VIEW(userbox), b);
if ( Taskbar ) {
Taskbar->bounds.b.x = b.a.x - 2;
Taskbar->draw_me(Taskbar);
};
};
VIEW(userbox)->draw_view(VIEW(userbox));
};
////////////////////////////////////////////////////////////////////////////////
void add_to_userbox(p_object o)
{
obj_insert(OBJECT(userbox), o);
refresh_userbox();
};
////////////////////////////////////////////////////////////////////////////////
void remove_from_userbox(p_object o)
{
obj_remove(OBJECT(userbox), o);
refresh_userbox();
};
////////////////////////////////////////////////////////////////////////////////
typedef struct t_taskbar {
struct t_view obclass;
p_object relative;
l_int oldnbwin;
l_int oldnbviswin;
p_object oldtopwin;
p_list lst;
l_int sel;
} t_taskbar, *p_taskbar;
#define TASKBAR(o) ((p_taskbar)(o))
////////////////////////////////////////////////////////////////////////////////
void get_num_view_from( p_object o, l_dword tag, l_int *nb, l_int *visnb ) {
if ( o && o->last ) {
p_object p = o->first_view(o);
p_object f = p;
(*nb) = 0;
(*visnb)=0;
do {
if ( p->tag & tag && nb ) {
(*nb)++;
if ( p->is_state(p, OB_SF_VISIBLE) ) (*visnb)++;
};
p = p->next_view(p);
} while(f != p);
};
};
l_bool taskbar_done ( p_object o ) {
if ( Taskbar == VIEW(o) ) Taskbar = NULL;
return view_done(o);
};
////////////////////////////////////////////////////////////////////////////////
void taskbar_update ( p_taskbar o ) {
if ( o ) {
get_num_view_from ( o->relative, TAG_WINDOW, &o->oldnbwin, &o->oldnbviswin );
o->oldtopwin = o->relative->first(o->relative);
};
};
////////////////////////////////////////////////////////////////////////////////
l_bool taskbar_changed( p_taskbar o ) {
if ( o ) {
l_bool result = false;
l_int nb, visnb;
get_num_view_from ( o->relative, TAG_WINDOW, &nb, &visnb );
if ( nb != o->oldnbwin || visnb != o->oldnbviswin ) result = true;
if ( o->oldtopwin != o->relative->first(o->relative) ) result = true;
return result;
};
};
////////////////////////////////////////////////////////////////////////////////
t_rect taskbar_rect( p_taskbar o, l_int id ) {
t_rect r = VIEW(o)->get_local_extent(VIEW(o));
if ( BarPosition == 0 || BarPosition == 2 ) {
l_int w = min ( 150, r.b.x / o->oldnbwin );
return rect_assign ( r.a.x + ( id * w ), r.a.y, r.a.x + ( id * w ) + w - 2, r.b.y );
} else {
return rect_assign ( r.a.x, r.a.y + ( id * 20 ), r.b.x, r.a.y + ( id * 20 ) + 18 );
};
};
////////////////////////////////////////////////////////////////////////////////
void taskbar_func_callback ( p_object o ) {
if ( o && taskbar_changed(TASKBAR(o)) ) VIEW(o)->draw_me(VIEW(o));
};
////////////////////////////////////////////////////////////////////////////////
void taskbar_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 ) {
l_int dwn = 0;
if ( OBJECT(mouse)->state & MO_SF_MOUSELDOWN ) dwn = 1;
rectfill(out, p.x+r.a.x, p.y+r.a.y, p.x+r.b.x, p.y+r.b.y, color_deskbar_face );
taskbar_update(TASKBAR(o));
if ( TASKBAR(o)->oldnbwin ) {
p_item xpp = TASKBAR(o)->lst->first(TASKBAR(o)->lst);
p_item f = xpp;
l_int id = 0;
do {
p_object pp = OBJECT(xpp->rec);
t_rect item_r = rect_move( taskbar_rect(TASKBAR(o),id), p.x, p.y);
l_int dec = 0, z = 0;
if ( (pp->is_state(pp, OB_SF_FOCUSED)) && (pp->is_state(pp, OB_SF_VISIBLE)) ) {
button(out, item_r.a.x,
item_r.a.y,
item_r.b.x,
item_r.b.y,
color_deskbar_shadow, color_deskbar_light);
rectfill(out, item_r.a.x+1, item_r.a.y+1, item_r.b.x-1,item_r.b.y-1, color_deskbar_selected_face);
z = 1;
} else {
button(out, item_r.a.x,
item_r.a.y,
item_r.b.x,
item_r.b.y,
color_deskbar_light, color_deskbar_shadow);
};
if ( id == TASKBAR(o)->sel )
if ( dwn ) { button(out, item_r.a.x,
item_r.a.y,
item_r.b.x,
item_r.b.y,
color_deskbar_shadow, color_deskbar_light);
z = 1;
};
if ( pp->setup == &appwin_setup )
if ( APPWIN(pp)->icon16 && WINDOW(pp)->flags & WF_SYSMENU ) {
l_int x = item_r.a.x + 4;
l_int y = item_r.a.y + ( ( item_r.b.y - item_r.a.y ) - APPWIN(pp)->icon16->h ) / 2;
draw_sprite(out, APPWIN(pp)->icon16, x+z, y+z);
dec += APPWIN(pp)->icon16->w + 4;
};
if ( WINDOW(pp)-> caption )
textout_draw_rect(out, o->font, WINDOW(pp)->caption, -1,
item_r.a.x + 4 + dec + z,
item_r.a.y + 2 + z,
item_r.b.x - 4 + z,
item_r.b.y - 2 + z,
TX_ALIGN_CENTERY, (pp->is_state(pp, OB_SF_FOCUSED)) && (pp->is_state(pp, OB_SF_VISIBLE)) ? color_deskbar_selected_text : color_deskbar_text , TX_NOCOLOR, 1);
id++;
xpp = xpp->next; // Next ...
}while(f != xpp) ;
};
};
o->end_of_paint(o, r);
};
////////////////////////////////////////////////////////////////////////////////
void taskbar_translate_event ( p_object o, t_event *event ) {
RETVIEW(o, event);
view_translate_event(o, event);
if ( event->type & EV_MOUSE && ( OBJECT(mouse)->state & MO_SF_MOUSERUP || OBJECT(mouse)->state & MO_SF_MOUSELDOWN ) ) {
clear_event(event);
if ( TASKBAR(o)->oldnbwin ) {
t_point p = VIEW(o)->get_local_point(VIEW(o), mouse->where);
p_item xpp = TASKBAR(o)->lst->first(TASKBAR(o)->lst);
p_item f = xpp;
l_int id = 0;
do {
p_object pp = OBJECT(xpp->rec);
t_rect item_r = taskbar_rect(TASKBAR(o),id);
if ( rect_contains(item_r,p) ) {
TASKBAR(o)->sel = id;
if ( OBJECT(mouse)->state & MO_SF_MOUSERUP ) {
if ( pp->setup == &appwin_setup ) { // is it a appwin ?
if ( APPWIN(pp)->menu ) {
t_point xp = VIEW(o)->get_global_point(VIEW(o), point_assign(item_r.a.x,item_r.b.y+1));
t_rect r = rect_assign(xp.x,xp.y,xp.x,xp.y);
l_dword msg;
p_menu m = new_menu(APPWIN(pp)->menu);
p_menuview menu;
clear_event(event);
if (m) menu = menuview_init(malloc(sizeof(t_menuview)), r, m);
if (menu) {
msg = desktop->execute_view(desktop, VIEW(menu));
if ( msg == MSG_MAXIMIZE && !pp->is_state(pp, OB_SF_VISIBLE) ) {
VIEW(pp)->show(VIEW(pp));
OBJECT(pp)->select(OBJECT(pp));
} else {
set_event_info(event, EV_MESSAGE, msg, pp, NULL);
pp->put_event(pp, event);
clear_event(event);
};
};
};
};
} else if ( OBJECT(mouse)->state & MO_SF_MOUSELDOWN ) {
l_bool in_view = false;
VIEW(o)->draw_me(VIEW(o));
while ( OBJECT(mouse)->state & MO_SF_MOUSELPRESS ) {
l_bool safe_in_view = in_view;
p = VIEW(o)->get_local_point(VIEW(o), mouse->where);
in_view = rect_contains(item_r,p);
if ( in_view != safe_in_view )
VIEW(o)->draw_me(VIEW(o));
o->get_event(o, event);
};
if ( in_view ) {
VIEW(pp)->show(VIEW(pp));
OBJECT(pp)->select(OBJECT(pp));
VIEW(o)->draw_me(VIEW(o));
clear_event(event);
};
};
};
id++;
xpp = xpp->next; // Next ...
}while(f != xpp) ;
};
};
};
////////////////////////////////////////////////////////////////////////////////
p_taskbar taskbar_init ( p_taskbar o, t_rect r, p_object relative ) {
if (!o) return NULL;
clear_type(o, sizeof(t_taskbar));
view_init(VIEW(o), r);
o->relative = relative;
if ( !Tasklst ) Tasklst = list_init(malloc(sizeof(t_list)),0,0);
o->lst = Tasklst;
OBJECT(o)->done = &taskbar_done;
VIEW(o)->draw = &taskbar_draw;
OBJECT(o)->func_callback = &taskbar_func_callback;
OBJECT(o)->translate_event = &taskbar_translate_event;
OBJECT(o)->process_tick = 200;
OBJECT(o)->set_options(OBJECT(o), OB_OF_SELECTABLE+OB_OF_ENABLE, false);
OBJECT(o)->set_options(OBJECT(o), OB_OF_STILLPROCESS, true);
taskbar_update(o);
return o;
};
////////////////////////////////////////////////////////////////////////////////
t_object* dsk_insert ( p_object o, p_object sub ) {
if ( sub->tag & TAG_WINDOW && Tasklst ) {
Tasklst->insert(Tasklst,sub);
};
return obj_insert(o,sub);
};
t_object* dsk_insert_before ( p_object o, p_object sub, p_object before ) {
if ( sub->tag & TAG_WINDOW && Tasklst ) {
Tasklst->insert(Tasklst,sub);
};
return obj_insert_before(o,sub,before);
};
void dsk_remove ( p_object o, p_object sub ) {
if ( sub->tag & TAG_WINDOW && Tasklst ) {
p_item it = Tasklst->find_rec( Tasklst,sub);
if ( it ) Tasklst->remove_item( Tasklst,it);
};
obj_remove(o,sub);
};
void dsk_put_in_front_of ( p_object o, p_object before ){
if ( o->owner ) {
p_object owner = o->owner;
owner->set_prefer(owner, o);
if ( o != before ) {
VIEW(o)->draw_overlays(VIEW(o));
obj_remove(owner, o);
obj_insert_before(owner, o, before);
owner->reset_prefer(owner);
};
};
};
p_view dsk_view_init ( p_view o, t_rect r ) {
o = _view_init(o,r);
OBJECT(o)->put_in_front_of = &dsk_put_in_front_of;
return o;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -