4 * Author: Alessandro Scotti (Dec 2005)
\r
6 * Copyright 2005 Alessandro Scotti
\r
8 * ------------------------------------------------------------------------
\r
10 * GNU XBoard is free software: you can redistribute it and/or modify
\r
11 * it under the terms of the GNU General Public License as published by
\r
12 * the Free Software Foundation, either version 3 of the License, or (at
\r
13 * your option) any later version.
\r
15 * GNU XBoard is distributed in the hope that it will be useful, but
\r
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
\r
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
18 * General Public License for more details.
\r
20 * You should have received a copy of the GNU General Public License
\r
21 * along with this program. If not, see http://www.gnu.org/licenses/. *
\r
23 *------------------------------------------------------------------------
\r
24 ** See the file ChangeLog for a revision history. */
\r
28 #include <windows.h> /* required for all Windows applications */
\r
32 #include <commdlg.h>
\r
36 #include "winboard.h"
\r
38 VOID RestoreWindowPlacement( HWND hWnd, WindowPlacement * wp )
\r
40 if( wp->x != CW_USEDEFAULT ||
\r
41 wp->y != CW_USEDEFAULT ||
\r
42 wp->width != CW_USEDEFAULT ||
\r
43 wp->height != CW_USEDEFAULT )
\r
45 WINDOWPLACEMENT stWP;
\r
47 ZeroMemory( &stWP, sizeof(stWP) );
\r
49 EnsureOnScreen( &wp->x, &wp->y, 0, 0);
\r
51 stWP.length = sizeof(stWP);
\r
53 stWP.showCmd = SW_SHOW;
\r
54 stWP.ptMaxPosition.x = 0;
\r
55 stWP.ptMaxPosition.y = 0;
\r
56 stWP.rcNormalPosition.left = wp->x;
\r
57 stWP.rcNormalPosition.right = wp->x + wp->width;
\r
58 stWP.rcNormalPosition.top = wp->y;
\r
59 stWP.rcNormalPosition.bottom = wp->y + wp->height;
\r
61 SetWindowPlacement(hWnd, &stWP);
\r
65 VOID InitWindowPlacement( WindowPlacement * wp )
\r
68 wp->x = CW_USEDEFAULT;
\r
69 wp->y = CW_USEDEFAULT;
\r
70 wp->width = CW_USEDEFAULT;
\r
71 wp->height = CW_USEDEFAULT;
\r
74 static BOOL IsAttachDistance( int a, int b )
\r
76 BOOL result = FALSE;
\r
85 static BOOL IsDefaultPlacement( WindowPlacement * wp )
\r
87 BOOL result = FALSE;
\r
89 if( wp->x == CW_USEDEFAULT || wp->y == CW_USEDEFAULT || wp->width == CW_USEDEFAULT || wp->height == CW_USEDEFAULT ) {
\r
96 static BOOL GetActualPlacement( HWND hWnd, WindowPlacement * wp )
\r
98 BOOL result = FALSE;
\r
100 if( hWnd != NULL ) {
\r
101 WINDOWPLACEMENT stWP;
\r
103 ZeroMemory( &stWP, sizeof(stWP) );
\r
105 stWP.length = sizeof(stWP);
\r
107 GetWindowPlacement( hWnd, &stWP );
\r
109 wp->x = stWP.rcNormalPosition.left;
\r
110 wp->y = stWP.rcNormalPosition.top;
\r
111 wp->width = stWP.rcNormalPosition.right - stWP.rcNormalPosition.left;
\r
112 wp->height = stWP.rcNormalPosition.bottom - stWP.rcNormalPosition.top;
\r
120 static BOOL IsAttachedByWindowPlacement( LPRECT lprcMain, WindowPlacement * wp )
\r
122 BOOL result = FALSE;
\r
124 if( ! IsDefaultPlacement(wp) ) {
\r
125 if( IsAttachDistance( lprcMain->right, wp->x ) ||
\r
126 IsAttachDistance( lprcMain->bottom, wp->y ) ||
\r
127 IsAttachDistance( lprcMain->left, (wp->x + wp->width) ) ||
\r
128 IsAttachDistance( lprcMain->top, (wp->y + wp->height) ) )
\r
137 VOID ReattachAfterMove( LPRECT lprcOldPos, int new_x, int new_y, HWND hWndChild, WindowPlacement * pwpChild )
\r
139 if( ! IsDefaultPlacement( pwpChild ) ) {
\r
140 GetActualPlacement( hWndChild, pwpChild );
\r
142 if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {
\r
143 /* Get position delta */
\r
144 int delta_x = pwpChild->x - lprcOldPos->left;
\r
145 int delta_y = pwpChild->y - lprcOldPos->top;
\r
147 /* Adjust placement */
\r
148 pwpChild->x = new_x + delta_x;
\r
149 pwpChild->y = new_y + delta_y;
\r
152 if( hWndChild != NULL ) {
\r
153 SetWindowPos( hWndChild, HWND_TOP,
\r
154 pwpChild->x, pwpChild->y,
\r
156 SWP_NOZORDER | SWP_NOSIZE );
\r
162 extern FILE *debugFP;
\r
163 VOID ReattachAfterSize( LPRECT lprcOldPos, int new_w, int new_h, HWND hWndChild, WindowPlacement * pwpChild )
\r
165 if( ! IsDefaultPlacement( pwpChild ) ) {
\r
166 GetActualPlacement( hWndChild, pwpChild );
\r
168 if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {
\r
169 /* Get delta of lower right corner */
\r
170 int delta_x = new_w - (lprcOldPos->right - lprcOldPos->left);
\r
171 int delta_y = new_h - (lprcOldPos->bottom - lprcOldPos->top);
\r
173 /* Adjust size & placement */
\r
174 if(pwpChild->x + pwpChild->width >= lprcOldPos->right )
\r
175 pwpChild->width += delta_x;
\r
176 if(pwpChild->y + pwpChild->height >= lprcOldPos->bottom )
\r
177 pwpChild->height += delta_y;
\r
178 if(pwpChild->x >= lprcOldPos->right) pwpChild->width -= delta_x, pwpChild->x += delta_x;
\r
179 if(pwpChild->y >= lprcOldPos->bottom) pwpChild->height -= delta_y, pwpChild->y += delta_y;
\r
181 if( hWndChild != NULL ) {
\r
182 SetWindowPos( hWndChild, HWND_TOP,
\r
183 pwpChild->x, pwpChild->y,
\r
184 pwpChild->width, pwpChild->height,
\r