Sync with trunk r63502.
[reactos.git] / base / applications / mspaint / dialogs.c
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/paint/dialogs.c
5 * PURPOSE: Window procedures of the dialog windows plus launching functions
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include "precomp.h"
12
13 #include <winnls.h>
14
15 /* FUNCTIONS ********************************************************/
16
17 LRESULT CALLBACK
18 MRDlgWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
19 {
20 switch (message)
21 {
22 case WM_INITDIALOG:
23 CheckDlgButton(hwnd, IDD_MIRRORROTATERB1, BST_CHECKED);
24 CheckDlgButton(hwnd, IDD_MIRRORROTATERB4, BST_CHECKED);
25 return TRUE;
26 case WM_CLOSE:
27 EndDialog(hwnd, 0);
28 break;
29 case WM_COMMAND:
30 switch (LOWORD(wParam))
31 {
32 case IDOK:
33 if (IsDlgButtonChecked(hwnd, IDD_MIRRORROTATERB1))
34 EndDialog(hwnd, 1);
35 else if (IsDlgButtonChecked(hwnd, IDD_MIRRORROTATERB2))
36 EndDialog(hwnd, 2);
37 else if (IsDlgButtonChecked(hwnd, IDD_MIRRORROTATERB4))
38 EndDialog(hwnd, 3);
39 else if (IsDlgButtonChecked(hwnd, IDD_MIRRORROTATERB5))
40 EndDialog(hwnd, 4);
41 else if (IsDlgButtonChecked(hwnd, IDD_MIRRORROTATERB6))
42 EndDialog(hwnd, 5);
43 break;
44 case IDCANCEL:
45 EndDialog(hwnd, 0);
46 break;
47 case IDD_MIRRORROTATERB3:
48 EnableWindow(GetDlgItem(hwnd, IDD_MIRRORROTATERB4), TRUE);
49 EnableWindow(GetDlgItem(hwnd, IDD_MIRRORROTATERB5), TRUE);
50 EnableWindow(GetDlgItem(hwnd, IDD_MIRRORROTATERB6), TRUE);
51 break;
52 case IDD_MIRRORROTATERB1:
53 case IDD_MIRRORROTATERB2:
54 EnableWindow(GetDlgItem(hwnd, IDD_MIRRORROTATERB4), FALSE);
55 EnableWindow(GetDlgItem(hwnd, IDD_MIRRORROTATERB5), FALSE);
56 EnableWindow(GetDlgItem(hwnd, IDD_MIRRORROTATERB6), FALSE);
57 break;
58 }
59 break;
60 default:
61 return FALSE;
62 }
63 return TRUE;
64 }
65
66 int
67 mirrorRotateDlg()
68 {
69 return DialogBox(hProgInstance, MAKEINTRESOURCE(IDD_MIRRORROTATE), hMainWnd, (DLGPROC) MRDlgWinProc);
70 }
71
72 LRESULT CALLBACK
73 ATTDlgWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
74 {
75 switch (message)
76 {
77 case WM_INITDIALOG:
78 {
79 TCHAR strrc[100];
80 TCHAR res[100];
81
82 widthSetInDlg = imgXRes;
83 heightSetInDlg = imgYRes;
84
85 CheckDlgButton(hwnd, IDD_ATTRIBUTESRB3, BST_CHECKED);
86 CheckDlgButton(hwnd, IDD_ATTRIBUTESRB5, BST_CHECKED);
87 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT1, widthSetInDlg, FALSE);
88 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT2, heightSetInDlg, FALSE);
89
90 if (isAFile)
91 {
92 TCHAR date[100];
93 TCHAR size[100];
94 TCHAR temp[100];
95 GetDateFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, date, SIZEOF(date));
96 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, temp, SIZEOF(temp));
97 _tcscat(date, _T(" "));
98 _tcscat(date, temp);
99 LoadString(hProgInstance, IDS_FILESIZE, strrc, SIZEOF(strrc));
100 _stprintf(size, strrc, fileSize);
101 SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT6, date);
102 SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT7, size);
103 }
104 LoadString(hProgInstance, IDS_PRINTRES, strrc, SIZEOF(strrc));
105 _stprintf(res, strrc, fileHPPM, fileVPPM);
106 SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT8, res);
107 return TRUE;
108 }
109 case WM_CLOSE:
110 EndDialog(hwnd, 0);
111 break;
112 case WM_COMMAND:
113 switch (LOWORD(wParam))
114 {
115 case IDOK:
116 EndDialog(hwnd, 1);
117 break;
118 case IDCANCEL:
119 EndDialog(hwnd, 0);
120 break;
121 case IDD_ATTRIBUTESSTANDARD:
122 widthSetInDlg = imgXRes;
123 heightSetInDlg = imgYRes;
124 CheckDlgButton(hwnd, IDD_ATTRIBUTESRB3, BST_CHECKED);
125 CheckDlgButton(hwnd, IDD_ATTRIBUTESRB5, BST_CHECKED);
126 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT1, widthSetInDlg, FALSE);
127 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT2, heightSetInDlg, FALSE);
128 break;
129 case IDD_ATTRIBUTESRB1:
130 {
131 TCHAR number[100];
132 _stprintf(number, _T("%.3lf"), widthSetInDlg / (0.0254 * fileHPPM));
133 SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, number);
134 _stprintf(number, _T("%.3lf"), heightSetInDlg / (0.0254 * fileVPPM));
135 SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, number);
136 break;
137 }
138 case IDD_ATTRIBUTESRB2:
139 {
140 TCHAR number[100];
141 _stprintf(number, _T("%.3lf"), widthSetInDlg * 100.0 / fileHPPM);
142 SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, number);
143 _stprintf(number, _T("%.3lf"), heightSetInDlg * 100.0 / fileVPPM);
144 SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, number);
145 break;
146 }
147 case IDD_ATTRIBUTESRB3:
148 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT1, widthSetInDlg, FALSE);
149 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT2, heightSetInDlg, FALSE);
150 break;
151 case IDD_ATTRIBUTESEDIT1:
152 if (Edit_GetModify((HWND)lParam))
153 {
154 TCHAR tempS[100];
155 if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB1))
156 {
157 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, tempS, SIZEOF(tempS));
158 widthSetInDlg = max(1, (int) (_tcstod(tempS, NULL) * fileHPPM * 0.0254));
159 }
160 else if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB2))
161 {
162 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, tempS, SIZEOF(tempS));
163 widthSetInDlg = max(1, (int) (_tcstod(tempS, NULL) * fileHPPM / 100));
164 }
165 else if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB3))
166 {
167 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, tempS, SIZEOF(tempS));
168 widthSetInDlg = max(1, _tstoi(tempS));
169 }
170 Edit_SetModify((HWND)lParam, FALSE);
171 }
172 break;
173 case IDD_ATTRIBUTESEDIT2:
174 if (Edit_GetModify((HWND)lParam))
175 {
176 TCHAR tempS[100];
177 if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB1))
178 {
179 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, tempS, SIZEOF(tempS));
180 heightSetInDlg = max(1, (int) (_tcstod(tempS, NULL) * fileVPPM * 0.0254));
181 }
182 else if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB2))
183 {
184 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, tempS, SIZEOF(tempS));
185 heightSetInDlg = max(1, (int) (_tcstod(tempS, NULL) * fileVPPM / 100));
186 }
187 else if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB3))
188 {
189 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, tempS, SIZEOF(tempS));
190 heightSetInDlg = max(1, _tstoi(tempS));
191 }
192 Edit_SetModify((HWND)lParam, FALSE);
193 }
194 break;
195 }
196 break;
197 default:
198 return FALSE;
199 }
200 return TRUE;
201 }
202
203 int
204 attributesDlg()
205 {
206 return DialogBox(hProgInstance, MAKEINTRESOURCE(IDD_ATTRIBUTES), hMainWnd, (DLGPROC) ATTDlgWinProc);
207 }
208
209 LRESULT CALLBACK
210 CHSIZEDlgWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
211 {
212 switch (message)
213 {
214 case WM_INITDIALOG:
215 SetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITHSTRETCH, 100, FALSE);
216 SetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITVSTRETCH, 100, FALSE);
217 SetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITHSKEW, 0, FALSE);
218 SetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITVSKEW, 0, FALSE);
219 return TRUE;
220 case WM_CLOSE:
221 EndDialog(hwnd, 0);
222 break;
223 case WM_COMMAND:
224 switch (LOWORD(wParam))
225 {
226 case IDOK:
227 {
228 TCHAR strrcIntNumbers[100];
229 TCHAR strrcPercentage[100];
230 TCHAR strrcAngle[100];
231 BOOL tr1, tr2, tr3, tr4;
232
233 LoadString(hProgInstance, IDS_INTNUMBERS, strrcIntNumbers, SIZEOF(strrcIntNumbers));
234 LoadString(hProgInstance, IDS_PERCENTAGE, strrcPercentage, SIZEOF(strrcPercentage));
235 LoadString(hProgInstance, IDS_ANGLE, strrcAngle, SIZEOF(strrcAngle));
236
237 stretchSkew.percentage.x = GetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITHSTRETCH, &tr1, FALSE);
238 stretchSkew.percentage.y = GetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITVSTRETCH, &tr2, FALSE);
239 stretchSkew.angle.x = GetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITHSKEW, &tr3, TRUE);
240 stretchSkew.angle.y = GetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITVSKEW, &tr4, TRUE);
241
242 if (!(tr1 && tr2 && tr3 && tr4))
243 MessageBox(hwnd, strrcIntNumbers, NULL, MB_ICONEXCLAMATION);
244 else if (stretchSkew.percentage.x < 1 || stretchSkew.percentage.x > 500
245 || stretchSkew.percentage.y < 1 || stretchSkew.percentage.y > 500)
246 MessageBox(hwnd, strrcPercentage, NULL, MB_ICONEXCLAMATION);
247 else if (stretchSkew.angle.x < -89 || stretchSkew.angle.x > 89
248 || stretchSkew.angle.y < -89 || stretchSkew.angle.y > 89)
249 MessageBox(hwnd, strrcAngle, NULL, MB_ICONEXCLAMATION);
250 else
251 EndDialog(hwnd, 1);
252
253 break;
254 }
255 case IDCANCEL:
256 EndDialog(hwnd, 0);
257 break;
258 }
259 break;
260 default:
261 return FALSE;
262 }
263 return TRUE;
264 }
265
266 int
267 changeSizeDlg()
268 {
269 return DialogBox(hProgInstance, MAKEINTRESOURCE(IDD_STRETCHSKEW), hMainWnd, (DLGPROC) CHSIZEDlgWinProc);
270 }