ReactOS  0.4.11-dev-946-g431643b
dialog.c File Reference
#include "notepad.h"
#include <assert.h>
#include <commctrl.h>
#include <strsafe.h>
Include dependency graph for dialog.c:

Go to the source code of this file.

Typedefs

typedef HWND(WINAPIFINDPROC) (LPFINDREPLACE lpfr)
 

Functions

LRESULT CALLBACK EDIT_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
static UINT_PTR CALLBACK DIALOG_PAGESETUP_Hook (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
 
VOID ShowLastError (VOID)
 
void UpdateWindowCaption (BOOL clearModifyAlert)
 
int DIALOG_StringMsgBox (HWND hParent, int formatId, LPCTSTR szString, DWORD dwFlags)
 
static void AlertFileNotFound (LPCTSTR szFileName)
 
static int AlertFileNotSaved (LPCTSTR szFileName)
 
static void AlertPrintError (void)
 
BOOL FileExists (LPCTSTR szFilename)
 
BOOL HasFileExtension (LPCTSTR szFilename)
 
int GetSelectionTextLength (HWND hWnd)
 
int GetSelectionText (HWND hWnd, LPTSTR lpString, int nMaxCount)
 
static RECT GetPrintingRect (HDC hdc, RECT margins)
 
static BOOL DoSaveFile (VOID)
 
BOOL DoCloseFile (VOID)
 
VOID DoOpenFile (LPCTSTR szFileName)
 
VOID DIALOG_FileNew (VOID)
 
VOID DIALOG_FileOpen (VOID)
 
BOOL DIALOG_FileSave (VOID)
 
static UINT_PTR CALLBACK DIALOG_FileSaveAs_Hook (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
 
BOOL DIALOG_FileSaveAs (VOID)
 
VOID DIALOG_FilePrint (VOID)
 
VOID DIALOG_FileExit (VOID)
 
VOID DIALOG_EditUndo (VOID)
 
VOID DIALOG_EditCut (VOID)
 
VOID DIALOG_EditCopy (VOID)
 
VOID DIALOG_EditPaste (VOID)
 
VOID DIALOG_EditDelete (VOID)
 
VOID DIALOG_EditSelectAll (VOID)
 
VOID DIALOG_EditTimeDate (VOID)
 
VOID DoCreateStatusBar (VOID)
 
VOID DoCreateEditWindow (VOID)
 
VOID DIALOG_EditWrap (VOID)
 
VOID DIALOG_SelectFont (VOID)
 
static VOID DIALOG_SearchDialog (FINDPROC pfnProc)
 
VOID DIALOG_Search (VOID)
 
VOID DIALOG_SearchNext (VOID)
 
VOID DIALOG_Replace (VOID)
 
static INT_PTR CALLBACK DIALOG_GoTo_DialogProc (HWND hwndDialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
VOID DIALOG_GoTo (VOID)
 
VOID DIALOG_StatusBarUpdateCaretPos (VOID)
 
VOID DIALOG_ViewStatusBar (VOID)
 
VOID DIALOG_HelpContents (VOID)
 
VOID DIALOG_HelpAboutNotepad (VOID)
 
VOID DIALOG_FilePageSetup (void)
 

Variables

static const TCHAR helpfile [] = _T("notepad.hlp")
 
static const TCHAR empty_str [] = _T("")
 
static const TCHAR szDefaultExt [] = _T("txt")
 
static const TCHAR txt_files [] = _T("*.txt")
 

Typedef Documentation

◆ FINDPROC

typedef HWND(WINAPI * FINDPROC) (LPFINDREPLACE lpfr)

Definition at line 1042 of file dialog.c.

Function Documentation

◆ AlertFileNotFound()

static void AlertFileNotFound ( LPCTSTR  szFileName)
static

Definition at line 119 of file dialog.c.

Referenced by DIALOG_FileOpen().

120 {
122 }
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCTSTR szString, DWORD dwFlags)
Definition: dialog.c:98
#define MB_OK
Definition: winuser.h:784
#define STRING_NOTFOUND
Definition: notepad_res.h:86

◆ AlertFileNotSaved()

static int AlertFileNotSaved ( LPCTSTR  szFileName)
static

Definition at line 124 of file dialog.c.

Referenced by DoCloseFile().

125 {
126  TCHAR szUntitled[MAX_STRING_LEN];
127 
128  LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, ARRAY_SIZE(szUntitled));
129 
131  szFileName[0] ? szFileName : szUntitled,
133 }
#define MAX_STRING_LEN
Definition: precomp.h:36
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define STRING_NOTSAVED
Definition: notepad_res.h:84
#define MB_ICONQUESTION
Definition: winuser.h:783
#define MB_YESNOCANCEL
Definition: winuser.h:812
char TCHAR
Definition: xmlstorage.h:189
#define STRING_UNTITLED
Definition: notepad_res.h:78
int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCTSTR szString, DWORD dwFlags)
Definition: dialog.c:98
#define ARRAY_SIZE(a)
Definition: main.h:24
HINSTANCE hInstance
Definition: precomp.h:43
#define LoadString
Definition: winuser.h:5685

◆ AlertPrintError()

static void AlertPrintError ( void  )
static

Definition at line 135 of file dialog.c.

Referenced by DIALOG_FilePrint().

136 {
137  TCHAR szUntitled[MAX_STRING_LEN];
138 
139  LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, ARRAY_SIZE(szUntitled));
140 
142  Globals.szFileName[0] ? Globals.szFileName : szUntitled,
144 }
#define MAX_STRING_LEN
Definition: precomp.h:36
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define STRING_PRINTERROR
Definition: notepad_res.h:100
char TCHAR
Definition: xmlstorage.h:189
#define STRING_UNTITLED
Definition: notepad_res.h:78
int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCTSTR szString, DWORD dwFlags)
Definition: dialog.c:98
#define ARRAY_SIZE(a)
Definition: main.h:24
#define MB_OK
Definition: winuser.h:784
HINSTANCE hInstance
Definition: precomp.h:43
#define LoadString
Definition: winuser.h:5685

◆ DIALOG_EditCopy()

VOID DIALOG_EditCopy ( VOID  )

Definition at line 787 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

788 {
789  SendMessage(Globals.hEdit, WM_COPY, 0, 0);
790 }
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define WM_COPY
Definition: winuser.h:1823
#define SendMessage
Definition: winuser.h:5709

◆ DIALOG_EditCut()

VOID DIALOG_EditCut ( VOID  )

Definition at line 782 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

783 {
784  SendMessage(Globals.hEdit, WM_CUT, 0, 0);
785 }
#define WM_CUT
Definition: winuser.h:1822
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define SendMessage
Definition: winuser.h:5709

◆ DIALOG_EditDelete()

VOID DIALOG_EditDelete ( VOID  )

Definition at line 797 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

798 {
799  SendMessage(Globals.hEdit, WM_CLEAR, 0, 0);
800 }
#define WM_CLEAR
Definition: winuser.h:1825
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define SendMessage
Definition: winuser.h:5709

◆ DIALOG_EditPaste()

VOID DIALOG_EditPaste ( VOID  )

Definition at line 792 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

793 {
794  SendMessage(Globals.hEdit, WM_PASTE, 0, 0);
795 }
#define WM_PASTE
Definition: winuser.h:1824
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define SendMessage
Definition: winuser.h:5709

◆ DIALOG_EditSelectAll()

VOID DIALOG_EditSelectAll ( VOID  )

Definition at line 802 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

803 {
804  SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1);
805 }
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
LONG_PTR LPARAM
Definition: windef.h:208
#define EM_SETSEL
Definition: winuser.h:1979
#define SendMessage
Definition: winuser.h:5709

◆ DIALOG_EditTimeDate()

VOID DIALOG_EditTimeDate ( VOID  )

Definition at line 807 of file dialog.c.

Referenced by DoOpenFile(), and NOTEPAD_MenuCommand().

808 {
809  SYSTEMTIME st;
811  TCHAR szText[MAX_STRING_LEN * 2 + 2];
812 
813  GetLocalTime(&st);
814 
816  _tcscpy(szText, szDate);
817  _tcscat(szText, _T(" "));
819  _tcscat(szText, szDate);
820  SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szText);
821 }
#define TRUE
Definition: types.h:120
#define LOCALE_USER_DEFAULT
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define MAX_STRING_LEN
Definition: precomp.h:36
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
static const WCHAR szText[]
Definition: dialog.c:139
LONG_PTR LPARAM
Definition: windef.h:208
smooth NULL
Definition: ftsmooth.c:416
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:276
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
static const WCHAR szDate[]
Definition: http.c:99
#define GetTimeFormat
Definition: winnls.h:1157
#define GetDateFormat
Definition: winnls.h:1152
#define DATE_LONGDATE
Definition: winnls.h:194
#define SendMessage
Definition: winuser.h:5709
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
#define EM_REPLACESEL
Definition: winuser.h:1967

◆ DIALOG_EditUndo()

VOID DIALOG_EditUndo ( VOID  )

Definition at line 777 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

778 {
779  SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
780 }
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define EM_UNDO
Definition: winuser.h:1982
#define SendMessage
Definition: winuser.h:5709

◆ DIALOG_EditWrap()

VOID DIALOG_EditWrap ( VOID  )

Definition at line 1003 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

1004 {
1005  Globals.bWrapLongLines = !Globals.bWrapLongLines;
1006 
1007  if (Globals.bWrapLongLines)
1008  {
1010  }
1011  else
1012  {
1014  }
1015 
1017 }
#define MF_DISABLED
Definition: winuser.h:130
#define MF_BYCOMMAND
Definition: winuser.h:202
#define CMD_GOTO
Definition: notepad_res.h:55
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
VOID DoCreateEditWindow(VOID)
Definition: dialog.c:901
#define MF_ENABLED
Definition: winuser.h:128
#define MF_GRAYED
Definition: winuser.h:129

◆ DIALOG_FileExit()

VOID DIALOG_FileExit ( VOID  )

Definition at line 772 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

