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 "frontend.h"
\r
37 #include "winboard.h"
\r
39 VOID RestoreWindowPlacement( HWND hWnd, WindowPlacement * wp )
\r
41 if( wp->x != CW_USEDEFAULT ||
\r
42 wp->y != CW_USEDEFAULT ||
\r
43 wp->width != CW_USEDEFAULT ||
\r
44 wp->height != CW_USEDEFAULT )
\r
46 WINDOWPLACEMENT stWP;
\r
48 ZeroMemory( &stWP, sizeof(stWP) );
\r
50 EnsureOnScreen( &wp->x, &wp->y, 0, 0);
\r
52 stWP.length = sizeof(stWP);
\r
54 stWP.showCmd = SW_SHOW;
\r
55 stWP.ptMaxPosition.x = 0;
\r
56 stWP.ptMaxPosition.y = 0;
\r
57 stWP.rcNormalPosition.left = wp->x;
\r
58 stWP.rcNormalPosition.right = wp->x + wp->width;
\r
59 stWP.rcNormalPosition.top = wp->y;
\r
60 stWP.rcNormalPosition.bottom = wp->y + wp->height;
\r
62 SetWindowPlacement(hWnd, &stWP);
\r
66 VOID InitWindowPlacement( WindowPlacement * wp )
\r
69 wp->x = CW_USEDEFAULT;
\r
70 wp->y = CW_USEDEFAULT;
\r
71 wp->width = CW_USEDEFAULT;
\r
72 wp->height = CW_USEDEFAULT;
\r
75 static BOOL IsAttachDistance( int a, int b )
\r
77 BOOL result = FALSE;
\r
86 static BOOL IsDefaultPlacement( WindowPlacement * wp )
\r
88 BOOL result = FALSE;
\r
90 if( wp->x == CW_USEDEFAULT || wp->y == CW_USEDEFAULT || wp->width == CW_USEDEFAULT || wp->height == CW_USEDEFAULT ) {
\r
97 BOOL GetActualPlacement( HWND hWnd, WindowPlacement * wp )
\r
99 BOOL result = FALSE;
\r
101 if( hWnd != NULL ) {
\r
102 WINDOWPLACEMENT stWP;
\r
104 ZeroMemory( &stWP, sizeof(stWP) );
\r
106 stWP.length = sizeof(stWP);
\r
108 GetWindowPlacement( hWnd, &stWP );
\r
110 wp->x = stWP.rcNormalPosition.left;
\r
111 wp->y = stWP.rcNormalPosition.top;
\r
112 wp->width = stWP.rcNormalPosition.right - stWP.rcNormalPosition.left;
\r
113 wp->height = stWP.rcNormalPosition.bottom - stWP.rcNormalPosition.top;
\r
121 static BOOL IsAttachedByWindowPlacement( LPRECT lprcMain, WindowPlacement * wp )
\r
123 BOOL result = FALSE;
\r
125 if( ! IsDefaultPlacement(wp) ) {
\r
126 if( IsAttachDistance( lprcMain->right, wp->x ) ||
\r
127 IsAttachDistance( lprcMain->bottom, wp->y ) ||
\r
128 IsAttachDistance( lprcMain->left, (wp->x + wp->width) ) ||
\r
129 IsAttachDistance( lprcMain->top, (wp->y + wp->height) ) )
\r
138 VOID ReattachAfterMove( LPRECT lprcOldPos, int new_x, int new_y, HWND hWndChild, WindowPlacement * pwpChild )
\r
140 if( ! IsDefaultPlacement( pwpChild ) ) {
\r
141 GetActualPlacement( hWndChild, pwpChild );
\r
143 if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {
\r
144 /* Get position delta */
\r
145 int delta_x = pwpChild->x - lprcOldPos->left;
\r
146 int delta_y = pwpChild->y - lprcOldPos->top;
\r
148 /* Adjust placement */
\r
149 pwpChild->x = new_x + delta_x;
\r
150 pwpChild->y = new_y + delta_y;
\r
153 if( hWndChild != NULL ) {
\r
154 SetWindowPos( hWndChild, HWND_TOP,
\r
155 pwpChild->x, pwpChild->y,
\r
157 SWP_NOZORDER | SWP_NOSIZE );
\r
163 extern FILE *debugFP;
\r
164 VOID ReattachAfterSize( LPRECT lprcOldPos, int new_w, int new_h, HWND hWndChild, WindowPlacement * pwpChild )
\r
166 if( ! IsDefaultPlacement( pwpChild ) ) {
\r
167 GetActualPlacement( hWndChild, pwpChild );
\r
169 if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {
\r
170 /* Get delta of lower right corner */
\r
171 int delta_x = new_w - (lprcOldPos->right - lprcOldPos->left);
\r
172 int delta_y = new_h - (lprcOldPos->bottom - lprcOldPos->top);
\r
174 /* Adjust size & placement */
\r
175 if(pwpChild->x + pwpChild->width >= lprcOldPos->right )
\r
176 pwpChild->width += delta_x;
\r
177 if(pwpChild->y + pwpChild->height >= lprcOldPos->bottom )
\r
178 pwpChild->height += delta_y;
\r
179 if(pwpChild->x >= lprcOldPos->right) pwpChild->width -= delta_x, pwpChild->x += delta_x;
\r
180 if(pwpChild->y >= lprcOldPos->bottom) pwpChild->height -= delta_y, pwpChild->y += delta_y;
\r
182 if( hWndChild != NULL ) {
\r
183 SetWindowPos( hWndChild, HWND_TOP,
\r
184 pwpChild->x, pwpChild->y,
\r
185 pwpChild->width, pwpChild->height,
\r