From c37cdce905fc773ac1dc8469307d688bc80c06f9 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Mon, 19 Jul 2010 18:22:22 -0400 Subject: [PATCH] wordpad: Save and load word wrap registry options. --- programs/wordpad/registry.c | 32 +++++++++++++++++++++++--------- programs/wordpad/wordpad.c | 2 +- programs/wordpad/wordpad.h | 2 +- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/programs/wordpad/registry.c b/programs/wordpad/registry.c index 7311fb68232..472ed4da9be 100644 --- a/programs/wordpad/registry.c +++ b/programs/wordpad/registry.c @@ -34,6 +34,7 @@ static const WCHAR key_text[] = {'T','e','x','t',0}; static const WCHAR var_file[] = {'F','i','l','e','%','d',0}; static const WCHAR var_framerect[] = {'F','r','a','m','e','R','e','c','t',0}; static const WCHAR var_barstate0[] = {'B','a','r','S','t','a','t','e','0',0}; +static const WCHAR var_wrap[] = {'W','r','a','p',0}; static const WCHAR var_maximized[] = {'M','a','x','i','m','i','z','e','d',0}; static LRESULT registry_get_handle(HKEY *hKey, LPDWORD action, LPCWSTR subKey) @@ -377,10 +378,22 @@ static void registry_read_formatopts(int index, LPCWSTR key, DWORD barState[], D if(!fetched) barState[index] = (1 << BANDID_TOOLBAR) | (1 << BANDID_FORMATBAR) | (1 << BANDID_RULER) | (1 << BANDID_STATUSBAR); - if(index == reg_formatindex(SF_RTF)) - wordWrap[index] = ID_WORDWRAP_WINDOW; - else if(index == reg_formatindex(SF_TEXT)) - wordWrap[index] = ID_WORDWRAP_NONE; + fetched = FALSE; + if(action == REG_OPENED_EXISTING_KEY) + { + DWORD size = sizeof(DWORD); + if(RegQueryValueExW(hKey, var_wrap, 0, NULL, (LPBYTE)&wordWrap[index], + &size) == ERROR_SUCCESS) + fetched = TRUE; + } + + if (!fetched) + { + if(index == reg_formatindex(SF_RTF)) + wordWrap[index] = ID_WORDWRAP_WINDOW; + else if(index == reg_formatindex(SF_TEXT)) + wordWrap[index] = ID_WORDWRAP_NONE; + } RegCloseKey(hKey); } @@ -391,7 +404,7 @@ void registry_read_formatopts_all(DWORD barState[], DWORD wordWrap[]) registry_read_formatopts(reg_formatindex(SF_TEXT), key_text, barState, wordWrap); } -static void registry_set_formatopts(int index, LPCWSTR key, DWORD barState[]) +static void registry_set_formatopts(int index, LPCWSTR key, DWORD barState[], DWORD wordWrap[]) { HKEY hKey; DWORD action = 0; @@ -400,13 +413,14 @@ static void registry_set_formatopts(int index, LPCWSTR key, DWORD barState[]) { RegSetValueExW(hKey, var_barstate0, 0, REG_DWORD, (LPBYTE)&barState[index], sizeof(DWORD)); - + RegSetValueExW(hKey, var_wrap, 0, REG_DWORD, (LPBYTE)&wordWrap[index], + sizeof(DWORD)); RegCloseKey(hKey); } } -void registry_set_formatopts_all(DWORD barState[]) +void registry_set_formatopts_all(DWORD barState[], DWORD wordWrap[]) { - registry_set_formatopts(reg_formatindex(SF_RTF), key_rtf, barState); - registry_set_formatopts(reg_formatindex(SF_TEXT), key_text, barState); + registry_set_formatopts(reg_formatindex(SF_RTF), key_rtf, barState, wordWrap); + registry_set_formatopts(reg_formatindex(SF_TEXT), key_text, barState, wordWrap); } diff --git a/programs/wordpad/wordpad.c b/programs/wordpad/wordpad.c index 80fe19d7f00..abd7cd21db4 100644 --- a/programs/wordpad/wordpad.c +++ b/programs/wordpad/wordpad.c @@ -2639,7 +2639,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara } else if(prompt_save_changes()) { registry_set_options(hMainWnd); - registry_set_formatopts_all(barState); + registry_set_formatopts_all(barState, wordWrap); PostQuitMessage(0); } break; diff --git a/programs/wordpad/wordpad.h b/programs/wordpad/wordpad.h index c3c5bc089ba..f50881abe07 100644 --- a/programs/wordpad/wordpad.h +++ b/programs/wordpad/wordpad.h @@ -262,5 +262,5 @@ void registry_read_formatopts_all(DWORD[], DWORD[]); void registry_read_winrect(RECT*); void registry_read_maximized(DWORD*); void registry_set_filelist(LPCWSTR, HWND); -void registry_set_formatopts_all(DWORD[]); +void registry_set_formatopts_all(DWORD[], DWORD[]); void registry_set_options(HWND);