773 {
775 }
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define PostMessage
Definition: winuser.h:5698
r l[0]
Definition: byte_order.h:167
#define WM_CLOSE
Definition: winuser.h:1603

◆ DIALOG_FileNew()

VOID DIALOG_FileNew ( VOID  )

Definition at line 398 of file dialog.c.

Referenced by _tWinMain(), and NOTEPAD_MenuCommand().

399 {
400  /* Close any files and prompt to save changes */
401  if (DoCloseFile()) {
403  SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
404  SetFocus(Globals.hEdit);
406  }
407 }
static const TCHAR empty_str[]
Definition: dialog.c:32
HWND WINAPI SetFocus(_In_opt_ HWND)
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
BOOL DoCloseFile(VOID)
Definition: dialog.c:313
#define EM_EMPTYUNDOBUFFER
Definition: winuser.h:1946
#define SetWindowText
Definition: winuser.h:5723
VOID NOTEPAD_EnableSearchMenu()
Definition: main.c:32
#define SendMessage
Definition: winuser.h:5709

◆ DIALOG_FileOpen()

VOID DIALOG_FileOpen ( VOID  )

Definition at line 409 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

410 {
411  OPENFILENAME openfilename;
413 
414  ZeroMemory(&openfilename, sizeof(openfilename));
415 
416  if (Globals.szFileName[0] == 0)
417  _tcscpy(szPath, txt_files);
418  else
419  _tcscpy(szPath, Globals.szFileName);
420 
421  openfilename.lStructSize = sizeof(openfilename);
422  openfilename.hwndOwner = Globals.hMainWnd;
423  openfilename.hInstance = Globals.hInstance;
424  openfilename.lpstrFilter = Globals.szFilter;
425  openfilename.lpstrFile = szPath;
426  openfilename.nMaxFile = ARRAY_SIZE(szPath);
428  openfilename.lpstrDefExt = szDefaultExt;
429 
430  if (GetOpenFileName(&openfilename)) {
431  if (FileExists(openfilename.lpstrFile))
432  DoOpenFile(openfilename.lpstrFile);
433  else
434  AlertFileNotFound(openfilename.lpstrFile);
435  }
436 }
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
VOID DoOpenFile(LPCTSTR szFileName)
Definition: dialog.c:345
HWND hwndOwner
Definition: commdlg.h:330
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define ZeroMemory
Definition: winbase.h:1635
LPCSTR lpstrDefExt
Definition: commdlg.h:345
static void AlertFileNotFound(LPCTSTR szFileName)
Definition: dialog.c:119
#define GetOpenFileName
Definition: commdlg.h:665
DWORD nMaxFile
Definition: commdlg.h:337
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
BOOL FileExists(LPCTSTR szFilename)
Definition: dialog.c:151
HINSTANCE hInstance
Definition: commdlg.h:331
static const TCHAR szDefaultExt[]
Definition: dialog.c:33
#define OFN_PATHMUSTEXIST
Definition: commdlg.h:117
char TCHAR
Definition: xmlstorage.h:189
#define MAX_PATH
Definition: compat.h:26
DWORD lStructSize
Definition: commdlg.h:329
static const TCHAR txt_files[]
Definition: dialog.c:34
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
LPSTR lpstrFile
Definition: commdlg.h:336
LPCWSTR szPath
Definition: env.c:35
#define ARRAY_SIZE(a)
Definition: main.h:24
LPCSTR lpstrFilter
Definition: commdlg.h:332
HINSTANCE hInstance
Definition: precomp.h:43
DWORD Flags
Definition: commdlg.h:342

◆ DIALOG_FilePageSetup()

VOID DIALOG_FilePageSetup ( void  )

Definition at line 1209 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

