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 | |
Ulrich Weigand | 97d05c8 | 2000-01-29 22:07:03 +0000 | [diff] [blame] | 23 | #include <assert.h> |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 25 | #include <windows.h> |
| 26 | #include <commdlg.h> |
| 27 | #include <winerror.h> |
| 28 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 29 | #include "main.h" |
| 30 | #include "license.h" |
| 31 | #include "dialog.h" |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 32 | |
Alexandre Julliard | 3da872d | 2000-11-10 01:06:36 +0000 | [diff] [blame] | 33 | static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 34 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 35 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 36 | |
Andriy Palamarchuk | 83ad886 | 2002-07-16 01:09:24 +0000 | [diff] [blame] | 37 | VOID ShowLastError() |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 38 | { |
| 39 | DWORD error = GetLastError(); |
| 40 | if (error != NO_ERROR) |
| 41 | { |
| 42 | LPVOID lpMsgBuf; |
| 43 | CHAR szTitle[MAX_STRING_LEN]; |
| 44 | |
| 45 | LoadString(Globals.hInstance, STRING_ERROR, szTitle, sizeof(szTitle)); |
| 46 | FormatMessage( |
| 47 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
| 48 | NULL, error, 0, |
| 49 | (LPTSTR) &lpMsgBuf, 0, NULL); |
| 50 | MessageBox(NULL, (char*)lpMsgBuf, szTitle, MB_OK | MB_ICONERROR); |
| 51 | LocalFree(lpMsgBuf); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Sets the caption of the main window according to Globals.szFileTitle: |
| 57 | * Notepad - (untitled) if no file is open |
| 58 | * Notepad - [filename] if a file is given |
| 59 | */ |
| 60 | void UpdateWindowCaption(void) { |
| 61 | CHAR szCaption[MAX_STRING_LEN]; |
| 62 | CHAR szUntitled[MAX_STRING_LEN]; |
| 63 | |
| 64 | LoadString(Globals.hInstance, STRING_NOTEPAD, szCaption, sizeof(szCaption)); |
| 65 | |
| 66 | if (Globals.szFileTitle[0] != '\0') { |
| 67 | lstrcat(szCaption, " - ["); |
| 68 | lstrcat(szCaption, Globals.szFileTitle); |
| 69 | lstrcat(szCaption, "]"); |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, sizeof(szUntitled)); |
| 74 | lstrcat(szCaption, " - "); |
| 75 | lstrcat(szCaption, szUntitled); |
| 76 | } |
| 77 | |
| 78 | SetWindowText(Globals.hMainWnd, szCaption); |
| 79 | } |
| 80 | |
| 81 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 82 | int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 83 | /* |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 84 | * Given some ids strings, this acts as a language-aware wrapper for |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 85 | * "MessageBox" |
| 86 | */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 87 | CHAR szMessage[MAX_STRING_LEN]; |
| 88 | CHAR szCaption[MAX_STRING_LEN]; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 89 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 90 | LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage)); |
| 91 | LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption)); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 92 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 93 | return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type)); |
| 94 | } |
| 95 | |
Niels Kristian Bech Jensen | 52be93c | 2000-03-19 21:49:49 +0000 | [diff] [blame] | 96 | void AlertFileNotFound(LPSTR szFileName) { |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 97 | |
| 98 | int nResult; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 99 | CHAR szMessage[MAX_STRING_LEN]; |
| 100 | CHAR szRessource[MAX_STRING_LEN]; |
| 101 | |
| 102 | /* Load and format szMessage */ |
Sylvain Petreolle | eaa8df6 | 2002-03-20 22:55:46 +0000 | [diff] [blame] | 103 | LoadString(Globals.hInstance, STRING_NOTFOUND, szRessource, sizeof(szRessource)); |
Mike McCormack | 0e2d0e0 | 2000-07-23 14:22:47 +0000 | [diff] [blame] | 104 | wsprintf(szMessage, szRessource, szFileName); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 105 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 106 | /* Load szCaption */ |
Sylvain Petreolle | eaa8df6 | 2002-03-20 22:55:46 +0000 | [diff] [blame] | 107 | LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource)); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 108 | |
| 109 | /* Display Modal Dialog */ |
| 110 | nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION); |
| 111 | |
| 112 | } |
| 113 | |
Niels Kristian Bech Jensen | 52be93c | 2000-03-19 21:49:49 +0000 | [diff] [blame] | 114 | int AlertFileNotSaved(LPSTR szFileName) { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 115 | |
| 116 | int nResult; |
| 117 | CHAR szMessage[MAX_STRING_LEN]; |
| 118 | CHAR szRessource[MAX_STRING_LEN]; |
| 119 | |
| 120 | /* Load and format Message */ |
| 121 | |
Sylvain Petreolle | eaa8df6 | 2002-03-20 22:55:46 +0000 | [diff] [blame] | 122 | LoadString(Globals.hInstance, STRING_NOTSAVED, szRessource, sizeof(szRessource)); |
Mike McCormack | 0e2d0e0 | 2000-07-23 14:22:47 +0000 | [diff] [blame] | 123 | wsprintf(szMessage, szRessource, szFileName); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 124 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 125 | /* Load Caption */ |
| 126 | |
Sylvain Petreolle | eaa8df6 | 2002-03-20 22:55:46 +0000 | [diff] [blame] | 127 | LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource)); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 128 | |
| 129 | /* Display modal */ |
Andreas Mohr | 1081dfe | 2000-12-09 03:06:54 +0000 | [diff] [blame] | 130 | nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION|MB_YESNOCANCEL); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 131 | return(nResult); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | |
| 135 | VOID AlertOutOfMemory(void) { |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 136 | int nResult; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 137 | |
Sylvain Petreolle | eaa8df6 | 2002-03-20 22:55:46 +0000 | [diff] [blame] | 138 | nResult = AlertIDS(STRING_OUT_OF_MEMORY, STRING_ERROR, MB_ICONEXCLAMATION); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 139 | PostQuitMessage(1); |
| 140 | } |
| 141 | |
| 142 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 143 | /** |
| 144 | * Returns: |
| 145 | * TRUE - if file exists |
| 146 | * FALSE - if file does not exist |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 147 | */ |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 148 | BOOL FileExists(LPSTR szFilename) { |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 149 | WIN32_FIND_DATA entry; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 150 | HANDLE hFile; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 151 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 152 | hFile = FindFirstFile(szFilename, &entry); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 153 | FindClose(hFile); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 154 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 155 | return (hFile != INVALID_HANDLE_VALUE); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 158 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 159 | VOID DoSaveFile(VOID) { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 160 | HANDLE hFile; |
| 161 | DWORD dwNumWrite; |
| 162 | BOOL bTest; |
| 163 | CHAR *pTemp; |
| 164 | int size; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 165 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 166 | hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE, |
| 167 | NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 168 | if(hFile == INVALID_HANDLE_VALUE) |
| 169 | { |
| 170 | ShowLastError(); |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | size = GetWindowTextLength(Globals.hEdit); |
| 175 | pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size); |
| 176 | if (!pTemp) |
| 177 | { |
| 178 | ShowLastError(); |
| 179 | return; |
| 180 | } |
| 181 | GetWindowText(Globals.hEdit, pTemp, size); |
| 182 | |
| 183 | bTest = WriteFile(hFile, pTemp, size, &dwNumWrite, NULL); |
| 184 | if(bTest == FALSE) |
| 185 | { |
| 186 | ShowLastError(); |
| 187 | } |
| 188 | CloseHandle(hFile); |
| 189 | GlobalFree(pTemp); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 192 | /** |
| 193 | * Returns: |
| 194 | * TRUE - User agreed to close (both save/don't save) |
| 195 | * FALSE - User cancelled close by selecting "Cancel" |
| 196 | */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 197 | BOOL DoCloseFile(void) { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 198 | int nResult; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 199 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 200 | if (Globals.szFileName[0] != 0) { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 201 | /* prompt user to save changes */ |
| 202 | nResult = AlertFileNotSaved(Globals.szFileName); |
| 203 | switch (nResult) { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 204 | case IDYES: DIALOG_FileSave(); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 205 | break; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 206 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 207 | case IDNO: break; |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 208 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 209 | case IDCANCEL: return(FALSE); |
| 210 | break; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 211 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 212 | default: return(FALSE); |
| 213 | break; |
| 214 | } /* switch */ |
| 215 | } /* if */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 216 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 217 | SetFileName(""); |
| 218 | |
| 219 | UpdateWindowCaption(); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 220 | return(TRUE); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 224 | void DoOpenFile(LPSTR szFileName) { |
Marcus Meissner | 73458b0 | 1998-12-26 12:54:29 +0000 | [diff] [blame] | 225 | /* Close any files and prompt to save changes */ |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 226 | if (DoCloseFile()) |
| 227 | { |
| 228 | HANDLE hFile; |
| 229 | CHAR *pTemp; |
| 230 | DWORD size; |
| 231 | DWORD dwNumRead; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 232 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 233 | hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, |
| 234 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 235 | if(hFile == INVALID_HANDLE_VALUE) |
| 236 | { |
| 237 | ShowLastError(); |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | size = GetFileSize(hFile, NULL); |
| 242 | if (size == 0xFFFFFFFF) |
| 243 | { |
| 244 | ShowLastError(); |
| 245 | return; |
| 246 | } |
| 247 | size++; |
| 248 | pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size); |
| 249 | if (!pTemp) |
| 250 | { |
| 251 | ShowLastError(); |
| 252 | return; |
| 253 | } |
| 254 | if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL)) |
| 255 | { |
| 256 | ShowLastError(); |
| 257 | return; |
| 258 | } |
| 259 | CloseHandle(hFile); |
| 260 | pTemp[dwNumRead] = '\0'; |
| 261 | if (!SetWindowText(Globals.hEdit, pTemp)) |
| 262 | { |
| 263 | GlobalFree(pTemp); |
| 264 | ShowLastError(); |
| 265 | return; |
| 266 | } |
| 267 | SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0); |
| 268 | GlobalFree(pTemp); |
| 269 | SetFocus(Globals.hEdit); |
| 270 | |
| 271 | SetFileName(szFileName); |
| 272 | UpdateWindowCaption(); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 276 | VOID DIALOG_FileNew(VOID) |
| 277 | { |
Marcus Meissner | 73458b0 | 1998-12-26 12:54:29 +0000 | [diff] [blame] | 278 | /* Close any files and promt to save changes */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 279 | if (DoCloseFile()) { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 280 | SetWindowText(Globals.hEdit, ""); |
| 281 | SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0); |
| 282 | SetFocus(Globals.hEdit); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 283 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | VOID DIALOG_FileOpen(VOID) |
| 287 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 288 | OPENFILENAME openfilename; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 289 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 290 | CHAR szPath[MAX_PATH]; |
| 291 | CHAR szDir[MAX_PATH]; |
| 292 | CHAR szDefaultExt[] = "txt"; |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 293 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 294 | ZeroMemory(&openfilename, sizeof(openfilename)); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 295 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 296 | GetCurrentDirectory(sizeof(szDir), szDir); |
| 297 | lstrcpy(szPath,"*.txt"); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 298 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 299 | openfilename.lStructSize = sizeof(openfilename); |
| 300 | openfilename.hwndOwner = Globals.hMainWnd; |
| 301 | openfilename.hInstance = Globals.hInstance; |
| 302 | openfilename.lpstrFilter = Globals.szFilter; |
| 303 | openfilename.lpstrFile = szPath; |
| 304 | openfilename.nMaxFile = sizeof(szPath); |
| 305 | openfilename.lpstrInitialDir = szDir; |
| 306 | openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | |
| 307 | OFN_HIDEREADONLY; |
| 308 | openfilename.lpstrDefExt = szDefaultExt; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 309 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 310 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 311 | if (GetOpenFileName(&openfilename)) { |
| 312 | if (FileExists(openfilename.lpstrFile)) |
| 313 | DoOpenFile(openfilename.lpstrFile); |
| 314 | else |
| 315 | AlertFileNotFound(openfilename.lpstrFile); |
| 316 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 319 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 320 | VOID DIALOG_FileSave(VOID) |
| 321 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 322 | if (Globals.szFileName[0] == '\0') |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 323 | DIALOG_FileSaveAs(); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 324 | else |
| 325 | DoSaveFile(); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | VOID DIALOG_FileSaveAs(VOID) |
| 329 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 330 | OPENFILENAME saveas; |
| 331 | CHAR szPath[MAX_PATH]; |
| 332 | CHAR szDir[MAX_PATH]; |
| 333 | CHAR szDefaultExt[] = "txt"; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 334 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 335 | ZeroMemory(&saveas, sizeof(saveas)); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 336 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 337 | GetCurrentDirectory(sizeof(szDir), szDir); |
| 338 | lstrcpy(szPath,"*.*"); |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 339 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 340 | saveas.lStructSize = sizeof(OPENFILENAME); |
| 341 | saveas.hwndOwner = Globals.hMainWnd; |
| 342 | saveas.hInstance = Globals.hInstance; |
| 343 | saveas.lpstrFilter = Globals.szFilter; |
| 344 | saveas.lpstrFile = szPath; |
| 345 | saveas.nMaxFile = sizeof(szPath); |
| 346 | saveas.lpstrInitialDir = szDir; |
| 347 | saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | |
| 348 | OFN_HIDEREADONLY; |
| 349 | saveas.lpstrDefExt = szDefaultExt; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 350 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 351 | if (GetSaveFileName(&saveas)) { |
| 352 | SetFileName(szPath); |
| 353 | UpdateWindowCaption(); |
| 354 | DoSaveFile(); |
| 355 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | VOID DIALOG_FilePrint(VOID) |
| 359 | { |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 360 | LONG bFlags; |
| 361 | DOCINFO di; |
| 362 | int nResult; |
| 363 | HDC hContext; |
| 364 | PRINTDLG printer; |
| 365 | char *pDevNamesSpace; |
| 366 | LPDEVNAMES lpDevNames; |
| 367 | SIZE szMetric; |
| 368 | int cWidthPels, cHeightPels, border; |
| 369 | int xLeft, yTop, count, i, pagecount, dopage, copycount; |
| 370 | LOGFONT hdrFont; |
| 371 | HFONT font, old_font=0; |
| 372 | CHAR *pTemp; |
| 373 | int size; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 374 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 375 | CHAR szDocumentName[MAX_STRING_LEN]; /* Name of document */ |
| 376 | CHAR szPrinterName[MAX_STRING_LEN]; /* Name of the printer */ |
| 377 | CHAR szDeviceName[MAX_STRING_LEN]; /* Name of the printer device */ |
| 378 | CHAR szOutput[MAX_STRING_LEN]; /* in which file/device to print */ |
| 379 | |
| 380 | strcpy(szDocumentName, Globals.szFileTitle); |
| 381 | count = strlen(szDocumentName); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 382 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 383 | /* Get a small font and print some header info on each page */ |
| 384 | hdrFont.lfHeight = 100; |
| 385 | hdrFont.lfWidth = 0; |
| 386 | hdrFont.lfEscapement = 0; |
| 387 | hdrFont.lfOrientation = 0; |
| 388 | hdrFont.lfWeight = FW_BOLD; |
| 389 | hdrFont.lfItalic = 0; |
| 390 | hdrFont.lfUnderline = 0; |
| 391 | hdrFont.lfStrikeOut = 0; |
| 392 | hdrFont.lfCharSet = ANSI_CHARSET; |
| 393 | hdrFont.lfOutPrecision = OUT_DEFAULT_PRECIS; |
| 394 | hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; |
| 395 | hdrFont.lfQuality = PROOF_QUALITY; |
| 396 | hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN; |
| 397 | strcpy(hdrFont.lfFaceName, "Times New Roman"); |
| 398 | |
| 399 | font = CreateFontIndirect(&hdrFont); |
| 400 | |
| 401 | /* Get Current Settings */ |
| 402 | ZeroMemory(&printer, sizeof(printer)); |
| 403 | printer.lStructSize = sizeof(printer); |
| 404 | printer.hwndOwner = Globals.hMainWnd; |
| 405 | printer.hInstance = Globals.hInstance; |
| 406 | |
| 407 | /* Set some default flags */ |
| 408 | bFlags = PD_RETURNDC + PD_SHOWHELP; |
| 409 | if (TRUE) { |
| 410 | /* Remove "Print Selection" if there is no selection */ |
| 411 | bFlags = bFlags + PD_NOSELECTION; |
| 412 | } |
| 413 | printer.Flags = bFlags; |
| 414 | printer.nFromPage = 1; |
| 415 | printer.nMinPage = 1; |
| 416 | /* we really need to calculate number of pages to set nMaxPage and nToPage */ |
| 417 | printer.nToPage = 20; |
| 418 | printer.nMaxPage = 20; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 419 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 420 | /* Let commdlg manage copy settings */ |
| 421 | printer.nCopies = (WORD)PD_USEDEVMODECOPIES; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 422 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 423 | nResult = PrintDlg(&printer); |
| 424 | if (printer.hDevNames==0) |
| 425 | return; |
| 426 | if (!nResult) { |
| 427 | MessageBox(Globals.hMainWnd, "PrintDlg failed", "Print Error", MB_ICONEXCLAMATION); |
| 428 | return; |
| 429 | } |
| 430 | hContext = printer.hDC; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 431 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 432 | pDevNamesSpace = GlobalLock(printer.hDevNames); |
| 433 | lpDevNames = (LPDEVNAMES) pDevNamesSpace; |
| 434 | lstrcpy(szPrinterName, pDevNamesSpace+lpDevNames->wDriverOffset); |
| 435 | lstrcpy(szDeviceName, pDevNamesSpace+lpDevNames->wDeviceOffset); |
| 436 | lstrcpy(szOutput, pDevNamesSpace+lpDevNames->wOutputOffset); |
| 437 | GlobalUnlock(printer.hDevNames); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 438 | /* |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 439 | MessageBox(Globals.hMainWnd, szPrinterName, "Printer Name", MB_ICONEXCLAMATION); |
| 440 | MessageBox(Globals.hMainWnd, szDeviceName, "Device Name", MB_ICONEXCLAMATION); |
| 441 | MessageBox(Globals.hMainWnd, szOutput, "Output", MB_ICONEXCLAMATION); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 442 | */ |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 443 | /* initialize DOCINFO */ |
| 444 | di.cbSize = sizeof(DOCINFO); |
| 445 | di.lpszDocName = szDocumentName; |
| 446 | di.lpszOutput = szOutput; |
| 447 | di.lpszDatatype = (LPTSTR) NULL; |
| 448 | di.fwType = 0; |
| 449 | |
| 450 | /* The default resolution is pixels, ie MM_TEXT */ |
| 451 | /* SetMapMode(hContext, MM_TWIPS);*/ |
| 452 | /* SetViewPortExExt(hContext, 10, 10, 0);*/ |
| 453 | /* SetBkMode(hContext, OPAQUE);*/ |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 454 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 455 | /* Get the page dimensions in pixels. */ |
| 456 | cWidthPels = GetDeviceCaps(hContext, HORZRES); |
| 457 | cHeightPels = GetDeviceCaps(hContext, VERTRES); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 458 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 459 | /* Get the file text */ |
| 460 | size = GetWindowTextLength(Globals.hEdit); |
| 461 | pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size); |
| 462 | if (!pTemp) |
| 463 | { |
| 464 | ShowLastError(); |
| 465 | return; |
| 466 | } |
| 467 | GetWindowText(Globals.hEdit, pTemp, size); |
| 468 | if (!size) |
| 469 | { |
| 470 | ShowLastError(); |
| 471 | return; |
| 472 | } |
| 473 | |
| 474 | /* Okay, let's print */ |
| 475 | nResult = StartDoc(hContext, &di); |
| 476 | if (nResult <= 0) { |
| 477 | MessageBox(Globals.hMainWnd, "StartDoc failed", "Print Error", MB_ICONEXCLAMATION); |
| 478 | return; |
| 479 | } |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 480 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 481 | border = 150; |
| 482 | for (copycount=1; copycount <= printer.nCopies; copycount++) { |
| 483 | i = 0; |
| 484 | pagecount = 1; |
| 485 | do { |
| 486 | if (pagecount >= printer.nFromPage && |
| 487 | /* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/ |
| 488 | pagecount <= printer.nToPage) |
| 489 | dopage = 1; |
| 490 | else |
| 491 | dopage = 0; |
| 492 | |
| 493 | old_font = SelectObject(hContext, font); |
| 494 | GetTextExtentPoint32(hContext, "M", 1, &szMetric); |
| 495 | |
| 496 | if (dopage) { |
| 497 | nResult = StartPage(hContext); |
| 498 | if (nResult <= 0) { |
| 499 | MessageBox(Globals.hMainWnd, "StartPage failed", "Print Error", MB_ICONEXCLAMATION); |
| 500 | return; |
| 501 | } |
| 502 | /* Write a rectangle and header at the top of each page */ |
| 503 | Rectangle(hContext, border, border, cWidthPels-border, border+szMetric.cy*2); |
| 504 | /* I don't know what's up with this TextOut command. This comes out |
| 505 | kind of mangled. |
| 506 | */ |
Shachar Shemesh | fc0d07f | 2003-01-28 01:10:28 +0000 | [diff] [blame^] | 507 | TextOut(hContext, border*2, border+szMetric.cy/2, szDocumentName, count); |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /* The starting point for the main text */ |
| 511 | xLeft = border*2; |
| 512 | yTop = border+szMetric.cy*4; |
| 513 | |
| 514 | SelectObject(hContext, old_font); |
| 515 | GetTextExtentPoint32(hContext, "M", 1, &szMetric); |
| 516 | |
| 517 | /* Since outputting strings is giving me problems, output the main |
| 518 | text one character at a time. |
| 519 | */ |
| 520 | do { |
| 521 | if (pTemp[i] == '\n') { |
| 522 | xLeft = border*2; |
| 523 | yTop += szMetric.cy; |
| 524 | } |
| 525 | else if (pTemp[i] != '\r') { |
| 526 | if (dopage) |
| 527 | TextOut(hContext, xLeft, yTop, &pTemp[i], 1); |
| 528 | xLeft += szMetric.cx; |
| 529 | } |
| 530 | } while (i++<size && yTop<(cHeightPels-border*2)); |
| 531 | |
| 532 | if (dopage) |
| 533 | EndPage(hContext); |
| 534 | pagecount++; |
| 535 | } while (i<size); |
| 536 | } |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 537 | |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 538 | switch (nResult) { |
| 539 | case SP_ERROR: |
| 540 | MessageBox(Globals.hMainWnd, "Generic Error", "Print Engine Error", MB_ICONEXCLAMATION); |
| 541 | break; |
| 542 | case SP_APPABORT: |
| 543 | MessageBox(Globals.hMainWnd, "The print job was aborted.", "Print Engine Error", MB_ICONEXCLAMATION); |
| 544 | break; |
| 545 | case SP_USERABORT: |
| 546 | MessageBox(Globals.hMainWnd, "The print job was aborted using the Print Manager ", "Print Engine Error", MB_ICONEXCLAMATION); |
| 547 | break; |
| 548 | case SP_OUTOFDISK: |
| 549 | MessageBox(Globals.hMainWnd, "Out of disk space", "Print Engine Error", MB_ICONEXCLAMATION); |
| 550 | break; |
| 551 | case SP_OUTOFMEMORY: |
| 552 | AlertOutOfMemory(); |
| 553 | break; |
| 554 | default: |
| 555 | break; |
| 556 | } /* switch */ |
| 557 | nResult = EndDoc(hContext); |
| 558 | assert(nResult>=0); |
| 559 | nResult = DeleteDC(hContext); |
| 560 | assert(nResult!=0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | VOID DIALOG_FilePageSetup(VOID) |
| 564 | { |
Duane Clark | 4eb4c04 | 2002-10-21 18:22:15 +0000 | [diff] [blame] | 565 | DIALOG_PageSetup(); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | VOID DIALOG_FilePrinterSetup(VOID) |
| 569 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 570 | PRINTDLG printer; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 571 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 572 | ZeroMemory(&printer, sizeof(printer)); |
| 573 | printer.lStructSize = sizeof(printer); |
| 574 | printer.hwndOwner = Globals.hMainWnd; |
| 575 | printer.hInstance = Globals.hInstance; |
| 576 | printer.Flags = PD_PRINTSETUP; |
| 577 | printer.nCopies = 1; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 578 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 579 | if (PrintDlg(&printer)) { |
| 580 | /* do nothing */ |
| 581 | }; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | VOID DIALOG_FileExit(VOID) |
| 585 | { |
Andriy Palamarchuk | 83ad886 | 2002-07-16 01:09:24 +0000 | [diff] [blame] | 586 | PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | VOID DIALOG_EditUndo(VOID) |
| 590 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 591 | SendMessage(Globals.hEdit, EM_UNDO, 0, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | VOID DIALOG_EditCut(VOID) |
| 595 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 596 | HANDLE hMem; |
| 597 | |
| 598 | hMem = GlobalAlloc(GMEM_ZEROINIT, 99); |
| 599 | |
| 600 | OpenClipboard(Globals.hMainWnd); |
| 601 | EmptyClipboard(); |
| 602 | |
| 603 | /* FIXME: Get text */ |
| 604 | lstrcpy((CHAR *)hMem, "Hello World"); |
| 605 | |
| 606 | SetClipboardData(CF_TEXT, hMem); |
| 607 | CloseClipboard(); |
| 608 | |
| 609 | GlobalFree(hMem); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | VOID DIALOG_EditCopy(VOID) |
| 613 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 614 | HANDLE hMem; |
| 615 | |
| 616 | hMem = GlobalAlloc(GMEM_ZEROINIT, 99); |
| 617 | |
| 618 | OpenClipboard(Globals.hMainWnd); |
| 619 | EmptyClipboard(); |
| 620 | |
| 621 | /* FIXME: Get text */ |
| 622 | lstrcpy((CHAR *)hMem, "Hello World"); |
| 623 | |
| 624 | SetClipboardData(CF_TEXT, hMem); |
| 625 | CloseClipboard(); |
| 626 | |
| 627 | GlobalFree(hMem); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | VOID DIALOG_EditPaste(VOID) |
| 631 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 632 | HANDLE hClipText; |
| 633 | |
| 634 | if (IsClipboardFormatAvailable(CF_TEXT)) { |
| 635 | OpenClipboard(Globals.hMainWnd); |
| 636 | hClipText = GetClipboardData(CF_TEXT); |
| 637 | CloseClipboard(); |
| 638 | MessageBox(Globals.hMainWnd, (CHAR *)hClipText, "PASTE", MB_ICONEXCLAMATION); |
| 639 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | VOID DIALOG_EditDelete(VOID) |
| 643 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 644 | /* Delete */ |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | VOID DIALOG_EditSelectAll(VOID) |
| 648 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 649 | /* Select all */ |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 652 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 653 | VOID DIALOG_EditTimeDate(VOID) |
| 654 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 655 | SYSTEMTIME st; |
| 656 | LPSYSTEMTIME lpst = &st; |
| 657 | CHAR szDate[MAX_STRING_LEN]; |
| 658 | LPSTR date = szDate; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 659 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 660 | GetLocalTime(&st); |
| 661 | GetDateFormat(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, lpst, NULL, date, MAX_STRING_LEN); |
| 662 | GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, date, MAX_STRING_LEN); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | VOID DIALOG_EditWrap(VOID) |
| 666 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 667 | Globals.bWrapLongLines = !Globals.bWrapLongLines; |
| 668 | CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP, |
| 669 | MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED)); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 670 | } |
| 671 | |
Shachar Shemesh | fc0d07f | 2003-01-28 01:10:28 +0000 | [diff] [blame^] | 672 | VOID DIALOG_SelectFont(VOID) |
| 673 | { |
| 674 | CHOOSEFONT cf; |
| 675 | LOGFONT lf=Globals.lfFont; |
| 676 | |
| 677 | ZeroMemory( &cf, sizeof(cf) ); |
| 678 | cf.lStructSize=sizeof(cf); |
| 679 | cf.hwndOwner=Globals.hMainWnd; |
| 680 | cf.lpLogFont=&lf; |
| 681 | cf.Flags=CF_SCREENFONTS; |
| 682 | |
| 683 | if( ChooseFont(&cf) ) |
| 684 | { |
| 685 | HFONT currfont=Globals.hFont; |
| 686 | |
| 687 | Globals.hFont=CreateFontIndirect( &lf ); |
| 688 | Globals.lfFont=lf; |
| 689 | SendMessage( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE ); |
| 690 | if( currfont!=NULL ) |
| 691 | DeleteObject( currfont ); |
| 692 | } |
| 693 | } |
| 694 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 695 | VOID DIALOG_Search(VOID) |
| 696 | { |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 697 | ZeroMemory(&Globals.find, sizeof(Globals.find)); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 698 | Globals.find.lStructSize = sizeof(Globals.find); |
| 699 | Globals.find.hwndOwner = Globals.hMainWnd; |
| 700 | Globals.find.hInstance = Globals.hInstance; |
| 701 | Globals.find.lpstrFindWhat = (CHAR *) &Globals.szFindText; |
| 702 | Globals.find.wFindWhatLen = sizeof(Globals.szFindText); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 703 | Globals.find.Flags = FR_DOWN; |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 704 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 705 | /* We only need to create the modal FindReplace dialog which will */ |
| 706 | /* notify us of incoming events using hMainWnd Window Messages */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 707 | |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 708 | Globals.hFindReplaceDlg = FindText(&Globals.find); |
| 709 | assert(Globals.hFindReplaceDlg !=0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | VOID DIALOG_SearchNext(VOID) |
| 713 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 714 | /* Search Next */ |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | VOID DIALOG_HelpContents(VOID) |
| 718 | { |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 719 | WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | VOID DIALOG_HelpSearch(VOID) |
| 723 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 724 | /* Search Help */ |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | VOID DIALOG_HelpHelp(VOID) |
| 728 | { |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 729 | WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | VOID DIALOG_HelpLicense(VOID) |
| 733 | { |
Alexandre Julliard | 3da872d | 2000-11-10 01:06:36 +0000 | [diff] [blame] | 734 | WineLicense(Globals.hMainWnd); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | VOID DIALOG_HelpNoWarranty(VOID) |
| 738 | { |
Alexandre Julliard | 3da872d | 2000-11-10 01:06:36 +0000 | [diff] [blame] | 739 | WineWarranty(Globals.hMainWnd); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | VOID DIALOG_HelpAboutWine(VOID) |
| 743 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 744 | CHAR szNotepad[MAX_STRING_LEN]; |
| 745 | |
Sylvain Petreolle | eaa8df6 | 2002-03-20 22:55:46 +0000 | [diff] [blame] | 746 | LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, sizeof(szNotepad)); |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 747 | ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 750 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 751 | /*********************************************************************** |
| 752 | * |
| 753 | * DIALOG_PageSetup |
| 754 | */ |
| 755 | |
| 756 | VOID DIALOG_PageSetup(VOID) |
| 757 | { |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 758 | WNDPROC lpfnDlg; |
| 759 | |
| 760 | lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance); |
Andriy Palamarchuk | c55dce0 | 2002-07-08 19:41:09 +0000 | [diff] [blame] | 761 | DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP), |
| 762 | Globals.hMainWnd, (DLGPROC)lpfnDlg); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 763 | FreeProcInstance(lpfnDlg); |
| 764 | } |
| 765 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 766 | |
| 767 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 768 | * |
| 769 | * DIALOG_PAGESETUP_DlgProc |
| 770 | */ |
| 771 | |
Alexandre Julliard | 3da872d | 2000-11-10 01:06:36 +0000 | [diff] [blame] | 772 | static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 773 | { |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 774 | |
| 775 | switch (msg) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 776 | { |
| 777 | case WM_COMMAND: |
| 778 | switch (wParam) |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 779 | { |
| 780 | case IDOK: |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 781 | /* save user input and close dialog */ |
Sylvain Petreolle | eaa8df6 | 2002-03-20 22:55:46 +0000 | [diff] [blame] | 782 | GetDlgItemText(hDlg, 0x141, Globals.szHeader, sizeof(Globals.szHeader)); |
| 783 | GetDlgItemText(hDlg, 0x143, Globals.szFooter, sizeof(Globals.szFooter)); |
| 784 | GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, sizeof(Globals.szMarginTop)); |
| 785 | GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, sizeof(Globals.szMarginBottom)); |
| 786 | GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, sizeof(Globals.szMarginLeft)); |
| 787 | GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, sizeof(Globals.szMarginRight)); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 788 | EndDialog(hDlg, IDOK); |
| 789 | return TRUE; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 790 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 791 | case IDCANCEL: |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 792 | /* discard user input and close dialog */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 793 | EndDialog(hDlg, IDCANCEL); |
| 794 | return TRUE; |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 795 | |
| 796 | case IDHELP: |
| 797 | /* FIXME: Bring this to work */ |
| 798 | MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION); |
| 799 | return TRUE; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 800 | } |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 801 | break; |
| 802 | |
| 803 | case WM_INITDIALOG: |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 804 | /* fetch last user input prior to display dialog */ |
Sylvain Petreolle | eaa8df6 | 2002-03-20 22:55:46 +0000 | [diff] [blame] | 805 | SetDlgItemText(hDlg, 0x141, Globals.szHeader); |
| 806 | SetDlgItemText(hDlg, 0x143, Globals.szFooter); |
| 807 | SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop); |
| 808 | SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom); |
| 809 | SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft); |
| 810 | SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight); |
Marcel Baur | a43295d | 1998-10-18 14:11:42 +0000 | [diff] [blame] | 811 | break; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 812 | } |
Marcel Baur | 0328745 | 1999-02-14 11:28:37 +0000 | [diff] [blame] | 813 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 814 | return FALSE; |
| 815 | } |