]> git.tdb.fi Git - ext/subsurface.git/blob - windows.c
Fix profile and average depth for freedives
[ext/subsurface.git] / windows.c
1 /* windows.c */
2 /* implements Windows specific functions */
3 #include "display-gtk.h"
4 #include <windows.h>
5 #define DIVELIST_DEFAULT_FONT "Sans 8"
6
7 static HKEY hkey;
8
9 static int get_from_registry(HKEY hkey, const char *key)
10 {
11         DWORD value;
12         DWORD len = 4;
13         LONG success;
14
15         success = RegQueryValueEx(hkey, (LPCTSTR)TEXT(key), NULL, NULL,
16                                 (LPBYTE) &value, (LPDWORD)&len );
17         if (success != ERROR_SUCCESS)
18                 return FALSE; /* that's what happens the first time we start */
19         return value;
20 }
21
22 void subsurface_open_conf(void)
23 {
24         LONG success;
25
26         success = RegCreateKeyEx(HKEY_CURRENT_USER, (LPCTSTR)TEXT("Software\\subsurface"),
27                                 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
28                                 NULL, &hkey, NULL);
29         if (success != ERROR_SUCCESS)
30                 printf("CreateKey Software\\subsurface failed %ld\n", success);
31 }
32
33 void subsurface_set_conf(char *name, pref_type_t type, const void *value)
34 {
35         /* since we are using the pointer 'value' as both an actual
36          * pointer to the string setting and as a way to pass the
37          * numbers 0 and 1 to this function for booleans, one of the
38          * calls to RegSetValueEx needs to pass &value (when we want
39          * to pass the boolean value), the other one passes value (the
40          * address of the string. */
41         switch (type) {
42         case PREF_BOOL:
43                 /* we simply store the value as DWORD */
44                 RegSetValueEx(hkey, (LPCTSTR)TEXT(name), 0, REG_DWORD, (const BYTE *)&value, 4);
45                 break;
46         case PREF_STRING:
47                 RegSetValueEx(hkey, (LPCTSTR)TEXT(name), 0, REG_SZ, (const BYTE *)value, strlen(value));
48         }
49 }
50
51 const void *subsurface_get_conf(char *name, pref_type_t type)
52 {
53         LONG success;
54         char *string;
55         int len;
56
57         switch (type) {
58         case PREF_BOOL:
59                 return get_from_registry(hkey, name) ? (void *) 1 : NULL;
60         case PREF_STRING:
61                 string = malloc(80);
62                 len = 80;
63                 success = RegQueryValueEx(hkey, (LPCTSTR)TEXT(name), NULL, NULL,
64                                         (LPBYTE) string, (LPDWORD)&len );
65                 if (success != ERROR_SUCCESS) {
66                         /* that's what happens the first time we start - just return NULL */
67                         free(string);
68                         return NULL;
69                 }
70                 return string;
71         }
72         /* we shouldn't get here */
73         return NULL;
74 }
75
76 void subsurface_flush_conf(void)
77 {
78         /* this is a no-op */
79 }
80
81 void subsurface_close_conf(void)
82 {
83         RegCloseKey(hkey);
84 }
85
86 const char *subsurface_USB_name()
87 {
88         return "COM3";
89 }
90
91 const char *subsurface_icon_name()
92 {
93         return "subsurface.ico";
94 }
95
96 void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
97                 GtkWidget *vbox, GtkUIManager *ui_manager)
98 {
99         if (!divelist_font)
100                 divelist_font = DIVELIST_DEFAULT_FONT;
101         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
102 }