1210 {
1212 
1213  ZeroMemory(&page, sizeof(page));
1214  page.lStructSize = sizeof(page);
1215  page.hwndOwner = Globals.hMainWnd;
1217  page.hInstance = Globals.hInstance;
1218  page.rtMargin = Globals.lMargins;
1219  page.hDevMode = Globals.hDevMode;
1220  page.hDevNames = Globals.hDevNames;
1223 
1224  PageSetupDlg(&page);
1225 
1226  Globals.hDevMode = page.hDevMode;
1227  Globals.hDevNames = page.hDevNames;
1228  Globals.lMargins = page.rtMargin;
1229 }
static UINT_PTR CALLBACK DIALOG_PAGESETUP_Hook(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:1236
HGLOBAL hDevMode
Definition: commdlg.h:435
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define PSD_ENABLEPAGESETUPTEMPLATE
Definition: commdlg.h:184
#define PageSetupDlg
Definition: commdlg.h:667
#define PSD_MARGINS
Definition: commdlg.h:173
HWND hwndOwner
Definition: commdlg.h:434
#define ZeroMemory
Definition: winbase.h:1635
LPCSTR lpPageSetupTemplateName
Definition: commdlg.h:445
RECT rtMargin
Definition: commdlg.h:440
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define DIALOG_PAGESETUP
Definition: notepad_res.h:25
Definition: module.h:566
DWORD lStructSize
Definition: commdlg.h:433
DWORD Flags
Definition: commdlg.h:437
HINSTANCE hInstance
Definition: commdlg.h:441
LPPAGESETUPHOOK lpfnPageSetupHook
Definition: commdlg.h:443
HGLOBAL hDevNames
Definition: commdlg.h:436
#define PSD_ENABLEPAGESETUPHOOK
Definition: commdlg.h:183
HINSTANCE hInstance
Definition: precomp.h:43

◆ DIALOG_FilePrint()

VOID DIALOG_FilePrint ( VOID  )

Definition at line 557 of file dialog.c.

Referenced by HandleCommandLine(), and NOTEPAD_MenuCommand().

558 {
559  DOCINFO di;
560  TEXTMETRIC tm;
561  PRINTDLG printer;
562  SIZE szMetric;
563  int border;
564  int xLeft, yTop, pagecount, dopage, copycount;
565  unsigned int i;
566  LOGFONT hdrFont;
567  HFONT font, old_font=0;
568  DWORD size;
569  LPTSTR pTemp;
570  static const TCHAR times_new_roman[] = _T("Times New Roman");
571  RECT rcPrintRect;
572 
573  /* Get a small font and print some header info on each page */
574  ZeroMemory(&hdrFont, sizeof(hdrFont));
575  hdrFont.lfHeight = 100;
576  hdrFont.lfWeight = FW_BOLD;
577  hdrFont.lfCharSet = ANSI_CHARSET;
580  hdrFont.lfQuality = PROOF_QUALITY;
582  _tcscpy(hdrFont.lfFaceName, times_new_roman);
583 
584  font = CreateFontIndirect(&hdrFont);
585 
586  /* Get Current Settings */
587  ZeroMemory(&printer, sizeof(printer));
588  printer.lStructSize = sizeof(printer);
589  printer.hwndOwner = Globals.hMainWnd;
590  printer.hInstance = Globals.hInstance;
591 
592  /* Set some default flags */
593  printer.Flags = PD_RETURNDC | PD_SELECTION;
594 
595  /* Disable the selection radio button if there is no text selected */
596  if (!GetSelectionTextLength(Globals.hEdit))
597  {
598  printer.Flags = printer.Flags | PD_NOSELECTION;
599  }
600 
601  printer.nFromPage = 0;
602  printer.nMinPage = 1;
603  /* we really need to calculate number of pages to set nMaxPage and nToPage */
604  printer.nToPage = (WORD)-1;
605  printer.nMaxPage = (WORD)-1;
606 
607  /* Let commdlg manage copy settings */
608  printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
609 
610  printer.hDevMode = Globals.hDevMode;
611  printer.hDevNames = Globals.hDevNames;
612 
613  if (!PrintDlg(&printer))
614  {
615  DeleteObject(font);
616  return;
617  }
618 
619  Globals.hDevMode = printer.hDevMode;
620  Globals.hDevNames = printer.hDevNames;
621 
622  assert(printer.hDC != 0);
623 
624  /* initialize DOCINFO */
625  di.cbSize = sizeof(DOCINFO);
626  di.lpszDocName = Globals.szFileTitle;
627  di.lpszOutput = NULL;
628  di.lpszDatatype = NULL;
629  di.fwType = 0;
630 
631  if (StartDoc(printer.hDC, &di) <= 0)
632  {
633  DeleteObject(font);
634  return;
635  }
636 
637 
638  /* Get the file text */
639  if (printer.Flags & PD_SELECTION)
640  {
641  size = GetSelectionTextLength(Globals.hEdit) + 1;
642  }
643  else
644  {
645  size = GetWindowTextLength(Globals.hEdit) + 1;
646  }
647 
648  pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(TCHAR));
649  if (!pTemp)
650  {
651  EndDoc(printer.hDC);
652  DeleteObject(font);
653  ShowLastError();
654  return;
655  }
656 
657  if (printer.Flags & PD_SELECTION)
658  {
659  size = GetSelectionText(Globals.hEdit, pTemp, size);
660  }
661  else
662  {
663  size = GetWindowText(Globals.hEdit, pTemp, size);
664  }
665 
666  /* Get the current printing area */
667  rcPrintRect = GetPrintingRect(printer.hDC, Globals.lMargins);
668 
669  /* Ensure that each logical unit maps to one pixel */
670  SetMapMode(printer.hDC, MM_TEXT);
671 
672  /* Needed to get the correct height of a text line */
673  GetTextMetrics(printer.hDC, &tm);
674 
675  border = 15;
676  for (copycount=1; copycount <= printer.nCopies; copycount++) {
677  i = 0;
678  pagecount = 1;
679  do {
680  /* Don't start a page if none of the conditions below are true */
681  dopage = 0;
682 
683  /* The user wants to print the current selection */
684  if (printer.Flags & PD_SELECTION)
685  {
686  dopage = 1;
687  }
688 
689  /* The user wants to print the entire document */
690  if (!(printer.Flags & PD_PAGENUMS) && !(printer.Flags & PD_SELECTION))
691  {
692  dopage = 1;
693  }
694 
695  /* The user wants to print a specified range of pages */
696  if ((pagecount >= printer.nFromPage && pagecount <= printer.nToPage))
697  {
698  dopage = 1;
699  }
700 
701  old_font = SelectObject(printer.hDC, font);
702 
703  if (dopage) {
704  if (StartPage(printer.hDC) <= 0) {
705  SelectObject(printer.hDC, old_font);
706  EndDoc(printer.hDC);
707  DeleteDC(printer.hDC);
708  HeapFree(GetProcessHeap(), 0, pTemp);
709  DeleteObject(font);
710  AlertPrintError();
711  return;
712  }
713 
714  SetViewportOrgEx(printer.hDC, rcPrintRect.left, rcPrintRect.top, NULL);
715 
716  /* Write a rectangle and header at the top of each page */
717  Rectangle(printer.hDC, border, border, rcPrintRect.right - border, border + tm.tmHeight * 2);
718  /* I don't know what's up with this TextOut command. This comes out
719  kind of mangled.
720  */
721  TextOut(printer.hDC,
722  border * 2,
723  border + tm.tmHeight / 2,
724  Globals.szFileTitle,
725  lstrlen(Globals.szFileTitle));
726  }
727 
728  /* The starting point for the main text */
729  xLeft = 0;
730  yTop = border + tm.tmHeight * 4;
731 
732  SelectObject(printer.hDC, old_font);
733 
734  /* Since outputting strings is giving me problems, output the main
735  * text one character at a time. */
736  do {
737  if (pTemp[i] == '\n') {
738  xLeft = 0;
739  yTop += tm.tmHeight;
740  }
741  else if (pTemp[i] != '\r') {
742  if (dopage)
743  TextOut(printer.hDC, xLeft, yTop, &pTemp[i], 1);
744 
745  /* We need to get the width for each individual char, since a proportional font may be used */
746  GetTextExtentPoint32(printer.hDC, &pTemp[i], 1, &szMetric);
747  xLeft += szMetric.cx;
748 
749  /* Insert a line break if the current line does not fit into the printing area */
750  if (xLeft > rcPrintRect.right)
751  {
752  xLeft = 0;
753  yTop = yTop + tm.tmHeight;
754  }
755  }
756  } while (i++ < size && yTop < rcPrintRect.bottom);
757 
758  if (dopage)
759  EndPage(printer.hDC);
760  pagecount++;
761  } while (i < size);
762  }
763 
764  if (old_font != 0)
765  SelectObject(printer.hDC, old_font);
766  EndDoc(printer.hDC);
767  DeleteDC(printer.hDC);
768  HeapFree(GetProcessHeap(), 0, pTemp);
769  DeleteObject(font);
770 }
BOOL WINAPI SetViewportOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
Definition: coord.c:648
#define PD_NOSELECTION
Definition: commdlg.h:149
WORD nMaxPage
Definition: commdlg.h:474
#define VARIABLE_PITCH
Definition: wingdi.h:443
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
Definition: mk_font.cpp:20
LONG top
Definition: windef.h:297
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define assert(x)
Definition: debug.h:53
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
BYTE lfCharSet
Definition: dimm.idl:50
WORD nCopies
Definition: commdlg.h:475
LONG left
Definition: windef.h:296
#define GetTextMetrics
Definition: wingdi.h:4451
LONG right
Definition: windef.h:298
#define PROOF_QUALITY
Definition: wingdi.h:436
CHAR * LPTSTR
Definition: xmlstorage.h:192
int WINAPI EndPage(_In_ HDC)
static RECT GetPrintingRect(HDC hdc, RECT margins)
Definition: dialog.c:240
BYTE lfOutPrecision
Definition: dimm.idl:51
WORD nMinPage
Definition: commdlg.h:473
#define GetWindowText
Definition: winuser.h:5664
int WINAPI StartPage(_In_ HDC)
HANDLE hDevNames
Definition: commdlg.h:468
#define PrintDlg
Definition: commdlg.h:668
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
GLenum GLclampf GLint i
Definition: glfuncs.h:14
int WINAPI SetMapMode(_In_ HDC, _In_ int)
LONG lfHeight
Definition: dimm.idl:42
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:424
LONG lfWeight
Definition: dimm.idl:46
WORD nFromPage
Definition: commdlg.h:471
smooth NULL
Definition: ftsmooth.c:416
int GetSelectionText(HWND hWnd, LPTSTR lpString, int nMaxCount)
Definition: dialog.c:182
LONG cx
Definition: windef.h:324
#define PD_SELECTION
Definition: commdlg.h:147
#define PD_RETURNDC
Definition: commdlg.h:155
BYTE lfPitchAndFamily
Definition: dimm.idl:54
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
DWORD fwType
Definition: wingdi.h:1657
VOID ShowLastError(VOID)
Definition: dialog.c:38
GLsizeiptr size
Definition: glext.h:5919
LPCSTR lpszOutput
Definition: wingdi.h:1655
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG tmHeight
Definition: wingdi.h:2338
GLint GLint GLsizei GLsizei GLsizei GLint border
Definition: gl.h:1546
unsigned short WORD
Definition: ntddk_ex.h:93
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:413
unsigned long DWORD
Definition: ntddk_ex.h:95
#define PD_PAGENUMS
Definition: commdlg.h:148
LPCSTR lpszDatatype
Definition: wingdi.h:1656
#define PD_USEDEVMODECOPIES
Definition: commdlg.h:165
Definition: time.h:76
#define FF_ROMAN
Definition: wingdi.h:448
int cbSize
Definition: wingdi.h:1653
BYTE lfQuality
Definition: dimm.idl:53
HWND hwndOwner
Definition: commdlg.h:466
#define lstrlen
Definition: winbase.h:3690
#define FW_BOLD
Definition: wingdi.h:376
HINSTANCE hInstance
Definition: commdlg.h:476
BOOL WINAPI DeleteDC(_In_ HDC)
LPCSTR lpszDocName
Definition: wingdi.h:1654
BYTE lfClipPrecision
Definition: dimm.idl:52
#define CreateFontIndirect
Definition: wingdi.h:4421
DWORD lStructSize
Definition: commdlg.h:465
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
WORD nToPage
Definition: commdlg.h:472
#define MM_TEXT
Definition: wingdi.h:871
#define GetTextExtentPoint32
Definition: wingdi.h:4449
#define TextOut
Definition: wingdi.h:4460
#define GetWindowTextLength
Definition: winuser.h:5665
CHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:55
LONG bottom
Definition: windef.h:299
DWORD Flags
Definition: commdlg.h:470
#define StartDoc
Definition: wingdi.h:4459
static void AlertPrintError(void)
Definition: dialog.c:135
int GetSelectionTextLength(HWND hWnd)
Definition: dialog.c:172
#define ANSI_CHARSET
Definition: wingdi.h:381
HINSTANCE hInstance
Definition: precomp.h:43
HDC hDC
Definition: commdlg.h:469
HANDLE hDevMode
Definition: commdlg.h:467
#define HeapFree(x, y, z)
Definition: compat.h:394
DOCINFOA DOCINFO
Definition: wingdi.h:4391
int WINAPI EndDoc(_In_ HDC)

◆ DIALOG_FileSave()

BOOL DIALOG_FileSave ( VOID  )

Definition at line 438 of file dialog.c.

Referenced by DoCloseFile(), and NOTEPAD_MenuCommand().

439 {
440  if (Globals.szFileName[0] == 0)
441  {
442  return DIALOG_FileSaveAs();
443  }
444  else if (DoSaveFile())
445  {
447  return TRUE;
448  }
449  return FALSE;
450 }
void UpdateWindowCaption(BOOL clearModifyAlert)
Definition: dialog.c:66
#define TRUE
Definition: types.h:120
static BOOL DoSaveFile(VOID)
Definition: dialog.c:264
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
BOOL DIALOG_FileSaveAs(VOID)
Definition: dialog.c:510

◆ DIALOG_FileSaveAs()

BOOL DIALOG_FileSaveAs ( VOID  )

Definition at line 510 of file dialog.c.

Referenced by DIALOG_FileSave(), and NOTEPAD_MenuCommand().

