Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 1 | /* |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 2 | * Notepad (dialog.c) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 3 | * |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 4 | * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch> |
Sylvain Petreolle | eaa8df6 | 2002-03-20 22:55:46 +0000 | [diff] [blame] | 5 | * Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr> |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 6 | * Copyright 2002 Andriy Palamarchuk |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 23 | #define UNICODE |
| 24 | |
Ulrich Weigand | 97d05c8 | 2000-01-29 22:07:03 +0000 | [diff] [blame] | 25 | #include <assert.h> |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 27 | #include <windows.h> |
| 28 | #include <commdlg.h> |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 29 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 30 | #include "main.h" |
| 31 | #include "license.h" |
| 32 | #include "dialog.h" |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 33 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 34 | static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 }; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 35 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 36 | static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 37 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 38 | VOID ShowLastError(void) |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 39 | { |
| 40 | DWORD error = GetLastError(); |
| 41 | if (error != NO_ERROR) |
| 42 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 43 | LPWSTR lpMsgBuf; |
| 44 | WCHAR szTitle[MAX_STRING_LEN]; |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 45 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 46 | LoadString(Globals.hInstance, STRING_ERROR, szTitle, SIZEOF(szTitle)); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 47 | FormatMessage( |
| 48 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
| 49 | NULL, error, 0, |
| 50 | (LPTSTR) &lpMsgBuf, 0, NULL); |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 51 | MessageBox(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 52 | LocalFree(lpMsgBuf); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Sets the caption of the main window according to Globals.szFileTitle: |
| 58 | * Notepad - (untitled) if no file is open |
| 59 | * Notepad - [filename] if a file is given |
| 60 | */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 61 | static void UpdateWindowCaption(void) |
| 62 | { |
| 63 | WCHAR szCaption[MAX_STRING_LEN]; |
| 64 | WCHAR szUntitled[MAX_STRING_LEN]; |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 65 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 66 | LoadString(Globals.hInstance, STRING_NOTEPAD, szCaption, SIZEOF(szCaption)); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 67 | |
| 68 | if (Globals.szFileTitle[0] != '\0') { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 69 | static const WCHAR bracket_lW[] = { ' ','-',' ','[',0 }; |
| 70 | static const WCHAR bracket_rW[] = { ']',0 }; |
| 71 | lstrcat(szCaption, bracket_lW); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 72 | lstrcat(szCaption, Globals.szFileTitle); |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 73 | lstrcat(szCaption, bracket_rW); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 74 | } |
| 75 | else |
| 76 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 77 | static const WCHAR hyphenW[] = { ' ','-',' ',0 }; |
| 78 | LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled)); |
| 79 | lstrcat(szCaption, hyphenW); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 80 | lstrcat(szCaption, szUntitled); |
| 81 | } |
| 82 | |
| 83 | SetWindowText(Globals.hMainWnd, szCaption); |
| 84 | } |
| 85 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 86 | static void AlertFileNotFound(LPCWSTR szFileName) |
| 87 | { |
| 88 | WCHAR szMessage[MAX_STRING_LEN]; |
| 89 | WCHAR szResource[MAX_STRING_LEN]; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 90 | |
| 91 | /* Load and format szMessage */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 92 | LoadString(Globals.hInstance, STRING_NOTFOUND, szResource, SIZEOF(szResource)); |
| 93 | wsprintf(szMessage, szResource, szFileName); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 94 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 95 | /* Load szCaption */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 96 | LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource)); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 97 | |
| 98 | /* Display Modal Dialog */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 99 | MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 102 | static int AlertFileNotSaved(LPCWSTR szFileName) |
| 103 | { |
| 104 | WCHAR szMessage[MAX_STRING_LEN]; |
| 105 | WCHAR szResource[MAX_STRING_LEN]; |
| 106 | WCHAR szUntitled[MAX_STRING_LEN]; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 107 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 108 | LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled)); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 109 | |
| 110 | /* Load and format Message */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 111 | LoadString(Globals.hInstance, STRING_NOTSAVED, szResource, SIZEOF(szResource)); |
| 112 | wsprintf(szMessage, szResource, szFileName[0] ? szFileName : szUntitled); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 113 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 114 | /* Load Caption */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 115 | LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource)); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 116 | |
| 117 | /* Display modal */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 118 | return MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION|MB_YESNOCANCEL); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 121 | /** |
| 122 | * Returns: |
| 123 | * TRUE - if file exists |
| 124 | * FALSE - if file does not exist |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 125 | */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 126 | BOOL FileExists(LPCWSTR szFilename) |
| 127 | { |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 128 | WIN32_FIND_DATA entry; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 129 | HANDLE hFile; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 130 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 131 | hFile = FindFirstFile(szFilename, &entry); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 132 | FindClose(hFile); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 133 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 134 | return (hFile != INVALID_HANDLE_VALUE); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 137 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 138 | static VOID DoSaveFile(VOID) |
| 139 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 140 | HANDLE hFile; |
| 141 | DWORD dwNumWrite; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 142 | LPSTR pTemp; |
| 143 | DWORD size; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 144 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 145 | hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE, |
| 146 | NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 147 | if(hFile == INVALID_HANDLE_VALUE) |
| 148 | { |
| 149 | ShowLastError(); |
| 150 | return; |
| 151 | } |
| 152 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 153 | size = GetWindowTextLengthA(Globals.hEdit) + 1; |
| 154 | pTemp = HeapAlloc(GetProcessHeap(), 0, size); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 155 | if (!pTemp) |
| 156 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 157 | CloseHandle(hFile); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 158 | ShowLastError(); |
| 159 | return; |
| 160 | } |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 161 | size = GetWindowTextA(Globals.hEdit, pTemp, size); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 162 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 163 | if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL)) |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 164 | ShowLastError(); |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 165 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 166 | CloseHandle(hFile); |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 167 | HeapFree(GetProcessHeap(), 0, pTemp); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 170 | /** |
| 171 | * Returns: |
| 172 | * TRUE - User agreed to close (both save/don't save) |
| 173 | * FALSE - User cancelled close by selecting "Cancel" |
| 174 | */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 175 | BOOL DoCloseFile(void) |
| 176 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 177 | int nResult; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 178 | static const WCHAR empty_strW[] = { 0 }; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 179 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 180 | if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0)) |
| 181 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 182 | /* prompt user to save changes */ |
| 183 | nResult = AlertFileNotSaved(Globals.szFileName); |
| 184 | switch (nResult) { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 185 | case IDYES: DIALOG_FileSave(); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 186 | break; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 187 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 188 | case IDNO: break; |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 189 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 190 | case IDCANCEL: return(FALSE); |
| 191 | break; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 192 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 193 | default: return(FALSE); |
| 194 | break; |
| 195 | } /* switch */ |
| 196 | } /* if */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 197 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 198 | SetFileName(empty_strW); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 199 | |
| 200 | UpdateWindowCaption(); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 201 | return(TRUE); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 205 | void DoOpenFile(LPCWSTR szFileName) |
| 206 | { |
| 207 | HANDLE hFile; |
| 208 | LPSTR pTemp; |
| 209 | DWORD size; |
| 210 | DWORD dwNumRead; |
| 211 | |
Marcus Meissner | 73458b0 | 1998-12-26 12:54:29 +0000 | [diff] [blame] | 212 | /* Close any files and prompt to save changes */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 213 | if (!DoCloseFile()) |
| 214 | return; |
| 215 | |
| 216 | hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, |
| 217 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 218 | if(hFile == INVALID_HANDLE_VALUE) |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 219 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 220 | ShowLastError(); |
| 221 | return; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 222 | } |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 223 | |
| 224 | size = GetFileSize(hFile, NULL); |
| 225 | if (size == 0xFFFFFFFF) |
| 226 | { |
| 227 | CloseHandle(hFile); |
| 228 | ShowLastError(); |
| 229 | return; |
| 230 | } |
| 231 | size++; |
| 232 | |
| 233 | pTemp = HeapAlloc(GetProcessHeap(), 0, size); |
| 234 | if (!pTemp) |
| 235 | { |
| 236 | CloseHandle(hFile); |
| 237 | ShowLastError(); |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL)) |
| 242 | { |
| 243 | CloseHandle(hFile); |
| 244 | HeapFree(GetProcessHeap(), 0, pTemp); |
| 245 | ShowLastError(); |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | CloseHandle(hFile); |
| 250 | pTemp[dwNumRead] = 0; |
| 251 | |
| 252 | if (IsTextUnicode(pTemp, dwNumRead, NULL)) |
| 253 | { |
| 254 | LPWSTR p = (LPWSTR)pTemp; |
| 255 | /* We need to strip BOM Unicode character, SetWindowTextW won't do it for us. */ |
| 256 | if (*p == 0xFEFF || *p == 0xFFFE) p++; |
| 257 | SetWindowTextW(Globals.hEdit, p); |
| 258 | } |
| 259 | else |
| 260 | SetWindowTextA(Globals.hEdit, pTemp); |
| 261 | |
| 262 | HeapFree(GetProcessHeap(), 0, pTemp); |
| 263 | |
| 264 | SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0); |
| 265 | SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0); |
| 266 | SetFocus(Globals.hEdit); |
| 267 | |
| 268 | SetFileName(szFileName); |
| 269 | UpdateWindowCaption(); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 272 | VOID DIALOG_FileNew(VOID) |
| 273 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 274 | static const WCHAR empty_strW[] = { 0 }; |
| 275 | |
Marcus Meissner | 73458b0 | 1998-12-26 12:54:29 +0000 | [diff] [blame] | 276 | /* Close any files and promt to save changes */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 277 | if (DoCloseFile()) { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 278 | SetWindowText(Globals.hEdit, empty_strW); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 279 | SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0); |
| 280 | SetFocus(Globals.hEdit); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 281 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | VOID DIALOG_FileOpen(VOID) |
| 285 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 286 | OPENFILENAME openfilename; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 287 | WCHAR szPath[MAX_PATH]; |
| 288 | WCHAR szDir[MAX_PATH]; |
| 289 | static const WCHAR szDefaultExt[] = { 't','x','t',0 }; |
| 290 | static const WCHAR txt_files[] = { '*','.','t','x','t',0 }; |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 291 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 292 | ZeroMemory(&openfilename, sizeof(openfilename)); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 293 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 294 | GetCurrentDirectory(SIZEOF(szDir), szDir); |
| 295 | lstrcpy(szPath, txt_files); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 296 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 297 | openfilename.lStructSize = sizeof(openfilename); |
| 298 | openfilename.hwndOwner = Globals.hMainWnd; |
| 299 | openfilename.hInstance = Globals.hInstance; |
| 300 | openfilename.lpstrFilter = Globals.szFilter; |
| 301 | openfilename.lpstrFile = szPath; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 302 | openfilename.nMaxFile = SIZEOF(szPath); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 303 | openfilename.lpstrInitialDir = szDir; |
| 304 | openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | |
| 305 | OFN_HIDEREADONLY; |
| 306 | openfilename.lpstrDefExt = szDefaultExt; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 307 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 308 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 309 | if (GetOpenFileName(&openfilename)) { |
| 310 | if (FileExists(openfilename.lpstrFile)) |
| 311 | DoOpenFile(openfilename.lpstrFile); |
| 312 | else |
| 313 | AlertFileNotFound(openfilename.lpstrFile); |
| 314 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 317 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 318 | VOID DIALOG_FileSave(VOID) |
| 319 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 320 | if (Globals.szFileName[0] == '\0') |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 321 | DIALOG_FileSaveAs(); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 322 | else |
| 323 | DoSaveFile(); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | VOID DIALOG_FileSaveAs(VOID) |
| 327 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 328 | OPENFILENAME saveas; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 329 | WCHAR szPath[MAX_PATH]; |
| 330 | WCHAR szDir[MAX_PATH]; |
| 331 | static const WCHAR szDefaultExt[] = { 't','x','t',0 }; |
| 332 | static const WCHAR txt_files[] = { '*','.','t','x','t',0 }; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 333 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 334 | ZeroMemory(&saveas, sizeof(saveas)); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 335 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 336 | GetCurrentDirectory(SIZEOF(szDir), szDir); |
| 337 | lstrcpy(szPath, txt_files); |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 338 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 339 | saveas.lStructSize = sizeof(OPENFILENAME); |
| 340 | saveas.hwndOwner = Globals.hMainWnd; |
| 341 | saveas.hInstance = Globals.hInstance; |
| 342 | saveas.lpstrFilter = Globals.szFilter; |
| 343 | saveas.lpstrFile = szPath; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 344 | saveas.nMaxFile = SIZEOF(szPath); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 345 | saveas.lpstrInitialDir = szDir; |
| 346 | saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | |
| 347 | OFN_HIDEREADONLY; |
| 348 | saveas.lpstrDefExt = szDefaultExt; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 349 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 350 | if (GetSaveFileName(&saveas)) { |
| 351 | SetFileName(szPath); |
| 352 | UpdateWindowCaption(); |
| 353 | DoSaveFile(); |
| 354 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | VOID DIALOG_FilePrint(VOID) |
| 358 | { |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 359 | DOCINFO di; |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 360 | PRINTDLG printer; |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 361 | SIZE szMetric; |
| 362 | int cWidthPels, cHeightPels, border; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 363 | int xLeft, yTop, i, pagecount, dopage, copycount; |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 364 | LOGFONT hdrFont; |
| 365 | HFONT font, old_font=0; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 366 | DWORD size; |
| 367 | LPWSTR pTemp; |
| 368 | static const WCHAR times_new_romanW[] = { 'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0 }; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 369 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 370 | /* Get a small font and print some header info on each page */ |
| 371 | hdrFont.lfHeight = 100; |
| 372 | hdrFont.lfWidth = 0; |
| 373 | hdrFont.lfEscapement = 0; |
| 374 | hdrFont.lfOrientation = 0; |
| 375 | hdrFont.lfWeight = FW_BOLD; |
| 376 | hdrFont.lfItalic = 0; |
| 377 | hdrFont.lfUnderline = 0; |
| 378 | hdrFont.lfStrikeOut = 0; |
| 379 | hdrFont.lfCharSet = ANSI_CHARSET; |
| 380 | hdrFont.lfOutPrecision = OUT_DEFAULT_PRECIS; |
| 381 | hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; |
| 382 | hdrFont.lfQuality = PROOF_QUALITY; |
| 383 | hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 384 | lstrcpy(hdrFont.lfFaceName, times_new_romanW); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 385 | |
| 386 | font = CreateFontIndirect(&hdrFont); |
| 387 | |
| 388 | /* Get Current Settings */ |
| 389 | ZeroMemory(&printer, sizeof(printer)); |
| 390 | printer.lStructSize = sizeof(printer); |
| 391 | printer.hwndOwner = Globals.hMainWnd; |
| 392 | printer.hInstance = Globals.hInstance; |
| 393 | |
| 394 | /* Set some default flags */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 395 | printer.Flags = PD_RETURNDC; |
| 396 | printer.nFromPage = 0; |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 397 | printer.nMinPage = 1; |
| 398 | /* we really need to calculate number of pages to set nMaxPage and nToPage */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 399 | printer.nToPage = 0; |
| 400 | printer.nMaxPage = -1; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 401 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 402 | /* Let commdlg manage copy settings */ |
| 403 | printer.nCopies = (WORD)PD_USEDEVMODECOPIES; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 404 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 405 | if (!PrintDlg(&printer)) return; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 406 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 407 | assert(printer.hDC != 0); |
| 408 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 409 | /* initialize DOCINFO */ |
| 410 | di.cbSize = sizeof(DOCINFO); |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 411 | di.lpszDocName = Globals.szFileTitle; |
| 412 | di.lpszOutput = NULL; |
| 413 | di.lpszDatatype = NULL; |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 414 | di.fwType = 0; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 415 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 416 | if (StartDoc(printer.hDC, &di) <= 0) return; |
| 417 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 418 | /* Get the page dimensions in pixels. */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 419 | cWidthPels = GetDeviceCaps(printer.hDC, HORZRES); |
| 420 | cHeightPels = GetDeviceCaps(printer.hDC, VERTRES); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 421 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 422 | /* Get the file text */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 423 | size = GetWindowTextLength(Globals.hEdit) + 1; |
| 424 | pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 425 | if (!pTemp) |
| 426 | { |
| 427 | ShowLastError(); |
| 428 | return; |
| 429 | } |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 430 | size = GetWindowText(Globals.hEdit, pTemp, size); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 431 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 432 | border = 150; |
| 433 | for (copycount=1; copycount <= printer.nCopies; copycount++) { |
| 434 | i = 0; |
| 435 | pagecount = 1; |
| 436 | do { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 437 | static const WCHAR letterM[] = { 'M',0 }; |
| 438 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 439 | if (pagecount >= printer.nFromPage && |
| 440 | /* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/ |
| 441 | pagecount <= printer.nToPage) |
| 442 | dopage = 1; |
| 443 | else |
| 444 | dopage = 0; |
| 445 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 446 | old_font = SelectObject(printer.hDC, font); |
| 447 | GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 448 | |
| 449 | if (dopage) { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 450 | if (StartPage(printer.hDC) <= 0) { |
| 451 | static const WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 }; |
| 452 | static const WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 }; |
| 453 | MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 454 | return; |
| 455 | } |
| 456 | /* Write a rectangle and header at the top of each page */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 457 | Rectangle(printer.hDC, border, border, cWidthPels-border, border+szMetric.cy*2); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 458 | /* I don't know what's up with this TextOut command. This comes out |
| 459 | kind of mangled. |
| 460 | */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 461 | TextOut(printer.hDC, border*2, border+szMetric.cy/2, Globals.szFileTitle, lstrlen(Globals.szFileTitle)); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | /* The starting point for the main text */ |
| 465 | xLeft = border*2; |
| 466 | yTop = border+szMetric.cy*4; |
| 467 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 468 | SelectObject(printer.hDC, old_font); |
| 469 | GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 470 | |
| 471 | /* Since outputting strings is giving me problems, output the main |
| 472 | text one character at a time. |
| 473 | */ |
| 474 | do { |
| 475 | if (pTemp[i] == '\n') { |
| 476 | xLeft = border*2; |
| 477 | yTop += szMetric.cy; |
| 478 | } |
| 479 | else if (pTemp[i] != '\r') { |
| 480 | if (dopage) |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 481 | TextOut(printer.hDC, xLeft, yTop, &pTemp[i], 1); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 482 | xLeft += szMetric.cx; |
| 483 | } |
| 484 | } while (i++<size && yTop<(cHeightPels-border*2)); |
| 485 | |
| 486 | if (dopage) |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 487 | EndPage(printer.hDC); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 488 | pagecount++; |
| 489 | } while (i<size); |
| 490 | } |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 491 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 492 | EndDoc(printer.hDC); |
| 493 | DeleteDC(printer.hDC); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | VOID DIALOG_FilePrinterSetup(VOID) |
| 497 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 498 | PRINTDLG printer; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 499 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 500 | ZeroMemory(&printer, sizeof(printer)); |
| 501 | printer.lStructSize = sizeof(printer); |
| 502 | printer.hwndOwner = Globals.hMainWnd; |
| 503 | printer.hInstance = Globals.hInstance; |
| 504 | printer.Flags = PD_PRINTSETUP; |
| 505 | printer.nCopies = 1; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 506 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 507 | PrintDlg(&printer); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | VOID DIALOG_FileExit(VOID) |
| 511 | { |
Andriy Palamarchuk | 83ad886 | 2002-07-16 01:09:24 +0000 | [diff] [blame] | 512 | PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | VOID DIALOG_EditUndo(VOID) |
| 516 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 517 | SendMessage(Globals.hEdit, EM_UNDO, 0, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | VOID DIALOG_EditCut(VOID) |
| 521 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 522 | SendMessage(Globals.hEdit, WM_CUT, 0, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | VOID DIALOG_EditCopy(VOID) |
| 526 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 527 | SendMessage(Globals.hEdit, WM_COPY, 0, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | VOID DIALOG_EditPaste(VOID) |
| 531 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 532 | SendMessage(Globals.hEdit, WM_PASTE, 0, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | VOID DIALOG_EditDelete(VOID) |
| 536 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 537 | SendMessage(Globals.hEdit, WM_CLEAR, 0, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | VOID DIALOG_EditSelectAll(VOID) |
| 541 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 542 | SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | VOID DIALOG_EditTimeDate(VOID) |
| 546 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 547 | SYSTEMTIME st; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 548 | WCHAR szDate[MAX_STRING_LEN]; |
| 549 | static const WCHAR spaceW[] = { ' ',0 }; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 550 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 551 | GetLocalTime(&st); |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 552 | |
| 553 | GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN); |
| 554 | SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate); |
| 555 | |
| 556 | SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)spaceW); |
| 557 | |
| 558 | GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szDate, MAX_STRING_LEN); |
| 559 | SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | VOID DIALOG_EditWrap(VOID) |
| 563 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 564 | Globals.bWrapLongLines = !Globals.bWrapLongLines; |
| 565 | CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP, |
| 566 | MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED)); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Shachar Shemesh | fc0d07f | 2003-01-28 01:10:28 +0000 | [diff] [blame] | 569 | VOID DIALOG_SelectFont(VOID) |
| 570 | { |
| 571 | CHOOSEFONT cf; |
| 572 | LOGFONT lf=Globals.lfFont; |
| 573 | |
| 574 | ZeroMemory( &cf, sizeof(cf) ); |
| 575 | cf.lStructSize=sizeof(cf); |
| 576 | cf.hwndOwner=Globals.hMainWnd; |
| 577 | cf.lpLogFont=&lf; |
| 578 | cf.Flags=CF_SCREENFONTS; |
| 579 | |
| 580 | if( ChooseFont(&cf) ) |
| 581 | { |
| 582 | HFONT currfont=Globals.hFont; |
| 583 | |
| 584 | Globals.hFont=CreateFontIndirect( &lf ); |
| 585 | Globals.lfFont=lf; |
| 586 | SendMessage( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE ); |
| 587 | if( currfont!=NULL ) |
| 588 | DeleteObject( currfont ); |
| 589 | } |
| 590 | } |
| 591 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 592 | VOID DIALOG_Search(VOID) |
| 593 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 594 | ZeroMemory(&Globals.find, sizeof(Globals.find)); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 595 | Globals.find.lStructSize = sizeof(Globals.find); |
| 596 | Globals.find.hwndOwner = Globals.hMainWnd; |
| 597 | Globals.find.hInstance = Globals.hInstance; |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 598 | Globals.find.lpstrFindWhat = Globals.szFindText; |
| 599 | Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 600 | Globals.find.Flags = FR_DOWN; |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 601 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 602 | /* We only need to create the modal FindReplace dialog which will */ |
| 603 | /* notify us of incoming events using hMainWnd Window Messages */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 604 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 605 | Globals.hFindReplaceDlg = FindText(&Globals.find); |
| 606 | assert(Globals.hFindReplaceDlg !=0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | VOID DIALOG_SearchNext(VOID) |
| 610 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 611 | /* FIXME: Search Next */ |
| 612 | DIALOG_Search(); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | VOID DIALOG_HelpContents(VOID) |
| 616 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 617 | WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | VOID DIALOG_HelpSearch(VOID) |
| 621 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 622 | /* Search Help */ |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | VOID DIALOG_HelpHelp(VOID) |
| 626 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 627 | WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | VOID DIALOG_HelpLicense(VOID) |
| 631 | { |
Alexandre Julliard | 3da872d | 2000-11-10 01:06:36 +0000 | [diff] [blame] | 632 | WineLicense(Globals.hMainWnd); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | VOID DIALOG_HelpNoWarranty(VOID) |
| 636 | { |
Alexandre Julliard | 3da872d | 2000-11-10 01:06:36 +0000 | [diff] [blame] | 637 | WineWarranty(Globals.hMainWnd); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | VOID DIALOG_HelpAboutWine(VOID) |
| 641 | { |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 642 | static const WCHAR notepadW[] = { 'N','o','t','e','p','a','d','\n',0 }; |
| 643 | WCHAR szNotepad[MAX_STRING_LEN]; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 644 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 645 | LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad)); |
| 646 | ShellAbout(Globals.hMainWnd, szNotepad, notepadW, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 649 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 650 | /*********************************************************************** |
| 651 | * |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 652 | * DIALOG_FilePageSetup |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 653 | */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 654 | VOID DIALOG_FilePageSetup(void) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 655 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 656 | DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP), |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 657 | Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 660 | |
| 661 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 662 | * |
| 663 | * DIALOG_PAGESETUP_DlgProc |
| 664 | */ |
| 665 | |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 666 | static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 667 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 668 | |
| 669 | switch (msg) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 670 | { |
| 671 | case WM_COMMAND: |
| 672 | switch (wParam) |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 673 | { |
| 674 | case IDOK: |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 675 | /* save user input and close dialog */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 676 | GetDlgItemText(hDlg, 0x141, Globals.szHeader, SIZEOF(Globals.szHeader)); |
| 677 | GetDlgItemText(hDlg, 0x143, Globals.szFooter, SIZEOF(Globals.szFooter)); |
| 678 | GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, SIZEOF(Globals.szMarginTop)); |
| 679 | GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, SIZEOF(Globals.szMarginBottom)); |
| 680 | GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, SIZEOF(Globals.szMarginLeft)); |
| 681 | GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, SIZEOF(Globals.szMarginRight)); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 682 | EndDialog(hDlg, IDOK); |
| 683 | return TRUE; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 684 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 685 | case IDCANCEL: |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 686 | /* discard user input and close dialog */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 687 | EndDialog(hDlg, IDCANCEL); |
| 688 | return TRUE; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 689 | |
| 690 | case IDHELP: |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 691 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 692 | /* FIXME: Bring this to work */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 693 | 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 }; |
| 694 | static const WCHAR helpW[] = { 'H','e','l','p',0 }; |
| 695 | MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 696 | return TRUE; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 697 | } |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 698 | |
| 699 | default: |
| 700 | break; |
| 701 | } |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 702 | break; |
| 703 | |
| 704 | case WM_INITDIALOG: |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 705 | /* fetch last user input prior to display dialog */ |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 706 | SetDlgItemText(hDlg, 0x141, Globals.szHeader); |
| 707 | SetDlgItemText(hDlg, 0x143, Globals.szFooter); |
| 708 | SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop); |
Sylvain Petreolle | eaa8df6 | 2002-03-20 22:55:46 +0000 | [diff] [blame] | 709 | SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom); |
Dmitry Timoshkov | 398af16 | 2003-07-21 20:05:33 +0000 | [diff] [blame^] | 710 | SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft); |
| 711 | SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight); |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 712 | break; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 713 | } |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 714 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 715 | return FALSE; |
| 716 | } |