OSDN Git Service

Fix bugs of treating corrupted filenames.
[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 #include <windows.h>\r
32 #include <stdio.h>\r
33 #include <stdlib.h>\r
34 #include <string.h>\r
35 #include <commctrl.h>\r
36 #include <windowsx.h>\r
37 \r
38 #include "common.h"\r
39 #include "resource.h"\r
40 \r
41 \r
42 /*---------------------------------------------------------------------------*/\r
43 /* サイズ変更可能とするダイアログボックスは WS_CLIPCHILDREN スタイルを追加す */\r
44 /* ること */\r
45 /*---------------------------------------------------------------------------*/\r
46 \r
47 \r
48 /*----- ダイアログボックスの初期サイズを設定 ----------------------------------\r
49 *\r
50 *       Parameter\r
51 *               HWND hDlg : ウインドウハンドル\r
52 *               DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ\r
53 *               SIZE *Size : ダイアログのサイズ\r
54 *\r
55 *       Return Value\r
56 *               なし\r
57 *----------------------------------------------------------------------------*/\r
58 \r
59 void DlgSizeInit(HWND hDlg, DIALOGSIZE *Dt, SIZE *Size)\r
60 {\r
61         RECT Rect;\r
62 \r
63         GetWindowRect(hDlg, &Rect);\r
64         Dt->MinSize.cx = Rect.right - Rect.left;\r
65         Dt->MinSize.cy = Rect.bottom - Rect.top;\r
66         Dt->CurSize.cx = Dt->MinSize.cx;\r
67         Dt->CurSize.cy = Dt->MinSize.cy;\r
68 \r
69         if(Size->cx != -1)\r
70         {\r
71                 Rect.right = Rect.left + Size->cx;\r
72                 Rect.bottom = Rect.top + Size->cy;\r
73 \r
74                 DlgSizeChange(hDlg, Dt, &Rect, WMSZ_BOTTOMRIGHT);\r
75 \r
76                 GetWindowRect(hDlg, &Rect);\r
77                 MoveWindow(hDlg, Rect.left, Rect.top, Dt->CurSize.cx, Dt->CurSize.cy, TRUE);\r
78         }\r
79         return;\r
80 }\r
81 \r
82 \r
83 /*----- ダイアログボックスのサイズを返す --------------------------------------\r
84 *\r
85 *       Parameter\r
86 *               HWND hDlg : ウインドウハンドル\r
87 *               DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ\r
88 *               SIZE *Size : ダイアログのサイズを返すワーク\r
89 *\r
90 *       Return Value\r
91 *               なし\r
92 *----------------------------------------------------------------------------*/\r
93 \r
94 void AskDlgSize(HWND hDlg, DIALOGSIZE *Dt, SIZE *Size)\r
95 {\r
96         Size->cx = Dt->CurSize.cx;\r
97         Size->cy = Dt->CurSize.cy;\r
98         return;\r
99 }\r
100 \r
101 \r
102 \r
103 /*----- ダイアログボックスのサイズ変更処理 ------------------------------------\r
104 *\r
105 *       Parameter\r
106 *               HWND hDlg : ウインドウハンドル\r
107 *               DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ\r
108 *               RECT *New : 新しいダイアログのサイズ\r
109 *               int Flg : サイズ変更方向 (WMSZ_xxx)\r
110 *\r
111 *       Return Value\r
112 *               なし\r
113 *\r
114 *       Note\r
115 *               ダイアログボックスに WM_SIZING メッセージが来た時に呼ぶ事\r
116 *----------------------------------------------------------------------------*/\r
117 \r
118 void DlgSizeChange(HWND hDlg, DIALOGSIZE *Dt, RECT *New, int Flg)\r
119 {\r
120         int *Win;\r
121         RECT Rect;\r
122         POINT Point;\r
123 \r
124         /* 最少サイズより小さくならないようにする処理 */\r
125         if((New->right - New->left) < Dt->MinSize.cx)\r
126         {\r
127                 if((Flg == WMSZ_LEFT) || (Flg == WMSZ_TOPLEFT) || (Flg == WMSZ_BOTTOMLEFT))\r
128                         New->left = New->right - Dt->MinSize.cx;\r
129                 else\r
130                         New->right = New->left + Dt->MinSize.cx;\r
131         }\r
132         if((New->bottom - New->top) < Dt->MinSize.cy)\r
133         {\r
134                 if((Flg == WMSZ_TOP) || (Flg == WMSZ_TOPLEFT) || (Flg == WMSZ_TOPRIGHT))\r
135                         New->top = New->bottom - Dt->MinSize.cy;\r
136                 else\r
137                         New->bottom = New->top + Dt->MinSize.cy;\r
138         }\r
139 \r
140         /* 水平方向に移動する部品の処理 */\r
141         if(Dt->CurSize.cx != New->right - New->left)\r
142         {\r
143                 Win = Dt->HorMoveList;\r
144                 while(*Win != -1)\r
145                 {\r
146                         GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);\r
147                         Point.x = Rect.left + (New->right - New->left) - Dt->CurSize.cx;\r
148                         Point.y = Rect.top;\r
149                         ScreenToClient(hDlg, &Point);\r
150 \r
151                         GetClientRect(GetDlgItem(hDlg, *Win), &Rect);\r
152                         Rect.left = Point.x;\r
153                         Rect.top = Point.y;\r
154                         MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);\r
155 \r
156                         Win++;\r
157                 }\r
158         }\r
159 \r
160         /* 垂直方向に移動する部品の処理 */\r
161         if(Dt->CurSize.cy != New->bottom - New->top)\r
162         {\r
163                 Win = Dt->VarMoveList;\r
164                 while(*Win != -1)\r
165                 {\r
166                         GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);\r
167                         Point.x = Rect.left;\r
168                         Point.y = Rect.top + (New->bottom - New->top) - Dt->CurSize.cy;\r
169                         ScreenToClient(hDlg, &Point);\r
170 \r
171                         GetClientRect(GetDlgItem(hDlg, *Win), &Rect);\r
172                         Rect.left = Point.x;\r
173                         Rect.top = Point.y;\r
174                         MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);\r
175 \r
176                         Win++;\r
177                 }\r
178         }\r
179 \r
180         /* 大きさを変更する部品の処理 */\r
181         if((Dt->CurSize.cx != New->right - New->left) ||\r
182            (Dt->CurSize.cy != New->bottom - New->top))\r
183         {\r
184                 Win = Dt->ResizeList;\r
185                 while(*Win != -1)\r
186                 {\r
187                         GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);\r
188                         Rect.right = (Rect.right - Rect.left) + (New->right - New->left) - Dt->CurSize.cx;\r
189                         Rect.bottom = (Rect.bottom - Rect.top) + (New->bottom - New->top) - Dt->CurSize.cy;\r
190 \r
191                         Point.x = Rect.left;\r
192                         Point.y = Rect.top;\r
193                         ScreenToClient(hDlg, &Point);\r
194                         Rect.left = Point.x;\r
195                         Rect.top = Point.y;\r
196 \r
197                         MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);\r
198 \r
199                         Win++;\r
200                 }\r
201 \r
202         }\r
203 \r
204         Dt->CurSize.cx = New->right - New->left;\r
205         Dt->CurSize.cy = New->bottom - New->top;\r
206         InvalidateRect(hDlg, NULL, FALSE);\r
207 \r
208         return;\r
209 }\r
210 \r
211 \r