511 {
512  OPENFILENAME saveas;
514 
515  ZeroMemory(&saveas, sizeof(saveas));
516 
517  if (Globals.szFileName[0] == 0)
518  _tcscpy(szPath, txt_files);
519  else
520  _tcscpy(szPath, Globals.szFileName);
521 
522  saveas.lStructSize = sizeof(OPENFILENAME);
523  saveas.hwndOwner = Globals.hMainWnd;
524  saveas.hInstance = Globals.hInstance;
525  saveas.lpstrFilter = Globals.szFilter;
526  saveas.lpstrFile = szPath;
527  saveas.nMaxFile = ARRAY_SIZE(szPath);
530  saveas.lpstrDefExt = szDefaultExt;
533 
534  if (GetSaveFileName(&saveas))
535  {
536  /* HACK: Because in ROS, Save-As boxes don't check the validity
537  * of file names and thus, here, szPath can be invalid !! We only
538  * see its validity when we call DoSaveFile()... */
539  SetFileName(szPath);
540  if (DoSaveFile())
541  {
543  return TRUE;
544  }
545  else
546  {
547  SetFileName(_T(""));
548  return FALSE;
549  }
550  }
551  else
552  {
553  return FALSE;
554  }
555 }
void UpdateWindowCaption(BOOL clearModifyAlert)
Definition: dialog.c:66
#define OFN_EXPLORER
Definition: commdlg.h:104
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define TRUE
Definition: types.h:120
static UINT_PTR CALLBACK DIALOG_FileSaveAs_Hook(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:454
HWND hwndOwner
Definition: commdlg.h:330
static BOOL DoSaveFile(VOID)
Definition: dialog.c:264
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define ZeroMemory
Definition: winbase.h:1635
LPCSTR lpstrDefExt
Definition: commdlg.h:345
LPCSTR lpTemplateName
Definition: commdlg.h:348
DWORD nMaxFile
Definition: commdlg.h:337
#define GetSaveFileName
Definition: commdlg.h:666
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
LPOFNHOOKPROC lpfnHook
Definition: commdlg.h:347
#define OFN_ENABLEHOOK
Definition: commdlg.h:99
#define OFN_ENABLETEMPLATE
Definition: commdlg.h:102
HINSTANCE hInstance
Definition: commdlg.h:331
static const TCHAR szDefaultExt[]
Definition: dialog.c:33
OPENFILENAMEA OPENFILENAME
Definition: commdlg.h:657
#define OFN_PATHMUSTEXIST
Definition: commdlg.h:117
static VOID SetFileName(PCONSOLE_CHILDFRM_WND Info, PWSTR pFileName)
Definition: console.c:177
#define DIALOG_ENCODING
Definition: notepad_res.h:27
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define MAX_PATH
Definition: compat.h:26
DWORD lStructSize
Definition: commdlg.h:329
static const TCHAR txt_files[]
Definition: dialog.c:34
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
LPSTR lpstrFile
Definition: commdlg.h:336
LPCWSTR szPath
Definition: env.c:35
#define ARRAY_SIZE(a)
Definition: main.h:24
#define OFN_OVERWRITEPROMPT
Definition: commdlg.h:116
LPCSTR lpstrFilter
Definition: commdlg.h:332
HINSTANCE hInstance
Definition: precomp.h:43
DWORD Flags
Definition: commdlg.h:342

◆ DIALOG_FileSaveAs_Hook()

static UINT_PTR CALLBACK DIALOG_FileSaveAs_Hook ( HWND  hDlg,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 454 of file dialog.c.

Referenced by DIALOG_FileSaveAs().

455 {
456  TCHAR szText[128];
457  HWND hCombo;
458 
460 
461  switch(msg)
462  {
463  case WM_INITDIALOG:
464  hCombo = GetDlgItem(hDlg, ID_ENCODING);
465 
467  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
468 
470  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
471 
473  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
474 
476  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
477 
478  SendMessage(hCombo, CB_SETCURSEL, Globals.encFile, 0);
479 
480  hCombo = GetDlgItem(hDlg, ID_EOLN);
481 
483  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
484 
485  LoadString(Globals.hInstance, STRING_LF, szText, ARRAY_SIZE(szText));
486  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
487 
488  LoadString(Globals.hInstance, STRING_CR, szText, ARRAY_SIZE(szText));
489  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
490 
491  SendMessage(hCombo, CB_SETCURSEL, Globals.iEoln, 0);
492  break;
493 
494  case WM_NOTIFY:
495  if (((NMHDR *) lParam)->code == CDN_FILEOK)
496  {
497  hCombo = GetDlgItem(hDlg, ID_ENCODING);
498  if (hCombo)
499  Globals.encFile = (ENCODING) SendMessage(hCombo, CB_GETCURSEL, 0, 0);
500 
501  hCombo = GetDlgItem(hDlg, ID_EOLN);
502  if (hCombo)
503  Globals.iEoln = (int) SendMessage(hCombo, CB_GETCURSEL, 0, 0);
504  }
505  break;
506  }
507  return 0;
508 }
#define STRING_LF
Definition: notepad_res.h:96
#define STRING_ANSI
Definition: notepad_res.h:90
#define STRING_UTF8
Definition: notepad_res.h:93
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define CB_GETCURSEL
Definition: winuser.h:1904
WPARAM wParam
Definition: combotst.c:138
#define ID_ENCODING
Definition: notepad_res.h:28
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
static const WCHAR szText[]
Definition: dialog.c:139
LONG_PTR LPARAM
Definition: windef.h:208
#define CB_ADDSTRING
Definition: winuser.h:1897
UINT msg
Definition: msvc.h:92
#define STRING_UNICODE_BE
Definition: notepad_res.h:92
#define STRING_CRLF
Definition: notepad_res.h:95
char TCHAR
Definition: xmlstorage.h:189
#define CDN_FILEOK
Definition: commdlg.h:38
#define ID_EOLN
Definition: notepad_res.h:29
#define CB_SETCURSEL
Definition: winuser.h:1922
ENCODING
Definition: more.c:155
#define ARRAY_SIZE(a)
Definition: main.h:24
#define STRING_UNICODE
Definition: notepad_res.h:91
#define SendMessage
Definition: winuser.h:5709
HWND WINAPI GetDlgItem(HWND hDlg, int nIDDlgItem)
Definition: dialog.c:2113
HINSTANCE hInstance
Definition: precomp.h:43
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define STRING_CR
Definition: notepad_res.h:97
#define LoadString
Definition: winuser.h:5685
#define WM_NOTIFY
Definition: richedit.h:61
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:29

◆ DIALOG_GoTo()

VOID DIALOG_GoTo ( VOID  )

Definition at line 1123 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

1124 {
1125  INT_PTR nLine;
1126  LPTSTR pszText;
1127  int nLength, i;
1128  DWORD dwStart, dwEnd;
1129 
1130  nLength = GetWindowTextLength(Globals.hEdit);
1131  pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(*pszText));
1132  if (!pszText)
1133  return;
1134 
1135  /* Retrieve current text */
1136  GetWindowText(Globals.hEdit, pszText, nLength + 1);
1137  SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwStart, (LPARAM) &dwEnd);
1138 
1139  nLine = 1;
1140  for (i = 0; (i < (int) dwStart) && pszText[i]; i++)
1141  {
1142  if (pszText[i] == '\n')
1143  nLine++;
1144  }
1145 
1148  Globals.hMainWnd,
1150  nLine);
1151 
1152  if (nLine >= 1)
1153  {
1154  for (i = 0; pszText[i] && (nLine > 1) && (i < nLength - 1); i++)
1155  {
1156  if (pszText[i] == '\n')
1157  nLine--;
1158  }
1159  SendMessage(Globals.hEdit, EM_SETSEL, i, i);
1160  SendMessage(Globals.hEdit, EM_SCROLLCARET, 0, 0);
1161  }
1162  HeapFree(GetProcessHeap(), 0, pszText);
1163 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
LPCWSTR pszText
Definition: msvc.h:103
_In_ DWORD nLength
Definition: wincon.h:461
int32_t INT_PTR
Definition: typedefs.h:62
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5664
UINT_PTR WPARAM
Definition: windef.h:207
#define EM_GETSEL
Definition: winuser.h:1958
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
GLenum GLclampf GLint i
Definition: glfuncs.h:14
LONG_PTR LPARAM
Definition: windef.h:208
#define DIALOG_GOTO
Definition: notepad_res.h:30
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define EM_SETSEL
Definition: winuser.h:1979
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DialogBoxParam
Definition: winuser.h:5630
#define SendMessage
Definition: winuser.h:5709
#define GetWindowTextLength
Definition: winuser.h:5665
HINSTANCE hInstance
Definition: precomp.h:43
#define HeapFree(x, y, z)
Definition: compat.h:394
#define EM_SCROLLCARET
Definition: richedit.h:81
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:29
static INT_PTR CALLBACK DIALOG_GoTo_DialogProc(HWND hwndDialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:1089

◆ DIALOG_GoTo_DialogProc()

static INT_PTR CALLBACK DIALOG_GoTo_DialogProc ( HWND  hwndDialog,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 1089 of file dialog.c.

Referenced by DIALOG_GoTo().

1090 {
1091  BOOL bResult = FALSE;
1092  HWND hTextBox;
1093  TCHAR szText[32];
1094 
1095  switch(uMsg) {
1096  case WM_INITDIALOG:
1097  hTextBox = GetDlgItem(hwndDialog, ID_LINENUMBER);
1098  _sntprintf(szText, ARRAY_SIZE(szText), _T("%ld"), lParam);
1099  SetWindowText(hTextBox, szText);
1100  break;
1101  case WM_COMMAND:
1102  if (HIWORD(wParam) == BN_CLICKED)
1103  {
1104  if (LOWORD(wParam) == IDOK)
1105  {
1106  hTextBox = GetDlgItem(hwndDialog, ID_LINENUMBER);
1107  GetWindowText(hTextBox, szText, ARRAY_SIZE(szText));
1108  EndDialog(hwndDialog, _ttoi(szText));
1109  bResult = TRUE;
1110  }
1111  else if (LOWORD(wParam) == IDCANCEL)
1112  {
1113  EndDialog(hwndDialog, 0);
1114  bResult = TRUE;
1115  }
1116  }
1117  break;
1118  }
1119 
1120  return bResult;
1121 }
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
WPARAM wParam
Definition: combotst.c:138
#define GetWindowText
Definition: winuser.h:5664
static const WCHAR szText[]
Definition: dialog.c:139
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
#define BN_CLICKED
Definition: winuser.h:1886
#define _sntprintf
Definition: xmlstorage.h:201
#define WM_COMMAND
Definition: winuser.h:1716
BOOL WINAPI EndDialog(HWND hwnd, INT_PTR retval)
Definition: dialog.c:2015
#define ARRAY_SIZE(a)
Definition: main.h:24
int CDECL _ttoi(const _TCHAR *str)
Definition: atoi.c:10
#define SetWindowText
Definition: winuser.h:5723
#define ID_LINENUMBER
Definition: notepad_res.h:31
HWND WINAPI GetDlgItem(HWND hDlg, int nIDDlgItem)
Definition: dialog.c:2113
#define HIWORD(l)
Definition: typedefs.h:246
#define IDCANCEL
Definition: winuser.h:825
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82

◆ DIALOG_HelpAboutNotepad()

VOID DIALOG_HelpAboutNotepad ( VOID  )

Definition at line 1191 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

1192 {
1193  TCHAR szNotepad[MAX_STRING_LEN];
1194  TCHAR szNotepadAuthors[MAX_STRING_LEN];
1195 
1197 
1198  LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, ARRAY_SIZE(szNotepad));
1199  LoadString(Globals.hInstance, STRING_NOTEPAD_AUTHORS, szNotepadAuthors, ARRAY_SIZE(szNotepadAuthors));
1200 
1201  ShellAbout(Globals.hMainWnd, szNotepad, szNotepadAuthors, notepadIcon);
1202  DeleteObject(notepadIcon);
1203 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
static HICON
Definition: imagelist.c:84
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define MAX_STRING_LEN
Definition: precomp.h:36
#define STRING_NOTEPAD_AUTHORS
Definition: notepad_res.h:104
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define STRING_NOTEPAD
Definition: notepad_res.h:74
char TCHAR
Definition: xmlstorage.h:189
#define ShellAbout
Definition: shellapi.h:678
#define ARRAY_SIZE(a)
Definition: main.h:24
#define IDI_NPICON
Definition: notepad_res.h:32
#define LoadIcon
Definition: winuser.h:5679
HINSTANCE hInstance
Definition: precomp.h:43
#define LoadString
Definition: winuser.h:5685

◆ DIALOG_HelpContents()

VOID DIALOG_HelpContents ( VOID  )

Definition at line 1186 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

1187 {
1189 }
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define HELP_INDEX
Definition: winuser.h:2364
static const TCHAR helpfile[]
Definition: dialog.c:31
#define WinHelp
Definition: winuser.h:5730

◆ DIALOG_PAGESETUP_Hook()

static UINT_PTR CALLBACK DIALOG_PAGESETUP_Hook ( HWND  hDlg,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 1236 of file dialog.c.

Referenced by DIALOG_FilePageSetup().

1237 {
1238  switch (msg)
1239  {
1240  case WM_COMMAND:
1241  if (HIWORD(wParam) == BN_CLICKED)
1242  {
1243  switch (LOWORD(wParam))
1244  {
1245  case IDOK:
1246  /* save user input and close dialog */
1247  GetDlgItemText(hDlg, 0x141, Globals.szHeader, ARRAY_SIZE(Globals.szHeader));
1248  GetDlgItemText(hDlg, 0x143, Globals.szFooter, ARRAY_SIZE(Globals.szFooter));
1249  return FALSE;
1250 
1251  case IDCANCEL:
1252  /* discard user input and close dialog */
1253  return FALSE;
1254 
1255  case IDHELP:
1256  {
1257  /* FIXME: Bring this to work */
1258  static const TCHAR sorry[] = _T("Sorry, no help available");
1259  static const TCHAR help[] = _T("Help");
1261  return TRUE;
1262  }
1263 
1264  default:
1265  break;
1266  }
1267  }
1268  break;
1269 
1270  case WM_INITDIALOG:
1271  /* fetch last user input prior to display dialog */
1272  SetDlgItemText(hDlg, 0x141, Globals.szHeader);
1273  SetDlgItemText(hDlg, 0x143, Globals.szFooter);
1274  break;
1275  }
1276 
1277  return FALSE;
1278 }
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
WPARAM wParam
Definition: combotst.c:138
#define IDHELP
Definition: resource_2.h:8
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
UINT msg
Definition: msvc.h:92
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define GetDlgItemText
Definition: winuser.h:5651
#define BN_CLICKED
Definition: winuser.h:1886
#define SetDlgItemText
Definition: winuser.h:5715
#define MessageBox
Definition: winuser.h:5688
#define WM_COMMAND
Definition: winuser.h:1716
#define ARRAY_SIZE(a)
Definition: main.h:24
#define HIWORD(l)
Definition: typedefs.h:246
#define IDCANCEL
Definition: winuser.h:825
int help
Definition: sort.c:20
#define WM_INITDIALOG
Definition: winuser.h:1715
#define LOWORD(l)
Definition: pedump.c:82

◆ DIALOG_Replace()

VOID DIALOG_Replace ( VOID  )

Definition at line 1082 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

1083 {
1085 }
#define ReplaceText
Definition: commdlg.h:669
static VOID DIALOG_SearchDialog(FINDPROC pfnProc)
Definition: dialog.c:1044

◆ DIALOG_Search()

VOID DIALOG_Search ( VOID  )

Definition at line 1069 of file dialog.c.

Referenced by DIALOG_SearchNext(), and NOTEPAD_MenuCommand().

1070 {
1072 }
static VOID DIALOG_SearchDialog(FINDPROC pfnProc)
Definition: dialog.c:1044
#define FindText
Definition: commdlg.h:663

◆ DIALOG_SearchDialog()

static VOID DIALOG_SearchDialog ( FINDPROC  pfnProc)
static

Definition at line 1044 of file dialog.c.

Referenced by DIALOG_Replace(), and DIALOG_Search().

1045 {
1046  if (Globals.hFindReplaceDlg != NULL)
1047  {
1048  SetFocus(Globals.hFindReplaceDlg);
1049  return;
1050  }
1051 
1052  ZeroMemory(&Globals.find, sizeof(Globals.find));
1053  Globals.find.lStructSize = sizeof(Globals.find);
1054  Globals.find.hwndOwner = Globals.hMainWnd;
1056  Globals.find.lpstrFindWhat = Globals.szFindText;
1057  Globals.find.wFindWhatLen = ARRAY_SIZE(Globals.szFindText);
1058  Globals.find.lpstrReplaceWith = Globals.szReplaceText;
1059  Globals.find.wReplaceWithLen = ARRAY_SIZE(Globals.szReplaceText);
1060  Globals.find.Flags = FR_DOWN;
1061 
1062  /* We only need to create the modal FindReplace dialog which will */
1063  /* notify us of incoming events using hMainWnd Window Messages */
1064 
1065  Globals.hFindReplaceDlg = pfnProc(&Globals.find);
1066  assert(Globals.hFindReplaceDlg != NULL);
1067 }
#define assert(x)
Definition: debug.h:53
#define ZeroMemory
Definition: winbase.h:1635
HWND WINAPI SetFocus(_In_opt_ HWND)
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
smooth NULL
Definition: ftsmooth.c:416
#define ARRAY_SIZE(a)
Definition: main.h:24
#define FR_DOWN
Definition: commdlg.h:127
HINSTANCE hInstance
Definition: precomp.h:43

◆ DIALOG_SearchNext()

VOID DIALOG_SearchNext ( VOID  )

Definition at line 1074 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

1075 {
1076  if (Globals.find.lpstrFindWhat != NULL)
1078  else
1079  DIALOG_Search();
1080 }
VOID DIALOG_Search(VOID)
Definition: dialog.c:1069
#define TRUE
Definition: types.h:120
BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert)
Definition: main.c:138
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
smooth NULL
Definition: ftsmooth.c:416

◆ DIALOG_SelectFont()

VOID DIALOG_SelectFont ( VOID  )

Definition at line 1019 of file dialog.c.

Referenced by NOTEPAD_MenuCommand().

1020 {
1021  CHOOSEFONT cf;
1022  LOGFONT lf = Globals.lfFont;
1023 
1024  ZeroMemory( &cf, sizeof(cf) );
1025  cf.lStructSize = sizeof(cf);
1026  cf.hwndOwner = Globals.hMainWnd;
1027  cf.lpLogFont = &lf;
1029 
1030  if (ChooseFont(&cf))
1031  {
1032  HFONT currfont = Globals.hFont;
1033 
1034  Globals.hFont = CreateFontIndirect(&lf);
1035  Globals.lfFont = lf;
1037  if (currfont != NULL)
1038  DeleteObject(currfont);
1039  }
1040 }
static IClassFactory * cf
LPLOGFONTA lpLogFont
Definition: commdlg.h:264
#define TRUE
Definition: types.h:120
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
DWORD lStructSize
Definition: commdlg.h:261
UINT_PTR WPARAM
Definition: windef.h:207
#define ChooseFont
Definition: commdlg.h:662
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
LONG_PTR LPARAM
Definition: windef.h:208
#define CF_SCREENFONTS
Definition: commdlg.h:59
smooth NULL
Definition: ftsmooth.c:416
DWORD Flags
Definition: commdlg.h:266
HWND hwndOwner
Definition: commdlg.h:262
#define CreateFontIndirect
Definition: wingdi.h:4421
#define WM_SETFONT
Definition: winuser.h:1632
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define SendMessage
Definition: winuser.h:5709
#define CF_NOVERTFONTS
Definition: commdlg.h:86
#define CF_INITTOLOGFONTSTRUCT
Definition: commdlg.h:66

◆ DIALOG_StatusBarUpdateCaretPos()

VOID DIALOG_StatusBarUpdateCaretPos ( VOID  )

Definition at line 1165 of file dialog.c.

Referenced by DoCreateStatusBar(), EDIT_WndProc(), and NOTEPAD_WndProc().

1166 {
1167  int line, col;
1168  TCHAR buff[MAX_PATH];
1169  DWORD dwStart, dwSize;
1170 
1171  SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwSize);
1172  line = SendMessage(Globals.hEdit, EM_LINEFROMCHAR, (WPARAM)dwStart, 0);
1173  col = dwStart - SendMessage(Globals.hEdit, EM_LINEINDEX, (WPARAM)line, 0);
1174 
1175  _stprintf(buff, Globals.szStatusBarLineCol, line + 1, col + 1);
1176  SendMessage(Globals.hStatusBar, SB_SETTEXT, SB_SIMPLEID, (LPARAM)buff);
1177 }
UINT_PTR WPARAM
Definition: windef.h:207
#define EM_GETSEL
Definition: winuser.h:1958
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
LONG_PTR LPARAM
Definition: windef.h:208
#define SB_SIMPLEID
Definition: precomp.h:15
char TCHAR
Definition: xmlstorage.h:189
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
char line[200]
Definition: main.c:97
#define SB_SETTEXT
Definition: commctrl.h:1919
#define _stprintf
Definition: utility.h:124
#define EM_LINEFROMCHAR
Definition: winuser.h:1962
#define SendMessage
Definition: winuser.h:5709
#define EM_LINEINDEX
Definition: winuser.h:1963
static unsigned char buff[32768]
Definition: fatten.c:17
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

◆ DIALOG_StringMsgBox()

int DIALOG_StringMsgBox ( HWND  hParent,
int  formatId,
LPCTSTR  szString,
DWORD  dwFlags 
)

Definition at line 98 of file dialog.c.

Referenced by AlertFileDoesNotExist(), AlertFileNotFound(), AlertFileNotSaved(), and AlertPrintError().

99 {
100  TCHAR szMessage[MAX_STRING_LEN];
101  TCHAR szResource[MAX_STRING_LEN];
102 
103  /* Load and format szMessage */
104  LoadString(Globals.hInstance, formatId, szResource, ARRAY_SIZE(szResource));
105  _sntprintf(szMessage, ARRAY_SIZE(szMessage), szResource, szString);
106 
107  /* Load szCaption */
109  LoadString(Globals.hInstance, STRING_ERROR, szResource, ARRAY_SIZE(szResource));
110  else
111  LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, ARRAY_SIZE(szResource));
112 
113  /* Display Modal Dialog */
114  // if (hParent == NULL)
115  // hParent = Globals.hMainWnd;
116  return MessageBox(hParent, szMessage, szResource, dwFlags);
117 }
#define MB_ICONMASK
Definition: winuser.h:813
#define MAX_STRING_LEN
Definition: precomp.h:36
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define STRING_NOTEPAD
Definition: notepad_res.h:74
char TCHAR
Definition: xmlstorage.h:189
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define _sntprintf
Definition: xmlstorage.h:201
#define MessageBox
Definition: winuser.h:5688
#define ARRAY_SIZE(a)
Definition: main.h:24
#define STRING_ERROR
Definition: notepad_res.h:75
HINSTANCE hInstance
Definition: precomp.h:43
#define LoadString
Definition: winuser.h:5685

