Implemented ILGetDisplayName.
[wine/multimedia.git] / programs / notepad / language.c
blobf0525d842aca0e21b25823ca8bf21a1d487cf96c
1 /*
2 * Notepad
4 * Copyright 1997,98 Marcel Baur <mbaur@g26.ethz.ch>
5 * Copyright 1998 Karl BackstrĂ·m <karl_b@geocities.com>
6 */
8 #include <stdio.h>
9 #include "windows.h"
10 #include "main.h"
11 #include "language.h"
13 #ifdef WINELIB
14 #include "options.h"
15 #endif
17 CHAR STRING_MENU_Xx[] = "MENU_Xx";
18 CHAR STRING_PAGESETUP_Xx[] = "DIALOG_PAGESETUP_Xx";
20 void LANGUAGE_UpdateWindowCaption(void) {
21 /* Sets the caption of the main window according to Globals.szFileName:
22 Notepad - (untitled) if no file is open
23 Notepad - [filename] if a file is given
26 CHAR szCaption[MAX_STRING_LEN];
27 CHAR szUntitled[MAX_STRING_LEN];
29 LoadString(Globals.hInstance, IDS_NOTEPAD, szCaption, sizeof(szCaption));
31 if (strlen(Globals.szFileName)>0) {
32 lstrcat(szCaption, " - [");
33 lstrcat(szCaption, Globals.szFileName);
34 lstrcat(szCaption, "]");
36 else
38 LoadString(Globals.hInstance, IDS_UNTITLED, szUntitled, sizeof(szUntitled));
39 lstrcat(szCaption, " - ");
40 lstrcat(szCaption, szUntitled);
43 SetWindowText(Globals.hMainWnd, szCaption);
49 static BOOL LANGUAGE_LoadStringOther(UINT num, UINT ids, LPSTR str, UINT len)
51 ids -= Globals.wStringTableOffset;
52 ids += num * 0x100;
53 return(LoadString(Globals.hInstance, ids, str, len));
58 VOID LANGUAGE_SelectByName(LPCSTR lang)
60 INT i;
61 CHAR newlang[3];
63 for (i = 0; i <= MAX_LANGUAGE_NUMBER; i++)
64 if (LANGUAGE_LoadStringOther(i, IDS_LANGUAGE_ID, newlang, sizeof(newlang)) &&
65 !lstrcmp(lang, newlang))
67 LANGUAGE_SelectByNumber(i);
68 return;
71 /* Fallback */
72 for (i = 0; i <= MAX_LANGUAGE_NUMBER; i++)
73 if (LANGUAGE_LoadStringOther(i, IDS_LANGUAGE_ID, newlang, sizeof(newlang)))
75 LANGUAGE_SelectByNumber(i);
76 return;
79 MessageBox(Globals.hMainWnd, "No language found", "FATAL ERROR", MB_OK);
80 PostQuitMessage(1);
83 VOID LANGUAGE_SelectByNumber(UINT num)
85 INT i;
86 CHAR lang[3];
87 CHAR item[MAX_STRING_LEN];
88 HMENU hMainMenu;
90 /* Select string table */
91 Globals.wStringTableOffset = num * 0x100;
93 /* Get Language id */
94 LoadString(Globals.hInstance, IDS_LANGUAGE_ID, lang, sizeof(lang));
95 Globals.lpszLanguage = lang;
97 /* Set frame caption */
98 LANGUAGE_UpdateWindowCaption();
100 /* Change Resource names */
101 lstrcpyn(STRING_MENU_Xx + sizeof(STRING_MENU_Xx) - 3, lang, 3);
102 lstrcpyn(STRING_PAGESETUP_Xx + sizeof(STRING_PAGESETUP_Xx) - 3, lang, 3);
104 /* Create menu */
105 hMainMenu = LoadMenu(Globals.hInstance, STRING_MENU_Xx);
106 Globals.hFileMenu = GetSubMenu(hMainMenu, 0);
107 Globals.hEditMenu = GetSubMenu(hMainMenu, 1);
108 Globals.hSearchMenu = GetSubMenu(hMainMenu, 2);
109 Globals.hLanguageMenu = GetSubMenu(hMainMenu, 3);
110 Globals.hHelpMenu = GetSubMenu(hMainMenu, 4);
112 /* Remove dummy item */
113 RemoveMenu(Globals.hLanguageMenu, 0, MF_BYPOSITION);
114 /* Add language items */
115 for (i = 0; i <= MAX_LANGUAGE_NUMBER; i++)
116 if (LANGUAGE_LoadStringOther(i, IDS_LANGUAGE_MENU_ITEM, item, sizeof(item)))
117 AppendMenu(Globals.hLanguageMenu, MF_STRING | MF_BYCOMMAND,
118 NP_FIRST_LANGUAGE + i, item);
120 SetMenu(Globals.hMainWnd, hMainMenu);
122 /* Destroy old menu */
123 if (Globals.hMainMenu) DestroyMenu(Globals.hMainMenu);
124 Globals.hMainMenu = hMainMenu;
126 #ifdef WINELIB
127 /* Update system menus */
128 for (i = 0; Languages[i].name && lstrcmp(lang, Languages[i].name);) i++;
129 if (Languages[i].name) Options.language = i;
131 #endif
134 VOID LANGUAGE_DefaultHandle(WPARAM wParam)
136 if ((wParam >=NP_FIRST_LANGUAGE) && (wParam<=NP_LAST_LANGUAGE))
137 LANGUAGE_SelectByNumber(wParam - NP_FIRST_LANGUAGE);
138 else printf("Unimplemented menu command %i\n", wParam);
141 VOID LANGUAGE_Init(VOID)
143 #ifdef WINELIB
144 Globals.lpszLanguage = Languages[Options.language].name;
145 #else
146 CHAR buffer[MAX_PATHNAME_LEN], *p;
148 PROFILE_GetWineIniString("programs", "language", "language",
149 buffer, sizeof(buffer));
150 Globals.lpszLanguage = p = LocalLock(LocalAlloc(LMEM_FIXED, lstrlen(buffer)));
151 strcpy(p, buffer);
152 // hmemcpy(p, buffer, 1 + lstrlen(buffer));
153 #endif
156 /* Local Variables: */
157 /* c-file-style: "GNU" */
158 /* End: */