4 * Author: Alessandro Scotti (Dec 2005)
\r
6 * ------------------------------------------------------------------------
\r
7 * This program is free software; you can redistribute it and/or modify
\r
8 * it under the terms of the GNU General Public License as published by
\r
9 * the Free Software Foundation; either version 2 of the License, or
\r
10 * (at your option) any later version.
\r
12 * This program is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with this program; if not, write to the Free Software
\r
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\r
20 * ------------------------------------------------------------------------
\r
24 #include <windows.h> /* required for all Windows applications */
\r
28 #include <commdlg.h>
\r
32 #include "winboard.h"
\r
34 VOID RestoreWindowPlacement( HWND hWnd, WindowPlacement * wp )
\r
36 if( wp->x != CW_USEDEFAULT ||
\r
37 wp->y != CW_USEDEFAULT ||
\r
38 wp->width != CW_USEDEFAULT ||
\r
39 wp->height != CW_USEDEFAULT )
\r
41 WINDOWPLACEMENT stWP;
\r
43 ZeroMemory( &stWP, sizeof(stWP) );
\r
45 EnsureOnScreen( &wp->x, &wp->y);
\r
47 stWP.length = sizeof(stWP);
\r
49 stWP.showCmd = SW_SHOW;
\r
50 stWP.ptMaxPosition.x = 0;
\r
51 stWP.ptMaxPosition.y = 0;
\r
52 stWP.rcNormalPosition.left = wp->x;
\r
53 stWP.rcNormalPosition.right = wp->x + wp->width;
\r
54 stWP.rcNormalPosition.top = wp->y;
\r
55 stWP.rcNormalPosition.bottom = wp->y + wp->height;
\r
57 SetWindowPlacement(hWnd, &stWP);
\r
61 VOID InitWindowPlacement( WindowPlacement * wp )
\r
64 wp->x = CW_USEDEFAULT;
\r
65 wp->y = CW_USEDEFAULT;
\r
66 wp->width = CW_USEDEFAULT;
\r
67 wp->height = CW_USEDEFAULT;
\r
70 static BOOL IsAttachDistance( int a, int b )
\r
72 BOOL result = FALSE;
\r
81 static BOOL IsDefaultPlacement( WindowPlacement * wp )
\r
83 BOOL result = FALSE;
\r
85 if( wp->x == CW_USEDEFAULT || wp->y == CW_USEDEFAULT || wp->width == CW_USEDEFAULT || wp->height == CW_USEDEFAULT ) {
\r
92 static BOOL GetActualPlacement( HWND hWnd, WindowPlacement * wp )
\r
94 BOOL result = FALSE;
\r
96 if( hWnd != NULL ) {
\r
97 WINDOWPLACEMENT stWP;
\r
99 ZeroMemory( &stWP, sizeof(stWP) );
\r
101 stWP.length = sizeof(stWP);
\r
103 GetWindowPlacement( hWnd, &stWP );
\r
105 wp->x = stWP.rcNormalPosition.left;
\r
106 wp->y = stWP.rcNormalPosition.top;
\r
107 wp->width = stWP.rcNormalPosition.right - stWP.rcNormalPosition.left;
\r
108 wp->height = stWP.rcNormalPosition.bottom - stWP.rcNormalPosition.top;
\r
116 static BOOL IsAttachedByWindowPlacement( LPRECT lprcMain, WindowPlacement * wp )
\r
118 BOOL result = FALSE;
\r
120 if( ! IsDefaultPlacement(wp) ) {
\r
121 if( IsAttachDistance( lprcMain->right, wp->x ) ||
\r
122 IsAttachDistance( lprcMain->bottom, wp->y ) ||
\r
123 IsAttachDistance( lprcMain->left, (wp->x + wp->width) ) ||
\r
124 IsAttachDistance( lprcMain->top, (wp->y + wp->height) ) )
\r
133 VOID ReattachAfterMove( LPRECT lprcOldPos, int new_x, int new_y, HWND hWndChild, WindowPlacement * pwpChild )
\r
135 if( ! IsDefaultPlacement( pwpChild ) ) {
\r
136 GetActualPlacement( hWndChild, pwpChild );
\r
138 if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {
\r
139 /* Get position delta */
\r
140 int delta_x = pwpChild->x - lprcOldPos->left;
\r
141 int delta_y = pwpChild->y - lprcOldPos->top;
\r
143 /* Adjust placement */
\r
144 pwpChild->x = new_x + delta_x;
\r
145 pwpChild->y = new_y + delta_y;
\r
148 if( hWndChild != NULL ) {
\r
149 SetWindowPos( hWndChild, HWND_TOP,
\r
150 pwpChild->x, pwpChild->y,
\r
152 SWP_NOZORDER | SWP_NOSIZE );
\r