diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b4bf0f378..40ae2a8a62 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,11 @@ cmake_minimum_required(VERSION 3.2) set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.navitproject.navit") set(MACOSX_BUNDLE_BUNDLE_NAME "Navit") +set(MACOSX_BUNDLE_ICON_FILE "Default.png") +execute_process(COMMAND git describe --tags OUTPUT_VARIABLE MACOSX_BUNDLE_INFO_STRING) message(STATUS "Building with CMake V${CMAKE_VERSION}") +message(STATUS "Git Version: ${MACOSX_BUNDLE_INFO_STRING}") + if (DISABLE_CXX) project(navit C) else(DISABLE_CXX) @@ -714,12 +718,18 @@ if(WINCE) set_with_reason(support/espeak "Windows detected" TRUE) endif() if (APPLE OR USE_UIKIT) - set_with_reason(vehicle/iphone "apple detected" TRUE) + if(NOT USE_UIKIT) + ADD_DEFINITIONS(-DIOS=0) + endif(NOT USE_UIKIT) + if (EXISTS "${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks/UIKit.framework") + set_with_reason(vehicle/iphone "apple detected" TRUE) + endif() set_with_reason(graphics/cocoa "apple detected" TRUE) if (EXISTS "${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks/VoiceServices.framework") set_with_reason(speech/iphone "apple detected" TRUE) endif() set(BUILD_BUNDLE TRUE CACHE BOOLEAN "build an osx bundle") + set(NAVIT_COMPILE_FLAGS "${NAVIT_COMPILE_FLAGS} -ObjC") endif() if(CMAKE_SIZEOF_VOID_P LESS 8) diff --git a/contrib/macos/CMakeLists.txt b/contrib/macos/CMakeLists.txt new file mode 100644 index 0000000000..6c1075e795 --- /dev/null +++ b/contrib/macos/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.2) +project(macosbundle C) + +include(ExternalProject) +ExternalProject_Add(navit CMAKE_ARGS + -Dbinding/python=false SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/../) +ExternalProject_Get_Property(navit BINARY_DIR) +ExternalProject_Get_Property(navit SOURCE_DIR) + +install(DIRECTORY /usr/local/lib/navit/ DESTINATION ${BINARY_DIR}/navit.app/Contents/Resources) +install(DIRECTORY ${BINARY_DIR}/navit/resources/share/navit/ DESTINATION ${BINARY_DIR}/navit.app/Contents/Resources/share) +install(DIRECTORY ${BINARY_DIR}/navit//resources/share/locale DESTINATION ${BINARY_DIR}/navit.app/Contents/Resources/share) +install(DIRECTORY ${BINARY_DIR}/navit/icons DESTINATION ${BINARY_DIR}/navit.app/Contents/Resources/share) +install(DIRECTORY ${BINARY_DIR}/navit/textures DESTINATION ${BINARY_DIR}/navit.app/Contents/Resources/share) +install(DIRECTORY ${BINARY_DIR}/navit/maps DESTINATION ${BINARY_DIR}/navit.app/Contents/Resources/share) +install(DIRECTORY ${BINARY_DIR}/navit.app DESTINATION /usr/local/bin) +Install(FILES ${SOURCE_DIR}navit/navit_shipped_gtkgui.xml DESTINATION ~/.navit RENAME navit.xml) diff --git a/docs/development/macos_development.rst b/docs/development/macos_development.rst index bfc2b2b43e..c6e2759973 100644 --- a/docs/development/macos_development.rst +++ b/docs/development/macos_development.rst @@ -1,113 +1,70 @@ -================= MacOS Development ================= -Here are some notes about running navit under Apple Mac OSX. - -================================================================================================================================ -WARNING: These instructions are currently unmaintained. Please feel free to submit a PR if you manage to build navit on Mac OSX. -================================================================================================================================ +Here are some notes about running navit under Apple macOS. What you will need -================== - -You need Xcode Tools and MacPorts in order to install navit. - -MacPorts developers suggest to install Xcode Tools from http://developer.apple.com/tools/xcode/ and not from the Mac OSX install disk. -See `Mac-How `_ - -Make sure you don't have fink installed on your system, it can confuse MacPorts package building and installation. - - * GTK Gui: You should only need gtk2 and glib2 via macPorts - * SDL Gui: Untested yet. - -Installation instruction -======================== - -Download Xcode Tools from http://developer.apple.com/tools/xcode/ and install it with X11 SDK - -Download and Install MacPorts from http://www.macports.org/, or update your version - -.. code-block:: bash - - sudo port -d selfupdate - -Open up a terminal - -make sure your PATH variables has `/opt/local/bin` and `/opt/local/sbin` in it: +------------------ -.. code-block:: bash +You need Xcode Tools and homebrew in order to install navit. - echo $PATH +.. code:: shell +If you have macports or fink installed create and use a new user account +to build navit. -Install automake, wget, libtool, gpsd (if you want gps support), gtk2 and glib2 (for gkt GUI) with +For convinience there is the script prepare_navit_macos.sh available +under the navit/scripts directory. -.. code-block:: bash +.. code:: shell - sudo port install automake wget gpsd gtk2 glib2 libtool + $ curl https://raw.githubusercontent.com/OLFDB/navit/macosbuild/scripts/prepare_navit_macos.sh -o prepare_navit_macos.sh -Download navit or checkout it from Git + Then start the installation procedure: -.. code-block:: bash + .. code-block:: bash - git clone git@github.com:navit-gps/navit.git + $ sh prepare_navit_macos.sh -You may also need a header file to handle endian issues (for PPC only) +What is working +--------------- -.. code-block:: bash +- internal Gui: Working, but problems with window refresh - wget https://navit.svn.sourceforge.net/svnroot/navit/tags/R0_1_0/navit/projs/CodeBlocks/Win32Extra/byteswap.h +- GTK Gui: Working. -If you want to install navit along the MacPorts packages, you need to use the /opt/local directory as prefix: +- SDL Gui: Untested yet. -.. code-block:: bash +GPSD +---- - ./autogen.sh && ./configure --prefix=/opt/local --disable-binding-python +You have to add the GPS receiver device to gpsd: -type `make` to build NavIt, and `sudo make install` to install it. - -Then, you may edit and adapt your `navit.xml` file. The XML maptype is not supported, however normal Navit binfile works perfectly. +GPSD_SOCKET="/usr/local/var/gpsd.sock" /usr/local/opt/gpsd/sbin/gpsdctl +add /dev/tty.usbserial-XYZ Speech -====== - -If you want (spoken) directions, get espeak from http://espeak.sourceforge.net, install as advised and use the following snippet in your navit.xml: - -.. code-block:: xml - - - -This will tell speak to use a female (f) german (de) voice. - - -Using xcode -=========== - -Download one of the `Git sources `_ that don't contain autogen.sh. - -Open X-Code and create a new project. Cocoa will suffice - -Add in a new target by clicking the triangle next to "Targets" and selected the location of the navit folder. Delete the previous target. - -Delete the default files, and add in the navit files. - -In a terminal, go into the navit folder. - -.. code-block:: bash +------ - ./configure --disable-binding-python --disable-sample-map --disable-maptool +If you want (spoken) directions, use the following snippet in your +navit.xml: -xcode can now build the navit +.. code:: xml + -You can also use CMake. +This will use the native say command. You can list all available voices +by typing say -v ? in a terminal. Change the command to say -v + if you would like a non standard voice to be used. New +voices can be added in system preferences->keyboard->dictation -.. code-block:: bash +Using Xcode +----------- - cd navit && cmake -G Xcode . +cmake -G Xcode ../ -DUSE_PLUGINS=0 -DBUILD_MAPTOOL=1 -DXSLTS=macos +-Dbinding/python=false -DCLANG_ENABLE_OBJC_WEAK=YES Something went wrong? -===================== +--------------------- Please let us know by filing an issue on Github or reach out on IRC. diff --git a/navit/CMakeLists.txt b/navit/CMakeLists.txt index f695e14d28..9e73f1c7de 100644 --- a/navit/CMakeLists.txt +++ b/navit/CMakeLists.txt @@ -6,6 +6,11 @@ include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/support") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/THIS_IS_THE_NAVIT_WORKING_DIR "\r\nThis File should never appear on binary distributions\r\n" ) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/THIS_IS_THE_NAVIT_WORKING_DIR "\r\nOnly Devs should ever see this file" ) +IF(APPLE) + # Fix linking on 10.14+. See https://stackoverflow.com/questions/54068035 + LINK_DIRECTORIES(/usr/local/lib) +ENDIF() + # navit core set(NAVIT_SRC announcement.c atom.c attr.c cache.c callback.c command.c config_.c coord.c country.c data_window.c debug.c event.c file.c geom.c graphics.c gui.c item.c layout.c log.c main.c map.c maps.c @@ -77,9 +82,11 @@ if(NOT ANDROID) endif() endif() if (BUILD_BUNDLE) + set(EXECUTABLE_NAME navit) + set(APP_ICON_FILE Default.png) list(APPEND NAVIT_START_SRC resources/share resources/Icon.png resources/Default.png) - add_custom_command(OUTPUT resources/Icon.png COMMAND convert -scale 79x79 -crop 60x60+8+19 ${CMAKE_CURRENT_SOURCE_DIR}/icons/desktop_icons/128x128/navit.png resources/Icon.png) - add_custom_command(OUTPUT resources/Default.png COMMAND convert -scale 79x79 -crop 60x60+8+19 ${CMAKE_CURRENT_SOURCE_DIR}/icons/desktop_icons/128x128/navit.png resources/Default.png) + add_custom_command(OUTPUT resources/Icon.png COMMAND convert -scale 79x79 ${CMAKE_CURRENT_SOURCE_DIR}/icons/desktop_icons/128x128/navit.png resources/Icon.png) + add_custom_command(OUTPUT resources/Default.png COMMAND convert -scale 79x79 ${CMAKE_CURRENT_SOURCE_DIR}/icons/desktop_icons/128x128/navit.png resources/Default.png) endif() add_executable(navit ${NAVIT_START_SRC}) target_link_libraries (navit ${NAVIT_LIBNAME}) @@ -87,13 +94,15 @@ if(NOT ANDROID) set_target_properties(navit PROPERTIES OUTPUT_NAME ${NAVIT_BINARY}) endif(DEFINED NAVIT_BINARY) if (BUILD_BUNDLE) + target_link_libraries(navit stdc++ "-framework Foundation -framework CoreText -framework CoreImage" objc) add_custom_command(OUTPUT resources/share COMMAND mkdir -p resources/share) - set_source_files_properties(resources/share resources/Icon.png resources/Default.png PROPERTIES MACOSX_PACKAGE_LOCATION Resources) + set_source_files_properties(${NAVIT_SUPPORT_LIBS} resources/share resources/Icon.png resources/Default.png PROPERTIES MACOSX_PACKAGE_LOCATION Resources) set_target_properties(navit PROPERTIES MACOSX_BUNDLE TRUE) - set_target_properties(navit PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) +#set_target_properties(navit PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) add_dependencies(navit navit_config_xml_resource) add_dependencies(navit images_resource) add_dependencies(navit locale_resource) + add_dependencies(navit textures_resource) endif() endif() @@ -208,7 +217,7 @@ else() endforeach() add_custom_target( navit_config_xml_resource DEPENDS ${XMLCFG_INSTALLED_PATH_LIST} COMMAND mkdir -p resources/share/navit COMMAND cp ${XMLCFG_INSTALLED_PATH_LIST} resources/share/navit) add_custom_target( locale_resource DEPENDS locales COMMAND mkdir -p resources/share COMMAND cp -a ${CMAKE_CURRENT_BINARY_DIR}/../locale resources/share/locale) - add_custom_target( navit_config_xml ALL DEPENDS ${XMLCFG_OUTPUT_LIST}) + add_custom_target( navit_config_xml ALL DEPENDS ${XMLCFG_OUTPUT_LIST} navit_config_xml_resource) endif() if (USE_LIBGNUINTL AND NOT HAVE_GLIB) diff --git a/navit/android.c b/navit/android.c index 214e3171cd..09c62712d9 100644 --- a/navit/android.c +++ b/navit/android.c @@ -7,7 +7,7 @@ #include "config_.h" #include "command.h" #include "debug.h" -#include "event.h" +#include "navit/event.h" #include "callback.h" #include "country.h" #include "projection.h" diff --git a/navit/binding/dbus/binding_dbus.c b/navit/binding/dbus/binding_dbus.c index 3470bdd4e9..e347ccf770 100644 --- a/navit/binding/dbus/binding_dbus.c +++ b/navit/binding/dbus/binding_dbus.c @@ -49,7 +49,7 @@ #include "roadprofile.h" #include "util.h" #include "transform.h" -#include "event.h" +#include "navit/event.h" #include "traffic.h" static DBusConnection *connection; diff --git a/navit/command.c b/navit/command.c index f2c6c0bb03..dade81da1f 100644 --- a/navit/command.c +++ b/navit/command.c @@ -13,7 +13,7 @@ #include "debug.h" #include "callback.h" #include "command.h" -#include "event.h" +#include "navit/event.h" #include "navit_nls.h" /* diff --git a/navit/event.c b/navit/event.c index ecb21ee946..d3b3717bfb 100644 --- a/navit/event.c +++ b/navit/event.c @@ -19,7 +19,7 @@ #include #include -#include "event.h" +#include "navit/event.h" #include "plugin.h" #include "debug.h" diff --git a/navit/event_glib.c b/navit/event_glib.c index 0048071b02..96f2bbf5a4 100644 --- a/navit/event_glib.c +++ b/navit/event_glib.c @@ -18,7 +18,7 @@ */ #include -#include "event.h" +#include "navit/event.h" #include "event_glib.h" #include "debug.h" #include "callback.h" diff --git a/navit/graphics.c b/navit/graphics.c index 2c7cd49fff..5ffd2db9e5 100644 --- a/navit/graphics.c +++ b/navit/graphics.c @@ -50,7 +50,7 @@ #include "util.h" #include "callback.h" #include "file.h" -#include "event.h" +#include "navit/event.h" #include "navit.h" /** diff --git a/navit/graphics/android/graphics_android.c b/navit/graphics/android/graphics_android.c index 2109fee7e4..cf6600e72e 100644 --- a/navit/graphics/android/graphics_android.c +++ b/navit/graphics/android/graphics_android.c @@ -28,7 +28,7 @@ #include "item.h" #include "xmlconfig.h" #include "plugin.h" -#include "event.h" +#include "navit/event.h" #include "debug.h" #include "callback.h" #include "android.h" diff --git a/navit/graphics/cocoa/graphics_cocoa.h b/navit/graphics/cocoa/graphics_cocoa.h new file mode 100644 index 0000000000..c7e1bfc8a5 --- /dev/null +++ b/navit/graphics/cocoa/graphics_cocoa.h @@ -0,0 +1,19 @@ +// +// graphics_cocoa.h +// graphics_cocoa +// +// Created by olf on 12.06.21. +// + +#ifndef graphics_cocoa_h +#define graphics_cocoa_h + +#if USE_UIKIT +#import +#else +#import +#endif + +CGContextRef current_context(void); + +#endif /* graphics_cocoa_h */ diff --git a/navit/graphics/cocoa/graphics_cocoa.m b/navit/graphics/cocoa/graphics_cocoa.m index 6f5bcedc5b..155eacd495 100644 --- a/navit/graphics/cocoa/graphics_cocoa.m +++ b/navit/graphics/cocoa/graphics_cocoa.m @@ -6,11 +6,12 @@ #include "point.h" #include "window.h" #include "graphics.h" -#include "event.h" +#include "navit/event.h" #include "item.h" #include "callback.h" #include "color.h" #include +#include "navit.h" #ifdef __IPHONE_OS_VERSION_MIN_REQUIRED #define USE_UIKIT 1 @@ -18,20 +19,20 @@ #define USE_UIKIT 0 #endif +#include "graphics_cocoa.h" + #if USE_UIKIT -#import +#import +#import #define NSRect CGRect #define NSMakeRect CGRectMake #define REVERSE_Y 0 -CGContextRef -current_context(void) -{ - return UIGraphicsGetCurrentContext(); +CGContextRef current_context(void) { + return UIGraphicsGetCurrentContext(); } #else -#import #define UIView NSView #define UIViewController NSViewController #define UIApplicationDelegate NSApplicationDelegate @@ -42,11 +43,11 @@ #define UIEvent NSEvent #define applicationFrame frame #define REVERSE_Y 1 +#define UIFont NSFont +#define UIColor NSColor -CGContextRef -current_context(void) -{ - return [[NSGraphicsContext currentContext] graphicsPort]; +CGContextRef current_context(void) { + return [[NSGraphicsContext currentContext] CGContext]; } #endif @@ -54,164 +55,112 @@ @interface NavitView : UIView { @public - struct graphics_priv *graphics; + struct graphics_priv *graphics; } @end static struct graphics_priv { - struct window win; - NavitView *view; - CGLayerRef layer; - CGContextRef layer_context; - struct callback_list *cbl; - struct point p, pclean; - int w, h, wraparound, overlay_disabled, cleanup; - struct graphics_priv *parent, *next, *overlays; + struct navit *navit; + struct window win; + NavitView *view; + CGLayerRef layer; + CGContextRef layer_context; + struct callback_list *cbl; + struct point p, pclean; + int w, h, wraparound, overlay_disabled, cleanup; + struct graphics_priv *parent, *next, *overlays; } *global_graphics_cocoa; iconv_t utf8_macosroman; struct graphics_gc_priv { - CGFloat rgba[4]; - int w; + CGFloat rgba[4]; + int w; }; struct graphics_font_priv { - int size; - char *name; + int size; + char *name; }; +int has_appeared = 0; +float startScale = 1; @implementation NavitView -- (void)drawRect:(NSRect)rect -{ - struct graphics_priv *gr=NULL; +- (void)drawRect:(NSRect)rect { + struct graphics_priv *gr=NULL; #if 0 - NSLog(@"NavitView:drawRect..."); + NSLog(@"NavitView:drawRect..."); #endif - CGContextRef X = current_context(); - - CGContextDrawLayerAtPoint(X, CGPointZero, graphics->layer); - if (!graphics->overlay_disabled) - gr=graphics->overlays; - while (gr) { - if (!gr->overlay_disabled) { - struct CGPoint pc; - pc.x=gr->p.x; - pc.y=gr->p.y; - if (gr->wraparound) { - if (pc.x < 0) - pc.x+=graphics->w; - if (pc.y < 0) - pc.y+=graphics->h; - } - #if REVERSE_Y - pc.y=graphics->h-pc.y-gr->h; - #endif - dbg(1,"draw %dx%d at %f,%f",gr->w,gr->h,pc.x,pc.y); - CGContextDrawLayerAtPoint(X, pc, gr->layer); - } - gr=gr->next; - } -} - -#if USE_UIKIT -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -{ - NSArray *arr=touches.allObjects; - UITouch *touch=[arr objectAtIndex: 0]; - struct CGPoint pc=[touch locationInView: self]; - struct point p; - p.x=pc.x; - p.y=pc.y; - dbg(1,"Enter count=%d %d %d",touches.count,p.x,p.y); - callback_list_call_attr_3(graphics->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(1), (void *)&p); -} - - -- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event -{ - NSArray *arr=touches.allObjects; - UITouch *touch=[arr objectAtIndex: 0]; - struct CGPoint pc=[touch locationInView: self]; - struct point p; - p.x=pc.x; - p.y=pc.y; - dbg(1,"Enter count=%d %d %d",touches.count,p.x,p.y); - callback_list_call_attr_3(graphics->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(1), (void *)&p); + CGContextRef X = current_context(); + + CGContextDrawLayerAtPoint(X, CGPointZero, graphics->layer); + if (!graphics->overlay_disabled) + gr=graphics->overlays; + while (gr) { + if (!gr->overlay_disabled) { + struct CGPoint pc; + pc.x=gr->p.x; + pc.y=gr->p.y; + if (gr->wraparound) { + if (pc.x < 0) + pc.x+=graphics->w; + if (pc.y < 0) + pc.y+=graphics->h; + } +#if REVERSE_Y + pc.y=graphics->h-pc.y-gr->h; +#endif + dbg(1,"draw %dx%d at %f,%f",gr->w,gr->h,pc.x,pc.y); + CGContextDrawLayerAtPoint(X, pc, gr->layer); + } + gr=gr->next; + } } -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event -{ - NSArray *arr=touches.allObjects; - UITouch *touch=[arr objectAtIndex: 0]; - struct CGPoint pc=[touch locationInView: self]; - struct point p; - p.x=pc.x; - p.y=pc.y; - dbg(1,"Enter count=%d %d %d",touches.count,p.x,p.y); - callback_list_call_attr_3(graphics->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(1), (void *)&p); -} +#if (USE_UIKIT==0) +- (void)mouseDown:(UIEvent *)theEvent { + struct point p; + p.x=theEvent.locationInWindow.x; + p.y=graphics->h-theEvent.locationInWindow.y; -- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event -{ - NSArray *arr=touches.allObjects; - UITouch *touch=[arr objectAtIndex: 0]; - struct CGPoint pc=[touch locationInView: self]; - struct point p; - p.x=pc.x; - p.y=pc.y; - dbg(1,"Enter count=%d %d %d",touches.count,p.x,p.y); - callback_list_call_attr_1(graphics->cbl, attr_motion, (void *)&p); + dbg(1,"Enter %d %d",p.x,p.y); + callback_list_call_attr_3(graphics->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(1), (void *)&p); } -#else -- (void)mouseDown:(UIEvent *)theEvent -{ - struct point p; - p.x=theEvent.locationInWindow.x; - p.y=graphics->h-theEvent.locationInWindow.y; +- (void)mouseUp:(UIEvent *)theEvent { + struct point p; + p.x=theEvent.locationInWindow.x; + p.y=graphics->h-theEvent.locationInWindow.y; - dbg(1,"Enter %d %d",p.x,p.y); - callback_list_call_attr_3(graphics->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(1), (void *)&p); + dbg(1,"Enter %d %d",p.x,p.y); + callback_list_call_attr_3(graphics->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(1), (void *)&p); } -- (void)mouseUp:(UIEvent *)theEvent -{ - struct point p; - p.x=theEvent.locationInWindow.x; - p.y=graphics->h-theEvent.locationInWindow.y; +- (void)mouseDragged:(UIEvent *)theEvent { + struct point p; + p.x=theEvent.locationInWindow.x; + p.y=graphics->h-theEvent.locationInWindow.y; - dbg(1,"Enter %d %d",p.x,p.y); - callback_list_call_attr_3(graphics->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(1), (void *)&p); -} - -- (void)mouseDragged:(UIEvent *)theEvent -{ - struct point p; - p.x=theEvent.locationInWindow.x; - p.y=graphics->h-theEvent.locationInWindow.y; - - dbg(1,"Enter %d %d",p.x,p.y); - callback_list_call_attr_1(graphics->cbl, attr_motion, (void *)&p); + dbg(1,"Enter %d %d",p.x,p.y); + callback_list_call_attr_1(graphics->cbl, attr_motion, (void *)&p); } #endif - (void)dealloc { - [super dealloc]; + [super dealloc]; } @end -@interface NavitViewController : UIViewController -{ - NSRect frame; - CGLayerRef layer; +@interface NavitViewController : UIViewController { + NSRect frame; + CGLayerRef layer; } @property (nonatomic) NSRect frame; @@ -225,72 +174,238 @@ - (id) init_withFrame : (NSRect) _frame; @implementation NavitViewController @synthesize frame; +#if USE_UIKIT +- (UIInterfaceOrientationMask)supportedInterfaceOrientations { + return (UIInterfaceOrientationMaskAll); +} -- (id) init_withFrame : (NSRect) _frame -{ - NSLog(@"init with frame\n"); - frame = _frame; - return [self init]; +- (IBAction)handlePinch:(UIPinchGestureRecognizer *)sender { + if(sender.state == UIGestureRecognizerStateBegan) { + startScale = sender.scale; + } else if(sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateChanged) { + struct point p; + p.x=[sender locationInView: self.view].x; + p.y=[sender locationInView: self.view].y; + + if((startScale / sender.scale > 2) || (startScale / sender.scale < 0.5)) { + if((sender.scale > 1)) { + navit_zoom_in(global_graphics_cocoa->navit, 2, &p); + startScale=sender.scale * 1.5; + } else { + navit_zoom_out(global_graphics_cocoa->navit, 2, &p); + startScale=sender.scale * 0.75; + } + } + } +} + +- (IBAction)handlePan:(UIPanGestureRecognizer *)sender { + + if (sender.state == UIGestureRecognizerStateBegan) { + struct point p; + p.x=[sender locationInView: self.view].x; + p.y=[sender locationInView: self.view].y; + callback_list_call_attr_3(global_graphics_cocoa->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(1), (void *)&p); + + } + + if (sender.state == UIGestureRecognizerStateChanged) { + struct point p; + p.x=[sender locationInView: self.view].x; + p.y=[sender locationInView: self.view].y; + callback_list_call_attr_1(global_graphics_cocoa->cbl, attr_motion, (void *)&p); + } + + if(sender.state == UIGestureRecognizerStateEnded) { + struct point p; + p.x=[sender locationInView: self.view].x; + p.y=[sender locationInView: self.view].y; + callback_list_call_attr_3(global_graphics_cocoa->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(1), (void *)&p); + } +} + +- (IBAction)handleTap:(UITapGestureRecognizer *)sender { + if (sender.state == UIGestureRecognizerStateEnded) { + struct CGPoint pc=[sender locationInView: self.view]; + struct point p; + p.x=pc.x; + p.y=pc.y; + callback_list_call_attr_3(global_graphics_cocoa->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(1), (void *)&p); + callback_list_call_attr_3(global_graphics_cocoa->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(1), (void *)&p); + } +} + +- (void)rotated:(NSNotification *)notification { + + NSLog(@"rotated enter"); + + int width =(int)UIScreen.mainScreen.bounds.size.width; + int height = (int)UIScreen.mainScreen.bounds.size.height; + + // Hack: issue on iPad2: the width and height of the mainscreen bounds are not changing when orientation changes + // Detect OS version and exchange width<->height when iOS < 10 detected and orientation is landscape + UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; + int lt_ten=1; + + NSLog(@"System Version: %f",[[[UIDevice currentDevice] systemVersion] floatValue]); + + if([[[UIDevice currentDevice] systemVersion] floatValue] >=10) { + lt_ten=0; + + } + + if(lt_ten && (orientation==UIDeviceOrientationFaceDown + || orientation == UIDeviceOrientationFaceUp)) { + return; + } + + if (!UIDeviceOrientationIsValidInterfaceOrientation(orientation)) { + return; + } + + if (lt_ten && UIDeviceOrientationIsLandscape(orientation)) { + global_graphics_cocoa->w=height; + global_graphics_cocoa->h=width; + callback_list_call_attr_2(global_graphics_cocoa->cbl, attr_resize, (int)height, (int)width); + NSLog(@"Rotated 9 %i %i %i %ld", lt_ten, width, height, (long)orientation); + } else { + global_graphics_cocoa->w=width; + global_graphics_cocoa->h=height; + callback_list_call_attr_2(global_graphics_cocoa->cbl, attr_resize, (int)width, (int)height); + NSLog(@"Rotated 10 %i %i %i %ld", lt_ten, width, height, (long)orientation); + } + + dbg(1,"Rotated"); +} + +- (BOOL)prefersStatusBarHidden { + return NO; +} + +#endif + +- (id) init_withFrame : (NSRect) _frame { + NSLog(@"init with frame\n"); + frame = _frame; + return [self init]; } static -void free_graphics(struct graphics_priv *gr) -{ - if (gr->layer) { - CGLayerRelease(gr->layer); - gr->layer=NULL; - } +void free_graphics(struct graphics_priv *gr) { + if (gr->layer) { + CGLayerRelease(gr->layer); + gr->layer=NULL; + } } -static void -setup_graphics(struct graphics_priv *gr) -{ - CGRect lr=CGRectMake(0, 0, gr->w, gr->h); - gr->layer=CGLayerCreateWithContext(current_context(), lr.size, NULL); - gr->layer_context=CGLayerGetContext(gr->layer); +static void setup_graphics(struct graphics_priv *gr) { + CGRect lr=CGRectMake(0, 0, gr->w, gr->h); + gr->layer=CGLayerCreateWithContext(current_context(), lr.size, NULL); + gr->layer_context=CGLayerGetContext(gr->layer); #if REVERSE_Y - CGContextScaleCTM(gr->layer_context, 1, -1); - CGContextTranslateCTM(gr->layer_context, 0, -gr->h); + CGContextScaleCTM(gr->layer_context, 1, -1); + CGContextTranslateCTM(gr->layer_context, 0, -gr->h); #endif - CGContextSetRGBFillColor(gr->layer_context, 0, 0, 0, 0); - CGContextSetRGBStrokeColor(gr->layer_context, 0, 0, 0, 0); - CGContextClearRect(gr->layer_context, lr); + CGContextSetRGBFillColor(gr->layer_context, 0, 0, 0, 0); + CGContextSetRGBStrokeColor(gr->layer_context, 0, 0, 0, 0); + CGContextClearRect(gr->layer_context, lr); } +- (void)loadView { + NSLog(@"loadView"); + NavitView* myV = [NavitView alloc]; + +#if USE_UIKIT + myV.tag = 100; +#endif + if (global_graphics_cocoa) { + global_graphics_cocoa->view=myV; + myV->graphics=global_graphics_cocoa; -- (void)loadView -{ - NSLog(@"loadView"); - NavitView* myV = [NavitView alloc]; + global_graphics_cocoa->w=frame.size.width; + global_graphics_cocoa->h=frame.size.height; - if (global_graphics_cocoa) { - global_graphics_cocoa->view=myV; - myV->graphics=global_graphics_cocoa; - global_graphics_cocoa->w=frame.size.width; - global_graphics_cocoa->h=frame.size.height; - setup_graphics(global_graphics_cocoa); - } + setup_graphics(global_graphics_cocoa); + } - [myV initWithFrame: frame]; + [myV initWithFrame: frame]; - [self setView: myV]; + [self setView: myV]; - [myV release]; + [myV release]; } +- (void)viewDidLoad { + NSLog(@"View loaded!"); +#if USE_UIKIT + NSNotificationCenter *notficationcenter = NSNotificationCenter.defaultCenter; + [notficationcenter addObserver:self selector:@selector(appMovedToBackground:) name: + UIApplicationWillResignActiveNotification object: nil]; + [notficationcenter addObserver:self selector:@selector(appMovedToForeground:) name: + UIApplicationDidBecomeActiveNotification object: nil]; +#endif +} + +- (void)viewDidAppear:(BOOL)animated { + dbg(lvl_debug,"view appeared"); +#if USE_UIKIT + self.modalPresentationCapturesStatusBarAppearance = false; +#endif + + has_appeared = 1; +#if USE_UIKIT + callback_list_call_attr_0(global_graphics_cocoa->cbl, attr_vehicle_request_location_authorization); + + UIPinchGestureRecognizer* pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)]; + [self.view addGestureRecognizer:pinch]; + + UITapGestureRecognizer* tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)]; + [self.view addGestureRecognizer:tap]; + + UIPanGestureRecognizer* pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)]; + [self.view addGestureRecognizer:pan]; + + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotated:) name: + UIDeviceOrientationDidChangeNotification object:nil]; + +#endif +} + +- (void) appMovedToBackground:(NSNotification*)note { + NSLog(@"App moved to background!"); + //TODO: add a callback to deactivate speech instance. Otherwise an active announcement will keep the radio muted in HFP mode +} + +#if USE_UIKIT +- (void) appMovedToForeground:(NSNotification*)note { + NSLog(@"App moved to foreground!"); + [self rotated: (NULL)]; + //TODO: add a callback to deactivate speech instance. Otherwise an active announcement will keep the radio muted in HFP mode +} +#endif + - (void)didReceiveMemoryWarning { - dbg(0,"enter"); + dbg(1,"enter"); } +#if USE_UIKIT +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { + NSLog(@"didRotateFromInterfaceOrientation enter"); + [self rotated: (NULL)]; +} +#endif - (void)viewDidUnload { - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; } - - (void)dealloc { - [super dealloc]; + NSLog(@"Dealloc enter"); + [super dealloc]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; } @end @@ -298,13 +413,15 @@ - (void)dealloc { @class NavitViewController; @interface NavitAppDelegate : NSObject { - UIWindow *window; - NavitViewController *viewController; + UIWindow *window; + NavitViewController *viewController; } @property (nonatomic, retain) /*IBOutlet*/ UIWindow *window; @property (nonatomic, retain) /*IBOutlet*/ NavitViewController *viewController; +void onUncaughtException(NSException* exception); + @end @@ -313,406 +430,538 @@ @implementation NavitAppDelegate @synthesize window; @synthesize viewController; +void onUncaughtException(NSException* exception) { + NSLog(@"onUncaughtException: %@ %@", exception.reason, exception.debugDescription); +#if (!USE_UIKIT) + [NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0]; +#endif +} #if USE_UIKIT - (BOOL)application:(UIApplication *)application -didFinishLaunchingWithOptions:(NSDictionary *)launchOptions + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions #else - (void) -applicationDidFinishLaunching:(NSNotification *)aNotification + applicationDidFinishLaunching:(NSNotification *)aNotification #endif { - NSLog(@"DidFinishLaunching\n"); + NSLog(@"DidFinishLaunching\n"); + //#if USE_UIKIT + // [[UIApplication sharedApplication] setStatusBarHidden:NO]; + //#endif + + NSSetUncaughtExceptionHandler(&onUncaughtException); #if USE_UIKIT - [[UIApplication sharedApplication] setStatusBarHidden:NO]; + NSRect appFrame = [UIScreen mainScreen].bounds; +#else + NSRect appFrame = [NSScreen mainScreen].frame; #endif - NSRect appFrame = [UIScreen mainScreen].applicationFrame; + self.viewController = [[[NavitViewController alloc] init_withFrame : appFrame] autorelease]; - self.viewController = [[[NavitViewController alloc] init_withFrame : appFrame] autorelease]; - - NSRect windowRect = NSMakeRect(0, 0, appFrame.size.width, appFrame.size.height); +#if USE_UIKIT + self.viewController.modalPresentationStyle = UIModalPresentationFullScreen; +#endif + NSRect windowRect = NSMakeRect(0, 0, appFrame.size.width, appFrame.size.height); #if USE_UIKIT - self.window = [[[UIWindow alloc] initWithFrame:windowRect] autorelease]; + self.window = [[[UIWindow alloc] initWithFrame:windowRect] autorelease]; #else - self.window = [[[UIWindow alloc] initWithContentRect:windowRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO] autorelease]; + self.window = [[[UIWindow alloc] initWithContentRect:windowRect styleMask:NSWindowStyleMaskBorderless backing: + NSBackingStoreBuffered defer:NO] autorelease]; #endif - utf8_macosroman=iconv_open("MACROMAN","UTF-8"); + utf8_macosroman=iconv_open("MACROMAN","UTF-8"); #if USE_UIKIT - [window addSubview:viewController.view]; - [window makeKeyAndVisible]; + [window setRootViewController:viewController]; + [window makeKeyAndVisible]; #else - NSWindowController * controller = [[NSWindowController alloc] initWithWindow : window]; - NSLog(@"Setting view\n"); - [viewController loadView]; - [window setContentView : viewController.view]; - [controller setWindow : window]; - [controller showWindow : nil]; + NSWindowController * controller = [[NSWindowController alloc] initWithWindow : window]; + NSLog(@"Setting view\n"); + [viewController loadView]; + [window setContentView : viewController.view]; + [controller setWindow : window]; + [controller showWindow : nil]; #endif - if (global_graphics_cocoa) { - callback_list_call_attr_2(global_graphics_cocoa->cbl, attr_resize, (int)appFrame.size.width, (int)appFrame.size.height); + if (global_graphics_cocoa) { + callback_list_call_attr_2(global_graphics_cocoa->cbl, attr_resize, (int)appFrame.size.width, (int)appFrame.size.height); - } + } #if USE_UIKIT - return YES; + return YES; #endif } - - (void)dealloc { - [viewController release]; - [window release]; - [super dealloc]; + [viewController release]; + [window release]; + [super dealloc]; } @end -static void -draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) -{ - if (mode == draw_mode_end) { - dbg(1,"end %p",gr); - if (!gr->parent) { +static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) { + if (mode == draw_mode_end) { + dbg(1,"end %p",gr); + if (!gr->parent) { #if USE_UIKIT - [gr->view setNeedsDisplay]; + [gr->view setNeedsDisplay]; #else - [gr->view display]; + [gr->view display]; #endif - } - } + } + } } -static void -draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) -{ - CGPoint points[count]; - int i; - for (i = 0 ; i < count ; i++) { - points[i].x=p[i].x; - points[i].y=p[i].y; - } - CGContextSetStrokeColor(gr->layer_context, gc->rgba); - CGContextSetLineWidth(gr->layer_context, gc->w); - CGContextSetLineCap(gr->layer_context, kCGLineCapRound); - CGContextBeginPath(gr->layer_context); - CGContextAddLines(gr->layer_context, points, count); - CGContextStrokePath(gr->layer_context); - -} - -static void -draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) -{ - CGPoint points[count]; - int i; - for (i = 0 ; i < count ; i++) { - points[i].x=p[i].x; - points[i].y=p[i].y; - } - CGContextSetFillColor(gr->layer_context, gc->rgba); - CGContextBeginPath(gr->layer_context); - CGContextAddLines(gr->layer_context, points, count); - CGContextFillPath(gr->layer_context); -} - -static void -draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) -{ - CGRect lr=CGRectMake(p->x, p->y, w, h); - if (p->x <= 0 && p->y <= 0 && p->x+w+1 >= gr->w && p->y+h+1 >= gr->h) { - dbg(1,"clear %p %dx%d",gr,w,h); - free_graphics(gr); - setup_graphics(gr); - } - CGContextSetFillColor(gr->layer_context, gc->rgba); - CGContextFillRect(gr->layer_context, lr); -} - -static void -draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) -{ - size_t len,inlen=strlen(text)+1,outlen=strlen(text)+1; - char outb[outlen]; - char *inp=text,*outp=outb; +static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) { + CGPoint points[count]; + int i; + for (i = 0 ; i < count ; i++) { + points[i].x=p[i].x; + points[i].y=p[i].y; + } + CGContextSetStrokeColor(gr->layer_context, gc->rgba); + CGContextSetLineWidth(gr->layer_context, gc->w); + CGContextSetLineCap(gr->layer_context, kCGLineCapRound); + CGContextBeginPath(gr->layer_context); + CGContextAddLines(gr->layer_context, points, count); + CGContextStrokePath(gr->layer_context); - len=iconv (utf8_macosroman, &inp, &inlen, &outp, &outlen); +} - CGContextSetFillColor(gr->layer_context, fg->rgba); +static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) { + CGPoint points[count]; + int i; + for (i = 0 ; i < count ; i++) { + points[i].x=p[i].x; + points[i].y=p[i].y; + } + CGContextSetFillColor(gr->layer_context, gc->rgba); + CGContextBeginPath(gr->layer_context); + CGContextAddLines(gr->layer_context, points, count); + CGContextFillPath(gr->layer_context); +} - CGContextSelectFont(gr->layer_context, font->name, font->size/16.0, kCGEncodingMacRoman); - CGContextSetTextDrawingMode(gr->layer_context, kCGTextFill); - CGAffineTransform xform = CGAffineTransformMake(dx/65536.0, dy/65536.0, dy/65536.0, -dx/65536.0, 0.0f, 0.0f); - CGContextSetTextMatrix(gr->layer_context, xform); - CGContextShowTextAtPoint(gr->layer_context, p->x, p->y, outb, strlen(outb)); +static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) { + CGRect lr=CGRectMake(p->x, p->y, w, h); + if (p->x <= 0 && p->y <= 0 && p->x+w+1 >= gr->w && p->y+h+1 >= gr->h) { + dbg(1,"clear %p %dx%d",gr,w,h); + free_graphics(gr); + setup_graphics(gr); + } + CGContextSetFillColor(gr->layer_context, gc->rgba); + CGContextFillRect(gr->layer_context, lr); } -static void -draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) -{ - CGImageRef imgc=(CGImageRef) img; - int w=CGImageGetWidth(imgc); - int h=CGImageGetHeight(imgc); - CGRect rect=CGRectMake(0, 0, w, h); - CGContextSaveGState(gr->layer_context); - CGContextTranslateCTM(gr->layer_context, p->x, p->y+h); - CGContextScaleCTM(gr->layer_context, 1.0, -1.0); - CGContextDrawImage(gr->layer_context, rect, imgc); - CGContextRestoreGState(gr->layer_context); -} - -static void font_destroy(struct graphics_font_priv *font) -{ - g_free(font); +static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, + struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) { +#pragma unused (bg) + size_t outlen=strlen(text)+1; + char outb[outlen]; + char *inp=text; + + strcpy(outb, inp); + + CGContextRef context = gr->layer_context; + CGContextSaveGState(context); + +#if !USE_UIKIT + NSGraphicsContext * oldctx = [NSGraphicsContext currentContext]; + NSGraphicsContext * nscg = [NSGraphicsContext graphicsContextWithCGContext:context flipped:NO]; + [NSGraphicsContext setCurrentContext:nscg]; +#endif + + CGAffineTransform xform = CGAffineTransformMake(dx/65536.0, dy/65536.0, dy/65536.0, -dx/65536.0, p->x, p->y ); + CGContextTranslateCTM(context, 0, 0); + CGContextConcatCTM(context, xform); + +#if USE_UIKIT + CGAffineTransform flipit = CGAffineTransformMakeScale(1, -1); + CGContextConcatCTM(context, flipit); +#endif + + CGColorRef color = CGColorCreate(CGColorSpaceCreateDeviceRGB(), fg->rgba); + NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:font->size/16.0], + NSFontAttributeName, [UIColor colorWithCGColor:(CGColorRef) color], NSForegroundColorAttributeName, nil]; + +#if USE_UIKIT + UIGraphicsPushContext(context); +#endif + + NSAttributedString *myText = [[NSAttributedString alloc] initWithString:[NSString stringWithUTF8String:outb] attributes + :attrs]; + +#if USE_UIKIT + [myText drawAtPoint:CGPointMake(0, 0 + -font->size/16.0)];//[(id)mytext drawAtPoint:CGPointMake(p->x, p->y-font->size/16.0) withAttributes:attrs]; + UIGraphicsPopContext(); +#else + [myText drawAtPoint:CGPointMake(0 + font->size/16.0/4, + 0 - font->size/16.0/4)];//[(id)mytext drawAtPoint:CGPointMake(p->x, p->y-font->size/16.0) withAttributes:attrs]; + [NSGraphicsContext setCurrentContext:oldctx]; +#endif + + CGContextRestoreGState(context); +} + +static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, + struct graphics_image_priv *img) { +#pragma unused (fg) + CGImageRef imgc=(CGImageRef) img; + int w=(int)CGImageGetWidth(imgc); + int h=(int)CGImageGetHeight(imgc); + CGRect rect=CGRectMake(0, 0, w, h); + CGContextSaveGState(gr->layer_context); + CGContextTranslateCTM(gr->layer_context, p->x, p->y+h); + CGContextScaleCTM(gr->layer_context, 1.0, -1.0); + CGContextDrawImage(gr->layer_context, rect, imgc); + CGContextRestoreGState(gr->layer_context); +} + +static void font_destroy(struct graphics_font_priv *font) { + g_free(font); } static struct graphics_font_methods font_methods = { - font_destroy + font_destroy }; -static void -draw_drag(struct graphics_priv *gr, struct point *p) -{ - if (!gr->cleanup) { - gr->pclean=gr->p; - gr->cleanup=1; - } - if (p) - gr->p=*p; - else { - gr->p.x=0; - gr->p.y=0; - } -} - -static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, int size, int flags) -{ - struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1); - *meth=font_methods; +static void draw_drag(struct graphics_priv *gr, struct point *p) { + if (!gr->cleanup) { + gr->pclean=gr->p; + gr->cleanup=1; + } + if (p) + gr->p=*p; + else { + gr->p.x=0; + gr->p.y=0; + } +} + +static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, + int size, int flags) { +#pragma unused (font, flags, gr) + struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1); + *meth=font_methods; - ret->size=size; - ret->name="Helvetica"; - return ret; + ret->size=size; + ret->name="Helvetica"; + return ret; } -static void -gc_destroy(struct graphics_gc_priv *gc) -{ - g_free(gc); +static void gc_destroy(struct graphics_gc_priv *gc) { + g_free(gc); } -static void -gc_set_linewidth(struct graphics_gc_priv *gc, int w) -{ - gc->w=w; +static void gc_set_linewidth(struct graphics_gc_priv *gc, int w) { + gc->w=w; } -static void -gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) -{ +static void gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) { +#pragma unused (gc, w, offset, dash_list, n) } -static void -gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) -{ - gc->rgba[0]=c->r/65535.0; - gc->rgba[1]=c->g/65535.0; - gc->rgba[2]=c->b/65535.0; - gc->rgba[3]=c->a/65535.0; +static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) { + gc->rgba[0]=c->r/65535.0; + gc->rgba[1]=c->g/65535.0; + gc->rgba[2]=c->b/65535.0; + gc->rgba[3]=c->a/65535.0; } -static void -gc_set_background(struct graphics_gc_priv *gc, struct color *c) -{ +static void gc_set_background(struct graphics_gc_priv *gc, struct color *c) { +#pragma unused (gc, c) +} + +static void gc_set_texture(struct graphics_gc_priv *gc, struct graphics_image_priv *img) { +#pragma unused (gc, img) } static struct graphics_gc_methods gc_methods = { - gc_destroy, - gc_set_linewidth, - gc_set_dashes, - gc_set_foreground, - gc_set_background, + gc_destroy, + gc_set_linewidth, + gc_set_dashes, + gc_set_foreground, + gc_set_background, + gc_set_texture, }; -static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) -{ - struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1); - gc->w=1; +static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) { +#pragma unused (gr, meth) + struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1); + gc->w=1; - *meth=gc_methods; - return gc; + *meth=gc_methods; + return gc; } -static void -background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) -{ +static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) { +#pragma unused (gr, gc) } -static struct graphics_priv * -overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound); +static struct graphics_priv *overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, + int w, int h, int wraparound); + + +static struct graphics_image_priv *image_new(struct graphics_priv *gra, struct graphics_image_methods *meth, char *path, + int *w, int *h, struct point *hot, int rotation) { +#pragma unused (gra, meth, rotation) + NSString *s=[[NSString alloc]initWithCString:path encoding:NSMacOSRomanStringEncoding]; + CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)[NSData dataWithContentsOfFile:s]); + [s release]; + + if (!imgDataProvider) + return NULL; + + CGImageRef image = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault); + CGDataProviderRelease(imgDataProvider); + dbg(1,"size %dx%d",(int)CGImageGetWidth(image),(int)CGImageGetHeight(image)); + if (w) + *w=(int)CGImageGetWidth(image); + if (h) + *h=(int)CGImageGetHeight(image); + if (hot) { + hot->x=(int)CGImageGetWidth(image)/2; + hot->y=(int)CGImageGetHeight(image)/2; + } + return (struct graphics_image_priv *)image; +} +static int cocoa_fullscreen(struct window *win, int on) { + return 0; +} -static struct graphics_image_priv * -image_new(struct graphics_priv *gra, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation) -{ - NSString *s=[[NSString alloc]initWithCString:path encoding:NSMacOSRomanStringEncoding]; - CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)[NSData dataWithContentsOfFile:s]); - [s release]; - - if (!imgDataProvider) - return NULL; - - CGImageRef image = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault); - CGDataProviderRelease(imgDataProvider); - dbg(1,"size %dx%d",CGImageGetWidth(image),CGImageGetHeight(image)); - if (w) - *w=CGImageGetWidth(image); - if (h) - *h=CGImageGetHeight(image); - if (hot) { - hot->x=CGImageGetWidth(image)/2; - hot->y=CGImageGetHeight(image)/2; - } - return (struct graphics_image_priv *)image; -} - -static void * -get_data(struct graphics_priv *this, const char *type) -{ - dbg(0,"enter"); - if (strcmp(type,"window")) - return NULL; - return &this->win; +static void *get_data(struct graphics_priv *this, const char *type) { + dbg(lvl_debug,"enter"); + if (strcmp(type,"window")) + return NULL; + this->win.fullscreen=cocoa_fullscreen; + this->win.disable_suspend=0; + return &this->win; } -static void -image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) -{ - CGImageRelease((CGImageRef)priv); +static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) { +#pragma unused (gr) + CGImageRelease((CGImageRef)priv); } -static void -get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate) -{ - int len = g_utf8_strlen(text, -1); - int xMin = 0; - int yMin = 0; - int yMax = 13*font->size/256; - int xMax = 9*font->size*len/256; - - ret[0].x = xMin; - ret[0].y = -yMin; - ret[1].x = xMin; - ret[1].y = -yMax; - ret[2].x = xMax; - ret[2].y = -yMax; - ret[3].x = xMax; - ret[3].y = -yMin; -} - -static void -overlay_disable(struct graphics_priv *gr, int disabled) -{ - gr->overlay_disabled=disabled; +static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, + struct point *ret, int estimate) { +#pragma unused (gr, dx, dy, estimate) + int len = (int)g_utf8_strlen(text, -1); + int xMin = 0; + int yMin = 0; + int yMax = 13*font->size/256; + int xMax = 9*font->size*len/256; + + ret[0].x = xMin; + ret[0].y = -yMin; + ret[1].x = xMin; + ret[1].y = -yMax; + ret[2].x = xMax; + ret[2].y = -yMax; + ret[3].x = xMax; + ret[3].y = -yMin; +} + +static void overlay_disable(struct graphics_priv *gr, int disabled) { + gr->overlay_disabled=disabled; +} + +static int set_attr(struct graphics_priv *gr, struct attr * attr) { + if(attr->type == attr_callback) { + callback_list_add(gr->cbl, attr->u.callback); + } + return 1; +} + +static void overlay_resize(struct graphics_priv *this, struct point *p, int w, int h, int wraparound) { + //do not dereference parent for non overlay osds + if(!this->parent) { + return; + } + + int changed = 0; + int w2,h2; + + if (w == 0) { + w2 = 1; + } else { + w2 = w; + } + + if (h == 0) { + h2 = 1; + } else { + h2 = h; + } + + this->p = *p; + if (this->w != w2) { + this->w = w2; + changed = 1; + } + + if (this->h != h2) { + this->h = h2; + changed = 1; + } + + this->wraparound = wraparound; + + if (changed) { + callback_list_call_attr_2(this->cbl, attr_resize, GINT_TO_POINTER(w), GINT_TO_POINTER(h)); + } +} + +static void graphics_destroy (struct graphics_priv *gr) { +#pragma unused (gr) } static struct graphics_methods graphics_methods = { - NULL, /* graphics_destroy, */ - draw_mode, - draw_lines, - draw_polygon, - draw_rectangle, - NULL, /* draw_circle, */ - draw_text, - draw_image, - NULL, /* draw_image_warp, */ - draw_drag, - font_new, - gc_new, - background_gc, - overlay_new, - image_new, - get_data, - image_free, - get_text_bbox, - overlay_disable, - NULL, /* overlay_resize, */ - NULL, /* set_attr, */ + graphics_destroy, /* graphics_destroy, */ + draw_mode, + draw_lines, + draw_polygon, + draw_rectangle, + NULL, /* draw_circle, */ + draw_text, + draw_image, + NULL, /* draw_image_warp, */ + draw_drag, + font_new, + gc_new, + background_gc, + overlay_new, + image_new, + get_data, + image_free, + get_text_bbox, + overlay_disable, + overlay_resize, + set_attr, + NULL, /* show_native_keyboard, */ + NULL, /* hide_native_keyboard, */ + NULL, /* navit_float, */ + NULL, /* draw_polygon_with_holes, */ }; +static struct graphics_priv *overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, + int w, int h, int wraparound) { + struct graphics_priv *ret=g_new0(struct graphics_priv, 1); + *meth=graphics_methods; + ret->p=*p; + ret->w=w; + ret->h=h; + ret->parent=gr; + ret->next=gr->overlays; + ret->wraparound=wraparound; + gr->overlays=ret; + setup_graphics(gr); + return ret; +} + +static struct graphics_priv *graphics_cocoa_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, + struct callback_list *cbl) { +#pragma unused (attrs) + struct graphics_priv *ret; + *meth=graphics_methods; + dbg(1,"enter"); + if(!event_request_system("cocoa","graphics_cocoa")) + return NULL; + ret=g_new0(struct graphics_priv, 1); + ret->navit = nav; + ret->cbl=cbl; + global_graphics_cocoa=ret; + return ret; +} + -static struct graphics_priv * -overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) -{ - struct graphics_priv *ret=g_new0(struct graphics_priv, 1); - *meth=graphics_methods; - ret->p=*p; - ret->w=w; - ret->h=h; - ret->parent=gr; - ret->next=gr->overlays; - ret->wraparound=wraparound; - gr->overlays=ret; - setup_graphics(gr); - return ret; -} - - -struct graphics_priv * -graphics_cocoa_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) -{ - struct graphics_priv *ret; - *meth=graphics_methods; - dbg(0,"enter"); - if(!event_request_system("cocoa","graphics_cocoa")) - return NULL; - ret=g_new0(struct graphics_priv, 1); - ret->cbl=cbl; - global_graphics_cocoa=ret; - return ret; -} - -static void -event_cocoa_main_loop_run(void) -{ - dbg(0,"enter"); +struct event_watch { + GIOChannel *iochan; + guint source; +}; + +static gboolean event_cocoa_call_watch(GIOChannel * iochan, GIOCondition condition, gpointer t) { +#pragma unused(iochan, condition) + struct callback *cb=t; + callback_call_0(cb); + return TRUE; +} + +static struct event_watch *event_cocoa_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) { + struct event_watch *ret=g_new0(struct event_watch, 1); + int flags=0; + ret->iochan = g_io_channel_unix_new(fd); + switch (cond) { + case event_watch_cond_read: + flags=G_IO_IN; + break; + case event_watch_cond_write: + flags=G_IO_OUT; + break; + case event_watch_cond_except: + flags=G_IO_ERR|G_IO_HUP; + break; + } + ret->source = g_io_add_watch(ret->iochan, flags, event_cocoa_call_watch, (gpointer)cb); + return ret; +} + +static void event_cocoa_remove_watch(struct event_watch *ev) { + if (! ev) + return; + g_source_remove(ev->source); + g_io_channel_unref(ev->iochan); + g_free(ev); +} + + +static void event_cocoa_main_loop_run(void) { + + dbg(1,"enter"); #if 0 - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *documentsDirectory = [paths objectAtIndex:0]; - NSString *logPath = [documentsDirectory stringByAppendingPathComponent:@"console.log"]; - freopen("/tmp/log.txt","a+",stderr); - NSLog(@"Test\n"); + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *documentsDirectory = [paths objectAtIndex:0]; + NSString *logPath = [documentsDirectory stringByAppendingPathComponent:@"console.log"]; + freopen("/tmp/log.txt","a+",stderr); + NSLog(@"Test\n"); #endif - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; #if USE_UIKIT - dbg(0,"calling main"); - int retval = UIApplicationMain(main_argc, main_argv, nil, @"NavitAppDelegate"); - dbg(0,"retval=%d",retval); + dbg(1,"calling main"); + int retval = UIApplicationMain(main_argc, (char * _Nullable * _Nonnull)main_argv, nil, @"NavitAppDelegate"); + dbg(1,"retval=%d",retval); #else - NavitAppDelegate * delegate = [[NavitAppDelegate alloc] init]; - NSApplication * application = [NSApplication sharedApplication]; - [application setDelegate:delegate]; - NSLog(@"Test\n"); + NavitAppDelegate * delegate = [[NavitAppDelegate alloc] init]; + NSApplication * application = [NSApplication sharedApplication]; + [application setDelegate:delegate]; + NSLog(@"Test\n"); - [NSApp run]; + [NSApp run]; - [delegate release]; + [delegate release]; #endif - [pool release]; + [pool release]; +} + +#if (!USE_UIKIT) +static void event_cocoa_main_loop_quit(void) { + [NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0]; } +#endif -@interface NavitTimer : NSObject{ +@interface NavitTimer : NSObject { @public - struct callback *cb; - NSTimer *timer; + struct callback *cb; + NSTimer *timer; } - (void)onTimer:(NSTimer*)theTimer; @@ -720,86 +969,84 @@ - (void)onTimer:(NSTimer*)theTimer; @implementation NavitTimer -- (void)onTimer:(NSTimer*)theTimer -{ - callback_call_0(cb); +- (void)onTimer:(NSTimer*)theTimer { + callback_call_0(cb); } @end struct event_idle { - struct callback *cb; - NSTimer *timer; + struct callback *cb; + NSTimer *timer; }; -static struct event_timeout * -event_cocoa_add_timeout(int timeout, int multi, struct callback *cb) -{ - NavitTimer *ret=[[NavitTimer alloc]init]; - ret->cb=cb; - ret->timer=[NSTimer scheduledTimerWithTimeInterval:(timeout/1000.0) target:ret selector:@selector(onTimer:) userInfo:nil repeats:multi?YES:NO]; - dbg(1,"timer=%p",ret->timer); - return (struct event_timeout *)ret; +static struct event_timeout *event_cocoa_add_timeout(int timeout, int multi, struct callback *cb) { + NavitTimer *ret=[[NavitTimer alloc]init]; + ret->cb=cb; + ret->timer=[NSTimer scheduledTimerWithTimeInterval:(timeout/1000.0) target:ret selector:@selector( + onTimer:) userInfo:nil repeats:multi?YES:NO]; + dbg(1,"timer=%p",ret->timer); + return (struct event_timeout *)ret; } -static void -event_cocoa_remove_timeout(struct event_timeout *ev) -{ - NavitTimer *t=(NavitTimer *)ev; +static void event_cocoa_remove_timeout(struct event_timeout *ev) { + NavitTimer *t=(NavitTimer *)ev; - [t->timer invalidate]; - [t release]; + if(t) { + [t->timer invalidate]; + [t release]; + } } -static struct event_idle * -event_cocoa_add_idle(int priority, struct callback *cb) -{ - NavitTimer *ret=[[NavitTimer alloc]init]; - ret->cb=cb; - ret->timer=[NSTimer scheduledTimerWithTimeInterval:(0.0) target:ret selector:@selector(onTimer:) userInfo:nil repeats:YES]; +static struct event_idle *event_cocoa_add_idle(int priority, struct callback *cb) { +#pragma unused (priority) + NavitTimer *ret=[[NavitTimer alloc]init]; + ret->cb=cb; + ret->timer=[NSTimer scheduledTimerWithTimeInterval:(0.0) target:ret selector:@selector( + onTimer:) userInfo:nil repeats:YES]; - dbg(1,"timer=%p",ret->timer); - return (struct event_idle *)ret; + dbg(1,"timer=%p",ret->timer); + return (struct event_idle *)ret; } -static void -event_cocoa_remove_idle(struct event_idle *ev) -{ - NavitTimer *t=(NavitTimer *)ev; +static void event_cocoa_remove_idle(struct event_idle *ev) { + NavitTimer *t=(NavitTimer *)ev; - [t->timer invalidate]; - [t release]; + [t->timer invalidate]; + [t release]; } static struct event_methods event_cocoa_methods = { - event_cocoa_main_loop_run, - NULL, /* event_cocoa_main_loop_quit, */ - NULL, /* event_cocoa_add_watch, */ - NULL, /* event_cocoa_remove_watch, */ - event_cocoa_add_timeout, - event_cocoa_remove_timeout, - event_cocoa_add_idle, - event_cocoa_remove_idle, - NULL, /* event_cocoa_call_callback, */ + event_cocoa_main_loop_run, +#if (USE_UIKIT) + NULL, /* event_cocoa_main_loop_quit */ + NULL, /* event_cocoa_add_watch */ + NULL, /* event_cocoa_remove_watch */ +#else + event_cocoa_main_loop_quit, + event_cocoa_add_watch, + event_cocoa_remove_watch, +#endif + event_cocoa_add_timeout, + event_cocoa_remove_timeout, + event_cocoa_add_idle, + event_cocoa_remove_idle, + NULL, /* event_cocoa_call_callback, */ }; -static struct event_priv * -event_cocoa_new(struct event_methods *meth) -{ - dbg(0,"enter"); - *meth=event_cocoa_methods; - return NULL; +static struct event_priv *event_cocoa_new(struct event_methods *meth) { + dbg(1,"enter"); + *meth=event_cocoa_methods; + return NULL; } -void -plugin_init(void) -{ - dbg(0,"enter"); - plugin_register_category_graphics("cocoa", graphics_cocoa_new); - plugin_register_category_event("cocoa", event_cocoa_new); +void plugin_init(void) { + dbg(1,"enter"); + plugin_register_category_graphics("cocoa", graphics_cocoa_new); + plugin_register_category_event("cocoa", event_cocoa_new); } diff --git a/navit/graphics/egl/graphics_egl.c b/navit/graphics/egl/graphics_egl.c index 87291d7393..71677ee649 100644 --- a/navit/graphics/egl/graphics_egl.c +++ b/navit/graphics/egl/graphics_egl.c @@ -31,7 +31,7 @@ #include "graphics.h" #include "color.h" #include "plugin.h" -#include "event.h" +#include "navit/event.h" #include "debug.h" #include "callback.h" #include "keys.h" diff --git a/navit/graphics/gtk_drawing_area/CMakeLists.txt b/navit/graphics/gtk_drawing_area/CMakeLists.txt index b5b55f4f66..1999535154 100644 --- a/navit/graphics/gtk_drawing_area/CMakeLists.txt +++ b/navit/graphics/gtk_drawing_area/CMakeLists.txt @@ -1,3 +1,6 @@ set(graphics_gtk_drawing_area_LIBS ${IMLIB2_LDFLAGS} ${GTK2_LIBRARIES}) +if(BUILD_BUNDLE) + add_compile_options(-x objective-c) +endif(BUILD_BUNDLE) module_add_library(graphics_gtk_drawing_area graphics_gtk_drawing_area.c) diff --git a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c index e9d34dd826..4933c77e58 100644 --- a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c +++ b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c @@ -25,19 +25,26 @@ #include #include #include + #include #include /* For WIN32 */ #if !defined(GDK_KEY_Book) || !defined(GDK_Book) || !defined(GDK_Calendar) +#if !defined(__APPLE__) #include #endif +#endif #ifdef HAVE_IMLIB2 #include #endif #ifndef _WIN32 +#if !defined(__APPLE__) #include +#else +#include +#endif #endif -#include "event.h" +#include "navit/event.h" /* in case espeak is enabled the system finds the wrong event.h without navit/ prefix */ #include "debug.h" #include "point.h" #include "graphics.h" @@ -625,7 +632,11 @@ static gint configure(GtkWidget * widget, GdkEventConfigure * event, gpointer us if (! gra->visible) return TRUE; #ifndef _WIN32 +#if defined(__APPLE__) + dbg(lvl_debug,"window=%lu", GDK_WINDOW(widget->window)); +#else dbg(lvl_debug,"window=%lu", GDK_WINDOW_XID(widget->window)); +#endif #endif gra->width=widget->allocation.width; gra->height=widget->allocation.height; @@ -1016,7 +1027,11 @@ static void *get_data(struct graphics_priv *this, char const *type) { return this->widget; #ifndef _WIN32 if (!strcmp(type,"xwindow_id")) +#if defined(__APPLE__) + return (void *)GDK_WINDOW(this->win ? this->win->window : this->widget->window); +#else return (void *)GDK_WINDOW_XID(this->win ? this->win->window : this->widget->window); +#endif #endif if (!strcmp(type,"window")) { char *cp = getenv("NAVIT_XID"); @@ -1112,7 +1127,7 @@ static struct graphics_priv *graphics_gtk_drawing_area_new(struct navit *nav, st GtkWidget *draw; struct attr *attr; - if (! event_request_system("glib","graphics_gtk_drawing_area_new")) + if (event_request_system((const char *)"glib",(const char *)"graphics_gtk_drawing_area_new")==0) return NULL; draw=gtk_drawing_area_new(); diff --git a/navit/graphics/null/graphics_null.c b/navit/graphics/null/graphics_null.c index a04d12b6a9..7e8b337766 100644 --- a/navit/graphics/null/graphics_null.c +++ b/navit/graphics/null/graphics_null.c @@ -27,7 +27,7 @@ #include "graphics.h" #include "color.h" #include "plugin.h" -#include "event.h" +#include "navit/event.h" #include "debug.h" #include "window.h" #include "callback.h" diff --git a/navit/graphics/opengl/graphics_opengl.c b/navit/graphics/opengl/graphics_opengl.c index cc644e641e..abfab85820 100644 --- a/navit/graphics/opengl/graphics_opengl.c +++ b/navit/graphics/opengl/graphics_opengl.c @@ -34,7 +34,7 @@ #include "graphics.h" #include "color.h" #include "plugin.h" -#include "event.h" +#include "navit/event.h" #include "debug.h" #include "callback.h" #include "keys.h" @@ -79,6 +79,7 @@ typedef double GLdouble; #define USE_FLOAT 1 #ifdef __APPLE__ #include +# define APIENTRY #else #include /* glut.h includes gl.h and glu.h */ #endif diff --git a/navit/graphics/opengl/graphics_opengl_x11.c b/navit/graphics/opengl/graphics_opengl_x11.c index e8af93028f..46704215c0 100644 --- a/navit/graphics/opengl/graphics_opengl_x11.c +++ b/navit/graphics/opengl/graphics_opengl_x11.c @@ -2,7 +2,7 @@ #include #include #include "debug.h" -#include "event.h" +#include "navit/event.h" #include "callback.h" #include "graphics_opengl.h" diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp index dcd0d2aa57..5181c7d64a 100644 --- a/navit/graphics/qt5/QNavitQuick.cpp +++ b/navit/graphics/qt5/QNavitQuick.cpp @@ -28,7 +28,7 @@ extern "C" { #include "callback.h" #include "color.h" #include "debug.h" -#include "event.h" +#include "navit/event.h" #include "point.h" /* needs to be before graphics.h */ diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp index 869d5f2ec3..0385589827 100644 --- a/navit/graphics/qt5/QNavitWidget.cpp +++ b/navit/graphics/qt5/QNavitWidget.cpp @@ -28,7 +28,7 @@ extern "C" { #include "callback.h" #include "color.h" #include "debug.h" -#include "event.h" +#include "navit/event.h" #include "point.h" /* needs to be before graphics.h */ diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index e2747ff78b..f940c181c2 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -28,7 +28,7 @@ extern "C" { #include "callback.h" #include "color.h" #include "debug.h" -#include "event.h" +#include "navit/event.h" #include "point.h" /* needs to be before graphics.h */ diff --git a/navit/graphics/sdl/event_sdl.c b/navit/graphics/sdl/event_sdl.c index 454e9eb069..05cf83b095 100644 --- a/navit/graphics/sdl/event_sdl.c +++ b/navit/graphics/sdl/event_sdl.c @@ -23,7 +23,7 @@ #include #include #include "config.h" -#include "event.h" +#include "navit/event.h" #include "event_sdl.h" #include "graphics_sdl.h" #include "debug.h" diff --git a/navit/graphics/sdl/event_sdl.h b/navit/graphics/sdl/event_sdl.h index ee47f60d9e..2e2936a475 100644 --- a/navit/graphics/sdl/event_sdl.h +++ b/navit/graphics/sdl/event_sdl.h @@ -5,7 +5,7 @@ #include "SDL.h" #include "config.h" #include "callback.h" -#include "event.h" +#include "navit/event.h" #include "graphics_sdl.h" #ifdef USE_WEBOS diff --git a/navit/graphics/svg_debug/graphics_svg_debug.c b/navit/graphics/svg_debug/graphics_svg_debug.c index 348906ad83..e64815829d 100644 --- a/navit/graphics/svg_debug/graphics_svg_debug.c +++ b/navit/graphics/svg_debug/graphics_svg_debug.c @@ -50,7 +50,7 @@ #include "graphics.h" #include "color.h" #include "navit.h" -#include "event.h" +#include "navit/event.h" #include "debug.h" #include "callback.h" #include "util.h" diff --git a/navit/graphics/win32/graphics_win32.h b/navit/graphics/win32/graphics_win32.h index c50dbf4f7d..4162de1fca 100644 --- a/navit/graphics/win32/graphics_win32.h +++ b/navit/graphics/win32/graphics_win32.h @@ -5,7 +5,7 @@ #include "coord.h" #include "point.h" #include "graphics.h" -#include "event.h" +#include "navit/event.h" #ifdef UNICODE #include diff --git a/navit/gui/gtk/gui_gtk_window.c b/navit/gui/gtk/gui_gtk_window.c index f0d13528a0..868f51ce77 100644 --- a/navit/gui/gtk/gui_gtk_window.c +++ b/navit/gui/gtk/gui_gtk_window.c @@ -45,7 +45,7 @@ #include "vehicle.h" #include "map.h" #include "coord.h" -#include "event.h" +#include "navit/event.h" #include "bookmarks.h" #include "route.h" #include "navit_nls.h" diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index e8759f3d3f..215f822455 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -68,7 +68,7 @@ #include "track.h" #include "country.h" #include "config.h" -#include "event.h" +#include "navit/event.h" #include "navit_nls.h" #include "navigation.h" #include "gui_internal.h" diff --git a/navit/gui/internal/gui_internal_command.c b/navit/gui/internal/gui_internal_command.c index 4c0abcdb5c..3b1fb903f0 100644 --- a/navit/gui/internal/gui_internal_command.c +++ b/navit/gui/internal/gui_internal_command.c @@ -16,7 +16,7 @@ #include "command.h" #include "attr.h" #include "xmlconfig.h" -#include "event.h" +#include "navit/event.h" #include "config_.h" #include "map.h" #include "mapset.h" diff --git a/navit/gui/internal/gui_internal_gesture.c b/navit/gui/internal/gui_internal_gesture.c index 0ed2805cca..fac192db8a 100644 --- a/navit/gui/internal/gui_internal_gesture.c +++ b/navit/gui/internal/gui_internal_gesture.c @@ -16,7 +16,7 @@ #include "navit.h" #include "types.h" #include "navit_nls.h" -#include "event.h" +#include "navit/event.h" #include "search.h" #include "country.h" #include "track.h" diff --git a/navit/gui/internal/gui_internal_search.c b/navit/gui/internal/gui_internal_search.c index 66524e4077..fc1d674ce7 100644 --- a/navit/gui/internal/gui_internal_search.c +++ b/navit/gui/internal/gui_internal_search.c @@ -9,7 +9,7 @@ #include "debug.h" #include "navit.h" #include "navit_nls.h" -#include "event.h" +#include "navit/event.h" #include "search.h" #include "country.h" #include "track.h" diff --git a/navit/gui/qml/gui_qml.cpp b/navit/gui/qml/gui_qml.cpp index c8d20450ed..fc4af97af9 100644 --- a/navit/gui/qml/gui_qml.cpp +++ b/navit/gui/qml/gui_qml.cpp @@ -18,7 +18,7 @@ #include "navit.h" #include "point.h" #include "graphics.h" -#include "event.h" +#include "navit/event.h" #include "map.h" #include "coord.h" #include "vehicle.h" diff --git a/navit/gui/qt5_qml/gui_qt5_qml.cpp b/navit/gui/qt5_qml/gui_qt5_qml.cpp index caab81709d..00dd3e74a7 100644 --- a/navit/gui/qt5_qml/gui_qt5_qml.cpp +++ b/navit/gui/qt5_qml/gui_qt5_qml.cpp @@ -36,7 +36,7 @@ extern "C" { #include "coord.h" #include "country.h" #include "debug.h" -#include "event.h" +#include "navit/event.h" #include "point.h" /* needs to be before graphics.h */ diff --git a/navit/icons/CMakeLists.txt b/navit/icons/CMakeLists.txt index 548bef441c..3b9c1e95a7 100644 --- a/navit/icons/CMakeLists.txt +++ b/navit/icons/CMakeLists.txt @@ -137,7 +137,7 @@ foreach (IMAGE_FILE ${IMAGES_TO_COPY}) endforeach() add_custom_target(images ALL DEPENDS ${IMAGE_TARGETS}) -add_custom_target(images_resource COMMAND mkdir -p ../resources/share/navit/xpm COMMAND cp ${IMAGE_TARGETS} ../resources/share/navit/xpm) +add_custom_target(images_resource COMMAND mkdir -p ../resources/share/navit/icons COMMAND cp ${IMAGE_TARGETS} ../resources/share/navit/icons) add_dependencies(images_resource images) install( diff --git a/navit/log.c b/navit/log.c index 490414c037..79c10ad330 100644 --- a/navit/log.c +++ b/navit/log.c @@ -42,7 +42,7 @@ #include #include "file.h" #include "item.h" -#include "event.h" +#include "navit/event.h" #include "callback.h" #include "debug.h" #include "xmlconfig.h" diff --git a/navit/main.c b/navit/main.c index 0faf444859..6237b826ea 100644 --- a/navit/main.c +++ b/navit/main.c @@ -46,7 +46,7 @@ #include "coord.h" #include "route.h" #include "navigation.h" -#include "event.h" +#include "navit/event.h" #include "callback.h" #include "navit_nls.h" #include "util.h" diff --git a/navit/maptool/CMakeLists.txt b/navit/maptool/CMakeLists.txt index 8c4c824a8f..d13079d5b2 100644 --- a/navit/maptool/CMakeLists.txt +++ b/navit/maptool/CMakeLists.txt @@ -25,7 +25,9 @@ if(BUILD_MAPTOOL) endif(NOT MSVC) target_link_libraries(maptool maptool_core ${NAVIT_LIBNAME} ${NAVIT_LIBS}) - +if(BUILD_BUNDLE) + set_target_properties(maptool PROPERTIES MACOSX_BUNDLE TRUE) +endif(BUILD_BUNDLE) install(TARGETS maptool DESTINATION ${BIN_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/navit/messages.c b/navit/messages.c index bcb3f5e74f..9809bbff2f 100644 --- a/navit/messages.c +++ b/navit/messages.c @@ -21,7 +21,7 @@ #include #include "messages.h" #include "callback.h" -#include "event.h" +#include "navit/event.h" #include "attr.h" struct messagelist { diff --git a/navit/navigation.c b/navit/navigation.c index dd7c9fbf58..ab12a6a177 100644 --- a/navit/navigation.c +++ b/navit/navigation.c @@ -35,7 +35,7 @@ #include "projection.h" #include "map.h" #include "navit.h" -#include "event.h" +#include "navit/event.h" #include "callback.h" #include "speech.h" #include "vehicleprofile.h" diff --git a/navit/navit.c b/navit/navit.c index 5248e10eab..24960722b5 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -58,7 +58,7 @@ #include "layout.h" #include "log.h" #include "attr.h" -#include "event.h" +#include "navit/event.h" #include "file.h" #include "profile.h" #include "command.h" diff --git a/navit/navit_shipped_gtkgui.xml b/navit/navit_shipped_gtkgui.xml new file mode 100644 index 0000000000..e07aa0c683 --- /dev/null +++ b/navit/navit_shipped_gtkgui.xml @@ -0,0 +1,468 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Main menu + Actions + Show +Map + Settings + Tools + Route + About + Quit + + Actions + Bookmarks + Former +Destinations + + + Town + Coordinates + Stop +Navigation + + Settings + Display + Maps + + Vehicle + + Rules + + Display + + Layout + Fullscreen + Window Mode + 3D + 2D + Auto zoom + Manual zoom + Layers + + Tools + Show Locale + Network info + + Route + Zoom to route + Description + Height Profile + Waypoints + Drop last +Waypoint + Drop next +Waypoint + + Map Point + + + Layout + + + Maps + + + Layers + + + Vehicle + + + + + + Satellite Status + + + NMEA Data + + + + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/navit/osd/core/osd_core.c b/navit/osd/core/osd_core.c index 40ea4350da..fa8b9e0bbe 100644 --- a/navit/osd/core/osd_core.c +++ b/navit/osd/core/osd_core.c @@ -55,7 +55,7 @@ #include "roadprofile.h" #include "osd.h" #include "speech.h" -#include "event.h" +#include "navit/event.h" #include "mapset.h" #include "util.h" diff --git a/navit/route.c b/navit/route.c index 9d9ecf23de..1749a6b0f2 100644 --- a/navit/route.c +++ b/navit/route.c @@ -103,7 +103,7 @@ #include "transform.h" #include "plugin.h" #include "fib.h" -#include "event.h" +#include "navit/event.h" #include "callback.h" #include "vehicle.h" #include "vehicleprofile.h" diff --git a/navit/script.c b/navit/script.c index 1af8b6239a..977937f378 100644 --- a/navit/script.c +++ b/navit/script.c @@ -20,7 +20,7 @@ #include #include "item.h" #include "debug.h" -#include "event.h" +#include "navit/event.h" #include "callback.h" #include "command.h" #include "xmlconfig.h" diff --git a/navit/speech/iphone/speech_iphone.m b/navit/speech/iphone/speech_iphone.m index 571f6784b2..6f4c8db4d5 100644 --- a/navit/speech/iphone/speech_iphone.m +++ b/navit/speech/iphone/speech_iphone.m @@ -24,51 +24,67 @@ #include "debug.h" #include "plugin.h" #include "speech.h" +#include "attr.h" #import "VSSpeechSynthesizer.h" +#import struct speech_priv { - VSSpeechSynthesizer *speech; + VSSpeechSynthesizer *speech; }; -static int -speech_iphone_say(struct speech_priv *this, const char *text) -{ - dbg(0,"enter %s",text); - NSString *s=[[NSString alloc]initWithUTF8String: text]; - [this->speech startSpeakingString:s toURL:nil]; - [s release]; - dbg(0,"ok"); - return 1; +static int speech_iphone_say(struct speech_priv *this, const char *text) { + dbg(lvl_error,"enter %s",text); + NSString *s=[[NSString alloc]initWithUTF8String: text]; + [this->speech startSpeakingString:s]; + [s release]; + dbg(lvl_debug,"ok"); + return 1; } -static void -speech_iphone_destroy(struct speech_priv *this) -{ - [this->speech release]; - g_free(this); +static void speech_iphone_destroy(struct speech_priv *this) { + [this->speech release]; + g_free(this); } static struct speech_methods speech_iphone_meth = { - speech_iphone_destroy, - speech_iphone_say, + speech_iphone_destroy, + speech_iphone_say, }; -static struct speech_priv * -speech_iphone_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent) -{ - struct speech_priv *this; - *meth=speech_iphone_meth; - this=g_new0(struct speech_priv,1); - this->speech=[[NSClassFromString(@"VSSpeechSynthesizer") alloc] init]; - dbg(0,"this->speech=%p",this->speech); - [this->speech setRate:(float)1.0]; - return this; -} +static struct speech_priv *speech_iphone_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent) { + struct speech_priv *this; + *meth=speech_iphone_meth; + this=g_new0(struct speech_priv,1); + this->speech= [VSSpeechSynthesizer alloc]; + [this->speech init]; + dbg(lvl_debug,"this->speech=%p",this->speech); + + [this->speech setRate:0.5]; + NSLog(@"iOS is >= 10: %f", [[[UIDevice currentDevice] systemVersion] floatValue]); + + [this->speech setVolume:100.0]; + [this->speech setPitch:0.8]; + + struct attr *attr; + // With the attribute speech_use_hfp="1" user can force to use HFP always. + // This will force background music to HFP as well. + // If not set we set HFP, but will automatically switch to A2DP when background music is being played + // A2DP will not stop your radio from playing when an announcement is spoken + if ((attr=attr_search(attrs, attr_speech_use_hfp))) + [this->speech useHFP:(int)attr->u.num force:YES]; + else + [this->speech useHFP:YES force:NO]; // AUTO + + if ((attr=attr_search(attrs, attr_speech_hfp_delay))) + [this->speech setHFPDelay: attr->u.num*0.001]; + else + [this->speech setHFPDelay:DEFAULT_HFP_DELAY]; + + return this; +} -void -plugin_init(void) -{ - dbg(0,"enter"); - plugin_register_category_speech("iphone", speech_iphone_new); +void plugin_init(void) { + dbg(lvl_debug,"enter"); + plugin_register_category_speech("iphone", speech_iphone_new); } diff --git a/navit/start_apple.m b/navit/start_apple.m index 114fd4bbe0..5f1384ed62 100644 --- a/navit/start_apple.m +++ b/navit/start_apple.m @@ -21,29 +21,38 @@ #import #include #include +#include "debug.h" -int -main(int argc, char **argv) -{ - int ret; - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - NSString *appFolderPath = [[NSBundle mainBundle] resourcePath]; - NSString *locale = [[NSLocale currentLocale] localeIdentifier]; - char *lang=g_strdup_printf("%s.UTF-8",[locale UTF8String]); - dbg(0,"lang %s",lang); - setenv("LANG",lang,0); - setlocale(LC_ALL, NULL); +int main(int argc, char **argv) { + int ret; + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSString *appFolderPath = [[NSBundle mainBundle] resourcePath]; + //NSString *locale = [[NSLocale currentLocale] localeIdentifier]; + NSString *language = [[NSLocale preferredLanguages] firstObject]; + if(language.UTF8String[2]=='-') //IOS returns e.g. de-DE instead of de_DE + language=[language stringByReplacingOccurrencesOfString:@"-" withString:@"_"]; + char *lang=g_strdup_printf("%s.UTF-8",[language UTF8String]); + dbg(0,"lang %s",lang); + setenv("LANG",lang,0); + setlocale(LC_ALL, NULL); + setlocale(LC_NUMERIC,"C"); - const char *s=[appFolderPath UTF8String]; - char *user=g_strdup_printf("%s/../Documents",s); - chdir(s); - argv[0]=g_strdup_printf("%s/bin/navit",s); - setenv("NAVIT_USER_DATADIR",user,0); + const char *s=[appFolderPath UTF8String]; +#if IOS + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *documentsDirectory = [paths objectAtIndex:0]; + char *user=(char *)[documentsDirectory cStringUsingEncoding:[NSString defaultCStringEncoding]] ; +#else + char *user=g_strdup_printf("%s/.navit", NSHomeDirectory().UTF8String); +#endif + chdir(s); + argv[0]=g_strdup_printf("%s/bin/navit",s); + setenv("NAVIT_USER_DATADIR",user,0); - dbg(0,"calling main_real"); - ret=main_real(argc, argv); - g_free(argv[0]); - g_free(user); - [pool release]; - return ret; + dbg(0,"calling main_real"); + ret=main_real(argc, argv); + g_free(argv[0]); + g_free(user); + [pool release]; + return ret; } diff --git a/navit/start_real.c b/navit/start_real.c index a29d558bf7..724b234527 100644 --- a/navit/start_real.c +++ b/navit/start_real.c @@ -34,7 +34,7 @@ #include "navigation.h" #include "track.h" #include "debug.h" -#include "event.h" +#include "navit/event.h" #include "event_glib.h" #include "xmlconfig.h" #include "file.h" diff --git a/navit/support/espeak/speak_lib.c b/navit/support/espeak/speak_lib.c index 99269c42ff..da6f134fd5 100644 --- a/navit/support/espeak/speak_lib.c +++ b/navit/support/espeak/speak_lib.c @@ -48,7 +48,7 @@ #include "debug.h" #include "fifo.h" -#include "event.h" +#include "navit/event.h" #include "wave.h" #define double(x) ((double)(x)) diff --git a/navit/support/gettext_intl/localcharset.c b/navit/support/gettext_intl/localcharset.c index 4865f1037a..a866b5345f 100644 --- a/navit/support/gettext_intl/localcharset.c +++ b/navit/support/gettext_intl/localcharset.c @@ -36,9 +36,9 @@ #else # include #endif -#if HAVE_STDLIB_H +//#if HAVE_STDLIB_H # include -#endif +//#endif #if defined _WIN32 || defined __WIN32__ # undef WIN32 /* avoid warning on mingw32 */ @@ -74,7 +74,7 @@ #endif #if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__ - /* Win32, OS/2, DOS */ +/* Win32, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') #endif @@ -106,156 +106,144 @@ static const char * volatile charset_aliases; /* Return a pointer to the contents of the charset.alias file. */ -static const char * -get_charset_aliases () -{ - const char *cp; - - cp = charset_aliases; - if (cp == NULL) - { +static const char *get_charset_aliases () { + const char *cp; + + cp = charset_aliases; + if (cp == NULL) { #if !(defined VMS || defined WIN32) - FILE *fp; - const char *dir = relocate (LIBDIR); - const char *base = "charset.alias"; - char *file_name; - - /* Concatenate dir and base into freshly allocated file_name. */ - { - size_t dir_len = strlen (dir); - size_t base_len = strlen (base); - int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); - file_name = (char *) malloc (dir_len + add_slash + base_len + 1); - if (file_name != NULL) - { - memcpy (file_name, dir, dir_len); - if (add_slash) - file_name[dir_len] = DIRECTORY_SEPARATOR; - memcpy (file_name + dir_len + add_slash, base, base_len + 1); - } - } - - if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL) - /* Out of memory or file not found, treat it as empty. */ - cp = ""; - else - { - /* Parse the file's contents. */ - int c; - char buf1[50+1]; - char buf2[50+1]; - char *res_ptr = NULL; - size_t res_size = 0; - size_t l1, l2; - - for (;;) - { - c = getc (fp); - if (c == EOF) - break; - if (c == '\n' || c == ' ' || c == '\t') - continue; - if (c == '#') - { - /* Skip comment, to end of line. */ - do - c = getc (fp); - while (!(c == EOF || c == '\n')); - if (c == EOF) - break; - continue; - } - ungetc (c, fp); - if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) - break; - l1 = strlen (buf1); - l2 = strlen (buf2); - if (res_size == 0) - { - res_size = l1 + 1 + l2 + 1; - res_ptr = (char *) malloc (res_size + 1); - } - else - { - res_size += l1 + 1 + l2 + 1; - res_ptr = (char *) realloc (res_ptr, res_size + 1); - } - if (res_ptr == NULL) - { - /* Out of memory. */ - res_size = 0; - break; - } - strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); - strcpy (res_ptr + res_size - (l2 + 1), buf2); - } - fclose (fp); - if (res_size == 0) - cp = ""; - else - { - *(res_ptr + res_size) = '\0'; - cp = res_ptr; - } - } - - if (file_name != NULL) - free (file_name); + FILE *fp; + const char *dir = relocate (LIBDIR); + const char *base = "charset.alias"; + char *file_name; + + /* Concatenate dir and base into freshly allocated file_name. */ + { + size_t dir_len = strlen (dir); + size_t base_len = strlen (base); + int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); + file_name = (char *) malloc (dir_len + add_slash + base_len + 1); + if (file_name != NULL) { + memcpy (file_name, dir, dir_len); + if (add_slash) + file_name[dir_len] = DIRECTORY_SEPARATOR; + memcpy (file_name + dir_len + add_slash, base, base_len + 1); + } + } + + if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL) + /* Out of memory or file not found, treat it as empty. */ + cp = ""; + else { + /* Parse the file's contents. */ + int c; + char buf1[50+1]; + char buf2[50+1]; + char *res_ptr = NULL; + size_t res_size = 0; + size_t l1, l2; + + for (;;) { + c = getc (fp); + if (c == EOF) + break; + if (c == '\n' || c == ' ' || c == '\t') + continue; + if (c == '#') { + /* Skip comment, to end of line. */ + do + c = getc (fp); + while (!(c == EOF || c == '\n')); + if (c == EOF) + break; + continue; + } + ungetc (c, fp); + if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) + break; + l1 = strlen (buf1); + l2 = strlen (buf2); + if (res_size == 0) { + res_size = l1 + 1 + l2 + 1; + res_ptr = (char *) malloc (res_size + 1); + } else { + res_size += l1 + 1 + l2 + 1; + res_ptr = (char *) realloc (res_ptr, res_size + 1); + } + if (res_ptr == NULL) { + /* Out of memory. */ + res_size = 0; + break; + } + strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); + strcpy (res_ptr + res_size - (l2 + 1), buf2); + } + fclose (fp); + if (res_size == 0) + cp = ""; + else { + *(res_ptr + res_size) = '\0'; + cp = res_ptr; + } + } + + if (file_name != NULL) + free (file_name); #else # if defined VMS - /* To avoid the troubles of an extra file charset.alias_vms in the - sources of many GNU packages, simply inline the aliases here. */ - /* The list of encodings is taken from the OpenVMS 7.3-1 documentation - "Compaq C Run-Time Library Reference Manual for OpenVMS systems" - section 10.7 "Handling Different Character Sets". */ - cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" - "ISO8859-2" "\0" "ISO-8859-2" "\0" - "ISO8859-5" "\0" "ISO-8859-5" "\0" - "ISO8859-7" "\0" "ISO-8859-7" "\0" - "ISO8859-8" "\0" "ISO-8859-8" "\0" - "ISO8859-9" "\0" "ISO-8859-9" "\0" - /* Japanese */ - "eucJP" "\0" "EUC-JP" "\0" - "SJIS" "\0" "SHIFT_JIS" "\0" - "DECKANJI" "\0" "DEC-KANJI" "\0" - "SDECKANJI" "\0" "EUC-JP" "\0" - /* Chinese */ - "eucTW" "\0" "EUC-TW" "\0" - "DECHANYU" "\0" "DEC-HANYU" "\0" - "DECHANZI" "\0" "GB2312" "\0" - /* Korean */ - "DECKOREAN" "\0" "EUC-KR" "\0"; + /* To avoid the troubles of an extra file charset.alias_vms in the + sources of many GNU packages, simply inline the aliases here. */ + /* The list of encodings is taken from the OpenVMS 7.3-1 documentation + "Compaq C Run-Time Library Reference Manual for OpenVMS systems" + section 10.7 "Handling Different Character Sets". */ + cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" + "ISO8859-2" "\0" "ISO-8859-2" "\0" + "ISO8859-5" "\0" "ISO-8859-5" "\0" + "ISO8859-7" "\0" "ISO-8859-7" "\0" + "ISO8859-8" "\0" "ISO-8859-8" "\0" + "ISO8859-9" "\0" "ISO-8859-9" "\0" + /* Japanese */ + "eucJP" "\0" "EUC-JP" "\0" + "SJIS" "\0" "SHIFT_JIS" "\0" + "DECKANJI" "\0" "DEC-KANJI" "\0" + "SDECKANJI" "\0" "EUC-JP" "\0" + /* Chinese */ + "eucTW" "\0" "EUC-TW" "\0" + "DECHANYU" "\0" "DEC-HANYU" "\0" + "DECHANZI" "\0" "GB2312" "\0" + /* Korean */ + "DECKOREAN" "\0" "EUC-KR" "\0"; # endif # if defined WIN32 - /* To avoid the troubles of installing a separate file in the same - directory as the DLL and of retrieving the DLL's directory at - runtime, simply inline the aliases here. */ - - cp = "CP936" "\0" "GBK" "\0" - "CP1361" "\0" "JOHAB" "\0" - "CP20127" "\0" "ASCII" "\0" - "CP20866" "\0" "KOI8-R" "\0" - "CP21866" "\0" "KOI8-RU" "\0" - "CP28591" "\0" "ISO-8859-1" "\0" - "CP28592" "\0" "ISO-8859-2" "\0" - "CP28593" "\0" "ISO-8859-3" "\0" - "CP28594" "\0" "ISO-8859-4" "\0" - "CP28595" "\0" "ISO-8859-5" "\0" - "CP28596" "\0" "ISO-8859-6" "\0" - "CP28597" "\0" "ISO-8859-7" "\0" - "CP28598" "\0" "ISO-8859-8" "\0" - "CP28599" "\0" "ISO-8859-9" "\0" - "CP28605" "\0" "ISO-8859-15" "\0"; + /* To avoid the troubles of installing a separate file in the same + directory as the DLL and of retrieving the DLL's directory at + runtime, simply inline the aliases here. */ + + cp = "CP936" "\0" "GBK" "\0" + "CP1361" "\0" "JOHAB" "\0" + "CP20127" "\0" "ASCII" "\0" + "CP20866" "\0" "KOI8-R" "\0" + "CP21866" "\0" "KOI8-RU" "\0" + "CP28591" "\0" "ISO-8859-1" "\0" + "CP28592" "\0" "ISO-8859-2" "\0" + "CP28593" "\0" "ISO-8859-3" "\0" + "CP28594" "\0" "ISO-8859-4" "\0" + "CP28595" "\0" "ISO-8859-5" "\0" + "CP28596" "\0" "ISO-8859-6" "\0" + "CP28597" "\0" "ISO-8859-7" "\0" + "CP28598" "\0" "ISO-8859-8" "\0" + "CP28599" "\0" "ISO-8859-9" "\0" + "CP28605" "\0" "ISO-8859-15" "\0"; # endif #endif - charset_aliases = cp; + charset_aliases = cp; } - return cp; + return cp; } /* Determine the current locale's character encoding, and canonicalize it @@ -268,131 +256,120 @@ get_charset_aliases () STATIC #endif const char * -locale_charset () -{ - const char *codeset; - const char *aliases; +locale_charset () { + const char *codeset; + const char *aliases; #if !(defined WIN32 || defined OS2) # if HAVE_LANGINFO_CODESET - /* Most systems support nl_langinfo (CODESET) nowadays. */ - codeset = nl_langinfo (CODESET); + /* Most systems support nl_langinfo (CODESET) nowadays. */ + codeset = nl_langinfo (CODESET); # else - /* On old systems which lack it, use setlocale or getenv. */ - const char *locale = NULL; + /* On old systems which lack it, use setlocale or getenv. */ + const char *locale = NULL; - /* But most old systems don't have a complete set of locales. Some - (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't - use setlocale here; it would return "C" when it doesn't support the - locale name the user has set. */ + /* But most old systems don't have a complete set of locales. Some + (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't + use setlocale here; it would return "C" when it doesn't support the + locale name the user has set. */ # if HAVE_SETLOCALE && 0 - locale = setlocale (LC_CTYPE, NULL); + locale = setlocale (LC_CTYPE, NULL); # endif - if (locale == NULL || locale[0] == '\0') - { - locale = getenv ("LC_ALL"); - if (locale == NULL || locale[0] == '\0') - { - locale = getenv ("LC_CTYPE"); - if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); - } + if (locale == NULL || locale[0] == '\0') { + locale = getenv ("LC_ALL"); + if (locale == NULL || locale[0] == '\0') { + locale = getenv ("LC_CTYPE"); + if (locale == NULL || locale[0] == '\0') + locale = getenv ("LANG"); + } } - /* On some old systems, one used to set locale = "iso8859_1". On others, - you set it to "language_COUNTRY.charset". In any case, we resolve it - through the charset.alias file. */ - codeset = locale; + /* On some old systems, one used to set locale = "iso8859_1". On others, + you set it to "language_COUNTRY.charset". In any case, we resolve it + through the charset.alias file. */ + codeset = locale; # endif #elif defined WIN32 - static char buf[2 + 10 + 1]; + static char buf[2 + 10 + 1]; - /* Woe32 has a function returning the locale's codepage as a number. */ - sprintf (buf, "CP%u", GetACP ()); - codeset = buf; + /* Woe32 has a function returning the locale's codepage as a number. */ + sprintf (buf, "CP%u", GetACP ()); + codeset = buf; #elif defined OS2 - const char *locale; - static char buf[2 + 10 + 1]; - ULONG cp[3]; - ULONG cplen; - - /* Allow user to override the codeset, as set in the operating system, - with standard language environment variables. */ - locale = getenv ("LC_ALL"); - if (locale == NULL || locale[0] == '\0') - { - locale = getenv ("LC_CTYPE"); - if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); - } - if (locale != NULL && locale[0] != '\0') - { - /* If the locale name contains an encoding after the dot, return it. */ - const char *dot = strchr (locale, '.'); - - if (dot != NULL) - { - const char *modifier; - - dot++; - /* Look for the possible @... trailer and remove it, if any. */ - modifier = strchr (dot, '@'); - if (modifier == NULL) - return dot; - if (modifier - dot < sizeof (buf)) - { - memcpy (buf, dot, modifier - dot); - buf [modifier - dot] = '\0'; - return buf; - } - } - - /* Resolve through the charset.alias file. */ - codeset = locale; + const char *locale; + static char buf[2 + 10 + 1]; + ULONG cp[3]; + ULONG cplen; + + /* Allow user to override the codeset, as set in the operating system, + with standard language environment variables. */ + locale = getenv ("LC_ALL"); + if (locale == NULL || locale[0] == '\0') { + locale = getenv ("LC_CTYPE"); + if (locale == NULL || locale[0] == '\0') + locale = getenv ("LANG"); } - else - { - /* OS/2 has a function returning the locale's codepage as a number. */ - if (DosQueryCp (sizeof (cp), cp, &cplen)) - codeset = ""; - else - { - sprintf (buf, "CP%u", cp[0]); - codeset = buf; - } + if (locale != NULL && locale[0] != '\0') { + /* If the locale name contains an encoding after the dot, return it. */ + const char *dot = strchr (locale, '.'); + + if (dot != NULL) { + const char *modifier; + + dot++; + /* Look for the possible @... trailer and remove it, if any. */ + modifier = strchr (dot, '@'); + if (modifier == NULL) + return dot; + if (modifier - dot < sizeof (buf)) { + memcpy (buf, dot, modifier - dot); + buf [modifier - dot] = '\0'; + return buf; + } + } + + /* Resolve through the charset.alias file. */ + codeset = locale; + } else { + /* OS/2 has a function returning the locale's codepage as a number. */ + if (DosQueryCp (sizeof (cp), cp, &cplen)) + codeset = ""; + else { + sprintf (buf, "CP%u", cp[0]); + codeset = buf; + } } #endif - if (codeset == NULL) - /* The canonical name cannot be determined. */ - codeset = ""; - - /* Resolve alias. */ - for (aliases = get_charset_aliases (); - *aliases != '\0'; - aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) - if (strcmp (codeset, aliases) == 0 - || (aliases[0] == '*' && aliases[1] == '\0')) - { - codeset = aliases + strlen (aliases) + 1; - break; - } - - /* Don't return an empty string. GNU libc and GNU libiconv interpret - the empty string as denoting "the locale's character encoding", - thus GNU libiconv would call this function a second time. */ - if (codeset[0] == '\0') - codeset = "ASCII"; - - return codeset; + if (codeset == NULL) + /* The canonical name cannot be determined. */ + codeset = ""; + + /* Resolve alias. */ + for (aliases = get_charset_aliases (); + *aliases != '\0'; + aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) + if (strcmp (codeset, aliases) == 0 + || (aliases[0] == '*' && aliases[1] == '\0')) { + codeset = aliases + strlen (aliases) + 1; + break; + } + + /* Don't return an empty string. GNU libc and GNU libiconv interpret + the empty string as denoting "the locale's character encoding", + thus GNU libiconv would call this function a second time. */ + if (codeset[0] == '\0') + codeset = "ASCII"; + + return codeset; } diff --git a/navit/traffic.c b/navit/traffic.c index 85bef0baac..e34af0531a 100644 --- a/navit/traffic.c +++ b/navit/traffic.c @@ -48,7 +48,7 @@ #include "traffic.h" #include "plugin.h" #include "fib.h" -#include "event.h" +#include "navit/event.h" #include "callback.h" #include "vehicleprofile.h" #include "debug.h" diff --git a/navit/transform.c b/navit/transform.c index 771037f8c6..8732818338 100644 --- a/navit/transform.c +++ b/navit/transform.c @@ -725,6 +725,9 @@ transform_get_selection(struct transformation *this_, enum projection pro, int o struct map_selection *ret,*curri,*curro; struct coord_geo g; + if(!this_) + return 0; + ret=map_selection_dup(this_->map_sel); curri=this_->map_sel; curro=ret; diff --git a/navit/util.c b/navit/util.c index 0dfdab20ec..838c9a4e8a 100644 --- a/navit/util.c +++ b/navit/util.c @@ -26,6 +26,10 @@ #include #include +#ifdef __APPLE__ +#define _POSIX_C_SOURCE 200809L +#endif + #ifdef _POSIX_C_SOURCE #include #include @@ -1030,7 +1034,7 @@ static char* spawn_process_compose_cmdline(char **argv) { } #endif -#ifdef _POSIX_C_SOURCE +#if defined(_POSIX_C_SOURCE) || defined(__APPLE__) #if 0 /* def _POSIX_THREADS */ #define spawn_process_sigmask(how,set,old) pthread_sigmask(how,set,old) @@ -1053,7 +1057,7 @@ GList *spawn_process_children=NULL; struct spawn_process_info* spawn_process(char **argv) { struct spawn_process_info*r=g_new(struct spawn_process_info,1); -#ifdef _POSIX_C_SOURCE +#if defined(_POSIX_C_SOURCE) || defined(__APPLE__) { pid_t pid; @@ -1296,3 +1300,7 @@ void get_compass_direction(char *buffer, int angle, int mode) { break; } } + +#ifdef __APPLE__ +#undef _POSIX_C_SOURCE +#endif diff --git a/navit/vehicle.c b/navit/vehicle.c index 78fadfd46c..4af448f37a 100644 --- a/navit/vehicle.c +++ b/navit/vehicle.c @@ -43,7 +43,7 @@ #include "plugin.h" #include "transform.h" #include "util.h" -#include "event.h" +#include "navit/event.h" #include "coord.h" #include "transform.h" #include "projection.h" diff --git a/navit/vehicle/demo/vehicle_demo.c b/navit/vehicle/demo/vehicle_demo.c index 06ab2117a3..a2b354d6ad 100644 --- a/navit/vehicle/demo/vehicle_demo.c +++ b/navit/vehicle/demo/vehicle_demo.c @@ -31,7 +31,7 @@ #include "transform.h" #include "plugin.h" #include "vehicle.h" -#include "event.h" +#include "navit/event.h" #include "util.h" /** @@ -69,7 +69,7 @@ static void vehicle_demo_destroy(struct vehicle_priv *priv) { } static void nmea_chksum(char *nmea) { - int i; + unsigned long i; if (nmea && strlen(nmea) > 3) { unsigned char csum=0; for (i = 1 ; i < strlen(nmea)-4 ; i++) diff --git a/navit/vehicle/file/vehicle_file.c b/navit/vehicle/file/vehicle_file.c index 666fd59c62..2ef1bf150d 100644 --- a/navit/vehicle/file/vehicle_file.c +++ b/navit/vehicle/file/vehicle_file.c @@ -38,7 +38,7 @@ #include "plugin.h" #include "coord.h" #include "item.h" -#include "event.h" +#include "navit/event.h" #include "vehicle.h" #include "file.h" #ifdef HAVE_SOCKET diff --git a/navit/vehicle/gpsd/vehicle_gpsd.c b/navit/vehicle/gpsd/vehicle_gpsd.c index 9dbc18aa41..451e3cd985 100644 --- a/navit/vehicle/gpsd/vehicle_gpsd.c +++ b/navit/vehicle/gpsd/vehicle_gpsd.c @@ -33,7 +33,7 @@ #include "coord.h" #include "item.h" #include "vehicle.h" -#include "event.h" +#include "navit/event.h" #include "types.h" /** @@ -264,7 +264,7 @@ static int vehicle_gpsd_try_open(struct vehicle_priv *priv) { if (!priv->gps->gps_fd) { dbg(lvl_error,"Warning: gps_fd is 0, most likely you have used a gps.h incompatible to libgps"); } - dbg(lvl_debug,"Connected to gpsd fd=%d evwatch=%p", priv->gps->gps_fd, priv->evwatch); + dbg(lvl_error,"Connected to gpsd fd=%d evwatch=%p", priv->gps->gps_fd, priv->evwatch); event_remove_timeout(priv->retry_timer2); priv->retry_timer2=NULL; return FALSE; diff --git a/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c b/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c index 0ce18a1d34..10d0c2b0ac 100644 --- a/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c +++ b/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c @@ -32,7 +32,7 @@ #include "coord.h" #include "item.h" #include "vehicle.h" -#include "event.h" +#include "navit/event.h" /** * @defgroup vehicle-gpsd-dbus Vehicle Gpsd DBus diff --git a/navit/vehicle/iphone/vehicle_iphone.c b/navit/vehicle/iphone/vehicle_iphone.c index 26b778a6e3..b4e8fae167 100644 --- a/navit/vehicle/iphone/vehicle_iphone.c +++ b/navit/vehicle/iphone/vehicle_iphone.c @@ -30,7 +30,7 @@ #include "transform.h" #include "plugin.h" #include "vehicle.h" -#include "event.h" +#include "navit/event.h" #include "corelocation.h" /** diff --git a/navit/vehicle/maemo/vehicle_maemo.c b/navit/vehicle/maemo/vehicle_maemo.c index 34514ad0e7..59a1878d85 100644 --- a/navit/vehicle/maemo/vehicle_maemo.c +++ b/navit/vehicle/maemo/vehicle_maemo.c @@ -30,7 +30,7 @@ #include "coord.h" #include "item.h" #include "vehicle.h" -#include "event.h" +#include "navit/event.h" /** * @defgroup vehicle-iphone Vehicle Maemo diff --git a/navit/vehicle/webos/bluetooth.c b/navit/vehicle/webos/bluetooth.c index d51ec450be..e85f5c977b 100644 --- a/navit/vehicle/webos/bluetooth.c +++ b/navit/vehicle/webos/bluetooth.c @@ -11,7 +11,7 @@ #include "SDL.h" #include "debug.h" #include "callback.h" -#include "event.h" +#include "navit/event.h" #include "cJSON.h" #include "vehicle_webos.h" #include "bluetooth.h" diff --git a/navit/vehicle/webos/vehicle_webos.c b/navit/vehicle/webos/vehicle_webos.c index c81b6342ba..ecf03e6d36 100644 --- a/navit/vehicle/webos/vehicle_webos.c +++ b/navit/vehicle/webos/vehicle_webos.c @@ -33,7 +33,7 @@ #include "coord.h" #include "item.h" #include "vehicle.h" -#include "event.h" +#include "navit/event.h" #include "vehicle_webos.h" #include "bluetooth.h" diff --git a/navit/vehicle/wince/vehicle_wince.c b/navit/vehicle/wince/vehicle_wince.c index afb39a959c..9e5ad57c3c 100644 --- a/navit/vehicle/wince/vehicle_wince.c +++ b/navit/vehicle/wince/vehicle_wince.c @@ -34,7 +34,7 @@ #include "plugin.h" #include "coord.h" #include "item.h" -#include "event.h" +#include "navit/event.h" #include "vehicle.h" #include #include diff --git a/navit/xslt/macos.xslt b/navit/xslt/macos.xslt new file mode 100644 index 0000000000..8746bed026 --- /dev/null +++ b/navit/xslt/macos.xslt @@ -0,0 +1,37 @@ + + + + + + + yes + + + + + + + + + + 86400 + + + + + + gpsd:localhost + 1 + + + + + + + + + + + + + diff --git a/scripts/prepare_navit_macos.sh b/scripts/prepare_navit_macos.sh new file mode 100644 index 0000000000..e0090cdae5 --- /dev/null +++ b/scripts/prepare_navit_macos.sh @@ -0,0 +1,19 @@ +# Use this script to build navit on a Mac +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +brew install glib gtk+ gettext libpng protobuf-c cmake librsvg imagemagick gpsd +brew services start gpsd + +#TODO: this needs to be adapted for the PR: git clone https://github.com/navit/navit.git +git clone https://github.com/OLFDB/navit.git +cd navit + +#TODO: this needs to be adapted for the PR: remove +git checkout macosbuild +git fetch +#remove end + +mkdir build +cd build +cmake ../contrib/macos/ +make install +open /usr/local/bin/navit.app