◆ DIALOG_ViewStatusBar()

VOID DIALOG_ViewStatusBar ( VOID  )

Definition at line 1179 of file dialog.c.

Referenced by _tWinMain(), and NOTEPAD_MenuCommand().

1180 {
1181  Globals.bShowStatusBar = !Globals.bShowStatusBar;
1182 
1184 }
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
VOID DoCreateStatusBar(VOID)
Definition: dialog.c:823

◆ DoCloseFile()

BOOL DoCloseFile ( VOID  )

Returns: TRUE - User agreed to close (both save/don't save) FALSE - User cancelled close by selecting "Cancel"

Definition at line 313 of file dialog.c.

Referenced by DIALOG_FileNew(), DoOpenFile(), and NOTEPAD_WndProc().

314 {
315  int nResult;
316 
317  if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
318  {
319  /* prompt user to save changes */
320  nResult = AlertFileNotSaved(Globals.szFileName);
321  switch (nResult)
322  {
323  case IDYES:
324  if(!DIALOG_FileSave())
325  return FALSE;
326  break;
327 
328  case IDNO:
329  break;
330 
331  case IDCANCEL:
332  return FALSE;
333 
334  default:
335  return FALSE;
336  }
337  }
338 
341 
342  return TRUE;
343 }
void UpdateWindowCaption(BOOL clearModifyAlert)
Definition: dialog.c:66
#define TRUE
Definition: types.h:120
static const TCHAR empty_str[]
Definition: dialog.c:32
#define IDYES
Definition: winuser.h:829
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
static VOID SetFileName(PCONSOLE_CHILDFRM_WND Info, PWSTR pFileName)
Definition: console.c:177
#define EM_GETMODIFY
Definition: winuser.h:1955
#define SendMessage
Definition: winuser.h:5709
#define IDNO
Definition: winuser.h:830
#define IDCANCEL
Definition: winuser.h:825
static int AlertFileNotSaved(LPCTSTR szFileName)
Definition: dialog.c:124
BOOL DIALOG_FileSave(VOID)
Definition: dialog.c:438

◆ DoCreateEditWindow()

VOID DoCreateEditWindow ( VOID  )

Definition at line 901 of file dialog.c.

Referenced by _tWinMain(), and DIALOG_EditWrap().

902 {
903  DWORD dwStyle;
904  int iSize;
905  LPTSTR pTemp = NULL;
906  BOOL bModified = FALSE;
907 
908  iSize = 0;
909 
910  /* If the edit control already exists, try to save its content */
911  if (Globals.hEdit != NULL)
912  {
913  /* number of chars currently written into the editor. */
914  iSize = GetWindowTextLength(Globals.hEdit);
915  if (iSize)
916  {
917  /* Allocates temporary buffer. */
918  pTemp = HeapAlloc(GetProcessHeap(), 0, (iSize + 1) * sizeof(TCHAR));
919  if (!pTemp)
920  {
921  ShowLastError();
922  return;
923  }
924 
925  /* Recover the text into the control. */
926  GetWindowText(Globals.hEdit, pTemp, iSize + 1);
927 
928  if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
929  bModified = TRUE;
930  }
931 
932  /* Restore original window procedure */
934 
935  /* Destroy the edit control */
936  DestroyWindow(Globals.hEdit);
937  }
938 
939  /* Update wrap status into the main menu and recover style flags */
940  if (Globals.bWrapLongLines)
941  {
942  dwStyle = EDIT_STYLE_WRAP;
944  } else {
945  dwStyle = EDIT_STYLE;
947  }
948 
949  /* Update previous changes */
951 
952  /* Create the new edit control */
954  EDIT_CLASS,
955  NULL,
956  dwStyle,
962  NULL,
964  NULL);
965 
966  if (Globals.hEdit == NULL)
967  {
968  if (pTemp)
969  {
970  HeapFree(GetProcessHeap(), 0, pTemp);
971  }
972 
973  ShowLastError();
974  return;
975  }
976 
978  SendMessage(Globals.hEdit, EM_LIMITTEXT, 0, 0);
979 
980  /* If some text was previously saved, restore it. */
981  if (iSize != 0)
982  {
983  SetWindowText(Globals.hEdit, pTemp);
984  HeapFree(GetProcessHeap(), 0, pTemp);
985 
986  if (bModified)
987  SendMessage(Globals.hEdit, EM_SETMODIFY, TRUE, 0);
988  }
989 
990  /* Sub-class a new window callback for row/column detection. */
991  Globals.EditProc = (WNDPROC)SetWindowLongPtr(Globals.hEdit,
992  GWLP_WNDPROC,
994 
995  /* Create/update status bar */
997 
998  /* Finally shows new edit control and set focus into it. */
999  ShowWindow(Globals.hEdit, SW_SHOW);
1000  SetFocus(Globals.hEdit);
1001 }
#define EM_LIMITTEXT
Definition: winuser.h:1961
#define MF_DISABLED
Definition: winuser.h:130
#define TRUE
Definition: types.h:120
BOOL WINAPI DrawMenuBar(_In_ HWND)
#define MF_BYCOMMAND
Definition: winuser.h:202
HWND WINAPI SetFocus(_In_opt_ HWND)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI DestroyWindow(_In_ HWND)
#define SetWindowLongPtr
Definition: treelist.c:70
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5664
UINT_PTR WPARAM
Definition: windef.h:207
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define CMD_STATUSBAR
Definition: notepad_res.h:60
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define CreateWindowEx
Definition: winuser.h:5621
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
VOID DoCreateStatusBar(VOID)
Definition: dialog.c:823
#define SW_SHOW
Definition: winuser.h:769
char TCHAR
Definition: xmlstorage.h:189
VOID ShowLastError(VOID)
Definition: dialog.c:38
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define EDIT_CLASS
Definition: main.h:32
#define MF_ENABLED
Definition: winuser.h:128
#define EM_GETMODIFY
Definition: winuser.h:1955
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EM_SETMODIFY
Definition: winuser.h:1974
#define GWLP_WNDPROC
Definition: treelist.c:66
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2859
LRESULT CALLBACK EDIT_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: main.c:304
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define SetWindowText
Definition: winuser.h:5723
#define WM_SETFONT
Definition: winuser.h:1632
#define SendMessage
Definition: winuser.h:5709
#define EDIT_STYLE_WRAP
Definition: main.h:28
#define EDIT_STYLE
Definition: main.h:30
#define GetWindowTextLength
Definition: winuser.h:5665
#define MF_GRAYED
Definition: winuser.h:129
HINSTANCE hInstance
Definition: precomp.h:43
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ DoCreateStatusBar()

VOID DoCreateStatusBar ( VOID  )

Definition at line 823 of file dialog.c.

Referenced by DIALOG_ViewStatusBar(), and DoCreateEditWindow().

824 {
825  RECT rc;
826  RECT rcstatus;
827  BOOL bStatusBarVisible;
828 
829  /* Check if status bar object already exists. */
830  if (Globals.hStatusBar == NULL)
831  {
832  /* Try to create the status bar */
834  NULL,
837 
838  if (Globals.hStatusBar == NULL)
839  {
840  ShowLastError();
841  return;
842  }
843 
844  /* Load the string for formatting column/row text output */
845  LoadString(Globals.hInstance, STRING_LINE_COLUMN, Globals.szStatusBarLineCol, MAX_PATH - 1);
846 
847  /* Set the status bar for single-text output */
848  SendMessage(Globals.hStatusBar, SB_SIMPLE, (WPARAM)TRUE, (LPARAM)0);
849  }
850 
851  /* Set status bar visiblity according to the settings. */
852  if ((Globals.bWrapLongLines != FALSE) || (Globals.bShowStatusBar == FALSE))
853  {
854  bStatusBarVisible = FALSE;
855  ShowWindow(Globals.hStatusBar, SW_HIDE);
856  }
857  else
858  {
859  bStatusBarVisible = TRUE;
860  ShowWindow(Globals.hStatusBar, SW_SHOW);
861  SendMessage(Globals.hStatusBar, WM_SIZE, 0, 0);
862  }
863 
864  /* Set check state in show status bar item. */
865  if (bStatusBarVisible)
866  {
868  }
869  else
870  {
872  }
873 
874  /* Update menu mar with the previous changes */
876 
877  /* Sefety test is edit control exists */
878  if (Globals.hEdit != NULL)
879  {
880  /* Retrieve the sizes of the controls */
882  GetClientRect(Globals.hStatusBar, &rcstatus);
883 
884  /* If status bar is currently visible, update dimensions of edit control */
885  if (bStatusBarVisible)
886  rc.bottom -= (rcstatus.bottom - rcstatus.top);
887 
888  /* Resize edit control to right size. */
889  MoveWindow(Globals.hEdit,
890  rc.left,
891  rc.top,
892  rc.right - rc.left,
893  rc.bottom - rc.top,
894  TRUE);
895  }
896 
897  /* Update content with current row/column text */
899 }
#define STRING_LINE_COLUMN
Definition: notepad_res.h:99
#define TRUE
Definition: types.h:120
BOOL WINAPI DrawMenuBar(_In_ HWND)
#define MF_BYCOMMAND
Definition: winuser.h:202
#define SW_HIDE
Definition: winuser.h:762
LONG top
Definition: windef.h:297
#define WS_CHILD
Definition: pedump.c:617
LONG left
Definition: windef.h:296
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
LONG right
Definition: windef.h:298
UINT_PTR WPARAM
Definition: windef.h:207
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define CMD_STATUSBAR
Definition: notepad_res.h:60
LONG_PTR LPARAM
Definition: windef.h:208
#define CreateStatusWindow
Definition: commctrl.h:1903
#define SB_SIMPLE
Definition: commctrl.h:1928
smooth NULL
Definition: ftsmooth.c:416
#define SW_SHOW
Definition: winuser.h:769
#define MF_CHECKED
Definition: winuser.h:132
VOID ShowLastError(VOID)
Definition: dialog.c:38
unsigned int BOOL
Definition: ntddk_ex.h:94
#define WM_SIZE
Definition: winuser.h:1593
#define MAX_PATH
Definition: compat.h:26
VOID DIALOG_StatusBarUpdateCaretPos(VOID)
Definition: dialog.c:1165
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MF_UNCHECKED
Definition: winuser.h:204
BOOL WINAPI MoveWindow(_In_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ BOOL)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define SendMessage
Definition: winuser.h:5709
LONG bottom
Definition: windef.h:299
HINSTANCE hInstance
Definition: precomp.h:43
#define WS_VISIBLE
Definition: pedump.c:620
#define CMD_STATUSBAR_WND_ID
Definition: notepad_res.h:61
#define WS_EX_STATICEDGE
Definition: winuser.h:403
#define LoadString
Definition: winuser.h:5685

◆ DoOpenFile()

VOID DoOpenFile ( LPCTSTR  szFileName)

Definition at line 345 of file dialog.c.

Referenced by DIALOG_FileOpen().

346 {
347  static const TCHAR dotlog[] = _T(".LOG");
348  HANDLE hFile;
349  LPTSTR pszText = NULL;
350  DWORD dwTextLen;
351  TCHAR log[5];
352 
353  /* Close any files and prompt to save changes */
354  if (!DoCloseFile())
355  return;
356 
359  if (hFile == INVALID_HANDLE_VALUE)
360  {
361  ShowLastError();
362  goto done;
363  }
364 
365  if (!ReadText(hFile, (LPWSTR *)&pszText, &dwTextLen, &Globals.encFile, &Globals.iEoln))
366  {
367  ShowLastError();
368  goto done;
369  }
370  SetWindowText(Globals.hEdit, pszText);
371 
373  SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
374  SetFocus(Globals.hEdit);
375 
376  /* If the file starts with .LOG, add a time/date at the end and set cursor after
377  * See http://support.microsoft.com/?kbid=260563
378  */
379  if (GetWindowText(Globals.hEdit, log, ARRAY_SIZE(log)) && !_tcscmp(log, dotlog))
380  {
381  static const TCHAR lf[] = _T("\r\n");
386  }
387 
388  SetFileName(szFileName);
391 done:
392  if (hFile != INVALID_HANDLE_VALUE)
393  CloseHandle(hFile);
394  if (pszText)
395  HeapFree(GetProcessHeap(), 0, pszText);
396 }
void UpdateWindowCaption(BOOL clearModifyAlert)
Definition: dialog.c:66
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
LPCWSTR pszText
Definition: msvc.h:103
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
HWND WINAPI SetFocus(_In_opt_ HWND)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FILE_SHARE_READ
Definition: compat.h:125
#define GetWindowText
Definition: winuser.h:5664
BOOL ReadText(HANDLE hFile, LPWSTR *ppszText, DWORD *pdwTextLen, ENCODING *pencFile, int *piEoln)
Definition: text.c:51
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
LONG_PTR LPARAM
Definition: windef.h:208
BOOL DoCloseFile(VOID)
Definition: dialog.c:313
smooth NULL
Definition: ftsmooth.c:416
static VOID SetFileName(PCONSOLE_CHILDFRM_WND Info, PWSTR pFileName)
Definition: console.c:177
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
VOID ShowLastError(VOID)
Definition: dialog.c:38
#define GetProcessHeap()
Definition: compat.h:395
#define EM_SETSEL
Definition: winuser.h:1979
unsigned long DWORD
Definition: ntddk_ex.h:95
#define OPEN_ALWAYS
Definition: disk.h:70
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define EM_EMPTYUNDOBUFFER
Definition: winuser.h:1946
#define GENERIC_READ
Definition: compat.h:124
#define EM_SETMODIFY
Definition: winuser.h:1974
_In_ HANDLE hFile
Definition: mswsock.h:90
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define ARRAY_SIZE(a)
Definition: main.h:24
#define SetWindowText
Definition: winuser.h:5723
VOID NOTEPAD_EnableSearchMenu()
Definition: main.c:32
#define SendMessage
Definition: winuser.h:5709
#define GetWindowTextLength
Definition: winuser.h:5665
WCHAR * LPWSTR
Definition: xmlstorage.h:184
VOID DIALOG_EditTimeDate(VOID)
Definition: dialog.c:807
#define HeapFree(x, y, z)
Definition: compat.h:394
#define log(outFile, fmt,...)
Definition: util.h:15
#define EM_REPLACESEL
Definition: winuser.h:1967

◆ DoSaveFile()

static BOOL DoSaveFile ( VOID  )
static

Definition at line 264 of file dialog.c.

Referenced by DIALOG_FileSave(), and DIALOG_FileSaveAs().

265 {
266  BOOL bRet = TRUE;
267  HANDLE hFile;
268  LPTSTR pTemp;
269  DWORD size;
270 
271  hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
273  if(hFile == INVALID_HANDLE_VALUE)
274  {
275  ShowLastError();
276  return FALSE;
277  }
278 
279  size = GetWindowTextLength(Globals.hEdit) + 1;
280  pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*pTemp));
281  if (!pTemp)
282  {
283  CloseHandle(hFile);
284  ShowLastError();
285  return FALSE;
286  }
287  size = GetWindowText(Globals.hEdit, pTemp, size);
288 
289  if (size)
290  {
291  if (!WriteText(hFile, (LPWSTR)pTemp, size, Globals.encFile, Globals.iEoln))
292  {
293  ShowLastError();
294  bRet = FALSE;
295  }
296  else
297  {
299  bRet = TRUE;
300  }
301  }
302 
303  CloseHandle(hFile);
304  HeapFree(GetProcessHeap(), 0, pTemp);
305  return bRet;
306 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, ENCODING encFile, int iEoln)
Definition: text.c:319
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5664
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
VOID ShowLastError(VOID)
Definition: dialog.c:38
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define EM_SETMODIFY
Definition: winuser.h:1974
_In_ HANDLE hFile
Definition: mswsock.h:90
#define CREATE_ALWAYS
Definition: disk.h:72
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define SendMessage
Definition: winuser.h:5709
#define GetWindowTextLength
Definition: winuser.h:5665
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ EDIT_WndProc()

