OSDN Git Service

Compile executable files.
[ffftp/ffftp.git] / dlgsize.c
1 /*=============================================================================\r
2 *\r
3 *                                       ダイアログボックスのサイズ変更処理\r
4 *\r
5 ===============================================================================\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.\r
7 /\r
8 / Redistribution and use in source and binary forms, with or without \r
9 / modification, are permitted provided that the following conditions \r
10 / are met:\r
11 /\r
12 /  1. Redistributions of source code must retain the above copyright \r
13 /     notice, this list of conditions and the following disclaimer.\r
14 /  2. Redistributions in binary form must reproduce the above copyright \r
15 /     notice, this list of conditions and the following disclaimer in the \r
16 /     documentation and/or other materials provided with the distribution.\r
17 /\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR \r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES \r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, \r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF \r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28 /============================================================================*/\r
29 \r
30 #define STRICT\r
31 // IPv6対応\r
32 #include <winsock2.h>\r
33 #include <windows.h>\r
34 #include <stdio.h>\r
35 #include <stdlib.h>\r
36 #include <string.h>\r
37 #include <commctrl.h>\r
38 #include <windowsx.h>\r
39 \r
40 #include "common.h"\r
41 #include "resource.h"\r
42 \r
43 \r
44 /*---------------------------------------------------------------------------*/\r
45 /* サイズ変更可能とするダイアログボックスは WS_CLIPCHILDREN スタイルを追加す */\r
46 /* ること */\r
47 /*---------------------------------------------------------------------------*/\r
48 \r
49 \r
50 /*----- ダイアログボックスの初期サイズを設定 ----------------------------------\r
51 *\r
52 *       Parameter\r
53 *               HWND hDlg : ウインドウハンドル\r
54 *               DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ\r
55 *               SIZE *Size : ダイアログのサイズ\r
56 *\r
57 *       Return Value\r
58 *               なし\r
59 *----------------------------------------------------------------------------*/\r
60 \r
61 void DlgSizeInit(HWND hDlg, DIALOGSIZE *Dt, SIZE *Size)\r
62 {\r
63         RECT Rect;\r
64 \r
65         GetWindowRect(hDlg, &Rect);\r
66         Dt->MinSize.cx = Rect.right - Rect.left;\r
67         Dt->MinSize.cy = Rect.bottom - Rect.top;\r
68         Dt->CurSize.cx = Dt->MinSize.cx;\r
69         Dt->CurSize.cy = Dt->MinSize.cy;\r
70 \r
71         if(Size->cx != -1)\r
72         {\r
73                 Rect.right = Rect.left + Size->cx;\r
74                 Rect.bottom = Rect.top + Size->cy;\r
75 \r
76                 DlgSizeChange(hDlg, Dt, &Rect, WMSZ_BOTTOMRIGHT);\r
77 \r
78                 GetWindowRect(hDlg, &Rect);\r
79                 MoveWindow(hDlg, Rect.left, Rect.top, Dt->CurSize.cx, Dt->CurSize.cy, TRUE);\r
80         }\r
81         return;\r
82 }\r
83 \r
84 \r
85 /*----- ダイアログボックスのサイズを返す --------------------------------------\r
86 *\r
87 *       Parameter\r
88 *               HWND hDlg : ウインドウハンドル\r
89 *               DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ\r
90 *               SIZE *Size : ダイアログのサイズを返すワーク\r
91 *\r
92 *       Return Value\r
93 *               なし\r
94 *----------------------------------------------------------------------------*/\r
95 \r
96 void AskDlgSize(HWND hDlg, DIALOGSIZE *Dt, SIZE *Size)\r
97 {\r
98         Size->cx = Dt->CurSize.cx;\r
99         Size->cy = Dt->CurSize.cy;\r
100         return;\r
101 }\r
102 \r
103 \r
104 \r
105 /*----- ダイアログボックスのサイズ変更処理 ------------------------------------\r
106 *\r
107 *       Parameter\r
108 *               HWND hDlg : ウインドウハンドル\r
109 *               DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ\r
110 *               RECT *New : 新しいダイアログのサイズ\r
111 *               int Flg : サイズ変更方向 (WMSZ_xxx)\r
112 *\r
113 *       Return Value\r
114 *               なし\r
115 *\r
116 *       Note\r
117 *               ダイアログボックスに WM_SIZING メッセージが来た時に呼ぶ事\r
118 *----------------------------------------------------------------------------*/\r
119 \r
120 void DlgSizeChange(HWND hDlg, DIALOGSIZE *Dt, RECT *New, int Flg)\r
121 {\r
122         int *Win;\r
123         RECT Rect;\r
124         POINT Point;\r
125 \r
126         /* 最少サイズより小さくならないようにする処理 */\r
127         if((New->right - New->left) < Dt->MinSize.cx)\r
128         {\r
129                 if((Flg == WMSZ_LEFT) || (Flg == WMSZ_TOPLEFT) || (Flg == WMSZ_BOTTOMLEFT))\r
130                         New->left = New->right - Dt->MinSize.cx;\r
131                 else\r
132                         New->right = New->left + Dt->MinSize.cx;\r
133         }\r
134         if((New->bottom - New->top) < Dt->MinSize.cy)\r
135         {\r
136                 if((Flg == WMSZ_TOP) || (Flg == WMSZ_TOPLEFT) || (Flg == WMSZ_TOPRIGHT))\r
137                         New->top = New->bottom - Dt->MinSize.cy;\r
138                 else\r
139                         New->bottom = New->top + Dt->MinSize.cy;\r
140         }\r
141 \r
142         /* 水平方向に移動する部品の処理 */\r
143         if(Dt->CurSize.cx != New->right - New->left)\r
144         {\r
145                 Win = Dt->HorMoveList;\r
146                 while(*Win != -1)\r
147                 {\r
148                         GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);\r
149                         Point.x = Rect.left + (New->right - New->left) - Dt->CurSize.cx;\r
150                         Point.y = Rect.top;\r
151                         ScreenToClient(hDlg, &Point);\r
152 \r
153                         GetClientRect(GetDlgItem(hDlg, *Win), &Rect);\r
154                         Rect.left = Point.x;\r
155                         Rect.top = Point.y;\r
156                         MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);\r
157 \r
158                         Win++;\r
159                 }\r
160         }\r
161 \r
162         /* 垂直方向に移動する部品の処理 */\r
163         if(Dt->CurSize.cy != New->bottom - New->top)\r
164         {\r
165                 Win = Dt->VarMoveList;\r
166                 while(*Win != -1)\r
167                 {\r
168                         GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);\r
169                         Point.x = Rect.left;\r
170                         Point.y = Rect.top + (New->bottom - New->top) - Dt->CurSize.cy;\r
171                         ScreenToClient(hDlg, &Point);\r
172 \r
173                         GetClientRect(GetDlgItem(hDlg, *Win), &Rect);\r
174                         Rect.left = Point.x;\r
175                         Rect.top = Point.y;\r
176                         MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);\r
177 \r
178                         Win++;\r
179                 }\r
180         }\r
181 \r
182         /* 大きさを変更する部品の処理 */\r
183         if((Dt->CurSize.cx != New->right - New->left) ||\r
184            (Dt->CurSize.cy != New->bottom - New->top))\r
185         {\r
186                 Win = Dt->ResizeList;\r
187                 while(*Win != -1)\r
188                 {\r
189                         GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);\r
190                         Rect.right = (Rect.right - Rect.left) + (New->right - New->left) - Dt->CurSize.cx;\r
191                         Rect.bottom = (Rect.bottom - Rect.top) + (New->bottom - New->top) - Dt->CurSize.cy;\r
192 \r
193                         Point.x = Rect.left;\r
194                         Point.y = Rect.top;\r
195                         ScreenToClient(hDlg, &Point);\r
196                         Rect.left = Point.x;\r
197                         Rect.top = Point.y;\r
198 \r
199                         MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);\r
200 \r
201                         Win++;\r
202                 }\r
203 \r
204         }\r
205 \r
206         Dt->CurSize.cx = New->right - New->left;\r
207         Dt->CurSize.cy = New->bottom - New->top;\r
208         InvalidateRect(hDlg, NULL, FALSE);\r
209 \r
210         return;\r
211 }\r
212 \r
213 \r