diff --git a/src/terminal/font/properties.c b/src/terminal/font/properties.c index d69172b..81876e8 100644 --- a/src/terminal/font/properties.c +++ b/src/terminal/font/properties.c @@ -47,11 +47,65 @@ static const gchar * invalid_font_messages[] = { const gchar * v3270_get_default_font_name() { #if defined(_WIN32) - return "Lucida Console"; + { + HKEY hKey; + DWORD disp = 0; + LSTATUS rc = RegCreateKeyEx( + HKEY_LOCAL_MACHINE, + "Software\\" LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME), + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_QUERY_VALUE|KEY_READ, + NULL, + &hKey, + &disp); + + debug("%s=%d","Software\\" LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),rc); + + if(rc == ERROR_SUCCESS) + { + static char * default_font_name = NULL; + DWORD cbData = 4096; + + if(!default_font_name) + { + default_font_name = (char *) malloc(cbData+1); + } + else + { + default_font_name = (char *) realloc(default_font_name,cbData+1); + } + + DWORD dwRet = RegQueryValueEx(hKey,"font-family",NULL,NULL,(LPBYTE) default_font_name, &cbData); + + debug("dwRet=%d",dwRet); + + RegCloseKey(hKey); + + if(dwRet == ERROR_SUCCESS) + { + default_font_name = (char *) realloc(default_font_name,cbData+1); + default_font_name[cbData] = 0; + return default_font_name; + } + + free(default_font_name); + default_font_name = NULL; + } + } + + // TODO: Search for a valid font-family + return "Courier New"; + #elif defined(__APPLE__) + return "Courier New"; + #else + return "monospace"; + #endif // _WIN32 } diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index 43f91d3..2570136 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -71,35 +71,6 @@ } */ -#ifdef _WIN32 - - static int get_registry(HKEY *hKey,REGSAM samDesired) - { - DWORD disp; - - if(RegCreateKeyEx(HKEY_CURRENT_USER,"software\\v3270",0,NULL,REG_OPTION_NON_VOLATILE,samDesired,NULL,hKey,&disp) != ERROR_SUCCESS) - { - g_warning("Can't open registry"); - return -1; - } - - return 0; - - } - - static void save_settings(GtkWidget *terminal, GtkWidget *window) - { - HKEY hKey = 0; - - if(get_registry(&hKey,KEY_SET_VALUE)) - return; - - v3270_to_registry(terminal,hKey,"terminal"); - RegCloseKey(hKey); - } - -#else - static GKeyFile * get_key_file() { GKeyFile * key_file = g_key_file_new(); @@ -109,7 +80,7 @@ static void save_settings(GtkWidget *terminal, GtkWidget *window) { - debug("%s: Saving settings for windows %p",__FUNCTION__,window); + debug("%s: Saving settings for window %p",__FUNCTION__,window); GKeyFile * key_file = get_key_file(); @@ -122,8 +93,6 @@ } -#endif // _WIN32 - static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { GtkWidget * window = gtk_application_window_new(app); @@ -147,32 +116,12 @@ gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new("Terminal")); -#ifdef _WIN32 - v3270_set_font_family(terminal,"Lucida Console"); -#endif // _WIN32 - - v3270_selection_set_font_family(terminal,"monospace"); - // Load settings before connecting the signals. -#ifdef _WIN32 - { - HKEY hKey = 0; - - if(!get_registry(&hKey,KEY_SET_VALUE)) - { - v3270_load_registry(terminal,hKey,"terminal"); - RegCloseKey(hKey); - } - - } -#else debug("%s: Loading settings...",__FUNCTION__); GKeyFile * key_file = get_key_file(); v3270_load_key_file(terminal,key_file,NULL); v3270_accelerator_map_load_key_file(terminal,key_file,NULL); - g_key_file_free(key_file); -#endif // _WIN32 } -- libgit2 0.21.2