4 * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
5 * To be distributed under the Wine License
31 static LRESULT
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
35 int AlertIDS(UINT ids_message
, UINT ids_caption
, WORD type
) {
37 * Given some ids strings, this acts as a language-aware wrapper for
40 CHAR szMessage
[MAX_STRING_LEN
];
41 CHAR szCaption
[MAX_STRING_LEN
];
43 LoadString(Globals
.hInstance
, ids_message
, szMessage
, sizeof(szMessage
));
44 LoadString(Globals
.hInstance
, ids_caption
, szCaption
, sizeof(szCaption
));
46 return (MessageBox(Globals
.hMainWnd
, szMessage
, szCaption
, type
));
49 void AlertFileNotFound(LPCSTR szFileName
) {
52 CHAR szMessage
[MAX_STRING_LEN
];
53 CHAR szRessource
[MAX_STRING_LEN
];
55 /* Load and format szMessage */
56 LoadString(Globals
.hInstance
, IDS_NOTFOUND
, szRessource
, sizeof(szRessource
));
57 wvsprintf(szMessage
, szRessource
, szFileName
);
60 LoadString(Globals
.hInstance
, IDS_ERROR
, szRessource
, sizeof(szRessource
));
62 /* Display Modal Dialog */
63 nResult
= MessageBox(Globals
.hMainWnd
, szMessage
, szRessource
, MB_ICONEXCLAMATION
);
67 int AlertFileNotSaved(LPCSTR szFileName
) {
70 CHAR szMessage
[MAX_STRING_LEN
];
71 CHAR szRessource
[MAX_STRING_LEN
];
73 /* Load and format Message */
75 LoadString(Globals
.hInstance
, IDS_NOTSAVED
, szRessource
, sizeof(szRessource
));
76 wvsprintf(szMessage
, szRessource
, szFileName
);
80 LoadString(Globals
.hInstance
, IDS_ERROR
, szRessource
, sizeof(szRessource
));
83 nResult
= MessageBox(Globals
.hMainWnd
, szMessage
, szRessource
, MB_ICONEXCLAMATION
+ MB_YESNOCANCEL
);
88 VOID
AlertOutOfMemory(void) {
91 nResult
= AlertIDS(IDS_OUT_OF_MEMORY
, IDS_ERROR
, MB_ICONEXCLAMATION
);
96 BOOL
ExistFile(LPCSTR szFilename
) {
98 * Returns: TRUE - if "szFileName" exists
99 * FALSE - if it does not
101 WIN32_FIND_DATA entry
;
104 hFile
= FindFirstFile(szFilename
, &entry
);
106 return (hFile
!=INVALID_HANDLE_VALUE
);
109 VOID
DoSaveFile(VOID
) {
111 /* FIXME: Really Save the file */
112 /* ... (Globals.szFileName); */
116 BOOL
DoCloseFile(void) {
117 /* Return value: TRUE - User agreed to close (both save/don't save) */
118 /* FALSE - User cancelled close by selecting "Cancel" */
122 if (strlen(Globals
.szFileName
)>0) {
123 /* prompt user to save changes */
124 nResult
= AlertFileNotSaved(Globals
.szFileName
);
126 case IDYES
: DoSaveFile();
131 case IDCANCEL
: return(FALSE
);
134 default: return(FALSE
);
139 /* Forget file name */
140 lstrcpy(Globals
.szFileName
, "");
141 LANGUAGE_UpdateWindowCaption();
146 void DoOpenFile(LPCSTR szFileName
) {
151 /* Close any files and prompt to save changes */
153 GetFileTitle(szFileName
, Globals
.szFileName
, sizeof(Globals
.szFileName
));
154 LANGUAGE_UpdateWindowCaption();
155 hFile
= _lopen(szFileName
, OF_READ
);
156 nResult
= _lread(hFile
, Globals
.Buffer
, sizeof(Globals
.Buffer
));
159 /* FIXME: Append time/date if first line contains LOGPREFIX */
160 /* (Globals.Buffer, ) */
165 VOID
DIALOG_FileNew(VOID
)
167 /* Close any files and promt to save changes */
173 VOID
DIALOG_FileOpen(VOID
)
175 OPENFILENAME openfilename
;
176 CHAR szPath
[MAX_PATHNAME_LEN
];
177 CHAR szDir
[MAX_PATHNAME_LEN
];
178 CHAR szzFilter
[2 * MAX_STRING_LEN
+ 100];
179 CHAR szDefaultExt
[4];
182 lstrcpy(szDefaultExt
, "txt");
184 LoadString(Globals
.hInstance
, IDS_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
188 LoadString(Globals
.hInstance
, IDS_ALL_FILES
, p
, MAX_STRING_LEN
);
194 GetCurrentDirectory(sizeof(szDir
), szDir
);
195 lstrcpy(szPath
,"*.txt");
197 openfilename
.lStructSize
= sizeof(OPENFILENAME
);
198 openfilename
.hwndOwner
= Globals
.hMainWnd
;
199 openfilename
.hInstance
= Globals
.hInstance
;
200 openfilename
.lpstrFilter
= szzFilter
;
201 openfilename
.lpstrCustomFilter
= 0;
202 openfilename
.nMaxCustFilter
= 0;
203 openfilename
.nFilterIndex
= 0;
204 openfilename
.lpstrFile
= szPath
;
205 openfilename
.nMaxFile
= sizeof(szPath
);
206 openfilename
.lpstrFileTitle
= 0;
207 openfilename
.nMaxFileTitle
= 0;
208 openfilename
.lpstrInitialDir
= szDir
;
209 openfilename
.lpstrTitle
= 0;
210 openfilename
.Flags
= OFN_FILEMUSTEXIST
+ OFN_PATHMUSTEXIST
;
211 openfilename
.nFileOffset
= 0;
212 openfilename
.nFileExtension
= 0;
213 openfilename
.lpstrDefExt
= szDefaultExt
;
214 openfilename
.lCustData
= 0;
215 openfilename
.lpfnHook
= 0;
216 openfilename
.lpTemplateName
= 0;
218 if (GetOpenFileName(&openfilename
)) {
220 if (ExistFile(openfilename
.lpstrFile
))
221 DoOpenFile(openfilename
.lpstrFile
);
223 AlertFileNotFound(openfilename
.lpstrFile
);
228 VOID
DIALOG_FileSave(VOID
)
230 /* FIXME: Save File */
235 VOID
DIALOG_FileSaveAs(VOID
)
238 CHAR szPath
[MAX_PATHNAME_LEN
];
239 CHAR szDir
[MAX_PATHNAME_LEN
];
240 CHAR szDefaultExt
[4];
241 CHAR szzFilter
[2 * MAX_STRING_LEN
+ 100];
245 lstrcpy(szDefaultExt
, "txt");
247 LoadString(Globals
.hInstance
, IDS_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
251 LoadString(Globals
.hInstance
, IDS_ALL_FILES
, p
, MAX_STRING_LEN
);
257 lstrcpy(szPath
,"*.*");
259 GetCurrentDirectory(sizeof(szDir
), szDir
);
261 saveas
.lStructSize
= sizeof(OPENFILENAME
);
262 saveas
.hwndOwner
= Globals
.hMainWnd
;
263 saveas
.hInstance
= Globals
.hInstance
;
264 saveas
.lpstrFilter
= szzFilter
;
265 saveas
.lpstrCustomFilter
= 0;
266 saveas
.nMaxCustFilter
= 0;
267 saveas
.nFilterIndex
= 0;
268 saveas
.lpstrFile
= szPath
;
269 saveas
.nMaxFile
= sizeof(szPath
);
270 saveas
.lpstrFileTitle
= 0;
271 saveas
.nMaxFileTitle
= 0;
272 saveas
.lpstrInitialDir
= szDir
;
273 saveas
.lpstrTitle
= 0;
274 saveas
.Flags
= OFN_PATHMUSTEXIST
+ OFN_OVERWRITEPROMPT
+ OFN_HIDEREADONLY
;
275 saveas
.nFileOffset
= 0;
276 saveas
.nFileExtension
= 0;
277 saveas
.lpstrDefExt
= szDefaultExt
;
278 saveas
.lCustData
= 0;
280 saveas
.lpTemplateName
= 0;
282 if (GetSaveFileName(&saveas
)) {
283 lstrcpy(Globals
.szFileName
, saveas
.lpstrFile
);
284 LANGUAGE_UpdateWindowCaption();
289 VOID
DIALOG_FilePrint(VOID
)
298 CHAR szDocumentName
[MAX_STRING_LEN
]; /* Name of document */
299 CHAR szPrinterName
[MAX_STRING_LEN
]; /* Name of the printer */
300 CHAR szDeviceName
[MAX_STRING_LEN
]; /* Name of the printer device */
301 CHAR szOutput
[MAX_STRING_LEN
]; /* in which file/device to print */
303 /* LPDEVMODE hDevMode; */
304 /* LPDEVNAMES hDevNames; */
306 /* hDevMode = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVMODE)); */
307 /* hDevNames = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVNAMES)); */
309 /* Get Current Settings */
311 printer
.lStructSize
= sizeof(PRINTDLG
);
312 printer
.hwndOwner
= Globals
.hMainWnd
;
313 printer
.hInstance
= Globals
.hInstance
;
315 /* Let PrintDlg create a DEVMODE structure */
316 printer
.hDevMode
= 0;
317 printer
.hDevNames
= 0;
319 printer
.Flags
= PD_RETURNDEFAULT
;
320 printer
.nFromPage
= 0;
322 printer
.nMinPage
= 0;
323 printer
.nMaxPage
= 0;
325 printer
.lCustData
= 0;
326 printer
.lpfnPrintHook
= 0;
327 printer
.lpfnSetupHook
= 0;
328 printer
.lpPrintTemplateName
= 0;
329 printer
.lpSetupTemplateName
= 0;
330 printer
.hPrintTemplate
= 0;
331 printer
.hSetupTemplate
= 0;
333 nResult
= PrintDlg(&printer
);
335 /* hContext = CreateDC(, szDeviceName, "TEST.TXT", 0); */
337 /* Congratulations to those Microsoft Engineers responsable */
338 /* for the following pointer acrobatics */
340 assert(printer
.hDevNames
!=0);
342 nBase
= (LONG
)(printer
.hDevNames
);
344 nOffset
= (WORD
)((LPDEVNAMES
) printer
.hDevNames
)->wDriverOffset
;
345 lstrcpy(szPrinterName
, (LPCSTR
) (nBase
+ nOffset
));
347 nOffset
= (WORD
)((LPDEVNAMES
) printer
.hDevNames
)->wDeviceOffset
;
348 lstrcpy(szDeviceName
, (LPCSTR
) (nBase
+ nOffset
));
350 nOffset
= (WORD
)((LPDEVNAMES
) printer
.hDevNames
)->wOutputOffset
;
351 lstrcpy(szOutput
, (LPCSTR
) (nBase
+ nOffset
));
353 MessageBox(Globals
.hMainWnd
, szPrinterName
, "Printer Name", MB_ICONEXCLAMATION
);
354 MessageBox(Globals
.hMainWnd
, szDeviceName
, "Device Name", MB_ICONEXCLAMATION
);
355 MessageBox(Globals
.hMainWnd
, szOutput
, "Output", MB_ICONEXCLAMATION
);
357 /* Set some default flags */
359 bFlags
= PD_RETURNDC
+ PD_SHOWHELP
;
362 /* Remove "Print Selection" if there is no selection */
363 bFlags
= bFlags
+ PD_NOSELECTION
;
366 printer
.Flags
= bFlags
;
368 printer.nFromPage = 0;
370 printer.nMinPage = 0;
371 printer.nMaxPage = 0;
374 /* Let commdlg manage copy settings */
375 printer
.nCopies
= PD_USEDEVMODECOPIES
;
377 if (PrintDlg(&printer
)) {
379 /* initialize DOCINFO */
380 di
.cbSize
= sizeof(DOCINFO
);
381 lstrcpy(di
.lpszDocName
, szDocumentName
);
382 lstrcpy(di
.lpszOutput
, szOutput
);
384 hContext
= printer
.hDC
;
386 assert( (int) hContext
!=PD_RETURNDC
);
388 SetMapMode(hContext
, MM_LOMETRIC
);
389 /* SetViewPortExExt(hContext, 10, 10, 0); */
390 SetBkMode(hContext
, OPAQUE
);
392 nResult
= TextOut(hContext
, 0, 0, " ", 1);
393 assert(nResult
!= 0);
395 nResult
= StartDoc(hContext
, &di
);
396 assert(nResult
!= SP_ERROR
);
398 nResult
= StartPage(hContext
);
401 /* FIXME: actually print */
403 nResult
= EndPage(hContext
);
407 MessageBox(Globals
.hMainWnd
, "Generic Error", "Print Engine Error", MB_ICONEXCLAMATION
);
410 MessageBox(Globals
.hMainWnd
, "The print job was aborted.", "Print Engine Error", MB_ICONEXCLAMATION
);
413 MessageBox(Globals
.hMainWnd
, "The print job was aborted using the Print Manager ", "Print Engine Error", MB_ICONEXCLAMATION
);
416 MessageBox(Globals
.hMainWnd
, "Out of disk space", "Print Engine Error", MB_ICONEXCLAMATION
);
422 MessageBox(Globals
.hMainWnd
, "Default", "Print", MB_ICONEXCLAMATION
);
424 nResult
= EndDoc(hContext
);
426 nResult
= DeleteDC(hContext
);
430 /* GlobalFree(hDevNames); */
431 /* GlobalFree(hDevMode); */
434 VOID
DIALOG_FilePageSetup(VOID
)
439 VOID
DIALOG_FilePrinterSetup(VOID
)
443 printer
.lStructSize
= sizeof(PRINTDLG
);
444 printer
.hwndOwner
= Globals
.hMainWnd
;
445 printer
.hInstance
= Globals
.hInstance
;
446 printer
.hDevMode
= 0;
447 printer
.hDevNames
= 0;
449 printer
.Flags
= PD_PRINTSETUP
;
450 printer
.nFromPage
= 0;
452 printer
.nMinPage
= 0;
453 printer
.nMaxPage
= 0;
455 printer
.lCustData
= 0;
456 printer
.lpfnPrintHook
= 0;
457 printer
.lpfnSetupHook
= 0;
458 printer
.lpPrintTemplateName
= 0;
459 printer
.lpSetupTemplateName
= 0;
460 printer
.hPrintTemplate
= 0;
461 printer
.hSetupTemplate
= 0;
463 if (PrintDlg(&printer
)) {
469 VOID
DIALOG_FileExit(VOID
)
476 VOID
DIALOG_EditUndo(VOID
)
478 MessageBox(Globals
.hMainWnd
, "Undo", "Debug", MB_ICONEXCLAMATION
);
482 VOID
DIALOG_EditCut(VOID
)
486 hMem
= GlobalAlloc(GMEM_ZEROINIT
, 99);
488 OpenClipboard(Globals
.hMainWnd
);
491 /* FIXME: Get text */
492 lstrcpy((CHAR
*)hMem
, "Hello World");
494 SetClipboardData(CF_TEXT
, hMem
);
500 VOID
DIALOG_EditCopy(VOID
)
504 hMem
= GlobalAlloc(GMEM_ZEROINIT
, 99);
506 OpenClipboard(Globals
.hMainWnd
);
509 /* FIXME: Get text */
510 lstrcpy((CHAR
*)hMem
, "Hello World");
512 SetClipboardData(CF_TEXT
, hMem
);
518 VOID
DIALOG_EditPaste(VOID
)
522 if (IsClipboardFormatAvailable(CF_TEXT
)) {
523 OpenClipboard(Globals
.hMainWnd
);
524 hClipText
= GetClipboardData(CF_TEXT
);
526 MessageBox(Globals
.hMainWnd
, (CHAR
*)hClipText
, "PASTE", MB_ICONEXCLAMATION
);
530 VOID
DIALOG_EditDelete(VOID
)
535 VOID
DIALOG_EditSelectAll(VOID
)
540 VOID
DIALOG_EditTimeDate(VOID
)
543 LPSYSTEMTIME lpst
= &st
;
544 CHAR szDate
[MAX_STRING_LEN
];
548 GetDateFormat(LOCALE_USER_DEFAULT
, LOCALE_SLONGDATE
, lpst
, NULL
, date
, MAX_STRING_LEN
);
549 GetTimeFormat(LOCALE_USER_DEFAULT
, LOCALE_STIMEFORMAT
, lpst
, NULL
, date
, MAX_STRING_LEN
);
553 VOID
DIALOG_EditWrap(VOID
)
555 Globals
.bWrapLongLines
= !Globals
.bWrapLongLines
;
556 CheckMenuItem(Globals
.hEditMenu
, NP_EDIT_WRAP
, MF_BYCOMMAND
|
557 (Globals
.bWrapLongLines
? MF_CHECKED
: MF_UNCHECKED
));
560 VOID
DIALOG_Search(VOID
)
562 Globals
.find
.lStructSize
= sizeof(Globals
.find
);
563 Globals
.find
.hwndOwner
= Globals
.hMainWnd
;
564 Globals
.find
.hInstance
= Globals
.hInstance
;
565 Globals
.find
.lpstrFindWhat
= (CHAR
*) &Globals
.szFindText
;
566 Globals
.find
.wFindWhatLen
= sizeof(Globals
.szFindText
);
567 Globals
.find
.lpstrReplaceWith
= 0;
568 Globals
.find
.wReplaceWithLen
= 0;
569 Globals
.find
.Flags
= FR_DOWN
;
570 Globals
.find
.lCustData
= 0;
571 Globals
.find
.lpfnHook
= 0;
572 Globals
.find
.lpTemplateName
= 0;
574 /* We only need to create the modal FindReplace dialog which will */
575 /* notify us of incoming events using hMainWnd Window Messages */
577 Globals
.hFindReplaceDlg
= FindText(&Globals
.find
);
578 assert(Globals
.hFindReplaceDlg
!=0);
581 VOID
DIALOG_SearchNext(VOID
)
586 VOID
DIALOG_HelpContents(VOID
)
588 WinHelp(Globals
.hMainWnd
, HELPFILE
, HELP_INDEX
, 0);
591 VOID
DIALOG_HelpSearch(VOID
)
596 VOID
DIALOG_HelpHelp(VOID
)
598 WinHelp(Globals
.hMainWnd
, HELPFILE
, HELP_HELPONHELP
, 0);
601 VOID
DIALOG_HelpLicense(VOID
)
603 WineLicense(Globals
.hMainWnd
, Globals
.lpszLanguage
);
606 VOID
DIALOG_HelpNoWarranty(VOID
)
608 WineWarranty(Globals
.hMainWnd
, Globals
.lpszLanguage
);
611 VOID
DIALOG_HelpAboutWine(VOID
)
613 CHAR szNotepad
[MAX_STRING_LEN
];
615 LoadString(Globals
.hInstance
, IDS_NOTEPAD
, szNotepad
, sizeof(szNotepad
));
616 ShellAbout(Globals
.hMainWnd
, szNotepad
, "Notepad\n" WINE_RELEASE_INFO
, 0);
619 /***********************************************************************
624 VOID
DIALOG_PageSetup(VOID
)
628 lpfnDlg
= MakeProcInstance(DIALOG_PAGESETUP_DlgProc
, Globals
.hInstance
);
629 DialogBox(Globals
.hInstance
, STRING_PAGESETUP_Xx
, Globals
.hMainWnd
, lpfnDlg
);
630 FreeProcInstance(lpfnDlg
);
634 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
636 * DIALOG_PAGESETUP_DlgProc
639 static LRESULT
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
648 /* save user input and close dialog */
649 GetDlgItemText(hDlg
, NP_PAGESETUP_HEAD
, Globals
.szHeader
, sizeof(Globals
.szHeader
));
650 GetDlgItemText(hDlg
, NP_PAGESETUP_TAIL
, Globals
.szFooter
, sizeof(Globals
.szFooter
));
651 GetDlgItemText(hDlg
, NP_PAGESETUP_TOP
, Globals
.szMarginTop
, sizeof(Globals
.szMarginTop
));
652 GetDlgItemText(hDlg
, NP_PAGESETUP_BOTTOM
, Globals
.szMarginBottom
, sizeof(Globals
.szMarginBottom
));
653 GetDlgItemText(hDlg
, NP_PAGESETUP_LEFT
, Globals
.szMarginLeft
, sizeof(Globals
.szMarginLeft
));
654 GetDlgItemText(hDlg
, NP_PAGESETUP_RIGHT
, Globals
.szMarginRight
, sizeof(Globals
.szMarginRight
));
655 EndDialog(hDlg
, IDOK
);
659 /* discard user input and close dialog */
660 EndDialog(hDlg
, IDCANCEL
);
664 /* FIXME: Bring this to work */
665 MessageBox(Globals
.hMainWnd
, "Sorry, no help available", "Help", MB_ICONEXCLAMATION
);
671 /* fetch last user input prior to display dialog */
672 SetDlgItemText(hDlg
, NP_PAGESETUP_HEAD
, Globals
.szHeader
);
673 SetDlgItemText(hDlg
, NP_PAGESETUP_TAIL
, Globals
.szFooter
);
674 SetDlgItemText(hDlg
, NP_PAGESETUP_TOP
, Globals
.szMarginTop
);
675 SetDlgItemText(hDlg
, NP_PAGESETUP_BOTTOM
, Globals
.szMarginBottom
);
676 SetDlgItemText(hDlg
, NP_PAGESETUP_LEFT
, Globals
.szMarginLeft
);
677 SetDlgItemText(hDlg
, NP_PAGESETUP_RIGHT
, Globals
.szMarginRight
);