blob: 0595f690d2d123b9e795d8a5753b5b656fa809da [file] [log] [blame]
Alexandre Julliard03468f71998-02-15 19:40:49 +00001/*
Marcel Baura43295d1998-10-18 14:11:42 +00002 * Notepad (dialog.c)
Alexandre Julliard03468f71998-02-15 19:40:49 +00003 *
Marcel Baur03287451999-02-14 11:28:37 +00004 * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
Sylvain Petreolleeaa8df62002-03-20 22:55:46 +00005 * Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
Andriy Palamarchukc55dce02002-07-08 19:41:09 +00006 * Copyright 2002 Andriy Palamarchuk
Rolf Kalbermatter5eb6c112007-04-06 19:50:37 +02007 * Copyright 2007 Rolf Kalbermatter
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00008 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
Jonathan Ernst360a3f92006-05-18 14:49:52 +020021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard03468f71998-02-15 19:40:49 +000022 */
23
Dmitry Timoshkov398af162003-07-21 20:05:33 +000024#define UNICODE
25
Ulrich Weigand97d05c82000-01-29 22:07:03 +000026#include <assert.h>
Alexandre Julliard03468f71998-02-15 19:40:49 +000027#include <stdio.h>
Marcel Baura43295d1998-10-18 14:11:42 +000028#include <windows.h>
29#include <commdlg.h>
Mikołaj Zalewskib0905ac2006-10-22 18:54:51 +020030#include <shlwapi.h>
Marcel Baura43295d1998-10-18 14:11:42 +000031
Alexandre Julliard03468f71998-02-15 19:40:49 +000032#include "main.h"
Alexandre Julliard03468f71998-02-15 19:40:49 +000033#include "dialog.h"
Marcel Baura43295d1998-10-18 14:11:42 +000034
Duane Clarka60ee9c2006-07-16 16:20:30 -070035#define SPACES_IN_TAB 8
Rolf Kalbermatter5eb6c112007-04-06 19:50:37 +020036#define PRINT_LEN_MAX 500
Duane Clarka60ee9c2006-07-16 16:20:30 -070037
Dmitry Timoshkov398af162003-07-21 20:05:33 +000038static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
Alexandre Julliard03468f71998-02-15 19:40:49 +000039
Dmitry Timoshkov398af162003-07-21 20:05:33 +000040static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000041
Dmitry Timoshkov398af162003-07-21 20:05:33 +000042VOID ShowLastError(void)
Andriy Palamarchukc55dce02002-07-08 19:41:09 +000043{
44 DWORD error = GetLastError();
45 if (error != NO_ERROR)
46 {
Dmitry Timoshkov398af162003-07-21 20:05:33 +000047 LPWSTR lpMsgBuf;
48 WCHAR szTitle[MAX_STRING_LEN];
Andriy Palamarchukc55dce02002-07-08 19:41:09 +000049
Dmitry Timoshkov398af162003-07-21 20:05:33 +000050 LoadString(Globals.hInstance, STRING_ERROR, szTitle, SIZEOF(szTitle));
Andriy Palamarchukc55dce02002-07-08 19:41:09 +000051 FormatMessage(
52 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
53 NULL, error, 0,
54 (LPTSTR) &lpMsgBuf, 0, NULL);
Dmitry Timoshkov398af162003-07-21 20:05:33 +000055 MessageBox(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +000056 LocalFree(lpMsgBuf);
57 }
58}
59
60/**
61 * Sets the caption of the main window according to Globals.szFileTitle:
Thomas Kho3ec165f2006-07-12 14:15:31 -070062 * Untitled - Notepad if no file is open
63 * filename - Notepad if a file is given
Andriy Palamarchukc55dce02002-07-08 19:41:09 +000064 */
Dmitry Timoshkov398af162003-07-21 20:05:33 +000065static void UpdateWindowCaption(void)
66{
67 WCHAR szCaption[MAX_STRING_LEN];
Thomas Kho3ec165f2006-07-12 14:15:31 -070068 WCHAR szNotepad[MAX_STRING_LEN];
69 static const WCHAR hyphenW[] = { ' ','-',' ',0 };
Andriy Palamarchukc55dce02002-07-08 19:41:09 +000070
Thomas Kho3ec165f2006-07-12 14:15:31 -070071 if (Globals.szFileTitle[0] != '\0')
72 lstrcpy(szCaption, Globals.szFileTitle);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +000073 else
Thomas Kho3ec165f2006-07-12 14:15:31 -070074 LoadString(Globals.hInstance, STRING_UNTITLED, szCaption, SIZEOF(szCaption));
75
76 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
77 lstrcat(szCaption, hyphenW);
78 lstrcat(szCaption, szNotepad);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +000079
80 SetWindowText(Globals.hMainWnd, szCaption);
81}
82
Mikołaj Zalewskib0905ac2006-10-22 18:54:51 +020083int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCWSTR szString, DWORD dwFlags)
Dmitry Timoshkov398af162003-07-21 20:05:33 +000084{
85 WCHAR szMessage[MAX_STRING_LEN];
86 WCHAR szResource[MAX_STRING_LEN];
Marcel Baur03287451999-02-14 11:28:37 +000087
88 /* Load and format szMessage */
Mikołaj Zalewskib0905ac2006-10-22 18:54:51 +020089 LoadString(Globals.hInstance, formatId, szResource, SIZEOF(szResource));
90 wnsprintf(szMessage, SIZEOF(szMessage), szResource, szString);
Vincent Béron9a624912002-05-31 23:06:46 +000091
Marcel Baur03287451999-02-14 11:28:37 +000092 /* Load szCaption */
Mikołaj Zalewskib0905ac2006-10-22 18:54:51 +020093 if ((dwFlags & MB_ICONMASK) == MB_ICONEXCLAMATION)
94 LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource));
95 else
96 LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource));
Marcel Baur03287451999-02-14 11:28:37 +000097
98 /* Display Modal Dialog */
Mikołaj Zalewskib0905ac2006-10-22 18:54:51 +020099 if (hParent == NULL)
100 hParent = Globals.hMainWnd;
101 return MessageBox(hParent, szMessage, szResource, dwFlags);
102}
103
104static void AlertFileNotFound(LPCWSTR szFileName)
105{
106 DIALOG_StringMsgBox(NULL, STRING_NOTFOUND, szFileName, MB_ICONEXCLAMATION|MB_OK);
Marcel Baur03287451999-02-14 11:28:37 +0000107}
108
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000109static int AlertFileNotSaved(LPCWSTR szFileName)
110{
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000111 WCHAR szUntitled[MAX_STRING_LEN];
Marcel Baur03287451999-02-14 11:28:37 +0000112
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000113 LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled));
Mikołaj Zalewskib0905ac2006-10-22 18:54:51 +0200114 return DIALOG_StringMsgBox(NULL, STRING_NOTSAVED, szFileName[0] ? szFileName : szUntitled,
115 MB_ICONQUESTION|MB_YESNOCANCEL);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000116}
117
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000118/**
119 * Returns:
120 * TRUE - if file exists
121 * FALSE - if file does not exist
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000122 */
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000123BOOL FileExists(LPCWSTR szFilename)
124{
Marcel Baura43295d1998-10-18 14:11:42 +0000125 WIN32_FIND_DATA entry;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000126 HANDLE hFile;
Vincent Béron9a624912002-05-31 23:06:46 +0000127
Marcel Baur03287451999-02-14 11:28:37 +0000128 hFile = FindFirstFile(szFilename, &entry);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000129 FindClose(hFile);
Vincent Béron9a624912002-05-31 23:06:46 +0000130
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000131 return (hFile != INVALID_HANDLE_VALUE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000132}
133
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000134
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000135static VOID DoSaveFile(VOID)
136{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000137 HANDLE hFile;
138 DWORD dwNumWrite;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000139 LPSTR pTemp;
140 DWORD size;
Marcel Baur03287451999-02-14 11:28:37 +0000141
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000142 hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
143 NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
144 if(hFile == INVALID_HANDLE_VALUE)
145 {
146 ShowLastError();
147 return;
148 }
149
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000150 size = GetWindowTextLengthA(Globals.hEdit) + 1;
151 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000152 if (!pTemp)
153 {
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000154 CloseHandle(hFile);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000155 ShowLastError();
156 return;
157 }
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000158 size = GetWindowTextA(Globals.hEdit, pTemp, size);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000159
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000160 if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL))
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000161 ShowLastError();
Juan Lange55b9432004-12-06 16:14:44 +0000162 else
163 SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000164
Jan Nieuwenhuizen137e54d2005-10-26 10:07:05 +0000165 SetEndOfFile(hFile);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000166 CloseHandle(hFile);
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000167 HeapFree(GetProcessHeap(), 0, pTemp);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000168}
169
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000170/**
171 * Returns:
172 * TRUE - User agreed to close (both save/don't save)
173 * FALSE - User cancelled close by selecting "Cancel"
174 */
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000175BOOL DoCloseFile(void)
176{
Marcel Baur03287451999-02-14 11:28:37 +0000177 int nResult;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000178 static const WCHAR empty_strW[] = { 0 };
Vincent Béron9a624912002-05-31 23:06:46 +0000179
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000180 if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
181 {
Marcel Baur03287451999-02-14 11:28:37 +0000182 /* prompt user to save changes */
183 nResult = AlertFileNotSaved(Globals.szFileName);
184 switch (nResult) {
Hirofumi Katayama32b6a1a2008-09-09 12:44:36 +0900185 case IDYES: return DIALOG_FileSave();
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000186
Marcel Baur03287451999-02-14 11:28:37 +0000187 case IDNO: break;
Marcel Baura43295d1998-10-18 14:11:42 +0000188
Marcel Baur03287451999-02-14 11:28:37 +0000189 case IDCANCEL: return(FALSE);
Vincent Béron9a624912002-05-31 23:06:46 +0000190
Marcel Baur03287451999-02-14 11:28:37 +0000191 default: return(FALSE);
Marcel Baur03287451999-02-14 11:28:37 +0000192 } /* switch */
193 } /* if */
Vincent Béron9a624912002-05-31 23:06:46 +0000194
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000195 SetFileName(empty_strW);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000196
197 UpdateWindowCaption();
Marcel Baur03287451999-02-14 11:28:37 +0000198 return(TRUE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000199}
200
201
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000202void DoOpenFile(LPCWSTR szFileName)
203{
Kevin Koltzau868a2b042005-05-07 12:14:05 +0000204 static const WCHAR dotlog[] = { '.','L','O','G',0 };
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000205 HANDLE hFile;
206 LPSTR pTemp;
207 DWORD size;
208 DWORD dwNumRead;
Kevin Koltzau868a2b042005-05-07 12:14:05 +0000209 WCHAR log[5];
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000210
Marcus Meissner73458b01998-12-26 12:54:29 +0000211 /* Close any files and prompt to save changes */
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000212 if (!DoCloseFile())
213 return;
214
215 hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
216 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
217 if(hFile == INVALID_HANDLE_VALUE)
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000218 {
Dmitry Timoshkov4ea5fce2007-08-31 16:02:01 +0900219 AlertFileNotFound(szFileName);
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000220 return;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000221 }
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000222
223 size = GetFileSize(hFile, NULL);
Alexandre Julliard2aa8a832003-10-16 19:31:11 +0000224 if (size == INVALID_FILE_SIZE)
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000225 {
226 CloseHandle(hFile);
227 ShowLastError();
228 return;
229 }
230 size++;
231
232 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
233 if (!pTemp)
234 {
235 CloseHandle(hFile);
236 ShowLastError();
237 return;
238 }
239
240 if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
241 {
242 CloseHandle(hFile);
243 HeapFree(GetProcessHeap(), 0, pTemp);
244 ShowLastError();
245 return;
246 }
247
248 CloseHandle(hFile);
249 pTemp[dwNumRead] = 0;
250
Alexander Nicolaysen Sørnesd50e2df2008-07-13 14:08:58 +0200251 if((size -1) >= 2 && (BYTE)pTemp[0] == 0xff && (BYTE)pTemp[1] == 0xfe)
252 SetWindowTextW(Globals.hEdit, (LPWSTR)pTemp + 1);
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000253 else
254 SetWindowTextA(Globals.hEdit, pTemp);
255
256 HeapFree(GetProcessHeap(), 0, pTemp);
257
258 SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
259 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
260 SetFocus(Globals.hEdit);
Kevin Koltzau868a2b042005-05-07 12:14:05 +0000261
James Hawkinse4c12272008-02-29 22:37:21 -0600262 /* If the file starts with .LOG, add a time/date at the end and set cursor after */
Kevin Koltzau868a2b042005-05-07 12:14:05 +0000263 if (GetWindowTextW(Globals.hEdit, log, sizeof(log)/sizeof(log[0])) && !lstrcmp(log, dotlog))
264 {
265 static const WCHAR lfW[] = { '\r','\n',0 };
266 SendMessage(Globals.hEdit, EM_SETSEL, GetWindowTextLength(Globals.hEdit), -1);
267 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW);
268 DIALOG_EditTimeDate();
269 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW);
270 }
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000271
272 SetFileName(szFileName);
273 UpdateWindowCaption();
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000274}
275
Alexandre Julliard03468f71998-02-15 19:40:49 +0000276VOID DIALOG_FileNew(VOID)
277{
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000278 static const WCHAR empty_strW[] = { 0 };
279
Francois Gouget8a18e0e2008-04-07 13:01:02 +0200280 /* Close any files and prompt to save changes */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000281 if (DoCloseFile()) {
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000282 SetWindowText(Globals.hEdit, empty_strW);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000283 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
284 SetFocus(Globals.hEdit);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000285 }
Alexandre Julliard03468f71998-02-15 19:40:49 +0000286}
287
288VOID DIALOG_FileOpen(VOID)
289{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000290 OPENFILENAME openfilename;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000291 WCHAR szPath[MAX_PATH];
292 WCHAR szDir[MAX_PATH];
293 static const WCHAR szDefaultExt[] = { 't','x','t',0 };
294 static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
Marcel Baura43295d1998-10-18 14:11:42 +0000295
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000296 ZeroMemory(&openfilename, sizeof(openfilename));
Alexandre Julliard03468f71998-02-15 19:40:49 +0000297
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000298 GetCurrentDirectory(SIZEOF(szDir), szDir);
299 lstrcpy(szPath, txt_files);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000300
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000301 openfilename.lStructSize = sizeof(openfilename);
302 openfilename.hwndOwner = Globals.hMainWnd;
303 openfilename.hInstance = Globals.hInstance;
304 openfilename.lpstrFilter = Globals.szFilter;
305 openfilename.lpstrFile = szPath;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000306 openfilename.nMaxFile = SIZEOF(szPath);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000307 openfilename.lpstrInitialDir = szDir;
308 openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
309 OFN_HIDEREADONLY;
310 openfilename.lpstrDefExt = szDefaultExt;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000311
Vincent Béron9a624912002-05-31 23:06:46 +0000312
Dmitry Timoshkov4ea5fce2007-08-31 16:02:01 +0900313 if (GetOpenFileName(&openfilename))
314 DoOpenFile(openfilename.lpstrFile);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000315}
316
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000317
Hirofumi Katayama32b6a1a2008-09-09 12:44:36 +0900318BOOL DIALOG_FileSave(VOID)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000319{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000320 if (Globals.szFileName[0] == '\0')
Hirofumi Katayama32b6a1a2008-09-09 12:44:36 +0900321 return DIALOG_FileSaveAs();
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000322 else
323 DoSaveFile();
Hirofumi Katayama32b6a1a2008-09-09 12:44:36 +0900324 return TRUE;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000325}
326
Hirofumi Katayama32b6a1a2008-09-09 12:44:36 +0900327BOOL DIALOG_FileSaveAs(VOID)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000328{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000329 OPENFILENAME saveas;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000330 WCHAR szPath[MAX_PATH];
331 WCHAR szDir[MAX_PATH];
332 static const WCHAR szDefaultExt[] = { 't','x','t',0 };
333 static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
Vincent Béron9a624912002-05-31 23:06:46 +0000334
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000335 ZeroMemory(&saveas, sizeof(saveas));
Alexandre Julliard03468f71998-02-15 19:40:49 +0000336
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000337 GetCurrentDirectory(SIZEOF(szDir), szDir);
338 lstrcpy(szPath, txt_files);
Marcel Baura43295d1998-10-18 14:11:42 +0000339
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000340 saveas.lStructSize = sizeof(OPENFILENAME);
341 saveas.hwndOwner = Globals.hMainWnd;
342 saveas.hInstance = Globals.hInstance;
343 saveas.lpstrFilter = Globals.szFilter;
344 saveas.lpstrFile = szPath;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000345 saveas.nMaxFile = SIZEOF(szPath);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000346 saveas.lpstrInitialDir = szDir;
347 saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
348 OFN_HIDEREADONLY;
349 saveas.lpstrDefExt = szDefaultExt;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000350
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000351 if (GetSaveFileName(&saveas)) {
352 SetFileName(szPath);
353 UpdateWindowCaption();
354 DoSaveFile();
Hirofumi Katayama32b6a1a2008-09-09 12:44:36 +0900355 return TRUE;
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000356 }
Hirofumi Katayama32b6a1a2008-09-09 12:44:36 +0900357 return FALSE;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000358}
359
Rolf Kalbermatter5eb6c112007-04-06 19:50:37 +0200360typedef struct {
361 LPWSTR mptr;
362 LPWSTR mend;
363 LPWSTR lptr;
364 DWORD len;
365} TEXTINFO, *LPTEXTINFO;
366
367static int notepad_print_header(HDC hdc, RECT *rc, BOOL dopage, BOOL header, int page, LPWSTR text)
368{
369 SIZE szMetric;
370
371 if (*text)
372 {
373 /* Write the header or footer */
374 GetTextExtentPoint32(hdc, text, lstrlen(text), &szMetric);
375 if (dopage)
376 ExtTextOut(hdc, (rc->left + rc->right - szMetric.cx) / 2,
377 header ? rc->top : rc->bottom - szMetric.cy,
378 ETO_CLIPPED, rc, text, lstrlen(text), NULL);
379 return 1;
380 }
381 return 0;
382}
383
384static BOOL notepad_print_page(HDC hdc, RECT *rc, BOOL dopage, int page, LPTEXTINFO tInfo)
385{
386 int b, y;
387 TEXTMETRIC tm;
388 SIZE szMetrics;
389
390 if (dopage)
391 {
392 if (StartPage(hdc) <= 0)
393 {
394 static const WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
395 static const WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
396 MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION);
397 return FALSE;
398 }
399 }
400
401 GetTextMetrics(hdc, &tm);
402 y = rc->top + notepad_print_header(hdc, rc, dopage, TRUE, page, Globals.szFileName) * tm.tmHeight;
403 b = rc->bottom - 2 * notepad_print_header(hdc, rc, FALSE, FALSE, page, Globals.szFooter) * tm.tmHeight;
404
405 do {
406 INT m, n;
407
408 if (!tInfo->len)
409 {
410 /* find the end of the line */
411 while (tInfo->mptr < tInfo->mend && *tInfo->mptr != '\n' && *tInfo->mptr != '\r')
412 {
413 if (*tInfo->mptr == '\t')
414 {
415 /* replace tabs with spaces */
416 for (m = 0; m < SPACES_IN_TAB; m++)
417 {
418 if (tInfo->len < PRINT_LEN_MAX)
419 tInfo->lptr[tInfo->len++] = ' ';
420 else if (Globals.bWrapLongLines)
421 break;
422 }
423 }
424 else if (tInfo->len < PRINT_LEN_MAX)
425 tInfo->lptr[tInfo->len++] = *tInfo->mptr;
426
427 if (tInfo->len >= PRINT_LEN_MAX && Globals.bWrapLongLines)
428 break;
429
430 tInfo->mptr++;
431 }
432 }
433
434 /* Find out how much we should print if line wrapping is enabled */
435 if (Globals.bWrapLongLines)
436 {
437 GetTextExtentExPoint(hdc, tInfo->lptr, tInfo->len, rc->right - rc->left, &n, NULL, &szMetrics);
438 if (n < tInfo->len && tInfo->lptr[n] != ' ')
439 {
440 m = n;
441 /* Don't wrap words unless it's a single word over the entire line */
442 while (m && tInfo->lptr[m] != ' ') m--;
443 if (m > 0) n = m + 1;
444 }
445 }
446 else
447 n = tInfo->len;
448
449 if (dopage)
450 ExtTextOut(hdc, rc->left, y, ETO_CLIPPED, rc, tInfo->lptr, n, NULL);
451
452 tInfo->len -= n;
453
454 if (tInfo->len)
455 {
456 memcpy(tInfo->lptr, tInfo->lptr + n, tInfo->len * sizeof(WCHAR));
457 y += tm.tmHeight + tm.tmExternalLeading;
458 }
459 else
460 {
461 /* find the next line */
462 while (tInfo->mptr < tInfo->mend && y < b && (*tInfo->mptr == '\n' || *tInfo->mptr == '\r'))
463 {
464 if (*tInfo->mptr == '\n')
465 y += tm.tmHeight + tm.tmExternalLeading;
466 tInfo->mptr++;
467 }
468 }
469 } while (tInfo->mptr < tInfo->mend && y < b);
470
471 notepad_print_header(hdc, rc, dopage, FALSE, page, Globals.szFooter);
472 if (dopage)
473 {
474 EndPage(hdc);
475 }
476 return TRUE;
477}
478
Alexandre Julliard03468f71998-02-15 19:40:49 +0000479VOID DIALOG_FilePrint(VOID)
480{
Duane Clark4eb4c042002-10-21 18:22:15 +0000481 DOCINFO di;
Duane Clark4eb4c042002-10-21 18:22:15 +0000482 PRINTDLG printer;
Rolf Kalbermatter5eb6c112007-04-06 19:50:37 +0200483 int page, dopage, copy;
484 LOGFONT lfFont;
485 HFONT hTextFont, old_font = 0;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000486 DWORD size;
Rolf Kalbermatter5eb6c112007-04-06 19:50:37 +0200487 BOOL ret = FALSE;
488 RECT rc;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000489 LPWSTR pTemp;
Rolf Kalbermatter5eb6c112007-04-06 19:50:37 +0200490 TEXTINFO tInfo;
Duane Clarka60ee9c2006-07-16 16:20:30 -0700491 WCHAR cTemp[PRINT_LEN_MAX];
Marcel Baur03287451999-02-14 11:28:37 +0000492
Duane Clark4eb4c042002-10-21 18:22:15 +0000493 /* Get Current Settings */
494 ZeroMemory(&printer, sizeof(printer));
495 printer.lStructSize = sizeof(printer);
496 printer.hwndOwner = Globals.hMainWnd;
Robert Shearman8be66cb2005-12-08 11:57:58 +0100497 printer.hDevMode = Globals.hDevMode;
498 printer.hDevNames = Globals.hDevNames;
Duane Clark4eb4c042002-10-21 18:22:15 +0000499 printer.hInstance = Globals.hInstance;
Rolf Kalbermatter5eb6c112007-04-06 19:50:37 +0200500
Duane Clark4eb4c042002-10-21 18:22:15 +0000501 /* Set some default flags */
Duane Clarka60ee9c2006-07-16 16:20:30 -0700502 printer.Flags = PD_RETURNDC | PD_NOSELECTION;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000503 printer.nFromPage = 0;
Duane Clark4eb4c042002-10-21 18:22:15 +0000504 printer.nMinPage = 1;
505 /* we really need to calculate number of pages to set nMaxPage and nToPage */
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000506 printer.nToPage = 0;
507 printer.nMaxPage = -1;
Duane Clark4eb4c042002-10-21 18:22:15 +0000508 /* Let commdlg manage copy settings */
509 printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
Marcel Baur03287451999-02-14 11:28:37 +0000510
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000511 if (!PrintDlg(&printer)) return;
Marcel Baur03287451999-02-14 11:28:37 +0000512
Robert Shearman8be66cb2005-12-08 11:57:58 +0100513 Globals.hDevMode = printer.hDevMode;
514 Globals.hDevNames = printer.hDevNames;
515
Rolf Kalbermatter5eb6c112007-04-06 19:50:37 +0200516 SetMapMode(printer.hDC, MM_TEXT);
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000517
Duane Clark4eb4c042002-10-21 18:22:15 +0000518 /* initialize DOCINFO */
519 di.cbSize = sizeof(DOCINFO);
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000520 di.lpszDocName = Globals.szFileTitle;
521 di.lpszOutput = NULL;
522 di.lpszDatatype = NULL;
Duane Clark4eb4c042002-10-21 18:22:15 +0000523 di.fwType = 0;
Marcel Baur03287451999-02-14 11:28:37 +0000524
Duane Clark4eb4c042002-10-21 18:22:15 +0000525 /* Get the file text */
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000526 size = GetWindowTextLength(Globals.hEdit) + 1;
527 pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
Duane Clark4eb4c042002-10-21 18:22:15 +0000528 if (!pTemp)
529 {
Rolf Kalbermatter5eb6c112007-04-06 19:50:37 +0200530 DeleteDC(printer.hDC);
531 ShowLastError();
532 return;
Duane Clark4eb4c042002-10-21 18:22:15 +0000533 }
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000534 size = GetWindowText(Globals.hEdit, pTemp, size);
Marcel Baur03287451999-02-14 11:28:37 +0000535
Rolf Kalbermatter5eb6c112007-04-06 19:50:37 +0200536 if (StartDoc(printer.hDC, &di) > 0)
537 {
538 /* Get the page margins in pixels. */
539 rc.top = MulDiv(Globals.iMarginTop, GetDeviceCaps(printer.hDC, LOGPIXELSY), 2540) -
540 GetDeviceCaps(printer.hDC, PHYSICALOFFSETY);
541 rc.bottom = GetDeviceCaps(printer.hDC, PHYSICALHEIGHT) -
542 MulDiv(Globals.iMarginBottom, GetDeviceCaps(printer.hDC, LOGPIXELSY), 2540);
543 rc.left = MulDiv(Globals.iMarginLeft, GetDeviceCaps(printer.hDC, LOGPIXELSX), 2540) -
544 GetDeviceCaps(printer.hDC, PHYSICALOFFSETX);
545 rc.right = GetDeviceCaps(printer.hDC, PHYSICALWIDTH) -
546 MulDiv(Globals.iMarginRight, GetDeviceCaps(printer.hDC, LOGPIXELSX), 2540);
547
548 /* Create a font for the printer resolution */
549 lfFont = Globals.lfFont;
550 lfFont.lfHeight = MulDiv(lfFont.lfHeight, GetDeviceCaps(printer.hDC, LOGPIXELSY), get_dpi());
551 /* Make the font a bit lighter */
552 lfFont.lfWeight -= 100;
553 hTextFont = CreateFontIndirect(&lfFont);
554 old_font = SelectObject(printer.hDC, hTextFont);
555
556 for (copy = 1; copy <= printer.nCopies; copy++)
557 {
558 page = 1;
559
560 tInfo.mptr = pTemp;
561 tInfo.mend = pTemp + size;
562 tInfo.lptr = cTemp;
563 tInfo.len = 0;
564
565 do {
566 if (printer.Flags & PD_PAGENUMS)
567 {
568 /* a specific range of pages is selected, so
569 * skip pages that are not to be printed
570 */
571 if (page > printer.nToPage)
572 break;
573 else if (page >= printer.nFromPage)
574 dopage = 1;
575 else
576 dopage = 0;
577 }
578 else
579 dopage = 1;
580
581 ret = notepad_print_page(printer.hDC, &rc, dopage, page, &tInfo);
582 page++;
583 } while (ret && tInfo.mptr < tInfo.mend);
584
585 if (!ret) break;
586 }
587 EndDoc(printer.hDC);
588 SelectObject(printer.hDC, old_font);
589 DeleteObject(hTextFont);
590 }
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000591 DeleteDC(printer.hDC);
Michael Stefaniuc81a7aad2003-09-27 02:25:21 +0000592 HeapFree(GetProcessHeap(), 0, pTemp);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000593}
594
595VOID DIALOG_FilePrinterSetup(VOID)
596{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000597 PRINTDLG printer;
Marcel Baur03287451999-02-14 11:28:37 +0000598
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000599 ZeroMemory(&printer, sizeof(printer));
600 printer.lStructSize = sizeof(printer);
601 printer.hwndOwner = Globals.hMainWnd;
Robert Shearman8be66cb2005-12-08 11:57:58 +0100602 printer.hDevMode = Globals.hDevMode;
603 printer.hDevNames = Globals.hDevNames;
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000604 printer.hInstance = Globals.hInstance;
605 printer.Flags = PD_PRINTSETUP;
606 printer.nCopies = 1;
Vincent Béron9a624912002-05-31 23:06:46 +0000607
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000608 PrintDlg(&printer);
Robert Shearman8be66cb2005-12-08 11:57:58 +0100609
610 Globals.hDevMode = printer.hDevMode;
611 Globals.hDevNames = printer.hDevNames;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000612}
613
614VOID DIALOG_FileExit(VOID)
615{
Andriy Palamarchuk83ad8862002-07-16 01:09:24 +0000616 PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000617}
618
619VOID DIALOG_EditUndo(VOID)
620{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000621 SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000622}
623
624VOID DIALOG_EditCut(VOID)
625{
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000626 SendMessage(Globals.hEdit, WM_CUT, 0, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000627}
628
629VOID DIALOG_EditCopy(VOID)
630{
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000631 SendMessage(Globals.hEdit, WM_COPY, 0, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000632}
633
634VOID DIALOG_EditPaste(VOID)
635{
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000636 SendMessage(Globals.hEdit, WM_PASTE, 0, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000637}
638
639VOID DIALOG_EditDelete(VOID)
640{
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000641 SendMessage(Globals.hEdit, WM_CLEAR, 0, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000642}
643
644VOID DIALOG_EditSelectAll(VOID)
645{
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000646 SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000647}
648
649VOID DIALOG_EditTimeDate(VOID)
650{
Marcel Baur03287451999-02-14 11:28:37 +0000651 SYSTEMTIME st;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000652 WCHAR szDate[MAX_STRING_LEN];
653 static const WCHAR spaceW[] = { ' ',0 };
Vincent Béron9a624912002-05-31 23:06:46 +0000654
Marcel Baur03287451999-02-14 11:28:37 +0000655 GetLocalTime(&st);
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000656
657 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN);
658 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
659
660 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)spaceW);
661
662 GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szDate, MAX_STRING_LEN);
663 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000664}
665
666VOID DIALOG_EditWrap(VOID)
667{
Byeong-Sik Jeon53a48942006-09-16 09:43:07 +0900668 BOOL modify = FALSE;
Lauri Tulmina1186032005-02-14 11:51:27 +0000669 static const WCHAR editW[] = { 'e','d','i','t',0 };
670 DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
671 ES_AUTOVSCROLL | ES_MULTILINE;
672 RECT rc;
673 DWORD size;
674 LPWSTR pTemp;
675
676 size = GetWindowTextLength(Globals.hEdit) + 1;
677 pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
678 if (!pTemp)
679 {
680 ShowLastError();
681 return;
682 }
683 GetWindowText(Globals.hEdit, pTemp, size);
Byeong-Sik Jeon53a48942006-09-16 09:43:07 +0900684 modify = SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0);
Lauri Tulmina1186032005-02-14 11:51:27 +0000685 DestroyWindow(Globals.hEdit);
686 GetClientRect(Globals.hMainWnd, &rc);
687 if( Globals.bWrapLongLines ) dwStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
688 Globals.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, editW, NULL, dwStyle,
689 0, 0, rc.right, rc.bottom, Globals.hMainWnd,
690 NULL, Globals.hInstance, NULL);
691 SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)FALSE);
692 SetWindowTextW(Globals.hEdit, pTemp);
Byeong-Sik Jeon53a48942006-09-16 09:43:07 +0900693 SendMessage(Globals.hEdit, EM_SETMODIFY, (WPARAM)modify, 0);
Lauri Tulmina1186032005-02-14 11:51:27 +0000694 SetFocus(Globals.hEdit);
695 HeapFree(GetProcessHeap(), 0, pTemp);
696
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000697 Globals.bWrapLongLines = !Globals.bWrapLongLines;
698 CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
699 MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
Alexandre Julliard03468f71998-02-15 19:40:49 +0000700}
701
Shachar Shemeshfc0d07f2003-01-28 01:10:28 +0000702VOID DIALOG_SelectFont(VOID)
703{
704 CHOOSEFONT cf;
705 LOGFONT lf=Globals.lfFont;
706
707 ZeroMemory( &cf, sizeof(cf) );
708 cf.lStructSize=sizeof(cf);
709 cf.hwndOwner=Globals.hMainWnd;
710 cf.lpLogFont=&lf;
Pavel Roskin5f5418a2005-12-01 12:35:13 +0100711 cf.Flags=CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
Shachar Shemeshfc0d07f2003-01-28 01:10:28 +0000712
713 if( ChooseFont(&cf) )
714 {
715 HFONT currfont=Globals.hFont;
716
717 Globals.hFont=CreateFontIndirect( &lf );
718 Globals.lfFont=lf;
719 SendMessage( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE );
720 if( currfont!=NULL )
721 DeleteObject( currfont );
722 }
723}
724
Alexandre Julliard03468f71998-02-15 19:40:49 +0000725VOID DIALOG_Search(VOID)
726{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000727 ZeroMemory(&Globals.find, sizeof(Globals.find));
Marcel Baur03287451999-02-14 11:28:37 +0000728 Globals.find.lStructSize = sizeof(Globals.find);
729 Globals.find.hwndOwner = Globals.hMainWnd;
730 Globals.find.hInstance = Globals.hInstance;
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000731 Globals.find.lpstrFindWhat = Globals.szFindText;
732 Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText);
Mikołaj Zalewski84fc75c2006-10-22 18:58:12 +0200733 Globals.find.Flags = FR_DOWN|FR_HIDEWHOLEWORD;
Marcel Baura43295d1998-10-18 14:11:42 +0000734
Marcel Baur03287451999-02-14 11:28:37 +0000735 /* We only need to create the modal FindReplace dialog which will */
736 /* notify us of incoming events using hMainWnd Window Messages */
Alexandre Julliard54c27111998-03-29 19:44:57 +0000737
Marcel Baur03287451999-02-14 11:28:37 +0000738 Globals.hFindReplaceDlg = FindText(&Globals.find);
739 assert(Globals.hFindReplaceDlg !=0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000740}
741
742VOID DIALOG_SearchNext(VOID)
743{
Mikołaj Zalewski84fc75c2006-10-22 18:58:12 +0200744 if (Globals.lastFind.lpstrFindWhat == NULL)
745 DIALOG_Search();
746 else /* use the last find data */
747 NOTEPAD_DoFind(&Globals.lastFind);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000748}
749
750VOID DIALOG_HelpContents(VOID)
751{
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000752 WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000753}
754
755VOID DIALOG_HelpSearch(VOID)
756{
Marcel Baur03287451999-02-14 11:28:37 +0000757 /* Search Help */
Alexandre Julliard03468f71998-02-15 19:40:49 +0000758}
759
760VOID DIALOG_HelpHelp(VOID)
761{
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000762 WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000763}
764
Rob Shearman90efadc2008-03-28 17:53:31 +0000765VOID DIALOG_HelpAboutNotepad(VOID)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000766{
Alexandre Julliard247754f2008-03-21 18:39:31 +0100767 static const WCHAR notepadW[] = { 'W','i','n','e',' ','N','o','t','e','p','a','d',0 };
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000768 WCHAR szNotepad[MAX_STRING_LEN];
Alexandre Julliard247754f2008-03-21 18:39:31 +0100769 HICON icon = LoadImageW( Globals.hInstance, MAKEINTRESOURCE(IDI_NOTEPAD),
770 IMAGE_ICON, 48, 48, LR_SHARED );
Marcel Baur03287451999-02-14 11:28:37 +0000771
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000772 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
Alexander Nicolaysen Sørnes29b69c52007-08-25 18:26:15 +0200773 ShellAbout(Globals.hMainWnd, szNotepad, notepadW, icon);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000774}
775
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000776
Alexandre Julliard03468f71998-02-15 19:40:49 +0000777/***********************************************************************
778 *
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000779 * DIALOG_FilePageSetup
Alexandre Julliard03468f71998-02-15 19:40:49 +0000780 */
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000781VOID DIALOG_FilePageSetup(void)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000782{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000783 DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000784 Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000785}
786
Alexandre Julliard03468f71998-02-15 19:40:49 +0000787
788/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
789 *
790 * DIALOG_PAGESETUP_DlgProc
791 */
792
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000793static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000794{
Marcel Baur03287451999-02-14 11:28:37 +0000795
796 switch (msg)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000797 {
798 case WM_COMMAND:
799 switch (wParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000800 {
801 case IDOK:
Marcel Baur03287451999-02-14 11:28:37 +0000802 /* save user input and close dialog */
Rolf Kalbermatter3cae9202007-04-01 20:52:08 +0200803 GetDlgItemText(hDlg, IDC_PAGESETUP_HEADERVALUE, Globals.szHeader, SIZEOF(Globals.szHeader));
804 GetDlgItemText(hDlg, IDC_PAGESETUP_FOOTERVALUE, Globals.szFooter, SIZEOF(Globals.szFooter));
805
806 Globals.iMarginTop = GetDlgItemInt(hDlg, IDC_PAGESETUP_TOPVALUE, NULL, FALSE) * 100;
807 Globals.iMarginBottom = GetDlgItemInt(hDlg, IDC_PAGESETUP_BOTTOMVALUE, NULL, FALSE) * 100;
808 Globals.iMarginLeft = GetDlgItemInt(hDlg, IDC_PAGESETUP_LEFTVALUE, NULL, FALSE) * 100;
809 Globals.iMarginRight = GetDlgItemInt(hDlg, IDC_PAGESETUP_RIGHTVALUE, NULL, FALSE) * 100;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000810 EndDialog(hDlg, IDOK);
811 return TRUE;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000812
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000813 case IDCANCEL:
Marcel Baur03287451999-02-14 11:28:37 +0000814 /* discard user input and close dialog */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000815 EndDialog(hDlg, IDCANCEL);
816 return TRUE;
Marcel Baur03287451999-02-14 11:28:37 +0000817
818 case IDHELP:
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000819 {
Marcel Baur03287451999-02-14 11:28:37 +0000820 /* FIXME: Bring this to work */
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000821 static const WCHAR sorryW[] = { 'S','o','r','r','y',',',' ','n','o',' ','h','e','l','p',' ','a','v','a','i','l','a','b','l','e',0 };
822 static const WCHAR helpW[] = { 'H','e','l','p',0 };
823 MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION);
Marcel Baur03287451999-02-14 11:28:37 +0000824 return TRUE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000825 }
Dmitry Timoshkov398af162003-07-21 20:05:33 +0000826
827 default:
828 break;
829 }
Marcel Baura43295d1998-10-18 14:11:42 +0000830 break;
831
832 case WM_INITDIALOG:
Marcel Baur03287451999-02-14 11:28:37 +0000833 /* fetch last user input prior to display dialog */
Rolf Kalbermatter3cae9202007-04-01 20:52:08 +0200834 SetDlgItemText(hDlg, IDC_PAGESETUP_HEADERVALUE, Globals.szHeader);
835 SetDlgItemText(hDlg, IDC_PAGESETUP_FOOTERVALUE, Globals.szFooter);
836 SetDlgItemInt(hDlg, IDC_PAGESETUP_TOPVALUE, Globals.iMarginTop / 100, FALSE);
837 SetDlgItemInt(hDlg, IDC_PAGESETUP_BOTTOMVALUE, Globals.iMarginBottom / 100, FALSE);
838 SetDlgItemInt(hDlg, IDC_PAGESETUP_LEFTVALUE, Globals.iMarginLeft / 100, FALSE);
839 SetDlgItemInt(hDlg, IDC_PAGESETUP_RIGHTVALUE, Globals.iMarginRight / 100, FALSE);
Marcel Baura43295d1998-10-18 14:11:42 +0000840 break;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000841 }
Marcel Baur03287451999-02-14 11:28:37 +0000842
Alexandre Julliard03468f71998-02-15 19:40:49 +0000843 return FALSE;
844}