4 * Copyright 1997 Marcel Baur <mbaur@g26.ethz.ch>
16 void LIBWINE_Register_De();
17 void LIBWINE_Register_En();
18 void LIBWINE_Register_Sw();
21 NOTEPAD_GLOBALS Globals;
23 CHAR STRING_MENU_Xx[] = "MENU_Xx";
24 CHAR STRING_PAGESETUP_Xx[] = "DIALOG_PAGESETUP_Xx";
26 static BOOL MAIN_LoadStringOtherLanguage(UINT num, UINT ids, LPSTR str, UINT len)
28 ids -= Globals.wStringTableOffset;
30 return(LoadString(Globals.hInstance, ids, str, len));
33 VOID MAIN_SelectLanguageByName(LPCSTR lang)
38 for (i = 0; i <= MAX_LANGUAGE_NUMBER; i++)
39 if (MAIN_LoadStringOtherLanguage(i, IDS_LANGUAGE_ID, newlang, sizeof(newlang)) &&
40 !lstrcmp(lang, newlang))
42 MAIN_SelectLanguageByNumber(i);
47 for (i = 0; i <= MAX_LANGUAGE_NUMBER; i++)
48 if (MAIN_LoadStringOtherLanguage(i, IDS_LANGUAGE_ID, newlang, sizeof(newlang)))
50 MAIN_SelectLanguageByNumber(i);
54 MessageBox(Globals.hMainWnd, "No language found", "FATAL ERROR", MB_OK);
58 VOID MAIN_SelectLanguageByNumber(UINT num)
62 CHAR caption[MAX_STRING_LEN];
63 CHAR item[MAX_STRING_LEN];
66 /* Select string table */
67 Globals.wStringTableOffset = num * 0x100;
70 LoadString(Globals.hInstance, IDS_LANGUAGE_ID, lang, sizeof(lang));
71 Globals.lpszLanguage = lang;
73 /* Set frame caption */
74 LoadString(Globals.hInstance, IDS_NOTEPAD, caption, sizeof(caption));
75 SetWindowText(Globals.hMainWnd, caption);
77 /* Change Resource names */
78 lstrcpyn(STRING_MENU_Xx + sizeof(STRING_MENU_Xx) - 3, lang, 3);
79 lstrcpyn(STRING_PAGESETUP_Xx + sizeof(STRING_PAGESETUP_Xx) - 3, lang, 3);
82 hMainMenu = LoadMenu(Globals.hInstance, STRING_MENU_Xx);
83 Globals.hFileMenu = GetSubMenu(hMainMenu, 0);
84 Globals.hEditMenu = GetSubMenu(hMainMenu, 1);
85 Globals.hSearchMenu = GetSubMenu(hMainMenu, 2);
86 Globals.hLanguageMenu = GetSubMenu(hMainMenu, 3);
87 Globals.hHelpMenu = GetSubMenu(hMainMenu, 4);
89 /* Remove dummy item */
90 RemoveMenu(Globals.hLanguageMenu, 0, MF_BYPOSITION);
91 /* Add language items */
92 for (i = 0; i <= MAX_LANGUAGE_NUMBER; i++)
93 if (MAIN_LoadStringOtherLanguage(i, IDS_LANGUAGE_MENU_ITEM, item, sizeof(item)))
94 AppendMenu(Globals.hLanguageMenu, MF_STRING | MF_BYCOMMAND,
95 NP_FIRST_LANGUAGE + i, item);
97 SetMenu(Globals.hMainWnd, hMainMenu);
99 /* Destroy old menu */
100 if (Globals.hMainMenu) DestroyMenu(Globals.hMainMenu);
101 Globals.hMainMenu = hMainMenu;
104 /* Update system menus */
105 for (i = 0; Languages[i].name && lstrcmp(lang, Languages[i].name);) i++;
106 if (Languages[i].name) Options.language = i;
111 /***********************************************************************
113 * NOTEPAD_RegisterLanguages
115 * Handle language stuff at startup
118 void NOTEPAD_RegisterLanguages(void) {
120 LPCSTR opt_lang = "En";
124 /* Find language specific string table */
125 for (langnum = 0; langnum <= MAX_LANGUAGE_NUMBER; langnum++)
127 Globals.wStringTableOffset = langnum * 0x100;
128 if (LoadString(Globals.hInstance, IDS_LANGUAGE_ID, lang,
129 sizeof(lang)) && !lstrcmp(opt_lang, lang))
132 if (langnum > MAX_LANGUAGE_NUMBER)
134 /* Find fallback language */
135 for (langnum = 0; langnum <= MAX_LANGUAGE_NUMBER; langnum++)
137 Globals.wStringTableOffset = langnum * 0x100;
138 if (LoadString(Globals.hInstance, IDS_LANGUAGE_ID, lang, sizeof(lang)))
141 if (langnum > MAX_LANGUAGE_NUMBER)
143 MessageBox(0, "No language found", "FATAL ERROR", MB_OK);
148 /* Change Resource names */
149 lstrcpyn(STRING_MENU_Xx + lstrlen(STRING_MENU_Xx) - 2, lang, 3);
153 /***********************************************************************
155 * NOTEPAD_MenuCommand
157 * All handling of main menu events
160 int NOTEPAD_MenuCommand (WPARAM wParam)
162 // printf("NOTEPAD_MenuCommand()\n");
165 case NP_FILE_NEW: DIALOG_FileNew(); break;
166 case NP_FILE_OPEN: DIALOG_FileOpen(); break;
167 case NP_FILE_SAVE: DIALOG_FileSave(); break;
168 case NP_FILE_SAVEAS: DIALOG_FileSaveAs(); break;
169 case NP_FILE_PRINT: DIALOG_FilePrint(); break;
170 case NP_FILE_PAGESETUP: DIALOG_FilePageSetup(); break;
171 case NP_FILE_PRINTSETUP: DIALOG_FilePrinterSetup();break;
172 case NP_FILE_EXIT: DIALOG_FileExit(); break;
174 case NP_EDIT_UNDO: DIALOG_EditUndo(); break;
175 case NP_EDIT_CUT: DIALOG_EditCut(); break;
176 case NP_EDIT_COPY: DIALOG_EditCopy(); break;
177 case NP_EDIT_PASTE: DIALOG_EditPaste(); break;
178 case NP_EDIT_DELETE: DIALOG_EditDelete(); break;
179 case NP_EDIT_SELECTALL: DIALOG_EditSelectAll(); break;
180 case NP_EDIT_TIMEDATE: DIALOG_EditTimeDate();break;
181 case NP_EDIT_WRAP: DIALOG_EditWrap(); break;
183 case NP_SEARCH_SEARCH: DIALOG_Search(); break;
184 case NP_SEARCH_NEXT: DIALOG_SearchNext(); break;
186 case NP_HELP_CONTENTS: DIALOG_HelpContents(); break;
187 case NP_HELP_SEARCH: DIALOG_HelpSearch(); break;
188 case NP_HELP_ON_HELP: DIALOG_HelpHelp(); break;
189 case NP_HELP_LICENSE: DIALOG_HelpLicense(); break;
190 case NP_HELP_NO_WARRANTY: DIALOG_HelpNoWarranty(); break;
191 case NP_HELP_ABOUT_WINE: DIALOG_HelpAboutWine(); break;
195 if ((wParam >=NP_FIRST_LANGUAGE) && (wParam<=NP_LAST_LANGUAGE))
196 MAIN_SelectLanguageByNumber(wParam - NP_FIRST_LANGUAGE);
197 else printf("Unimplemented menu command %i\n", wParam);
204 /***********************************************************************
209 LRESULT NOTEPAD_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
216 printf("WM_CREATE\n");
220 printf("WM_PAINT\n");
221 BeginPaint(hWnd, &ps);
226 printf("WM_COMMAND\n");
227 NOTEPAD_MenuCommand(wParam);
231 printf("WM_DESTROY\n");
236 return DefWindowProc (hWnd, msg, wParam, lParam);
243 /***********************************************************************
248 void DumpGlobals(void) {
250 printf("DumpGlobals()\n");
251 printf(" Globals.lpszIniFile: %s\n", Globals.lpszIniFile);
252 printf(" Globals.lpszIcoFile: %s\n", Globals.lpszIcoFile);
253 printf("Globals.lpszLanguage: %s\n", Globals.lpszLanguage);
254 printf(" Globals.hInstance: %i\n", Globals.hInstance);
255 printf(" Globals.hMainMenu: %i\n", Globals.hMainMenu);
259 int PASCAL WinMain (HANDLE hInstance, HANDLE prev, LPSTR cmdline, int show)
263 char className[] = "NPClass"; /* To make sure className >= 0x10000 */
264 char winName[] = "Notepad";
266 #if defined(WINELIB) && !defined(HAVE_WINE_CONSTRUCTOR)
267 /* Register resources */
268 LIBWINE_Register_De();
269 LIBWINE_Register_En();
270 LIBWINE_Register_Sw();
273 printf("WinMain()\n");
277 Globals.lpszIniFile = "notepad.ini";
278 Globals.lpszIcoFile = "notepad.ico";
280 /* Select Language */
282 Globals.lpszLanguage = Languages[Options.language].name;
284 Globals.lpszLanguage = "En";
287 Globals.hInstance = hInstance;
288 Globals.hMainIcon = ExtractIcon(Globals.hInstance,
289 Globals.lpszIcoFile, 0);
290 if (!Globals.hMainIcon) Globals.hMainIcon =
291 LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
296 class.style = CS_HREDRAW | CS_VREDRAW;
297 class.lpfnWndProc = NOTEPAD_WndProc;
298 class.cbClsExtra = 0;
299 class.cbWndExtra = 0;
300 class.hInstance = Globals.hInstance;
301 class.hIcon = LoadIcon (0, IDI_APPLICATION);
302 class.hCursor = LoadCursor (0, IDC_ARROW);
303 class.hbrBackground = GetStockObject (WHITE_BRUSH);
304 class.lpszMenuName = "bla\0";
305 class.lpszClassName = (SEGPTR)className;
307 if (!RegisterClass (&class))
310 Globals.hMainWnd = CreateWindow (className, winName, WS_OVERLAPPEDWINDOW,
311 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
312 LoadMenu(Globals.hInstance, STRING_MENU_Xx),
313 Globals.hInstance, 0);
314 MAIN_SelectLanguageByName(Globals.lpszLanguage);
316 SetMenu(Globals.hMainWnd, Globals.hMainMenu);
318 ShowWindow (Globals.hMainWnd, show);
319 UpdateWindow (Globals.hMainWnd);
322 while (GetMessage (&msg, 0, 0, 0)) {
323 TranslateMessage (&msg);
324 DispatchMessage (&msg);
332 /* Local Variables: */
333 /* c-file-style: "GNU" */