Handle generic column width changes.
[wine] / programs / notepad / dialog.c
1 /*
2  *  Notepad (dialog.c)
3  *
4  *  Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
5  *  Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6  *  Copyright 2002 Andriy Palamarchuk
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
21  */
22
23 #include <assert.h>
24 #include <stdio.h>
25 #include <windows.h>
26 #include <commdlg.h>
27 #include <winerror.h>
28
29 #include "main.h"
30 #include "license.h"
31 #include "dialog.h"
32
33 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
34
35
36
37 VOID ShowLastError()
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
82 int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) {
83   /*
84    * Given some ids strings, this acts as a language-aware wrapper for
85    * "MessageBox"
86    */
87    CHAR szMessage[MAX_STRING_LEN];
88    CHAR szCaption[MAX_STRING_LEN];
89
90    LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
91    LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
92
93    return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
94 }
95
96 void AlertFileNotFound(LPSTR szFileName) {
97
98    int nResult;
99    CHAR szMessage[MAX_STRING_LEN];
100    CHAR szRessource[MAX_STRING_LEN];
101
102    /* Load and format szMessage */
103    LoadString(Globals.hInstance, STRING_NOTFOUND, szRessource, sizeof(szRessource));
104    wsprintf(szMessage, szRessource, szFileName);
105
106    /* Load szCaption */
107    LoadString(Globals.hInstance, STRING_ERROR,  szRessource, sizeof(szRessource));
108
109    /* Display Modal Dialog */
110    nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION);
111
112 }
113
114 int AlertFileNotSaved(LPSTR szFileName) {
115
116    int nResult;
117    CHAR szMessage[MAX_STRING_LEN];
118    CHAR szRessource[MAX_STRING_LEN];
119
120    /* Load and format Message */
121
122    LoadString(Globals.hInstance, STRING_NOTSAVED, szRessource, sizeof(szRessource));
123    wsprintf(szMessage, szRessource, szFileName);
124
125    /* Load Caption */
126
127    LoadString(Globals.hInstance, STRING_ERROR,  szRessource, sizeof(szRessource));
128
129    /* Display modal */
130    nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION|MB_YESNOCANCEL);
131    return(nResult);
132 }
133
134
135 VOID AlertOutOfMemory(void) {
136    int nResult;
137
138    nResult = AlertIDS(STRING_OUT_OF_MEMORY, STRING_ERROR, MB_ICONEXCLAMATION);
139    PostQuitMessage(1);
140 }
141
142
143 /**
144  * Returns:
145  *   TRUE  - if file exists
146  *   FALSE - if file does not exist
147  */
148 BOOL FileExists(LPSTR szFilename) {
149    WIN32_FIND_DATA entry;
150    HANDLE hFile;
151
152    hFile = FindFirstFile(szFilename, &entry);
153    FindClose(hFile);
154
155    return (hFile != INVALID_HANDLE_VALUE);
156 }
157
158
159 VOID DoSaveFile(VOID) {
160     HANDLE hFile;
161     DWORD dwNumWrite;
162     BOOL bTest;
163     CHAR *pTemp;
164     int size;
165
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);
190 }
191
192 /**
193  * Returns:
194  *   TRUE  - User agreed to close (both save/don't save)
195  *   FALSE - User cancelled close by selecting "Cancel"
196  */
197 BOOL DoCloseFile(void) {
198     int nResult;
199
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;
206
207             case IDNO:      break;
208
209             case IDCANCEL:  return(FALSE);
210                             break;
211
212             default:        return(FALSE);
213                             break;
214         } /* switch */
215     } /* if */
216
217     SetFileName("");
218
219     UpdateWindowCaption();
220     return(TRUE);
221 }
222
223
224 void DoOpenFile(LPSTR szFileName) {
225     /* Close any files and prompt to save changes */
226     if (DoCloseFile())
227     {
228         HANDLE hFile;
229         CHAR *pTemp;
230         DWORD size;
231         DWORD dwNumRead;
232
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();
273     }
274 }
275
276 VOID DIALOG_FileNew(VOID)
277 {
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);
283     }
284 }
285
286 VOID DIALOG_FileOpen(VOID)
287 {
288     OPENFILENAME openfilename;
289
290     CHAR szPath[MAX_PATH];
291     CHAR szDir[MAX_PATH];
292     CHAR szDefaultExt[] = "txt";
293
294     ZeroMemory(&openfilename, sizeof(openfilename));
295
296     GetCurrentDirectory(sizeof(szDir), szDir);
297     lstrcpy(szPath,"*.txt");
298
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;
309
310
311     if (GetOpenFileName(&openfilename)) {
312         if (FileExists(openfilename.lpstrFile))
313             DoOpenFile(openfilename.lpstrFile);
314         else
315             AlertFileNotFound(openfilename.lpstrFile);
316     }
317 }
318
319
320 VOID DIALOG_FileSave(VOID)
321 {
322     if (Globals.szFileName[0] == '\0')
323         DIALOG_FileSaveAs();
324     else
325         DoSaveFile();
326 }
327
328 VOID DIALOG_FileSaveAs(VOID)
329 {
330     OPENFILENAME saveas;
331     CHAR szPath[MAX_PATH];
332     CHAR szDir[MAX_PATH];
333     CHAR szDefaultExt[] = "txt";
334
335     ZeroMemory(&saveas, sizeof(saveas));
336
337     GetCurrentDirectory(sizeof(szDir), szDir);
338     lstrcpy(szPath,"*.*");
339
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;
350
351     if (GetSaveFileName(&saveas)) {
352         SetFileName(szPath);
353         UpdateWindowCaption();
354         DoSaveFile();
355     }
356 }
357
358 VOID DIALOG_FilePrint(VOID)
359 {
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;
374
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);
382
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;
419
420     /* Let commdlg manage copy settings */
421     printer.nCopies               = (WORD)PD_USEDEVMODECOPIES;
422
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;
431
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);
438 /*
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);
442 */
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);*/
454
455     /* Get the page dimensions in pixels. */
456     cWidthPels = GetDeviceCaps(hContext, HORZRES);
457     cHeightPels = GetDeviceCaps(hContext, VERTRES);
458
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     }
480
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                 */
507                 TextOut(hContext, border*2, border+szMetric.cy*0.5, szDocumentName, count);
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     }
537
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);
561 }
562
563 VOID DIALOG_FilePageSetup(VOID)
564 {
565     DIALOG_PageSetup();
566 }
567
568 VOID DIALOG_FilePrinterSetup(VOID)
569 {
570     PRINTDLG printer;
571
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;
578
579     if (PrintDlg(&printer)) {
580         /* do nothing */
581     };
582 }
583
584 VOID DIALOG_FileExit(VOID)
585 {
586     PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
587 }
588
589 VOID DIALOG_EditUndo(VOID)
590 {
591     SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
592 }
593
594 VOID DIALOG_EditCut(VOID)
595 {
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);
610 }
611
612 VOID DIALOG_EditCopy(VOID)
613 {
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);
628 }
629
630 VOID DIALOG_EditPaste(VOID)
631 {
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     }
640 }
641
642 VOID DIALOG_EditDelete(VOID)
643 {
644         /* Delete */
645 }
646
647 VOID DIALOG_EditSelectAll(VOID)
648 {
649         /* Select all */
650 }
651
652
653 VOID DIALOG_EditTimeDate(VOID)
654 {
655     SYSTEMTIME   st;
656     LPSYSTEMTIME lpst = &st;
657     CHAR         szDate[MAX_STRING_LEN];
658     LPSTR        date = szDate;
659
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);
663 }
664
665 VOID DIALOG_EditWrap(VOID)
666 {
667     Globals.bWrapLongLines = !Globals.bWrapLongLines;
668     CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
669         MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
670 }
671
672 VOID DIALOG_Search(VOID)
673 {
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;
681
682         /* We only need to create the modal FindReplace dialog which will */
683         /* notify us of incoming events using hMainWnd Window Messages    */
684
685         Globals.hFindReplaceDlg = FindText(&Globals.find);
686         assert(Globals.hFindReplaceDlg !=0);
687 }
688
689 VOID DIALOG_SearchNext(VOID)
690 {
691         /* Search Next */
692 }
693
694 VOID DIALOG_HelpContents(VOID)
695 {
696         WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
697 }
698
699 VOID DIALOG_HelpSearch(VOID)
700 {
701         /* Search Help */
702 }
703
704 VOID DIALOG_HelpHelp(VOID)
705 {
706         WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
707 }
708
709 VOID DIALOG_HelpLicense(VOID)
710 {
711         WineLicense(Globals.hMainWnd);
712 }
713
714 VOID DIALOG_HelpNoWarranty(VOID)
715 {
716         WineWarranty(Globals.hMainWnd);
717 }
718
719 VOID DIALOG_HelpAboutWine(VOID)
720 {
721         CHAR szNotepad[MAX_STRING_LEN];
722
723         LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, sizeof(szNotepad));
724         ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0);
725 }
726
727
728 /***********************************************************************
729  *
730  *           DIALOG_PageSetup
731  */
732
733 VOID DIALOG_PageSetup(VOID)
734 {
735   WNDPROC lpfnDlg;
736
737   lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
738   DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
739             Globals.hMainWnd, (DLGPROC)lpfnDlg);
740   FreeProcInstance(lpfnDlg);
741 }
742
743
744 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
745  *
746  *           DIALOG_PAGESETUP_DlgProc
747  */
748
749 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
750 {
751
752    switch (msg)
753     {
754     case WM_COMMAND:
755       switch (wParam)
756         {
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;
767
768         case IDCANCEL:
769           /* discard user input and close dialog */
770           EndDialog(hDlg, IDCANCEL);
771           return TRUE;
772
773         case IDHELP:
774           /* FIXME: Bring this to work */
775           MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION);
776           return TRUE;
777         }
778       break;
779
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;
789     }
790
791   return FALSE;
792 }