In OSS_RawOpenDevice, always retrieve the device format and store it
[wine/multimedia.git] / programs / notepad / dialog.c
blob1faa023c4c1f0456dd8352c488087309a96a92dc
1 /*
2 * Notepad (dialog.c)
4 * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
5 * Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * Copyright 2002 Andriy Palamarchuk
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.
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.
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
23 #include <assert.h>
24 #include <stdio.h>
25 #include <windows.h>
26 #include <commdlg.h>
27 #include <winerror.h>
29 #include "main.h"
30 #include "license.h"
31 #include "dialog.h"
33 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
37 VOID ShowLastError()
39 DWORD error = GetLastError();
40 if (error != NO_ERROR)
42 LPVOID lpMsgBuf;
43 CHAR szTitle[MAX_STRING_LEN];
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);
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
60 void UpdateWindowCaption(void) {
61 CHAR szCaption[MAX_STRING_LEN];
62 CHAR szUntitled[MAX_STRING_LEN];
64 LoadString(Globals.hInstance, STRING_NOTEPAD, szCaption, sizeof(szCaption));
66 if (Globals.szFileTitle[0] != '\0') {
67 lstrcat(szCaption, " - [");
68 lstrcat(szCaption, Globals.szFileTitle);
69 lstrcat(szCaption, "]");
71 else
73 LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, sizeof(szUntitled));
74 lstrcat(szCaption, " - ");
75 lstrcat(szCaption, szUntitled);
78 SetWindowText(Globals.hMainWnd, szCaption);
82 int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) {
84 * Given some ids strings, this acts as a language-aware wrapper for
85 * "MessageBox"
87 CHAR szMessage[MAX_STRING_LEN];
88 CHAR szCaption[MAX_STRING_LEN];
90 LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
91 LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
93 return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
96 void AlertFileNotFound(LPSTR szFileName) {
98 int nResult;
99 CHAR szMessage[MAX_STRING_LEN];
100 CHAR szRessource[MAX_STRING_LEN];
102 /* Load and format szMessage */
103 LoadString(Globals.hInstance, STRING_NOTFOUND, szRessource, sizeof(szRessource));
104 wsprintf(szMessage, szRessource, szFileName);
106 /* Load szCaption */
107 LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource));
109 /* Display Modal Dialog */
110 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION);
114 int AlertFileNotSaved(LPSTR szFileName) {
116 int nResult;
117 CHAR szMessage[MAX_STRING_LEN];
118 CHAR szRessource[MAX_STRING_LEN];
120 /* Load and format Message */
122 LoadString(Globals.hInstance, STRING_NOTSAVED, szRessource, sizeof(szRessource));
123 wsprintf(szMessage, szRessource, szFileName);
125 /* Load Caption */
127 LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource));
129 /* Display modal */
130 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION|MB_YESNOCANCEL);
131 return(nResult);
135 VOID AlertOutOfMemory(void) {
136 int nResult;
138 nResult = AlertIDS(STRING_OUT_OF_MEMORY, STRING_ERROR, MB_ICONEXCLAMATION);
139 PostQuitMessage(1);
144 * Returns:
145 * TRUE - if file exists
146 * FALSE - if file does not exist
148 BOOL FileExists(LPSTR szFilename) {
149 WIN32_FIND_DATA entry;
150 HANDLE hFile;
152 hFile = FindFirstFile(szFilename, &entry);
153 FindClose(hFile);
155 return (hFile != INVALID_HANDLE_VALUE);
159 VOID DoSaveFile(VOID) {
160 HANDLE hFile;
161 DWORD dwNumWrite;
162 BOOL bTest;
163 CHAR *pTemp;
164 int size;
166 hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
167 NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
168 if(hFile == INVALID_HANDLE_VALUE)
170 ShowLastError();
171 return;
174 size = GetWindowTextLength(Globals.hEdit);
175 pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size);
176 if (!pTemp)
178 ShowLastError();
179 return;
181 GetWindowText(Globals.hEdit, pTemp, size);
183 bTest = WriteFile(hFile, pTemp, size, &dwNumWrite, NULL);
184 if(bTest == FALSE)
186 ShowLastError();
188 CloseHandle(hFile);
189 GlobalFree(pTemp);
193 * Returns:
194 * TRUE - User agreed to close (both save/don't save)
195 * FALSE - User cancelled close by selecting "Cancel"
197 BOOL DoCloseFile(void) {
198 int nResult;
200 if (Globals.szFileName[0] != 0) {
201 /* prompt user to save changes */
202 nResult = AlertFileNotSaved(Globals.szFileName);
203 switch (nResult) {
204 case IDYES: DIALOG_FileSave();
205 break;
207 case IDNO: break;
209 case IDCANCEL: return(FALSE);
210 break;
212 default: return(FALSE);
213 break;
214 } /* switch */
215 } /* if */
217 SetFileName("");
219 UpdateWindowCaption();
220 return(TRUE);
224 void DoOpenFile(LPSTR szFileName) {
225 /* Close any files and prompt to save changes */
226 if (DoCloseFile())
228 HANDLE hFile;
229 CHAR *pTemp;
230 DWORD size;
231 DWORD dwNumRead;
233 hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
234 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
235 if(hFile == INVALID_HANDLE_VALUE)
237 ShowLastError();
238 return;
241 size = GetFileSize(hFile, NULL);
242 if (size == 0xFFFFFFFF)
244 ShowLastError();
245 return;
247 size++;
248 pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size);
249 if (!pTemp)
251 ShowLastError();
252 return;
254 if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
256 ShowLastError();
257 return;
259 CloseHandle(hFile);
260 pTemp[dwNumRead] = '\0';
261 if (!SetWindowText(Globals.hEdit, pTemp))
263 GlobalFree(pTemp);
264 ShowLastError();
265 return;
267 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
268 GlobalFree(pTemp);
269 SetFocus(Globals.hEdit);
271 SetFileName(szFileName);
272 UpdateWindowCaption();
276 VOID DIALOG_FileNew(VOID)
278 /* Close any files and promt to save changes */
279 if (DoCloseFile()) {
280 SetWindowText(Globals.hEdit, "");
281 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
282 SetFocus(Globals.hEdit);
286 VOID DIALOG_FileOpen(VOID)
288 OPENFILENAME openfilename;
290 CHAR szPath[MAX_PATH];
291 CHAR szDir[MAX_PATH];
292 CHAR szDefaultExt[] = "txt";
294 ZeroMemory(&openfilename, sizeof(openfilename));
296 GetCurrentDirectory(sizeof(szDir), szDir);
297 lstrcpy(szPath,"*.txt");
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;
311 if (GetOpenFileName(&openfilename)) {
312 if (FileExists(openfilename.lpstrFile))
313 DoOpenFile(openfilename.lpstrFile);
314 else
315 AlertFileNotFound(openfilename.lpstrFile);
320 VOID DIALOG_FileSave(VOID)
322 if (Globals.szFileName[0] == '\0')
323 DIALOG_FileSaveAs();
324 else
325 DoSaveFile();
328 VOID DIALOG_FileSaveAs(VOID)
330 OPENFILENAME saveas;
331 CHAR szPath[MAX_PATH];
332 CHAR szDir[MAX_PATH];
333 CHAR szDefaultExt[] = "txt";
335 ZeroMemory(&saveas, sizeof(saveas));
337 GetCurrentDirectory(sizeof(szDir), szDir);
338 lstrcpy(szPath,"*.*");
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;
351 if (GetSaveFileName(&saveas)) {
352 SetFileName(szPath);
353 UpdateWindowCaption();
354 DoSaveFile();
358 VOID DIALOG_FilePrint(VOID)
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;
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 */
380 strcpy(szDocumentName, Globals.szFileTitle);
381 count = strlen(szDocumentName);
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");
399 font = CreateFontIndirect(&hdrFont);
401 /* Get Current Settings */
402 ZeroMemory(&printer, sizeof(printer));
403 printer.lStructSize = sizeof(printer);
404 printer.hwndOwner = Globals.hMainWnd;
405 printer.hInstance = Globals.hInstance;
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;
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;
420 /* Let commdlg manage copy settings */
421 printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
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;
430 hContext = printer.hDC;
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);
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);
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;
450 /* The default resolution is pixels, ie MM_TEXT */
451 /* SetMapMode(hContext, MM_TWIPS);*/
452 /* SetViewPortExExt(hContext, 10, 10, 0);*/
453 /* SetBkMode(hContext, OPAQUE);*/
455 /* Get the page dimensions in pixels. */
456 cWidthPels = GetDeviceCaps(hContext, HORZRES);
457 cHeightPels = GetDeviceCaps(hContext, VERTRES);
459 /* Get the file text */
460 size = GetWindowTextLength(Globals.hEdit);
461 pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size);
462 if (!pTemp)
464 ShowLastError();
465 return;
467 GetWindowText(Globals.hEdit, pTemp, size);
468 if (!size)
470 ShowLastError();
471 return;
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;
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;
493 old_font = SelectObject(hContext, font);
494 GetTextExtentPoint32(hContext, "M", 1, &szMetric);
496 if (dopage) {
497 nResult = StartPage(hContext);
498 if (nResult <= 0) {
499 MessageBox(Globals.hMainWnd, "StartPage failed", "Print Error", MB_ICONEXCLAMATION);
500 return;
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.
507 TextOut(hContext, border*2, border+szMetric.cy*0.5, szDocumentName, count);
510 /* The starting point for the main text */
511 xLeft = border*2;
512 yTop = border+szMetric.cy*4;
514 SelectObject(hContext, old_font);
515 GetTextExtentPoint32(hContext, "M", 1, &szMetric);
517 /* Since outputting strings is giving me problems, output the main
518 text one character at a time.
520 do {
521 if (pTemp[i] == '\n') {
522 xLeft = border*2;
523 yTop += szMetric.cy;
525 else if (pTemp[i] != '\r') {
526 if (dopage)
527 TextOut(hContext, xLeft, yTop, &pTemp[i], 1);
528 xLeft += szMetric.cx;
530 } while (i++<size && yTop<(cHeightPels-border*2));
532 if (dopage)
533 EndPage(hContext);
534 pagecount++;
535 } while (i<size);
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);
563 VOID DIALOG_FilePageSetup(VOID)
565 DIALOG_PageSetup();
568 VOID DIALOG_FilePrinterSetup(VOID)
570 PRINTDLG printer;
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;
579 if (PrintDlg(&printer)) {
580 /* do nothing */
584 VOID DIALOG_FileExit(VOID)
586 PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
589 VOID DIALOG_EditUndo(VOID)
591 SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
594 VOID DIALOG_EditCut(VOID)
596 HANDLE hMem;
598 hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
600 OpenClipboard(Globals.hMainWnd);
601 EmptyClipboard();
603 /* FIXME: Get text */
604 lstrcpy((CHAR *)hMem, "Hello World");
606 SetClipboardData(CF_TEXT, hMem);
607 CloseClipboard();
609 GlobalFree(hMem);
612 VOID DIALOG_EditCopy(VOID)
614 HANDLE hMem;
616 hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
618 OpenClipboard(Globals.hMainWnd);
619 EmptyClipboard();
621 /* FIXME: Get text */
622 lstrcpy((CHAR *)hMem, "Hello World");
624 SetClipboardData(CF_TEXT, hMem);
625 CloseClipboard();
627 GlobalFree(hMem);
630 VOID DIALOG_EditPaste(VOID)
632 HANDLE hClipText;
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);
642 VOID DIALOG_EditDelete(VOID)
644 /* Delete */
647 VOID DIALOG_EditSelectAll(VOID)
649 /* Select all */
653 VOID DIALOG_EditTimeDate(VOID)
655 SYSTEMTIME st;
656 LPSYSTEMTIME lpst = &st;
657 CHAR szDate[MAX_STRING_LEN];
658 LPSTR date = szDate;
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);
665 VOID DIALOG_EditWrap(VOID)
667 Globals.bWrapLongLines = !Globals.bWrapLongLines;
668 CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
669 MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
672 VOID DIALOG_Search(VOID)
674 ZeroMemory(&Globals.find, sizeof(Globals.find));
675 Globals.find.lStructSize = sizeof(Globals.find);
676 Globals.find.hwndOwner = Globals.hMainWnd;
677 Globals.find.hInstance = Globals.hInstance;
678 Globals.find.lpstrFindWhat = (CHAR *) &Globals.szFindText;
679 Globals.find.wFindWhatLen = sizeof(Globals.szFindText);
680 Globals.find.Flags = FR_DOWN;
682 /* We only need to create the modal FindReplace dialog which will */
683 /* notify us of incoming events using hMainWnd Window Messages */
685 Globals.hFindReplaceDlg = FindText(&Globals.find);
686 assert(Globals.hFindReplaceDlg !=0);
689 VOID DIALOG_SearchNext(VOID)
691 /* Search Next */
694 VOID DIALOG_HelpContents(VOID)
696 WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
699 VOID DIALOG_HelpSearch(VOID)
701 /* Search Help */
704 VOID DIALOG_HelpHelp(VOID)
706 WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
709 VOID DIALOG_HelpLicense(VOID)
711 WineLicense(Globals.hMainWnd);
714 VOID DIALOG_HelpNoWarranty(VOID)
716 WineWarranty(Globals.hMainWnd);
719 VOID DIALOG_HelpAboutWine(VOID)
721 CHAR szNotepad[MAX_STRING_LEN];
723 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, sizeof(szNotepad));
724 ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0);
728 /***********************************************************************
730 * DIALOG_PageSetup
733 VOID DIALOG_PageSetup(VOID)
735 WNDPROC lpfnDlg;
737 lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
738 DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
739 Globals.hMainWnd, (DLGPROC)lpfnDlg);
740 FreeProcInstance(lpfnDlg);
744 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
746 * DIALOG_PAGESETUP_DlgProc
749 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
752 switch (msg)
754 case WM_COMMAND:
755 switch (wParam)
757 case IDOK:
758 /* save user input and close dialog */
759 GetDlgItemText(hDlg, 0x141, Globals.szHeader, sizeof(Globals.szHeader));
760 GetDlgItemText(hDlg, 0x143, Globals.szFooter, sizeof(Globals.szFooter));
761 GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, sizeof(Globals.szMarginTop));
762 GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, sizeof(Globals.szMarginBottom));
763 GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, sizeof(Globals.szMarginLeft));
764 GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, sizeof(Globals.szMarginRight));
765 EndDialog(hDlg, IDOK);
766 return TRUE;
768 case IDCANCEL:
769 /* discard user input and close dialog */
770 EndDialog(hDlg, IDCANCEL);
771 return TRUE;
773 case IDHELP:
774 /* FIXME: Bring this to work */
775 MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION);
776 return TRUE;
778 break;
780 case WM_INITDIALOG:
781 /* fetch last user input prior to display dialog */
782 SetDlgItemText(hDlg, 0x141, Globals.szHeader);
783 SetDlgItemText(hDlg, 0x143, Globals.szFooter);
784 SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
785 SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
786 SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
787 SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);
788 break;
791 return FALSE;