4 * Author: Alessandro Scotti (Dec 2005)
\r
6 * Copyright 2005 Alessandro Scotti
\r
8 * Enhancements Copyright 2009, 2012, 2013, 2014 Free Software Foundation, Inc.
\r
10 * ------------------------------------------------------------------------
\r
12 * GNU XBoard is free software: you can redistribute it and/or modify
\r
13 * it under the terms of the GNU General Public License as published by
\r
14 * the Free Software Foundation, either version 3 of the License, or (at
\r
15 * your option) any later version.
\r
17 * GNU XBoard is distributed in the hope that it will be useful, but
\r
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
\r
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
20 * General Public License for more details.
\r
22 * You should have received a copy of the GNU General Public License
\r
23 * along with this program. If not, see http://www.gnu.org/licenses/. *
\r
25 *------------------------------------------------------------------------
\r
26 ** See the file ChangeLog for a revision history. */
\r
30 #include <windows.h> /* required for all Windows applications */
\r
34 #include <commdlg.h>
\r
38 #include "frontend.h"
\r
39 #include "winboard.h"
\r
41 VOID RestoreWindowPlacement( HWND hWnd, WindowPlacement * wp )
\r
43 if( wp->x != CW_USEDEFAULT ||
\r
44 wp->y != CW_USEDEFAULT ||
\r
45 wp->width != CW_USEDEFAULT ||
\r
46 wp->height != CW_USEDEFAULT )
\r
48 WINDOWPLACEMENT stWP;
\r
50 ZeroMemory( &stWP, sizeof(stWP) );
\r
52 EnsureOnScreen( &wp->x, &wp->y, 0, 0);
\r
54 stWP.length = sizeof(stWP);
\r
56 stWP.showCmd = SW_SHOW;
\r
57 stWP.ptMaxPosition.x = 0;
\r
58 stWP.ptMaxPosition.y = 0;
\r
59 stWP.rcNormalPosition.left = wp->x;
\r
60 stWP.rcNormalPosition.right = wp->x + wp->width;
\r
61 stWP.rcNormalPosition.top = wp->y;
\r
62 stWP.rcNormalPosition.bottom = wp->y + wp->height;
\r
64 SetWindowPlacement(hWnd, &stWP);
\r
68 VOID InitWindowPlacement( WindowPlacement * wp )
\r
71 wp->x = CW_USEDEFAULT;
\r
72 wp->y = CW_USEDEFAULT;
\r
73 wp->width = CW_USEDEFAULT;
\r
74 wp->height = CW_USEDEFAULT;
\r
77 static BOOL IsAttachDistance( int a, int b )
\r
79 BOOL result = FALSE;
\r
88 static BOOL IsDefaultPlacement( WindowPlacement * wp )
\r
90 BOOL result = FALSE;
\r
92 if( wp->x == CW_USEDEFAULT || wp->y == CW_USEDEFAULT || wp->width == CW_USEDEFAULT || wp->height == CW_USEDEFAULT ) {
\r
99 BOOL GetActualPlacement( HWND hWnd, WindowPlacement * wp )
\r
101 BOOL result = FALSE;
\r
103 if( hWnd != NULL ) {
\r
104 WINDOWPLACEMENT stWP;
\r
106 ZeroMemory( &stWP, sizeof(stWP) );
\r
108 stWP.length = sizeof(stWP);
\r
110 GetWindowPlacement( hWnd, &stWP );
\r
112 wp->x = stWP.rcNormalPosition.left;
\r
113 wp->y = stWP.rcNormalPosition.top;
\r
114 wp->width = stWP.rcNormalPosition.right - stWP.rcNormalPosition.left;
\r
115 wp->height = stWP.rcNormalPosition.bottom - stWP.rcNormalPosition.top;
\r
123 static BOOL IsAttachedByWindowPlacement( LPRECT lprcMain, WindowPlacement * wp )
\r
125 BOOL result = FALSE;
\r
127 if( ! IsDefaultPlacement(wp) ) {
\r
128 if( IsAttachDistance( lprcMain->right, wp->x ) ||
\r
129 IsAttachDistance( lprcMain->bottom, wp->y ) ||
\r
130 IsAttachDistance( lprcMain->left, (wp->x + wp->width) ) ||
\r
131 IsAttachDistance( lprcMain->top, (wp->y + wp->height) ) )
\r
140 VOID ReattachAfterMove( LPRECT lprcOldPos, int new_x, int new_y, HWND hWndChild, WindowPlacement * pwpChild )
\r
142 if( ! IsDefaultPlacement( pwpChild ) ) {
\r
143 GetActualPlacement( hWndChild, pwpChild );
\r
145 if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {
\r
146 /* Get position delta */
\r
147 int delta_x = pwpChild->x - lprcOldPos->left;
\r
148 int delta_y = pwpChild->y - lprcOldPos->top;
\r
150 /* Adjust placement */
\r
151 pwpChild->x = new_x + delta_x;
\r
152 pwpChild->y = new_y + delta_y;
\r
155 if( hWndChild != NULL ) {
\r
156 SetWindowPos( hWndChild, HWND_TOP,
\r
157 pwpChild->x, pwpChild->y,
\r
159 SWP_NOZORDER | SWP_NOSIZE );
\r
165 extern FILE *debugFP;
\r
166 VOID ReattachAfterSize( LPRECT lprcOldPos, int new_w, int new_h, HWND hWndChild, WindowPlacement * pwpChild )
\r
168 if( ! IsDefaultPlacement( pwpChild ) ) {
\r
169 GetActualPlacement( hWndChild, pwpChild );
\r
171 if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {
\r
172 /* Get delta of lower right corner */
\r
173 int delta_x = new_w - (lprcOldPos->right - lprcOldPos->left);
\r
174 int delta_y = new_h - (lprcOldPos->bottom - lprcOldPos->top);
\r
176 /* Adjust size & placement */
\r
177 if(pwpChild->x + pwpChild->width >= lprcOldPos->right &&
\r
178 (pwpChild->x + pwpChild->width < screenGeometry.right - 5 || delta_x > 0) ) // keep right edge glued to display edge if touching
\r
179 pwpChild->width += delta_x;
\r
180 if(pwpChild->x + pwpChild->width >= screenGeometry.right ) // don't move right edge off screen
\r
181 pwpChild->width = screenGeometry.right - pwpChild->x;
\r
182 if(pwpChild->y + pwpChild->height >= lprcOldPos->bottom &&
\r
183 (pwpChild->y + pwpChild->height < screenGeometry.bottom - 35 || delta_y > 0) ) // keep bottom edge glued to display edge if touching
\r
184 pwpChild->height += delta_y;
\r
185 if(pwpChild->y + pwpChild->height >= screenGeometry.bottom - 30 ) // don't move bottom edge off screen
\r
186 pwpChild->height = screenGeometry.bottom - 30 - pwpChild->y;
\r
187 if(pwpChild->x >= lprcOldPos->right) pwpChild->width -= delta_x, pwpChild->x += delta_x;
\r
188 if(pwpChild->y >= lprcOldPos->bottom) pwpChild->height -= delta_y, pwpChild->y += delta_y;
\r
189 if(pwpChild->width < 30) pwpChild->width = 30; // force minimum width
\r
190 if(pwpChild->height < 50) pwpChild->height = 50; // force minimum height
\r
192 if( hWndChild != NULL ) {
\r
193 SetWindowPos( hWndChild, HWND_TOP,
\r
194 pwpChild->x, pwpChild->y,
\r
195 pwpChild->width, pwpChild->height,
\r