[RAPPS]
[reactos.git] / reactos / base / applications / mspaint / dialogs.cpp
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/mspaint/dialogs.cpp
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 INT_PTR 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), mainWindow.m_hWnd, MRDlgWinProc);
70 }
71
72 INT_PTR CALLBACK
73 ATTDlgWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
74 {
75 switch (message)
76 {
77 case WM_INITDIALOG:
78 {
79 widthSetInDlg = imageModel.GetWidth();
80 heightSetInDlg = imageModel.GetHeight();
81
82 CheckDlgButton(hwnd, IDD_ATTRIBUTESRB3, BST_CHECKED);
83 CheckDlgButton(hwnd, IDD_ATTRIBUTESRB5, BST_CHECKED);
84 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT1, widthSetInDlg, FALSE);
85 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT2, heightSetInDlg, FALSE);
86
87 if (isAFile)
88 {
89 TCHAR date[100];
90 TCHAR temp[100];
91 GetDateFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, date, SIZEOF(date));
92 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, temp, SIZEOF(temp));
93 _tcscat(date, _T(" "));
94 _tcscat(date, temp);
95 CString strSize;
96 strSize.Format(IDS_FILESIZE, fileSize);
97 SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT6, date);
98 SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT7, strSize);
99 }
100 CString strRes;
101 strRes.Format(IDS_PRINTRES, fileHPPM, fileVPPM);
102 SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT8, strRes);
103 return TRUE;
104 }
105 case WM_CLOSE:
106 EndDialog(hwnd, 0);
107 break;
108 case WM_COMMAND:
109 switch (LOWORD(wParam))
110 {
111 case IDOK:
112 EndDialog(hwnd, 1);
113 break;
114 case IDCANCEL:
115 EndDialog(hwnd, 0);
116 break;
117 case IDD_ATTRIBUTESSTANDARD:
118 widthSetInDlg = imageModel.GetWidth();
119 heightSetInDlg = imageModel.GetHeight();
120 CheckDlgButton(hwnd, IDD_ATTRIBUTESRB3, BST_CHECKED);
121 CheckDlgButton(hwnd, IDD_ATTRIBUTESRB5, BST_CHECKED);
122 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT1, widthSetInDlg, FALSE);
123 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT2, heightSetInDlg, FALSE);
124 break;
125 case IDD_ATTRIBUTESRB1:
126 {
127 CString strNum;
128 strNum.Format(_T("%.3lf"), widthSetInDlg / (0.0254 * fileHPPM));
129 SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, strNum);
130 strNum.Format(_T("%.3lf"), heightSetInDlg / (0.0254 * fileVPPM));
131 SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, strNum);
132 break;
133 }
134 case IDD_ATTRIBUTESRB2:
135 {
136 CString strNum;
137 strNum.Format(_T("%.3lf"), widthSetInDlg * 100.0 / fileHPPM);
138 SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, strNum);
139 strNum.Format(_T("%.3lf"), heightSetInDlg * 100.0 / fileVPPM);
140 SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, strNum);
141 break;
142 }
143 case IDD_ATTRIBUTESRB3:
144 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT1, widthSetInDlg, FALSE);
145 SetDlgItemInt(hwnd, IDD_ATTRIBUTESEDIT2, heightSetInDlg, FALSE);
146 break;
147 case IDD_ATTRIBUTESEDIT1:
148 if (Edit_GetModify((HWND)lParam))
149 {
150 TCHAR tempS[100];
151 if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB1))
152 {
153 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, tempS, SIZEOF(tempS));
154 widthSetInDlg = max(1, (int) (_tcstod(tempS, NULL) * fileHPPM * 0.0254));
155 }
156 else if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB2))
157 {
158 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, tempS, SIZEOF(tempS));
159 widthSetInDlg = max(1, (int) (_tcstod(tempS, NULL) * fileHPPM / 100));
160 }
161 else if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB3))
162 {
163 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, tempS, SIZEOF(tempS));
164 widthSetInDlg = max(1, _tstoi(tempS));
165 }
166 Edit_SetModify((HWND)lParam, FALSE);
167 }
168 break;
169 case IDD_ATTRIBUTESEDIT2:
170 if (Edit_GetModify((HWND)lParam))
171 {
172 TCHAR tempS[100];
173 if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB1))
174 {
175 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, tempS, SIZEOF(tempS));
176 heightSetInDlg = max(1, (int) (_tcstod(tempS, NULL) * fileVPPM * 0.0254));
177 }
178 else if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB2))
179 {
180 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, tempS, SIZEOF(tempS));
181 heightSetInDlg = max(1, (int) (_tcstod(tempS, NULL) * fileVPPM / 100));
182 }
183 else if (IsDlgButtonChecked(hwnd, IDD_ATTRIBUTESRB3))
184 {
185 GetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, tempS, SIZEOF(tempS));
186 heightSetInDlg = max(1, _tstoi(tempS));
187 }
188 Edit_SetModify((HWND)lParam, FALSE);
189 }
190 break;
191 }
192 break;
193 default:
194 return FALSE;
195 }
196 return TRUE;
197 }
198
199 int
200 attributesDlg()
201 {
202 return DialogBox(hProgInstance, MAKEINTRESOURCE(IDD_ATTRIBUTES), mainWindow.m_hWnd, ATTDlgWinProc);
203 }
204
205 INT_PTR CALLBACK
206 CHSIZEDlgWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
207 {
208 switch (message)
209 {
210 case WM_INITDIALOG:
211 SetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITHSTRETCH, 100, FALSE);
212 SetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITVSTRETCH, 100, FALSE);
213 SetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITHSKEW, 0, FALSE);
214 SetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITVSKEW, 0, FALSE);
215 return TRUE;
216 case WM_CLOSE:
217 EndDialog(hwnd, 0);
218 break;
219 case WM_COMMAND:
220 switch (LOWORD(wParam))
221 {
222 case IDOK:
223 {
224 TCHAR strrcIntNumbers[100];
225 TCHAR strrcPercentage[100];
226 TCHAR strrcAngle[100];
227 BOOL tr1, tr2, tr3, tr4;
228
229 LoadString(hProgInstance, IDS_INTNUMBERS, strrcIntNumbers, SIZEOF(strrcIntNumbers));
230 LoadString(hProgInstance, IDS_PERCENTAGE, strrcPercentage, SIZEOF(strrcPercentage));
231 LoadString(hProgInstance, IDS_ANGLE, strrcAngle, SIZEOF(strrcAngle));
232
233 stretchSkew.percentage.x = GetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITHSTRETCH, &tr1, FALSE);
234 stretchSkew.percentage.y = GetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITVSTRETCH, &tr2, FALSE);
235 stretchSkew.angle.x = GetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITHSKEW, &tr3, TRUE);
236 stretchSkew.angle.y = GetDlgItemInt(hwnd, IDD_STRETCHSKEWEDITVSKEW, &tr4, TRUE);
237
238 if (!(tr1 && tr2 && tr3 && tr4))
239 MessageBox(hwnd, strrcIntNumbers, NULL, MB_ICONEXCLAMATION);
240 else if (stretchSkew.percentage.x < 1 || stretchSkew.percentage.x > 500
241 || stretchSkew.percentage.y < 1 || stretchSkew.percentage.y > 500)
242 MessageBox(hwnd, strrcPercentage, NULL, MB_ICONEXCLAMATION);
243 else if (stretchSkew.angle.x < -89 || stretchSkew.angle.x > 89
244 || stretchSkew.angle.y < -89 || stretchSkew.angle.y > 89)
245 MessageBox(hwnd, strrcAngle, NULL, MB_ICONEXCLAMATION);
246 else
247 EndDialog(hwnd, 1);
248
249 break;
250 }
251 case IDCANCEL:
252 EndDialog(hwnd, 0);
253 break;
254 }
255 break;
256 default:
257 return FALSE;
258 }
259 return TRUE;
260 }
261
262 int
263 changeSizeDlg()
264 {
265 return DialogBox(hProgInstance, MAKEINTRESOURCE(IDD_STRETCHSKEW), mainWindow.m_hWnd, CHSIZEDlgWinProc);
266 }