]> git.lyx.org Git - lyx.git/blob - src/support/os_unix.cpp
This optional argument to the InsetCollapsable constructor
[lyx.git] / src / support / os_unix.cpp
1 /**
2  * \file os_unix.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Ruurd A. Reitsma
7  *
8  * Full author contact details are available in file CREDITS.
9  *
10  * Various OS specific functions
11  */
12
13 #include <config.h>
14
15 #include "support/os.h"
16 #include "support/docstring.h"
17 #include "support/FileName.h"
18
19 #ifdef __APPLE__
20 #include <Carbon/Carbon.h>
21 #endif
22
23 using namespace std;
24
25 namespace lyx {
26 namespace support {
27 namespace os {
28
29 void init(int, char *[])
30 {}
31
32
33 string current_root()
34 {
35         return "/";
36 }
37
38
39 bool isFilesystemCaseSensitive()
40 {
41 #ifdef __APPLE__
42         return false;
43 #else
44         return true;
45 #endif
46 }
47
48
49 docstring::size_type common_path(docstring const & p1, docstring const & p2)
50 {
51         docstring::size_type i = 0;
52         docstring::size_type const p1_len = p1.length();
53         docstring::size_type const p2_len = p2.length();
54         while (i < p1_len && i < p2_len && p1[i] == p2[i])
55                 ++i;
56         if ((i < p1_len && i < p2_len)
57             || (i < p1_len && p1[i] != '/' && i == p2_len)
58             || (i < p2_len && p2[i] != '/' && i == p1_len))
59         {
60                 if (i)
61                         --i;     // here was the last match
62                 while (i && p1[i] != '/')
63                         --i;
64         }
65         return i;
66 }
67
68
69 string external_path(string const & p)
70 {
71         return p;
72 }
73
74
75 string internal_path(string const & p)
76 {
77         return p;
78 }
79
80
81 string external_path_list(string const & p)
82 {
83         return p;
84 }
85
86
87 string internal_path_list(string const & p)
88 {
89         return p;
90 }
91
92
93 string latex_path(string const & p)
94 {
95         return p;
96 }
97
98
99 char const * popen_read_mode()
100 {
101         return "r";
102 }
103
104
105 string const & nulldev()
106 {
107         static string const nulldev_ = "/dev/null";
108         return nulldev_;
109 }
110
111
112 shell_type shell()
113 {
114         return UNIX;
115 }
116
117
118 char path_separator()
119 {
120         return ':';
121 }
122
123
124 void windows_style_tex_paths(bool)
125 {}
126
127 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
128 {
129 #ifdef __APPLE__
130 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
131         CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
132                                         (UInt8 *) ext.c_str(), ext.length(),
133                                         kCFStringEncodingISOLatin1, false);
134         // this is what we would like to do but it seems that the
135         // viewer for PDF is often quicktime...
136         //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer :  kLSRolesEditor;
137         (void)mode;
138         LSRolesMask role = kLSRolesAll;
139         FSRef outAppRef;
140         OSStatus status =
141                 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
142                                         cfs_ext, role, &outAppRef, NULL);
143         CFRelease(cfs_ext);
144
145         return status != kLSApplicationNotFoundErr;
146 #else
147         // silence compiler warnings
148         (void)ext;
149         (void)mode;
150
151         // currently, no default viewer is tried for non-windows system
152         // support for KDE/Gnome/Macintosh may be added later
153         return false;
154 #endif
155 }
156
157
158 bool autoOpenFile(string const & filename, auto_open_mode const mode)
159 {
160 #ifdef __APPLE__
161 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
162         FSRef fileref;
163         OSStatus status =
164                 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
165         if (status != 0)
166                 return false;
167
168         // this is what we would like to do but it seems that the
169         // viewer for PDF is often quicktime...
170         //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer :  kLSRolesEditor;
171         (void)mode;
172         LSRolesMask role = kLSRolesAll;
173         FSRef outAppRef;
174
175         status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
176         if (status == kLSApplicationNotFoundErr)
177                 return false;
178
179         LSLaunchFSRefSpec inLaunchSpec;
180         inLaunchSpec.appRef = &outAppRef;
181         inLaunchSpec.numDocs = 1;
182         inLaunchSpec.itemRefs = &fileref;
183         inLaunchSpec.passThruParams = NULL;
184         inLaunchSpec.launchFlags = kLSLaunchDefaults;
185         inLaunchSpec.asyncRefCon = NULL;
186         status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
187
188         return status != kLSApplicationNotFoundErr;
189 #else
190         // silence compiler warnings
191         (void)filename;
192         (void)mode;
193
194         // currently, no default viewer is tried for non-windows system
195         // support for KDE/Gnome/Macintosh may be added later
196         return false;
197 #endif
198 }
199
200 } // namespace os
201 } // namespace support
202 } // namespace lyx