Made notepad uses NLS properly.
[wine] / programs / wineconsole / registry.c
1 /*
2  * an application for displaying Win32 console
3  *      registry and init functions
4  *
5  * Copyright 2001 Eric Pouech
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "winbase.h"
23 #include "winreg.h"
24 #include "winecon_private.h"
25
26 static const WCHAR wszConsole[]           = {'C','o','n','s','o','l','e',0};
27 static const WCHAR wszCursorSize[]        = {'C','u','r','s','o','r','S','i','z','e',0};
28 static const WCHAR wszCursorVisible[]     = {'C','u','r','s','o','r','V','i','s','i','b','l','e',0};
29 static const WCHAR wszFaceName[]          = {'F','a','c','e','N','a','m','e',0};
30 static const WCHAR wszFontSize[]          = {'F','o','n','t','S','i','z','e',0};
31 static const WCHAR wszFontWeight[]        = {'F','o','n','t','W','e','i','g','h','t',0};
32 static const WCHAR wszHistoryBufferSize[] = {'H','i','s','t','o','r','y','B','u','f','f','e','r','S','i','z','e',0};
33 static const WCHAR wszMenuMask[]          = {'M','e','n','u','M','a','s','k',0};
34 static const WCHAR wszQuickEdit[]         = {'Q','u','i','c','k','E','d','i','t',0};
35 static const WCHAR wszScreenBufferSize[]  = {'S','c','r','e','e','n','B','u','f','f','e','r','S','i','z','e',0};
36 static const WCHAR wszScreenColors[]      = {'S','c','r','e','e','n','C','o','l','o','r','s',0};
37 static const WCHAR wszWindowSize[]        = {'W','i','n','d','o','w','S','i','z','e',0};
38
39 /******************************************************************
40  *              WINECON_RegLoad
41  *
42  *
43  */
44 BOOL WINECON_RegLoad(struct config_data* cfg)
45 {
46     HKEY        hConKey;
47     DWORD       type;
48     DWORD       count;
49     DWORD       val;
50
51     if (RegOpenKey(HKEY_CURRENT_USER, wszConsole, &hConKey)) hConKey = 0;
52
53     count = sizeof(val);
54     if (!hConKey || RegQueryValueEx(hConKey, wszCursorSize, 0, &type, (char*)&val, &count)) 
55         val = 25;
56     cfg->cursor_size = val;
57
58     count = sizeof(val);
59     if (!hConKey || RegQueryValueEx(hConKey, wszCursorVisible, 0, &type, (char*)&val, &count)) 
60         val = 1;
61     cfg->cursor_visible = val;
62
63     count = sizeof(cfg->face_name); 
64     if (!hConKey || RegQueryValueEx(hConKey, wszFaceName, 0, &type, (char*)&cfg->face_name, &count))
65         cfg->face_name[0] = 0;
66
67     count = sizeof(val);
68     if (!hConKey || RegQueryValueEx(hConKey, wszFontSize, 0, &type, (char*)&val, &count)) 
69         val = 0x000C0008;
70     cfg->cell_height = HIWORD(val);
71     cfg->cell_width  = LOWORD(val);
72
73     count = sizeof(val);
74     if (!hConKey || RegQueryValueEx(hConKey, wszFontWeight, 0, &type, (char*)&val, &count)) 
75         val = 0;
76     cfg->font_weight = val;
77
78     count = sizeof(val);
79     if (!hConKey || RegQueryValueEx(hConKey, wszHistoryBufferSize, 0, &type, (char*)&val, &count)) 
80         val = 0;
81     cfg->history_size = val;
82
83     count = sizeof(val);
84     if (!hConKey || RegQueryValueEx(hConKey, wszMenuMask, 0, &type, (char*)&val, &count)) 
85         val = 0;
86     cfg->menu_mask = val;
87
88     count = sizeof(val);
89     if (!hConKey || RegQueryValueEx(hConKey, wszQuickEdit, 0, &type, (char*)&val, &count)) 
90         val = 0;
91     cfg->quick_edit = val;
92
93     count = sizeof(val);
94     if (!hConKey || RegQueryValueEx(hConKey, wszScreenBufferSize, 0, &type, (char*)&val, &count)) 
95         val = 0x00190050;
96     cfg->sb_height = HIWORD(val);
97     cfg->sb_width  = LOWORD(val);
98
99     count = sizeof(val);
100     if (!hConKey || RegQueryValueEx(hConKey, wszScreenColors, 0, &type, (char*)&val, &count)) 
101         val = 0x000F;
102     cfg->def_attr = val;
103
104     count = sizeof(val);
105     if (!hConKey || RegQueryValueEx(hConKey, wszWindowSize, 0, &type, (char*)&val, &count)) 
106         val = 0x00190050;
107     cfg->win_height = HIWORD(val);
108     cfg->win_width  = LOWORD(val);
109
110     /* win_pos isn't read from registry */
111
112     if (hConKey) RegCloseKey(hConKey);
113     return TRUE;
114 }
115
116 /******************************************************************
117  *              WINECON_RegSave
118  *
119  *
120  */
121 BOOL WINECON_RegSave(const struct config_data* cfg)
122 {
123     HKEY        hConKey;
124     DWORD       val;
125
126     if (RegCreateKey(HKEY_CURRENT_USER, wszConsole, &hConKey)) 
127     {
128         Trace(0, "Can't open registry for saving\n");
129         return FALSE;
130     }
131    
132     val = cfg->cursor_size;
133     RegSetValueEx(hConKey, wszCursorSize, 0, REG_DWORD, (char*)&val, sizeof(val));
134
135     val = cfg->cursor_visible;
136     RegSetValueEx(hConKey, wszCursorVisible, 0, REG_DWORD, (char*)&val, sizeof(val));
137
138     RegSetValueEx(hConKey, wszFaceName, 0, REG_SZ, (char*)&cfg->face_name, sizeof(cfg->face_name));
139
140     val = MAKELONG(cfg->cell_width, cfg->cell_height);
141     RegSetValueEx(hConKey, wszFontSize, 0, REG_DWORD, (char*)&val, sizeof(val));
142
143     val = cfg->font_weight;
144     RegSetValueEx(hConKey, wszFontWeight, 0, REG_DWORD, (char*)&val, sizeof(val));
145
146     val = cfg->history_size;
147     RegSetValueEx(hConKey, wszHistoryBufferSize, 0, REG_DWORD, (char*)&val, sizeof(val));
148
149     val = cfg->menu_mask;
150     RegSetValueEx(hConKey, wszMenuMask, 0, REG_DWORD, (char*)&val, sizeof(val));
151
152     val = cfg->quick_edit;
153     RegSetValueEx(hConKey, wszQuickEdit, 0, REG_DWORD, (char*)&val, sizeof(val));
154
155     val = MAKELONG(cfg->sb_width, cfg->sb_height);
156     RegSetValueEx(hConKey, wszScreenBufferSize, 0, REG_DWORD, (char*)&val, sizeof(val));
157
158     val = cfg->def_attr;
159     RegSetValueEx(hConKey, wszScreenColors, 0, REG_DWORD, (char*)&val, sizeof(val));
160
161     val = MAKELONG(cfg->win_width, cfg->win_height);
162     RegSetValueEx(hConKey, wszWindowSize, 0, REG_DWORD, (char*)&val, sizeof(val));
163
164     RegCloseKey(hConKey);
165     return TRUE;
166 }