ReactOS  0.4.14-dev-614-gbfd8a84
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 1045 of file dialog.c.

Function Documentation

◆ AlertFileNotFound()

static void AlertFileNotFound ( LPCTSTR  szFileName)
static

Definition at line 122 of file dialog.c.

123 {
125 }
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCTSTR szString, DWORD dwFlags)
Definition: dialog.c:101
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define MB_OK
Definition: winuser.h:784
#define STRING_NOTFOUND
Definition: notepad_res.h:86

Referenced by DIALOG_FileOpen().

◆ AlertFileNotSaved()

static int AlertFileNotSaved ( LPCTSTR  szFileName)
static

Definition at line 127 of file dialog.c.

128 {
129  TCHAR szUntitled[MAX_STRING_LEN];
130 
131  LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, ARRAY_SIZE(szUntitled));
132 
134  szFileName[0] ? szFileName : szUntitled,
136 }
HINSTANCE hInstance
Definition: precomp.h:32
#define MAX_STRING_LEN
Definition: precomp.h:36
#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:101
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define ARRAY_SIZE(a)
Definition: main.h:24
#define LoadString
Definition: winuser.h:5794

Referenced by DoCloseFile().

◆ AlertPrintError()

static void AlertPrintError ( void  )
static

Definition at line 138 of file dialog.c.

139 {
140  TCHAR szUntitled[MAX_STRING_LEN];
141 
142  LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, ARRAY_SIZE(szUntitled));
143 
145  Globals.szFileName[0] ? Globals.szFileName : szUntitled,
147 }
HINSTANCE hInstance
Definition: precomp.h:32
#define MAX_STRING_LEN
Definition: precomp.h:36
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
#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:101
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define ARRAY_SIZE(a)
Definition: main.h:24
#define MB_OK
Definition: winuser.h:784
#define LoadString
Definition: winuser.h:5794

Referenced by DIALOG_FilePrint().

◆ DIALOG_EditCopy()

VOID DIALOG_EditCopy ( VOID  )

Definition at line 790 of file dialog.c.

791 {
792  SendMessage(Globals.hEdit, WM_COPY, 0, 0);
793 }
#define WM_COPY
Definition: winuser.h:1844
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define SendMessage
Definition: winuser.h:5818

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_EditCut()

VOID DIALOG_EditCut ( VOID  )

Definition at line 785 of file dialog.c.

786 {
787  SendMessage(Globals.hEdit, WM_CUT, 0, 0);
788 }
#define WM_CUT
Definition: winuser.h:1843
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define SendMessage
Definition: winuser.h:5818

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_EditDelete()

VOID DIALOG_EditDelete ( VOID  )

Definition at line 800 of file dialog.c.

801 {
802  SendMessage(Globals.hEdit, WM_CLEAR, 0, 0);
803 }
#define WM_CLEAR
Definition: winuser.h:1846
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define SendMessage
Definition: winuser.h:5818

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_EditPaste()

VOID DIALOG_EditPaste ( VOID  )

Definition at line 795 of file dialog.c.

796 {
797  SendMessage(Globals.hEdit, WM_PASTE, 0, 0);
798 }
#define WM_PASTE
Definition: winuser.h:1845
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define SendMessage
Definition: winuser.h:5818

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_EditSelectAll()

VOID DIALOG_EditSelectAll ( VOID  )

Definition at line 805 of file dialog.c.

806 {
807  SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1);
808 }
LONG_PTR LPARAM
Definition: windef.h:208
#define EM_SETSEL
Definition: winuser.h:2000
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define SendMessage
Definition: winuser.h:5818

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_EditTimeDate()

VOID DIALOG_EditTimeDate ( VOID  )

Definition at line 810 of file dialog.c.

811 {
812  SYSTEMTIME st;
814  TCHAR szText[MAX_STRING_LEN * 2 + 2];
815 
816  GetLocalTime(&st);
817 
820  _tcscat(szText, _T(" "));
824 }
#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
static const WCHAR szText[]
Definition: dialog.c:139
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:286
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
static const WCHAR szDate[]
Definition: http.c:100
#define GetTimeFormat
Definition: winnls.h:1186
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define GetDateFormat
Definition: winnls.h:1181
#define DATE_LONGDATE
Definition: winnls.h:194
#define SendMessage
Definition: winuser.h:5818
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
#define EM_REPLACESEL
Definition: winuser.h:1988

Referenced by DoOpenFile(), and NOTEPAD_MenuCommand().

◆ DIALOG_EditUndo()

VOID DIALOG_EditUndo ( VOID  )

Definition at line 780 of file dialog.c.

781 {
782  SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
783 }
#define EM_UNDO
Definition: winuser.h:2003
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define SendMessage
Definition: winuser.h:5818

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_EditWrap()

VOID DIALOG_EditWrap ( VOID  )

Definition at line 1006 of file dialog.c.

1007 {
1008  Globals.bWrapLongLines = !Globals.bWrapLongLines;
1009 
1010  if (Globals.bWrapLongLines)
1011  {
1013  }
1014  else
1015  {
1017  }
1018 
1020 }
#define MF_DISABLED
Definition: winuser.h:130
#define MF_BYCOMMAND
Definition: winuser.h:202
#define CMD_GOTO
Definition: notepad_res.h:55
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
VOID DoCreateEditWindow(VOID)
Definition: dialog.c:904
#define MF_ENABLED
Definition: winuser.h:128
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define MF_GRAYED
Definition: winuser.h:129

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_FileExit()

VOID DIALOG_FileExit ( VOID  )

Definition at line 775 of file dialog.c.

776 {
777  PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
778 }
#define PostMessage
Definition: winuser.h:5807
r l[0]
Definition: byte_order.h:167
#define WM_CLOSE
Definition: winuser.h:1603
UTILMAN_GLOBALS Globals
Definition: dialog.c:15

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_FileNew()

VOID DIALOG_FileNew ( VOID  )

Definition at line 401 of file dialog.c.

402 {
403  /* Close any files and prompt to save changes */
404  if (DoCloseFile()) {
406  SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
407  SetFocus(Globals.hEdit);
409  }
410 }
static const TCHAR empty_str[]
Definition: dialog.c:32
HWND WINAPI SetFocus(_In_opt_ HWND)
BOOL DoCloseFile(VOID)
Definition: dialog.c:316
#define EM_EMPTYUNDOBUFFER
Definition: winuser.h:1967
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define SetWindowText
Definition: winuser.h:5832
VOID NOTEPAD_EnableSearchMenu()
Definition: main.c:32
#define SendMessage
Definition: winuser.h:5818

Referenced by _tWinMain(), and NOTEPAD_MenuCommand().

◆ DIALOG_FileOpen()

VOID DIALOG_FileOpen ( VOID  )

Definition at line 412 of file dialog.c.

413 {
414  OPENFILENAME openfilename;
416 
417  ZeroMemory(&openfilename, sizeof(openfilename));
418 
419  if (Globals.szFileName[0] == 0)
421  else
422  _tcscpy(szPath, Globals.szFileName);
423 
424  openfilename.lStructSize = sizeof(openfilename);
425  openfilename.hwndOwner = Globals.hMainWnd;
426  openfilename.hInstance = Globals.hInstance;
427  openfilename.lpstrFilter = Globals.szFilter;
428  openfilename.lpstrFile = szPath;
429  openfilename.nMaxFile = ARRAY_SIZE(szPath);
431  openfilename.lpstrDefExt = szDefaultExt;
432 
433  if (GetOpenFileName(&openfilename)) {
434  if (FileExists(openfilename.lpstrFile))
435  DoOpenFile(openfilename.lpstrFile);
436  else
437  AlertFileNotFound(openfilename.lpstrFile);
438  }
439 }
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
VOID DoOpenFile(LPCTSTR szFileName)
Definition: dialog.c:348
HWND hwndOwner
Definition: commdlg.h:330
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
HINSTANCE hInstance
Definition: precomp.h:32
#define ZeroMemory
Definition: winbase.h:1642
LPCSTR lpstrDefExt
Definition: commdlg.h:345
static void AlertFileNotFound(LPCTSTR szFileName)
Definition: dialog.c:122
#define GetOpenFileName
Definition: commdlg.h:665
DWORD nMaxFile
Definition: commdlg.h:337
BOOL FileExists(LPCTSTR szFilename)
Definition: dialog.c:154
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
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
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
DWORD Flags
Definition: commdlg.h:342

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_FilePageSetup()

VOID DIALOG_FilePageSetup ( void  )

Definition at line 1212 of file dialog.c.

1213 {
1215 
1216  ZeroMemory(&page, sizeof(page));
1217  page.lStructSize = sizeof(page);
1218  page.hwndOwner = Globals.hMainWnd;
1220  page.hInstance = Globals.hInstance;
1221  page.rtMargin = Globals.lMargins;
1222  page.hDevMode = Globals.hDevMode;
1223  page.hDevNames = Globals.hDevNames;
1224  page.lpPageSetupTemplateName = MAKEINTRESOURCE(DIALOG_PAGESETUP);
1225  page.lpfnPageSetupHook = DIALOG_PAGESETUP_Hook;
1226 
1227  PageSetupDlg(&page);
1228 
1229  Globals.hDevMode = page.hDevMode;
1230  Globals.hDevNames = page.hDevNames;
1231  Globals.lMargins = page.rtMargin;
1232 }
static UINT_PTR CALLBACK DIALOG_PAGESETUP_Hook(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:1239
#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
HINSTANCE hInstance
Definition: precomp.h:32
#define ZeroMemory
Definition: winbase.h:1642
#define DIALOG_PAGESETUP
Definition: notepad_res.h:25
Definition: module.h:566
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define PSD_ENABLEPAGESETUPHOOK
Definition: commdlg.h:183

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_FilePrint()

VOID DIALOG_FilePrint ( VOID  )

Definition at line 560 of file dialog.c.

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

Referenced by HandleCommandLine(), and NOTEPAD_MenuCommand().

◆ DIALOG_FileSave()

BOOL DIALOG_FileSave ( VOID  )

Definition at line 441 of file dialog.c.

442 {
443  if (Globals.szFileName[0] == 0)
444  {
445  return DIALOG_FileSaveAs();
446  }
447  else if (DoSaveFile())
448  {
450  return TRUE;
451  }
452  return FALSE;
453 }
void UpdateWindowCaption(BOOL clearModifyAlert)
Definition: dialog.c:66
#define TRUE
Definition: types.h:120
static BOOL DoSaveFile(VOID)
Definition: dialog.c:267
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
BOOL DIALOG_FileSaveAs(VOID)
Definition: dialog.c:513

Referenced by DoCloseFile(), and NOTEPAD_MenuCommand().

◆ DIALOG_FileSaveAs()

BOOL DIALOG_FileSaveAs ( VOID  )

Definition at line 513 of file dialog.c.

514 {
515  OPENFILENAME saveas;
517 
518  ZeroMemory(&saveas, sizeof(saveas));
519 
520  if (Globals.szFileName[0] == 0)
522  else
523  _tcscpy(szPath, Globals.szFileName);
524 
525  saveas.lStructSize = sizeof(OPENFILENAME);
526  saveas.hwndOwner = Globals.hMainWnd;
527  saveas.hInstance = Globals.hInstance;
528  saveas.lpstrFilter = Globals.szFilter;
529  saveas.lpstrFile = szPath;
530  saveas.nMaxFile = ARRAY_SIZE(szPath);
533  saveas.lpstrDefExt = szDefaultExt;
536 
537  if (GetSaveFileName(&saveas))
538  {
539  /* HACK: Because in ROS, Save-As boxes don't check the validity
540  * of file names and thus, here, szPath can be invalid !! We only
541  * see its validity when we call DoSaveFile()... */
543  if (DoSaveFile())
544  {
546  return TRUE;
547  }
548  else
549  {
550  SetFileName(_T(""));
551  return FALSE;
552  }
553  }
554  else
555  {
556  return FALSE;
557  }
558 }
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:457
HWND hwndOwner
Definition: commdlg.h:330
static BOOL DoSaveFile(VOID)
Definition: dialog.c:267
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
HINSTANCE hInstance
Definition: precomp.h:32
#define ZeroMemory
Definition: winbase.h:1642
LPCSTR lpstrDefExt
Definition: commdlg.h:345
LPCSTR lpTemplateName
Definition: commdlg.h:348
DWORD nMaxFile
Definition: commdlg.h:337
#define GetSaveFileName
Definition: commdlg.h:666
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:179
#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
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
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
DWORD Flags
Definition: commdlg.h:342

Referenced by DIALOG_FileSave(), and NOTEPAD_MenuCommand().

◆ DIALOG_FileSaveAs_Hook()

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

Definition at line 457 of file dialog.c.

458 {
459  TCHAR szText[128];
460  HWND hCombo;
461 
463 
464  switch(msg)
465  {
466  case WM_INITDIALOG:
467  hCombo = GetDlgItem(hDlg, ID_ENCODING);
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 
479  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
480 
481  SendMessage(hCombo, CB_SETCURSEL, Globals.encFile, 0);
482 
483  hCombo = GetDlgItem(hDlg, ID_EOLN);
484 
486  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
487 
489  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
490 
492  SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) szText);
493 
494  SendMessage(hCombo, CB_SETCURSEL, Globals.iEoln, 0);
495  break;
496 
497  case WM_NOTIFY:
498  if (((NMHDR *) lParam)->code == CDN_FILEOK)
499  {
500  hCombo = GetDlgItem(hDlg, ID_ENCODING);
501  if (hCombo)
502  Globals.encFile = (ENCODING) SendMessage(hCombo, CB_GETCURSEL, 0, 0);
503 
504  hCombo = GetDlgItem(hDlg, ID_EOLN);
505  if (hCombo)
506  Globals.iEoln = (int) SendMessage(hCombo, CB_GETCURSEL, 0, 0);
507  }
508  break;
509  }
510  return 0;
511 }
#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
HINSTANCE hInstance
Definition: precomp.h:32
#define CB_GETCURSEL
Definition: winuser.h:1925
WPARAM wParam
Definition: combotst.c:138
#define ID_ENCODING
Definition: notepad_res.h:28
static const WCHAR szText[]
Definition: dialog.c:139
#define CB_ADDSTRING
Definition: winuser.h:1918
LONG_PTR LPARAM
Definition: windef.h:208
#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:1943
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
ENCODING
Definition: more.c:155
#define ARRAY_SIZE(a)
Definition: main.h:24
#define msg(x)
Definition: auth_time.c:54
#define STRING_UNICODE
Definition: notepad_res.h:91
#define SendMessage
Definition: winuser.h:5818
HWND WINAPI GetDlgItem(HWND hDlg, int nIDDlgItem)
Definition: dialog.c:2183
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define STRING_CR
Definition: notepad_res.h:97
#define LoadString
Definition: winuser.h:5794
#define WM_NOTIFY
Definition: richedit.h:61
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by DIALOG_FileSaveAs().

◆ DIALOG_GoTo()

VOID DIALOG_GoTo ( VOID  )

Definition at line 1126 of file dialog.c.

1127 {
1128  INT_PTR nLine;
1129  LPTSTR pszText;
1130  int nLength, i;
1131  DWORD dwStart, dwEnd;
1132 
1134  pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(*pszText));
1135  if (!pszText)
1136  return;
1137 
1138  /* Retrieve current text */
1139  GetWindowText(Globals.hEdit, pszText, nLength + 1);
1140  SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwStart, (LPARAM) &dwEnd);
1141 
1142  nLine = 1;
1143  for (i = 0; (i < (int) dwStart) && pszText[i]; i++)
1144  {
1145  if (pszText[i] == '\n')
1146  nLine++;
1147  }
1148 
1151  Globals.hMainWnd,
1153  nLine);
1154 
1155  if (nLine >= 1)
1156  {
1157  for (i = 0; pszText[i] && (nLine > 1) && (i < nLength - 1); i++)
1158  {
1159  if (pszText[i] == '\n')
1160  nLine--;
1161  }
1162  SendMessage(Globals.hEdit, EM_SETSEL, i, i);
1163  SendMessage(Globals.hEdit, EM_SCROLLCARET, 0, 0);
1164  }
1165  HeapFree(GetProcessHeap(), 0, pszText);
1166 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
_In_ DWORD nLength
Definition: wincon.h:461
HINSTANCE hInstance
Definition: precomp.h:32
UINT_PTR WPARAM
Definition: windef.h:207
int32_t INT_PTR
Definition: typedefs.h:62
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5773
#define EM_GETSEL
Definition: winuser.h:1979
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG_PTR LPARAM
Definition: windef.h:208
#define DIALOG_GOTO
Definition: notepad_res.h:30
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define EM_SETSEL
Definition: winuser.h:2000
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DialogBoxParam
Definition: winuser.h:5739
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define SendMessage
Definition: winuser.h:5818
#define GetWindowTextLength
Definition: winuser.h:5774
#define HeapFree(x, y, z)
Definition: compat.h:402
#define EM_SCROLLCARET
Definition: richedit.h:81
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
static INT_PTR CALLBACK DIALOG_GoTo_DialogProc(HWND hwndDialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:1092

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_GoTo_DialogProc()

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

Definition at line 1092 of file dialog.c.

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

Referenced by DIALOG_GoTo().

◆ DIALOG_HelpAboutNotepad()

VOID DIALOG_HelpAboutNotepad ( VOID  )

Definition at line 1194 of file dialog.c.

1195 {
1196  TCHAR szNotepad[MAX_STRING_LEN];
1197  TCHAR szNotepadAuthors[MAX_STRING_LEN];
1198 
1200 
1201  LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, ARRAY_SIZE(szNotepad));
1202  LoadString(Globals.hInstance, STRING_NOTEPAD_AUTHORS, szNotepadAuthors, ARRAY_SIZE(szNotepadAuthors));
1203 
1204  ShellAbout(Globals.hMainWnd, szNotepad, szNotepadAuthors, notepadIcon);
1205  DeleteObject(notepadIcon);
1206 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
static HICON
Definition: imagelist.c:84
HINSTANCE hInstance
Definition: precomp.h:32
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define MAX_STRING_LEN
Definition: precomp.h:36
#define STRING_NOTEPAD_AUTHORS
Definition: notepad_res.h:104
#define STRING_NOTEPAD
Definition: notepad_res.h:74
char TCHAR
Definition: xmlstorage.h:189
#define ShellAbout
Definition: shellapi.h:688
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define ARRAY_SIZE(a)
Definition: main.h:24
#define IDI_NPICON
Definition: notepad_res.h:32
#define LoadIcon
Definition: winuser.h:5788
#define LoadString
Definition: winuser.h:5794

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_HelpContents()

VOID DIALOG_HelpContents ( VOID  )

Definition at line 1189 of file dialog.c.

1190 {
1191  WinHelp(Globals.hMainWnd, helpfile, HELP_INDEX, 0);
1192 }
#define HELP_INDEX
Definition: winuser.h:2385
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
static const TCHAR helpfile[]
Definition: dialog.c:31
#define WinHelp
Definition: winuser.h:5839

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_PAGESETUP_Hook()

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

Definition at line 1239 of file dialog.c.

1240 {
1241  switch (msg)
1242  {
1243  case WM_COMMAND:
1244  if (HIWORD(wParam) == BN_CLICKED)
1245  {
1246  switch (LOWORD(wParam))
1247  {
1248  case IDOK:
1249  /* save user input and close dialog */
1250  GetDlgItemText(hDlg, 0x141, Globals.szHeader, ARRAY_SIZE(Globals.szHeader));
1251  GetDlgItemText(hDlg, 0x143, Globals.szFooter, ARRAY_SIZE(Globals.szFooter));
1252  return FALSE;
1253 
1254  case IDCANCEL:
1255  /* discard user input and close dialog */
1256  return FALSE;
1257 
1258  case IDHELP:
1259  {
1260  /* FIXME: Bring this to work */
1261  static const TCHAR sorry[] = _T("Sorry, no help available");
1262  static const TCHAR help[] = _T("Help");
1263  MessageBox(Globals.hMainWnd, sorry, help, MB_ICONEXCLAMATION);
1264  return TRUE;
1265  }
1266 
1267  default:
1268  break;
1269  }
1270  }
1271  break;
1272 
1273  case WM_INITDIALOG:
1274  /* fetch last user input prior to display dialog */
1275  SetDlgItemText(hDlg, 0x141, Globals.szHeader);
1276  SetDlgItemText(hDlg, 0x143, Globals.szFooter);
1277  break;
1278  }
1279 
1280  return FALSE;
1281 }
#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
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define GetDlgItemText
Definition: winuser.h:5760
#define BN_CLICKED
Definition: winuser.h:1907
#define SetDlgItemText
Definition: winuser.h:5824
#define MessageBox
Definition: winuser.h:5797
#define WM_COMMAND
Definition: winuser.h:1722
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define ARRAY_SIZE(a)
Definition: main.h:24
#define msg(x)
Definition: auth_time.c:54
#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:1721
#define LOWORD(l)
Definition: pedump.c:82

Referenced by DIALOG_FilePageSetup().

◆ DIALOG_Replace()

VOID DIALOG_Replace ( VOID  )

Definition at line 1085 of file dialog.c.

1086 {
1088 }
#define ReplaceText
Definition: commdlg.h:669
static VOID DIALOG_SearchDialog(FINDPROC pfnProc)
Definition: dialog.c:1047

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_Search()

VOID DIALOG_Search ( VOID  )

Definition at line 1072 of file dialog.c.

1073 {
1075 }
static VOID DIALOG_SearchDialog(FINDPROC pfnProc)
Definition: dialog.c:1047
#define FindText
Definition: commdlg.h:663

Referenced by DIALOG_SearchNext(), and NOTEPAD_MenuCommand().

◆ DIALOG_SearchDialog()

static VOID DIALOG_SearchDialog ( FINDPROC  pfnProc)
static

Definition at line 1047 of file dialog.c.

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

Referenced by DIALOG_Replace(), and DIALOG_Search().

◆ DIALOG_SearchNext()

VOID DIALOG_SearchNext ( VOID  )

Definition at line 1077 of file dialog.c.

1078 {
1079  if (Globals.find.lpstrFindWhat != NULL)
1081  else
1082  DIALOG_Search();
1083 }
VOID DIALOG_Search(VOID)
Definition: dialog.c:1072
#define TRUE
Definition: types.h:120
BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert)
Definition: main.c:138
smooth NULL
Definition: ftsmooth.c:416
UTILMAN_GLOBALS Globals
Definition: dialog.c:15

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_SelectFont()

VOID DIALOG_SelectFont ( VOID  )

Definition at line 1022 of file dialog.c.

1023 {
1024  CHOOSEFONT cf;
1025  LOGFONT lf = Globals.lfFont;
1026 
1027  ZeroMemory( &cf, sizeof(cf) );
1028  cf.lStructSize = sizeof(cf);
1029  cf.hwndOwner = Globals.hMainWnd;
1030  cf.lpLogFont = &lf;
1032 
1033  if (ChooseFont(&cf))
1034  {
1035  HFONT currfont = Globals.hFont;
1036 
1037  Globals.hFont = CreateFontIndirect(&lf);
1038  Globals.lfFont = lf;
1040  if (currfont != NULL)
1041  DeleteObject(currfont);
1042  }
1043 }
static IClassFactory * cf
#define TRUE
Definition: types.h:120
#define ZeroMemory
Definition: winbase.h:1642
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
UINT_PTR WPARAM
Definition: windef.h:207
#define ChooseFont
Definition: commdlg.h:662
#define CF_SCREENFONTS
Definition: commdlg.h:59
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define CreateFontIndirect
Definition: wingdi.h:4443
#define WM_SETFONT
Definition: winuser.h:1632
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define SendMessage
Definition: winuser.h:5818
#define CF_NOVERTFONTS
Definition: commdlg.h:86
#define CF_INITTOLOGFONTSTRUCT
Definition: commdlg.h:66

Referenced by NOTEPAD_MenuCommand().

◆ DIALOG_StatusBarUpdateCaretPos()

VOID DIALOG_StatusBarUpdateCaretPos ( VOID  )

Definition at line 1168 of file dialog.c.

1169 {
1170  int line, col;
1171  TCHAR buff[MAX_PATH];
1172  DWORD dwStart, dwSize;
1173 
1174  SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwSize);
1175  line = SendMessage(Globals.hEdit, EM_LINEFROMCHAR, (WPARAM)dwStart, 0);
1176  col = dwStart - SendMessage(Globals.hEdit, EM_LINEINDEX, (WPARAM)line, 0);
1177 
1178  _stprintf(buff, Globals.szStatusBarLineCol, line + 1, col + 1);
1180 }
UINT_PTR WPARAM
Definition: windef.h:207
#define EM_GETSEL
Definition: winuser.h:1979
#define SB_SIMPLEID
Definition: precomp.h:15
LONG_PTR LPARAM
Definition: windef.h:208
Definition: parser.c:48
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:1945
#define _stprintf
Definition: utility.h:124
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define EM_LINEFROMCHAR
Definition: winuser.h:1983
#define SendMessage
Definition: winuser.h:5818
#define EM_LINEINDEX
Definition: winuser.h:1984
static unsigned char buff[32768]
Definition: fatten.c:17
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

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

◆ DIALOG_StringMsgBox()

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

Definition at line 101 of file dialog.c.

102 {
103  TCHAR szMessage[MAX_STRING_LEN];
104  TCHAR szResource[MAX_STRING_LEN];
105 
106  /* Load and format szMessage */
107  LoadString(Globals.hInstance, formatId, szResource, ARRAY_SIZE(szResource));
108  _sntprintf(szMessage, ARRAY_SIZE(szMessage), szResource, szString);
109 
110  /* Load szCaption */
112  LoadString(Globals.hInstance, STRING_ERROR, szResource, ARRAY_SIZE(szResource));
113  else
114  LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, ARRAY_SIZE(szResource));
115 
116  /* Display Modal Dialog */
117  // if (hParent == NULL)
118  // hParent = Globals.hMainWnd;
119  return MessageBox(hParent, szMessage, szResource, dwFlags);
120 }
#define MB_ICONMASK
Definition: winuser.h:813
HINSTANCE hInstance
Definition: precomp.h:32
#define MAX_STRING_LEN
Definition: precomp.h:36
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
#define STRING_NOTEPAD
Definition: notepad_res.h:74
char TCHAR
Definition: xmlstorage.h:189
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
#define _sntprintf
Definition: xmlstorage.h:201
#define MessageBox
Definition: winuser.h:5797
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define ARRAY_SIZE(a)
Definition: main.h:24
#define STRING_ERROR
Definition: notepad_res.h:75
#define LoadString
Definition: winuser.h:5794

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

◆ DIALOG_ViewStatusBar()

VOID DIALOG_ViewStatusBar ( VOID  )

Definition at line 1182 of file dialog.c.

1183 {
1184  Globals.bShowStatusBar = !Globals.bShowStatusBar;
1185 
1187 }
VOID DoCreateStatusBar(VOID)
Definition: dialog.c:826
UTILMAN_GLOBALS Globals
Definition: dialog.c:15

Referenced by _tWinMain(), and NOTEPAD_MenuCommand().

◆ 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 316 of file dialog.c.

317 {
318  int nResult;
319 
320  if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
321  {
322  /* prompt user to save changes */
323  nResult = AlertFileNotSaved(Globals.szFileName);
324  switch (nResult)
325  {
326  case IDYES:
327  if(!DIALOG_FileSave())
328  return FALSE;
329  break;
330 
331  case IDNO:
332  break;
333 
334  case IDCANCEL:
335  return FALSE;
336 
337  default:
338  return FALSE;
339  }
340  }
341 
344 
345  return TRUE;
346 }
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
static VOID SetFileName(PCONSOLE_CHILDFRM_WND Info, PWSTR pFileName)
Definition: console.c:179
#define EM_GETMODIFY
Definition: winuser.h:1976
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define SendMessage
Definition: winuser.h:5818
#define IDNO
Definition: winuser.h:830
#define IDCANCEL
Definition: winuser.h:825
static int AlertFileNotSaved(LPCTSTR szFileName)
Definition: dialog.c:127
BOOL DIALOG_FileSave(VOID)
Definition: dialog.c:441

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

◆ DoCreateEditWindow()

VOID DoCreateEditWindow ( VOID  )

Definition at line 904 of file dialog.c.

905 {
906  DWORD dwStyle;
907  int iSize;
908  LPTSTR pTemp = NULL;
909  BOOL bModified = FALSE;
910 
911  iSize = 0;
912 
913  /* If the edit control already exists, try to save its content */
914  if (Globals.hEdit != NULL)
915  {
916  /* number of chars currently written into the editor. */
917  iSize = GetWindowTextLength(Globals.hEdit);
918  if (iSize)
919  {
920  /* Allocates temporary buffer. */
921  pTemp = HeapAlloc(GetProcessHeap(), 0, (iSize + 1) * sizeof(TCHAR));
922  if (!pTemp)
923  {
924  ShowLastError();
925  return;
926  }
927 
928  /* Recover the text into the control. */
929  GetWindowText(Globals.hEdit, pTemp, iSize + 1);
930 
931  if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
932  bModified = TRUE;
933  }
934 
935  /* Restore original window procedure */
937 
938  /* Destroy the edit control */
939  DestroyWindow(Globals.hEdit);
940  }
941 
942  /* Update wrap status into the main menu and recover style flags */
943  if (Globals.bWrapLongLines)
944  {
945  dwStyle = EDIT_STYLE_WRAP;
947  } else {
948  dwStyle = EDIT_STYLE;
950  }
951 
952  /* Update previous changes */
953  DrawMenuBar(Globals.hMainWnd);
954 
955  /* Create the new edit control */
957  EDIT_CLASS,
958  NULL,
959  dwStyle,
964  Globals.hMainWnd,
965  NULL,
967  NULL);
968 
969  if (Globals.hEdit == NULL)
970  {
971  if (pTemp)
972  {
973  HeapFree(GetProcessHeap(), 0, pTemp);
974  }
975 
976  ShowLastError();
977  return;
978  }
979 
981  SendMessage(Globals.hEdit, EM_LIMITTEXT, 0, 0);
982 
983  /* If some text was previously saved, restore it. */
984  if (iSize != 0)
985  {
986  SetWindowText(Globals.hEdit, pTemp);
987  HeapFree(GetProcessHeap(), 0, pTemp);
988 
989  if (bModified)
990  SendMessage(Globals.hEdit, EM_SETMODIFY, TRUE, 0);
991  }
992 
993  /* Sub-class a new window callback for row/column detection. */
994  Globals.EditProc = (WNDPROC)SetWindowLongPtr(Globals.hEdit,
995  GWLP_WNDPROC,
997 
998  /* Create/update status bar */
1000 
1001  /* Finally shows new edit control and set focus into it. */
1002  ShowWindow(Globals.hEdit, SW_SHOW);
1003  SetFocus(Globals.hEdit);
1004 }
#define EM_LIMITTEXT
Definition: winuser.h:1982
#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
HINSTANCE hInstance
Definition: precomp.h:32
HWND WINAPI SetFocus(_In_opt_ HWND)
UINT_PTR WPARAM
Definition: windef.h:207
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:5773
#define CMD_STATUSBAR
Definition: notepad_res.h:60
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CreateWindowEx
Definition: winuser.h:5730
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
VOID DoCreateStatusBar(VOID)
Definition: dialog.c:826
#define SW_SHOW
Definition: winuser.h:769
char TCHAR
Definition: xmlstorage.h:189
VOID ShowLastError(VOID)
Definition: dialog.c:38
#define GetProcessHeap()
Definition: compat.h:403
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:1976
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EM_SETMODIFY
Definition: winuser.h:1995
#define GWLP_WNDPROC
Definition: treelist.c:66
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2881
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
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:5832
#define WM_SETFONT
Definition: winuser.h:1632
#define SendMessage
Definition: winuser.h:5818
#define EDIT_STYLE_WRAP
Definition: main.h:28
#define EDIT_STYLE
Definition: main.h:30
#define GetWindowTextLength
Definition: winuser.h:5774
#define MF_GRAYED
Definition: winuser.h:129
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by _tWinMain(), and DIALOG_EditWrap().

◆ DoCreateStatusBar()

VOID DoCreateStatusBar ( VOID  )

Definition at line 826 of file dialog.c.

827 {
828  RECT rc;
829  RECT rcstatus;
830  BOOL bStatusBarVisible;
831 
832  /* Check if status bar object already exists. */
833  if (Globals.hStatusBar == NULL)
834  {
835  /* Try to create the status bar */
837  NULL,
838  Globals.hMainWnd,
840 
841  if (Globals.hStatusBar == NULL)
842  {
843  ShowLastError();
844  return;
845  }
846 
847  /* Load the string for formatting column/row text output */
848  LoadString(Globals.hInstance, STRING_LINE_COLUMN, Globals.szStatusBarLineCol, MAX_PATH - 1);
849 
850  /* Set the status bar for single-text output */
851  SendMessage(Globals.hStatusBar, SB_SIMPLE, (WPARAM)TRUE, (LPARAM)0);
852  }
853 
854  /* Set status bar visiblity according to the settings. */
855  if ((Globals.bWrapLongLines != FALSE) || (Globals.bShowStatusBar == FALSE))
856  {
857  bStatusBarVisible = FALSE;
858  ShowWindow(Globals.hStatusBar, SW_HIDE);
859  }
860  else
861  {
862  bStatusBarVisible = TRUE;
863  ShowWindow(Globals.hStatusBar, SW_SHOW);
864  SendMessage(Globals.hStatusBar, WM_SIZE, 0, 0);
865  }
866 
867  /* Set check state in show status bar item. */
868  if (bStatusBarVisible)
869  {
871  }
872  else
873  {
875  }
876 
877  /* Update menu mar with the previous changes */
878  DrawMenuBar(Globals.hMainWnd);
879 
880  /* Sefety test is edit control exists */
881  if (Globals.hEdit != NULL)
882  {
883  /* Retrieve the sizes of the controls */
884  GetClientRect(Globals.hMainWnd, &rc);
885  GetClientRect(Globals.hStatusBar, &rcstatus);
886 
887  /* If status bar is currently visible, update dimensions of edit control */
888  if (bStatusBarVisible)
889  rc.bottom -= (rcstatus.bottom - rcstatus.top);
890 
891  /* Resize edit control to right size. */
892  MoveWindow(Globals.hEdit,
893  rc.left,
894  rc.top,
895  rc.right - rc.left,
896  rc.bottom - rc.top,
897  TRUE);
898  }
899 
900  /* Update content with current row/column text */
902 }
#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:307
HINSTANCE hInstance
Definition: precomp.h:32
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
LONG left
Definition: windef.h:306
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
LONG right
Definition: windef.h:308
#define CMD_STATUSBAR
Definition: notepad_res.h:60
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CreateStatusWindow
Definition: commctrl.h:1929
#define SB_SIMPLE
Definition: commctrl.h:1954
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define SW_SHOW
Definition: winuser.h:769
#define MF_CHECKED
Definition: winuser.h:132
VOID ShowLastError(VOID)
Definition: dialog.c:38
#define WM_SIZE
Definition: winuser.h:1593
#define MAX_PATH
Definition: compat.h:26
VOID DIALOG_StatusBarUpdateCaretPos(VOID)
Definition: dialog.c:1168
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)
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define SendMessage
Definition: winuser.h:5818
LONG bottom
Definition: windef.h:309
#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:5794

Referenced by DIALOG_ViewStatusBar(), and DoCreateEditWindow().

◆ DoOpenFile()

VOID DoOpenFile ( LPCTSTR  szFileName)

Definition at line 348 of file dialog.c.

349 {
350  static const TCHAR dotlog[] = _T(".LOG");
351  HANDLE hFile;
352  LPTSTR pszText = NULL;
353  DWORD dwTextLen;
354  TCHAR log[5];
355 
356  /* Close any files and prompt to save changes */
357  if (!DoCloseFile())
358  return;
359 
363  {
364  ShowLastError();
365  goto done;
366  }
367 
368  if (!ReadText(hFile, (LPWSTR *)&pszText, &dwTextLen, &Globals.encFile, &Globals.iEoln))
369  {
370  ShowLastError();
371  goto done;
372  }
373  SetWindowText(Globals.hEdit, pszText);
374 
376  SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
377  SetFocus(Globals.hEdit);
378 
379  /* If the file starts with .LOG, add a time/date at the end and set cursor after
380  * See http://support.microsoft.com/?kbid=260563
381  */
382  if (GetWindowText(Globals.hEdit, log, ARRAY_SIZE(log)) && !_tcscmp(log, dotlog))
383  {
384  static const TCHAR lf[] = _T("\r\n");
389  }
390 
391  SetFileName(szFileName);
394 done:
397  if (pszText)
398  HeapFree(GetProcessHeap(), 0, pszText);
399 }
void UpdateWindowCaption(BOOL clearModifyAlert)
Definition: dialog.c:66
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
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:5773
BOOL ReadText(HANDLE hFile, LPWSTR *ppszText, DWORD *pdwTextLen, ENCODING *pencFile, int *piEoln)
Definition: text.c:96
BOOL DoCloseFile(VOID)
Definition: dialog.c:316
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
static VOID SetFileName(PCONSOLE_CHILDFRM_WND Info, PWSTR pFileName)
Definition: console.c:179
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:403
#define EM_SETSEL
Definition: winuser.h:2000
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:1967
#define GENERIC_READ
Definition: compat.h:124
#define EM_SETMODIFY
Definition: winuser.h:1995
_In_ HANDLE hFile
Definition: mswsock.h:90
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
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:5832
VOID NOTEPAD_EnableSearchMenu()
Definition: main.c:32
#define SendMessage
Definition: winuser.h:5818
#define GetWindowTextLength
Definition: winuser.h:5774
WCHAR * LPWSTR
Definition: xmlstorage.h:184
VOID DIALOG_EditTimeDate(VOID)
Definition: dialog.c:810
#define HeapFree(x, y, z)
Definition: compat.h:402
#define log(outFile, fmt,...)
Definition: util.h:15
#define EM_REPLACESEL
Definition: winuser.h:1988

Referenced by DIALOG_FileOpen().

◆ DoSaveFile()

static BOOL DoSaveFile ( VOID  )
static

Definition at line 267 of file dialog.c.

268 {
269  BOOL bRet = TRUE;
270  HANDLE hFile;
271  LPTSTR pTemp;
272  DWORD size;
273 
277  {
278  ShowLastError();
279  return FALSE;
280  }
281 
282  size = GetWindowTextLength(Globals.hEdit) + 1;
283  pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*pTemp));
284  if (!pTemp)
285  {
287  ShowLastError();
288  return FALSE;
289  }
290  size = GetWindowText(Globals.hEdit, pTemp, size);
291 
292  if (size)
293  {
294  if (!WriteText(hFile, (LPWSTR)pTemp, size, Globals.encFile, Globals.iEoln))
295  {
296  ShowLastError();
297  bRet = FALSE;
298  }
299  else
300  {
302  bRet = TRUE;
303  }
304  }
305 
307  HeapFree(GetProcessHeap(), 0, pTemp);
308  return bRet;
309 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, ENCODING encFile, int iEoln)
Definition: text.c:368
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5773
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
VOID ShowLastError(VOID)
Definition: dialog.c:38
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:403
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:1995
_In_ HANDLE hFile
Definition: mswsock.h:90
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#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:5818
#define GetWindowTextLength
Definition: winuser.h:5774
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by DIALOG_FileSave(), and DIALOG_FileSaveAs().

◆ EDIT_WndProc()

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

Definition at line 304 of file main.c.

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  }
333 }
#define CallWindowProc
Definition: winuser.h:5710
NOTEPAD_GLOBALS Globals
Definition: main.c:29
HWND hWnd
Definition: settings.c:17
#define VK_LEFT
Definition: winuser.h:2199
#define VK_DOWN
Definition: winuser.h:2202
WNDPROC EditProc
Definition: main.h:81
WPARAM wParam
Definition: combotst.c:138
#define VK_UP
Definition: winuser.h:2200
#define WM_KEYDOWN
Definition: winuser.h:1697
VOID DIALOG_StatusBarUpdateCaretPos(VOID)
Definition: dialog.c:1168
#define WM_KEYUP
Definition: winuser.h:1698
#define VK_RIGHT
Definition: winuser.h:2201
#define WM_LBUTTONUP
Definition: winuser.h:1759
#define msg(x)
Definition: auth_time.c:54
LPARAM lParam
Definition: combotst.c:139
void UpdateWindowCaption(HWND hwnd)
Definition: mplay32.c:102

Referenced by DoCreateEditWindow().

◆ FileExists()

BOOL FileExists ( LPCTSTR  szFilename)

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

Definition at line 154 of file dialog.c.

155 {
157  HANDLE hFile;
158 
159  hFile = FindFirstFile(szFilename, &entry);
160  FindClose(hFile);
161 
162  return (hFile != INVALID_HANDLE_VALUE);
163 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define FindFirstFile
Definition: winbase.h:3616
uint32_t entry
Definition: isohybrid.c:63
_In_ HANDLE hFile
Definition: mswsock.h:90
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by DIALOG_FileOpen(), and HandleCommandLine().

◆ GetPrintingRect()

static RECT GetPrintingRect ( HDC  hdc,
RECT  margins 
)
static

Definition at line 243 of file dialog.c.

244 {
245  int iLogPixelsX, iLogPixelsY;
246  int iHorzRes, iVertRes;
247  int iPhysPageX, iPhysPageY, iPhysPageW, iPhysPageH;
248  RECT rcPrintRect;
249 
250  iPhysPageX = GetDeviceCaps(hdc, PHYSICALOFFSETX);
251  iPhysPageY = GetDeviceCaps(hdc, PHYSICALOFFSETY);
252  iPhysPageW = GetDeviceCaps(hdc, PHYSICALWIDTH);
253  iPhysPageH = GetDeviceCaps(hdc, PHYSICALHEIGHT);
254  iLogPixelsX = GetDeviceCaps(hdc, LOGPIXELSX);
255  iLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY);
256  iHorzRes = GetDeviceCaps(hdc, HORZRES);
257  iVertRes = GetDeviceCaps(hdc, VERTRES);
258 
259  rcPrintRect.left = (margins.left * iLogPixelsX / 2540) - iPhysPageX;
260  rcPrintRect.top = (margins.top * iLogPixelsY / 2540) - iPhysPageY;
261  rcPrintRect.right = iHorzRes - (((margins.left * iLogPixelsX / 2540) - iPhysPageX) + ((margins.right * iLogPixelsX / 2540) - (iPhysPageW - iPhysPageX - iHorzRes)));
262  rcPrintRect.bottom = iVertRes - (((margins.top * iLogPixelsY / 2540) - iPhysPageY) + ((margins.bottom * iLogPixelsY / 2540) - (iPhysPageH - iPhysPageY - iVertRes)));
263 
264  return rcPrintRect;
265 }
#define HORZRES
Definition: wingdi.h:715
#define LOGPIXELSX
Definition: wingdi.h:717
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
LONG right
Definition: windef.h:308
#define PHYSICALHEIGHT
Definition: wingdi.h:735
#define PHYSICALOFFSETY
Definition: wingdi.h:737
HDC hdc
Definition: main.c:9
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
static RECT margins
Definition: print.c:55
#define PHYSICALOFFSETX
Definition: wingdi.h:736
#define PHYSICALWIDTH
Definition: wingdi.h:734
#define VERTRES
Definition: wingdi.h:716
LONG bottom
Definition: windef.h:309
#define LOGPIXELSY
Definition: wingdi.h:718

Referenced by DIALOG_FilePrint().

◆ GetSelectionText()

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

Definition at line 185 of file dialog.c.

186 {
187  DWORD dwStart = 0;
188  DWORD dwEnd = 0;
189  DWORD dwSize;
190  HRESULT hResult;
191  LPTSTR lpTemp;
192 
193  if (!lpString)
194  {
195  return 0;
196  }
197 
198  SendMessage(hWnd, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
199 
200  if (dwStart == dwEnd)
201  {
202  return 0;
203  }
204 
206  lpTemp = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(TCHAR));
207  if (!lpTemp)
208  {
209  return 0;
210  }
211 
212  dwSize = GetWindowText(hWnd, lpTemp, dwSize);
213 
214  if (!dwSize)
215  {
216  HeapFree(GetProcessHeap(), 0, lpTemp);
217  return 0;
218  }
219 
220  hResult = StringCchCopyN(lpString, nMaxCount, lpTemp + dwStart, dwEnd - dwStart);
221  HeapFree(GetProcessHeap(), 0, lpTemp);
222 
223  switch (hResult)
224  {
225  case S_OK:
226  {
227  return dwEnd - dwStart;
228  }
229 
231  {
232  return nMaxCount - 1;
233  }
234 
235  default:
236  {
237  return 0;
238  }
239  }
240 }
HWND hWnd
Definition: settings.c:17
#define StringCchCopyN
Definition: strsafe.h:227
UINT_PTR WPARAM
Definition: windef.h:207
#define STRSAFE_E_INSUFFICIENT_BUFFER
Definition: strsafe.h:103
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5773
#define EM_GETSEL
Definition: winuser.h:1979
LONG_PTR LPARAM
Definition: windef.h:208
char TCHAR
Definition: xmlstorage.h:189
#define GetProcessHeap()
Definition: compat.h:403
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:5818
#define GetWindowTextLength
Definition: winuser.h:5774
_In_ int nMaxCount
Definition: winuser.h:4852
#define HeapFree(x, y, z)
Definition: compat.h:402
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by DIALOG_FilePrint().

◆ GetSelectionTextLength()

int GetSelectionTextLength ( HWND  hWnd)

Definition at line 175 of file dialog.c.

176 {
177  DWORD dwStart = 0;
178  DWORD dwEnd = 0;
179 
180  SendMessage(hWnd, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
181 
182  return dwEnd - dwStart;
183 }
HWND hWnd
Definition: settings.c:17
UINT_PTR WPARAM
Definition: windef.h:207
#define EM_GETSEL
Definition: winuser.h:1979
LONG_PTR LPARAM
Definition: windef.h:208
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SendMessage
Definition: winuser.h:5818

Referenced by DIALOG_FilePrint().

◆ HasFileExtension()

BOOL HasFileExtension ( LPCTSTR  szFilename)

Definition at line 165 of file dialog.c.

166 {
167  LPCTSTR s;
168 
169  s = _tcsrchr(szFilename, _T('\\'));
170  if (s)
171  szFilename = s;
172  return _tcsrchr(szFilename, _T('.')) != NULL;
173 }
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

Referenced by HandleCommandLine().

◆ ShowLastError()

VOID ShowLastError ( VOID  )

Definition at line 38 of file dialog.c.

39 {
41  if (error != NO_ERROR)
42  {
43  LPTSTR lpMsgBuf = NULL;
45 
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
HINSTANCE hInstance
Definition: precomp.h:32
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
#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:35
#define FormatMessage
Definition: winbase.h:3629
#define MB_ICONERROR
Definition: winuser.h:781
#define MessageBox
Definition: winuser.h:5797
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#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
#define LoadString
Definition: winuser.h:5794

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

◆ 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.

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  {
85  StringCbPrintf(szCaption, sizeof(szCaption), _T("%s - %s"),
86  szFilename, szNotepad);
87  }
88  else
89  {
90  BOOL isModified = (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0) ? TRUE : FALSE);
91 
92  /* Update the caption based upon if the user has modified the contents of the file or not */
93  StringCbPrintf(szCaption, sizeof(szCaption), _T("%s%s - %s"),
94  (isModified ? _T("*") : _T("")), szFilename, szNotepad);
95  }
96 
97  /* Update the window caption */
98  SetWindowText(Globals.hMainWnd, szCaption);
99 }
#define TRUE
Definition: types.h:120
HINSTANCE hInstance
Definition: precomp.h:32
#define MAX_STRING_LEN
Definition: precomp.h:36
#define STRING_NOTEPAD
Definition: notepad_res.h:74
unsigned int BOOL
Definition: ntddk_ex.h:94
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define STRING_UNTITLED
Definition: notepad_res.h:78
#define StringCbPrintf
Definition: strsafe.h:544
#define EM_GETMODIFY
Definition: winuser.h:1976
#define StringCchCopy
Definition: strsafe.h:139
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
#define ARRAY_SIZE(a)
Definition: main.h:24
#define SetWindowText
Definition: winuser.h:5832
#define SendMessage
Definition: winuser.h:5818
#define LoadString
Definition: winuser.h:5794

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

Variable Documentation

◆ empty_str

◆ helpfile

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

◆ 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().