blob: ab5d00e543b8d30fcd143407c89ddb7b79edf437 [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
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00007 *
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 Julliard03468f71998-02-15 19:40:49 +000021 */
22
Ulrich Weigand97d05c82000-01-29 22:07:03 +000023#include <assert.h>
Alexandre Julliard03468f71998-02-15 19:40:49 +000024#include <stdio.h>
Marcel Baura43295d1998-10-18 14:11:42 +000025#include <windows.h>
26#include <commdlg.h>
27#include <winerror.h>
28
Alexandre Julliard03468f71998-02-15 19:40:49 +000029#include "main.h"
30#include "license.h"
31#include "dialog.h"
Marcel Baura43295d1998-10-18 14:11:42 +000032
Alexandre Julliard3da872d2000-11-10 01:06:36 +000033static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
Alexandre Julliard03468f71998-02-15 19:40:49 +000034
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000035
Marcel Baur03287451999-02-14 11:28:37 +000036
Andriy Palamarchuk83ad8862002-07-16 01:09:24 +000037VOID ShowLastError()
Andriy Palamarchukc55dce02002-07-08 19:41:09 +000038{
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 */
60void 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 Julliarddadf78f1998-05-17 17:13:43 +000082int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) {
Marcel Baur03287451999-02-14 11:28:37 +000083 /*
Vincent Béron9a624912002-05-31 23:06:46 +000084 * Given some ids strings, this acts as a language-aware wrapper for
Marcel Baur03287451999-02-14 11:28:37 +000085 * "MessageBox"
86 */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000087 CHAR szMessage[MAX_STRING_LEN];
88 CHAR szCaption[MAX_STRING_LEN];
Vincent Béron9a624912002-05-31 23:06:46 +000089
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000090 LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
91 LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
Vincent Béron9a624912002-05-31 23:06:46 +000092
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000093 return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
94}
95
Niels Kristian Bech Jensen52be93c2000-03-19 21:49:49 +000096void AlertFileNotFound(LPSTR szFileName) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000097
98 int nResult;
Marcel Baur03287451999-02-14 11:28:37 +000099 CHAR szMessage[MAX_STRING_LEN];
100 CHAR szRessource[MAX_STRING_LEN];
101
102 /* Load and format szMessage */
Sylvain Petreolleeaa8df62002-03-20 22:55:46 +0000103 LoadString(Globals.hInstance, STRING_NOTFOUND, szRessource, sizeof(szRessource));
Mike McCormack0e2d0e02000-07-23 14:22:47 +0000104 wsprintf(szMessage, szRessource, szFileName);
Vincent Béron9a624912002-05-31 23:06:46 +0000105
Marcel Baur03287451999-02-14 11:28:37 +0000106 /* Load szCaption */
Sylvain Petreolleeaa8df62002-03-20 22:55:46 +0000107 LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource));
Marcel Baur03287451999-02-14 11:28:37 +0000108
109 /* Display Modal Dialog */
110 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION);
111
112}
113
Niels Kristian Bech Jensen52be93c2000-03-19 21:49:49 +0000114int AlertFileNotSaved(LPSTR szFileName) {
Marcel Baur03287451999-02-14 11:28:37 +0000115
116 int nResult;
117 CHAR szMessage[MAX_STRING_LEN];
118 CHAR szRessource[MAX_STRING_LEN];
119
120 /* Load and format Message */
121
Sylvain Petreolleeaa8df62002-03-20 22:55:46 +0000122 LoadString(Globals.hInstance, STRING_NOTSAVED, szRessource, sizeof(szRessource));
Mike McCormack0e2d0e02000-07-23 14:22:47 +0000123 wsprintf(szMessage, szRessource, szFileName);
Vincent Béron9a624912002-05-31 23:06:46 +0000124
Marcel Baur03287451999-02-14 11:28:37 +0000125 /* Load Caption */
126
Sylvain Petreolleeaa8df62002-03-20 22:55:46 +0000127 LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource));
Marcel Baur03287451999-02-14 11:28:37 +0000128
129 /* Display modal */
Andreas Mohr1081dfe2000-12-09 03:06:54 +0000130 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION|MB_YESNOCANCEL);
Marcel Baur03287451999-02-14 11:28:37 +0000131 return(nResult);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000132}
133
134
135VOID AlertOutOfMemory(void) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000136 int nResult;
Vincent Béron9a624912002-05-31 23:06:46 +0000137
Sylvain Petreolleeaa8df62002-03-20 22:55:46 +0000138 nResult = AlertIDS(STRING_OUT_OF_MEMORY, STRING_ERROR, MB_ICONEXCLAMATION);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000139 PostQuitMessage(1);
140}
141
142
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000143/**
144 * Returns:
145 * TRUE - if file exists
146 * FALSE - if file does not exist
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000147 */
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000148BOOL FileExists(LPSTR szFilename) {
Marcel Baura43295d1998-10-18 14:11:42 +0000149 WIN32_FIND_DATA entry;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000150 HANDLE hFile;
Vincent Béron9a624912002-05-31 23:06:46 +0000151
Marcel Baur03287451999-02-14 11:28:37 +0000152 hFile = FindFirstFile(szFilename, &entry);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000153 FindClose(hFile);
Vincent Béron9a624912002-05-31 23:06:46 +0000154
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000155 return (hFile != INVALID_HANDLE_VALUE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000156}
157
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000158
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000159VOID DoSaveFile(VOID) {
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000160 HANDLE hFile;
161 DWORD dwNumWrite;
162 BOOL bTest;
163 CHAR *pTemp;
164 int size;
Marcel Baur03287451999-02-14 11:28:37 +0000165
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000166 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 Julliarddadf78f1998-05-17 17:13:43 +0000190}
191
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000192/**
193 * Returns:
194 * TRUE - User agreed to close (both save/don't save)
195 * FALSE - User cancelled close by selecting "Cancel"
196 */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000197BOOL DoCloseFile(void) {
Marcel Baur03287451999-02-14 11:28:37 +0000198 int nResult;
Vincent Béron9a624912002-05-31 23:06:46 +0000199
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000200 if (Globals.szFileName[0] != 0) {
Marcel Baur03287451999-02-14 11:28:37 +0000201 /* prompt user to save changes */
202 nResult = AlertFileNotSaved(Globals.szFileName);
203 switch (nResult) {
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000204 case IDYES: DIALOG_FileSave();
Marcel Baur03287451999-02-14 11:28:37 +0000205 break;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000206
Marcel Baur03287451999-02-14 11:28:37 +0000207 case IDNO: break;
Marcel Baura43295d1998-10-18 14:11:42 +0000208
Marcel Baur03287451999-02-14 11:28:37 +0000209 case IDCANCEL: return(FALSE);
210 break;
Vincent Béron9a624912002-05-31 23:06:46 +0000211
Marcel Baur03287451999-02-14 11:28:37 +0000212 default: return(FALSE);
213 break;
214 } /* switch */
215 } /* if */
Vincent Béron9a624912002-05-31 23:06:46 +0000216
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000217 SetFileName("");
218
219 UpdateWindowCaption();
Marcel Baur03287451999-02-14 11:28:37 +0000220 return(TRUE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000221}
222
223
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000224void DoOpenFile(LPSTR szFileName) {
Marcus Meissner73458b01998-12-26 12:54:29 +0000225 /* Close any files and prompt to save changes */
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000226 if (DoCloseFile())
227 {
228 HANDLE hFile;
229 CHAR *pTemp;
230 DWORD size;
231 DWORD dwNumRead;
Marcel Baur03287451999-02-14 11:28:37 +0000232
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000233 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 Julliarddadf78f1998-05-17 17:13:43 +0000273 }
274}
275
Alexandre Julliard03468f71998-02-15 19:40:49 +0000276VOID DIALOG_FileNew(VOID)
277{
Marcus Meissner73458b01998-12-26 12:54:29 +0000278 /* Close any files and promt to save changes */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000279 if (DoCloseFile()) {
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000280 SetWindowText(Globals.hEdit, "");
281 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
282 SetFocus(Globals.hEdit);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000283 }
Alexandre Julliard03468f71998-02-15 19:40:49 +0000284}
285
286VOID DIALOG_FileOpen(VOID)
287{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000288 OPENFILENAME openfilename;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000289
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000290 CHAR szPath[MAX_PATH];
291 CHAR szDir[MAX_PATH];
292 CHAR szDefaultExt[] = "txt";
Marcel Baura43295d1998-10-18 14:11:42 +0000293
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000294 ZeroMemory(&openfilename, sizeof(openfilename));
Alexandre Julliard03468f71998-02-15 19:40:49 +0000295
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000296 GetCurrentDirectory(sizeof(szDir), szDir);
297 lstrcpy(szPath,"*.txt");
Alexandre Julliard03468f71998-02-15 19:40:49 +0000298
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000299 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 Julliarddadf78f1998-05-17 17:13:43 +0000309
Vincent Béron9a624912002-05-31 23:06:46 +0000310
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000311 if (GetOpenFileName(&openfilename)) {
312 if (FileExists(openfilename.lpstrFile))
313 DoOpenFile(openfilename.lpstrFile);
314 else
315 AlertFileNotFound(openfilename.lpstrFile);
316 }
Alexandre Julliard03468f71998-02-15 19:40:49 +0000317}
318
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000319
Alexandre Julliard03468f71998-02-15 19:40:49 +0000320VOID DIALOG_FileSave(VOID)
321{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000322 if (Globals.szFileName[0] == '\0')
Marcel Baur03287451999-02-14 11:28:37 +0000323 DIALOG_FileSaveAs();
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000324 else
325 DoSaveFile();
Alexandre Julliard03468f71998-02-15 19:40:49 +0000326}
327
328VOID DIALOG_FileSaveAs(VOID)
329{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000330 OPENFILENAME saveas;
331 CHAR szPath[MAX_PATH];
332 CHAR szDir[MAX_PATH];
333 CHAR szDefaultExt[] = "txt";
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
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000337 GetCurrentDirectory(sizeof(szDir), szDir);
338 lstrcpy(szPath,"*.*");
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;
345 saveas.nMaxFile = sizeof(szPath);
346 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();
355 }
Alexandre Julliard03468f71998-02-15 19:40:49 +0000356}
357
358VOID DIALOG_FilePrint(VOID)
359{
Duane Clark4eb4c042002-10-21 18:22:15 +0000360 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 Baur03287451999-02-14 11:28:37 +0000374
Duane Clark4eb4c042002-10-21 18:22:15 +0000375 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 Baur03287451999-02-14 11:28:37 +0000382
Duane Clark4eb4c042002-10-21 18:22:15 +0000383 /* 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 Baur03287451999-02-14 11:28:37 +0000419
Duane Clark4eb4c042002-10-21 18:22:15 +0000420 /* Let commdlg manage copy settings */
421 printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
Marcel Baur03287451999-02-14 11:28:37 +0000422
Duane Clark4eb4c042002-10-21 18:22:15 +0000423 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 Baur03287451999-02-14 11:28:37 +0000431
Duane Clark4eb4c042002-10-21 18:22:15 +0000432 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 Baur03287451999-02-14 11:28:37 +0000438/*
Duane Clark4eb4c042002-10-21 18:22:15 +0000439 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 Baur03287451999-02-14 11:28:37 +0000442*/
Duane Clark4eb4c042002-10-21 18:22:15 +0000443 /* 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 Baur03287451999-02-14 11:28:37 +0000454
Duane Clark4eb4c042002-10-21 18:22:15 +0000455 /* Get the page dimensions in pixels. */
456 cWidthPels = GetDeviceCaps(hContext, HORZRES);
457 cHeightPels = GetDeviceCaps(hContext, VERTRES);
Marcel Baur03287451999-02-14 11:28:37 +0000458
Duane Clark4eb4c042002-10-21 18:22:15 +0000459 /* 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 Baur03287451999-02-14 11:28:37 +0000480
Duane Clark4eb4c042002-10-21 18:22:15 +0000481 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 Shemeshfc0d07f2003-01-28 01:10:28 +0000507 TextOut(hContext, border*2, border+szMetric.cy/2, szDocumentName, count);
Duane Clark4eb4c042002-10-21 18:22:15 +0000508 }
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 Baur03287451999-02-14 11:28:37 +0000537
Duane Clark4eb4c042002-10-21 18:22:15 +0000538 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 Julliard03468f71998-02-15 19:40:49 +0000561}
562
563VOID DIALOG_FilePageSetup(VOID)
564{
Duane Clark4eb4c042002-10-21 18:22:15 +0000565 DIALOG_PageSetup();
Alexandre Julliard03468f71998-02-15 19:40:49 +0000566}
567
568VOID DIALOG_FilePrinterSetup(VOID)
569{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000570 PRINTDLG printer;
Marcel Baur03287451999-02-14 11:28:37 +0000571
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000572 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éron9a624912002-05-31 23:06:46 +0000578
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000579 if (PrintDlg(&printer)) {
580 /* do nothing */
581 };
Alexandre Julliard03468f71998-02-15 19:40:49 +0000582}
583
584VOID DIALOG_FileExit(VOID)
585{
Andriy Palamarchuk83ad8862002-07-16 01:09:24 +0000586 PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000587}
588
589VOID DIALOG_EditUndo(VOID)
590{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000591 SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000592}
593
594VOID DIALOG_EditCut(VOID)
595{
Marcel Baur03287451999-02-14 11:28:37 +0000596 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 Julliard03468f71998-02-15 19:40:49 +0000610}
611
612VOID DIALOG_EditCopy(VOID)
613{
Marcel Baur03287451999-02-14 11:28:37 +0000614 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 Julliard03468f71998-02-15 19:40:49 +0000628}
629
630VOID DIALOG_EditPaste(VOID)
631{
Marcel Baur03287451999-02-14 11:28:37 +0000632 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 Julliard03468f71998-02-15 19:40:49 +0000640}
641
642VOID DIALOG_EditDelete(VOID)
643{
Marcel Baur03287451999-02-14 11:28:37 +0000644 /* Delete */
Alexandre Julliard03468f71998-02-15 19:40:49 +0000645}
646
647VOID DIALOG_EditSelectAll(VOID)
648{
Marcel Baur03287451999-02-14 11:28:37 +0000649 /* Select all */
Alexandre Julliard03468f71998-02-15 19:40:49 +0000650}
651
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000652
Alexandre Julliard03468f71998-02-15 19:40:49 +0000653VOID DIALOG_EditTimeDate(VOID)
654{
Marcel Baur03287451999-02-14 11:28:37 +0000655 SYSTEMTIME st;
656 LPSYSTEMTIME lpst = &st;
657 CHAR szDate[MAX_STRING_LEN];
658 LPSTR date = szDate;
Vincent Béron9a624912002-05-31 23:06:46 +0000659
Marcel Baur03287451999-02-14 11:28:37 +0000660 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 Julliard03468f71998-02-15 19:40:49 +0000663}
664
665VOID DIALOG_EditWrap(VOID)
666{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000667 Globals.bWrapLongLines = !Globals.bWrapLongLines;
668 CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
669 MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
Alexandre Julliard03468f71998-02-15 19:40:49 +0000670}
671
Shachar Shemeshfc0d07f2003-01-28 01:10:28 +0000672VOID 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 Julliard03468f71998-02-15 19:40:49 +0000695VOID DIALOG_Search(VOID)
696{
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000697 ZeroMemory(&Globals.find, sizeof(Globals.find));
Marcel Baur03287451999-02-14 11:28:37 +0000698 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 Baur03287451999-02-14 11:28:37 +0000703 Globals.find.Flags = FR_DOWN;
Marcel Baura43295d1998-10-18 14:11:42 +0000704
Marcel Baur03287451999-02-14 11:28:37 +0000705 /* We only need to create the modal FindReplace dialog which will */
706 /* notify us of incoming events using hMainWnd Window Messages */
Alexandre Julliard54c27111998-03-29 19:44:57 +0000707
Marcel Baur03287451999-02-14 11:28:37 +0000708 Globals.hFindReplaceDlg = FindText(&Globals.find);
709 assert(Globals.hFindReplaceDlg !=0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000710}
711
712VOID DIALOG_SearchNext(VOID)
713{
Marcel Baur03287451999-02-14 11:28:37 +0000714 /* Search Next */
Alexandre Julliard03468f71998-02-15 19:40:49 +0000715}
716
717VOID DIALOG_HelpContents(VOID)
718{
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000719 WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000720}
721
722VOID DIALOG_HelpSearch(VOID)
723{
Marcel Baur03287451999-02-14 11:28:37 +0000724 /* Search Help */
Alexandre Julliard03468f71998-02-15 19:40:49 +0000725}
726
727VOID DIALOG_HelpHelp(VOID)
728{
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000729 WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000730}
731
732VOID DIALOG_HelpLicense(VOID)
733{
Alexandre Julliard3da872d2000-11-10 01:06:36 +0000734 WineLicense(Globals.hMainWnd);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000735}
736
737VOID DIALOG_HelpNoWarranty(VOID)
738{
Alexandre Julliard3da872d2000-11-10 01:06:36 +0000739 WineWarranty(Globals.hMainWnd);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000740}
741
742VOID DIALOG_HelpAboutWine(VOID)
743{
Marcel Baur03287451999-02-14 11:28:37 +0000744 CHAR szNotepad[MAX_STRING_LEN];
745
Sylvain Petreolleeaa8df62002-03-20 22:55:46 +0000746 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, sizeof(szNotepad));
Marcel Baur03287451999-02-14 11:28:37 +0000747 ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000748}
749
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000750
Alexandre Julliard03468f71998-02-15 19:40:49 +0000751/***********************************************************************
752 *
753 * DIALOG_PageSetup
754 */
755
756VOID DIALOG_PageSetup(VOID)
757{
Marcel Baura43295d1998-10-18 14:11:42 +0000758 WNDPROC lpfnDlg;
759
760 lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
Andriy Palamarchukc55dce02002-07-08 19:41:09 +0000761 DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
762 Globals.hMainWnd, (DLGPROC)lpfnDlg);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000763 FreeProcInstance(lpfnDlg);
764}
765
Alexandre Julliard03468f71998-02-15 19:40:49 +0000766
767/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
768 *
769 * DIALOG_PAGESETUP_DlgProc
770 */
771
Alexandre Julliard3da872d2000-11-10 01:06:36 +0000772static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000773{
Marcel Baur03287451999-02-14 11:28:37 +0000774
775 switch (msg)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000776 {
777 case WM_COMMAND:
778 switch (wParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000779 {
780 case IDOK:
Marcel Baur03287451999-02-14 11:28:37 +0000781 /* save user input and close dialog */
Sylvain Petreolleeaa8df62002-03-20 22:55:46 +0000782 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 Julliarddadf78f1998-05-17 17:13:43 +0000788 EndDialog(hDlg, IDOK);
789 return TRUE;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000790
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000791 case IDCANCEL:
Marcel Baur03287451999-02-14 11:28:37 +0000792 /* discard user input and close dialog */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000793 EndDialog(hDlg, IDCANCEL);
794 return TRUE;
Marcel Baur03287451999-02-14 11:28:37 +0000795
796 case IDHELP:
797 /* FIXME: Bring this to work */
798 MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION);
799 return TRUE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000800 }
Marcel Baura43295d1998-10-18 14:11:42 +0000801 break;
802
803 case WM_INITDIALOG:
Marcel Baur03287451999-02-14 11:28:37 +0000804 /* fetch last user input prior to display dialog */
Sylvain Petreolleeaa8df62002-03-20 22:55:46 +0000805 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 Baura43295d1998-10-18 14:11:42 +0000811 break;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000812 }
Marcel Baur03287451999-02-14 11:28:37 +0000813
Alexandre Julliard03468f71998-02-15 19:40:49 +0000814 return FALSE;
815}