Initial revision of the About dialog.
[lilypad-windows.git] / dialog.c
blob43cc8c418ee8c966b389cc744178ac2bdb9b40d9
1 /* -*-c-style:stroustrup-*-
2 * LilyPad (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., 51 Franklin St, Suite 500, Boston, MA 02110-1335, USA
23 #include <assert.h>
24 #include <stdio.h>
25 #include <windows.h>
26 #include <commdlg.h>
27 #include <shlwapi.h>
29 #include "main.h"
30 #include "dialog.h"
32 static const __WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
34 static INT_PTR WINAPI DIALOG_AboutLilyPadDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
35 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
37 VOID ShowLastError(void)
39 DWORD error = GetLastError();
40 if (error != NO_ERROR)
42 __LPWSTR lpMsgBuf;
43 __WCHAR 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, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
51 LocalFree(lpMsgBuf);
55 /**
56 * Sets the caption of the main window according to Globals.szFileTitle:
57 * Untitled - LilyPad if no file is open
58 * filename - LilyPad if a file is given
60 static void UpdateWindowCaption(void)
62 __WCHAR szCaption[MAX_STRING_LEN];
63 __WCHAR szLilyPad[MAX_STRING_LEN];
64 static const __WCHAR hyphenW[] = { ' ','-',' ',0 };
66 LoadString(Globals.hInstance, STRING_LILYPAD, szCaption, SIZEOF(szCaption));
68 if (Globals.szFileTitle[0] != '\0')
69 lstrcpy (szCaption, Globals.szFileTitle);
70 else
71 LoadString(Globals.hInstance, STRING_UNTITLED, szCaption, SIZEOF(szCaption));
73 LoadString(Globals.hInstance, STRING_LILYPAD, szLilyPad, SIZEOF(szLilyPad));
74 lstrcat(szCaption, hyphenW);
75 lstrcat(szCaption, szLilyPad);
77 SetWindowText(Globals.hMainWnd, szCaption);
80 int DIALOG_StringMsgBox(HWND hParent, int formatId, __LPCWSTR szString, DWORD dwFlags)
82 __WCHAR szMessage[MAX_STRING_LEN];
83 __WCHAR szResource[MAX_STRING_LEN];
85 /* Load and format szMessage */
86 LoadString(Globals.hInstance, formatId, szResource, SIZEOF(szResource));
87 wnsprintf(szMessage, SIZEOF(szMessage), szResource, szString);
89 /* Load szCaption */
90 if ((dwFlags & MB_ICONMASK) == MB_ICONEXCLAMATION)
91 LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource));
92 else
93 LoadString(Globals.hInstance, STRING_LILYPAD, szResource, SIZEOF(szResource));
95 /* Display Modal Dialog */
96 if (hParent == NULL)
97 hParent = Globals.hMainWnd;
98 return MessageBox(hParent, szMessage, szResource, dwFlags);
101 static void AlertFileNotFound(__LPCWSTR szFileName)
103 DIALOG_StringMsgBox(0, STRING_NOTFOUND, szFileName, MB_ICONEXCLAMATION|MB_OK);
106 static int AlertFileNotSaved(__LPCWSTR szFileName)
108 __WCHAR szUntitled[MAX_STRING_LEN];
110 LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled));
112 return DIALOG_StringMsgBox(0,
113 STRING_NOTSAVED,
114 szFileName[0] ? szFileName : szUntitled,
115 MB_ICONQUESTION|MB_YESNOCANCEL);
119 * Returns:
120 * TRUE - if file exists
121 * FALSE - if file does not exist
123 BOOL FileExists(__LPCWSTR szFilename)
125 WIN32_FIND_DATA entry;
126 HANDLE hFile;
128 hFile = FindFirstFile(szFilename, &entry);
129 FindClose(hFile);
131 return (hFile != INVALID_HANDLE_VALUE);
135 static VOID DoSaveFile(VOID)
137 HANDLE hFile;
138 DWORD dwNumWrite;
139 LPSTR pTemp;
140 DWORD size;
142 hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
143 NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
144 if(hFile == INVALID_HANDLE_VALUE)
146 ShowLastError();
147 return;
150 size = GetWindowTextLengthA(Globals.hEdit) + 1;
151 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
152 if (!pTemp)
154 CloseHandle(hFile);
155 ShowLastError();
156 return;
158 size = GetWindowTextA(Globals.hEdit, pTemp, size);
160 if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL))
161 ShowLastError();
162 else
163 SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
165 SetEndOfFile(hFile);
166 CloseHandle(hFile);
167 HeapFree(GetProcessHeap(), 0, pTemp);
171 * Returns:
172 * TRUE - User agreed to close (both save/don't save)
173 * FALSE - User cancelled close by selecting "Cancel"
175 BOOL DoCloseFile(void)
177 int nResult;
178 static const __WCHAR empty_strW[] = { 0 };
180 if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
182 /* prompt user to save changes */
183 nResult = AlertFileNotSaved(Globals.szFileName);
184 switch (nResult) {
185 case IDYES: DIALOG_FileSave();
186 break;
188 case IDNO: break;
190 case IDCANCEL: return(FALSE);
192 default: return(FALSE);
193 } /* switch */
194 } /* if */
196 SetFileName(empty_strW);
198 UpdateWindowCaption();
199 return(TRUE);
203 void DoOpenFile(__LPCWSTR szFileName)
205 static const __WCHAR dotlog[] = { '.','L','O','G',0 };
206 HANDLE hFile;
207 __LPWSTR pTemp;
208 DWORD size;
209 DWORD dwNumRead;
210 __WCHAR log[5];
212 /* Close any files and prompt to save changes */
213 if (!DoCloseFile())
214 return;
216 hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
217 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
218 if(hFile == INVALID_HANDLE_VALUE)
220 AlertFileNotFound(szFileName);
221 return;
224 size = GetFileSize(hFile, NULL);
225 if (size == INVALID_FILE_SIZE)
227 CloseHandle(hFile);
228 ShowLastError();
229 return;
231 size++;
233 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
234 if (!pTemp)
236 CloseHandle(hFile);
237 ShowLastError();
238 return;
241 if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
243 CloseHandle(hFile);
244 HeapFree(GetProcessHeap(), 0, pTemp);
245 ShowLastError();
246 return;
249 CloseHandle(hFile);
250 pTemp[dwNumRead] = 0;
252 #ifdef UNICODE
253 if (IsTextUnicode(pTemp, dwNumRead, NULL))
255 __LPWSTR p = (__LPWSTR)pTemp;
256 /* We need to strip BOM Unicode character, SetWindowTextW won't do it for us. */
257 if (*p == 0xFEFF || *p == 0xFFFE) p++;
258 SetWindowText(Globals.hEdit, p);
260 else
261 #endif
262 SetWindowText(Globals.hEdit, pTemp);
264 HeapFree(GetProcessHeap(), 0, pTemp);
266 SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
267 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
268 SetFocus(Globals.hEdit);
270 /* If the file starts with .LOG, add a time/date at the end and set cursor after
271 * See http://support.microsoft.com/?kbid=260563
273 if (GetWindowText
274 (Globals.hEdit, log, sizeof(log)/sizeof(log[0])) && !lstrcmp(log, dotlog))
276 static const __WCHAR lfW[] = { '\r','\n',0 };
277 SendMessage(Globals.hEdit, EM_SETSEL, GetWindowTextLength(Globals.hEdit), -1);
278 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW);
279 DIALOG_EditTimeDate();
280 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW);
283 SetFileName(szFileName);
284 UpdateWindowCaption();
287 VOID DIALOG_FileNew(VOID)
289 static const __WCHAR empty_strW[] = { 0 };
291 /* Close any files and promt to save changes */
292 if (DoCloseFile()) {
293 SetWindowText(Globals.hEdit, empty_strW);
294 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
295 SetFocus(Globals.hEdit);
299 VOID DIALOG_FileOpen(VOID)
301 OPENFILENAME openfilename;
302 __WCHAR szPath[MAX_PATH];
303 __WCHAR szDir[MAX_PATH];
304 static const __WCHAR szDefaultExt[] = { 'l','y',0 };
305 static const __WCHAR ly_files[] = { '*','.','l','y',0 };
307 ZeroMemory(&openfilename, sizeof(openfilename));
309 GetCurrentDirectory(SIZEOF(szDir), szDir);
310 lstrcpy(szPath, ly_files);
312 openfilename.lStructSize = sizeof(openfilename);
313 openfilename.hwndOwner = Globals.hMainWnd;
314 openfilename.hInstance = Globals.hInstance;
315 openfilename.lpstrFilter = Globals.szFilter;
316 openfilename.lpstrFile = szPath;
317 openfilename.nMaxFile = SIZEOF(szPath);
318 openfilename.lpstrInitialDir = szDir;
319 openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
320 OFN_HIDEREADONLY;
321 openfilename.lpstrDefExt = szDefaultExt;
324 if (GetOpenFileName(&openfilename))
325 DoOpenFile(openfilename.lpstrFile);
329 VOID DIALOG_FileSave(VOID)
331 if (Globals.szFileName[0] == '\0')
332 DIALOG_FileSaveAs();
333 else
334 DoSaveFile();
337 VOID DIALOG_FileSaveAs(VOID)
339 OPENFILENAME saveas;
340 __WCHAR szPath[MAX_PATH];
341 __WCHAR szDir[MAX_PATH];
342 static const __WCHAR szDefaultExt[] = { 'l','y',0 };
343 static const __WCHAR ly_files[] = { '*','.','l','y',0 };
345 ZeroMemory(&saveas, sizeof(saveas));
347 GetCurrentDirectory(SIZEOF(szDir), szDir);
348 lstrcpy(szPath, ly_files);
350 saveas.lStructSize = sizeof(OPENFILENAME);
351 saveas.hwndOwner = Globals.hMainWnd;
352 saveas.hInstance = Globals.hInstance;
353 saveas.lpstrFilter = Globals.szFilter;
354 saveas.lpstrFile = szPath;
355 saveas.nMaxFile = SIZEOF(szPath);
356 saveas.lpstrInitialDir = szDir;
357 saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
358 OFN_HIDEREADONLY;
359 saveas.lpstrDefExt = szDefaultExt;
361 if (GetSaveFileName(&saveas)) {
362 SetFileName(szPath);
363 UpdateWindowCaption();
364 DoSaveFile();
368 VOID DIALOG_FilePrint(VOID)
370 DOCINFO di;
371 PRINTDLG printer;
372 SIZE szMetric;
373 int cWidthPels, cHeightPels, border;
374 int xLeft, yTop, pagecount, dopage, copycount;
375 unsigned int i;
376 LOGFONT hdrFont;
377 HFONT font, old_font=0;
378 DWORD size;
379 __LPWSTR pTemp;
380 static const __WCHAR times_new_romanW[] = { 'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0 };
382 /* Get a small font and print some header info on each page */
383 hdrFont.lfHeight = 100;
384 hdrFont.lfWidth = 0;
385 hdrFont.lfEscapement = 0;
386 hdrFont.lfOrientation = 0;
387 hdrFont.lfWeight = FW_BOLD;
388 hdrFont.lfItalic = 0;
389 hdrFont.lfUnderline = 0;
390 hdrFont.lfStrikeOut = 0;
391 hdrFont.lfCharSet = ANSI_CHARSET;
392 hdrFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
393 hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
394 hdrFont.lfQuality = PROOF_QUALITY;
395 hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
396 lstrcpy(hdrFont.lfFaceName, times_new_romanW);
398 font = CreateFontIndirect(&hdrFont);
400 /* Get Current Settings */
401 ZeroMemory(&printer, sizeof(printer));
402 printer.lStructSize = sizeof(printer);
403 printer.hwndOwner = Globals.hMainWnd;
404 printer.hDevMode = Globals.hDevMode;
405 printer.hDevNames = Globals.hDevNames;
406 printer.hInstance = Globals.hInstance;
408 /* Set some default flags */
409 printer.Flags = PD_RETURNDC;
410 printer.nFromPage = 0;
411 printer.nMinPage = 1;
412 /* we really need to calculate number of pages to set nMaxPage and nToPage */
413 printer.nToPage = 0;
414 printer.nMaxPage = -1;
416 /* Let commdlg manage copy settings */
417 printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
419 if (!PrintDlg(&printer)) return;
421 Globals.hDevMode = printer.hDevMode;
422 Globals.hDevNames = printer.hDevNames;
424 assert(printer.hDC != 0);
426 /* initialize DOCINFO */
427 di.cbSize = sizeof(DOCINFO);
428 di.lpszDocName = Globals.szFileTitle;
429 di.lpszOutput = NULL;
430 di.lpszDatatype = NULL;
431 di.fwType = 0;
433 if (StartDoc(printer.hDC, &di) <= 0) return;
435 /* Get the page dimensions in pixels. */
436 cWidthPels = GetDeviceCaps(printer.hDC, HORZRES);
437 cHeightPels = GetDeviceCaps(printer.hDC, VERTRES);
439 /* Get the file text */
440 size = GetWindowTextLength(Globals.hEdit) + 1;
441 pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(__WCHAR));
442 if (!pTemp)
444 ShowLastError();
445 return;
447 size = GetWindowText(Globals.hEdit, pTemp, size);
449 border = 150;
450 for (copycount=1; copycount <= printer.nCopies; copycount++) {
451 i = 0;
452 pagecount = 1;
453 do {
454 static const __WCHAR letterM[] = { 'M',0 };
456 if (pagecount >= printer.nFromPage &&
457 /* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/
458 pagecount <= printer.nToPage)
459 dopage = 1;
460 else
461 dopage = 0;
463 old_font = SelectObject(printer.hDC, font);
464 GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
466 if (dopage) {
467 if (StartPage(printer.hDC) <= 0) {
468 static const __WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
469 static const __WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
470 MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION);
471 return;
473 /* Write a rectangle and header at the top of each page */
474 Rectangle(printer.hDC, border, border, cWidthPels-border, border+szMetric.cy*2);
475 /* I don't know what's up with this TextOut command. This comes out
476 kind of mangled.
478 TextOut(printer.hDC, border*2, border+szMetric.cy/2, Globals.szFileTitle, lstrlen(Globals.szFileTitle));
481 /* The starting point for the main text */
482 xLeft = border*2;
483 yTop = border+szMetric.cy*4;
485 SelectObject(printer.hDC, old_font);
486 GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
488 /* Since outputting strings is giving me problems, output the main
489 text one character at a time.
491 do {
492 if (pTemp[i] == '\n') {
493 xLeft = border*2;
494 yTop += szMetric.cy;
496 else if (pTemp[i] != '\r') {
497 if (dopage)
498 TextOut(printer.hDC, xLeft, yTop, &pTemp[i], 1);
499 xLeft += szMetric.cx;
501 } while (i++<size && yTop<(cHeightPels-border*2));
503 if (dopage)
504 EndPage(printer.hDC);
505 pagecount++;
506 } while (i<size);
509 EndDoc(printer.hDC);
510 DeleteDC(printer.hDC);
511 HeapFree(GetProcessHeap(), 0, pTemp);
514 VOID DIALOG_FilePrinterSetup(VOID)
516 PRINTDLG printer;
518 ZeroMemory(&printer, sizeof(printer));
519 printer.lStructSize = sizeof(printer);
520 printer.hwndOwner = Globals.hMainWnd;
521 printer.hDevMode = Globals.hDevMode;
522 printer.hDevNames = Globals.hDevNames;
523 printer.hInstance = Globals.hInstance;
524 printer.Flags = PD_PRINTSETUP;
525 printer.nCopies = 1;
527 PrintDlg(&printer);
529 Globals.hDevMode = printer.hDevMode;
530 Globals.hDevNames = printer.hDevNames;
533 VOID DIALOG_FileExit(VOID)
535 PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
538 VOID DIALOG_EditUndo(VOID)
540 SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
543 VOID DIALOG_EditCut(VOID)
545 SendMessage(Globals.hEdit, WM_CUT, 0, 0);
548 VOID DIALOG_EditCopy(VOID)
550 SendMessage(Globals.hEdit, WM_COPY, 0, 0);
553 VOID DIALOG_EditPaste(VOID)
555 SendMessage(Globals.hEdit, WM_PASTE, 0, 0);
558 VOID DIALOG_EditDelete(VOID)
560 SendMessage(Globals.hEdit, WM_CLEAR, 0, 0);
563 VOID DIALOG_EditSelectAll(VOID)
565 SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1);
568 VOID DIALOG_EditTimeDate(VOID)
570 SYSTEMTIME st;
571 __WCHAR szDate[MAX_STRING_LEN];
572 static const __WCHAR spaceW[] = { ' ',0 };
574 GetLocalTime(&st);
576 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN);
577 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
579 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)spaceW);
581 GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szDate, MAX_STRING_LEN);
582 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
585 VOID DIALOG_EditWrap(VOID)
587 BOOL modify = FALSE;
588 static const __WCHAR editW[] = { 'e','d','i','t',0 };
589 DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
590 ES_AUTOVSCROLL | ES_MULTILINE;
591 RECT rc;
592 DWORD size;
593 __LPWSTR pTemp;
595 size = GetWindowTextLength(Globals.hEdit) + 1;
596 pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(__WCHAR));
597 if (!pTemp)
599 ShowLastError();
600 return;
602 GetWindowText(Globals.hEdit, pTemp, size);
603 modify = SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0);
604 DestroyWindow(Globals.hEdit);
605 GetClientRect(Globals.hMainWnd, &rc);
606 if( Globals.bWrapLongLines ) dwStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
607 Globals.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, editW, NULL, dwStyle,
608 0, 0, rc.right, rc.bottom, Globals.hMainWnd,
609 NULL, Globals.hInstance, NULL);
610 SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)FALSE);
611 SetWindowText(Globals.hEdit, pTemp);
612 SendMessage(Globals.hEdit, EM_SETMODIFY, (WPARAM)modify, 0);
613 SetFocus(Globals.hEdit);
614 HeapFree(GetProcessHeap(), 0, pTemp);
616 Globals.bWrapLongLines = !Globals.bWrapLongLines;
617 CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
618 MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
621 VOID DIALOG_SelectFont(VOID)
623 CHOOSEFONT cf;
624 LOGFONT lf=Globals.lfFont;
626 ZeroMemory( &cf, sizeof(cf) );
627 cf.lStructSize=sizeof(cf);
628 cf.hwndOwner=Globals.hMainWnd;
629 cf.lpLogFont=&lf;
630 cf.Flags=CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
632 if( ChooseFont(&cf) )
634 HFONT currfont=Globals.hFont;
636 Globals.hFont=CreateFontIndirect( &lf );
637 Globals.lfFont=lf;
638 SendMessage( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE );
639 if( currfont!=NULL )
640 DeleteObject( currfont );
644 VOID DIALOG_Search(VOID)
646 ZeroMemory(&Globals.find, sizeof(Globals.find));
647 Globals.find.lStructSize = sizeof(Globals.find);
648 Globals.find.hwndOwner = Globals.hMainWnd;
649 Globals.find.hInstance = Globals.hInstance;
650 Globals.find.lpstrFindWhat = Globals.szFindText;
651 Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText);
652 Globals.find.Flags = FR_DOWN|FR_HIDEWHOLEWORD;
654 /* We only need to create the modal FindReplace dialog which will */
655 /* notify us of incoming events using hMainWnd Window Messages */
657 Globals.hFindReplaceDlg = FindText(&Globals.find);
658 assert(Globals.hFindReplaceDlg !=0);
661 VOID DIALOG_SearchNext(VOID)
663 if (Globals.lastFind.lpstrFindWhat == NULL)
664 DIALOG_Search();
665 else /* use the last find data */
666 LILYPAD_DoFind(&Globals.lastFind);
669 VOID DIALOG_HelpContents(VOID)
671 WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0);
674 VOID DIALOG_HelpSearch(VOID)
676 /* Search Help */
679 VOID DIALOG_HelpHelp(VOID)
681 WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0);
684 VOID DIALOG_HelpAboutLilyPad(VOID)
686 DialogBox (Globals.hInstance, MAKEINTRESOURCE(DIALOG_ABOUTLILYPAD),
687 Globals.hMainWnd, DIALOG_AboutLilyPadDlgProc);
690 static INT_PTR WINAPI DIALOG_AboutLilyPadDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
692 switch (msg)
694 case WM_COMMAND:
695 switch (wParam)
697 case IDOK:
698 EndDialog (hDlg, IDOK);
699 return TRUE;
700 case IDCANCEL:
701 EndDialog (hDlg, IDCANCEL);
702 return TRUE;
703 default:
704 break;
706 break;
707 case WM_INITDIALOG:
708 break;
711 return FALSE;
714 /***********************************************************************
716 * DIALOG_FilePageSetup
718 VOID DIALOG_FilePageSetup(void)
720 DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
721 Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc);
725 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
727 * DIALOG_PAGESETUP_DlgProc
730 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
733 switch (msg)
735 case WM_COMMAND:
736 switch (wParam)
738 case IDOK:
739 /* save user input and close dialog */
740 GetDlgItemText(hDlg, 0x141, Globals.szHeader, SIZEOF(Globals.szHeader));
741 GetDlgItemText(hDlg, 0x143, Globals.szFooter, SIZEOF(Globals.szFooter));
742 GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, SIZEOF(Globals.szMarginTop));
743 GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, SIZEOF(Globals.szMarginBottom));
744 GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, SIZEOF(Globals.szMarginLeft));
745 GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, SIZEOF(Globals.szMarginRight));
746 EndDialog(hDlg, IDOK);
747 return TRUE;
749 case IDCANCEL:
750 /* discard user input and close dialog */
751 EndDialog(hDlg, IDCANCEL);
752 return TRUE;
754 case IDHELP:
756 /* FIXME: Bring this to work */
757 static const __WCHAR sorryW[] = { 'S','o','r','r','y',',',' ','n','o',' ','h','e','l','p',' ','a','v','a','i','l','a','b','l','e',0 };
758 static const __WCHAR helpW[] = { 'H','e','l','p',0 };
759 MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION);
760 return TRUE;
763 default:
764 break;
766 break;
768 case WM_INITDIALOG:
769 /* fetch last user input prior to display dialog */
770 SetDlgItemText(hDlg, 0x141, Globals.szHeader);
771 SetDlgItemText(hDlg, 0x143, Globals.szFooter);
772 SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
773 SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
774 SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
775 SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);
776 break;
779 return FALSE;
783 * Returns:
784 * TRUE - Placement successful.
785 * FALSE - Placement outside of text.
787 BOOL GotoLineColumn(int nLine, int nColumn)
789 int nResult;
790 int nLines;
791 int nCharacters;
792 int nIndex;
794 /* Line count is zero based. */
795 if (nLine > 0)
796 nLine--;
798 /* The number of lines. */
799 nLines = SendMessage(Globals.hEdit, EM_GETLINECOUNT, 0, 0);
801 if (nLine > nLines)
802 return FALSE;
804 /* The number of characters in the selected line. */
805 nCharacters = SendMessage(Globals.hEdit, EM_LINELENGTH, nLine, 0);
807 if (nColumn > nCharacters)
808 nColumn = 0;
810 /* The desired line's character index. */
811 nIndex = SendMessage(Globals.hEdit, EM_LINEINDEX, nLine, 0);
813 /* select the text .. place cursor */
814 SendMessage(Globals.hEdit, EM_SETSEL, nIndex + nColumn, nIndex + nColumn);
816 return TRUE;