4 * Author: Alessandro Scotti (Dec 2005)
\r
6 * ------------------------------------------------------------------------
\r
8 * GNU XBoard is free software: you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation, either version 3 of the License, or (at
\r
11 * your option) any later version.
\r
13 * GNU XBoard is distributed in the hope that it will be useful, but
\r
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
16 * General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License
\r
19 * along with this program. If not, see http://www.gnu.org/licenses/. *
\r
21 *------------------------------------------------------------------------
\r
22 ** See the file ChangeLog for a revision history. */
\r
26 #include <windows.h> /* required for all Windows applications */
\r
30 #include <commdlg.h>
\r
34 #include "winboard.h"
\r
36 VOID RestoreWindowPlacement( HWND hWnd, WindowPlacement * wp )
\r
38 if( wp->x != CW_USEDEFAULT ||
\r
39 wp->y != CW_USEDEFAULT ||
\r
40 wp->width != CW_USEDEFAULT ||
\r
41 wp->height != CW_USEDEFAULT )
\r
43 WINDOWPLACEMENT stWP;
\r
45 ZeroMemory( &stWP, sizeof(stWP) );
\r
47 EnsureOnScreen( &wp->x, &wp->y);
\r
49 stWP.length = sizeof(stWP);
\r
51 stWP.showCmd = SW_SHOW;
\r
52 stWP.ptMaxPosition.x = 0;
\r
53 stWP.ptMaxPosition.y = 0;
\r
54 stWP.rcNormalPosition.left = wp->x;
\r
55 stWP.rcNormalPosition.right = wp->x + wp->width;
\r
56 stWP.rcNormalPosition.top = wp->y;
\r
57 stWP.rcNormalPosition.bottom = wp->y + wp->height;
\r
59 SetWindowPlacement(hWnd, &stWP);
\r
63 VOID InitWindowPlacement( WindowPlacement * wp )
\r
66 wp->x = CW_USEDEFAULT;
\r
67 wp->y = CW_USEDEFAULT;
\r
68 wp->width = CW_USEDEFAULT;
\r
69 wp->height = CW_USEDEFAULT;
\r
72 static BOOL IsAttachDistance( int a, int b )
\r
74 BOOL result = FALSE;
\r
83 static BOOL IsDefaultPlacement( WindowPlacement * wp )
\r
85 BOOL result = FALSE;
\r
87 if( wp->x == CW_USEDEFAULT || wp->y == CW_USEDEFAULT || wp->width == CW_USEDEFAULT || wp->height == CW_USEDEFAULT ) {
\r
94 static BOOL GetActualPlacement( HWND hWnd, WindowPlacement * wp )
\r
96 BOOL result = FALSE;
\r
98 if( hWnd != NULL ) {
\r
99 WINDOWPLACEMENT stWP;
\r
101 ZeroMemory( &stWP, sizeof(stWP) );
\r
103 stWP.length = sizeof(stWP);
\r
105 GetWindowPlacement( hWnd, &stWP );
\r
107 wp->x = stWP.rcNormalPosition.left;
\r
108 wp->y = stWP.rcNormalPosition.top;
\r
109 wp->width = stWP.rcNormalPosition.right - stWP.rcNormalPosition.left;
\r
110 wp->height = stWP.rcNormalPosition.bottom - stWP.rcNormalPosition.top;
\r
118 static BOOL IsAttachedByWindowPlacement( LPRECT lprcMain, WindowPlacement * wp )
\r
120 BOOL result = FALSE;
\r
122 if( ! IsDefaultPlacement(wp) ) {
\r
123 if( IsAttachDistance( lprcMain->right, wp->x ) ||
\r
124 IsAttachDistance( lprcMain->bottom, wp->y ) ||
\r
125 IsAttachDistance( lprcMain->left, (wp->x + wp->width) ) ||
\r
126 IsAttachDistance( lprcMain->top, (wp->y + wp->height) ) )
\r
135 VOID ReattachAfterMove( LPRECT lprcOldPos, int new_x, int new_y, HWND hWndChild, WindowPlacement * pwpChild )
\r
137 if( ! IsDefaultPlacement( pwpChild ) ) {
\r
138 GetActualPlacement( hWndChild, pwpChild );
\r
140 if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {
\r
141 /* Get position delta */
\r
142 int delta_x = pwpChild->x - lprcOldPos->left;
\r
143 int delta_y = pwpChild->y - lprcOldPos->top;
\r
145 /* Adjust placement */
\r
146 pwpChild->x = new_x + delta_x;
\r
147 pwpChild->y = new_y + delta_y;
\r
150 if( hWndChild != NULL ) {
\r
151 SetWindowPos( hWndChild, HWND_TOP,
\r
152 pwpChild->x, pwpChild->y,
\r
154 SWP_NOZORDER | SWP_NOSIZE );
\r