Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/programs/notepad/dialog.c
4387 views
1
/*
2
* Notepad (dialog.c)
3
*
4
* Copyright 1998,99 Marcel Baur <[email protected]>
5
* Copyright 2002 Sylvain Petreolle <[email protected]>
6
* Copyright 2002 Andriy Palamarchuk
7
* Copyright 2007 Rolf Kalbermatter
8
* Copyright 2010 Vitaly Perov
9
*
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2.1 of the License, or (at your option) any later version.
14
*
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Lesser General Public License for more details.
19
*
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with this library; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23
*/
24
25
#include <assert.h>
26
#include <stdio.h>
27
#include <windows.h>
28
#include <shellapi.h>
29
#include <commdlg.h>
30
#include <commctrl.h>
31
#include <shlwapi.h>
32
#include <winternl.h>
33
34
#include "main.h"
35
#include "dialog.h"
36
37
#define SPACES_IN_TAB 8
38
#define PRINT_LEN_MAX 500
39
40
static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
41
42
/* Swap bytes of WCHAR buffer (big-endian <-> little-endian). */
43
static inline void byteswap_wide_string(LPWSTR str, UINT num)
44
{
45
UINT i;
46
for (i = 0; i < num; i++) str[i] = RtlUshortByteSwap(str[i]);
47
}
48
49
static void load_encoding_name(ENCODING enc, WCHAR* buffer, int length)
50
{
51
switch (enc)
52
{
53
case ENCODING_UTF16LE:
54
LoadStringW(Globals.hInstance, STRING_UNICODE_LE, buffer, length);
55
break;
56
57
case ENCODING_UTF16BE:
58
LoadStringW(Globals.hInstance, STRING_UNICODE_BE, buffer, length);
59
break;
60
61
case ENCODING_UTF8:
62
LoadStringW(Globals.hInstance, STRING_UTF8, buffer, length);
63
break;
64
65
case ENCODING_ANSI:
66
{
67
CPINFOEXW cpi;
68
GetCPInfoExW(CP_ACP, 0, &cpi);
69
lstrcpynW(buffer, cpi.CodePageName, length);
70
break;
71
}
72
73
default:
74
assert(0 && "bad encoding in load_encoding_name");
75
break;
76
}
77
}
78
79
VOID ShowLastError(void)
80
{
81
DWORD error = GetLastError();
82
if (error != NO_ERROR)
83
{
84
LPWSTR lpMsgBuf;
85
WCHAR szTitle[MAX_STRING_LEN];
86
87
LoadStringW(Globals.hInstance, STRING_ERROR, szTitle, ARRAY_SIZE(szTitle));
88
FormatMessageW(
89
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
90
NULL, error, 0, (LPWSTR)&lpMsgBuf, 0, NULL);
91
MessageBoxW(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
92
LocalFree(lpMsgBuf);
93
}
94
}
95
96
/**
97
* Sets the caption of the main window according to Globals.szFileTitle:
98
* Untitled - Notepad if no file is open
99
* filename - Notepad if a file is given
100
*/
101
void UpdateWindowCaption(void)
102
{
103
WCHAR szNotepad[64];
104
WCHAR szCaption[ARRAY_SIZE(Globals.szFileTitle) + ARRAY_SIZE(L" - ") + ARRAY_SIZE(szNotepad)];
105
106
if (Globals.szFileTitle[0] != '\0')
107
lstrcpyW(szCaption, Globals.szFileTitle);
108
else
109
LoadStringW(Globals.hInstance, STRING_UNTITLED, szCaption, ARRAY_SIZE(szCaption));
110
111
LoadStringW(Globals.hInstance, STRING_NOTEPAD, szNotepad, ARRAY_SIZE(szNotepad));
112
lstrcatW(szCaption, L" - ");
113
lstrcatW(szCaption, szNotepad);
114
115
SetWindowTextW(Globals.hMainWnd, szCaption);
116
}
117
118
int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCWSTR szString, DWORD dwFlags)
119
{
120
WCHAR szMessage[MAX_STRING_LEN];
121
WCHAR szResource[MAX_STRING_LEN];
122
123
/* Load and format szMessage */
124
LoadStringW(Globals.hInstance, formatId, szResource, ARRAY_SIZE(szResource));
125
wnsprintfW(szMessage, ARRAY_SIZE(szMessage), szResource, szString);
126
127
/* Load szCaption */
128
if ((dwFlags & MB_ICONMASK) == MB_ICONEXCLAMATION)
129
LoadStringW(Globals.hInstance, STRING_ERROR, szResource, ARRAY_SIZE(szResource));
130
else
131
LoadStringW(Globals.hInstance, STRING_NOTEPAD, szResource, ARRAY_SIZE(szResource));
132
133
/* Display Modal Dialog */
134
if (hParent == NULL)
135
hParent = Globals.hMainWnd;
136
return MessageBoxW(hParent, szMessage, szResource, dwFlags);
137
}
138
139
static void AlertFileNotFound(LPCWSTR szFileName)
140
{
141
DIALOG_StringMsgBox(NULL, STRING_NOTFOUND, szFileName, MB_ICONEXCLAMATION|MB_OK);
142
}
143
144
static int AlertFileNotSaved(LPCWSTR szFileName)
145
{
146
WCHAR szUntitled[MAX_STRING_LEN];
147
148
LoadStringW(Globals.hInstance, STRING_UNTITLED, szUntitled, ARRAY_SIZE(szUntitled));
149
return DIALOG_StringMsgBox(NULL, STRING_NOTSAVED, szFileName[0] ? szFileName : szUntitled,
150
MB_ICONQUESTION|MB_YESNOCANCEL);
151
}
152
153
static int AlertUnicodeCharactersLost(LPCWSTR szFileName)
154
{
155
WCHAR szCaption[MAX_STRING_LEN];
156
WCHAR szMsgFormat[MAX_STRING_LEN];
157
WCHAR szEnc[MAX_STRING_LEN];
158
WCHAR* szMsg;
159
DWORD_PTR args[2];
160
int rc;
161
162
LoadStringW(Globals.hInstance, STRING_NOTEPAD, szCaption,
163
ARRAY_SIZE(szCaption));
164
LoadStringW(Globals.hInstance, STRING_LOSS_OF_UNICODE_CHARACTERS,
165
szMsgFormat, ARRAY_SIZE(szMsgFormat));
166
load_encoding_name(ENCODING_ANSI, szEnc, ARRAY_SIZE(szEnc));
167
args[0] = (DWORD_PTR)szFileName;
168
args[1] = (DWORD_PTR)szEnc;
169
FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_ARGUMENT_ARRAY, szMsgFormat, 0, 0, (LPWSTR)&szMsg, 0, (va_list *)args);
170
rc = MessageBoxW(Globals.hMainWnd, szMsg, szCaption,
171
MB_OKCANCEL|MB_ICONEXCLAMATION);
172
LocalFree(szMsg);
173
return rc;
174
}
175
176
/**
177
* Returns:
178
* TRUE - if file exists
179
* FALSE - if file does not exist
180
*/
181
BOOL FileExists(LPCWSTR szFilename)
182
{
183
WIN32_FIND_DATAW entry;
184
HANDLE hFile;
185
186
hFile = FindFirstFileW(szFilename, &entry);
187
FindClose(hFile);
188
189
return (hFile != INVALID_HANDLE_VALUE);
190
}
191
192
static inline BOOL is_conversion_to_ansi_lossy(LPCWSTR textW, int lenW)
193
{
194
BOOL ret = FALSE;
195
WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, textW, lenW, NULL, 0,
196
NULL, &ret);
197
return ret;
198
}
199
200
typedef enum
201
{
202
SAVED_OK,
203
SAVE_FAILED,
204
SHOW_SAVEAS_DIALOG
205
} SAVE_STATUS;
206
207
/* szFileName is the filename to save under; enc is the encoding to use.
208
*
209
* If the function succeeds, it returns SAVED_OK.
210
* If the function fails, it returns SAVE_FAILED.
211
* If Unicode data could be lost due to conversion to a non-Unicode character
212
* set, a warning is displayed. The user can continue (and the function carries
213
* on), or cancel (and the function returns SHOW_SAVEAS_DIALOG).
214
*/
215
static SAVE_STATUS DoSaveFile(LPCWSTR szFileName, ENCODING enc)
216
{
217
int lenW;
218
WCHAR* textW;
219
HANDLE hFile;
220
DWORD dwNumWrite;
221
PVOID pBytes;
222
DWORD size;
223
224
/* lenW includes the byte-order mark, but not the \0. */
225
lenW = GetWindowTextLengthW(Globals.hEdit) + 1;
226
textW = HeapAlloc(GetProcessHeap(), 0, (lenW+1) * sizeof(WCHAR));
227
if (!textW)
228
{
229
ShowLastError();
230
return SAVE_FAILED;
231
}
232
textW[0] = (WCHAR) 0xfeff;
233
lenW = GetWindowTextW(Globals.hEdit, textW+1, lenW) + 1;
234
235
switch (enc)
236
{
237
case ENCODING_UTF16BE:
238
byteswap_wide_string(textW, lenW);
239
/* fall through */
240
241
case ENCODING_UTF16LE:
242
size = lenW * sizeof(WCHAR);
243
pBytes = textW;
244
break;
245
246
case ENCODING_UTF8:
247
size = WideCharToMultiByte(CP_UTF8, 0, textW, lenW, NULL, 0, NULL, NULL);
248
pBytes = HeapAlloc(GetProcessHeap(), 0, size);
249
if (!pBytes)
250
{
251
ShowLastError();
252
HeapFree(GetProcessHeap(), 0, textW);
253
return SAVE_FAILED;
254
}
255
WideCharToMultiByte(CP_UTF8, 0, textW, lenW, pBytes, size, NULL, NULL);
256
HeapFree(GetProcessHeap(), 0, textW);
257
break;
258
259
default:
260
if (is_conversion_to_ansi_lossy(textW+1, lenW-1)
261
&& AlertUnicodeCharactersLost(szFileName) == IDCANCEL)
262
{
263
HeapFree(GetProcessHeap(), 0, textW);
264
return SHOW_SAVEAS_DIALOG;
265
}
266
267
size = WideCharToMultiByte(CP_ACP, 0, textW+1, lenW-1, NULL, 0, NULL, NULL);
268
pBytes = HeapAlloc(GetProcessHeap(), 0, size);
269
if (!pBytes)
270
{
271
ShowLastError();
272
HeapFree(GetProcessHeap(), 0, textW);
273
return SAVE_FAILED;
274
}
275
WideCharToMultiByte(CP_ACP, 0, textW+1, lenW-1, pBytes, size, NULL, NULL);
276
HeapFree(GetProcessHeap(), 0, textW);
277
break;
278
}
279
280
hFile = CreateFileW(szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
281
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
282
if(hFile == INVALID_HANDLE_VALUE)
283
{
284
ShowLastError();
285
HeapFree(GetProcessHeap(), 0, pBytes);
286
return SAVE_FAILED;
287
}
288
if (!WriteFile(hFile, pBytes, size, &dwNumWrite, NULL))
289
{
290
ShowLastError();
291
CloseHandle(hFile);
292
HeapFree(GetProcessHeap(), 0, pBytes);
293
return SAVE_FAILED;
294
}
295
SetEndOfFile(hFile);
296
CloseHandle(hFile);
297
HeapFree(GetProcessHeap(), 0, pBytes);
298
299
SendMessageW(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
300
return SAVED_OK;
301
}
302
303
/**
304
* Returns:
305
* TRUE - User agreed to close (both save/don't save)
306
* FALSE - User cancelled close by selecting "Cancel"
307
*/
308
BOOL DoCloseFile(void)
309
{
310
int nResult;
311
312
nResult=GetWindowTextLengthW(Globals.hEdit);
313
if (SendMessageW(Globals.hEdit, EM_GETMODIFY, 0, 0) &&
314
(nResult || Globals.szFileName[0]))
315
{
316
/* prompt user to save changes */
317
nResult = AlertFileNotSaved(Globals.szFileName);
318
switch (nResult) {
319
case IDYES: return DIALOG_FileSave();
320
321
case IDNO: break;
322
323
case IDCANCEL: return(FALSE);
324
325
default: return(FALSE);
326
} /* switch */
327
} /* if */
328
329
SetFileNameAndEncoding(L"", ENCODING_ANSI);
330
331
UpdateWindowCaption();
332
return(TRUE);
333
}
334
335
static inline ENCODING detect_encoding_of_buffer(const void* buffer, int size)
336
{
337
static const char bom_utf8[] = { 0xef, 0xbb, 0xbf };
338
if (size >= sizeof(bom_utf8) && !memcmp(buffer, bom_utf8, sizeof(bom_utf8)))
339
return ENCODING_UTF8;
340
else
341
{
342
int flags = IS_TEXT_UNICODE_SIGNATURE |
343
IS_TEXT_UNICODE_REVERSE_SIGNATURE |
344
IS_TEXT_UNICODE_ODD_LENGTH;
345
IsTextUnicode(buffer, size, &flags);
346
if (flags & IS_TEXT_UNICODE_SIGNATURE)
347
return ENCODING_UTF16LE;
348
else if (flags & IS_TEXT_UNICODE_REVERSE_SIGNATURE)
349
return ENCODING_UTF16BE;
350
else
351
return ENCODING_ANSI;
352
}
353
}
354
355
void DoOpenFile(LPCWSTR szFileName, ENCODING enc)
356
{
357
HANDLE hFile;
358
LPSTR pTemp;
359
DWORD size;
360
DWORD dwNumRead;
361
int lenW;
362
WCHAR* textW;
363
int i;
364
WCHAR log[5];
365
366
/* Close any files and prompt to save changes */
367
if (!DoCloseFile())
368
return;
369
370
hFile = CreateFileW(szFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
371
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
372
if(hFile == INVALID_HANDLE_VALUE)
373
{
374
AlertFileNotFound(szFileName);
375
return;
376
}
377
378
size = GetFileSize(hFile, NULL);
379
if (size == INVALID_FILE_SIZE)
380
{
381
CloseHandle(hFile);
382
ShowLastError();
383
return;
384
}
385
386
/* Extra memory for (WCHAR)'\0'-termination. */
387
pTemp = HeapAlloc(GetProcessHeap(), 0, size+2);
388
if (!pTemp)
389
{
390
CloseHandle(hFile);
391
ShowLastError();
392
return;
393
}
394
395
if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
396
{
397
CloseHandle(hFile);
398
HeapFree(GetProcessHeap(), 0, pTemp);
399
ShowLastError();
400
return;
401
}
402
403
CloseHandle(hFile);
404
405
size = dwNumRead;
406
407
if (enc == ENCODING_AUTO)
408
enc = detect_encoding_of_buffer(pTemp, size);
409
else if (size >= 2 && (enc==ENCODING_UTF16LE || enc==ENCODING_UTF16BE))
410
{
411
/* If UTF-16 (BE or LE) is selected, and there is a UTF-16 BOM,
412
* override the selection (like native Notepad).
413
*/
414
if ((BYTE)pTemp[0] == 0xff && (BYTE)pTemp[1] == 0xfe)
415
enc = ENCODING_UTF16LE;
416
else if ((BYTE)pTemp[0] == 0xfe && (BYTE)pTemp[1] == 0xff)
417
enc = ENCODING_UTF16BE;
418
}
419
420
switch (enc)
421
{
422
case ENCODING_UTF16BE:
423
byteswap_wide_string((WCHAR*) pTemp, size/sizeof(WCHAR));
424
/* Forget whether the file is BE or LE, like native Notepad. */
425
enc = ENCODING_UTF16LE;
426
427
/* fall through */
428
429
case ENCODING_UTF16LE:
430
textW = (LPWSTR)pTemp;
431
lenW = size/sizeof(WCHAR);
432
break;
433
434
default:
435
{
436
int cp = (enc==ENCODING_UTF8) ? CP_UTF8 : CP_ACP;
437
lenW = MultiByteToWideChar(cp, 0, pTemp, size, NULL, 0);
438
textW = HeapAlloc(GetProcessHeap(), 0, (lenW+1) * sizeof(WCHAR));
439
if (!textW)
440
{
441
ShowLastError();
442
HeapFree(GetProcessHeap(), 0, pTemp);
443
return;
444
}
445
MultiByteToWideChar(cp, 0, pTemp, size, textW, lenW);
446
HeapFree(GetProcessHeap(), 0, pTemp);
447
break;
448
}
449
}
450
451
/* Replace '\0's with spaces. Other than creating a custom control that
452
* can deal with '\0' characters, it's the best that can be done.
453
*/
454
for (i = 0; i < lenW; i++)
455
if (textW[i] == '\0')
456
textW[i] = ' ';
457
textW[lenW] = '\0';
458
459
if (lenW >= 1 && textW[0] == 0xfeff)
460
SetWindowTextW(Globals.hEdit, textW+1);
461
else
462
SetWindowTextW(Globals.hEdit, textW);
463
464
HeapFree(GetProcessHeap(), 0, textW);
465
466
SendMessageW(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
467
SendMessageW(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
468
SetFocus(Globals.hEdit);
469
470
/* If the file starts with .LOG, add a time/date at the end and set cursor after */
471
if (GetWindowTextW(Globals.hEdit, log, ARRAY_SIZE(log)) && !lstrcmpW(log, L".LOG"))
472
{
473
SendMessageW(Globals.hEdit, EM_SETSEL, GetWindowTextLengthW(Globals.hEdit), -1);
474
SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)L"\r\n");
475
DIALOG_EditTimeDate();
476
SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)L"\r\n");
477
}
478
479
SetFileNameAndEncoding(szFileName, enc);
480
UpdateWindowCaption();
481
}
482
483
VOID DIALOG_FileNew(VOID)
484
{
485
/* Close any files and prompt to save changes */
486
if (DoCloseFile()) {
487
SetWindowTextW(Globals.hEdit, L"");
488
SendMessageW(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
489
SetFocus(Globals.hEdit);
490
}
491
}
492
493
/* Used to detect encoding of files selected in Open dialog.
494
* Returns ENCODING_AUTO if file can't be read, etc.
495
*/
496
static ENCODING detect_encoding_of_file(LPCWSTR szFileName)
497
{
498
DWORD size;
499
HANDLE hFile = CreateFileW(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
500
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
501
if (hFile == INVALID_HANDLE_VALUE)
502
return ENCODING_AUTO;
503
size = GetFileSize(hFile, NULL);
504
if (size == INVALID_FILE_SIZE)
505
{
506
CloseHandle(hFile);
507
return ENCODING_AUTO;
508
}
509
else
510
{
511
DWORD dwNumRead;
512
BYTE buffer[MAX_STRING_LEN];
513
if (!ReadFile(hFile, buffer, min(size, sizeof(buffer)), &dwNumRead, NULL))
514
{
515
CloseHandle(hFile);
516
return ENCODING_AUTO;
517
}
518
CloseHandle(hFile);
519
return detect_encoding_of_buffer(buffer, dwNumRead);
520
}
521
}
522
523
static LPWSTR dialog_print_to_file(HWND hMainWnd)
524
{
525
OPENFILENAMEW ofn;
526
static WCHAR file[MAX_PATH] = L"output.prn";
527
528
ZeroMemory(&ofn, sizeof(ofn));
529
530
ofn.lStructSize = sizeof(ofn);
531
ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
532
ofn.hwndOwner = hMainWnd;
533
ofn.lpstrFile = file;
534
ofn.nMaxFile = MAX_PATH;
535
ofn.lpstrDefExt = L"prn";
536
537
if(GetSaveFileNameW(&ofn))
538
return file;
539
else
540
return FALSE;
541
}
542
static UINT_PTR CALLBACK OfnHookProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
543
{
544
static HWND hEncCombo;
545
546
switch (uMsg)
547
{
548
case WM_INITDIALOG:
549
{
550
ENCODING enc;
551
hEncCombo = GetDlgItem(hdlg, IDC_OFN_ENCCOMBO);
552
for (enc = MIN_ENCODING; enc <= MAX_ENCODING; enc++)
553
{
554
WCHAR szEnc[MAX_STRING_LEN];
555
load_encoding_name(enc, szEnc, ARRAY_SIZE(szEnc));
556
SendMessageW(hEncCombo, CB_ADDSTRING, 0, (LPARAM)szEnc);
557
}
558
SendMessageW(hEncCombo, CB_SETCURSEL, (WPARAM)Globals.encOfnCombo, 0);
559
}
560
break;
561
562
case WM_COMMAND:
563
if (LOWORD(wParam) == IDC_OFN_ENCCOMBO &&
564
HIWORD(wParam) == CBN_SELCHANGE)
565
{
566
int index = SendMessageW(hEncCombo, CB_GETCURSEL, 0, 0);
567
Globals.encOfnCombo = index==CB_ERR ? ENCODING_ANSI : (ENCODING)index;
568
}
569
570
break;
571
572
case WM_NOTIFY:
573
switch (((OFNOTIFYW*)lParam)->hdr.code)
574
{
575
case CDN_SELCHANGE:
576
if (Globals.bOfnIsOpenDialog)
577
{
578
/* Check the start of the selected file for a BOM. */
579
ENCODING enc;
580
WCHAR szFileName[MAX_PATH];
581
SendMessageW(GetParent(hdlg), CDM_GETFILEPATH,
582
ARRAY_SIZE(szFileName), (LPARAM)szFileName);
583
enc = detect_encoding_of_file(szFileName);
584
if (enc != ENCODING_AUTO)
585
{
586
Globals.encOfnCombo = enc;
587
SendMessageW(hEncCombo, CB_SETCURSEL, (WPARAM)enc, 0);
588
}
589
}
590
break;
591
592
default:
593
break;
594
}
595
break;
596
597
default:
598
break;
599
}
600
return 0;
601
}
602
603
VOID DIALOG_FileOpen(VOID)
604
{
605
OPENFILENAMEW openfilename;
606
WCHAR szPath[MAX_PATH];
607
608
ZeroMemory(&openfilename, sizeof(openfilename));
609
610
lstrcpyW(szPath, L"*.txt");
611
612
openfilename.lStructSize = sizeof(openfilename);
613
openfilename.hwndOwner = Globals.hMainWnd;
614
openfilename.hInstance = Globals.hInstance;
615
openfilename.lpstrFilter = Globals.szFilter;
616
openfilename.lpstrFile = szPath;
617
openfilename.nMaxFile = ARRAY_SIZE(szPath);
618
openfilename.Flags = OFN_ENABLETEMPLATE | OFN_ENABLEHOOK | OFN_EXPLORER |
619
OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
620
OFN_HIDEREADONLY | OFN_ENABLESIZING;
621
openfilename.lpfnHook = OfnHookProc;
622
openfilename.lpTemplateName = MAKEINTRESOURCEW(IDD_OFN_TEMPLATE);
623
openfilename.lpstrDefExt = L"txt";
624
625
Globals.encOfnCombo = ENCODING_ANSI;
626
Globals.bOfnIsOpenDialog = TRUE;
627
628
if (GetOpenFileNameW(&openfilename))
629
DoOpenFile(openfilename.lpstrFile, Globals.encOfnCombo);
630
}
631
632
/* Return FALSE to cancel close */
633
BOOL DIALOG_FileSave(VOID)
634
{
635
if (Globals.szFileName[0] == '\0')
636
return DIALOG_FileSaveAs();
637
else
638
{
639
switch (DoSaveFile(Globals.szFileName, Globals.encFile))
640
{
641
case SAVED_OK: return TRUE;
642
case SHOW_SAVEAS_DIALOG: return DIALOG_FileSaveAs();
643
default: return FALSE;
644
}
645
}
646
}
647
648
BOOL DIALOG_FileSaveAs(VOID)
649
{
650
OPENFILENAMEW saveas;
651
WCHAR szPath[MAX_PATH];
652
653
ZeroMemory(&saveas, sizeof(saveas));
654
655
lstrcpyW(szPath, L"*.txt");
656
657
saveas.lStructSize = sizeof(OPENFILENAMEW);
658
saveas.hwndOwner = Globals.hMainWnd;
659
saveas.hInstance = Globals.hInstance;
660
saveas.lpstrFilter = Globals.szFilter;
661
saveas.lpstrFile = szPath;
662
saveas.nMaxFile = ARRAY_SIZE(szPath);
663
saveas.Flags = OFN_ENABLETEMPLATE | OFN_ENABLEHOOK | OFN_EXPLORER |
664
OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
665
OFN_HIDEREADONLY | OFN_ENABLESIZING;
666
saveas.lpfnHook = OfnHookProc;
667
saveas.lpTemplateName = MAKEINTRESOURCEW(IDD_OFN_TEMPLATE);
668
saveas.lpstrDefExt = L"txt";
669
670
/* Preset encoding to what file was opened/saved last with. */
671
Globals.encOfnCombo = Globals.encFile;
672
Globals.bOfnIsOpenDialog = FALSE;
673
674
retry:
675
if (!GetSaveFileNameW(&saveas))
676
return FALSE;
677
678
switch (DoSaveFile(szPath, Globals.encOfnCombo))
679
{
680
case SAVED_OK:
681
SetFileNameAndEncoding(szPath, Globals.encOfnCombo);
682
UpdateWindowCaption();
683
return TRUE;
684
685
case SHOW_SAVEAS_DIALOG:
686
goto retry;
687
688
default:
689
return FALSE;
690
}
691
}
692
693
typedef struct {
694
LPWSTR mptr;
695
LPWSTR mend;
696
LPWSTR lptr;
697
DWORD len;
698
} TEXTINFO, *LPTEXTINFO;
699
700
static int notepad_print_header(HDC hdc, RECT *rc, BOOL dopage, BOOL header, int page, LPWSTR text)
701
{
702
SIZE szMetric;
703
704
if (*text)
705
{
706
/* Write the header or footer */
707
GetTextExtentPoint32W(hdc, text, lstrlenW(text), &szMetric);
708
if (dopage)
709
ExtTextOutW(hdc, (rc->left + rc->right - szMetric.cx) / 2,
710
header ? rc->top : rc->bottom - szMetric.cy,
711
ETO_CLIPPED, rc, text, lstrlenW(text), NULL);
712
return 1;
713
}
714
return 0;
715
}
716
717
static WCHAR *expand_header_vars(WCHAR *pattern, int page)
718
{
719
int length = 0;
720
int i;
721
BOOL inside = FALSE;
722
WCHAR *buffer = NULL;
723
724
for (i = 0; pattern[i]; i++)
725
{
726
if (inside)
727
{
728
if (pattern[i] == '&')
729
length++;
730
else if (pattern[i] == 'p')
731
length += 11;
732
inside = FALSE;
733
}
734
else if (pattern[i] == '&')
735
inside = TRUE;
736
else
737
length++;
738
}
739
740
buffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
741
if (buffer)
742
{
743
int j = 0;
744
inside = FALSE;
745
for (i = 0; pattern[i]; i++)
746
{
747
if (inside)
748
{
749
if (pattern[i] == '&')
750
buffer[j++] = '&';
751
else if (pattern[i] == 'p')
752
j += wnsprintfW(&buffer[j], 11, L"%d", page);
753
inside = FALSE;
754
}
755
else if (pattern[i] == '&')
756
inside = TRUE;
757
else
758
buffer[j++] = pattern[i];
759
}
760
buffer[j++] = 0;
761
}
762
return buffer;
763
}
764
765
static BOOL notepad_print_page(HDC hdc, RECT *rc, BOOL dopage, int page, LPTEXTINFO tInfo)
766
{
767
int b, y;
768
TEXTMETRICW tm;
769
SIZE szMetrics;
770
WCHAR *footer_text = NULL;
771
772
footer_text = expand_header_vars(Globals.szFooter, page);
773
if (footer_text == NULL)
774
return FALSE;
775
776
if (dopage)
777
{
778
if (StartPage(hdc) <= 0)
779
{
780
MessageBoxW(Globals.hMainWnd, L"StartPage failed", L"Print Error", MB_ICONEXCLAMATION);
781
HeapFree(GetProcessHeap(), 0, footer_text);
782
return FALSE;
783
}
784
}
785
786
GetTextMetricsW(hdc, &tm);
787
y = rc->top + notepad_print_header(hdc, rc, dopage, TRUE, page, Globals.szFileName) * tm.tmHeight;
788
b = rc->bottom - 2 * notepad_print_header(hdc, rc, FALSE, FALSE, page, footer_text) * tm.tmHeight;
789
790
do {
791
INT m, n;
792
793
if (!tInfo->len)
794
{
795
/* find the end of the line */
796
while (tInfo->mptr < tInfo->mend && *tInfo->mptr != '\n' && *tInfo->mptr != '\r')
797
{
798
if (*tInfo->mptr == '\t')
799
{
800
/* replace tabs with spaces */
801
for (m = 0; m < SPACES_IN_TAB; m++)
802
{
803
if (tInfo->len < PRINT_LEN_MAX)
804
tInfo->lptr[tInfo->len++] = ' ';
805
else if (Globals.bWrapLongLines)
806
break;
807
}
808
}
809
else if (tInfo->len < PRINT_LEN_MAX)
810
tInfo->lptr[tInfo->len++] = *tInfo->mptr;
811
812
if (tInfo->len >= PRINT_LEN_MAX && Globals.bWrapLongLines)
813
break;
814
815
tInfo->mptr++;
816
}
817
}
818
819
/* Find out how much we should print if line wrapping is enabled */
820
if (Globals.bWrapLongLines)
821
{
822
GetTextExtentExPointW(hdc, tInfo->lptr, tInfo->len, rc->right - rc->left, &n, NULL, &szMetrics);
823
if (n < tInfo->len && tInfo->lptr[n] != ' ')
824
{
825
m = n;
826
/* Don't wrap words unless it's a single word over the entire line */
827
while (m && tInfo->lptr[m] != ' ') m--;
828
if (m > 0) n = m + 1;
829
}
830
}
831
else
832
n = tInfo->len;
833
834
if (dopage)
835
ExtTextOutW(hdc, rc->left, y, ETO_CLIPPED, rc, tInfo->lptr, n, NULL);
836
837
tInfo->len -= n;
838
839
if (tInfo->len)
840
{
841
memcpy(tInfo->lptr, tInfo->lptr + n, tInfo->len * sizeof(WCHAR));
842
y += tm.tmHeight + tm.tmExternalLeading;
843
}
844
else
845
{
846
/* find the next line */
847
while (tInfo->mptr < tInfo->mend && y < b && (*tInfo->mptr == '\n' || *tInfo->mptr == '\r'))
848
{
849
if (*tInfo->mptr == '\n')
850
y += tm.tmHeight + tm.tmExternalLeading;
851
tInfo->mptr++;
852
}
853
}
854
} while (tInfo->mptr < tInfo->mend && y < b);
855
856
notepad_print_header(hdc, rc, dopage, FALSE, page, footer_text);
857
if (dopage)
858
{
859
EndPage(hdc);
860
}
861
HeapFree(GetProcessHeap(), 0, footer_text);
862
return TRUE;
863
}
864
865
VOID DIALOG_FilePrint(VOID)
866
{
867
DOCINFOW di;
868
PRINTDLGW printer;
869
int page, dopage, copy;
870
LOGFONTW lfFont;
871
HFONT hTextFont, old_font = 0;
872
DWORD size;
873
BOOL ret = FALSE;
874
RECT rc;
875
LPWSTR pTemp;
876
TEXTINFO tInfo;
877
WCHAR cTemp[PRINT_LEN_MAX];
878
879
/* Get Current Settings */
880
ZeroMemory(&printer, sizeof(printer));
881
printer.lStructSize = sizeof(printer);
882
printer.hwndOwner = Globals.hMainWnd;
883
printer.hDevMode = Globals.hDevMode;
884
printer.hDevNames = Globals.hDevNames;
885
printer.hInstance = Globals.hInstance;
886
887
/* Set some default flags */
888
printer.Flags = PD_RETURNDC | PD_NOSELECTION;
889
printer.nFromPage = 0;
890
printer.nMinPage = 1;
891
/* we really need to calculate number of pages to set nMaxPage and nToPage */
892
printer.nToPage = 0;
893
printer.nMaxPage = -1;
894
/* Let commdlg manage copy settings */
895
printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
896
897
if (!PrintDlgW(&printer)) return;
898
899
Globals.hDevMode = printer.hDevMode;
900
Globals.hDevNames = printer.hDevNames;
901
902
SetMapMode(printer.hDC, MM_TEXT);
903
904
/* initialize DOCINFO */
905
di.cbSize = sizeof(DOCINFOW);
906
di.lpszDocName = Globals.szFileTitle;
907
di.lpszOutput = NULL;
908
di.lpszDatatype = NULL;
909
di.fwType = 0;
910
911
if(printer.Flags & PD_PRINTTOFILE)
912
{
913
di.lpszOutput = dialog_print_to_file(printer.hwndOwner);
914
if(!di.lpszOutput)
915
return;
916
}
917
918
/* Get the file text */
919
size = GetWindowTextLengthW(Globals.hEdit) + 1;
920
pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
921
if (!pTemp)
922
{
923
DeleteDC(printer.hDC);
924
ShowLastError();
925
return;
926
}
927
size = GetWindowTextW(Globals.hEdit, pTemp, size);
928
929
if (StartDocW(printer.hDC, &di) > 0)
930
{
931
/* Get the page margins in pixels. */
932
rc.top = MulDiv(Globals.iMarginTop, GetDeviceCaps(printer.hDC, LOGPIXELSY), 2540) -
933
GetDeviceCaps(printer.hDC, PHYSICALOFFSETY);
934
rc.bottom = GetDeviceCaps(printer.hDC, PHYSICALHEIGHT) -
935
MulDiv(Globals.iMarginBottom, GetDeviceCaps(printer.hDC, LOGPIXELSY), 2540);
936
rc.left = MulDiv(Globals.iMarginLeft, GetDeviceCaps(printer.hDC, LOGPIXELSX), 2540) -
937
GetDeviceCaps(printer.hDC, PHYSICALOFFSETX);
938
rc.right = GetDeviceCaps(printer.hDC, PHYSICALWIDTH) -
939
MulDiv(Globals.iMarginRight, GetDeviceCaps(printer.hDC, LOGPIXELSX), 2540);
940
941
/* Create a font for the printer resolution */
942
lfFont = Globals.lfFont;
943
lfFont.lfHeight = MulDiv(lfFont.lfHeight, GetDeviceCaps(printer.hDC, LOGPIXELSY), GetDpiForWindow(Globals.hMainWnd));
944
/* Make the font a bit lighter */
945
lfFont.lfWeight -= 100;
946
hTextFont = CreateFontIndirectW(&lfFont);
947
old_font = SelectObject(printer.hDC, hTextFont);
948
949
for (copy = 1; copy <= printer.nCopies; copy++)
950
{
951
page = 1;
952
953
tInfo.mptr = pTemp;
954
tInfo.mend = pTemp + size;
955
tInfo.lptr = cTemp;
956
tInfo.len = 0;
957
958
do {
959
if (printer.Flags & PD_PAGENUMS)
960
{
961
/* a specific range of pages is selected, so
962
* skip pages that are not to be printed
963
*/
964
if (page > printer.nToPage)
965
break;
966
else if (page >= printer.nFromPage)
967
dopage = 1;
968
else
969
dopage = 0;
970
}
971
else
972
dopage = 1;
973
974
ret = notepad_print_page(printer.hDC, &rc, dopage, page, &tInfo);
975
page++;
976
} while (ret && tInfo.mptr < tInfo.mend);
977
978
if (!ret) break;
979
}
980
EndDoc(printer.hDC);
981
SelectObject(printer.hDC, old_font);
982
DeleteObject(hTextFont);
983
}
984
DeleteDC(printer.hDC);
985
HeapFree(GetProcessHeap(), 0, pTemp);
986
}
987
988
VOID DIALOG_FilePrinterSetup(VOID)
989
{
990
PRINTDLGW printer;
991
992
ZeroMemory(&printer, sizeof(printer));
993
printer.lStructSize = sizeof(printer);
994
printer.hwndOwner = Globals.hMainWnd;
995
printer.hDevMode = Globals.hDevMode;
996
printer.hDevNames = Globals.hDevNames;
997
printer.hInstance = Globals.hInstance;
998
printer.Flags = PD_PRINTSETUP;
999
printer.nCopies = 1;
1000
1001
PrintDlgW(&printer);
1002
1003
Globals.hDevMode = printer.hDevMode;
1004
Globals.hDevNames = printer.hDevNames;
1005
}
1006
1007
VOID DIALOG_FileExit(VOID)
1008
{
1009
PostMessageW(Globals.hMainWnd, WM_CLOSE, 0, 0l);
1010
}
1011
1012
VOID DIALOG_EditUndo(VOID)
1013
{
1014
SendMessageW(Globals.hEdit, EM_UNDO, 0, 0);
1015
}
1016
1017
VOID DIALOG_EditCut(VOID)
1018
{
1019
SendMessageW(Globals.hEdit, WM_CUT, 0, 0);
1020
}
1021
1022
VOID DIALOG_EditCopy(VOID)
1023
{
1024
SendMessageW(Globals.hEdit, WM_COPY, 0, 0);
1025
}
1026
1027
VOID DIALOG_EditPaste(VOID)
1028
{
1029
SendMessageW(Globals.hEdit, WM_PASTE, 0, 0);
1030
}
1031
1032
VOID DIALOG_EditDelete(VOID)
1033
{
1034
SendMessageW(Globals.hEdit, WM_CLEAR, 0, 0);
1035
}
1036
1037
VOID DIALOG_EditSelectAll(VOID)
1038
{
1039
SendMessageW(Globals.hEdit, EM_SETSEL, 0, -1);
1040
}
1041
1042
VOID DIALOG_EditTimeDate(VOID)
1043
{
1044
SYSTEMTIME st;
1045
WCHAR szDate[MAX_STRING_LEN];
1046
1047
GetLocalTime(&st);
1048
1049
GetTimeFormatW(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, NULL, szDate, MAX_STRING_LEN);
1050
SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
1051
1052
SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)L" ");
1053
1054
GetDateFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN);
1055
SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
1056
}
1057
1058
VOID DIALOG_EditWrap(VOID)
1059
{
1060
BOOL modify = FALSE;
1061
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
1062
ES_AUTOVSCROLL | ES_MULTILINE;
1063
RECT rc;
1064
DWORD size;
1065
LPWSTR pTemp;
1066
1067
size = GetWindowTextLengthW(Globals.hEdit) + 1;
1068
pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
1069
if (!pTemp)
1070
{
1071
ShowLastError();
1072
return;
1073
}
1074
GetWindowTextW(Globals.hEdit, pTemp, size);
1075
modify = SendMessageW(Globals.hEdit, EM_GETMODIFY, 0, 0);
1076
DestroyWindow(Globals.hEdit);
1077
GetClientRect(Globals.hMainWnd, &rc);
1078
if( Globals.bWrapLongLines ) dwStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
1079
Globals.hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, L"edit", NULL, dwStyle,
1080
0, 0, rc.right, rc.bottom, Globals.hMainWnd,
1081
NULL, Globals.hInstance, NULL);
1082
SendMessageW(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, FALSE);
1083
SetWindowTextW(Globals.hEdit, pTemp);
1084
SendMessageW(Globals.hEdit, EM_SETMODIFY, modify, 0);
1085
SetFocus(Globals.hEdit);
1086
HeapFree(GetProcessHeap(), 0, pTemp);
1087
1088
Globals.bWrapLongLines = !Globals.bWrapLongLines;
1089
CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
1090
MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
1091
SetWindowSubclass(Globals.hEdit, EDIT_CallBackProc, 0, 0);
1092
updateWindowSize(rc.right, rc.bottom);
1093
}
1094
1095
VOID DIALOG_SelectFont(VOID)
1096
{
1097
CHOOSEFONTW cf;
1098
LOGFONTW lf=Globals.lfFont;
1099
1100
ZeroMemory( &cf, sizeof(cf) );
1101
cf.lStructSize=sizeof(cf);
1102
cf.hwndOwner=Globals.hMainWnd;
1103
cf.lpLogFont=&lf;
1104
cf.Flags=CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_NOVERTFONTS;
1105
1106
if( ChooseFontW(&cf) )
1107
{
1108
HFONT currfont=Globals.hFont;
1109
1110
Globals.hFont=CreateFontIndirectW( &lf );
1111
Globals.lfFont=lf;
1112
SendMessageW( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, TRUE );
1113
if( currfont!=NULL )
1114
DeleteObject( currfont );
1115
}
1116
}
1117
1118
VOID DIALOG_Search(VOID)
1119
{
1120
/* Allow only one search/replace dialog to open */
1121
if(Globals.hFindReplaceDlg != NULL)
1122
{
1123
SetActiveWindow(Globals.hFindReplaceDlg);
1124
return;
1125
}
1126
1127
ZeroMemory(&Globals.find, sizeof(Globals.find));
1128
Globals.find.lStructSize = sizeof(Globals.find);
1129
Globals.find.hwndOwner = Globals.hMainWnd;
1130
Globals.find.hInstance = Globals.hInstance;
1131
Globals.find.lpstrFindWhat = Globals.szFindText;
1132
Globals.find.wFindWhatLen = ARRAY_SIZE(Globals.szFindText);
1133
Globals.find.Flags = FR_DOWN|FR_HIDEWHOLEWORD;
1134
1135
/* We only need to create the modal FindReplace dialog which will */
1136
/* notify us of incoming events using hMainWnd Window Messages */
1137
1138
Globals.hFindReplaceDlg = FindTextW(&Globals.find);
1139
assert(Globals.hFindReplaceDlg !=0);
1140
}
1141
1142
VOID DIALOG_SearchNext(VOID)
1143
{
1144
if (Globals.lastFind.lpstrFindWhat == NULL)
1145
DIALOG_Search();
1146
else /* use the last find data */
1147
NOTEPAD_DoFind(&Globals.lastFind);
1148
}
1149
1150
VOID DIALOG_Replace(VOID)
1151
{
1152
/* Allow only one search/replace dialog to open */
1153
if(Globals.hFindReplaceDlg != NULL)
1154
{
1155
SetActiveWindow(Globals.hFindReplaceDlg);
1156
return;
1157
}
1158
1159
ZeroMemory(&Globals.find, sizeof(Globals.find));
1160
Globals.find.lStructSize = sizeof(Globals.find);
1161
Globals.find.hwndOwner = Globals.hMainWnd;
1162
Globals.find.hInstance = Globals.hInstance;
1163
Globals.find.lpstrFindWhat = Globals.szFindText;
1164
Globals.find.wFindWhatLen = ARRAY_SIZE(Globals.szFindText);
1165
Globals.find.lpstrReplaceWith = Globals.szReplaceText;
1166
Globals.find.wReplaceWithLen = ARRAY_SIZE(Globals.szReplaceText);
1167
Globals.find.Flags = FR_DOWN|FR_HIDEWHOLEWORD;
1168
1169
/* We only need to create the modal FindReplace dialog which will */
1170
/* notify us of incoming events using hMainWnd Window Messages */
1171
1172
Globals.hFindReplaceDlg = ReplaceTextW(&Globals.find);
1173
assert(Globals.hFindReplaceDlg !=0);
1174
}
1175
1176
VOID DIALOG_HelpContents(VOID)
1177
{
1178
WinHelpW(Globals.hMainWnd, L"notepad.hlp", HELP_INDEX, 0);
1179
}
1180
1181
VOID DIALOG_HelpAboutNotepad(VOID)
1182
{
1183
WCHAR szNotepad[MAX_STRING_LEN];
1184
HICON icon = LoadImageW(Globals.hInstance, MAKEINTRESOURCEW(IDI_NOTEPAD),
1185
IMAGE_ICON, 48, 48, LR_SHARED);
1186
1187
LoadStringW(Globals.hInstance, STRING_NOTEPAD, szNotepad, ARRAY_SIZE(szNotepad));
1188
ShellAboutW(Globals.hMainWnd, szNotepad, L"Wine Notepad", icon);
1189
}
1190
1191
1192
/***********************************************************************
1193
*
1194
* DIALOG_FilePageSetup
1195
*/
1196
VOID DIALOG_FilePageSetup(void)
1197
{
1198
DialogBoxW(Globals.hInstance, MAKEINTRESOURCEW(DIALOG_PAGESETUP),
1199
Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc);
1200
}
1201
1202
1203
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1204
*
1205
* DIALOG_PAGESETUP_DlgProc
1206
*/
1207
1208
static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1209
{
1210
1211
switch (msg)
1212
{
1213
case WM_COMMAND:
1214
switch (wParam)
1215
{
1216
case IDOK:
1217
/* save user input and close dialog */
1218
GetDlgItemTextW(hDlg, IDC_PAGESETUP_HEADERVALUE, Globals.szHeader, ARRAY_SIZE(Globals.szHeader));
1219
GetDlgItemTextW(hDlg, IDC_PAGESETUP_FOOTERVALUE, Globals.szFooter, ARRAY_SIZE(Globals.szFooter));
1220
1221
Globals.iMarginTop = GetDlgItemInt(hDlg, IDC_PAGESETUP_TOPVALUE, NULL, FALSE) * 100;
1222
Globals.iMarginBottom = GetDlgItemInt(hDlg, IDC_PAGESETUP_BOTTOMVALUE, NULL, FALSE) * 100;
1223
Globals.iMarginLeft = GetDlgItemInt(hDlg, IDC_PAGESETUP_LEFTVALUE, NULL, FALSE) * 100;
1224
Globals.iMarginRight = GetDlgItemInt(hDlg, IDC_PAGESETUP_RIGHTVALUE, NULL, FALSE) * 100;
1225
EndDialog(hDlg, IDOK);
1226
return TRUE;
1227
1228
case IDCANCEL:
1229
/* discard user input and close dialog */
1230
EndDialog(hDlg, IDCANCEL);
1231
return TRUE;
1232
1233
case IDHELP:
1234
{
1235
/* FIXME: Bring this to work */
1236
MessageBoxW(Globals.hMainWnd, L"Sorry, no help available", L"Help", MB_ICONEXCLAMATION);
1237
return TRUE;
1238
}
1239
1240
default:
1241
break;
1242
}
1243
break;
1244
1245
case WM_INITDIALOG:
1246
/* fetch last user input prior to display dialog */
1247
SetDlgItemTextW(hDlg, IDC_PAGESETUP_HEADERVALUE, Globals.szHeader);
1248
SetDlgItemTextW(hDlg, IDC_PAGESETUP_FOOTERVALUE, Globals.szFooter);
1249
SetDlgItemInt(hDlg, IDC_PAGESETUP_TOPVALUE, Globals.iMarginTop / 100, FALSE);
1250
SetDlgItemInt(hDlg, IDC_PAGESETUP_BOTTOMVALUE, Globals.iMarginBottom / 100, FALSE);
1251
SetDlgItemInt(hDlg, IDC_PAGESETUP_LEFTVALUE, Globals.iMarginLeft / 100, FALSE);
1252
SetDlgItemInt(hDlg, IDC_PAGESETUP_RIGHTVALUE, Globals.iMarginRight / 100, FALSE);
1253
break;
1254
}
1255
1256
return FALSE;
1257
}
1258
1259
static INT_PTR WINAPI DIALOG_GOTO_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1260
{
1261
switch(msg)
1262
{
1263
case WM_COMMAND:
1264
{
1265
switch (wParam)
1266
{
1267
case IDOK:
1268
{
1269
int lineValue = GetDlgItemInt(hDlg, IDC_GOTO_LINEVALUE, NULL, FALSE) - 1;
1270
long lineIndex = SendMessageW(Globals.hEdit, EM_LINEINDEX, lineValue, 0);
1271
1272
SendMessageW(Globals.hEdit, EM_SETSEL, lineIndex, lineIndex);
1273
UpdateStatusBar();
1274
EndDialog(hDlg, IDOK);
1275
return TRUE;
1276
}
1277
case IDCANCEL:
1278
{
1279
EndDialog(hDlg, IDCANCEL);
1280
return TRUE;
1281
}
1282
default:
1283
{
1284
break;
1285
}
1286
}
1287
break;
1288
}
1289
case WM_INITDIALOG:
1290
{
1291
int currentLine = SendMessageW(Globals.hEdit, EM_LINEFROMCHAR, -1, 0) + 1;
1292
SetDlgItemInt(hDlg, IDC_GOTO_LINEVALUE, currentLine, FALSE);
1293
break;
1294
}
1295
}
1296
return FALSE;
1297
}
1298
1299
void DIALOG_EditGoTo(void)
1300
{
1301
DialogBoxW(Globals.hInstance, MAKEINTRESOURCEW(DIALOG_GOTO),
1302
Globals.hMainWnd, DIALOG_GOTO_DlgProc);
1303
}
1304
1305