From 30da68bc7b42a960ac0bcb38ed5b82cce9af1ef0 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Mon, 29 May 2017 11:06:59 +0200 Subject: iOS, LOkit link problems solved .swift -> .c -> LibreOfficeKit does not work (LOkit is compiled with C++) changed to .swift -> .mm -> LibreOfficeKit Change-Id: I4d4684876ca21534389189a431fcaadbbac78d3f --- .../LibreOfficeLight.xcodeproj/project.pbxproj | 38 +-- .../LibreOfficeLight/AppDelegate.swift | 2 +- .../LibreOfficeLight/en.lproj/InfoPlist.strings | 2 + .../LibreOfficeLight/lokit-Bridging-Header.h | 4 +- .../LibreOfficeLight/LibreOfficeLight/lokit.c | 329 ------------------- .../LibreOfficeLight/LibreOfficeLight/lokit.mm | 351 +++++++++++++++++++++ 6 files changed, 374 insertions(+), 352 deletions(-) create mode 100644 ios/experimental/LibreOfficeLight/LibreOfficeLight/en.lproj/InfoPlist.strings delete mode 100755 ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit.c create mode 100755 ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit.mm (limited to 'ios/experimental') diff --git a/ios/experimental/LibreOfficeLight/LibreOfficeLight.xcodeproj/project.pbxproj b/ios/experimental/LibreOfficeLight/LibreOfficeLight.xcodeproj/project.pbxproj index 2b395c08a596..31a667b88560 100644 --- a/ios/experimental/LibreOfficeLight/LibreOfficeLight.xcodeproj/project.pbxproj +++ b/ios/experimental/LibreOfficeLight/LibreOfficeLight.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 39022C181EDC142F00100066 /* lokit.mm in Sources */ = {isa = PBXBuildFile; fileRef = 39022C171EDC142F00100066 /* lokit.mm */; }; 392ED9B31E5E4B03005C8435 /* ViewPrintManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 392ED9B21E5E4B03005C8435 /* ViewPrintManager.swift */; }; 396F92F71E7AE62400A28C82 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 396F92F61E7AE62400A28C82 /* Settings.bundle */; }; 397868D61E59A3EA007F9248 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 397868D81E59A3EA007F9248 /* LaunchScreen.xib */; }; @@ -19,8 +20,6 @@ 3992D85D1E5B764A00BEA987 /* SideMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3992D85B1E5B764A00BEA987 /* SideMenu.swift */; }; 3992D85E1E5B764A00BEA987 /* FileManagerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3992D85C1E5B764A00BEA987 /* FileManagerController.swift */; }; 399648471E5B87DC00E73E83 /* ViewProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 399648461E5B87DC00E73E83 /* ViewProperties.swift */; }; - 39A83A8F1E5F471D00D0C683 /* lokit.c in Sources */ = {isa = PBXBuildFile; fileRef = 39A83A8E1E5F471D00D0C683 /* lokit.c */; }; - 39B084E31E5F0A9600682A59 /* lo.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 39B084E21E5F0A9600682A59 /* lo.xcconfig */; }; 39B08B9D1E5F0BB600682A59 /* fundamentalrc in Resources */ = {isa = PBXBuildFile; fileRef = 39B084E51E5F0BB400682A59 /* fundamentalrc */; }; 39B08B9E1E5F0BB600682A59 /* offapi.rdb in Resources */ = {isa = PBXBuildFile; fileRef = 39B084E61E5F0BB400682A59 /* offapi.rdb */; }; 39B08B9F1E5F0BB600682A59 /* oovbaapi.rdb in Resources */ = {isa = PBXBuildFile; fileRef = 39B084E71E5F0BB400682A59 /* oovbaapi.rdb */; }; @@ -48,6 +47,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 39022C171EDC142F00100066 /* lokit.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = lokit.mm; sourceTree = ""; }; + 39022C191EDC14D300100066 /* lokit-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "lokit-Bridging-Header.h"; sourceTree = ""; }; 392ED9B21E5E4B03005C8435 /* ViewPrintManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ViewPrintManager.swift; path = LibreOfficeLight/ViewPrintManager.swift; sourceTree = SOURCE_ROOT; }; 396F92F61E7AE62400A28C82 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = ""; }; 397275391E77D9F1006ACDCC /* LibreOfficeLight.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LibreOfficeLight.entitlements; sourceTree = ""; }; @@ -67,8 +68,6 @@ 3992D85B1E5B764A00BEA987 /* SideMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SideMenu.swift; path = LibreOfficeLight/SideMenu.swift; sourceTree = SOURCE_ROOT; }; 3992D85C1E5B764A00BEA987 /* FileManagerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FileManagerController.swift; path = LibreOfficeLight/FileManagerController.swift; sourceTree = SOURCE_ROOT; }; 399648461E5B87DC00E73E83 /* ViewProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ViewProperties.swift; path = LibreOfficeLight/ViewProperties.swift; sourceTree = SOURCE_ROOT; }; - 39A83A8D1E5F471C00D0C683 /* lokit-Bridging-Header.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; name = "lokit-Bridging-Header.h"; path = "LibreOfficeLight/lokit-Bridging-Header.h"; sourceTree = SOURCE_ROOT; }; - 39A83A8E1E5F471D00D0C683 /* lokit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = lokit.c; path = LibreOfficeLight/lokit.c; sourceTree = SOURCE_ROOT; }; 39B084E21E5F0A9600682A59 /* lo.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = lo.xcconfig; path = "../../../../ios-work/workdir/ios/generated/lo.xcconfig"; sourceTree = SOURCE_ROOT; }; 39B084E51E5F0BB400682A59 /* fundamentalrc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = fundamentalrc; path = "../../../../ios-work/workdir/ios/resources/fundamentalrc"; sourceTree = SOURCE_ROOT; }; 39B084E61E5F0BB400682A59 /* offapi.rdb */ = {isa = PBXFileReference; lastKnownFileType = file; name = offapi.rdb; path = "../../../../ios-work/workdir/ios/resources/offapi.rdb"; sourceTree = SOURCE_ROOT; }; @@ -152,7 +151,8 @@ 397E08FC1E597BD8001374E0 /* LibreOfficeLight */ = { isa = PBXGroup; children = ( - 39A83A8E1E5F471D00D0C683 /* lokit.c */, + 39022C191EDC14D300100066 /* lokit-Bridging-Header.h */, + 39022C171EDC142F00100066 /* lokit.mm */, 397E08FD1E597BD8001374E0 /* AppDelegate.swift */, 3992D85B1E5B764A00BEA987 /* SideMenu.swift */, 3992D8591E5B762A00BEA987 /* DocumentController.swift */, @@ -161,7 +161,6 @@ 399648461E5B87DC00E73E83 /* ViewProperties.swift */, 397E09011E597BD8001374E0 /* Main.storyboard */, 397868D81E59A3EA007F9248 /* LaunchScreen.xib */, - 39A83A8D1E5F471C00D0C683 /* lokit-Bridging-Header.h */, ); path = LibreOfficeLight; sourceTree = SOURCE_ROOT; @@ -261,7 +260,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0820; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0830; ORGANIZATIONNAME = jani; TargetAttributes = { 397E08F91E597BD8001374E0 = { @@ -317,7 +316,6 @@ 397E09081E597BD8001374E0 /* Assets.xcassets in Resources */, 39B08BD71E5F0BB600682A59 /* rc in Resources */, 39B08B9E1E5F0BB600682A59 /* offapi.rdb in Resources */, - 39B084E31E5F0A9600682A59 /* lo.xcconfig in Resources */, 397868D61E59A3EA007F9248 /* LaunchScreen.xib in Resources */, 396F92F71E7AE62400A28C82 /* Settings.bundle in Resources */, 39B08B9F1E5F0BB600682A59 /* oovbaapi.rdb in Resources */, @@ -355,8 +353,8 @@ 399648471E5B87DC00E73E83 /* ViewProperties.swift in Sources */, 3992D85E1E5B764A00BEA987 /* FileManagerController.swift in Sources */, 3992D85A1E5B762A00BEA987 /* DocumentController.swift in Sources */, + 39022C181EDC142F00100066 /* lokit.mm in Sources */, 397E08FE1E597BD8001374E0 /* AppDelegate.swift in Sources */, - 39A83A8F1E5F471D00D0C683 /* lokit.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -477,6 +475,10 @@ IPHONEOS_DEPLOYMENT_TARGET = 10.2; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = ( + "$(LINK_LDFLAGS)", + "-lstdc++", + ); SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -542,6 +544,10 @@ IPHONEOS_DEPLOYMENT_TARGET = 10.2; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = ( + "$(LINK_LDFLAGS)", + "-lstdc++", + ); SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; @@ -553,10 +559,6 @@ isa = XCBuildConfiguration; baseConfigurationReference = 39B084E21E5F0A9600682A59 /* lo.xcconfig */; buildSettings = { - ARCHS = ( - "$(ARCHS_STANDARD)", - i386, - ); ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CLANG_WARN_DOCUMENTATION_COMMENTS = NO; @@ -569,12 +571,13 @@ GCC_SYMBOLS_PRIVATE_EXTERN = NO; INFOPLIST_FILE = LibreOfficeLight/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + OTHER_LDFLAGS = "$(LINK_LDFLAGS)"; PRODUCT_BUNDLE_IDENTIFIER = com.jani.Editors.LibreOfficeLight; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "LibreOfficeLight/lokit-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 3.0; - VALID_ARCHS = "i386 $(ARCHS_STANDARD)"; + VALID_ARCHS = i386; }; name = Debug; }; @@ -582,10 +585,6 @@ isa = XCBuildConfiguration; baseConfigurationReference = 39B084E21E5F0A9600682A59 /* lo.xcconfig */; buildSettings = { - ARCHS = ( - "$(ARCHS_STANDARD)", - i386, - ); ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CLANG_WARN_DOCUMENTATION_COMMENTS = NO; @@ -599,11 +598,12 @@ INFOPLIST_FILE = LibreOfficeLight/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = "$(LINK_LDFLAGS)"; PRODUCT_BUNDLE_IDENTIFIER = com.jani.Editors.LibreOfficeLight; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "LibreOfficeLight/lokit-Bridging-Header.h"; SWIFT_VERSION = 3.0; - VALID_ARCHS = "i386 $(ARCHS_STANDARD)"; + VALID_ARCHS = i386; }; name = Release; }; diff --git a/ios/experimental/LibreOfficeLight/LibreOfficeLight/AppDelegate.swift b/ios/experimental/LibreOfficeLight/LibreOfficeLight/AppDelegate.swift index e50e462939aa..97693370478a 100644 --- a/ios/experimental/LibreOfficeLight/LibreOfficeLight/AppDelegate.swift +++ b/ios/experimental/LibreOfficeLight/LibreOfficeLight/AppDelegate.swift @@ -24,7 +24,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // start LibreOfficeKit - BridgeLOkit_Init() + BridgeLOkit_Init(Bundle.main.bundlePath) // Get version info let appInfo = Bundle.main.infoDictionary! as Dictionary diff --git a/ios/experimental/LibreOfficeLight/LibreOfficeLight/en.lproj/InfoPlist.strings b/ios/experimental/LibreOfficeLight/LibreOfficeLight/en.lproj/InfoPlist.strings new file mode 100644 index 000000000000..477b28ff8f86 --- /dev/null +++ b/ios/experimental/LibreOfficeLight/LibreOfficeLight/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit-Bridging-Header.h b/ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit-Bridging-Header.h index 2591dd90ae1d..9254f96c3545 100644 --- a/ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit-Bridging-Header.h +++ b/ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit-Bridging-Header.h @@ -6,8 +6,6 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // - // Bridge functions to LibreOfficeKit -int BridgeLOkit_Init(); +int BridgeLOkit_Init(const char *path); int BridgeLOkit_ClientCommand(const char *input); - diff --git a/ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit.c b/ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit.c deleted file mode 100755 index ec566a6e78ee..000000000000 --- a/ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit.c +++ /dev/null @@ -1,329 +0,0 @@ -// -// This file is part of the LibreOffice project. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -#include -#define LOK_USE_UNSTABLE_API -#include - -// pointers to our instance -static LibreOfficeKit* kit; -static LibreOfficeKitDocument* document; - - -// Bridge functions to LibreOfficeKit -int BridgeLOkit_Init() -{ - // Initialize LibreOfficeKit - kit = lok_init(NULL); - return 0; -} - - -int LOkit_open(char *file) -{ - document = kit->pClass->documentLoad(kit, file); - document->pClass->initializeForRendering(document, ""); - return 0; -} - - -#if 0 -// createpath from tiled -static NSString *createPaths(NSString *base, NSString *appRootEscaped, NSArray *fileNames) -{ - NSString *result; - NSString *prefix = @"file://"; - BOOL first = YES; - - result = base; - for (NSString *fileName in fileNames) { - result = [result stringByAppendingString: prefix]; - result = [result stringByAppendingString: [appRootEscaped stringByAppendingPathComponent: fileName]]; - - if (first) { - prefix = [@" " stringByAppendingString:prefix]; - first = NO; - } - } - - return result; -} - - -// Force reference to libreofficekit_hook -extern "C" void *libreofficekit_hook(const char *); -static __attribute__((used)) void *(*foop)(const char *) = libreofficekit_hook; - -extern "C" void lo_initialize(NSString *documentPath) -{ - NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; - NSString *app_root_escaped = [bundlePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - NSString *uno_types = createPaths(@"-env:UNO_TYPES=", app_root_escaped, @[@"offapi.rdb", @"oovbaapi.rdb", @"types.rdb"]); - NSString *uno_services = createPaths(@"-env:UNO_SERVICES=", app_root_escaped, @[@"ure/services.rdb", @"services.rdb"]); - - int fd = open([[bundlePath stringByAppendingPathComponent:@U_ICUDATA_NAME".dat"] UTF8String], O_RDONLY); - if (fd != -1) { - struct stat st; - if (fstat(fd, &st) != -1 - && st.st_size < (size_t)-1) { - void *icudata = mmap(0, (size_t) st.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); - if (icudata == MAP_FAILED) { -#if OSL_DEBUG_LEVEL > 0 - NSLog(@"mmap failed:%s", strerror(errno)); -#endif - } else { - UErrorCode icuStatus = U_ZERO_ERROR; - udata_setCommonData(icudata, &icuStatus); -#if OSL_DEBUG_LEVEL > 0 - if (U_FAILURE(icuStatus)) - NSLog(@"udata_setCommonData failed"); - else { - // Test that ICU works... - UConverter *cnv = ucnv_open("iso-8859-3", &icuStatus); - NSLog(@"ucnv_open(iso-8859-3)-> %p, err = %s, name=%s", - (void *)cnv, u_errorName(icuStatus), (!cnv)?"?":ucnv_getName(cnv,&icuStatus)); - if (U_SUCCESS(icuStatus)) - ucnv_close(cnv); - } -#endif - } - } - close(fd); - } - - const char *argv[] = { - [[[NSBundle mainBundle] executablePath] UTF8String], - "-env:URE_INTERNAL_LIB_DIR=file:///", - [uno_types UTF8String], - [uno_services UTF8String], - [[@"file://" stringByAppendingString: [documentPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] UTF8String] - }; - - const int argc = sizeof(argv)/sizeof(*argv); - - osl_setCommandArgs(argc, (char **) argv); -} - -#endif - - -#if 0 -// LOK_main (online) -#endif - - -// CLIENT COMMAND INTERFACE -static bool client_canceltiles(const char *args[]) -{ - return true; -} - -static bool client_clientvisiblearea(const char *args[]) -{ - return true; -} - -static bool client_closedocument(const char *args[]) -{ - return true; -} - -static bool client_commandvalues(const char *args[]) -{ - return true; -} - -static bool client_downloadas(const char *args[]) -{ - return true; -} - -static bool client_getchildid(const char *args[]) -{ - return true; -} - -static bool client_gettextselection(const char *args[]) -{ - return true; -} - -static bool client_insertfile(const char *args[]) -{ - return true; -} - -static bool client_key(const char *args[]) -{ - return true; -} - -static bool client_load(const char *args[]) -{ - return true; -} - -static bool client_loolclient(const char *args[]) -{ - return true; -} - -static bool client_mouse(const char *args[]) -{ - return true; -} - -static bool client_paste(const char *args[]) -{ - return true; -} - -static bool client_ping(const char *args[]) -{ - return true; -} - -static bool client_renderfont(const char *args[]) -{ - return true; -} - -static bool client_requestloksession(const char *args[]) -{ - return true; -} - -static bool client_resetselection(const char *args[]) -{ - return true; -} - -static bool client_saveas(const char *args[]) -{ - return true; -} - -static bool client_selectgraphic(const char *args[]) -{ - return true; -} - -static bool client_selecttext(const char *args[]) -{ - return true; -} - -static bool client_setclientpart(const char *args[]) -{ - return true; -} - -static bool client_status(const char *args[]) -{ - return true; -} - -static bool client_styles(const char *args[]) -{ - return true; -} - -static bool client_tile(const char *args[]) -{ - return true; -} - -static bool client_tilecombine(const char *args[]) -{ - return true; -} - -static bool client_uno(const char *args[]) -{ - return true; -} - -static bool client_useractive(const char *args[]) -{ - return true; -} - -static bool client_userinactive(const char *args[]) -{ - return true; -} - - - -typedef struct {const char *command; bool useArgs; bool (*funcCmd)(const char *[]);} CLIENTCOMMAND; -static CLIENTCOMMAND clientcommands[] = {{"canceltiles", false, client_canceltiles}, - {"clientvisiblearea", true, client_clientvisiblearea}, - {"closedocument", false, client_closedocument}, - {"commandvalues", false, client_commandvalues}, - {"downloadas", true, client_downloadas}, - {"getchildid", false, client_getchildid}, - {"gettextselection", false, client_gettextselection}, - {"insertfile", true, client_insertfile}, - {"key", true, client_key}, - {"load", true, client_load}, - {"loolclient", true, client_loolclient}, - {"mouse", true, client_mouse}, - {"paste", true, client_paste}, - {"ping", false, client_ping}, - {"renderfont", true, client_renderfont}, - {"requestloksession", false, client_requestloksession}, - {"resetselection", false, client_resetselection}, - {"saveas", true, client_saveas}, - {"selectgraphic", true, client_selectgraphic}, - {"selecttext", true, client_selecttext}, - {"setclientpart", true, client_setclientpart}, - {"status", false, client_status}, - {"styles", false, client_styles}, - {"tile", true, client_tile}, - {"tilecombine", true, client_tilecombine}, - {"uno", false, client_uno}, - {"useractive", false, client_useractive}, - {"userinactive", false, client_userinactive}, - {NULL, false, NULL} - }; - - - - -int BridgeLOkit_ClientCommand(const char *input) -{ - static char argStore[2048]; - const char *args[10]; - char *cmd, *arg; - const char *sep = " "; - int j = 0; - - // Split input into cmd + args - strcpy(argStore, input); - arg = cmd = strtok(argStore, sep); - - // Locate correct command - CLIENTCOMMAND *client_cmd = clientcommands; - for (; client_cmd->command; ++client_cmd) - if (!strcmp(client_cmd->command,cmd)) { - args[j++] = input; - args[j] = NULL; - if (client_cmd->useArgs) - while (arg && j < 10) - { - arg = strtok(NULL, sep); - args[j++] = arg; - } - return (int)client_cmd->funcCmd(args); - } - - - // Call/Return from command - return -999; -} - - diff --git a/ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit.mm b/ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit.mm new file mode 100755 index 000000000000..1964de9a7420 --- /dev/null +++ b/ios/experimental/LibreOfficeLight/LibreOfficeLight/lokit.mm @@ -0,0 +1,351 @@ +// +// This file is part of the LibreOffice project. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// +#include +#include +#define LOK_USE_UNSTABLE_API +#include + +#include + +#include +#include + +// generated by solenv/bin/native-code.py: +#include "native-code.mm" + + +// Force reference to libreofficekit_hook +extern "C" __attribute__((used)) void *libreofficekit_hook(const char *); +static __attribute__((used)) void *(*foop)(const char *) = libreofficekit_hook; + +// pointers to our instance +static LibreOfficeKit* kit; +static LibreOfficeKitDocument* document; + + +// Bridge functions to LibreOfficeKit +extern "C" int BridgeLOkit_Init(const char *path) +{ + // Initialize LibreOfficeKit + kit = lok_init(path); + + udata_setCommonData(NULL, NULL); + ucnv_open("iso-8859-3", NULL); + + ucnv_getName(NULL,NULL); + ucnv_close(NULL); + osl_setCommandArgs(8, NULL); + kit->pClass->documentLoad(kit, NULL); + document->pClass->initializeForRendering(document, ""); + return 0; +} + +int LOkit_open(char *file) +{ + document = kit->pClass->documentLoad(kit, file); + document->pClass->initializeForRendering(document, ""); + return 0; +} + + +#if 0 +// createpath from tiled +static NSString *createPaths(NSString *base, NSString *appRootEscaped, NSArray *fileNames) +{ + NSString *result; + NSString *prefix = @"file://"; + BOOL first = YES; + + result = base; + for (NSString *fileName in fileNames) { + result = [result stringByAppendingString: prefix]; + result = [result stringByAppendingString: [appRootEscaped stringByAppendingPathComponent: fileName]]; + + if (first) { + prefix = [@" " stringByAppendingString:prefix]; + first = NO; + } + } + + return result; +} + + +// Force reference to libreofficekit_hook +extern "C" void *libreofficekit_hook(const char *); +static __attribute__((used)) void *(*foop)(const char *) = libreofficekit_hook; + +extern "C" void lo_initialize(NSString *documentPath) +{ + NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; + NSString *app_root_escaped = [bundlePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *uno_types = createPaths(@"-env:UNO_TYPES=", app_root_escaped, @[@"offapi.rdb", @"oovbaapi.rdb", @"types.rdb"]); + NSString *uno_services = createPaths(@"-env:UNO_SERVICES=", app_root_escaped, @[@"ure/services.rdb", @"services.rdb"]); + + int fd = open([[bundlePath stringByAppendingPathComponent:@U_ICUDATA_NAME".dat"] UTF8String], O_RDONLY); + if (fd != -1) { + struct stat st; + if (fstat(fd, &st) != -1 + && st.st_size < (size_t)-1) { + void *icudata = mmap(0, (size_t) st.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); + if (icudata == MAP_FAILED) { +#if OSL_DEBUG_LEVEL > 0 + NSLog(@"mmap failed:%s", strerror(errno)); +#endif + } else { + UErrorCode icuStatus = U_ZERO_ERROR; + udata_setCommonData(icudata, &icuStatus); +#if OSL_DEBUG_LEVEL > 0 + if (U_FAILURE(icuStatus)) + NSLog(@"udata_setCommonData failed"); + else { + // Test that ICU works... + UConverter *cnv = ucnv_open("iso-8859-3", &icuStatus); + NSLog(@"ucnv_open(iso-8859-3)-> %p, err = %s, name=%s", + (void *)cnv, u_errorName(icuStatus), (!cnv)?"?":ucnv_getName(cnv,&icuStatus)); + if (U_SUCCESS(icuStatus)) + ucnv_close(cnv); + } +#endif + } + } + close(fd); + } + + const char *argv[] = { + [[[NSBundle mainBundle] executablePath] UTF8String], + "-env:URE_INTERNAL_LIB_DIR=file:///", + [uno_types UTF8String], + [uno_services UTF8String], + [[@"file://" stringByAppendingString: [documentPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] UTF8String] + }; + + const int argc = sizeof(argv)/sizeof(*argv); + + osl_setCommandArgs(argc, (char **) argv); +} + +#endif + + +#if 0 +// LOK_main (online) +#endif + + +// CLIENT COMMAND INTERFACE +static bool client_canceltiles(const char *args[]) +{ + return true; +} + +static bool client_clientvisiblearea(const char *args[]) +{ + return true; +} + +static bool client_closedocument(const char *args[]) +{ + return true; +} + +static bool client_commandvalues(const char *args[]) +{ + return true; +} + +static bool client_downloadas(const char *args[]) +{ + return true; +} + +static bool client_getchildid(const char *args[]) +{ + return true; +} + +static bool client_gettextselection(const char *args[]) +{ + return true; +} + +static bool client_insertfile(const char *args[]) +{ + return true; +} + +static bool client_key(const char *args[]) +{ + return true; +} + +static bool client_load(const char *args[]) +{ + return true; +} + +static bool client_loolclient(const char *args[]) +{ + return true; +} + +static bool client_mouse(const char *args[]) +{ + return true; +} + +static bool client_paste(const char *args[]) +{ + return true; +} + +static bool client_ping(const char *args[]) +{ + return true; +} + +static bool client_renderfont(const char *args[]) +{ + return true; +} + +static bool client_requestloksession(const char *args[]) +{ + return true; +} + +static bool client_resetselection(const char *args[]) +{ + return true; +} + +static bool client_saveas(const char *args[]) +{ + return true; +} + +static bool client_selectgraphic(const char *args[]) +{ + return true; +} + +static bool client_selecttext(const char *args[]) +{ + return true; +} + +static bool client_setclientpart(const char *args[]) +{ + return true; +} + +static bool client_status(const char *args[]) +{ + return true; +} + +static bool client_styles(const char *args[]) +{ + return true; +} + +static bool client_tile(const char *args[]) +{ + return true; +} + +static bool client_tilecombine(const char *args[]) +{ + return true; +} + +static bool client_uno(const char *args[]) +{ + return true; +} + +static bool client_useractive(const char *args[]) +{ + return true; +} + +static bool client_userinactive(const char *args[]) +{ + return true; +} + + + +typedef struct {const char *command; bool useArgs; bool (*funcCmd)(const char *[]);} CLIENTCOMMAND; +static CLIENTCOMMAND clientcommands[] = {{"canceltiles", false, client_canceltiles}, + {"clientvisiblearea", true, client_clientvisiblearea}, + {"closedocument", false, client_closedocument}, + {"commandvalues", false, client_commandvalues}, + {"downloadas", true, client_downloadas}, + {"getchildid", false, client_getchildid}, + {"gettextselection", false, client_gettextselection}, + {"insertfile", true, client_insertfile}, + {"key", true, client_key}, + {"load", true, client_load}, + {"loolclient", true, client_loolclient}, + {"mouse", true, client_mouse}, + {"paste", true, client_paste}, + {"ping", false, client_ping}, + {"renderfont", true, client_renderfont}, + {"requestloksession", false, client_requestloksession}, + {"resetselection", false, client_resetselection}, + {"saveas", true, client_saveas}, + {"selectgraphic", true, client_selectgraphic}, + {"selecttext", true, client_selecttext}, + {"setclientpart", true, client_setclientpart}, + {"status", false, client_status}, + {"styles", false, client_styles}, + {"tile", true, client_tile}, + {"tilecombine", true, client_tilecombine}, + {"uno", false, client_uno}, + {"useractive", false, client_useractive}, + {"userinactive", false, client_userinactive}, + {NULL, false, NULL} + }; + + + + +int BridgeLOkit_ClientCommand(const char *input) +{ + static char argStore[2048]; + const char *args[10]; + char *cmd, *arg; + const char *sep = " "; + int j = 0; + + // Split input into cmd + args + strcpy(argStore, input); + arg = cmd = strtok(argStore, sep); + + // Locate correct command + CLIENTCOMMAND *client_cmd = clientcommands; + for (; client_cmd->command; ++client_cmd) + if (!strcmp(client_cmd->command,cmd)) { + args[j++] = input; + args[j] = NULL; + if (client_cmd->useArgs) + while (arg && j < 10) + { + arg = strtok(NULL, sep); + args[j++] = arg; + } + return (int)client_cmd->funcCmd(args); + } + + + // Call/Return from command + return -999; +} + + -- cgit