LRESULT CALLBACK EDIT_WndProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 304 of file main.c.

Referenced by DoCreateEditWindow().

305 {
306  switch (msg)
307  {
308  case WM_KEYDOWN:
309  case WM_KEYUP:
310  {
311  switch (wParam)
312  {
313  case VK_UP:
314  case VK_DOWN:
315  case VK_LEFT:
316  case VK_RIGHT:
318  break;
319  default:
320  {
322  break;
323  }
324  }
325  }
326  case WM_LBUTTONUP:
327  {
329  break;
330  }
331  }
332  return CallWindowProc( Globals.EditProc, hWnd, msg, wParam, lParam);
333 }
#define CallWindowProc
Definition: winuser.h:5601
NOTEPAD_GLOBALS Globals
Definition: main.c:29
#define VK_LEFT
Definition: winuser.h:2178
#define VK_DOWN
Definition: winuser.h:2181
WNDPROC EditProc
Definition: main.h:85
WPARAM wParam
Definition: combotst.c:138
#define VK_UP
Definition: winuser.h:2179
UINT msg
Definition: msvc.h:92
#define WM_KEYDOWN
Definition: winuser.h:1691
VOID DIALOG_StatusBarUpdateCaretPos(VOID)
Definition: dialog.c:1165
#define WM_KEYUP
Definition: winuser.h:1692
#define VK_RIGHT
Definition: winuser.h:2180
#define WM_LBUTTONUP
Definition: winuser.h:1753
LPARAM lParam
Definition: combotst.c:139
void UpdateWindowCaption(HWND hwnd)
Definition: mplay32.c:96

