X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwsnap.c;h=683aa159559d74d0a03819be0e1cfad5c63c431f;hb=542a66e557c246ca40ea112f34ccba6a33c147cc;hp=5492e8075cf3ac283bd31e3d67b442043be37b5f;hpb=682bb14684d3d8be078029778e08ec2b48bae65e;p=xboard.git diff --git a/winboard/wsnap.c b/winboard/wsnap.c index 5492e80..683aa15 100644 --- a/winboard/wsnap.c +++ b/winboard/wsnap.c @@ -64,14 +64,22 @@ static void AddSnapRectangle( SnapData * sd, RECT * rc ) AddSnapPoint( sd->y_grid, &sd->y_grid_len, rc->bottom ); } +static RECT activeRect, mainRect; +static int side, loc; // code for edge we were dragging, and its latest coordinate + static void AddSnapWindow( HWND hWndCaller, SnapData * sd, HWND hWndSnapWindow ) { - if( hWndSnapWindow != NULL && hWndCaller != hWndSnapWindow && IsWindowVisible(hWndSnapWindow) ) { + if( hWndSnapWindow != NULL && IsWindowVisible(hWndSnapWindow) ) { RECT rc; GetWindowRect( hWndSnapWindow, &rc ); + if(hWndSnapWindow == hwndMain) mainRect = rc; - AddSnapRectangle( sd, &rc ); + if(hWndCaller != hWndSnapWindow) { + AddSnapRectangle( sd, &rc ); + } else { + activeRect = rc; // [HGM] glue: remember original geometry of dragged window + } } } @@ -101,6 +109,7 @@ LRESULT OnEnterSizeMove( SnapData * snapData, HWND hWnd, WPARAM wParam, LPARAM l snapData->x_grid_len = 0; snapData->y_grid_len = 0; + side = 0; /* Add desktop area */ if( SystemParametersInfo( SPI_GETWORKAREA, 0, &rc, 0 ) ) { @@ -157,7 +166,7 @@ LRESULT OnSizing( SnapData * snapData, HWND hWnd, WPARAM wParam, LPARAM lParam ) switch( wParam ) { case WMSZ_BOTTOM: AdjustToSnapPoint( snapData->y_grid, snapData->y_grid_len, lprc->bottom, &snap_size_y, &delta_y ); - lprc->bottom += delta_y; + lprc->bottom += delta_y; side = 4; loc = lprc->bottom; break; case WMSZ_BOTTOMLEFT: AdjustToSnapPoint( snapData->y_grid, snapData->y_grid_len, lprc->bottom, &snap_size_y, &delta_y ); @@ -173,15 +182,15 @@ LRESULT OnSizing( SnapData * snapData, HWND hWnd, WPARAM wParam, LPARAM lParam ) break; case WMSZ_LEFT: AdjustToSnapPoint( snapData->x_grid, snapData->x_grid_len, lprc->left, &snap_size_x, &delta_x ); - lprc->left += delta_x; + lprc->left += delta_x; side = 1; loc = lprc->left; break; case WMSZ_RIGHT: AdjustToSnapPoint( snapData->x_grid, snapData->x_grid_len, lprc->right, &snap_size_x, &delta_x ); - lprc->right += delta_x; + lprc->right += delta_x; side = 2; loc = lprc->right; break; case WMSZ_TOP: AdjustToSnapPoint( snapData->y_grid, snapData->y_grid_len, lprc->top, &snap_size_y, &delta_y ); - lprc->top += delta_y; + lprc->top += delta_y; side = 3; loc = lprc->top; break; case WMSZ_TOPLEFT: AdjustToSnapPoint( snapData->y_grid, snapData->y_grid_len, lprc->top, &snap_size_y, &delta_y ); @@ -202,7 +211,60 @@ LRESULT OnSizing( SnapData * snapData, HWND hWnd, WPARAM wParam, LPARAM lParam ) return TRUE; } +static int Adjust( LONG *data, int new, int old , int vertical) +{ + // protect edges that also touch main window + if(!vertical && (old == mainRect.left || old == mainRect.right)) return 0; + if( vertical && (old == mainRect.top || old == mainRect.bottom)) return 0; + // if the coordinate was the same as the old, now make it the same as the new edge position + if(*data == old) { *data = new; return 1; } + return 0; +} + +static void KeepTouching( int side, int new, int old, HWND hWnd ) +{ // if the mentioned window was touching on the moved edge, move its touching edge too + if( IsWindowVisible(hWnd) ) { + RECT rc; + int i = 0; + + GetWindowRect( hWnd, &rc ); + + switch(side) { // figure out which edge we might need to drag along (if any) + case 1: i = Adjust(&rc.right, new, old, 0); break; + case 2: i = Adjust(&rc.left, new, old, 0); break; + case 3: i = Adjust(&rc.bottom, new, old, 1); break; + case 4: i = Adjust(&rc.top, new, old, 1); break; + } + + if(i) { // the correct edge was touching, and is adjusted + SetWindowPos(hWnd, HWND_TOP, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER ); + } + } +} + LRESULT OnExitSizeMove( SnapData * snapData, HWND hWnd, WPARAM wParam, LPARAM lParam ) { + if(side && hWnd != hwndMain) { // [HGM] glue: we have been sizing, by dragging an edge + int *grid = (side > 2 ? snapData->y_grid : snapData->x_grid); + int i, pos = -1, len = (side > 2 ? snapData->y_grid_len : snapData->x_grid_len); + + switch(side) { + case 1: pos = activeRect.left; break; + case 2: pos = activeRect.right; break; + case 3: pos = activeRect.top; break; + case 4: pos = activeRect.bottom; break; + } + + for(i=0; i