3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Ruurd A. Reitsma
8 * Full author contact details are available in file CREDITS.
10 * Various OS specific functions
15 #include "support/os.h"
19 #include <Carbon/Carbon.h>
20 #include <ApplicationServices/ApplicationServices.h>
31 void init(int, char *[])
41 docstring::size_type common_path(docstring const & p1, docstring const & p2)
43 docstring::size_type i = 0;
44 docstring::size_type const p1_len = p1.length();
45 docstring::size_type const p2_len = p2.length();
46 while (i < p1_len && i < p2_len && p1[i] == p2[i])
48 if ((i < p1_len && i < p2_len)
49 || (i < p1_len && p1[i] != '/' && i == p2_len)
50 || (i < p2_len && p2[i] != '/' && i == p1_len))
53 --i; // here was the last match
54 while (i && p1[i] != '/')
61 string external_path(string const & p)
67 string internal_path(string const & p)
73 string external_path_list(string const & p)
79 string internal_path_list(string const & p)
85 string latex_path(string const & p)
91 bool is_absolute_path(string const & p)
93 return !p.empty() && p[0] == '/';
97 char const * popen_read_mode()
103 string const & nulldev()
105 static string const nulldev_ = "/dev/null";
116 char path_separator()
122 void windows_style_tex_paths(bool)
125 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
128 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
129 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
130 (UInt8 *) ext.c_str(), ext.length(),
131 kCFStringEncodingISOLatin1, false);
132 // this is what we would like to do but it seems that the
133 // viewer for PDF is often quicktime...
134 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
136 LSRolesMask role = kLSRolesAll;
139 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
140 cfs_ext, role, &outAppRef, NULL);
143 return status != kLSApplicationNotFoundErr;
145 // silence compiler warnings
149 // currently, no default viewer is tried for non-windows system
150 // support for KDE/Gnome/Macintosh may be added later
156 bool autoOpenFile(string const & filename, auto_open_mode const mode)
159 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
162 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
166 // this is what we would like to do but it seems that the
167 // viewer for PDF is often quicktime...
168 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
170 LSRolesMask role = kLSRolesAll;
173 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
174 if (status == kLSApplicationNotFoundErr)
177 LSLaunchFSRefSpec inLaunchSpec;
178 inLaunchSpec.appRef = &outAppRef;
179 inLaunchSpec.numDocs = 1;
180 inLaunchSpec.itemRefs = &fileref;
181 inLaunchSpec.passThruParams = NULL;
182 inLaunchSpec.launchFlags = kLSLaunchDefaults;
183 inLaunchSpec.asyncRefCon = NULL;
184 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
186 return status != kLSApplicationNotFoundErr;
188 // silence compiler warnings
192 // currently, no default viewer is tried for non-windows system
193 // support for KDE/Gnome/Macintosh may be added later
199 void addFontResources()
202 CFBundleRef myAppBundle = CFBundleGetMainBundle();
203 CFURLRef myAppResourcesURL, FontsURL;
206 CFStringRef filePath = CFStringCreateWithBytes(kCFAllocatorDefault,
207 (UInt8 *) "fonts", strlen("fonts"),
208 kCFStringEncodingISOLatin1, false);
210 myAppResourcesURL = CFBundleCopyResourcesDirectoryURL(myAppBundle);
211 FontsURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault,
212 myAppResourcesURL, filePath, true);
213 if (lyxerr.debugging(Debug::FONT)) {
215 if (CFURLGetFileSystemRepresentation(FontsURL, true, buf, 255))
216 lyxerr << "Adding Fonts directory: " << buf << endl;
218 CFURLGetFSRef (FontsURL, &fontDirRef);
219 OSStatus err = FSGetCatalogInfo (&fontDirRef, kFSCatInfoNone,
220 NULL, NULL, &fontDirSpec, NULL);
222 lyxerr << "FSGetCatalogInfo err = " << err << endl;
223 err = FMActivateFonts (&fontDirSpec, NULL, NULL,
224 kFMLocalActivationContext);
226 lyxerr << "FMActivateFonts err = " << err << endl;
231 void restoreFontResources()
235 } // namespace support