Added some digital video interface
[wine/multimedia.git] / programs / notepad / language.c
blob8593986c22b6785bf5d53cdf6871f62c7f9d1811
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 BOOL bOk;
53 ids -= Globals.wStringTableOffset;
54 ids += num * 0x100;
56 bOk = LoadString(Globals.hInstance, ids, str, len);
58 return(bOk);
63 VOID LANGUAGE_SelectByName(LPCSTR lang)
65 INT i;
66 CHAR newlang[3];
68 for (i = 0; i <= MAX_LANGUAGE_NUMBER; i++)
69 if (LANGUAGE_LoadStringOther(i, IDS_LANGUAGE_ID, newlang, sizeof(newlang)) &&
70 !lstrcmp(lang, newlang))
72 LANGUAGE_SelectByNumber(i);
73 return;
76 /* Fallback */
77 for (i = 0; i <= MAX_LANGUAGE_NUMBER; i++)
78 if (LANGUAGE_LoadStringOther(i, IDS_LANGUAGE_ID, newlang, sizeof(newlang)))
80 LANGUAGE_SelectByNumber(i);
81 return;
84 MessageBox(Globals.hMainWnd, "No language found", "FATAL ERROR", MB_OK);
85 PostQuitMessage(1);
88 VOID LANGUAGE_SelectByNumber(UINT num)
90 INT i;
91 CHAR lang[3];
92 CHAR item[MAX_STRING_LEN];
93 HMENU hMainMenu;
95 /* Select string table */
96 Globals.wStringTableOffset = num * 0x100;
98 /* Get Language id */
99 LoadString(Globals.hInstance, IDS_LANGUAGE_ID, lang, sizeof(lang));
100 Globals.lpszLanguage = lang;
102 /* Set frame caption */
103 LANGUAGE_UpdateWindowCaption();
105 /* Change Resource names */
106 lstrcpyn(STRING_MENU_Xx + sizeof(STRING_MENU_Xx) - 3, lang, 3);
107 lstrcpyn(STRING_PAGESETUP_Xx + sizeof(STRING_PAGESETUP_Xx) - 3, lang, 3);
109 /* Create menu */
110 hMainMenu = LoadMenu(Globals.hInstance, STRING_MENU_Xx);
111 Globals.hFileMenu = GetSubMenu(hMainMenu, 0);
112 Globals.hEditMenu = GetSubMenu(hMainMenu, 1);
113 Globals.hSearchMenu = GetSubMenu(hMainMenu, 2);
114 Globals.hLanguageMenu = GetSubMenu(hMainMenu, 3);
115 Globals.hHelpMenu = GetSubMenu(hMainMenu, 4);
117 /* Remove dummy item */
118 RemoveMenu(Globals.hLanguageMenu, 0, MF_BYPOSITION);
119 /* Add language items */
120 for (i = 0; i <= MAX_LANGUAGE_NUMBER; i++)
121 if (LANGUAGE_LoadStringOther(i, IDS_LANGUAGE_MENU_ITEM, item, sizeof(item)))
122 AppendMenu(Globals.hLanguageMenu, MF_STRING | MF_BYCOMMAND,
123 NP_FIRST_LANGUAGE + i, item);
125 SetMenu(Globals.hMainWnd, hMainMenu);
127 /* Destroy old menu */
128 if (Globals.hMainMenu) DestroyMenu(Globals.hMainMenu);
129 Globals.hMainMenu = hMainMenu;
131 #ifdef WINELIB
132 /* Update system menus */
133 for (i = 0; Languages[i].name && lstrcmp(lang, Languages[i].name);) i++;
134 if (Languages[i].name) Options.language = i;
136 #endif
139 VOID LANGUAGE_DefaultHandle(WPARAM wParam)
141 if ((wParam >=NP_FIRST_LANGUAGE) && (wParam<=NP_LAST_LANGUAGE))
142 LANGUAGE_SelectByNumber(wParam - NP_FIRST_LANGUAGE);
143 else printf("Unimplemented menu command %i\n", wParam);
146 VOID LANGUAGE_Init(VOID)
148 #ifdef WINELIB
149 Globals.lpszLanguage = Languages[Options.language].name;
150 #else
151 CHAR buffer[MAX_PATHNAME_LEN], *p;
153 #ifndef LCC
154 PROFILE_GetWineIniString("programs", "language", "language",
155 buffer, sizeof(buffer));
156 #endif
157 Globals.lpszLanguage = p = LocalLock(LocalAlloc(LMEM_FIXED, lstrlen(buffer)+1));
158 strcpy(p, buffer);
159 /* hmemcpy(p, buffer, 1 + lstrlen(buffer)); */
160 #endif