2 /* implements Mac OS X specific functions */
3 #include "display-gtk.h"
4 #include <CoreFoundation/CoreFoundation.h>
5 #include <mach-o/dyld.h>
6 #include "gtkosxapplication.h"
8 static GtkOSXApplication *osx_app;
10 /* macos defines CFSTR to create a CFString object from a constant,
11 * but no similar macros if a C string variable is supposed to be
12 * the argument. We add this here (hardcoding the default allocator
13 * and MacRoman encoding */
14 #define CFSTR_VAR(_var) CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, \
15 (_var), kCFStringEncodingMacRoman, \
18 #define SUBSURFACE_PREFERENCES CFSTR("org.hohndel.subsurface")
19 #define ICON_NAME "Subsurface.icns"
20 #define UI_FONT "Arial Unicode MS 12"
21 #define DIVELIST_MAC_DEFAULT_FONT "Arial Unicode MS 9"
23 void subsurface_open_conf(void)
25 /* nothing at this time */
28 void subsurface_set_conf(char *name, pref_type_t type, const void *value)
32 CFPreferencesSetAppValue(CFSTR_VAR(name),
33 value == NULL ? kCFBooleanFalse : kCFBooleanTrue, SUBSURFACE_PREFERENCES);
36 CFPreferencesSetAppValue(CFSTR_VAR(name), CFSTR_VAR(value), SUBSURFACE_PREFERENCES);
40 const void *subsurface_get_conf(char *name, pref_type_t type)
43 CFPropertyListRef strpref;
47 boolpref = CFPreferencesGetAppBooleanValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES, FALSE);
53 strpref = CFPreferencesCopyAppValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES);
56 return CFStringGetCStringPtr(strpref, kCFStringEncodingMacRoman);
58 /* we shouldn't get here, but having this line makes the compiler happy */
62 void subsurface_flush_conf(void)
64 int ok = CFPreferencesAppSynchronize(SUBSURFACE_PREFERENCES);
66 fprintf(stderr,"Could not save preferences\n");
69 void subsurface_close_conf(void)
74 const char *subsurface_USB_name()
76 return "/dev/tty.SLAB_USBtoUART";
79 const char *subsurface_icon_name()
81 static char path[1024];
83 snprintf(path, 1024, "%s/%s", quartz_application_get_resource_path(), ICON_NAME);
88 void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
89 GtkWidget *vbox, GtkUIManager *ui_manager)
91 GtkWidget *menu_item, *sep;
94 divelist_font = DIVELIST_MAC_DEFAULT_FONT;
95 g_object_set(G_OBJECT(settings), "gtk-font-name", UI_FONT, NULL);
97 osx_app = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
98 gtk_widget_hide (menubar);
99 gtk_osxapplication_set_menu_bar(osx_app, GTK_MENU_SHELL(menubar));
101 sep = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/FileMenu/Separator2");
103 gtk_widget_destroy(sep);
105 menu_item = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/FileMenu/Quit");
106 gtk_widget_hide (menu_item);
107 menu_item = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/Help/About");
108 gtk_osxapplication_insert_app_menu_item(osx_app, menu_item, 0);
110 sep = gtk_separator_menu_item_new();
112 gtk_osxapplication_insert_app_menu_item (osx_app, sep, 1);
114 menu_item = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/FileMenu/Preferences");
115 gtk_osxapplication_insert_app_menu_item(osx_app, menu_item, 2);
117 sep = gtk_separator_menu_item_new();
119 gtk_osxapplication_insert_app_menu_item (osx_app, sep, 3);
121 gtk_osxapplication_set_use_quartz_accelerators(osx_app, TRUE);
122 gtk_osxapplication_ready(osx_app);