mouse.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,373 行 · 第 1/3 页
C
1,373 行
}
static void IgnoreMousePress( POINT pt, WORD ks, OBJPTR obj )
/********************************************************************/
/* Ignore a mouse action */
{
pt = pt; /* ref'd to avoid warning */
ks = ks; /* ref'd to avoid warning */
obj = obj; /* ref'd to avoid warning */
}
static void FinishResize( POINT pt )
/**********************************/
/* finish the resize operation */
{
OBJPTR currobj;
pt = pt;
currobj = GetECurrObject();
if( currobj != NULL ) {
if( !Register( currobj ) ) {
RestorePrevObject();
}
}
MarkCurrObject();
SetDefState();
}
extern void AbortResize( void )
/*****************************/
{
OBJPTR eobj;
eobj = GetECurrObject();
if( eobj != NULL ) {
Destroy( eobj, FALSE );
RestorePrevObject();
}
MarkCurrObject();
SetDefState();
} /* AbortResize */
static void DoObjectRecreate( POINT pt )
/**************************************/
/* recreate the current object based on the mouse movement */
{
POINT point;
OBJPTR currobj;
point = pt;
SnapPointToGrid( &point );
currobj = GetECurrObject();
if( currobj != NULL ) {
Recreate( currobj, &point );
}
SetPrevMouse( pt );
}
static void DoSelectRecreate( POINT pt )
/**************************************/
/* recreate the current object based on the mouse movement */
{
POINT point;
OBJPTR eatom;
point = pt;
eatom = GetSelectEatom();
if( eatom != NULL ) {
Recreate( eatom, &point );
}
SetPrevMouse( pt );
}
static void FinishCreate( POINT pt )
/**********************************/
/* finish the create operation */
{
OBJPTR currobj;
pt = pt;
currobj = GetECurrObject();
if( currobj != NULL ) {
if( !Register( currobj ) ) {
RestorePrevObject();
}
}
MarkCurrObject();
SetDefState();
}
static BOOL SignificantMove( POINT pt )
/*************************************/
{
POINT prev;
prev = GetPrevMouse();
return( !( (pt.x == prev.x) && (pt.y == prev.y)) );
}
extern void ProcessButtonUp( POINT point )
/****************************************/
/* responds to a button up message from the mouse */
{
ProcessMouseMove( point );
MouseReleaseActions[GetState()]( point );
CheckMousePosn( point );
SnapPointToGrid( &point );
SetPrevMouse( point );
ReleaseCapture();
}
static BOOL Close( int cursor, int corner )
/*****************************************/
/* decides if the cursor position is within half of the width of a sizing
* square away from the corner
*/
{
return( (cursor > corner - SQUAREWIDTH/2 ) &&
(cursor < corner + SQUAREWIDTH/2 ) ) ;
}
static BOOL CheckForSquare( RECT * rect, int x, char sizeid )
/************************************************************/
/* checks if the cursor is near any of the sizing squares */
{
if( Close( x, rect->left ) && ( sizeid & R_LEFT ) ) {
SetSize( R_LEFT );
return( TRUE );
}
if( Close( x, rect->right ) && ( sizeid & R_RIGHT ) ) {
SetSize( R_RIGHT );
return( TRUE );
}
if( Close( x, ( rect->left + rect->right) / 2 ) ) {
return( TRUE );
}
return( FALSE );
}
static void CheckMousePosn( POINT pt )
/************************************/
/* Check the position of the mouse and change the mouse cursor if necessary */
{
RECT rect;
RESIZE_ID sizeid;
OBJPTR currobj;
currobj = GetPrimaryObject();
if( currobj == NULL ) {
return;
}
ResetSize();
Location( currobj, &rect );
sizeid = R_ALL;
GetResizeInfo( currobj, &sizeid );
if( sizeid != R_NONE ) {
if( ( sizeid & R_TOP ) && Close( pt.y, rect.top ) ) {
/* check for sizing boxes along top edge */
if( CheckForSquare( &rect, pt.x, sizeid ) ) {
SetSize( R_TOP );
}
} else if( ( sizeid & R_BOTTOM ) && Close( pt.y, rect.bottom ) ) {
/* check for sizing boxes along bottom edge */
if( CheckForSquare( &rect, pt.x, sizeid ) ) {
SetSize( R_BOTTOM );
}
} else if( Close( pt.y , ( rect.top + rect.bottom ) / 2 ) ) {
/* check for sizing on left or right edges */
if( ( sizeid & R_LEFT ) && Close( pt.x, rect.left ) ) {
SetSize( R_LEFT );
} else if( ( sizeid & R_RIGHT ) && Close( pt.x, rect.right ) ) {
SetSize( R_RIGHT );
}
}
}
if( GetState() == OVERBOX ) {
if( !Sizing( R_ALL ) ) {
/* was over a sizing square but isn't anymore */
SetDefState();
}
} else if( Sizing( R_ALL ) ) {
/* wasn't over a sizing squaure but now it is */
SetState( OVERBOX );
}
SetPrevMouse( pt );
}
static void DoObjectMove( POINT pt )
/**********************************/
/* move the current object based on the mouse movement */
{
POINT lastmouse;
POINT offset;
CURROBJPTR currobj;
lastmouse = GetPrevMouse();
offset.x = pt.x - lastmouse.x;
offset.y = pt.y - lastmouse.y;
currobj = GetECurrObject();
while( currobj != NULL ) {
if( GetObjptr( GetObjptr( currobj ) ) != NULL ) {
Move( currobj, &offset, TRUE );
}
currobj = GetNextECurrObject( currobj );
}
SetPrevMouse( pt );
}
static void DoObjectResize( POINT pt )
/************************************/
/* resize the current object based on the mouse movement */
{
RECT newloc;
POINT lastmouse;
POINT offset;
OBJPTR currobj;
SnapPointToResizeGrid( &pt );
lastmouse = GetPrevMouse();
SnapPointToResizeGrid( &lastmouse );
offset.x = pt.x - lastmouse.x;
offset.y = pt.y - lastmouse.y;
if( (offset.x != 0) || (offset.y != 0) ) {
newloc.top = offset.y;
newloc.bottom = offset.y;
newloc.left = offset.x;
newloc.right = offset.x;
currobj = GetECurrObject();
if( currobj != NULL ) {
Resize( currobj, &newloc, TRUE );
}
SetPrevMouse( pt );
}
}
extern void ProcessMouseMove( POINT point )
/*****************************************/
/* responds to a button down message from the mouse */
{
STATE_ID st;
st = GetState();
if( (st != MOVE_PENDING) || SignificantMove( point ) ) {
MouseMoveActions[st]( point );
}
}
static void FindPasteOffset( POINT * offset, POINT mouse )
/********************************************************/
/* Figure out how much to move all of the current objects so that the one
* that has it's top left corner fartherest to the left has the
* cursor at it's top left corner, and all other objects are positioned
* relative to it, to the right.
*/
{
OBJPTR obj;
RECT left;
RECT rect;
void * clist;
left.left = SHRT_MAX;
for( clist = GetClipList(); clist != NULL; clist = NextClipList( clist ) ) {
obj = GetClipObject( clist );
Location( obj, &rect );
if( rect.left < left.left ) {
CopyRect( &left, &rect );
}
}
offset->x = mouse.x - left.left;
offset->y = mouse.y - left.top;
}
static void BeginPaste( POINT pt, WORD keystate, OBJPTR d )
/*********************************************************/
/* begin a paste operation */
{
OBJPTR object;
OBJPTR newobj;
RECT rect;
POINT offset;
OBJPTR eatom;
void * clist;
keystate = keystate; /* ref'd to avoid warnings */
d = d;
SetState( PASTEING );
FindPasteOffset( &offset, pt );
ResetCurrObject( FALSE );
StartCurrObjMod();
for( clist = GetClipList(); clist != NULL; clist = NextClipList( clist ) ) {
object = GetClipObject( clist );
CopyObject( object, &newobj, NULL );
Location( newobj, &rect );
OffsetRect( &rect, offset.x, offset.y );
eatom = Create( O_EATOM, newobj, &rect, NULL );
AddCurrObject( eatom );
}
EndCurrObjMod();
}
static void DoPasteMove( POINT pt )
/*********************************/
/* move the current object based on the mouse movement */
{
POINT lastmouse;
POINT offset;
BOOL flag;
lastmouse = GetPrevMouse();
offset.x = pt.x - lastmouse.x;
offset.y = pt.y - lastmouse.y;
flag = TRUE;
ExecuteCurrObject( MOVE, &offset, &flag );
SetPrevMouse( pt );
}
static void FinishPaste( POINT pt )
/*********************************/
/* finish a paste operation */
{
OBJPTR parent;
POINT loc_pt;
OBJPTR eatom;
OBJPTR object;
CURROBJPTR currobj;
RECT rect;
LIST * newcurrobj;
newcurrobj = NULL;
SnapPointToGrid( &pt );
currobj = GetECurrObject();
while( currobj != NULL ) {
Location( currobj, &rect );
loc_pt.x = rect.left;
loc_pt.y = rect.top;
SnapPointToGrid( &loc_pt );
parent = FindOneObjPt( loc_pt );
eatom = GetObjptr( currobj );
object = GetObjptr( eatom );
if( PasteObject( object, parent, loc_pt ) ) {
ListAddElt( &newcurrobj, object );
}
Destroy( eatom, FALSE );
DeleteCurrObject( currobj );
MarkCurrObject();
currobj = GetECurrObject();
}
StartCurrObjMod();
while( newcurrobj != NULL ) {
AddCurrObject( ListElement( newcurrobj ) );
newcurrobj = ListConsume( newcurrobj );
}
EndCurrObjMod();
SetDefState();
}
static void PointSelect( POINT pt )
/*********************************/
{
OBJPTR currobj;
CURROBJPTR currobjptr;
LIST * list;
FindObjectsPt( pt, &list );
for( ; list != NULL; list = ListConsume( list ) ) {
currobj = ListElement( list );
currobjptr = GetCurrObjptr( currobj );
if( GetShift() ) { /* Doing multiple select */
if( currobjptr != NULL ) {
/* Object is already current so make it primary */
SetPrimaryObject( currobjptr );
} else {
AddCurrObject( currobj );
}
} else if( GetControl() ) {
/* Toggle the selection status of the object */
if( currobjptr != NULL ) {
DeleteCurrObjptr( currobj );
MarkCurrObject();
} else {
AddCurrObject( currobj );
}
} else {
SetCurrObject( currobj );
}
}
} /* PointSelect */
typedef enum {
RECT_EQUAL,
RECT_A_IN_B,
RECT_B_IN_A,
RECT_DISJOINT,
RECT_INTERSECT
} compare_rect_rc;
static compare_rect_rc CompareRect( LPRECT rect_a, LPRECT rect_b )
/****************************************************************/
{
RECT intersect;
if( EqualRect( rect_a, rect_b ) ) {
return( RECT_EQUAL );
} else if( IntersectRect( &intersect, rect_a, rect_b ) ) {
if( EqualRect( rect_a, &intersect ) ) {
return( RECT_A_IN_B );
} else if( EqualRect( rect_b, &intersect ) ) {
return( RECT_B_IN_A );
} else {
return( RECT_INTERSECT );
}
} else {
return( RECT_DISJOINT );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?