📄 view.c
字号:
o->set_bounds(o, r);
};
};
l_dword view_execute_view ( p_view o, p_view sub )
{
l_dword message = MSG_NOTHING;
if ( sub ) {
l_dword poptions = OBJECT(sub)->options;
l_dword pstate = OBJECT(sub)->state;
p_object owner = OBJECT(OBJECT(sub)->owner_view(OBJECT(sub)));
p_object prefer = OBJECT(o)->prefer;
l_bool prefmodal = false;
OBJECT(sub)->set_options(OBJECT(sub), OB_OF_TOPSELECT, true);
OBJECT(sub)->set_state(OBJECT(sub), OB_SF_MODAL, true);
if ( !owner ) OBJECT(o)->insert(OBJECT(o), OBJECT(sub));
OBJECT(o)->set_prefer(OBJECT(o), OBJECT(sub));
message = OBJECT(sub)->execute(OBJECT(sub));
if ( !owner ) {
dispose(OBJECT(sub));
sub = NULL;
};
if ( sub ) {
OBJECT(sub)->options = poptions;
OBJECT(sub)->state = pstate;
};
OBJECT(o)->set_prefer(OBJECT(o), prefer);
};
return message;
};
p_data view_drag_data ( p_view o )
{
clear_type(&clipboard, sizeof(t_data));
if ( l_tag_cmp(OBJECT(o)->data_type, TAG_NONE) )
return NULL;
clipboard.style = DS_WHATEVER;
if ( OBJECT(o)->get_data(OBJECT(o), &clipboard) ) {
p_view t = NULL;
mouse_set_cursor_focus_id(CUR_DRAG);
while ( OBJECT(mouse)->state & MO_SF_MOUSELPRESS ) {
p_view oldt = NULL;
p_view tv = VIEW(o)->top_view(VIEW(o));
t = tv->get_top_view_under_mouse(tv);
OBJECT(o)->get_event(OBJECT(o), &event_main);
if ( t && OBJECT(mouse)->state & MO_SF_MOUSEMOVE ) {
t->drag_where(t, &clipboard, t->get_local_point(t, mouse->where));
if ( oldt ) {
oldt->drag_where(oldt, &clipboard, oldt->get_local_point(oldt, mouse->where));
};
};
oldt = t;
};
if ( t ) {
t->drag_where(t, NULL, t->get_local_point(t, mouse->where));
};
if ( o ) {
o->drag_where(o, NULL, o->get_local_point(o, mouse->where));
};
if ( t ) {
set_event(&event_main, EV_MESSAGE, MSG_PASTE, OBJECT(t));
OBJECT(o)->put_event(OBJECT(o), &event_main);
};
clear_event(&event_main);
mouse_set_cursor_focus_id(CUR_ARROW);
return (&clipboard);
};
return NULL;
};
/*
- this function is called even, when data is droped under the object
- where is local point to object in rectangle
(0,0, rect_sizex(o->bounds), rect_sizey(o->bounds))
- rec is pointer to t_data structure and contains information about
data that comes from draging object.
- when rec = NULL, it means it's end of draging so take things to right
place. if mouse(where) is not under me, it means that mouse was under me
before.
- standard structure of function is :
if ( view_drag_where(o, rec, where) ) { is mouse under view
return true;
} else mouse is not under view or end
if ( OBJECT(o)->is_state(OBJECT(o), OB_SF_FOCUSED) ) {
if ( rec ) mouse is not under view
else end of dragging - give things to right place
} else { mouse is not under view or end but in non-focused view
};
return false;
*/
l_bool view_drag_where ( p_view o, p_data rec, t_point where )
{
if ( rec && rect_contains(o->get_local_extent(o), where) ) {
if ( l_tag_cmp(OBJECT(o)->data_type, rec->id) &&
!is_active(OBJECT(o)) ) { /* not active process me + under me */
mouse_set_cursor_focus_id(CUR_DRAG); /* set drag cursor */
return true;
} else { /* my data_type not include rec->id */
mouse_set_cursor_focus_id(CUR_STOP); /* set stop cursor */
return false;
};
} else
return false;
};
/*
- where is local point
- not used, it's for compatibility
*/
l_bool view_drop_data ( p_view o, p_data rec, t_point where )
{
return false;
};
void view_drag_view ( p_view o, l_word mode, t_event *event )
{
t_rect safebounds = o->bounds;
t_rect r = safebounds;
if ( o->drag_mode & mode ) {
STOP_PROCESS();
if ( mode & DM_DRAGMOVE ) mouse_set_cursor_focus_id(CUR_MOVE);
if ( mode & DM_DRAGGROW ) mouse_set_cursor_focus_id(CUR_GROW);
r = o->drag(o, mode, event);
START_PROCESS();
o->change_bounds(o, r);
};
};
t_rect view_drag ( p_view o, l_word mode, t_event *event )
{
/*t_point delta;
t_rect box = o->bounds;
p_view owner = VIEW(OBJECT(o)->owner_view(OBJECT(o)));
if ( event->type & EV_MOUSE && owner ) {
t_rect limits = mouse->get_range(mouse);
t_rect b = owner->get_global_bounds(owner, o->get_limits(o));
t_point fc = owner->get_local_point(owner, mouse->where);
t_point change;
if ( _mode & DM_DRAGGROW ) _mode &= ~DM_DRAGCONTEXT;
if ( !(_mode & DM_DRAGCONTEXT) )
if ( !_mode & DM_DRAGMOVE )
mouse_set_mode(mouse, MO_MO_RECT, COLOR(CO_LIGHTGRAY), o->get_global_bounds(o, o->get_local_extent(o)));
else
if ( _mode & DM_DRAGGROW ) {
t_point p = o->get_global_point(o, o->size_minimum(o));
mouse_set_mode(mouse, MO_MO_GROW, COLOR(CO_LIGHTGRAY), o->get_global_bounds(o, o->get_local_extent(o)));
};
mouse->set_range(mouse, b);
if ( _mode & DM_DRAGCONTEXT )
mouse_set_mode(mouse, 0, 0, rect_empty);
while ( event->type & EV_MOUSE && !(OBJECT(mouse)->state & MO_SF_MOUSEUP) )
{
OBJECT(o)->get_event(OBJECT(o), event);
change = owner->get_local_point(owner, mouse->where);
if ( _mode & DM_DRAGCONTEXT && !_mode & DM_DRAGGROW) {
change.x -= fc.x; // delta X change
change.y -= fc.y; // delta Y change
box = rect_assign(box.a.x+change.x, box.a.y+change.y, box.b.x+change.x, box.b.y+change.y);
o->change_bounds(o, box);
fc = owner->get_local_point(owner, mouse->where);
};
};
change = owner->get_local_point(owner, mouse->where);
change.x -= fc.x; // delta X change
change.y -= fc.y; // delta Y change
if ( _mode & DM_DRAGMOVE )
box = rect_assign(box.a.x+change.x, box.a.y+change.y, box.b.x+change.x, box.b.y+change.y);
else
if ( _mode & DM_DRAGGROW )
box = rect_assign(o->bounds.a.x, o->bounds.a.y, box.b.x+change.x, box.b.y+change.y);
mouse_set_mode(mouse, 0, 0, rect_empty);
mouse->set_range(mouse, limits);
};
return box;*/
static t_rect box; // we pass this struct back, make sure it still there after we leave
box.a.x= o->bounds.a.x;
box.a.y= o->bounds.a.y;
box.b.x= o->bounds.b.x;
box.b.y= o->bounds.b.y;
if ( event->type & EV_MOUSE ) {
if (!(mode & DM_DRAGGROW)){
l_int sx,sy,fcx=mouse_x,fcy=mouse_y;
if ( move_step ) {
fcx = (fcx/move_step)*move_step;
fcy = (fcy/move_step)*move_step;
};
while ( !(OBJECT(mouse)->state & MO_SF_MOUSEUP) ) {
OBJECT(o)->get_event(OBJECT(o), event);
sx = mouse_x;sy = mouse_y;
if ( move_step ) {
sx = (sx/move_step)*move_step;
sy = (sy/move_step)*move_step;
if ( (sx-fcx) || (sy-fcy) ) {
box.b.x+=sx-fcx;
box.b.y+=sy-fcy;
box.a.x+=sx-fcx;
box.a.y+=sy-fcy;
fcx=sx;fcy=sy;
o->change_bounds(o, box);
};
} else if ( (sx-fcx) || (sy-fcy) ) {
box.b.x+=sx-fcx;
box.b.y+=sy-fcy;
box.a.x+=sx-fcx;
box.a.y+=sy-fcy;
fcx=sx;fcy=sy;
o->change_bounds(o, box);
}
}
} else {
l_int sx,sy,fcx=mouse_x,fcy=mouse_y; // record starting mouse position
if ( move_step ) {
fcx = (fcx/move_step)*move_step;
fcy = (fcy/move_step)*move_step;
};
while ( !(OBJECT(mouse)->state & MO_SF_MOUSEUP) ) {
OBJECT(o)->get_event(OBJECT(o), event);
sx = mouse_x;sy = mouse_y; // change= current mouse pos - prior mouse pos
if ( move_step ) {
sx = (sx/move_step)*move_step;
sy = (sy/move_step)*move_step;
if ( (sx-fcx) || (sy-fcy) ) {
box.b.x+=sx-fcx;
box.b.y+=sy-fcy;
fcx=sx;fcy=sy;
o->change_bounds(o, box);
};
} else
if( (sx-fcx) || (sy-fcy) ){
box.b.x+=sx-fcx;box.b.y+=sy-fcy; // alter size
fcx=sx;fcy=sy;
o->change_bounds(o, box);
}
}
}
}
return box;
};
t_rect view_get_limits ( p_view o )
{
p_view owner = VIEW(OBJECT(o)->owner_view(OBJECT(o)));
if ( !owner ) return o->bounds;
if ( OBJECT(o)->is_options(OBJECT(o), VW_OF_IGNORELIM) )
return owner->get_local_extent(owner);
return owner->size_limits(owner);
};
t_point view_size_minimum ( p_view o )
{
return point_assign(1, 1);
};
void view_for_each_sub_view_set_state ( p_view o, l_dword st, l_bool set )
{
o = VIEW(OBJECT(o)->last_view(OBJECT(o)));
while ( o ) {
OBJECT(o)->set_state(OBJECT(o), st, set);
o = VIEW(OBJECT(o)->prev_view_to_first(OBJECT(o)));
};
};
void view_lock_drawing ( p_view o )
{
o->draw_lock++;
};
l_bool view_unlock_drawing ( p_view o )
{
o->draw_lock--;
if ( o->draw_lock <= 0 ) {
o->draw_lock = 0;
};
return o->is_draw_lock(o);
};
l_bool view_is_draw_lock ( p_view o )
{
while ( o ) {
if ( o->draw_lock ) return true;
o = VIEW(OBJECT(o)->owner_view(OBJECT(o)));
};
return false;
};
void view_draw_overlays ( p_view o )
{
p_view owner = VIEW(OBJECT(o)->owner_view(OBJECT(o)));
p_view p;
l_long nobj;
l_long safe;
l_dword *states;
if ( !owner ) return;
p = VIEW(OBJECT(owner)->first_view(OBJECT(owner)));
nobj = OBJECT(owner)->index_of(OBJECT(owner), OBJECT(o));
safe = nobj;
states = (l_dword*)_calloc(nobj, sizeof(l_dword));
if ( !states ) return;
while ( p != o && nobj ) {
nobj--;
states[nobj] = OBJECT(p)->state;
OBJECT(p)->state &= ~OB_SF_VISIBLE;
p = VIEW(OBJECT(p)->next_view(OBJECT(p)));
};
p = VIEW(OBJECT(owner)->first_view(OBJECT(owner)));
while ( p != o ) {
t_rect r = rect_cliped(o->bounds, p->bounds);
if ( !rect_check_empty(r) ) {
t_rect safeclip = o->clip;
o->clip = rect_move(r, -o->bounds.a.x, -o->bounds.a.y);
o->draw_me(o);
o->clip = safeclip;
};
p = VIEW(OBJECT(p)->next_view(OBJECT(p)));
};
p = VIEW(OBJECT(owner)->first_view(OBJECT(owner)));
nobj = safe;
while ( p != o && nobj ) {
t_rect r = rect_cliped(o->bounds, p->bounds);
nobj--;
if ( !rect_check_empty(r) ) {
t_rect safeclip = o->clip;
o->clip = rect_move(r, -o->bounds.a.x, -o->bounds.a.y);
o->draw_sub_views(o, VIEW(OBJECT(o)->first_view(OBJECT(o))), VIEW(OBJECT(o)->first_view(OBJECT(o))));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -