4 * Copyright 1997,98 Marcel Baur <mbaur@g26.ethz.ch>
5 * To be distributed under the Wine License
20 extern BOOL
DoCloseFile(void);
21 extern void DoOpenFile(LPCSTR szFileName
);
23 NOTEPAD_GLOBALS Globals
;
25 /***********************************************************************
29 * All handling of main menu events
32 int NOTEPAD_MenuCommand (WPARAM wParam
)
35 case NP_FILE_NEW
: DIALOG_FileNew(); break;
36 case NP_FILE_OPEN
: DIALOG_FileOpen(); break;
37 case NP_FILE_SAVE
: DIALOG_FileSave(); break;
38 case NP_FILE_SAVEAS
: DIALOG_FileSaveAs(); break;
39 case NP_FILE_PRINT
: DIALOG_FilePrint(); break;
40 case NP_FILE_PAGESETUP
: DIALOG_FilePageSetup(); break;
41 case NP_FILE_PRINTSETUP
: DIALOG_FilePrinterSetup();break;
42 case NP_FILE_EXIT
: DIALOG_FileExit(); break;
44 case NP_EDIT_UNDO
: DIALOG_EditUndo(); break;
45 case NP_EDIT_CUT
: DIALOG_EditCut(); break;
46 case NP_EDIT_COPY
: DIALOG_EditCopy(); break;
47 case NP_EDIT_PASTE
: DIALOG_EditPaste(); break;
48 case NP_EDIT_DELETE
: DIALOG_EditDelete(); break;
49 case NP_EDIT_SELECTALL
: DIALOG_EditSelectAll(); break;
50 case NP_EDIT_TIMEDATE
: DIALOG_EditTimeDate();break;
51 case NP_EDIT_WRAP
: DIALOG_EditWrap(); break;
53 case NP_SEARCH_SEARCH
: DIALOG_Search(); break;
54 case NP_SEARCH_NEXT
: DIALOG_SearchNext(); break;
56 case NP_HELP_CONTENTS
: DIALOG_HelpContents(); break;
57 case NP_HELP_SEARCH
: DIALOG_HelpSearch(); break;
58 case NP_HELP_ON_HELP
: DIALOG_HelpHelp(); break;
59 case NP_HELP_LICENSE
: DIALOG_HelpLicense(); break;
60 case NP_HELP_NO_WARRANTY
: DIALOG_HelpNoWarranty(); break;
61 case NP_HELP_ABOUT_WINE
: DIALOG_HelpAboutWine(); break;
63 /* Handle languages */
65 LANGUAGE_DefaultHandle(wParam
);
72 /***********************************************************************
77 LRESULT
NOTEPAD_WndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
81 HANDLE hDrop
; /* drag & drop */
82 CHAR szFileName
[MAX_STRING_LEN
];
85 lstrcpy(szFileName
, "");
93 hContext
= BeginPaint(hWnd
, &ps
);
94 TextOut(hContext
, 1, 1, Globals
.Buffer
, strlen(Globals
.Buffer
));
99 NOTEPAD_MenuCommand(wParam
);
102 case WM_DESTROYCLIPBOARD
:
103 MessageBox(Globals
.hMainWnd
, "Empty clipboard", "Debug", MB_ICONEXCLAMATION
);
117 GetClientRect(Globals
.hMainWnd
, &Windowsize
);
121 /* User has dropped a file into main window */
122 hDrop
= (HANDLE
) wParam
;
123 DragQueryFile(hDrop
, 0, (CHAR
*) &szFileName
, sizeof(szFileName
));
125 DoOpenFile(szFileName
);
129 return DefWindowProc (hWnd
, msg
, wParam
, lParam
);
136 /***********************************************************************
141 int PASCAL
WinMain (HANDLE hInstance
, HANDLE prev
, LPSTR cmdline
, int show
)
145 char className
[] = "NPClass"; /* To make sure className >= 0x10000 */
146 char winName
[] = "Notepad";
148 /* Select Language */
154 Globals
.lpszIniFile
= "notepad.ini";
155 Globals
.lpszIcoFile
= "notepad.ico";
157 Globals
.hInstance
= hInstance
;
160 Globals
.hMainIcon
= ExtractIcon(Globals
.hInstance
,
161 Globals
.lpszIcoFile
, 0);
163 if (!Globals
.hMainIcon
) {
164 Globals
.hMainIcon
= LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON
));
167 lstrcpy(Globals
.szFindText
, "");
168 lstrcpy(Globals
.szFileName
, "");
169 lstrcpy(Globals
.szMarginTop
, "25 mm");
170 lstrcpy(Globals
.szMarginBottom
, "25 mm");
171 lstrcpy(Globals
.szMarginLeft
, "20 mm");
172 lstrcpy(Globals
.szMarginRight
, "20 mm");
173 lstrcpy(Globals
.szHeader
, "&n");
174 lstrcpy(Globals
.szFooter
, "Page &s");
175 lstrcpy(Globals
.Buffer
, "Hello World");
178 class.style
= CS_HREDRAW
| CS_VREDRAW
;
179 class.lpfnWndProc
= NOTEPAD_WndProc
;
180 class.cbClsExtra
= 0;
181 class.cbWndExtra
= 0;
182 class.hInstance
= Globals
.hInstance
;
183 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
184 class.hCursor
= LoadCursor (0, IDC_ARROW
);
185 class.hbrBackground
= GetStockObject (WHITE_BRUSH
);
186 class.lpszMenuName
= 0;
187 class.lpszClassName
= className
;
190 if (!RegisterClass (&class)) return FALSE
;
195 Globals
.hMainWnd
= CreateWindow (className
, winName
,
196 WS_OVERLAPPEDWINDOW
+ WS_HSCROLL
+ WS_VSCROLL
,
197 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0, 0,
198 LoadMenu(Globals
.hInstance
, STRING_MENU_Xx
),
199 Globals
.hInstance
, 0);
201 Globals
.hFindReplaceDlg
= 0;
203 LANGUAGE_SelectByName(Globals
.lpszLanguage
);
205 SetMenu(Globals
.hMainWnd
, Globals
.hMainMenu
);
207 ShowWindow (Globals
.hMainWnd
, show
);
208 UpdateWindow (Globals
.hMainWnd
);
212 /* Identify Messages originating from FindReplace */
214 Globals
.nCommdlgFindReplaceMsg
= RegisterWindowMessage("commdlg_FindReplace");
215 if (Globals
.nCommdlgFindReplaceMsg
==0) {
216 MessageBox(Globals
.hMainWnd
, "Could not register commdlg_FindReplace window message",
217 "Error", MB_ICONEXCLAMATION
);
220 /* now handle command line */
222 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
226 /* LPCSTR topic_id; */
228 if (*cmdline
++ == ' ') continue;
231 if (option
) cmdline
++;
232 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
237 case 'P': printf("Print file: ");
238 /* Not yet able to print a file */
243 /* Set up Drag&Drop */
245 DragAcceptFiles(Globals
.hMainWnd
, TRUE
);
247 MessageBox(Globals
.hMainWnd
, "BEWARE!\nThis is ALPHA software that may destroy your file system.\nPlease take care.",
248 "A note from the developer...", MB_ICONEXCLAMATION
);
250 /* now enter mesage loop */
252 while (GetMessage (&msg
, 0, 0, 0)) {
253 if (IsDialogMessage(Globals
.hFindReplaceDlg
, &msg
)!=0) {
254 /* Message belongs to FindReplace dialog */
255 /* We just let IsDialogMessage handle it */
259 /* Message belongs to the Notepad Main Window */
260 TranslateMessage (&msg
);
261 DispatchMessage (&msg
);