Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / setup_native / source / win32 / customactions / reg4msdoc / registrationcontextinformation.cxx
blob89d82d4e6033d3acae5be8cfaa54c625673f992d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 //Implementierung der Klasse RegistrationContextInformation.
4 #include "registrationcontextinformation.hxx"
5 #include "msihelper.hxx"
7 #define WINDOWS_LEAN_AND_MEAN
8 #include <windows.h>
9 #include <assert.h>
10 #include <algorithm>
12 namespace /* private */
14 const int MAX_REGKEY_LENGTH_WIN9X = 16300;
17 RegistrationContextInformation::RegistrationContextInformation(MSIHANDLE hMsi, const std::wstring& OpenOfficeExecutablePath) :
18 msihandle_(hMsi),
19 m_OOExecPath(OpenOfficeExecutablePath)
21 assert(m_OOExecPath.length());
22 ExtractOpenOfficeExecNameFromPath();
23 m_OOIconPath = m_OOExecPath.replace(m_OOExecPath.find(m_OOExecName), m_OOExecName.size(), std::wstring(TEXT("soffice.bin")));
26 std::wstring RegistrationContextInformation::GetWordDocumentDisplayName() const
28 std::wstring str;
29 GetMsiProp(msihandle_, TEXT("STR_MS_WORD_DOCUMENT"), str);
30 return str;
33 std::wstring RegistrationContextInformation::GetWordDocumentFileExtension() const
35 return std::wstring(TEXT(".doc"));
38 std::wstring RegistrationContextInformation::GetWordDocumentDefaultIconEntry() const
40 return m_OOIconPath + std::wstring(TEXT(",1"));
43 std::wstring RegistrationContextInformation::GetWordDocumentDefaultShellCommand() const
45 return std::wstring(TEXT("open"));
48 std::wstring RegistrationContextInformation::GetMOOXWordDocumentDisplayName() const
50 std::wstring str;
51 str = TEXT("Microsoft Word 2007 Document");
52 return str;
55 std::wstring RegistrationContextInformation::GetMOOXWordDocumentFileExtension() const
57 return std::wstring(TEXT(".docx"));
60 std::wstring RegistrationContextInformation::GetWordTemplateDisplayName() const
62 std::wstring str;
63 GetMsiProp(msihandle_, TEXT("STR_MS_WORD_TEMPLATE"), str);
64 return str;
67 std::wstring RegistrationContextInformation::GetWordTemplateFileExtension() const
69 return std::wstring(TEXT(".dot"));
72 std::wstring RegistrationContextInformation::GetWordTemplateDefaultIconEntry() const
74 return m_OOIconPath + std::wstring(TEXT(",2"));
77 std::wstring RegistrationContextInformation::GetWordTemplateDefaultShellCommand() const
79 return std::wstring(TEXT("new"));
82 std::wstring RegistrationContextInformation::GetRtfDocumentDisplayName() const
84 std::wstring str;
85 GetMsiProp(msihandle_, TEXT("STR_RTF_DOCUMENT"), str);
86 return str;
89 std::wstring RegistrationContextInformation::GetRtfDocumentFileExtension() const
91 return std::wstring(TEXT(".rtf"));
94 std::wstring RegistrationContextInformation::GetRtfDocumentDefaultIconEntry() const
96 return m_OOIconPath + std::wstring(TEXT(",1"));
99 std::wstring RegistrationContextInformation::GetRtfDocumentDefaultShellCommand() const
101 return std::wstring(TEXT("open"));
104 std::wstring RegistrationContextInformation::GetExcelSheetDisplayName() const
106 std::wstring str;
107 GetMsiProp(msihandle_, TEXT("STR_MS_EXCEL_WORKSHEET"), str);
108 return str;
111 std::wstring RegistrationContextInformation::GetExcelSheetFileExtension() const
113 return std::wstring(TEXT(".xls"));
116 std::wstring RegistrationContextInformation::GetExcelSheetDefaultIconEntry() const
118 return m_OOIconPath + std::wstring(TEXT(",3"));
121 std::wstring RegistrationContextInformation::GetExcelSheetDefaultShellCommand() const
123 return std::wstring(TEXT("open"));
126 std::wstring RegistrationContextInformation::GetMOOXExcelSheetDisplayName() const
128 std::wstring str;
129 str = TEXT("Microsoft Excel 2007 Spreadsheet");
130 return str;
133 std::wstring RegistrationContextInformation::GetMOOXExcelSheetFileExtension() const
135 return std::wstring(TEXT(".xlsx"));
138 std::wstring RegistrationContextInformation::GetExcelTemplateDisplayName() const
140 std::wstring str;
141 GetMsiProp(msihandle_, TEXT("STR_MS_EXCEL_TEMPLATE"), str);
142 return str;
145 std::wstring RegistrationContextInformation::GetExcelTemplateFileExtension() const
147 return std::wstring(TEXT(".xlt"));
150 std::wstring RegistrationContextInformation::GetExcelTemplateDefaultIconEntry() const
152 return m_OOIconPath + std::wstring(TEXT(",4"));
155 std::wstring RegistrationContextInformation::GetExcelTemplateDefaultShellCommand() const
157 return std::wstring(TEXT("new"));
160 std::wstring RegistrationContextInformation::GetPowerPointDocumentDisplayName() const
162 std::wstring str;
163 GetMsiProp(msihandle_, TEXT("STR_MS_POWERPOINT_PRESENTATION"), str);
164 return str;
167 std::wstring RegistrationContextInformation::GetPowerPointDocumentFileExtension() const
169 return std::wstring(TEXT(".ppt"));
172 std::wstring RegistrationContextInformation::GetPowerPointDocumentDefaultIconEntry() const
174 return m_OOIconPath + std::wstring(TEXT(",7"));
177 std::wstring RegistrationContextInformation::GetPowerPointDocumentDefaultShellCommand() const
179 return std::wstring(TEXT("open"));
182 std::wstring RegistrationContextInformation::GetMOOXPowerPointDocumentDisplayName() const
184 std::wstring str;
185 str = TEXT("Microsoft PowerPoint 2007 Presentation");
186 return str;
189 std::wstring RegistrationContextInformation::GetMOOXPowerPointDocumentFileExtension() const
191 return std::wstring(TEXT(".pptx"));
194 std::wstring RegistrationContextInformation::GetPowerPointTemplateDisplayName() const
196 std::wstring str;
197 GetMsiProp(msihandle_, TEXT("STR_MS_POWERPOINT_TEMPLATE"), str);
198 return str;
201 std::wstring RegistrationContextInformation::GetPowerPointTemplateFileExtension() const
203 return std::wstring(TEXT(".pot"));
206 std::wstring RegistrationContextInformation::GetPowerPointTemplateDefaultIconEntry() const
208 return m_OOIconPath + std::wstring(TEXT(",8"));
211 std::wstring RegistrationContextInformation::GetPowerPointTemplateDefaultShellCommand() const
213 return std::wstring(TEXT("new"));
216 std::wstring RegistrationContextInformation::GetPowerPointShowDisplayName() const
218 std::wstring str;
219 GetMsiProp(msihandle_, TEXT("STR_MS_POWERPOINT_SHOW"), str);
220 return str;
223 std::wstring RegistrationContextInformation::GetPowerPointShowFileExtension() const
225 return std::wstring(TEXT(".pps"));
228 std::wstring RegistrationContextInformation::GetPowerPointShowDefaultIconEntry() const
230 return m_OOIconPath + std::wstring(TEXT(",7"));
233 std::wstring RegistrationContextInformation::GetPowerPointShowDefaultShellCommand() const
235 return std::wstring(TEXT("open"));
238 //----------------------------------------------
239 /** The string for the "New" command that should appear
240 in the Explorer context menu when someone right
241 clicks a Microsoft document
243 std::wstring RegistrationContextInformation::ShellNewCommandDisplayName() const
245 std::wstring str;
246 GetMsiProp(msihandle_, TEXT("STR_NEW_DISPLAY_NAME"), str);
247 std::wstring::size_type idx = str.find(TEXT("~"));
249 if(std::wstring::npos != idx)
250 str.replace(idx, 1, TEXT("&"));
252 return str;
255 /** The string for the "Edit" command that should
256 appear in the Explorer context menu when someone
257 right clicks a document
259 std::wstring RegistrationContextInformation::ShellEditCommandDisplayName() const
261 std::wstring str;
262 GetMsiProp(msihandle_, TEXT("STR_EDIT"), str);
263 std::wstring::size_type idx = str.find(TEXT("~"));
265 if(std::wstring::npos != idx)
266 str.replace(idx, 1, TEXT("&"));
268 return str;
271 std::wstring RegistrationContextInformation::GetOpenOfficeFriendlyAppName() const
273 std::wstring str;
274 GetMsiProp(msihandle_, TEXT("ProductName"), str);
275 return str;
278 std::wstring RegistrationContextInformation::GetOpenOfficeExecutablePath() const
280 return m_OOExecPath;
283 //----------------------------------------------
284 /** The name of the executable (currently "soffice.exe"
285 but may change in the future, who knows) */
286 std::wstring RegistrationContextInformation::GetOpenOfficeExecutableName() const
288 return m_OOExecName;
291 /** A command line for the specified shell command */
292 std::wstring RegistrationContextInformation::GetOpenOfficeCommandline(SHELL_COMMAND ShellCommand,
293 OFFICE_APPLICATION OfficeApp) const
295 // quote the path to OpenOffice, this is important
296 // for Windows 9x
297 std::wstring cmd_line = std::wstring(TEXT("\"")) + m_OOExecPath + std::wstring(TEXT("\""));
299 switch( OfficeApp )
301 case Writer:
302 cmd_line += std::wstring( TEXT( " -writer" ) );
303 break;
304 case Calc:
305 cmd_line += std::wstring( TEXT( " -calc" ) );
306 break;
307 case Impress:
308 cmd_line += std::wstring( TEXT( " -impress" ) );
309 break;
310 case Office: // default to std command line
311 break;
312 // default: no default to find new added enums at compile time
314 switch(ShellCommand)
316 case New:
317 cmd_line += std::wstring(TEXT(" -n \"%1\""));
318 break;
319 case Open:
320 cmd_line += std::wstring(TEXT(" -o \"%1\""));
321 break;
322 case Print:
323 cmd_line += std::wstring(TEXT(" -p \"%1\""));
324 break;
325 case Printto:
326 cmd_line += std::wstring(TEXT(" -pt \"%2\" \"%1\""));
327 break;
328 // default: no default to find new added enums at compile time
330 return cmd_line;
333 void RegistrationContextInformation::ExtractOpenOfficeExecNameFromPath()
335 std::wstring::size_type idx = m_OOExecPath.find_last_of(TEXT('\\'));
336 assert(idx != std::wstring::npos); // assert valid path
337 m_OOExecName = m_OOExecPath.substr(idx + 1);
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */