Skip to content

Commit

Permalink
Translation.ini can now be reloaded without restarting AltDrag.
Browse files Browse the repository at this point in the history
Config window now reloads settings if open and settings were manually changed in the ini file.
Fix bug introduced in r569 that broke all the action menus. Ops.
Config window can be dragged on the borders (instead of doing nothing), this is pretty cool.
Update pt-BR translation. Thanks Jucá!
  • Loading branch information
stefansundin committed Dec 29, 2014
1 parent 2f6621f commit abf5589
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 100 deletions.
Binary file modified AltDrag.ini
Binary file not shown.
39 changes: 9 additions & 30 deletions altdrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,9 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, char *szCmdLine, in
}
}

// Load Translation.ini if it exists
wchar_t translation_ini[300];
GetModuleFileName(NULL, translation_ini, ARRAY_SIZE(inipath));
PathRemoveFileSpec(translation_ini);
wcscat(translation_ini, L"\\Translation.ini");
FILE *f = _wfopen(translation_ini, L"rb");
if (f != NULL) {
fclose(f);
LoadTranslation(translation_ini);
}

// Language
GetPrivateProfileString(L"General", L"Language", L"en-US", txt, ARRAY_SIZE(txt), inipath);
for (i=0; i < ARRAY_SIZE(languages); i++) {
if (!wcsicmp(txt,languages[i]->code)) {
l10n = languages[i];
break;
}
}
memset(&l10n_ini, 0, sizeof(l10n_ini));
UpdateLanguage();

// Create window
WNDCLASSEX wnd = { sizeof(WNDCLASSEX), 0, WindowProc, 0, 0, hInst, NULL, NULL, (HBRUSH)(COLOR_WINDOW+1), NULL, APP_NAME, NULL };
Expand Down Expand Up @@ -254,7 +238,7 @@ int HookSystem() {
HOOKPROC procaddr;
if (!keyhook) {
// Get address to keyboard hook (beware name mangling)
procaddr = (HOOKPROC)GetProcAddress(hinstDLL, "LowLevelKeyboardProc@12");
procaddr = (HOOKPROC) GetProcAddress(hinstDLL, "LowLevelKeyboardProc@12");
if (procaddr == NULL) {
Error(L"GetProcAddress('LowLevelKeyboardProc@12')", L"This probably means that the file hooks.dll is from an old version or corrupt. You can try reinstalling "APP_NAME".", GetLastError());
return 1;
Expand All @@ -272,7 +256,7 @@ int HookSystem() {
GetPrivateProfileString(L"Advanced", L"HookWindows", L"0", txt, ARRAY_SIZE(txt), inipath);
if (!msghook && _wtoi(txt)) {
// Get address to message hook (beware name mangling)
procaddr = (HOOKPROC)GetProcAddress(hinstDLL, "CallWndProc@12");
procaddr = (HOOKPROC) GetProcAddress(hinstDLL, "CallWndProc@12");
if (procaddr == NULL) {
Error(L"GetProcAddress('CallWndProc@12')", L"This probably means that the file hooks.dll is from an old version or corrupt. You can try reinstalling "APP_NAME".", GetLastError());
return 1;
Expand Down Expand Up @@ -404,21 +388,16 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
}
}
else if (msg == WM_UPDATESETTINGS) {
wchar_t txt[10];
// Language
GetPrivateProfileString(L"General", L"Language", L"en-US", txt, ARRAY_SIZE(txt), inipath);
int i;
for (i=0; i < ARRAY_SIZE(languages); i++) {
if (!wcsicmp(txt,languages[i]->code)) {
l10n = languages[i];
break;
}
}
UpdateLanguage();
// Reload hooks
if (ENABLED()) {
UnhookSystem();
HookSystem();
}
// Reload config language
if (!wParam && IsWindow(g_cfgwnd)) {
SendMessage(g_cfgwnd, WM_UPDATESETTINGS, 0, 0);
}
}
else if (msg == WM_ADDTRAY) {
hide = 0;
Expand Down
68 changes: 45 additions & 23 deletions config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void CloseConfig() {
}

void UpdateSettings() {
PostMessage(g_hwnd, WM_UPDATESETTINGS, 0, 0);
PostMessage(g_hwnd, WM_UPDATESETTINGS, 1, 0);
}

void UpdateStrings() {
Expand Down Expand Up @@ -133,7 +133,14 @@ void UpdateStrings() {
LRESULT CALLBACK PropSheetWinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) {
LRESULT ret = DefSubclassProc(hwnd, msg, wParam, lParam);
if (msg == WM_NCHITTEST && (ret == HTBOTTOM || ret == HTBOTTOMLEFT || ret == HTBOTTOMRIGHT || ret == HTLEFT || ret == HTTOPLEFT || ret == HTTOPRIGHT || ret == HTRIGHT || ret == HTTOP)) {
ret = HTBORDER;
ret = HTCAPTION;
}
else if (msg == WM_UPDATESETTINGS) {
UpdateStrings();
HWND page = PropSheet_GetCurrentPageHwnd(g_cfgwnd);
SendMessage(page, WM_INITDIALOG, 0, 0);
NMHDR pnmh = { g_cfgwnd, 0, PSN_SETACTIVE };
SendMessage(page, WM_NOTIFY, 0, (LPARAM) &pnmh);
}
return ret;
}
Expand All @@ -145,7 +152,7 @@ BOOL CALLBACK PropSheetProc(HWND hwnd, UINT msg, LPARAM lParam) {
}
else if (msg == PSCB_INITIALIZED) {
g_cfgwnd = hwnd;
SetWindowSubclass(hwnd, PropSheetWinProc, 0, 0);
SetWindowSubclass(g_cfgwnd, PropSheetWinProc, 0, 0);
UpdateStrings();

// OK button replaces Cancel button
Expand Down Expand Up @@ -179,11 +186,21 @@ INT_PTR CALLBACK GeneralPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
GetPrivateProfileString(L"General", L"MDI", L"0", txt, ARRAY_SIZE(txt), inipath);
Button_SetCheck(GetDlgItem(hwnd,IDC_MDI), _wtoi(txt)?BST_CHECKED:BST_UNCHECKED);

int i;
for (i=0; i < ARRAY_SIZE(languages); i++) {
ComboBox_AddString(GetDlgItem(hwnd,IDC_LANGUAGE), languages[i]->lang);
if (l10n == languages[i]) {
ComboBox_SetCurSel(GetDlgItem(hwnd,IDC_LANGUAGE), i);
HWND control = GetDlgItem(hwnd, IDC_LANGUAGE);
ComboBox_ResetContent(control);
if (l10n == &l10n_ini) {
ComboBox_AddString(control, l10n->lang);
ComboBox_SetCurSel(control, 0);
ComboBox_Enable(control, FALSE);
}
else {
ComboBox_Enable(control, TRUE);
int i;
for (i=0; i < ARRAY_SIZE(languages); i++) {
ComboBox_AddString(control, languages[i]->lang);
if (l10n == languages[i]) {
ComboBox_SetCurSel(control, i);
}
}
}

Expand Down Expand Up @@ -271,7 +288,7 @@ INT_PTR CALLBACK GeneralPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
UpdateSettings();
}
else if (msg == WM_NOTIFY) {
LPNMHDR pnmh = (LPNMHDR)lParam;
LPNMHDR pnmh = (LPNMHDR) lParam;
if (pnmh->code == PSN_SETACTIVE) {
updatestrings = 1;

Expand Down Expand Up @@ -302,19 +319,21 @@ INT_PTR CALLBACK GeneralPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
SetDlgItemText(hwnd, IDC_AUTOSAVE, l10n->general.autosave);

// AutoSnap
ComboBox_ResetContent(GetDlgItem(hwnd,IDC_AUTOSNAP));
ComboBox_AddString(GetDlgItem(hwnd,IDC_AUTOSNAP), l10n->general.autosnap0);
ComboBox_AddString(GetDlgItem(hwnd,IDC_AUTOSNAP), l10n->general.autosnap1);
ComboBox_AddString(GetDlgItem(hwnd,IDC_AUTOSNAP), l10n->general.autosnap2);
ComboBox_AddString(GetDlgItem(hwnd,IDC_AUTOSNAP), l10n->general.autosnap3);
HWND control = GetDlgItem(hwnd, IDC_AUTOSNAP);
ComboBox_ResetContent(control);
ComboBox_AddString(control, l10n->general.autosnap0);
ComboBox_AddString(control, l10n->general.autosnap1);
ComboBox_AddString(control, l10n->general.autosnap2);
ComboBox_AddString(control, l10n->general.autosnap3);
wchar_t txt[10];
GetPrivateProfileString(L"General", L"AutoSnap", L"0", txt, ARRAY_SIZE(txt), inipath);
ComboBox_SetCurSel(GetDlgItem(hwnd,IDC_AUTOSNAP), _wtoi(txt));
ComboBox_SetCurSel(control, _wtoi(txt));

// Language
ComboBox_DeleteString(GetDlgItem(hwnd,IDC_LANGUAGE), ARRAY_SIZE(languages));
control = GetDlgItem(hwnd, IDC_LANGUAGE);
ComboBox_DeleteString(control, ARRAY_SIZE(languages));
if (l10n == &en_US) {
ComboBox_AddString(GetDlgItem(hwnd,IDC_LANGUAGE), L"How can I help translate?");
ComboBox_AddString(control, L"How can I help translate?");
}
}
return FALSE;
Expand Down Expand Up @@ -462,32 +481,35 @@ INT_PTR CALLBACK InputPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
LPNMHDR pnmh = (LPNMHDR)lParam;
if (pnmh->code == PSN_SETACTIVE) {
wchar_t txt[50];
int i, j;
int i, j, sel;

// Mouse actions
for (i=0; i < ARRAY_SIZE(mouse_buttons); i++) {
HWND control = GetDlgItem(hwnd, mouse_buttons[i].control);
ComboBox_ResetContent(control);
GetPrivateProfileString(L"Input", mouse_buttons[i].option, L"Nothing", txt, ARRAY_SIZE(txt), inipath);
sel = ARRAY_SIZE(mouse_actions)-1;
for (j=0; j < ARRAY_SIZE(mouse_actions); j++) {
ComboBox_AddString(control, mouse_actions[j].l10n);
if (!wcscmp(txt,mouse_actions[j].action) || j == ARRAY_SIZE(mouse_actions)-1) {
ComboBox_SetCurSel(control, j);
break;
if (!wcscmp(txt,mouse_actions[j].action)) {
sel = j;
}
}
ComboBox_SetCurSel(control, sel);
}

// Scroll
HWND control = GetDlgItem(hwnd, IDC_SCROLL);
ComboBox_ResetContent(control);
GetPrivateProfileString(L"Input", L"Scroll", L"Nothing", txt, ARRAY_SIZE(txt), inipath);
sel = ARRAY_SIZE(scroll_actions)-1;
for (j=0; j < ARRAY_SIZE(scroll_actions); j++) {
ComboBox_AddString(control, scroll_actions[j].l10n);
if (!wcscmp(txt,scroll_actions[j].action) || j == ARRAY_SIZE(scroll_actions)-1) {
ComboBox_SetCurSel(control, j);
if (!wcscmp(txt,scroll_actions[j].action)) {
sel = j;
}
}
ComboBox_SetCurSel(control, sel);

// Update text
SetDlgItemText(hwnd, IDC_MOUSE_BOX, l10n->input.mouse.box);
Expand Down
32 changes: 25 additions & 7 deletions include/localization.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,38 @@ void LoadTranslation(wchar_t *ini) {
wchar_t txt[3000];
int i;
for (i=0; i < ARRAY_SIZE(l10n_mapping); i++) {
// Replace English
if (l10n_mapping[i].str == &l10n_ini.code) {
languages[0] = &l10n_ini;
l10n_ini.code = en_US.code;
continue;
}
// Get pointer to default English string to be used if ini entry doesn't exist
wchar_t *def = *(wchar_t**) ((void*)&en_US + ((void*)l10n_mapping[i].str - (void*)&l10n_ini));
GetPrivateProfileString(L"Translation", l10n_mapping[i].name, def, txt, ARRAY_SIZE(txt), ini);
if (l10n_mapping[i].str == &l10n_ini.about.version) {
wcscat(txt, L" ");
wcscat(txt, TEXT(APP_VERSION));
}
*l10n_mapping[i].str = malloc((wcslen(txt)+1)*sizeof(wchar_t));
*l10n_mapping[i].str = realloc(*l10n_mapping[i].str, (wcslen_resolved(txt)+1)*sizeof(wchar_t));
wcscpy_resolve(*l10n_mapping[i].str, txt);
}
}

void UpdateLanguage() {
wchar_t path[MAX_PATH];
GetModuleFileName(NULL, path, ARRAY_SIZE(path));
PathRemoveFileSpec(path);
wcscat(path, L"\\Translation.ini");
FILE *f = _wfopen(path, L"rb");
if (f != NULL) {
fclose(f);
LoadTranslation(path);
l10n = &l10n_ini;
return;
}

wchar_t txt[10];
GetPrivateProfileString(L"General", L"Language", L"en-US", txt, ARRAY_SIZE(txt), inipath);
int i;
for (i=0; i < ARRAY_SIZE(languages); i++) {
if (!wcsicmp(txt,languages[i]->code)) {
l10n = languages[i];
break;
}
}
}
Binary file modified localization/pt-BR/Translation.ini
Binary file not shown.
16 changes: 8 additions & 8 deletions localization/pt-BR/installer.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ LangString L10N_UPDATE_DIALOG 0 "Uma nova versão está disponível.$\nCance

LangString L10N_ALTSHIFT_TITLE 0 "Atalho de teclado"
LangString L10N_ALTSHIFT_SUBTITLE 0 "O atalho Alt + Shift entra em conflito com ${APP_NAME}."
LangString L10N_ALTSHIFT_HEADER 0 "O instalador detectou que o atalho do Windows para alternar o layout do teclado é Alt + Shift.$\n$\nAo utilizar ${APP_NAME}, você pode pressionar Shift enquanto arrasta uma janela para alinhá-la com outras janelas. Isso significa que é provável que você pressione Alt + Shift, a mesma combinação que alterna o layout do teclado. Ainda que o ${APP_NAME} tente bloquear estas mudanças acidentais, ele poderá não conseguir se você pressionar Shift antes de começar a arrastar uma janela.$\n$\nVocê pode desativar ou mudar o atalho que alterna o layout do teclado pressionado o botão abaxio. Clique em Próximo para continuar."
LangString L10N_ALTSHIFT_HEADER 0 "O instalador detectou que o atalho do Windows para alternar o layout do teclado é Alt + Shift.$\n$\nAo utilizar o ${APP_NAME}, você pode pressionar Shift enquanto arrasta uma janela para alinhá-la com outras janelas. Isso significa que é provável que você pressione Alt + Shift, a mesma combinação que alterna o layout do teclado. Ainda que o ${APP_NAME} tente bloquear estas mudanças acidentais, ele poderá não conseguir se você pressionar Shift antes de começar a arrastar uma janela.$\n$\nVocê pode desativar ou mudar o atalho que alterna o layout do teclado pressionando o botão abaixo. Clique em Próximo para continuar."
LangString L10N_ALTSHIFT_BUTTON 0 "&Alterar teclados..."

LangString L10N_HOOKTIMEOUT_TITLE 0 "Registry tweak"
LangString L10N_HOOKTIMEOUT_SUBTITLE 0 "Optional tweak to keep ${APP_NAME} from stopping unexpectedly."
LangString L10N_HOOKTIMEOUT_HEADER 0 "In Windows 7, Microsoft implemented a feature that stops keyboard and mouse hooks if they take too long to respond. Unfortunately, this check can erroneously misbehave, especially if you hibernate, sleep, or lock the computer a lot.$\n$\nIf this happens, you will find that ${APP_NAME} stop functioning without warning, and you have to manually disable and enable ${APP_NAME} to make it work again.$\n$\nThere is a registry tweak to make Windows wait longer before stopping hooks, which you can enable or disable by using the buttons below. Please note that this registry tweak is completely optional."
LangString L10N_HOOKTIMEOUT_APPLYBUTTON 0 "&Enable registry tweak"
LangString L10N_HOOKTIMEOUT_REVERTBUTTON 0 "&Disable registry tweak"
LangString L10N_HOOKTIMEOUT_ALREADYAPPLIED 0 "The registry tweak has already been applied."
LangString L10N_HOOKTIMEOUT_FOOTER 0 "The change will take effect on your next login."
LangString L10N_HOOKTIMEOUT_TITLE 0 "Ajuste do resgitro"
LangString L10N_HOOKTIMEOUT_SUBTITLE 0 "Ajuste opcional para evitar que o ${APP_NAME} pare de funcionar inesperadamente."
LangString L10N_HOOKTIMEOUT_HEADER 0 "No Windows 7, a Microsoft acrescentou uma ferramenta para interromper injeções (hooks) do teclado e mouse se eles demorassem a responder. Infelizmente, esta verificação pode equivocadamente se comportar mal, especialmente se você hiberna, suspende ou troca de usuário frequentemente.$\n$\nSe isto acontecer, o ${APP_NAME} poderá parar de funcionar sem qualquer aviso, e você deverá desativá-lo e reativá-lo manualmente para que ele volte a funcionar.$\n$\nHá um ajuste no Registro do Windows para fazer com que o sistema aguarde mais tempo antes de interromper injeções (hooks). Você pode ativá-lo usando os botões abaixo. Note que este ajuste é completamente opcional."
LangString L10N_HOOKTIMEOUT_APPLYBUTTON 0 "&Ativar ajuste no registro"
LangString L10N_HOOKTIMEOUT_REVERTBUTTON 0 "&Desativar ajuste no registro"
LangString L10N_HOOKTIMEOUT_ALREADYAPPLIED 0 "O ajuste no registro já foi aplicado."
LangString L10N_HOOKTIMEOUT_FOOTER 0 "A mudança será aplicada no seu próximo logon."
Loading

0 comments on commit abf5589

Please sign in to comment.