Commit 1f296515df5e567143fdc991984c7e704b455b53
1 parent
b2833efd
Exists in
master
and in
1 other branch
Loading default font-family from windows registry
Showing
2 changed files
with
56 additions
and
53 deletions
Show diff stats
src/terminal/font/properties.c
... | ... | @@ -47,11 +47,65 @@ static const gchar * invalid_font_messages[] = { |
47 | 47 | const gchar * v3270_get_default_font_name() |
48 | 48 | { |
49 | 49 | #if defined(_WIN32) |
50 | - return "Lucida Console"; | |
50 | + { | |
51 | + HKEY hKey; | |
52 | + DWORD disp = 0; | |
53 | + LSTATUS rc = RegCreateKeyEx( | |
54 | + HKEY_LOCAL_MACHINE, | |
55 | + "Software\\" LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME), | |
56 | + 0, | |
57 | + NULL, | |
58 | + REG_OPTION_NON_VOLATILE, | |
59 | + KEY_QUERY_VALUE|KEY_READ, | |
60 | + NULL, | |
61 | + &hKey, | |
62 | + &disp); | |
63 | + | |
64 | + debug("%s=%d","Software\\" LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),rc); | |
65 | + | |
66 | + if(rc == ERROR_SUCCESS) | |
67 | + { | |
68 | + static char * default_font_name = NULL; | |
69 | + DWORD cbData = 4096; | |
70 | + | |
71 | + if(!default_font_name) | |
72 | + { | |
73 | + default_font_name = (char *) malloc(cbData+1); | |
74 | + } | |
75 | + else | |
76 | + { | |
77 | + default_font_name = (char *) realloc(default_font_name,cbData+1); | |
78 | + } | |
79 | + | |
80 | + DWORD dwRet = RegQueryValueEx(hKey,"font-family",NULL,NULL,(LPBYTE) default_font_name, &cbData); | |
81 | + | |
82 | + debug("dwRet=%d",dwRet); | |
83 | + | |
84 | + RegCloseKey(hKey); | |
85 | + | |
86 | + if(dwRet == ERROR_SUCCESS) | |
87 | + { | |
88 | + default_font_name = (char *) realloc(default_font_name,cbData+1); | |
89 | + default_font_name[cbData] = 0; | |
90 | + return default_font_name; | |
91 | + } | |
92 | + | |
93 | + free(default_font_name); | |
94 | + default_font_name = NULL; | |
95 | + } | |
96 | + } | |
97 | + | |
98 | + // TODO: Search for a valid font-family | |
99 | + return "Courier New"; | |
100 | + | |
51 | 101 | #elif defined(__APPLE__) |
102 | + | |
52 | 103 | return "Courier New"; |
104 | + | |
53 | 105 | #else |
106 | + | |
54 | 107 | return "monospace"; |
108 | + | |
55 | 109 | #endif // _WIN32 |
56 | 110 | } |
57 | 111 | ... | ... |
src/testprogram/testprogram.c
... | ... | @@ -71,35 +71,6 @@ |
71 | 71 | } |
72 | 72 | */ |
73 | 73 | |
74 | -#ifdef _WIN32 | |
75 | - | |
76 | - static int get_registry(HKEY *hKey,REGSAM samDesired) | |
77 | - { | |
78 | - DWORD disp; | |
79 | - | |
80 | - if(RegCreateKeyEx(HKEY_CURRENT_USER,"software\\v3270",0,NULL,REG_OPTION_NON_VOLATILE,samDesired,NULL,hKey,&disp) != ERROR_SUCCESS) | |
81 | - { | |
82 | - g_warning("Can't open registry"); | |
83 | - return -1; | |
84 | - } | |
85 | - | |
86 | - return 0; | |
87 | - | |
88 | - } | |
89 | - | |
90 | - static void save_settings(GtkWidget *terminal, GtkWidget *window) | |
91 | - { | |
92 | - HKEY hKey = 0; | |
93 | - | |
94 | - if(get_registry(&hKey,KEY_SET_VALUE)) | |
95 | - return; | |
96 | - | |
97 | - v3270_to_registry(terminal,hKey,"terminal"); | |
98 | - RegCloseKey(hKey); | |
99 | - } | |
100 | - | |
101 | -#else | |
102 | - | |
103 | 74 | static GKeyFile * get_key_file() |
104 | 75 | { |
105 | 76 | GKeyFile * key_file = g_key_file_new(); |
... | ... | @@ -109,7 +80,7 @@ |
109 | 80 | |
110 | 81 | static void save_settings(GtkWidget *terminal, GtkWidget *window) |
111 | 82 | { |
112 | - debug("%s: Saving settings for windows %p",__FUNCTION__,window); | |
83 | + debug("%s: Saving settings for window %p",__FUNCTION__,window); | |
113 | 84 | |
114 | 85 | GKeyFile * key_file = get_key_file(); |
115 | 86 | |
... | ... | @@ -122,8 +93,6 @@ |
122 | 93 | |
123 | 94 | } |
124 | 95 | |
125 | -#endif // _WIN32 | |
126 | - | |
127 | 96 | static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { |
128 | 97 | |
129 | 98 | GtkWidget * window = gtk_application_window_new(app); |
... | ... | @@ -147,32 +116,12 @@ |
147 | 116 | |
148 | 117 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new("Terminal")); |
149 | 118 | |
150 | -#ifdef _WIN32 | |
151 | - v3270_set_font_family(terminal,"Lucida Console"); | |
152 | -#endif // _WIN32 | |
153 | - | |
154 | - v3270_selection_set_font_family(terminal,"monospace"); | |
155 | - | |
156 | 119 | // Load settings before connecting the signals. |
157 | -#ifdef _WIN32 | |
158 | - { | |
159 | - HKEY hKey = 0; | |
160 | - | |
161 | - if(!get_registry(&hKey,KEY_SET_VALUE)) | |
162 | - { | |
163 | - v3270_load_registry(terminal,hKey,"terminal"); | |
164 | - RegCloseKey(hKey); | |
165 | - } | |
166 | - | |
167 | - } | |
168 | -#else | |
169 | 120 | debug("%s: Loading settings...",__FUNCTION__); |
170 | 121 | GKeyFile * key_file = get_key_file(); |
171 | 122 | v3270_load_key_file(terminal,key_file,NULL); |
172 | 123 | v3270_accelerator_map_load_key_file(terminal,key_file,NULL); |
173 | - | |
174 | 124 | g_key_file_free(key_file); |
175 | -#endif // _WIN32 | |
176 | 125 | |
177 | 126 | } |
178 | 127 | ... | ... |