◆ FileExists()

BOOL FileExists ( LPCTSTR  szFilename)

Returns: TRUE - if file exists FALSE - if file does not exist

Definition at line 151 of file dialog.c.

Referenced by DIALOG_FileOpen(), and HandleCommandLine().

152 {
154  HANDLE hFile;
155 
156  hFile = FindFirstFile(szFilename, &entry);
157  FindClose(hFile);
158 
159  return (hFile != INVALID_HANDLE_VALUE);
160 }
uint8_t entry
Definition: isohybrid.c:63
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FindFirstFile
Definition: winbase.h:3596
_In_ HANDLE hFile
Definition: mswsock.h:90
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

◆ GetPrintingRect()

static RECT GetPrintingRect ( HDC  hdc,
RECT  margins 
)
static

Definition at line 240 of file dialog.c.

Referenced by DIALOG_FilePrint().

241 {
242  int iLogPixelsX, iLogPixelsY;
243  int iHorzRes, iVertRes;
244  int iPhysPageX, iPhysPageY, iPhysPageW, iPhysPageH;
245  RECT rcPrintRect;
246 
247  iPhysPageX = GetDeviceCaps(hdc, PHYSICALOFFSETX);
248  iPhysPageY = GetDeviceCaps(hdc, PHYSICALOFFSETY);
249  iPhysPageW = GetDeviceCaps(hdc, PHYSICALWIDTH);
250  iPhysPageH = GetDeviceCaps(hdc, PHYSICALHEIGHT);
251  iLogPixelsX = GetDeviceCaps(hdc, LOGPIXELSX);
252  iLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY);
253  iHorzRes = GetDeviceCaps(hdc, HORZRES);
254  iVertRes = GetDeviceCaps(hdc, VERTRES);
255 
256  rcPrintRect.left = (margins.left * iLogPixelsX / 2540) - iPhysPageX;
257  rcPrintRect.top = (margins.top * iLogPixelsY / 2540) - iPhysPageY;
258  rcPrintRect.right = iHorzRes - (((margins.left * iLogPixelsX / 2540) - iPhysPageX) + ((margins.right * iLogPixelsX / 2540) - (iPhysPageW - iPhysPageX - iHorzRes)));
259  rcPrintRect.bottom = iVertRes - (((margins.top * iLogPixelsY / 2540) - iPhysPageY) + ((margins.bottom * iLogPixelsY / 2540) - (iPhysPageH - iPhysPageY - iVertRes)));
260 
261  return rcPrintRect;
262 }
#define HORZRES
Definition: wingdi.h:714
#define LOGPIXELSX
Definition: wingdi.h:716
LONG top
Definition: windef.h:297
LONG left
Definition: windef.h:296
LONG right
Definition: windef.h:298
#define PHYSICALHEIGHT
Definition: wingdi.h:734
HDC hdc
Definition: msvc.h:53
#define PHYSICALOFFSETY
Definition: wingdi.h:736
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define PHYSICALOFFSETX
Definition: wingdi.h:735
#define PHYSICALWIDTH
Definition: wingdi.h:733
#define VERTRES
Definition: wingdi.h:715
LONG bottom
Definition: windef.h:299
#define LOGPIXELSY
Definition: wingdi.h:717

