/
prop.c
370 lines (318 loc) · 7.1 KB
/
prop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/*
* prop.c
*
* (C) Copyright 1999-2005 Jan van den Baard.
* All Rights Reserved.
*/
#include "defs.h"
/*
* File types.
*/
static LPCTSTR lpszFileModes[] =
{
_T("MS DOS"), _T("Unix"), _T("Macintosh")
};
static void SetSizeControls( HWND hDlg )
{
LPCLASSDATA lpcd = ( LPCLASSDATA )GetWindowLong( hDlg, DWL_USER );
TCHAR szBuffer[ 256 ];
SHFILEINFO psfi;
int nLines = ArrayGetSize( lpcd->lpLines ), i, nFileMode;
unsigned int nBytes = 0, nLineTerm = 1;
/*
* Get system file type.
*/
SHGetFileInfo( lpcd->szFileName, 0, &psfi, sizeof( SHFILEINFO ), SHGFI_USEFILEATTRIBUTES | SHGFI_TYPENAME );
SetDlgItemText( hDlg, IDC_PROP_SYSTYPE, psfi.szTypeName[ 0 ] ? psfi.szTypeName : GetString( IDS_NO_TYPENAME ));
/*
* Setup language name.
*/
SetDlgItemText( hDlg, IDC_PROP_LANGUAGE, Parser->pszTitle );
/*
* Setup tab-size.
*/
SetDlgItemInt( hDlg, IDC_PROP_TABSIZE, Parser->nTabSize, FALSE );
/*
* Setup icon.
*/
SendDlgItemMessage( hDlg, IDC_PROP_ICON, STM_SETICON, ( WPARAM )lpcd->hIconLarge, 0 );
/*
* Setup file mode.
*/
SendDlgItemMessage( hDlg, IDC_PROP_TYPE, CB_SETCURSEL, Parser->nFileMode, 0 );
/*
* Get file mode.
*/
nFileMode = SendDlgItemMessage( hDlg, IDC_PROP_TYPE, CB_GETCURSEL, 0, 0 );
/*
* Compute size of the
* line terminator.
*/
if ( nFileMode == FMODE_MSDOS || nFileMode == FMODE_UNIX )
nLineTerm = 2;
/*
* Compute the file size
* in bytes.
*/
for ( i = 0; i < nLines; i++ )
{
/*
* Add line length.
*/
nBytes += (( LPLINE )ArrayGetAt( lpcd->lpLines, i ))->nLength;
/*
* Add line terminator bytes
* if this is not the last line.
*/
if ( i < nLines - 1 )
nBytes += nLineTerm;
}
/*
* Format and set size string.
*/
_stprintf_s( szBuffer, 256, GetString( IDS_FILE_SIZE ), nBytes, nLines );
SetDlgItemText( hDlg, IDC_PROP_SIZE, szBuffer );
}
/*
* Default data.
*/
int nFileMode, nTabSize;
static LRESULT CALLBACK PropProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
case WM_INITDIALOG:
{
LPCLASSDATA lpcd = ( LPCLASSDATA )lParam;
HDC hDC;
RECT rcClient;
HWND hControl;
HFONT hFont, hOFont;
TCHAR szBuffer[ MAX_PATH ];
int i;
/*
* Save data.
*/
nFileMode = Parser->nFileMode;
nTabSize = Parser->nTabSize;
/*
* Setup class data pointer as
* the dialog user data.
*/
SetWindowLong( hDlg, DWL_USER, ( LONG )lpcd );
/*
* Get handle to the file name control.
*/
hControl = GetDlgItem( hDlg, IDC_PROP_FILENAME );
/*
* Copy the file name into
* a buffer.
*/
_tcsncpy_s( szBuffer, MAX_PATH, lpcd->szFileName, MAX_PATH );
/*
* Get the client rectangle of
* the file name control.
*/
GetClientRect( hControl, &rcClient );
/*
* Get the device context.
*/
if (( hDC = GetDC( hControl )) != NULL )
{
/*
* Get the dialog font.
*/
if (( hFont = ( HFONT )SendMessage( hDlg, WM_GETFONT, 0, 0 )) != NULL )
{
/*
* Make sure we use the correct font.
*/
hOFont = SelectObject( hDC, hFont );
/*
* Compact the path.
*/
PathCompactPath( hDC, szBuffer, rcClient.right );
/*
* Reset the font.
*/
SelectObject( hDC, hOFont );
}
/*
* Release the device context.
*/
ReleaseDC( hControl, hDC );
}
/*
* Set the path.
*/
SetWindowText( hControl, szBuffer );
/*
* Unicode?
*/
SetDlgItemText( hDlg, IDC_PROP_UNICODE, GetString( lpcd->bUnicode ? IDS_TRUE : IDS_FALSE ));
/*
* Setup the up/down range
* and the tab stop.
*/
SendDlgItemMessage( hDlg, IDC_PROP_TABSPIN, UDM_SETRANGE, 0, MAKELPARAM( 24,2 ));
/*
* Setup file modes.
*/
for ( i = FMODE_MSDOS; i <= FMODE_MACINTOSH; i++ )
SendDlgItemMessage( hDlg, IDC_PROP_TYPE, CB_ADDSTRING, 0, ( LPARAM )lpszFileModes[ i ] );
/*
* Setup the file size and the
* tab size controls.
*/
SetSizeControls( hDlg );
/*
* Valid file date?
*/
if ( lpcd->ftFileTime.dwHighDateTime == 0 && lpcd->ftFileTime.dwLowDateTime == 0 )
SetDlgItemText( hDlg, IDC_PROP_DATE, GetString( IDS_NOT_SAVED ));
else
{
FILETIME ft;
SYSTEMTIME st;
/*
* Convert file time to
* system time.
*/
FileTimeToLocalFileTime( &lpcd->ftFileTime, &ft );
FileTimeToSystemTime( &ft, &st );
/*
* Format time.
*/
GetTimeFormat( LOCALE_USER_DEFAULT,
0, //LOCALE_NOUSEROVERRIDE,
&st,
NULL,
szBuffer,
256 );
/*
* Add space.
*/
_tcscat_s( szBuffer, MAX_PATH, _T(" "));
/*
* Format date.
*/
GetDateFormat( LOCALE_USER_DEFAULT,
0, //LOCALE_NOUSEROVERRIDE,
&st,
NULL,
&szBuffer[ _tcslen( szBuffer ) ],
256 - _tcslen( szBuffer ));
/*
* Output result.
*/
SetDlgItemText( hDlg, IDC_PROP_DATE, szBuffer );
}
/*
* Focus the OK button.
*/
return TRUE;
}
case WM_CLOSE:
/*
* Bye...
*/
EndDialog( hDlg, 0 );
break;
case WM_COMMAND:
{
LPCLASSDATA lpcd = ( LPCLASSDATA )GetWindowLong( hDlg, DWL_USER );
switch ( LOWORD( wParam ))
{
case IDC_PROP_TYPE:
/*
* Get file mode.
*/
Parser->nFileMode = SendDlgItemMessage( hDlg, IDC_PROP_TYPE, CB_GETCURSEL, 0, 0 );
/*
* Send status message.
*/
SendStatusMessage( lpcd );
break;
case IDC_PROP_TABSIZE:
{
/*
* Lost focus on the edit control?
*/
if ( HIWORD( wParam ) == EN_KILLFOCUS )
{
/*
* Get value.
*/
int nTabStop = GetDlgItemInt( hDlg, IDC_PROP_TABSIZE, NULL, FALSE );
/*
* Clamp entered value between 2 and 24.
*/
if ( nTabStop < 2 ) nTabStop = 2;
else if ( nTabStop > 24 ) nTabStop = 24;
/*
* Set this value to the
* edit control.
*/
SetDlgItemInt( hDlg, IDC_PROP_TABSIZE, ( UINT )nTabStop, FALSE );
/*
* Save tab value.
*/
Parser->nTabSize = nTabStop;
/*
* Re-render if it changed...
*/
if ( nTabStop != nTabSize )
InvalidateRect( lpcd->hWnd, NULL, FALSE );
}
break;
}
case IDCANCEL:
/*
* Reset tabsize.
*/
if ( Parser->nTabSize != nTabSize )
{
Parser->nTabSize = nTabSize;
InvalidateRect( lpcd->hWnd, NULL, FALSE );
}
/*
* And file mode.
*/
if ( Parser->nFileMode != nFileMode )
{
Parser->nFileMode = nFileMode;
SendStatusMessage( lpcd );
}
/*
* Fall through...
*/
case IDOK:
/*
* Bye...
*/
EndDialog( hDlg, 0 );
break;
}
}
}
return 0;
}
void PropertiesDialog( LPCLASSDATA lpcd )
{
/*
* Clear qualifiers.
*/
lpcd->cQualifier = 0;
/*
* Popup the dialog.
*/
DialogBoxParam( hDLL, MAKEINTRESOURCE( IDD_PROPERTIES ), lpcd->hWnd, PropProc, ( LPARAM )lpcd );
}
LRESULT OnPropDialog( HWND hWnd, WPARAM wParam, LPARAM lParam, LPCLASSDATA lpcd )
{
/*
* Popup the properties dialog.
*/
PropertiesDialog( lpcd );
return 0;
}