* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#define UNICODE
-
-#include <assert.h>
-#include <stdio.h>
-#include <windows.h>
-#include <commdlg.h>
-
-#include "main.h"
-#include "license.h"
-#include "dialog.h"
+#include <notepad.h>
static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
}
+BOOL HasFileExtension(LPCWSTR szFilename)
+{
+ LPCWSTR s;
+
+ s = wcsrchr(szFilename, '\\');
+ if (s)
+ szFilename = s;
+ return wcsrchr(szFilename, '.') != NULL;
+}
+
+
static VOID DoSaveFile(VOID)
{
HANDLE hFile;
{
static const WCHAR empty_strW[] = { 0 };
- /* Close any files and promt to save changes */
+ /* Close any files and prompt to save changes */
if (DoCloseFile()) {
SetWindowText(Globals.hEdit, empty_strW);
SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
DWORD size;
LPWSTR pTemp;
+ Globals.bWrapLongLines = !Globals.bWrapLongLines;
+
size = GetWindowTextLength(Globals.hEdit) + 1;
pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
if (!pTemp)
0, 0, rc.right, rc.bottom, Globals.hMainWnd,
NULL, Globals.hInstance, NULL);
SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)FALSE);
+ SendMessage(Globals.hEdit, EM_LIMITTEXT, 0, 0);
SetWindowTextW(Globals.hEdit, pTemp);
SetFocus(Globals.hEdit);
HeapFree(GetProcessHeap(), 0, pTemp);
-
- Globals.bWrapLongLines = !Globals.bWrapLongLines;
- CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
- MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
}
VOID DIALOG_SelectFont(VOID)
}
}
-VOID DIALOG_Search(VOID)
+typedef HWND (WINAPI *FINDPROC)(LPFINDREPLACE lpfr);
+
+static VOID DIALOG_SearchDialog(FINDPROC pfnProc)
{
- ZeroMemory(&Globals.find, sizeof(Globals.find));
- Globals.find.lStructSize = sizeof(Globals.find);
- Globals.find.hwndOwner = Globals.hMainWnd;
- Globals.find.hInstance = Globals.hInstance;
- Globals.find.lpstrFindWhat = Globals.szFindText;
- Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText);
- Globals.find.Flags = FR_DOWN;
+ ZeroMemory(&Globals.find, sizeof(Globals.find));
+ Globals.find.lStructSize = sizeof(Globals.find);
+ Globals.find.hwndOwner = Globals.hMainWnd;
+ Globals.find.hInstance = Globals.hInstance;
+ Globals.find.lpstrFindWhat = Globals.szFindText;
+ Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText);
+ Globals.find.lpstrReplaceWith = Globals.szReplaceText;
+ Globals.find.wReplaceWithLen = SIZEOF(Globals.szReplaceText);
+ Globals.find.Flags = FR_DOWN;
+
+ /* We only need to create the modal FindReplace dialog which will */
+ /* notify us of incoming events using hMainWnd Window Messages */
- /* We only need to create the modal FindReplace dialog which will */
- /* notify us of incoming events using hMainWnd Window Messages */
+ Globals.hFindReplaceDlg = pfnProc(&Globals.find);
+ assert(Globals.hFindReplaceDlg !=0);
+}
- Globals.hFindReplaceDlg = FindText(&Globals.find);
- assert(Globals.hFindReplaceDlg !=0);
+VOID DIALOG_Search(VOID)
+{
+ DIALOG_SearchDialog(FindText);
}
VOID DIALOG_SearchNext(VOID)
DIALOG_Search();
}
+VOID DIALOG_Replace(VOID)
+{
+ DIALOG_SearchDialog(ReplaceText);
+}
+
+static INT_PTR CALLBACK DIALOG_GoTo_DialogProc(HWND hwndDialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ BOOL bResult = FALSE;
+ HWND hTextBox;
+ TCHAR szText[32];
+
+ switch(uMsg) {
+ case WM_INITDIALOG:
+ hTextBox = GetDlgItem(hwndDialog, ID_LINENUMBER);
+ _sntprintf(szText, sizeof(szText) / sizeof(szText[0]), _T("%d"), lParam);
+ SetWindowText(hTextBox, szText);
+ break;
+ case WM_COMMAND:
+ if (HIWORD(wParam) == BN_CLICKED)
+ {
+ if (LOWORD(wParam) == IDOK)
+ {
+ hTextBox = GetDlgItem(hwndDialog, ID_LINENUMBER);
+ GetWindowText(hTextBox, szText, sizeof(szText) / sizeof(szText[0]));
+ EndDialog(hwndDialog, _ttoi(szText));
+ bResult = TRUE;
+ }
+ else if (LOWORD(wParam) == IDCANCEL)
+ {
+ EndDialog(hwndDialog, 0);
+ bResult = TRUE;
+ }
+ }
+ break;
+ }
+
+ return bResult;
+}
+
+VOID DIALOG_GoTo(VOID)
+{
+ INT_PTR nLine;
+ LPTSTR pszText;
+ int nLength, i;
+ DWORD dwStart, dwEnd;
+
+ nLength = GetWindowTextLength(Globals.hEdit);
+ pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(*pszText));
+ if (!pszText)
+ return;
+
+ /* Retrieve current text */
+ GetWindowText(Globals.hEdit, pszText, nLength + 1);
+ SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwStart, (LPARAM) &dwEnd);
+
+ nLine = 1;
+ for (i = 0; pszText[i] && (i < dwStart); i++)
+ {
+ if (pszText[i] == '\n')
+ nLine++;
+ }
+
+ nLine = DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(DIALOG_GOTO),
+ Globals.hMainWnd, DIALOG_GoTo_DialogProc, nLine);
+
+ if (nLine >= 1)
+ {
+ for (i = 0; pszText[i] && (nLine > 1) && (i < nLength - 1); i++)
+ {
+ if (pszText[i] == '\n')
+ nLine--;
+ }
+ SendMessage(Globals.hEdit, EM_SETSEL, i, i);
+ SendMessage(Globals.hEdit, EM_SCROLLCARET, 0, 0);
+ }
+ HeapFree(GetProcessHeap(), 0, pszText);
+}
+
VOID DIALOG_HelpContents(VOID)
{
WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0);
static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
+ switch (msg)
{
case WM_COMMAND:
- switch (wParam)
- {
- case IDOK:
- /* save user input and close dialog */
- GetDlgItemText(hDlg, 0x141, Globals.szHeader, SIZEOF(Globals.szHeader));
- GetDlgItemText(hDlg, 0x143, Globals.szFooter, SIZEOF(Globals.szFooter));
- GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, SIZEOF(Globals.szMarginTop));
- GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, SIZEOF(Globals.szMarginBottom));
- GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, SIZEOF(Globals.szMarginLeft));
- GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, SIZEOF(Globals.szMarginRight));
- EndDialog(hDlg, IDOK);
- return TRUE;
-
- case IDCANCEL:
- /* discard user input and close dialog */
- EndDialog(hDlg, IDCANCEL);
- return TRUE;
-
- case IDHELP:
+ if (HIWORD(wParam) == BN_CLICKED)
{
- /* FIXME: Bring this to work */
- 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 };
- static const WCHAR helpW[] = { 'H','e','l','p',0 };
- MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION);
- return TRUE;
- }
+ switch (LOWORD(wParam))
+ {
+ case IDOK:
+ /* save user input and close dialog */
+ GetDlgItemText(hDlg, 0x141, Globals.szHeader, SIZEOF(Globals.szHeader));
+ GetDlgItemText(hDlg, 0x143, Globals.szFooter, SIZEOF(Globals.szFooter));
+ GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, SIZEOF(Globals.szMarginTop));
+ GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, SIZEOF(Globals.szMarginBottom));
+ GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, SIZEOF(Globals.szMarginLeft));
+ GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, SIZEOF(Globals.szMarginRight));
+ EndDialog(hDlg, IDOK);
+ return TRUE;
+
+ case IDCANCEL:
+ /* discard user input and close dialog */
+ EndDialog(hDlg, IDCANCEL);
+ return TRUE;
+
+ case IDHELP:
+ {
+ /* FIXME: Bring this to work */
+ 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 };
+ static const WCHAR helpW[] = { 'H','e','l','p',0 };
+ MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION);
+ return TRUE;
+ }
- default:
- break;
+ default:
+ break;
+ }
}
- break;
+ break;
case WM_INITDIALOG:
- /* fetch last user input prior to display dialog */
- SetDlgItemText(hDlg, 0x141, Globals.szHeader);
- SetDlgItemText(hDlg, 0x143, Globals.szFooter);
- SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
- SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
- SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
- SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);
- break;
+ /* fetch last user input prior to display dialog */
+ SetDlgItemText(hDlg, 0x141, Globals.szHeader);
+ SetDlgItemText(hDlg, 0x143, Globals.szFooter);
+ SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
+ SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
+ SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
+ SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);
+ break;
}
- return FALSE;
+ return FALSE;
}