◆ GetSelectionText()

int GetSelectionText ( HWND  hWnd,
LPTSTR  lpString,
int  nMaxCount 
)

Definition at line 182 of file dialog.c.

Referenced by DIALOG_FilePrint().

183 {
184  DWORD dwStart = 0;
185  DWORD dwEnd = 0;
186  DWORD dwSize;
187  HRESULT hResult;
188  LPTSTR lpTemp;
189 
190  if (!lpString)
191  {
192  return 0;
193  }
194 
195  SendMessage(hWnd, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
196 
197  if (dwStart == dwEnd)
198  {
199  return 0;
200  }
201 
202  dwSize = GetWindowTextLength(hWnd) + 1;
203  lpTemp = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(TCHAR));
204  if (!lpTemp)
205  {
206  return 0;
207  }
208 
209  dwSize = GetWindowText(hWnd, lpTemp, dwSize);
210 
211  if (!dwSize)
212  {
213  HeapFree(GetProcessHeap(), 0, lpTemp);
214  return 0;
215  }
216 
217  hResult = StringCchCopyN(lpString, nMaxCount, lpTemp + dwStart, dwEnd - dwStart);
218  HeapFree(GetProcessHeap(), 0, lpTemp);
219 
220  switch (hResult)
221  {
222  case S_OK:
223  {
224  return dwEnd - dwStart;
225  }
226 
228  {
229  return nMaxCount - 1;
230  }
231 
232  default:
233  {
234  return 0;
235  }
236  }
237 }
#define StringCchCopyN
Definition: strsafe.h:227
#define STRSAFE_E_INSUFFICIENT_BUFFER
Definition: strsafe.h:103
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5664
UINT_PTR WPARAM
Definition: windef.h:207
#define EM_GETSEL
Definition: winuser.h:1958
LONG_PTR LPARAM
Definition: windef.h:208
char TCHAR
Definition: xmlstorage.h:189
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:59
#define SendMessage
Definition: winuser.h:5709
#define GetWindowTextLength
Definition: winuser.h:5665
_In_ int nMaxCount
Definition: winuser.h:4746
#define HeapFree(x, y, z)
Definition: compat.h:394
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

◆ GetSelectionTextLength()

int GetSelectionTextLength ( HWND  hWnd)

Definition at line 172 of file dialog.c.

Referenced by DIALOG_FilePrint().

173 {
174  DWORD dwStart = 0;
175  DWORD dwEnd = 0;
176 
177  SendMessage(hWnd, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
178 
179  return dwEnd - dwStart;
180 }
UINT_PTR WPARAM
Definition: windef.h:207
#define EM_GETSEL
Definition: winuser.h:1958
LONG_PTR LPARAM
Definition: windef.h:208
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SendMessage
Definition: winuser.h:5709

◆ HasFileExtension()

BOOL HasFileExtension ( LPCTSTR  szFilename)

Definition at line 162 of file dialog.c.

Referenced by HandleCommandLine().

163 {
164  LPCTSTR s;
165 
166  s = _tcsrchr(szFilename, _T('\\'));
167  if (s)
168  szFilename = s;
169  return _tcsrchr(szFilename, _T('.')) != NULL;
170 }
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
GLdouble s
Definition: gl.h:2039
_TCHAR * _tcsrchr(const _TCHAR *s, _XINT c)
Definition: tcsrchr.h:4

◆ ShowLastError()

VOID ShowLastError ( VOID  )

Definition at line 38 of file dialog.c.

Referenced by _tWinMain(), DIALOG_FilePrint(), DoCreateEditWindow(), DoCreateStatusBar(), DoOpenFile(), and DoSaveFile().

39 {
41  if (error != NO_ERROR)
42  {
43  LPTSTR lpMsgBuf = NULL;
45 
46  LoadString(Globals.hInstance, STRING_ERROR, szTitle, ARRAY_SIZE(szTitle));
47 
49  NULL,
50  error,
51  0,
52  (LPTSTR) &lpMsgBuf,
53  0,
54  NULL);
55 
56  MessageBox(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
57  LocalFree(lpMsgBuf);
58  }
59 }
#define error(str)
Definition: mkdosfs.c:1605
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define MAX_STRING_LEN
Definition: precomp.h:36
#define NO_ERROR
Definition: dderror.h:5
CHAR * LPTSTR
Definition: xmlstorage.h:192
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
char TCHAR
Definition: xmlstorage.h:189
unsigned long DWORD
Definition: ntddk_ex.h:95
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:36
#define FormatMessage
Definition: winbase.h:3609
#define MB_ICONERROR
Definition: winuser.h:781
#define MessageBox
Definition: winuser.h:5688
#define ARRAY_SIZE(a)
Definition: main.h:24
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define STRING_ERROR
Definition: notepad_res.h:75
#define MB_OK
Definition: winuser.h:784
HINSTANCE hInstance
Definition: precomp.h:43
#define LoadString
Definition: winuser.h:5685

◆ UpdateWindowCaption()

void UpdateWindowCaption ( BOOL  clearModifyAlert)

Sets the caption of the main window according to Globals.szFileTitle: (untitled) - Notepad if no file is open [filename] - Notepad if a file is given

Definition at line 66 of file dialog.c.

Referenced by DIALOG_FileSave(), DIALOG_FileSaveAs(), DoCloseFile(), and DoOpenFile().

67 {
68  TCHAR szCaption[MAX_STRING_LEN];
69  TCHAR szNotepad[MAX_STRING_LEN];
70  TCHAR szFilename[MAX_STRING_LEN];
71 
72  /* Load the name of the application */
73  LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, ARRAY_SIZE(szNotepad));
74 
75  /* Determine if the file has been saved or if this is a new file */
76  if (Globals.szFileTitle[0] != 0)
77  StringCchCopy(szFilename, ARRAY_SIZE(szFilename), Globals.szFileTitle);
78  else
79  LoadString(Globals.hInstance, STRING_UNTITLED, szFilename, ARRAY_SIZE(szFilename));
80 
81  /* When a file is being opened or created, there is no need to have the edited flag shown
82  when the new or opened file has not been edited yet */
83  if (clearModifyAlert)
84  StringCbPrintf(szCaption, ARRAY_SIZE(szCaption), _T("%s - %s"), szFilename, szNotepad);
85  else
86  {
87  BOOL isModified = (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0) ? TRUE : FALSE);
88 
89  /* Update the caption based upon if the user has modified the contents of the file or not */
90  StringCbPrintf(szCaption, ARRAY_SIZE(szCaption), _T("%s%s - %s"),
91  (isModified ? _T("*") : _T("")), szFilename, szNotepad);
92  }
93 
94  /* Update the window caption */
95  SetWindowText(Globals.hMainWnd, szCaption);
96 }
#define TRUE
Definition: types.h:120
#define MAX_STRING_LEN
Definition: precomp.h:36
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define STRING_NOTEPAD
Definition: notepad_res.h:74
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
#define STRING_UNTITLED
Definition: notepad_res.h:78
#define StringCbPrintf
Definition: strsafe.h:544
#define EM_GETMODIFY
Definition: winuser.h:1955
#define StringCchCopy
Definition: strsafe.h:139
#define ARRAY_SIZE(a)
Definition: main.h:24
#define SetWindowText
Definition: winuser.h:5723
#define SendMessage
Definition: winuser.h:5709
HINSTANCE hInstance
Definition: precomp.h:43
#define LoadString
Definition: winuser.h:5685

Variable Documentation

◆ empty_str

◆ helpfile

const TCHAR helpfile[] = _T("notepad.hlp")
static

Definition at line 31 of file dialog.c.

Referenced by DIALOG_HelpContents(), and test_CreateTypeLib().

◆ szDefaultExt

const TCHAR szDefaultExt[] = _T("txt")
static

Definition at line 33 of file dialog.c.

Referenced by DIALOG_FileOpen(), and DIALOG_FileSaveAs().

◆ txt_files

const TCHAR txt_files[] = _T("*.txt")
static

Definition at line 34 of file dialog.c.

Referenced by DIALOG_FileOpen(), DIALOG_FileSaveAs(), and NOTEPAD_InitData().