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